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
@@ -34,7 +34,9 @@ import Testing
|
||||
/// chunks); `loadReplay` (#28) adds the lifecycle wire: session/new/load/fork
|
||||
/// all require `mcpServers` (-32602 without, the #44 invariant), session ids
|
||||
/// are minted uniquely (sess-1, sess-2, …), session/load replays
|
||||
/// user+thought+message chunks for ANY minted sess-* id then answers its id
|
||||
/// user+thought+message chunks PLUS one submit_research_notes tool call
|
||||
/// (#29 — candidates re-materialize on resume) for ANY minted sess-* id
|
||||
/// then answers its id
|
||||
/// (a relaunch default-open resumes the newest rostered entry, #28 review
|
||||
/// fix; any other id answers with NO sessionId = unknown), and session/fork
|
||||
/// of sess-1 returns a fresh F-<n> (any other source id returns ""). load/fork
|
||||
@@ -52,6 +54,7 @@ func makeFakeACP(at dir: String, name: String = "hermes-acp", mode: String = "fu
|
||||
let path = (dir as NSString).appendingPathComponent(name)
|
||||
let modeFile = (dir as NSString).appendingPathComponent("\(name)-mode")
|
||||
let fixCardB64 = fixCardPayloadB64()
|
||||
let researchB64 = researchPayloadB64()
|
||||
// ponytail: one echo per wire message — long payloads ride shell vars so
|
||||
// each line stays under the lint cap and inspectable against the schema.
|
||||
let script = """
|
||||
@@ -59,6 +62,8 @@ func makeFakeACP(at dir: String, name: String = "hermes-acp", mode: String = "fu
|
||||
mode="full"
|
||||
[[ -f "${0:h}/\(name)-mode" ]] && mode=$(<"${0:h}/\(name)-mode")
|
||||
card=$(print -- '\(fixCardB64)' | base64 -d)
|
||||
research=$(print -- '\(researchB64)' | base64 -d)
|
||||
researchstray=$(print -- '\(strayResearchPayloadB64())' | base64 -d)
|
||||
framing='{"jsonrpc":"2.0","id":'
|
||||
sessn=0
|
||||
forkn=0
|
||||
@@ -99,6 +104,14 @@ func makeFakeACP(at dir: String, name: String = "hermes-acp", mode: String = "fu
|
||||
continue
|
||||
fi
|
||||
echo $notify'{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"mentor."},"messageId":"m1"}}}'
|
||||
if [[ "$mode" == "strayResearchOnPrompt" ]]; then
|
||||
# #29 audit pin: a research payload carrying stray fix-card keys at
|
||||
# the top level must route by shape (notes array), not vanish into
|
||||
# a card row.
|
||||
echo $notify'{"sessionUpdate":"tool_call","toolCallId":"tc1","title":"submit_research_notes","rawInput":'"$researchstray"'}}}'
|
||||
echo $framing"$rid",'"result":{"stopReason":"end_turn"}}'
|
||||
continue
|
||||
fi
|
||||
echo $notify'{"sessionUpdate":"tool_call","toolCallId":"tc1","title":"submit_fix_cards","rawInput":'"$card"'}}}'
|
||||
if [[ "$mode" == "hangOnPrompt" ]]; then
|
||||
# #124: the cancel-acknowledging hold — the real engine answers its
|
||||
@@ -141,6 +154,7 @@ func makeFakeACP(at dir: String, name: String = "hermes-acp", mode: String = "fu
|
||||
echo $rnot'{"sessionUpdate":"user_message_chunk","content":{"type":"text","text":"earlier ask"}}}}'
|
||||
echo $rnot'{"sessionUpdate":"agent_thought_chunk","content":{"type":"text","text":"old thinking"}}}}'
|
||||
echo $rnot'{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"earlier verdict"}}}}'
|
||||
echo $rnot'{"sessionUpdate":"tool_call","toolCallId":"tc2","title":"submit_research_notes","rawInput":'"$research"'}}}'
|
||||
echo $framing"$rid",'"result":{"sessionId":"'"$lsid"'"}}'
|
||||
else
|
||||
echo $framing"$rid",'"result":{}}' # unknown session — no sessionId
|
||||
@@ -188,6 +202,25 @@ private func fixCardPayloadB64() -> String {
|
||||
return Data(json.utf8).base64EncodedString()
|
||||
}
|
||||
|
||||
/// The research-notes payload for the fake's replayed tool call (#29) —
|
||||
/// base64 like the fix card so shell quoting can never break the wire JSON.
|
||||
/// Two notes: one complete, one with quote/note absent (the "" defaults).
|
||||
private func researchPayloadB64() -> String {
|
||||
let json = #"{"piece_path":"/tmp/piece","notes":["# +
|
||||
#"{"title":"Hinge Study","url":"https://example.org/hinge","quote":"We should stop listening.","note":"Counts the pivot tense."},"# +
|
||||
#"{"title":"Second Source","url":"https://example.org/second"}]}"#
|
||||
return Data(json.utf8).base64EncodedString()
|
||||
}
|
||||
|
||||
/// The #29 routing pin's payload: a research batch that ALSO carries stray
|
||||
/// fix-card keys at the top level (LLM tool calls pick up stray keys). The
|
||||
/// notes-array shape must win over the pattern/problem match.
|
||||
private func strayResearchPayloadB64() -> String {
|
||||
let json = #"{"pattern":"stray","problem":"stray","piece_path":"/tmp/piece","notes":["# +
|
||||
#"{"title":"Hinge Study","url":"https://example.org/hinge"}]}"#
|
||||
return Data(json.utf8).base64EncodedString()
|
||||
}
|
||||
|
||||
func acpTempDir(_ label: String) -> String {
|
||||
let dir = NSTemporaryDirectory() + "museion-acp-\(label)-\(UUID().uuidString)"
|
||||
try? FileManager.default.createDirectory(atPath: dir, withIntermediateDirectories: true)
|
||||
@@ -400,6 +433,43 @@ struct ACPClientTests {
|
||||
#expect(refused)
|
||||
}
|
||||
|
||||
/// #29 audit pin: a research payload with stray fix-card keys routes by
|
||||
/// SHAPE (the notes array) — it renders candidates, never a card row.
|
||||
/// Title-based routing would also work on the fake but titles are
|
||||
/// display text; the payload is the contract.
|
||||
@MainActor
|
||||
@Test func `research payload with stray card keys renders candidates not a card`() async {
|
||||
let fake = makeFakeACP(at: acpTempDir("stray-research"), mode: "strayResearchOnPrompt")
|
||||
let model = MentorSessionModel(binaryPath: fake)
|
||||
defer { model.shutdown() }
|
||||
await model.openSession()
|
||||
let outcome = await model.sendPrompt("research this")
|
||||
guard case .ended = outcome else {
|
||||
Issue.record("turn did not end: \(outcome)")
|
||||
return
|
||||
}
|
||||
var hasCandidates = false
|
||||
var hasCard = false
|
||||
for _ in 0 ..< 250 {
|
||||
hasCandidates = model.rows.contains {
|
||||
if case .researchNote = $0.content {
|
||||
return true
|
||||
}; return false
|
||||
}
|
||||
hasCard = model.rows.contains {
|
||||
if case .fixCard = $0.content {
|
||||
return true
|
||||
}; return false
|
||||
}
|
||||
if hasCandidates {
|
||||
break
|
||||
}
|
||||
try? await Task.sleep(nanoseconds: 20_000_000)
|
||||
}
|
||||
#expect(hasCandidates, "the stray-key research batch never rendered as candidates")
|
||||
#expect(!hasCard, "the research payload was swallowed by the fix-card parser")
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Test func `thought chunks land in a collapsed thought row not the critique`() async {
|
||||
let fake = makeFakeACP(at: acpTempDir("thought-lane"))
|
||||
|
||||
Reference in new issue
Block a user