feat(mentor): museion-tools MCP server (#23)
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:
AlexKucera committed 2026-10-20 12:20:54 +02:00
1 parent c2e94fd825
commit 683ddf8426
29 files changed
+2626 -169

No files matched your search

+51
View File
@@ -567,3 +567,54 @@ nonisolated enum PostStore {
return lines.joined(separator: "\n")
}
}
// MARK: Pass substrate (#24)
/// #24 (S3.1): the pass write side — pre-pass snapshots and monotonic
/// Pass State advancement. Same file as the enum: `private` members
/// (folder/existingStamp/stamped) stay reachable at file scope.
nonisolated extension PostStore {
/// #24 (S3.1): pre-pass snapshot — the body exactly as it stood when
/// the pass was invoked, written verbatim to
/// `<piece>/passes/<kind.snapshotFileName>`. Fixed filename per pass
/// type: a re-run overwrites, so the LATEST pre-pass body per type
/// survives (running a pass never destroys text). Body only, no
/// frontmatter — it is the writer's diff anchor against post.md. A
/// vanished piece throws (a snapshot never resurrects, #18).
static func snapshotPass(id: String, kind: PassKind, body: String, home: URL) throws {
guard let dir = folder(of: id, home: home) else {
throw CocoaError(.fileReadNoSuchFile)
}
let passes = dir.appendingPathComponent("passes", isDirectory: true)
try FileManager.default.createDirectory(at: passes, withIntermediateDirectories: true)
try body.write(to: passes.appendingPathComponent(kind.snapshotFileName), atomically: true, encoding: .utf8)
}
/// #24 (S3.1): advance `pass_state` when a pass completes. Monotonic:
/// the new state is the higher of the file's current state and the
/// pass's doneState — passes run in ANY order, so a Pass 1 completing
/// on a Pass-2 Done piece never regresses it. Body/origin/type ride the
/// existingStamp→stamped round-trip unchanged (same preservation as
/// `overwrite`). Returns the state now stamped. A vanished piece throws.
static func advancePassState(id: String, kind: PassKind, home: URL) throws -> Post.PassState {
let piece = try existingStamp(id: id, home: home)
let advanced = higherState(piece.passState, kind.doneState)
try stamped(body: piece.body, passState: advanced, origin: piece.origin, type: piece.type)
.write(to: piece.dir.appendingPathComponent("post.md"), atomically: true, encoding: .utf8)
return advanced
}
/// #24: Pass State maturity order — First Draft < Pass-1 Done <
/// Pass-2 Done. Private: state advancement is the only consumer (making
/// `Post.PassState` Comparable would widen the public surface for it).
private static func higherState(_ current: Post.PassState, _ completed: Post.PassState) -> Post.PassState {
func rank(_ state: Post.PassState) -> Int {
switch state {
case .firstDraft: 0
case .pass1Done: 1
case .pass2Done: 2
}
}
return rank(current) >= rank(completed) ? current : completed
}
}