refactor: remove coding-agent hook management (P2.2)

The hooks for Claude Code, Codex and the other agents ran the
hive-mind-hooks-* packages, which left the repository; ADR-0002 hides
the feature in v1. Remove the hook installer surface from the tool
launcher, the POST /api/tools/hooks route, the hook status probe in
tool detection, and the hook fields of the tool manifest and detection
envelope (hookCapable, hookRoot, hookPointer, hooksInstalled,
hookPointerPath). Third-party adapter manifests no longer accept the
hook fields.

In the web UI, remove the hidden hook actions and the "How memory is
shared" explainer from the Launcher, adapter.manageHooks, the
hook-wired count in Mission Control and the agentHooks and memoryMcp
memory feature flags. Launch, watch and stop are unchanged; the
roadmap tool note no longer mentions hooks.
This commit is contained in:
shumeiko.it
2026-11-01 00:35:13 +01:00
parent 46687a823a
commit 2edfd01e6e
32 changed files with 168 additions and 2575 deletions

View File

@@ -24,7 +24,7 @@ type DetectOpts = ToolDetectionDeps & {
/**
* Build a deps object that defaults to "nothing exists anywhere".
* Tests selectively override `exists` / `execVersion` / `readJson` to
* Tests selectively override `exists` / `execVersion` to
* simulate specific tools being installed.
*/
function makeDeps(overrides: Partial<DetectOpts> = {}): DetectOpts {
@@ -32,10 +32,9 @@ function makeDeps(overrides: Partial<DetectOpts> = {}): DetectOpts {
platform: 'win32',
home: 'C:\\Users\\test',
env: {},
cwd: 'D:\\projects\\waggle-os',
cwd: 'C:\\work\\waggle',
exists: async () => false,
execVersion: async () => null,
readJson: async () => null,
pathFromEnv: () => null,
windowsAppExecutables: () => ({}),
// Hermetic: no third-party adapters unless a test injects them.
@@ -44,83 +43,6 @@ function makeDeps(overrides: Partial<DetectOpts> = {}): DetectOpts {
};
}
type ClaudeHookCommandBuilder = (basename: string, scriptPath: string) => string;
function activeClaudeHookSettings(
commandBuilder: ClaudeHookCommandBuilder = (_basename, scriptPath) => `node "${scriptPath}"`,
) {
const group = (basename: string) => [{
_hiveMindShim: '@hive-mind/claude-code-hooks',
hooks: [{
type: 'command',
command: commandBuilder(
basename,
`/opt/waggle/hive-mind-hooks-claude-code/dist/hooks/${basename}.js`,
),
}],
}];
return {
hooks: {
SessionStart: group('session-start'),
UserPromptSubmit: group('user-prompt-submit'),
Stop: group('stop'),
PreCompact: group('pre-compact'),
},
};
}
function markerStrippedClaudeHookSettings(
packageName = 'hive-mind-hooks-claude-code',
commandBuilder: ClaudeHookCommandBuilder = (_basename, scriptPath) => `node "${scriptPath}"`,
entryType = 'command',
) {
const group = (basename: string) => [{
hooks: [{
type: entryType,
command: commandBuilder(
basename,
`D:\\Waggle\\packages\\${packageName}\\dist\\hooks\\${basename}.js`,
),
}],
}];
return {
hooks: {
SessionStart: group('session-start'),
UserPromptSubmit: group('user-prompt-submit'),
Stop: group('stop'),
PreCompact: group('pre-compact'),
},
};
}
async function detectClaudeHookStatus(
settingsValue: unknown,
platform: NodeJS.Platform = 'win32',
): Promise<boolean | undefined> {
const windows = platform === 'win32';
const home = windows ? 'C:\\Users\\test' : '/Users/test';
const installed = windows ? `${home}\\AppData\\Roaming\\npm\\claude.cmd` : '/usr/local/bin/claude';
const pointer = windows ? `${home}\\.claude\\hive-mind-install.json` : `${home}/.claude/hive-mind-install.json`;
const backup = windows
? `${home}\\.claude\\settings.json.hive-mind-backup.X`
: `${home}/.claude/settings.json.hive-mind-backup.X`;
const settings = windows ? `${home}\\.claude\\settings.json` : `${home}/.claude/settings.json`;
const existsSet = new Set([installed, pointer, backup, settings]);
const result = await detectInstalledTools(makeDeps({
platform,
home,
exists: async (candidate) => existsSet.has(candidate),
pathFromEnv: () => installed,
execVersion: async () => 'claude 2.1.214',
readJson: async (candidate) => {
if (candidate === pointer) return { settings_backup: backup };
if (candidate === settings) return settingsValue;
return null;
},
}));
return result.tools.find((tool) => tool.id === 'claude-code')?.hooksInstalled;
}
describe('detectInstalledTools', () => {
it('does not expose ambient secrets to the production version probe', async () => {
const previousOpenAi = process.env.OPENAI_API_KEY;
@@ -165,8 +87,6 @@ describe('detectInstalledTools', () => {
id: 'foo-cli',
displayName: 'Foo',
launchable: true,
hookCapable: false,
hookPointer: '.foo/hm.json',
detect: { kind: 'path', binaryName: 'foo' },
promptArgTemplate: ['--print', '{prompt}'],
task: {
@@ -188,7 +108,6 @@ describe('detectInstalledTools', () => {
expect(foo?.installed).toBe(true);
expect(foo?.installedPath).toBe('/usr/bin/foo');
expect(foo?.launchable).toBe(true);
expect(foo?.hookCapable).toBe(false);
expect(foo?.builtin).toBe(false);
expect(foo?.acceptsInlinePrompt).toBe(true);
expect(foo?.capabilities).toEqual({
@@ -225,12 +144,10 @@ describe('detectInstalledTools', () => {
expect(cursor).toMatchObject({
releaseStatus: 'roadmap',
launchable: false,
hookCapable: false,
});
expect(openclaw).toMatchObject({
releaseStatus: 'roadmap',
launchable: false,
hookCapable: false,
});
});
@@ -247,7 +164,6 @@ describe('detectInstalledTools', () => {
expect(t.installed).toBe(false);
expect(t.installedPath).toBeNull();
expect(t.version).toBeNull();
expect(t.hooksInstalled).toBe(false);
}
});
@@ -295,238 +211,6 @@ describe('claude-code detector', () => {
expect(t.version).toBe('1.2.3');
});
it('reports hooksInstalled=true when the pointer, backup, and active Claude hooks are healthy', async () => {
const installed = '/usr/local/bin/claude';
const home = '/Users/test';
const pointer = '/Users/test/.claude/hive-mind-install.json';
const backup = '/Users/test/.claude/settings.json.hive-mind-backup.X';
const settings = '/Users/test/.claude/settings.json';
const existsSet = new Set([installed, pointer, backup, settings]);
const result = await detectInstalledTools(
makeDeps({
platform: 'darwin',
home,
exists: async (p) => existsSet.has(p),
pathFromEnv: () => installed,
execVersion: async () => 'claude 1.2.3',
readJson: async (p) => {
if (p === pointer) return { settings_backup: backup };
if (p === settings) return activeClaudeHookSettings();
return null;
},
}),
);
const t = result.tools.find((x) => x.id === 'claude-code')!;
expect(t.hooksInstalled).toBe(true);
expect(t.hookPointerPath).toBe(pointer);
});
it('keeps hooksInstalled=true after Claude strips private markers from Waggle hook groups', async () => {
const installed = 'C:\\Users\\test\\AppData\\Roaming\\npm\\claude.cmd';
const pointer = 'C:\\Users\\test\\.claude\\hive-mind-install.json';
const backup = 'C:\\Users\\test\\.claude\\settings.json.hive-mind-backup.X';
const settings = 'C:\\Users\\test\\.claude\\settings.json';
const existsSet = new Set([installed, pointer, backup, settings]);
const result = await detectInstalledTools(makeDeps({
exists: async (candidate) => existsSet.has(candidate),
pathFromEnv: () => installed,
execVersion: async () => 'claude 2.1.214',
readJson: async (candidate) => {
if (candidate === pointer) return { settings_backup: backup };
if (candidate === settings) return markerStrippedClaudeHookSettings();
return null;
},
}));
expect(result.tools.find((tool) => tool.id === 'claude-code')?.hooksInstalled).toBe(true);
});
it.each([
[
'a pinned mixed-case Node executable, hook path, and cli path',
(_basename: string, scriptPath: string) => {
const spacedPath = scriptPath.replace('D:\\Waggle', 'D:\\Program Files\\Waggle').toUpperCase();
return `"C:\\Program Files\\nodejs\\node.EXE" "${spacedPath}" --cli-path "D:\\Program Files\\Hive Mind\\cli.JS"`;
},
],
[
'safe unquoted absolute paths without spaces',
(_basename: string, scriptPath: string) => `C:\\Node\\node.exe ${scriptPath} --cli-path D:\\HiveMind\\cli.js`,
],
])('accepts marker-stripped hooks using %s', async (_label, commandBuilder) => {
expect(await detectClaudeHookStatus(
markerStrippedClaudeHookSettings('hive-mind-hooks-claude-code', commandBuilder),
)).toBe(true);
});
it('accepts a canonical marker-stripped POSIX command', async () => {
const settings = markerStrippedClaudeHookSettings(
'hive-mind-hooks-claude-code',
(basename) =>
`"/usr/local/bin/node" "/opt/waggle/hive-mind-hooks-claude-code/dist/hooks/${basename}.js" --cli-path "/opt/waggle/hive-mind-cli.js"`,
);
expect(await detectClaudeHookStatus(settings, 'linux')).toBe(true);
});
it('finds the canonical command entry when Claude preserves another entry first', async () => {
const settings = markerStrippedClaudeHookSettings();
for (const groups of Object.values(settings.hooks)) {
groups[0].hooks.unshift({ type: 'prompt', command: 'not executable' });
}
expect(await detectClaudeHookStatus(settings)).toBe(true);
});
it.each<Array<[string, ClaudeHookCommandBuilder]>>([
['echo text', (_basename, scriptPath) => `echo "${scriptPath}"`],
['a Node wrapper comment', (_basename, scriptPath) => `node "D:\\wrapper.js" --comment "${scriptPath}"`],
['a cmd wrapper', (_basename, scriptPath) => `cmd /c node "${scriptPath}"`],
['a PowerShell wrapper', (_basename, scriptPath) => `powershell -Command node "${scriptPath}"`],
['node -e text', (_basename, scriptPath) => `node -e "${scriptPath}"`],
['a backup extension', (_basename, scriptPath) => `node "${scriptPath}.bak"`],
['the wrong hook basename', (_basename, scriptPath) => `node "${scriptPath.replace(/[^\\]+\.js$/, 'other.js')}"`],
['an unknown argument', (_basename, scriptPath) => `node "${scriptPath}" --verbose`],
['a shell AND chain', (_basename, scriptPath) => `node "${scriptPath}" && echo done`],
['a shell semicolon chain', (_basename, scriptPath) => `node "${scriptPath}"; echo done`],
['a shell pipe', (_basename, scriptPath) => `node "${scriptPath}" | tee out`],
['a shell redirect', (_basename, scriptPath) => `node "${scriptPath}" > out`],
['a newline command', (_basename, scriptPath) => `node "${scriptPath}"\necho done`],
['an unmatched quote', (_basename, scriptPath) => `node "${scriptPath}`],
[
'an unquoted path with spaces',
(_basename, scriptPath) => `node ${scriptPath.replace('D:\\Waggle', 'D:\\Program Files\\Waggle')}`,
],
])('rejects marker-stripped hook commands containing %s', async (_label, commandBuilder) => {
expect(await detectClaudeHookStatus(
markerStrippedClaudeHookSettings('hive-mind-hooks-claude-code', commandBuilder),
)).toBe(false);
});
it('rejects a canonical-looking entry whose type is not command', async () => {
expect(await detectClaudeHookStatus(
markerStrippedClaudeHookSettings(
'hive-mind-hooks-claude-code',
(_basename, scriptPath) => `node "${scriptPath}"`,
'prompt',
),
)).toBe(false);
});
it('rejects an arbitrary same-basename script even when the Waggle marker is present', async () => {
const settings = activeClaudeHookSettings(
(basename) => `node "C:\\malware\\${basename}.js"`,
);
expect(await detectClaudeHookStatus(settings)).toBe(false);
});
it.each<Array<[string, ClaudeHookCommandBuilder]>>([
[
'quoted command substitution',
(basename) => `node "/tmp/$(echo owned)/hive-mind-hooks-claude-code/dist/hooks/${basename}.js"`,
],
[
'quoted backtick substitution',
(basename) => `node "/tmp/` + '`echo owned`' + `/hive-mind-hooks-claude-code/dist/hooks/${basename}.js"`,
],
[
'unquoted command substitution',
(basename) => `node /tmp/$(echo)/hive-mind-hooks-claude-code/dist/hooks/${basename}.js`,
],
[
'an unquoted glob',
(basename) => `node /opt/*/hive-mind-hooks-claude-code/dist/hooks/${basename}.js`,
],
])('rejects POSIX hook paths containing %s', async (_label, commandBuilder) => {
const settings = markerStrippedClaudeHookSettings(
'hive-mind-hooks-claude-code',
commandBuilder,
);
expect(await detectClaudeHookStatus(settings, 'linux')).toBe(false);
});
it('rejects node.exe as a POSIX hook executable', async () => {
const settings = markerStrippedClaudeHookSettings(
'hive-mind-hooks-claude-code',
(basename) =>
`/usr/local/bin/node.exe /opt/waggle/hive-mind-hooks-claude-code/dist/hooks/${basename}.js`,
);
expect(await detectClaudeHookStatus(settings, 'linux')).toBe(false);
});
it('rejects marker-stripped hook commands from a lookalike package', async () => {
const installed = 'C:\\Users\\test\\AppData\\Roaming\\npm\\claude.cmd';
const pointer = 'C:\\Users\\test\\.claude\\hive-mind-install.json';
const backup = 'C:\\Users\\test\\.claude\\settings.json.hive-mind-backup.X';
const settings = 'C:\\Users\\test\\.claude\\settings.json';
const existsSet = new Set([installed, pointer, backup, settings]);
const result = await detectInstalledTools(makeDeps({
exists: async (candidate) => existsSet.has(candidate),
pathFromEnv: () => installed,
execVersion: async () => 'claude 2.1.214',
readJson: async (candidate) => {
if (candidate === pointer) return { settings_backup: backup };
if (candidate === settings) {
return markerStrippedClaudeHookSettings('hive-mind-hooks-claude-code-copy');
}
return null;
},
}));
expect(result.tools.find((tool) => tool.id === 'claude-code')?.hooksInstalled).toBe(false);
});
it('reports hooksInstalled=false when a stale pointer survives but active Claude hooks are gone', async () => {
const installed = '/usr/local/bin/claude';
const pointer = '/Users/test/.claude/hive-mind-install.json';
const backup = '/Users/test/.claude/settings.json.hive-mind-backup.X';
const settings = '/Users/test/.claude/settings.json';
const existsSet = new Set([installed, pointer, backup, settings]);
const result = await detectInstalledTools(makeDeps({
platform: 'darwin',
home: '/Users/test',
exists: async (candidate) => existsSet.has(candidate),
pathFromEnv: () => installed,
execVersion: async () => 'claude 1.2.3',
readJson: async (candidate) => {
if (candidate === pointer) return { settings_backup: backup };
if (candidate === settings) return { hooks: {} };
return null;
},
}));
expect(result.tools.find((tool) => tool.id === 'claude-code')).toMatchObject({
hooksInstalled: false,
hookPointerPath: pointer,
});
});
it('reports hooksInstalled=false when the pointer exists but its backup is gone (partial rollback)', async () => {
const installed = '/usr/local/bin/claude';
const home = '/Users/test';
const pointer = '/Users/test/.claude/hive-mind-install.json';
const existsSet = new Set([installed, pointer]); // backup deliberately missing
const result = await detectInstalledTools(
makeDeps({
platform: 'darwin',
home,
exists: async (p) => existsSet.has(p),
pathFromEnv: () => installed,
execVersion: async () => 'claude 1.2.3',
readJson: async (p) =>
p === pointer
? { settings_backup: '/Users/test/.claude/settings.json.hive-mind-backup.X' }
: null,
}),
);
const t = result.tools.find((x) => x.id === 'claude-code')!;
expect(t.hooksInstalled).toBe(false);
expect(t.hookPointerPath).toBe(pointer);
});
it('records a diagnostic when claude-code is installed but --version fails', async () => {
const installed = '/usr/local/bin/claude';
const result = await detectInstalledTools(
@@ -574,25 +258,6 @@ describe('cursor detector', () => {
expect(t.installed).toBe(true);
expect(t.installedPath).toBe(installed);
});
it('reports cursor hooks installed when pointer file is present and valid', async () => {
const installed = '/Applications/Cursor.app/Contents/MacOS/Cursor';
const pointer = '/Users/test/.cursor/hive-mind-install.json';
const backup = '/Users/test/.cursor/settings.json.hive-mind-backup.X';
const existsSet = new Set([installed, pointer, backup]);
const result = await detectInstalledTools(
makeDeps({
platform: 'darwin',
home: '/Users/test',
exists: async (p) => existsSet.has(p),
readJson: async (p) => (p === pointer ? { settings_backup: backup } : null),
}),
);
const t = result.tools.find((x) => x.id === 'cursor')!;
expect(t.hooksInstalled).toBe(true);
expect(t.hookPointerPath).toBe(pointer);
});
});
describe('claude-desktop detector', () => {
@@ -687,28 +352,6 @@ describe('extended-cohort detectors (Codex / Hermes / OpenClaw — Phase 4)', ()
expect(t.version).toBe('codex 0.5.0');
});
it('recognizes a healthy create-if-missing hook install with no backup', async () => {
const installed = '/usr/local/bin/codex';
const pointer = '/Users/test/.codex/hive-mind-install.json';
const configPath = '/Users/test/.codex/hooks.json';
const hooksDir = '/waggle/runtime/codex/hooks';
const existsSet = new Set([installed, pointer, configPath, hooksDir]);
const result = await detectInstalledTools(makeDeps({
platform: 'darwin', home: '/Users/test',
exists: async (candidate) => existsSet.has(candidate),
pathFromEnv: (name) => name === 'codex' ? installed : null,
execVersion: async () => 'codex 0.5.0',
readJson: async (candidate) => candidate === pointer ? {
settings_backup: null,
created_by_us: true,
config_path: configPath,
hooks_dir: hooksDir,
installed_hooks: ['session-start'],
} : null,
}));
expect(result.tools.find((tool) => tool.id === 'codex')?.hooksInstalled).toBe(true);
});
it('reports WindowsApps Codex as installed but not launchable when Windows blocks exec', async () => {
const installed =
'C:\\Program Files\\WindowsApps\\OpenAI.Codex_26.623.19656.0_x64__2p2nqsd0c76g0\\app\\resources\\codex.exe';
@@ -764,55 +407,39 @@ describe('extended-cohort detectors (Codex / Hermes / OpenClaw — Phase 4)', ()
});
});
it('uses the direct HERMES_HOME Windows executable fallback and hook pointer', async () => {
it('uses the direct HERMES_HOME Windows executable fallback', async () => {
const hermesHome = 'D:\\Hermes Data';
const installed = `${hermesHome}\\hermes-agent\\venv\\Scripts\\hermes.exe`;
const pointer = `${hermesHome}\\hive-mind-install.json`;
const backup = `${hermesHome}\\config.yaml.hive-mind-backup.X`;
const existsSet = new Set([installed, pointer, backup]);
const result = await detectInstalledTools(makeDeps({
env: {
HERMES_HOME: hermesHome,
LOCALAPPDATA: 'C:\\Users\\test\\AppData\\Local',
},
exists: async (candidate) => existsSet.has(candidate),
exists: async (candidate) => candidate === installed,
execVersion: async (binary) => binary === installed ? '0.18.2' : null,
readJson: async (candidate) => candidate === pointer
? { settings_backup: backup }
: null,
}));
expect(result.tools.find((tool) => tool.id === 'hermes')).toMatchObject({
installed: true,
installedPath: installed,
version: '0.18.2',
hooksInstalled: true,
hookPointerPath: pointer,
});
});
it('uses redirected LOCALAPPDATA for the Windows CLI fallback and hook pointer', async () => {
it('uses redirected LOCALAPPDATA for the Windows CLI fallback', async () => {
const localAppData = 'E:\\Redirected\\Local';
const hermesHome = `${localAppData}\\hermes`;
const installed = `${hermesHome}\\hermes-agent\\venv\\Scripts\\hermes.exe`;
const pointer = `${hermesHome}\\hive-mind-install.json`;
const configPath = `${hermesHome}\\config.yaml`;
const existsSet = new Set([installed, pointer, configPath]);
const result = await detectInstalledTools(makeDeps({
env: { LOCALAPPDATA: localAppData },
exists: async (candidate) => existsSet.has(candidate),
exists: async (candidate) => candidate === installed,
execVersion: async (binary) => binary === installed ? '0.18.2' : null,
readJson: async (candidate) => candidate === pointer
? { settings_backup: null, created_by_us: true, config_path: configPath }
: null,
}));
expect(result.tools.find((tool) => tool.id === 'hermes')).toMatchObject({
installed: true,
installedPath: installed,
version: '0.18.2',
hooksInstalled: true,
hookPointerPath: pointer,
});
});
@@ -899,7 +526,6 @@ describe('extended-cohort detectors (Codex / Hermes / OpenClaw — Phase 4)', ()
installedPath: desktop,
version: null,
launchable: true,
hookCapable: false,
capabilities: { interactiveLaunch: true, headlessTask: false },
});
expect(versionProbes).toContain(cli);