From bf20052a01c627f4c53df02669daae1bd86d1511 Mon Sep 17 00:00:00 2001 From: rUv Date: Sat, 7 Feb 2026 23:15:59 +0000 Subject: [PATCH] Checkpoint: File edits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automatic checkpoint created by Claude Code - Branch: feature/init-upgrade-settings - Timestamp: 2026-02-07T23:15:59Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- v3/@claude-flow/cli/src/init/executor.ts | 79 ++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/v3/@claude-flow/cli/src/init/executor.ts b/v3/@claude-flow/cli/src/init/executor.ts index 3ad691924f..c38ff7deef 100644 --- a/v3/@claude-flow/cli/src/init/executor.ts +++ b/v3/@claude-flow/cli/src/init/executor.ts @@ -251,6 +251,85 @@ export interface UpgradeResult { settingsUpdated?: string[]; } +/** + * Merge new settings into existing settings.json + * Preserves user customizations while adding new features like Agent Teams + */ +function mergeSettingsForUpgrade(existing: Record): Record { + const merged = { ...existing }; + + // 1. Merge env vars (preserve existing, add new) + const existingEnv = (existing.env as Record) || {}; + merged.env = { + ...existingEnv, + CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS: '1', + CLAUDE_FLOW_V3_ENABLED: existingEnv.CLAUDE_FLOW_V3_ENABLED || 'true', + CLAUDE_FLOW_HOOKS_ENABLED: existingEnv.CLAUDE_FLOW_HOOKS_ENABLED || 'true', + }; + + // 2. Merge hooks (preserve existing, add new Agent Teams hooks) + const existingHooks = (existing.hooks as Record) || {}; + merged.hooks = { ...existingHooks }; + + // Add TeammateIdle hook if not present + if (!existingHooks.TeammateIdle) { + (merged.hooks as Record).TeammateIdle = [ + { + hooks: [ + { + type: 'command', + command: 'npx @claude-flow/cli@latest hooks teammate-idle --auto-assign true 2>/dev/null || true', + timeout: 5000, + continueOnError: true, + }, + ], + }, + ]; + } + + // Add TaskCompleted hook if not present + if (!existingHooks.TaskCompleted) { + (merged.hooks as Record).TaskCompleted = [ + { + hooks: [ + { + type: 'command', + command: '[ -n "$TASK_ID" ] && npx @claude-flow/cli@latest hooks task-completed --task-id "$TASK_ID" --train-patterns true 2>/dev/null || true', + timeout: 5000, + continueOnError: true, + }, + ], + }, + ]; + } + + // 3. Merge claudeFlow settings (preserve existing, add agentTeams) + const existingClaudeFlow = (existing.claudeFlow as Record) || {}; + merged.claudeFlow = { + ...existingClaudeFlow, + version: existingClaudeFlow.version || '3.0.0', + enabled: existingClaudeFlow.enabled !== false, + agentTeams: { + enabled: true, + teammateMode: 'auto', + taskListEnabled: true, + mailboxEnabled: true, + coordination: { + autoAssignOnIdle: true, + trainPatternsOnComplete: true, + notifyLeadOnComplete: true, + sharedMemoryNamespace: 'agent-teams', + }, + hooks: { + teammateIdle: { enabled: true, autoAssign: true, checkTaskList: true }, + taskCompleted: { enabled: true, trainPatterns: true, notifyLead: true }, + }, + }, + }; + + return merged; +} + /** * Execute upgrade - updates helpers and creates missing metrics without losing data * This is safe for existing users who want the latest statusline fixes