kenaz 0.3.17 → 0.3.19

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 (316) 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/hooks/synapse-first-investigation.js +15 -0
  7. package/core/.claude/skills/architect_agent/SKILL.md +11 -92
  8. package/core/.claude/skills/assessment_agent/SKILL.md +0 -1
  9. package/core/.claude/skills/backend_engineer/SKILL.md +3 -6
  10. package/core/.claude/skills/code_reviewer/SKILL.md +1 -1
  11. package/core/.claude/skills/code_reviewer/patterns.yaml +1 -1
  12. package/core/.claude/skills/designer/SKILL.md +3 -6
  13. package/core/.claude/skills/dev_agent/SKILL.md +30 -491
  14. package/core/.claude/skills/developer/SKILL.md +3 -6
  15. package/core/.claude/skills/feature_agent/SKILL.md +3 -17
  16. package/core/.claude/skills/product_manager/SKILL.md +29 -1064
  17. package/core/.claude/skills/qa_engineer/SKILL.md +12 -17
  18. package/core/.claude/skills/spec_optimizer/SKILL.md +25 -275
  19. package/core/.claude/skills/sre_agent/SKILL.md +3 -6
  20. package/core/.collaboration/README.md +2 -3
  21. package/core/.collaboration/core/task-api.js +5 -138
  22. package/core/.collaboration/docs/CLI.md +0 -2
  23. package/core/.failure/INDEX.yaml +6 -40
  24. package/core/.failure/agent-execution/FAIL-013-search-cwd-drift-and-case-mismatch.yaml +1 -1
  25. package/core/.failure/tools/README.md +9 -227
  26. package/core/.formation/bifrost/exec.js +29 -4
  27. package/core/.formation/bifrost/launch.js +1 -6
  28. package/core/.formation/bifrost/launch.test.js +1 -1
  29. package/core/.formation/bifrost/provider-launch.js +18 -11
  30. package/core/.formation/bifrost/provider-launch.test.js +26 -2
  31. package/core/.formation/bifrost/shared/ansuz-boot-policy.js +3 -3
  32. package/core/.formation/bifrost/shared/ansuz-boot-policy.test.js +1 -2
  33. package/core/.formation/tools/__tests__/dispatch-cwd-project.test.js +42 -0
  34. package/core/.formation/tools/__tests__/m1-hmap-convid.test.js +1 -124
  35. package/core/.formation/tools/__tests__/subagent-executor.test.js +3 -2
  36. package/core/.formation/tools/dispatch.js +15 -2
  37. package/core/.formation/tools/loader.js +17 -140
  38. package/core/.formation/tools/post-complete.js +0 -31
  39. package/core/.rule/INDEX.yaml +0 -18
  40. package/core/.rule/general/agent-workflow.yaml +14 -164
  41. package/core/.rule/general/project-self-containment.yaml +8 -19
  42. package/core/.rule/general/rust-verify-target.yaml +6 -5
  43. package/core/.rule/general/synapse-code-intelligence.yaml +3 -3
  44. package/core/.specialist/Amelia/capability.yaml +12 -12
  45. package/core/.specialist/Amelia/workflow.yaml +2 -2
  46. package/core/.specialist/Ansuz/SYSTEM_DOC.md +20 -578
  47. package/core/.specialist/Ansuz/cognitive_principles.yaml +2 -3
  48. package/core/.specialist/Ansuz/concepts/boot_rules_summary.yaml +0 -1
  49. package/core/.specialist/Ansuz/concepts/deep_knowledge_pointers.yaml +1 -2
  50. package/core/.specialist/Ansuz/core.yaml +6 -108
  51. package/core/.specialist/Ansuz/guards/lesson_guards.yaml +0 -3
  52. package/core/.specialist/Ansuz/identity_contract.yaml +0 -1
  53. package/core/.specialist/Ansuz/knowledge.yaml +0 -4
  54. package/core/.specialist/Ansuz/rule.yaml +0 -1
  55. package/core/.specialist/Ansuz/tools/handoff-session-identity.test.js +6 -150
  56. package/core/.specialist/tests/runtime-discovery/README.md +1 -1
  57. package/core/.specialist/tools/__tests__/task-2374-usage-counter.test.js +1 -12
  58. package/core/.specialist/tools/prompt-files.test.js +1 -0
  59. package/core/.specialist/tools/task-bridge.js +1 -66
  60. package/core/.system/README.md +11 -552
  61. package/core/.system/collaboration/README.md +10 -174
  62. package/core/CLAUDE.md +1 -6
  63. package/core/KENAZ_CORE_VERSION +1 -1
  64. package/core/dev/scripts/js-yaml-resolution.test.js +1 -1
  65. package/core/dev/scripts/run-rust-tests.js +30 -46
  66. package/core/dev/scripts/run-rust-tests.test.js +17 -0
  67. package/core/dev/scripts/rust-verify-worktree.js +4 -4
  68. package/core/dev/scripts/verify-target-dir.js +6 -6
  69. package/core/plugins/kenaz/INVENTORY.md +8 -8
  70. package/core/plugins/kenaz/commands/architect.md +1 -2
  71. package/core/plugins/kenaz/commands/spec.md +1 -1
  72. package/core/plugins/kenaz/commands//347/224/242/345/223/201.md +1 -1
  73. package/core/plugins/kenaz/guidance.md +1 -1
  74. package/core/plugins/kenaz/scripts/sync.js +1 -1
  75. package/core/plugins/kenaz/scripts/ygg.js +6 -0
  76. package/core/plugins/kenaz/skills/architect_agent/SKILL.md +11 -92
  77. package/core/plugins/kenaz/skills/assessment_agent/SKILL.md +0 -1
  78. package/core/plugins/kenaz/skills/backend_engineer/SKILL.md +3 -6
  79. package/core/plugins/kenaz/skills/code_reviewer/SKILL.md +1 -1
  80. package/core/plugins/kenaz/skills/code_reviewer/patterns.yaml +1 -1
  81. package/core/plugins/kenaz/skills/designer/SKILL.md +3 -6
  82. package/core/plugins/kenaz/skills/dev_agent/SKILL.md +30 -491
  83. package/core/plugins/kenaz/skills/developer/SKILL.md +3 -6
  84. package/core/plugins/kenaz/skills/feature_agent/SKILL.md +3 -17
  85. package/core/plugins/kenaz/skills/product_manager/SKILL.md +29 -1064
  86. package/core/plugins/kenaz/skills/qa_engineer/SKILL.md +12 -17
  87. package/core/plugins/kenaz/skills/spec_optimizer/SKILL.md +25 -275
  88. package/core/plugins/kenaz/skills/sre_agent/SKILL.md +3 -6
  89. package/package.json +6 -6
  90. package/core/.claude/commands/archive.md +0 -24
  91. package/core/.claude/commands/init.md +0 -112
  92. package/core/.claude/commands/legacy_dev.md +0 -18
  93. package/core/.claude/commands/product-review.md +0 -131
  94. package/core/.claude/commands/strategy.md +0 -141
  95. package/core/.claude/commands/sunny.md +0 -1
  96. package/core/.claude/commands//347/224/242/345/223/201/346/252/242/350/246/226.md +0 -129
  97. package/core/.claude/commands//351/200/262/345/272/246.md +0 -15
  98. package/core/.claude/hooks/__tests__/substrate.test.js +0 -122
  99. package/core/.claude/hooks/_substrate-paths.js +0 -95
  100. package/core/.claude/hooks/context-check.js +0 -51
  101. package/core/.claude/hooks/fatigue-check.js +0 -52
  102. package/core/.claude/hooks/handoff-snapshot-on-commit.js +0 -154
  103. package/core/.claude/hooks/handoff-snapshot-on-question.js +0 -158
  104. package/core/.claude/hooks/handoff-staleness.js +0 -197
  105. package/core/.claude/hooks/jev-thalamus-context.js +0 -17
  106. package/core/.claude/hooks/jev-thalamus-context.test.js +0 -41
  107. package/core/.claude/hooks/lease-release.js +0 -119
  108. package/core/.claude/hooks/lease-touch.js +0 -96
  109. package/core/.claude/hooks/reflex-feedback.js +0 -5
  110. package/core/.claude/hooks/session-init.ps1 +0 -49
  111. package/core/.claude/hooks/sound-event.js +0 -70
  112. package/core/.claude/hooks/sound-event.sh +0 -37
  113. package/core/.claude/hooks/stream-delta.js +0 -169
  114. package/core/.claude/no-hooks.settings.json +0 -3
  115. package/core/.claude/skills/legacy_dev/SKILL.md +0 -202
  116. package/core/.claude/skills/sunny/SKILL.md +0 -74
  117. package/core/.collaboration/cli/commands/assign.js +0 -39
  118. package/core/.collaboration/cli/commands/claim.js +0 -33
  119. package/core/.collaboration/cli/commands/complete.js +0 -44
  120. package/core/.collaboration/cli/commands/create.js +0 -110
  121. package/core/.collaboration/cli/commands/get.js +0 -83
  122. package/core/.collaboration/cli/commands/index.js +0 -52
  123. package/core/.collaboration/cli/commands/list.js +0 -51
  124. package/core/.collaboration/cli/commands/lock.js +0 -45
  125. package/core/.collaboration/cli/commands/rebuild.js +0 -39
  126. package/core/.collaboration/cli/commands/search.js +0 -61
  127. package/core/.collaboration/cli/commands/stats.js +0 -61
  128. package/core/.collaboration/cli/commands/transfer.js +0 -41
  129. package/core/.collaboration/cli/commands/unlock.js +0 -48
  130. package/core/.collaboration/cli/formatters/help-formatter.js +0 -70
  131. package/core/.collaboration/cli/formatters/index.js +0 -7
  132. package/core/.collaboration/cli/task-cli.js +0 -46
  133. package/core/.collaboration/cli/utils/arg-parser.js +0 -74
  134. package/core/.collaboration/cli/utils/git-user.js +0 -25
  135. package/core/.collaboration/cli/utils/index.js +0 -9
  136. package/core/.collaboration/cli/utils/output.js +0 -10
  137. package/core/.collaboration/config/default.yaml +0 -189
  138. package/core/.collaboration/core/conflict-resolver.js +0 -461
  139. package/core/.collaboration/core/conflict-resolver.test.js +0 -389
  140. package/core/.collaboration/core/migrate-legacy.js +0 -260
  141. package/core/.collaboration/docs/API.md +0 -787
  142. package/core/.collaboration/docs/ARCHITECTURE.md +0 -596
  143. package/core/.collaboration/docs/FAQ.md +0 -695
  144. package/core/.collaboration/docs/MIGRATION.md +0 -804
  145. package/core/.collaboration/docs/examples/README.md +0 -320
  146. package/core/.collaboration/docs/examples/advanced-queries.js +0 -261
  147. package/core/.collaboration/docs/examples/basic-usage.js +0 -184
  148. package/core/.collaboration/docs/examples/team-workflow.js +0 -352
  149. package/core/.failure/agent-execution/FAIL-001-agent-no-output.yaml +0 -391
  150. package/core/.failure/agent-execution/FAIL-007-pm-lead-wrong-team-invocation.yaml +0 -0
  151. package/core/.failure/agent-execution/FAIL-010-phase0-poem-format-skipped.yaml +0 -28
  152. package/core/.failure/agent-execution/FAIL-010-skipping-cognitive-checkpoint-after-verification.yaml +0 -59
  153. package/core/.failure/agent-execution/FAIL-012-grep-shortcut-during-investigation.yaml +0 -85
  154. package/core/.failure/architecture/FAIL-006-python-version-compatibility.yaml +0 -445
  155. package/core/.failure/pipeline/FAIL-003-queue-pollution.yaml +0 -335
  156. package/core/.failure/pipeline/README.md +0 -95
  157. package/core/.failure/retired/FAIL-009-skipping-synapse-pulse-before-code-change.yaml +0 -49
  158. package/core/.failure/tools/USAGE_GUIDE.md +0 -323
  159. package/core/.failure/tools/check_failures.ps1 +0 -387
  160. package/core/.failure/tools/log_failure.ps1 +0 -474
  161. package/core/.formation/.episode-input.json +0 -10
  162. package/core/.formation/.merge-lock +0 -1
  163. package/core/.formation/lead.yaml +0 -118
  164. package/core/.formation/legacy.bak/designer.yaml +0 -57
  165. package/core/.formation/legacy.bak/pm.yaml +0 -57
  166. package/core/.formation/legacy.bak/qa.yaml +0 -57
  167. package/core/.formation/legacy.bak/review.yaml +0 -62
  168. package/core/.formation/legacy.bak/scheduler.yaml +0 -129
  169. package/core/.formation/legacy.bak/sre.yaml +0 -57
  170. package/core/.formation/role-map.yaml +0 -274
  171. package/core/.formation/roles/_shared/modules/code_review.yaml +0 -98
  172. package/core/.formation/roles/_shared/modules/security.yaml +0 -103
  173. package/core/.formation/roles/_shared/modules/testing.yaml +0 -14
  174. package/core/.formation/roles/backend/role.yaml +0 -93
  175. package/core/.formation/roles/code_reviewer/role.yaml +0 -102
  176. package/core/.formation/roles/database_optimizer/role.yaml +0 -107
  177. package/core/.formation/roles/designer/role.yaml +0 -66
  178. package/core/.formation/roles/developer/role.yaml +0 -75
  179. package/core/.formation/roles/frontend/role.yaml +0 -134
  180. package/core/.formation/roles/incident_response/role.yaml +0 -89
  181. package/core/.formation/roles/qa/role.yaml +0 -89
  182. package/core/.formation/roles/security/role.yaml +0 -87
  183. package/core/.formation/roles/sre/role.yaml +0 -66
  184. package/core/.formation/skills/coordinator.yaml +0 -52
  185. package/core/.formation/solo/diagnosis.yaml +0 -78
  186. package/core/.formation/solo/strategy.yaml +0 -121
  187. package/core/.formation/tests/hello.txt +0 -2
  188. package/core/.formation/tools/coordinator.js +0 -350
  189. package/core/.formation/tools/jev-correction.js +0 -214
  190. package/core/.formation/tools/jev-correction.test.js +0 -178
  191. package/core/.formation/tools/log-reader.js +0 -232
  192. package/core/.formation/tools/revert-daemon-state.js +0 -162
  193. package/core/.formation/tools/test-drift.js +0 -148
  194. package/core/.formation/unit/heimdall.yaml +0 -96
  195. package/core/.formation/unit/plan.yaml +0 -67
  196. package/core/.formation/unit/think.yaml +0 -58
  197. package/core/.kenaz/MUNINN_SNAPSHOT9_EPISODE.json +0 -32
  198. package/core/.kenaz/MUNINN_SNAPSHOT9_RUNE.json +0 -23
  199. package/core/.kenaz/MUNINN_SNAPSHOT9_SUMMARY.md +0 -89
  200. package/core/.kenaz/ash_TASK_1428-20260507.json +0 -14
  201. package/core/.kenaz/muninn_episode_write.ps1 +0 -17
  202. package/core/.kenaz/muninn_snapshot11_rune_candidates.md +0 -63
  203. package/core/.kenaz/muninn_snapshot1_rune_candidates.md +0 -49
  204. package/core/.kenaz/runes_TASK_1428.json +0 -57
  205. package/core/.kenaz/tmp_heimdall_proposal_8d3e392.json +0 -13
  206. package/core/.kenaz/tmp_props.json +0 -1
  207. package/core/.kenaz/tmp_sounddrop_t1_prompt.txt +0 -371
  208. package/core/.rule/MECHANIZED.md +0 -61
  209. package/core/.rule/general/cortex-memory-recall.yaml +0 -446
  210. package/core/.rule/general/pipeline.yaml +0 -246
  211. package/core/.rule/general/sunny-access-control.yaml +0 -60
  212. package/core/.rule/general/system-invariants.yaml +0 -231
  213. package/core/.rule/pipeline/PPL-002-completed-task-archival.yaml +0 -528
  214. package/core/.rule/pipeline/auto-update.yaml +0 -282
  215. package/core/.rule/pipeline/task-execution.yaml +0 -365
  216. package/core/.specialist/Ansuz/concepts/phase_protocol.yaml +0 -65
  217. package/core/.specialist/Ansuz/experiments/boot_ablation_replay.js +0 -197
  218. package/core/.specialist/Ansuz/tools/bootstrap-anchors.js +0 -289
  219. package/core/.specialist/Ansuz/workflow.yaml +0 -1225
  220. package/core/.specialist/experiments/rg_benchmark.js +0 -523
  221. package/core/.specialist/experiments/rg_benchmark_results.json +0 -27
  222. package/core/.specialist/tools/jev-optional-context.js +0 -107
  223. package/core/.specialist/tools/jev-optional-context.test.js +0 -152
  224. package/core/.specialist/tools/memory-action-log.js +0 -839
  225. package/core/.specialist/tools/phase-gate.js +0 -3534
  226. package/core/.specialist/tools/phase-gate.test.js +0 -85
  227. package/core/.specialist/tools/precompute-runner.js +0 -444
  228. package/core/.specialist/tools/rule-engine.js +0 -621
  229. package/core/.specialist/tools/task-bridge-jev.test.js +0 -170
  230. package/core/.synapse/memory-shared.json.sync +0 -1
  231. package/core/.system/agent-skills/README.md +0 -724
  232. package/core/.system/cli-tools/README.md +0 -724
  233. package/core/.system/cortex/MODULES.md +0 -1046
  234. package/core/.system/dashboard/FRONTEND.md +0 -812
  235. package/core/.system/dashboard/README.md +0 -737
  236. package/core/.system/failure/README.md +0 -723
  237. package/core/.system/formation/LEGACY_SKILLS.md +0 -974
  238. package/core/.system/formation/POST_COMPLETE.md +0 -602
  239. package/core/.system/formation/README.md +0 -1094
  240. package/core/.system/formation/TOOLS_REFERENCE.md +0 -1145
  241. package/core/.system/kenaz/README.md +0 -787
  242. package/core/.system/memory/README.md +0 -719
  243. package/core/.system/pipeline/README.md +0 -712
  244. package/core/.system/rule/README.md +0 -794
  245. package/core/.system/sunny/README.md +0 -476
  246. package/core/.system/sunny/RULES.json +0 -89
  247. package/core/.system/sunny/knowledge/INDEX.md +0 -37
  248. package/core/.system/sunny/knowledge/agent-teams-api.md +0 -0
  249. package/core/.system/sunny/knowledge/ansuz-specialist.md +0 -500
  250. package/core/.system/sunny/knowledge/claude-cli-spawn.md +0 -177
  251. package/core/.system/sunny/knowledge/collaboration-api.md +0 -925
  252. package/core/.system/sunny/teammates/README.md +0 -107
  253. package/core/.system/sunny/teammates/how_to_use.yaml +0 -101
  254. package/core/.system/sunny/teammates/tools/headless/launcher.js +0 -318
  255. package/core/.system/sunny/teammates/tools/powershell/launcher.js +0 -241
  256. package/core/.system/sunny/teammates/tools/powershell/start.bat +0 -50
  257. package/core/.system/sunny/teammates/tools/utils/env.js +0 -96
  258. package/core/.system/sunny/teammates/tools/utils/format-output.js +0 -329
  259. package/core/.system/sunny/tools.json +0 -101
  260. package/core/dev/scripts/cleanup-queue.js +0 -184
  261. package/core/dev/scripts/cleanup_queue.js +0 -86
  262. package/core/dev/scripts/legacy/README.md +0 -39
  263. package/core/dev/scripts/legacy/dev_agent_scheduler.ps1.bak +0 -536
  264. package/core/dev/scripts/legacy/multi_agent_scheduler.ps1.bak +0 -1978
  265. package/core/dev/scripts/matrix/CLI_README.md +0 -214
  266. package/core/dev/scripts/matrix/README.md +0 -310
  267. package/core/dev/scripts/matrix/package-lock.json +0 -4266
  268. package/core/dev/scripts/matrix/package.json +0 -55
  269. package/core/dev/scripts/matrix/src/abbreviations.ts +0 -295
  270. package/core/dev/scripts/matrix/src/cli/commands/convert.ts +0 -211
  271. package/core/dev/scripts/matrix/src/cli/commands/create.ts +0 -95
  272. package/core/dev/scripts/matrix/src/cli/commands/delete.ts +0 -102
  273. package/core/dev/scripts/matrix/src/cli/commands/list-tags.ts.wip +0 -140
  274. package/core/dev/scripts/matrix/src/cli/commands/manage-tags.ts.wip +0 -173
  275. package/core/dev/scripts/matrix/src/cli/commands/query.ts +0 -261
  276. package/core/dev/scripts/matrix/src/cli/commands/read.ts +0 -77
  277. package/core/dev/scripts/matrix/src/cli/commands/stats.ts.wip +0 -168
  278. package/core/dev/scripts/matrix/src/cli/commands/tokens.ts.wip +0 -126
  279. package/core/dev/scripts/matrix/src/cli/commands/update.ts +0 -147
  280. package/core/dev/scripts/matrix/src/cli/commands/validate.ts +0 -275
  281. package/core/dev/scripts/matrix/src/cli/index.ts +0 -350
  282. package/core/dev/scripts/matrix/src/cli/utils/file-handler.ts +0 -72
  283. package/core/dev/scripts/matrix/src/cli/utils/logger.ts +0 -65
  284. package/core/dev/scripts/matrix/src/index.ts +0 -62
  285. package/core/dev/scripts/matrix/src/indexer/tag-indexer.ts +0 -165
  286. package/core/dev/scripts/matrix/src/parser.ts +0 -281
  287. package/core/dev/scripts/matrix/src/serializer.ts +0 -151
  288. package/core/dev/scripts/matrix/src/validator.ts +0 -301
  289. package/core/dev/scripts/matrix/tests/abbreviations.test.ts +0 -122
  290. package/core/dev/scripts/matrix/tests/cli.test.ts +0 -177
  291. package/core/dev/scripts/matrix/tests/convert.test.ts +0 -143
  292. package/core/dev/scripts/matrix/tests/parser.test.ts +0 -203
  293. package/core/dev/scripts/matrix/tests/query.test.ts +0 -85
  294. package/core/dev/scripts/matrix/tests/serializer.test.ts +0 -197
  295. package/core/dev/scripts/matrix/tests/validate.test.ts +0 -141
  296. package/core/dev/scripts/matrix/tests/validator.test.ts +0 -167
  297. package/core/dev/scripts/matrix/tsconfig.json +0 -20
  298. package/core/dev/scripts/matrix/types/index.d.ts +0 -111
  299. package/core/dev/scripts/matrix/types/index.d.ts.map +0 -1
  300. package/core/dev/scripts/matrix/types/index.js +0 -8
  301. package/core/dev/scripts/matrix/types/index.js.map +0 -1
  302. package/core/dev/scripts/matrix/types/index.ts +0 -124
  303. package/core/dev/scripts/memory-usage-report.js +0 -152
  304. package/core/dev/scripts/probe/ansuz-scaffold-ablation.js +0 -579
  305. package/core/dev/scripts/probe/ansuz-scaffold-ablation.test.js +0 -244
  306. package/core/dev/scripts/probe/hook-latency-probe.js +0 -315
  307. package/core/dev/scripts/probe/hook-latency-probe.test.js +0 -105
  308. package/core/dev/scripts/probe/prediction-signal-auc.js +0 -483
  309. package/core/dev/scripts/probe/prediction-signal-auc.test.js +0 -200
  310. package/core/dev/scripts/test-pty-ws-tunnel.js +0 -229
  311. package/core/dev/scripts/validate_pipeline.js +0 -197
  312. package/core/dev/spikes/task2145-evidence-20261004/backend-log-excerpt.txt +0 -56
  313. package/core/dev/spikes/task2145-evidence-20261004/graph.shadow +0 -0
  314. package/core/dev/spikes/task2145-evidence-20261004/graph.wal +0 -0
  315. package/core/dev/spikes/task2145-evidence-20261004/graph_corrupt_suspect.marker +0 -1
  316. package/core/plugins/kenaz/commands/strategy.md +0 -141
@@ -1,329 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * format-output.js
4
- * 將 Claude JSON 日誌轉換為人類可讀的 log 格式
5
- *
6
- * Usage (CLI):
7
- * claude ... | node format-output.js <output.log>
8
- * node format-output.js <input.jsonl> <output.log>
9
- *
10
- * Usage (Module):
11
- * const { formatJsonLines } = require('./format-output');
12
- * const formatted = formatJsonLines(jsonLines, { sessionId: 'xxx' });
13
- */
14
-
15
- const fs = require('fs');
16
-
17
- // CLI 入口 - 只在直接執行時運行
18
- if (require.main === module) {
19
- const args = process.argv.slice(2);
20
- let inputFile = null;
21
- let outputFile = null;
22
-
23
- if (args.length === 1) {
24
- // stdin mode: node format-output.js output.log
25
- outputFile = args[0];
26
- } else if (args.length === 2) {
27
- // file mode: node format-output.js input.jsonl output.log
28
- inputFile = args[0];
29
- outputFile = args[1];
30
- } else {
31
- console.error('Usage: claude ... | node format-output.js <output.log>');
32
- console.error(' node format-output.js <input.jsonl> <output.log>');
33
- process.exit(1);
34
- }
35
-
36
- // 讀取輸入
37
- if (inputFile) {
38
- const content = fs.readFileSync(inputFile, 'utf-8');
39
- processContent(content, outputFile);
40
- } else {
41
- // 從 stdin 讀取
42
- const chunks = [];
43
- process.stdin.setEncoding('utf-8');
44
- process.stdin.on('data', chunk => chunks.push(chunk));
45
- process.stdin.on('end', () => {
46
- const content = chunks.join('');
47
- processContent(content, outputFile);
48
- });
49
- }
50
- }
51
-
52
- function processContent(content, outputFile) {
53
- const lines = content.split('\n').filter(l => l.trim());
54
-
55
- const output = [];
56
-
57
- output.push('================================================================================');
58
- output.push('SUNNY TEAM EXECUTION LOG');
59
- output.push('================================================================================');
60
- output.push('');
61
-
62
- for (const line of lines) {
63
- try {
64
- const entry = JSON.parse(line);
65
- const logLine = formatEntry(entry);
66
- if (logLine) {
67
- output.push(logLine);
68
- }
69
- } catch (e) {
70
- // 非 JSON 行,忽略
71
- }
72
- }
73
-
74
- fs.writeFileSync(outputFile, output.join('\n'), 'utf-8');
75
- console.log(`Formatted: ${outputFile}`);
76
- }
77
-
78
- // 追蹤已創建的隊員
79
- const spawnedTeammates = new Map(); // name -> team_name
80
-
81
- function formatEntry(entry) {
82
- const { type, subtype } = entry;
83
- const ts = new Date().toISOString().slice(11, 19); // HH:MM:SS
84
-
85
- switch (type) {
86
- case 'system':
87
- if (subtype === 'init') {
88
- sessionId = entry.session_id?.slice(0, 8) || '';
89
- return `[${ts}][SYSTEM][INIT] model=${entry.model} cwd=${entry.cwd}`;
90
- }
91
- if (subtype === 'hook_started') {
92
- return `[${ts}][SYSTEM][HOOK] ${entry.hook_name} started`;
93
- }
94
- if (subtype === 'hook_response') {
95
- const status = entry.outcome === 'error' ? 'FAILED' : 'OK';
96
- return `[${ts}][SYSTEM][HOOK] ${entry.hook_name} ${status}`;
97
- }
98
- break;
99
-
100
- case 'assistant':
101
- if (entry.message?.content) {
102
- const results = [];
103
- for (const block of entry.message.content) {
104
- if (block.type === 'text' && block.text) {
105
- // 過濾 <tool_use> 標籤,並轉換 markdown 為純文字
106
- let text = block.text
107
- .replace(/<tool_use>[\s\S]*?<\/tool_use>/g, '')
108
- .replace(/^#{1,6}\s+/gm, '') // 移除 headers
109
- .replace(/\*\*([^*]+)\*\*/g, '$1') // 移除 bold
110
- .replace(/\*([^*]+)\*/g, '$1') // 移除 italic
111
- .replace(/`([^`]+)`/g, '$1') // 移除 inline code
112
- .replace(/---+/g, '') // 移除分隔線
113
- .trim();
114
- if (text) {
115
- // 多行文字分開顯示
116
- const textLines = text.split('\n').filter(l => l.trim());
117
- for (const tl of textLines) {
118
- results.push(`[${ts}][Team Lead] ${tl.trim()}`);
119
- }
120
- }
121
- } else if (block.type === 'tool_use') {
122
- const tool = block.name;
123
- const input = block.input || {};
124
-
125
- if (tool === 'TeamCreate') {
126
- const teamName = input.team_name || '';
127
- results.push(`[${ts}][Team Lead][TeamCreate] team="${teamName}"`);
128
- } else if (tool === 'Task') {
129
- const name = input.name || input.description?.slice(0, 30) || 'unnamed';
130
- const agentType = input.subagent_type || 'general';
131
- results.push(`[${ts}][Team Lead][Task] spawn="${name}" type=${agentType}`);
132
- } else if (tool === 'SendMessage') {
133
- const msgType = input.type || 'message';
134
- const recipient = input.recipient || '';
135
- const content = input.content || input.message || '';
136
- results.push(`[${ts}][Team Lead][SendMessage] to=${recipient} type=${msgType}`);
137
- if (content) {
138
- // 完整訊息內容,每行加前綴
139
- const msgLines = content.split('\n');
140
- for (const ml of msgLines) {
141
- results.push(` | ${ml}`);
142
- }
143
- }
144
- } else if (tool === 'TeamDelete') {
145
- results.push(`[${ts}][Team Lead][TeamDelete]`);
146
- } else if (tool === 'Bash') {
147
- const cmd = input.command || '';
148
- const desc = input.description || '';
149
- if (desc) {
150
- results.push(`[${ts}][Team Lead][Bash] ${desc}`);
151
- } else if (cmd) {
152
- // 顯示 command 前 80 字元
153
- const shortCmd = cmd.length > 80 ? cmd.slice(0, 80) + '...' : cmd;
154
- results.push(`[${ts}][Team Lead][Bash] $ ${shortCmd}`);
155
- } else {
156
- results.push(`[${ts}][Team Lead][Bash]`);
157
- }
158
- } else if (tool === 'Read') {
159
- const filePath = input.file_path || '';
160
- results.push(`[${ts}][Team Lead][Read] ${filePath}`);
161
- } else if (tool === 'Write') {
162
- const filePath = input.file_path || '';
163
- results.push(`[${ts}][Team Lead][Write] ${filePath}`);
164
- } else if (tool === 'Edit') {
165
- const filePath = input.file_path || '';
166
- results.push(`[${ts}][Team Lead][Edit] ${filePath}`);
167
- } else if (tool === 'Glob') {
168
- const pattern = input.pattern || '';
169
- results.push(`[${ts}][Team Lead][Glob] ${pattern}`);
170
- } else if (tool === 'Grep') {
171
- const pattern = input.pattern || '';
172
- results.push(`[${ts}][Team Lead][Grep] ${pattern}`);
173
- } else {
174
- results.push(`[${ts}][Team Lead][${tool}]`);
175
- }
176
- }
177
- }
178
- return results.join('\n');
179
- }
180
- break;
181
-
182
- case 'user':
183
- const userResults = [];
184
-
185
- // 處理 tool_use_result
186
- if (entry.tool_use_result) {
187
- const result = entry.tool_use_result;
188
- if (result.status === 'teammate_spawned') {
189
- // 記錄隊員
190
- spawnedTeammates.set(result.name, result.team_name);
191
- userResults.push(`[${ts}][SYSTEM][Spawned] Teammate "${result.name}" model=${result.model}`);
192
- } else if (result.team_name && result.success !== undefined) {
193
- const status = result.success ? 'OK' : 'FAILED';
194
- userResults.push(`[${ts}][SYSTEM][TeamDelete] ${status}: ${result.team_name}`);
195
- } else if (result.success !== undefined) {
196
- userResults.push(`[${ts}][SYSTEM][Result] ${result.success ? 'OK' : 'FAILED'}: ${result.message || ''}`);
197
- }
198
- }
199
-
200
- // 處理收到的訊息(來自隊員的 SendMessage)
201
- if (entry.message?.content) {
202
- for (const block of entry.message.content) {
203
- if (block.type === 'text' && block.text) {
204
- const text = block.text;
205
- // 嘗試從訊息中提取隊員名稱
206
- let teammateName = 'Unknown';
207
- const nameMatch = text.match(/(?:from|From)\s+["']?(\w+[-\w]*)["']?/i);
208
- if (nameMatch) {
209
- teammateName = nameMatch[1];
210
- }
211
- // 檢查是否是來自隊員的訊息
212
- if (text.includes('Message from') || text.includes('teammate') || text.includes('Teammate')) {
213
- userResults.push(`[${ts}][Teammate ${teammateName}]`);
214
- const msgLines = text.split('\n').filter(l => l.trim());
215
- for (const ml of msgLines) {
216
- userResults.push(` | ${ml}`);
217
- }
218
- }
219
- }
220
- }
221
- }
222
-
223
- return userResults.length > 0 ? userResults.join('\n') : null;
224
-
225
- case 'result':
226
- const lines = [];
227
- lines.push('');
228
- lines.push('--------------------------------------------------------------------------------');
229
- lines.push(`[${ts}][RESULT][${(subtype || 'unknown').toUpperCase()}]`);
230
- lines.push(` Duration: ${((entry.duration_ms || 0) / 1000).toFixed(1)}s`);
231
- lines.push(` Turns: ${entry.num_turns || 0}`);
232
- lines.push(` Cost: $${(entry.total_cost_usd || 0).toFixed(4)}`);
233
-
234
- if (entry.modelUsage) {
235
- lines.push(' Token Usage:');
236
- let totalIn = 0, totalOut = 0, totalCacheR = 0, totalCacheW = 0;
237
- for (const [model, usage] of Object.entries(entry.modelUsage)) {
238
- const shortModel = model.replace('claude-', '').replace(/-\d+$/, '');
239
- const inputTokens = usage.inputTokens || 0;
240
- const outputTokens = usage.outputTokens || 0;
241
- const cacheRead = usage.cacheReadInputTokens || 0;
242
- const cacheWrite = usage.cacheCreationInputTokens || 0;
243
- const totalModelTokens = inputTokens + outputTokens + cacheRead + cacheWrite;
244
- totalIn += inputTokens;
245
- totalOut += outputTokens;
246
- totalCacheR += cacheRead;
247
- totalCacheW += cacheWrite;
248
- lines.push(` [${shortModel}] $${(usage.costUSD || 0).toFixed(4)} | ${totalModelTokens.toLocaleString()} tokens`);
249
- lines.push(` ├─ Input: ${inputTokens.toLocaleString().padStart(10)}`);
250
- lines.push(` ├─ Output: ${outputTokens.toLocaleString().padStart(10)}`);
251
- lines.push(` ├─ Cache Read: ${cacheRead.toLocaleString().padStart(10)} (90% cheaper)`);
252
- lines.push(` └─ Cache Write: ${cacheWrite.toLocaleString().padStart(10)} (25% more expensive)`);
253
- }
254
- const grandTotal = totalIn + totalOut + totalCacheR + totalCacheW;
255
- lines.push(' ─────────────────────────────────────');
256
- lines.push(` Total: ${grandTotal.toLocaleString()} tokens | $${(entry.total_cost_usd || 0).toFixed(4)}`);
257
- lines.push(` ├─ Billable Input: ${totalIn.toLocaleString()}`);
258
- lines.push(` ├─ Billable Output: ${totalOut.toLocaleString()}`);
259
- lines.push(` ├─ Cache Read: ${totalCacheR.toLocaleString()} (discounted)`);
260
- lines.push(` └─ Cache Write: ${totalCacheW.toLocaleString()}`);
261
- }
262
-
263
- // Final result 轉為純 log 格式(移除 markdown)
264
- if (entry.result) {
265
- lines.push('');
266
- lines.push(' Final:');
267
- const cleanResult = entry.result
268
- .replace(/^#{1,6}\s+/gm, '[H] ') // headers
269
- .replace(/\*\*([^*]+)\*\*/g, '$1') // bold
270
- .replace(/\*([^*]+)\*/g, '$1') // italic
271
- .replace(/`([^`]+)`/g, '$1') // inline code
272
- .replace(/^[-*]\s+/gm, ' - ') // list items
273
- .replace(/^\d+\.\s+/gm, ' # ') // numbered list
274
- .replace(/^>\s+/gm, ' > ') // blockquote
275
- .replace(/---+/g, ''); // horizontal rules
276
- const resultLines = cleanResult.split('\n');
277
- for (const rl of resultLines) {
278
- if (rl.trim()) {
279
- lines.push(` ${rl}`);
280
- }
281
- }
282
- }
283
- lines.push('--------------------------------------------------------------------------------');
284
- return lines.join('\n');
285
- }
286
-
287
- return null;
288
- }
289
-
290
- function truncate(str, len) {
291
- if (!str) return '';
292
- str = str.replace(/\s+/g, ' ').trim();
293
- return str.length > len ? str.slice(0, len) + '...' : str;
294
- }
295
-
296
- /**
297
- * 格式化 JSON 行陣列為人類可讀格式
298
- * @param {string[]} jsonLines - JSON 字串陣列
299
- * @param {Object} options - 選項
300
- * @param {string} options.sessionId - Session ID
301
- * @returns {string} 格式化後的日誌內容
302
- */
303
- function formatJsonLines(jsonLines, options = {}) {
304
- const { sessionId = 'unknown' } = options;
305
- const output = [];
306
-
307
- output.push('================================================================================');
308
- output.push('SUNNY TEAM EXECUTION LOG');
309
- output.push(`Session: ${sessionId}`);
310
- output.push(`Generated: ${new Date().toISOString()}`);
311
- output.push('================================================================================');
312
- output.push('');
313
-
314
- for (const line of jsonLines) {
315
- try {
316
- const entry = JSON.parse(line);
317
- const logLine = formatEntry(entry);
318
- if (logLine) {
319
- output.push(logLine);
320
- }
321
- } catch (e) {
322
- // 非 JSON 行,忽略
323
- }
324
- }
325
-
326
- return output.join('\n');
327
- }
328
-
329
- module.exports = { formatEntry, formatJsonLines, truncate };
@@ -1,101 +0,0 @@
1
- {
2
- "name": "Sunny Tools",
3
- "version": "2.0.0",
4
- "tools": {
5
- "formation": {
6
- "description": "Formation 系統 — 多陣型 Agent 調度",
7
- "status": "stable",
8
- "usage": {
9
- "dispatch-via-subagent": {
10
- "description": "Sunny 調度 Formation 的標準方式:開 subagent 執行",
11
- "method": "Task tool → subagent_type: general-purpose",
12
- "rules": [
13
- "派工一律走 subagent(Formation 退役中,2026-10-09)",
14
- "subagent prompt 須包含:任務描述 + 陣型選擇 + 驗收標準",
15
- "subagent 用 run_in_background: true,Sunny 保持待命"
16
- ],
17
- "prompt_template": "node .formation/tools/dispatch.js --skill=do --task=TASK_XXX --dispatch-mode=subagent,把輸出的 promptText 原樣當 Agent prompt、agentParams 原樣帶入"
18
- },
19
- "headless-direct": {
20
- "description": "直接呼叫 headless.js(Sunny 用 Bash 工具執行)",
21
- "command": "node .formation/tools/headless.js",
22
- "args": {
23
- "--formation": "unit | solo | squad | legion | legacy",
24
- "--skill": "do | think | plan | strategy | diagnosis | blitz | sweep | forge | hive",
25
- "--task": "TASK_XXX 或自由文字描述",
26
- "--dry-run": "只輸出 prompt 不執行"
27
- },
28
- "examples": [
29
- "node .formation/tools/headless.js --skill=do --task=\"修正按鈕顏色\"",
30
- "node .formation/tools/headless.js --formation=solo --skill=strategy --task=\"評估快取方案\"",
31
- "node .formation/tools/headless.js --formation=squad --skill=blitz --task=TASK_201"
32
- ]
33
- }
34
- },
35
- "formations": {
36
- "unit": {
37
- "skills": ["do", "think", "plan"],
38
- "when": "單一任務 ≤3 檔案 | 調查 | 規劃"
39
- },
40
- "solo": {
41
- "skills": ["strategy", "diagnosis"],
42
- "when": "多角度動態分析"
43
- },
44
- "squad": {
45
- "skills": ["blitz", "sweep", "strategy", "strategy-tribunal"],
46
- "when": "互不依賴子任務並行 | 跨模組批量變更"
47
- },
48
- "legion": {
49
- "skills": ["forge", "hive"],
50
- "when": "順序依賴 | 回饋循環 | 高度耦合"
51
- },
52
- "legacy": {
53
- "skills": ["scheduler"],
54
- "when": "長時間自動迭代"
55
- }
56
- },
57
- "paths": {
58
- "headless": ".formation/tools/headless.js",
59
- "runner": ".formation/tools/runner.js",
60
- "prompt": ".formation/tools/prompt.js",
61
- "loader": ".formation/tools/loader.js",
62
- "configs": ".formation/{formation}/{skill}.yaml",
63
- "logs": ".formation/logs/{formation}/"
64
- }
65
- },
66
- "task-api": {
67
- "description": "任務系統 API(雙軌制)",
68
- "status": "stable",
69
- "commands": {
70
- "list": "node .collaboration/core/task-api.js list",
71
- "get": "node .collaboration/core/task-api.js get TASK_XXX",
72
- "create": "node .collaboration/core/task-api.js create --title \"{title}\" --priority P1",
73
- "claim": "node .collaboration/core/task-api.js claim TASK_XXX",
74
- "complete": "node .collaboration/core/task-api.js complete TASK_XXX",
75
- "move": "node .collaboration/core/task-api.js move TASK_XXX {status}",
76
- "json": "node .collaboration/core/task-api-json.js --task TASK_XXX"
77
- }
78
- },
79
- "cortex": {
80
- "description": "Kenaz Cortex RAG 引擎(MCP 工具)",
81
- "type": "mcp",
82
- "server": "kenaz-cortex",
83
- "status": "stable",
84
- "tools": {
85
- "cortex_search": "語義代碼搜索",
86
- "cortex_context": "專案結構化 Context",
87
- "cortex_symbols": "ctags 符號搜索",
88
- "cortex_file_chunks": "特定文件 AST 切片",
89
- "cortex_overview": "Map-Reduce 專案概覽",
90
- "cortex_status": "引擎狀態",
91
- "cortex_cross_search": "跨專案搜索",
92
- "cortex_list_projects": "列出已索引專案"
93
- }
94
- },
95
- "knowledge": {
96
- "description": "Claude Code 官方功能知識庫索引",
97
- "path": "knowledge/INDEX.md",
98
- "status": "stable"
99
- }
100
- }
101
- }
@@ -1,184 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * cleanup-queue.js
4
- *
5
- * 清理 TASK_QUEUE.json 中的已完成任務
6
- *
7
- * 用途:
8
- * - 移除所有 status 為 'completed' 或 'cancelled' 的任務
9
- * - 重新計算統計數據(當前佇列制)
10
- * - 保持佇列精簡,提升 Agent 任務選取效率
11
- *
12
- * 執行方式:
13
- * node dev/scripts/cleanup-queue.js
14
- * node dev/scripts/cleanup-queue.js --dry-run
15
- * node dev/scripts/cleanup-queue.js --verbose
16
- *
17
- * 相關失敗記錄:.failure/pipeline/FAIL-003-queue-pollution.yaml
18
- */
19
-
20
- const fs = require('fs');
21
- const path = require('path');
22
-
23
- // ============================================================
24
- // 配置
25
- // ============================================================
26
- const QUEUE_PATH = path.join(process.cwd(), 'dev/pipeline/TASK_QUEUE.json');
27
- const BACKUP_DIR = path.join(process.cwd(), 'dev/pipeline/backups');
28
-
29
- // 解析命令行參數
30
- const args = process.argv.slice(2);
31
- const isDryRun = args.includes('--dry-run');
32
- const isVerbose = args.includes('--verbose') || isDryRun;
33
-
34
- // ============================================================
35
- // 主函數
36
- // ============================================================
37
- async function main() {
38
- console.log('🧹 TASK_QUEUE.json 清理工具\n');
39
-
40
- // 1. 驗證文件存在
41
- if (!fs.existsSync(QUEUE_PATH)) {
42
- console.error(`❌ 錯誤:找不到文件 ${QUEUE_PATH}`);
43
- process.exit(1);
44
- }
45
-
46
- // 2. 讀取並解析 JSON(處理 BOM)
47
- console.log(`📖 讀取佇列文件:${QUEUE_PATH}`);
48
- let content = fs.readFileSync(QUEUE_PATH, 'utf8');
49
-
50
- // 移除 BOM(如果存在)
51
- if (content.charCodeAt(0) === 0xFEFF) {
52
- console.log('⚠️ 偵測到 BOM,已自動移除');
53
- content = content.slice(1);
54
- }
55
-
56
- let data;
57
- try {
58
- data = JSON.parse(content);
59
- } catch (error) {
60
- console.error(`❌ JSON 解析失敗:${error.message}`);
61
- process.exit(1);
62
- }
63
-
64
- // 3. 統計當前狀態
65
- const totalBefore = data.tasks.length;
66
- const statusBefore = getStatusCounts(data.tasks);
67
-
68
- console.log('\n📊 清理前統計:');
69
- console.log(` 總任務數:${totalBefore}`);
70
- console.log(` - pending: ${statusBefore.pending}`);
71
- console.log(` - in_progress: ${statusBefore.in_progress}`);
72
- console.log(` - blocked: ${statusBefore.blocked}`);
73
- console.log(` - completed: ${statusBefore.completed} 🗑️`);
74
- console.log(` - cancelled: ${statusBefore.cancelled} 🗑️`);
75
-
76
- // 4. 過濾任務(只保留 pending/in_progress/blocked)
77
- const activeTasks = data.tasks.filter(task =>
78
- ['pending', 'in_progress', 'blocked'].includes(task.status)
79
- );
80
-
81
- const removedTasks = data.tasks.filter(task =>
82
- ['completed', 'cancelled'].includes(task.status)
83
- );
84
-
85
- // 5. 顯示將被移除的任務(詳細模式)
86
- if (isVerbose && removedTasks.length > 0) {
87
- console.log('\n🗑️ 將被移除的任務:');
88
- removedTasks.forEach(task => {
89
- console.log(` - [${task.status.toUpperCase()}] ${task.id}: ${task.title}`);
90
- });
91
- }
92
-
93
- // 6. 更新數據結構
94
- data.tasks = activeTasks;
95
-
96
- // 重新計算統計數據(當前佇列制)
97
- data.statistics = {
98
- total: activeTasks.length,
99
- pending: activeTasks.filter(t => t.status === 'pending').length,
100
- in_progress: activeTasks.filter(t => t.status === 'in_progress').length,
101
- blocked: activeTasks.filter(t => t.status === 'blocked').length,
102
- completed: 0,
103
- cancelled: 0
104
- };
105
-
106
- // 更新時間戳
107
- data.last_updated = new Date().toISOString();
108
-
109
- // 7. 統計清理後狀態
110
- const totalAfter = data.tasks.length;
111
- const statusAfter = getStatusCounts(data.tasks);
112
-
113
- console.log('\n📊 清理後統計:');
114
- console.log(` 總任務數:${totalAfter}`);
115
- console.log(` - pending: ${statusAfter.pending}`);
116
- console.log(` - in_progress: ${statusAfter.in_progress}`);
117
- console.log(` - blocked: ${statusAfter.blocked}`);
118
- console.log(` - completed: ${statusAfter.completed}`);
119
- console.log(` - cancelled: ${statusAfter.cancelled}`);
120
-
121
- console.log(`\n✨ 移除 ${removedTasks.length} 個已完成/已取消任務`);
122
-
123
- // 8. 執行寫入(非 dry-run 模式)
124
- if (isDryRun) {
125
- console.log('\n🔍 DRY RUN 模式:不會實際修改文件');
126
- console.log(' 移除 --dry-run 參數以執行清理');
127
- } else {
128
- // 備份原文件
129
- const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, -5);
130
- const backupPath = path.join(BACKUP_DIR, `queue_backup_${timestamp}.json`);
131
-
132
- if (!fs.existsSync(BACKUP_DIR)) {
133
- fs.mkdirSync(BACKUP_DIR, { recursive: true });
134
- }
135
-
136
- fs.copyFileSync(QUEUE_PATH, backupPath);
137
- console.log(`\n💾 已備份到:${backupPath}`);
138
-
139
- // 寫回文件
140
- fs.writeFileSync(QUEUE_PATH, JSON.stringify(data, null, 2), 'utf8');
141
- console.log(`✅ 已更新:${QUEUE_PATH}`);
142
- }
143
-
144
- // 9. 驗證結果
145
- if (!isDryRun) {
146
- const verifyContent = fs.readFileSync(QUEUE_PATH, 'utf8');
147
- const verifyData = JSON.parse(verifyContent.charCodeAt(0) === 0xFEFF ? verifyContent.slice(1) : verifyContent);
148
-
149
- const completedInQueue = verifyData.tasks.filter(t => ['completed', 'cancelled'].includes(t.status)).length;
150
-
151
- if (completedInQueue > 0) {
152
- console.error(`\n⚠️ 警告:佇列中仍有 ${completedInQueue} 個已完成/已取消任務!`);
153
- process.exit(1);
154
- } else {
155
- console.log('\n✅ 驗證通過:佇列已清理,無已完成/已取消任務');
156
- }
157
- }
158
-
159
- console.log('\n🎉 清理完成!\n');
160
- }
161
-
162
- // ============================================================
163
- // 工具函數
164
- // ============================================================
165
- function getStatusCounts(tasks) {
166
- return {
167
- pending: tasks.filter(t => t.status === 'pending').length,
168
- in_progress: tasks.filter(t => t.status === 'in_progress').length,
169
- blocked: tasks.filter(t => t.status === 'blocked').length,
170
- completed: tasks.filter(t => t.status === 'completed').length,
171
- cancelled: tasks.filter(t => t.status === 'cancelled').length
172
- };
173
- }
174
-
175
- // ============================================================
176
- // 執行
177
- // ============================================================
178
- main().catch(error => {
179
- console.error(`\n❌ 執行錯誤:${error.message}`);
180
- if (isVerbose) {
181
- console.error(error.stack);
182
- }
183
- process.exit(1);
184
- });