claude-dev-env 8.116.5 → 8.117.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ever-registered-hooks.mjs +2 -0
- package/bin/ever-registered-hooks.test.mjs +4 -0
- package/bin/install-constants.mjs +3 -1
- package/bin/install.cursor-rules.test.mjs +64 -2
- package/bin/install.mjs +15 -2
- package/bin/install.prune.test.mjs +92 -0
- package/bin/install.test.mjs +1 -0
- package/docs/model-choice/escalation.md +3 -3
- package/docs/model-choice/subagents-and-fan-out.md +2 -2
- package/docs/model-choice/which-model.md +1 -1
- package/docs/references/working-style.md +1 -0
- package/docs/rule-guides/question-presentation.md +6 -0
- package/docs/rule-guides/session-title.md +8 -9
- package/docs/rule-guides/subagent-model-effort.md +13 -13
- package/hooks/advisory/owned_pr_review_loop.py +2 -3
- package/hooks/blocking/bash_post_call_dispatcher.py +17 -9
- package/hooks/blocking/bash_pre_tool_use_dispatcher.py +12 -8
- package/hooks/blocking/final_reply_gate.py +5 -9
- package/hooks/blocking/open_tasks_stop_gate.py +9 -20
- package/hooks/blocking/open_tasks_transcript.py +8 -3
- package/hooks/blocking/pii_prevention_blocker_parts/repository_exemption.py +7 -2
- package/hooks/blocking/question_brief_gate.py +382 -0
- package/hooks/blocking/step_note_gate.py +5 -2
- package/hooks/blocking/task_subject_length_gate.py +111 -0
- package/hooks/blocking/test_bash_post_call_dispatcher.py +36 -1
- package/hooks/blocking/test_bash_pre_tool_use_dispatcher.py +57 -0
- package/hooks/blocking/test_final_reply_gate.py +26 -2
- package/hooks/blocking/test_open_tasks_stop_gate.py +21 -11
- package/hooks/blocking/test_question_brief_gate.py +916 -0
- package/hooks/blocking/test_step_note_gate.py +26 -0
- package/hooks/blocking/test_task_subject_length_gate.py +221 -0
- package/hooks/blocking/test_turn_review_child.py +166 -0
- package/hooks/blocking/test_turn_review_claim.py +194 -0
- package/hooks/blocking/test_turn_review_findings.py +124 -1
- package/hooks/blocking/test_turn_review_gate.py +1312 -10
- package/hooks/blocking/test_turn_review_repositories.py +65 -0
- package/hooks/blocking/test_turn_review_snapshot.py +8 -0
- package/hooks/blocking/test_turn_review_state.py +132 -0
- package/hooks/blocking/test_turn_review_transcript.py +125 -0
- package/hooks/blocking/tests/test_repository_exemption.py +11 -0
- package/hooks/blocking/turn_review_child.py +145 -0
- package/hooks/blocking/turn_review_claim.py +306 -0
- package/hooks/blocking/turn_review_findings.py +173 -13
- package/hooks/blocking/turn_review_gate.py +259 -262
- package/hooks/blocking/turn_review_repositories.py +58 -0
- package/hooks/blocking/turn_review_snapshot.py +5 -1
- package/hooks/blocking/turn_review_state.py +260 -0
- package/hooks/blocking/turn_review_transcript.py +158 -0
- package/hooks/features/bash-dispatchers.md +1 -3
- package/hooks/features/conduct-gates.md +19 -9
- package/hooks/features/lifecycle-cleanup.md +1 -1
- package/hooks/features/spawn-routing.md +1 -1
- package/hooks/hooks.json +24 -11
- package/hooks/hooks_constants/final_reply_gate_constants.py +0 -3
- package/hooks/hooks_constants/hook_time_budget.py +61 -0
- package/hooks/hooks_constants/hosted_hook_runner.py +51 -21
- package/hooks/hooks_constants/hosted_hook_runner_constants.py +3 -0
- package/hooks/hooks_constants/nested_project_hooks_constants.py +8 -0
- package/hooks/hooks_constants/once_per_session_constants.py +1 -0
- package/hooks/hooks_constants/open_tasks_stop_gate_constants.py +0 -4
- package/hooks/hooks_constants/owned_pr_review_loop_constants.py +0 -4
- package/hooks/hooks_constants/pre_tool_use_context_runner.py +23 -3
- package/hooks/hooks_constants/pre_tool_use_context_runner_constants.py +5 -0
- package/hooks/hooks_constants/pre_tool_use_stdin.py +1 -1
- package/hooks/hooks_constants/question_brief_gate_constants.py +66 -0
- package/hooks/hooks_constants/session_title_constants.py +8 -29
- package/hooks/hooks_constants/stop_hook_hold.py +54 -0
- package/hooks/hooks_constants/stop_hook_hold_constants.py +9 -0
- package/hooks/hooks_constants/subagent_effort_levels.json +6 -0
- package/hooks/hooks_constants/subagent_effort_route_constants.py +20 -19
- package/hooks/hooks_constants/task_subject_length_gate_constants.py +43 -0
- package/hooks/hooks_constants/test_hook_time_budget.py +104 -0
- package/hooks/hooks_constants/test_hosted_hook_runner.py +12 -0
- package/hooks/hooks_constants/test_pre_tool_use_context_runner.py +16 -0
- package/hooks/hooks_constants/test_pre_tool_use_stdin.py +6 -0
- package/hooks/hooks_constants/test_stop_hook_hold.py +40 -0
- package/hooks/hooks_constants/thread_spawn_pace_hook_constants.py +1 -2
- package/hooks/hooks_constants/turn_review_gate_constants.py +246 -12
- package/hooks/lifecycle/nested_project_hooks.py +34 -4
- package/hooks/lifecycle/test_nested_project_hooks.py +52 -0
- package/hooks/once_per_session.py +33 -4
- package/hooks/open_task_asks.py +1 -1
- package/hooks/owned_pr_session_record.py +1 -76
- package/hooks/routing/subagent_effort_route.py +107 -13
- package/hooks/routing/subagent_effort_route_hook.py +9 -8
- package/hooks/routing/test_subagent_effort_route.py +201 -14
- package/hooks/routing/test_subagent_effort_route_hook.py +56 -0
- package/hooks/routing/test_thread_spawn_pace_hook.py +32 -0
- package/hooks/routing/thread_spawn_pace_hook.py +3 -3
- package/hooks/session/background_silence_prompt.py +1 -1
- package/hooks/session/test_background_silence_prompt.py +8 -0
- package/hooks/session/test_tracking_nudge.py +125 -2
- package/hooks/session/tracking_nudge.py +28 -18
- package/hooks/session_title_transcript.py +216 -0
- package/hooks/test_once_per_session.py +10 -0
- package/hooks/test_owned_pr_session_record.py +0 -26
- package/hooks/test_session_title_transcript.py +142 -0
- package/hooks/validation/post_tool_use_dispatcher.py +38 -21
- package/hooks/validation/test_post_tool_use_dispatcher.py +43 -0
- package/package.json +1 -1
- package/rules/question-presentation.md +4 -4
- package/rules/subagent-model-effort.md +1 -1
- package/scripts/account_broker_support.py +24 -5
- package/scripts/claude_account_worker.py +4 -3
- package/scripts/dev_env_scripts_constants/account_broker_constants.py +1 -0
- package/scripts/policy_lint/adapter_configuration.py +12 -11
- package/scripts/policy_lint/config/approved_test_pairs.py +27 -0
- package/scripts/policy_lint/config/constants.py +2 -2
- package/scripts/test_account_broker_support.py +43 -1
- package/scripts/test_claude_account_worker.py +1 -0
- package/scripts/tests/test_adapter_configuration.py +10 -2
- package/scripts/tests/test_policy_lint_rules_pairing.py +24 -0
- package/hooks/blocking/owned_pr_merge_stop_gate.py +0 -185
- package/hooks/blocking/session_title_turn_gate.py +0 -417
- package/hooks/blocking/test_owned_pr_merge_stop_gate.py +0 -254
- package/hooks/blocking/test_session_title_turn_gate.py +0 -396
- package/hooks/hooks_constants/owned_pr_merge_stop_gate_constants.py +0 -40
|
@@ -77,6 +77,7 @@ export const EVER_REGISTERED_HOOK_RELATIVE_PATHS = new Set([
|
|
|
77
77
|
'blocking/pyautogui-scroll-blocker.py',
|
|
78
78
|
'blocking/pyautogui_scroll_blocker.py',
|
|
79
79
|
'blocking/pytest_testpaths_orphan_blocker.py',
|
|
80
|
+
'blocking/question_brief_gate.py',
|
|
80
81
|
'blocking/question_to_user_enforcer.py',
|
|
81
82
|
'blocking/reply_length_gate.py',
|
|
82
83
|
'blocking/resolve_thread_reply_gate.py',
|
|
@@ -98,6 +99,7 @@ export const EVER_REGISTERED_HOOK_RELATIVE_PATHS = new Set([
|
|
|
98
99
|
'blocking/subagent_model_gate.py',
|
|
99
100
|
'blocking/subagent_model_routing.mjs',
|
|
100
101
|
'blocking/subprocess_budget_completeness.py',
|
|
102
|
+
'blocking/task_subject_length_gate.py',
|
|
101
103
|
'blocking/tdd-enforcer.py',
|
|
102
104
|
'blocking/tdd_enforcer.py',
|
|
103
105
|
'blocking/test-preflight-check.py',
|
|
@@ -20,6 +20,10 @@ test('EVER_REGISTERED_HOOK_RELATIVE_PATHS includes every script the package regi
|
|
|
20
20
|
);
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
+
test('EVER_REGISTERED_HOOK_RELATIVE_PATHS keeps the question brief gate', () => {
|
|
24
|
+
assert.ok(EVER_REGISTERED_HOOK_RELATIVE_PATHS.has('blocking/question_brief_gate.py'));
|
|
25
|
+
});
|
|
26
|
+
|
|
23
27
|
test('EVER_REGISTERED_HOOK_RELATIVE_PATHS keeps the retired merge-over-review card gate', () => {
|
|
24
28
|
assert.equal(
|
|
25
29
|
EVER_REGISTERED_HOOK_RELATIVE_PATHS.has('blocking/merge_over_review_offer_gate.py'),
|
|
@@ -177,7 +177,9 @@ export const ADDITIONAL_SETTINGS_BLOB_PREFIX = 'settings-';
|
|
|
177
177
|
export const CODEX_NATIVE_ROUTING_MATCHER = 'multi_agent_v1__spawn_agent';
|
|
178
178
|
export const ALL_CODEX_NATIVE_STOP_HOOK_SCRIPT_NAMES = new Set([
|
|
179
179
|
'open_tasks_stop_gate.py',
|
|
180
|
-
|
|
180
|
+
]);
|
|
181
|
+
export const ALL_CODEX_EXCLUDED_USER_PROMPT_SUBMIT_HOOK_SCRIPT_NAMES = new Set([
|
|
182
|
+
'turn_review_gate.py',
|
|
181
183
|
]);
|
|
182
184
|
export const ALL_CODEX_NATIVE_SESSION_START_HOOK_SCRIPT_NAMES = new Set([
|
|
183
185
|
'compaction_recall_prompt.py',
|
|
@@ -102,6 +102,35 @@ test('--only journal is rejected before the policy is seeded; --only core seeds
|
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
|
|
105
|
+
test('registers the turn review Stop hook in the background on Claude Code only', () => {
|
|
106
|
+
const homeDirectory = mkdtempSync(join(tmpdir(), 'cdev-turn-review-install-'));
|
|
107
|
+
try {
|
|
108
|
+
const resolution = resolveInstallRoot({ homeDirectory, environment: {}, explicitTarget: null });
|
|
109
|
+
|
|
110
|
+
runInstaller(homeDirectory, ['--only', 'core']);
|
|
111
|
+
|
|
112
|
+
const claudeSettings = JSON.parse(readFileSync(join(resolution.managedRoot, 'settings.json'), 'utf8'));
|
|
113
|
+
const turnReviewHooks = eventName => claudeSettings.hooks[eventName].flatMap(
|
|
114
|
+
group => group.hooks.filter(hook => String(hook.command).includes('blocking/turn_review_gate.py')),
|
|
115
|
+
);
|
|
116
|
+
const [stopHook] = turnReviewHooks('Stop');
|
|
117
|
+
assert.equal(turnReviewHooks('Stop').length, 1);
|
|
118
|
+
assert.equal(stopHook.asyncRewake, true);
|
|
119
|
+
assert.equal(stopHook.timeout, 300);
|
|
120
|
+
assert.equal(typeof stopHook.rewakeSummary, 'string');
|
|
121
|
+
const [promptHook] = turnReviewHooks('UserPromptSubmit');
|
|
122
|
+
assert.equal(promptHook.asyncRewake, undefined);
|
|
123
|
+
const codexHooksText = readFileSync(join(homeDirectory, '.codex', 'hooks.json'), 'utf8');
|
|
124
|
+
assert.equal(codexHooksText.includes('turn_review_gate.py'), false, 'Codex gets no turn review');
|
|
125
|
+
const cursorHooksPath = join(homeDirectory, DEFAULT_CURSOR_DIRECTORY_NAME, 'hooks.json');
|
|
126
|
+
const cursorHooksText = existsSync(cursorHooksPath) ? readFileSync(cursorHooksPath, 'utf8') : '';
|
|
127
|
+
assert.equal(cursorHooksText.includes('turn_review_gate.py'), false, 'Cursor gets no turn review');
|
|
128
|
+
} finally {
|
|
129
|
+
rmSync(homeDirectory, { recursive: true, force: true });
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
|
|
105
134
|
test('seeds one editable policy and one native Codex routing hook', () => {
|
|
106
135
|
const homeDirectory = mkdtempSync(join(tmpdir(), 'cdev-routing-install-'));
|
|
107
136
|
try {
|
|
@@ -142,9 +171,8 @@ test('seeds one editable policy and one native Codex routing hook', () => {
|
|
|
142
171
|
assert.equal(allCodexPostToolUseCommands.length, 1, 'Codex gets the owned PR review loop and no other PostToolUse hook');
|
|
143
172
|
assert.match(allCodexPostToolUseCommands[0], /advisory\/owned_pr_review_loop\.py/);
|
|
144
173
|
const allCodexStopCommands = firstCodexHooks.hooks.Stop.flatMap(group => group.hooks.map(hook => hook.command));
|
|
145
|
-
assert.equal(allCodexStopCommands.length,
|
|
174
|
+
assert.equal(allCodexStopCommands.length, 1, 'Codex gets the open tasks Stop gate and no other Stop hook');
|
|
146
175
|
assert.match(allCodexStopCommands[0], /open_tasks_stop_gate\.py/);
|
|
147
|
-
assert.match(allCodexStopCommands[1], /owned_pr_merge_stop_gate\.py/);
|
|
148
176
|
const allCodexSessionStartGroups = firstCodexHooks.hooks.SessionStart;
|
|
149
177
|
assert.deepEqual(allCodexSessionStartGroups.map(group => group.matcher), ['compact']);
|
|
150
178
|
const allCodexSessionStartCommands = allCodexSessionStartGroups.flatMap(group => group.hooks.map(hook => hook.command));
|
|
@@ -160,6 +188,33 @@ test('seeds one editable policy and one native Codex routing hook', () => {
|
|
|
160
188
|
firstCodexHooks.hooks.PreToolUse.some(group => group.matcher === 'Write|Edit|MultiEdit|apply_patch'),
|
|
161
189
|
false,
|
|
162
190
|
);
|
|
191
|
+
const allFirstCodexPromptCommands = firstCodexHooks.hooks.UserPromptSubmit.flatMap(
|
|
192
|
+
group => group.hooks.map(hook => String(hook.command)),
|
|
193
|
+
);
|
|
194
|
+
assert.ok(allFirstCodexPromptCommands.length > 0);
|
|
195
|
+
assert.equal(allFirstCodexPromptCommands.some(command => command.includes('turn_review_gate.py')), false);
|
|
196
|
+
const claudeSettings = JSON.parse(readFileSync(join(resolution.managedRoot, 'settings.json'), 'utf8'));
|
|
197
|
+
for (const eachEvent of ['UserPromptSubmit', 'Stop']) {
|
|
198
|
+
assert.equal(
|
|
199
|
+
claudeSettings.hooks[eachEvent].some(group =>
|
|
200
|
+
group.hooks.some(hook => String(hook.command).includes('blocking/turn_review_gate.py')),
|
|
201
|
+
),
|
|
202
|
+
true,
|
|
203
|
+
`Claude Code keeps the turn review gate on ${eachEvent}`,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
const managedPromptCommand = firstCodexHooks.hooks.UserPromptSubmit[0].hooks[0].command;
|
|
207
|
+
const managedPromptScriptPath = managedPromptCommand.match(/\S+\.py/)[0];
|
|
208
|
+
firstCodexHooks.hooks.UserPromptSubmit.push({
|
|
209
|
+
matcher: '',
|
|
210
|
+
hooks: [{
|
|
211
|
+
type: 'command',
|
|
212
|
+
command: managedPromptCommand.replace(
|
|
213
|
+
managedPromptScriptPath,
|
|
214
|
+
join(dirname(dirname(managedPromptScriptPath)), 'blocking', 'turn_review_gate.py'),
|
|
215
|
+
),
|
|
216
|
+
}],
|
|
217
|
+
});
|
|
163
218
|
|
|
164
219
|
const editedPolicy = '{"schemaVersion":1,"edited":true}\n';
|
|
165
220
|
writeFileSync(policyPath, editedPolicy);
|
|
@@ -173,6 +228,13 @@ test('seeds one editable policy and one native Codex routing hook', () => {
|
|
|
173
228
|
|
|
174
229
|
assert.equal(readFileSync(policyPath, 'utf8'), editedPolicy);
|
|
175
230
|
const secondCodexHooks = JSON.parse(readFileSync(codexHooksPath, 'utf8'));
|
|
231
|
+
assert.equal(
|
|
232
|
+
secondCodexHooks.hooks.UserPromptSubmit.some(group =>
|
|
233
|
+
group.hooks.some(hook => String(hook.command).includes('turn_review_gate.py')),
|
|
234
|
+
),
|
|
235
|
+
false,
|
|
236
|
+
'an update strips the turn review gate from the Codex prompt hooks',
|
|
237
|
+
);
|
|
176
238
|
assert.equal(
|
|
177
239
|
secondCodexHooks.hooks.PreToolUse.filter(
|
|
178
240
|
group => group.matcher === 'multi_agent_v1__spawn_agent',
|
package/bin/install.mjs
CHANGED
|
@@ -52,6 +52,7 @@ import {
|
|
|
52
52
|
WINDOWS_PYTHON_LAUNCHER_COMMAND,
|
|
53
53
|
PYTHON_PROBE_TIMEOUT_MILLISECONDS,
|
|
54
54
|
CODEX_NATIVE_ROUTING_MATCHER,
|
|
55
|
+
ALL_CODEX_EXCLUDED_USER_PROMPT_SUBMIT_HOOK_SCRIPT_NAMES,
|
|
55
56
|
ALL_CODEX_NATIVE_SESSION_START_HOOK_SCRIPT_NAMES,
|
|
56
57
|
ALL_CODEX_NATIVE_STOP_HOOK_SCRIPT_NAMES,
|
|
57
58
|
ALL_CODEX_NATIVE_POST_TOOL_USE_HOOK_SCRIPT_NAMES,
|
|
@@ -1332,6 +1333,7 @@ export const RETIRED_HOOK_REGISTRATION_RELATIVE_PATHS = new Set([
|
|
|
1332
1333
|
'blocking/session_handoff_blocker.py',
|
|
1333
1334
|
'blocking/artifact_look_gate.py',
|
|
1334
1335
|
'blocking/session_title_stop_gate.py',
|
|
1336
|
+
'blocking/session_title_turn_gate.py',
|
|
1335
1337
|
'session/issue_tracker_session_starter.py',
|
|
1336
1338
|
'session/deepen_first_prompt.py',
|
|
1337
1339
|
'workflow/investigation_tracker_reset.py',
|
|
@@ -2344,16 +2346,27 @@ function selectCodexNativeGroupsByScriptName(groups, allScriptNames) {
|
|
|
2344
2346
|
.filter(group => group.hooks.length > 0);
|
|
2345
2347
|
}
|
|
2346
2348
|
|
|
2349
|
+
function withoutCodexExcludedPromptHooks(groups) {
|
|
2350
|
+
if (!Array.isArray(groups)) return [];
|
|
2351
|
+
return groups
|
|
2352
|
+
.map(group => ({
|
|
2353
|
+
...group,
|
|
2354
|
+
hooks: (group?.hooks ?? []).filter(
|
|
2355
|
+
hook => !ALL_CODEX_EXCLUDED_USER_PROMPT_SUBMIT_HOOK_SCRIPT_NAMES.has(hookScriptName(hook)),
|
|
2356
|
+
),
|
|
2357
|
+
}))
|
|
2358
|
+
.filter(group => group.hooks.length > 0);
|
|
2359
|
+
}
|
|
2360
|
+
|
|
2347
2361
|
function selectCodexNativeHooksConfig(hooksConfig) {
|
|
2348
2362
|
const preToolUseGroups = hooksConfig.hooks?.PreToolUse;
|
|
2349
|
-
const userPromptSubmitGroups = hooksConfig.hooks?.UserPromptSubmit;
|
|
2350
2363
|
return {
|
|
2351
2364
|
...hooksConfig,
|
|
2352
2365
|
hooks: {
|
|
2353
2366
|
PreToolUse: Array.isArray(preToolUseGroups)
|
|
2354
2367
|
? preToolUseGroups.filter(group => group?.matcher === CODEX_NATIVE_ROUTING_MATCHER)
|
|
2355
2368
|
: [],
|
|
2356
|
-
UserPromptSubmit:
|
|
2369
|
+
UserPromptSubmit: withoutCodexExcludedPromptHooks(hooksConfig.hooks?.UserPromptSubmit),
|
|
2357
2370
|
PostToolUse: selectCodexNativeGroupsByScriptName(
|
|
2358
2371
|
hooksConfig.hooks?.PostToolUse,
|
|
2359
2372
|
ALL_CODEX_NATIVE_POST_TOOL_USE_HOOK_SCRIPT_NAMES,
|
|
@@ -1615,6 +1615,98 @@ test('a full reinstall removes a retired hook entry under an event type the curr
|
|
|
1615
1615
|
}
|
|
1616
1616
|
});
|
|
1617
1617
|
|
|
1618
|
+
const RETIRED_TITLE_GATE_RELATIVE_SEGMENTS = ['blocking', 'session_title_turn_gate.py'];
|
|
1619
|
+
const TITLE_HOOK_NAME_FRAGMENT = 'session_title';
|
|
1620
|
+
|
|
1621
|
+
|
|
1622
|
+
/**
|
|
1623
|
+
* List the hook commands the settings file holds under one event type.
|
|
1624
|
+
*
|
|
1625
|
+
* @param {object} settings The parsed settings object.
|
|
1626
|
+
* @param {string} eventType The hook event type, such as Stop.
|
|
1627
|
+
* @returns {string[]} Each hook command under that event type.
|
|
1628
|
+
*/
|
|
1629
|
+
function hookCommandsForEvent(settings, eventType) {
|
|
1630
|
+
return (settings.hooks?.[eventType] ?? [])
|
|
1631
|
+
.flatMap(group => group.hooks || [])
|
|
1632
|
+
.map(hook => hook.command ?? '');
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
/**
|
|
1636
|
+
* Put back the session title Stop entry an earlier install wrote.
|
|
1637
|
+
*
|
|
1638
|
+
* @param {object} sandbox The sandbox a first install already ran in.
|
|
1639
|
+
* @param {string[]} allUserStopCommands Stop commands the user wrote, each added as its own group.
|
|
1640
|
+
*/
|
|
1641
|
+
function seedRetiredTitleStopEntry(sandbox, allUserStopCommands) {
|
|
1642
|
+
const retiredGatePath = join(
|
|
1643
|
+
sandbox.claudeDirectory, HOOKS_DIRECTORY_NAME, ...RETIRED_TITLE_GATE_RELATIVE_SEGMENTS,
|
|
1644
|
+
);
|
|
1645
|
+
writeFileWithParents(retiredGatePath, RETIRED_HOOK_SEEDED_CONTENTS);
|
|
1646
|
+
appendManifestFiles(sandbox.manifestPath, [retiredGatePath]);
|
|
1647
|
+
const retiredGateCommand = `python3 "${retiredGatePath.replace(/\\/g, '/')}"`;
|
|
1648
|
+
const settings = readSettings(sandbox.claudeDirectory);
|
|
1649
|
+
settings.hooks.Stop[0].hooks.push({ type: 'command', command: retiredGateCommand, timeout: 10 });
|
|
1650
|
+
for (const eachUserCommand of allUserStopCommands) {
|
|
1651
|
+
settings.hooks.Stop.push({ hooks: [{ type: 'command', command: eachUserCommand }] });
|
|
1652
|
+
}
|
|
1653
|
+
writeFileSync(
|
|
1654
|
+
join(sandbox.claudeDirectory, SETTINGS_FILE_NAME),
|
|
1655
|
+
JSON.stringify(settings, null, 4) + '\n',
|
|
1656
|
+
);
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
test('an uninstall removes the session title Stop entry an earlier install wrote and keeps a user Stop entry', () => {
|
|
1660
|
+
const sandbox = createSandbox();
|
|
1661
|
+
try {
|
|
1662
|
+
runInstaller(sandbox.homeDirectory, []);
|
|
1663
|
+
seedRetiredTitleStopEntry(sandbox, [USER_HOOK_COMMAND]);
|
|
1664
|
+
|
|
1665
|
+
runInstaller(sandbox.homeDirectory, ['--uninstall']);
|
|
1666
|
+
|
|
1667
|
+
assert.deepEqual(
|
|
1668
|
+
hookCommandsForEvent(readSettings(sandbox.claudeDirectory), 'Stop'),
|
|
1669
|
+
[USER_HOOK_COMMAND],
|
|
1670
|
+
'only the Stop entry the user wrote stays',
|
|
1671
|
+
);
|
|
1672
|
+
} finally {
|
|
1673
|
+
rmSync(sandbox.homeDirectory, { recursive: true, force: true });
|
|
1674
|
+
}
|
|
1675
|
+
});
|
|
1676
|
+
|
|
1677
|
+
test('a full reinstall registers no session title Stop hook and removes the one an earlier install wrote', () => {
|
|
1678
|
+
const sandbox = createSandbox();
|
|
1679
|
+
try {
|
|
1680
|
+
runInstaller(sandbox.homeDirectory, []);
|
|
1681
|
+
const titleStopCommands = () => hookCommandsForEvent(
|
|
1682
|
+
readSettings(sandbox.claudeDirectory), 'Stop',
|
|
1683
|
+
).filter(command => command.includes(TITLE_HOOK_NAME_FRAGMENT));
|
|
1684
|
+
assert.deepEqual(titleStopCommands(), [], 'a fresh install registers no session title Stop hook');
|
|
1685
|
+
|
|
1686
|
+
seedRetiredTitleStopEntry(sandbox, []);
|
|
1687
|
+
|
|
1688
|
+
runInstaller(sandbox.homeDirectory, []);
|
|
1689
|
+
|
|
1690
|
+
const reinstalledSettings = readSettings(sandbox.claudeDirectory);
|
|
1691
|
+
assert.deepEqual(titleStopCommands(), [], 'the reinstall removes the earlier session title Stop entry');
|
|
1692
|
+
const allStopCommands = hookCommandsForEvent(reinstalledSettings, 'Stop');
|
|
1693
|
+
for (const eachKeptStopScript of ['final_reply_gate.py', 'open_tasks_stop_gate.py']) {
|
|
1694
|
+
assert.ok(
|
|
1695
|
+
allStopCommands.some(command => command.includes(eachKeptStopScript)),
|
|
1696
|
+
`the ${eachKeptStopScript} Stop entry stays`,
|
|
1697
|
+
);
|
|
1698
|
+
}
|
|
1699
|
+
assert.ok(
|
|
1700
|
+
hookCommandsForEvent(reinstalledSettings, 'PreToolUse').some(
|
|
1701
|
+
command => command.includes('session_title_format_gate.py'),
|
|
1702
|
+
),
|
|
1703
|
+
'the title format gate stays on PreToolUse',
|
|
1704
|
+
);
|
|
1705
|
+
} finally {
|
|
1706
|
+
rmSync(sandbox.homeDirectory, { recursive: true, force: true });
|
|
1707
|
+
}
|
|
1708
|
+
});
|
|
1709
|
+
|
|
1618
1710
|
const UNSHIPPED_GATE_RELATIVE_SEGMENTS = ['blocking', 'merge_over_review_offer_gate.py'];
|
|
1619
1711
|
const UNSHIPPED_GATE_MATCHER = 'AskUserQuestion|mcp__.*__ask_decision';
|
|
1620
1712
|
const USER_AUTHORED_HOOK_RELATIVE_SEGMENTS = ['blocking', 'codemap_first_redirector.py'];
|
package/bin/install.test.mjs
CHANGED
|
@@ -1244,6 +1244,7 @@ test('retired hook registrations stay managed so reinstall removes them', () =>
|
|
|
1244
1244
|
'blocking/session_handoff_blocker.py',
|
|
1245
1245
|
'blocking/artifact_look_gate.py',
|
|
1246
1246
|
'blocking/session_title_stop_gate.py',
|
|
1247
|
+
'blocking/session_title_turn_gate.py',
|
|
1247
1248
|
'session/issue_tracker_session_starter.py',
|
|
1248
1249
|
'session/deepen_first_prompt.py',
|
|
1249
1250
|
'workflow/investigation_tracker_reset.py',
|
|
@@ -13,8 +13,8 @@ When a result is not good enough, first give the agent a way to check its own wo
|
|
|
13
13
|
The order comes from [Which Claude model should you build with](https://claude.dev/blog/which-claude-model-should-you-build-with/). The rungs are adapted to the allowed pairs.
|
|
14
14
|
|
|
15
15
|
1. Add self-verification. Give the agent a test, a build or a script that tells it when the work is done.
|
|
16
|
-
2. Raise effort one level, where the
|
|
17
|
-
3. Move up one model, at a lower effort.
|
|
16
|
+
2. Raise effort one level, where the [effort levels file](../../hooks/hooks_constants/subagent_effort_levels.json) allows the model a higher effort.
|
|
17
|
+
3. Move up one model, at a lower effort. For a model the file allows only one effort, step 2 is this step.
|
|
18
18
|
|
|
19
19
|
The model rungs, in order:
|
|
20
20
|
|
|
@@ -34,7 +34,7 @@ The article says to try effort before you change models. Past high, one more eff
|
|
|
34
34
|
- In the article's FrontierCode 2.0 run, Fable at high scored 45.3%. Opus at max scored 45.5% at about twice the cost per task.
|
|
35
35
|
- In the article's Terminal-Bench 3.0 run, Opus at high scored 58.9%. Fable 5.1 at max scored 58.0% and used about twice the tokens. Max effort added cost and no score.
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
Choose the effort from the allowed pairs in the [effort levels file](../../hooks/hooks_constants/subagent_effort_levels.json). Opus at medium keeps most of the score for less spend. Past Opus at high, Fable at high gives about the same score for less cost.
|
|
38
38
|
|
|
39
39
|
## Low first, then retry the failures
|
|
40
40
|
|
|
@@ -40,7 +40,7 @@ The article sets `model: haiku` in agent frontmatter, defines a custom Explore a
|
|
|
40
40
|
For work bigger than one context window, a top-tier lead splits the task across many cheaper workers and merges the results.
|
|
41
41
|
|
|
42
42
|
- In the article's defect search over about 22M tokens, an Opus lead with up to 25 parallel Sonnet workers cost about a third less than Opus alone. The score was the same.
|
|
43
|
-
- The article ran both at default effort. Here the lead is Opus
|
|
43
|
+
- The article ran both at default effort. Here the lead is Opus or Fable, and the workers are Sonnet or Haiku, each at an effort the [effort levels file](../../hooks/hooks_constants/subagent_effort_levels.json) allows.
|
|
44
44
|
- Skip fan-out for one chain of dependent steps, or for work that fits one context.
|
|
45
45
|
- The lead stays open until every worker's result is merged. Read [Workers done before complete](../rule-guides/workers-done-before-complete.md).
|
|
46
46
|
- For a long run with no one watching, read [Long-horizon autonomy](../rule-guides/long-horizon-autonomy.md).
|
|
@@ -49,7 +49,7 @@ For work bigger than one context window, a top-tier lead splits the task across
|
|
|
49
49
|
## Advisor pairs
|
|
50
50
|
|
|
51
51
|
- In the article, none of four advisor pairings clearly beat the executor alone.
|
|
52
|
-
- An Opus high executor with a Fable 5.1 advisor scored 90.1% at $2.92 an attempt. That is 1.7 points above Opus alone, for about 2.1 times the cost.
|
|
52
|
+
- An Opus high executor with a Fable 5.1 advisor scored 90.1% at $2.92 an attempt. That is 1.7 points above Opus alone, for about 2.1 times the cost.
|
|
53
53
|
- Measure how often the executor consults the advisor before you add one.
|
|
54
54
|
|
|
55
55
|
The call rules are in [Advisor tool](../references/advisor-tool.md). The advisor exception is in [Subagent model and effort](../rule-guides/subagent-model-effort.md).
|
|
@@ -37,7 +37,7 @@ This table adapts [Which Claude model should you build with](https://claude.dev/
|
|
|
37
37
|
## Move up
|
|
38
38
|
|
|
39
39
|
- Move to Fable for the hardest coding, finance and science work.
|
|
40
|
-
- Move to Fable when Opus
|
|
40
|
+
- Move to Fable when Opus falls short on a task at the highest effort the [effort levels file](../../hooks/hooks_constants/subagent_effort_levels.json) allows it. The article says "when Opus at high falls short".
|
|
41
41
|
- Move to Fable for long runs with no one watching.
|
|
42
42
|
- Before you move up, follow the [escalation ladder](escalation.md).
|
|
43
43
|
|
|
@@ -6,6 +6,7 @@ The SessionStart hook `hooks/session/working_style_prompt.py` points every sessi
|
|
|
6
6
|
|
|
7
7
|
- Document each task in a location that remains easy to find later.
|
|
8
8
|
- Keep a running scratch text ledger as you work.
|
|
9
|
+
- Keep each task list subject to 80 characters or fewer, start it with who acts (Me, You, or Handed off), and say what is left; put detail in the description.
|
|
9
10
|
|
|
10
11
|
## Presentation
|
|
11
12
|
|
|
@@ -6,6 +6,12 @@ Full text behind [`rules/question-presentation.md`](../../rules/question-present
|
|
|
6
6
|
|
|
7
7
|
The user may see only the question dialog or the closing line of a reply. Each time a question stays open, send it through the question tool again, with the context inside the question text and each option's effect in its description. A closing line that repeats the question reaches the user with no brief. The `final_reply_gate.py` Stop hook blocks a reply whose last paragraph ends with a question mark, or says a question still stands, when the turn sent no question tool call.
|
|
8
8
|
|
|
9
|
+
## Several items, one question at a time
|
|
10
|
+
|
|
11
|
+
When the user has several items to review or decide, such as test cases, findings, or a plan's steps, do not post the list in chat and ask about it as a whole. Send the first item through the question tool with a short brief: its context and each choice's effect. Send the next item after the user answers. A long list in chat makes the user read everything at once, and the user asked for the items bit by bit.
|
|
12
|
+
|
|
13
|
+
The limit is 450 words and 15 list or table items of chat text before a question, counted from the start of the question's turn. A turn starts at a message the user types, at an answer or refusal of an earlier question, or at the first input after the previous turn ends, so text from an earlier turn never counts. A Stop hook that holds a reply keeps the turn open, so that reply's text counts. Each bullet or numbered line is one item, and each table row below the header is one item. Lines inside a code fence are not items. On Claude, the `question_brief_gate.py` PreToolUse hook refuses an `AskUserQuestion` call past either limit and names the limit it passed. The hook reads only the last 1 MB of the transcript, so a long review followed by more than 1 MB of tool output in the same turn is not seen. The text has already posted by then, so do not repeat it. Shorten the brief to the context and each choice's effect, or split the question and ask about one item now.
|
|
14
|
+
|
|
9
15
|
## Codex visual comparisons
|
|
10
16
|
|
|
11
17
|
For Codex visual comparisons, find Page creation, visualization upload, and Page opening tools. Create the comparison, upload its visualization, and open its Page here before asking. If tools are missing, steps fail, or opening queues, compare in chat before asking. Put inline Visualize references only in final replies. An async acknowledgement or saved visual is context only; wait for and use the submitted answer before dependent work.
|
|
@@ -6,7 +6,7 @@ Back to the [rules index](../../rules/index.md).
|
|
|
6
6
|
|
|
7
7
|
Keep the title's status current. Set `<emoji> <name>` when the status changes. Set the hourglass when a new ask starts work. Use the red flag when the user must act, the construction sign when an outside dependency blocks the work, the check mark when the work is done, and the hourglass while work, CI, or a merge queue runs. The name has 25 characters or fewer, in sentence case, with concrete nouns and no IDs, dates, or branch names.
|
|
8
8
|
|
|
9
|
-
**Enforcement:** `hooks/blocking/session_title_format_gate.py` denies a malformed title. `hooks/
|
|
9
|
+
**Enforcement:** `hooks/blocking/session_title_format_gate.py` denies a malformed title. `hooks/session/tracking_nudge.py` adds a quiet note to a new ask when the title is missing or stale.
|
|
10
10
|
|
|
11
11
|
**When this applies:** The session has a tool whose name ends in `__set_session_title`, such as `mcp__claude-code-remote__set_session_title` in a cloud session or `mcp__ccd_session_mgmt__set_session_title` in the desktop app.
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ Keep the title's status current. Set `<emoji> <name>` when the status changes. S
|
|
|
14
14
|
|
|
15
15
|
Set the title to `<emoji> <name>` when the session's status changes, at any point in a turn. A title that still fits needs no new call. When a new ask arrives while the title shows the red flag or the check mark, set the hourglass before other work, so the user sees the session working. Get the session id from `get_session` with no `session_id` when the tool asks for one.
|
|
16
16
|
|
|
17
|
-
Set the title before the final reply, and set it in silence. The reply to the user carries no mention of the title, its emoji, or the reminder that asked for it.
|
|
17
|
+
Set the title before the final reply, and set it in silence. The reply to the user carries no mention of the title, its emoji, or the reminder that asked for it.
|
|
18
18
|
|
|
19
19
|
## Status emoji
|
|
20
20
|
|
|
@@ -33,13 +33,12 @@ The name has 25 characters or fewer and names the main change or outcome in conc
|
|
|
33
33
|
|
|
34
34
|
`hooks/blocking/session_title_format_gate.py` denies a malformed title.
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
No hook holds the end of a turn for the title.
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
- The red flag shows, and the prompt that started the turn asks for work.
|
|
40
|
-
- The check mark shows, and the task list has open items.
|
|
41
|
-
- The hourglass shows, and every task list item is completed or deleted.
|
|
38
|
+
`hooks/session/tracking_nudge.py` runs when the user sends a prompt. It adds a quiet note when the prompt asks for work:
|
|
42
39
|
|
|
43
|
-
|
|
40
|
+
- The title shows the red flag or the check mark. The note names that title and asks for the hourglass before other work.
|
|
41
|
+
- The session has no title yet. The note names the title tool and asks for `⏳ <name>` before other work. It shows at most once in a session, compactions included.
|
|
42
|
+
- The title shows the hourglass or the construction sign. No note.
|
|
44
43
|
|
|
45
|
-
|
|
44
|
+
The note never blocks. It applies when the transcript shows the title tool. A cloud session lists the tool only partway through its first turn, so the no title note can come on the second ask.
|
|
@@ -4,36 +4,36 @@ Back to the [rules index](../../rules/index.md).
|
|
|
4
4
|
|
|
5
5
|
## In brief
|
|
6
6
|
|
|
7
|
-
Every agent you start runs on an Anthropic model at an allowed effort.
|
|
7
|
+
Every agent you start runs on an Anthropic model at an allowed effort. The allowed efforts for each model are in [`subagent_effort_levels.json`](../../hooks/hooks_constants/subagent_effort_levels.json). Name the model and the effort on every spawn.
|
|
8
8
|
|
|
9
9
|
**When this applies:** Every time one agent starts another on a Claude host. That covers the Agent and Task tools, a thread or session spawn, a Workflow agent, an advisor bind, and a headless `claude -p` run.
|
|
10
10
|
|
|
11
11
|
## Allowed pairs
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
[`subagent_effort_levels.json`](../../hooks/hooks_constants/subagent_effort_levels.json) is the file to edit for the allowed pairs. For each model family it lists the `allowed` efforts and the `default` effort a spawn gets when it names none or names one outside the list. The effort route hooks and the second-account worker read it on every run.
|
|
14
|
+
|
|
15
|
+
Edit the file by hand when models or their best effort levels change:
|
|
16
|
+
|
|
17
|
+
- Edit the repository copy, `packages/claude-dev-env/hooks/hooks_constants/subagent_effort_levels.json`, then reinstall. Each install writes the repository copy over the installed copy in `~/.claude/hooks/hooks_constants/`, so an edit made only there is lost at the next install.
|
|
18
|
+
- `ALL_BUILT_IN_EFFORT_LEVELS_BY_FAMILY` in `hooks_constants/subagent_effort_route_constants.py` is the fallback copy the hooks use when the file cannot be read. Copy each edit there too. A test fails while the two differ.
|
|
19
|
+
- Use only the efforts `low`, `medium`, `high`, `xhigh` and `max`, keep the opus, sonnet, fable and haiku families, and put each `default` in its own `allowed` list. A file that breaks any of these, or that does not parse, writes one line to stderr that names the file and the fault, and the hooks use the built-in levels.
|
|
19
20
|
|
|
20
21
|
- Use Anthropic models only.
|
|
21
|
-
-
|
|
22
|
-
- Any pair outside the table is out.
|
|
22
|
+
- Any pair the file does not allow is out.
|
|
23
23
|
- One exception: an advisor that is not the built-in advisor tool runs on Opus at high. The built-in advisor follows the `advisorModel` setting.
|
|
24
24
|
|
|
25
25
|
Codex spawns follow their own policy in [Automatic child model choices](../subagent-model-routing.md).
|
|
26
26
|
|
|
27
27
|
## Rule
|
|
28
28
|
|
|
29
|
-
- Name both the model and the effort. A spawn that leaves either one out takes the parent's, and
|
|
30
|
-
- A fork always takes its parent's model and effort. Fork only from a parent whose own pair
|
|
29
|
+
- Name both the model and the effort. A spawn that leaves either one out takes the parent's, and the effort route hook then moves an effort outside the file to that model's default.
|
|
30
|
+
- A fork always takes its parent's model and effort. Fork only from a parent whose own pair the file allows.
|
|
31
31
|
- For `claude -p`, pass the pair as flags, such as `--model claude-opus-5-5 --effort medium` or `--model claude-sonnet-5-5 --effort high`.
|
|
32
|
-
- When a brief, skill, hook, setting or default gives a pair
|
|
32
|
+
- When a brief, skill, hook, setting or default gives a pair the file does not allow, use an allowed pair for that model and say so in your report.
|
|
33
33
|
|
|
34
34
|
## Which model gets which work
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
Pick the model by the work, then an effort the file allows for it.
|
|
37
37
|
|
|
38
38
|
- Haiku: finding files, reading logs, running tests, summing up, and sorting or pulling data out of many items. A Haiku mistake is cheap to spot.
|
|
39
39
|
- Sonnet: well-scoped work, such as a bug fix or a feature built to a clear spec.
|
|
@@ -14,8 +14,7 @@ block to the agent's context::
|
|
|
14
14
|
3. Babysit. Follow the pstack babysit playbook ...
|
|
15
15
|
4. Ship. Follow the pstack shipping playbook ...
|
|
16
16
|
|
|
17
|
-
Each reported pull request also goes into the session record
|
|
18
|
-
pull request Stop gate holds the turn until it merges.
|
|
17
|
+
Each reported pull request also goes into the session record.
|
|
19
18
|
|
|
20
19
|
The pull request URL in the tool response is the proof that a pull request
|
|
21
20
|
opened, so the hook needs no network call and reads the same on Claude Code
|
|
@@ -395,7 +394,7 @@ def main() -> None:
|
|
|
395
394
|
"""Add the review-loop instructions after a pull request opens on an owned repository.
|
|
396
395
|
|
|
397
396
|
Reads the PostToolUse payload from stdin. The pull request also goes into
|
|
398
|
-
the session record
|
|
397
|
+
the session record. Every quiet branch returns with
|
|
399
398
|
no output, so this hook can never alter or block a tool call.
|
|
400
399
|
"""
|
|
401
400
|
hook_payload = read_hook_input_dictionary_from_stdin()
|
|
@@ -19,7 +19,9 @@ roster unconditionally and never blocks. The one thing it forwards is context:
|
|
|
19
19
|
a hosted hook may print a ``hookSpecificOutput.additionalContext`` string (the
|
|
20
20
|
PR done reminder does), and the dispatcher joins every such string into one
|
|
21
21
|
PostToolUse payload through the shared emitter every PostToolUse hook here
|
|
22
|
-
writes with. A hook that prints nothing adds nothing.
|
|
22
|
+
writes with. A hook that prints nothing adds nothing. A hosted hook that
|
|
23
|
+
exits 2 makes the dispatcher exit 2 after the whole roster runs, and on
|
|
24
|
+
PostToolUse the host then shows that hook's stderr to the model.
|
|
23
25
|
|
|
24
26
|
A single hosted hook crash fails open: ``run_hook_capturing_output`` isolates
|
|
25
27
|
it, so it contributes nothing and does not stop the remaining hosted hooks.
|
|
@@ -45,6 +47,8 @@ from hooks_constants.hook_specific_output_keys import (
|
|
|
45
47
|
from hooks_constants.post_tool_use_context import write_post_tool_use_context_to_stdout
|
|
46
48
|
from hooks_constants.bash_pre_tool_use_dispatcher_constants import BashHostedHookEntry
|
|
47
49
|
from hooks_constants.hosted_hook_runner import (
|
|
50
|
+
HostedHookRun,
|
|
51
|
+
host_exit_code,
|
|
48
52
|
run_hook_capturing_output,
|
|
49
53
|
resolved_hook_script_path,
|
|
50
54
|
run_dispatcher_main,
|
|
@@ -83,26 +87,30 @@ def additional_context_from_hook_output(captured_stdout: str) -> str | None:
|
|
|
83
87
|
return additional_context
|
|
84
88
|
|
|
85
89
|
|
|
86
|
-
def dispatch(payload_text: str, tool_name: str) ->
|
|
87
|
-
"""Run every hosted hook applicable to tool_name,
|
|
90
|
+
def dispatch(payload_text: str, tool_name: str) -> int:
|
|
91
|
+
"""Run every hosted hook applicable to tool_name, forward their context, and return the exit code.
|
|
88
92
|
|
|
89
93
|
Each hosted hook's crash is isolated by ``run_hook_capturing_output``, so
|
|
90
94
|
one hook failing never stops a later one in the same roster. Every
|
|
91
95
|
additionalContext string the hooks printed is joined into one PostToolUse
|
|
92
|
-
payload on stdout; when no hook printed one, nothing is written.
|
|
96
|
+
payload on stdout; when no hook printed one, nothing is written. Returns 2
|
|
97
|
+
when a hosted hook exited 2, so the host shows that hook's stderr to the
|
|
98
|
+
model, and 0 otherwise.
|
|
93
99
|
"""
|
|
100
|
+
all_runs: list[HostedHookRun] = []
|
|
94
101
|
all_additional_context: list[str] = []
|
|
95
102
|
for each_entry in select_applicable_entries(tool_name):
|
|
96
103
|
script_path = resolved_hook_script_path(each_entry.script_relative_path)
|
|
97
104
|
hook_run = run_hook_capturing_output(script_path, payload_text)
|
|
105
|
+
all_runs.append(hook_run)
|
|
98
106
|
additional_context = additional_context_from_hook_output(hook_run.captured_stdout)
|
|
99
107
|
if additional_context is not None:
|
|
100
108
|
all_additional_context.append(additional_context)
|
|
101
|
-
if
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
)
|
|
109
|
+
if all_additional_context:
|
|
110
|
+
write_post_tool_use_context_to_stdout(
|
|
111
|
+
ADDITIONAL_CONTEXT_JOIN_SEPARATOR.join(all_additional_context)
|
|
112
|
+
)
|
|
113
|
+
return host_exit_code(all_runs)
|
|
106
114
|
|
|
107
115
|
|
|
108
116
|
def main() -> None:
|
|
@@ -11,6 +11,8 @@ A deny short-circuits the remaining chain: once any hosted hook denies, the
|
|
|
11
11
|
dispatcher aggregates what has run so far, emits that deny immediately, and
|
|
12
12
|
returns so a later process timeout cannot drop an already-known denial. Ask and
|
|
13
13
|
allow continue through the full roster because a later hook may still deny.
|
|
14
|
+
A hosted hook that exits 2 short-circuits the chain the same way, and the
|
|
15
|
+
dispatcher exits 2, so the host blocks the tool call with that hook's stderr.
|
|
14
16
|
|
|
15
17
|
A single hosted hook crash fails open: it contributes no decision and does not
|
|
16
18
|
stop the remaining hooks, matching a standalone hook whose uncaught exception
|
|
@@ -36,6 +38,7 @@ from hooks_constants.bash_pre_tool_use_dispatcher_constants import (
|
|
|
36
38
|
BashHostedHookEntry,
|
|
37
39
|
)
|
|
38
40
|
from hooks_constants.hosted_hook_runner import (
|
|
41
|
+
host_exit_code,
|
|
39
42
|
run_dispatcher_main,
|
|
40
43
|
run_hook_capturing_output,
|
|
41
44
|
HostedHookRun,
|
|
@@ -251,11 +254,13 @@ def _run_is_deny(hook_run: HostedHookRun) -> bool:
|
|
|
251
254
|
return parsed_decision.decision == DENY_DECISION
|
|
252
255
|
|
|
253
256
|
|
|
254
|
-
def dispatch(payload_text: str, tool_name: str) ->
|
|
255
|
-
"""Run applicable hosted hooks
|
|
257
|
+
def dispatch(payload_text: str, tool_name: str) -> int:
|
|
258
|
+
"""Run applicable hosted hooks, emit the aggregated decision, and return the exit code.
|
|
256
259
|
|
|
257
|
-
Emits and returns as soon as any hosted hook denies so a
|
|
258
|
-
later in the chain cannot fail-open past an already-known
|
|
260
|
+
Emits and returns as soon as any hosted hook denies or exits 2, so a
|
|
261
|
+
process timeout later in the chain cannot fail-open past an already-known
|
|
262
|
+
denial. Returns 2 when a hosted hook exited 2, so the host blocks the call
|
|
263
|
+
with that hook's stderr, and 0 otherwise.
|
|
259
264
|
"""
|
|
260
265
|
applicable_entries = select_applicable_entries(tool_name)
|
|
261
266
|
all_runs: list[HostedHookRun] = []
|
|
@@ -263,12 +268,11 @@ def dispatch(payload_text: str, tool_name: str) -> None:
|
|
|
263
268
|
script_path = resolved_hook_script_path(each_entry.script_relative_path)
|
|
264
269
|
hook_run = run_hook_capturing_output(script_path, payload_text)
|
|
265
270
|
all_runs.append(hook_run)
|
|
266
|
-
if _run_is_deny(hook_run):
|
|
267
|
-
|
|
268
|
-
_emit_decision(aggregated_decision)
|
|
269
|
-
return
|
|
271
|
+
if _run_is_deny(hook_run) or host_exit_code([hook_run]):
|
|
272
|
+
break
|
|
270
273
|
aggregated_decision = aggregate_bash_hook_results(all_runs)
|
|
271
274
|
_emit_decision(aggregated_decision)
|
|
275
|
+
return host_exit_code(all_runs)
|
|
272
276
|
|
|
273
277
|
|
|
274
278
|
def main() -> None:
|