Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix(init): omit unimplemented generated hooks (#4200) (#4213)

Wu Shuwen422e61cf036a
diff --git a/v3/@claude-flow/cli/__tests__/settings-hooks-implemented.test.ts b/v3/@claude-flow/cli/__tests__/settings-hooks-implemented.test.ts
new file mode 100644
index 0000000000..06d496d8b8
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/settings-hooks-implemented.test.ts
@@ -0,0 +1,24 @@
+import { describe, expect, it } from 'vitest';
+import { DEFAULT_INIT_OPTIONS } from '../src/init/types.js';
+import { generateSettings } from '../src/init/settings-generator.js';
+
+describe('generated hook settings', () => {
+ it('only wires commands implemented by hook-handler.cjs', () => {
+ const settings = generateSettings(DEFAULT_INIT_OPTIONS) as {
+ hooks: Record<string, Array<{ hooks: Array<{ command: string }> }>>;
+ };
+ const hooks = settings.hooks;
+ const commands = Object.values(hooks)
+ .flatMap((groups) => groups.flatMap((group) => group.hooks.map((hook) => hook.command)));
+
+ for (const unsupported of ['pre-edit', 'post-bash', 'compact-manual', 'compact-auto', 'status', 'notify']) {
+ expect(commands.some((command) => new RegExp(`(?:^|[\\s'\"])${unsupported}(?:['\"]|$)`).test(command))).toBe(false);
+ }
+ expect(hooks.PreToolUse).toBeDefined();
+ expect(hooks.PostToolUse).toBeDefined();
+ expect(hooks.PreCompact).toBeDefined();
+ expect(commands.some((command) => /(?:^|[\s'])pre-bash(?:['"]|$)/.test(command))).toBe(true);
+ expect(commands.some((command) => /(?:^|[\s'])post-edit(?:['"]|$)/.test(command))).toBe(true);
+ expect(commands.some((command) => /(?:^|[\s'])session-end(?:['"]|$)/.test(command))).toBe(true);
+ });
+});
diff --git a/v3/@claude-flow/cli/src/init/settings-generator.ts b/v3/@claude-flow/cli/src/init/settings-generator.ts
index e52e9bafdd..467b7a9a78 100644
--- a/v3/@claude-flow/cli/src/init/settings-generator.ts
+++ b/v3/@claude-flow/cli/src/init/settings-generator.ts
@@ -220,7 +220,7 @@ function generateHooksConfig(config: HooksConfig, scope: HelperScope): object {
// Node.js scripts handle errors internally via try/catch.
// No shell-level error suppression needed (2>/dev/null || true breaks Windows).
- // PreToolUse β€” validate commands and edits before execution
+ // PreToolUse β€” validate shell commands before execution
if (config.preToolUse) {
hooks.PreToolUse = [
{
@@ -233,20 +233,10 @@ function generateHooksConfig(config: HooksConfig, scope: HelperScope): object {
},
],
},
- {
- matcher: 'Write|Edit|MultiEdit',
- hooks: [
- {
- type: 'command',
- command: hookHandlerCmd('pre-edit', scope),
- timeout: config.timeout,
- },
- ],
- },
];
}
- // PostToolUse β€” record edits and commands for session metrics / learning
+ // PostToolUse β€” record edits for session metrics / learning
if (config.postToolUse) {
hooks.PostToolUse = [
{
@@ -259,16 +249,6 @@ function generateHooksConfig(config: HooksConfig, scope: HelperScope): object {
},
],
},
- {
- matcher: 'Bash',
- hooks: [
- {
- type: 'command',
- command: hookHandlerCmd('post-bash', scope),
- timeout: config.timeout,
- },
- ],
- },
];
}
@@ -337,16 +317,13 @@ function generateHooksConfig(config: HooksConfig, scope: HelperScope): object {
];
}
- // PreCompact β€” preserve context before compaction
+ // PreCompact β€” end the current session before compaction. The handler has no
+ // manual/automatic compaction-specific command, so don't wire no-op hooks.
if (config.preCompact) {
hooks.PreCompact = [
{
matcher: 'manual',
hooks: [
- {
- type: 'command',
- command: hookHandlerCmd('compact-manual', scope),
- },
{
type: 'command',
command: hookHandlerCmd('session-end', scope),
@@ -357,10 +334,6 @@ function generateHooksConfig(config: HooksConfig, scope: HelperScope): object {
{
matcher: 'auto',
hooks: [
- {
- type: 'command',
- command: hookHandlerCmd('compact-auto', scope),
- },
{
type: 'command',
command: hookHandlerCmd('session-end', scope),
@@ -371,19 +344,6 @@ function generateHooksConfig(config: HooksConfig, scope: HelperScope): object {
];
}
- // SubagentStart β€” status update when a sub-agent is spawned
- hooks.SubagentStart = [
- {
- hooks: [
- {
- type: 'command',
- command: hookHandlerCmd('status', scope),
- timeout: 3000,
- },
- ],
- },
- ];
-
// SubagentStop β€” track agent completion for metrics
// NOTE: The valid event is "SubagentStop" (not "SubagentEnd")
hooks.SubagentStop = [
@@ -398,21 +358,6 @@ function generateHooksConfig(config: HooksConfig, scope: HelperScope): object {
},
];
- // Notification β€” capture Claude Code notifications for logging
- if (config.notification) {
- hooks.Notification = [
- {
- hooks: [
- {
- type: 'command',
- command: hookHandlerCmd('notify', scope),
- timeout: 3000,
- },
- ],
- },
- ];
- }
-
// NOTE: TeammateIdle, TaskCompleted, and PostCompact are NOT accepted by
// Claude Code's settings.json validator (rejected as "Invalid key in record").
// Agent Teams coordination lives in claudeFlow.agentTeams.hooks instead.