The design language that makes your AI harness better at design.
JavaScript
Merge origin/main into fix/603-codex-stop-payload
Abdul Wahab2064b0696f95
diff --cc skill/scripts/hook-lib.mjsindex 0a2d827e7,8a9f38102..1e709b11a--- a/skill/scripts/hook-lib.mjs+++ b/skill/scripts/hook-lib.mjs@@@ -1251,10 -1251,14 +1251,15 @@@ export function resolveHarness(env = {}const explicit = env?.IMPECCABLE_HOOK_HARNESS;if (explicit === 'cursor') return 'cursor';if (explicit === 'github') return 'github';+ if (explicit === 'grok') return 'grok';- if (explicit === 'claude' || explicit === 'codex') return 'claude';+ if (explicit === 'claude') return 'claude';+ if (explicit === 'codex') return 'codex';- // GitHub Copilot's postToolUse event uses camelCase `toolName`/`toolArgs` and- // has no `tool_name`/`tool_input`. That shape is the discriminator.+ // Grok Build sends camelCase `toolName`/`toolInput`/`hookEventName` and no+ // snake_case pair. GitHub Copilot sends camelCase `toolName`/`toolArgs`.+ // Check Grok first: the old GitHub heuristic (`toolName` and no+ // `tool_input`) also matches Grok, which is how live PostToolUse was+ // classified as Copilot and then skipped with no-file-path (#646).+ if (looksLikeGrokEnvelope(event)) return 'grok';if (event && typeof event === 'object'&& (typeof event.toolName === 'string' || event.toolArgs !== undefined)&& event.tool_name === undefined && event.tool_input === undefined) {@@@ -2169,11 -2224,8 +2230,11 @@@ export const STOP_MAX_FILES = 20* { exitCode, stdout, audit, emission? }** Never throws; exits silent (and fast) when the session touched no UI- * files. Output uses the Stop hookSpecificOutput channel: additionalContext- * is delivered to the model and the conversation continues so it can act.+ * files. Output goes out on the harness's Stop continuation channel: Claude- * Code reads hookSpecificOutput.additionalContext, Codex takes a- * decision: "block" whose reason becomes the continuation prompt. Either++ * Code and Grok Build read hookSpecificOutput.additionalContext, Codex takes++ * a decision: "block" whose reason becomes the continuation prompt. Either+ * way the findings reach the model and the conversation continues so it+ * can act.*/export async function runStopHook({ stdinJson, env = {}, cwd = process.cwd(), now = Date.now, detector } = {}) {const audit = { ts: new Date(now()).toISOString(), event: 'Stop' };@@@ -2200,21 -2252,21 +2261,25 @@@return result({ skipped: 'stdin-empty', durationMs: Date.now() - started });}+ const harness = resolveHarness(env, event);+ audit.harness = harness;+ event = normalizeHookEvent(event, cwd, harness);+- // Claude Code's Stop-hook contract: `stop_hook_active` is true when this- // hook is being re-invoked only because a prior invocation kept the turn- // alive (here, via hookSpecificOutput.additionalContext). Re-scanning and- // re-blocking now would loop until Claude Code's consecutive-block cap- // force-ends the turn (issue #400). The prior fire already surfaced the- // findings; whether to act on them is the agent's call. Exit fast with no- // output before any scan. Claude sends `stop_hook_active`; Grok sends- // `stopHookActive`, copied onto the snake_case field above. The strict- // `=== true` is a no-op when the field is absent. This guard makes the- // loop impossible regardless of the finding cache key's line-number- // sensitivity (out of scope here; see findingCacheKey).+ // Stop-hook re-entry guard: `stop_hook_active` is true when this hook is+ // being re-invoked only because a prior invocation kept the turn alive+ // (Claude Code via hookSpecificOutput.additionalContext, Codex via a+ // decision: "block" continuation). Re-scanning and re-blocking now could+ // loop (issue #400). The prior fire already surfaced the findings;+ // whether to act on them is the agent's call. Exit fast with no output+ // before any scan. Claude Code and Codex both send this field: Codex+ // mirrors the Claude contract (StopCommandInput in+ // codex-rs/hooks/src/schema.rs) and latches it true for the rest of the- // turn once a block is honored (codex-rs/core/src/session/turn.rs), so- // this guard is also what caps the Codex deep pass at one continuation- // per turn. Cursor and GitHub Copilot omit the field, so the strict- // `=== true` is a no-op for them. The guard makes the loop impossible- // regardless of the finding cache key's line-number sensitivity (out of- // scope here; see findingCacheKey).++ // turn once a block is honored (codex-rs/core/src/session/turn.rs). Grok++ // sends `stopHookActive`, copied onto the snake_case field above. Cursor++ // and GitHub Copilot omit the field, so the strict `=== true` is a no-op++ // for them. The guard makes the loop impossible regardless of the finding++ // cache key's line-number sensitivity (out of scope here; see++ // findingCacheKey).if (event.stop_hook_active === true) {return result({ skipped: 'stop-hook-active', durationMs: Date.now() - started });}diff --cc skill/scripts/hook.mjsindex 9dd67b1c7,771e0cc75..a190ad697--- a/skill/scripts/hook.mjs+++ b/skill/scripts/hook.mjs@@@ -7,10 -8,11 +8,11 @@@** - PostToolUse: runs the immediate-tier detector rules against the touched* file and emits a system reminder via- * `hookSpecificOutput.additionalContext` when findings exist.+ * `hookSpecificOutput.additionalContext` when findings exist. Grok+ * discards that stdout; the scan still warms the session cache for Stop.* - Stop: runs the FULL detector rule set over every UI file touched this* session (the deep pass), deduped against what the per-edit pass already- * surfaced, and emits once via the Stop additionalContext channel.+ * surfaced, and emits once via the harness-specific continuation channel.** Contract: never break a turn. Always exit 0. Clean files emit a small ack* unless quiet mode is enabled; a clean Stop pass is silent.diff --cc tests/hook.test.mjsindex 1152ccb5f,4604f80c6..15f549e43--- a/tests/hook.test.mjs+++ b/tests/hook.test.mjs@@@ -2739,13 -2743,6 +2766,14 @@@ describe('resolveHarness() / normalizeHassert.equal(resolveHarness({}), 'claude');});+ it('prefers explicit harness and Cursor detection over the Codex turn_id', () => {+ assert.equal(resolveHarness({ IMPECCABLE_HOOK_HARNESS: 'claude' }, { turn_id: 'turn-1' }), 'claude');++ assert.equal(resolveHarness({ IMPECCABLE_HOOK_HARNESS: 'grok' }, { turn_id: 'turn-1' }), 'grok');+ assert.equal(resolveHarness({}, { conversation_id: 'c1', turn_id: 'turn-1' }), 'cursor');+ assert.equal(resolveHarness({}, { turn_id: '' }), 'claude');+ assert.equal(resolveHarness({}, { turn_id: 42 }), 'claude');+ });+it('maps Cursor postToolUse Write path into file_path + cwd', () => {const normalized = normalizeHookEvent({conversation_id: 'c1',