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

@@ -0,0 +1,68 @@
# Type the transcript rail — speaker and notice kind as data, one shared tool-payload decoder
> **Date:** 2026-11-09
> **Type:** issue
> **Reference:** git.babylondreams.de/AlexKucera/museion#177
## Goal
Implement issue #177 (mentor line, step 1 of 3 from the 2026-11-09 architecture review): SessionRow's text rows carry speaker (agent/user/system) and notice kind (refused/interrupted/connectionLost/kickoff/failed/plain) as typed data instead of `"Mentor: "`/`"You: "` display prefixes; Fix Card and Research Note tool payloads decode through ONE shared decoder consumed by the museion-tools MCP server and the session model alike; the replayed pass kick-off is sniffed exactly once at the append seam; the transcript view, writing-session filter, and New Post prefill become pure consumers of typed rows; rendering identical; the self-owed debt comment in the session model dies.
## What Was Done
- **Slice 1 — one decoder** (subagent): new `Museion/ToolPayloads.swift` — the lenient transcript-rail decoders moved verbatim from MentorSessionModel's private `FixCard.init?(rawInput:)` + `ResearchCandidate.batch` (both shapes kept: nested card-rail first, flat #14-era fake fallback; both diagnostic spellings; anchor string-or-`{quote}`), plus strict `submitFixCards`/`submitResearchNotes` entries replacing MCPServer's Codable arg structs (`SubmitArgs`/`ResearchNotesArgs`/`ResearchNoteArgs` deleted; every violation throws a short named `CardError`, never a raw `DecodingError` dump). `FixCardStore.Input` dropped `Decodable` (memberwise init stays — DeslopLint + tests construct it); `FixCardStore.decoder` stays (StoredFixCard disk decode, query_learnings). `appendToolCall` rerouted through ToolPayloads (same routing order: notes-array gate → card → raw row).
- **Slice 2 — typed rail** (subagent): `SessionRow.Content.text(String, Speaker, NoticeKind)` with nonisolated nested `Speaker`/`NoticeKind` enums (SessionEntry rule; Content gained Equatable for off-actor pins). All 21 append sites typed per the pinned table (refused ×9, failed ×4 — including "Resume failed" for render parity, plain system rows, user labels unprefixed, pass labels `.system`/`.plain`). The two wire-only classifications sniffed ONCE at the append seam: `agentSpeakerNotice` ("Operation interrupted:" → system/interrupted, shared by live flush + replayed chunk) and `replayedUserContent`/`isPassKickoff` ("Pass Pass " → system/kickoff, moved from the view). `turnCore` takes one typed `labelContent` param. `draftCandidateText` pure over `.text(body, .agent, .plain)`; the ponytail debt comment + prefix-exclusion logic deleted.
- **View seam**: `speaker(of:)`, `Speaker`, `isPassKickoff`, `statusDisplayText`, `isWarningStatus` deleted from SessionTranscriptView; rowView switches on typed data; warning = notice ∈ {interrupted, connectionLost, failed}; kick-off collapse = `kickoffDisplayText` (first line + "Pass Pass "→"Pass "); `warningParts` unprefixed; `isKickoffPill` keys on `.kickoff`; the 8pt-air rule preserved.
- **Tests**: constructors/extractions updated across ACPClientTests, SessionLifecycleTests, PassRunTests, SessionScopeTests, ResearchCandidateTests; new `ToolPayloadsTests` (strict envelope + exact CardError messages + decode facts) and `TranscriptRailTests` (type facts through the fake ACP, prefix-free invariant, append-seam classifiers).
- **Implement-close review** (2 parallel reviewers): four findings fixed — ACPClientTests type-body ceiling (pins split to TranscriptRailTests), strict research-notes envelope refusals pinned, "Pass Pass " literal deduped, decoder shape pins consolidated into ToolPayloadsTests, scenario comment corrected.
- **Finish-audit** (3 parallel reviewers: ponytail/security/general): 5 LOW findings → dead `ResearchNote` struct cut (`submitResearchNotes` returns the validated count), dead kickoff guard cut, strict-boundary type parity restored (`quote`/`note` route through `stringField` — present-but-wrong-type throws), wrong-typed-values pin added, flat-shape lenient pin added. Flip-verified: guard off → pin fails (8 executed, 1 failed); restored → green.
- **DOX pass**: #177 contract facts layered into the (concurrently restructured — see Gotchas) Museion/AGENTS.md (MCPServer, ToolPayloads, MentorSessionModel bullets) and MuseionTests/AGENTS.md (suite map rows). GitNexus re-indexed.
## Decisions & Rationale
| Decision | Rationale |
|----------|-----------|
| Render-faithful typing: `(refused the prompt)` and `connection lost` rows typed `(.agent, .refused)`/`(.agent, .connectionLost)` — agent serif prose, NOT status pills | The ticket's AC says "The UI renders identically"; the agent-prose render is pinned by the old classifier test. The notices exist so pure consumers (draft extraction) exclude by data. Per-site type flip if the owner ever wants the status voice. |
| Lenient + strict as two entry points in ONE file, shape facts pinned in ONE suite | The strictness split is the trust boundary's requirement (ticket: lenient decoder "consumed by both"). The deeper single-parser merge (shared field readers for a 6-field overlap) rejected — indirection for ~6 saved lines; the drift risk the ticket named is killed by the single home + single pin suite. |
| Strict entry: empty cards/notes arrays throw; camelCase `diagnosticQuestion` alias rejected | Empty arrays were silent no-ops (an empty submit used to mkdir an empty `cards/` dir); the declared schema is snake_case-only. Wire-visible, owner-sanctioned. |
| Kick-off sniff at the replay append seam only (not in sendPrompt) | The live label row knows its provenance (`.system, .plain`); only the REPLAYED user turn needs sniffing. Accepted drift: a user literally typing a "Pass Pass …" prompt renders capsule live, pill on replay — pathological, and the new behavior is more correct. |
| `draftCandidateText` excludes non-`.plain` notices (an interrupted row no longer prefills) | Notices aren't draft prose; falls back to the last real reply. Improvement, reported. |
| Test file splits (ToolPayloadsTests, TranscriptRailTests) | The repo's file-length/type-body ceiling protocol (MCPToolsPromoteTests precedent); helpers stay internal in the founding files. |
## Gotchas & Fixes
| Problem | Root Cause | Fix |
|---------|------------|-----|
| Both AGENTS.md files (later also root AGENTS.md) showed modified though every child was forbidden from touching them | A CONCURRENT foreign session restructured/compressed the AGENTS.md tree (15:25–15:36, not from this session's agents — verified via delegation transcripts, read-only) | Left the foreign restructure untouched; #177 doc facts layered on top; the three AGENTS.md files stay UNCOMMITTED (not this session's work to commit) |
| Delegation gateway flagged a "failed file edit" on MentorSessionModel | Transient patch retries ("Failed to read file" — read race), superseded by successful retries before the green build | Verified against the live transcript (last patch ok, then build/test green) and the tree state — no gap |
| `grep -cE` printing `0` exits nonzero, breaking a `&&` chain — the "final" suite never ran and a stale flip-run xcresult was read as final | `grep -c` exit semantics in chains (the finish-audit skill's own documented pitfall) | Re-ran the suite as its own command; authoritative 653/653 on the final bytes |
| Slice-1 harness runs died silently mid-build | The child harness's 420 s foreground cap killed long builds under parallel load | Child switched to `build-for-testing` + `test-without-building`; two initial failures (EditorSession debounce, UI automation) were load flakes — verified green on the definitive idle run |
## Files Changed
| File | Change Summary |
|------|---------------|
| `Museion/ToolPayloads.swift` | NEW — THE tool-payload decoder (lenient rail + strict MCP entries) |
| `Museion/MentorSessionModel.swift` | SessionRow typed text case + enums; 21 append sites typed; append-seam sniffs; draftCandidateText pure; debt comment gone; decoders moved out |
| `Museion/SessionTranscriptView.swift` | Render seam switches on typed data; five prefix classifiers deleted; kickoffDisplayText |
| `Museion/MCPServer.swift` | Submit tools route through ToolPayloads; Codable arg structs deleted |
| `Museion/FixCardStore.swift` | Input drops Decodable |
| `MuseionTests/ToolPayloadsTests.swift` | NEW — every wire-shape fact, strict + lenient |
| `MuseionTests/TranscriptRailTests.swift` | NEW — type facts, prefix-free invariant, append-seam classifiers |
| `MuseionTests/ACPClientTests.swift` | Seam pins updated to typed rows; #177 pins moved out |
| `MuseionTests/SessionLifecycleTests.swift` | Draft-candidate + extraction helpers on typed rows |
| `MuseionTests/PassRunTests.swift`, `MuseionTests/SessionScopeTests.swift` | Extraction helper pattern updates |
| `MuseionTests/ResearchCandidateTests.swift` | Pure shape pin moved to ToolPayloadsTests; behavior pins stay |
| `MuseionTests/MCPToolsTests.swift` | Direct-Codable pins rewritten onto ToolPayloads |
| `Museion/AGENTS.md`, `MuseionTests/AGENTS.md` | #177 contract facts (layered onto the foreign restructure; uncommitted) |
## Open Items & Next Steps
- [ ] The three AGENTS.md files stay uncommitted (foreign session's compression + this session's layered #177 facts) — commit with that session's work
- [ ] Deferred: `query_learnings` still decodes via `FixCardStore.decoder` + Codable — fold into ToolPayloads when that tool is next touched
- [ ] Deferred: live-vs-replay kickoff consistency for literal "Pass Pass …" user prompts — accepted as designed; one-line `.kickoff` typing in `sendPrompt` if it ever matters
- [ ] #178 (extract the engine host) is blocked by this ticket — ready once #177 lands
---
*Log written by write-log skill. Verification cited: `build-for-testing` SUCCEEDED, 653/653 tests passed (xcresult), swiftformat 0/130, swiftlint zero new vs HEAD, on the exact committed bytes.*
+1
View File
@@ -5,6 +5,7 @@ Complete history of session logs in this directory, newest first. One-line summa
<!-- write-log: full-index -->
| Date | Type | File | Summary |
|------|------|------|---------|
| 2026-11-09 | issue | [20261109-issue177-type-transcript-rail-shared-tool-payload-decoder_log.md](20261109-issue177-type-transcript-rail-shared-tool-payload-decoder_log.md) | SessionRow text rows typed (speaker+notice), kick-off sniffed at append seam, one ToolPayloads decoder both rails read |
| 2026-11-09 | issue | [20261109-issue183-shrink-agentsmd_log.md](20261109-issue183-shrink-agentsmd_log.md) | AGENTS.md rails shrunk 206 KB → 36 KB — contracts and rulings kept, per-issue diaries cut; serif payload untouched (#183) |
| 2026-11-05 | issue | [20261105-issue175-nous-portal-provider_log.md](20261105-issue175-nous-portal-provider_log.md) | Fourth provider `nous`: plain chat-completions probe, session-key fallback gated to the official endpoint, keyless readiness (#175) |
| 2026-11-05 | issue | [20261105-issue171-default-home-icloud-pin-once-legacy-guard_log.md](20261105-issue171-default-home-icloud-pin-once-legacy-guard_log.md) | Fresh installs pin `<CloudDocs>/Museion` with a legacy-dir guard; injectable probe seam, 9 tests (#171) |