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
@@ -12,9 +12,10 @@ import Foundation
|
||||
import Testing
|
||||
|
||||
/// Throwaway Home + model (EditorSessionTests convention: direct @MainActor
|
||||
/// instantiation, no app gate).
|
||||
/// instantiation, no app gate). Internal — PassRunTests builds its rig on
|
||||
/// it (review: a hand-copy drifted).
|
||||
@MainActor
|
||||
private func makeModelHome() throws -> (PostsModel, URL) {
|
||||
func makeModelHome() throws -> (PostsModel, URL) {
|
||||
let home = FileManager.default.temporaryDirectory
|
||||
.appendingPathComponent("postsmodel-\(UUID().uuidString)", isDirectory: true)
|
||||
try FileManager.default.createDirectory(at: home, withIntermediateDirectories: true)
|
||||
@@ -468,3 +469,75 @@ private func writeMixedOutline(home: URL) throws -> Post {
|
||||
#expect(onDisk.contains("type: post"))
|
||||
#expect(onDisk.contains("A paragraph between bullets.")) // verbatim kept everything
|
||||
}
|
||||
|
||||
// #23 (M2, slice 3): the open piece's stored fix cards surface live.
|
||||
// The card Input helper is MCPToolsTests' internal card() — one shape,
|
||||
// no hand-copy (review).
|
||||
|
||||
/// refreshCards hops off MainActor (scan runs in Task.detached) — poll for
|
||||
/// the hop-back instead of asserting synchronously.
|
||||
@MainActor
|
||||
private func waitForCards(_ model: PostsModel, _ count: Int) async throws {
|
||||
for _ in 0 ..< 250 where model.openPieceCards.count < count {
|
||||
try await Task.sleep(nanoseconds: 20_000_000)
|
||||
}
|
||||
}
|
||||
|
||||
@Test @MainActor func `opening a piece surfaces its stored fix cards`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Carded\n\nThe anchor sentence.\n", home: home)
|
||||
let folder = try #require(PostStore.folder(of: post.id, home: home))
|
||||
try FixCardStore.submit(piecePath: folder.path, cards: [card(pattern: "Hedging", quote: "The anchor sentence.")])
|
||||
|
||||
model.select(post.id, home: home)
|
||||
try await waitForCards(model, 1)
|
||||
|
||||
#expect(model.openPieceCards.map(\.pattern) == ["Hedging"])
|
||||
#expect(model.openPieceCards.first?.anchorStatus == .valid)
|
||||
}
|
||||
|
||||
@Test @MainActor func `a card landing after open joins the list without reselect`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Carded\n\nThe anchor sentence.\n", home: home)
|
||||
let folder = try #require(PostStore.folder(of: post.id, home: home))
|
||||
try FixCardStore.submit(piecePath: folder.path, cards: [card(pattern: "Hedging", quote: "The anchor sentence.")])
|
||||
model.select(post.id, home: home)
|
||||
try await waitForCards(model, 1)
|
||||
|
||||
// An MCP client submits another card while the piece stays open —
|
||||
// the piece-roots watcher fires on <piece>/cards/ and the rescan
|
||||
// tail refreshes (poll-loop convention).
|
||||
try FixCardStore.submit(piecePath: folder.path, cards: [card(pattern: "Telling", quote: "The anchor sentence.")])
|
||||
|
||||
for _ in 0 ..< 250 where model.openPieceCards.count < 2 {
|
||||
try await Task.sleep(nanoseconds: 20_000_000)
|
||||
}
|
||||
#expect(model.openPieceCards.count == 2) // grew live, no reselect
|
||||
}
|
||||
|
||||
@Test @MainActor func `closing the piece clears the card list`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Carded\n\nThe anchor sentence.\n", home: home)
|
||||
let folder = try #require(PostStore.folder(of: post.id, home: home))
|
||||
try FixCardStore.submit(piecePath: folder.path, cards: [card(pattern: "Hedging", quote: "The anchor sentence.")])
|
||||
model.select(post.id, home: home)
|
||||
try await waitForCards(model, 1)
|
||||
|
||||
model.newPost()
|
||||
|
||||
#expect(model.openPieceCards == []) // the nil-session rule
|
||||
}
|
||||
|
||||
@Test @MainActor func `an archived piece opened shows its cards too`() async throws {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Filed\n\nThe anchor sentence.\n", home: home)
|
||||
try PostStore.archive(post, home: home)
|
||||
let folder = try #require(PostStore.folder(of: post.id, home: home))
|
||||
#expect(folder.path.contains("/archive/"))
|
||||
try FixCardStore.submit(piecePath: folder.path, cards: [card(pattern: "Hedging", quote: "The anchor sentence.")])
|
||||
|
||||
model.select(post.id, home: home) // opened from the Archive pane
|
||||
try await waitForCards(model, 1)
|
||||
|
||||
#expect(model.openPieceCards.count == 1)
|
||||
}
|
||||
Reference in new issue
Block a user