claude-flow 3.1.0-alpha.13 → 3.1.0-alpha.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,7 +24,7 @@ const CONFIG = {
24
24
  showPerformance: true,
25
25
  refreshInterval: 5000,
26
26
  maxAgents: 15,
27
- topology: 'hierarchical',
27
+ topology: 'hierarchical-mesh',
28
28
  };
29
29
 
30
30
  // ANSI colors
@@ -178,52 +178,50 @@ function getLearningStats() {
178
178
  return { patterns, sessions, trajectories };
179
179
  }
180
180
 
181
- // Get V3 progress from learning state (grows as system learns)
181
+ // Get V3 progress from REAL metrics files
182
182
  function getV3Progress() {
183
183
  const learning = getLearningStats();
184
+ const totalDomains = 5;
185
+
186
+ let dddProgress = 0;
187
+ let dddScore = 0;
188
+ let dddMaxScore = 100;
189
+ let moduleCount = 0;
184
190
 
185
- // Check for metrics file first (created by init)
186
- const metricsPath = path.join(process.cwd(), '.claude-flow', 'metrics', 'v3-progress.json');
187
- if (fs.existsSync(metricsPath)) {
191
+ // Check ddd-progress.json for REAL DDD analysis
192
+ const dddPath = path.join(process.cwd(), '.claude-flow', 'metrics', 'ddd-progress.json');
193
+ if (fs.existsSync(dddPath)) {
188
194
  try {
189
- const data = JSON.parse(fs.readFileSync(metricsPath, 'utf-8'));
190
- if (data.domains) {
191
- const domainsCompleted = data.domains.completed || 0;
192
- const totalDomains = data.domains.total || 5;
193
- // Use ddd.progress if provided and > 0, otherwise calculate from domains
194
- const dddProgress = (data.ddd?.progress > 0)
195
- ? data.ddd.progress
196
- : Math.min(100, Math.floor((domainsCompleted / totalDomains) * 100));
197
- return {
198
- domainsCompleted,
199
- totalDomains,
200
- dddProgress,
201
- patternsLearned: data.learning?.patternsLearned || learning.patterns,
202
- sessionsCompleted: data.learning?.sessionsCompleted || learning.sessions
203
- };
204
- }
195
+ const data = JSON.parse(fs.readFileSync(dddPath, 'utf-8'));
196
+ dddProgress = data.progress || 0;
197
+ dddScore = data.score || 0;
198
+ dddMaxScore = data.maxScore || 100;
199
+ moduleCount = data.modules ? Object.keys(data.modules).length : 0;
205
200
  } catch (e) {
206
- // Fall through to pattern-based calculation
201
+ // Ignore - use fallback
207
202
  }
208
203
  }
209
204
 
210
- // DDD progress based on actual learned patterns
211
- // New install: 0 patterns = 0/5 domains, 0% DDD
212
- // As patterns grow: 10+ patterns = 1 domain, 50+ = 2, 100+ = 3, 200+ = 4, 500+ = 5
213
- let domainsCompleted = 0;
214
- if (learning.patterns >= 500) domainsCompleted = 5;
215
- else if (learning.patterns >= 200) domainsCompleted = 4;
216
- else if (learning.patterns >= 100) domainsCompleted = 3;
217
- else if (learning.patterns >= 50) domainsCompleted = 2;
218
- else if (learning.patterns >= 10) domainsCompleted = 1;
219
-
220
- const totalDomains = 5;
221
- const dddProgress = Math.min(100, Math.floor((domainsCompleted / totalDomains) * 100));
205
+ // Calculate domains completed from DDD progress (each 20% = 1 domain)
206
+ let domainsCompleted = Math.min(5, Math.floor(dddProgress / 20));
207
+
208
+ // Fallback: if no DDD data, use pattern-based calculation
209
+ if (dddProgress === 0 && learning.patterns > 0) {
210
+ if (learning.patterns >= 500) domainsCompleted = 5;
211
+ else if (learning.patterns >= 200) domainsCompleted = 4;
212
+ else if (learning.patterns >= 100) domainsCompleted = 3;
213
+ else if (learning.patterns >= 50) domainsCompleted = 2;
214
+ else if (learning.patterns >= 10) domainsCompleted = 1;
215
+ dddProgress = Math.floor((domainsCompleted / totalDomains) * 100);
216
+ }
222
217
 
223
218
  return {
224
219
  domainsCompleted,
225
220
  totalDomains,
226
221
  dddProgress,
222
+ dddScore,
223
+ dddMaxScore,
224
+ moduleCount,
227
225
  patternsLearned: learning.patterns,
228
226
  sessionsCompleted: learning.sessions
229
227
  };
@@ -358,15 +356,16 @@ function getSystemMetrics() {
358
356
  let memoryMB = 0;
359
357
  let subAgents = 0;
360
358
 
361
- // Check learning.json first (works on all platforms)
359
+ // Check learning.json first for REAL intelligence metrics
362
360
  const learningMetricsPath = path.join(process.cwd(), '.claude-flow', 'metrics', 'learning.json');
363
361
  let intelligenceFromFile = null;
364
362
  let contextFromFile = null;
365
363
  if (fs.existsSync(learningMetricsPath)) {
366
364
  try {
367
365
  const data = JSON.parse(fs.readFileSync(learningMetricsPath, 'utf-8'));
368
- if (data.routing?.accuracy !== undefined) {
369
- intelligenceFromFile = Math.min(100, Math.floor(data.routing.accuracy));
366
+ // Use intelligence.score (the REAL metric) instead of routing.accuracy
367
+ if (data.intelligence?.score !== undefined) {
368
+ intelligenceFromFile = Math.min(100, Math.floor(data.intelligence.score));
370
369
  }
371
370
  if (data.sessions?.total !== undefined) {
372
371
  contextFromFile = Math.min(100, data.sessions.total * 5);
@@ -517,8 +516,29 @@ function getSystemMetrics() {
517
516
  };
518
517
  }
519
518
 
520
- // Get ADR (Architecture Decision Records) status
519
+ // Get ADR (Architecture Decision Records) status from REAL compliance data
521
520
  function getADRStatus() {
521
+ let compliance = 0;
522
+ let totalChecks = 0;
523
+ let compliantChecks = 0;
524
+ let checks = {};
525
+
526
+ // Check adr-compliance.json for REAL compliance data
527
+ const compliancePath = path.join(process.cwd(), '.claude-flow', 'metrics', 'adr-compliance.json');
528
+ if (fs.existsSync(compliancePath)) {
529
+ try {
530
+ const data = JSON.parse(fs.readFileSync(compliancePath, 'utf-8'));
531
+ compliance = data.compliance || 0;
532
+ checks = data.checks || {};
533
+ totalChecks = Object.keys(checks).length;
534
+ compliantChecks = Object.values(checks).filter(c => c.compliant).length;
535
+ return { count: totalChecks, implemented: compliantChecks, compliance };
536
+ } catch (e) {
537
+ // Fall through to file-based detection
538
+ }
539
+ }
540
+
541
+ // Fallback: count ADR files directly
522
542
  const adrPaths = [
523
543
  path.join(process.cwd(), 'docs', 'adrs'),
524
544
  path.join(process.cwd(), 'docs', 'adr'),
@@ -540,7 +560,6 @@ function getADRStatus() {
540
560
  );
541
561
  count = files.length;
542
562
 
543
- // Check for implemented status in ADR files
544
563
  for (const file of files) {
545
564
  try {
546
565
  const content = fs.readFileSync(path.join(adrPath, file), 'utf-8');
@@ -559,7 +578,8 @@ function getADRStatus() {
559
578
  }
560
579
  }
561
580
 
562
- return { count, implemented };
581
+ compliance = count > 0 ? Math.floor((implemented / count) * 100) : 0;
582
+ return { count, implemented, compliance };
563
583
  }
564
584
 
565
585
  // Get hooks status (enabled/registered hooks)
@@ -1096,9 +1116,14 @@ function generateStatusline() {
1096
1116
  const vectorColor = agentdb.vectorCount > 0 ? c.brightGreen : c.dim;
1097
1117
  const testColor = tests.testFiles > 0 ? c.brightGreen : c.dim;
1098
1118
 
1119
+ // Show ADR compliance % if from real data, otherwise show count
1120
+ const adrDisplay = adrs.compliance > 0
1121
+ ? `${adrColor}●${adrs.compliance}%${c.reset}`
1122
+ : `${adrColor}●${adrs.implemented}/${adrs.count}${c.reset}`;
1123
+
1099
1124
  lines.push(
1100
1125
  `${c.brightPurple}🔧 Architecture${c.reset} ` +
1101
- `${c.cyan}ADRs${c.reset} ${adrColor}●${adrs.implemented}/${adrs.count}${c.reset} ${c.dim}│${c.reset} ` +
1126
+ `${c.cyan}ADRs${c.reset} ${adrDisplay} ${c.dim}│${c.reset} ` +
1102
1127
  `${c.cyan}DDD${c.reset} ${dddColor}●${String(progress.dddProgress).padStart(3)}%${c.reset} ${c.dim}│${c.reset} ` +
1103
1128
  `${c.cyan}Security${c.reset} ${securityColor}●${security.status}${c.reset}`
1104
1129
  );
@@ -32,7 +32,8 @@
32
32
  "CLAUDE_FLOW_CHECKPOINTS_ENABLED": "true",
33
33
  "CLAUDE_FLOW_V3_CLI_ENABLED": "true",
34
34
  "CLAUDE_FLOW_V3_CLI_PATH": "/workspaces/claude-flow/v3/@claude-flow/cli/bin/cli.js",
35
- "CLAUDE_FLOW_V3_INTELLIGENCE": "true"
35
+ "CLAUDE_FLOW_V3_INTELLIGENCE": "true",
36
+ "CLAUDE_FLOW_V3_ENABLED": "true"
36
37
  },
37
38
  "permissions": {
38
39
  "allowedTools": [
@@ -173,12 +174,12 @@
173
174
  "timeout": 4000,
174
175
  "command": "/workspaces/claude-flow/.claude/helpers/learning-hooks.sh store \"Edit: $TOOL_INPUT_file_path\" code 0.7 2>/dev/null || true"
175
176
  },
176
- {
177
+ {
177
178
  "type": "command",
178
179
  "timeout": 4000,
179
180
  "command": "node /workspaces/claude-flow/v3/@claude-flow/cli/bin/cli.js hooks post-edit --file \"$TOOL_INPUT_file_path\" --success true --train-patterns true --memory-key \"edit/$TOOL_INPUT_file_path\" 2>/dev/null || true"
180
181
  },
181
- {
182
+ {
182
183
  "type": "command",
183
184
  "timeout": 10000,
184
185
  "command": "/workspaces/claude-flow/.claude/helpers/auto-commit.sh batch 'Checkpoint: File edits' 2>/dev/null || true"
@@ -510,7 +511,13 @@
510
511
  "v3Configuration": {
511
512
  "domains": {
512
513
  "total": 5,
513
- "names": ["task-management", "session-management", "health-monitoring", "lifecycle-management", "event-coordination"],
514
+ "names": [
515
+ "task-management",
516
+ "session-management",
517
+ "health-monitoring",
518
+ "lifecycle-management",
519
+ "event-coordination"
520
+ ],
514
521
  "sourceDir": "src/domains"
515
522
  },
516
523
  "swarm": {
@@ -567,5 +574,36 @@
567
574
  "commit": "Co-Authored-By: claude-flow <ruv@ruv.net>",
568
575
  "pr": "🤖 Generated with [claude-flow](https://github.com/ruvnet/claude-flow)"
569
576
  },
570
- "enabledMcpjsonServers": ["claude-flow", "ruv-swarm"]
571
- }
577
+ "enabledMcpjsonServers": [
578
+ "claude-flow",
579
+ "ruv-swarm"
580
+ ],
581
+ "claudeFlow": {
582
+ "version": "3.0.0",
583
+ "enabled": true,
584
+ "agentTeams": {
585
+ "enabled": true,
586
+ "teammateMode": "auto",
587
+ "taskListEnabled": true,
588
+ "mailboxEnabled": true,
589
+ "coordination": {
590
+ "autoAssignOnIdle": true,
591
+ "trainPatternsOnComplete": true,
592
+ "notifyLeadOnComplete": true,
593
+ "sharedMemoryNamespace": "agent-teams"
594
+ },
595
+ "hooks": {
596
+ "teammateIdle": {
597
+ "enabled": true,
598
+ "autoAssign": true,
599
+ "checkTaskList": true
600
+ },
601
+ "taskCompleted": {
602
+ "enabled": true,
603
+ "trainPatterns": true,
604
+ "notifyLead": true
605
+ }
606
+ }
607
+ }
608
+ }
609
+ }
package/README.md CHANGED
@@ -489,8 +489,8 @@ bunx claude-flow@alpha init
489
489
 
490
490
  | Profile | Size | Use Case |
491
491
  |---------|------|----------|
492
- | `--omit=optional` | ~340MB | Core features only |
493
- | Default | ~340MB | Standard install |
492
+ | `--omit=optional` | ~45MB | Core CLI only (fastest) |
493
+ | Default | ~340MB | Full install with ML/embeddings |
494
494
 
495
495
  ```bash
496
496
  # Minimal install (skip ML/embeddings)
@@ -1515,6 +1515,76 @@ npx claude-flow hive-mind sessions # List active sessions
1515
1515
 
1516
1516
  </details>
1517
1517
 
1518
+ <details>
1519
+ <summary>👥 <strong>Agent Teams</strong> — Claude Code multi-instance coordination</summary>
1520
+
1521
+ Native integration with Claude Code's experimental Agent Teams feature for spawning and coordinating multiple Claude instances.
1522
+
1523
+ **Enable Agent Teams:**
1524
+ ```bash
1525
+ # Automatically enabled with claude-flow init
1526
+ npx claude-flow@latest init
1527
+
1528
+ # Or manually add to .claude/settings.json
1529
+ {
1530
+ "env": {
1531
+ "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
1532
+ }
1533
+ }
1534
+ ```
1535
+
1536
+ **Agent Teams Components:**
1537
+
1538
+ | Component | Tool | Purpose |
1539
+ |-----------|------|---------|
1540
+ | **Team Lead** | Main Claude | Coordinates teammates, assigns tasks, reviews results |
1541
+ | **Teammates** | `Task` tool | Sub-agents spawned to work on specific tasks |
1542
+ | **Task List** | `TaskCreate/TaskList/TaskUpdate` | Shared todos visible to all team members |
1543
+ | **Mailbox** | `SendMessage` | Inter-agent messaging for coordination |
1544
+
1545
+ **Quick Start:**
1546
+ ```javascript
1547
+ // Create a team
1548
+ TeamCreate({ team_name: "feature-dev", description: "Building feature" })
1549
+
1550
+ // Create shared tasks
1551
+ TaskCreate({ subject: "Design API", description: "..." })
1552
+ TaskCreate({ subject: "Implement endpoints", description: "..." })
1553
+
1554
+ // Spawn teammates (parallel background work)
1555
+ Task({ prompt: "Work on task #1...", subagent_type: "architect",
1556
+ team_name: "feature-dev", name: "architect", run_in_background: true })
1557
+ Task({ prompt: "Work on task #2...", subagent_type: "coder",
1558
+ team_name: "feature-dev", name: "developer", run_in_background: true })
1559
+
1560
+ // Message teammates
1561
+ SendMessage({ type: "message", recipient: "developer",
1562
+ content: "Prioritize auth", summary: "Priority update" })
1563
+
1564
+ // Cleanup when done
1565
+ SendMessage({ type: "shutdown_request", recipient: "developer" })
1566
+ TeamDelete()
1567
+ ```
1568
+
1569
+ **Agent Teams Hooks:**
1570
+
1571
+ | Hook | Trigger | Purpose |
1572
+ |------|---------|---------|
1573
+ | `teammate-idle` | Teammate finishes turn | Auto-assign pending tasks |
1574
+ | `task-completed` | Task marked complete | Train patterns, notify lead |
1575
+
1576
+ ```bash
1577
+ # Handle idle teammate
1578
+ npx claude-flow@latest hooks teammate-idle --auto-assign true
1579
+
1580
+ # Handle task completion
1581
+ npx claude-flow@latest hooks task-completed --task-id <id> --train-patterns
1582
+ ```
1583
+
1584
+ **Display Modes:** `auto` (default), `in-process`, `tmux` (split-pane)
1585
+
1586
+ </details>
1587
+
1518
1588
  <details>
1519
1589
  <summary>🔧 <strong>MCP Tools & Integration</strong> — 31+ tools across 7 categories</summary>
1520
1590
 
@@ -1527,7 +1597,7 @@ Full MCP server with tools for coordination, monitoring, memory, and GitHub inte
1527
1597
  | **Memory & Neural** | `memory_usage`, `neural_status`, `neural_train`, `neural_patterns` | Memory operations and learning |
1528
1598
  | **GitHub** | `github_swarm`, `repo_analyze`, `pr_enhance`, `issue_triage`, `code_review` | Repository integration |
1529
1599
  | **Workers** | `worker/run`, `worker/status`, `worker/alerts`, `worker/history` | Background task management |
1530
- | **Hooks** | `hooks/pre-*`, `hooks/post-*`, `hooks/route`, `hooks/session-*`, `hooks/intelligence/*` | 31 lifecycle hooks |
1600
+ | **Hooks** | `hooks/pre-*`, `hooks/post-*`, `hooks/route`, `hooks/session-*`, `hooks/teammate-*`, `hooks/task-*` | 33 lifecycle hooks |
1531
1601
  | **Progress** | `progress/check`, `progress/sync`, `progress/summary`, `progress/watch` | V3 implementation tracking |
1532
1602
 
1533
1603
  </details>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-flow",
3
- "version": "3.1.0-alpha.13",
3
+ "version": "3.1.0-alpha.14",
4
4
  "description": "Enterprise AI agent orchestration for Claude Code - Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -489,8 +489,8 @@ bunx claude-flow@alpha init
489
489
 
490
490
  | Profile | Size | Use Case |
491
491
  |---------|------|----------|
492
- | `--omit=optional` | ~340MB | Core features only |
493
- | Default | ~340MB | Standard install |
492
+ | `--omit=optional` | ~45MB | Core CLI only (fastest) |
493
+ | Default | ~340MB | Full install with ML/embeddings |
494
494
 
495
495
  ```bash
496
496
  # Minimal install (skip ML/embeddings)
@@ -1515,6 +1515,76 @@ npx claude-flow hive-mind sessions # List active sessions
1515
1515
 
1516
1516
  </details>
1517
1517
 
1518
+ <details>
1519
+ <summary>👥 <strong>Agent Teams</strong> — Claude Code multi-instance coordination</summary>
1520
+
1521
+ Native integration with Claude Code's experimental Agent Teams feature for spawning and coordinating multiple Claude instances.
1522
+
1523
+ **Enable Agent Teams:**
1524
+ ```bash
1525
+ # Automatically enabled with claude-flow init
1526
+ npx claude-flow@latest init
1527
+
1528
+ # Or manually add to .claude/settings.json
1529
+ {
1530
+ "env": {
1531
+ "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
1532
+ }
1533
+ }
1534
+ ```
1535
+
1536
+ **Agent Teams Components:**
1537
+
1538
+ | Component | Tool | Purpose |
1539
+ |-----------|------|---------|
1540
+ | **Team Lead** | Main Claude | Coordinates teammates, assigns tasks, reviews results |
1541
+ | **Teammates** | `Task` tool | Sub-agents spawned to work on specific tasks |
1542
+ | **Task List** | `TaskCreate/TaskList/TaskUpdate` | Shared todos visible to all team members |
1543
+ | **Mailbox** | `SendMessage` | Inter-agent messaging for coordination |
1544
+
1545
+ **Quick Start:**
1546
+ ```javascript
1547
+ // Create a team
1548
+ TeamCreate({ team_name: "feature-dev", description: "Building feature" })
1549
+
1550
+ // Create shared tasks
1551
+ TaskCreate({ subject: "Design API", description: "..." })
1552
+ TaskCreate({ subject: "Implement endpoints", description: "..." })
1553
+
1554
+ // Spawn teammates (parallel background work)
1555
+ Task({ prompt: "Work on task #1...", subagent_type: "architect",
1556
+ team_name: "feature-dev", name: "architect", run_in_background: true })
1557
+ Task({ prompt: "Work on task #2...", subagent_type: "coder",
1558
+ team_name: "feature-dev", name: "developer", run_in_background: true })
1559
+
1560
+ // Message teammates
1561
+ SendMessage({ type: "message", recipient: "developer",
1562
+ content: "Prioritize auth", summary: "Priority update" })
1563
+
1564
+ // Cleanup when done
1565
+ SendMessage({ type: "shutdown_request", recipient: "developer" })
1566
+ TeamDelete()
1567
+ ```
1568
+
1569
+ **Agent Teams Hooks:**
1570
+
1571
+ | Hook | Trigger | Purpose |
1572
+ |------|---------|---------|
1573
+ | `teammate-idle` | Teammate finishes turn | Auto-assign pending tasks |
1574
+ | `task-completed` | Task marked complete | Train patterns, notify lead |
1575
+
1576
+ ```bash
1577
+ # Handle idle teammate
1578
+ npx claude-flow@latest hooks teammate-idle --auto-assign true
1579
+
1580
+ # Handle task completion
1581
+ npx claude-flow@latest hooks task-completed --task-id <id> --train-patterns
1582
+ ```
1583
+
1584
+ **Display Modes:** `auto` (default), `in-process`, `tmux` (split-pane)
1585
+
1586
+ </details>
1587
+
1518
1588
  <details>
1519
1589
  <summary>🔧 <strong>MCP Tools & Integration</strong> — 31+ tools across 7 categories</summary>
1520
1590
 
@@ -1527,7 +1597,7 @@ Full MCP server with tools for coordination, monitoring, memory, and GitHub inte
1527
1597
  | **Memory & Neural** | `memory_usage`, `neural_status`, `neural_train`, `neural_patterns` | Memory operations and learning |
1528
1598
  | **GitHub** | `github_swarm`, `repo_analyze`, `pr_enhance`, `issue_triage`, `code_review` | Repository integration |
1529
1599
  | **Workers** | `worker/run`, `worker/status`, `worker/alerts`, `worker/history` | Background task management |
1530
- | **Hooks** | `hooks/pre-*`, `hooks/post-*`, `hooks/route`, `hooks/session-*`, `hooks/intelligence/*` | 31 lifecycle hooks |
1600
+ | **Hooks** | `hooks/pre-*`, `hooks/post-*`, `hooks/route`, `hooks/session-*`, `hooks/teammate-*`, `hooks/task-*` | 33 lifecycle hooks |
1531
1601
  | **Progress** | `progress/check`, `progress/sync`, `progress/summary`, `progress/watch` | V3 implementation tracking |
1532
1602
 
1533
1603
  </details>
@@ -736,24 +736,41 @@ const upgradeCommand = {
736
736
  type: 'boolean',
737
737
  default: false,
738
738
  },
739
+ {
740
+ name: 'settings',
741
+ short: 's',
742
+ description: 'Merge new settings (Agent Teams, hooks) into existing settings.json',
743
+ type: 'boolean',
744
+ default: false,
745
+ },
739
746
  ],
740
747
  action: async (ctx) => {
741
748
  const addMissing = (ctx.flags['add-missing'] || ctx.flags.addMissing);
749
+ const upgradeSettings = (ctx.flags.settings);
742
750
  output.writeln();
743
751
  output.writeln(output.bold('Upgrading Claude Flow'));
744
- if (addMissing) {
752
+ if (addMissing && upgradeSettings) {
753
+ output.writeln(output.dim('Updates helpers, settings, and adds any missing skills/agents/commands'));
754
+ }
755
+ else if (addMissing) {
745
756
  output.writeln(output.dim('Updates helpers and adds any missing skills/agents/commands'));
746
757
  }
758
+ else if (upgradeSettings) {
759
+ output.writeln(output.dim('Updates helpers and merges new settings (Agent Teams, hooks)'));
760
+ }
747
761
  else {
748
762
  output.writeln(output.dim('Updates helpers while preserving your existing data'));
749
763
  }
750
764
  output.writeln();
751
- const spinner = output.createSpinner({ text: addMissing ? 'Upgrading and adding missing assets...' : 'Upgrading...' });
765
+ const spinnerText = upgradeSettings
766
+ ? 'Upgrading helpers and settings...'
767
+ : (addMissing ? 'Upgrading and adding missing assets...' : 'Upgrading...');
768
+ const spinner = output.createSpinner({ text: spinnerText });
752
769
  spinner.start();
753
770
  try {
754
771
  const result = addMissing
755
- ? await executeUpgradeWithMissing(ctx.cwd)
756
- : await executeUpgrade(ctx.cwd);
772
+ ? await executeUpgradeWithMissing(ctx.cwd, upgradeSettings)
773
+ : await executeUpgrade(ctx.cwd, upgradeSettings);
757
774
  if (!result.success) {
758
775
  spinner.fail('Upgrade failed');
759
776
  for (const error of result.errors) {
@@ -795,8 +812,17 @@ const upgradeCommand = {
795
812
  output.printBox(result.addedCommands.map(c => `+ ${c}`).join('\n'), `Added Commands (${result.addedCommands.length} new)`);
796
813
  output.writeln();
797
814
  }
815
+ // Show settings updates
816
+ if (result.settingsUpdated && result.settingsUpdated.length > 0) {
817
+ output.printBox(result.settingsUpdated.map(s => `+ ${s}`).join('\n'), 'Settings Updated');
818
+ output.writeln();
819
+ }
798
820
  output.printSuccess('Your statusline helper has been updated to the latest version');
799
821
  output.printInfo('Existing metrics and learning data were preserved');
822
+ // Show settings summary
823
+ if (upgradeSettings && result.settingsUpdated && result.settingsUpdated.length > 0) {
824
+ output.printSuccess('Settings.json updated with new Agent Teams configuration');
825
+ }
800
826
  // Show summary for --add-missing
801
827
  if (addMissing) {
802
828
  const totalAdded = (result.addedSkills?.length || 0) + (result.addedAgents?.length || 0) + (result.addedCommands?.length || 0);
@@ -910,6 +936,7 @@ export const initCommand = {
910
936
  { command: 'claude-flow init skills --all', description: 'Install all available skills' },
911
937
  { command: 'claude-flow init hooks --minimal', description: 'Create minimal hooks configuration' },
912
938
  { command: 'claude-flow init upgrade', description: 'Update helpers while preserving data' },
939
+ { command: 'claude-flow init upgrade --settings', description: 'Update helpers and merge new settings (Agent Teams)' },
913
940
  { command: 'claude-flow init upgrade --verbose', description: 'Show detailed upgrade info' },
914
941
  { command: 'claude-flow init --codex', description: 'Initialize for OpenAI Codex (AGENTS.md)' },
915
942
  { command: 'claude-flow init --codex --full', description: 'Codex init with all 137+ skills' },
@@ -20,16 +20,22 @@ export interface UpgradeResult {
20
20
  addedSkills?: string[];
21
21
  addedAgents?: string[];
22
22
  addedCommands?: string[];
23
+ /** Added by --settings flag */
24
+ settingsUpdated?: string[];
23
25
  }
24
26
  /**
25
27
  * Execute upgrade - updates helpers and creates missing metrics without losing data
26
28
  * This is safe for existing users who want the latest statusline fixes
29
+ * @param targetDir - Target directory
30
+ * @param upgradeSettings - If true, merge new settings into existing settings.json
27
31
  */
28
- export declare function executeUpgrade(targetDir: string): Promise<UpgradeResult>;
32
+ export declare function executeUpgrade(targetDir: string, upgradeSettings?: boolean): Promise<UpgradeResult>;
29
33
  /**
30
34
  * Execute upgrade with --add-missing flag
31
35
  * Adds any new skills, agents, and commands that don't exist yet
36
+ * @param targetDir - Target directory
37
+ * @param upgradeSettings - If true, merge new settings into existing settings.json
32
38
  */
33
- export declare function executeUpgradeWithMissing(targetDir: string): Promise<UpgradeResult>;
39
+ export declare function executeUpgradeWithMissing(targetDir: string, upgradeSettings?: boolean): Promise<UpgradeResult>;
34
40
  export default executeInit;
35
41
  //# sourceMappingURL=executor.d.ts.map
@@ -10,7 +10,7 @@ import { dirname } from 'path';
10
10
  const __filename = fileURLToPath(import.meta.url);
11
11
  const __dirname = dirname(__filename);
12
12
  import { detectPlatform, DEFAULT_INIT_OPTIONS } from './types.js';
13
- import { generateSettingsJson } from './settings-generator.js';
13
+ import { generateSettingsJson, generateSettings } from './settings-generator.js';
14
14
  import { generateMCPJson } from './mcp-generator.js';
15
15
  import { generateStatuslineScript, generateStatuslineHook } from './statusline-generator.js';
16
16
  import { generatePreCommitHook, generatePostCommitHook, generateSessionManager, generateAgentRouter, generateMemoryHelper, } from './helpers-generator.js';
@@ -204,17 +204,104 @@ export async function executeInit(options) {
204
204
  }
205
205
  return result;
206
206
  }
207
+ /**
208
+ * Merge new settings into existing settings.json
209
+ * Preserves user customizations while adding new features like Agent Teams
210
+ * Uses platform-specific commands for Mac, Linux, and Windows
211
+ */
212
+ function mergeSettingsForUpgrade(existing) {
213
+ const merged = { ...existing };
214
+ const platform = detectPlatform();
215
+ const isWindows = platform.os === 'windows';
216
+ // Platform-specific command wrappers
217
+ // Windows: Use PowerShell-compatible commands
218
+ // Mac/Linux: Use bash-compatible commands with 2>/dev/null
219
+ const teammateIdleCmd = isWindows
220
+ ? 'npx @claude-flow/cli@latest hooks teammate-idle --auto-assign true 2>$null; exit 0'
221
+ : 'npx @claude-flow/cli@latest hooks teammate-idle --auto-assign true 2>/dev/null || true';
222
+ const taskCompletedCmd = isWindows
223
+ ? 'if ($env:TASK_ID) { npx @claude-flow/cli@latest hooks task-completed --task-id $env:TASK_ID --train-patterns true 2>$null }; exit 0'
224
+ : '[ -n "$TASK_ID" ] && npx @claude-flow/cli@latest hooks task-completed --task-id "$TASK_ID" --train-patterns true 2>/dev/null || true';
225
+ // 1. Merge env vars (preserve existing, add new)
226
+ const existingEnv = existing.env || {};
227
+ merged.env = {
228
+ ...existingEnv,
229
+ CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS: '1',
230
+ CLAUDE_FLOW_V3_ENABLED: existingEnv.CLAUDE_FLOW_V3_ENABLED || 'true',
231
+ CLAUDE_FLOW_HOOKS_ENABLED: existingEnv.CLAUDE_FLOW_HOOKS_ENABLED || 'true',
232
+ };
233
+ // 2. Merge hooks (preserve existing, add new Agent Teams hooks)
234
+ const existingHooks = existing.hooks || {};
235
+ merged.hooks = { ...existingHooks };
236
+ // Add TeammateIdle hook if not present
237
+ if (!existingHooks.TeammateIdle) {
238
+ merged.hooks.TeammateIdle = [
239
+ {
240
+ hooks: [
241
+ {
242
+ type: 'command',
243
+ command: teammateIdleCmd,
244
+ timeout: 5000,
245
+ continueOnError: true,
246
+ },
247
+ ],
248
+ },
249
+ ];
250
+ }
251
+ // Add TaskCompleted hook if not present
252
+ if (!existingHooks.TaskCompleted) {
253
+ merged.hooks.TaskCompleted = [
254
+ {
255
+ hooks: [
256
+ {
257
+ type: 'command',
258
+ command: taskCompletedCmd,
259
+ timeout: 5000,
260
+ continueOnError: true,
261
+ },
262
+ ],
263
+ },
264
+ ];
265
+ }
266
+ // 3. Merge claudeFlow settings (preserve existing, add agentTeams)
267
+ const existingClaudeFlow = existing.claudeFlow || {};
268
+ merged.claudeFlow = {
269
+ ...existingClaudeFlow,
270
+ version: existingClaudeFlow.version || '3.0.0',
271
+ enabled: existingClaudeFlow.enabled !== false,
272
+ agentTeams: {
273
+ enabled: true,
274
+ teammateMode: 'auto',
275
+ taskListEnabled: true,
276
+ mailboxEnabled: true,
277
+ coordination: {
278
+ autoAssignOnIdle: true,
279
+ trainPatternsOnComplete: true,
280
+ notifyLeadOnComplete: true,
281
+ sharedMemoryNamespace: 'agent-teams',
282
+ },
283
+ hooks: {
284
+ teammateIdle: { enabled: true, autoAssign: true, checkTaskList: true },
285
+ taskCompleted: { enabled: true, trainPatterns: true, notifyLead: true },
286
+ },
287
+ },
288
+ };
289
+ return merged;
290
+ }
207
291
  /**
208
292
  * Execute upgrade - updates helpers and creates missing metrics without losing data
209
293
  * This is safe for existing users who want the latest statusline fixes
294
+ * @param targetDir - Target directory
295
+ * @param upgradeSettings - If true, merge new settings into existing settings.json
210
296
  */
211
- export async function executeUpgrade(targetDir) {
297
+ export async function executeUpgrade(targetDir, upgradeSettings = false) {
212
298
  const result = {
213
299
  success: true,
214
300
  updated: [],
215
301
  created: [],
216
302
  preserved: [],
217
303
  errors: [],
304
+ settingsUpdated: [],
218
305
  };
219
306
  try {
220
307
  // Ensure required directories exist
@@ -320,6 +407,34 @@ export async function executeUpgrade(targetDir) {
320
407
  else {
321
408
  result.preserved.push('.claude-flow/security/audit-status.json');
322
409
  }
410
+ // 3. Merge settings if requested
411
+ if (upgradeSettings) {
412
+ const settingsPath = path.join(targetDir, '.claude', 'settings.json');
413
+ if (fs.existsSync(settingsPath)) {
414
+ try {
415
+ const existingSettings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
416
+ const mergedSettings = mergeSettingsForUpgrade(existingSettings);
417
+ fs.writeFileSync(settingsPath, JSON.stringify(mergedSettings, null, 2), 'utf-8');
418
+ result.updated.push('.claude/settings.json');
419
+ result.settingsUpdated = [
420
+ 'env.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS',
421
+ 'hooks.TeammateIdle',
422
+ 'hooks.TaskCompleted',
423
+ 'claudeFlow.agentTeams',
424
+ ];
425
+ }
426
+ catch (settingsError) {
427
+ result.errors.push(`Settings merge failed: ${settingsError instanceof Error ? settingsError.message : String(settingsError)}`);
428
+ }
429
+ }
430
+ else {
431
+ // Create new settings.json with defaults
432
+ const defaultSettings = generateSettings(DEFAULT_INIT_OPTIONS);
433
+ fs.writeFileSync(settingsPath, JSON.stringify(defaultSettings, null, 2), 'utf-8');
434
+ result.created.push('.claude/settings.json');
435
+ result.settingsUpdated = ['Created new settings.json with Agent Teams'];
436
+ }
437
+ }
323
438
  }
324
439
  catch (error) {
325
440
  result.success = false;
@@ -330,10 +445,12 @@ export async function executeUpgrade(targetDir) {
330
445
  /**
331
446
  * Execute upgrade with --add-missing flag
332
447
  * Adds any new skills, agents, and commands that don't exist yet
448
+ * @param targetDir - Target directory
449
+ * @param upgradeSettings - If true, merge new settings into existing settings.json
333
450
  */
334
- export async function executeUpgradeWithMissing(targetDir) {
335
- // First do the normal upgrade
336
- const result = await executeUpgrade(targetDir);
451
+ export async function executeUpgradeWithMissing(targetDir, upgradeSettings = false) {
452
+ // First do the normal upgrade (pass through upgradeSettings)
453
+ const result = await executeUpgrade(targetDir, upgradeSettings);
337
454
  if (!result.success) {
338
455
  return result;
339
456
  }
@@ -2,6 +2,7 @@
2
2
  * Settings.json Generator
3
3
  * Creates .claude/settings.json with V3-optimized hook configurations
4
4
  */
5
+ import { detectPlatform } from './types.js';
5
6
  /**
6
7
  * Generate the complete settings.json content
7
8
  */
@@ -161,9 +162,33 @@ function generateStatusLineConfig(options) {
161
162
  }
162
163
  /**
163
164
  * Generate hooks configuration
165
+ * Detects platform and generates appropriate commands for Mac, Linux, and Windows
164
166
  */
165
167
  function generateHooksConfig(config) {
166
168
  const hooks = {};
169
+ const platform = detectPlatform();
170
+ const isWindows = platform.os === 'windows';
171
+ // Platform-specific command helpers
172
+ // Windows: PowerShell syntax with 2>$null and ; exit 0
173
+ // Mac/Linux: Bash syntax with 2>/dev/null || true
174
+ const cmd = {
175
+ // Check if variable is set and run command
176
+ ifVar: (varName, command) => isWindows
177
+ ? `if ($env:${varName}) { ${command} 2>$null }; exit 0`
178
+ : `[ -n "$${varName}" ] && ${command} 2>/dev/null || true`,
179
+ // Simple command with error suppression
180
+ simple: (command) => isWindows
181
+ ? `${command} 2>$null; exit 0`
182
+ : `${command} 2>/dev/null || true`,
183
+ // Echo JSON (different quote escaping)
184
+ echoJson: (json) => isWindows
185
+ ? `Write-Output '${json}'`
186
+ : `echo '${json}'`,
187
+ // Generate timestamp (for unique keys)
188
+ timestamp: () => isWindows
189
+ ? '$(Get-Date -UFormat %s)'
190
+ : '$(date +%s)',
191
+ };
167
192
  // PreToolUse hooks - cross-platform via npx with defensive guards
168
193
  if (config.preToolUse) {
169
194
  hooks.PreToolUse = [
@@ -173,7 +198,9 @@ function generateHooksConfig(config) {
173
198
  hooks: [
174
199
  {
175
200
  type: 'command',
176
- command: '[ -n "$TOOL_INPUT_file_path" ] && npx @claude-flow/cli@latest hooks pre-edit --file "$TOOL_INPUT_file_path" 2>/dev/null || true',
201
+ command: cmd.ifVar('TOOL_INPUT_file_path', isWindows
202
+ ? 'npx @claude-flow/cli@latest hooks pre-edit --file $env:TOOL_INPUT_file_path'
203
+ : 'npx @claude-flow/cli@latest hooks pre-edit --file "$TOOL_INPUT_file_path"'),
177
204
  timeout: config.timeout,
178
205
  continueOnError: true,
179
206
  },
@@ -185,7 +212,9 @@ function generateHooksConfig(config) {
185
212
  hooks: [
186
213
  {
187
214
  type: 'command',
188
- command: '[ -n "$TOOL_INPUT_command" ] && npx @claude-flow/cli@latest hooks pre-command --command "$TOOL_INPUT_command" 2>/dev/null || true',
215
+ command: cmd.ifVar('TOOL_INPUT_command', isWindows
216
+ ? 'npx @claude-flow/cli@latest hooks pre-command --command $env:TOOL_INPUT_command'
217
+ : 'npx @claude-flow/cli@latest hooks pre-command --command "$TOOL_INPUT_command"'),
189
218
  timeout: config.timeout,
190
219
  continueOnError: true,
191
220
  },
@@ -197,7 +226,9 @@ function generateHooksConfig(config) {
197
226
  hooks: [
198
227
  {
199
228
  type: 'command',
200
- command: '[ -n "$TOOL_INPUT_prompt" ] && npx @claude-flow/cli@latest hooks pre-task --task-id "task-$(date +%s)" --description "$TOOL_INPUT_prompt" 2>/dev/null || true',
229
+ command: cmd.ifVar('TOOL_INPUT_prompt', isWindows
230
+ ? `npx @claude-flow/cli@latest hooks pre-task --task-id "task-${cmd.timestamp()}" --description $env:TOOL_INPUT_prompt`
231
+ : `npx @claude-flow/cli@latest hooks pre-task --task-id "task-${cmd.timestamp()}" --description "$TOOL_INPUT_prompt"`),
201
232
  timeout: config.timeout,
202
233
  continueOnError: true,
203
234
  },
@@ -214,7 +245,9 @@ function generateHooksConfig(config) {
214
245
  hooks: [
215
246
  {
216
247
  type: 'command',
217
- command: '[ -n "$TOOL_INPUT_file_path" ] && npx @claude-flow/cli@latest hooks post-edit --file "$TOOL_INPUT_file_path" --success "${TOOL_SUCCESS:-true}" 2>/dev/null || true',
248
+ command: cmd.ifVar('TOOL_INPUT_file_path', isWindows
249
+ ? 'npx @claude-flow/cli@latest hooks post-edit --file $env:TOOL_INPUT_file_path --success $($env:TOOL_SUCCESS ?? "true")'
250
+ : 'npx @claude-flow/cli@latest hooks post-edit --file "$TOOL_INPUT_file_path" --success "${TOOL_SUCCESS:-true}"'),
218
251
  timeout: config.timeout,
219
252
  continueOnError: true,
220
253
  },
@@ -226,7 +259,9 @@ function generateHooksConfig(config) {
226
259
  hooks: [
227
260
  {
228
261
  type: 'command',
229
- command: '[ -n "$TOOL_INPUT_command" ] && npx @claude-flow/cli@latest hooks post-command --command "$TOOL_INPUT_command" --success "${TOOL_SUCCESS:-true}" 2>/dev/null || true',
262
+ command: cmd.ifVar('TOOL_INPUT_command', isWindows
263
+ ? 'npx @claude-flow/cli@latest hooks post-command --command $env:TOOL_INPUT_command --success $($env:TOOL_SUCCESS ?? "true")'
264
+ : 'npx @claude-flow/cli@latest hooks post-command --command "$TOOL_INPUT_command" --success "${TOOL_SUCCESS:-true}"'),
230
265
  timeout: config.timeout,
231
266
  continueOnError: true,
232
267
  },
@@ -238,7 +273,9 @@ function generateHooksConfig(config) {
238
273
  hooks: [
239
274
  {
240
275
  type: 'command',
241
- command: '[ -n "$TOOL_RESULT_agent_id" ] && npx @claude-flow/cli@latest hooks post-task --task-id "$TOOL_RESULT_agent_id" --success "${TOOL_SUCCESS:-true}" 2>/dev/null || true',
276
+ command: cmd.ifVar('TOOL_RESULT_agent_id', isWindows
277
+ ? 'npx @claude-flow/cli@latest hooks post-task --task-id $env:TOOL_RESULT_agent_id --success $($env:TOOL_SUCCESS ?? "true")'
278
+ : 'npx @claude-flow/cli@latest hooks post-task --task-id "$TOOL_RESULT_agent_id" --success "${TOOL_SUCCESS:-true}"'),
242
279
  timeout: config.timeout,
243
280
  continueOnError: true,
244
281
  },
@@ -253,7 +290,9 @@ function generateHooksConfig(config) {
253
290
  hooks: [
254
291
  {
255
292
  type: 'command',
256
- command: '[ -n "$PROMPT" ] && npx @claude-flow/cli@latest hooks route --task "$PROMPT" || true',
293
+ command: cmd.ifVar('PROMPT', isWindows
294
+ ? 'npx @claude-flow/cli@latest hooks route --task $env:PROMPT'
295
+ : 'npx @claude-flow/cli@latest hooks route --task "$PROMPT"'),
257
296
  timeout: config.timeout,
258
297
  continueOnError: true,
259
298
  },
@@ -268,13 +307,15 @@ function generateHooksConfig(config) {
268
307
  hooks: [
269
308
  {
270
309
  type: 'command',
271
- command: 'npx @claude-flow/cli@latest daemon start --quiet 2>/dev/null || true',
310
+ command: cmd.simple('npx @claude-flow/cli@latest daemon start --quiet'),
272
311
  timeout: 5000,
273
312
  continueOnError: true,
274
313
  },
275
314
  {
276
315
  type: 'command',
277
- command: '[ -n "$SESSION_ID" ] && npx @claude-flow/cli@latest hooks session-restore --session-id "$SESSION_ID" 2>/dev/null || true',
316
+ command: cmd.ifVar('SESSION_ID', isWindows
317
+ ? 'npx @claude-flow/cli@latest hooks session-restore --session-id $env:SESSION_ID'
318
+ : 'npx @claude-flow/cli@latest hooks session-restore --session-id "$SESSION_ID"'),
278
319
  timeout: 10000,
279
320
  continueOnError: true,
280
321
  },
@@ -290,7 +331,7 @@ function generateHooksConfig(config) {
290
331
  hooks: [
291
332
  {
292
333
  type: 'command',
293
- command: 'echo \'{"ok": true}\'',
334
+ command: cmd.echoJson('{"ok": true}'),
294
335
  timeout: 1000,
295
336
  },
296
337
  ],
@@ -304,7 +345,9 @@ function generateHooksConfig(config) {
304
345
  hooks: [
305
346
  {
306
347
  type: 'command',
307
- command: '[ -n "$NOTIFICATION_MESSAGE" ] && npx @claude-flow/cli@latest memory store --namespace notifications --key "notify-$(date +%s)" --value "$NOTIFICATION_MESSAGE" 2>/dev/null || true',
348
+ command: cmd.ifVar('NOTIFICATION_MESSAGE', isWindows
349
+ ? `npx @claude-flow/cli@latest memory store --namespace notifications --key "notify-${cmd.timestamp()}" --value $env:NOTIFICATION_MESSAGE`
350
+ : `npx @claude-flow/cli@latest memory store --namespace notifications --key "notify-${cmd.timestamp()}" --value "$NOTIFICATION_MESSAGE"`),
308
351
  timeout: 3000,
309
352
  continueOnError: true,
310
353
  },
@@ -320,7 +363,7 @@ function generateHooksConfig(config) {
320
363
  hooks: [
321
364
  {
322
365
  type: 'command',
323
- command: 'npx @claude-flow/cli@latest hooks teammate-idle --auto-assign true 2>/dev/null || true',
366
+ command: cmd.simple('npx @claude-flow/cli@latest hooks teammate-idle --auto-assign true'),
324
367
  timeout: 5000,
325
368
  continueOnError: true,
326
369
  },
@@ -332,7 +375,9 @@ function generateHooksConfig(config) {
332
375
  hooks: [
333
376
  {
334
377
  type: 'command',
335
- command: '[ -n "$TASK_ID" ] && npx @claude-flow/cli@latest hooks task-completed --task-id "$TASK_ID" --train-patterns true 2>/dev/null || true',
378
+ command: cmd.ifVar('TASK_ID', isWindows
379
+ ? 'npx @claude-flow/cli@latest hooks task-completed --task-id $env:TASK_ID --train-patterns true'
380
+ : 'npx @claude-flow/cli@latest hooks task-completed --task-id "$TASK_ID" --train-patterns true'),
336
381
  timeout: 5000,
337
382
  continueOnError: true,
338
383
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claude-flow/cli",
3
- "version": "3.1.0-alpha.13",
3
+ "version": "3.1.0-alpha.14",
4
4
  "type": "module",
5
5
  "description": "Claude Flow CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
6
6
  "main": "dist/src/index.js",