feat: import open Discussion Framework agendas into Works

Add deterministic preview and fingerprint-bound application for independent
DF sources under an AIE umbrella. Preserve complete agendas and original
evidence with source-scoped identities, validated receipts and safe retries.

Publish prepared Works atomically, require review for changed imports and
retain existing refinement without source edits or model calls.

Advertise protocol contract 2 while continuing to read contract-1 projects. Add JVM,
concurrency, recovery and native coverage; document usage and complete
WRK-0007 with verification evidence.
This commit is contained in:
2026-11-16 14:53:05 +00:00
parent bc9fe8152c
commit 8f6cfa5d86
74 changed files with 3663 additions and 78 deletions
@@ -42,6 +42,7 @@ public final class EngineeringCli implements Runnable {
.addSubcommand("plan", new CommandLine(new PlanCommands()).addSubcommand("step", new StepCommands()))
.addSubcommand("topic", new TopicCommands()).addSubcommand("survey", new SurveyCommands()).addSubcommand("agent", new AgentCommands())
.addSubcommand("epic", new EpicCommands());
commandLine.addSubcommand("import", new CommandLine(new ImportCommands()).addSubcommand("discussion", new DiscussionImportCommand()));
configure(commandLine, out, err);
commandLine.setExecutionExceptionHandler((exception, command, parse) -> {
if (exception instanceof ProtocolException problem) { err.println(problem.getMessage()); return problem.exitCode(); }
@@ -61,6 +62,49 @@ public final class EngineeringCli implements Runnable {
}
private Path resolve(Path path) { return path.isAbsolute() ? path : cwd.resolve(path); }
enum Format { markdown, json }
@Command(name = "import", mixinStandardHelpOptions = true, description = "Import supported legacy context with explicit preview and application.")
public class ImportCommands implements Runnable {
@Override public void run() { commandLine.getSubcommands().get("import").usage(output); }
}
@Command(name = "discussion", mixinStandardHelpOptions = true, description = "Preview or import DF DSCs with open AGD agendas, without a model call.")
public class DiscussionImportCommand implements java.util.concurrent.Callable<Integer> {
@Option(names = "--source", required = true, description = "Stable source ID=PATH; repeat for independent DF projects. Paths are caller-relative.") List<String> sources;
@Option(names = "--target", description = "SOURCE=TEXT target description; repeat for multiple targets.") List<String> targets;
@Option(names = "--apply", description = "Publish the reviewed import; requires --expect.") boolean apply;
@Option(names = "--expect", description = "Fingerprint returned by a valid preview.") String expected;
@Option(names = "--author", defaultValue = "human") String author;
@Option(names = "--format", defaultValue = "markdown") Format format;
private String[] pair(String value, String option) {
int at = value.indexOf('=');
if (at < 1 || at == value.length() - 1) throw ProtocolException.invalid(option + " requires ID=VALUE");
return new String[]{value.substring(0, at), value.substring(at + 1)};
}
@Override public Integer call() {
if (apply && expected == null) throw ProtocolException.invalid("--apply requires --expect from a preview");
if (!apply && expected != null) throw ProtocolException.invalid("--expect requires --apply");
var roots = new java.util.LinkedHashMap<String, String>(); var targetMap = new java.util.HashMap<String, List<String>>();
for (String raw : sources) {
var pair = pair(raw, "--source");
if (roots.putIfAbsent(pair[0], resolve(Path.of(pair[1])).normalize().toString()) != null)
throw ProtocolException.invalid("Duplicate source ID: " + pair[0]);
}
for (String raw : safe(targets)) {
var pair = pair(raw, "--target");
if (!roots.containsKey(pair[0])) throw ProtocolException.invalid("Unknown target source: " + pair[0]);
targetMap.computeIfAbsent(pair[0], k -> new java.util.ArrayList<>()).add(pair[1]);
}
var inputs = roots.entrySet().stream().map(e -> new net.intrepid.aiengineering.legacyimport.DiscussionImport.Source(e.getKey(), e.getValue(), targetMap.get(e.getKey()))).toList();
var importer = new net.intrepid.aiengineering.legacyimport.DiscussionImportService(); Path destination = root();
if (apply) {
var validity = verification.project(destination);
if (!validity.valid()) throw ProtocolException.validation(String.join("; ", validity.issues()));
}
var result = apply ? importer.apply(destination, inputs, expected, author) : importer.preview(destination, inputs);
if (format == Format.json) output.print(Documents.json(result));
else output.print(net.intrepid.aiengineering.legacyimport.DiscussionImportService.markdown(result));
return result.valid() ? 0 : 4;
}
}
private int emit(Object value, Format format) {
output.print(format == Format.json ? Documents.json(value) : Documents.yaml(value)); return 0;
}