feat(mentor): research & library-light (S8) (#29)
CI / ci (push) Canceled after 0s
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:
1 parent
9895614b7e
commit
b02d36bb5d
22 files changed
+977
-33
No files matched your search
@@ -622,3 +622,58 @@ nonisolated extension PostStore {
|
||||
return rank(current) >= rank(completed) ? current : completed
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Research notes (#29)
|
||||
|
||||
/// #29 (S8.2): the keep write — the writer's explicit act. One plain
|
||||
/// markdown Research Note with provenance per keep, landed in
|
||||
/// `<piece>/research/`; the candidates themselves wait in their session
|
||||
/// and are never persisted by the tool rail (CONTEXT.md). Same-file
|
||||
/// extension like the pass substrate: the enum's private members stay
|
||||
/// reachable at file scope.
|
||||
nonisolated extension PostStore {
|
||||
/// Write ONE kept research note. `piecePath` is the piece folder or its
|
||||
/// post.md — resolved through the ONE id→folder resolver so the write
|
||||
/// anchors to THIS Home (a garbage path fails the id lookup honestly).
|
||||
/// Returns the landed file NAME inside `<piece>/research/`.
|
||||
/// `quote`/`note` arrive as "" when the candidate carried none; empty
|
||||
/// sections are omitted. A vanished piece throws (a keep never
|
||||
/// resurrects, #18's rule).
|
||||
// swiftlint:disable:next function_parameter_count
|
||||
static func writeResearchNote(
|
||||
piecePath: String, title: String, url: String, quote: String, note: String, home: URL,
|
||||
) throws -> String {
|
||||
let given = URL(fileURLWithPath: piecePath)
|
||||
let pieceDir = given.lastPathComponent == "post.md" ? given.deletingLastPathComponent() : given
|
||||
guard let dir = folder(of: pieceDir.lastPathComponent, home: home) else {
|
||||
throw FixCardStore.CardError(message: "piece not found: \(piecePath)")
|
||||
}
|
||||
let research = dir.appendingPathComponent("research", isDirectory: true)
|
||||
// Security (promote's posture): a pre-planted symlinked research/
|
||||
// must not turn the keep into a write-outside-Home primitive —
|
||||
// refuse before any write.
|
||||
let values = try? research.resourceValues(forKeys: [.isSymbolicLinkKey])
|
||||
if values?.isSymbolicLink == true {
|
||||
throw FixCardStore.CardError(message: "research path is a symlink: \(research.path)")
|
||||
}
|
||||
try FileManager.default.createDirectory(at: research, withIntermediateDirectories: true)
|
||||
let day = FixCardStore.formatted(Date(), "yyyyMMdd")
|
||||
/// Flat single-line structural fields (Learning-file precedent): a
|
||||
/// newline in a hostile title/url must not break the heading or the
|
||||
/// frontmatter shape. Note/quote stay verbatim — they are content.
|
||||
func flat(_ value: String) -> String {
|
||||
value.components(separatedBy: .newlines).joined(separator: " ")
|
||||
}
|
||||
var body = "# \(flat(title))"
|
||||
if !note.isEmpty {
|
||||
body += "\n\n\(note)"
|
||||
}
|
||||
if !quote.isEmpty {
|
||||
body += "\n\n> \(quote)"
|
||||
}
|
||||
let markdown = "---\nsource: \(flat(url))\nkept: \(day)\n---\n\n\(body)\n"
|
||||
let name = FixCardStore.uniqueFile(research, base: "\(day)-\(slug(from: title))", ext: "md")
|
||||
try markdown.write(to: research.appendingPathComponent(name), atomically: true, encoding: .utf8)
|
||||
return name
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user