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

Checkpoint: File edits

rUvcb09a97160ba
diff --git a/v3/@claude-flow/cli/src/init/settings-generator.ts b/v3/@claude-flow/cli/src/init/settings-generator.ts
index f275c5d2fe..7a6122a844 100644
--- a/v3/@claude-flow/cli/src/init/settings-generator.ts
+++ b/v3/@claude-flow/cli/src/init/settings-generator.ts
@@ -170,180 +170,77 @@ function generateStatusLineConfig(options: InitOptions): object {
/**
* Generate hooks configuration
- * Detects platform and generates appropriate commands for Mac, Linux, and Windows
+ * Uses local hook-handler.cjs for cross-platform compatibility.
+ * All hooks delegate to `node .claude/helpers/hook-handler.cjs <command>`
+ * which works identically on Windows, macOS, and Linux without
+ * shell-specific syntax (no bash 2>/dev/null, no PowerShell 2>$null).
*/
function generateHooksConfig(config: HooksConfig): object {
const hooks: Record<string, unknown[]> = {};
- const platform = detectPlatform();
- const isWindows = platform.os === 'windows';
- // Platform-specific command helpers
- // Windows: PowerShell syntax with 2>$null and ; exit 0
- // Mac/Linux: Bash syntax with 2>/dev/null || true
- const cmd = {
- // Check if variable is set and run command
- ifVar: (varName: string, command: string) => isWindows
- ? `if ($env:${varName}) { ${command} 2>$null }; exit 0`
- : `[ -n "$${varName}" ] && ${command} 2>/dev/null || true`,
- // Simple command with error suppression
- simple: (command: string) => isWindows
- ? `${command} 2>$null; exit 0`
- : `${command} 2>/dev/null || true`,
- // Echo JSON (different quote escaping)
- echoJson: (json: string) => isWindows
- ? `Write-Output '${json}'`
- : `echo '${json}'`,
- // Generate timestamp (for unique keys)
- timestamp: () => isWindows
- ? '$(Get-Date -UFormat %s)'
- : '$(date +%s)',
- };
-
- // PreToolUse hooks - cross-platform via npx with defensive guards
+ // PreToolUse β€” validate commands before execution
if (config.preToolUse) {
hooks.PreToolUse = [
- // File edit hooks with intelligence routing
- {
- matcher: '^(Write|Edit|MultiEdit)$',
- hooks: [
- {
- type: 'command',
- command: cmd.ifVar('TOOL_INPUT_file_path',
- isWindows
- ? 'npx @claude-flow/cli@latest hooks pre-edit --file $env:TOOL_INPUT_file_path'
- : 'npx @claude-flow/cli@latest hooks pre-edit --file "$TOOL_INPUT_file_path"'),
- timeout: config.timeout,
- continueOnError: true,
- },
- ],
- },
- // Bash command hooks with safety validation
- {
- matcher: '^Bash$',
- hooks: [
- {
- type: 'command',
- command: cmd.ifVar('TOOL_INPUT_command',
- isWindows
- ? 'npx @claude-flow/cli@latest hooks pre-command --command $env:TOOL_INPUT_command'
- : 'npx @claude-flow/cli@latest hooks pre-command --command "$TOOL_INPUT_command"'),
- timeout: config.timeout,
- continueOnError: true,
- },
- ],
- },
- // Task/Agent hooks - require task-id for tracking
{
- matcher: '^Task$',
+ matcher: 'Bash',
hooks: [
{
type: 'command',
- command: cmd.ifVar('TOOL_INPUT_prompt',
- isWindows
- ? `npx @claude-flow/cli@latest hooks pre-task --task-id "task-${cmd.timestamp()}" --description $env:TOOL_INPUT_prompt`
- : `npx @claude-flow/cli@latest hooks pre-task --task-id "task-${cmd.timestamp()}" --description "$TOOL_INPUT_prompt"`),
+ command: 'node .claude/helpers/hook-handler.cjs pre-bash',
timeout: config.timeout,
- continueOnError: true,
},
],
},
];
}
- // PostToolUse hooks - cross-platform via npx with defensive guards
+ // PostToolUse β€” record edits for session metrics / learning
if (config.postToolUse) {
hooks.PostToolUse = [
- // File edit hooks with neural pattern training
- {
- matcher: '^(Write|Edit|MultiEdit)$',
- hooks: [
- {
- type: 'command',
- command: cmd.ifVar('TOOL_INPUT_file_path',
- isWindows
- ? 'npx @claude-flow/cli@latest hooks post-edit --file $env:TOOL_INPUT_file_path --success $($env:TOOL_SUCCESS ?? "true")'
- : 'npx @claude-flow/cli@latest hooks post-edit --file "$TOOL_INPUT_file_path" --success "${TOOL_SUCCESS:-true}"'),
- timeout: config.timeout,
- continueOnError: true,
- },
- ],
- },
- // Bash command hooks with metrics tracking
{
- matcher: '^Bash$',
+ matcher: 'Write|Edit|MultiEdit',
hooks: [
{
type: 'command',
- command: cmd.ifVar('TOOL_INPUT_command',
- isWindows
- ? 'npx @claude-flow/cli@latest hooks post-command --command $env:TOOL_INPUT_command --success $($env:TOOL_SUCCESS ?? "true")'
- : 'npx @claude-flow/cli@latest hooks post-command --command "$TOOL_INPUT_command" --success "${TOOL_SUCCESS:-true}"'),
- timeout: config.timeout,
- continueOnError: true,
- },
- ],
- },
- // Task completion hooks - use task-id
- {
- matcher: '^Task$',
- hooks: [
- {
- type: 'command',
- command: cmd.ifVar('TOOL_RESULT_agent_id',
- isWindows
- ? 'npx @claude-flow/cli@latest hooks post-task --task-id $env:TOOL_RESULT_agent_id --success $($env:TOOL_SUCCESS ?? "true")'
- : 'npx @claude-flow/cli@latest hooks post-task --task-id "$TOOL_RESULT_agent_id" --success "${TOOL_SUCCESS:-true}"'),
- timeout: config.timeout,
- continueOnError: true,
+ command: 'node .claude/helpers/hook-handler.cjs post-edit',
+ timeout: 10000,
},
],
},
];
}
- // UserPromptSubmit for intelligent routing
+ // UserPromptSubmit β€” intelligent task routing
if (config.userPromptSubmit) {
hooks.UserPromptSubmit = [
{
hooks: [
{
type: 'command',
- command: cmd.ifVar('PROMPT',
- isWindows
- ? 'npx @claude-flow/cli@latest hooks route --task $env:PROMPT'
- : 'npx @claude-flow/cli@latest hooks route --task "$PROMPT"'),
- timeout: config.timeout,
- continueOnError: true,
+ command: 'node .claude/helpers/hook-handler.cjs route',
+ timeout: 10000,
},
],
},
];
}
- // SessionStart for context loading and daemon auto-start
+ // SessionStart β€” restore session state + import auto memory
if (config.sessionStart) {
hooks.SessionStart = [
{
+ matcher: 'startup|resume',
hooks: [
{
type: 'command',
- command: cmd.simple('npx @claude-flow/cli@latest daemon start --quiet'),
- timeout: 5000,
+ command: 'node .claude/helpers/hook-handler.cjs session-restore',
+ timeout: 15000,
continueOnError: true,
},
{
type: 'command',
- command: cmd.simple('node .claude/helpers/auto-memory-hook.mjs import'),
- timeout: 6000,
- continueOnError: true,
- },
- {
- type: 'command',
- command: cmd.ifVar('SESSION_ID',
- isWindows
- ? 'npx @claude-flow/cli@latest hooks session-restore --session-id $env:SESSION_ID'
- : 'npx @claude-flow/cli@latest hooks session-restore --session-id "$SESSION_ID"'),
- timeout: 10000,
+ command: 'node .claude/helpers/auto-memory-hook.mjs import',
+ timeout: 8000,
continueOnError: true,
},
],
@@ -351,21 +248,15 @@ function generateHooksConfig(config: HooksConfig): object {
];
}
- // SessionEnd for memory sync and state persistence
+ // SessionEnd β€” persist session state
if (config.sessionStart) {
hooks.SessionEnd = [
{
hooks: [
{
type: 'command',
- command: cmd.simple('node .claude/helpers/auto-memory-hook.mjs sync'),
- timeout: 8000,
- continueOnError: true,
- },
- {
- type: 'command',
- command: cmd.simple('npx @claude-flow/cli@latest hooks session-end --persist-memory true --export-patterns true'),
- timeout: 8000,
+ command: 'node .claude/helpers/hook-handler.cjs session-end',
+ timeout: 10000,
continueOnError: true,
},
],
@@ -373,34 +264,15 @@ function generateHooksConfig(config: HooksConfig): object {
];
}
- // Stop hooks for task evaluation - always return ok by default
- // The hook outputs JSON that Claude Code validates
+ // Stop β€” sync auto memory on exit
if (config.stop) {
hooks.Stop = [
{
hooks: [
{
type: 'command',
- command: cmd.echoJson('{"ok": true}'),
- timeout: 1000,
- },
- ],
- },
- ];
- }
-
- // Notification hooks - store notifications in memory for swarm awareness
- if (config.notification) {
- hooks.Notification = [
- {
- hooks: [
- {
- type: 'command',
- command: cmd.ifVar('NOTIFICATION_MESSAGE',
- isWindows
- ? `npx @claude-flow/cli@latest memory store --namespace notifications --key "notify-${cmd.timestamp()}" --value $env:NOTIFICATION_MESSAGE`
- : `npx @claude-flow/cli@latest memory store --namespace notifications --key "notify-${cmd.timestamp()}" --value "$NOTIFICATION_MESSAGE"`),
- timeout: 3000,
+ command: 'node .claude/helpers/auto-memory-hook.mjs sync',
+ timeout: 10000,
continueOnError: true,
},
],
@@ -408,33 +280,14 @@ function generateHooksConfig(config: HooksConfig): object {
];
}
- // Note: PermissionRequest is NOT a valid Claude Code hook type
- // Auto-allow behavior is configured via settings.permissions.allow instead
-
- // Agent Teams hooks - TeammateIdle for task assignment, TaskCompleted for coordination
- hooks.TeammateIdle = [
- {
- hooks: [
- {
- type: 'command',
- command: cmd.simple('npx @claude-flow/cli@latest hooks teammate-idle --auto-assign true'),
- timeout: 5000,
- continueOnError: true,
- },
- ],
- },
- ];
-
- hooks.TaskCompleted = [
+ // SubagentStart β€” status update
+ hooks.SubagentStart = [
{
hooks: [
{
type: 'command',
- command: cmd.ifVar('TASK_ID',
- isWindows
- ? 'npx @claude-flow/cli@latest hooks task-completed --task-id $env:TASK_ID --train-patterns true'
- : 'npx @claude-flow/cli@latest hooks task-completed --task-id "$TASK_ID" --train-patterns true'),
- timeout: 5000,
+ command: 'node .claude/helpers/hook-handler.cjs status',
+ timeout: 3000,
continueOnError: true,
},
],