Files
museion/docs/devlog/20261022-issue29-research-library-light_log.md
T
AlexKucera b02d36bb5d
CI / ci (push) Canceled after 0s
feat(mentor): research & library-light (S8) (#29)
The mentor researches mid-pass and its findings arrive as candidate
source-notes with provenance inside their Session. A third museion-
tools tool, submit_research_notes, is the typed rail (ADR-0006
posture): decode-validate only, reply {"received": N}, write NOTHING
— the session is the holding area, and keeping is the writer's act.

Candidates ride the transcript as first-class rows (researchNote):
parsed from the tool call's rawInput by payload shape — the notes
array routes before the fix-card parse, titles are display text —
one row per note, all-or-nothing per batch, the wire's whitespace
rule mirrored so both boundaries agree. Resume re-materializes them
for free: replays re-run the same parse; dispositions reset honestly
(they were never persisted — engine-owned cargo, ADR-0007).

The writer curates in place (full cards in the shared transcript, no
palette — a handful curates where it lands): Keep opens the
ask-before sheet (G9; PromoteAskSheet posture — inline refusal,
buttons kept) and ONE confirm lands one plain markdown note with
provenance into the piece's research/ via writeResearchNote — the
one folder(of:) id lookup anchors it inside this Home, a symlinked
research/ refuses, collision -2; Reject vanishes, recording nothing.
The pass stub names the rail and forbids the engine writing
candidates itself; kept notes flip hasResearch, so every later pass
sees the research/ path (S8.3 at v1 depth).

Finish-audit (three reviewers) drove the whitespace-parity and
shape-routing fixes, the ResearchNoteContent dedup, and a poll-loop
fix for the debounce rig's sidecar half that the larger suite's load
had pushed past its fixed sleep — full suite green (373 tests).

Closes #29
2026-10-22 14:06:16 +02:00

11 KiB
Raw Blame History

#29 M5: Research & library-light (S8)

Date: 2026-10-22 Type: issue Reference: #29 M5: Research & library-light (S8) (PRD S8.1–S8.3, G9 trust defaults)

Goal

The mentor researches mid-pass and its findings arrive as candidate source-notes with provenance inside their Session. The writer curates: Keep writes plain markdown into the Post's research/; Reject vanishes; nothing auto-saves. Candidates survive session resume (engine-owned cargo, ADR-0007); kept notes feed later passes as context. Both blockers (#24, #28) were closed before work started.

What Was Done

Two parallel subagent slices implemented the feature (both interrupted by infra timeouts near the end; finished in-session), then a three-reviewer finish-audit (ponytail / security / general) drove a second fix batch.

  • The candidates rail (Museion/MCPServer.swift) — third museion-tools tool submit_research_notes, shape {piece_path, notes:[{title, url, quote?, note?}]}. Decode-validate ONLY; replies {"received": N}; writes nothing (S8.2 nothing-auto-saves — the tool is not a storage rail). Schema declares the candidates-only semantics.
  • The pass prompt names the rail (Museion/Pass.swift) — the pinned stub gains one clause: fact-check where needed, findings travel as submit_research_notes candidate tool calls, never written by the engine.
  • The keep write (Museion/PostStore.swift) — writeResearchNote(piecePath:title:url:quote:note:home:): resolves the piece through the ONE folder(of:) id lookup (folder or post.md path form), refuses a symlinked research/ (promote's posture), lands <yyyyMMdd>-<slug(title)>.md via FixCardStore's now-internal uniqueFile, flat single-line frontmatter (source/kept; title/url newline-flattened), empty note/quote sections omitted, atomic. Returns the landed file name.
  • Session cargo (Museion/MentorSessionModel.swift) — ResearchCandidate (piecePath/title/url/quote/note + Disposition pending|kept(fileName)|rejected) rides SessionRow.Content.researchNote. appendToolCall routes on PAYLOAD SHAPE (top-level notes array) BEFORE the fix-card parse — titles are display text, never a routing key. ResearchCandidate.batch parses one candidate per note, all-or-nothing per batch (garbage → raw row), whitespace-only title/url refused (the wire's trim rule mirrored). setResearchDisposition flips the ACTIVE session's row (file-scope extension, type-body posture). Resume re-materializes candidates for free: replays re-run appendToolCall.
  • The curation surface (Museion/SessionTranscriptView.swift, new Museion/ResearchKeepSheet.swift, Museion/MentorPaneView.swift, Museion/SessionsPaneView.swift, Museion/WorkspaceView.swift) — candidates render as full cards in the shared transcript (no palette — a handful curates in place): serif title, mono muted url, selectable note, italic quote; pending offers Keep + Reject (hidden when home is nil — previews); kept/rejected dim 0.45 with meta kept · research/<file> / rejected. Keep = ask-before (G9): ResearchKeepSheet (PromoteAskSheet posture — inline orange refusal, buttons kept) → ONE confirm → writeResearchNote. Reject = no confirm (Dismiss-button voice). Sheet state lives in SessionTranscriptView (pendingKeep, .sheet(item:) — never inside a lazy row); home threads from both panes.
  • Finish-audit fixes — whitespace title/url parity between wire and parser (converged finding); shape-based routing so a research payload with stray pattern/problem keys can't vanish into a card row (converged); ResearchNoteContent extracted (row + sheet share one render); war-story trimmed from MuseionTests/AGENTS.md. Rejected: parser merge (strict wire vs lenient transcript are deliberate different postures), batch cap (the raw-row fallback retains identical bytes — the unbounded transcript IS the adjudicated engine-owned-cargo ceiling). Deferred: piece-level symlink guard in folder(of:) (same ceiling as promote; fixes both when it lifts).
  • Tests — new MuseionTests/ResearchCandidateTests.swift (own file; SessionLifecycleTests crossed its type-body ceiling, MCPToolsPromoteTests precedent): batch matrix (incl. whitespace audit pin), resume re-materialization AC pin (end-to-end over the real client + fake), disposition flip/no-op, writing-filter pin. MuseionTests/ACPClientTests.swift: the fake's loadReplay mode streams a research tool_call (resume pin) and a strayResearchOnPrompt mode carries a stray-keys payload (routing pin). MCPServerWireTests: three tools listed, received-count reply, nothing-on-disk pin, malformed → isError. PostStoreTests: markdown shape, section omission, collision -2, post.md path form, vanished piece, symlinked research/ refusal. Stub-shape pin updated for the research clause.

Decisions & Rationale

Decision Rationale
Candidates travel as a typed tool call that writes NOTHING ADR-0006 posture (never prose to parse) + S8.2: the session is the holding area; the only path to disk is the writer's Keep. The tool's reply is a received count, not storage.
Resume survival comes free from replay Transcripts are engine-owned (ADR-0007); the candidates ARE transcript rows, so session/load re-materializes them with no app-side persistence. Dispositions reset honestly — they were never persisted.
Keep = blocking ask sheet; Reject = no confirm G9 classifies keep-note as ask-before (PromoteAskSheet/ApplyAskSheet house posture); rejection is low-stakes and self-healing (Dismiss-button voice).
Route tool calls by payload shape, not title A tool_call's title is display text, not guaranteed to be the raw tool name; the notes array is the deterministic discriminator, and routing research first keeps stray-key payloads from vanishing into a card row.
Full cards in the transcript instead of a Fix-Cards-style palette Fix cards accumulate dozens and need a work surface; research candidates are a handful mid-pass — curating in place is the smaller UI.
writeResearchNote anchors via folder(of:) id lookup, not path-shape validation The one-resolver rule beats re-implementing resolvePostURL's shape check; a garbage path fails the id lookup honestly and the write can only land inside this Home.
Two parsers stay separate (audit rejection) The MCP decode is strict (a tool error teaches the engine the shape); the transcript parse is deliberately lenient (falls to the raw row, payload stays visible). Merging needs a mode flag that costs more than the duplication; both shapes are test-pinned.

Gotchas & Fixes

Problem Root Cause Fix
Both resume pins timed out (10 s polls, 0 candidates); the subagent chased "parallel load" The fake ACP's research echo line missed the "rawInput" key's closing quote — "rawInput':"$research" emitted invalid JSON, which the client silently dropped (deterministic, load-independent) Fixed the quoting to the fix-card line's exact pattern; lesson pinned in the test file's fake comments
Grep-filtered xcodebuild output lost the verdict line while xcresult showed 372 failed: 1 Background runs pipe through `grep tail`, and concurrent xcodebuild invocations (an orphaned foreground rerun) wrote interleaved result bundles
Full suite failed 1–3 tests per run; the persistent one was debounce flushes after idle and stamps the sidecar The rig's FIRST flush already polled, but its sidecar half slept a fixed 200 ms — under full-suite parallel load (48 more tests from #29) the main actor starved the second debounce past any constant Converted the sidecar wait to the same poll loop (poll readCursor == cursor within the existing deadline — the sidecar lands on flush, so the pin still proves the flush wrote it); full suite went green (373 tests, 0 failures). Remaining single-run rotates in PassRun rigs pass isolated — follow-up issue candidate
Audit additions pushed SessionLifecycleTests and MentorSessionModel over their SwiftLint type-body ceilings The #29 pins (~120 lines) and routing changes landed in already-large bodies Own-file ResearchCandidateTests.swift (MCPToolsPromoteTests precedent) + setResearchDisposition moved to a file-scope extension (PostsModel guards precedent)

Files Changed

File Change Summary
Museion/MCPServer.swift Third tool submit_research_notes — validate-only rail, {"received": N} reply
Museion/Pass.swift Stub gains the research-rail clause
Museion/PostStore.swift writeResearchNote — the keep write into <piece>/research/
Museion/FixCardStore.swift uniqueFile widened internal for reuse
Museion/MentorSessionModel.swift ResearchCandidate + shape-based routing in appendToolCall + setResearchDisposition (file-scope extension)
Museion/SessionTranscriptView.swift home param, candidate cards, Keep/Reject, shared ResearchNoteContent, keep sheet state
Museion/ResearchKeepSheet.swift NEW — the ask-before keep confirm
Museion/MentorPaneView.swift / SessionsPaneView.swift / WorkspaceView.swift home threading to the transcript
MuseionTests/ACPClientTests.swift Fake: research replay payload + strayResearchOnPrompt mode; routing pin test
MuseionTests/ResearchCandidateTests.swift NEW — the four research-candidate pins
MuseionTests/MCPServerWireTests.swift / PostStoreTests.swift Wire pins (received/nothing-written/malformed) + store pins (shape/collision/forms/symlink)
MuseionTests/SessionLifecycleTests.swift Rebalanced below its type-body ceiling (pins moved out)
AGENTS.md / Museion/AGENTS.md / MuseionTests/AGENTS.md DOX pass: the research rail, keep write, candidates, curation surface, test pins

Open Items & Next Steps

  • Engine-side research initiative (when to research, how to use the tool) is the museion-profile/skills lane (#56–#58); the stub now tells passes the rail exists
  • Full-suite parallel-load flakes in PassRun/EditorSession rigs (2–3 rotating settle-window failures per run; all pass isolated) — follow-up issue candidate
  • Piece-level symlink guard in PostStore.folder(of:) if the single-user ceiling ever lifts (fixes promote + research keep together)
  • Kept candidate re-keep after resume creates a -2 duplicate — accepted (engine-owned cargo); revisit only if it bites

Log written by write-log skill