feat: store discussion prose in Markdown bodies
Add versioned Markdown discussion documents with legacy YAML reading and explicit migration that backs up originals and preserves semantic history. Render readable discussion and decision prose in Markdown context, document compatibility, and extend native smoke coverage for migration. Validated with 29 passing tests, macOS ARM64 native smoke, and context-preserving migration of the Zelda pilot Work.
This commit is contained in:
@@ -11,7 +11,7 @@ public final class DiscussionService {
|
||||
public List<DiscussionEntry> list(Path root, String id) {
|
||||
Work work = works.load(root, id); Path folder = works.folder(root, id);
|
||||
return work.discussions().stream().map(ref -> {
|
||||
var entry = Documents.readDocument(Filespace.resolve(folder, "discussions/" + ref + ".md"), DiscussionEntry.class);
|
||||
var entry = Documents.readMarkdownDocument(Filespace.resolve(folder, "discussions/" + ref + ".md"), DiscussionEntry.class, "text");
|
||||
if (!entry.id().equals(ref) || !entry.workId().equals(id)) throw ProtocolException.validation("Discussion identity mismatch: " + ref);
|
||||
return entry;
|
||||
}).toList();
|
||||
@@ -23,8 +23,41 @@ public final class DiscussionService {
|
||||
throw ProtocolException.invalid("Response target not found in Work: " + respondsTo);
|
||||
String id = works.nextReference(work.discussions(), "DSC");
|
||||
var entry = new DiscussionEntry(1, id, workId, discussionId, kind, author, Instant.now().toString(), respondsTo, text);
|
||||
Documents.writeDocument(Filespace.resolve(works.folder(root, workId), "discussions/" + id + ".md"), entry, false);
|
||||
Documents.writeMarkdownDocument(Filespace.resolve(works.folder(root, workId), "discussions/" + id + ".md"), entry, "text", false);
|
||||
works.addReference(root, workId, "discussions", id); return entry;
|
||||
});
|
||||
}
|
||||
public record MigrationReport(int schemaVersion, int converted, int unchanged, List<String> backups) {
|
||||
public MigrationReport { backups = List.copyOf(backups); }
|
||||
}
|
||||
private record Conversion(Path path, String original, String converted) {}
|
||||
/** Explicit formatting migration, preserving semantic history and Work modification timestamps. */
|
||||
public MigrationReport migrate(Path root, String workId) {
|
||||
return Filespace.locked(root, () -> {
|
||||
var entries = list(root, workId); var conversions = new java.util.ArrayList<Conversion>();
|
||||
Path folder = works.folder(root, workId);
|
||||
// Preflight every entry before creating backups or replacing any file.
|
||||
for (var entry : entries) {
|
||||
Path path = Filespace.resolve(folder, "discussions/" + entry.id() + ".md");
|
||||
if (Documents.documentVersion(path) == 1) {
|
||||
String original = Filespace.read(path);
|
||||
if (!Documents.readMarkdownDocument(path, DiscussionEntry.class, "text").equals(entry))
|
||||
throw ProtocolException.validation("Discussion changed during migration: " + path);
|
||||
conversions.add(new Conversion(path, original, Documents.markdownMigration(path, entry, "text")));
|
||||
}
|
||||
}
|
||||
var backups = new java.util.ArrayList<String>();
|
||||
String backupDirectory = ".ai-engineering/.local/backups/discussions/" + workId + "/" + java.util.UUID.randomUUID();
|
||||
for (var conversion : conversions) {
|
||||
if (!Filespace.read(conversion.path()).equals(conversion.original()))
|
||||
throw ProtocolException.validation("Discussion changed during migration; retry after the other editor finishes: " + conversion.path());
|
||||
String relative = backupDirectory + "/" + conversion.path().getFileName();
|
||||
Path backup = Filespace.resolve(root, relative); Filespace.directory(backup.getParent());
|
||||
Filespace.write(backup, conversion.original(), false);
|
||||
Filespace.write(conversion.path(), conversion.converted(), true);
|
||||
backups.add(relative);
|
||||
}
|
||||
return new MigrationReport(1, conversions.size(), entries.size() - conversions.size(), backups);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user