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

@@ -25,6 +25,14 @@ struct SeedSkill {
/// - ok: creates the dir, exit 0. exists: creates the dir, "already exists" on
/// stdout, exit 1 (the create race). fail: "Error: create exploded", exit 1.
/// stderr-only: error on stderr with empty stdout (#48 fallback).
///
/// Also speaks `mcp` behind the `-p museion` global flag (#23): `mcp list`
/// prints "museion-tools" iff `<binaryDir>/mcp-registered` exists, else
/// "No MCP servers configured."; `mcp add` verifies its argv, reads ONE "y"
/// line from stdin (mismatch/EOF → "Cancelled.", exit 1 — nothing saved),
/// records the exact invocation in `<binaryDir>/mcp-add-invocation`, drops the
/// marker, prints "Saved 'museion-tools' to …" (verified wire strings).
/// `<binaryDir>/mcp-add-fails` forces "Error: mcp add exploded", exit 1.
func makeFakeHermes(at dir: String, name: String = "hermes", mode: String) -> String {
let path = (dir as NSString).appendingPathComponent(name)
let createBlock = switch mode {
@@ -57,6 +65,35 @@ func makeFakeHermes(at dir: String, name: String = "hermes", mode: String) -> St
NAME="$3"
\(createBlock)
fi
if [[ "$1" == "-p" && "$2" == "museion" && "$3" == "mcp" ]]; then
if [[ "$4" == "list" ]]; then
if [[ -f "${0:h}/mcp-registered" ]]; then
print "museion-tools enabled"
exit 0
fi
print "No MCP servers configured."
exit 0
fi
if [[ "$4" == "add" ]]; then
if [[ "$5" != "museion-tools" || "$6" != "--command" || -z "$7" || "$8" != "--args" || "$9" != "--serve-mcp" ]]; then
print "Error: mcp add unexpected argv: $5 $6 $7 $8 $9"
exit 1
fi
if [[ -f "${0:h}/mcp-add-fails" ]]; then
print "Error: mcp add exploded"
exit 1
fi
read -r ANSWER
if [[ "$ANSWER" != "y" ]]; then
print "Cancelled."
exit 1
fi
print -r -- "$*" > "${0:h}/mcp-add-invocation"
touch "${0:h}/mcp-registered"
print "Saved 'museion-tools' to ${0:h}/profiles/museion/config.yaml"
exit 0
fi
fi
exit 97
"""
try? FileManager.default.createDirectory(atPath: dir, withIntermediateDirectories: true)
@@ -277,6 +314,58 @@ struct ProfileProvisionerTests {
#expect(!FileManager.default.fileExists(atPath: orphan))
}
@Test func `fresh pass registers museion-tools via the cli with the exact command line`() {
let binDir = provTempDir("mcp-add")
let serverPath = (provTempDir("server") as NSString).appendingPathComponent("Museion")
let outcome = ProfileProvisioner.perform(
hermesBinary: makeFakeHermes(at: binDir, mode: "ok"),
profileRoot: (binDir as NSString).appendingPathComponent("profiles"),
payloadRoot: makePayload(at: provTempDir("payload"), skills: skills),
serverBinaryPath: serverPath,
)
#expect(outcome == .seeded(copied: 2, present: 0))
let invocation = ((try? String(
contentsOfFile: (binDir as NSString).appendingPathComponent("mcp-add-invocation"),
encoding: .utf8,
)) ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
#expect(invocation == "-p museion mcp add museion-tools --command \(serverPath) --args --serve-mcp")
}
@Test func `already-registered profile skips the add`() {
let binDir = provTempDir("mcp-skip")
// Pre-existing registration → `mcp list` reports it → no add: a re-add
// would prompt "Overwrite? [y/N]" — the skip avoids that branch.
try? "".write(
toFile: (binDir as NSString).appendingPathComponent("mcp-registered"),
atomically: true,
encoding: .utf8,
)
let outcome = ProfileProvisioner.perform(
hermesBinary: makeFakeHermes(at: binDir, mode: "ok"),
profileRoot: (binDir as NSString).appendingPathComponent("profiles"),
payloadRoot: makePayload(at: provTempDir("payload"), skills: skills),
serverBinaryPath: "/fake/Museon",
)
#expect(outcome == .seeded(copied: 2, present: 0))
#expect(!FileManager.default.fileExists(atPath: (binDir as NSString).appendingPathComponent("mcp-add-invocation")))
}
@Test func `rejected add fails the register phase with the cli excerpt`() {
let binDir = provTempDir("mcp-reject")
try? "".write(
toFile: (binDir as NSString).appendingPathComponent("mcp-add-fails"),
atomically: true,
encoding: .utf8,
)
let outcome = ProfileProvisioner.perform(
hermesBinary: makeFakeHermes(at: binDir, mode: "ok"),
profileRoot: (binDir as NSString).appendingPathComponent("profiles"),
payloadRoot: makePayload(at: provTempDir("payload"), skills: skills),
serverBinaryPath: "/fake/Museion",
)
#expect(outcome == .failed(phase: .register, excerpt: "Error: mcp add exploded"))
}
@Test func `bundled manifest matches bundled payload`() {
// url(forResource:) doesn't resolve folder references — use the same path
// the provisioner itself builds.