feat: add agent coordination and automatic work completion

Add portable topics and surveys, decision approval history, execution plans, local Codex and Claude adapters, and general agent routing. Consolidate Plan and EPIC results through deterministic completion receipts, reviewed cancellation scope and recoverable reconciliation.

Track the completed WRK-0001 and WRK-0002 records, protocol documentation, source manifests and delivery evidence.

Validation: 117 tests including Modulith; GraalVM 25 native compilation, standalone smoke and ZIP/TAR verification on macOS ARM64; identical persisted context across JVM and native executions.
This commit is contained in:
2026-11-14 01:12:21 +00:00
parent 94e3135c2e
commit a8a8faf5d8
355 changed files with 25740 additions and 154 deletions
@@ -1,9 +1,27 @@
package net.intrepid.aiengineering.project;
import net.intrepid.aiengineering.filesystem.ProtocolException;
import java.util.List;
import java.util.*;
public record ProjectConfig(int schemaVersion, Identity project, List<Repository> repositories) {
public record ProjectConfig(int schemaVersion, Identity project, List<Repository> repositories, Agents agents) {
public ProjectConfig(int schemaVersion, Identity project, List<Repository> repositories) { this(schemaVersion, project, repositories, null); }
public record Executor(String adapter, String profile, String model,
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL) Integer timeoutSeconds) {
public Executor(String adapter, String profile, String model) { this(adapter, profile, model, null); }
public Executor {
identifier(adapter); ProtocolException.text(profile, "profile"); ProtocolException.text(model, "model");
if (timeoutSeconds != null && (timeoutSeconds < 1 || timeoutSeconds > 600)) throw ProtocolException.invalid("Timeout must be 1–600 seconds");
}
public int timeout() { return timeoutSeconds == null ? 120 : timeoutSeconds; }
}
public record Agents(Executor general, Map<String, Executor> activities, String archivePolicy) {
public Agents {
if (general == null) throw ProtocolException.invalid("Configure general before specialized activities");
var ordered = new TreeMap<String, Executor>(); ordered.putAll(activities); activities = Collections.unmodifiableMap(ordered);
activities.forEach((activity, executor) -> { identifier(activity); Objects.requireNonNull(executor); });
if (!List.of("review-only", "reversible").contains(archivePolicy)) throw ProtocolException.invalid("archivePolicy must be review-only or reversible");
}
}
public ProjectConfig {
ProtocolException.schema(schemaVersion);
if (project == null || repositories == null) throw ProtocolException.validation("project and repositories are required");
@@ -31,12 +31,14 @@ public final class ProjectService {
var config = new ProjectConfig(1, identity, List.of());
Path target = Filespace.resolve(root, ".ai-engineering");
if (Files.exists(target, LinkOption.NOFOLLOW_LINKS)) throw ProtocolException.invalid("Project already exists: " + target);
ProtocolGuide.preflight(root);
Path staging = Filespace.resolve(root, ".ai-engineering-init-" + UUID.randomUUID());
Filespace.directory(staging);
for (String dir : List.of("works", "contracts", ".local")) Filespace.directory(staging.resolve(dir));
Filespace.write(staging.resolve("ai-engineering.yaml"), Documents.yaml(config), false);
Filespace.write(staging.resolve(".gitignore"), ".local/\nworks/.*.tmp\nworks/*/runs/\n", false);
Filespace.moveDirectory(staging, target);
ProtocolGuide.install(root);
return config;
}
public static String slug(String text) {
@@ -56,7 +58,7 @@ public final class ProjectService {
if (config.repositories().stream().anyMatch(r -> repositoryPath(root, r).equals(path))) throw ProtocolException.invalid("Repository path already registered: " + path);
git.inspect(root, path, repository.type());
var repositories = new ArrayList<>(config.repositories()); repositories.add(repository);
var updated = new ProjectConfig(1, config.project(), repositories);
var updated = new ProjectConfig(1, config.project(), repositories, config.agents());
Filespace.write(Filespace.resolve(root, ".ai-engineering/ai-engineering.yaml"), Documents.yaml(updated), true);
return updated;
});
@@ -66,6 +68,13 @@ public final class ProjectService {
if (path.startsWith(root.resolve(".ai-engineering"))) throw ProtocolException.invalid("Repository must be outside .ai-engineering");
return path;
}
public ProjectConfig configureAgents(Path root, ProjectConfig.Agents agents) {
return Filespace.locked(root, () -> {
var original = load(root); var changed = new ProjectConfig(1, original.project(), original.repositories(), agents);
if (!changed.equals(original)) Filespace.write(Filespace.resolve(root, ".ai-engineering/ai-engineering.yaml"), Documents.yaml(changed), true);
return changed;
});
}
public void validate(Path root) {
var config = load(root); var paths = new HashSet<Path>();
for (var repo : config.repositories()) {
@@ -0,0 +1,106 @@
package net.intrepid.aiengineering.project;
import net.intrepid.aiengineering.filesystem.*;
import java.nio.file.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
/** Provider-neutral, portable bootstrap contract, also available without a running CLI. */
public final class ProtocolGuide {
private static final String START = "<!-- ai-engineering:start -->";
private static final String END = "<!-- ai-engineering:end -->";
private static final String POINTER = START + "\n## Engineering protocol\n\n"
+ "This project uses AI Engineering. Read `.ai-engineering/README.md` and\n"
+ "`.ai-engineering/protocol.json` before engineering work. Run `aie status` and\n"
+ "`aie next-actions`, then load the selected Work with `aie work context <WRK>`.\n"
+ "Use `ai-engineering` if the `aie` alias is unavailable; without a CLI, read the\n"
+ "portable files directly. Preserve the project rules outside this block.\n"
+ "Never infer human approval; record it explicitly before significant commitments.\n" + END;
private ProtocolGuide() {}
public static String bundled(String name) {
return Filespace.io(() -> {
try (var input = ProtocolGuide.class.getResourceAsStream("/protocol/" + name)) {
if (input == null) throw new java.io.IOException("Missing bundled protocol resource: " + name);
return new String(input.readAllBytes(), StandardCharsets.UTF_8);
}
});
}
public static String guide(Path root) {
Path path = Filespace.resolve(root, ".ai-engineering/README.md");
return Files.exists(path) ? Filespace.read(path) : bundled("README.md");
}
public static boolean installed(Path root) {
boolean present = List.of("README.md", "AGENTS.md", "protocol.json").stream()
.allMatch(name -> Files.isRegularFile(Filespace.resolve(root, ".ai-engineering/" + name)))
&& Files.isRegularFile(Filespace.resolve(root, "AGENTS.md")) && Filespace.read(Filespace.resolve(root, "AGENTS.md")).contains(POINTER);
if (!present) return false;
try { validate(root); return true; } catch (ProtocolException e) { return false; }
}
public record Manifest(int schemaVersion, String protocol, String entrypoint, String instructions, String configuration,
String works, String command, List<String> aliases, List<String> startup, List<String> capabilities,
String humanApproval, String execution, boolean legacyImport) {
public Manifest {
ProtocolException.schema(schemaVersion);
if (!"ai-engineering".equals(protocol) || !"ai-engineering".equals(command)
|| !"README.md".equals(entrypoint) || !"AGENTS.md".equals(instructions)
|| !"ai-engineering.yaml".equals(configuration) || !"works".equals(works)
|| !"explicit-attestation".equals(humanApproval) || !"external-human-or-agent".equals(execution) || legacyImport)
throw ProtocolException.validation("Unsupported protocol discovery manifest");
for (String value : List.of(entrypoint, instructions, configuration, works)) ProtocolException.text(value, "manifest path");
aliases = List.copyOf(aliases); startup = List.copyOf(startup); capabilities = List.copyOf(capabilities);
if (startup.isEmpty() || capabilities.isEmpty()) throw ProtocolException.validation("Incomplete protocol discovery manifest");
}
}
/** Older projects may have no entry files; a partially installed contract is diagnosed. */
public static void validate(Path root) {
Path workspace = Filespace.resolve(root, ".ai-engineering");
var names = List.of("README.md", "AGENTS.md", "protocol.json");
if (names.stream().noneMatch(name -> Files.exists(Filespace.resolve(workspace, name)))) return;
for (String name : names) {
Path file = Filespace.resolve(workspace, name);
if (!Files.isRegularFile(file) || Filespace.read(file).isBlank()) throw ProtocolException.validation("Incomplete protocol entry contract: " + name + "; run onboard");
}
var manifest = Documents.readJson(Filespace.resolve(workspace, "protocol.json"), Manifest.class);
for (String relative : List.of(manifest.entrypoint(), manifest.instructions(), manifest.configuration()))
if (!Files.isRegularFile(Filespace.resolve(workspace, relative))) throw ProtocolException.validation("Missing manifest entry: " + relative);
if (!Files.isDirectory(Filespace.resolve(workspace, manifest.works()))) throw ProtocolException.validation("Missing manifest Works directory");
}
public record Report(int schemaVersion, List<String> updated, List<String> backups) {
public Report { updated = List.copyOf(updated); backups = List.copyOf(backups); }
}
public static void preflight(Path root) { rootInstructions(root); }
private static String rootInstructions(Path root) {
Path path = Filespace.resolve(root, "AGENTS.md");
if (!Files.exists(path)) return POINTER + "\n";
if (!Files.isRegularFile(path)) throw ProtocolException.invalid("AGENTS.md must be a regular file");
String original = Filespace.read(path); int start = original.indexOf(START), end = original.indexOf(END);
if ((start < 0) != (end < 0) || (start >= 0 && (end < start || original.indexOf(START, start + START.length()) >= 0
|| original.indexOf(END, end + END.length()) >= 0))) throw ProtocolException.validation("Ambiguous AIE instruction block in AGENTS.md");
if (start >= 0) return original.substring(0, start) + POINTER + original.substring(end + END.length());
return original + (original.isEmpty() ? "" : original.endsWith("\n") ? "\n" : "\n\n") + POINTER + "\n";
}
public static Report install(Path root) {
return Filespace.locked(root, () -> {
var content = new LinkedHashMap<String, String>();
for (String name : List.of("README.md", "AGENTS.md", "protocol.json")) content.put(".ai-engineering/" + name, bundled(name));
content.put("AGENTS.md", rootInstructions(root));
var originals = new LinkedHashMap<String, String>();
for (var item : content.entrySet()) {
Path path = Filespace.resolve(root, item.getKey());
if (Files.exists(path) && !Files.isRegularFile(path)) throw ProtocolException.invalid("Protocol destination must be a regular file: " + path);
originals.put(item.getKey(), Files.exists(path) ? Filespace.read(path) : null);
}
var updated = new ArrayList<String>(); var backups = new ArrayList<String>(); String operation = UUID.randomUUID().toString();
for (var item : content.entrySet()) {
String original = originals.get(item.getKey()); if (item.getValue().equals(original)) continue;
Path path = Filespace.resolve(root, item.getKey());
if (original != null) {
String relative = ".ai-engineering/.local/backups/onboarding/" + operation + "/" + (backups.size() + 1) + "-" + path.getFileName();
Path backup = Filespace.resolve(root, relative); Filespace.directory(backup.getParent()); Filespace.write(backup, original, false); backups.add(relative);
}
Filespace.write(path, item.getValue(), original != null); updated.add(item.getKey());
}
return new Report(1, updated, backups);
});
}
}