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,151 +0,0 @@
1
- /**
2
- * .matrix 格式序列化器
3
- * @version 1.0.0
4
- */
5
-
6
- import type { MatrixFile, SerializeOptions } from '../types';
7
- import { abbreviateField, encodeValue, shortenTimestamp } from './abbreviations';
8
-
9
- export class MatrixSerializer {
10
- private options: Required<SerializeOptions>;
11
-
12
- constructor(options: SerializeOptions = {}) {
13
- this.options = {
14
- pretty: options.pretty ?? false,
15
- includeComment: options.includeComment ?? true,
16
- comment: options.comment ?? '.matrix v1.0',
17
- };
18
- }
19
-
20
- /**
21
- * 序列化 MatrixFile 為 .matrix 格式
22
- * @param data MatrixFile 物件
23
- * @returns .matrix 文件內容
24
- */
25
- serialize(data: MatrixFile): string {
26
- const lines: string[] = [];
27
-
28
- // 註釋行
29
- if (this.options.includeComment) {
30
- lines.push(`# ${this.options.comment}`);
31
- }
32
-
33
- // @meta 層
34
- lines.push(this.serializeMeta(data.meta));
35
-
36
- // @index 層
37
- lines.push(this.serializeIndex(data.index));
38
-
39
- // @data 層(如果存在)
40
- if (data.data && data.data.records.length > 0) {
41
- lines.push('@data');
42
- for (const record of data.data.records) {
43
- lines.push(this.serializeDataRecord(record));
44
- }
45
- }
46
-
47
- return lines.join('\n') + '\n';
48
- }
49
-
50
- /**
51
- * 序列化 @meta 層
52
- */
53
- private serializeMeta(meta: Record<string, any>): string {
54
- const fields: string[] = [];
55
-
56
- for (const [key, value] of Object.entries(meta)) {
57
- if (value !== undefined && value !== null) {
58
- const abbr = abbreviateField(key);
59
- const encoded = this.encodeFieldValue(key, value);
60
- fields.push(`${abbr}=${encoded}`);
61
- }
62
- }
63
-
64
- return `@meta |${fields.join('|')}|`;
65
- }
66
-
67
- /**
68
- * 序列化 @index 層
69
- */
70
- private serializeIndex(index: Record<string, any>): string {
71
- const fields: string[] = [];
72
-
73
- for (const [key, value] of Object.entries(index)) {
74
- if (value !== undefined && value !== null) {
75
- const abbr = abbreviateField(key);
76
- const encoded = this.encodeFieldValue(key, value);
77
- fields.push(`${abbr}=${encoded}`);
78
- }
79
- }
80
-
81
- return `@index |${fields.join('|')}|`;
82
- }
83
-
84
- /**
85
- * 序列化 @data 記錄
86
- */
87
- private serializeDataRecord(record: { id: string; fields: Record<string, any> }): string {
88
- const fields: string[] = [];
89
-
90
- for (const [key, value] of Object.entries(record.fields)) {
91
- if (value !== undefined && value !== null) {
92
- const abbr = abbreviateField(key);
93
- const encoded = this.encodeFieldValue(key, value);
94
- fields.push(`${abbr}=${encoded}`);
95
- }
96
- }
97
-
98
- return `${record.id}|${fields.join('|')}|`;
99
- }
100
-
101
- /**
102
- * 編碼欄位值
103
- */
104
- private encodeFieldValue(fieldKey: string, value: any): string {
105
- // 布林值
106
- if (typeof value === 'boolean') {
107
- return value ? '1' : '0';
108
- }
109
-
110
- // 數字
111
- if (typeof value === 'number') {
112
- return String(value);
113
- }
114
-
115
- // 陣列(列表)
116
- if (Array.isArray(value)) {
117
- // 任務組(包含子欄位)
118
- if (value.length > 0 && typeof value[0] === 'object' && 'id' in value[0]) {
119
- return value
120
- .map(item => {
121
- const { id, ...subFields } = item;
122
- const subFieldsStr = Object.entries(subFields)
123
- .map(([k, v]) => {
124
- const abbr = abbreviateField(k);
125
- const encoded = encodeValue(k, v);
126
- return `${abbr}=${encoded}`;
127
- })
128
- .join(',');
129
- return `${id},${subFieldsStr}`;
130
- })
131
- .join(';');
132
- }
133
- // 一般列表
134
- return value.join(',');
135
- }
136
-
137
- // 時間戳(ISO 8601 → YYMMDD-HHMM)
138
- if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(value)) {
139
- return shortenTimestamp(value);
140
- }
141
-
142
- // 值代碼化
143
- const encoded = encodeValue(fieldKey, value);
144
- if (encoded !== String(value)) {
145
- return encoded;
146
- }
147
-
148
- // 純文本
149
- return String(value);
150
- }
151
- }
@@ -1,301 +0,0 @@
1
- /**
2
- * .matrix 格式驗證器
3
- * @version 1.0.0
4
- */
5
-
6
- import type { ValidationResult, ParseError } from '../types';
7
-
8
- export class MatrixValidator {
9
- /**
10
- * 驗證 .matrix 文件語法
11
- * @param content .matrix 文件內容
12
- * @returns 驗證結果
13
- */
14
- validate(content: string): ValidationResult {
15
- const errors: ParseError[] = [];
16
- const warnings: ParseError[] = [];
17
-
18
- const lines = content.split(/\r?\n/);
19
- let lineNum = 0;
20
- let hasMeta = false;
21
- let hasIndex = false;
22
- let metaLineNum = -1;
23
- let indexLineNum = -1;
24
-
25
- // E000: 空文件
26
- if (!content.trim()) {
27
- errors.push({
28
- code: 'E000',
29
- message: 'Empty file',
30
- line: 1,
31
- column: 1,
32
- });
33
- return { valid: false, errors, warnings };
34
- }
35
-
36
- // 逐行檢查
37
- for (const line of lines) {
38
- lineNum++;
39
- const trimmed = line.trim();
40
-
41
- // 跳過空行
42
- if (!trimmed) continue;
43
-
44
- // 跳過註釋行
45
- if (trimmed.startsWith('#')) continue;
46
-
47
- // 檢查 @meta
48
- if (trimmed.startsWith('@meta')) {
49
- if (hasMeta) {
50
- errors.push({
51
- code: 'E002',
52
- message: 'Duplicate @meta section',
53
- line: lineNum,
54
- column: 1,
55
- });
56
- }
57
- hasMeta = true;
58
- metaLineNum = lineNum;
59
-
60
- // 驗證 @meta 格式
61
- const metaError = this.validateMeta(trimmed, lineNum);
62
- if (metaError) errors.push(metaError);
63
-
64
- continue;
65
- }
66
-
67
- // 檢查 @index
68
- if (trimmed.startsWith('@index')) {
69
- if (hasIndex) {
70
- errors.push({
71
- code: 'E002',
72
- message: 'Duplicate @index section',
73
- line: lineNum,
74
- column: 1,
75
- });
76
- }
77
- hasIndex = true;
78
- indexLineNum = lineNum;
79
-
80
- // 驗證順序
81
- if (!hasMeta) {
82
- errors.push({
83
- code: 'E002',
84
- message: '@index must come after @meta',
85
- line: lineNum,
86
- column: 1,
87
- });
88
- }
89
-
90
- // 驗證 @index 格式
91
- const indexError = this.validateIndex(trimmed, lineNum);
92
- if (indexError) errors.push(indexError);
93
-
94
- continue;
95
- }
96
-
97
- // 檢查 @data
98
- if (trimmed.startsWith('@data')) {
99
- if (!hasMeta || !hasIndex) {
100
- errors.push({
101
- code: 'E002',
102
- message: '@data must come after @meta and @index',
103
- line: lineNum,
104
- column: 1,
105
- });
106
- }
107
- continue;
108
- }
109
-
110
- // 數據行(必須在 @data 之後)
111
- if (hasMeta && hasIndex && lineNum > indexLineNum) {
112
- const dataError = this.validateDataLine(trimmed, lineNum);
113
- if (dataError) {
114
- if (dataError.code.startsWith('W')) {
115
- warnings.push(dataError);
116
- } else {
117
- errors.push(dataError);
118
- }
119
- }
120
- }
121
- }
122
-
123
- // E001: 缺少必要層級
124
- if (!hasMeta) {
125
- errors.push({
126
- code: 'E001',
127
- message: 'Missing required section @meta',
128
- line: 1,
129
- column: 1,
130
- expected: '@meta |v=1.0|c=...|',
131
- });
132
- }
133
-
134
- if (!hasIndex) {
135
- errors.push({
136
- code: 'E001',
137
- message: 'Missing required section @index',
138
- line: metaLineNum + 1,
139
- column: 1,
140
- expected: '@index |tot=...|',
141
- });
142
- }
143
-
144
- return {
145
- valid: errors.length === 0,
146
- errors,
147
- warnings,
148
- };
149
- }
150
-
151
- /**
152
- * 驗證 @meta 層格式
153
- */
154
- private validateMeta(line: string, lineNum: number): ParseError | null {
155
- // E003: 分隔符錯誤
156
- if (!line.match(/^@meta\s+\|.+\|$/)) {
157
- return {
158
- code: 'E003',
159
- message: 'Invalid @meta format - missing delimiters',
160
- line: lineNum,
161
- column: 1,
162
- expected: '@meta |field=value|...|',
163
- got: line,
164
- };
165
- }
166
-
167
- // 檢查必要欄位
168
- if (!line.includes('v=')) {
169
- return {
170
- code: 'E005',
171
- message: '@meta must contain "v" (version) field',
172
- line: lineNum,
173
- column: 1,
174
- };
175
- }
176
-
177
- if (!line.includes('c=')) {
178
- return {
179
- code: 'E005',
180
- message: '@meta must contain "c" (category) field',
181
- line: lineNum,
182
- column: 1,
183
- };
184
- }
185
-
186
- // E004: 欄位格式錯誤
187
- const fieldsMatch = line.match(/\|(.+)\|$/);
188
- if (fieldsMatch) {
189
- const fields = fieldsMatch[1].split('|').filter(f => f.trim());
190
- for (const field of fields) {
191
- if (!field.includes('=')) {
192
- return {
193
- code: 'E004',
194
- message: `Invalid field format: "${field}" (should be key=value)`,
195
- line: lineNum,
196
- column: line.indexOf(field),
197
- };
198
- }
199
- }
200
- }
201
-
202
- return null;
203
- }
204
-
205
- /**
206
- * 驗證 @index 層格式
207
- */
208
- private validateIndex(line: string, lineNum: number): ParseError | null {
209
- // E003: 分隔符錯誤
210
- if (!line.match(/^@index\s+\|.+\|$/)) {
211
- return {
212
- code: 'E003',
213
- message: 'Invalid @index format - missing delimiters',
214
- line: lineNum,
215
- column: 1,
216
- expected: '@index |field=value|...|',
217
- got: line,
218
- };
219
- }
220
-
221
- // E004: 欄位格式錯誤
222
- const fieldsMatch = line.match(/\|(.+)\|$/);
223
- if (fieldsMatch) {
224
- const fields = fieldsMatch[1].split('|').filter(f => f.trim());
225
- for (const field of fields) {
226
- if (!field.includes('=')) {
227
- return {
228
- code: 'E004',
229
- message: `Invalid field format: "${field}" (should be key=value)`,
230
- line: lineNum,
231
- column: line.indexOf(field),
232
- };
233
- }
234
- }
235
- }
236
-
237
- return null;
238
- }
239
-
240
- /**
241
- * 驗證 @data 數據行格式
242
- */
243
- private validateDataLine(line: string, lineNum: number): ParseError | null {
244
- // E003: 分隔符錯誤
245
- if (!line.match(/^[^|]+\|.+\|$/)) {
246
- return {
247
- code: 'E003',
248
- message: 'Invalid data line format',
249
- line: lineNum,
250
- column: 1,
251
- expected: 'id|field=value|...|',
252
- got: line,
253
- };
254
- }
255
-
256
- // E004: 欄位格式錯誤
257
- const match = line.match(/\|(.+)\|$/);
258
- if (match) {
259
- const fields = match[1].split('|').filter(f => f.trim());
260
- for (const field of fields) {
261
- // 跳過任務組格式(包含分號)
262
- if (field.includes(';')) continue;
263
-
264
- if (!field.includes('=')) {
265
- return {
266
- code: 'E004',
267
- message: `Invalid field format: "${field}" (should be key=value)`,
268
- line: lineNum,
269
- column: line.indexOf(field),
270
- };
271
- }
272
- }
273
- }
274
-
275
- // W008: 未知欄位鍵名(警告)
276
- // 這裡可以加入欄位名驗證邏輯
277
-
278
- return null;
279
- }
280
-
281
- /**
282
- * 檢測至少 10 種語法錯誤
283
- */
284
- getErrorTypes(): string[] {
285
- return [
286
- 'E000 - Empty file',
287
- 'E001 - Missing required section (@meta or @index)',
288
- 'E002 - Invalid section order or duplicate sections',
289
- 'E003 - Missing delimiters (|)',
290
- 'E004 - Invalid field format (should be key=value)',
291
- 'E005 - Missing required field (@meta must have v and c)',
292
- 'E006 - Invalid timestamp format',
293
- 'E007 - Duplicate record_id',
294
- 'E008 - Unknown field key',
295
- 'E009 - Invalid value type',
296
- 'E010 - Invalid version number',
297
- 'W001 - Warning: Deprecated field',
298
- 'W008 - Warning: Unknown field key (preserved)',
299
- ];
300
- }
301
- }
@@ -1,122 +0,0 @@
1
- /**
2
- * Abbreviations 模組單元測試
3
- */
4
-
5
- import {
6
- abbreviateField,
7
- expandField,
8
- encodeValue,
9
- decodeValue,
10
- shortenTimestamp,
11
- expandTimestamp,
12
- FIELD_ABBREVIATIONS,
13
- VALUE_CODES,
14
- } from '../src/abbreviations';
15
-
16
- describe('Abbreviations', () => {
17
- describe('欄位名縮寫', () => {
18
- it('應該正確縮寫常用欄位', () => {
19
- expect(abbreviateField('status')).toBe('st');
20
- expect(abbreviateField('priority')).toBe('p');
21
- expect(abbreviateField('created_at')).toBe('ct');
22
- expect(abbreviateField('updated_at')).toBe('ut');
23
- expect(abbreviateField('duration')).toBe('dur');
24
- });
25
-
26
- it('應該保留未知欄位', () => {
27
- expect(abbreviateField('unknown_field')).toBe('unknown_field');
28
- });
29
-
30
- it('應該正確展開縮寫', () => {
31
- expect(expandField('st')).toBe('status');
32
- expect(expandField('p')).toBe('priority');
33
- expect(expandField('ct')).toBe('created_at');
34
- expect(expandField('ut')).toBe('updated_at');
35
- expect(expandField('dur')).toBe('duration');
36
- });
37
-
38
- it('應該保留未知縮寫', () => {
39
- expect(expandField('xyz')).toBe('xyz');
40
- });
41
-
42
- it('應該包含至少 30 個欄位縮寫', () => {
43
- const count = Object.keys(FIELD_ABBREVIATIONS).length;
44
- expect(count).toBeGreaterThanOrEqual(30);
45
- });
46
- });
47
-
48
- describe('值代碼化', () => {
49
- it('應該正確編碼狀態值', () => {
50
- expect(encodeValue('status', 'completed')).toBe('C');
51
- expect(encodeValue('status', 'in_progress')).toBe('P');
52
- expect(encodeValue('status', 'pending')).toBe('D');
53
- expect(encodeValue('status', 'blocked')).toBe('B');
54
- });
55
-
56
- it('應該正確編碼優先級', () => {
57
- expect(encodeValue('priority', 'P0')).toBe('0');
58
- expect(encodeValue('priority', 'P1')).toBe('1');
59
- expect(encodeValue('priority', 'P2')).toBe('2');
60
- expect(encodeValue('priority', 'P3')).toBe('3');
61
- });
62
-
63
- it('應該正確編碼 Agent 類型', () => {
64
- expect(encodeValue('agent_type', 'developer')).toBe('dev');
65
- expect(encodeValue('agent_type', 'backend_engineer')).toBe('be');
66
- expect(encodeValue('agent_type', 'frontend_engineer')).toBe('fe');
67
- });
68
-
69
- it('應該保留未知值', () => {
70
- expect(encodeValue('unknown_field', 'unknown_value')).toBe('unknown_value');
71
- });
72
-
73
- it('應該正確解碼狀態值', () => {
74
- expect(decodeValue('status', 'C')).toBe('completed');
75
- expect(decodeValue('status', 'P')).toBe('in_progress');
76
- expect(decodeValue('status', 'D')).toBe('pending');
77
- expect(decodeValue('status', 'B')).toBe('blocked');
78
- });
79
-
80
- it('應該正確解碼優先級', () => {
81
- expect(decodeValue('priority', '0')).toBe('P0');
82
- expect(decodeValue('priority', '1')).toBe('P1');
83
- expect(decodeValue('priority', '2')).toBe('P2');
84
- expect(decodeValue('priority', '3')).toBe('P3');
85
- });
86
-
87
- it('應該包含至少 20 個值代碼', () => {
88
- let totalCodes = 0;
89
- for (const field in VALUE_CODES) {
90
- totalCodes += Object.keys(VALUE_CODES[field as keyof typeof VALUE_CODES]).length;
91
- }
92
- expect(totalCodes).toBeGreaterThanOrEqual(20);
93
- });
94
- });
95
-
96
- describe('時間戳轉換', () => {
97
- it('應該正確縮短時間戳', () => {
98
- expect(shortenTimestamp('2026-02-07T05:30:00Z')).toBe('260207-0530');
99
- expect(shortenTimestamp('2026-12-31T23:59:00Z')).toBe('261231-2359');
100
- expect(shortenTimestamp('2025-01-01T00:00:00Z')).toBe('250101-0000');
101
- });
102
-
103
- it('應該正確展開時間戳', () => {
104
- expect(expandTimestamp('260207-0530')).toBe('2026-02-07T05:30:00Z');
105
- expect(expandTimestamp('261231-2359')).toBe('2026-12-31T23:59:00Z');
106
- expect(expandTimestamp('250101-0000')).toBe('2025-01-01T00:00:00Z');
107
- });
108
-
109
- it('應該正確處理僅日期格式', () => {
110
- expect(expandTimestamp('260207')).toBe('2026-02-07');
111
- expect(expandTimestamp('261231')).toBe('2026-12-31');
112
- });
113
-
114
- it('時間戳轉換應該往返無損', () => {
115
- const original = '2026-02-07T05:30:00Z';
116
- const shortened = shortenTimestamp(original);
117
- const expanded = expandTimestamp(shortened);
118
-
119
- expect(expanded).toBe(original);
120
- });
121
- });
122
- });