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,483 +0,0 @@
1
- #!/usr/bin/env node
2
- // TASK_1903 R2: read-only AUC report per prediction_ledger signal.
3
- //
4
- // Background: main-thread + agent measurement (2026-08-27/09,
5
- // dev/TASK_1903_SIGNAL_AUC_MEASUREMENT.md) found raw EFE (predicted_value)
6
- // carries no measurable relationship to whether a symbol gets touched
7
- // (AUC 0.4784, CI spans 0.5) — the folded composites (g_risk/g_novelty/...)
8
- // mix multiple raw sources whose individual contribution can't be
9
- // attributed after the fact. This card (re-scoped 2026-09-21) added
10
- // heat_raw/co_change_raw/recency_raw columns so the PURE per-signal values
11
- // get persisted going forward; this script is the read-only instrument that
12
- // re-measures AUC per signal once 30 days of that data has accrued.
13
- //
14
- // Method: Mann-Whitney U -> AUC (rank-based, average-rank tie handling),
15
- // bootstrap 95% CI (resample rows with replacement), permutation p-value
16
- // (shuffle labels), and best-achievable single-threshold accuracy scanned
17
- // against the majority-class baseline — same method used for the
18
- // 2026-08-27 baseline this script reproduces as its own control.
19
- //
20
- // Uses Node's built-in `node:sqlite` (experimental, stable since v22.5,
21
- // present on this repo's pinned Node 24) opened READ-ONLY — no new
22
- // dependency added; checked package.json first per the dispatch note, no
23
- // better-sqlite3/sqlite3 present anywhere in the repo.
24
- //
25
- // SAFETY: never opens the live memory.db. Always copies the .db (+ -wal/
26
- // -shm sidecars, since the db runs in WAL mode) to a temp file first and
27
- // reads the copy read-only.
28
- //
29
- // Usage:
30
- // node dev/scripts/probe/prediction-signal-auc.js [--project-path <dir>] [--db <path>] [--json]
31
- //
32
- // --project-path: project root containing .synapse/db/memory.db (default: repo root).
33
- // --db: explicit path to a memory.db (overrides --project-path).
34
- // --json: also print the raw result object as JSON (for tooling).
35
-
36
- 'use strict';
37
-
38
- const fs = require('fs');
39
- const os = require('os');
40
- const path = require('path');
41
- const { DatabaseSync } = require('node:sqlite');
42
-
43
- const REPO_ROOT = path.resolve(__dirname, '..', '..', '..');
44
-
45
- // TASK_1903: pure-signal columns (heat_raw/co_change_raw/recency_raw) were
46
- // added to prediction_ledger on this date. Historical rows before this
47
- // cutover carry the migration's DEFAULT 0.0 for those columns — that is
48
- // "not measured", not "measured as zero" — so pure-signal AUC MUST exclude
49
- // rows predicted before this cutover. The existing predicted_value/
50
- // component_breakdown columns have no such gap and use full history.
51
- const PURE_SIGNAL_CUTOVER_ISO = '2026-09-21T00:00:00Z';
52
- const PURE_SIGNAL_CUTOVER_EPOCH = Math.floor(Date.parse(PURE_SIGNAL_CUTOVER_ISO) / 1000);
53
-
54
- // A4: the re-measure decision rule recorded on the card.
55
- const REMEASURE_DUE_ISO = '2026-10-21T00:00:00Z';
56
- const REMEASURE_MIN_N = 300;
57
- const REMEASURE_REOPEN_AUC = 0.60;
58
-
59
- // 2026-08-27 baseline (main thread + agent-verified, independently
60
- // reproduced in dev/TASK_1903_SIGNAL_AUC_MEASUREMENT.md) for header context.
61
- const BASELINE_2026_08_27 = {
62
- n: 597,
63
- hit: 88,
64
- miss: 509,
65
- majority_baseline_pct: 85.26,
66
- auc_raw_efe: 0.4784,
67
- ci_raw_efe: [0.4134, 0.5450],
68
- };
69
-
70
- function parseArgs(argv) {
71
- const args = { projectPath: REPO_ROOT, db: null, json: false };
72
- for (let i = 0; i < argv.length; i++) {
73
- const a = argv[i];
74
- if (a === '--project-path') args.projectPath = argv[++i];
75
- else if (a === '--db') args.db = argv[++i];
76
- else if (a === '--json') args.json = true;
77
- }
78
- return args;
79
- }
80
-
81
- /** Copy a sqlite db (+ WAL/SHM sidecars if present) to a temp location. */
82
- function copyDbToTemp(dbPath) {
83
- if (!fs.existsSync(dbPath)) {
84
- throw new Error(`memory.db not found at ${dbPath}`);
85
- }
86
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'task1903-auc-'));
87
- const tmpDb = path.join(tmpDir, 'memory.db');
88
- fs.copyFileSync(dbPath, tmpDb);
89
- for (const suffix of ['-wal', '-shm']) {
90
- const side = dbPath + suffix;
91
- if (fs.existsSync(side)) {
92
- fs.copyFileSync(side, tmpDb + suffix);
93
- }
94
- }
95
- return { tmpDir, tmpDb };
96
- }
97
-
98
- /** Rank-based Mann-Whitney AUC with average-rank tie handling. */
99
- function mannWhitneyAuc(values, labels) {
100
- const n = values.length;
101
- const idx = Array.from({ length: n }, (_, i) => i);
102
- idx.sort((a, b) => values[a] - values[b]);
103
-
104
- const ranks = new Array(n);
105
- let i = 0;
106
- while (i < n) {
107
- let j = i;
108
- while (j + 1 < n && values[idx[j + 1]] === values[idx[i]]) j++;
109
- const avgRank = (i + j) / 2 + 1; // 1-based average rank across the tie block
110
- for (let k = i; k <= j; k++) ranks[idx[k]] = avgRank;
111
- i = j + 1;
112
- }
113
-
114
- let rankSumPos = 0;
115
- let nPos = 0;
116
- let nNeg = 0;
117
- for (let k = 0; k < n; k++) {
118
- if (labels[k] === 1) {
119
- rankSumPos += ranks[k];
120
- nPos++;
121
- } else {
122
- nNeg++;
123
- }
124
- }
125
- if (nPos === 0 || nNeg === 0) return { auc: null, nPos, nNeg };
126
- const u1 = rankSumPos - (nPos * (nPos + 1)) / 2;
127
- const auc = u1 / (nPos * nNeg);
128
- return { auc, nPos, nNeg };
129
- }
130
-
131
- function mulberry32(seed) {
132
- let a = seed >>> 0;
133
- return function () {
134
- a |= 0;
135
- a = (a + 0x6d2b79f5) | 0;
136
- let t = Math.imul(a ^ (a >>> 15), 1 | a);
137
- t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
138
- return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
139
- };
140
- }
141
-
142
- function bootstrapCI(values, labels, iterations, rng) {
143
- const n = values.length;
144
- const aucs = [];
145
- for (let it = 0; it < iterations; it++) {
146
- const sv = new Array(n);
147
- const sl = new Array(n);
148
- for (let k = 0; k < n; k++) {
149
- const r = Math.floor(rng() * n);
150
- sv[k] = values[r];
151
- sl[k] = labels[r];
152
- }
153
- const { auc } = mannWhitneyAuc(sv, sl);
154
- if (auc !== null) aucs.push(auc);
155
- }
156
- aucs.sort((a, b) => a - b);
157
- const lo = aucs[Math.floor(0.025 * aucs.length)];
158
- const hi = aucs[Math.min(aucs.length - 1, Math.floor(0.975 * aucs.length))];
159
- return [lo, hi];
160
- }
161
-
162
- function permutationP(values, labels, observedAuc, iterations, rng) {
163
- const n = labels.length;
164
- const shuffled = labels.slice();
165
- let extreme = 0;
166
- const observedDist = Math.abs(observedAuc - 0.5);
167
- for (let it = 0; it < iterations; it++) {
168
- // Fisher-Yates shuffle
169
- for (let k = n - 1; k > 0; k--) {
170
- const j = Math.floor(rng() * (k + 1));
171
- const tmp = shuffled[k];
172
- shuffled[k] = shuffled[j];
173
- shuffled[j] = tmp;
174
- }
175
- const { auc } = mannWhitneyAuc(values, shuffled);
176
- if (auc !== null && Math.abs(auc - 0.5) >= observedDist) extreme++;
177
- }
178
- return extreme / iterations;
179
- }
180
-
181
- /**
182
- * Best achievable single-threshold accuracy, scanned over unique values, both
183
- * directions, PLUS the two degenerate "always predict one class" rules
184
- * (threshold beyond the data range in each direction) — without those, a
185
- * signal with little-to-no variance can score below the majority-class
186
- * baseline, which would misrepresent "no threshold beats the baseline" as
187
- * "the baseline itself is unreachable". The 2026-08-27 baseline report found
188
- * raw EFE's best-threshold accuracy exactly equal to the majority baseline
189
- * (both 85.26%) — that tie is only representable if the always-predict-
190
- * majority rule is in the candidate set.
191
- */
192
- function bestThresholdAccuracy(values, labels) {
193
- const uniq = Array.from(new Set(values)).sort((a, b) => a - b);
194
- const n = values.length;
195
- const nHit = labels.filter((l) => l === 1).length;
196
- let best = Math.max(nHit, n - nHit) / n; // always-predict-majority-class floor
197
- let bestThreshold = null;
198
- let bestDirection = best === nHit / n ? 'always-hit' : 'always-miss';
199
- for (const t of uniq) {
200
- // Direction A: predict hit when value >= t
201
- let correctA = 0;
202
- // Direction B: predict hit when value <= t
203
- let correctB = 0;
204
- for (let k = 0; k < n; k++) {
205
- const predA = values[k] >= t ? 1 : 0;
206
- const predB = values[k] <= t ? 1 : 0;
207
- if (predA === labels[k]) correctA++;
208
- if (predB === labels[k]) correctB++;
209
- }
210
- if (correctA / n > best) {
211
- best = correctA / n;
212
- bestThreshold = t;
213
- bestDirection = '>=';
214
- }
215
- if (correctB / n > best) {
216
- best = correctB / n;
217
- bestThreshold = t;
218
- bestDirection = '<=';
219
- }
220
- }
221
- return { accuracy: best, threshold: bestThreshold, direction: bestDirection };
222
- }
223
-
224
- function medianOf(values) {
225
- const s = values.slice().sort((a, b) => a - b);
226
- const n = s.length;
227
- if (n === 0) return null;
228
- const mid = Math.floor(n / 2);
229
- return n % 2 === 0 ? (s[mid - 1] + s[mid]) / 2 : s[mid];
230
- }
231
-
232
- /**
233
- * Compute the full AUC report for one signal over the rows that have it.
234
- * `predictedAtCutoverEpoch`, when set, drops rows predicted before it —
235
- * used for the pure signals which only became meaningful after TASK_1903.
236
- */
237
- function evaluateSignal(name, rows, extractor, opts) {
238
- opts = opts || {};
239
- const iterations = opts.iterations || 2000;
240
- const seed = opts.seed || 20260921;
241
- const cutover = opts.cutoverEpoch || null;
242
-
243
- const values = [];
244
- const labels = [];
245
- for (const row of rows) {
246
- if (cutover !== null && row.predicted_at < cutover) continue;
247
- const v = extractor(row);
248
- if (v === null || v === undefined || Number.isNaN(v)) continue;
249
- values.push(v);
250
- labels.push(row.is_hit);
251
- }
252
-
253
- const n = values.length;
254
- const nHit = labels.filter((l) => l === 1).length;
255
- const nMiss = n - nHit;
256
- if (n === 0) {
257
- return { signal: name, n: 0, note: 'no rows (cutover filter or missing values)' };
258
- }
259
- const majorityBaseline = Math.max(nHit, nMiss) / n;
260
-
261
- const { auc } = mannWhitneyAuc(values, labels);
262
- const rng1 = mulberry32(seed);
263
- const ci = auc === null ? [null, null] : bootstrapCI(values, labels, iterations, rng1);
264
- const rng2 = mulberry32(seed + 1);
265
- const p = auc === null ? null : permutationP(values, labels, auc, iterations, rng2);
266
- const thresholdResult = bestThresholdAccuracy(values, labels);
267
-
268
- const hitValues = values.filter((_, k) => labels[k] === 1);
269
- const missValues = values.filter((_, k) => labels[k] === 0);
270
-
271
- return {
272
- signal: name,
273
- n,
274
- hit: nHit,
275
- miss: nMiss,
276
- majority_baseline_pct: +(majorityBaseline * 100).toFixed(2),
277
- auc: auc === null ? null : +auc.toFixed(4),
278
- ci_95: ci[0] === null ? null : [+ci[0].toFixed(4), +ci[1].toFixed(4)],
279
- permutation_p: p === null ? null : +p.toFixed(4),
280
- best_threshold_accuracy_pct: +(thresholdResult.accuracy * 100).toFixed(2),
281
- best_threshold: thresholdResult.threshold,
282
- best_threshold_direction: thresholdResult.direction,
283
- hit_median: medianOf(hitValues),
284
- miss_median: medianOf(missValues),
285
- };
286
- }
287
-
288
- /**
289
- * Idempotently add the TASK_1903 pure-signal columns to a (already-copied,
290
- * never the live) db if the running Rust binary hasn't migrated it yet —
291
- * mirrors memory/schema.rs's migrate_prediction_ledger ALTER TABLE pattern
292
- * exactly (additive, default 0.0, silently ignored if already present).
293
- * Opens the COPY briefly in writable mode; the live file is never touched —
294
- * see copyDbToTemp / main(), which always operate on a temp copy first.
295
- */
296
- function ensurePureSignalColumns(dbPath) {
297
- const db = new DatabaseSync(dbPath);
298
- try {
299
- for (const col of ['heat_raw', 'co_change_raw', 'recency_raw']) {
300
- try {
301
- db.exec(`ALTER TABLE prediction_ledger ADD COLUMN ${col} REAL NOT NULL DEFAULT 0.0`);
302
- } catch (e) {
303
- // Column already exists (duplicate column name) — expected on a
304
- // db the live Rust binary has already migrated. Anything else
305
- // would also surface downstream when loadRows queries it.
306
- }
307
- }
308
- } finally {
309
- db.close();
310
- }
311
- }
312
-
313
- function loadRows(dbPath) {
314
- ensurePureSignalColumns(dbPath);
315
- const db = new DatabaseSync(dbPath, { readOnly: true });
316
- try {
317
- const stmt = db.prepare(
318
- `SELECT predicted_value, confidence, component_breakdown,
319
- heat_raw, co_change_raw, recency_raw,
320
- predicted_at, outcome_quality
321
- FROM prediction_ledger
322
- WHERE prediction_type = 'efe'
323
- AND verified = 1
324
- AND predicted_value IS NOT NULL
325
- AND outcome_quality IN ('hit', 'miss')`
326
- );
327
- const rawRows = stmt.all();
328
- return rawRows.map((r) => {
329
- let breakdown = {};
330
- try {
331
- breakdown = JSON.parse(r.component_breakdown || '{}');
332
- } catch (e) {
333
- breakdown = {};
334
- }
335
- return {
336
- predicted_value: r.predicted_value,
337
- confidence: r.confidence,
338
- g_risk: typeof breakdown.g_risk === 'number' ? breakdown.g_risk : null,
339
- g_ambiguity: typeof breakdown.g_ambiguity === 'number' ? breakdown.g_ambiguity : null,
340
- g_novelty: typeof breakdown.g_novelty === 'number' ? breakdown.g_novelty : null,
341
- g_salience: typeof breakdown.g_salience === 'number' ? breakdown.g_salience : null,
342
- complexity_penalty:
343
- typeof breakdown.complexity_penalty === 'number' ? breakdown.complexity_penalty : null,
344
- heat_raw: r.heat_raw,
345
- co_change_raw: r.co_change_raw,
346
- recency_raw: r.recency_raw,
347
- predicted_at: r.predicted_at,
348
- is_hit: r.outcome_quality === 'hit' ? 1 : 0,
349
- };
350
- });
351
- } finally {
352
- db.close();
353
- }
354
- }
355
-
356
- function buildReport(dbPath) {
357
- const rows = loadRows(dbPath);
358
-
359
- const foldedSignals = [
360
- ['raw_efe (predicted_value)', (r) => r.predicted_value, null],
361
- ['confidence', (r) => r.confidence, null],
362
- ['g_risk (heat-dominated composite)', (r) => r.g_risk, null],
363
- ['g_ambiguity', (r) => r.g_ambiguity, null],
364
- ['g_novelty (co-change-dominated composite)', (r) => r.g_novelty, null],
365
- ['g_salience', (r) => r.g_salience, null],
366
- ['complexity_penalty', (r) => r.complexity_penalty, null],
367
- ];
368
-
369
- const pureSignals = [
370
- ['heat_raw (pure Heat)', (r) => r.heat_raw, PURE_SIGNAL_CUTOVER_EPOCH],
371
- ['co_change_raw (pure Co-change)', (r) => r.co_change_raw, PURE_SIGNAL_CUTOVER_EPOCH],
372
- ['recency_raw (pure Recency)', (r) => r.recency_raw, PURE_SIGNAL_CUTOVER_EPOCH],
373
- ];
374
-
375
- const results = [];
376
- for (const [name, extractor, cutover] of foldedSignals) {
377
- results.push(evaluateSignal(name, rows, extractor, { cutoverEpoch: cutover }));
378
- }
379
- for (const [name, extractor, cutover] of pureSignals) {
380
- results.push(evaluateSignal(name, rows, extractor, { cutoverEpoch: cutover }));
381
- }
382
-
383
- return {
384
- baseline_2026_08_27: BASELINE_2026_08_27,
385
- pure_signal_cutover: PURE_SIGNAL_CUTOVER_ISO,
386
- remeasure_rule: {
387
- due: REMEASURE_DUE_ISO,
388
- min_n: REMEASURE_MIN_N,
389
- reopen_if_auc_at_least: REMEASURE_REOPEN_AUC,
390
- description:
391
- 'Any signal with AUC >= 0.60 at n >= 300 (post-cutover rows) by the due date reopens the ' +
392
- 'grounding question; otherwise P3 grounding stays closed (TASK_1903 A4).',
393
- },
394
- total_rows_all_time: rows.length,
395
- results,
396
- };
397
- }
398
-
399
- function printReport(report) {
400
- const b = report.baseline_2026_08_27;
401
- console.log('TASK_1903 — Prediction Signal AUC Report');
402
- console.log('='.repeat(60));
403
- console.log(
404
- `2026-08-27 baseline (control): n=${b.n} (hit=${b.hit}/miss=${b.miss}), ` +
405
- `majority=${b.majority_baseline_pct}%, raw EFE AUC=${b.auc_raw_efe} ` +
406
- `CI[${b.ci_raw_efe[0]}, ${b.ci_raw_efe[1]}]`
407
- );
408
- console.log(
409
- `Pure-signal cutover: ${report.pure_signal_cutover} (rows before this date have ` +
410
- `heat_raw/co_change_raw/recency_raw = migration default 0.0, excluded from pure-signal rows)`
411
- );
412
- console.log(
413
- `Re-measure rule: reopen if any signal AUC >= ${report.remeasure_rule.reopen_if_auc_at_least} ` +
414
- `at n >= ${report.remeasure_rule.min_n} by ${report.remeasure_rule.due}`
415
- );
416
- console.log(`Total ledger rows (all-time, verified efe hit/miss): ${report.total_rows_all_time}`);
417
- console.log('-'.repeat(60));
418
-
419
- const header = [
420
- 'signal',
421
- 'n',
422
- 'hit/miss',
423
- 'baseline%',
424
- 'AUC',
425
- '95% CI',
426
- 'perm p',
427
- 'best-thr acc%',
428
- ];
429
- console.log(header.join(' | '));
430
- for (const r of report.results) {
431
- if (r.n === 0) {
432
- console.log(`${r.signal} | n=0 (${r.note})`);
433
- continue;
434
- }
435
- console.log(
436
- [
437
- r.signal,
438
- r.n,
439
- `${r.hit}/${r.miss}`,
440
- r.majority_baseline_pct,
441
- r.auc,
442
- r.ci_95 ? `[${r.ci_95[0]}, ${r.ci_95[1]}]` : 'n/a',
443
- r.permutation_p,
444
- r.best_threshold_accuracy_pct,
445
- ].join(' | ')
446
- );
447
- }
448
- }
449
-
450
- function main() {
451
- const args = parseArgs(process.argv.slice(2));
452
- const dbPath = args.db || path.join(args.projectPath, '.synapse', 'db', 'memory.db');
453
-
454
- let tmpDir = null;
455
- try {
456
- const copy = copyDbToTemp(dbPath);
457
- tmpDir = copy.tmpDir;
458
- const report = buildReport(copy.tmpDb);
459
- printReport(report);
460
- if (args.json) {
461
- console.log('\n--- JSON ---');
462
- console.log(JSON.stringify(report, null, 2));
463
- }
464
- } finally {
465
- if (tmpDir) {
466
- fs.rmSync(tmpDir, { recursive: true, force: true });
467
- }
468
- }
469
- }
470
-
471
- if (require.main === module) {
472
- main();
473
- }
474
-
475
- module.exports = {
476
- mannWhitneyAuc,
477
- bootstrapCI,
478
- permutationP,
479
- bestThresholdAccuracy,
480
- evaluateSignal,
481
- buildReport,
482
- PURE_SIGNAL_CUTOVER_EPOCH,
483
- };
@@ -1,200 +0,0 @@
1
- #!/usr/bin/env node
2
- // TASK_1903 R4: unit tests for prediction-signal-auc.js's pure functions.
3
- //
4
- // Fixtures per the card's explicit requirement: a perfectly separable
5
- // signal must score AUC ~1.0, and a random (label-independent) signal must
6
- // score AUC ~0.5. Also covers the persist -> read round trip end-to-end via
7
- // a real temp sqlite db (node:sqlite), and the pure-signal cutover filter
8
- // that excludes pre-migration rows (which default to 0.0, not "measured 0").
9
- //
10
- // Run: node --test dev/scripts/probe/prediction-signal-auc.test.js
11
-
12
- 'use strict';
13
-
14
- const fs = require('fs');
15
- const os = require('os');
16
- const path = require('path');
17
- const test = require('node:test');
18
- const assert = require('node:assert/strict');
19
- const { DatabaseSync } = require('node:sqlite');
20
-
21
- const mod = require('./prediction-signal-auc.js');
22
-
23
- function mulberry32(seed) {
24
- let a = seed >>> 0;
25
- return function () {
26
- a |= 0;
27
- a = (a + 0x6d2b79f5) | 0;
28
- let t = Math.imul(a ^ (a >>> 15), 1 | a);
29
- t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
30
- return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
31
- };
32
- }
33
-
34
- test('mannWhitneyAuc: perfectly separable signal scores AUC 1.0', () => {
35
- // All hits strictly greater than all misses -> AUC == 1.0.
36
- const values = [10, 11, 12, 13, 14, 0, 1, 2, 3, 4];
37
- const labels = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0];
38
- const { auc } = mod.mannWhitneyAuc(values, labels);
39
- assert.equal(auc, 1.0);
40
- });
41
-
42
- test('mannWhitneyAuc: perfectly inverted signal scores AUC 0.0', () => {
43
- const values = [0, 1, 2, 3, 4, 10, 11, 12, 13, 14];
44
- const labels = [1, 1, 1, 1, 1, 0, 0, 0, 0, 0];
45
- const { auc } = mod.mannWhitneyAuc(values, labels);
46
- assert.equal(auc, 0.0);
47
- });
48
-
49
- test('mannWhitneyAuc: random (label-independent) signal scores ~0.5 at scale', () => {
50
- const rng = mulberry32(42);
51
- const n = 4000;
52
- const values = [];
53
- const labels = [];
54
- for (let i = 0; i < n; i++) {
55
- values.push(rng()); // uniform noise, unrelated to label
56
- labels.push(rng() < 0.15 ? 1 : 0); // 15% hit rate, matches the real data's imbalance
57
- }
58
- const { auc } = mod.mannWhitneyAuc(values, labels);
59
- assert.ok(
60
- Math.abs(auc - 0.5) < 0.03,
61
- `expected AUC near 0.5 for a random signal at n=${n}, got ${auc}`
62
- );
63
- });
64
-
65
- test('mannWhitneyAuc: tied values are handled via average rank without crashing', () => {
66
- const values = [1, 1, 1, 2, 2, 3];
67
- const labels = [1, 0, 1, 0, 1, 0];
68
- const { auc, nPos, nNeg } = mod.mannWhitneyAuc(values, labels);
69
- assert.equal(nPos, 3);
70
- assert.equal(nNeg, 3);
71
- assert.ok(auc >= 0 && auc <= 1);
72
- });
73
-
74
- test('bestThresholdAccuracy: separable signal achieves 100% accuracy', () => {
75
- const values = [10, 11, 12, 0, 1, 2];
76
- const labels = [1, 1, 1, 0, 0, 0];
77
- const { accuracy } = mod.bestThresholdAccuracy(values, labels);
78
- assert.equal(accuracy, 1.0);
79
- });
80
-
81
- test('bestThresholdAccuracy: never scores below the always-predict-majority floor', () => {
82
- // Same value for every row -> no observed threshold can isolate the single
83
- // hit, so the only candidates that can win are the two degenerate
84
- // "always predict one class" rules. Majority class is miss (4/5 = 80%).
85
- const values = [5, 5, 5, 5, 5];
86
- const labels = [1, 0, 0, 0, 0];
87
- const { accuracy, direction } = mod.bestThresholdAccuracy(values, labels);
88
- assert.equal(accuracy, 0.8, 'majority-class floor (4 miss / 5) must be reachable');
89
- assert.equal(direction, 'always-miss');
90
- });
91
-
92
- test('evaluateSignal: end-to-end on a separable fixture reproduces AUC 1.0 with n and baseline', () => {
93
- const rows = [
94
- { my_signal: 9, predicted_at: 100, is_hit: 1 },
95
- { my_signal: 8, predicted_at: 100, is_hit: 1 },
96
- { my_signal: 1, predicted_at: 100, is_hit: 0 },
97
- { my_signal: 2, predicted_at: 100, is_hit: 0 },
98
- { my_signal: 3, predicted_at: 100, is_hit: 0 },
99
- ];
100
- const result = mod.evaluateSignal('my_signal', rows, (r) => r.my_signal, { iterations: 200 });
101
- assert.equal(result.n, 5);
102
- assert.equal(result.hit, 2);
103
- assert.equal(result.miss, 3);
104
- assert.equal(result.auc, 1);
105
- assert.equal(result.majority_baseline_pct, 60);
106
- assert.equal(result.best_threshold_accuracy_pct, 100);
107
- });
108
-
109
- test('evaluateSignal: pure-signal cutover excludes pre-migration rows (default-0.0 pollution guard)', () => {
110
- const cutover = mod.PURE_SIGNAL_CUTOVER_EPOCH;
111
- const rows = [
112
- // Pre-cutover rows: heat_raw defaults to 0.0 (migration backfill), not a real measurement.
113
- { heat_raw: 0.0, predicted_at: cutover - 1000, is_hit: 1 },
114
- { heat_raw: 0.0, predicted_at: cutover - 2000, is_hit: 0 },
115
- // Post-cutover rows: real values.
116
- { heat_raw: 5.0, predicted_at: cutover + 1000, is_hit: 1 },
117
- { heat_raw: 0.5, predicted_at: cutover + 2000, is_hit: 0 },
118
- ];
119
- const result = mod.evaluateSignal('heat_raw', rows, (r) => r.heat_raw, {
120
- cutoverEpoch: cutover,
121
- iterations: 50,
122
- });
123
- assert.equal(result.n, 2, 'only post-cutover rows should be counted');
124
- });
125
-
126
- test('persistence + report round trip: a real temp sqlite prediction_ledger reproduces expected AUC', () => {
127
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'task1903-roundtrip-'));
128
- const dbPath = path.join(tmpDir, 'memory.db');
129
- try {
130
- const db = new DatabaseSync(dbPath);
131
- db.exec(`
132
- CREATE TABLE prediction_ledger (
133
- id INTEGER PRIMARY KEY AUTOINCREMENT,
134
- prediction_type TEXT NOT NULL,
135
- symbol_id TEXT NOT NULL DEFAULT '',
136
- predicted_at INTEGER NOT NULL,
137
- predicted_value REAL NOT NULL DEFAULT 0.0,
138
- confidence REAL NOT NULL DEFAULT 0.0,
139
- component_breakdown TEXT NOT NULL DEFAULT '{}',
140
- resolution_condition TEXT NOT NULL DEFAULT '',
141
- outcome_symbol_id TEXT NOT NULL DEFAULT '',
142
- outcome_timestamp INTEGER,
143
- outcome_quality TEXT NOT NULL DEFAULT '',
144
- surprise_magnitude REAL,
145
- verified INTEGER NOT NULL DEFAULT 0,
146
- scored INTEGER NOT NULL DEFAULT 0,
147
- rune_id TEXT NOT NULL DEFAULT '',
148
- heat_raw REAL NOT NULL DEFAULT 0.0,
149
- co_change_raw REAL NOT NULL DEFAULT 0.0,
150
- recency_raw REAL NOT NULL DEFAULT 0.0
151
- );
152
- `);
153
- const insert = db.prepare(
154
- `INSERT INTO prediction_ledger
155
- (prediction_type, symbol_id, predicted_at, predicted_value, confidence,
156
- component_breakdown, verified, outcome_quality, heat_raw, co_change_raw, recency_raw)
157
- VALUES ('efe', ?, ?, ?, ?, ?, 1, ?, ?, ?, ?)`
158
- );
159
- const cutover = mod.PURE_SIGNAL_CUTOVER_EPOCH;
160
- const breakdown = JSON.stringify({
161
- g_risk: 1.0,
162
- g_ambiguity: 0.2,
163
- g_novelty: 0.1,
164
- g_salience: 0.05,
165
- complexity_penalty: 0.3,
166
- });
167
- // 6 rows post-cutover: heat_raw perfectly separates hit/miss for this fixture.
168
- const fixtureRows = [
169
- ['sym_a', cutover + 10, 0.5, 0.1, 'hit', 9.0, 1.0, 1.0],
170
- ['sym_b', cutover + 20, 0.5, 0.1, 'hit', 8.0, 1.0, 1.0],
171
- ['sym_c', cutover + 30, 0.5, 0.1, 'miss', 1.0, 1.0, 1.0],
172
- ['sym_d', cutover + 40, 0.5, 0.1, 'miss', 2.0, 1.0, 1.0],
173
- ['sym_e', cutover + 50, 0.5, 0.1, 'miss', 3.0, 1.0, 1.0],
174
- ];
175
- for (const [sym, ts, pv, conf, quality, heat, cc, rec] of fixtureRows) {
176
- insert.run(sym, ts, pv, conf, breakdown, quality, heat, cc, rec);
177
- }
178
- db.close();
179
-
180
- // Read back exactly as the report script's loadRows() would, via buildReport
181
- // against this temp db path (already a "copy" for test purposes).
182
- const report = mod.buildReport(dbPath);
183
- const heatSignal = report.results.find((r) => r.signal.startsWith('heat_raw'));
184
- assert.ok(heatSignal, 'heat_raw signal should be present in the report');
185
- assert.equal(heatSignal.n, 5);
186
- assert.equal(heatSignal.hit, 2);
187
- assert.equal(heatSignal.miss, 3);
188
- assert.equal(heatSignal.auc, 1, 'heat_raw perfectly separates hit/miss in this fixture');
189
-
190
- const efeSignal = report.results.find((r) => r.signal.startsWith('raw_efe'));
191
- assert.equal(efeSignal.n, 5);
192
- assert.equal(
193
- efeSignal.auc,
194
- 0.5,
195
- 'constant predicted_value across every row ties all ranks -> AUC collapses to exactly 0.5'
196
- );
197
- } finally {
198
- fs.rmSync(tmpDir, { recursive: true, force: true });
199
- }
200
- });