feat(mentor): research & library-light (S8) (#29)
CI / ci (push) Canceled after 0s

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
This commit is contained in:
AlexKucera committed 2026-10-22 14:06:16 +02:00
1 parent 9895614b7e
commit b02d36bb5d
22 files changed
+977 -33

No files matched your search

+136 -3
View File
@@ -8,6 +8,16 @@
// project (#60), Trash delete, save-time normalization.
// #108: project moves, archive/restore, project unarchive + creation.
//
// ## Scenario: candidate rail and the keep write
// From #29 (S8.1/S8.2)
// Given a piece in the library and the mentor researching mid-pass
// When the engine delivers findings as submit_research_notes tool calls
// Then well-formed candidates are accepted with a received count and
// nothing is written anywhere; malformed ones answer a tool error
// And the pass prompt names that rail
// And when the writer keeps one, one plain markdown note with provenance
// lands in the piece's research/ — nothing else auto-saves.
//
import Foundation
@testable import Museion
@@ -669,15 +679,19 @@ private func readPiece(_ home: URL, root: String, project: String, _ id: String)
}
}
@Test func `stub carries pass name piece path and fix-card reminder`() {
@Test func `stub carries pass name piece path research rail and fix-card reminder`() {
let pieceURL = URL(fileURLWithPath: "/vault/projects/essays/essay/post.md")
let stub = PassContext.stub(kind: .pass1, pieceURL: pieceURL, hasResearch: false)
#expect(stub.contains("Pass 1 — paragraph level and up."))
#expect(stub.contains("Piece: /vault/projects/essays/essay/post.md"))
#expect(!stub.contains("Research notes:"))
let closing = "Critique the piece for this pass. Deliver the verdict in your reply — "
+ "findings travel as fix-card tool calls (submit_fix_cards). Do not write to the piece folder."
// #29: the typed research rail is named in the closing block — the
// engine delivers findings, it never writes candidates itself.
let closing = "Critique the piece for this pass. Fact-check claims where needed — research findings "
+ "travel as candidate source-note tool calls (submit_research_notes), never written to disk. "
+ "Deliver the verdict in your reply — findings travel as fix-card tool calls (submit_fix_cards). "
+ "Do not write to the piece folder."
#expect(stub.contains(closing))
#expect(PassContext.stub(kind: .pass2, pieceURL: pieceURL, hasResearch: false)
.contains("Pass 2 — sentence level and below."))
@@ -703,3 +717,122 @@ private func readPiece(_ home: URL, root: String, project: String, _ id: String)
}
}
}
// MARK: Research notes (#29)
/// The keep writes "today" — computed at test time like promote's day
/// stamp (a midnight rollover mid-suite is tolerated).
private func researchDay() -> String {
FixCardStore.formatted(Date(), "yyyyMMdd")
}
@Test func `writeResearchNote lands the pinned markdown shape in research`() throws {
let home = try storeHome()
let post = try PostStore.writeNew(body: "# Kept\n", home: home)
let name = try PostStore.writeResearchNote(
piecePath: home.appendingPathComponent("projects/posts/\(post.id)", isDirectory: true).path,
title: "The Long Now",
url: "https://example.org/long-now",
quote: "pace layers",
note: "Supports the slowness claim.",
home: home,
)
let day = researchDay()
#expect(name == "\(day)-the-long-now.md")
let markdown = try String(
contentsOf: home.appendingPathComponent("projects/posts/\(post.id)/research/\(name)"),
encoding: .utf8,
)
let expected = "---\nsource: https://example.org/long-now\nkept: \(day)\n---\n\n"
+ "# The Long Now\n\nSupports the slowness claim.\n\n> pace layers\n"
#expect(markdown == expected)
}
@Test func `writeResearchNote omits absent note and quote sections`() throws {
let home = try storeHome()
let post = try PostStore.writeNew(body: "# Bare\n", home: home)
let pieceDir = home.appendingPathComponent("projects/posts/\(post.id)", isDirectory: true)
// Both absent: frontmatter + heading, nothing else.
let name = try PostStore.writeResearchNote(
piecePath: pieceDir.path, title: "Only A Link", url: "https://example.org/one",
quote: "", note: "", home: home,
)
let bare = try String(contentsOf: pieceDir.appendingPathComponent("research/\(name)"), encoding: .utf8)
#expect(bare == "---\nsource: https://example.org/one\nkept: \(researchDay())\n---\n\n# Only A Link\n")
// Quote without note: the note section goes, the quote stays.
let quoted = try PostStore.writeResearchNote(
piecePath: pieceDir.path, title: "Quoted", url: "https://example.org/two",
quote: "citation needed", note: "", home: home,
)
let text = try String(contentsOf: pieceDir.appendingPathComponent("research/\(quoted)"), encoding: .utf8)
#expect(text.hasSuffix("\n\n# Quoted\n\n> citation needed\n"))
}
@Test func `writeResearchNote collision takes -2`() throws {
let home = try storeHome()
let post = try PostStore.writeNew(body: "# Twice\n", home: home)
let piecePath = home.appendingPathComponent("projects/posts/\(post.id)").path
let first = try PostStore.writeResearchNote(
piecePath: piecePath, title: "Same Source", url: "https://example.org/same",
quote: "", note: "", home: home,
)
let second = try PostStore.writeResearchNote(
piecePath: piecePath, title: "Same Source", url: "https://example.org/same",
quote: "", note: "", home: home,
)
let day = researchDay()
#expect(first == "\(day)-same-source.md")
#expect(second == "\(day)-same-source-2.md")
}
@Test func `writeResearchNote accepts the post.md file form`() throws {
let home = try storeHome()
let post = try PostStore.writeNew(body: "# File Form\n", home: home)
let name = try PostStore.writeResearchNote(
piecePath: home.appendingPathComponent("projects/posts/\(post.id)/post.md").path,
title: "Via File", url: "https://example.org/file",
quote: "", note: "", home: home,
)
#expect(FileManager.default.fileExists(
atPath: home.appendingPathComponent("projects/posts/\(post.id)/research/\(name)").path,
))
}
@Test func `writeResearchNote on vanished piece throws`() throws {
let home = try storeHome()
#expect(throws: FixCardStore.CardError(message: "piece not found: /nowhere/post.md")) {
try PostStore.writeResearchNote(
piecePath: "/nowhere/post.md", title: "Ghost", url: "https://example.org",
quote: "", note: "", home: home,
)
}
}
@Test func `writeResearchNote refuses a symlinked research dir`() throws {
let home = try storeHome()
let post = try PostStore.writeNew(body: "# Guarded\n", home: home)
let pieceDir = home.appendingPathComponent("projects/posts/\(post.id)", isDirectory: true)
let target = home.appendingPathComponent("elsewhere", isDirectory: true)
try FileManager.default.createDirectory(at: target, withIntermediateDirectories: true)
try FileManager.default.createSymbolicLink(
at: pieceDir.appendingPathComponent("research"),
withDestinationURL: target,
)
let planted = pieceDir.appendingPathComponent("research").path
#expect(throws: FixCardStore.CardError(message: "research path is a symlink: \(planted)")) {
try PostStore.writeResearchNote(
piecePath: pieceDir.path, title: "Planted", url: "https://example.org",
quote: "", note: "", home: home,
)
}
#expect(try FileManager.default.contentsOfDirectory(atPath: target.path).isEmpty)
}