Skip to content

armgit / ECC

Public Imported from GitHub
0

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

Merge origin/main into feat/insaits-security-hook

Affaan Mustafa5a5d647825f1
diff --cc tests/hooks/hooks.test.js
index be7dd3947,154af48f6..8cbfa3acd
--- a/tests/hooks/hooks.test.js
+++ b/tests/hooks/hooks.test.js
@@@ -104,123 -182,114 +182,136 @@@ async function runTests()
// session-start.js edge cases
console.log('\nsession-start.js (edge cases):');
- if (await asyncTest('exits 0 even with isolated empty HOME', async () => {
- const isoHome = path.join(os.tmpdir(), `ecc-iso-start-${Date.now()}`);
- fs.mkdirSync(path.join(isoHome, '.claude', 'sessions'), { recursive: true });
- fs.mkdirSync(path.join(isoHome, '.claude', 'skills', 'learned'), { recursive: true });
- try {
- const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
- HOME: isoHome, USERPROFILE: isoHome
- });
- assert.strictEqual(result.code, 0, `Exit code should be 0, got ${result.code}`);
- } finally {
- fs.rmSync(isoHome, { recursive: true, force: true });
- }
- })) passed++; else failed++;
-
- if (await asyncTest('reports package manager detection', async () => {
- const result = await runScript(path.join(scriptsDir, 'session-start.js'));
- assert.ok(
- result.stderr.includes('Package manager') || result.stderr.includes('[SessionStart]'),
- 'Should report package manager info'
- );
- })) passed++; else failed++;
-
- if (await asyncTest('skips template session content', async () => {
- const isoHome = path.join(os.tmpdir(), `ecc-tpl-start-${Date.now()}`);
- const sessionsDir = path.join(isoHome, '.claude', 'sessions');
- fs.mkdirSync(sessionsDir, { recursive: true });
- fs.mkdirSync(path.join(isoHome, '.claude', 'skills', 'learned'), { recursive: true });
-
- // Create a session file with template placeholder
- const sessionFile = path.join(sessionsDir, '2026-02-11-abcd1234-session.tmp');
- fs.writeFileSync(sessionFile, '## Current State\n\n[Session context goes here]\n');
-
- try {
- const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
- HOME: isoHome, USERPROFILE: isoHome
- });
- assert.strictEqual(result.code, 0);
- // stdout should NOT contain the template content
- assert.ok(
- !result.stdout.includes('Previous session summary'),
- 'Should not inject template session content'
- );
- } finally {
- fs.rmSync(isoHome, { recursive: true, force: true });
- }
- })) passed++; else failed++;
-
- if (await asyncTest('injects real session content', async () => {
- const isoHome = path.join(os.tmpdir(), `ecc-real-start-${Date.now()}`);
- const sessionsDir = path.join(isoHome, '.claude', 'sessions');
- fs.mkdirSync(sessionsDir, { recursive: true });
- fs.mkdirSync(path.join(isoHome, '.claude', 'skills', 'learned'), { recursive: true });
-
- // Create a real session file
- const sessionFile = path.join(sessionsDir, '2026-02-11-efgh5678-session.tmp');
- fs.writeFileSync(sessionFile, '# Real Session\n\nI worked on authentication refactor.\n');
-
- try {
- const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
- HOME: isoHome, USERPROFILE: isoHome
- });
- assert.strictEqual(result.code, 0);
- assert.ok(
- result.stdout.includes('Previous session summary'),
- 'Should inject real session content'
- );
- assert.ok(
- result.stdout.includes('authentication refactor'),
- 'Should include session content text'
- );
- } finally {
- fs.rmSync(isoHome, { recursive: true, force: true });
- }
- })) passed++; else failed++;
-
- if (await asyncTest('reports learned skills count', async () => {
- const isoHome = path.join(os.tmpdir(), `ecc-skills-start-${Date.now()}`);
- const learnedDir = path.join(isoHome, '.claude', 'skills', 'learned');
- fs.mkdirSync(learnedDir, { recursive: true });
- fs.mkdirSync(path.join(isoHome, '.claude', 'sessions'), { recursive: true });
-
- // Create learned skill files
- fs.writeFileSync(path.join(learnedDir, 'testing-patterns.md'), '# Testing');
- fs.writeFileSync(path.join(learnedDir, 'debugging.md'), '# Debugging');
-
- try {
- const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
- HOME: isoHome, USERPROFILE: isoHome
- });
- assert.strictEqual(result.code, 0);
- assert.ok(
- result.stderr.includes('2 learned skill(s)'),
- `Should report 2 learned skills, stderr: ${result.stderr}`
- );
- } finally {
- fs.rmSync(isoHome, { recursive: true, force: true });
- }
- })) passed++; else failed++;
+ if (
+ await asyncTest('exits 0 even with isolated empty HOME', async () => {
+ const isoHome = path.join(os.tmpdir(), `ecc-iso-start-${Date.now()}`);
+ fs.mkdirSync(path.join(isoHome, '.claude', 'sessions'), { recursive: true });
+ fs.mkdirSync(path.join(isoHome, '.claude', 'skills', 'learned'), { recursive: true });
+ try {
+ const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
+ HOME: isoHome,
+ USERPROFILE: isoHome
+ });
+ assert.strictEqual(result.code, 0, `Exit code should be 0, got ${result.code}`);
+ } finally {
+ fs.rmSync(isoHome, { recursive: true, force: true });
+ }
+ })
+ )
+ passed++;
+ else failed++;
+
+ if (
+ await asyncTest('reports package manager detection', async () => {
+ const result = await runScript(path.join(scriptsDir, 'session-start.js'));
+ assert.ok(result.stderr.includes('Package manager') || result.stderr.includes('[SessionStart]'), 'Should report package manager info');
+ })
+ )
+ passed++;
+ else failed++;
+
+ if (
+ await asyncTest('skips template session content', async () => {
+ const isoHome = path.join(os.tmpdir(), `ecc-tpl-start-${Date.now()}`);
+ const sessionsDir = path.join(isoHome, '.claude', 'sessions');
+ fs.mkdirSync(sessionsDir, { recursive: true });
+ fs.mkdirSync(path.join(isoHome, '.claude', 'skills', 'learned'), { recursive: true });
+
+ // Create a session file with template placeholder
+ const sessionFile = path.join(sessionsDir, '2026-02-11-abcd1234-session.tmp');
+ fs.writeFileSync(sessionFile, '## Current State\n\n[Session context goes here]\n');
+
+ try {
+ const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
+ HOME: isoHome,
+ USERPROFILE: isoHome
+ });
+ assert.strictEqual(result.code, 0);
+ // stdout should NOT contain the template content
+ assert.ok(!result.stdout.includes('Previous session summary'), 'Should not inject template session content');
+ } finally {
+ fs.rmSync(isoHome, { recursive: true, force: true });
+ }
+ })
+ )
+ passed++;
+ else failed++;
+
+ if (
+ await asyncTest('injects real session content', async () => {
+ const isoHome = path.join(os.tmpdir(), `ecc-real-start-${Date.now()}`);
+ const sessionsDir = path.join(isoHome, '.claude', 'sessions');
+ fs.mkdirSync(sessionsDir, { recursive: true });
+ fs.mkdirSync(path.join(isoHome, '.claude', 'skills', 'learned'), { recursive: true });
+
+ // Create a real session file
+ const sessionFile = path.join(sessionsDir, '2026-02-11-efgh5678-session.tmp');
+ fs.writeFileSync(sessionFile, '# Real Session\n\nI worked on authentication refactor.\n');
+
+ try {
+ const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
+ HOME: isoHome,
+ USERPROFILE: isoHome
+ });
+ assert.strictEqual(result.code, 0);
+ assert.ok(result.stdout.includes('Previous session summary'), 'Should inject real session content');
+ assert.ok(result.stdout.includes('authentication refactor'), 'Should include session content text');
+ } finally {
+ fs.rmSync(isoHome, { recursive: true, force: true });
+ }
+ })
+ )
+ passed++;
+ else failed++;
+
+ if (
+ await asyncTest('reports learned skills count', async () => {
+ const isoHome = path.join(os.tmpdir(), `ecc-skills-start-${Date.now()}`);
+ const learnedDir = path.join(isoHome, '.claude', 'skills', 'learned');
+ fs.mkdirSync(learnedDir, { recursive: true });
+ fs.mkdirSync(path.join(isoHome, '.claude', 'sessions'), { recursive: true });
+
+ // Create learned skill files
+ fs.writeFileSync(path.join(learnedDir, 'testing-patterns.md'), '# Testing');
+ fs.writeFileSync(path.join(learnedDir, 'debugging.md'), '# Debugging');
+
+ try {
+ const result = await runScript(path.join(scriptsDir, 'session-start.js'), '', {
+ HOME: isoHome,
+ USERPROFILE: isoHome
+ });
+ assert.strictEqual(result.code, 0);
+ assert.ok(result.stderr.includes('2 learned skill(s)'), `Should report 2 learned skills, stderr: ${result.stderr}`);
+ } finally {
+ fs.rmSync(isoHome, { recursive: true, force: true });
+ }
+ })
+ )
+ passed++;
+ else failed++;
+ // insaits-security-wrapper.js tests
+ console.log('\ninsaits-security-wrapper.js:');
+
- if (await asyncTest('passes through input unchanged when integration is disabled', async () => {
- const stdinData = JSON.stringify({
- tool_name: 'Write',
- tool_input: { file_path: 'src/index.ts', content: 'console.log("ok");' }
- });
- const result = await runScript(
- path.join(scriptsDir, 'insaits-security-wrapper.js'),
- stdinData,
- { ECC_ENABLE_INSAITS: '' }
- );
- assert.strictEqual(result.code, 0, `Exit code should be 0, got ${result.code}`);
- assert.strictEqual(result.stdout, stdinData, 'Should pass stdin through unchanged');
- assert.strictEqual(result.stderr, '', 'Should stay silent when integration is disabled');
- })) passed++; else failed++;
++ if (
++ await asyncTest('passes through input unchanged when integration is disabled', async () => {
++ const stdinData = JSON.stringify({
++ tool_name: 'Write',
++ tool_input: { file_path: 'src/index.ts', content: 'console.log("ok");' }
++ });
++ const result = await runScript(
++ path.join(scriptsDir, 'insaits-security-wrapper.js'),
++ stdinData,
++ { ECC_ENABLE_INSAITS: '' }
++ );
++ assert.strictEqual(result.code, 0, `Exit code should be 0, got ${result.code}`);
++ assert.strictEqual(result.stdout, stdinData, 'Should pass stdin through unchanged');
++ assert.strictEqual(result.stderr, '', 'Should stay silent when integration is disabled');
++ })
++ )
++ passed++;
++ else failed++;
+
// check-console-log.js tests
console.log('\ncheck-console-log.js:');
@@@ -1183,101 -1570,85 +1592,103 @@@
// hooks.json validation
console.log('\nhooks.json Validation:');
- if (test('hooks.json is valid JSON', () => {
- const hooksPath = path.join(__dirname, '..', '..', 'hooks', 'hooks.json');
- const content = fs.readFileSync(hooksPath, 'utf8');
- JSON.parse(content); // Will throw if invalid
- })) passed++; else failed++;
-
- if (test('hooks.json has required event types', () => {
- const hooksPath = path.join(__dirname, '..', '..', 'hooks', 'hooks.json');
- const hooks = JSON.parse(fs.readFileSync(hooksPath, 'utf8'));
-
- assert.ok(hooks.hooks.PreToolUse, 'Should have PreToolUse hooks');
- assert.ok(hooks.hooks.PostToolUse, 'Should have PostToolUse hooks');
- assert.ok(hooks.hooks.SessionStart, 'Should have SessionStart hooks');
- assert.ok(hooks.hooks.SessionEnd, 'Should have SessionEnd hooks');
- assert.ok(hooks.hooks.Stop, 'Should have Stop hooks');
- assert.ok(hooks.hooks.PreCompact, 'Should have PreCompact hooks');
- })) passed++; else failed++;
-
- if (test('all hook commands use node or approved shell wrappers', () => {
- const hooksPath = path.join(__dirname, '..', '..', 'hooks', 'hooks.json');
- const hooks = JSON.parse(fs.readFileSync(hooksPath, 'utf8'));
-
- const checkHooks = (hookArray) => {
- for (const entry of hookArray) {
- for (const hook of entry.hooks) {
- if (hook.type === 'command') {
- const isNode = hook.command.startsWith('node');
- const isSkillScript = hook.command.includes('/skills/') && (
- /^(bash|sh)\s/.test(hook.command) ||
- hook.command.startsWith('${CLAUDE_PLUGIN_ROOT}/skills/')
- );
- const isHookShellWrapper = /^(bash|sh)\s+["']?\$\{CLAUDE_PLUGIN_ROOT\}\/scripts\/hooks\/run-with-flags-shell\.sh/.test(hook.command);
- const isSessionStartFallback = hook.command.startsWith('bash -lc') && hook.command.includes('run-with-flags.js');
- assert.ok(
- isNode || isSkillScript || isHookShellWrapper || isSessionStartFallback,
- `Hook command should use node or approved shell wrapper: ${hook.command.substring(0, 100)}...`
- );
+ if (
+ test('hooks.json is valid JSON', () => {
+ const hooksPath = path.join(__dirname, '..', '..', 'hooks', 'hooks.json');
+ const content = fs.readFileSync(hooksPath, 'utf8');
+ JSON.parse(content); // Will throw if invalid
+ })
+ )
+ passed++;
+ else failed++;
+
+ if (
+ test('hooks.json has required event types', () => {
+ const hooksPath = path.join(__dirname, '..', '..', 'hooks', 'hooks.json');
+ const hooks = JSON.parse(fs.readFileSync(hooksPath, 'utf8'));
+
+ assert.ok(hooks.hooks.PreToolUse, 'Should have PreToolUse hooks');
+ assert.ok(hooks.hooks.PostToolUse, 'Should have PostToolUse hooks');
+ assert.ok(hooks.hooks.SessionStart, 'Should have SessionStart hooks');
+ assert.ok(hooks.hooks.SessionEnd, 'Should have SessionEnd hooks');
+ assert.ok(hooks.hooks.Stop, 'Should have Stop hooks');
+ assert.ok(hooks.hooks.PreCompact, 'Should have PreCompact hooks');
+ })
+ )
+ passed++;
+ else failed++;
+
+ if (
+ test('all hook commands use node or approved shell wrappers', () => {
+ const hooksPath = path.join(__dirname, '..', '..', 'hooks', 'hooks.json');
+ const hooks = JSON.parse(fs.readFileSync(hooksPath, 'utf8'));
+
+ const checkHooks = hookArray => {
+ for (const entry of hookArray) {
+ for (const hook of entry.hooks) {
+ if (hook.type === 'command') {
+ const isNode = hook.command.startsWith('node');
+ const isSkillScript = hook.command.includes('/skills/') && (/^(bash|sh)\s/.test(hook.command) || hook.command.startsWith('${CLAUDE_PLUGIN_ROOT}/skills/'));
+ const isHookShellWrapper = /^(bash|sh)\s+["']?\$\{CLAUDE_PLUGIN_ROOT\}\/scripts\/hooks\/run-with-flags-shell\.sh/.test(hook.command);
+ const isSessionStartFallback = hook.command.startsWith('bash -lc') && hook.command.includes('run-with-flags.js');
+ assert.ok(isNode || isSkillScript || isHookShellWrapper || isSessionStartFallback, `Hook command should use node or approved shell wrapper: ${hook.command.substring(0, 100)}...`);
+ }
}
}
- }
- };
+ };
- for (const [, hookArray] of Object.entries(hooks.hooks)) {
- checkHooks(hookArray);
- }
- })) passed++; else failed++;
-
- if (test('script references use CLAUDE_PLUGIN_ROOT variable (except SessionStart fallback)', () => {
- const hooksPath = path.join(__dirname, '..', '..', 'hooks', 'hooks.json');
- const hooks = JSON.parse(fs.readFileSync(hooksPath, 'utf8'));
-
- const checkHooks = (hookArray) => {
- for (const entry of hookArray) {
- for (const hook of entry.hooks) {
- if (hook.type === 'command' && hook.command.includes('scripts/hooks/')) {
- // Check for the literal string "${CLAUDE_PLUGIN_ROOT}" in the command
- const isSessionStartFallback = hook.command.startsWith('bash -lc') && hook.command.includes('run-with-flags.js');
- const hasPluginRoot = hook.command.includes('${CLAUDE_PLUGIN_ROOT}') || isSessionStartFallback;
- assert.ok(
- hasPluginRoot,
- `Script paths should use CLAUDE_PLUGIN_ROOT: ${hook.command.substring(0, 80)}...`
- );
+ for (const [, hookArray] of Object.entries(hooks.hooks)) {
+ checkHooks(hookArray);
+ }
+ })
+ )
+ passed++;
+ else failed++;
+
+ if (
+ test('script references use CLAUDE_PLUGIN_ROOT variable (except SessionStart fallback)', () => {
+ const hooksPath = path.join(__dirname, '..', '..', 'hooks', 'hooks.json');
+ const hooks = JSON.parse(fs.readFileSync(hooksPath, 'utf8'));
+
+ const checkHooks = hookArray => {
+ for (const entry of hookArray) {
+ for (const hook of entry.hooks) {
+ if (hook.type === 'command' && hook.command.includes('scripts/hooks/')) {
+ // Check for the literal string "${CLAUDE_PLUGIN_ROOT}" in the command
+ const isSessionStartFallback = hook.command.startsWith('bash -lc') && hook.command.includes('run-with-flags.js');
+ const hasPluginRoot = hook.command.includes('${CLAUDE_PLUGIN_ROOT}') || isSessionStartFallback;
+ assert.ok(hasPluginRoot, `Script paths should use CLAUDE_PLUGIN_ROOT: ${hook.command.substring(0, 80)}...`);
+ }
}
}
- }
- };
+ };
- for (const [, hookArray] of Object.entries(hooks.hooks)) {
- checkHooks(hookArray);
- }
- })) passed++; else failed++;
-
- if (test('InsAIts hook is opt-in and scoped to high-signal tool inputs', () => {
- const hooksPath = path.join(__dirname, '..', '..', 'hooks', 'hooks.json');
- const hooks = JSON.parse(fs.readFileSync(hooksPath, 'utf8'));
- const insaitsHook = hooks.hooks.PreToolUse.find(entry =>
- entry.description && entry.description.includes('InsAIts')
- );
-
- assert.ok(insaitsHook, 'Should define an InsAIts PreToolUse hook');
- assert.strictEqual(
- insaitsHook.matcher,
- 'Bash|Write|Edit|MultiEdit',
- 'InsAIts hook should avoid matching every tool'
- );
- assert.ok(
- insaitsHook.description.includes('ECC_ENABLE_INSAITS=1'),
- 'InsAIts hook should document explicit opt-in'
- );
- assert.ok(
- insaitsHook.hooks[0].command.includes('insaits-security-wrapper.js'),
- 'InsAIts hook should execute through the JS wrapper'
- );
- })) passed++; else failed++;
+ for (const [, hookArray] of Object.entries(hooks.hooks)) {
+ checkHooks(hookArray);
+ }
+ })
+ )
+ passed++;
+ else failed++;
+
++ if (
++ test('InsAIts hook is opt-in and scoped to high-signal tool inputs', () => {
++ const hooksPath = path.join(__dirname, '..', '..', 'hooks', 'hooks.json');
++ const hooks = JSON.parse(fs.readFileSync(hooksPath, 'utf8'));
++ const insaitsHook = hooks.hooks.PreToolUse.find(entry => entry.description && entry.description.includes('InsAIts'));
++
++ assert.ok(insaitsHook, 'Should define an InsAIts PreToolUse hook');
++ assert.strictEqual(insaitsHook.matcher, 'Bash|Write|Edit|MultiEdit', 'InsAIts hook should avoid matching every tool');
++ assert.ok(insaitsHook.description.includes('ECC_ENABLE_INSAITS=1'), 'InsAIts hook should document explicit opt-in');
++ assert.ok(
++ insaitsHook.hooks[0].command.includes('insaits-security-wrapper.js'),
++ 'InsAIts hook should execute through the JS wrapper'
++ );
++ })
++ )
++ passed++;
++ else failed++;
+
// plugin.json validation
console.log('\nplugin.json Validation:');