feat(install): require an explicit hook decision at the apply layer

The guided installer asks how ECC hooks should run, but that consent
lived only in the wizard path. Running install-apply directly with a
profile that includes hooks-runtime still materialized the hook runtime
with no disclosure and no decision.

Gate the apply layer instead, so every entry point is covered:

- disclose the six hook capability groups when a plan would materialize
  the hook runtime, and refuse to apply until the caller decides
- --enable-hooks confirms the hook runtime; --no-hooks installs the rest
  of the selection without it and records the reduced module closure in
  install-state
- surface the pending decision as a dry-run warning
- show the same capability disclosure in the guided installer's plan
  preview, so the wizard's hook question states what it is asking about

Plans that never materialize hooks (Kimi, --profile minimal,
--without baseline:hooks) are unaffected and need no flag. Repair and
uninstall operate on already-recorded state and stay unchanged.

The capability taxonomy and the held-materialization behavior come from
Samarjeet Singh Tomar's PR #2634, reworked to fit the single-decision
consent model that shipped with the guided installer in #2649.

Co-Authored-By: Samarjeet Singh Tomar <samar_tomar@hotmail.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
haelyra
2026-08-09 17:16:03 -04:00
co-authored by Samarjeet Singh Tomar Claude Fable 5
parent 649def769b
commit f0cea4f3df
14 changed files with 436 additions and 21 deletions
+69 -18
View File
@@ -127,7 +127,7 @@ function runTests() {
const projectDir = createTempDir('install-apply-project-');
try {
const result = run(['typescript'], { cwd: projectDir, homeDir });
const result = run(['typescript', '--enable-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
const claudeRoot = path.join(homeDir, '.claude');
@@ -165,7 +165,7 @@ function runTests() {
const projectDir = createTempDir('install-apply-project-');
try {
const result = run(['typescript'], { cwd: projectDir, homeDir });
const result = run(['typescript', '--enable-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
const claudeRoot = path.join(homeDir, '.claude');
@@ -199,7 +199,7 @@ function runTests() {
const projectDir = createTempDir('install-apply-project-');
try {
const result = run(['--target', 'cursor', 'typescript'], { cwd: projectDir, homeDir });
const result = run(['--target', 'cursor', 'typescript', '--enable-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
assert.ok(fs.existsSync(path.join(projectDir, '.cursor', 'rules', 'common-coding-style.mdc')));
@@ -259,7 +259,7 @@ function runTests() {
},
}, null, 2));
const result = run(['--target', 'cursor', 'typescript'], { cwd: projectDir, homeDir });
const result = run(['--target', 'cursor', 'typescript', '--enable-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
const mcpConfig = readJson(path.join(projectDir, '.cursor', 'mcp.json'));
@@ -460,7 +460,7 @@ function runTests() {
const projectDir = createTempDir('install-apply-project-');
try {
const result = run(['--profile', 'core'], { cwd: projectDir, homeDir });
const result = run(['--profile', 'core', '--enable-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
const claudeRoot = path.join(homeDir, '.claude');
@@ -502,7 +502,7 @@ function runTests() {
fs.writeFileSync(userRulePath, '# User custom rule\n');
fs.writeFileSync(userSkillPath, '# User custom skill\n');
const result = run(['--profile', 'core'], { cwd: projectDir, homeDir });
const result = run(['--profile', 'core', '--enable-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
assert.ok(result.stdout.includes('user-owned'), result.stdout);
assert.ok(result.stdout.includes('Skipped operations:'), result.stdout);
@@ -649,7 +649,7 @@ function runTests() {
const projectDir = createTempDir('install-apply-project-');
try {
const result = run(['--target', 'cursor', '--modules', 'platform-configs'], {
const result = run(['--target', 'cursor', '--modules', 'platform-configs', '--enable-hooks'], {
cwd: projectDir,
homeDir,
});
@@ -686,7 +686,7 @@ function runTests() {
const projectDir = createTempDir('install-apply-project-');
try {
const result = run(['--profile', 'core'], { cwd: projectDir, homeDir });
const result = run(['--profile', 'core', '--enable-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
const claudeRoot = path.join(homeDir, '.claude');
@@ -703,7 +703,7 @@ function runTests() {
const projectDir = createTempDir('install-apply-project-');
try {
const result = run(['--profile', 'core'], { cwd: projectDir, homeDir });
const result = run(['--profile', 'core', '--enable-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
const claudeRoot = path.join(homeDir, '.claude');
@@ -761,7 +761,7 @@ function runTests() {
}, null, 2)
);
const result = run(['--profile', 'core'], { cwd: projectDir, homeDir });
const result = run(['--profile', 'core', '--enable-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
const settings = readJson(path.join(claudeRoot, 'settings.json'));
@@ -862,10 +862,10 @@ function runTests() {
const projectDir = createTempDir('install-apply-project-');
try {
const firstInstall = run(['--profile', 'core'], { cwd: projectDir, homeDir });
const firstInstall = run(['--profile', 'core', '--enable-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(firstInstall.code, 0, firstInstall.stderr);
const secondInstall = run(['--profile', 'core'], { cwd: projectDir, homeDir });
const secondInstall = run(['--profile', 'core', '--enable-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(secondInstall.code, 0, secondInstall.stderr);
assert.ok(!fs.existsSync(path.join(homeDir, '.claude', 'settings.json')));
@@ -890,7 +890,7 @@ function runTests() {
};
fs.writeFileSync(settingsPath, JSON.stringify(legacySettings, null, 2));
const secondInstall = run(['--profile', 'core'], { cwd: projectDir, homeDir });
const secondInstall = run(['--profile', 'core', '--enable-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(secondInstall.code, 0, secondInstall.stderr);
const afterSecondInstall = readJson(settingsPath);
@@ -911,7 +911,7 @@ function runTests() {
const settingsPath = path.join(claudeRoot, 'settings.json');
fs.writeFileSync(settingsPath, '{ invalid json\n');
const result = run(['--profile', 'core'], { cwd: projectDir, homeDir });
const result = run(['--profile', 'core', '--enable-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
assert.strictEqual(fs.readFileSync(settingsPath, 'utf8'), '{ invalid json\n');
assert.ok(fs.existsSync(path.join(claudeRoot, 'hooks', 'hooks.json')), 'hooks.json should still be copied');
@@ -932,7 +932,7 @@ function runTests() {
const settingsPath = path.join(claudeRoot, 'settings.json');
fs.writeFileSync(settingsPath, '[]\n');
const result = run(['--profile', 'core'], { cwd: projectDir, homeDir });
const result = run(['--profile', 'core', '--enable-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
assert.strictEqual(fs.readFileSync(settingsPath, 'utf8'), '[]\n');
assert.ok(fs.existsSync(path.join(claudeRoot, 'hooks', 'hooks.json')), 'hooks.json should still be copied');
@@ -956,6 +956,7 @@ function runTests() {
applyInstallPlan({
targetRoot,
installStatePath,
hookConsent: 'enabled',
statePreview: {
schemaVersion: 'ecc.install.v1',
installedAt: new Date().toISOString(),
@@ -1019,7 +1020,7 @@ function runTests() {
exclude: ['capability:orchestration'],
}, null, 2));
const result = run(['--config', configPath], { cwd: projectDir, homeDir });
const result = run(['--config', configPath, '--enable-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
assert.ok(fs.existsSync(path.join(homeDir, '.claude', 'skills', 'security-review', 'SKILL.md')));
@@ -1051,7 +1052,7 @@ function runTests() {
exclude: ['capability:orchestration'],
}, null, 2));
const result = run([], { cwd: projectDir, homeDir });
const result = run(['--enable-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
assert.ok(fs.existsSync(path.join(homeDir, '.claude', 'skills', 'security-review', 'SKILL.md')));
@@ -1082,7 +1083,7 @@ function runTests() {
include: ['capability:security'],
}, null, 2));
const result = run(['typescript'], { cwd: projectDir, homeDir });
const result = run(['typescript', '--enable-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
const state = readJson(path.join(homeDir, '.claude', 'ecc', 'install-state.json'));
@@ -1098,6 +1099,56 @@ function runTests() {
}
})) passed++; else failed++;
if (test('holds hook materialization without an explicit hook decision', () => {
const projectDir = createTempDir('install-apply-consent-held-');
const homeDir = createTempDir('install-apply-consent-held-home-');
try {
const result = run(['--profile', 'core'], { cwd: projectDir, homeDir });
assert.notStrictEqual(result.code, 0);
assert.ok(result.stderr.includes('automatic hook runtime'));
assert.ok(result.stderr.includes('--enable-hooks'));
assert.ok(!fs.existsSync(path.join(homeDir, '.claude', 'hooks', 'hooks.json')));
} finally {
cleanup(homeDir);
cleanup(projectDir);
}
})) passed++; else failed++;
if (test('--no-hooks installs the profile without the hook runtime', () => {
const projectDir = createTempDir('install-apply-no-hooks-');
const homeDir = createTempDir('install-apply-no-hooks-home-');
try {
const result = run(['--profile', 'core', '--no-hooks'], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
assert.ok(!fs.existsSync(path.join(homeDir, '.claude', 'hooks', 'hooks.json')));
const state = readJson(path.join(homeDir, '.claude', 'ecc', 'install-state.json'));
assert.ok(!state.resolution.selectedModules.includes('hooks-runtime'));
assert.ok(state.resolution.selectedModules.includes('rules-core'));
} finally {
cleanup(homeDir);
cleanup(projectDir);
}
})) passed++; else failed++;
if (test('rejects --enable-hooks combined with --no-hooks', () => {
const result = run(['--profile', 'core', '--enable-hooks', '--no-hooks']);
assert.notStrictEqual(result.code, 0);
assert.ok(result.stderr.includes('mutually exclusive'));
})) passed++; else failed++;
if (test('dry-run surfaces the pending hook decision as a warning', () => {
const projectDir = createTempDir('install-apply-consent-dry-');
const homeDir = createTempDir('install-apply-consent-dry-home-');
try {
const result = run(['--profile', 'core', '--dry-run'], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
assert.ok(result.stdout.includes('explicit hook decision'));
} finally {
cleanup(homeDir);
cleanup(projectDir);
}
})) passed++; else failed++;
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
process.exit(failed > 0 ? 1 : 0);
}
+23
View File
@@ -8,6 +8,7 @@ const {
collectInteractiveOptions,
main,
parseArgs,
printPlan,
validateExecutionMode,
} = require('../../scripts/install-guided');
const {
@@ -361,6 +362,28 @@ function runGuidedPtyFixture(answers) {
assert.doesNotMatch(errorOutput.read(), /\[31m/);
});
await test('printPlan discloses hook capabilities for non-off Claude hook profiles', async () => {
let written = '';
const output = { write: chunk => { written += chunk; } };
printPlan({
harnesses: [{ id: 'claude', channel: 'native-plugin' }],
request: { harnesses: ['claude'], claudeHooks: 'standard' },
}, output);
assert.ok(written.includes("hook profile 'standard'"));
assert.ok(written.includes('modify project source files'));
assert.ok(written.includes("--claude-hooks off"));
});
await test('printPlan omits the hook disclosure when Claude hooks are off', async () => {
let written = '';
const output = { write: chunk => { written += chunk; } };
printPlan({
harnesses: [{ id: 'claude', channel: 'native-plugin' }],
request: { harnesses: ['claude'], claudeHooks: 'off' },
}, output);
assert.ok(!written.includes('enables automation'));
});
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
process.exitCode = failed > 0 ? 1 : 0;
})();
+1 -1
View File
@@ -98,7 +98,7 @@ function runTests() {
const projectRoot = createTempDir('repair-project-');
try {
const installResult = runNode(INSTALL_SCRIPT, ['--target', 'cursor', 'typescript'], {
const installResult = runNode(INSTALL_SCRIPT, ['--target', 'cursor', 'typescript', '--enable-hooks'], {
cwd: projectRoot,
homeDir,
});
+1 -1
View File
@@ -85,7 +85,7 @@ function runTests() {
const projectRoot = createTempDir('uninstall-project-');
try {
const installStdout = execFileSync('node', [INSTALL_SCRIPT, '--target', 'cursor', 'typescript'], {
const installStdout = execFileSync('node', [INSTALL_SCRIPT, '--target', 'cursor', 'typescript', '--enable-hooks'], {
cwd: projectRoot,
env: {
...process.env,