feat: promote draft decisions when creating plans
Promote referenced drafts deterministically with system provenance, causal Plan links, supersession history and recovery from publication failures. Preserve direct human approval and historical records. Add JVM and native regression coverage and update the portable protocol. Record the WRK-0007 importer decision and six-step plan, and complete WRK-0008 with verification evidence.
This commit is contained in:
@@ -44,10 +44,31 @@ public final class PlanService {
|
||||
}
|
||||
public Plan create(Path root, String workId, String title, String description, List<String> refs, String author) {
|
||||
return Filespace.locked(root, () -> {
|
||||
var work = works.editable(root, workId); accepted(root, workId, refs); String id = works.nextReference(work.plans(), "PLN"), now = Instant.now().toString();
|
||||
var work = works.editable(root, workId); String id = works.nextReference(work.plans(), "PLN"), now = Instant.now().toString();
|
||||
var plan = new Plan(1, id, workId, title, description, refs, List.of(), Plan.Status.OPEN, author, now, 1, null, now, author, "Plan created");
|
||||
Path path = path(root, workId, id); Filespace.directory(path.getParent()); Documents.writeMarkdownDocument(path, plan, "description", false);
|
||||
works.addReference(root, workId, "plans", id); return plan;
|
||||
Path path = path(root, workId, id), folder = works.folder(root, workId), workPath = Filespace.resolve(folder, "work.md");
|
||||
if (Files.exists(path)) throw ProtocolException.invalid("Already exists: " + path);
|
||||
String originalWork = Filespace.read(workPath), document = Documents.markdownDocument(plan, "description");
|
||||
var promotions = decisions.preparePlanAcceptance(root, workId, refs, id, author);
|
||||
Filespace.directory(path.getParent());
|
||||
try {
|
||||
promotions.publish(folder);
|
||||
Filespace.write(path, document, false);
|
||||
works.addReference(root, workId, "plans", id); return plan;
|
||||
} catch (RuntimeException failure) {
|
||||
try {
|
||||
if (Files.exists(path)) {
|
||||
if (!Filespace.read(path).equals(document)) throw ProtocolException.validation("Concurrent edit during Plan recovery: " + path);
|
||||
Filespace.io(() -> { Files.delete(path); return null; });
|
||||
}
|
||||
promotions.rollback();
|
||||
if (!Filespace.read(workPath).equals(originalWork)) Filespace.write(workPath, originalWork, true);
|
||||
} catch (RuntimeException recovery) {
|
||||
failure.addSuppressed(recovery);
|
||||
throw new ProtocolException(4, "Plan creation interrupted; inspect " + workId + ": " + failure.getMessage() + "; recovery: " + recovery.getMessage());
|
||||
}
|
||||
throw failure;
|
||||
}
|
||||
});
|
||||
}
|
||||
private Plan mutate(Path root, String work, String id, String by, String reason, Function<Plan, Plan> mutation) {
|
||||
|
||||
Reference in New Issue
Block a user