moflo 4.6.12 → 4.7.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.
Files changed (30) hide show
  1. package/.claude/settings.json +4 -4
  2. package/.claude/workflow-state.json +1 -5
  3. package/README.md +1 -1
  4. package/bin/hooks.mjs +7 -3
  5. package/bin/setup-project.mjs +1 -1
  6. package/package.json +1 -1
  7. package/src/@claude-flow/cli/README.md +452 -7536
  8. package/src/@claude-flow/cli/dist/src/commands/doctor.js +1 -1
  9. package/src/@claude-flow/cli/dist/src/commands/embeddings.js +4 -4
  10. package/src/@claude-flow/cli/dist/src/commands/init.js +35 -8
  11. package/src/@claude-flow/cli/dist/src/commands/swarm.js +2 -2
  12. package/src/@claude-flow/cli/dist/src/init/claudemd-generator.js +316 -294
  13. package/src/@claude-flow/cli/dist/src/init/executor.js +461 -465
  14. package/src/@claude-flow/cli/dist/src/init/helpers-generator.d.ts +0 -36
  15. package/src/@claude-flow/cli/dist/src/init/helpers-generator.js +146 -1124
  16. package/src/@claude-flow/cli/dist/src/init/index.d.ts +1 -1
  17. package/src/@claude-flow/cli/dist/src/init/index.js +1 -1
  18. package/src/@claude-flow/cli/dist/src/init/moflo-init.js +78 -5
  19. package/src/@claude-flow/cli/dist/src/init/settings-generator.js +50 -120
  20. package/src/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +275 -32
  21. package/src/@claude-flow/cli/dist/src/plugins/store/discovery.js +4 -204
  22. package/src/@claude-flow/cli/dist/src/plugins/tests/standalone-test.js +4 -4
  23. package/src/@claude-flow/cli/dist/src/runtime/headless.d.ts +3 -3
  24. package/src/@claude-flow/cli/dist/src/runtime/headless.js +31 -31
  25. package/src/@claude-flow/cli/dist/src/services/agentic-flow-bridge.d.ts +3 -3
  26. package/src/@claude-flow/cli/dist/src/services/agentic-flow-bridge.js +3 -1
  27. package/src/@claude-flow/cli/dist/src/services/headless-worker-executor.js +14 -0
  28. package/src/@claude-flow/cli/dist/src/services/workflow-gate.js +21 -1
  29. package/src/@claude-flow/cli/dist/src/transfer/store/tests/standalone-test.js +4 -4
  30. package/src/@claude-flow/cli/package.json +1 -1
@@ -8,354 +8,376 @@
8
8
  */
9
9
  // --- Section Generators (each returns enforceable markdown) ---
10
10
  function behavioralRules() {
11
- return `## Behavioral Rules (Always Enforced)
12
-
13
- - Do what has been asked; nothing more, nothing less
14
- - NEVER create files unless they're absolutely necessary for achieving your goal
15
- - ALWAYS prefer editing an existing file to creating a new one
16
- - NEVER proactively create documentation files (*.md) or README files unless explicitly requested
17
- - NEVER save working files, text/mds, or tests to the root folder
18
- - Never continuously check status after spawning a swarm — wait for results
19
- - ALWAYS read a file before editing it
11
+ return `## Behavioral Rules (Always Enforced)
12
+
13
+ - Do what has been asked; nothing more, nothing less
14
+ - NEVER create files unless they're absolutely necessary for achieving your goal
15
+ - ALWAYS prefer editing an existing file to creating a new one
16
+ - NEVER proactively create documentation files (*.md) or README files unless explicitly requested
17
+ - NEVER save working files, text/mds, or tests to the root folder
18
+ - Never continuously check status after spawning a swarm — wait for results
19
+ - ALWAYS read a file before editing it
20
20
  - NEVER commit secrets, credentials, or .env files`;
21
21
  }
22
22
  function fileOrganization() {
23
- return `## File Organization
24
-
25
- - NEVER save to root folder — use the directories below
26
- - Use \`/src\` for source code files
27
- - Use \`/tests\` for test files
28
- - Use \`/docs\` for documentation and markdown files
29
- - Use \`/config\` for configuration files
30
- - Use \`/scripts\` for utility scripts
23
+ return `## File Organization
24
+
25
+ - NEVER save to root folder — use the directories below
26
+ - Use \`/src\` for source code files
27
+ - Use \`/tests\` for test files
28
+ - Use \`/docs\` for documentation and markdown files
29
+ - Use \`/config\` for configuration files
30
+ - Use \`/scripts\` for utility scripts
31
31
  - Use \`/examples\` for example code`;
32
32
  }
33
33
  function projectArchitecture(options) {
34
- return `## Project Architecture
35
-
36
- - Follow Domain-Driven Design with bounded contexts
37
- - Keep files under 500 lines
38
- - Use typed interfaces for all public APIs
39
- - Prefer TDD London School (mock-first) for new code
40
- - Use event sourcing for state changes
41
- - Ensure input validation at system boundaries
42
-
43
- ### Project Config
44
-
45
- - **Topology**: ${options.runtime.topology}
46
- - **Max Agents**: ${options.runtime.maxAgents}
47
- - **Memory**: ${options.runtime.memoryBackend}
48
- - **HNSW**: ${options.runtime.enableHNSW ? 'Enabled' : 'Disabled'}
34
+ return `## Project Architecture
35
+
36
+ - Follow Domain-Driven Design with bounded contexts
37
+ - Keep files under 500 lines
38
+ - Use typed interfaces for all public APIs
39
+ - Prefer TDD London School (mock-first) for new code
40
+ - Use event sourcing for state changes
41
+ - Ensure input validation at system boundaries
42
+
43
+ ### Project Config
44
+
45
+ - **Topology**: ${options.runtime.topology}
46
+ - **Max Agents**: ${options.runtime.maxAgents}
47
+ - **Memory**: ${options.runtime.memoryBackend}
48
+ - **HNSW**: ${options.runtime.enableHNSW ? 'Enabled' : 'Disabled'}
49
49
  - **Neural**: ${options.runtime.enableNeural ? 'Enabled' : 'Disabled'}`;
50
50
  }
51
51
  function concurrencyRules() {
52
- return `## Concurrency: 1 MESSAGE = ALL RELATED OPERATIONS
53
-
54
- - All operations MUST be concurrent/parallel in a single message
55
- - Use Claude Code's Task tool for spawning agents, not just MCP
56
- - ALWAYS batch ALL todos in ONE TodoWrite call (5-10+ minimum)
57
- - ALWAYS spawn ALL agents in ONE message with full instructions via Task tool
58
- - ALWAYS batch ALL file reads/writes/edits in ONE message
52
+ return `## Concurrency: 1 MESSAGE = ALL RELATED OPERATIONS
53
+
54
+ - All operations MUST be concurrent/parallel in a single message
55
+ - Use Claude Code's Task tool for spawning agents, not just MCP
56
+ - ALWAYS batch ALL todos in ONE TodoWrite call (5-10+ minimum)
57
+ - ALWAYS spawn ALL agents in ONE message with full instructions via Task tool
58
+ - ALWAYS batch ALL file reads/writes/edits in ONE message
59
59
  - ALWAYS batch ALL Bash commands in ONE message`;
60
60
  }
61
61
  function swarmOrchestration() {
62
- return `## Swarm Orchestration
63
-
64
- - MUST initialize the swarm using CLI tools when starting complex tasks
65
- - MUST spawn concurrent agents using Claude Code's Task tool
66
- - Never use CLI tools alone for execution — Task tool agents do the actual work
67
- - MUST call CLI tools AND Task tool in ONE message for complex work
68
-
69
- ### 3-Tier Model Routing (ADR-026)
70
-
71
- | Tier | Handler | Latency | Cost | Use Cases |
72
- |------|---------|---------|------|-----------|
73
- | **1** | Agent Booster (WASM) | <1ms | $0 | Simple transforms (var→const, add types) — Skip LLM |
74
- | **2** | Haiku | ~500ms | $0.0002 | Simple tasks, low complexity (<30%) |
75
- | **3** | Sonnet/Opus | 2-5s | $0.003-0.015 | Complex reasoning, architecture, security (>30%) |
76
-
77
- - Always check for \`[AGENT_BOOSTER_AVAILABLE]\` or \`[TASK_MODEL_RECOMMENDATION]\` before spawning agents
62
+ return `## Swarm Orchestration
63
+
64
+ - MUST initialize the swarm using CLI tools when starting complex tasks
65
+ - MUST spawn concurrent agents using Claude Code's Task tool
66
+ - Never use CLI tools alone for execution — Task tool agents do the actual work
67
+ - MUST call CLI tools AND Task tool in ONE message for complex work
68
+
69
+ ### 3-Tier Model Routing (ADR-026)
70
+
71
+ | Tier | Handler | Latency | Cost | Use Cases |
72
+ |------|---------|---------|------|-----------|
73
+ | **1** | Agent Booster (WASM) | <1ms | $0 | Simple transforms (var→const, add types) — Skip LLM |
74
+ | **2** | Haiku | ~500ms | $0.0002 | Simple tasks, low complexity (<30%) |
75
+ | **3** | Sonnet/Opus | 2-5s | $0.003-0.015 | Complex reasoning, architecture, security (>30%) |
76
+
77
+ - Always check for \`[AGENT_BOOSTER_AVAILABLE]\` or \`[TASK_MODEL_RECOMMENDATION]\` before spawning agents
78
78
  - Use Edit tool directly when \`[AGENT_BOOSTER_AVAILABLE]\``;
79
79
  }
80
80
  function antiDriftConfig() {
81
- return `## Swarm Configuration & Anti-Drift
82
-
83
- - ALWAYS use hierarchical topology for coding swarms
84
- - Keep maxAgents at 6-8 for tight coordination
85
- - Use specialized strategy for clear role boundaries
86
- - Use \`raft\` consensus for hive-mind (leader maintains authoritative state)
87
- - Run frequent checkpoints via \`post-task\` hooks
88
- - Keep shared memory namespace for all agents
89
-
90
- \`\`\`bash
91
- npx @claude-flow/cli@latest swarm init --topology hierarchical --max-agents 8 --strategy specialized
81
+ return `## Swarm Configuration & Anti-Drift
82
+
83
+ - ALWAYS use hierarchical topology for coding swarms
84
+ - Keep maxAgents at 6-8 for tight coordination
85
+ - Use specialized strategy for clear role boundaries
86
+ - Use \`raft\` consensus for hive-mind (leader maintains authoritative state)
87
+ - Run frequent checkpoints via \`post-task\` hooks
88
+ - Keep shared memory namespace for all agents
89
+
90
+ \`\`\`bash
91
+ npx moflo swarm init --topology hierarchical --max-agents 8 --strategy specialized
92
92
  \`\`\``;
93
93
  }
94
94
  function autoStartProtocol() {
95
- return `## Swarm Protocols & Routing
96
-
97
- ### Auto-Start Swarm Protocol
98
-
99
- When the user requests a complex task, spawn agents in background and WAIT:
100
-
101
- \`\`\`javascript
102
- // STEP 1: Initialize swarm coordination
103
- Bash("npx @claude-flow/cli@latest swarm init --topology hierarchical --max-agents 8 --strategy specialized")
104
-
105
- // STEP 2: Spawn ALL agents IN BACKGROUND in a SINGLE message
106
- Task({prompt: "Research requirements...", subagent_type: "researcher", run_in_background: true})
107
- Task({prompt: "Design architecture...", subagent_type: "system-architect", run_in_background: true})
108
- Task({prompt: "Implement solution...", subagent_type: "coder", run_in_background: true})
109
- Task({prompt: "Write tests...", subagent_type: "tester", run_in_background: true})
110
- Task({prompt: "Review code quality...", subagent_type: "reviewer", run_in_background: true})
111
- \`\`\`
112
-
113
- ### Agent Routing
114
-
115
- | Code | Task | Agents |
116
- |------|------|--------|
117
- | 1 | Bug Fix | coordinator, researcher, coder, tester |
118
- | 3 | Feature | coordinator, architect, coder, tester, reviewer |
119
- | 5 | Refactor | coordinator, architect, coder, reviewer |
120
- | 7 | Performance | coordinator, perf-engineer, coder |
121
- | 9 | Security | coordinator, security-architect, auditor |
122
-
123
- ### Task Complexity Detection
124
-
125
- - AUTO-INVOKE SWARM when task involves: 3+ files, new features, cross-module refactoring, API changes, security, or performance work
95
+ return `## Swarm Protocols & Routing
96
+
97
+ ### Auto-Start Swarm Protocol
98
+
99
+ When the user requests a complex task, spawn agents in background and WAIT:
100
+
101
+ \`\`\`javascript
102
+ // STEP 1: Initialize swarm coordination
103
+ Bash("npx moflo swarm init --topology hierarchical --max-agents 8 --strategy specialized")
104
+
105
+ // STEP 2: Spawn ALL agents IN BACKGROUND in a SINGLE message
106
+ Task({prompt: "Research requirements...", subagent_type: "researcher", run_in_background: true})
107
+ Task({prompt: "Design architecture...", subagent_type: "system-architect", run_in_background: true})
108
+ Task({prompt: "Implement solution...", subagent_type: "coder", run_in_background: true})
109
+ Task({prompt: "Write tests...", subagent_type: "tester", run_in_background: true})
110
+ Task({prompt: "Review code quality...", subagent_type: "reviewer", run_in_background: true})
111
+ \`\`\`
112
+
113
+ ### Agent Routing
114
+
115
+ | Code | Task | Agents |
116
+ |------|------|--------|
117
+ | 1 | Bug Fix | coordinator, researcher, coder, tester |
118
+ | 3 | Feature | coordinator, architect, coder, tester, reviewer |
119
+ | 5 | Refactor | coordinator, architect, coder, reviewer |
120
+ | 7 | Performance | coordinator, perf-engineer, coder |
121
+ | 9 | Security | coordinator, security-architect, auditor |
122
+
123
+ ### Task Complexity Detection
124
+
125
+ - AUTO-INVOKE SWARM when task involves: 3+ files, new features, cross-module refactoring, API changes, security, or performance work
126
126
  - SKIP SWARM for: single file edits, simple bug fixes (1-2 lines), documentation updates, configuration changes`;
127
127
  }
128
128
  function executionRules() {
129
- return `## Swarm Execution Rules
130
-
131
- - ALWAYS use \`run_in_background: true\` for all agent Task calls
132
- - ALWAYS put ALL agent Task calls in ONE message for parallel execution
133
- - After spawning, STOP — do NOT add more tool calls or check status
134
- - Never poll TaskOutput or check swarm status — trust agents to return
129
+ return `## Swarm Execution Rules
130
+
131
+ - ALWAYS use \`run_in_background: true\` for all agent Task calls
132
+ - ALWAYS put ALL agent Task calls in ONE message for parallel execution
133
+ - After spawning, STOP — do NOT add more tool calls or check status
134
+ - Never poll TaskOutput or check swarm status — trust agents to return
135
135
  - When agent results arrive, review ALL results before proceeding`;
136
136
  }
137
137
  function cliCommandsTable() {
138
- return `## V3 CLI Commands
139
-
140
- ### Core Commands
141
-
142
- | Command | Subcommands | Description |
143
- |---------|-------------|-------------|
144
- | \`init\` | 4 | Project initialization |
145
- | \`agent\` | 8 | Agent lifecycle management |
146
- | \`swarm\` | 6 | Multi-agent swarm coordination |
147
- | \`memory\` | 11 | AgentDB memory with HNSW search |
148
- | \`task\` | 6 | Task creation and lifecycle |
149
- | \`session\` | 7 | Session state management |
150
- | \`hooks\` | 17 | Self-learning hooks + 12 workers |
151
- | \`hive-mind\` | 6 | Byzantine fault-tolerant consensus |
152
-
153
- ### Quick CLI Examples
154
-
155
- \`\`\`bash
156
- npx @claude-flow/cli@latest init --wizard
157
- npx @claude-flow/cli@latest agent spawn -t coder --name my-coder
158
- npx @claude-flow/cli@latest swarm init --v3-mode
159
- npx @claude-flow/cli@latest memory search --query "authentication patterns"
160
- npx @claude-flow/cli@latest doctor --fix
138
+ return `## V3 CLI Commands
139
+
140
+ ### Core Commands
141
+
142
+ | Command | Subcommands | Description |
143
+ |---------|-------------|-------------|
144
+ | \`init\` | 4 | Project initialization |
145
+ | \`agent\` | 8 | Agent lifecycle management |
146
+ | \`swarm\` | 6 | Multi-agent swarm coordination |
147
+ | \`memory\` | 11 | AgentDB memory with HNSW search |
148
+ | \`task\` | 6 | Task creation and lifecycle |
149
+ | \`session\` | 7 | Session state management |
150
+ | \`hooks\` | 17 | Self-learning hooks + 12 workers |
151
+ | \`hive-mind\` | 6 | Byzantine fault-tolerant consensus |
152
+
153
+ ### Quick CLI Examples
154
+
155
+ \`\`\`bash
156
+ npx moflo init --wizard
157
+ npx moflo agent spawn -t coder --name my-coder
158
+ npx moflo swarm init --v3-mode
159
+ npx moflo memory search --query "authentication patterns"
160
+ npx moflo doctor --fix
161
161
  \`\`\``;
162
162
  }
163
163
  function agentTypes() {
164
- return `## Available Agents (60+ Types)
165
-
166
- ### Core Development
167
- \`coder\`, \`reviewer\`, \`tester\`, \`planner\`, \`researcher\`
168
-
169
- ### Specialized
170
- \`security-architect\`, \`security-auditor\`, \`memory-specialist\`, \`performance-engineer\`
171
-
172
- ### Swarm Coordination
173
- \`hierarchical-coordinator\`, \`mesh-coordinator\`, \`adaptive-coordinator\`
174
-
175
- ### GitHub & Repository
176
- \`pr-manager\`, \`code-review-swarm\`, \`issue-tracker\`, \`release-manager\`
177
-
178
- ### SPARC Methodology
164
+ return `## Available Agents (60+ Types)
165
+
166
+ ### Core Development
167
+ \`coder\`, \`reviewer\`, \`tester\`, \`planner\`, \`researcher\`
168
+
169
+ ### Specialized
170
+ \`security-architect\`, \`security-auditor\`, \`memory-specialist\`, \`performance-engineer\`
171
+
172
+ ### Swarm Coordination
173
+ \`hierarchical-coordinator\`, \`mesh-coordinator\`, \`adaptive-coordinator\`
174
+
175
+ ### GitHub & Repository
176
+ \`pr-manager\`, \`code-review-swarm\`, \`issue-tracker\`, \`release-manager\`
177
+
178
+ ### SPARC Methodology
179
179
  \`sparc-coord\`, \`sparc-coder\`, \`specification\`, \`pseudocode\`, \`architecture\``;
180
180
  }
181
181
  function hooksSystem() {
182
- return `## Hooks System (27 Hooks + 12 Workers)
183
-
184
- ### Essential Hooks
185
-
186
- | Hook | Description |
187
- |------|-------------|
188
- | \`pre-task\` / \`post-task\` | Task lifecycle with learning |
189
- | \`pre-edit\` / \`post-edit\` | File editing with neural training |
190
- | \`session-start\` / \`session-end\` | Session state persistence |
191
- | \`route\` | Route task to optimal agent |
192
- | \`intelligence\` | RuVector intelligence system |
193
- | \`worker\` | Background worker management |
194
-
195
- ### 12 Background Workers
196
-
197
- | Worker | Priority | Description |
198
- |--------|----------|-------------|
199
- | \`optimize\` | high | Performance optimization |
200
- | \`audit\` | critical | Security analysis |
201
- | \`testgaps\` | normal | Test coverage analysis |
202
- | \`map\` | normal | Codebase mapping |
203
- | \`deepdive\` | normal | Deep code analysis |
204
- | \`document\` | normal | Auto-documentation |
205
-
206
- \`\`\`bash
207
- npx @claude-flow/cli@latest hooks pre-task --description "[task]"
208
- npx @claude-flow/cli@latest hooks post-task --task-id "[id]" --success true
209
- npx @claude-flow/cli@latest hooks worker dispatch --trigger audit
182
+ return `## Hooks System (27 Hooks + 12 Workers)
183
+
184
+ ### Essential Hooks
185
+
186
+ | Hook | Description |
187
+ |------|-------------|
188
+ | \`pre-task\` / \`post-task\` | Task lifecycle with learning |
189
+ | \`pre-edit\` / \`post-edit\` | File editing with neural training |
190
+ | \`session-start\` / \`session-end\` | Session state persistence |
191
+ | \`route\` | Route task to optimal agent |
192
+ | \`intelligence\` | RuVector intelligence system |
193
+ | \`worker\` | Background worker management |
194
+
195
+ ### 12 Background Workers
196
+
197
+ | Worker | Priority | Description |
198
+ |--------|----------|-------------|
199
+ | \`optimize\` | high | Performance optimization |
200
+ | \`audit\` | critical | Security analysis |
201
+ | \`testgaps\` | normal | Test coverage analysis |
202
+ | \`map\` | normal | Codebase mapping |
203
+ | \`deepdive\` | normal | Deep code analysis |
204
+ | \`document\` | normal | Auto-documentation |
205
+
206
+ \`\`\`bash
207
+ npx moflo hooks pre-task --description "[task]"
208
+ npx moflo hooks post-task --task-id "[id]" --success true
209
+ npx moflo hooks worker dispatch --trigger audit
210
210
  \`\`\``;
211
211
  }
212
212
  function learningProtocol() {
213
- return `## Auto-Learning Protocol
214
-
215
- ### Before Starting Any Task
216
- \`\`\`bash
217
- npx @claude-flow/cli@latest memory search --query "[task keywords]" --namespace patterns
218
- npx @claude-flow/cli@latest hooks route --task "[task description]"
219
- \`\`\`
220
-
221
- ### After Completing Any Task Successfully
222
- \`\`\`bash
223
- npx @claude-flow/cli@latest memory store --namespace patterns --key "[pattern-name]" --value "[what worked]"
224
- npx @claude-flow/cli@latest hooks post-task --task-id "[id]" --success true --store-results true
225
- \`\`\`
226
-
227
- - ALWAYS check memory before starting new features, debugging, or refactoring
228
- - ALWAYS store patterns in memory after solving bugs, completing features, or finding optimizations`;
213
+ return `## Auto-Learning Protocol
214
+
215
+ ### Before Starting Any Task
216
+ \`\`\`bash
217
+ npx moflo memory search --query "[task keywords]" --namespace patterns
218
+ npx moflo memory search --query "[task keywords]" --namespace knowledge
219
+ npx moflo hooks route --task "[task description]"
220
+ \`\`\`
221
+
222
+ ### After Completing Any Task Successfully
223
+ \`\`\`bash
224
+ npx moflo memory store --namespace patterns --key "[pattern-name]" --value "[what worked]"
225
+ npx moflo hooks post-task --task-id "[id]" --success true
226
+ \`\`\`
227
+
228
+ ### When the User Asks You to Remember Something
229
+ \`\`\`bash
230
+ npx moflo memory store --namespace knowledge --key "[topic]" --value "[what to remember]"
231
+ \`\`\`
232
+
233
+ The \`knowledge\` namespace is for user-directed project knowledge — things like "always use soft delete",
234
+ "don't use MUI DataGrid, use TableComponent", or "the billing service uses Stripe". These are searchable
235
+ during the memory-first gate and persist across sessions.
236
+
237
+ - ALWAYS check memory before starting new features, debugging, or refactoring
238
+ - ALWAYS store user-directed knowledge in the \`knowledge\` namespace when asked to remember something
239
+ - ALWAYS store code patterns in the \`patterns\` namespace after solving bugs or finding optimizations`;
229
240
  }
230
241
  function memoryCommands() {
231
- return `## Memory Commands Reference
232
-
233
- \`\`\`bash
234
- # Store (REQUIRED: --key, --value; OPTIONAL: --namespace, --ttl, --tags)
235
- npx @claude-flow/cli@latest memory store --key "pattern-auth" --value "JWT with refresh" --namespace patterns
236
-
237
- # Search (REQUIRED: --query; OPTIONAL: --namespace, --limit, --threshold)
238
- npx @claude-flow/cli@latest memory search --query "authentication patterns"
239
-
240
- # List (OPTIONAL: --namespace, --limit)
241
- npx @claude-flow/cli@latest memory list --namespace patterns --limit 10
242
-
243
- # Retrieve (REQUIRED: --key; OPTIONAL: --namespace)
244
- npx @claude-flow/cli@latest memory retrieve --key "pattern-auth" --namespace patterns
245
- \`\`\``;
242
+ return `## Memory Commands Reference
243
+
244
+ \`\`\`bash
245
+ # Store a code pattern
246
+ npx moflo memory store --key "pattern-auth" --value "JWT with refresh" --namespace patterns
247
+
248
+ # Store user-directed knowledge (remember for next time)
249
+ npx moflo memory store --key "soft-delete" --value "Always use soft delete on entities" --namespace knowledge
250
+
251
+ # Search (searches across all namespaces if --namespace omitted)
252
+ npx moflo memory search --query "authentication patterns"
253
+
254
+ # List entries in a namespace
255
+ npx moflo memory list --namespace knowledge --limit 10
256
+
257
+ # Retrieve a specific key
258
+ npx moflo memory retrieve --key "pattern-auth" --namespace patterns
259
+ \`\`\`
260
+
261
+ ### Namespaces
262
+ | Namespace | Purpose | Populated by |
263
+ |-----------|---------|-------------|
264
+ | \`guidance\` | Doc chunks from .claude/guidance + docs/ | \`flo-index\` (session start) |
265
+ | \`code-map\` | File/dir structure for navigation | \`flo-codemap\` (session start) |
266
+ | \`patterns\` | Code patterns from repo analysis | \`hooks pretrain\` (session start) |
267
+ | \`knowledge\` | User-directed project knowledge | User ("remember X for next time") |`;
246
268
  }
247
269
  function securityRulesLight() {
248
- return `## Security Rules
249
-
250
- - NEVER hardcode API keys, secrets, or credentials in source files
251
- - NEVER commit .env files or any file containing secrets
252
- - Always validate user input at system boundaries
253
- - Always sanitize file paths to prevent directory traversal
254
- - Run \`npx @claude-flow/cli@latest security scan\` after security-related changes`;
270
+ return `## Security Rules
271
+
272
+ - NEVER hardcode API keys, secrets, or credentials in source files
273
+ - NEVER commit .env files or any file containing secrets
274
+ - Always validate user input at system boundaries
275
+ - Always sanitize file paths to prevent directory traversal
276
+ - Run \`npx moflo security scan\` after security-related changes`;
255
277
  }
256
278
  function buildAndTest() {
257
- return `## Build & Test
258
-
259
- \`\`\`bash
260
- # Build
261
- npm run build
262
-
263
- # Test
264
- npm test
265
-
266
- # Lint
267
- npm run lint
268
- \`\`\`
269
-
270
- - ALWAYS run tests after making code changes
279
+ return `## Build & Test
280
+
281
+ \`\`\`bash
282
+ # Build
283
+ npm run build
284
+
285
+ # Test
286
+ npm test
287
+
288
+ # Lint
289
+ npm run lint
290
+ \`\`\`
291
+
292
+ - ALWAYS run tests after making code changes
271
293
  - ALWAYS verify build succeeds before committing`;
272
294
  }
273
295
  function securitySection() {
274
- return `## Security Protocol
275
-
276
- - NEVER hardcode API keys, secrets, or credentials in source files
277
- - NEVER commit .env files or any file containing secrets
278
- - Always validate all user input at system boundaries using Zod schemas
279
- - Always sanitize file paths to prevent directory traversal attacks
280
- - Always use parameterized queries — never concatenate SQL strings
281
- - Run security audit after any authentication or authorization changes
282
-
283
- ### Security Scanning
284
- \`\`\`bash
285
- npx @claude-flow/cli@latest security scan --depth full
286
- npx @claude-flow/cli@latest security audit --report
287
- npx @claude-flow/cli@latest security cve --check
288
- \`\`\`
289
-
290
- ### Security Agents
291
- - \`security-architect\` — threat modeling, architecture review
292
- - \`security-auditor\` — code audit, vulnerability detection
296
+ return `## Security Protocol
297
+
298
+ - NEVER hardcode API keys, secrets, or credentials in source files
299
+ - NEVER commit .env files or any file containing secrets
300
+ - Always validate all user input at system boundaries using Zod schemas
301
+ - Always sanitize file paths to prevent directory traversal attacks
302
+ - Always use parameterized queries — never concatenate SQL strings
303
+ - Run security audit after any authentication or authorization changes
304
+
305
+ ### Security Scanning
306
+ \`\`\`bash
307
+ npx moflo security scan --depth full
308
+ npx moflo security audit --report
309
+ npx moflo security cve --check
310
+ \`\`\`
311
+
312
+ ### Security Agents
313
+ - \`security-architect\` — threat modeling, architecture review
314
+ - \`security-auditor\` — code audit, vulnerability detection
293
315
  - Use agent routing code 9 (hierarchical/specialized) for security tasks`;
294
316
  }
295
317
  function performanceSection() {
296
- return `## Performance Optimization Protocol
297
-
298
- - Always run benchmarks before and after performance changes
299
- - Always profile before optimizing — never guess at bottlenecks
300
- - Prefer algorithmic improvements over micro-optimizations
301
- - Keep HNSW search within 150x-12,500x faster target
302
- - Keep memory reduction within 50-75% target with quantization
303
-
304
- ### Performance Tooling
305
- \`\`\`bash
306
- npx @claude-flow/cli@latest performance benchmark --suite all
307
- npx @claude-flow/cli@latest performance profile --target "[component]"
308
- npx @claude-flow/cli@latest performance metrics --format table
309
- \`\`\`
310
-
311
- ### Performance Agents
312
- - \`performance-engineer\` — profiling, benchmarking, optimization
313
- - \`perf-analyzer\` — bottleneck detection, analysis
318
+ return `## Performance Optimization Protocol
319
+
320
+ - Always run benchmarks before and after performance changes
321
+ - Always profile before optimizing — never guess at bottlenecks
322
+ - Prefer algorithmic improvements over micro-optimizations
323
+ - Keep HNSW search within 150x-12,500x faster target
324
+ - Keep memory reduction within 50-75% target with quantization
325
+
326
+ ### Performance Tooling
327
+ \`\`\`bash
328
+ npx moflo performance benchmark --suite all
329
+ npx moflo performance profile --target "[component]"
330
+ npx moflo performance metrics --format table
331
+ \`\`\`
332
+
333
+ ### Performance Agents
334
+ - \`performance-engineer\` — profiling, benchmarking, optimization
335
+ - \`perf-analyzer\` — bottleneck detection, analysis
314
336
  - Use agent routing code 7 (hierarchical/specialized) for performance tasks`;
315
337
  }
316
338
  function intelligenceSystem() {
317
- return `## Intelligence System (RuVector)
318
-
319
- - **SONA**: Self-Optimizing Neural Architecture (<0.05ms adaptation)
320
- - **HNSW**: 150x-12,500x faster pattern search
321
- - **EWC++**: Elastic Weight Consolidation (prevents forgetting)
322
- - **Flash Attention**: 2.49x-7.47x speedup
323
-
324
- The 4-step intelligence pipeline:
325
- 1. **RETRIEVE** - Fetch relevant patterns via HNSW
326
- 2. **JUDGE** - Evaluate with verdicts (success/failure)
327
- 3. **DISTILL** - Extract key learnings via LoRA
339
+ return `## Intelligence System (RuVector)
340
+
341
+ - **SONA**: Self-Optimizing Neural Architecture (<0.05ms adaptation)
342
+ - **HNSW**: 150x-12,500x faster pattern search
343
+ - **EWC++**: Elastic Weight Consolidation (prevents forgetting)
344
+ - **Flash Attention**: 2.49x-7.47x speedup
345
+
346
+ The 4-step intelligence pipeline:
347
+ 1. **RETRIEVE** - Fetch relevant patterns via HNSW
348
+ 2. **JUDGE** - Evaluate with verdicts (success/failure)
349
+ 3. **DISTILL** - Extract key learnings via LoRA
328
350
  4. **CONSOLIDATE** - Prevent catastrophic forgetting via EWC++`;
329
351
  }
330
352
  function envVars() {
331
- return `## Environment Variables
332
-
333
- \`\`\`bash
334
- CLAUDE_FLOW_CONFIG=./claude-flow.config.json
335
- CLAUDE_FLOW_LOG_LEVEL=info
336
- ANTHROPIC_API_KEY=sk-ant-...
337
- CLAUDE_FLOW_MEMORY_BACKEND=hybrid
338
- CLAUDE_FLOW_MEMORY_PATH=./data/memory
353
+ return `## Environment Variables
354
+
355
+ \`\`\`bash
356
+ CLAUDE_FLOW_CONFIG=./claude-flow.config.json
357
+ CLAUDE_FLOW_LOG_LEVEL=info
358
+ ANTHROPIC_API_KEY=sk-ant-...
359
+ CLAUDE_FLOW_MEMORY_BACKEND=hybrid
360
+ CLAUDE_FLOW_MEMORY_PATH=./data/memory
339
361
  \`\`\``;
340
362
  }
341
363
  function setupAndBoundary() {
342
- return `## Quick Setup
343
-
344
- \`\`\`bash
345
- claude mcp add claude-flow -- npx -y @claude-flow/cli@latest
346
- npx @claude-flow/cli@latest daemon start
347
- npx @claude-flow/cli@latest doctor --fix
348
- \`\`\`
349
-
350
- ## Claude Code vs CLI Tools
351
-
352
- - Claude Code's Task tool handles ALL execution: agents, file ops, code generation, git
353
- - CLI tools handle coordination via Bash: swarm init, memory, hooks, routing
354
- - NEVER use CLI tools as a substitute for Task tool agents
355
-
356
- ## Support
357
-
358
- - Documentation: https://github.com/eric-cielo/moflo
364
+ return `## Quick Setup
365
+
366
+ \`\`\`bash
367
+ claude mcp add claude-flow -- npx -y @claude-flow/cli@latest
368
+ npx moflo daemon start
369
+ npx moflo doctor --fix
370
+ \`\`\`
371
+
372
+ ## Claude Code vs CLI Tools
373
+
374
+ - Claude Code's Task tool handles ALL execution: agents, file ops, code generation, git
375
+ - CLI tools handle coordination via Bash: swarm init, memory, hooks, routing
376
+ - NEVER use CLI tools as a substitute for Task tool agents
377
+
378
+ ## Support
379
+
380
+ - Documentation: https://github.com/eric-cielo/moflo
359
381
  - Issues: https://github.com/eric-cielo/moflo/issues`;
360
382
  }
361
383
  // --- Template Composers ---