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 -4
View File
@@ -86,14 +86,31 @@ nonisolated enum EngineProbe {
return result
}
/// Run a process with stdin closed, capture stdout/stderr, kill after `timeout`.
static func execute(_ arguments: [String], timeout: TimeInterval) -> ProcessOutput {
/// Run a process, capture stdout/stderr, kill after `timeout`. `stdin` (when
/// set) is written to the child then closed — for interactive prompts like
/// the mcp add's "Enable all tools? [Y/n]"; otherwise stdin is /dev/null.
static func execute(_ arguments: [String], timeout: TimeInterval, stdin: String? = nil) -> ProcessOutput {
let path = arguments[0]
guard FileManager.default.isExecutableFile(atPath: path) else { return ProcessOutput(exitCode: -1) }
let process = Process()
process.executableURL = URL(fileURLWithPath: path)
process.arguments = Array(arguments.dropFirst())
process.standardInput = FileHandle.nullDevice
// The parent holds the pipe's read end until dealloc, so this small
// pre-spawn write can't hit EPIPE; closing our write end gives the
// child one line + EOF. Ceiling (audit INFO-6): a pre-spawn write
// must stay well under the 64 KB pipe buffer or it deadlocks before
// the watchdog exists — chunked write or spawn-then-write if a
// caller ever needs more.
var stdinPipe: Pipe?
if let stdin {
let pipe = Pipe()
process.standardInput = pipe
try? pipe.fileHandleForWriting.write(contentsOf: Data(stdin.utf8))
try? pipe.fileHandleForWriting.close()
stdinPipe = pipe
} else {
process.standardInput = FileHandle.nullDevice
}
let stdoutPipe = Pipe(), stderrPipe = Pipe()
process.standardOutput = stdoutPipe
@@ -109,7 +126,11 @@ nonisolated enum EngineProbe {
Thread.sleep(forTimeInterval: 0.01)
}
if process.isRunning {
terminateAndReap(process, pipes: [stdoutPipe.fileHandleForReading, stderrPipe.fileHandleForReading])
var pipes = [stdoutPipe.fileHandleForReading, stderrPipe.fileHandleForReading]
if let stdinPipe {
pipes.append(stdinPipe.fileHandleForReading)
}
terminateAndReap(process, pipes: pipes)
return ProcessOutput(exitCode: -1, stderr: "timed out after \(Int(timeout)) s")
}