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,389 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * conflict-resolver.test.js
4
- * ConflictResolver 單元測試
5
- *
6
- * 測試覆蓋:
7
- * - 版本衝突偵測
8
- * - 時間戳比較
9
- * - 自動合併策略
10
- * - Git 衝突解析
11
- * - 錯誤處理
12
- */
13
-
14
- const assert = require('assert');
15
- const { ConflictResolver, ConflictType, ResolutionStrategy } = require('./conflict-resolver.js');
16
-
17
- // ============================================================================
18
- // 測試資料
19
- // ============================================================================
20
-
21
- const createTaskV1 = () => ({
22
- id: 'TASK_001',
23
- title: '實作登入功能',
24
- status: 'in_progress',
25
- _version: 1,
26
- collaborators: ['alice', 'bob'],
27
- keywords: ['auth', 'login'],
28
- dependencies: {
29
- required: [],
30
- optional: ['TASK_002'],
31
- },
32
- last_modified_by: {
33
- name: 'Alice',
34
- timestamp: '2026-02-11T10:00:00Z',
35
- },
36
- });
37
-
38
- const createTaskV2 = () => ({
39
- id: 'TASK_001',
40
- title: '實作登入功能(含 OAuth)',
41
- status: 'in_progress',
42
- _version: 2,
43
- collaborators: ['alice', 'charlie'],
44
- keywords: ['auth', 'login', 'oauth'],
45
- dependencies: {
46
- required: [],
47
- optional: ['TASK_002', 'TASK_003'],
48
- },
49
- last_modified_by: {
50
- name: 'Charlie',
51
- timestamp: '2026-02-11T10:05:00Z',
52
- },
53
- });
54
-
55
- const createTaskSimultaneous = () => ({
56
- id: 'TASK_001',
57
- title: '實作登入功能(含 2FA)',
58
- status: 'completed',
59
- _version: 1,
60
- collaborators: ['alice', 'david'],
61
- keywords: ['auth', 'login', '2fa'],
62
- dependencies: {
63
- required: [],
64
- optional: ['TASK_004'],
65
- },
66
- last_modified_by: {
67
- name: 'David',
68
- timestamp: '2026-02-11T10:00:00.500Z', // 同時修改(0.5 秒差異)
69
- },
70
- });
71
-
72
- // ============================================================================
73
- // 測試套件
74
- // ============================================================================
75
-
76
- class TestRunner {
77
- constructor() {
78
- this.tests = [];
79
- this.passed = 0;
80
- this.failed = 0;
81
- }
82
-
83
- test(name, fn) {
84
- this.tests.push({ name, fn });
85
- }
86
-
87
- async run() {
88
- console.log('========================================');
89
- console.log('ConflictResolver 單元測試');
90
- console.log('========================================\n');
91
-
92
- for (const { name, fn } of this.tests) {
93
- try {
94
- await fn();
95
- console.log(`✅ ${name}`);
96
- this.passed++;
97
- } catch (error) {
98
- console.log(`❌ ${name}`);
99
- console.error(` 錯誤: ${error.message}`);
100
- this.failed++;
101
- }
102
- }
103
-
104
- console.log('\n========================================');
105
- console.log(`測試結果: ${this.passed} 通過, ${this.failed} 失敗`);
106
- console.log(`覆蓋率: ${((this.passed / this.tests.length) * 100).toFixed(2)}%`);
107
- console.log('========================================\n');
108
-
109
- process.exit(this.failed > 0 ? 1 : 0);
110
- }
111
- }
112
-
113
- const runner = new TestRunner();
114
-
115
- // ============================================================================
116
- // 測試案例: 版本衝突偵測
117
- // ============================================================================
118
-
119
- runner.test('detectConflict: 無衝突(相同版本)', () => {
120
- const resolver = new ConflictResolver();
121
- const task1 = createTaskV1();
122
- const task2 = { ...createTaskV1() };
123
-
124
- const conflict = resolver.detectConflict(task1, task2);
125
-
126
- assert.strictEqual(conflict.hasConflict, false);
127
- assert.strictEqual(conflict.type, ConflictType.NO_CONFLICT);
128
- });
129
-
130
- runner.test('detectConflict: 版本號衝突', () => {
131
- const resolver = new ConflictResolver();
132
- const task1 = createTaskV1();
133
- const task2 = createTaskV2();
134
-
135
- const conflict = resolver.detectConflict(task1, task2);
136
-
137
- assert.strictEqual(conflict.hasConflict, true);
138
- assert.strictEqual(conflict.type, ConflictType.VERSION_MISMATCH);
139
- assert.strictEqual(conflict.details.versionMismatch.ours, 1);
140
- assert.strictEqual(conflict.details.versionMismatch.theirs, 2);
141
- });
142
-
143
- runner.test('detectConflict: 時間戳衝突(同時修改)', () => {
144
- const resolver = new ConflictResolver();
145
- const task1 = createTaskV1();
146
- const task2 = createTaskSimultaneous();
147
-
148
- const conflict = resolver.detectConflict(task1, task2);
149
-
150
- assert.strictEqual(conflict.hasConflict, true);
151
- assert.strictEqual(conflict.type, ConflictType.TIMESTAMP_CONFLICT);
152
- assert.ok(conflict.details.timestampConflict.diff < 1000);
153
- });
154
-
155
- runner.test('detectConflict: 欄位衝突', () => {
156
- const resolver = new ConflictResolver();
157
- const task1 = createTaskV1();
158
- const task2 = {
159
- ...createTaskV1(),
160
- status: 'completed',
161
- last_modified_by: {
162
- name: 'Alice',
163
- timestamp: '2026-02-11T10:10:00Z', // 10 分鐘後,避免被視為同時修改
164
- },
165
- };
166
-
167
- const conflict = resolver.detectConflict(task1, task2);
168
-
169
- assert.strictEqual(conflict.hasConflict, true);
170
- assert.strictEqual(conflict.type, ConflictType.FIELD_CONFLICT);
171
- assert.ok(conflict.details.fieldConflicts.length > 0);
172
- });
173
-
174
- runner.test('detectConflict: 缺少參數拋出錯誤', () => {
175
- const resolver = new ConflictResolver();
176
-
177
- assert.throws(() => {
178
- resolver.detectConflict(null, createTaskV1());
179
- }, /必須提供兩個版本/);
180
- });
181
-
182
- runner.test('detectConflict: 任務 ID 不匹配拋出錯誤', () => {
183
- const resolver = new ConflictResolver();
184
- const task1 = createTaskV1();
185
- const task2 = { ...createTaskV1(), id: 'TASK_002' };
186
-
187
- assert.throws(() => {
188
- resolver.detectConflict(task1, task2);
189
- }, /任務 ID 不匹配/);
190
- });
191
-
192
- // ============================================================================
193
- // 測試案例: 自動解決策略
194
- // ============================================================================
195
-
196
- runner.test('autoResolve: KEEP_OURS 策略', () => {
197
- const resolver = new ConflictResolver();
198
- const task1 = createTaskV1();
199
- const task2 = createTaskV2();
200
-
201
- const resolved = resolver.autoResolve(task1, task2, ResolutionStrategy.KEEP_OURS);
202
-
203
- assert.strictEqual(resolved.id, task1.id);
204
- assert.strictEqual(resolved.title, task1.title);
205
- assert.strictEqual(resolved._version, 2); // 版本遞增
206
- assert.strictEqual(resolved.last_modified_by.resolution, 'keep_ours');
207
- });
208
-
209
- runner.test('autoResolve: KEEP_THEIRS 策略', () => {
210
- const resolver = new ConflictResolver();
211
- const task1 = createTaskV1();
212
- const task2 = createTaskV2();
213
-
214
- const resolved = resolver.autoResolve(task1, task2, ResolutionStrategy.KEEP_THEIRS);
215
-
216
- assert.strictEqual(resolved.id, task2.id);
217
- assert.strictEqual(resolved.title, task2.title);
218
- assert.strictEqual(resolved._version, 3); // 版本遞增
219
- assert.strictEqual(resolved.last_modified_by.resolution, 'keep_theirs');
220
- });
221
-
222
- runner.test('autoResolve: AUTO_MERGE 策略(合併 collaborators)', () => {
223
- const resolver = new ConflictResolver();
224
- const task1 = createTaskV1();
225
- const task2 = createTaskV2();
226
-
227
- const resolved = resolver.autoResolve(task1, task2, ResolutionStrategy.AUTO_MERGE);
228
-
229
- assert.strictEqual(resolved._version, 3); // max(1, 2) + 1
230
- assert.strictEqual(resolved.last_modified_by.resolution, 'auto_merge');
231
-
232
- // collaborators 應該合併去重
233
- const expectedCollaborators = new Set(['alice', 'bob', 'charlie']);
234
- assert.deepStrictEqual(new Set(resolved.collaborators), expectedCollaborators);
235
- });
236
-
237
- runner.test('autoResolve: AUTO_MERGE 策略(合併 keywords)', () => {
238
- const resolver = new ConflictResolver();
239
- const task1 = createTaskV1();
240
- const task2 = createTaskV2();
241
-
242
- const resolved = resolver.autoResolve(task1, task2, ResolutionStrategy.AUTO_MERGE);
243
-
244
- // keywords 應該合併去重
245
- const expectedKeywords = new Set(['auth', 'login', 'oauth']);
246
- assert.deepStrictEqual(new Set(resolved.keywords), expectedKeywords);
247
- });
248
-
249
- runner.test('autoResolve: AUTO_MERGE 策略(合併 dependencies.optional)', () => {
250
- const resolver = new ConflictResolver();
251
- const task1 = createTaskV1();
252
- const task2 = createTaskV2();
253
-
254
- const resolved = resolver.autoResolve(task1, task2, ResolutionStrategy.AUTO_MERGE);
255
-
256
- // dependencies.optional 應該合併去重
257
- const expectedOptional = new Set(['TASK_002', 'TASK_003']);
258
- assert.deepStrictEqual(new Set(resolved.dependencies.optional), expectedOptional);
259
- });
260
-
261
- runner.test('autoResolve: AUTO_MERGE 使用較新的時間戳', () => {
262
- const resolver = new ConflictResolver();
263
- const task1 = createTaskV1(); // 10:00:00
264
- const task2 = createTaskV2(); // 10:05:00 (較新)
265
-
266
- const resolved = resolver.autoResolve(task1, task2, ResolutionStrategy.AUTO_MERGE);
267
-
268
- // 應該使用較新的時間戳(但被 auto_merge 覆寫)
269
- assert.ok(resolved.last_modified_by.mergedFrom);
270
- assert.strictEqual(resolved.last_modified_by.mergedFrom.ours, task1.last_modified_by.timestamp);
271
- assert.strictEqual(resolved.last_modified_by.mergedFrom.theirs, task2.last_modified_by.timestamp);
272
- });
273
-
274
- runner.test('autoResolve: 無衝突時保留原版本', () => {
275
- const resolver = new ConflictResolver();
276
- const task1 = createTaskV1();
277
- const task2 = { ...createTaskV1() };
278
-
279
- const resolved = resolver.autoResolve(task1, task2, ResolutionStrategy.AUTO_MERGE);
280
-
281
- assert.deepStrictEqual(resolved, task1);
282
- });
283
-
284
- runner.test('autoResolve: 未知策略拋出錯誤', () => {
285
- const resolver = new ConflictResolver();
286
- const task1 = createTaskV1();
287
- const task2 = createTaskV2();
288
-
289
- assert.throws(() => {
290
- resolver.autoResolve(task1, task2, 'INVALID_STRATEGY');
291
- }, /未知的解決策略/);
292
- });
293
-
294
- // ============================================================================
295
- // 測試案例: Git 衝突解析
296
- // ============================================================================
297
-
298
- runner.test('parseGitConflict: 正確解析 Git 衝突標記', () => {
299
- const resolver = new ConflictResolver();
300
- const task1 = createTaskV1();
301
- const task2 = createTaskV2();
302
-
303
- const gitConflict = `<<<<<<< HEAD
304
- ${JSON.stringify(task1, null, 2)}
305
- =======
306
- ${JSON.stringify(task2, null, 2)}
307
- >>>>>>> feature-branch
308
- `;
309
-
310
- const { ours, theirs } = resolver.parseGitConflict(gitConflict);
311
-
312
- assert.deepStrictEqual(ours, task1);
313
- assert.deepStrictEqual(theirs, task2);
314
- });
315
-
316
- runner.test('parseGitConflict: 缺少標記拋出錯誤', () => {
317
- const resolver = new ConflictResolver();
318
- const invalidContent = 'This is not a git conflict';
319
-
320
- assert.throws(() => {
321
- resolver.parseGitConflict(invalidContent);
322
- }, /未找到 Git 衝突標記/);
323
- });
324
-
325
- runner.test('parseGitConflict: 無效 JSON 拋出錯誤', () => {
326
- const resolver = new ConflictResolver();
327
- const invalidConflict = `<<<<<<< HEAD
328
- {invalid json}
329
- =======
330
- {also invalid}
331
- >>>>>>> branch
332
- `;
333
-
334
- assert.throws(() => {
335
- resolver.parseGitConflict(invalidConflict);
336
- }, /解析 Git 衝突內容失敗/);
337
- });
338
-
339
- // ============================================================================
340
- // 測試案例: 邊界情況
341
- // ============================================================================
342
-
343
- runner.test('邊界: _version 欄位缺失時預設為 1', () => {
344
- const resolver = new ConflictResolver();
345
- const task1 = { id: 'TASK_001', title: 'Test' };
346
- const task2 = { id: 'TASK_001', title: 'Test', _version: 2 };
347
-
348
- const conflict = resolver.detectConflict(task1, task2);
349
-
350
- assert.strictEqual(conflict.hasConflict, true);
351
- assert.strictEqual(conflict.details.versionMismatch.ours, 1);
352
- assert.strictEqual(conflict.details.versionMismatch.theirs, 2);
353
- });
354
-
355
- runner.test('邊界: 時間戳缺失時不檢查時間戳衝突', () => {
356
- const resolver = new ConflictResolver();
357
- const task1 = { id: 'TASK_001', title: 'Test', _version: 1 };
358
- const task2 = { id: 'TASK_001', title: 'Test', _version: 1 };
359
-
360
- const conflict = resolver.detectConflict(task1, task2);
361
-
362
- assert.strictEqual(conflict.type, ConflictType.NO_CONFLICT);
363
- });
364
-
365
- runner.test('邊界: collaborators 為空陣列時自動合併正確', () => {
366
- const resolver = new ConflictResolver();
367
- const task1 = { ...createTaskV1(), collaborators: [] };
368
- const task2 = { ...createTaskV2(), collaborators: ['alice'] };
369
-
370
- const resolved = resolver.autoResolve(task1, task2, ResolutionStrategy.AUTO_MERGE);
371
-
372
- assert.deepStrictEqual(resolved.collaborators, ['alice']);
373
- });
374
-
375
- runner.test('邊界: dependencies.optional 缺失時不報錯', () => {
376
- const resolver = new ConflictResolver();
377
- const task1 = { ...createTaskV1(), dependencies: { required: [] } };
378
- const task2 = { ...createTaskV2(), dependencies: { required: [] } };
379
-
380
- const resolved = resolver.autoResolve(task1, task2, ResolutionStrategy.AUTO_MERGE);
381
-
382
- assert.ok(resolved.dependencies);
383
- });
384
-
385
- // ============================================================================
386
- // 執行測試
387
- // ============================================================================
388
-
389
- runner.run();
@@ -1,260 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * migrate-legacy.js
4
- * 將舊系統 (dev/pipeline/) 的任務遷移到新系統 (.collaboration/tasks/archived/)
5
- *
6
- * 來源:
7
- * 1. dev/pipeline/completed/*.yaml — 舊 YAML 檔
8
- * 2. dev/pipeline/TASK_QUEUE.json — JSON 索引(補充 YAML 沒有的)
9
- *
10
- * 目標:.collaboration/tasks/archived/TASK_XXX.yaml(新系統格式)
11
- *
12
- * Usage:
13
- * node .collaboration/core/migrate-legacy.js # 預覽
14
- * node .collaboration/core/migrate-legacy.js --execute # 執行寫入
15
- */
16
-
17
- const fs = require('fs');
18
- const path = require('path');
19
- const yaml = (() => {
20
- try { return require('js-yaml'); } catch {
21
- const candidates = [
22
- path.resolve(__dirname, '../../.vendor/js-yaml.cjs'),
23
- path.resolve(__dirname, '.vendor/js-yaml.cjs'),
24
- ];
25
- if (process.env.KENAZ_SOURCE_DIR) {
26
- candidates.unshift(path.join(process.env.KENAZ_SOURCE_DIR, '.vendor', 'js-yaml.cjs'));
27
- }
28
- for (const c of candidates) {
29
- try { return require(c); } catch { /* next */ }
30
- }
31
- throw new Error('js-yaml not found. Install it or ensure .vendor/js-yaml.cjs exists.');
32
- }
33
- })();
34
- const { randomUUID } = require('crypto');
35
-
36
- const ROOT = path.resolve(__dirname, '..', '..');
37
- const LEGACY_COMPLETED = path.join(ROOT, 'dev', 'pipeline', 'completed');
38
- const LEGACY_TASKS = path.join(ROOT, 'dev', 'pipeline', 'tasks');
39
- const LEGACY_QUEUE = path.join(ROOT, 'dev', 'pipeline', 'TASK_QUEUE.json');
40
- const NEW_ARCHIVED = path.join(ROOT, '.collaboration', 'tasks', 'archived');
41
-
42
- // 新系統所有已存在的任務 ID
43
- function getExistingIds() {
44
- const dirs = ['backlog', 'active', 'done', 'cancel', 'blocked', 'archived'];
45
- const ids = new Set();
46
- for (const d of dirs) {
47
- const dir = path.join(ROOT, '.collaboration', 'tasks', d);
48
- if (!fs.existsSync(dir)) continue;
49
- for (const f of fs.readdirSync(dir)) {
50
- const m = f.match(/^(TASK_\d+)/);
51
- if (m) ids.add(m[1]);
52
- }
53
- }
54
- return ids;
55
- }
56
-
57
- // 將字串陣列中的物件/非字串轉為字串
58
- function toStringArray(arr) {
59
- if (!Array.isArray(arr)) return [];
60
- return arr.map(item => {
61
- if (typeof item === 'string') return item;
62
- if (item == null) return null;
63
- if (typeof item === 'object') {
64
- if (item.description) return item.description;
65
- if (item.name) return item.name;
66
- return JSON.stringify(item);
67
- }
68
- return String(item);
69
- }).filter(Boolean);
70
- }
71
-
72
- // 從舊格式轉換成新系統格式
73
- function convertToNewFormat(old, source) {
74
- const id = old.id || old.ID;
75
-
76
- // description 處理
77
- let desc = old.description || '';
78
- if (typeof desc !== 'string') desc = String(desc);
79
-
80
- // status 映射
81
- const statusMap = {
82
- 'pending': 'backlog',
83
- 'in_progress': 'active',
84
- 'completed': 'completed',
85
- 'cancelled': 'cancel',
86
- 'blocked': 'blocked',
87
- 'done': 'completed',
88
- 'split': 'backlog'
89
- };
90
- const rawStatus = (old.status || 'completed').toLowerCase();
91
- const status = statusMap[rawStatus] || rawStatus;
92
-
93
- // role 映射
94
- const role = old.role || old.agent_type || old.assigned_team || 'developer';
95
-
96
- // created_at / completed_at
97
- const createdAt = old.created_at || old.metadata?.created_at || '';
98
- const completedAt = old.completed_at || old.metadata?.completed_at || '';
99
- const createdBy = old.metadata?.created_by || old.created_by || 'Legacy Migration';
100
-
101
- // estimated_hours
102
- const estHours = old.estimated_hours != null ? old.estimated_hours : null;
103
- const actHours = old.actual_hours != null ? old.actual_hours : null;
104
-
105
- return {
106
- id,
107
- hash: randomUUID(),
108
- title: old.title || '',
109
- description: desc.trim(),
110
- priority: old.priority || 'P2',
111
- status,
112
- role: typeof role === 'string' ? role.replace(/"/g, '') : 'developer',
113
- tags: Array.isArray(old.tags) ? old.tags : [],
114
- complexity: old.complexity || 'medium',
115
- rigor: 'low',
116
- estimated_hours: estHours,
117
- actual_hours: actHours,
118
- branch: old.branch || null,
119
- dependencies: old.dependencies || [],
120
- scope_paths: old.scope_paths || old.scope || [],
121
- requirements: toStringArray(old.requirements),
122
- acceptance_criteria: toStringArray(old.acceptance_criteria),
123
- technical_notes: toStringArray(old.technical_notes),
124
- feature_ids: old.feature_ids || [],
125
- created_by: {
126
- name: typeof createdBy === 'string' ? createdBy : (createdBy.name || 'Legacy'),
127
- git_user: '',
128
- timestamp: typeof createdAt === 'string' ? createdAt : ''
129
- },
130
- executed_by: null,
131
- assigned_to: null,
132
- metadata: {
133
- migrated_from: source,
134
- migrated_at: new Date().toISOString()
135
- }
136
- };
137
- }
138
-
139
- // YAML dump 設定(匹配新系統輸出風格)
140
- function dumpYaml(obj) {
141
- return yaml.dump(obj, {
142
- lineWidth: -1,
143
- noRefs: true,
144
- quotingType: "'",
145
- forceQuotes: false
146
- });
147
- }
148
-
149
- // 主程式
150
- function main() {
151
- const execute = process.argv.includes('--execute');
152
- const existingIds = getExistingIds();
153
-
154
- console.log(`📋 Existing tasks in new system: ${existingIds.size}`);
155
-
156
- // 收集所有舊系統任務
157
- const legacyTasks = new Map(); // id -> { data, source }
158
-
159
- // 1. 從 completed/ YAML 載入
160
- for (const dir of [LEGACY_COMPLETED, LEGACY_TASKS]) {
161
- if (!fs.existsSync(dir)) continue;
162
- for (const file of fs.readdirSync(dir)) {
163
- if (!file.endsWith('.yaml') && !file.endsWith('.md')) continue;
164
- const match = file.match(/^(TASK_\d+)/);
165
- if (!match) continue;
166
- const taskId = match[1];
167
- if (legacyTasks.has(taskId)) continue; // 不覆蓋
168
-
169
- try {
170
- const content = fs.readFileSync(path.join(dir, file), 'utf8');
171
- // 跳過 .md 文件中沒有 YAML frontmatter 的
172
- if (file.endsWith('.md')) {
173
- if (!content.startsWith('---')) continue;
174
- // 提取 frontmatter
175
- const parts = content.split('---');
176
- if (parts.length < 3) continue;
177
- const data = yaml.load(parts[1]);
178
- if (data && data.id) {
179
- legacyTasks.set(taskId, { data, source: `dev/pipeline/completed/${file}` });
180
- }
181
- } else {
182
- const data = yaml.load(content);
183
- if (data && (data.id || data.ID)) {
184
- legacyTasks.set(taskId, { data, source: `dev/pipeline/completed/${file}` });
185
- }
186
- }
187
- } catch (e) {
188
- console.warn(` ⚠️ Parse error: ${file}: ${e.message}`);
189
- }
190
- }
191
- }
192
-
193
- // 2. 從 TASK_QUEUE.json 補充
194
- if (fs.existsSync(LEGACY_QUEUE)) {
195
- try {
196
- const queue = JSON.parse(fs.readFileSync(LEGACY_QUEUE, 'utf8'));
197
- for (const task of (queue.tasks || [])) {
198
- if (!legacyTasks.has(task.id)) {
199
- legacyTasks.set(task.id, { data: task, source: 'dev/pipeline/TASK_QUEUE.json' });
200
- }
201
- }
202
- } catch (e) {
203
- console.warn(` ⚠️ TASK_QUEUE.json parse error: ${e.message}`);
204
- }
205
- }
206
-
207
- // 找出缺失的
208
- const missing = [];
209
- for (const [id, info] of legacyTasks) {
210
- if (!existingIds.has(id)) {
211
- missing.push({ id, ...info });
212
- }
213
- }
214
-
215
- // 按 ID 排序
216
- missing.sort((a, b) => {
217
- const na = parseInt(a.id.replace('TASK_', ''));
218
- const nb = parseInt(b.id.replace('TASK_', ''));
219
- return na - nb;
220
- });
221
-
222
- console.log(`🔍 Legacy tasks found: ${legacyTasks.size}`);
223
- console.log(`❌ Missing from new system: ${missing.length}`);
224
-
225
- if (missing.length === 0) {
226
- console.log('✅ All tasks are synced!');
227
- return;
228
- }
229
-
230
- console.log('');
231
-
232
- // 確保 archived 目錄存在
233
- if (execute && !fs.existsSync(NEW_ARCHIVED)) {
234
- fs.mkdirSync(NEW_ARCHIVED, { recursive: true });
235
- }
236
-
237
- let created = 0;
238
- for (const task of missing) {
239
- const newTask = convertToNewFormat(task.data, task.source);
240
- const filename = `${task.id}.yaml`;
241
- const filepath = path.join(NEW_ARCHIVED, filename);
242
-
243
- if (execute) {
244
- fs.writeFileSync(filepath, dumpYaml(newTask), 'utf8');
245
- console.log(` ✅ ${task.id} ← ${task.source}`);
246
- created++;
247
- } else {
248
- console.log(` 📝 ${task.id} ← ${task.source} (dry-run)`);
249
- }
250
- }
251
-
252
- console.log('');
253
- if (execute) {
254
- console.log(`✅ Migrated ${created} tasks to .collaboration/tasks/archived/`);
255
- } else {
256
- console.log(`📋 ${missing.length} tasks would be migrated. Run with --execute to apply.`);
257
- }
258
- }
259
-
260
- main();