claude-dev-env 8.124.0 → 8.126.0
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 +1 -0
- package/bin/ever-registered-hooks.test.mjs +4 -0
- package/bin/install-constants.mjs +5 -0
- package/bin/install-constants.test.mjs +29 -0
- package/bin/install.mjs +15 -15
- package/bin/install.test.mjs +6 -2
- package/bin/profile-stop-gate.mjs +99 -70
- package/bin/profile-stop-gate.test.mjs +230 -12
- package/docs/agents-guidance/asks.md +1 -1
- package/docs/rule-guides/question-presentation.md +1 -1
- package/hooks/blocking/closing_reply_judge.py +332 -0
- package/hooks/blocking/closing_reply_shapes.py +365 -0
- package/hooks/blocking/conftest.py +84 -0
- package/hooks/blocking/open_tasks_stop_gate.py +247 -10
- package/hooks/blocking/open_tasks_transcript.py +25 -2
- package/hooks/blocking/open_tasks_transcript_records.py +10 -0
- package/hooks/blocking/question_brief_gate.py +6 -4
- package/hooks/blocking/test_closing_reply_judge.py +246 -0
- package/hooks/blocking/test_closing_reply_shapes.py +247 -0
- package/hooks/blocking/test_open_tasks_stop_gate.py +562 -0
- package/hooks/blocking/test_open_tasks_transcript.py +23 -0
- package/hooks/blocking/test_open_tasks_transcript_records.py +14 -0
- package/hooks/blocking/test_question_brief_gate.py +22 -0
- package/hooks/features/conduct-gates.md +7 -3
- package/hooks/hooks.json +6 -1
- package/hooks/hooks_constants/closing_reply_judge_constants.py +143 -0
- package/hooks/hooks_constants/open_tasks_stop_gate_constants.py +93 -0
- package/hooks/hooks_constants/test_hook_time_budget.py +7 -0
- package/hooks/once_per_session.py +65 -1
- package/hooks/test_once_per_session.py +35 -0
- package/package.json +1 -1
- package/scripts/gh_artifact_upload.py +3 -3
- package/scripts/policy_lint/adapter_configuration.py +6 -0
- package/scripts/policy_lint/config/constants.py +1 -0
- package/scripts/tests/test_adapter_configuration.py +8 -0
- package/scripts/tests/test_gh_artifact_upload.py +18 -0
|
@@ -23,6 +23,7 @@ export const EVER_REGISTERED_HOOK_RELATIVE_PATHS = new Set([
|
|
|
23
23
|
'blocking/build_eval_before_eval_write_gate.py',
|
|
24
24
|
'blocking/chat_reply_gate.py',
|
|
25
25
|
'blocking/claude_md_orphan_file_blocker.py',
|
|
26
|
+
'blocking/closing_question_round_gate.py',
|
|
26
27
|
'blocking/code-rules-enforcer.py',
|
|
27
28
|
'blocking/code_review_pr_create_gate.py',
|
|
28
29
|
'blocking/code_rules_enforcer.py',
|
|
@@ -24,6 +24,10 @@ test('EVER_REGISTERED_HOOK_RELATIVE_PATHS keeps the question brief gate', () =>
|
|
|
24
24
|
assert.ok(EVER_REGISTERED_HOOK_RELATIVE_PATHS.has('blocking/question_brief_gate.py'));
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
+
test('EVER_REGISTERED_HOOK_RELATIVE_PATHS keeps the closing question round gate', () => {
|
|
28
|
+
assert.ok(EVER_REGISTERED_HOOK_RELATIVE_PATHS.has('blocking/closing_question_round_gate.py'));
|
|
29
|
+
});
|
|
30
|
+
|
|
27
31
|
test('EVER_REGISTERED_HOOK_RELATIVE_PATHS keeps the artifact current page gate and its link record', () => {
|
|
28
32
|
assert.ok(EVER_REGISTERED_HOOK_RELATIVE_PATHS.has('blocking/artifact_current_page_gate.py'));
|
|
29
33
|
assert.ok(EVER_REGISTERED_HOOK_RELATIVE_PATHS.has('session/artifact_link_record.py'));
|
|
@@ -192,6 +192,11 @@ export const CURSOR_HOOKS_SCHEMA_VERSION = 1;
|
|
|
192
192
|
export const CURSOR_HOOK_TIMEOUT_SECONDS = 10;
|
|
193
193
|
export const CURSOR_GUIDANCE_HOOK_RELATIVE_PATH = Object.freeze(['session', 'cursor_agents_guidance.py']);
|
|
194
194
|
export const CURSOR_OPEN_TASKS_HOOK_RELATIVE_PATH = Object.freeze(['blocking', 'open_tasks_stop_gate.py']);
|
|
195
|
+
export const CLOSING_QUESTION_ROUND_HOOK_RELATIVE_PATH = Object.freeze(['blocking', 'closing_question_round_gate.py']);
|
|
196
|
+
export const ALL_PROFILE_STOP_GATE_HOOK_RELATIVE_PATHS = Object.freeze([
|
|
197
|
+
CURSOR_OPEN_TASKS_HOOK_RELATIVE_PATH,
|
|
198
|
+
CLOSING_QUESTION_ROUND_HOOK_RELATIVE_PATH,
|
|
199
|
+
]);
|
|
195
200
|
export const CURSOR_SESSION_START_EVENT = 'sessionStart';
|
|
196
201
|
export const CURSOR_BEFORE_SUBMIT_PROMPT_EVENT = 'beforeSubmitPrompt';
|
|
197
202
|
export const CURSOR_STOP_EVENT = 'stop';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { strict as assert } from 'node:assert';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {
|
|
7
|
+
ALL_PROFILE_STOP_GATE_HOOK_RELATIVE_PATHS,
|
|
8
|
+
CLOSING_QUESTION_ROUND_HOOK_RELATIVE_PATH,
|
|
9
|
+
CURSOR_OPEN_TASKS_HOOK_RELATIVE_PATH,
|
|
10
|
+
} from './install-constants.mjs';
|
|
11
|
+
|
|
12
|
+
const HOOKS_DIRECTORY = fileURLToPath(new URL('../hooks', import.meta.url));
|
|
13
|
+
|
|
14
|
+
test('ALL_PROFILE_STOP_GATE_HOOK_RELATIVE_PATHS should list the open tasks gate, then the closing question round gate', () => {
|
|
15
|
+
assert.deepEqual(ALL_PROFILE_STOP_GATE_HOOK_RELATIVE_PATHS, [
|
|
16
|
+
CURSOR_OPEN_TASKS_HOOK_RELATIVE_PATH,
|
|
17
|
+
CLOSING_QUESTION_ROUND_HOOK_RELATIVE_PATH,
|
|
18
|
+
]);
|
|
19
|
+
assert.deepEqual(CLOSING_QUESTION_ROUND_HOOK_RELATIVE_PATH, ['blocking', 'closing_question_round_gate.py']);
|
|
20
|
+
assert.ok(Object.isFrozen(ALL_PROFILE_STOP_GATE_HOOK_RELATIVE_PATHS));
|
|
21
|
+
assert.ok(Object.isFrozen(CLOSING_QUESTION_ROUND_HOOK_RELATIVE_PATH));
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('each profile Stop gate path should name a hook script the package ships', () => {
|
|
25
|
+
const allMissingPaths = ALL_PROFILE_STOP_GATE_HOOK_RELATIVE_PATHS.map(
|
|
26
|
+
relativeParts => path.join(HOOKS_DIRECTORY, ...relativeParts),
|
|
27
|
+
).filter(scriptPath => !existsSync(scriptPath));
|
|
28
|
+
assert.deepEqual(allMissingPaths, []);
|
|
29
|
+
});
|
package/bin/install.mjs
CHANGED
|
@@ -146,9 +146,9 @@ import {
|
|
|
146
146
|
} from './install-transaction.mjs';
|
|
147
147
|
import { findShadowingGlobalInstall, shadowingGlobalAdvice } from './global-install-shadow.mjs';
|
|
148
148
|
import {
|
|
149
|
-
|
|
149
|
+
addStopGatesToProfiles,
|
|
150
150
|
otherProfileSettingsPaths,
|
|
151
|
-
|
|
151
|
+
removeStopGatesFromProfiles,
|
|
152
152
|
splitUnreadableProfileSettings,
|
|
153
153
|
unparsedSettingsMayHoldGate,
|
|
154
154
|
} from './profile-stop-gate.mjs';
|
|
@@ -2876,10 +2876,10 @@ function install(selectedGroups, options = {}) {
|
|
|
2876
2876
|
}
|
|
2877
2877
|
|
|
2878
2878
|
/**
|
|
2879
|
-
* List the profile settings paths that get the open
|
|
2879
|
+
* List the profile settings paths that get the open tasks and closing question round Stop gates.
|
|
2880
2880
|
*
|
|
2881
|
-
* Only an install into the main ~/.claude does this, because
|
|
2882
|
-
* names the main home
|
|
2881
|
+
* Only an install into the main ~/.claude does this, because each gate entry
|
|
2882
|
+
* names a hook script in the main home.
|
|
2883
2883
|
*
|
|
2884
2884
|
* @param {string} mainSettingsPath
|
|
2885
2885
|
* @returns {string[]}
|
|
@@ -2901,7 +2901,7 @@ function readableProfileSettingsPathsForStopGate(mainSettingsPath) {
|
|
|
2901
2901
|
);
|
|
2902
2902
|
for (const { settingsPath, reason } of allUnreadable) {
|
|
2903
2903
|
const actionLine = `Profile settings: ${settingsPath} was left unchanged because it is not valid JSON (${reason}).`
|
|
2904
|
-
+ ' Fix the file and run the install again to add the open
|
|
2904
|
+
+ ' Fix the file and run the install again to add the open tasks and closing question round Stop gates there.';
|
|
2905
2905
|
console.warn(` ${actionLine}`);
|
|
2906
2906
|
allActionNeededLines.push(actionLine);
|
|
2907
2907
|
}
|
|
@@ -2909,12 +2909,12 @@ function readableProfileSettingsPathsForStopGate(mainSettingsPath) {
|
|
|
2909
2909
|
}
|
|
2910
2910
|
|
|
2911
2911
|
/**
|
|
2912
|
-
* Return the profile settings the uninstall removes the
|
|
2912
|
+
* Return the profile settings the uninstall removes the gates from, or the reason it must stop first.
|
|
2913
2913
|
*
|
|
2914
|
-
* A profile file that does not parse and may still hold
|
|
2914
|
+
* A profile file that does not parse and may still hold a gate stops the
|
|
2915
2915
|
* uninstall before it changes anything. The manifest then stays, so running
|
|
2916
|
-
* --uninstall again after fixing the file removes the
|
|
2917
|
-
* not parse and
|
|
2916
|
+
* --uninstall again after fixing the file removes the gates. A file that does
|
|
2917
|
+
* not parse and names neither gate has nothing to remove and is left as
|
|
2918
2918
|
* it is.
|
|
2919
2919
|
*
|
|
2920
2920
|
* @param {string} mainSettingsPath
|
|
@@ -2930,7 +2930,7 @@ function profileSettingsPathsForGateRemoval(mainSettingsPath) {
|
|
|
2930
2930
|
if (allHoldingGate.length === 0) return { allReadablePaths, blockingReason: null };
|
|
2931
2931
|
const fileLines = allHoldingGate.map(({ settingsPath, reason }) => ` ${settingsPath}: not valid JSON (${reason})`);
|
|
2932
2932
|
const blockingReason = [
|
|
2933
|
-
'ERROR: uninstall stopped before changing anything. These profile settings files still name the open
|
|
2933
|
+
'ERROR: uninstall stopped before changing anything. These profile settings files still name the open tasks or closing question round Stop gate, and they are not valid JSON, so the gates cannot be removed from them:',
|
|
2934
2934
|
...fileLines,
|
|
2935
2935
|
'Fix each file and run --uninstall again.',
|
|
2936
2936
|
].join('\n');
|
|
@@ -3435,14 +3435,14 @@ function executeInstallPlanMutations(plan, transactionHelpers) {
|
|
|
3435
3435
|
for (const eachLine of describeProfileSettingsOutcome(mergeOutcome, false)) {
|
|
3436
3436
|
console.log(` Profile settings: ${eachLine}`);
|
|
3437
3437
|
}
|
|
3438
|
-
for (const eachOutcome of
|
|
3438
|
+
for (const eachOutcome of addStopGatesToProfiles({
|
|
3439
3439
|
mainSettingsPath: join(CLAUDE_HOME, SETTINGS_FILE_NAME),
|
|
3440
3440
|
claudeHome: CLAUDE_HOME,
|
|
3441
3441
|
allProfileSettingsPaths: readableProfileSettingsPathsForStopGate(join(CLAUDE_HOME, SETTINGS_FILE_NAME)),
|
|
3442
3442
|
homeDirectory: homedir(),
|
|
3443
3443
|
})) {
|
|
3444
3444
|
if (eachOutcome.additions.length > 0) {
|
|
3445
|
-
console.log(` Profile settings:
|
|
3445
|
+
console.log(` Profile settings: Stop gates added to ${eachOutcome.settingsPath}`);
|
|
3446
3446
|
}
|
|
3447
3447
|
}
|
|
3448
3448
|
|
|
@@ -3732,11 +3732,11 @@ function executeUninstallPlan(plan, helpers = {}) {
|
|
|
3732
3732
|
writeFileAtomically(plan.settingsPath, JSON.stringify(settings, null, 4) + '\n');
|
|
3733
3733
|
}
|
|
3734
3734
|
}
|
|
3735
|
-
for (const eachChangedPath of
|
|
3735
|
+
for (const eachChangedPath of removeStopGatesFromProfiles({
|
|
3736
3736
|
claudeHome: CLAUDE_HOME,
|
|
3737
3737
|
allProfileSettingsPaths: helpers.allProfileSettingsPaths,
|
|
3738
3738
|
})) {
|
|
3739
|
-
console.log(` Profile settings:
|
|
3739
|
+
console.log(` Profile settings: Stop gates removed from ${eachChangedPath}`);
|
|
3740
3740
|
}
|
|
3741
3741
|
if (!codexRoutingHookExists()) {
|
|
3742
3742
|
pruneManagedHooksFromHostConfiguration(CODEX_HOOKS_CONFIGURATION_PATH, 2);
|
package/bin/install.test.mjs
CHANGED
|
@@ -3933,7 +3933,7 @@ test('install prints no Action needed block when every side step finished', (con
|
|
|
3933
3933
|
assert.equal(result.stderr.includes('Action needed'), false, result.stderr);
|
|
3934
3934
|
});
|
|
3935
3935
|
|
|
3936
|
-
test('install adds the open
|
|
3936
|
+
test('install adds the open tasks and closing question round Stop gates to every profile with its own settings.json, and uninstall removes both', (context) => {
|
|
3937
3937
|
const homeDirectory = mkdtempSync(join(tmpdir(), 'cde-profile-gate-install-'));
|
|
3938
3938
|
context.after(() => rmSync(homeDirectory, { recursive: true, force: true }));
|
|
3939
3939
|
const profileSettingsPath = join(homeDirectory, '.claude-profiles', 'prefs-only', 'settings.json');
|
|
@@ -3966,7 +3966,11 @@ test('install adds the open-tasks Stop gate to every profile with its own settin
|
|
|
3966
3966
|
|
|
3967
3967
|
const installation = runInstaller([]);
|
|
3968
3968
|
assert.equal(installation.status, 0, installation.stderr);
|
|
3969
|
-
assert.
|
|
3969
|
+
assert.deepEqual(
|
|
3970
|
+
profileStopCommands().map((eachCommand) => eachCommand.replace(/\\/g, '/').split('/').pop()),
|
|
3971
|
+
['open_tasks_stop_gate.py', 'closing_question_round_gate.py'],
|
|
3972
|
+
);
|
|
3973
|
+
assert.ok(installation.stdout.includes(`Profile settings: Stop gates added to ${profileSettingsPath}`), installation.stdout);
|
|
3970
3974
|
|
|
3971
3975
|
const uninstallation = runInstaller(['--uninstall']);
|
|
3972
3976
|
assert.equal(uninstallation.status, 0, uninstallation.stderr);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { ALL_PROFILE_STOP_GATE_HOOK_RELATIVE_PATHS } from './install-constants.mjs';
|
|
5
5
|
import {
|
|
6
6
|
discoverProfileSettingsPaths,
|
|
7
7
|
hostConfigurationIndent,
|
|
@@ -28,36 +28,52 @@ function comparableCommand(command) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* Return
|
|
31
|
+
* Return one gate script's path under a Claude home, in the spelling hook commands compare by.
|
|
32
32
|
*
|
|
33
33
|
* @param {string} claudeHome
|
|
34
|
+
* @param {readonly string[]} hookRelativePath The script's path segments under the hooks directory.
|
|
34
35
|
* @returns {string}
|
|
35
36
|
*/
|
|
36
|
-
export function gateScriptCommandFragment(claudeHome) {
|
|
37
|
-
return comparableCommand(join(claudeHome, MANAGED_HOOKS_DIRECTORY_NAME, ...
|
|
37
|
+
export function gateScriptCommandFragment(claudeHome, hookRelativePath) {
|
|
38
|
+
return comparableCommand(join(claudeHome, MANAGED_HOOKS_DIRECTORY_NAME, ...hookRelativePath));
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
function isGateHook(eachHook, claudeHome) {
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
function isGateHook(eachHook, claudeHome, allHookRelativePaths = ALL_PROFILE_STOP_GATE_HOOK_RELATIVE_PATHS) {
|
|
42
|
+
if (typeof eachHook?.command !== 'string') return false;
|
|
43
|
+
const command = comparableCommand(eachHook.command);
|
|
44
|
+
return allHookRelativePaths.some(
|
|
45
|
+
(eachRelativePath) => command.includes(gateScriptCommandFragment(claudeHome, eachRelativePath)),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function stopHooks(settingsPath) {
|
|
50
|
+
const settingsText = readFileSync(settingsPath, 'utf8');
|
|
51
|
+
if (!settingsText.trim()) return [];
|
|
52
|
+
const settings = JSON.parse(settingsText);
|
|
53
|
+
const stopGroups = settings?.hooks?.[STOP_EVENT_NAME];
|
|
54
|
+
if (!Array.isArray(stopGroups)) return [];
|
|
55
|
+
return stopGroups.flatMap((eachGroup) => (Array.isArray(eachGroup?.hooks) ? eachGroup.hooks : []));
|
|
43
56
|
}
|
|
44
57
|
|
|
45
58
|
/**
|
|
46
|
-
* Find
|
|
59
|
+
* Find each profile Stop gate hook the install wrote into the main settings.
|
|
60
|
+
*
|
|
61
|
+
* The gates come back in the order of ALL_PROFILE_STOP_GATE_HOOK_RELATIVE_PATHS.
|
|
62
|
+
* A gate the main settings do not hold is left out.
|
|
47
63
|
*
|
|
48
64
|
* @param {string} mainSettingsPath
|
|
49
65
|
* @param {string} claudeHome
|
|
50
|
-
* @returns {Record<string, unknown
|
|
66
|
+
* @returns {{ hookRelativePath: readonly string[], gateHook: Record<string, unknown> }[]} A copy of each hook entry.
|
|
51
67
|
*/
|
|
52
|
-
export function
|
|
53
|
-
if (!existsSync(mainSettingsPath)) return
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
68
|
+
export function mainStopGateHooks(mainSettingsPath, claudeHome) {
|
|
69
|
+
if (!existsSync(mainSettingsPath)) return [];
|
|
70
|
+
const allMainStopHooks = stopHooks(mainSettingsPath);
|
|
71
|
+
const allMainGates = [];
|
|
72
|
+
for (const eachRelativePath of ALL_PROFILE_STOP_GATE_HOOK_RELATIVE_PATHS) {
|
|
73
|
+
const gateHook = allMainStopHooks.find((eachHook) => isGateHook(eachHook, claudeHome, [eachRelativePath]));
|
|
74
|
+
if (gateHook) allMainGates.push({ hookRelativePath: eachRelativePath, gateHook: structuredClone(gateHook) });
|
|
59
75
|
}
|
|
60
|
-
return
|
|
76
|
+
return allMainGates;
|
|
61
77
|
}
|
|
62
78
|
|
|
63
79
|
/**
|
|
@@ -112,11 +128,11 @@ export function splitUnreadableProfileSettings(allProfileSettingsPaths) {
|
|
|
112
128
|
}
|
|
113
129
|
|
|
114
130
|
/**
|
|
115
|
-
* True when a settings.json that does not parse may still hold this Claude home's
|
|
131
|
+
* True when a settings.json that does not parse may still hold one of this Claude home's profile Stop gates.
|
|
116
132
|
*
|
|
117
|
-
* The raw text is searched for
|
|
133
|
+
* The raw text is searched for each gate script path, with JSON-escaped
|
|
118
134
|
* backslashes read as path separators. A file that cannot be read counts as
|
|
119
|
-
* one that may hold
|
|
135
|
+
* one that may hold a gate.
|
|
120
136
|
*
|
|
121
137
|
* @param {string} settingsPath
|
|
122
138
|
* @param {string} claudeHome
|
|
@@ -129,93 +145,104 @@ export function unparsedSettingsMayHoldGate(settingsPath, claudeHome) {
|
|
|
129
145
|
} catch {
|
|
130
146
|
return true;
|
|
131
147
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const settingsText = readFileSync(settingsPath, 'utf8');
|
|
137
|
-
if (!settingsText.trim()) return [];
|
|
138
|
-
const settings = JSON.parse(settingsText);
|
|
139
|
-
const stopGroups = settings?.hooks?.[STOP_EVENT_NAME];
|
|
140
|
-
if (!Array.isArray(stopGroups)) return [];
|
|
141
|
-
return stopGroups.flatMap((eachGroup) => (Array.isArray(eachGroup?.hooks) ? eachGroup.hooks : []));
|
|
148
|
+
const comparableText = comparableCommand(settingsText.replace(/\\\\/g, '/'));
|
|
149
|
+
return ALL_PROFILE_STOP_GATE_HOOK_RELATIVE_PATHS.some(
|
|
150
|
+
(eachRelativePath) => comparableText.includes(gateScriptCommandFragment(claudeHome, eachRelativePath)),
|
|
151
|
+
);
|
|
142
152
|
}
|
|
143
153
|
|
|
144
|
-
function
|
|
145
|
-
return stopHooks(settingsPath)
|
|
146
|
-
.filter((eachHook) => isGateHook(eachHook, claudeHome))
|
|
147
|
-
.map((eachHook) => eachHook.command);
|
|
154
|
+
function profileGateHooks(settingsPath, claudeHome, hookRelativePath) {
|
|
155
|
+
return stopHooks(settingsPath).filter((eachHook) => isGateHook(eachHook, claudeHome, [hookRelativePath]));
|
|
148
156
|
}
|
|
149
157
|
|
|
150
158
|
/**
|
|
151
|
-
* True when a profile's settings.json already runs
|
|
159
|
+
* True when a profile's settings.json already runs one gate script from another Claude home.
|
|
152
160
|
*
|
|
153
161
|
* An install with CLAUDE_CONFIG_DIR set to the profile writes a gate entry
|
|
154
162
|
* for the profile's own copy of the script, and a second entry for the main
|
|
155
|
-
* home's copy would run
|
|
163
|
+
* home's copy would run that gate twice on every stop.
|
|
156
164
|
*
|
|
157
165
|
* @param {string} settingsPath
|
|
158
166
|
* @param {string} claudeHome
|
|
167
|
+
* @param {readonly string[]} hookRelativePath The gate script's path segments under the hooks directory.
|
|
159
168
|
* @returns {boolean}
|
|
160
169
|
*/
|
|
161
|
-
export function profileRunsItsOwnGate(settingsPath, claudeHome) {
|
|
162
|
-
const scriptPathSuffix = `/${comparableCommand(join(MANAGED_HOOKS_DIRECTORY_NAME, ...
|
|
170
|
+
export function profileRunsItsOwnGate(settingsPath, claudeHome, hookRelativePath) {
|
|
171
|
+
const scriptPathSuffix = `/${comparableCommand(join(MANAGED_HOOKS_DIRECTORY_NAME, ...hookRelativePath))}`;
|
|
163
172
|
return stopHooks(settingsPath).some((eachHook) => typeof eachHook?.command === 'string'
|
|
164
173
|
&& comparableCommand(eachHook.command).includes(scriptPathSuffix)
|
|
165
|
-
&& !isGateHook(eachHook, claudeHome));
|
|
174
|
+
&& !isGateHook(eachHook, claudeHome, [hookRelativePath]));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function staleGateRelativePaths(settingsPath, claudeHome, allWantedGates) {
|
|
178
|
+
return allWantedGates
|
|
179
|
+
.filter(({ hookRelativePath, gateHook }) => profileGateHooks(settingsPath, claudeHome, hookRelativePath)
|
|
180
|
+
.some((eachHook) => eachHook.command !== gateHook.command || eachHook.timeout !== gateHook.timeout))
|
|
181
|
+
.map(({ hookRelativePath }) => hookRelativePath);
|
|
166
182
|
}
|
|
167
183
|
|
|
168
184
|
/**
|
|
169
|
-
* Add the main settings'
|
|
185
|
+
* Add each of the main settings' profile Stop gates to every other profile's settings.json.
|
|
170
186
|
*
|
|
171
|
-
* A profile keeps its own settings and hooks.
|
|
172
|
-
* entry, in the spelling the main settings use,
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
187
|
+
* A profile keeps its own settings and hooks. Each gate is handled on its
|
|
188
|
+
* own. The merge adds a gate entry, in the spelling the main settings use,
|
|
189
|
+
* only where that gate is missing, so a profile that holds one gate gets the
|
|
190
|
+
* other. An entry left with an older interpreter spelling or timeout is replaced. The
|
|
191
|
+
* file as it was before either change is copied to a timestamped `.bak`. A
|
|
192
|
+
* gate the profile already runs from its own copy of the script is left as
|
|
193
|
+
* it is, and so is a gate the main settings do not hold.
|
|
176
194
|
*
|
|
177
195
|
* @param {{ mainSettingsPath: string, claudeHome: string, allProfileSettingsPaths: string[],
|
|
178
196
|
* homeDirectory: string, now?: Date }} options
|
|
179
197
|
* @returns {{ settingsPath: string, additions: string[], backupPath: string|null }[]}
|
|
180
198
|
*/
|
|
181
|
-
export function
|
|
182
|
-
const
|
|
183
|
-
if (!gateHook) return [];
|
|
199
|
+
export function addStopGatesToProfiles(options) {
|
|
200
|
+
const allMainGates = mainStopGateHooks(options.mainSettingsPath, options.claudeHome);
|
|
184
201
|
const timestamp = (options.now ?? new Date()).toISOString().replace(/[:.]/g, '-');
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
202
|
+
const allOutcomes = [];
|
|
203
|
+
for (const eachPath of options.allProfileSettingsPaths) {
|
|
204
|
+
const allWantedGates = allMainGates.filter(
|
|
205
|
+
({ hookRelativePath }) => !profileRunsItsOwnGate(eachPath, options.claudeHome, hookRelativePath),
|
|
206
|
+
);
|
|
207
|
+
if (allWantedGates.length === 0) continue;
|
|
208
|
+
const allStaleRelativePaths = staleGateRelativePaths(eachPath, options.claudeHome, allWantedGates);
|
|
209
|
+
const originalText = readFileSync(eachPath, 'utf8');
|
|
210
|
+
removeStopGatesFromProfiles({
|
|
211
|
+
claudeHome: options.claudeHome,
|
|
212
|
+
allProfileSettingsPaths: [eachPath],
|
|
213
|
+
allHookRelativePaths: allStaleRelativePaths,
|
|
214
|
+
});
|
|
196
215
|
const outcome = mergeProfileSettingsFile(eachPath, {
|
|
197
216
|
dryRun: false,
|
|
198
217
|
homeDirectory: options.homeDirectory,
|
|
199
218
|
timestamp,
|
|
200
|
-
declaredSettings
|
|
219
|
+
declaredSettings: [{
|
|
220
|
+
keyPath: ['hooks', STOP_EVENT_NAME],
|
|
221
|
+
items: allWantedGates.map(({ gateHook }) => ({ hooks: [gateHook] })),
|
|
222
|
+
}],
|
|
201
223
|
});
|
|
202
|
-
if (outcome.backupPath &&
|
|
203
|
-
writeFileSync(outcome.backupPath,
|
|
224
|
+
if (outcome.backupPath && allStaleRelativePaths.length > 0) {
|
|
225
|
+
writeFileSync(outcome.backupPath, originalText);
|
|
204
226
|
}
|
|
205
|
-
|
|
206
|
-
}
|
|
227
|
+
allOutcomes.push(outcome);
|
|
228
|
+
}
|
|
229
|
+
return allOutcomes;
|
|
207
230
|
}
|
|
208
231
|
|
|
209
232
|
/**
|
|
210
|
-
* Remove the gate
|
|
233
|
+
* Remove the gate entries that point at the main Claude home from each listed profile settings path.
|
|
211
234
|
*
|
|
212
|
-
* Only a hook whose command runs the main home's gate
|
|
213
|
-
* group left empty goes too, and so does an emptied Stop list or hooks
|
|
235
|
+
* Only a hook whose command runs one of the main home's gate scripts goes. A
|
|
236
|
+
* Stop group left empty goes too, and so does an emptied Stop list or hooks
|
|
237
|
+
* object.
|
|
214
238
|
*
|
|
215
|
-
* @param {{ claudeHome: string, allProfileSettingsPaths: string[]
|
|
239
|
+
* @param {{ claudeHome: string, allProfileSettingsPaths: string[],
|
|
240
|
+
* allHookRelativePaths?: readonly (readonly string[])[] }} options
|
|
241
|
+
* allHookRelativePaths limits the removal to those gates. Every profile Stop gate goes without it.
|
|
216
242
|
* @returns {string[]} The settings paths that changed.
|
|
217
243
|
*/
|
|
218
|
-
export function
|
|
244
|
+
export function removeStopGatesFromProfiles(options) {
|
|
245
|
+
const allHookRelativePaths = options.allHookRelativePaths ?? ALL_PROFILE_STOP_GATE_HOOK_RELATIVE_PATHS;
|
|
219
246
|
const allChangedPaths = [];
|
|
220
247
|
for (const eachPath of options.allProfileSettingsPaths) {
|
|
221
248
|
const settingsText = readFileSync(eachPath, 'utf8');
|
|
@@ -226,7 +253,9 @@ export function removeOpenTasksGateFromProfiles(options) {
|
|
|
226
253
|
let removedCount = 0;
|
|
227
254
|
for (const eachGroup of stopGroups) {
|
|
228
255
|
if (!Array.isArray(eachGroup?.hooks)) continue;
|
|
229
|
-
const keptHooks = eachGroup.hooks.filter(
|
|
256
|
+
const keptHooks = eachGroup.hooks.filter(
|
|
257
|
+
(eachHook) => !isGateHook(eachHook, options.claudeHome, allHookRelativePaths),
|
|
258
|
+
);
|
|
230
259
|
removedCount += eachGroup.hooks.length - keptHooks.length;
|
|
231
260
|
eachGroup.hooks = keptHooks;
|
|
232
261
|
}
|