fix(unslop-hook): review round, the Stop fallback logs late: true and the comment names the two stale cases left: an input with no last_assistant_message, and a reply whose text equals the last turn's last reply; cli.mjs notes that the packs-http read is the tested gate for system-only templates (#1873, lane triage-followups)
This commit was merged in pull request #1986.
This commit is contained in:
1 parent
c85c768a4a
commit
b39d5e2ff3
4 files changed
+17
-9
No files matched your search
@@ -117,8 +117,10 @@ lists.
|
||||
transcript (seen on 2.1.319 to 2.1.325, on any turn). The hook reads the
|
||||
transcript again until its last reply matches `last_assistant_message`,
|
||||
for up to 2 s. If it never does, the hook checks `last_assistant_message`
|
||||
alone and logs an empty `entryId`, and the turn's earlier replies go
|
||||
unchecked.
|
||||
alone, logs an empty `entryId` and `late: true`, and the turn's earlier
|
||||
replies go unchecked. Two stale cases remain: a hook input with no
|
||||
`last_assistant_message`, and a reply whose text equals the last turn's
|
||||
last reply. Either can log the last turn's replies again.
|
||||
- The word/phrase lists are the mechanical subset of ms-unslop only, keyed to
|
||||
pattern ids in lists.json. Style judgments (voice, rhythm, structure) stay in
|
||||
the skill, not the gate.
|
||||
|
||||
@@ -88,7 +88,11 @@ function turnReplies(path) {
|
||||
// Claude Code can run the Stop hook before it writes the turn to the transcript, so the
|
||||
// transcript may still end with the last turn. Read it again until its last reply is the one
|
||||
// the hook input names, for up to STOP_WAIT_MS (the hook's own limit is 10 s). A transcript that
|
||||
// never catches up gives last_assistant_message alone, never the last turn's replies again.
|
||||
// never catches up gives last_assistant_message alone, logged with late: true so a release where
|
||||
// it never matches shows in the log.
|
||||
// Two stale cases remain: an input with no last_assistant_message is not waited for, and a reply
|
||||
// whose text equals the last turn's last reply matches a stale transcript at once. Either can log
|
||||
// the last turn's replies again.
|
||||
const STOP_WAIT_MS = 2000;
|
||||
const flat = (s) => s.replace(/\s+/g, "");
|
||||
const pause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
||||
@@ -96,10 +100,11 @@ const pause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0,
|
||||
function stop(input) {
|
||||
const told = typeof input.last_assistant_message === "string" && input.last_assistant_message.trim() ? input.last_assistant_message : null;
|
||||
const deadline = Date.now() + STOP_WAIT_MS;
|
||||
let turn = turnReplies(input.transcript_path);
|
||||
let turn = turnReplies(input.transcript_path), late = false;
|
||||
while (told !== null && !(turn.length && flat(turn.at(-1).text) === flat(told))) {
|
||||
if (Date.now() >= deadline) {
|
||||
turn = [{ id: "", text: told }];
|
||||
late = true;
|
||||
break;
|
||||
}
|
||||
pause(25);
|
||||
@@ -108,8 +113,9 @@ function stop(input) {
|
||||
for (const r of turn) {
|
||||
const result = check(r.text, "stop");
|
||||
if (result === null) return;
|
||||
if (result.clean) log({ ev: "checked", clean: true, entryId: r.id, charsChecked: result.charsChecked });
|
||||
else log({ ev: "flagged", clean: false, entryId: r.id, charsChecked: result.charsChecked, findings: result.findings });
|
||||
const extra = late ? { late: true } : {};
|
||||
if (result.clean) log({ ev: "checked", clean: true, entryId: r.id, charsChecked: result.charsChecked, ...extra });
|
||||
else log({ ev: "flagged", clean: false, entryId: r.id, charsChecked: result.charsChecked, findings: result.findings, ...extra });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -331,13 +331,13 @@ t("claude-hook: Stop with a transcript that never catches up checks last_assista
|
||||
const log = tmp("hook-stale.jsonl");
|
||||
const r = hook("stop", { transcript_path: transcript, last_assistant_message: TELL_REPLY }, { MOSAIC_UNSLOP_LOG: log });
|
||||
assert.strictEqual(r.status, 0, r.stderr);
|
||||
assert.deepStrictEqual(events(log).map((e) => [e.ev, e.entryId]), [["flagged", ""]]);
|
||||
assert.deepStrictEqual(events(log).map((e) => [e.ev, e.entryId, e.late]), [["flagged", "", true]]);
|
||||
// A turn already in the transcript is checked at once, with its entry id.
|
||||
const now = tmp("hook-current.jsonl");
|
||||
const started = Date.now();
|
||||
hook("stop", { transcript_path: transcript, last_assistant_message: "The build is green." }, { MOSAIC_UNSLOP_LOG: now });
|
||||
assert.ok(Date.now() - started < 1500, "no wait when the transcript is current");
|
||||
assert.deepStrictEqual(events(now).map((e) => [e.ev, e.entryId]), [["checked", "a1"]]);
|
||||
assert.deepStrictEqual(events(now).map((e) => [e.ev, e.entryId, e.late]), [["checked", "a1", undefined]]);
|
||||
});
|
||||
|
||||
let failed = 0;
|
||||
|
||||
Reference in new issue
Block a user