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
@@ -3,7 +3,9 @@
|
||||
// Museion
|
||||
//
|
||||
// S2.1 provisioning (#47): create the museion profile via the Hermes CLI,
|
||||
// then seed the bundled writing skills additively (#43/#45/#46).
|
||||
// then seed the bundled writing skills additively (#43/#45/#46), then
|
||||
// register museion-tools via `hermes -p museion mcp add` (#23 slice 2 —
|
||||
// the CLI rail only, never hand-written mcp_servers YAML, #44).
|
||||
//
|
||||
|
||||
import Foundation
|
||||
@@ -16,6 +18,7 @@ nonisolated enum ProfileProvisioner {
|
||||
enum Phase: String, Equatable, Sendable {
|
||||
case create = "couldn't set up the writing profile"
|
||||
case copy = "couldn't copy the writing skills"
|
||||
case register = "couldn't register the writing tools"
|
||||
}
|
||||
|
||||
enum Outcome: Equatable, Sendable {
|
||||
@@ -23,15 +26,19 @@ nonisolated enum ProfileProvisioner {
|
||||
case failed(phase: Phase, excerpt: String)
|
||||
}
|
||||
|
||||
/// One idempotent pass: create the profile if missing, seed missing skills (#45).
|
||||
/// One idempotent pass: create the profile if missing, seed missing skills
|
||||
/// (#45), register museion-tools when missing (#23).
|
||||
/// - Parameters:
|
||||
/// - hermesBinary: absolute path to the engine binary (gate's winner; tests pass fakes).
|
||||
/// - profileRoot: profiles base dir (tests inject; default `~/.hermes/profiles`).
|
||||
/// - payloadRoot: bundled writing-skills payload dir (tests inject; default in-bundle).
|
||||
/// - serverBinaryPath: MCP server the engine spawns — this app's binary with
|
||||
/// `--serve-mcp` (tests inject; nil skips registration).
|
||||
static func perform(
|
||||
hermesBinary: String?,
|
||||
profileRoot: String = ("~/.hermes/profiles" as NSString).expandingTildeInPath,
|
||||
payloadRoot: String = defaultPayloadRoot(),
|
||||
serverBinaryPath: String? = Bundle.main.executableURL?.path,
|
||||
timeout: TimeInterval = 60,
|
||||
) -> Outcome {
|
||||
let profileDir = (profileRoot as NSString).appendingPathComponent("museion")
|
||||
@@ -56,7 +63,18 @@ nonisolated enum ProfileProvisioner {
|
||||
}
|
||||
|
||||
// Phase 2 — additive seed per seed-manifest.txt (#46).
|
||||
return seedSkills(payloadRoot: payloadRoot, profileDir: profileDir)
|
||||
let seeded = seedSkills(payloadRoot: payloadRoot, profileDir: profileDir)
|
||||
guard case .seeded = seeded else { return seeded }
|
||||
|
||||
// Phase 3 — museion-tools registration (#23 slice 2). nil on either
|
||||
// binary is the test-injection seam; production always has both after a
|
||||
// gate pass (the server IS this app's binary).
|
||||
guard let hermesBinary, let serverBinaryPath else {
|
||||
Logger(subsystem: subsystem, category: "provisioning")
|
||||
.info("museion-tools registration skipped: engine or server binary missing")
|
||||
return seeded
|
||||
}
|
||||
return registerTools(seeded, hermesBinary: hermesBinary, serverBinaryPath: serverBinaryPath, timeout: timeout)
|
||||
}
|
||||
|
||||
/// The bundled payload ships as a plain Resources directory (#46 map decision).
|
||||
@@ -129,6 +147,41 @@ nonisolated enum ProfileProvisioner {
|
||||
return .seeded(copied: copied, present: present)
|
||||
}
|
||||
|
||||
/// #23 slice 2: register museion-tools into the profile exactly once, via
|
||||
/// the hermes CLI only — the provisioner never writes mcp_servers YAML
|
||||
/// itself (#44). `mcp list` first: a re-add would prompt "Overwrite? [y/N]"
|
||||
/// interactively; the skip avoids that branch. ponytail: a stale command
|
||||
/// path after the app moves is refreshed manually via
|
||||
/// `hermes -p museion mcp remove museion-tools`.
|
||||
private static func registerTools(
|
||||
_ seeded: Outcome,
|
||||
hermesBinary: String,
|
||||
serverBinaryPath: String,
|
||||
timeout: TimeInterval,
|
||||
) -> Outcome {
|
||||
let list = EngineProbe.execute([hermesBinary, "-p", "museion", "mcp", "list"], timeout: timeout)
|
||||
if list.stdout.contains("museion-tools") {
|
||||
return seeded
|
||||
}
|
||||
let add = EngineProbe.execute(
|
||||
[
|
||||
hermesBinary, "-p", "museion", "mcp", "add", "museion-tools",
|
||||
"--command", serverBinaryPath, "--args", "--serve-mcp",
|
||||
],
|
||||
timeout: timeout,
|
||||
stdin: String(repeating: "y\n", count: 4), // answers "Enable all tools? [Y/n]" — and survives
|
||||
// profile-startup stdin consumers (observed live: a seeded profile burned
|
||||
// one line before the prompt; a single y cancelled the save)
|
||||
)
|
||||
// Verified wire contract: exit 0 + "Saved 'museion-tools'" on stdout.
|
||||
guard add.exitCode == 0, add.stdout.contains("Saved 'museion-tools'") else {
|
||||
return logFailure(.failed(phase: .register, excerpt: excerpt(add)))
|
||||
}
|
||||
Logger(subsystem: subsystem, category: "provisioning")
|
||||
.info("registered museion-tools via hermes CLI (command: \(serverBinaryPath, privacy: .public))")
|
||||
return seeded
|
||||
}
|
||||
|
||||
/// Sweep `.name-UUID` temp dirs left by an interrupted copy+rename; the next
|
||||
/// pass re-copies the skill, but the orphan would linger forever otherwise.
|
||||
private static func sweepOrphanedTemps(_ skillsDir: String) {
|
||||
|
||||
Reference in new issue
Block a user