kenaz 0.3.18 → 0.3.20

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 (329) hide show
  1. package/core/.claude/commands/agent-worker.md +1 -1
  2. package/core/.claude/commands/architect.md +1 -2
  3. package/core/.claude/commands/spec.md +1 -1
  4. package/core/.claude/commands//347/224/242/345/223/201.md +1 -1
  5. package/core/.claude/hooks/__tests__/task-1977-dedupe-guard.test.js +8 -8
  6. package/core/.claude/skills/architect_agent/SKILL.md +11 -92
  7. package/core/.claude/skills/assessment_agent/SKILL.md +0 -1
  8. package/core/.claude/skills/backend_engineer/SKILL.md +3 -6
  9. package/core/.claude/skills/code_reviewer/SKILL.md +1 -1
  10. package/core/.claude/skills/code_reviewer/patterns.yaml +1 -1
  11. package/core/.claude/skills/designer/SKILL.md +3 -6
  12. package/core/.claude/skills/dev_agent/SKILL.md +30 -491
  13. package/core/.claude/skills/developer/SKILL.md +3 -6
  14. package/core/.claude/skills/feature_agent/SKILL.md +3 -17
  15. package/core/.claude/skills/product_manager/SKILL.md +29 -1064
  16. package/core/.claude/skills/qa_engineer/SKILL.md +12 -17
  17. package/core/.claude/skills/spec_optimizer/SKILL.md +25 -275
  18. package/core/.claude/skills/sre_agent/SKILL.md +3 -6
  19. package/core/.collaboration/README.md +2 -3
  20. package/core/.collaboration/core/task-api.js +5 -138
  21. package/core/.collaboration/docs/CLI.md +0 -2
  22. package/core/.failure/INDEX.yaml +6 -40
  23. package/core/.failure/agent-execution/FAIL-013-search-cwd-drift-and-case-mismatch.yaml +1 -1
  24. package/core/.failure/tools/README.md +9 -227
  25. package/core/.formation/bifrost/launch.js +1 -6
  26. package/core/.formation/bifrost/launch.test.js +1 -1
  27. package/core/.formation/bifrost/shared/ansuz-boot-policy.js +3 -3
  28. package/core/.formation/bifrost/shared/ansuz-boot-policy.test.js +1 -2
  29. package/core/.formation/tools/__tests__/arms.test.js +41 -0
  30. package/core/.formation/tools/__tests__/diagnose-bug.test.js +10 -0
  31. package/core/.formation/tools/__tests__/m1-hmap-convid.test.js +1 -124
  32. package/core/.formation/tools/arms.js +48 -0
  33. package/core/.formation/tools/dispatch.js +24 -15
  34. package/core/.formation/tools/kenaz-stats.js +32 -8
  35. package/core/.formation/tools/kenaz-stats.test.js +15 -2
  36. package/core/.formation/tools/loader.js +17 -140
  37. package/core/.formation/tools/post-complete.js +0 -31
  38. package/core/.formation/tools/prompt.js +16 -1
  39. package/core/.formation/tools/prompt.test.js +20 -0
  40. package/core/.rule/INDEX.yaml +0 -18
  41. package/core/.rule/general/agent-workflow.yaml +14 -164
  42. package/core/.rule/general/project-self-containment.yaml +8 -19
  43. package/core/.rule/general/rust-verify-target.yaml +6 -5
  44. package/core/.rule/general/synapse-code-intelligence.yaml +3 -3
  45. package/core/.specialist/Amelia/capability.yaml +12 -12
  46. package/core/.specialist/Amelia/workflow.yaml +2 -2
  47. package/core/.specialist/Ansuz/SYSTEM_DOC.md +20 -578
  48. package/core/.specialist/Ansuz/cognitive_principles.yaml +2 -3
  49. package/core/.specialist/Ansuz/concepts/boot_rules_summary.yaml +0 -1
  50. package/core/.specialist/Ansuz/concepts/deep_knowledge_pointers.yaml +1 -2
  51. package/core/.specialist/Ansuz/core.yaml +6 -108
  52. package/core/.specialist/Ansuz/guards/lesson_guards.yaml +0 -3
  53. package/core/.specialist/Ansuz/identity_contract.yaml +0 -1
  54. package/core/.specialist/Ansuz/knowledge.yaml +0 -4
  55. package/core/.specialist/Ansuz/rule.yaml +0 -1
  56. package/core/.specialist/Ansuz/tools/handoff-session-identity.test.js +6 -150
  57. package/core/.specialist/tests/runtime-discovery/README.md +1 -1
  58. package/core/.specialist/tools/__tests__/task-2374-usage-counter.test.js +1 -12
  59. package/core/.specialist/tools/ansuz-boot-fast.js +7 -4
  60. package/core/.specialist/tools/ansuz-boot-fast.test.js +10 -3
  61. package/core/.specialist/tools/prompt-files.test.js +1 -0
  62. package/core/.specialist/tools/task-bridge.js +1 -66
  63. package/core/.system/README.md +11 -552
  64. package/core/.system/collaboration/README.md +10 -174
  65. package/core/CLAUDE.md +1 -6
  66. package/core/KENAZ_CORE_VERSION +1 -1
  67. package/core/dev/scripts/js-yaml-resolution.test.js +1 -1
  68. package/core/dev/scripts/peer-identity-e2e.js +402 -0
  69. package/core/dev/scripts/peer-identity-e2e.md +47 -0
  70. package/core/dev/scripts/relay-admin.js +94 -0
  71. package/core/dev/scripts/relay-admin.test.js +131 -0
  72. package/core/dev/scripts/run-rust-tests.js +9 -45
  73. package/core/dev/scripts/rust-verify-worktree.js +4 -4
  74. package/core/dev/scripts/verify-target-dir.js +6 -6
  75. package/core/plugins/kenaz/INVENTORY.md +8 -8
  76. package/core/plugins/kenaz/README.md +10 -0
  77. package/core/plugins/kenaz/commands/architect.md +1 -2
  78. package/core/plugins/kenaz/commands/spec.md +1 -1
  79. package/core/plugins/kenaz/commands//347/224/242/345/223/201.md +1 -1
  80. package/core/plugins/kenaz/guidance.md +1 -1
  81. package/core/plugins/kenaz/hooks/kenaz-hook.js +2 -1
  82. package/core/plugins/kenaz/hooks/sdk-gate.js +9 -0
  83. package/core/plugins/kenaz/scripts/kenaz.test.js +15 -3
  84. package/core/plugins/kenaz/scripts/sync.js +1 -1
  85. package/core/plugins/kenaz/scripts/ygg.js +8 -0
  86. package/core/plugins/kenaz/scripts/ygg.test.js +72 -0
  87. package/core/plugins/kenaz/skills/architect_agent/SKILL.md +11 -92
  88. package/core/plugins/kenaz/skills/assessment_agent/SKILL.md +0 -1
  89. package/core/plugins/kenaz/skills/backend_engineer/SKILL.md +3 -6
  90. package/core/plugins/kenaz/skills/code_reviewer/SKILL.md +1 -1
  91. package/core/plugins/kenaz/skills/code_reviewer/patterns.yaml +1 -1
  92. package/core/plugins/kenaz/skills/designer/SKILL.md +3 -6
  93. package/core/plugins/kenaz/skills/dev_agent/SKILL.md +30 -491
  94. package/core/plugins/kenaz/skills/developer/SKILL.md +3 -6
  95. package/core/plugins/kenaz/skills/feature_agent/SKILL.md +3 -17
  96. package/core/plugins/kenaz/skills/product_manager/SKILL.md +29 -1064
  97. package/core/plugins/kenaz/skills/qa_engineer/SKILL.md +12 -17
  98. package/core/plugins/kenaz/skills/spec_optimizer/SKILL.md +25 -275
  99. package/core/plugins/kenaz/skills/sre_agent/SKILL.md +3 -6
  100. package/core/plugins/kenaz-peer/hooks/register.test.ts +32 -0
  101. package/core/plugins/kenaz-peer/hooks/register.ts +9 -0
  102. package/package.json +6 -6
  103. package/core/.claude/commands/archive.md +0 -24
  104. package/core/.claude/commands/init.md +0 -112
  105. package/core/.claude/commands/legacy_dev.md +0 -18
  106. package/core/.claude/commands/product-review.md +0 -131
  107. package/core/.claude/commands/strategy.md +0 -141
  108. package/core/.claude/commands/sunny.md +0 -1
  109. package/core/.claude/commands//347/224/242/345/223/201/346/252/242/350/246/226.md +0 -129
  110. package/core/.claude/commands//351/200/262/345/272/246.md +0 -15
  111. package/core/.claude/hooks/__tests__/substrate.test.js +0 -122
  112. package/core/.claude/hooks/_substrate-paths.js +0 -95
  113. package/core/.claude/hooks/context-check.js +0 -51
  114. package/core/.claude/hooks/fatigue-check.js +0 -52
  115. package/core/.claude/hooks/handoff-snapshot-on-commit.js +0 -154
  116. package/core/.claude/hooks/handoff-snapshot-on-question.js +0 -158
  117. package/core/.claude/hooks/handoff-staleness.js +0 -197
  118. package/core/.claude/hooks/jev-thalamus-context.js +0 -17
  119. package/core/.claude/hooks/jev-thalamus-context.test.js +0 -41
  120. package/core/.claude/hooks/lease-release.js +0 -119
  121. package/core/.claude/hooks/lease-touch.js +0 -96
  122. package/core/.claude/hooks/reflex-feedback.js +0 -5
  123. package/core/.claude/hooks/session-init.ps1 +0 -49
  124. package/core/.claude/hooks/sound-event.js +0 -70
  125. package/core/.claude/hooks/sound-event.sh +0 -37
  126. package/core/.claude/hooks/stream-delta.js +0 -169
  127. package/core/.claude/no-hooks.settings.json +0 -3
  128. package/core/.claude/skills/legacy_dev/SKILL.md +0 -202
  129. package/core/.claude/skills/sunny/SKILL.md +0 -74
  130. package/core/.collaboration/cli/commands/assign.js +0 -39
  131. package/core/.collaboration/cli/commands/claim.js +0 -33
  132. package/core/.collaboration/cli/commands/complete.js +0 -44
  133. package/core/.collaboration/cli/commands/create.js +0 -110
  134. package/core/.collaboration/cli/commands/get.js +0 -83
  135. package/core/.collaboration/cli/commands/index.js +0 -52
  136. package/core/.collaboration/cli/commands/list.js +0 -51
  137. package/core/.collaboration/cli/commands/lock.js +0 -45
  138. package/core/.collaboration/cli/commands/rebuild.js +0 -39
  139. package/core/.collaboration/cli/commands/search.js +0 -61
  140. package/core/.collaboration/cli/commands/stats.js +0 -61
  141. package/core/.collaboration/cli/commands/transfer.js +0 -41
  142. package/core/.collaboration/cli/commands/unlock.js +0 -48
  143. package/core/.collaboration/cli/formatters/help-formatter.js +0 -70
  144. package/core/.collaboration/cli/formatters/index.js +0 -7
  145. package/core/.collaboration/cli/task-cli.js +0 -46
  146. package/core/.collaboration/cli/utils/arg-parser.js +0 -74
  147. package/core/.collaboration/cli/utils/git-user.js +0 -25
  148. package/core/.collaboration/cli/utils/index.js +0 -9
  149. package/core/.collaboration/cli/utils/output.js +0 -10
  150. package/core/.collaboration/config/default.yaml +0 -189
  151. package/core/.collaboration/core/conflict-resolver.js +0 -461
  152. package/core/.collaboration/core/conflict-resolver.test.js +0 -389
  153. package/core/.collaboration/core/migrate-legacy.js +0 -260
  154. package/core/.collaboration/docs/API.md +0 -787
  155. package/core/.collaboration/docs/ARCHITECTURE.md +0 -596
  156. package/core/.collaboration/docs/FAQ.md +0 -695
  157. package/core/.collaboration/docs/MIGRATION.md +0 -804
  158. package/core/.collaboration/docs/examples/README.md +0 -320
  159. package/core/.collaboration/docs/examples/advanced-queries.js +0 -261
  160. package/core/.collaboration/docs/examples/basic-usage.js +0 -184
  161. package/core/.collaboration/docs/examples/team-workflow.js +0 -352
  162. package/core/.failure/agent-execution/FAIL-001-agent-no-output.yaml +0 -391
  163. package/core/.failure/agent-execution/FAIL-007-pm-lead-wrong-team-invocation.yaml +0 -0
  164. package/core/.failure/agent-execution/FAIL-010-phase0-poem-format-skipped.yaml +0 -28
  165. package/core/.failure/agent-execution/FAIL-010-skipping-cognitive-checkpoint-after-verification.yaml +0 -59
  166. package/core/.failure/agent-execution/FAIL-012-grep-shortcut-during-investigation.yaml +0 -85
  167. package/core/.failure/architecture/FAIL-006-python-version-compatibility.yaml +0 -445
  168. package/core/.failure/pipeline/FAIL-003-queue-pollution.yaml +0 -335
  169. package/core/.failure/pipeline/README.md +0 -95
  170. package/core/.failure/retired/FAIL-009-skipping-synapse-pulse-before-code-change.yaml +0 -49
  171. package/core/.failure/tools/USAGE_GUIDE.md +0 -323
  172. package/core/.failure/tools/check_failures.ps1 +0 -387
  173. package/core/.failure/tools/log_failure.ps1 +0 -474
  174. package/core/.formation/.episode-input.json +0 -10
  175. package/core/.formation/.merge-lock +0 -1
  176. package/core/.formation/lead.yaml +0 -118
  177. package/core/.formation/legacy.bak/designer.yaml +0 -57
  178. package/core/.formation/legacy.bak/pm.yaml +0 -57
  179. package/core/.formation/legacy.bak/qa.yaml +0 -57
  180. package/core/.formation/legacy.bak/review.yaml +0 -62
  181. package/core/.formation/legacy.bak/scheduler.yaml +0 -129
  182. package/core/.formation/legacy.bak/sre.yaml +0 -57
  183. package/core/.formation/role-map.yaml +0 -274
  184. package/core/.formation/roles/_shared/modules/code_review.yaml +0 -98
  185. package/core/.formation/roles/_shared/modules/security.yaml +0 -103
  186. package/core/.formation/roles/_shared/modules/testing.yaml +0 -14
  187. package/core/.formation/roles/backend/role.yaml +0 -93
  188. package/core/.formation/roles/code_reviewer/role.yaml +0 -102
  189. package/core/.formation/roles/database_optimizer/role.yaml +0 -107
  190. package/core/.formation/roles/designer/role.yaml +0 -66
  191. package/core/.formation/roles/developer/role.yaml +0 -75
  192. package/core/.formation/roles/frontend/role.yaml +0 -134
  193. package/core/.formation/roles/incident_response/role.yaml +0 -89
  194. package/core/.formation/roles/qa/role.yaml +0 -89
  195. package/core/.formation/roles/security/role.yaml +0 -87
  196. package/core/.formation/roles/sre/role.yaml +0 -66
  197. package/core/.formation/skills/coordinator.yaml +0 -52
  198. package/core/.formation/solo/diagnosis.yaml +0 -78
  199. package/core/.formation/solo/strategy.yaml +0 -121
  200. package/core/.formation/tests/hello.txt +0 -2
  201. package/core/.formation/tools/coordinator.js +0 -350
  202. package/core/.formation/tools/jev-correction.js +0 -214
  203. package/core/.formation/tools/jev-correction.test.js +0 -178
  204. package/core/.formation/tools/log-reader.js +0 -232
  205. package/core/.formation/tools/revert-daemon-state.js +0 -162
  206. package/core/.formation/tools/test-drift.js +0 -148
  207. package/core/.formation/unit/heimdall.yaml +0 -96
  208. package/core/.formation/unit/plan.yaml +0 -67
  209. package/core/.formation/unit/think.yaml +0 -58
  210. package/core/.kenaz/MUNINN_SNAPSHOT9_EPISODE.json +0 -32
  211. package/core/.kenaz/MUNINN_SNAPSHOT9_RUNE.json +0 -23
  212. package/core/.kenaz/MUNINN_SNAPSHOT9_SUMMARY.md +0 -89
  213. package/core/.kenaz/ash_TASK_1428-20260507.json +0 -14
  214. package/core/.kenaz/muninn_episode_write.ps1 +0 -17
  215. package/core/.kenaz/muninn_snapshot11_rune_candidates.md +0 -63
  216. package/core/.kenaz/muninn_snapshot1_rune_candidates.md +0 -49
  217. package/core/.kenaz/runes_TASK_1428.json +0 -57
  218. package/core/.kenaz/tmp_heimdall_proposal_8d3e392.json +0 -13
  219. package/core/.kenaz/tmp_props.json +0 -1
  220. package/core/.kenaz/tmp_sounddrop_t1_prompt.txt +0 -371
  221. package/core/.rule/MECHANIZED.md +0 -61
  222. package/core/.rule/general/cortex-memory-recall.yaml +0 -446
  223. package/core/.rule/general/pipeline.yaml +0 -246
  224. package/core/.rule/general/sunny-access-control.yaml +0 -60
  225. package/core/.rule/general/system-invariants.yaml +0 -231
  226. package/core/.rule/pipeline/PPL-002-completed-task-archival.yaml +0 -528
  227. package/core/.rule/pipeline/auto-update.yaml +0 -282
  228. package/core/.rule/pipeline/task-execution.yaml +0 -365
  229. package/core/.specialist/Ansuz/concepts/phase_protocol.yaml +0 -65
  230. package/core/.specialist/Ansuz/experiments/boot_ablation_replay.js +0 -197
  231. package/core/.specialist/Ansuz/tools/bootstrap-anchors.js +0 -289
  232. package/core/.specialist/Ansuz/workflow.yaml +0 -1225
  233. package/core/.specialist/experiments/rg_benchmark.js +0 -523
  234. package/core/.specialist/experiments/rg_benchmark_results.json +0 -27
  235. package/core/.specialist/tools/jev-optional-context.js +0 -107
  236. package/core/.specialist/tools/jev-optional-context.test.js +0 -152
  237. package/core/.specialist/tools/memory-action-log.js +0 -839
  238. package/core/.specialist/tools/phase-gate.js +0 -3534
  239. package/core/.specialist/tools/phase-gate.test.js +0 -85
  240. package/core/.specialist/tools/precompute-runner.js +0 -444
  241. package/core/.specialist/tools/rule-engine.js +0 -621
  242. package/core/.specialist/tools/task-bridge-jev.test.js +0 -170
  243. package/core/.synapse/memory-shared.json.sync +0 -1
  244. package/core/.system/agent-skills/README.md +0 -724
  245. package/core/.system/cli-tools/README.md +0 -724
  246. package/core/.system/cortex/MODULES.md +0 -1046
  247. package/core/.system/dashboard/FRONTEND.md +0 -812
  248. package/core/.system/dashboard/README.md +0 -737
  249. package/core/.system/failure/README.md +0 -723
  250. package/core/.system/formation/LEGACY_SKILLS.md +0 -974
  251. package/core/.system/formation/POST_COMPLETE.md +0 -602
  252. package/core/.system/formation/README.md +0 -1094
  253. package/core/.system/formation/TOOLS_REFERENCE.md +0 -1145
  254. package/core/.system/kenaz/README.md +0 -787
  255. package/core/.system/memory/README.md +0 -719
  256. package/core/.system/pipeline/README.md +0 -712
  257. package/core/.system/rule/README.md +0 -794
  258. package/core/.system/sunny/README.md +0 -476
  259. package/core/.system/sunny/RULES.json +0 -89
  260. package/core/.system/sunny/knowledge/INDEX.md +0 -37
  261. package/core/.system/sunny/knowledge/agent-teams-api.md +0 -0
  262. package/core/.system/sunny/knowledge/ansuz-specialist.md +0 -500
  263. package/core/.system/sunny/knowledge/claude-cli-spawn.md +0 -177
  264. package/core/.system/sunny/knowledge/collaboration-api.md +0 -925
  265. package/core/.system/sunny/teammates/README.md +0 -107
  266. package/core/.system/sunny/teammates/how_to_use.yaml +0 -101
  267. package/core/.system/sunny/teammates/tools/headless/launcher.js +0 -318
  268. package/core/.system/sunny/teammates/tools/powershell/launcher.js +0 -241
  269. package/core/.system/sunny/teammates/tools/powershell/start.bat +0 -50
  270. package/core/.system/sunny/teammates/tools/utils/env.js +0 -96
  271. package/core/.system/sunny/teammates/tools/utils/format-output.js +0 -329
  272. package/core/.system/sunny/tools.json +0 -101
  273. package/core/dev/scripts/cleanup-queue.js +0 -184
  274. package/core/dev/scripts/cleanup_queue.js +0 -86
  275. package/core/dev/scripts/legacy/README.md +0 -39
  276. package/core/dev/scripts/legacy/dev_agent_scheduler.ps1.bak +0 -536
  277. package/core/dev/scripts/legacy/multi_agent_scheduler.ps1.bak +0 -1978
  278. package/core/dev/scripts/matrix/CLI_README.md +0 -214
  279. package/core/dev/scripts/matrix/README.md +0 -310
  280. package/core/dev/scripts/matrix/package-lock.json +0 -4266
  281. package/core/dev/scripts/matrix/package.json +0 -55
  282. package/core/dev/scripts/matrix/src/abbreviations.ts +0 -295
  283. package/core/dev/scripts/matrix/src/cli/commands/convert.ts +0 -211
  284. package/core/dev/scripts/matrix/src/cli/commands/create.ts +0 -95
  285. package/core/dev/scripts/matrix/src/cli/commands/delete.ts +0 -102
  286. package/core/dev/scripts/matrix/src/cli/commands/list-tags.ts.wip +0 -140
  287. package/core/dev/scripts/matrix/src/cli/commands/manage-tags.ts.wip +0 -173
  288. package/core/dev/scripts/matrix/src/cli/commands/query.ts +0 -261
  289. package/core/dev/scripts/matrix/src/cli/commands/read.ts +0 -77
  290. package/core/dev/scripts/matrix/src/cli/commands/stats.ts.wip +0 -168
  291. package/core/dev/scripts/matrix/src/cli/commands/tokens.ts.wip +0 -126
  292. package/core/dev/scripts/matrix/src/cli/commands/update.ts +0 -147
  293. package/core/dev/scripts/matrix/src/cli/commands/validate.ts +0 -275
  294. package/core/dev/scripts/matrix/src/cli/index.ts +0 -350
  295. package/core/dev/scripts/matrix/src/cli/utils/file-handler.ts +0 -72
  296. package/core/dev/scripts/matrix/src/cli/utils/logger.ts +0 -65
  297. package/core/dev/scripts/matrix/src/index.ts +0 -62
  298. package/core/dev/scripts/matrix/src/indexer/tag-indexer.ts +0 -165
  299. package/core/dev/scripts/matrix/src/parser.ts +0 -281
  300. package/core/dev/scripts/matrix/src/serializer.ts +0 -151
  301. package/core/dev/scripts/matrix/src/validator.ts +0 -301
  302. package/core/dev/scripts/matrix/tests/abbreviations.test.ts +0 -122
  303. package/core/dev/scripts/matrix/tests/cli.test.ts +0 -177
  304. package/core/dev/scripts/matrix/tests/convert.test.ts +0 -143
  305. package/core/dev/scripts/matrix/tests/parser.test.ts +0 -203
  306. package/core/dev/scripts/matrix/tests/query.test.ts +0 -85
  307. package/core/dev/scripts/matrix/tests/serializer.test.ts +0 -197
  308. package/core/dev/scripts/matrix/tests/validate.test.ts +0 -141
  309. package/core/dev/scripts/matrix/tests/validator.test.ts +0 -167
  310. package/core/dev/scripts/matrix/tsconfig.json +0 -20
  311. package/core/dev/scripts/matrix/types/index.d.ts +0 -111
  312. package/core/dev/scripts/matrix/types/index.d.ts.map +0 -1
  313. package/core/dev/scripts/matrix/types/index.js +0 -8
  314. package/core/dev/scripts/matrix/types/index.js.map +0 -1
  315. package/core/dev/scripts/matrix/types/index.ts +0 -124
  316. package/core/dev/scripts/memory-usage-report.js +0 -152
  317. package/core/dev/scripts/probe/ansuz-scaffold-ablation.js +0 -579
  318. package/core/dev/scripts/probe/ansuz-scaffold-ablation.test.js +0 -244
  319. package/core/dev/scripts/probe/hook-latency-probe.js +0 -315
  320. package/core/dev/scripts/probe/hook-latency-probe.test.js +0 -105
  321. package/core/dev/scripts/probe/prediction-signal-auc.js +0 -483
  322. package/core/dev/scripts/probe/prediction-signal-auc.test.js +0 -200
  323. package/core/dev/scripts/test-pty-ws-tunnel.js +0 -229
  324. package/core/dev/scripts/validate_pipeline.js +0 -197
  325. package/core/dev/spikes/task2145-evidence-20261004/backend-log-excerpt.txt +0 -56
  326. package/core/dev/spikes/task2145-evidence-20261004/graph.shadow +0 -0
  327. package/core/dev/spikes/task2145-evidence-20261004/graph.wal +0 -0
  328. package/core/dev/spikes/task2145-evidence-20261004/graph_corrupt_suspect.marker +0 -1
  329. package/core/plugins/kenaz/commands/strategy.md +0 -141
@@ -1,1094 +0,0 @@
1
- # Formation System - 多陣型調度系統
2
-
3
- > **[RETIRED 2026-10, TASK_2401/2402/2403]** 本文描述已退役的 headless / legacy-scheduler Formation,僅留作歷史參考。現行路徑:`node .formation/tools/dispatch.js --skill=do --task=TASK_XXX --dispatch-mode=subagent`(見 `.formation/README.md`)。
4
-
5
- > **專案位置**: `.formation/`
6
- > **系統類型**: Multi-Agent 協作陣型系統
7
- > **適用場景**: 根據任務規模動態選擇最佳 Agent 部署策略
8
-
9
- ---
10
-
11
- ## 📋 系統概述
12
-
13
- Formation 系統是 Kenaz AI 的 **Agent 部署陣型系統**,根據任務規模和協作需求,提供 **5 種不同的 Agent 調度陣型**,從最輕量的單人執行到最重火力的即時團隊協作。
14
-
15
- ### 核心理念
16
-
17
- **「合適的陣型 = 最佳的效率與成本平衡」**
18
-
19
- 不同任務需要不同的協作模式:
20
- - 簡單任務不需要團隊,浪費資源
21
- - 複雜任務單人做不完,拆不好反而更慢
22
- - 高耦合任務需要即時溝通,延遲會產生返工
23
-
24
- Formation 提供漸進式的陣型選擇,從「一人做一事」到「團隊即時協作」。
25
-
26
- ---
27
-
28
- ## 🔥 陣型一覽
29
-
30
- ```
31
- Unit → Solo → Squad → Legion → Legacy
32
- 1×1 1×N N×1 Team 自動化
33
- 最輕量 最靈活 真並行 最重火力 排程器
34
- ```
35
-
36
- | 陣型 | 人數 | 溝通 | 成本 | 適用場景 |
37
- |------|------|------|------|---------|
38
- | **Unit** | 1 Agent, 1 Task | 無 | 最低 | 明確單一任務、Bug 修復 |
39
- | **Solo** | 1 Agent, N 視角 | 自主切換 | 低 | 策略分析、多角度審視 |
40
- | **Squad** | N Agents, 1 Task | 無(靠 context) | 中 | 並行子任務、批量修改 |
41
- | **Legion** | N Agents, 即時通訊 | SendMessage | 高 | 順序依賴、回饋循環 |
42
- | **Legacy** | 排程器自動調度 | 無 | 最低 | 自動化連續開發 |
43
-
44
- ---
45
-
46
- ## 📁 目錄結構
47
-
48
- ```
49
- .formation/
50
- ├── README.md # 陣型選擇指南(本文件)
51
- ├── lead.yaml # Formation Lead 定義(陣型選擇器)
52
- │
53
- ├── tools/ # ⭐ 核心工具模組
54
- │ ├── headless.js # 無頭啟動器(推薦,所有陣型)
55
- │ ├── dispatch.js # CLI 入口(互動式)
56
- │ ├── loader.js # YAML/Task 載入(三層 fallback)
57
- │ ├── prompt.js # Prompt 組裝(unit/solo/squad/legion)
58
- │ ├── runner.js # Claude 進程管理(單進程 + 並行)
59
- │ ├── logger.js # 日誌格式化
60
- │ ├── utils.js # 工具函數
61
- │ ├── run-round2.js # Round 2 調度器(測試用)
62
- │ └── legacy-scheduler.js # Legacy 排程器實作
63
- │
64
- ├── logs/ # ⭐ 執行日誌(按陣型分目錄)
65
- │ ├── unit/
66
- │ ├── solo/
67
- │ ├── squad/
68
- │ ├── legion/
69
- │ └── legacy/
70
- │
71
- ├── briefs/ # 任務簡報
72
- ├── reports/ # 執行報告
73
- │
74
- ├── unit/ # Unit 陣型定義
75
- │ ├── do.yaml # 執行者(做事)
76
- │ ├── think.yaml # 分析者(思考)
77
- │ └── plan.yaml # 規劃者(計畫)
78
- │
79
- ├── solo/ # Solo 陣型定義(多視角)
80
- │ ├── strategy.yaml # 策略分析(6 視角)
81
- │ └── diagnosis.yaml # 問題診斷(4 視角)
82
- │
83
- ├── squad/ # Squad 陣型定義(並行協作)
84
- │ ├── blitz.yaml # 通用並行拆分
85
- │ ├── sweep.yaml # 同規則多範圍掃蕩
86
- │ └── strategy-tribunal.yaml # 策略法庭(多視角辯論)
87
- │
88
- ├── legion/ # Legion 陣型定義(即時團隊)
89
- │ ├── forge.yaml # 順序流水線(設計→打造→淬煉)
90
- │ └── hive.yaml # 網狀即時協調(全連接)
91
- │
92
- └── legacy/ # Legacy 陣型定義(排程器)
93
- ├── scheduler.yaml # 排程器配置
94
- ├── frontend.yaml # 前端團隊
95
- ├── backend.yaml # 後端團隊
96
- ├── designer.yaml # 設計團隊
97
- ├── qa.yaml # 測試團隊
98
- ├── sre.yaml # 運維團隊
99
- └── pm.yaml # 產品團隊
100
- ```
101
-
102
- ---
103
-
104
- ## 🎯 5 種陣型詳解
105
-
106
- ### 1. Unit(單兵作戰)
107
-
108
- **1 Agent, 1 Task** — 最小部署單位。
109
-
110
- **機制**:
111
- - 使用 `Task` 工具,單次 subagent 調用
112
- - 不切換角色、不協作,純粹的「去做這件事」
113
-
114
- **成本**:最低
115
-
116
- **適用場景**:
117
- - ✅ 明確的單一任務
118
- - ✅ Bug 修復
119
- - ✅ 檔案修改
120
- - ✅ 腳本執行
121
- - ✅ 明確的 TASK_ID 任務
122
-
123
- **可用 Skills**:
124
- - `do`: 重心在「做」,交付可用成果
125
- - `think`: 重心在「思考」,深度分析
126
- - `plan`: 重心在「計畫」,規劃步驟
127
-
128
- **範例**:
129
- ```bash
130
- # 修正按鈕顏色
131
- node .formation/tools/headless.js --skill=do --task="修正按鈕顏色為藍色"
132
-
133
- # 執行特定任務
134
- node .formation/tools/headless.js --skill=do --task=TASK_172
135
- ```
136
-
137
- ---
138
-
139
- ### 2. Solo(單人多視角)
140
-
141
- **1 Agent, N Perspectives** — 單人多視角自主切換。
142
-
143
- **機制**:
144
- - 派出一個 subagent,同時裝備多個專業視角
145
- - Agent 根據分析過程中的需要,**自主決定何時切換到哪個視角**
146
- - 不是輪流發言,是一個人用不同鏡頭看同一件事
147
-
148
- **成本**:低(單次 subagent 調用)
149
-
150
- **適用場景**:
151
- - ✅ 策略分析
152
- - ✅ 程式碼審查
153
- - ✅ 方案評估
154
- - ✅ 設計決策
155
- - ✅ 問題診斷
156
-
157
- **可用 Skills**:
158
-
159
- #### solo/strategy.yaml(策略分析 — 6 視角)
160
-
161
- **視角集**:
162
- 1. **產品策略師** - 用戶需求、功能優先級、產品方向、競品分析
163
- 2. **技術架構師** - 技術可行性、架構設計、技術選型、效能評估
164
- 3. **UX 策略師** - 用戶體驗、交互模式、易用性、設計原則
165
- 4. **商業分析師** - 價值評估、複雜度成本、技術債權衡、系統 ROI
166
- 5. **創新專家** - 新技術探索、突破性方案、趨勢分析
167
- 6. **風險分析師** - 風險識別、影響評估、緩解策略、應急計劃
168
-
169
- **核心原則**:
170
- - **獨立驗證**:不照抄輸入結論,自己讀源碼驗證
171
- - **深度優先**:每個視角要有具體證據(源碼行號、實際數據)
172
- - **不相關就跳過**:6 個視角不需要全部用到
173
-
174
- **範例流程**:
175
- ```
176
- 問題:評估快取方案
177
- → [技術架構師] 分析架構影響,發現成本問題
178
- → [產品策略師] 評估 ROI
179
- → [風險分析師] 識別安全疑慮
180
- → 綜合判斷,產出結論
181
- (視角切換由 agent 自主決定,非固定順序)
182
- ```
183
-
184
- #### solo/diagnosis.yaml(問題診斷 — 4 視角)
185
-
186
- **視角集**:
187
- 1. **表層診斷** - 錯誤訊息分析、日誌檢查
188
- 2. **深層分析** - 源碼追蹤、資料流檢查
189
- 3. **根因探索** - 為什麼會發生、系統性問題
190
- 4. **解決方案** - 修復方案、預防措施
191
-
192
- **範例**:
193
- ```bash
194
- # 策略分析(深度模式)
195
- node .formation/tools/headless.js \
196
- --formation=solo \
197
- --skill=strategy \
198
- --task="評估 Redis vs Memcached 快取方案" \
199
- --depth=deep
200
-
201
- # 問題診斷
202
- node .formation/tools/headless.js \
203
- --formation=solo \
204
- --skill=diagnosis \
205
- --task="分析登入失敗問題"
206
- ```
207
-
208
- ---
209
-
210
- ### 3. Squad(多人並行)
211
-
212
- **N Agents, 1 Task** — 多 Agent 並行協作。
213
-
214
- **機制**:
215
- - 同時派出多個 subagent,各自負責任務的不同部分
216
- - 並行執行後由 Lead 整合成果
217
- - **成員之間不能互相通訊**(那是 Legion 的事)
218
- - 各自獨立完成後由 Lead 整合
219
-
220
- **成本**:中等(隨 Agent 數量線性增長)
221
-
222
- **核心約束**:
223
- - ✅ 成員之間**不通訊**,只靠 `shared_context`(啟動前定義的共享約定)協調
224
- - ✅ 每個成員的 `scope_paths` 不得重疊(避免檔案衝突)
225
- - ❌ 如果子任務之間有依賴關係,不適合用 Squad
226
-
227
- **適用場景**:
228
- - ✅ 並行子任務開發
229
- - ✅ 跨模組批量修改
230
- - ✅ 多區域同步掃蕩
231
- - ❌ 子任務有順序依賴 → 用 Legion
232
-
233
- **可用 Skills**:
234
-
235
- #### squad/blitz.yaml(通用並行拆分)
236
-
237
- **機制**:一個大任務拆成 N 個獨立子任務,每個成員拿到不同的子任務描述和檔案範圍。
238
-
239
- **與 sweep 的差別**:
240
- - blitz: 「同一個目標拆成 N 件**不同的事**」
241
- - sweep: 「同一個規則套 N 個**不同的地方**」
242
-
243
- **拆分原則**:
244
- - 每個子任務必須能獨立完成,不依賴其他子任務的產出
245
- - 每個成員的 `scope_paths` 不得重疊
246
- - 如果拆出來的子任務之間有「A 做完才能做 B」的關係,不要用 Squad
247
-
248
- **範例**:
249
- ```
250
- 範例 1:並行拆分
251
- ├── [part_1] → 實作模組 A 的功能
252
- ├── [part_2] → 實作模組 B 的功能
253
- └── [part_3] → 實作模組 C 的功能
254
- → Lead 整合驗證,統一提交
255
- ```
256
-
257
- #### squad/sweep.yaml(同規則掃蕩)
258
-
259
- **機制**:同一個規則套用到 N 個不同範圍。
260
-
261
- **範例**:
262
- ```
263
- 範例 2:同規則掃蕩
264
- ├── [zone_1] → 重構 cmd_modules/ 下的模組
265
- ├── [zone_2] → 重構 components/ 下的元件
266
- └── [zone_3] → 重構 lib/ 下的工具函數
267
- → Lead 驗證一致性,統一提交
268
- ```
269
-
270
- **啟動方式**:
271
- ```bash
272
- # Blitz: 並行拆分
273
- node .formation/tools/headless.js \
274
- --formation=squad \
275
- --skill=blitz \
276
- --task=TASK_201 \
277
- --max_members=3
278
-
279
- # Sweep: 同規則掃蕩
280
- node .formation/tools/headless.js \
281
- --formation=squad \
282
- --skill=sweep \
283
- --task="重構所有 API 模組使用 async/await"
284
- ```
285
-
286
- ---
287
-
288
- ### 4. Legion(即時團隊)
289
-
290
- **Native Team** — 即時溝通的完整團隊。
291
-
292
- **機制**:
293
- - 使用 Claude Code 原生的 `TeamCreate` 機制,建立持久化團隊
294
- - 成員之間可互相通訊(`SendMessage`)、即時協調
295
- - Legion 的核心價值不是「更多人」,而是「**即時溝通**」
296
-
297
- **成本**:最高(持久化 context + 通訊開銷)
298
-
299
- **核心價值**(Squad 做不到的事):
300
- - ✅ 即時通知「我改了 X,你要更新」
301
- - ✅ 回饋循環(review → fix → re-review)
302
- - ✅ 順序依賴(A 做完 B 才開始)
303
- - ✅ 動態調整(做到一半改方向)
304
-
305
- **適用場景**:
306
- - ✅ 有順序依賴、回饋循環、或高度耦合的複雜任務
307
- - ✅ 需要跨成員協調介面契約
308
- - ✅ 需要多輪審查與修正
309
- - ❌ 子任務獨立無溝通需求 → 用 Squad 更便宜
310
-
311
- **可用 Skills**:
312
-
313
- #### legion/forge.yaml(鍛造 — 順序流水線)
314
-
315
- **拓撲**:`Designer → Implementer(s) → Reviewer`(帶回饋循環)
316
-
317
- **角色**:
318
- 1. **Designer**(1 人)- 設計藍圖(介面契約、架構設計、遷移計劃)
319
- 2. **Implementer**(1-3 人)- 按藍圖執行,遇到問題即時回報 Designer
320
- 3. **Reviewer**(1 人)- 驗收每個 Implementer 的產出,不通過則打回修正
321
-
322
- **階段**:
323
- ```
324
- Phase 1: Design → Designer 產出藍圖
325
- Phase 2: Build → Implementer(s) 按藍圖執行,Reviewer 同步就位
326
- Phase 3: Temper → 全面驗證、修正、淬煉品質
327
- Phase 4: Teardown → 收集成果、關閉團隊
328
- ```
329
-
330
- **溝通觸發**:
331
- - **藍圖發布**:Designer → All(Implementers + Reviewer)
332
- - **問題回報**:Implementer → Designer
333
- - **跨邊界通知**:Implementer → Implementer
334
- - **完成通知**:Implementer → Reviewer
335
- - **審查結果**:Reviewer → Implementer(通過 / 需修正)
336
- - **全部通過**:Reviewer → Team Lead
337
-
338
- **範例**:
339
- ```
340
- 需求:重構 API 模組架構
341
- → Designer 設計新架構,產出介面契約
342
- → Implementer_1 重構模組 A
343
- → Implementer_2 重構模組 B
344
- → Reviewer 逐一審查,發現問題打回修正
345
- → 全部通過,整合提交
346
- ```
347
-
348
- #### legion/hive.yaml(蜂巢 — 網狀協調)
349
-
350
- **拓撲**:全連接(所有成員彼此互聯)
351
-
352
- **機制**:
353
- - Worker A ←→ Worker B
354
- - 所有人即時互聯,任何變更即時同步
355
-
356
- **適用**:工作高度耦合、需要全員即時同步的場景
357
-
358
- **啟動方式**:
359
- ```bash
360
- # Forge: 順序流水線
361
- node .formation/tools/headless.js \
362
- --formation=legion \
363
- --skill=forge \
364
- --task=TASK_202
365
-
366
- # Hive: 網狀協調
367
- node .formation/tools/headless.js \
368
- --formation=legion \
369
- --skill=hive \
370
- --task="多模組聯動重構"
371
-
372
- # Dry run(只看 prompt,不啟動)
373
- node .formation/tools/headless.js \
374
- --formation=legion \
375
- --skill=forge \
376
- --task=TASK_202 \
377
- --dry-run
378
- ```
379
-
380
- ---
381
-
382
- ### 5. Legacy(自動化排程器)
383
-
384
- **Scheduler = Formation Lead** — 連續調度排程器。
385
-
386
- #### 核心理念
387
-
388
- **Scheduler 升級為 Formation Lead**:
389
- - 不再只是「呼叫 CLI 的腳本」,而是真正的 **Formation Lead**
390
- - 負責 **任務調度 + post-complete(archive + git)+ Lead-only 任務處理**
391
- - 所有任務透過 Formation Legacy Skill 調度(不使用 `/dev` 或 `/product-review` CLI)
392
- - subagent 禁止執行 git 操作(Rule 5),由 Lead 統一管理
393
-
394
- #### 機制
395
-
396
- **雙重任務類型**:
397
- 1. **一般任務**(role ≠ lead):派給 Formation Legacy Skill 的 subagent 執行
398
- 2. **Lead-only 任務**(role: lead):Scheduler 自己處理(如 archive、git branch/merge)
399
-
400
- **完整流程**:
401
- ```
402
- 1. Scheduler 掃描待辦任務(新舊系統合併)
403
- ↓
404
- 2a. 一般任務(role ≠ lead)
405
- → 調度 Formation Legacy Skill subagent
406
- → subagent 完成任務移動(task-api.js complete)
407
- → Scheduler 執行 post-complete(archive + git)
408
-
409
- 2b. Lead-only 任務(role: lead)
410
- → Scheduler 自己執行(post-complete.js)
411
- → Scheduler 標記任務完成(task-api.js complete)
412
- ↓
413
- 3. 失敗 → 重置為 pending,繼續迴圈
414
- ```
415
-
416
- **持續迴圈**:
417
- - 無待辦時進入 **idle check 模式**(預設 20s 輪詢)
418
- - 支援 **self-enhancement 模式**:無待辦時使用 review skill 分析專案
419
-
420
- **成本**:最低(自動化執行,無人工介入)
421
-
422
- **適用場景**:
423
- - ✅ 自動化連續開發
424
- - ✅ 夜間批量任務處理
425
- - ✅ Self-enhancement 迭代模式
426
- - ❌ 需要即時決策 → 用其他陣型
427
-
428
- #### 關鍵工具
429
-
430
- ##### post-complete.js(Archive + Git)
431
-
432
- **任務完成後的自動化處理**:
433
- 1. **Archive 檢查**(雙系統):
434
- - 新系統:`.collaboration/tasks/done/ → archived/`(超過 N 個)
435
- - 舊系統:`dev/pipeline/completed/ → dev/pipeline/archived/`
436
- - 預設保留 10 個最新任務,其餘移到 archived/
437
-
438
- 2. **Git 分支管理**:
439
- ```
440
- task/task_xxx → user_branch → (手動) main
441
- ```
442
- - 建立 task branch(如 `task/task_205`)
443
- - Stage + commit 所有變更(Co-Authored-By: Claude)
444
- - Merge 到用戶分支(Git user name,如 `{git_user}`)
445
- - 用戶手動 merge 到 main
446
-
447
- 3. **Windows 安全處理**:
448
- - `gitAddSafe()`:移除保留檔名(nul, con, prn, aux, com1-9, lpt1-9)
449
- - SQLite journal 重試機制(暫存檔可能在 git add 時消失)
450
-
451
- **使用方式**:
452
- ```bash
453
- # CLI 手動呼叫
454
- node .formation/tools/post-complete.js --task=TASK_205
455
-
456
- # Scheduler 自動呼叫(via postComplete() 函數)
457
- # (在 legacy-scheduler.js 的 runDevAgent 中)
458
- ```
459
-
460
- ##### HEADLESS_PREFIX(Rule 5:禁止 git 操作)
461
-
462
- **subagent 的行為規則**(prompt.js 注入):
463
- ```
464
- [HEADLESS MODE]
465
- 你已被 Formation Lead 指派任務。規則:
466
- 1. 直接執行,不要提問。需求已經確認過了。
467
- 2. 不要讀取 CLAUDE.md — 這是 Formation 系統。
468
- 3. 完成後輸出結構化結果。
469
- 4. 遇到無法執行的問題,輸出錯誤描述後結束。
470
- 5. 禁止執行任何 git 操作(commit、branch、merge、push)。Git 由 Formation Lead 統一管理。
471
- ```
472
-
473
- **Rule 5 的重要性**:
474
- - ❌ 如果 subagent 執行 git commit → 可能與 Scheduler 的 post-complete 衝突
475
- - ✅ subagent 只負責「完成任務內容」(檔案修改、程式碼實作)
476
- - ✅ Scheduler 統一處理 git(避免混亂的 commit 歷史)
477
-
478
- #### 配置
479
-
480
- **對應 `legacy/scheduler.yaml`**:
481
- ```yaml
482
- config:
483
- initial_delay_secs: 30 # 首次執行前等待
484
- interval_minutes: 20 # 執行間隔
485
- idle_check_secs: 20 # 無任務時輪詢間隔(新增!)
486
- early_finish_delay_secs: 30 # 提前完成時等待
487
- dev_timeout_minutes: 60 # 任務超時
488
- review_timeout_minutes: 30 # review skill 超時
489
- enable_self_enhancement: false # 啟用自我增強
490
-
491
- formation_dispatch:
492
- role_skill_map:
493
- developer: developer
494
- frontend: frontend
495
- backend: backend
496
- designer: designer
497
- qa: qa
498
- sre: sre
499
- pm: pm
500
- lead: lead # Lead-only 任務(Scheduler 自己處理)
501
- default_skill: developer
502
- review_skill: review
503
-
504
- post_complete:
505
- keep: 10 # archive 保留數量
506
- git_flow: "task/task_xxx → user_branch → (手動) main"
507
- ```
508
-
509
- **狀態機**:
510
- ```
511
- stopped → waiting → running_dev → paused → completed
512
- ↓ ↑
513
- running_review ──┘
514
- ↓
515
- idle / error
516
- ```
517
-
518
- **Idle Check 機制**(新增!):
519
- - 無待辦任務時,每 `idle_check_secs` 秒(預設 20s)重新檢查
520
- - 避免 self-enhancement 模式頻繁執行 review(cost 最佳化)
521
- - 新任務出現時立即執行(手動使用 task-api.js 建立)
522
-
523
- #### 啟動方式
524
-
525
- ```bash
526
- # 透過 headless.js(整合模式)
527
- node .formation/tools/headless.js \
528
- --formation=legacy \
529
- --skill=scheduler \
530
- --task="連續開發所有待辦任務"
531
-
532
- # 透過專用排程器(推薦)
533
- node .formation/tools/legacy-scheduler.js
534
-
535
- # 啟用 self-enhancement
536
- node .formation/tools/legacy-scheduler.js --self-enhancement
537
-
538
- # 調整配置
539
- node .formation/tools/legacy-scheduler.js \
540
- --initial-delay=0 \
541
- --interval=10 \
542
- --idle-check=30 \
543
- --dev-timeout=120
544
-
545
- # Dry run(只檢查任務狀態)
546
- node .formation/tools/legacy-scheduler.js --dry-run
547
- ```
548
-
549
- #### Lead-only 任務範例
550
-
551
- **任務定義**(`TASK_XXX.yaml`):
552
- ```yaml
553
- id: TASK_999
554
- title: "Archive 舊任務到 .memory/"
555
- role: lead # ← 關鍵:role: lead
556
- status: pending
557
- priority: P2
558
- dependencies: []
559
- scope_paths: [".collaboration/tasks/done/"]
560
- requirements:
561
- - "將 done/ 中超過 20 個的舊任務移到 archived/"
562
- acceptance_criteria:
563
- - "done/ 目錄保留最新 10 個任務"
564
- commit_message: "[TASK_999] Archive 舊任務"
565
- ```
566
-
567
- **執行流程**:
568
- ```javascript
569
- // legacy-scheduler.js 的 runDevAgent 函數
570
- if (task.agentType === 'lead') {
571
- // Lead-only 任務:Scheduler 自己處理
572
- postComplete({ taskId: task.taskId, message: task.commitMessage });
573
- execSync(`node .collaboration/core/task-api.js complete ${task.taskId}`);
574
- } else {
575
- // 一般任務:派給 subagent
576
- runWithFormation(task, skillName, config, logger);
577
- }
578
- ```
579
-
580
- ---
581
-
582
- ## 🛠️ 核心工具模組
583
-
584
- ### 1. headless.js(無頭啟動器)⭐
585
-
586
- **用途**:統一的無頭啟動器,支援所有陣型。
587
-
588
- **特性**:
589
- - Subagent 不問問題,直接執行
590
- - 支援 dry-run 模式(只看 prompt,不啟動)
591
- - 自動載入任務定義(支援三層 fallback)
592
- - 自動記錄日誌到 `.formation/logs/{formation}/`
593
-
594
- **使用方式**:
595
- ```bash
596
- # Unit
597
- node .formation/tools/headless.js --skill=do --task=TASK_172
598
-
599
- # Solo
600
- node .formation/tools/headless.js --formation=solo --skill=strategy --task=TASK_172
601
-
602
- # Squad
603
- node .formation/tools/headless.js --formation=squad --skill=blitz --task=TASK_173
604
-
605
- # Legion
606
- node .formation/tools/headless.js --formation=legion --skill=forge --task=TASK_174
607
-
608
- # Legacy
609
- node .formation/tools/headless.js --formation=legacy --skill=scheduler --task="持續開發"
610
-
611
- # Dry run(只看 prompt,不啟動)
612
- node .formation/tools/headless.js --formation=legion --skill=forge --task=TASK_174 --dry-run
613
- ```
614
-
615
- ### 2. dispatch.js(互動式 CLI)
616
-
617
- **用途**:互動式 CLI 入口,支援動態參數輸入。
618
-
619
- **使用方式**:
620
- ```bash
621
- node .formation/tools/dispatch.js --skill=do --task=TASK_172
622
- ```
623
-
624
- ### 3. loader.js(任務載入器)⭐
625
-
626
- **用途**:從三個來源載入任務定義(三層 fallback)。
627
-
628
- **Fallback 順序**:
629
- 1. **新系統** - `.collaboration/tasks/{status}/TASK_XXX.yaml`(優先,目錄即狀態)
630
- 2. **舊系統 YAML** - `dev/pipeline/completed/TASK_XXX_*.yaml`(降級,已完成任務)
631
- 3. **舊系統 JSON** - `dev/pipeline/TASK_QUEUE.json` 內的 tasks 陣列(最終降級,活躍任務)
632
-
633
- **載入邏輯**(v3.1 新版本):
634
- ```javascript
635
- const { loadTask } = require('./.formation/tools/loader');
636
-
637
- // 自動嘗試三層 fallback
638
- const taskData = loadTask('TASK_172');
639
-
640
- // 內部實作:
641
- function loadTask(taskId) {
642
- // Layer 1: 新系統 - .collaboration/tasks/
643
- const collaborationPath = findTaskInCollaboration(taskId);
644
- if (collaborationPath) {
645
- return parseYAML(fs.readFileSync(collaborationPath, 'utf8'));
646
- }
647
-
648
- // Layer 2: 舊系統 YAML - dev/pipeline/completed/
649
- const legacyYamlPath = findTaskInLegacy(taskId);
650
- if (legacyYamlPath) {
651
- return parseYAML(fs.readFileSync(legacyYamlPath, 'utf8'));
652
- }
653
-
654
- // Layer 3: 舊系統 JSON - dev/pipeline/TASK_QUEUE.json
655
- const taskQueue = JSON.parse(fs.readFileSync('dev/pipeline/TASK_QUEUE.json', 'utf8'));
656
- const task = taskQueue.tasks.find(t => t.id === taskId);
657
- if (task) {
658
- return task; // 已是 JS 物件,無需解析
659
- }
660
-
661
- throw new Error(`Task not found: ${taskId}`);
662
- }
663
- ```
664
-
665
- **遷移策略**:
666
- - **現階段**(2026-02-18):三層 fallback 同時運作,確保相容性
667
- - **未來階段 1**(2026 Q2 計劃):新系統功能補齊(路徑鎖定、依賴解析增強)
668
- - **未來階段 2**(2026 Q3 計劃):排程器遷移到新系統,舊系統標記為 Legacy
669
- - **未來階段 3**(2026 Q4 計劃):封存舊系統,移除 Layer 2/3 fallback
670
-
671
- **優點**:
672
- - ✅ 向後相容(可讀取歷史任務)
673
- - ✅ 零停機遷移(新舊並存)
674
- - ✅ 自動優先新系統(鼓勵使用新系統)
675
-
676
- ### 4. prompt.js(Prompt 組裝器)
677
-
678
- **用途**:根據陣型組裝對應的 Prompt。
679
-
680
- **支援陣型**:
681
- - `unit`: 單一 Agent prompt
682
- - `solo`: 單一 Agent + 多視角 prompt
683
- - `squad`: N 個 Agent prompts(並行)
684
- - `legion`: Team Lead prompt + Member prompts(團隊配置)
685
-
686
- **關鍵函數**:
687
- ```javascript
688
- const { buildPrompt } = require('./.formation/tools/prompt');
689
-
690
- // Unit / Solo
691
- const prompt = buildPrompt(skillDef, taskInput, taskData);
692
-
693
- // Squad(回傳陣列)
694
- const prompts = buildPrompt(skillDef, taskInput, taskData);
695
- // prompts = [
696
- // { memberId: 'part_1', prompt: '...', skill: 'do' },
697
- // { memberId: 'part_2', prompt: '...', skill: 'do' }
698
- // ]
699
-
700
- // Legion(回傳配置)
701
- const legionConfig = buildPrompt(skillDef, taskInput, taskData);
702
- // legionConfig = {
703
- // teamName: 'forge-team',
704
- // teamDesc: '...',
705
- // lead: { prompt: '...' },
706
- // members: [{ name: 'designer', prompt: '...', agentType: '...' }]
707
- // }
708
- ```
709
-
710
- ### 5. runner.js(進程管理器)
711
-
712
- **用途**:啟動 Claude 進程(單進程 + 並行)。
713
-
714
- **關鍵函數**:
715
- ```javascript
716
- const { runSingle, runParallel } = require('./.formation/tools/runner');
717
-
718
- // 單進程
719
- const result = await runSingle({ prompt, sessionId, output });
720
-
721
- // 並行進程
722
- const results = await runParallel([
723
- { prompt: prompt1, sessionId: 'part_1' },
724
- { prompt: prompt2, sessionId: 'part_2' }
725
- ]);
726
- ```
727
-
728
- ### 6. logger.js(日誌格式化)
729
-
730
- **用途**:統一的日誌格式化與寫入。
731
-
732
- **日誌路徑**:`.formation/logs/{formation}/{timestamp}_{skill}_{sessionId}.log`
733
-
734
- ### 7. utils.js(工具函數)
735
-
736
- **用途**:常用工具函數。
737
-
738
- **關鍵函數**:
739
- - `generateSessionId()`: 產生唯一 session ID
740
- - `parseCliArgs()`: 解析 CLI 參數
741
- - `findProjectRoot()`: 尋找專案根目錄
742
-
743
- ### 8. post-complete.js(Formation Lead 專用)⭐
744
-
745
- **用途**:任務完成後的自動化處理(Archive + Git)。
746
-
747
- **完整流程**:
748
- ```
749
- 任務完成(subagent 已執行 task-api.js complete)
750
- ↓
751
- ┌─────────────────────────────────────────┐
752
- │ Formation Lead 執行 post-complete.js │
753
- └─────────────────────────────────────────┘
754
- ↓
755
- ┌─ Step 1: Archive 檢查(雙系統)─────────┐
756
- │ 新系統:.collaboration/tasks/done/ │
757
- │ → 超過 keep 個 → 移到 archived/ │
758
- │ 舊系統:dev/pipeline/completed/ │
759
- │ → 超過 keep 個 → 移到 archived/ │
760
- │ (預設 keep=10) │
761
- └─────────────────────────────────────────┘
762
- ↓
763
- ┌─ Step 2: Git 分支管理 ──────────────────┐
764
- │ 1. 建立 task/task_xxx branch │
765
- │ 2. gitAddSafe() │
766
- │ - 移除 Windows 保留檔名 │
767
- │ - SQLite journal 重試機制 │
768
- │ 3. git commit(Co-Authored-By: Claude) │
769
- │ 4. 切換/建立用戶分支(git user name) │
770
- │ 5. git merge task/task_xxx → user_branch│
771
- │ 6. 留在 user_branch(用戶手動 merge main)│
772
- └─────────────────────────────────────────┘
773
- ↓
774
- 完成!
775
- ```
776
-
777
- **CLI 使用方式**:
778
- ```bash
779
- # 完整流程(archive + git)
780
- node .formation/tools/post-complete.js --task=TASK_205
781
-
782
- # 調整保留數量
783
- node .formation/tools/post-complete.js --task=TASK_205 --keep=15
784
-
785
- # 只做 archive(跳過 git)
786
- node .formation/tools/post-complete.js --skip-git
787
-
788
- # 只做 git(跳過 archive)
789
- node .formation/tools/post-complete.js --task=TASK_205 --skip-archive
790
-
791
- # Dry run(模擬執行)
792
- node .formation/tools/post-complete.js --task=TASK_205 --dry-run
793
-
794
- # 自訂 commit message
795
- node .formation/tools/post-complete.js --task=TASK_205 --message "[TASK_205] Custom message"
796
- ```
797
-
798
- **JavaScript API**:
799
- ```javascript
800
- const { postComplete } = require('./.formation/tools/post-complete');
801
-
802
- // 由 legacy-scheduler.js 自動呼叫
803
- postComplete({ taskId: 'TASK_205' });
804
-
805
- // 自訂參數
806
- postComplete({
807
- taskId: 'TASK_205',
808
- keep: 15,
809
- skipArchive: false,
810
- skipGit: false,
811
- message: '[TASK_205] Custom commit message'
812
- });
813
- ```
814
-
815
- **gitAddSafe() 處理**:
816
- 1. **Windows 保留檔名清理**:
817
- - 掃描專案根目錄,移除保留檔名(nul, con, prn, aux, com1-9, lpt1-9)
818
- - 這些檔案通常是意外產生的空檔,會導致 git add 失敗
819
-
820
- 2. **SQLite journal 重試機制**:
821
- - Chromadb 暫存檔(如 `chroma.sqlite3-journal`)可能在 git add 時消失
822
- - 最多重試 3 次,每次間隔 500ms
823
- - 防止 `fatal: pathspec 'xxx-journal' did not match any files`
824
-
825
- **輸出範例**:
826
- ```
827
- ⚔️ Post-Complete: TASK_205
828
- Keep: 10 | Archive: true | Git: true | DryRun: false
829
-
830
- ── Archive Check ──
831
- ✅ [新系統] done: 8/10 — no archive needed
832
- 📦 [舊系統] Archived 5 tasks (15 → 10):
833
- → TASK_134_api_refactor.yaml
834
- → TASK_135_ui_update.yaml
835
- ...
836
-
837
- ── Git Branch & Merge ──
838
- ✅ Committed on task/task_205
839
- ✅ Merged task/task_205 → {git_user}
840
- 📌 Now on branch: {git_user}
841
- 👉 Review changes, then: git checkout main && git merge {git_user}
842
-
843
- ── Summary ──
844
- Archive [新]: 0 archived, 8 kept
845
- Archive [舊]: 5 archived, 10 kept
846
- Git: branch=task/task_205 committed=true merged=true
847
- 👉 On branch: {git_user} — merge to main when ready
848
- ```
849
-
850
- ---
851
-
852
- ## 📊 選擇決策樹
853
-
854
- ```
855
- 問自己這些問題,找到最合適的陣型:
856
-
857
- 1. 任務簡單、目標明確?
858
- ✅ Yes → Unit
859
-
860
- 2. 需要多角度分析?
861
- ✅ Yes → Solo
862
-
863
- 3. 需要同時做多件事?
864
- ✅ Yes → 檢查是否有依賴
865
- - 無依賴 → Squad
866
- - 有依賴 → Legion (forge)
867
-
868
- 4. 有順序依賴或回饋循環?
869
- ✅ Yes → Legion (forge)
870
-
871
- 5. 工作高度耦合、需即時協調?
872
- ✅ Yes → Legion (hive)
873
-
874
- 6. 需要自動化連續執行?
875
- ✅ Yes → Legacy (scheduler)
876
- ```
877
-
878
- ### 選擇指南表格
879
-
880
- | 問自己 | 答案 | 陣型 |
881
- |--------|------|------|
882
- | 任務簡單、目標明確? | Yes | **Unit** |
883
- | 需要多角度分析? | Yes | **Solo** |
884
- | 需要同時做多件事? | Yes | **Squad** |
885
- | 有順序依賴或回饋循環? | Yes | **Legion** (forge) |
886
- | 工作高度耦合、需即時協調? | Yes | **Legion** (hive) |
887
- | 需要自動化連續執行? | Yes | **Legacy** (scheduler) |
888
-
889
- ---
890
-
891
- ## 🎓 最佳實踐
892
-
893
- ### 1. 陣型選擇原則
894
-
895
- **從小到大**:
896
- - 預設用 Unit,除非有明確理由升級
897
- - 需要多角度 → Solo
898
- - 需要並行 → Squad
899
- - 需要溝通 → Legion
900
-
901
- **避免過度設計**:
902
- - 不要為了用 Legion 而用 Legion
903
- - Squad 成員不要超過 4 個(成本和整合複雜度失控)
904
- - Legion 團隊規模:Designer(1) + Implementer(1-3) + Reviewer(1),最多 5 人
905
-
906
- ### 2. Squad 拆分品質
907
-
908
- **好的拆分**:
909
- ```yaml
910
- # ✅ 乾淨的拆分
911
- ├── part_1: scope_paths: ["src/api/auth/"]
912
- ├── part_2: scope_paths: ["src/api/user/"]
913
- └── part_3: scope_paths: ["src/api/admin/"]
914
- → 無依賴、無重疊、可並行
915
- ```
916
-
917
- **壞的拆分**:
918
- ```yaml
919
- # ❌ 有依賴關係
920
- ├── part_1: "設計 API 介面" # 必須先做
921
- └── part_2: "實作 API" # 依賴 part_1
922
- → 應該用 Legion (forge)
923
-
924
- # ❌ 路徑重疊
925
- ├── part_1: scope_paths: ["src/"]
926
- └── part_2: scope_paths: ["src/api/"] # 包含在 part_1 中
927
- → 會產生檔案衝突
928
- ```
929
-
930
- ### 3. Legion 溝通準則
931
-
932
- **只在必要時通訊**:
933
- - ✅ 藍圖有破壞性變更 → broadcast
934
- - ✅ 發現藍圖問題 → SendMessage 給 Designer
935
- - ✅ 跨邊界變更 → SendMessage 給其他 Implementer
936
- - ❌ 定期打招呼 → 浪費 token
937
-
938
- **Broadcast vs SendMessage**:
939
- | 場景 | 使用 |
940
- |------|------|
941
- | 藍圖破壞性變更 | `broadcast`(所有人都要知道) |
942
- | Team Lead 調整分工 | `broadcast` |
943
- | 回報問題給 Designer | `SendMessage` |
944
- | 跨邊界通知 | `SendMessage` |
945
- | 審查結果 | `SendMessage` |
946
-
947
- ### 4. Legacy 排程器配置
948
-
949
- **推薦配置**:
950
- ```yaml
951
- config:
952
- initial_delay_secs: 30 # 給系統初始化時間
953
- interval_minutes: 20 # 20 分鐘足夠完成大多數任務
954
- dev_timeout_minutes: 60 # 1 小時超時保護
955
- enable_self_enhancement: false # 預設關閉,手動啟用
956
- ```
957
-
958
- **Self-Enhancement 模式**:
959
- - 無待辦時自動執行 product review
960
- - 產生新任務後繼續執行
961
- - 設定 `max_enhancement_cycles` 防止無限迭代(推薦 3 次)
962
-
963
- ---
964
-
965
- ## 🔗 相關文檔
966
-
967
- | 文檔 | 路徑 | 說明 |
968
- |------|------|------|
969
- | **Formation 系統概述** | `.formation/README.md` | 陣型選擇指南 |
970
- | **任務載入器原理** | `.formation/tools/loader.js` | 三層 fallback 實作 |
971
- | **Prompt 組裝邏輯** | `.formation/tools/prompt.js` | 各陣型 prompt 生成 |
972
- | **新任務系統** | `.system/collaboration/README.md` | Collaboration 系統文檔 |
973
- | **舊任務系統** | `.system/pipeline/README.md` | Pipeline 系統文檔 |
974
- | **Lead Agent 流程** | `CLAUDE.md` | 12 步開發流程 |
975
-
976
- ---
977
-
978
- ## ❓ 常見問題
979
-
980
- ### Q1: Unit vs Solo 如何選擇?
981
-
982
- **A**: 看任務性質。
983
-
984
- - **Unit**:任務明確,直接執行即可(如「修正按鈕顏色」)
985
- - **Solo**:需要分析判斷,多角度審視(如「評估快取方案」)
986
-
987
- **判斷標準**:
988
- - 任務描述是「做 X」→ Unit
989
- - 任務描述是「分析 / 評估 / 選擇 X」→ Solo
990
-
991
- ### Q2: Squad vs Legion 如何選擇?
992
-
993
- **A**: 看子任務之間是否需要溝通。
994
-
995
- - **Squad**:子任務獨立,無溝通需求(省錢)
996
- - **Legion**:子任務有依賴、需要回饋循環(功能強)
997
-
998
- **判斷標準**:
999
- - 子任務之間能否用 `shared_context` 協調?
1000
- - ✅ Yes → Squad
1001
- - ❌ No(需要即時通訊)→ Legion
1002
-
1003
- ### Q3: Formation 與任務系統的關係?
1004
-
1005
- **A**: Formation 是 Agent 調度系統,支援兩套任務管理系統(新舊並存)。
1006
-
1007
- **任務系統對照**:
1008
-
1009
- | 特性 | 新系統(Collaboration) | 舊系統(Pipeline) | Formation 支援 |
1010
- |------|------------------------|-------------------|---------------|
1011
- | 路徑 | `.collaboration/tasks/` | `dev/pipeline/` | ✅ 三層 fallback |
1012
- | 格式 | 目錄 + YAML | JSON + YAML | ✅ 自動轉換 |
1013
- | 狀態 | 目錄即狀態 | JSON 索引 | ✅ 統一介面 |
1014
- | 適用 | 手動協作 | 排程器 | ✅ 兩者皆可 |
1015
- | 載入順序 | Layer 1(優先) | Layer 2/3(降級) | ✅ 向後相容 |
1016
-
1017
- **協作流程**:
1018
- ```
1019
- 1. 任務從任務系統載入(TASK_172)
1020
- ├─ 優先嘗試新系統(.collaboration/tasks/)
1021
- ├─ 降級舊系統 YAML(dev/pipeline/completed/)
1022
- └─ 最終降級舊系統 JSON(dev/pipeline/TASK_QUEUE.json)
1023
-
1024
- 2. Formation Lead 分析任務規模,選擇陣型
1025
- ├─ 簡單任務 → Unit
1026
- ├─ 多視角分析 → Solo
1027
- ├─ 並行子任務 → Squad
1028
- ├─ 順序依賴 → Legion
1029
- └─ 自動化連續執行 → Legacy
1030
-
1031
- 3. Formation 調度對應陣型的 Agent 執行
1032
-
1033
- 4. 完成後更新任務系統狀態
1034
- ├─ 新系統:移動 YAML 到 done/ 目錄
1035
- └─ 舊系統:更新 TASK_QUEUE.json 的 status 欄位
1036
- ```
1037
-
1038
- **未來計劃**:
1039
- - **2026 Q2**:新系統功能補齊(路徑鎖定、依賴解析)
1040
- - **2026 Q3**:Legacy 排程器遷移到新系統
1041
- - **2026 Q4**:移除舊系統 fallback,Formation 只讀取新系統
1042
-
1043
- ### Q4: 如何測試陣型配置?
1044
-
1045
- **A**: 使用 `--dry-run` 模式。
1046
-
1047
- ```bash
1048
- # 只看 prompt,不啟動
1049
- node .formation/tools/headless.js \
1050
- --formation=legion \
1051
- --skill=forge \
1052
- --task=TASK_174 \
1053
- --dry-run
1054
- ```
1055
-
1056
- 輸出會顯示:
1057
- - Lead prompt
1058
- - 各成員的 prompt
1059
- - 團隊配置(Legion)
1060
-
1061
- 確認 prompt 正確後再移除 `--dry-run` 執行。
1062
-
1063
- ### Q5: 如何除錯 Formation 執行失敗?
1064
-
1065
- **A**: 檢查日誌。
1066
-
1067
- ```bash
1068
- # 查看最新日誌
1069
- ls -lt .formation/logs/{formation}/ | head -5
1070
-
1071
- # 讀取日誌
1072
- cat .formation/logs/{formation}/{timestamp}_{skill}_{sessionId}.log
1073
- ```
1074
-
1075
- **常見問題**:
1076
- - **找不到任務**:檢查 `loader.js` 的三層 fallback 是否正確
1077
- - **Prompt 錯誤**:使用 `--dry-run` 檢查 prompt 內容
1078
- - **進程超時**:調整 `runner.js` 的超時配置
1079
-
1080
- ---
1081
-
1082
- ## 📈 未來規劃
1083
-
1084
- - [ ] **動態陣型切換**:執行中根據負載動態調整陣型
1085
- - [ ] **陣型效能分析**:記錄各陣型的成本與效率統計
1086
- - [ ] **自動陣型推薦**:根據任務特徵自動推薦最佳陣型
1087
- - [ ] **分散式 Squad**:支援跨機器並行執行
1088
-
1089
- ---
1090
-
1091
- **版本**: 1.0.0
1092
- **最後更新**: 2026-02-18
1093
- **維護者**: Developer Team
1094
- **相關任務**: TASK_192