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
@@ -23,6 +23,10 @@ struct SessionRow: Identifiable {
|
||||
/// never mixed into the critique text.
|
||||
case thought(String)
|
||||
case fixCard(FixCard)
|
||||
/// #29 (S8.2): a candidate research note from the session's research
|
||||
/// tool call — lives in THIS session until the writer keeps or
|
||||
/// rejects it (engine-owned cargo; replay re-materializes it).
|
||||
case researchNote(ResearchCandidate)
|
||||
case raw(kind: String, json: String)
|
||||
}
|
||||
|
||||
@@ -43,6 +47,21 @@ struct FixCard {
|
||||
var status: String
|
||||
}
|
||||
|
||||
/// #29 (S8.2) one candidate research note: a source finding the mentor
|
||||
/// surfaced mid-pass. Candidates wait in their SESSION until kept — nothing
|
||||
/// auto-saves (CONTEXT.md's Research Note: kept ones land in the piece's
|
||||
/// research/ via the store rail; rejected ones vanish). Nonisolated: a wire
|
||||
/// value parsed from rawInput and asserted from tests (SessionEntry rule).
|
||||
nonisolated struct ResearchCandidate: Equatable {
|
||||
enum Disposition: Equatable { case pending; case kept(fileName: String); case rejected }
|
||||
var piecePath: String
|
||||
var title: String
|
||||
var url: String
|
||||
var quote: String
|
||||
var note: String
|
||||
var disposition: Disposition = .pending
|
||||
}
|
||||
|
||||
/// How a turn ended — the pass orchestrator's seam (#24): a pass advances
|
||||
/// Pass State only when the engine's turn completed, never on cancel/crash.
|
||||
enum TurnOutcome: Equatable {
|
||||
@@ -726,6 +745,22 @@ extension MentorSessionModel {
|
||||
private func appendToolCall(_ update: [String: JSONValue], to sid: String) {
|
||||
let title = update["title"]?.stringValue ?? "tool call"
|
||||
let rawInput = update["rawInput"]
|
||||
// #29: the research rail routes on PAYLOAD SHAPE, not the title (a
|
||||
// tool_call's title is display text, not guaranteed to be the raw
|
||||
// tool name) and before the fix-card parse — a research payload with
|
||||
// stray pattern/problem keys must not vanish into a card row. The
|
||||
// notes-array presence gate keeps fix-card payloads out of the
|
||||
// research parser; a batch that fails to parse falls through.
|
||||
var candidates: [ResearchCandidate] = []
|
||||
if case .array? = rawInput?.objectValue?["notes"] {
|
||||
candidates = ResearchCandidate.batch(rawInput)
|
||||
}
|
||||
if !candidates.isEmpty {
|
||||
for candidate in candidates {
|
||||
appendRow(.researchNote(candidate), to: sid)
|
||||
}
|
||||
return
|
||||
}
|
||||
if let card = FixCard(rawInput: rawInput) {
|
||||
appendRow(.fixCard(card), to: sid)
|
||||
return
|
||||
@@ -767,3 +802,54 @@ private extension FixCard {
|
||||
status = card["status"]?.stringValue ?? "proposed"
|
||||
}
|
||||
}
|
||||
|
||||
/// Flip a research candidate's disposition (#29 S8.3): replaces the
|
||||
/// row's content in the ACTIVE session's transcript (rows are structs;
|
||||
/// the store is keyed by wire sessionId). No-op on an unknown row id.
|
||||
/// File-scope extension — type_body_length posture (PostsModel's guards
|
||||
/// precedent); the API is unchanged for callers.
|
||||
extension MentorSessionModel {
|
||||
func setResearchDisposition(rowID: UUID, _ disposition: ResearchCandidate.Disposition) {
|
||||
guard let sid = activeEntry?.sessionId, var rows = transcripts[sid]?.rows,
|
||||
let index = rows.firstIndex(where: { $0.id == rowID }),
|
||||
case let .researchNote(candidate) = rows[index].content
|
||||
else { return }
|
||||
var updated = candidate
|
||||
updated.disposition = disposition
|
||||
rows[index].content = .researchNote(updated)
|
||||
transcripts[sid]?.rows = rows
|
||||
}
|
||||
}
|
||||
|
||||
/// Research-candidate batch parsing (#29): the submit_research_notes wire
|
||||
/// shape {piece_path, notes: [{title, url, quote?, note?}]} — one candidate
|
||||
/// PER note. Lenient: a missing piece_path, an empty/absent notes array, or
|
||||
/// any note missing a NON-BLANK title/url yields NO candidates
|
||||
/// (appendToolCall falls through to the raw row) — the same trim rule the
|
||||
/// MCP wire enforces, so both boundaries agree (audit: a whitespace title
|
||||
/// used to render an invisible-titled card and keep as `-untitled.md`).
|
||||
/// Absent quote/note become "".
|
||||
nonisolated extension ResearchCandidate {
|
||||
static func batch(_ rawInput: JSONValue?) -> [ResearchCandidate] {
|
||||
guard let object = rawInput?.objectValue,
|
||||
let piecePath = object["piece_path"]?.stringValue,
|
||||
case let .array(notes)? = object["notes"],
|
||||
!notes.isEmpty
|
||||
else { return [] }
|
||||
var candidates: [ResearchCandidate] = []
|
||||
for note in notes {
|
||||
guard let fields = note.objectValue,
|
||||
let title = fields["title"]?.stringValue, !title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty,
|
||||
let url = fields["url"]?.stringValue, !url.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
|
||||
else { return [] }
|
||||
candidates.append(ResearchCandidate(
|
||||
piecePath: piecePath,
|
||||
title: title,
|
||||
url: url,
|
||||
quote: fields["quote"]?.stringValue ?? "",
|
||||
note: fields["note"]?.stringValue ?? "",
|
||||
))
|
||||
}
|
||||
return candidates
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user