@claude-flow/cli 3.0.0-alpha.1
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.
- package/.agentic-flow/intelligence.json +16 -0
- package/.claude-flow/metrics/agent-metrics.json +1 -0
- package/.claude-flow/metrics/performance.json +87 -0
- package/.claude-flow/metrics/task-metrics.json +10 -0
- package/README.md +1186 -0
- package/__tests__/README.md +140 -0
- package/__tests__/TEST_SUMMARY.md +144 -0
- package/__tests__/cli.test.ts +558 -0
- package/__tests__/commands.test.ts +726 -0
- package/__tests__/config-adapter.test.ts +362 -0
- package/__tests__/config-loading.test.ts +106 -0
- package/__tests__/coverage/.tmp/coverage-0.json +1 -0
- package/__tests__/coverage/.tmp/coverage-1.json +1 -0
- package/__tests__/coverage/.tmp/coverage-2.json +1 -0
- package/__tests__/coverage/.tmp/coverage-3.json +1 -0
- package/__tests__/coverage/.tmp/coverage-4.json +1 -0
- package/__tests__/coverage/.tmp/coverage-5.json +1 -0
- package/__tests__/mcp-client.test.ts +480 -0
- package/__tests__/p1-commands.test.ts +1064 -0
- package/bin/cli.js +14 -0
- package/dist/src/commands/agent.d.ts +8 -0
- package/dist/src/commands/agent.d.ts.map +1 -0
- package/dist/src/commands/agent.js +803 -0
- package/dist/src/commands/agent.js.map +1 -0
- package/dist/src/commands/config.d.ts +8 -0
- package/dist/src/commands/config.d.ts.map +1 -0
- package/dist/src/commands/config.js +406 -0
- package/dist/src/commands/config.js.map +1 -0
- package/dist/src/commands/hive-mind.d.ts +8 -0
- package/dist/src/commands/hive-mind.d.ts.map +1 -0
- package/dist/src/commands/hive-mind.js +627 -0
- package/dist/src/commands/hive-mind.js.map +1 -0
- package/dist/src/commands/hooks.d.ts +8 -0
- package/dist/src/commands/hooks.d.ts.map +1 -0
- package/dist/src/commands/hooks.js +2098 -0
- package/dist/src/commands/hooks.js.map +1 -0
- package/dist/src/commands/index.d.ts +51 -0
- package/dist/src/commands/index.d.ts.map +1 -0
- package/dist/src/commands/index.js +105 -0
- package/dist/src/commands/index.js.map +1 -0
- package/dist/src/commands/init.d.ts +8 -0
- package/dist/src/commands/init.d.ts.map +1 -0
- package/dist/src/commands/init.js +532 -0
- package/dist/src/commands/init.js.map +1 -0
- package/dist/src/commands/mcp.d.ts +11 -0
- package/dist/src/commands/mcp.d.ts.map +1 -0
- package/dist/src/commands/mcp.js +662 -0
- package/dist/src/commands/mcp.js.map +1 -0
- package/dist/src/commands/memory.d.ts +8 -0
- package/dist/src/commands/memory.d.ts.map +1 -0
- package/dist/src/commands/memory.js +911 -0
- package/dist/src/commands/memory.js.map +1 -0
- package/dist/src/commands/migrate.d.ts +8 -0
- package/dist/src/commands/migrate.d.ts.map +1 -0
- package/dist/src/commands/migrate.js +398 -0
- package/dist/src/commands/migrate.js.map +1 -0
- package/dist/src/commands/process.d.ts +10 -0
- package/dist/src/commands/process.d.ts.map +1 -0
- package/dist/src/commands/process.js +566 -0
- package/dist/src/commands/process.js.map +1 -0
- package/dist/src/commands/session.d.ts +8 -0
- package/dist/src/commands/session.d.ts.map +1 -0
- package/dist/src/commands/session.js +750 -0
- package/dist/src/commands/session.js.map +1 -0
- package/dist/src/commands/start.d.ts +8 -0
- package/dist/src/commands/start.d.ts.map +1 -0
- package/dist/src/commands/start.js +398 -0
- package/dist/src/commands/start.js.map +1 -0
- package/dist/src/commands/status.d.ts +8 -0
- package/dist/src/commands/status.d.ts.map +1 -0
- package/dist/src/commands/status.js +560 -0
- package/dist/src/commands/status.js.map +1 -0
- package/dist/src/commands/swarm.d.ts +8 -0
- package/dist/src/commands/swarm.d.ts.map +1 -0
- package/dist/src/commands/swarm.js +573 -0
- package/dist/src/commands/swarm.js.map +1 -0
- package/dist/src/commands/task.d.ts +8 -0
- package/dist/src/commands/task.d.ts.map +1 -0
- package/dist/src/commands/task.js +671 -0
- package/dist/src/commands/task.js.map +1 -0
- package/dist/src/commands/workflow.d.ts +8 -0
- package/dist/src/commands/workflow.d.ts.map +1 -0
- package/dist/src/commands/workflow.js +617 -0
- package/dist/src/commands/workflow.js.map +1 -0
- package/dist/src/config-adapter.d.ts +15 -0
- package/dist/src/config-adapter.d.ts.map +1 -0
- package/dist/src/config-adapter.js +185 -0
- package/dist/src/config-adapter.js.map +1 -0
- package/dist/src/index.d.ts +55 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +312 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/infrastructure/in-memory-repositories.d.ts +68 -0
- package/dist/src/infrastructure/in-memory-repositories.d.ts.map +1 -0
- package/dist/src/infrastructure/in-memory-repositories.js +264 -0
- package/dist/src/infrastructure/in-memory-repositories.js.map +1 -0
- package/dist/src/init/claudemd-generator.d.ts +15 -0
- package/dist/src/init/claudemd-generator.d.ts.map +1 -0
- package/dist/src/init/claudemd-generator.js +626 -0
- package/dist/src/init/claudemd-generator.js.map +1 -0
- package/dist/src/init/executor.d.ts +11 -0
- package/dist/src/init/executor.d.ts.map +1 -0
- package/dist/src/init/executor.js +647 -0
- package/dist/src/init/executor.js.map +1 -0
- package/dist/src/init/helpers-generator.d.ts +42 -0
- package/dist/src/init/helpers-generator.d.ts.map +1 -0
- package/dist/src/init/helpers-generator.js +613 -0
- package/dist/src/init/helpers-generator.js.map +1 -0
- package/dist/src/init/index.d.ts +12 -0
- package/dist/src/init/index.d.ts.map +1 -0
- package/dist/src/init/index.js +15 -0
- package/dist/src/init/index.js.map +1 -0
- package/dist/src/init/mcp-generator.d.ts +18 -0
- package/dist/src/init/mcp-generator.d.ts.map +1 -0
- package/dist/src/init/mcp-generator.js +71 -0
- package/dist/src/init/mcp-generator.js.map +1 -0
- package/dist/src/init/settings-generator.d.ts +14 -0
- package/dist/src/init/settings-generator.d.ts.map +1 -0
- package/dist/src/init/settings-generator.js +257 -0
- package/dist/src/init/settings-generator.js.map +1 -0
- package/dist/src/init/statusline-generator.d.ts +14 -0
- package/dist/src/init/statusline-generator.d.ts.map +1 -0
- package/dist/src/init/statusline-generator.js +206 -0
- package/dist/src/init/statusline-generator.js.map +1 -0
- package/dist/src/init/types.d.ts +240 -0
- package/dist/src/init/types.d.ts.map +1 -0
- package/dist/src/init/types.js +210 -0
- package/dist/src/init/types.js.map +1 -0
- package/dist/src/mcp-client.d.ts +92 -0
- package/dist/src/mcp-client.d.ts.map +1 -0
- package/dist/src/mcp-client.js +189 -0
- package/dist/src/mcp-client.js.map +1 -0
- package/dist/src/mcp-server.d.ts +153 -0
- package/dist/src/mcp-server.d.ts.map +1 -0
- package/dist/src/mcp-server.js +448 -0
- package/dist/src/mcp-server.js.map +1 -0
- package/dist/src/mcp-tools/agent-tools.d.ts +8 -0
- package/dist/src/mcp-tools/agent-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/agent-tools.js +90 -0
- package/dist/src/mcp-tools/agent-tools.js.map +1 -0
- package/dist/src/mcp-tools/config-tools.d.ts +8 -0
- package/dist/src/mcp-tools/config-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/config-tools.js +86 -0
- package/dist/src/mcp-tools/config-tools.js.map +1 -0
- package/dist/src/mcp-tools/hooks-tools.d.ts +41 -0
- package/dist/src/mcp-tools/hooks-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/hooks-tools.js +1646 -0
- package/dist/src/mcp-tools/hooks-tools.js.map +1 -0
- package/dist/src/mcp-tools/index.d.ts +12 -0
- package/dist/src/mcp-tools/index.d.ts.map +1 -0
- package/dist/src/mcp-tools/index.js +11 -0
- package/dist/src/mcp-tools/index.js.map +1 -0
- package/dist/src/mcp-tools/memory-tools.d.ts +8 -0
- package/dist/src/mcp-tools/memory-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/memory-tools.js +87 -0
- package/dist/src/mcp-tools/memory-tools.js.map +1 -0
- package/dist/src/mcp-tools/swarm-tools.d.ts +8 -0
- package/dist/src/mcp-tools/swarm-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/swarm-tools.js +67 -0
- package/dist/src/mcp-tools/swarm-tools.js.map +1 -0
- package/dist/src/mcp-tools/types.d.ts +31 -0
- package/dist/src/mcp-tools/types.d.ts.map +1 -0
- package/dist/src/mcp-tools/types.js +7 -0
- package/dist/src/mcp-tools/types.js.map +1 -0
- package/dist/src/output.d.ts +117 -0
- package/dist/src/output.d.ts.map +1 -0
- package/dist/src/output.js +471 -0
- package/dist/src/output.js.map +1 -0
- package/dist/src/parser.d.ts +41 -0
- package/dist/src/parser.d.ts.map +1 -0
- package/dist/src/parser.js +353 -0
- package/dist/src/parser.js.map +1 -0
- package/dist/src/prompt.d.ts +44 -0
- package/dist/src/prompt.d.ts.map +1 -0
- package/dist/src/prompt.js +501 -0
- package/dist/src/prompt.js.map +1 -0
- package/dist/src/types.d.ts +198 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +38 -0
- package/dist/src/types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/docs/CONFIG_LOADING.md +236 -0
- package/docs/IMPLEMENTATION_COMPLETE.md +421 -0
- package/docs/MCP_CLIENT_GUIDE.md +620 -0
- package/docs/REFACTORING_SUMMARY.md +247 -0
- package/package.json +29 -0
- package/src/commands/agent.ts +941 -0
- package/src/commands/config.ts +452 -0
- package/src/commands/hive-mind.ts +762 -0
- package/src/commands/hooks.ts +2603 -0
- package/src/commands/index.ts +115 -0
- package/src/commands/init.ts +597 -0
- package/src/commands/mcp.ts +753 -0
- package/src/commands/memory.ts +1063 -0
- package/src/commands/migrate.ts +447 -0
- package/src/commands/process.ts +617 -0
- package/src/commands/session.ts +891 -0
- package/src/commands/start.ts +457 -0
- package/src/commands/status.ts +705 -0
- package/src/commands/swarm.ts +648 -0
- package/src/commands/task.ts +792 -0
- package/src/commands/workflow.ts +742 -0
- package/src/config-adapter.ts +210 -0
- package/src/index.ts +383 -0
- package/src/infrastructure/in-memory-repositories.ts +310 -0
- package/src/init/claudemd-generator.ts +631 -0
- package/src/init/executor.ts +756 -0
- package/src/init/helpers-generator.ts +628 -0
- package/src/init/index.ts +60 -0
- package/src/init/mcp-generator.ts +83 -0
- package/src/init/settings-generator.ts +274 -0
- package/src/init/statusline-generator.ts +211 -0
- package/src/init/types.ts +447 -0
- package/src/mcp-client.ts +227 -0
- package/src/mcp-server.ts +571 -0
- package/src/mcp-tools/agent-tools.ts +92 -0
- package/src/mcp-tools/config-tools.ts +88 -0
- package/src/mcp-tools/hooks-tools.ts +1819 -0
- package/src/mcp-tools/index.ts +12 -0
- package/src/mcp-tools/memory-tools.ts +89 -0
- package/src/mcp-tools/swarm-tools.ts +69 -0
- package/src/mcp-tools/types.ts +33 -0
- package/src/output.ts +593 -0
- package/src/parser.ts +417 -0
- package/src/prompt.ts +619 -0
- package/src/types.ts +287 -0
- package/tsconfig.json +16 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/vitest.config.ts +13 -0
|
@@ -0,0 +1,628 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers Generator
|
|
3
|
+
* Creates utility scripts in .claude/helpers/
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { InitOptions } from './types.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Generate pre-commit hook script
|
|
10
|
+
*/
|
|
11
|
+
export function generatePreCommitHook(): string {
|
|
12
|
+
return `#!/bin/bash
|
|
13
|
+
# Claude Flow Pre-Commit Hook
|
|
14
|
+
# Validates code quality before commit
|
|
15
|
+
|
|
16
|
+
set -e
|
|
17
|
+
|
|
18
|
+
echo "🔍 Running Claude Flow pre-commit checks..."
|
|
19
|
+
|
|
20
|
+
# Get staged files
|
|
21
|
+
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)
|
|
22
|
+
|
|
23
|
+
# Run validation for each staged file
|
|
24
|
+
for FILE in $STAGED_FILES; do
|
|
25
|
+
if [[ "$FILE" =~ \\.(ts|js|tsx|jsx)$ ]]; then
|
|
26
|
+
echo " Validating: $FILE"
|
|
27
|
+
npx @claude-flow/cli hooks pre-edit --file "$FILE" --validate-syntax 2>/dev/null || true
|
|
28
|
+
fi
|
|
29
|
+
done
|
|
30
|
+
|
|
31
|
+
# Run tests if available
|
|
32
|
+
if [ -f "package.json" ] && grep -q '"test"' package.json; then
|
|
33
|
+
echo "🧪 Running tests..."
|
|
34
|
+
npm test --if-present 2>/dev/null || echo " Tests skipped or failed"
|
|
35
|
+
fi
|
|
36
|
+
|
|
37
|
+
echo "✅ Pre-commit checks complete"
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Generate post-commit hook script
|
|
43
|
+
*/
|
|
44
|
+
export function generatePostCommitHook(): string {
|
|
45
|
+
return `#!/bin/bash
|
|
46
|
+
# Claude Flow Post-Commit Hook
|
|
47
|
+
# Records commit metrics and trains patterns
|
|
48
|
+
|
|
49
|
+
COMMIT_HASH=$(git rev-parse HEAD)
|
|
50
|
+
COMMIT_MSG=$(git log -1 --pretty=%B)
|
|
51
|
+
|
|
52
|
+
echo "📊 Recording commit metrics..."
|
|
53
|
+
|
|
54
|
+
# Notify claude-flow of commit
|
|
55
|
+
npx @claude-flow/cli hooks notify \\
|
|
56
|
+
--message "Commit: $COMMIT_MSG" \\
|
|
57
|
+
--level info \\
|
|
58
|
+
--metadata '{"hash": "'$COMMIT_HASH'"}' 2>/dev/null || true
|
|
59
|
+
|
|
60
|
+
echo "✅ Commit recorded"
|
|
61
|
+
`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Generate session manager script
|
|
66
|
+
*/
|
|
67
|
+
export function generateSessionManager(): string {
|
|
68
|
+
return `#!/usr/bin/env node
|
|
69
|
+
/**
|
|
70
|
+
* Claude Flow Session Manager
|
|
71
|
+
* Handles session lifecycle: start, restore, end
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
const fs = require('fs');
|
|
75
|
+
const path = require('path');
|
|
76
|
+
|
|
77
|
+
const SESSION_DIR = path.join(process.cwd(), '.claude-flow', 'sessions');
|
|
78
|
+
const SESSION_FILE = path.join(SESSION_DIR, 'current.json');
|
|
79
|
+
|
|
80
|
+
const commands = {
|
|
81
|
+
start: () => {
|
|
82
|
+
const sessionId = \`session-\${Date.now()}\`;
|
|
83
|
+
const session = {
|
|
84
|
+
id: sessionId,
|
|
85
|
+
startedAt: new Date().toISOString(),
|
|
86
|
+
cwd: process.cwd(),
|
|
87
|
+
context: {},
|
|
88
|
+
metrics: {
|
|
89
|
+
edits: 0,
|
|
90
|
+
commands: 0,
|
|
91
|
+
tasks: 0,
|
|
92
|
+
errors: 0,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
fs.mkdirSync(SESSION_DIR, { recursive: true });
|
|
97
|
+
fs.writeFileSync(SESSION_FILE, JSON.stringify(session, null, 2));
|
|
98
|
+
|
|
99
|
+
console.log(\`Session started: \${sessionId}\`);
|
|
100
|
+
return session;
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
restore: () => {
|
|
104
|
+
if (!fs.existsSync(SESSION_FILE)) {
|
|
105
|
+
console.log('No session to restore');
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const session = JSON.parse(fs.readFileSync(SESSION_FILE, 'utf-8'));
|
|
110
|
+
session.restoredAt = new Date().toISOString();
|
|
111
|
+
fs.writeFileSync(SESSION_FILE, JSON.stringify(session, null, 2));
|
|
112
|
+
|
|
113
|
+
console.log(\`Session restored: \${session.id}\`);
|
|
114
|
+
return session;
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
end: () => {
|
|
118
|
+
if (!fs.existsSync(SESSION_FILE)) {
|
|
119
|
+
console.log('No active session');
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const session = JSON.parse(fs.readFileSync(SESSION_FILE, 'utf-8'));
|
|
124
|
+
session.endedAt = new Date().toISOString();
|
|
125
|
+
session.duration = Date.now() - new Date(session.startedAt).getTime();
|
|
126
|
+
|
|
127
|
+
// Archive session
|
|
128
|
+
const archivePath = path.join(SESSION_DIR, \`\${session.id}.json\`);
|
|
129
|
+
fs.writeFileSync(archivePath, JSON.stringify(session, null, 2));
|
|
130
|
+
fs.unlinkSync(SESSION_FILE);
|
|
131
|
+
|
|
132
|
+
console.log(\`Session ended: \${session.id}\`);
|
|
133
|
+
console.log(\`Duration: \${Math.round(session.duration / 1000 / 60)} minutes\`);
|
|
134
|
+
console.log(\`Metrics: \${JSON.stringify(session.metrics)}\`);
|
|
135
|
+
|
|
136
|
+
return session;
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
status: () => {
|
|
140
|
+
if (!fs.existsSync(SESSION_FILE)) {
|
|
141
|
+
console.log('No active session');
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const session = JSON.parse(fs.readFileSync(SESSION_FILE, 'utf-8'));
|
|
146
|
+
const duration = Date.now() - new Date(session.startedAt).getTime();
|
|
147
|
+
|
|
148
|
+
console.log(\`Session: \${session.id}\`);
|
|
149
|
+
console.log(\`Started: \${session.startedAt}\`);
|
|
150
|
+
console.log(\`Duration: \${Math.round(duration / 1000 / 60)} minutes\`);
|
|
151
|
+
console.log(\`Metrics: \${JSON.stringify(session.metrics)}\`);
|
|
152
|
+
|
|
153
|
+
return session;
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
update: (key, value) => {
|
|
157
|
+
if (!fs.existsSync(SESSION_FILE)) {
|
|
158
|
+
console.log('No active session');
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const session = JSON.parse(fs.readFileSync(SESSION_FILE, 'utf-8'));
|
|
163
|
+
session.context[key] = value;
|
|
164
|
+
session.updatedAt = new Date().toISOString();
|
|
165
|
+
fs.writeFileSync(SESSION_FILE, JSON.stringify(session, null, 2));
|
|
166
|
+
|
|
167
|
+
return session;
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
metric: (name) => {
|
|
171
|
+
if (!fs.existsSync(SESSION_FILE)) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const session = JSON.parse(fs.readFileSync(SESSION_FILE, 'utf-8'));
|
|
176
|
+
if (session.metrics[name] !== undefined) {
|
|
177
|
+
session.metrics[name]++;
|
|
178
|
+
fs.writeFileSync(SESSION_FILE, JSON.stringify(session, null, 2));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return session;
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// CLI
|
|
186
|
+
const [,, command, ...args] = process.argv;
|
|
187
|
+
|
|
188
|
+
if (command && commands[command]) {
|
|
189
|
+
commands[command](...args);
|
|
190
|
+
} else {
|
|
191
|
+
console.log('Usage: session.js <start|restore|end|status|update|metric> [args]');
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
module.exports = commands;
|
|
195
|
+
`;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Generate agent router script
|
|
200
|
+
*/
|
|
201
|
+
export function generateAgentRouter(): string {
|
|
202
|
+
return `#!/usr/bin/env node
|
|
203
|
+
/**
|
|
204
|
+
* Claude Flow Agent Router
|
|
205
|
+
* Routes tasks to optimal agents based on learned patterns
|
|
206
|
+
*/
|
|
207
|
+
|
|
208
|
+
const AGENT_CAPABILITIES = {
|
|
209
|
+
coder: ['code-generation', 'refactoring', 'debugging', 'implementation'],
|
|
210
|
+
tester: ['unit-testing', 'integration-testing', 'coverage', 'test-generation'],
|
|
211
|
+
reviewer: ['code-review', 'security-audit', 'quality-check', 'best-practices'],
|
|
212
|
+
researcher: ['web-search', 'documentation', 'analysis', 'summarization'],
|
|
213
|
+
architect: ['system-design', 'architecture', 'patterns', 'scalability'],
|
|
214
|
+
'backend-dev': ['api', 'database', 'server', 'authentication'],
|
|
215
|
+
'frontend-dev': ['ui', 'react', 'css', 'components'],
|
|
216
|
+
devops: ['ci-cd', 'docker', 'deployment', 'infrastructure'],
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const TASK_PATTERNS = {
|
|
220
|
+
// Code patterns
|
|
221
|
+
'implement|create|build|add|write code': 'coder',
|
|
222
|
+
'test|spec|coverage|unit test|integration': 'tester',
|
|
223
|
+
'review|audit|check|validate|security': 'reviewer',
|
|
224
|
+
'research|find|search|documentation|explore': 'researcher',
|
|
225
|
+
'design|architect|structure|plan': 'architect',
|
|
226
|
+
|
|
227
|
+
// Domain patterns
|
|
228
|
+
'api|endpoint|server|backend|database': 'backend-dev',
|
|
229
|
+
'ui|frontend|component|react|css|style': 'frontend-dev',
|
|
230
|
+
'deploy|docker|ci|cd|pipeline|infrastructure': 'devops',
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
function routeTask(task) {
|
|
234
|
+
const taskLower = task.toLowerCase();
|
|
235
|
+
|
|
236
|
+
// Check patterns
|
|
237
|
+
for (const [pattern, agent] of Object.entries(TASK_PATTERNS)) {
|
|
238
|
+
const regex = new RegExp(pattern, 'i');
|
|
239
|
+
if (regex.test(taskLower)) {
|
|
240
|
+
return {
|
|
241
|
+
agent,
|
|
242
|
+
confidence: 0.8,
|
|
243
|
+
reason: \`Matched pattern: \${pattern}\`,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Default to coder for unknown tasks
|
|
249
|
+
return {
|
|
250
|
+
agent: 'coder',
|
|
251
|
+
confidence: 0.5,
|
|
252
|
+
reason: 'Default routing - no specific pattern matched',
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// CLI
|
|
257
|
+
const task = process.argv.slice(2).join(' ');
|
|
258
|
+
|
|
259
|
+
if (task) {
|
|
260
|
+
const result = routeTask(task);
|
|
261
|
+
console.log(JSON.stringify(result, null, 2));
|
|
262
|
+
} else {
|
|
263
|
+
console.log('Usage: router.js <task description>');
|
|
264
|
+
console.log('\\nAvailable agents:', Object.keys(AGENT_CAPABILITIES).join(', '));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
module.exports = { routeTask, AGENT_CAPABILITIES, TASK_PATTERNS };
|
|
268
|
+
`;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Generate memory helper script
|
|
273
|
+
*/
|
|
274
|
+
export function generateMemoryHelper(): string {
|
|
275
|
+
return `#!/usr/bin/env node
|
|
276
|
+
/**
|
|
277
|
+
* Claude Flow Memory Helper
|
|
278
|
+
* Simple key-value memory for cross-session context
|
|
279
|
+
*/
|
|
280
|
+
|
|
281
|
+
const fs = require('fs');
|
|
282
|
+
const path = require('path');
|
|
283
|
+
|
|
284
|
+
const MEMORY_DIR = path.join(process.cwd(), '.claude-flow', 'data');
|
|
285
|
+
const MEMORY_FILE = path.join(MEMORY_DIR, 'memory.json');
|
|
286
|
+
|
|
287
|
+
function loadMemory() {
|
|
288
|
+
try {
|
|
289
|
+
if (fs.existsSync(MEMORY_FILE)) {
|
|
290
|
+
return JSON.parse(fs.readFileSync(MEMORY_FILE, 'utf-8'));
|
|
291
|
+
}
|
|
292
|
+
} catch (e) {
|
|
293
|
+
// Ignore
|
|
294
|
+
}
|
|
295
|
+
return {};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function saveMemory(memory) {
|
|
299
|
+
fs.mkdirSync(MEMORY_DIR, { recursive: true });
|
|
300
|
+
fs.writeFileSync(MEMORY_FILE, JSON.stringify(memory, null, 2));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const commands = {
|
|
304
|
+
get: (key) => {
|
|
305
|
+
const memory = loadMemory();
|
|
306
|
+
const value = key ? memory[key] : memory;
|
|
307
|
+
console.log(JSON.stringify(value, null, 2));
|
|
308
|
+
return value;
|
|
309
|
+
},
|
|
310
|
+
|
|
311
|
+
set: (key, value) => {
|
|
312
|
+
if (!key) {
|
|
313
|
+
console.error('Key required');
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const memory = loadMemory();
|
|
317
|
+
memory[key] = value;
|
|
318
|
+
memory._updated = new Date().toISOString();
|
|
319
|
+
saveMemory(memory);
|
|
320
|
+
console.log(\`Set: \${key}\`);
|
|
321
|
+
},
|
|
322
|
+
|
|
323
|
+
delete: (key) => {
|
|
324
|
+
if (!key) {
|
|
325
|
+
console.error('Key required');
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const memory = loadMemory();
|
|
329
|
+
delete memory[key];
|
|
330
|
+
saveMemory(memory);
|
|
331
|
+
console.log(\`Deleted: \${key}\`);
|
|
332
|
+
},
|
|
333
|
+
|
|
334
|
+
clear: () => {
|
|
335
|
+
saveMemory({});
|
|
336
|
+
console.log('Memory cleared');
|
|
337
|
+
},
|
|
338
|
+
|
|
339
|
+
keys: () => {
|
|
340
|
+
const memory = loadMemory();
|
|
341
|
+
const keys = Object.keys(memory).filter(k => !k.startsWith('_'));
|
|
342
|
+
console.log(keys.join('\\n'));
|
|
343
|
+
return keys;
|
|
344
|
+
},
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
// CLI
|
|
348
|
+
const [,, command, key, ...valueParts] = process.argv;
|
|
349
|
+
const value = valueParts.join(' ');
|
|
350
|
+
|
|
351
|
+
if (command && commands[command]) {
|
|
352
|
+
commands[command](key, value);
|
|
353
|
+
} else {
|
|
354
|
+
console.log('Usage: memory.js <get|set|delete|clear|keys> [key] [value]');
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
module.exports = commands;
|
|
358
|
+
`;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Generate Windows PowerShell daemon manager
|
|
363
|
+
*/
|
|
364
|
+
export function generateWindowsDaemonManager(): string {
|
|
365
|
+
return `# Claude Flow V3 Daemon Manager for Windows
|
|
366
|
+
# PowerShell script for managing background processes
|
|
367
|
+
|
|
368
|
+
param(
|
|
369
|
+
[Parameter(Position=0)]
|
|
370
|
+
[ValidateSet('start', 'stop', 'status', 'restart')]
|
|
371
|
+
[string]$Action = 'status'
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
$ErrorActionPreference = 'SilentlyContinue'
|
|
375
|
+
$ClaudeFlowDir = Join-Path $PWD '.claude-flow'
|
|
376
|
+
$PidDir = Join-Path $ClaudeFlowDir 'pids'
|
|
377
|
+
|
|
378
|
+
# Ensure directories exist
|
|
379
|
+
if (-not (Test-Path $PidDir)) {
|
|
380
|
+
New-Item -ItemType Directory -Path $PidDir -Force | Out-Null
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function Get-DaemonStatus {
|
|
384
|
+
param([string]$Name, [string]$PidFile)
|
|
385
|
+
|
|
386
|
+
if (Test-Path $PidFile) {
|
|
387
|
+
$pid = Get-Content $PidFile
|
|
388
|
+
$process = Get-Process -Id $pid -ErrorAction SilentlyContinue
|
|
389
|
+
if ($process) {
|
|
390
|
+
return @{ Running = $true; Pid = $pid }
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return @{ Running = $false; Pid = $null }
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function Start-SwarmMonitor {
|
|
397
|
+
$pidFile = Join-Path $PidDir 'swarm-monitor.pid'
|
|
398
|
+
$status = Get-DaemonStatus -Name 'swarm-monitor' -PidFile $pidFile
|
|
399
|
+
|
|
400
|
+
if ($status.Running) {
|
|
401
|
+
Write-Host "Swarm monitor already running (PID: $($status.Pid))" -ForegroundColor Yellow
|
|
402
|
+
return
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
Write-Host "Starting swarm monitor..." -ForegroundColor Cyan
|
|
406
|
+
$process = Start-Process -FilePath 'node' -ArgumentList @(
|
|
407
|
+
'-e',
|
|
408
|
+
'setInterval(() => { require("fs").writeFileSync(".claude-flow/metrics/swarm-activity.json", JSON.stringify({swarm:{active:true,agent_count:0},timestamp:Date.now()})) }, 5000)'
|
|
409
|
+
) -PassThru -WindowStyle Hidden
|
|
410
|
+
|
|
411
|
+
$process.Id | Out-File $pidFile
|
|
412
|
+
Write-Host "Swarm monitor started (PID: $($process.Id))" -ForegroundColor Green
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function Stop-SwarmMonitor {
|
|
416
|
+
$pidFile = Join-Path $PidDir 'swarm-monitor.pid'
|
|
417
|
+
$status = Get-DaemonStatus -Name 'swarm-monitor' -PidFile $pidFile
|
|
418
|
+
|
|
419
|
+
if (-not $status.Running) {
|
|
420
|
+
Write-Host "Swarm monitor not running" -ForegroundColor Yellow
|
|
421
|
+
return
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
Stop-Process -Id $status.Pid -Force
|
|
425
|
+
Remove-Item $pidFile -Force
|
|
426
|
+
Write-Host "Swarm monitor stopped" -ForegroundColor Green
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function Show-Status {
|
|
430
|
+
Write-Host ""
|
|
431
|
+
Write-Host "Claude Flow V3 Daemon Status" -ForegroundColor Cyan
|
|
432
|
+
Write-Host "=============================" -ForegroundColor Cyan
|
|
433
|
+
|
|
434
|
+
$swarmPid = Join-Path $PidDir 'swarm-monitor.pid'
|
|
435
|
+
$swarmStatus = Get-DaemonStatus -Name 'swarm-monitor' -PidFile $swarmPid
|
|
436
|
+
|
|
437
|
+
if ($swarmStatus.Running) {
|
|
438
|
+
Write-Host " Swarm Monitor: RUNNING (PID: $($swarmStatus.Pid))" -ForegroundColor Green
|
|
439
|
+
} else {
|
|
440
|
+
Write-Host " Swarm Monitor: STOPPED" -ForegroundColor Red
|
|
441
|
+
}
|
|
442
|
+
Write-Host ""
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
switch ($Action) {
|
|
446
|
+
'start' {
|
|
447
|
+
Start-SwarmMonitor
|
|
448
|
+
Show-Status
|
|
449
|
+
}
|
|
450
|
+
'stop' {
|
|
451
|
+
Stop-SwarmMonitor
|
|
452
|
+
Show-Status
|
|
453
|
+
}
|
|
454
|
+
'restart' {
|
|
455
|
+
Stop-SwarmMonitor
|
|
456
|
+
Start-Sleep -Seconds 1
|
|
457
|
+
Start-SwarmMonitor
|
|
458
|
+
Show-Status
|
|
459
|
+
}
|
|
460
|
+
'status' {
|
|
461
|
+
Show-Status
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
`;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Generate Windows batch file wrapper
|
|
469
|
+
*/
|
|
470
|
+
export function generateWindowsBatchWrapper(): string {
|
|
471
|
+
return `@echo off
|
|
472
|
+
REM Claude Flow V3 - Windows Batch Wrapper
|
|
473
|
+
REM Routes to PowerShell daemon manager
|
|
474
|
+
|
|
475
|
+
PowerShell -ExecutionPolicy Bypass -File "%~dp0daemon-manager.ps1" %*
|
|
476
|
+
`;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Generate cross-platform session manager
|
|
481
|
+
*/
|
|
482
|
+
export function generateCrossPlatformSessionManager(): string {
|
|
483
|
+
return `#!/usr/bin/env node
|
|
484
|
+
/**
|
|
485
|
+
* Claude Flow Cross-Platform Session Manager
|
|
486
|
+
* Works on Windows, macOS, and Linux
|
|
487
|
+
*/
|
|
488
|
+
|
|
489
|
+
const fs = require('fs');
|
|
490
|
+
const path = require('path');
|
|
491
|
+
const os = require('os');
|
|
492
|
+
|
|
493
|
+
// Platform-specific paths
|
|
494
|
+
const platform = os.platform();
|
|
495
|
+
const homeDir = os.homedir();
|
|
496
|
+
|
|
497
|
+
// Get data directory based on platform
|
|
498
|
+
function getDataDir() {
|
|
499
|
+
const localDir = path.join(process.cwd(), '.claude-flow', 'sessions');
|
|
500
|
+
if (fs.existsSync(path.dirname(localDir))) {
|
|
501
|
+
return localDir;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
switch (platform) {
|
|
505
|
+
case 'win32':
|
|
506
|
+
return path.join(process.env.APPDATA || homeDir, 'claude-flow', 'sessions');
|
|
507
|
+
case 'darwin':
|
|
508
|
+
return path.join(homeDir, 'Library', 'Application Support', 'claude-flow', 'sessions');
|
|
509
|
+
default:
|
|
510
|
+
return path.join(homeDir, '.claude-flow', 'sessions');
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const SESSION_DIR = getDataDir();
|
|
515
|
+
const SESSION_FILE = path.join(SESSION_DIR, 'current.json');
|
|
516
|
+
|
|
517
|
+
// Ensure directory exists
|
|
518
|
+
function ensureDir(dir) {
|
|
519
|
+
if (!fs.existsSync(dir)) {
|
|
520
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
const commands = {
|
|
525
|
+
start: () => {
|
|
526
|
+
ensureDir(SESSION_DIR);
|
|
527
|
+
const sessionId = \`session-\${Date.now()}\`;
|
|
528
|
+
const session = {
|
|
529
|
+
id: sessionId,
|
|
530
|
+
startedAt: new Date().toISOString(),
|
|
531
|
+
platform: platform,
|
|
532
|
+
cwd: process.cwd(),
|
|
533
|
+
context: {},
|
|
534
|
+
metrics: { edits: 0, commands: 0, tasks: 0, errors: 0 }
|
|
535
|
+
};
|
|
536
|
+
fs.writeFileSync(SESSION_FILE, JSON.stringify(session, null, 2));
|
|
537
|
+
console.log(\`Session started: \${sessionId}\`);
|
|
538
|
+
return session;
|
|
539
|
+
},
|
|
540
|
+
|
|
541
|
+
restore: () => {
|
|
542
|
+
if (!fs.existsSync(SESSION_FILE)) {
|
|
543
|
+
console.log('No session to restore');
|
|
544
|
+
return null;
|
|
545
|
+
}
|
|
546
|
+
const session = JSON.parse(fs.readFileSync(SESSION_FILE, 'utf-8'));
|
|
547
|
+
session.restoredAt = new Date().toISOString();
|
|
548
|
+
fs.writeFileSync(SESSION_FILE, JSON.stringify(session, null, 2));
|
|
549
|
+
console.log(\`Session restored: \${session.id}\`);
|
|
550
|
+
return session;
|
|
551
|
+
},
|
|
552
|
+
|
|
553
|
+
end: () => {
|
|
554
|
+
if (!fs.existsSync(SESSION_FILE)) {
|
|
555
|
+
console.log('No active session');
|
|
556
|
+
return null;
|
|
557
|
+
}
|
|
558
|
+
const session = JSON.parse(fs.readFileSync(SESSION_FILE, 'utf-8'));
|
|
559
|
+
session.endedAt = new Date().toISOString();
|
|
560
|
+
session.duration = Date.now() - new Date(session.startedAt).getTime();
|
|
561
|
+
|
|
562
|
+
const archivePath = path.join(SESSION_DIR, \`\${session.id}.json\`);
|
|
563
|
+
fs.writeFileSync(archivePath, JSON.stringify(session, null, 2));
|
|
564
|
+
fs.unlinkSync(SESSION_FILE);
|
|
565
|
+
|
|
566
|
+
console.log(\`Session ended: \${session.id}\`);
|
|
567
|
+
console.log(\`Duration: \${Math.round(session.duration / 1000 / 60)} minutes\`);
|
|
568
|
+
return session;
|
|
569
|
+
},
|
|
570
|
+
|
|
571
|
+
status: () => {
|
|
572
|
+
if (!fs.existsSync(SESSION_FILE)) {
|
|
573
|
+
console.log('No active session');
|
|
574
|
+
return null;
|
|
575
|
+
}
|
|
576
|
+
const session = JSON.parse(fs.readFileSync(SESSION_FILE, 'utf-8'));
|
|
577
|
+
const duration = Date.now() - new Date(session.startedAt).getTime();
|
|
578
|
+
console.log(\`Session: \${session.id}\`);
|
|
579
|
+
console.log(\`Platform: \${session.platform}\`);
|
|
580
|
+
console.log(\`Started: \${session.startedAt}\`);
|
|
581
|
+
console.log(\`Duration: \${Math.round(duration / 1000 / 60)} minutes\`);
|
|
582
|
+
return session;
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
// CLI
|
|
587
|
+
const [,, command, ...args] = process.argv;
|
|
588
|
+
if (command && commands[command]) {
|
|
589
|
+
commands[command](...args);
|
|
590
|
+
} else {
|
|
591
|
+
console.log('Usage: session.js <start|restore|end|status>');
|
|
592
|
+
console.log(\`Platform: \${platform}\`);
|
|
593
|
+
console.log(\`Data dir: \${SESSION_DIR}\`);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
module.exports = commands;
|
|
597
|
+
`;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Generate all helper files
|
|
602
|
+
*/
|
|
603
|
+
export function generateHelpers(options: InitOptions): Record<string, string> {
|
|
604
|
+
const helpers: Record<string, string> = {};
|
|
605
|
+
|
|
606
|
+
if (options.components.helpers) {
|
|
607
|
+
// Unix/macOS shell scripts
|
|
608
|
+
helpers['pre-commit'] = generatePreCommitHook();
|
|
609
|
+
helpers['post-commit'] = generatePostCommitHook();
|
|
610
|
+
|
|
611
|
+
// Cross-platform Node.js scripts
|
|
612
|
+
helpers['session.js'] = generateCrossPlatformSessionManager();
|
|
613
|
+
helpers['router.js'] = generateAgentRouter();
|
|
614
|
+
helpers['memory.js'] = generateMemoryHelper();
|
|
615
|
+
|
|
616
|
+
// Windows-specific scripts
|
|
617
|
+
helpers['daemon-manager.ps1'] = generateWindowsDaemonManager();
|
|
618
|
+
helpers['daemon-manager.cmd'] = generateWindowsBatchWrapper();
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
if (options.components.statusline) {
|
|
622
|
+
const { generateStatuslineScript, generateStatuslineHook } = require('./statusline-generator.js');
|
|
623
|
+
helpers['statusline.js'] = generateStatuslineScript(options);
|
|
624
|
+
helpers['statusline-hook.sh'] = generateStatuslineHook(options);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
return helpers;
|
|
628
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Init Module
|
|
3
|
+
* Comprehensive initialization system for Claude Code integration
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Types
|
|
7
|
+
export {
|
|
8
|
+
type InitOptions,
|
|
9
|
+
type InitComponents,
|
|
10
|
+
type InitResult,
|
|
11
|
+
type HooksConfig,
|
|
12
|
+
type SkillsConfig,
|
|
13
|
+
type CommandsConfig,
|
|
14
|
+
type AgentsConfig,
|
|
15
|
+
type StatuslineConfig,
|
|
16
|
+
type MCPConfig,
|
|
17
|
+
type RuntimeConfig,
|
|
18
|
+
type PlatformInfo,
|
|
19
|
+
DEFAULT_INIT_OPTIONS,
|
|
20
|
+
MINIMAL_INIT_OPTIONS,
|
|
21
|
+
FULL_INIT_OPTIONS,
|
|
22
|
+
detectPlatform,
|
|
23
|
+
} from './types.js';
|
|
24
|
+
|
|
25
|
+
// Generators
|
|
26
|
+
export {
|
|
27
|
+
generateSettings,
|
|
28
|
+
generateSettingsJson,
|
|
29
|
+
} from './settings-generator.js';
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
generateMCPConfig,
|
|
33
|
+
generateMCPJson,
|
|
34
|
+
generateMCPCommands,
|
|
35
|
+
} from './mcp-generator.js';
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
generateStatuslineScript,
|
|
39
|
+
generateStatuslineHook,
|
|
40
|
+
} from './statusline-generator.js';
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
generatePreCommitHook,
|
|
44
|
+
generatePostCommitHook,
|
|
45
|
+
generateSessionManager,
|
|
46
|
+
generateAgentRouter,
|
|
47
|
+
generateMemoryHelper,
|
|
48
|
+
generateHelpers,
|
|
49
|
+
generateWindowsDaemonManager,
|
|
50
|
+
generateWindowsBatchWrapper,
|
|
51
|
+
generateCrossPlatformSessionManager,
|
|
52
|
+
} from './helpers-generator.js';
|
|
53
|
+
|
|
54
|
+
export {
|
|
55
|
+
generateClaudeMd,
|
|
56
|
+
generateMinimalClaudeMd,
|
|
57
|
+
} from './claudemd-generator.js';
|
|
58
|
+
|
|
59
|
+
// Main executor
|
|
60
|
+
export { executeInit, default } from './executor.js';
|