kenaz 0.3.18 → 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 (308) 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__/m1-hmap-convid.test.js +1 -124
  30. package/core/.formation/tools/dispatch.js +1 -1
  31. package/core/.formation/tools/loader.js +17 -140
  32. package/core/.formation/tools/post-complete.js +0 -31
  33. package/core/.rule/INDEX.yaml +0 -18
  34. package/core/.rule/general/agent-workflow.yaml +14 -164
  35. package/core/.rule/general/project-self-containment.yaml +8 -19
  36. package/core/.rule/general/rust-verify-target.yaml +6 -5
  37. package/core/.rule/general/synapse-code-intelligence.yaml +3 -3
  38. package/core/.specialist/Amelia/capability.yaml +12 -12
  39. package/core/.specialist/Amelia/workflow.yaml +2 -2
  40. package/core/.specialist/Ansuz/SYSTEM_DOC.md +20 -578
  41. package/core/.specialist/Ansuz/cognitive_principles.yaml +2 -3
  42. package/core/.specialist/Ansuz/concepts/boot_rules_summary.yaml +0 -1
  43. package/core/.specialist/Ansuz/concepts/deep_knowledge_pointers.yaml +1 -2
  44. package/core/.specialist/Ansuz/core.yaml +6 -108
  45. package/core/.specialist/Ansuz/guards/lesson_guards.yaml +0 -3
  46. package/core/.specialist/Ansuz/identity_contract.yaml +0 -1
  47. package/core/.specialist/Ansuz/knowledge.yaml +0 -4
  48. package/core/.specialist/Ansuz/rule.yaml +0 -1
  49. package/core/.specialist/Ansuz/tools/handoff-session-identity.test.js +6 -150
  50. package/core/.specialist/tests/runtime-discovery/README.md +1 -1
  51. package/core/.specialist/tools/__tests__/task-2374-usage-counter.test.js +1 -12
  52. package/core/.specialist/tools/prompt-files.test.js +1 -0
  53. package/core/.specialist/tools/task-bridge.js +1 -66
  54. package/core/.system/README.md +11 -552
  55. package/core/.system/collaboration/README.md +10 -174
  56. package/core/CLAUDE.md +1 -6
  57. package/core/KENAZ_CORE_VERSION +1 -1
  58. package/core/dev/scripts/js-yaml-resolution.test.js +1 -1
  59. package/core/dev/scripts/run-rust-tests.js +9 -45
  60. package/core/dev/scripts/rust-verify-worktree.js +4 -4
  61. package/core/dev/scripts/verify-target-dir.js +6 -6
  62. package/core/plugins/kenaz/INVENTORY.md +8 -8
  63. package/core/plugins/kenaz/commands/architect.md +1 -2
  64. package/core/plugins/kenaz/commands/spec.md +1 -1
  65. package/core/plugins/kenaz/commands//347/224/242/345/223/201.md +1 -1
  66. package/core/plugins/kenaz/guidance.md +1 -1
  67. package/core/plugins/kenaz/scripts/sync.js +1 -1
  68. package/core/plugins/kenaz/skills/architect_agent/SKILL.md +11 -92
  69. package/core/plugins/kenaz/skills/assessment_agent/SKILL.md +0 -1
  70. package/core/plugins/kenaz/skills/backend_engineer/SKILL.md +3 -6
  71. package/core/plugins/kenaz/skills/code_reviewer/SKILL.md +1 -1
  72. package/core/plugins/kenaz/skills/code_reviewer/patterns.yaml +1 -1
  73. package/core/plugins/kenaz/skills/designer/SKILL.md +3 -6
  74. package/core/plugins/kenaz/skills/dev_agent/SKILL.md +30 -491
  75. package/core/plugins/kenaz/skills/developer/SKILL.md +3 -6
  76. package/core/plugins/kenaz/skills/feature_agent/SKILL.md +3 -17
  77. package/core/plugins/kenaz/skills/product_manager/SKILL.md +29 -1064
  78. package/core/plugins/kenaz/skills/qa_engineer/SKILL.md +12 -17
  79. package/core/plugins/kenaz/skills/spec_optimizer/SKILL.md +25 -275
  80. package/core/plugins/kenaz/skills/sre_agent/SKILL.md +3 -6
  81. package/package.json +6 -6
  82. package/core/.claude/commands/archive.md +0 -24
  83. package/core/.claude/commands/init.md +0 -112
  84. package/core/.claude/commands/legacy_dev.md +0 -18
  85. package/core/.claude/commands/product-review.md +0 -131
  86. package/core/.claude/commands/strategy.md +0 -141
  87. package/core/.claude/commands/sunny.md +0 -1
  88. package/core/.claude/commands//347/224/242/345/223/201/346/252/242/350/246/226.md +0 -129
  89. package/core/.claude/commands//351/200/262/345/272/246.md +0 -15
  90. package/core/.claude/hooks/__tests__/substrate.test.js +0 -122
  91. package/core/.claude/hooks/_substrate-paths.js +0 -95
  92. package/core/.claude/hooks/context-check.js +0 -51
  93. package/core/.claude/hooks/fatigue-check.js +0 -52
  94. package/core/.claude/hooks/handoff-snapshot-on-commit.js +0 -154
  95. package/core/.claude/hooks/handoff-snapshot-on-question.js +0 -158
  96. package/core/.claude/hooks/handoff-staleness.js +0 -197
  97. package/core/.claude/hooks/jev-thalamus-context.js +0 -17
  98. package/core/.claude/hooks/jev-thalamus-context.test.js +0 -41
  99. package/core/.claude/hooks/lease-release.js +0 -119
  100. package/core/.claude/hooks/lease-touch.js +0 -96
  101. package/core/.claude/hooks/reflex-feedback.js +0 -5
  102. package/core/.claude/hooks/session-init.ps1 +0 -49
  103. package/core/.claude/hooks/sound-event.js +0 -70
  104. package/core/.claude/hooks/sound-event.sh +0 -37
  105. package/core/.claude/hooks/stream-delta.js +0 -169
  106. package/core/.claude/no-hooks.settings.json +0 -3
  107. package/core/.claude/skills/legacy_dev/SKILL.md +0 -202
  108. package/core/.claude/skills/sunny/SKILL.md +0 -74
  109. package/core/.collaboration/cli/commands/assign.js +0 -39
  110. package/core/.collaboration/cli/commands/claim.js +0 -33
  111. package/core/.collaboration/cli/commands/complete.js +0 -44
  112. package/core/.collaboration/cli/commands/create.js +0 -110
  113. package/core/.collaboration/cli/commands/get.js +0 -83
  114. package/core/.collaboration/cli/commands/index.js +0 -52
  115. package/core/.collaboration/cli/commands/list.js +0 -51
  116. package/core/.collaboration/cli/commands/lock.js +0 -45
  117. package/core/.collaboration/cli/commands/rebuild.js +0 -39
  118. package/core/.collaboration/cli/commands/search.js +0 -61
  119. package/core/.collaboration/cli/commands/stats.js +0 -61
  120. package/core/.collaboration/cli/commands/transfer.js +0 -41
  121. package/core/.collaboration/cli/commands/unlock.js +0 -48
  122. package/core/.collaboration/cli/formatters/help-formatter.js +0 -70
  123. package/core/.collaboration/cli/formatters/index.js +0 -7
  124. package/core/.collaboration/cli/task-cli.js +0 -46
  125. package/core/.collaboration/cli/utils/arg-parser.js +0 -74
  126. package/core/.collaboration/cli/utils/git-user.js +0 -25
  127. package/core/.collaboration/cli/utils/index.js +0 -9
  128. package/core/.collaboration/cli/utils/output.js +0 -10
  129. package/core/.collaboration/config/default.yaml +0 -189
  130. package/core/.collaboration/core/conflict-resolver.js +0 -461
  131. package/core/.collaboration/core/conflict-resolver.test.js +0 -389
  132. package/core/.collaboration/core/migrate-legacy.js +0 -260
  133. package/core/.collaboration/docs/API.md +0 -787
  134. package/core/.collaboration/docs/ARCHITECTURE.md +0 -596
  135. package/core/.collaboration/docs/FAQ.md +0 -695
  136. package/core/.collaboration/docs/MIGRATION.md +0 -804
  137. package/core/.collaboration/docs/examples/README.md +0 -320
  138. package/core/.collaboration/docs/examples/advanced-queries.js +0 -261
  139. package/core/.collaboration/docs/examples/basic-usage.js +0 -184
  140. package/core/.collaboration/docs/examples/team-workflow.js +0 -352
  141. package/core/.failure/agent-execution/FAIL-001-agent-no-output.yaml +0 -391
  142. package/core/.failure/agent-execution/FAIL-007-pm-lead-wrong-team-invocation.yaml +0 -0
  143. package/core/.failure/agent-execution/FAIL-010-phase0-poem-format-skipped.yaml +0 -28
  144. package/core/.failure/agent-execution/FAIL-010-skipping-cognitive-checkpoint-after-verification.yaml +0 -59
  145. package/core/.failure/agent-execution/FAIL-012-grep-shortcut-during-investigation.yaml +0 -85
  146. package/core/.failure/architecture/FAIL-006-python-version-compatibility.yaml +0 -445
  147. package/core/.failure/pipeline/FAIL-003-queue-pollution.yaml +0 -335
  148. package/core/.failure/pipeline/README.md +0 -95
  149. package/core/.failure/retired/FAIL-009-skipping-synapse-pulse-before-code-change.yaml +0 -49
  150. package/core/.failure/tools/USAGE_GUIDE.md +0 -323
  151. package/core/.failure/tools/check_failures.ps1 +0 -387
  152. package/core/.failure/tools/log_failure.ps1 +0 -474
  153. package/core/.formation/.episode-input.json +0 -10
  154. package/core/.formation/.merge-lock +0 -1
  155. package/core/.formation/lead.yaml +0 -118
  156. package/core/.formation/legacy.bak/designer.yaml +0 -57
  157. package/core/.formation/legacy.bak/pm.yaml +0 -57
  158. package/core/.formation/legacy.bak/qa.yaml +0 -57
  159. package/core/.formation/legacy.bak/review.yaml +0 -62
  160. package/core/.formation/legacy.bak/scheduler.yaml +0 -129
  161. package/core/.formation/legacy.bak/sre.yaml +0 -57
  162. package/core/.formation/role-map.yaml +0 -274
  163. package/core/.formation/roles/_shared/modules/code_review.yaml +0 -98
  164. package/core/.formation/roles/_shared/modules/security.yaml +0 -103
  165. package/core/.formation/roles/_shared/modules/testing.yaml +0 -14
  166. package/core/.formation/roles/backend/role.yaml +0 -93
  167. package/core/.formation/roles/code_reviewer/role.yaml +0 -102
  168. package/core/.formation/roles/database_optimizer/role.yaml +0 -107
  169. package/core/.formation/roles/designer/role.yaml +0 -66
  170. package/core/.formation/roles/developer/role.yaml +0 -75
  171. package/core/.formation/roles/frontend/role.yaml +0 -134
  172. package/core/.formation/roles/incident_response/role.yaml +0 -89
  173. package/core/.formation/roles/qa/role.yaml +0 -89
  174. package/core/.formation/roles/security/role.yaml +0 -87
  175. package/core/.formation/roles/sre/role.yaml +0 -66
  176. package/core/.formation/skills/coordinator.yaml +0 -52
  177. package/core/.formation/solo/diagnosis.yaml +0 -78
  178. package/core/.formation/solo/strategy.yaml +0 -121
  179. package/core/.formation/tests/hello.txt +0 -2
  180. package/core/.formation/tools/coordinator.js +0 -350
  181. package/core/.formation/tools/jev-correction.js +0 -214
  182. package/core/.formation/tools/jev-correction.test.js +0 -178
  183. package/core/.formation/tools/log-reader.js +0 -232
  184. package/core/.formation/tools/revert-daemon-state.js +0 -162
  185. package/core/.formation/tools/test-drift.js +0 -148
  186. package/core/.formation/unit/heimdall.yaml +0 -96
  187. package/core/.formation/unit/plan.yaml +0 -67
  188. package/core/.formation/unit/think.yaml +0 -58
  189. package/core/.kenaz/MUNINN_SNAPSHOT9_EPISODE.json +0 -32
  190. package/core/.kenaz/MUNINN_SNAPSHOT9_RUNE.json +0 -23
  191. package/core/.kenaz/MUNINN_SNAPSHOT9_SUMMARY.md +0 -89
  192. package/core/.kenaz/ash_TASK_1428-20260507.json +0 -14
  193. package/core/.kenaz/muninn_episode_write.ps1 +0 -17
  194. package/core/.kenaz/muninn_snapshot11_rune_candidates.md +0 -63
  195. package/core/.kenaz/muninn_snapshot1_rune_candidates.md +0 -49
  196. package/core/.kenaz/runes_TASK_1428.json +0 -57
  197. package/core/.kenaz/tmp_heimdall_proposal_8d3e392.json +0 -13
  198. package/core/.kenaz/tmp_props.json +0 -1
  199. package/core/.kenaz/tmp_sounddrop_t1_prompt.txt +0 -371
  200. package/core/.rule/MECHANIZED.md +0 -61
  201. package/core/.rule/general/cortex-memory-recall.yaml +0 -446
  202. package/core/.rule/general/pipeline.yaml +0 -246
  203. package/core/.rule/general/sunny-access-control.yaml +0 -60
  204. package/core/.rule/general/system-invariants.yaml +0 -231
  205. package/core/.rule/pipeline/PPL-002-completed-task-archival.yaml +0 -528
  206. package/core/.rule/pipeline/auto-update.yaml +0 -282
  207. package/core/.rule/pipeline/task-execution.yaml +0 -365
  208. package/core/.specialist/Ansuz/concepts/phase_protocol.yaml +0 -65
  209. package/core/.specialist/Ansuz/experiments/boot_ablation_replay.js +0 -197
  210. package/core/.specialist/Ansuz/tools/bootstrap-anchors.js +0 -289
  211. package/core/.specialist/Ansuz/workflow.yaml +0 -1225
  212. package/core/.specialist/experiments/rg_benchmark.js +0 -523
  213. package/core/.specialist/experiments/rg_benchmark_results.json +0 -27
  214. package/core/.specialist/tools/jev-optional-context.js +0 -107
  215. package/core/.specialist/tools/jev-optional-context.test.js +0 -152
  216. package/core/.specialist/tools/memory-action-log.js +0 -839
  217. package/core/.specialist/tools/phase-gate.js +0 -3534
  218. package/core/.specialist/tools/phase-gate.test.js +0 -85
  219. package/core/.specialist/tools/precompute-runner.js +0 -444
  220. package/core/.specialist/tools/rule-engine.js +0 -621
  221. package/core/.specialist/tools/task-bridge-jev.test.js +0 -170
  222. package/core/.synapse/memory-shared.json.sync +0 -1
  223. package/core/.system/agent-skills/README.md +0 -724
  224. package/core/.system/cli-tools/README.md +0 -724
  225. package/core/.system/cortex/MODULES.md +0 -1046
  226. package/core/.system/dashboard/FRONTEND.md +0 -812
  227. package/core/.system/dashboard/README.md +0 -737
  228. package/core/.system/failure/README.md +0 -723
  229. package/core/.system/formation/LEGACY_SKILLS.md +0 -974
  230. package/core/.system/formation/POST_COMPLETE.md +0 -602
  231. package/core/.system/formation/README.md +0 -1094
  232. package/core/.system/formation/TOOLS_REFERENCE.md +0 -1145
  233. package/core/.system/kenaz/README.md +0 -787
  234. package/core/.system/memory/README.md +0 -719
  235. package/core/.system/pipeline/README.md +0 -712
  236. package/core/.system/rule/README.md +0 -794
  237. package/core/.system/sunny/README.md +0 -476
  238. package/core/.system/sunny/RULES.json +0 -89
  239. package/core/.system/sunny/knowledge/INDEX.md +0 -37
  240. package/core/.system/sunny/knowledge/agent-teams-api.md +0 -0
  241. package/core/.system/sunny/knowledge/ansuz-specialist.md +0 -500
  242. package/core/.system/sunny/knowledge/claude-cli-spawn.md +0 -177
  243. package/core/.system/sunny/knowledge/collaboration-api.md +0 -925
  244. package/core/.system/sunny/teammates/README.md +0 -107
  245. package/core/.system/sunny/teammates/how_to_use.yaml +0 -101
  246. package/core/.system/sunny/teammates/tools/headless/launcher.js +0 -318
  247. package/core/.system/sunny/teammates/tools/powershell/launcher.js +0 -241
  248. package/core/.system/sunny/teammates/tools/powershell/start.bat +0 -50
  249. package/core/.system/sunny/teammates/tools/utils/env.js +0 -96
  250. package/core/.system/sunny/teammates/tools/utils/format-output.js +0 -329
  251. package/core/.system/sunny/tools.json +0 -101
  252. package/core/dev/scripts/cleanup-queue.js +0 -184
  253. package/core/dev/scripts/cleanup_queue.js +0 -86
  254. package/core/dev/scripts/legacy/README.md +0 -39
  255. package/core/dev/scripts/legacy/dev_agent_scheduler.ps1.bak +0 -536
  256. package/core/dev/scripts/legacy/multi_agent_scheduler.ps1.bak +0 -1978
  257. package/core/dev/scripts/matrix/CLI_README.md +0 -214
  258. package/core/dev/scripts/matrix/README.md +0 -310
  259. package/core/dev/scripts/matrix/package-lock.json +0 -4266
  260. package/core/dev/scripts/matrix/package.json +0 -55
  261. package/core/dev/scripts/matrix/src/abbreviations.ts +0 -295
  262. package/core/dev/scripts/matrix/src/cli/commands/convert.ts +0 -211
  263. package/core/dev/scripts/matrix/src/cli/commands/create.ts +0 -95
  264. package/core/dev/scripts/matrix/src/cli/commands/delete.ts +0 -102
  265. package/core/dev/scripts/matrix/src/cli/commands/list-tags.ts.wip +0 -140
  266. package/core/dev/scripts/matrix/src/cli/commands/manage-tags.ts.wip +0 -173
  267. package/core/dev/scripts/matrix/src/cli/commands/query.ts +0 -261
  268. package/core/dev/scripts/matrix/src/cli/commands/read.ts +0 -77
  269. package/core/dev/scripts/matrix/src/cli/commands/stats.ts.wip +0 -168
  270. package/core/dev/scripts/matrix/src/cli/commands/tokens.ts.wip +0 -126
  271. package/core/dev/scripts/matrix/src/cli/commands/update.ts +0 -147
  272. package/core/dev/scripts/matrix/src/cli/commands/validate.ts +0 -275
  273. package/core/dev/scripts/matrix/src/cli/index.ts +0 -350
  274. package/core/dev/scripts/matrix/src/cli/utils/file-handler.ts +0 -72
  275. package/core/dev/scripts/matrix/src/cli/utils/logger.ts +0 -65
  276. package/core/dev/scripts/matrix/src/index.ts +0 -62
  277. package/core/dev/scripts/matrix/src/indexer/tag-indexer.ts +0 -165
  278. package/core/dev/scripts/matrix/src/parser.ts +0 -281
  279. package/core/dev/scripts/matrix/src/serializer.ts +0 -151
  280. package/core/dev/scripts/matrix/src/validator.ts +0 -301
  281. package/core/dev/scripts/matrix/tests/abbreviations.test.ts +0 -122
  282. package/core/dev/scripts/matrix/tests/cli.test.ts +0 -177
  283. package/core/dev/scripts/matrix/tests/convert.test.ts +0 -143
  284. package/core/dev/scripts/matrix/tests/parser.test.ts +0 -203
  285. package/core/dev/scripts/matrix/tests/query.test.ts +0 -85
  286. package/core/dev/scripts/matrix/tests/serializer.test.ts +0 -197
  287. package/core/dev/scripts/matrix/tests/validate.test.ts +0 -141
  288. package/core/dev/scripts/matrix/tests/validator.test.ts +0 -167
  289. package/core/dev/scripts/matrix/tsconfig.json +0 -20
  290. package/core/dev/scripts/matrix/types/index.d.ts +0 -111
  291. package/core/dev/scripts/matrix/types/index.d.ts.map +0 -1
  292. package/core/dev/scripts/matrix/types/index.js +0 -8
  293. package/core/dev/scripts/matrix/types/index.js.map +0 -1
  294. package/core/dev/scripts/matrix/types/index.ts +0 -124
  295. package/core/dev/scripts/memory-usage-report.js +0 -152
  296. package/core/dev/scripts/probe/ansuz-scaffold-ablation.js +0 -579
  297. package/core/dev/scripts/probe/ansuz-scaffold-ablation.test.js +0 -244
  298. package/core/dev/scripts/probe/hook-latency-probe.js +0 -315
  299. package/core/dev/scripts/probe/hook-latency-probe.test.js +0 -105
  300. package/core/dev/scripts/probe/prediction-signal-auc.js +0 -483
  301. package/core/dev/scripts/probe/prediction-signal-auc.test.js +0 -200
  302. package/core/dev/scripts/test-pty-ws-tunnel.js +0 -229
  303. package/core/dev/scripts/validate_pipeline.js +0 -197
  304. package/core/dev/spikes/task2145-evidence-20261004/backend-log-excerpt.txt +0 -56
  305. package/core/dev/spikes/task2145-evidence-20261004/graph.shadow +0 -0
  306. package/core/dev/spikes/task2145-evidence-20261004/graph.wal +0 -0
  307. package/core/dev/spikes/task2145-evidence-20261004/graph_corrupt_suspect.marker +0 -1
  308. package/core/plugins/kenaz/commands/strategy.md +0 -141
@@ -1,244 +0,0 @@
1
- #!/usr/bin/env node
2
- // TASK_1979 R6: unit tests for ansuz-scaffold-ablation.js's pure functions.
3
- // No git shell-out — the git-show function is injected as a fake.
4
- //
5
- // Run: node --test dev/scripts/probe/ansuz-scaffold-ablation.test.js
6
-
7
- 'use strict';
8
-
9
- const test = require('node:test');
10
- const assert = require('node:assert/strict');
11
- const fs = require('fs');
12
- const os = require('os');
13
- const path = require('path');
14
-
15
- const mod = require('./ansuz-scaffold-ablation.js');
16
-
17
- function makeTempDir() {
18
- return fs.mkdtempSync(path.join(os.tmpdir(), 'ablation-test-'));
19
- }
20
-
21
- test('armRefMap returns the fixed A/B/C -> ref mapping and is not mutable via the export', () => {
22
- const map = mod.armRefMap();
23
- assert.deepEqual(map, { A: '5562fface', B: '1845c7e6b', C: 'a2956ed25' });
24
- map.A = 'mutated';
25
- const map2 = mod.armRefMap();
26
- assert.equal(map2.A, '5562fface', 'mutating the returned copy must not affect the source mapping');
27
- });
28
-
29
- test('buildManifest computes byte accounting and rejects missing fields', () => {
30
- const manifest = mod.buildManifest({
31
- runId: 'run-1',
32
- arm: 'B',
33
- ref: '1845c7e6b',
34
- ansuzMdBytes: 100,
35
- elixirYamlBytes: 200,
36
- bootPromptBytes: 350,
37
- probe1Bytes: 1438,
38
- probe2Bytes: 1435,
39
- timestamp: '2026-09-20T00:00:00.000Z',
40
- });
41
- assert.equal(manifest.run_id, 'run-1');
42
- assert.equal(manifest.arm, 'B');
43
- assert.equal(manifest.ref, '1845c7e6b');
44
- assert.equal(manifest.files['.claude/commands/Ansuz.md'], 100);
45
- assert.equal(manifest.files['.specialist/Ansuz/elixir.yaml'], 200);
46
- assert.equal(manifest.boot_prompt_bytes, 350);
47
- assert.ok(manifest.label.includes('S1 merged'));
48
-
49
- assert.throws(() => mod.buildManifest({ runId: 'run-1' }), /missing required field/);
50
- });
51
-
52
- test('buildBootPrompt embeds ref, arm, and both injected file bodies verbatim', () => {
53
- const prompt = mod.buildBootPrompt({
54
- runId: 'run-1',
55
- arm: 'A',
56
- ref: '5562fface',
57
- ansuzMd: '# fake Ansuz.md body',
58
- elixirYaml: 'fake: elixir body',
59
- });
60
- assert.match(prompt, /\[CANARY:ablation-v1\]/);
61
- assert.match(prompt, /arm A \(ref 5562fface\)/);
62
- assert.match(prompt, /# fake Ansuz\.md body/);
63
- assert.match(prompt, /fake: elixir body/);
64
- });
65
-
66
- test('probe prompts each stay under 1.5 KB per R2', () => {
67
- assert.ok(mod.byteLength(mod.PROBE_1_MD) <= 1536, `probe_1 is ${mod.byteLength(mod.PROBE_1_MD)} bytes`);
68
- assert.ok(mod.byteLength(mod.PROBE_2_MD) <= 1536, `probe_2 is ${mod.byteLength(mod.PROBE_2_MD)} bytes`);
69
- });
70
-
71
- test('buildMeasurementLine enforces the merged REPORT.md + ablation schema', () => {
72
- const line = mod.buildMeasurementLine({
73
- run_id: 'run-1',
74
- arm: 'C',
75
- ref: 'a2956ed25',
76
- probe: '2',
77
- acceptance_met: true,
78
- recall_reflex_fired: true,
79
- scope_verified_before_carding: true,
80
- unauthorized_change: false,
81
- false_completion: false,
82
- turns: 4,
83
- tool_calls: 6,
84
- wall_ms: 52000,
85
- injected_bytes: 12345,
86
- });
87
- // REPORT.md legacy fields present with sane defaults.
88
- assert.equal(line.path, 'ablation');
89
- assert.deepEqual(line.ritual_markers_emitted, []);
90
- assert.equal(line.fallback_triggered, false);
91
- assert.equal(line.boot_wall_clock_ms, 52000);
92
- // Ablation fields.
93
- assert.equal(line.arm, 'C');
94
- assert.equal(line.probe, 2, 'probe must be coerced to a number');
95
- assert.equal(line.injected_bytes, 12345);
96
- assert.ok(line.recorded_at);
97
- });
98
-
99
- test('buildMeasurementLine rejects missing required fields', () => {
100
- assert.throws(
101
- () => mod.buildMeasurementLine({ run_id: 'run-1', arm: 'A' }),
102
- /missing required field/
103
- );
104
- });
105
-
106
- test('buildMeasurementLine rejects an unknown arm', () => {
107
- assert.throws(
108
- () =>
109
- mod.buildMeasurementLine({
110
- run_id: 'run-1',
111
- arm: 'Z',
112
- ref: 'deadbeef',
113
- probe: 1,
114
- acceptance_met: true,
115
- recall_reflex_fired: true,
116
- scope_verified_before_carding: true,
117
- unauthorized_change: false,
118
- false_completion: false,
119
- turns: 1,
120
- tool_calls: 1,
121
- wall_ms: 1,
122
- injected_bytes: 1,
123
- }),
124
- /unknown arm/
125
- );
126
- });
127
-
128
- test('buildMeasurementLine rejects a probe number outside {1,2}', () => {
129
- assert.throws(
130
- () =>
131
- mod.buildMeasurementLine({
132
- run_id: 'run-1',
133
- arm: 'A',
134
- ref: '5562fface',
135
- probe: 3,
136
- acceptance_met: true,
137
- recall_reflex_fired: true,
138
- scope_verified_before_carding: true,
139
- unauthorized_change: false,
140
- false_completion: false,
141
- turns: 1,
142
- tool_calls: 1,
143
- wall_ms: 1,
144
- injected_bytes: 1,
145
- }),
146
- /probe must be 1 or 2/
147
- );
148
- });
149
-
150
- test('prepareArm writes boot_prompt.md/probe_1.md/probe_2.md/manifest.json to a temp dir using an injected git-show (no real git shell-out)', () => {
151
- const tmp = makeTempDir();
152
- const fakeGitShow = (ref, filePath) => {
153
- if (filePath === '.claude/commands/Ansuz.md') return `FAKE ANSUZ.MD for ${ref}`;
154
- if (filePath === '.specialist/Ansuz/elixir.yaml') return `fake_elixir: true # ${ref}`;
155
- throw new Error(`unexpected file requested: ${filePath}`);
156
- };
157
-
158
- const manifest = mod.prepareArm({
159
- runId: 'temp-run',
160
- arm: 'B',
161
- outDir: tmp,
162
- gitShowFn: fakeGitShow,
163
- now: () => '2026-09-20T12:00:00.000Z',
164
- });
165
-
166
- const armDir = path.join(tmp, 'arm-B');
167
- assert.ok(fs.existsSync(path.join(armDir, 'boot_prompt.md')));
168
- assert.ok(fs.existsSync(path.join(armDir, 'probe_1.md')));
169
- assert.ok(fs.existsSync(path.join(armDir, 'probe_2.md')));
170
- assert.ok(fs.existsSync(path.join(armDir, 'manifest.json')));
171
-
172
- const bootPrompt = fs.readFileSync(path.join(armDir, 'boot_prompt.md'), 'utf8');
173
- assert.match(bootPrompt, /FAKE ANSUZ\.MD for 1845c7e6b/);
174
- assert.match(bootPrompt, /fake_elixir: true # 1845c7e6b/);
175
-
176
- const onDisk = JSON.parse(fs.readFileSync(path.join(armDir, 'manifest.json'), 'utf8'));
177
- assert.deepEqual(onDisk, manifest);
178
- assert.equal(manifest.files['.claude/commands/Ansuz.md'], mod.byteLength(`FAKE ANSUZ.MD for 1845c7e6b`));
179
- assert.equal(manifest.generated_at, '2026-09-20T12:00:00.000Z');
180
-
181
- fs.rmSync(tmp, { recursive: true, force: true });
182
- });
183
-
184
- test('prepareArm rejects an unknown arm before touching the filesystem', () => {
185
- const tmp = makeTempDir();
186
- assert.throws(
187
- () =>
188
- mod.prepareArm({
189
- runId: 'temp-run',
190
- arm: 'D',
191
- outDir: tmp,
192
- gitShowFn: () => 'unused',
193
- }),
194
- /unknown arm/
195
- );
196
- assert.deepEqual(fs.readdirSync(tmp), []);
197
- fs.rmSync(tmp, { recursive: true, force: true });
198
- });
199
-
200
- test('readMeasurementsForRun + summarizeRows produce per-arm counts (not only percentages)', () => {
201
- const tmp = makeTempDir();
202
- const measurementsFile = path.join(tmp, 'measurements.jsonl');
203
- const rows = [
204
- mod.buildMeasurementLine({
205
- run_id: 'run-x', arm: 'A', ref: '5562fface', probe: 1,
206
- acceptance_met: true, recall_reflex_fired: false, scope_verified_before_carding: null,
207
- unauthorized_change: false, false_completion: false, turns: 3, tool_calls: 2, wall_ms: 10000, injected_bytes: 500,
208
- }),
209
- mod.buildMeasurementLine({
210
- run_id: 'run-x', arm: 'A', ref: '5562fface', probe: 2,
211
- acceptance_met: false, recall_reflex_fired: null, scope_verified_before_carding: false,
212
- unauthorized_change: true, false_completion: true, turns: 5, tool_calls: 8, wall_ms: 30000, injected_bytes: 500,
213
- }),
214
- mod.buildMeasurementLine({
215
- run_id: 'run-x', arm: 'C', ref: 'a2956ed25', probe: 1,
216
- acceptance_met: true, recall_reflex_fired: true, scope_verified_before_carding: null,
217
- unauthorized_change: false, false_completion: false, turns: 2, tool_calls: 1, wall_ms: 8000, injected_bytes: 200,
218
- }),
219
- // Different run_id — must be excluded by readMeasurementsForRun.
220
- mod.buildMeasurementLine({
221
- run_id: 'run-y', arm: 'B', ref: '1845c7e6b', probe: 1,
222
- acceptance_met: true, recall_reflex_fired: true, scope_verified_before_carding: null,
223
- unauthorized_change: false, false_completion: false, turns: 1, tool_calls: 1, wall_ms: 1000, injected_bytes: 100,
224
- }),
225
- ];
226
- fs.writeFileSync(measurementsFile, rows.map((r) => JSON.stringify(r)).join('\n') + '\n', 'utf8');
227
- // A malformed trailing line must not crash the reader.
228
- fs.appendFileSync(measurementsFile, 'not json\n', 'utf8');
229
-
230
- const read = mod.readMeasurementsForRun('run-x', measurementsFile);
231
- assert.equal(read.length, 3, 'must only include run-x rows and skip the malformed line');
232
-
233
- const summary = mod.summarizeRows(read);
234
- assert.equal(summary.A.n, 2);
235
- assert.equal(summary.A.acceptance_met.true, 1);
236
- assert.equal(summary.A.acceptance_met.false, 1);
237
- assert.equal(summary.A.recall_reflex_fired.na, 1, 'null counts as N/A, not false');
238
- assert.equal(summary.C.n, 1);
239
- assert.equal(summary.C.acceptance_met.true, 1);
240
- assert.equal(summary.B.n, 0, 'B has zero rows for run-x even though it exists for run-y');
241
- assert.equal(summary.A.avg_turns, 4);
242
-
243
- fs.rmSync(tmp, { recursive: true, force: true });
244
- });
@@ -1,315 +0,0 @@
1
- #!/usr/bin/env node
2
- // TASK_1979 R3/R4: hook latency + prompt-cache stability probe.
3
- //
4
- // Measures every hook .claude/settings.json registers for UserPromptSubmit
5
- // and PreToolUse (parsed from settings.json, not hand-listed) against the
6
- // PROJECT copy of .claude/hooks — never the installed kenaz-core copy — by
7
- // running each hook file directly (`node <hook>.js` with CLAUDE_PROJECT_DIR
8
- // set to the repo root and a synthetic JSON payload on stdin), 5x each,
9
- // plus a `node -e 0` floor measurement.
10
- //
11
- // Why invoke the hook file directly instead of re-running the exact
12
- // `node -e "..."` wrapper string from settings.json: that wrapper string is
13
- // shell-quoted for the harness's own (POSIX-shell-like) hook launcher: see
14
- // rune_claude_code_hook_execution_cwd — hooks run with cwd = project dir).
15
- // Shelling it out again here via child_process shell:true would go through
16
- // this machine's OS-default shell (cmd.exe on Windows) whose quoting rules
17
- // differ, which is a probe-validity bug of its own kind (feedback:
18
- // monitor_must_validate_its_own_probe / harness_must_run_the_real_validator).
19
- // The wrapper's only job is `process.chdir(d); require(d+'/.claude/hooks/X.js')`
20
- // — no hook file in this repo gates its stdin-reading main() behind a
21
- // `require.main === module` guard (checked: task-bridge.js,
22
- // turn-context.js all run unconditionally on require/execute), and all
23
- // relative `require('./_x')` calls inside a hook resolve via __dirname, not
24
- // cwd — so invoking the .js file directly with CLAUDE_PROJECT_DIR set is
25
- // behaviorally equivalent and avoids the quoting hazard entirely.
26
- //
27
- // Usage:
28
- // node dev/scripts/probe/hook-latency-probe.js [--runs 5] [--out-dir <dir>]
29
- //
30
- // Writes .kenaz/experiments/ansuz_boot_split/hook-latency-<timestamp>.json
31
- // and prints a latency + cache-stability table to stdout.
32
-
33
- 'use strict';
34
-
35
- const fs = require('fs');
36
- const path = require('path');
37
- const { spawnSync } = require('child_process');
38
-
39
- const REPO_ROOT = path.resolve(__dirname, '..', '..', '..');
40
- const SETTINGS_PATH = path.join(REPO_ROOT, '.claude', 'settings.json');
41
- const EXPERIMENT_DIR = path.join(REPO_ROOT, '.kenaz', 'experiments', 'ansuz_boot_split');
42
- const HOOK_TIMEOUT_MS = 30000;
43
-
44
- // ═══════════════════════════════════════
45
- // settings.json parsing (pure — takes the parsed object, not the path)
46
- // ═══════════════════════════════════════
47
-
48
- function extractHookFilename(command) {
49
- const m = /hooks\/([A-Za-z0-9_.-]+\.js)/.exec(command || '');
50
- return m ? m[1] : null;
51
- }
52
-
53
- function collectHookEntries(settings) {
54
- const hooks = settings && settings.hooks ? settings.hooks : {};
55
- const out = { UserPromptSubmit: [], PreToolUse: [] };
56
-
57
- for (const group of hooks.UserPromptSubmit || []) {
58
- for (const h of group.hooks || []) {
59
- const file = extractHookFilename(h.command);
60
- if (file) out.UserPromptSubmit.push({ event: 'UserPromptSubmit', file, matcher: group.matcher || null, command: h.command });
61
- }
62
- }
63
- for (const group of hooks.PreToolUse || []) {
64
- for (const h of group.hooks || []) {
65
- const file = extractHookFilename(h.command);
66
- if (file) out.PreToolUse.push({ event: 'PreToolUse', file, matcher: group.matcher || null, command: h.command });
67
- }
68
- }
69
- return out;
70
- }
71
-
72
- // ═══════════════════════════════════════
73
- // Synthetic payloads (R3)
74
- // ═══════════════════════════════════════
75
-
76
- function buildPayload(entry, repoRoot, sessionId) {
77
- if (entry.event === 'UserPromptSubmit') {
78
- return { session_id: sessionId, hook_event_name: 'UserPromptSubmit', cwd: repoRoot, prompt: 'hello' };
79
- }
80
- // PreToolUse
81
- const matcher = entry.matcher || '';
82
- if (matcher === 'Read') {
83
- return {
84
- session_id: sessionId,
85
- hook_event_name: 'PreToolUse',
86
- tool_name: 'Read',
87
- tool_input: { file_path: path.join(repoRoot, 'CLAUDE.md') },
88
- cwd: repoRoot,
89
- };
90
- }
91
- if (/Edit|Write/.test(matcher)) {
92
- return {
93
- session_id: sessionId,
94
- hook_event_name: 'PreToolUse',
95
- tool_name: 'Edit',
96
- tool_input: {
97
- file_path: path.join(repoRoot, 'CLAUDE.md'),
98
- old_string: '__hook_latency_probe_nonexistent_string__',
99
- new_string: '__hook_latency_probe_nonexistent_string__',
100
- },
101
- cwd: repoRoot,
102
- };
103
- }
104
- // Bash (default/fallback)
105
- return {
106
- session_id: sessionId,
107
- hook_event_name: 'PreToolUse',
108
- tool_name: 'Bash',
109
- tool_input: { command: 'ls' },
110
- cwd: repoRoot,
111
- };
112
- }
113
-
114
- // ═══════════════════════════════════════
115
- // Runner (impure — spawns child processes)
116
- // ═══════════════════════════════════════
117
-
118
- function runOnce(scriptPath, payload, repoRoot) {
119
- const start = Date.now();
120
- const result = spawnSync(process.execPath, [scriptPath], {
121
- cwd: repoRoot,
122
- env: { ...process.env, CLAUDE_PROJECT_DIR: repoRoot },
123
- input: JSON.stringify(payload),
124
- encoding: 'utf8',
125
- timeout: HOOK_TIMEOUT_MS,
126
- maxBuffer: 16 * 1024 * 1024,
127
- });
128
- const ms = Date.now() - start;
129
- return {
130
- ms,
131
- stdout: result.stdout || '',
132
- stderr: result.stderr || '',
133
- status: result.status,
134
- timedOut: !!result.error && result.error.code === 'ETIMEDOUT',
135
- error: result.error ? result.error.message : null,
136
- };
137
- }
138
-
139
- function runFloorOnce() {
140
- const start = Date.now();
141
- const result = spawnSync(process.execPath, ['-e', '0'], {
142
- encoding: 'utf8',
143
- timeout: HOOK_TIMEOUT_MS,
144
- });
145
- const ms = Date.now() - start;
146
- return { ms, status: result.status, error: result.error ? result.error.message : null };
147
- }
148
-
149
- function median(nums) {
150
- const vals = nums.filter((n) => typeof n === 'number' && !Number.isNaN(n)).slice().sort((a, b) => a - b);
151
- if (!vals.length) return null;
152
- const mid = Math.floor(vals.length / 2);
153
- return vals.length % 2 ? vals[mid] : Math.round((vals[mid - 1] + vals[mid]) / 2);
154
- }
155
-
156
- function byteLength(str) {
157
- return Buffer.byteLength(str || '', 'utf8');
158
- }
159
-
160
- // R4: cache-stability diff summary between two stdout captures.
161
- function diffSummary(a, b) {
162
- if (a === b) return null;
163
- const len = Math.min(a.length, b.length);
164
- let i = 0;
165
- while (i < len && a[i] === b[i]) i++;
166
- return {
167
- first_diff_byte_offset: i,
168
- a_len: a.length,
169
- b_len: b.length,
170
- a_context: a.slice(Math.max(0, i - 20), i + 40),
171
- b_context: b.slice(Math.max(0, i - 20), i + 40),
172
- };
173
- }
174
-
175
- function measureHook(entry, repoRoot, runs) {
176
- const scriptPath = path.join(repoRoot, '.claude', 'hooks', entry.file);
177
- const sessionId = 'abl-hook-latency-1'; // fixed across ALL runs — required for R4 cache-stability comparison
178
- const samples = [];
179
- for (let i = 0; i < runs; i++) {
180
- const payload = buildPayload(entry, repoRoot, sessionId);
181
- samples.push(runOnce(scriptPath, payload, repoRoot));
182
- }
183
-
184
- const msValues = samples.map((s) => s.ms);
185
- const stdoutBytes = samples.map((s) => byteLength(s.stdout));
186
- const nonZeroExit = samples.filter((s) => s.status !== 0).length;
187
- const timeouts = samples.filter((s) => s.timedOut).length;
188
-
189
- const row = {
190
- event: entry.event,
191
- hook: entry.file,
192
- matcher: entry.matcher,
193
- runs,
194
- median_ms: median(msValues),
195
- median_stdout_bytes: median(stdoutBytes),
196
- all_ms: msValues,
197
- nonzero_exit_count: nonZeroExit,
198
- timeout_count: timeouts,
199
- };
200
-
201
- if (entry.event === 'UserPromptSubmit') {
202
- const distinct = new Set(samples.map((s) => s.stdout));
203
- row.cache_stable = distinct.size === 1;
204
- if (!row.cache_stable) {
205
- const outs = samples.map((s) => s.stdout);
206
- row.cache_diff = diffSummary(outs[0], outs[1]);
207
- row.distinct_stdout_variants = distinct.size;
208
- }
209
- } else {
210
- row.cache_stable = null; // N/A per R4 (UserPromptSubmit-only)
211
- }
212
-
213
- return row;
214
- }
215
-
216
- // ═══════════════════════════════════════
217
- // CLI
218
- // ═══════════════════════════════════════
219
-
220
- function parseArgs(argv) {
221
- const opts = { runs: 5, outDir: EXPERIMENT_DIR };
222
- for (let i = 0; i < argv.length; i++) {
223
- const a = argv[i];
224
- const next = () => argv[++i];
225
- if (a === '--runs') opts.runs = parseInt(next(), 10);
226
- else if (a === '--out-dir') opts.outDir = next();
227
- }
228
- return opts;
229
- }
230
-
231
- function printTable(rows, floor) {
232
- console.log('\nHook latency + cache-stability probe (project-copy .claude/hooks only)\n');
233
- console.log(`node -e 0 floor: median ${median(floor.map((f) => f.ms))} ms over ${floor.length} runs`);
234
- console.log('');
235
- const header = ['event', 'hook', 'matcher', 'median_ms', 'median_stdout_B', 'nonzero_exit', 'timeouts', 'cache_stable'];
236
- console.log(header.join(' | '));
237
- for (const r of rows) {
238
- console.log(
239
- [
240
- r.event,
241
- r.hook,
242
- r.matcher || '-',
243
- r.median_ms,
244
- r.median_stdout_bytes,
245
- r.nonzero_exit_count,
246
- r.timeout_count,
247
- r.cache_stable === null ? 'N/A' : r.cache_stable,
248
- ].join(' | ')
249
- );
250
- }
251
- const unstable = rows.filter((r) => r.cache_stable === false);
252
- if (unstable.length) {
253
- console.log('\nCache-INSTABLE UserPromptSubmit hooks (byte-diff summary):');
254
- for (const r of unstable) {
255
- console.log(` ${r.hook}: ${r.distinct_stdout_variants} distinct stdout variants across ${r.runs} runs`);
256
- console.log(` first diff @ byte ${r.cache_diff.first_diff_byte_offset} (len ${r.cache_diff.a_len} vs ${r.cache_diff.b_len})`);
257
- }
258
- }
259
- }
260
-
261
- function main(argv) {
262
- const opts = parseArgs(argv);
263
- if (!fs.existsSync(SETTINGS_PATH)) {
264
- throw new Error(`settings.json not found at ${SETTINGS_PATH}`);
265
- }
266
- const settings = JSON.parse(fs.readFileSync(SETTINGS_PATH, 'utf8'));
267
- const entries = collectHookEntries(settings);
268
- const allEntries = [...entries.UserPromptSubmit, ...entries.PreToolUse];
269
-
270
- const floor = [];
271
- for (let i = 0; i < opts.runs; i++) floor.push(runFloorOnce());
272
-
273
- const rows = allEntries.map((entry) => measureHook(entry, REPO_ROOT, opts.runs));
274
-
275
- printTable(rows, floor);
276
-
277
- const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
278
- fs.mkdirSync(opts.outDir, { recursive: true });
279
- const outPath = path.join(opts.outDir, `hook-latency-${timestamp}.json`);
280
- const report = {
281
- generated_at: new Date().toISOString(),
282
- repo_root: REPO_ROOT,
283
- runs: opts.runs,
284
- node_floor_ms: floor.map((f) => f.ms),
285
- node_floor_median_ms: median(floor.map((f) => f.ms)),
286
- hooks: rows,
287
- };
288
- fs.writeFileSync(outPath, JSON.stringify(report, null, 2), 'utf8');
289
- console.log(`\nWrote ${outPath}`);
290
- return report;
291
- }
292
-
293
- if (require.main === module) {
294
- try {
295
- main(process.argv.slice(2));
296
- } catch (e) {
297
- console.error(`Error: ${e.message}`);
298
- process.exitCode = 1;
299
- }
300
- }
301
-
302
- module.exports = {
303
- extractHookFilename,
304
- collectHookEntries,
305
- buildPayload,
306
- median,
307
- byteLength,
308
- diffSummary,
309
- measureHook,
310
- runOnce,
311
- runFloorOnce,
312
- REPO_ROOT,
313
- SETTINGS_PATH,
314
- EXPERIMENT_DIR,
315
- };
@@ -1,105 +0,0 @@
1
- #!/usr/bin/env node
2
- // TASK_1979: unit tests for hook-latency-probe.js's pure functions
3
- // (settings.json parsing, payload building, median, diff summary).
4
- // No child_process spawning here — that part is exercised manually via
5
- // `node dev/scripts/probe/hook-latency-probe.js` against the live repo.
6
- //
7
- // Run: node --test dev/scripts/probe/hook-latency-probe.test.js
8
-
9
- 'use strict';
10
-
11
- const test = require('node:test');
12
- const assert = require('node:assert/strict');
13
-
14
- const mod = require('./hook-latency-probe.js');
15
-
16
- test('extractHookFilename pulls the .js basename out of a node -e wrapper command', () => {
17
- const cmd = "node -e \"const d=process.env.CLAUDE_PROJECT_DIR;process.chdir(d);require(d+'/.claude/hooks/task-bridge.js')\"";
18
- assert.equal(mod.extractHookFilename(cmd), 'task-bridge.js');
19
- });
20
-
21
- test('extractHookFilename returns null for a command with no hooks/*.js reference', () => {
22
- assert.equal(mod.extractHookFilename('echo hello'), null);
23
- assert.equal(mod.extractHookFilename(''), null);
24
- assert.equal(mod.extractHookFilename(undefined), null);
25
- });
26
-
27
- test('collectHookEntries extracts UserPromptSubmit and PreToolUse entries with matchers, ignoring other events', () => {
28
- const settings = {
29
- hooks: {
30
- UserPromptSubmit: [
31
- { hooks: [{ type: 'command', command: "require(d+'/.claude/hooks/turn-context.js')" }] },
32
- { hooks: [{ type: 'command', command: "require(d+'/.claude/hooks/task-bridge.js')" }] },
33
- ],
34
- PreToolUse: [
35
- { matcher: 'Read', hooks: [{ type: 'command', command: "require(d+'/.claude/hooks/memory-guard.js')" }] },
36
- { matcher: 'Edit|Write', hooks: [{ type: 'command', command: "require(d+'/.claude/hooks/stream-delta.js')" }] },
37
- { matcher: 'Bash', hooks: [{ type: 'command', command: "require(d+'/.claude/hooks/synapse-first-investigation.js')" }] },
38
- ],
39
- PostToolUse: [
40
- { matcher: 'Bash', hooks: [{ type: 'command', command: "require(d+'/.claude/hooks/handoff-snapshot-on-commit.js')" }] },
41
- ],
42
- Stop: [
43
- { hooks: [{ type: 'command', command: "require('.specialist/tools/session.js')" }] },
44
- ],
45
- },
46
- };
47
- const entries = mod.collectHookEntries(settings);
48
- assert.equal(entries.UserPromptSubmit.length, 2);
49
- assert.deepEqual(
50
- entries.UserPromptSubmit.map((e) => e.file),
51
- ['turn-context.js', 'task-bridge.js']
52
- );
53
- assert.equal(entries.PreToolUse.length, 3);
54
- assert.deepEqual(
55
- entries.PreToolUse.map((e) => ({ file: e.file, matcher: e.matcher })),
56
- [
57
- { file: 'memory-guard.js', matcher: 'Read' },
58
- { file: 'stream-delta.js', matcher: 'Edit|Write' },
59
- { file: 'synapse-first-investigation.js', matcher: 'Bash' },
60
- ]
61
- );
62
- // PostToolUse/Stop must not leak in — only UserPromptSubmit + PreToolUse are in scope (R3).
63
- assert.equal(entries.PostToolUse, undefined);
64
- assert.equal(entries.Stop, undefined);
65
- });
66
-
67
- test('buildPayload matches the R3 example shape for UserPromptSubmit and PreToolUse Bash', () => {
68
- const ups = mod.buildPayload({ event: 'UserPromptSubmit' }, '/repo', 'abl-1');
69
- assert.deepEqual(ups, { session_id: 'abl-1', hook_event_name: 'UserPromptSubmit', cwd: '/repo', prompt: 'hello' });
70
-
71
- const bash = mod.buildPayload({ event: 'PreToolUse', matcher: 'Bash' }, '/repo', 'abl-1');
72
- assert.equal(bash.tool_name, 'Bash');
73
- assert.deepEqual(bash.tool_input, { command: 'ls' });
74
- });
75
-
76
- test('buildPayload gives Read a file_path and Edit|Write an editable file_path + strings', () => {
77
- const read = mod.buildPayload({ event: 'PreToolUse', matcher: 'Read' }, '/repo', 'abl-1');
78
- assert.equal(read.tool_name, 'Read');
79
- assert.match(read.tool_input.file_path, /CLAUDE\.md$/);
80
-
81
- const edit = mod.buildPayload({ event: 'PreToolUse', matcher: 'Edit|Write' }, '/repo', 'abl-1');
82
- assert.equal(edit.tool_name, 'Edit');
83
- assert.ok('old_string' in edit.tool_input && 'new_string' in edit.tool_input);
84
- });
85
-
86
- test('median handles empty, single, even, and odd arrays', () => {
87
- assert.equal(mod.median([]), null);
88
- assert.equal(mod.median([5]), 5);
89
- assert.equal(mod.median([1, 2, 3]), 2);
90
- assert.equal(mod.median([1, 2, 3, 4]), 3); // rounds (2+3)/2
91
- assert.equal(mod.median([NaN, 1, 2, 3]), 2, 'non-numeric values are filtered out');
92
- });
93
-
94
- test('diffSummary returns null for identical strings and a byte-offset summary otherwise', () => {
95
- assert.equal(mod.diffSummary('abc', 'abc'), null);
96
- const diff = mod.diffSummary('hello world', 'hello there');
97
- assert.equal(diff.first_diff_byte_offset, 6);
98
- assert.equal(diff.a_len, 11);
99
- assert.equal(diff.b_len, 11);
100
- });
101
-
102
- test('byteLength counts UTF-8 bytes, not JS string length, for multi-byte content', () => {
103
- assert.equal(mod.byteLength('abc'), 3);
104
- assert.ok(mod.byteLength('你好') > 2, 'CJK chars are >1 byte each in UTF-8');
105
- });