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

@@ -1,7 +1,7 @@
/**
* AI-OS Phase 2A — tool launcher tests.
*
* TDD coverage for launchTool() + runHookCommand(). All process
* TDD coverage for launchTool(). All process
* spawns are injected so the test never actually executes a binary.
*/
@@ -11,18 +11,14 @@ import { describe, it, expect, vi } from 'vitest';
import { join, resolve } from 'node:path';
import {
launchTool,
runHookCommand,
hookPackageFor,
HOOKS_COHORT,
createObservedHandle,
defaultSpawnObserved,
resolveHookRuntime,
resolveSpawnInvocation,
type HookRuntimePaths,
resolveWaggleRuntime,
type ToolLauncherDeps,
type ObservedHandle,
} from '../src/tool-launcher.js';
import { BUILTIN_TOOL_MANIFESTS, type ToolId, type ToolManifest } from '@waggle/shared';
import type { ToolId, ToolManifest } from '@waggle/shared';
function captureSpawn() {
const calls: Array<{
@@ -41,37 +37,6 @@ function captureSpawn() {
return { calls, spawnDetached };
}
function captureExec(
result: { stdout: string; stderr: string; code: number } | null = {
stdout: 'ok',
stderr: '',
code: 0,
},
) {
const calls: Array<{
binary: string;
args: string[];
options?: { timeoutMs?: number; env?: NodeJS.ProcessEnv };
}> = [];
const execCapture: NonNullable<ToolLauncherDeps['execCapture']> = async (
binary,
args,
options,
) => {
calls.push({ binary, args, options });
return result;
};
return { calls, execCapture };
}
function testHookRuntime(id: ToolId = 'claude-code'): HookRuntimePaths {
return {
nodePath: '/waggle/resources/node',
cliEntry: '/waggle/resources/node_modules/@waggle/hive-mind-cli/dist/index.js',
hookEntry: `/waggle/resources/node_modules/@waggle/hive-mind-hooks-${id}/dist/bin/${id}-hooks.js`,
};
}
// ── launchTool ──────────────────────────────────────────────────────
describe('launchTool', () => {
@@ -238,8 +203,6 @@ describe('launchTool', () => {
id: 'foo-cli',
displayName: 'Foo CLI',
launchable: true,
hookCapable: false,
hookPointer: '.foo/hive-mind-install.json',
detect: { kind: 'path', binaryName: 'foo' },
builtin: false,
};
@@ -260,8 +223,6 @@ describe('launchTool', () => {
id: 'foo-cli',
displayName: 'Foo CLI',
launchable: false,
hookCapable: false,
hookPointer: '.foo/hive-mind-install.json',
detect: { kind: 'path', binaryName: 'foo' },
builtin: false,
};
@@ -343,156 +304,6 @@ describe('launchTool — self-enabling signal env', () => {
});
});
// ── runHookCommand ──────────────────────────────────────────────────
describe('runHookCommand', () => {
it('invokes the packaged hook bin through bundled Node for install', async () => {
const { calls, execCapture } = captureExec();
const runtime = testHookRuntime();
const result = await runHookCommand({
id: 'claude-code',
action: 'install',
runtime,
dataDir: '/waggle-data',
deps: {
baseEnv: {
LOCALAPPDATA: 'C:\\Redirected\\Local',
HERMES_HOME: 'D:\\Hermes Data',
OPENAI_API_KEY: 'must-not-cross',
},
execCapture,
},
});
expect(result.ok).toBe(true);
expect(calls[0].binary).toBe(runtime.nodePath);
expect(calls[0].args).toEqual([
runtime.hookEntry,
'install',
'--cli-path',
runtime.cliEntry,
]);
expect(calls[0].options?.env).toMatchObject({
LOCALAPPDATA: 'C:\\Redirected\\Local',
HERMES_HOME: 'D:\\Hermes Data',
WAGGLE_HOOK_NODE_PATH: runtime.nodePath,
HIVE_MIND_DATA_DIR: '/waggle-data',
});
expect(calls[0].options?.env?.OPENAI_API_KEY).toBeUndefined();
});
it('pins the packaged CLI for install but not verify or uninstall', async () => {
const { calls, execCapture } = captureExec();
const runtime = testHookRuntime();
await runHookCommand({ id: 'claude-code', action: 'install', runtime, deps: { execCapture } });
await runHookCommand({ id: 'claude-code', action: 'verify', runtime, deps: { execCapture } });
await runHookCommand({ id: 'claude-code', action: 'uninstall', runtime, deps: { execCapture } });
expect(calls.map((call) => call.args)).toEqual([
[runtime.hookEntry, 'install', '--cli-path', runtime.cliEntry],
[runtime.hookEntry, 'verify'],
[runtime.hookEntry, 'uninstall'],
]);
});
it('captures stdout, stderr, and code on success', async () => {
const { execCapture } = captureExec({
stdout: 'Done.',
stderr: '',
code: 0,
});
const result = await runHookCommand({
id: 'claude-code',
action: 'install',
runtime: testHookRuntime(),
deps: { execCapture },
});
expect(result.ok).toBe(true);
expect(result.stdout).toBe('Done.');
expect(result.code).toBe(0);
});
it('reports ok=false on non-zero exit', async () => {
const { execCapture } = captureExec({
stdout: '',
stderr: 'Failed to write settings.json',
code: 1,
});
const result = await runHookCommand({
id: 'claude-code',
action: 'install',
runtime: testHookRuntime(),
deps: { execCapture },
});
expect(result.ok).toBe(false);
expect(result.stderr).toContain('Failed');
});
it('reports ok=false with diagnostic when exec returns null', async () => {
const execCapture: NonNullable<ToolLauncherDeps['execCapture']> = async () =>
null;
const result = await runHookCommand({
id: 'claude-code',
action: 'install',
runtime: testHookRuntime(),
deps: { execCapture },
});
expect(result.ok).toBe(false);
expect(result.error).toContain('exec failed');
});
// R8-001: hook management is gated on the release-supported HOOKS_COHORT.
it.each<ToolId>(['claude-code', 'claude-desktop', 'codex', 'codex-desktop', 'hermes'])(
'routes the hook command for HOOKS_COHORT tool (%s)',
async (id) => {
const { calls, execCapture } = captureExec();
const runtime = testHookRuntime(id);
const result = await runHookCommand({ id, action: 'install', runtime, deps: { execCapture } });
expect(result.ok).toBe(true);
expect(calls[0].args).toEqual([runtime.hookEntry, 'install', '--cli-path', runtime.cliEntry]);
},
);
it.each<ToolId>(['cursor', 'openclaw'])(
'refuses hook commands for roadmap tool %s without invoking exec',
async (id) => {
const { calls, execCapture } = captureExec();
const result = await runHookCommand({ id, action: 'install', deps: { execCapture } });
expect(result.ok).toBe(false);
expect(result.error).toContain('not supported');
expect(calls).toHaveLength(0);
},
);
it('refuses hook command for an unsupported tool id without invoking exec', async () => {
const fakeId = 'not-a-real-tool' as ToolId;
const { calls, execCapture } = captureExec();
const result = await runHookCommand({ id: fakeId, action: 'install', deps: { execCapture } });
expect(result.ok).toBe(false);
expect(result.error).toContain('not supported');
expect(calls).toHaveLength(0);
});
it('fails closed when the packaged runtime payload cannot be resolved', () => {
expect(resolveHookRuntime('claude-code', { nodeModulesRoots: ['/missing'], fileExists: () => false })).toBeUndefined();
});
});
describe('HOOKS_COHORT derivation (#5)', () => {
it('equals the hook-capable manifests and includes claude-desktop', () => {
const expected = BUILTIN_TOOL_MANIFESTS.filter((m) => m.hookCapable).map((m) => m.id).sort();
expect([...HOOKS_COHORT].sort()).toEqual(expected);
expect(HOOKS_COHORT).toContain('claude-desktop');
});
});
describe('hookPackageFor', () => {
it.each<ToolId>(['claude-code', 'claude-desktop', 'cursor'])(
'returns @waggle/hive-mind-hooks-%s',
(id) => {
expect(hookPackageFor(id)).toBe(`@waggle/hive-mind-hooks-${id}`);
},
);
});
describe('launchTool observe mode', () => {
it('preserves a target signal receipt instead of exposing the supervisor exit code', () => {
const child = new EventEmitter() as ChildProcess;
@@ -593,24 +404,25 @@ describe('launchTool observe mode', () => {
});
});
describe('resolveHookRuntime', () => {
it('resolves the CLI and hook bin from an explicit staged node_modules root', () => {
describe('resolveWaggleRuntime', () => {
it('resolves the collaboration CLI from an explicit staged node_modules root', () => {
const root = join('resources', 'node_modules');
const cliEntry = join(root, '@waggle', 'hive-mind-cli', 'dist', 'index.js');
const hookEntry = join(root, '@waggle', 'hive-mind-hooks-codex', 'dist', 'bin', 'codex-hooks.js');
const runtime = resolveHookRuntime('codex', {
const runtime = resolveWaggleRuntime({
nodePath: join('resources', 'node'),
nodeModulesRoots: [root],
fileExists: (candidate) => candidate === resolve(cliEntry) || candidate === resolve(hookEntry),
});
expect(runtime).toEqual({
nodePath: join('resources', 'node'),
cliEntry: resolve(cliEntry),
hookEntry: resolve(hookEntry),
fileExists: (candidate) => candidate === resolve(cliEntry),
});
expect(runtime).toEqual({ nodePath: join('resources', 'node'), cliEntry: resolve(cliEntry) });
});
it('injects the canonical Waggle data root for hook memory', () => {
it('fails closed when the collaboration CLI is not staged', () => {
expect(resolveWaggleRuntime({ nodeModulesRoots: ['/missing'], fileExists: () => false })).toBeUndefined();
});
});
describe('launchTool collaboration env', () => {
it('injects the canonical Waggle data root', () => {
const { calls, spawnDetached } = captureSpawn();
launchTool({
id: 'claude-code',