refactor(session): type the transcript rail
CI / ci (push) Canceled after 0s

SessionRow text rows carry (body, speaker, notice) as data — agent/
user/system plus refused/interrupted/connectionLost/kickoff/failed/
plain — typed at every append site; no stored row holds a speaker
prefix (pinned). The two wire-only classifications are sniffed once at
the append seam: a replayed pass kick-off ('Pass Pass N…') and the
engine's 'Operation interrupted:' notice. The transcript view, the
writing-session filter, and the New Post prefill switch on typed data;
rendering is identical (refusal/connection-lost rows stay agent prose
by pinned render).

Fix Card and Research Note payloads decode through one shared
ToolPayloads decoder: lenient for the transcript rail (both the nested
card-rail shape and the flat #14-era fake kept), strict for the
museion-tools MCP trust boundary with named CardErrors. Three
intentional wire tightenings at the strict entry: empty cards/notes
arrays throw instead of no-op succeeding, the camelCase
diagnosticQuestion alias is rejected (schema is snake_case), and
decode failures answer short named errors instead of DecodingError
dumps. quote/note type parity restored (present-but-wrong-type throws).
Every wire-shape fact is pinned in ToolPayloadsTests.

Full suite 653/653, swiftformat/swiftlint clean. Audit flip-verified.

Closes #177
This commit is contained in:
AlexKucera committed 2026-11-09 16:01:53 +01:00
1 parent c2eb9573db
commit d14cb40e73
18 files changed
+912 -358

No files matched your search

+6 -39
View File
@@ -131,10 +131,8 @@ nonisolated enum MCPServer {
]] as [[String: Any]],
])
case "submit_fix_cards":
let args = try FixCardStore.decoder.decode(
SubmitArgs.self, from: JSONSerialization.data(withJSONObject: arguments),
)
let written = try FixCardStore.submit(piecePath: args.piecePath, cards: args.cards)
let (piecePath, cards) = try ToolPayloads.submitFixCards(from: JSONValue(arguments))
let written = try FixCardStore.submit(piecePath: piecePath, cards: cards)
var payload: [String: Any] = [
"cards": written.map {
["file": $0.file, "anchor_status": $0.card.anchorStatus.rawValue]
@@ -142,8 +140,8 @@ nonisolated enum MCPServer {
]
// The ceiling backstop tells the truth on the wire (#25 S3.2):
// cards beyond the kept ranked head were dropped — say how many.
if args.cards.count > written.count {
payload["dropped_over_ceiling"] = args.cards.count - written.count
if cards.count > written.count {
payload["dropped_over_ceiling"] = cards.count - written.count
}
return reply(id: id, result: [
"content": [[
@@ -156,21 +154,11 @@ nonisolated enum MCPServer {
// Findings are engine-owned cargo in their session; the reply
// is a received count, never storage. The ONLY path to disk is
// the writer's keep (PostStore.writeResearchNote).
let args = try FixCardStore.decoder.decode(
ResearchNotesArgs.self, from: JSONSerialization.data(withJSONObject: arguments),
)
for note in args.notes {
guard !note.title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
throw FixCardStore.CardError(message: "note title must not be empty")
}
guard !note.url.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
throw FixCardStore.CardError(message: "note url must not be empty")
}
}
let received = try ToolPayloads.submitResearchNotes(from: JSONValue(arguments))
return reply(id: id, result: [
"content": [[
"type": "text",
"text": jsonString(["received": args.notes.count]) ?? "{}",
"text": jsonString(["received": received]) ?? "{}",
]] as [[String: Any]],
])
default:
@@ -185,27 +173,6 @@ nonisolated enum MCPServer {
var piecePath: String
}
private struct SubmitArgs: Decodable {
var piecePath: String
var cards: [FixCardStore.Input]
}
/// #29 (S8.1): one candidate source-note — quote/note optional on the
/// wire (they arrive as "" at the keep write when absent).
private struct ResearchNoteArgs: Decodable {
var title: String
var url: String
var quote: String?
var note: String?
}
/// #29 (S8.1): the research rail's wire shape — ONE shape, no legacy
/// fallback; a missing field fails decode = the trust boundary.
private struct ResearchNotesArgs: Decodable {
var piecePath: String
var notes: [ResearchNoteArgs]
}
// MARK: - Tools
/// The tools (#23 cards + learnings; #29 the research rail). The submit