@synergenius/flow-weaver-pack-weaver 0.9.140 → 0.9.144

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 (85) hide show
  1. package/dist/bot/assistant-tools.d.ts.map +1 -1
  2. package/dist/bot/assistant-tools.js +5 -11
  3. package/dist/bot/assistant-tools.js.map +1 -1
  4. package/dist/bot/behavior-defaults.d.ts +2 -2
  5. package/dist/bot/behavior-defaults.d.ts.map +1 -1
  6. package/dist/bot/behavior-defaults.js +11 -6
  7. package/dist/bot/behavior-defaults.js.map +1 -1
  8. package/dist/bot/capability-registry.d.ts +2 -0
  9. package/dist/bot/capability-registry.d.ts.map +1 -1
  10. package/dist/bot/capability-registry.js +282 -15
  11. package/dist/bot/capability-registry.js.map +1 -1
  12. package/dist/bot/dashboard.js +3 -3
  13. package/dist/bot/dashboard.js.map +1 -1
  14. package/dist/bot/hierarchy-event-log.d.ts +37 -0
  15. package/dist/bot/hierarchy-event-log.d.ts.map +1 -0
  16. package/dist/bot/hierarchy-event-log.js +58 -0
  17. package/dist/bot/hierarchy-event-log.js.map +1 -0
  18. package/dist/bot/operations.d.ts +2 -0
  19. package/dist/bot/operations.d.ts.map +1 -1
  20. package/dist/bot/operations.js +5 -0
  21. package/dist/bot/operations.js.map +1 -1
  22. package/dist/bot/profile-store.d.ts.map +1 -1
  23. package/dist/bot/profile-store.js +46 -0
  24. package/dist/bot/profile-store.js.map +1 -1
  25. package/dist/bot/runner.d.ts.map +1 -1
  26. package/dist/bot/runner.js +51 -16
  27. package/dist/bot/runner.js.map +1 -1
  28. package/dist/bot/step-executor.d.ts.map +1 -1
  29. package/dist/bot/step-executor.js +36 -1
  30. package/dist/bot/step-executor.js.map +1 -1
  31. package/dist/bot/swarm-controller.d.ts +1 -0
  32. package/dist/bot/swarm-controller.d.ts.map +1 -1
  33. package/dist/bot/swarm-controller.js +64 -6
  34. package/dist/bot/swarm-controller.js.map +1 -1
  35. package/dist/bot/task-store.d.ts +1 -1
  36. package/dist/bot/task-store.d.ts.map +1 -1
  37. package/dist/bot/task-store.js +21 -36
  38. package/dist/bot/task-store.js.map +1 -1
  39. package/dist/bot/task-types.d.ts +5 -1
  40. package/dist/bot/task-types.d.ts.map +1 -1
  41. package/dist/bot/types.d.ts +4 -0
  42. package/dist/bot/types.d.ts.map +1 -1
  43. package/dist/node-types/bot-report.d.ts +3 -1
  44. package/dist/node-types/bot-report.d.ts.map +1 -1
  45. package/dist/node-types/bot-report.js +62 -11
  46. package/dist/node-types/bot-report.js.map +1 -1
  47. package/dist/node-types/build-context.d.ts.map +1 -1
  48. package/dist/node-types/build-context.js +32 -0
  49. package/dist/node-types/build-context.js.map +1 -1
  50. package/dist/node-types/report.d.ts +2 -0
  51. package/dist/node-types/report.d.ts.map +1 -1
  52. package/dist/node-types/report.js +61 -7
  53. package/dist/node-types/report.js.map +1 -1
  54. package/dist/ui/capability-editor.js +268 -15
  55. package/dist/ui/profile-editor.js +271 -18
  56. package/dist/ui/swarm-dashboard.js +340 -51
  57. package/dist/ui/task-detail-view.js +69 -33
  58. package/dist/ui/trace-to-timeline.d.ts +2 -0
  59. package/dist/ui/trace-to-timeline.d.ts.map +1 -1
  60. package/dist/ui/trace-to-timeline.js.map +1 -1
  61. package/dist/ui/use-stream-timeline.d.ts +2 -0
  62. package/dist/ui/use-stream-timeline.d.ts.map +1 -1
  63. package/dist/ui/use-stream-timeline.js +76 -34
  64. package/dist/ui/use-stream-timeline.js.map +1 -1
  65. package/flowweaver.manifest.json +1 -1
  66. package/package.json +1 -1
  67. package/src/bot/assistant-tools.ts +5 -11
  68. package/src/bot/behavior-defaults.ts +12 -5
  69. package/src/bot/capability-registry.ts +300 -18
  70. package/src/bot/dashboard.ts +3 -3
  71. package/src/bot/hierarchy-event-log.ts +64 -0
  72. package/src/bot/operations.ts +7 -0
  73. package/src/bot/profile-store.ts +46 -0
  74. package/src/bot/runner.ts +51 -16
  75. package/src/bot/step-executor.ts +32 -1
  76. package/src/bot/swarm-controller.ts +67 -6
  77. package/src/bot/task-store.ts +22 -38
  78. package/src/bot/task-types.ts +7 -1
  79. package/src/bot/types.ts +4 -0
  80. package/src/node-types/bot-report.ts +63 -12
  81. package/src/node-types/build-context.ts +32 -0
  82. package/src/node-types/report.ts +60 -8
  83. package/src/ui/task-detail-view.tsx +3 -0
  84. package/src/ui/trace-to-timeline.ts +2 -0
  85. package/src/ui/use-stream-timeline.ts +81 -38
@@ -35,6 +35,8 @@ var OP_VALIDATE = "validate";
35
35
  var OP_TSC_CHECK = "tsc_check";
36
36
  var OP_RUN_TESTS = "run_tests";
37
37
  var OP_TASK_CREATE = "task_create";
38
+ var OP_REMEMBER = "remember";
39
+ var OP_RECALL = "recall";
38
40
  var OP_RESPOND = "respond";
39
41
  var PLAN_OPERATIONS = [
40
42
  OP_WRITE_FILE,
@@ -66,6 +68,84 @@ Do NOT describe what you would do \u2014 actually do it by calling tools.
66
68
  - Use patch_file for modifications, write_file only for new files.
67
69
  - Be concise \u2014 let tool results speak.`
68
70
  };
71
+ var CAP_ROLE_ORCHESTRATOR = {
72
+ name: "role-orchestrator",
73
+ description: "Orchestrator role: decomposes objectives into tasks, assigns profiles, creates project briefs.",
74
+ tools: [OP_TASK_CREATE, OP_LIST_FILES, OP_READ_FILE],
75
+ prompt: `## YOUR ROLE: Orchestrator
76
+ You DECOMPOSE and ASSIGN. You never write code or create files directly.
77
+
78
+ Your job:
79
+ 1. Analyze the objective and understand the project scope
80
+ 2. Create a PROJECT BRIEF (a concise description of what we're building, how pieces connect, conventions to follow)
81
+ 3. Break the objective into focused subtasks using task_create
82
+ 4. ALWAYS set assignedProfile on every subtask:
83
+ - Code writing, file creation \u2192 "developer"
84
+ - Code review, quality checks \u2192 "reviewer"
85
+ - Project setup, dependencies, config \u2192 "ops"
86
+ 5. Set dependencies so tasks execute in the right order
87
+ 6. Include the project brief in every subtask's description
88
+
89
+ You do NOT have write_file, patch_file, or run_shell. You cannot execute \u2014 only plan and delegate.
90
+
91
+ ### Project Brief Format
92
+ Include this at the TOP of every subtask description:
93
+ "PROJECT: [what we're building]. STRUCTURE: [file layout]. CONVENTIONS: [naming, patterns, exports]."
94
+
95
+ ### Subtask Quality
96
+ Each subtask must be:
97
+ - Focused (one file or one concern)
98
+ - Self-contained (has enough context to execute independently)
99
+ - Properly routed (assignedProfile is set)
100
+ - Ordered (dependsOn reflects real dependencies)`
101
+ };
102
+ var CAP_ROLE_DEVELOPER = {
103
+ name: "role-developer",
104
+ description: "Developer role: writes code, creates files, runs commands. Executes directly, never decomposes.",
105
+ prompt: `## YOUR ROLE: Developer
106
+ You WRITE CODE. Execute the task directly using write_file, patch_file, and run_shell.
107
+
108
+ Your job:
109
+ 1. Read the task description (including the project brief)
110
+ 2. Create a plan with CONCRETE file operations (write_file, patch_file, run_shell)
111
+ 3. Execute every step \u2014 produce actual files on disk
112
+ 4. Verify your work compiles and is correct
113
+
114
+ You do NOT have task_create. You cannot create subtasks or delegate.
115
+ If the task seems too large, do your best \u2014 the orchestrator already decomposed it for you.
116
+
117
+ ### Output Requirements
118
+ Your plan MUST include at least one write_file, patch_file, or run_shell step.
119
+ A plan with only "respond" steps is a FAILURE \u2014 you must produce artifacts.`
120
+ };
121
+ var CAP_ROLE_REVIEWER = {
122
+ name: "role-reviewer",
123
+ description: "Reviewer role: reads and evaluates code quality, security, correctness.",
124
+ prompt: `## YOUR ROLE: Reviewer
125
+ You READ and EVALUATE code. Check quality, security, correctness, and consistency.
126
+
127
+ Your job:
128
+ 1. Read the files that were created/modified
129
+ 2. Check against the task description and project conventions
130
+ 3. Report findings with file:line and severity
131
+ 4. Use patch_file to fix minor issues directly
132
+ 5. For major issues, document them clearly in your report
133
+
134
+ You do NOT have task_create or write_file. You can only read and patch.`
135
+ };
136
+ var CAP_ROLE_OPS = {
137
+ name: "role-ops",
138
+ description: "Ops role: sets up project infrastructure, configs, dependencies.",
139
+ prompt: `## YOUR ROLE: Ops
140
+ You SET UP infrastructure \u2014 package.json, tsconfig.json, directory structure, dependencies.
141
+
142
+ Your job:
143
+ 1. Initialize project structure (create config files, directories)
144
+ 2. Install dependencies with run_shell
145
+ 3. Ensure the project builds and tests can run
146
+
147
+ You do NOT have task_create. You execute infrastructure tasks directly.`
148
+ };
69
149
  var CAP_FILE_OPS = {
70
150
  name: "file-ops",
71
151
  description: "File read/write/patch operations and best practices for file manipulation.",
@@ -95,13 +175,31 @@ Use run_shell for running tests (npx vitest), validation (flow-weaver validate),
95
175
  };
96
176
  var CAP_TASK_MGMT = {
97
177
  name: "task-mgmt",
98
- description: "Create and manage swarm subtasks for parallel execution.",
178
+ description: "Create and manage swarm subtasks for parallel execution, with decomposition and review nudges.",
99
179
  tools: [OP_TASK_CREATE],
100
- prompt: `## Task Management
101
- - task_create: Create swarm subtasks for parallel execution. args: { title, description, complexity, subtasks[] }
102
- - task_list, task_get, task_update: Query and update existing tasks
180
+ prompt: `## Task Management & Decomposition
181
+
182
+ - task_create: Create swarm subtasks. args: { title, description, complexity, subtasks[], dependsOn[], assignedProfile? }
183
+
184
+ ### Decomposition
185
+ When you encounter a broad objective (multi-file, multi-concern), decompose into subtasks:
186
+ - If the task is bigger than a single file change, create subtasks instead of doing it all yourself.
187
+ - Minimize dependencies between subtasks to maximize parallel execution.
188
+ - Set complexity per subtask: trivial | simple | moderate | complex.
189
+ - Use dependsOn to express blocking relationships (e.g., setup before code, code before tests).
190
+
191
+ ### Review Task Creation
192
+ After creating or modifying multiple files, create a review task:
193
+ - title: "Review: [what was changed]"
194
+ - description: List the files modified and what to check
195
+ - assignedProfile: "reviewer"
196
+ - complexity: "simple"
197
+ Skip review for trivial single-file tasks.
103
198
 
104
- Use task_create to decompose complex work into smaller, independent subtasks that other bots can execute in parallel.`
199
+ ### Dependency Guidelines
200
+ - BAD: A \u2192 B \u2192 C \u2192 D (serial, slow)
201
+ - GOOD: A \u2192 [B + C + D] (A blocks all, but B/C/D run in parallel)
202
+ Structure as: setup \u2192 independent implementations \u2192 integration/testing.`
105
203
  };
106
204
  var CAP_FW_GRAMMAR = {
107
205
  name: "fw-grammar",
@@ -179,17 +277,41 @@ Note: compile, validate, modify, diff, diagram, and describe operations are avai
179
277
  };
180
278
  var CAP_CODE_REVIEW = {
181
279
  name: "code-review",
182
- description: "Code review guidelines, quality checklist, and security review patterns.",
183
- prompt: `## Code Review
280
+ description: "Comprehensive code review with correctness, security, style, testing, and performance checks.",
281
+ tools: [OP_READ_FILE, OP_PATCH_FILE, OP_RUN_SHELL],
282
+ prompt: `## Code Review Checklist
184
283
 
185
- When reviewing code, check for:
186
- 1. Correctness: Does the code do what the task asked?
187
- 2. Security: No hardcoded secrets, no injection vulnerabilities, no exposed APIs
188
- 3. Style: Consistent with project conventions, proper naming, no dead code
189
- 4. Testing: Are there tests? Do they cover edge cases?
190
- 5. Performance: No unnecessary loops, no blocking calls in async code
284
+ ### 1. Correctness
285
+ - Does the code do what the task asked?
286
+ - Edge cases handled (empty input, null, invalid types)?
287
+ - Error paths covered (try/catch, validation)?
288
+ - Return types match function signature?
191
289
 
192
- Report concerns with specific file:line references and suggested fixes.`
290
+ ### 2. Security
291
+ - NO hardcoded API keys, passwords, or tokens (use env vars)
292
+ - NO shell: true in child_process (command injection risk)
293
+ - NO eval() or Function() with untrusted input
294
+ - User input validated and sanitized before use
295
+ - File paths validated (no ../ traversal)
296
+
297
+ ### 3. Style
298
+ - Naming is clear and consistent with project conventions
299
+ - No dead code (unused variables, unreachable branches)
300
+ - No debug statements left in (console.log, debugger)
301
+ - Imports organized, no duplicates
302
+
303
+ ### 4. Testing
304
+ - Unit tests exist for new/changed functions
305
+ - Tests cover happy path AND edge cases
306
+ - Error cases have tests
307
+ - Code coverage adequate (aim for 80%+ of changed code)
308
+
309
+ ### 5. Performance
310
+ - No O(n\xB2) loops where O(n) is possible
311
+ - No blocking I/O in async code
312
+ - No memory leaks (listeners removed, timers cleared)
313
+
314
+ Report findings as: FILE:LINE | SEVERITY (critical/high/medium/low) | ISSUE \u2192 Fix suggestion`
193
315
  };
194
316
  var CAP_WEB = {
195
317
  name: "web",
@@ -206,8 +328,131 @@ var CAP_CONTEXT = {
206
328
  Use list_files to understand the project structure before making changes.
207
329
  The context bundle (when available) provides a snapshot of the workspace.`
208
330
  };
331
+ var CAP_VERIFICATION = {
332
+ name: "verification",
333
+ description: "Post-write verification: run tsc and tests to catch errors before delivery.",
334
+ tools: [OP_RUN_SHELL],
335
+ prompt: `## Verification
336
+
337
+ After writing or patching code, ALWAYS verify your work:
338
+ 1. Run \`npx tsc --noEmit\` in the project root to catch TypeScript errors
339
+ 2. If package.json has a "test" script, run \`npm test\` to validate functionality
340
+ 3. If verification fails, read the errors, fix the code, and re-verify
341
+
342
+ Include verification as explicit steps in your plan. Verification is NOT optional.
343
+ Do NOT deliver code that hasn't been verified.`
344
+ };
345
+ var CAP_CROSS_FILE_CHECK = {
346
+ name: "cross-file-check",
347
+ description: "Verify imports, exports, module paths, and cross-file dependencies.",
348
+ tools: [OP_READ_FILE, OP_LIST_FILES, OP_RUN_SHELL],
349
+ prompt: `## Cross-File Dependency Checks
350
+
351
+ When modifying code that affects multiple files:
352
+ 1. If you rename an export, grep for all imports of it and update them
353
+ 2. Verify relative import paths resolve correctly (../types vs ./types)
354
+ 3. Check for circular dependencies (A imports B imports A)
355
+ 4. If you change a function signature, update all callers
356
+ 5. Use \`run_shell\` with grep to search: grep -r "functionName" src/
357
+
358
+ Do NOT move or rename exports without verifying all dependents.`
359
+ };
360
+ var CAP_PROJECT_SETUP = {
361
+ name: "project-setup",
362
+ description: "Initialize new projects with correct structure, config, and dependencies.",
363
+ tools: [OP_WRITE_FILE, OP_RUN_SHELL],
364
+ prompt: `## Project Setup
365
+
366
+ When initializing a project:
367
+ 1. Create package.json with name, type: "module", main, scripts (build, test)
368
+ 2. Create tsconfig.json with strict: true, module: "esnext", target: "ES2020"
369
+ 3. Create standard directories: src/, tests/
370
+ 4. Install dependencies with run_shell: npm install <deps>
371
+ 5. Create .gitignore excluding node_modules/, dist/
372
+ 6. Verify setup: run tsc --noEmit to ensure TypeScript compiles`
373
+ };
374
+ var CAP_SECURITY = {
375
+ name: "security",
376
+ description: "Audit code for vulnerabilities, secrets, and security best practices.",
377
+ tools: [OP_READ_FILE, OP_LIST_FILES, OP_RUN_SHELL],
378
+ prompt: `## Security Audit
379
+
380
+ Check for:
381
+ 1. **Secrets**: NO hardcoded API keys, passwords, tokens. Use env vars.
382
+ grep -r "password\\|secret\\|apiKey\\|token" src/ to find leaks.
383
+ 2. **Injection**: NO string concatenation in SQL. NO shell: true in child_process. NO eval().
384
+ 3. **Dependencies**: Run npm audit to check for known CVEs.
385
+ 4. **File paths**: Validate paths to prevent ../ traversal attacks.
386
+ 5. **Data handling**: Validate user input (type, length, format). Sanitize before logging.
387
+
388
+ Report findings with severity: critical | high | medium | low.`
389
+ };
390
+ var CAP_DECOMPOSITION = {
391
+ name: "decomposition",
392
+ description: "Break complex objectives into subtask DAGs with dependencies for parallel execution.",
393
+ tools: [OP_TASK_CREATE],
394
+ prompt: `## Task Decomposition
395
+
396
+ When given a large objective, break it into smaller subtasks:
397
+ 1. Identify all work items (files, features, tests)
398
+ 2. Group by dependency: what must happen first?
399
+ 3. Create subtasks with task_create, each focused on one responsibility
400
+ 4. Set dependencies with dependsOn to model blocking relationships
401
+ 5. Minimize dependencies to maximize parallel execution
402
+ 6. Estimate complexity per subtask: trivial | simple | moderate | complex
403
+
404
+ Example: "Implement auth module"
405
+ - Task A: Extract shared auth types (simple)
406
+ - Task B: Rewrite login endpoint (moderate, depends on A)
407
+ - Task C: Add login tests (moderate, depends on B)
408
+ - Task D: Update auth docs (simple, independent \u2014 runs in parallel with B)
409
+
410
+ Assign profiles: code tasks \u2192 developer, review tasks \u2192 reviewer, infra \u2192 ops.`
411
+ };
412
+ var CAP_ROUTING = {
413
+ name: "routing",
414
+ description: "Route tasks to appropriate bot profiles based on capabilities and complexity.",
415
+ tools: [OP_TASK_CREATE],
416
+ prompt: `## Task Routing
417
+
418
+ When creating subtasks, assign the right profile:
419
+ - Code writing, file creation, bug fixes \u2192 developer profile
420
+ - Code review, quality checks \u2192 reviewer profile
421
+ - Shell commands, project setup, infrastructure \u2192 ops profile
422
+ - Leave assignedProfile empty for auto-triage when unsure
423
+
424
+ Match complexity to profile capabilities:
425
+ - trivial/simple tasks: any profile (prefer cheapest)
426
+ - moderate tasks: specialist profiles
427
+ - complex tasks: profiles with full capability sets`
428
+ };
429
+ var CAP_MEMORY = {
430
+ name: "memory",
431
+ description: "Remember and recall project conventions for continuity across sessions.",
432
+ tools: [OP_REMEMBER, OP_RECALL],
433
+ prompt: `## Project Memory
434
+
435
+ Persist project conventions for future sessions:
436
+ - remember: Save a convention. args: { key: "naming", value: "kebab-case for files" }
437
+ - recall: Load all saved conventions. args: {} \u2014 returns project memory.
438
+
439
+ What to remember:
440
+ - Naming conventions (file names, variable names)
441
+ - Architecture decisions (Result pattern, Zod for validation)
442
+ - Test patterns (where tests go, what framework)
443
+ - Common dependencies and their usage
444
+
445
+ Before planning, recall project memory to follow established patterns.
446
+ When you discover a new convention, remember it for future bots.`
447
+ };
209
448
  var BUILT_IN_CAPABILITIES = [
210
449
  CAP_CORE,
450
+ // Role capabilities
451
+ CAP_ROLE_ORCHESTRATOR,
452
+ CAP_ROLE_DEVELOPER,
453
+ CAP_ROLE_REVIEWER,
454
+ CAP_ROLE_OPS,
455
+ // Tool capabilities
211
456
  CAP_FILE_OPS,
212
457
  CAP_SHELL,
213
458
  CAP_TASK_MGMT,
@@ -217,7 +462,15 @@ var BUILT_IN_CAPABILITIES = [
217
462
  CAP_FW_CLI,
218
463
  CAP_CODE_REVIEW,
219
464
  CAP_WEB,
220
- CAP_CONTEXT
465
+ CAP_CONTEXT,
466
+ // Swarm improvement capabilities
467
+ CAP_VERIFICATION,
468
+ CAP_CROSS_FILE_CHECK,
469
+ CAP_PROJECT_SETUP,
470
+ CAP_SECURITY,
471
+ CAP_DECOMPOSITION,
472
+ CAP_ROUTING,
473
+ CAP_MEMORY
221
474
  ];
222
475
  var capabilityMap = new Map(
223
476
  BUILT_IN_CAPABILITIES.map((c) => [c.name, c])
@@ -217,6 +217,8 @@ var OP_VALIDATE = "validate";
217
217
  var OP_TSC_CHECK = "tsc_check";
218
218
  var OP_RUN_TESTS = "run_tests";
219
219
  var OP_TASK_CREATE = "task_create";
220
+ var OP_REMEMBER = "remember";
221
+ var OP_RECALL = "recall";
220
222
 
221
223
  // src/bot/capability-registry.ts
222
224
  var CAP_CORE = {
@@ -237,6 +239,84 @@ Do NOT describe what you would do \u2014 actually do it by calling tools.
237
239
  - Use patch_file for modifications, write_file only for new files.
238
240
  - Be concise \u2014 let tool results speak.`
239
241
  };
242
+ var CAP_ROLE_ORCHESTRATOR = {
243
+ name: "role-orchestrator",
244
+ description: "Orchestrator role: decomposes objectives into tasks, assigns profiles, creates project briefs.",
245
+ tools: [OP_TASK_CREATE, OP_LIST_FILES, OP_READ_FILE],
246
+ prompt: `## YOUR ROLE: Orchestrator
247
+ You DECOMPOSE and ASSIGN. You never write code or create files directly.
248
+
249
+ Your job:
250
+ 1. Analyze the objective and understand the project scope
251
+ 2. Create a PROJECT BRIEF (a concise description of what we're building, how pieces connect, conventions to follow)
252
+ 3. Break the objective into focused subtasks using task_create
253
+ 4. ALWAYS set assignedProfile on every subtask:
254
+ - Code writing, file creation \u2192 "developer"
255
+ - Code review, quality checks \u2192 "reviewer"
256
+ - Project setup, dependencies, config \u2192 "ops"
257
+ 5. Set dependencies so tasks execute in the right order
258
+ 6. Include the project brief in every subtask's description
259
+
260
+ You do NOT have write_file, patch_file, or run_shell. You cannot execute \u2014 only plan and delegate.
261
+
262
+ ### Project Brief Format
263
+ Include this at the TOP of every subtask description:
264
+ "PROJECT: [what we're building]. STRUCTURE: [file layout]. CONVENTIONS: [naming, patterns, exports]."
265
+
266
+ ### Subtask Quality
267
+ Each subtask must be:
268
+ - Focused (one file or one concern)
269
+ - Self-contained (has enough context to execute independently)
270
+ - Properly routed (assignedProfile is set)
271
+ - Ordered (dependsOn reflects real dependencies)`
272
+ };
273
+ var CAP_ROLE_DEVELOPER = {
274
+ name: "role-developer",
275
+ description: "Developer role: writes code, creates files, runs commands. Executes directly, never decomposes.",
276
+ prompt: `## YOUR ROLE: Developer
277
+ You WRITE CODE. Execute the task directly using write_file, patch_file, and run_shell.
278
+
279
+ Your job:
280
+ 1. Read the task description (including the project brief)
281
+ 2. Create a plan with CONCRETE file operations (write_file, patch_file, run_shell)
282
+ 3. Execute every step \u2014 produce actual files on disk
283
+ 4. Verify your work compiles and is correct
284
+
285
+ You do NOT have task_create. You cannot create subtasks or delegate.
286
+ If the task seems too large, do your best \u2014 the orchestrator already decomposed it for you.
287
+
288
+ ### Output Requirements
289
+ Your plan MUST include at least one write_file, patch_file, or run_shell step.
290
+ A plan with only "respond" steps is a FAILURE \u2014 you must produce artifacts.`
291
+ };
292
+ var CAP_ROLE_REVIEWER = {
293
+ name: "role-reviewer",
294
+ description: "Reviewer role: reads and evaluates code quality, security, correctness.",
295
+ prompt: `## YOUR ROLE: Reviewer
296
+ You READ and EVALUATE code. Check quality, security, correctness, and consistency.
297
+
298
+ Your job:
299
+ 1. Read the files that were created/modified
300
+ 2. Check against the task description and project conventions
301
+ 3. Report findings with file:line and severity
302
+ 4. Use patch_file to fix minor issues directly
303
+ 5. For major issues, document them clearly in your report
304
+
305
+ You do NOT have task_create or write_file. You can only read and patch.`
306
+ };
307
+ var CAP_ROLE_OPS = {
308
+ name: "role-ops",
309
+ description: "Ops role: sets up project infrastructure, configs, dependencies.",
310
+ prompt: `## YOUR ROLE: Ops
311
+ You SET UP infrastructure \u2014 package.json, tsconfig.json, directory structure, dependencies.
312
+
313
+ Your job:
314
+ 1. Initialize project structure (create config files, directories)
315
+ 2. Install dependencies with run_shell
316
+ 3. Ensure the project builds and tests can run
317
+
318
+ You do NOT have task_create. You execute infrastructure tasks directly.`
319
+ };
240
320
  var CAP_FILE_OPS = {
241
321
  name: "file-ops",
242
322
  description: "File read/write/patch operations and best practices for file manipulation.",
@@ -266,13 +346,31 @@ Use run_shell for running tests (npx vitest), validation (flow-weaver validate),
266
346
  };
267
347
  var CAP_TASK_MGMT = {
268
348
  name: "task-mgmt",
269
- description: "Create and manage swarm subtasks for parallel execution.",
349
+ description: "Create and manage swarm subtasks for parallel execution, with decomposition and review nudges.",
270
350
  tools: [OP_TASK_CREATE],
271
- prompt: `## Task Management
272
- - task_create: Create swarm subtasks for parallel execution. args: { title, description, complexity, subtasks[] }
273
- - task_list, task_get, task_update: Query and update existing tasks
351
+ prompt: `## Task Management & Decomposition
352
+
353
+ - task_create: Create swarm subtasks. args: { title, description, complexity, subtasks[], dependsOn[], assignedProfile? }
354
+
355
+ ### Decomposition
356
+ When you encounter a broad objective (multi-file, multi-concern), decompose into subtasks:
357
+ - If the task is bigger than a single file change, create subtasks instead of doing it all yourself.
358
+ - Minimize dependencies between subtasks to maximize parallel execution.
359
+ - Set complexity per subtask: trivial | simple | moderate | complex.
360
+ - Use dependsOn to express blocking relationships (e.g., setup before code, code before tests).
361
+
362
+ ### Review Task Creation
363
+ After creating or modifying multiple files, create a review task:
364
+ - title: "Review: [what was changed]"
365
+ - description: List the files modified and what to check
366
+ - assignedProfile: "reviewer"
367
+ - complexity: "simple"
368
+ Skip review for trivial single-file tasks.
274
369
 
275
- Use task_create to decompose complex work into smaller, independent subtasks that other bots can execute in parallel.`
370
+ ### Dependency Guidelines
371
+ - BAD: A \u2192 B \u2192 C \u2192 D (serial, slow)
372
+ - GOOD: A \u2192 [B + C + D] (A blocks all, but B/C/D run in parallel)
373
+ Structure as: setup \u2192 independent implementations \u2192 integration/testing.`
276
374
  };
277
375
  var CAP_FW_GRAMMAR = {
278
376
  name: "fw-grammar",
@@ -350,17 +448,41 @@ Note: compile, validate, modify, diff, diagram, and describe operations are avai
350
448
  };
351
449
  var CAP_CODE_REVIEW = {
352
450
  name: "code-review",
353
- description: "Code review guidelines, quality checklist, and security review patterns.",
354
- prompt: `## Code Review
451
+ description: "Comprehensive code review with correctness, security, style, testing, and performance checks.",
452
+ tools: [OP_READ_FILE, OP_PATCH_FILE, OP_RUN_SHELL],
453
+ prompt: `## Code Review Checklist
355
454
 
356
- When reviewing code, check for:
357
- 1. Correctness: Does the code do what the task asked?
358
- 2. Security: No hardcoded secrets, no injection vulnerabilities, no exposed APIs
359
- 3. Style: Consistent with project conventions, proper naming, no dead code
360
- 4. Testing: Are there tests? Do they cover edge cases?
361
- 5. Performance: No unnecessary loops, no blocking calls in async code
455
+ ### 1. Correctness
456
+ - Does the code do what the task asked?
457
+ - Edge cases handled (empty input, null, invalid types)?
458
+ - Error paths covered (try/catch, validation)?
459
+ - Return types match function signature?
362
460
 
363
- Report concerns with specific file:line references and suggested fixes.`
461
+ ### 2. Security
462
+ - NO hardcoded API keys, passwords, or tokens (use env vars)
463
+ - NO shell: true in child_process (command injection risk)
464
+ - NO eval() or Function() with untrusted input
465
+ - User input validated and sanitized before use
466
+ - File paths validated (no ../ traversal)
467
+
468
+ ### 3. Style
469
+ - Naming is clear and consistent with project conventions
470
+ - No dead code (unused variables, unreachable branches)
471
+ - No debug statements left in (console.log, debugger)
472
+ - Imports organized, no duplicates
473
+
474
+ ### 4. Testing
475
+ - Unit tests exist for new/changed functions
476
+ - Tests cover happy path AND edge cases
477
+ - Error cases have tests
478
+ - Code coverage adequate (aim for 80%+ of changed code)
479
+
480
+ ### 5. Performance
481
+ - No O(n\xB2) loops where O(n) is possible
482
+ - No blocking I/O in async code
483
+ - No memory leaks (listeners removed, timers cleared)
484
+
485
+ Report findings as: FILE:LINE | SEVERITY (critical/high/medium/low) | ISSUE \u2192 Fix suggestion`
364
486
  };
365
487
  var CAP_WEB = {
366
488
  name: "web",
@@ -377,8 +499,131 @@ var CAP_CONTEXT = {
377
499
  Use list_files to understand the project structure before making changes.
378
500
  The context bundle (when available) provides a snapshot of the workspace.`
379
501
  };
502
+ var CAP_VERIFICATION = {
503
+ name: "verification",
504
+ description: "Post-write verification: run tsc and tests to catch errors before delivery.",
505
+ tools: [OP_RUN_SHELL],
506
+ prompt: `## Verification
507
+
508
+ After writing or patching code, ALWAYS verify your work:
509
+ 1. Run \`npx tsc --noEmit\` in the project root to catch TypeScript errors
510
+ 2. If package.json has a "test" script, run \`npm test\` to validate functionality
511
+ 3. If verification fails, read the errors, fix the code, and re-verify
512
+
513
+ Include verification as explicit steps in your plan. Verification is NOT optional.
514
+ Do NOT deliver code that hasn't been verified.`
515
+ };
516
+ var CAP_CROSS_FILE_CHECK = {
517
+ name: "cross-file-check",
518
+ description: "Verify imports, exports, module paths, and cross-file dependencies.",
519
+ tools: [OP_READ_FILE, OP_LIST_FILES, OP_RUN_SHELL],
520
+ prompt: `## Cross-File Dependency Checks
521
+
522
+ When modifying code that affects multiple files:
523
+ 1. If you rename an export, grep for all imports of it and update them
524
+ 2. Verify relative import paths resolve correctly (../types vs ./types)
525
+ 3. Check for circular dependencies (A imports B imports A)
526
+ 4. If you change a function signature, update all callers
527
+ 5. Use \`run_shell\` with grep to search: grep -r "functionName" src/
528
+
529
+ Do NOT move or rename exports without verifying all dependents.`
530
+ };
531
+ var CAP_PROJECT_SETUP = {
532
+ name: "project-setup",
533
+ description: "Initialize new projects with correct structure, config, and dependencies.",
534
+ tools: [OP_WRITE_FILE, OP_RUN_SHELL],
535
+ prompt: `## Project Setup
536
+
537
+ When initializing a project:
538
+ 1. Create package.json with name, type: "module", main, scripts (build, test)
539
+ 2. Create tsconfig.json with strict: true, module: "esnext", target: "ES2020"
540
+ 3. Create standard directories: src/, tests/
541
+ 4. Install dependencies with run_shell: npm install <deps>
542
+ 5. Create .gitignore excluding node_modules/, dist/
543
+ 6. Verify setup: run tsc --noEmit to ensure TypeScript compiles`
544
+ };
545
+ var CAP_SECURITY = {
546
+ name: "security",
547
+ description: "Audit code for vulnerabilities, secrets, and security best practices.",
548
+ tools: [OP_READ_FILE, OP_LIST_FILES, OP_RUN_SHELL],
549
+ prompt: `## Security Audit
550
+
551
+ Check for:
552
+ 1. **Secrets**: NO hardcoded API keys, passwords, tokens. Use env vars.
553
+ grep -r "password\\|secret\\|apiKey\\|token" src/ to find leaks.
554
+ 2. **Injection**: NO string concatenation in SQL. NO shell: true in child_process. NO eval().
555
+ 3. **Dependencies**: Run npm audit to check for known CVEs.
556
+ 4. **File paths**: Validate paths to prevent ../ traversal attacks.
557
+ 5. **Data handling**: Validate user input (type, length, format). Sanitize before logging.
558
+
559
+ Report findings with severity: critical | high | medium | low.`
560
+ };
561
+ var CAP_DECOMPOSITION = {
562
+ name: "decomposition",
563
+ description: "Break complex objectives into subtask DAGs with dependencies for parallel execution.",
564
+ tools: [OP_TASK_CREATE],
565
+ prompt: `## Task Decomposition
566
+
567
+ When given a large objective, break it into smaller subtasks:
568
+ 1. Identify all work items (files, features, tests)
569
+ 2. Group by dependency: what must happen first?
570
+ 3. Create subtasks with task_create, each focused on one responsibility
571
+ 4. Set dependencies with dependsOn to model blocking relationships
572
+ 5. Minimize dependencies to maximize parallel execution
573
+ 6. Estimate complexity per subtask: trivial | simple | moderate | complex
574
+
575
+ Example: "Implement auth module"
576
+ - Task A: Extract shared auth types (simple)
577
+ - Task B: Rewrite login endpoint (moderate, depends on A)
578
+ - Task C: Add login tests (moderate, depends on B)
579
+ - Task D: Update auth docs (simple, independent \u2014 runs in parallel with B)
580
+
581
+ Assign profiles: code tasks \u2192 developer, review tasks \u2192 reviewer, infra \u2192 ops.`
582
+ };
583
+ var CAP_ROUTING = {
584
+ name: "routing",
585
+ description: "Route tasks to appropriate bot profiles based on capabilities and complexity.",
586
+ tools: [OP_TASK_CREATE],
587
+ prompt: `## Task Routing
588
+
589
+ When creating subtasks, assign the right profile:
590
+ - Code writing, file creation, bug fixes \u2192 developer profile
591
+ - Code review, quality checks \u2192 reviewer profile
592
+ - Shell commands, project setup, infrastructure \u2192 ops profile
593
+ - Leave assignedProfile empty for auto-triage when unsure
594
+
595
+ Match complexity to profile capabilities:
596
+ - trivial/simple tasks: any profile (prefer cheapest)
597
+ - moderate tasks: specialist profiles
598
+ - complex tasks: profiles with full capability sets`
599
+ };
600
+ var CAP_MEMORY = {
601
+ name: "memory",
602
+ description: "Remember and recall project conventions for continuity across sessions.",
603
+ tools: [OP_REMEMBER, OP_RECALL],
604
+ prompt: `## Project Memory
605
+
606
+ Persist project conventions for future sessions:
607
+ - remember: Save a convention. args: { key: "naming", value: "kebab-case for files" }
608
+ - recall: Load all saved conventions. args: {} \u2014 returns project memory.
609
+
610
+ What to remember:
611
+ - Naming conventions (file names, variable names)
612
+ - Architecture decisions (Result pattern, Zod for validation)
613
+ - Test patterns (where tests go, what framework)
614
+ - Common dependencies and their usage
615
+
616
+ Before planning, recall project memory to follow established patterns.
617
+ When you discover a new convention, remember it for future bots.`
618
+ };
380
619
  var BUILT_IN_CAPABILITIES = [
381
620
  CAP_CORE,
621
+ // Role capabilities
622
+ CAP_ROLE_ORCHESTRATOR,
623
+ CAP_ROLE_DEVELOPER,
624
+ CAP_ROLE_REVIEWER,
625
+ CAP_ROLE_OPS,
626
+ // Tool capabilities
382
627
  CAP_FILE_OPS,
383
628
  CAP_SHELL,
384
629
  CAP_TASK_MGMT,
@@ -388,7 +633,15 @@ var BUILT_IN_CAPABILITIES = [
388
633
  CAP_FW_CLI,
389
634
  CAP_CODE_REVIEW,
390
635
  CAP_WEB,
391
- CAP_CONTEXT
636
+ CAP_CONTEXT,
637
+ // Swarm improvement capabilities
638
+ CAP_VERIFICATION,
639
+ CAP_CROSS_FILE_CHECK,
640
+ CAP_PROJECT_SETUP,
641
+ CAP_SECURITY,
642
+ CAP_DECOMPOSITION,
643
+ CAP_ROUTING,
644
+ CAP_MEMORY
392
645
  ];
393
646
  var capabilityMap = new Map(
394
647
  BUILT_IN_CAPABILITIES.map((c) => [c.name, c])
@@ -396,9 +649,9 @@ var capabilityMap = new Map(
396
649
 
397
650
  // src/bot/behavior-defaults.ts
398
651
  var STRATEGY_CAPABILITIES = {
399
- frugal: ["core", "file-ops", "shell", "context"],
400
- balanced: ["core", "file-ops", "shell", "task-mgmt", "fw-grammar", "fw-validate", "context"],
401
- performance: ["core", "file-ops", "shell", "task-mgmt", "fw-grammar", "fw-validate", "fw-genesis", "fw-cli", "code-review", "web", "context"]
652
+ frugal: ["core", "role-developer", "file-ops", "shell", "context"],
653
+ balanced: ["core", "role-developer", "file-ops", "shell", "fw-grammar", "fw-validate", "context"],
654
+ performance: ["core", "role-developer", "file-ops", "shell", "fw-grammar", "fw-validate", "fw-genesis", "fw-cli", "code-review", "web", "context"]
402
655
  };
403
656
  var STRATEGY_BUDGETS = {
404
657
  frugal: 0.1,