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
@@ -205,7 +205,7 @@ try {
|
|||||||
templatesWrite: session.user === undefined && sendOn ? templatesCaller(consoleCall({ dataRoot: root, socket: paths.socket, business: id })) : null,
|
templatesWrite: session.user === undefined && sendOn ? templatesCaller(consoleCall({ dataRoot: root, socket: paths.socket, business: id })) : null,
|
||||||
// Starter packs SP6 (#1873): the owner's workflow read, the organization file and its revision as the
|
// Starter packs SP6 (#1873): the owner's workflow read, the organization file and its revision as the
|
||||||
// writer reads them (the read `mosaic org workflow set` takes its revision from), and the V2 template names
|
// writer reads them (the read `mosaic org workflow set` takes its revision from), and the V2 template names
|
||||||
// less the system-only ones.
|
// less the system-only ones. packs-http's workflowsRead drops them again and is the tested gate.
|
||||||
workflowsRead: session.user === undefined ? () => ({ ...organizationWriter({ dir: configDir(), rolesDir: rolesDir() }).read(id), templates: templateHashes(rolesDir()).map(t => t.template).filter(t => !systemOnly(t)) }) : null,
|
workflowsRead: session.user === undefined ? () => ({ ...organizationWriter({ dir: configDir(), rolesDir: rolesDir() }).read(id), templates: templateHashes(rolesDir()).map(t => t.template).filter(t => !systemOnly(t)) }) : null,
|
||||||
reads: consoleReads({ root: REPO, queueRoot: options.checkout ?? REPO, system, configDir: configDir(), rolesDir: rolesDir(), business: id, orgRoot: root }),
|
reads: consoleReads({ root: REPO, queueRoot: options.checkout ?? REPO, system, configDir: configDir(), rolesDir: rolesDir(), business: id, orgRoot: root }),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -117,8 +117,10 @@ lists.
|
|||||||
transcript (seen on 2.1.319 to 2.1.325, on any turn). The hook reads the
|
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`,
|
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`
|
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
|
alone, logs an empty `entryId` and `late: true`, and the turn's earlier
|
||||||
unchecked.
|
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
|
- 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
|
pattern ids in lists.json. Style judgments (voice, rhythm, structure) stay in
|
||||||
the skill, not the gate.
|
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
|
// 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
|
// 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
|
// 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 STOP_WAIT_MS = 2000;
|
||||||
const flat = (s) => s.replace(/\s+/g, "");
|
const flat = (s) => s.replace(/\s+/g, "");
|
||||||
const pause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
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) {
|
function stop(input) {
|
||||||
const told = typeof input.last_assistant_message === "string" && input.last_assistant_message.trim() ? input.last_assistant_message : null;
|
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;
|
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))) {
|
while (told !== null && !(turn.length && flat(turn.at(-1).text) === flat(told))) {
|
||||||
if (Date.now() >= deadline) {
|
if (Date.now() >= deadline) {
|
||||||
turn = [{ id: "", text: told }];
|
turn = [{ id: "", text: told }];
|
||||||
|
late = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pause(25);
|
pause(25);
|
||||||
@@ -108,8 +113,9 @@ function stop(input) {
|
|||||||
for (const r of turn) {
|
for (const r of turn) {
|
||||||
const result = check(r.text, "stop");
|
const result = check(r.text, "stop");
|
||||||
if (result === null) return;
|
if (result === null) return;
|
||||||
if (result.clean) log({ ev: "checked", clean: true, entryId: r.id, charsChecked: result.charsChecked });
|
const extra = late ? { late: true } : {};
|
||||||
else log({ ev: "flagged", clean: false, entryId: r.id, charsChecked: result.charsChecked, findings: result.findings });
|
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 log = tmp("hook-stale.jsonl");
|
||||||
const r = hook("stop", { transcript_path: transcript, last_assistant_message: TELL_REPLY }, { MOSAIC_UNSLOP_LOG: log });
|
const r = hook("stop", { transcript_path: transcript, last_assistant_message: TELL_REPLY }, { MOSAIC_UNSLOP_LOG: log });
|
||||||
assert.strictEqual(r.status, 0, r.stderr);
|
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.
|
// A turn already in the transcript is checked at once, with its entry id.
|
||||||
const now = tmp("hook-current.jsonl");
|
const now = tmp("hook-current.jsonl");
|
||||||
const started = Date.now();
|
const started = Date.now();
|
||||||
hook("stop", { transcript_path: transcript, last_assistant_message: "The build is green." }, { MOSAIC_UNSLOP_LOG: 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.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;
|
let failed = 0;
|
||||||
|
|||||||
Reference in new issue
Block a user