feat(mentor): museion-tools MCP server (#23)
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
Headless --serve-mcp role in the app binary: NDJSON JSON-RPC on stdio exposing query_learnings and submit_fix_cards (ADR-0006 cards, anchor-validated; stale lands flagged, never rejected), registered into the museion profile at provisioning. Cards persist per piece under <piece>/cards/ and surface in a floating Fix Cards palette with pass-stamped provenance. Live dogfood drove the shape: session/prompt waits pass length (the 15 s request default abandoned working turns), a liveness row and a persisted Debug checkbox (off) split writing sessions from debug chatter, the verdict references findings by title only while the cards carry the detail (persona v1.3 — tools work in silence), and the #24 pass rails (pass bar, TurnOutcome seam, snapshots) ride in. Three-reviewer audit round: piece-path shape guard closes the JSON-drop and substring-oracle holes, nested submit rawInput parsing (the flat parser never matched the live rail), missing stopReason never advances a pass, 1 MB stdin cap, card scan off MainActor. 296 tests green; every behavioral fix flip-verified. Closes #23
This commit is contained in:
1 parent
c2e94fd825
commit
683ddf8426
29 files changed
+2626
-169
No files matched your search
@@ -557,3 +557,149 @@ private func readPiece(_ home: URL, root: String, project: String, _ id: String)
|
||||
#expect(onDisk.contains("## one"))
|
||||
#expect(!FileManager.default.fileExists(atPath: home.appendingPathComponent("projects/posts/\(post.id)").path))
|
||||
}
|
||||
|
||||
// MARK: Pass substrate (#24)
|
||||
|
||||
@Test func `snapshotPass writes the pre-pass body verbatim under passes`() throws {
|
||||
let home = try storeHome()
|
||||
let post = try PostStore.writeNew(body: "# Snapshot\n\nPre-pass body.", home: home)
|
||||
|
||||
try PostStore.snapshotPass(id: post.id, kind: .pass1, body: "# Snapshot\n\nPre-pass body.", home: home)
|
||||
|
||||
let snapshot = try String(
|
||||
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/passes/pass-1.md"),
|
||||
encoding: .utf8,
|
||||
)
|
||||
#expect(snapshot == "# Snapshot\n\nPre-pass body.") // body only, no frontmatter
|
||||
}
|
||||
|
||||
@Test func `snapshotPass re-run overwrites keeping latest per pass type`() throws {
|
||||
let home = try storeHome()
|
||||
let post = try PostStore.writeNew(body: "# Snap\n\nBefore.", home: home)
|
||||
|
||||
try PostStore.snapshotPass(id: post.id, kind: .pass1, body: "# Snap\n\nBefore.", home: home)
|
||||
try PostStore.snapshotPass(id: post.id, kind: .pass1, body: "# Snap\n\nAfter the first pass.", home: home)
|
||||
|
||||
let snapshot = try String(
|
||||
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/passes/pass-1.md"),
|
||||
encoding: .utf8,
|
||||
)
|
||||
#expect(snapshot == "# Snap\n\nAfter the first pass.")
|
||||
}
|
||||
|
||||
@Test func `pass snapshots coexist per pass type`() throws {
|
||||
let home = try storeHome()
|
||||
let post = try PostStore.writeNew(body: "# Both\n\nBody.", home: home)
|
||||
let passes = home.appendingPathComponent("projects/posts/\(post.id)/passes", isDirectory: true)
|
||||
|
||||
try PostStore.snapshotPass(id: post.id, kind: .pass1, body: "before pass one", home: home)
|
||||
try PostStore.snapshotPass(id: post.id, kind: .pass2, body: "before pass two", home: home)
|
||||
|
||||
#expect(try String(contentsOf: passes.appendingPathComponent("pass-1.md"), encoding: .utf8) == "before pass one")
|
||||
#expect(try String(contentsOf: passes.appendingPathComponent("pass-2.md"), encoding: .utf8) == "before pass two")
|
||||
}
|
||||
|
||||
@Test func `snapshotPass on vanished piece throws`() throws {
|
||||
let home = try storeHome()
|
||||
#expect(throws: CocoaError(.fileReadNoSuchFile)) {
|
||||
try PostStore.snapshotPass(id: "ghost", kind: .pass1, body: "x", home: home)
|
||||
}
|
||||
#expect(!FileManager.default.fileExists(atPath: home.appendingPathComponent("projects/posts/ghost").path))
|
||||
}
|
||||
|
||||
@Test func `advancePassState stamps Pass-1 Done preserving origin type and body`() throws {
|
||||
let home = try storeHome { home in
|
||||
let dir = home.appendingPathComponent("projects/essays/essay", isDirectory: true)
|
||||
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
|
||||
try "---\ntype: outline\npass_state: First Draft\norigin: ai\n---\n# Essay\n\nArgued body."
|
||||
.write(to: dir.appendingPathComponent("post.md"), atomically: true, encoding: .utf8)
|
||||
}
|
||||
|
||||
let newState = try PostStore.advancePassState(id: "essay", kind: .pass1, home: home)
|
||||
|
||||
#expect(newState == .pass1Done)
|
||||
// Stamp round-trip: pass_state advanced, origin/type/body byte-preserved.
|
||||
#expect(try readPiece(home, root: "projects", project: "essays", "essay")
|
||||
== "---\ntype: outline\npass_state: Pass-1 Done\norigin: ai\n---\n# Essay\n\nArgued body.")
|
||||
#expect(PostStore.readBody(id: "essay", home: home) == "# Essay\n\nArgued body.")
|
||||
let scanned = try #require(Post.scan(home: home).first)
|
||||
#expect(scanned.passState == .pass1Done)
|
||||
#expect(scanned.origin == .ai)
|
||||
#expect(scanned.type == .outline)
|
||||
}
|
||||
|
||||
@Test func `advancePassState reaches Pass-2 Done straight from First Draft`() throws {
|
||||
let home = try storeHome()
|
||||
let post = try PostStore.writeNew(body: "# Direct\n\nBody.", home: home)
|
||||
// Passes run in any order — Pass 2 first is legal.
|
||||
#expect(try PostStore.advancePassState(id: post.id, kind: .pass2, home: home) == .pass2Done)
|
||||
#expect(Post.scan(home: home).first?.passState == .pass2Done)
|
||||
}
|
||||
|
||||
@Test func `advancePassState never regresses a higher state`() throws {
|
||||
let home = try storeHome { home in
|
||||
let dir = home.appendingPathComponent("projects/posts/done-both", isDirectory: true)
|
||||
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
|
||||
try "---\ntype: post\npass_state: Pass-2 Done\norigin: writer\n---\n# Done\n\nBody."
|
||||
.write(to: dir.appendingPathComponent("post.md"), atomically: true, encoding: .utf8)
|
||||
}
|
||||
|
||||
// A Pass 1 completing on a Pass-2 Done piece keeps the higher state.
|
||||
let newState = try PostStore.advancePassState(id: "done-both", kind: .pass1, home: home)
|
||||
|
||||
#expect(newState == .pass2Done)
|
||||
#expect(Post.scan(home: home).first?.passState == .pass2Done)
|
||||
#expect(try readPost(home, "done-both").contains("pass_state: Pass-2 Done"))
|
||||
}
|
||||
|
||||
@Test func `advancePassState is idempotent on re-run`() throws {
|
||||
let home = try storeHome()
|
||||
let post = try PostStore.writeNew(body: "# Again\n\nBody.", home: home)
|
||||
_ = try PostStore.advancePassState(id: post.id, kind: .pass1, home: home)
|
||||
let first = try readPost(home, post.id)
|
||||
|
||||
#expect(try PostStore.advancePassState(id: post.id, kind: .pass1, home: home) == .pass1Done)
|
||||
#expect(try readPost(home, post.id) == first)
|
||||
}
|
||||
|
||||
@Test func `advancePassState on vanished piece throws`() throws {
|
||||
let home = try storeHome()
|
||||
#expect(throws: CocoaError(.fileReadNoSuchFile)) {
|
||||
_ = try PostStore.advancePassState(id: "ghost", kind: .pass1, home: home)
|
||||
}
|
||||
}
|
||||
|
||||
@Test func `stub carries pass name piece path and fix-card reminder`() {
|
||||
let pieceURL = URL(fileURLWithPath: "/vault/projects/essays/essay/post.md")
|
||||
let stub = PassContext.stub(kind: .pass1, pieceURL: pieceURL, hasResearch: false)
|
||||
|
||||
#expect(stub.contains("Pass 1 — paragraph level and up."))
|
||||
#expect(stub.contains("Piece: /vault/projects/essays/essay/post.md"))
|
||||
#expect(!stub.contains("Research notes:"))
|
||||
let closing = "Critique the piece for this pass. Deliver the verdict in your reply — "
|
||||
+ "findings travel as fix-card tool calls (submit_fix_cards). Do not write to the piece folder."
|
||||
#expect(stub.contains(closing))
|
||||
#expect(PassContext.stub(kind: .pass2, pieceURL: pieceURL, hasResearch: false)
|
||||
.contains("Pass 2 — sentence level and below."))
|
||||
}
|
||||
|
||||
@Test func `stub adds the research line only when research exists`() {
|
||||
let pieceURL = URL(fileURLWithPath: "/vault/projects/essays/essay/post.md")
|
||||
let research = "/vault/projects/essays/essay/research"
|
||||
#expect(PassContext.stub(kind: .pass1, pieceURL: pieceURL, hasResearch: true)
|
||||
.contains("Research notes: \(research)"))
|
||||
#expect(!PassContext.stub(kind: .pass1, pieceURL: pieceURL, hasResearch: false).contains(research))
|
||||
}
|
||||
|
||||
@Test func `estimateTokens is stub plus body chars over four rounded up`() {
|
||||
let pieceURL = URL(fileURLWithPath: "/vault/essay/post.md")
|
||||
let body = "# Title\n\nTwo paragraphs of argued prose."
|
||||
for kind in PassKind.allCases {
|
||||
for hasResearch in [true, false] {
|
||||
let total = PassContext.stub(kind: kind, pieceURL: pieceURL, hasResearch: hasResearch).count + body.count
|
||||
let expected = total % 4 == 0 ? total / 4 : total / 4 + 1 // ceil — derived independently of the impl
|
||||
#expect(PassContext.estimateTokens(kind: kind, body: body, pieceURL: pieceURL, hasResearch: hasResearch)
|
||||
== expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user