ctxtop 4.0.0 → 4.1.1

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 (357) hide show
  1. package/.antigravity-plugin/plugin.json +1 -1
  2. package/.claude-plugin/plugin.json +21 -18
  3. package/CHECKSUMS.sha256 +81 -57
  4. package/LICENSE +27 -27
  5. package/README.md +385 -330
  6. package/SECURITY.md +7 -1
  7. package/assets/hero-demo.svg +1 -1
  8. package/bin/ah-statusline.mjs +30 -0
  9. package/bin/ctxtop.mjs +587 -49
  10. package/config/default_flightcheck.json +19 -0
  11. package/config/modelCatalog.json +952 -213
  12. package/hooks/handlers/compact-lifecycle.mjs +323 -8
  13. package/hooks/handlers/config-change.mjs +402 -0
  14. package/hooks/handlers/hookIo.mjs +56 -0
  15. package/hooks/handlers/hookIpcClient.mjs +8 -4
  16. package/hooks/handlers/post-model-switch.mjs +148 -0
  17. package/hooks/handlers/post-tool-use-core.mjs +394 -0
  18. package/hooks/handlers/post-tool-use.mjs +54 -220
  19. package/hooks/handlers/pre-model-switch.mjs +933 -24
  20. package/hooks/handlers/pre-tool-use-core.mjs +680 -0
  21. package/hooks/handlers/pre-tool-use.mjs +61 -304
  22. package/hooks/handlers/stop-gate.mjs +310 -12
  23. package/hooks/handlers/user-prompt-submit.mjs +334 -1
  24. package/hooks/hooks.json +50 -0
  25. package/hooks/post_tool_use.mjs +24 -3
  26. package/hooks/pre_tool_use.mjs +84 -54
  27. package/hooks/register.js +48 -9
  28. package/hooks/session_start.mjs +11 -1
  29. package/hooks/stop.mjs +11 -1
  30. package/hooks.json +56 -56
  31. package/package.json +12 -4
  32. package/packages/antigravity/package.json +10 -3
  33. package/packages/antigravity/src/adapter.mjs +109 -0
  34. package/packages/antigravity/src/index.mjs +7 -1
  35. package/packages/claude-code/package.json +10 -3
  36. package/packages/claude-code/src/adapter.mjs +194 -0
  37. package/packages/claude-code/src/index.mjs +8 -2
  38. package/packages/claude-code/src/register.js +726 -0
  39. package/packages/core/package.json +6 -2
  40. package/packages/core/src/catalog/detectorCatalog.mjs +558 -0
  41. package/packages/core/src/catalog/index.mjs +1 -0
  42. package/packages/core/src/catalog/safeguardGuide.mjs +412 -0
  43. package/packages/core/src/coach/cacheGravityRouter.mjs +1547 -0
  44. package/packages/core/src/coach/effortShiftDetector.mjs +316 -0
  45. package/packages/core/src/coach/microSkills.mjs +1 -0
  46. package/packages/core/src/coach/promptHygieneGovernor.mjs +1 -0
  47. package/packages/core/src/coach/repoCalibration.mjs +254 -0
  48. package/packages/core/src/coach/resumeToolsetAuditor.mjs +321 -0
  49. package/packages/core/src/coach/savedQuotaLedger.mjs +527 -0
  50. package/packages/core/src/coach/smartCompactAdvisor.mjs +339 -0
  51. package/packages/core/src/coach/stateBatonHydrator.mjs +810 -0
  52. package/packages/core/src/coach/ttlWatchdog.mjs +464 -0
  53. package/packages/core/src/config/anthropicModelCatalog.json +607 -0
  54. package/packages/core/src/config/catalogLoader.mjs +1271 -0
  55. package/packages/core/src/config/horizonConfig.mjs +1055 -0
  56. package/packages/core/src/control/callTree.mjs +338 -0
  57. package/packages/core/src/control/coachLatches.mjs +126 -0
  58. package/packages/core/src/control/controlStateMachine.mjs +205 -0
  59. package/packages/core/src/control/index.mjs +49 -0
  60. package/packages/core/src/control/swarmWorktree.mjs +109 -0
  61. package/packages/core/src/control/toolSuspension.mjs +197 -0
  62. package/packages/core/src/diagnostics/drift_guard.mjs +382 -0
  63. package/packages/core/src/diagnostics/index.mjs +9 -0
  64. package/packages/core/src/diagnostics/micro_skills.mjs +471 -0
  65. package/packages/core/src/diagnostics/prompt_hygiene_governor.mjs +888 -0
  66. package/packages/core/src/economics/billingBlocks.mjs +251 -0
  67. package/packages/core/src/economics/cacheGravity.mjs +371 -0
  68. package/packages/core/src/economics/cliffBreaker.mjs +256 -0
  69. package/packages/core/src/economics/driftLatency.mjs +433 -0
  70. package/packages/core/src/economics/dualTtl.mjs +198 -0
  71. package/packages/core/src/economics/index.mjs +47 -0
  72. package/packages/core/src/economics/retentionRadar.mjs +348 -0
  73. package/packages/core/src/economics/shadowAutoModel.mjs +228 -0
  74. package/packages/core/src/guards/bucketBAlphaBeta.mjs +860 -0
  75. package/packages/core/src/guards/bucketBGamma.mjs +442 -0
  76. package/packages/core/src/guards/bucketBHeuristics.mjs +37 -0
  77. package/packages/core/src/guards/circuitBreakers.mjs +1202 -0
  78. package/packages/core/src/guards/det01_03_shell_secret.mjs +1184 -0
  79. package/packages/core/src/guards/det04_12_thrash_rot.mjs +572 -0
  80. package/packages/core/src/guards/det13_20_mcp_scope.mjs +913 -0
  81. package/packages/core/src/guards/docIndexCore.mjs +446 -0
  82. package/packages/core/src/guards/losslessPostSanitizer.mjs +317 -0
  83. package/packages/core/src/guards/slopsquatGate.mjs +551 -0
  84. package/packages/core/src/index.js +27 -0
  85. package/packages/core/src/index.mjs +25 -1
  86. package/packages/core/src/telemetry/otelExporter.mjs +187 -0
  87. package/packages/core/src/telemetry/scopeLockRegistry.mjs +522 -0
  88. package/packages/core/src/telemetry/sprintMetrics.mjs +327 -0
  89. package/packages/core/src/telemetry/swarmTopology.mjs +152 -0
  90. package/packages/core/src/telemetry/telemetryBridge.mjs +1232 -0
  91. package/packages/core/src/ui/brailleSparkline.mjs +142 -0
  92. package/packages/core/src/ui/costRadarSvg.mjs +276 -0
  93. package/packages/core/src/ui/horizonGrid.mjs +475 -0
  94. package/packages/core/src/ui/horizonPanelHtml.mjs +1502 -0
  95. package/packages/core/src/ui/modViews.mjs +1558 -0
  96. package/packages/core/src/ui/pdfReceiptGenerator.mjs +329 -0
  97. package/packages/core/src/ustf/index.mjs +7 -0
  98. package/packages/core/src/ustf/normalizer.mjs +512 -0
  99. package/packages/core/src/ustf/schema.mjs +186 -0
  100. package/packages/core/src/utils/runtime.mjs +962 -0
  101. package/packages/engine-node/package.json +6 -2
  102. package/packages/engine-node/src/db/index.mjs +58 -0
  103. package/packages/engine-node/src/db/jsonl_fallback.mjs +184 -0
  104. package/packages/engine-node/src/db/probe.mjs +342 -0
  105. package/packages/engine-node/src/db/sqlite_wrapper.mjs +122 -0
  106. package/packages/engine-node/src/index.mjs +11 -1
  107. package/packages/engine-node/src/ipc/client.mjs +447 -0
  108. package/packages/engine-node/src/ipc/fast_client.mjs +191 -0
  109. package/packages/engine-node/src/ipc/index.mjs +24 -0
  110. package/packages/engine-node/src/ipc/protocol.mjs +177 -0
  111. package/packages/engine-node/src/ipc/server.mjs +445 -0
  112. package/packages/engine-node/src/multi_host_mcp.mjs +168 -0
  113. package/packages/engine-node/src/offloader/index.mjs +6 -0
  114. package/packages/engine-node/src/offloader/tool_offloader.mjs +241 -0
  115. package/packages/engine-node/src/rsl/index.mjs +3 -0
  116. package/packages/engine-node/src/sensors/blindspots.mjs +376 -0
  117. package/packages/engine-node/src/sensors/git_merge_tree.mjs +223 -0
  118. package/packages/engine-node/src/sensors/index.mjs +7 -0
  119. package/packages/engine-node/src/vendor/config/default_flightcheck.json +133 -0
  120. package/packages/engine-node/src/vendor/config/modelCatalog.json +1359 -0
  121. package/packages/engine-node/src/vendor/config/platformQuirks.json +19 -0
  122. package/packages/engine-node/src/vendor/core/atomic_io.mjs +124 -0
  123. package/packages/engine-node/src/vendor/core/constants.mjs +2150 -0
  124. package/packages/engine-node/src/vendor/core/doc_indexer.mjs +338 -0
  125. package/packages/engine-node/src/vendor/core/rsl_clash_auditor.mjs +423 -0
  126. package/packages/engine-node/src/vendor/core/rsl_distiller.mjs +394 -0
  127. package/packages/engine-node/src/vendor/core/rsl_ledger.mjs +1029 -0
  128. package/packages/engine-node/src/vendor/core/rsl_triage.mjs +1051 -0
  129. package/packages/engine-node/src/vendor/core/shield_manager.mjs +1417 -0
  130. package/packages/engine-node/src/vendor/core-isomorphic/catalog/detectorCatalog.mjs +558 -0
  131. package/packages/engine-node/src/vendor/core-isomorphic/catalog/index.mjs +1 -0
  132. package/packages/engine-node/src/vendor/core-isomorphic/catalog/safeguardGuide.mjs +412 -0
  133. package/packages/engine-node/src/vendor/core-isomorphic/coach/cacheGravityRouter.mjs +1547 -0
  134. package/packages/engine-node/src/vendor/core-isomorphic/coach/effortShiftDetector.mjs +316 -0
  135. package/packages/engine-node/src/vendor/core-isomorphic/coach/microSkills.mjs +1 -0
  136. package/packages/engine-node/src/vendor/core-isomorphic/coach/promptHygieneGovernor.mjs +1 -0
  137. package/packages/engine-node/src/vendor/core-isomorphic/coach/repoCalibration.mjs +254 -0
  138. package/packages/engine-node/src/vendor/core-isomorphic/coach/resumeToolsetAuditor.mjs +321 -0
  139. package/packages/engine-node/src/vendor/core-isomorphic/coach/savedQuotaLedger.mjs +527 -0
  140. package/packages/engine-node/src/vendor/core-isomorphic/coach/smartCompactAdvisor.mjs +339 -0
  141. package/packages/engine-node/src/vendor/core-isomorphic/coach/stateBatonHydrator.mjs +810 -0
  142. package/packages/engine-node/src/vendor/core-isomorphic/coach/ttlWatchdog.mjs +464 -0
  143. package/packages/engine-node/src/vendor/core-isomorphic/config/anthropicModelCatalog.json +607 -0
  144. package/packages/engine-node/src/vendor/core-isomorphic/config/catalogLoader.mjs +1271 -0
  145. package/packages/engine-node/src/vendor/core-isomorphic/config/horizonConfig.mjs +1055 -0
  146. package/packages/engine-node/src/vendor/core-isomorphic/control/callTree.mjs +338 -0
  147. package/packages/engine-node/src/vendor/core-isomorphic/control/coachLatches.mjs +126 -0
  148. package/packages/engine-node/src/vendor/core-isomorphic/control/controlStateMachine.mjs +205 -0
  149. package/packages/engine-node/src/vendor/core-isomorphic/control/index.mjs +49 -0
  150. package/packages/engine-node/src/vendor/core-isomorphic/control/swarmWorktree.mjs +109 -0
  151. package/packages/engine-node/src/vendor/core-isomorphic/control/toolSuspension.mjs +197 -0
  152. package/packages/engine-node/src/vendor/core-isomorphic/diagnostics/drift_guard.mjs +382 -0
  153. package/packages/engine-node/src/vendor/core-isomorphic/diagnostics/index.mjs +9 -0
  154. package/packages/engine-node/src/vendor/core-isomorphic/diagnostics/micro_skills.mjs +471 -0
  155. package/packages/engine-node/src/vendor/core-isomorphic/diagnostics/prompt_hygiene_governor.mjs +888 -0
  156. package/packages/engine-node/src/vendor/core-isomorphic/economics/billingBlocks.mjs +251 -0
  157. package/packages/engine-node/src/vendor/core-isomorphic/economics/cacheGravity.mjs +371 -0
  158. package/packages/engine-node/src/vendor/core-isomorphic/economics/cliffBreaker.mjs +256 -0
  159. package/packages/engine-node/src/vendor/core-isomorphic/economics/driftLatency.mjs +433 -0
  160. package/packages/engine-node/src/vendor/core-isomorphic/economics/dualTtl.mjs +198 -0
  161. package/packages/engine-node/src/vendor/core-isomorphic/economics/index.mjs +47 -0
  162. package/packages/engine-node/src/vendor/core-isomorphic/economics/retentionRadar.mjs +348 -0
  163. package/packages/engine-node/src/vendor/core-isomorphic/economics/shadowAutoModel.mjs +228 -0
  164. package/packages/engine-node/src/vendor/core-isomorphic/guards/bucketBAlphaBeta.mjs +860 -0
  165. package/packages/engine-node/src/vendor/core-isomorphic/guards/bucketBGamma.mjs +442 -0
  166. package/packages/engine-node/src/vendor/core-isomorphic/guards/bucketBHeuristics.mjs +37 -0
  167. package/packages/engine-node/src/vendor/core-isomorphic/guards/circuitBreakers.mjs +1202 -0
  168. package/packages/engine-node/src/vendor/core-isomorphic/guards/det01_03_shell_secret.mjs +1184 -0
  169. package/packages/engine-node/src/vendor/core-isomorphic/guards/det04_12_thrash_rot.mjs +572 -0
  170. package/packages/engine-node/src/vendor/core-isomorphic/guards/det13_20_mcp_scope.mjs +913 -0
  171. package/packages/engine-node/src/vendor/core-isomorphic/guards/docIndexCore.mjs +446 -0
  172. package/packages/engine-node/src/vendor/core-isomorphic/guards/losslessPostSanitizer.mjs +317 -0
  173. package/packages/engine-node/src/vendor/core-isomorphic/guards/slopsquatGate.mjs +551 -0
  174. package/packages/engine-node/src/vendor/core-isomorphic/index.js +27 -0
  175. package/packages/engine-node/src/vendor/core-isomorphic/telemetry/otelExporter.mjs +187 -0
  176. package/packages/engine-node/src/vendor/core-isomorphic/telemetry/scopeLockRegistry.mjs +522 -0
  177. package/packages/engine-node/src/vendor/core-isomorphic/telemetry/sprintMetrics.mjs +327 -0
  178. package/packages/engine-node/src/vendor/core-isomorphic/telemetry/swarmTopology.mjs +152 -0
  179. package/packages/engine-node/src/vendor/core-isomorphic/telemetry/telemetryBridge.mjs +1232 -0
  180. package/packages/engine-node/src/vendor/core-isomorphic/ui/brailleSparkline.mjs +142 -0
  181. package/packages/engine-node/src/vendor/core-isomorphic/ui/costRadarSvg.mjs +276 -0
  182. package/packages/engine-node/src/vendor/core-isomorphic/ui/horizonGrid.mjs +475 -0
  183. package/packages/engine-node/src/vendor/core-isomorphic/ui/horizonPanelHtml.mjs +1502 -0
  184. package/packages/engine-node/src/vendor/core-isomorphic/ui/modViews.mjs +1558 -0
  185. package/packages/engine-node/src/vendor/core-isomorphic/ui/pdfReceiptGenerator.mjs +329 -0
  186. package/packages/engine-node/src/vendor/core-isomorphic/ustf/index.mjs +7 -0
  187. package/packages/engine-node/src/vendor/core-isomorphic/ustf/normalizer.mjs +512 -0
  188. package/packages/engine-node/src/vendor/core-isomorphic/ustf/schema.mjs +186 -0
  189. package/packages/engine-node/src/vendor/core-isomorphic/utils/runtime.mjs +962 -0
  190. package/packages/mcp/package.json +7 -3
  191. package/packages/mcp/src/server.mjs +115 -14
  192. package/packages/mcp/src/vendor/config/default_flightcheck.json +133 -0
  193. package/packages/mcp/src/vendor/config/modelCatalog.json +1359 -0
  194. package/packages/mcp/src/vendor/config/platformQuirks.json +19 -0
  195. package/packages/mcp/src/vendor/core/atomic_io.mjs +124 -0
  196. package/packages/mcp/src/vendor/core/coach/saved_quota_ledger.mjs +615 -0
  197. package/packages/mcp/src/vendor/core/constants.mjs +2150 -0
  198. package/packages/mcp/src/vendor/core/doc_indexer.mjs +338 -0
  199. package/packages/mcp/src/vendor/core/fts5_output_compressor.mjs +596 -0
  200. package/packages/mcp/src/vendor/core/hook_diagnostics.mjs +158 -0
  201. package/packages/mcp/src/vendor/core/paths.mjs +311 -0
  202. package/packages/mcp/src/vendor/core/session_auditor.mjs +1109 -0
  203. package/packages/mcp/src/vendor/core/sqlite_client.mjs +289 -0
  204. package/packages/mcp/src/vendor/core/telemetry/scope_lock_registry.mjs +578 -0
  205. package/packages/mcp/src/vendor/core-isomorphic/catalog/detectorCatalog.mjs +558 -0
  206. package/packages/mcp/src/vendor/core-isomorphic/catalog/index.mjs +1 -0
  207. package/packages/mcp/src/vendor/core-isomorphic/catalog/safeguardGuide.mjs +412 -0
  208. package/packages/mcp/src/vendor/core-isomorphic/coach/cacheGravityRouter.mjs +1547 -0
  209. package/packages/mcp/src/vendor/core-isomorphic/coach/effortShiftDetector.mjs +316 -0
  210. package/packages/mcp/src/vendor/core-isomorphic/coach/microSkills.mjs +1 -0
  211. package/packages/mcp/src/vendor/core-isomorphic/coach/promptHygieneGovernor.mjs +1 -0
  212. package/packages/mcp/src/vendor/core-isomorphic/coach/repoCalibration.mjs +254 -0
  213. package/packages/mcp/src/vendor/core-isomorphic/coach/resumeToolsetAuditor.mjs +321 -0
  214. package/packages/mcp/src/vendor/core-isomorphic/coach/savedQuotaLedger.mjs +527 -0
  215. package/packages/mcp/src/vendor/core-isomorphic/coach/smartCompactAdvisor.mjs +339 -0
  216. package/packages/mcp/src/vendor/core-isomorphic/coach/stateBatonHydrator.mjs +810 -0
  217. package/packages/mcp/src/vendor/core-isomorphic/coach/ttlWatchdog.mjs +464 -0
  218. package/packages/mcp/src/vendor/core-isomorphic/config/anthropicModelCatalog.json +607 -0
  219. package/packages/mcp/src/vendor/core-isomorphic/config/catalogLoader.mjs +1271 -0
  220. package/packages/mcp/src/vendor/core-isomorphic/config/horizonConfig.mjs +1055 -0
  221. package/packages/mcp/src/vendor/core-isomorphic/control/callTree.mjs +338 -0
  222. package/packages/mcp/src/vendor/core-isomorphic/control/coachLatches.mjs +126 -0
  223. package/packages/mcp/src/vendor/core-isomorphic/control/controlStateMachine.mjs +205 -0
  224. package/packages/mcp/src/vendor/core-isomorphic/control/index.mjs +49 -0
  225. package/packages/mcp/src/vendor/core-isomorphic/control/swarmWorktree.mjs +109 -0
  226. package/packages/mcp/src/vendor/core-isomorphic/control/toolSuspension.mjs +197 -0
  227. package/packages/mcp/src/vendor/core-isomorphic/diagnostics/drift_guard.mjs +382 -0
  228. package/packages/mcp/src/vendor/core-isomorphic/diagnostics/index.mjs +9 -0
  229. package/packages/mcp/src/vendor/core-isomorphic/diagnostics/micro_skills.mjs +471 -0
  230. package/packages/mcp/src/vendor/core-isomorphic/diagnostics/prompt_hygiene_governor.mjs +888 -0
  231. package/packages/mcp/src/vendor/core-isomorphic/economics/billingBlocks.mjs +251 -0
  232. package/packages/mcp/src/vendor/core-isomorphic/economics/cacheGravity.mjs +371 -0
  233. package/packages/mcp/src/vendor/core-isomorphic/economics/cliffBreaker.mjs +256 -0
  234. package/packages/mcp/src/vendor/core-isomorphic/economics/driftLatency.mjs +433 -0
  235. package/packages/mcp/src/vendor/core-isomorphic/economics/dualTtl.mjs +198 -0
  236. package/packages/mcp/src/vendor/core-isomorphic/economics/index.mjs +47 -0
  237. package/packages/mcp/src/vendor/core-isomorphic/economics/retentionRadar.mjs +348 -0
  238. package/packages/mcp/src/vendor/core-isomorphic/economics/shadowAutoModel.mjs +228 -0
  239. package/packages/mcp/src/vendor/core-isomorphic/guards/bucketBAlphaBeta.mjs +860 -0
  240. package/packages/mcp/src/vendor/core-isomorphic/guards/bucketBGamma.mjs +442 -0
  241. package/packages/mcp/src/vendor/core-isomorphic/guards/bucketBHeuristics.mjs +37 -0
  242. package/packages/mcp/src/vendor/core-isomorphic/guards/circuitBreakers.mjs +1202 -0
  243. package/packages/mcp/src/vendor/core-isomorphic/guards/det01_03_shell_secret.mjs +1184 -0
  244. package/packages/mcp/src/vendor/core-isomorphic/guards/det04_12_thrash_rot.mjs +572 -0
  245. package/packages/mcp/src/vendor/core-isomorphic/guards/det13_20_mcp_scope.mjs +913 -0
  246. package/packages/mcp/src/vendor/core-isomorphic/guards/docIndexCore.mjs +446 -0
  247. package/packages/mcp/src/vendor/core-isomorphic/guards/losslessPostSanitizer.mjs +317 -0
  248. package/packages/mcp/src/vendor/core-isomorphic/guards/slopsquatGate.mjs +551 -0
  249. package/packages/mcp/src/vendor/core-isomorphic/index.js +27 -0
  250. package/packages/mcp/src/vendor/core-isomorphic/telemetry/otelExporter.mjs +187 -0
  251. package/packages/mcp/src/vendor/core-isomorphic/telemetry/scopeLockRegistry.mjs +522 -0
  252. package/packages/mcp/src/vendor/core-isomorphic/telemetry/sprintMetrics.mjs +327 -0
  253. package/packages/mcp/src/vendor/core-isomorphic/telemetry/swarmTopology.mjs +152 -0
  254. package/packages/mcp/src/vendor/core-isomorphic/telemetry/telemetryBridge.mjs +1232 -0
  255. package/packages/mcp/src/vendor/core-isomorphic/ui/brailleSparkline.mjs +142 -0
  256. package/packages/mcp/src/vendor/core-isomorphic/ui/costRadarSvg.mjs +276 -0
  257. package/packages/mcp/src/vendor/core-isomorphic/ui/horizonGrid.mjs +475 -0
  258. package/packages/mcp/src/vendor/core-isomorphic/ui/horizonPanelHtml.mjs +1502 -0
  259. package/packages/mcp/src/vendor/core-isomorphic/ui/modViews.mjs +1558 -0
  260. package/packages/mcp/src/vendor/core-isomorphic/ui/pdfReceiptGenerator.mjs +329 -0
  261. package/packages/mcp/src/vendor/core-isomorphic/ustf/index.mjs +7 -0
  262. package/packages/mcp/src/vendor/core-isomorphic/ustf/normalizer.mjs +512 -0
  263. package/packages/mcp/src/vendor/core-isomorphic/ustf/schema.mjs +186 -0
  264. package/packages/mcp/src/vendor/core-isomorphic/utils/runtime.mjs +962 -0
  265. package/packages/mcp/src/vendor/engine-node/db/probe.mjs +342 -0
  266. package/packages/mcp/src/vendor/pro/pro_license.mjs +547 -0
  267. package/packages/pro/package.json +23 -16
  268. package/packages/pro/src/index.mjs +9 -3
  269. package/packages/pro/src/pro_license.mjs +547 -0
  270. package/packages/pro/src/team_finops_pack.mjs +241 -241
  271. package/packages/pro/workers/polar_webhook_worker.mjs +219 -215
  272. package/plugin.json +1 -1
  273. package/sidecars/horizon-daemon/server.mjs +514 -40
  274. package/skills/handoff/SKILL.md +8 -0
  275. package/src/adapters/antigravity/index.mjs +31 -1
  276. package/src/adapters/claude-code/index.mjs +40 -1
  277. package/src/cli/doctor.mjs +11 -2
  278. package/src/cli/horizon_hud.mjs +283 -65
  279. package/src/cli/init.mjs +46 -13
  280. package/src/config/modelCatalog.json +952 -213
  281. package/src/core/bucket_b_runtime.mjs +1200 -0
  282. package/src/core/classifier.mjs +25 -11
  283. package/src/core/coach/circuit_breakers.mjs +84 -6
  284. package/src/core/coach/task_quota_router.mjs +8 -0
  285. package/src/core/code_fold_lite.mjs +169 -0
  286. package/src/core/config.mjs +44 -0
  287. package/src/core/constants.mjs +365 -15
  288. package/src/core/detectors_det01_to_16.mjs +98 -8
  289. package/src/core/doc_indexer.mjs +338 -0
  290. package/src/core/fts5_output_compressor.mjs +272 -35
  291. package/src/core/horizon_config.mjs +42 -0
  292. package/src/core/layer5_hygiene.mjs +118 -0
  293. package/src/core/parser.mjs +88 -12
  294. package/src/core/paths.mjs +3 -2
  295. package/src/core/pro_license.mjs +174 -12
  296. package/src/core/pruner.mjs +7 -146
  297. package/src/core/quota.mjs +14 -2
  298. package/src/core/rsl_clash_auditor.mjs +423 -0
  299. package/src/core/rsl_distiller.mjs +394 -0
  300. package/src/core/rsl_ledger.mjs +1029 -0
  301. package/src/core/rsl_triage.mjs +1051 -0
  302. package/src/core/session_auditor.mjs +1109 -0
  303. package/src/core/shadow_auto_ledger.mjs +205 -0
  304. package/src/core/shield_manager.mjs +1417 -0
  305. package/src/core/sqlite_client.mjs +10 -4
  306. package/src/core/subagents.mjs +18 -2
  307. package/src/core/task_quota_router.mjs +62 -5
  308. package/src/core-isomorphic/catalog/safeguardGuide.mjs +412 -0
  309. package/src/core-isomorphic/coach/cacheGravityRouter.mjs +874 -47
  310. package/src/core-isomorphic/coach/effortShiftDetector.mjs +316 -0
  311. package/src/core-isomorphic/coach/resumeToolsetAuditor.mjs +321 -0
  312. package/src/core-isomorphic/coach/smartCompactAdvisor.mjs +339 -0
  313. package/src/core-isomorphic/coach/ttlWatchdog.mjs +13 -6
  314. package/src/core-isomorphic/config/anthropicModelCatalog.json +405 -1
  315. package/src/core-isomorphic/config/catalogLoader.mjs +549 -46
  316. package/src/core-isomorphic/config/horizonConfig.mjs +47 -1
  317. package/src/core-isomorphic/diagnostics/prompt_hygiene_governor.mjs +266 -0
  318. package/src/core-isomorphic/economics/cacheGravity.mjs +21 -1
  319. package/src/core-isomorphic/economics/cliffBreaker.mjs +98 -12
  320. package/src/core-isomorphic/economics/driftLatency.mjs +114 -0
  321. package/src/core-isomorphic/economics/shadowAutoModel.mjs +228 -0
  322. package/src/core-isomorphic/guards/bucketBAlphaBeta.mjs +860 -0
  323. package/src/core-isomorphic/guards/bucketBGamma.mjs +442 -0
  324. package/src/core-isomorphic/guards/bucketBHeuristics.mjs +37 -0
  325. package/src/core-isomorphic/guards/circuitBreakers.mjs +191 -191
  326. package/src/core-isomorphic/guards/det01_03_shell_secret.mjs +154 -5
  327. package/src/core-isomorphic/guards/det04_12_thrash_rot.mjs +103 -11
  328. package/src/core-isomorphic/guards/det13_20_mcp_scope.mjs +311 -1
  329. package/src/core-isomorphic/guards/docIndexCore.mjs +446 -0
  330. package/src/core-isomorphic/guards/losslessPostSanitizer.mjs +16 -0
  331. package/src/core-isomorphic/guards/slopsquatGate.mjs +551 -0
  332. package/src/core-isomorphic/index.js +1 -0
  333. package/src/core-isomorphic/telemetry/telemetryBridge.mjs +113 -13
  334. package/src/core-isomorphic/ui/horizonPanelHtml.mjs +684 -363
  335. package/src/core-isomorphic/ui/modViews.mjs +95 -15
  336. package/src/diagnostics/claudeHookCapabilities.mjs +426 -0
  337. package/src/diagnostics/doctorEngine.mjs +122 -4
  338. package/src/engine-node/db/probe.mjs +234 -2
  339. package/src/engine-node/index.mjs +3 -0
  340. package/src/engine-node/ipc/fast_client.mjs +191 -0
  341. package/src/engine-node/ipc/index.mjs +2 -0
  342. package/src/engine-node/multi_host_mcp.mjs +168 -0
  343. package/src/engine-node/sensors/blindspots.mjs +13 -6
  344. package/src/hooks/antigravity_rsl_hook.mjs +272 -0
  345. package/src/hooks/claude_rsl_hook.mjs +308 -0
  346. package/src/hooks/daemon_hook_bridge.mjs +256 -0
  347. package/src/hooks/fast_hook_ipc.mjs +295 -0
  348. package/src/hooks/post_invocation.mjs +37 -405
  349. package/src/hooks/post_invocation_core.mjs +623 -0
  350. package/src/hooks/pre_invocation.mjs +103 -958
  351. package/src/hooks/pre_invocation_core.mjs +1830 -0
  352. package/src/hooks/session_start.mjs +39 -1
  353. package/src/utils/modelSwitchTelemetry.mjs +308 -0
  354. package/src/utils/sessionCalibration.mjs +704 -0
  355. package/src/webview/advanced_view.html +34 -18
  356. package/src/webview/horizon_panel.html +4191 -625
  357. package/src/webview/simple_view.html +1 -1
@@ -27,7 +27,8 @@ export class JsonlFallbackDatabaseSync {
27
27
  this.tables = parsed.tables;
28
28
  }
29
29
  }
30
- } catch {
30
+ } catch (readErr) {
31
+ void readErr;
31
32
  // Binary SQLite file or unreadable file in read-only fallback mode -> empty in-memory view
32
33
  }
33
34
  }
@@ -37,7 +38,9 @@ export class JsonlFallbackDatabaseSync {
37
38
  try {
38
39
  fs.mkdirSync(path.dirname(this.dbPath), { recursive: true });
39
40
  fs.writeFileSync(this.dbPath, JSON.stringify({ fallbackFormat: 'json-v1', tables: this.tables }), 'utf8');
40
- } catch {}
41
+ } catch (flushErr) {
42
+ void flushErr;
43
+ }
41
44
  }
42
45
 
43
46
  exec(sql = '') {
@@ -243,7 +246,8 @@ export function openLocalHorizonDb(dbPath, { readOnly = false, readonly = false,
243
246
  if (typeof db.exec === 'function') {
244
247
  db.exec(`PRAGMA busy_timeout = ${timeoutVal};`);
245
248
  }
246
- } catch {
249
+ } catch (pragmaErr) {
250
+ void pragmaErr;
247
251
  // Read-only handles on locked/immutable files may reject pragma mutations; ignore safely.
248
252
  }
249
253
  return db;
@@ -263,7 +267,9 @@ export function openLocalHorizonDb(dbPath, { readOnly = false, readonly = false,
263
267
  } catch (err) {
264
268
  try {
265
269
  if (typeof db.close === 'function') db.close();
266
- } catch {}
270
+ } catch (closeErr) {
271
+ void closeErr;
272
+ }
267
273
  throw err;
268
274
  }
269
275
  }
@@ -252,11 +252,27 @@ export const SWARM_IDLE_TTL_CONSTANTS = Object.freeze({
252
252
  */
253
253
  export function isFrontierSwarmModel(modelId = '') {
254
254
  const desc = resolveModelDescriptor(modelId);
255
- if (desc && (desc.family === 'carbon' || desc.family === 'argon' || desc.family === 'opus' || desc.family === 'sonnet')) {
255
+ if (
256
+ desc &&
257
+ (desc.family === 'carbon' ||
258
+ desc.family === 'argon' ||
259
+ desc.family === 'opus' ||
260
+ desc.family === 'sonnet' ||
261
+ desc.family === 'fable' ||
262
+ desc.family === 'mythos')
263
+ ) {
256
264
  return true;
257
265
  }
258
266
  const norm = normalizeModelId(modelId);
259
- return norm.includes('carbon') || norm.includes('argon') || norm.includes('opus') || norm.includes('pro');
267
+ return (
268
+ norm.includes('carbon') ||
269
+ norm.includes('argon') ||
270
+ norm.includes('opus') ||
271
+ norm.includes('fable') ||
272
+ norm.includes('mythos') ||
273
+ norm.includes('orchestrator') ||
274
+ norm.includes('pro')
275
+ );
260
276
  }
261
277
 
262
278
  /**
@@ -51,7 +51,7 @@ export const MODEL_CATALOG = {
51
51
  },
52
52
  'gemini-4-argon': {
53
53
  id: 'gemini-4-argon',
54
- aliases: ['gemini-4-argon-high', 'gemini-4-argon-medium', 'gemini-4-argon-med', 'gemini-4-argon-low'],
54
+ aliases: ['gemini-4-argon-high', 'gemini-4-argon-medium', 'gemini-4-argon-med', 'gemini-4-argon-low', 'gemini-pro-orchestrator-argon', 'orchestrator-argon'],
55
55
  family: 'argon',
56
56
  label: 'Gemini 4 Argon',
57
57
  supported_efforts: ['low', 'medium', 'high'],
@@ -62,9 +62,23 @@ export const MODEL_CATALOG = {
62
62
  deprecated_after: null,
63
63
  multipliers: { low: 3.0, med: 5.5, medium: 5.5, high: 9.25 }
64
64
  },
65
+ 'gemini-4-hydrogen': {
66
+ id: 'gemini-4-hydrogen',
67
+ aliases: ['gemini-4-hydrogen-xhigh', 'gemini-4-hydrogen-extra-high', 'gemini-4-hydrogen-high', 'gemini-4-hydrogen-medium', 'gemini-4-hydrogen-med', 'gemini-4-hydrogen-low', 'gemini-pro-orchestrator-hydrogen', 'orchestrator-hydrogen'],
68
+ family: 'hydrogen',
69
+ label: 'Gemini 4 Hydrogen',
70
+ supported_efforts: ['low', 'medium', 'high', 'xhigh'],
71
+ caching_mode: 'implicit_only',
72
+ supports_explicit_cache: false,
73
+ antigravity_min_tier: 'pro',
74
+ shared_pool_ceiling: SHARED_1M_CONTEXT_POOL_TOKENS,
75
+ max_output_tokens: 65536,
76
+ deprecated_after: null,
77
+ multipliers: { low: 1.5, med: 2.5, medium: 2.5, high: 4.0, xhigh: 6.0 }
78
+ },
65
79
  'gemini-4-carbon': {
66
80
  id: 'gemini-4-carbon',
67
- aliases: ['gemini-4-carbon-high', 'gemini-4-carbon-medium', 'gemini-4-carbon-med', 'gemini-4-carbon-low', 'M427', 'M437', 'M438'],
81
+ aliases: ['gemini-4-carbon-high', 'gemini-4-carbon-medium', 'gemini-4-carbon-med', 'gemini-4-carbon-low', 'M427', 'M437', 'M438', 'gemini-pro-orchestrator', 'orchestrator', 'orchestrator-carbon', 'antigravity-orchestrator'],
68
82
  family: 'carbon',
69
83
  label: 'Gemini 4 Carbon',
70
84
  supported_efforts: ['low', 'medium', 'high'],
@@ -153,6 +167,34 @@ export const MODEL_CATALOG = {
153
167
  deprecated_after: null,
154
168
  multipliers: { low: 12.0, med: 18.0, medium: 18.0, high: 26.0 }
155
169
  },
170
+ 'claude-mythos-5-2': {
171
+ id: 'claude-mythos-5-2',
172
+ aliases: ['claude-mythos-5.2', 'mythos-5-2', 'mythos-5.2'],
173
+ family: 'mythos',
174
+ label: 'Claude Mythos 5.2',
175
+ supported_efforts: ['low', 'medium', 'high'],
176
+ caching_mode: 'explicit_and_implicit',
177
+ supports_explicit_cache: true,
178
+ antigravity_min_tier: 'ultra',
179
+ shared_pool_ceiling: 1000000,
180
+ max_output_tokens: 128000,
181
+ deprecated_after: null,
182
+ multipliers: { low: 10.0, med: 15.0, medium: 15.0, high: 22.0 }
183
+ },
184
+ 'claude-mythos-5-1': {
185
+ id: 'claude-mythos-5-1',
186
+ aliases: ['claude-mythos-5.1', 'mythos-5-1', 'mythos-5.1'],
187
+ family: 'mythos',
188
+ label: 'Claude Mythos 5.1',
189
+ supported_efforts: ['low', 'medium', 'high'],
190
+ caching_mode: 'explicit_and_implicit',
191
+ supports_explicit_cache: true,
192
+ antigravity_min_tier: 'ultra',
193
+ shared_pool_ceiling: 1000000,
194
+ max_output_tokens: 128000,
195
+ deprecated_after: null,
196
+ multipliers: { low: 12.0, med: 18.0, medium: 18.0, high: 26.0 }
197
+ },
156
198
  'claude-sonnet-4-6': {
157
199
  id: 'claude-sonnet-4-6',
158
200
  family: 'sonnet',
@@ -258,6 +300,7 @@ export const EXPECTED_OUTPUT_TOKENS_BY_EFFORT = Object.freeze({
258
300
  med: 1500,
259
301
  medium: 1500,
260
302
  high: 3500,
303
+ xhigh: 5000,
261
304
  max: 6000
262
305
  });
263
306
 
@@ -325,13 +368,25 @@ export function normalizeModelId(rawModel = '') {
325
368
  if (Object.prototype.hasOwnProperty.call(ANTIGRAVITY_ENUM_ALIASES, lower)) {
326
369
  return ANTIGRAVITY_ENUM_ALIASES[lower];
327
370
  }
371
+ const parenStripped = lower.replace(/\s*\((?:low|medium|med|high|xhigh|extra[\s-]*high|max|minimal|auto|fast|thinking|standard|extended[\s-]*thinking)(?:\s*[,/|]\s*(?:low|medium|med|high|xhigh|extra[\s-]*high|max|minimal|auto|fast|thinking|standard|extended[\s-]*thinking))*\)\s*$/i, '').trim();
372
+ const parenSlug = parenStripped.replace(/[()]+/g, ' ').replace(/\s+/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '').replace(/-(xhigh|extra-high|high|medium|med|low)$/i, '');
373
+ if (Object.prototype.hasOwnProperty.call(ANTIGRAVITY_ENUM_ALIASES, parenSlug)) {
374
+ return ANTIGRAVITY_ENUM_ALIASES[parenSlug];
375
+ }
376
+ if (lower.includes('orchestrator-argon') || parenSlug.includes('orchestrator-argon')) return 'gemini-4-argon';
377
+ if (lower.includes('orchestrator-hydrogen') || parenSlug.includes('orchestrator-hydrogen')) return 'gemini-4-hydrogen';
378
+ if (lower.includes('orchestrator') || parenSlug.includes('orchestrator')) return 'gemini-4-carbon';
328
379
  if (lower.includes('carbon-cyber-permissive')) return 'gemini-4-carbon-cyber-permissive';
329
380
  if (lower.includes('carbon')) return 'gemini-4-carbon';
330
381
  if (lower.includes('flash')) return 'gemini-3.8-flash';
331
382
  if (lower.includes('argon')) return 'gemini-4-argon';
383
+ if (lower.includes('hydrogen')) return 'gemini-4-hydrogen';
332
384
  if (lower.includes('fable-5-2') || lower.includes('fable-5.2')) return 'claude-fable-5-2';
333
385
  if (lower.includes('fable-5-1') || lower.includes('fable-5.1')) return 'claude-fable-5-1';
334
386
  if (lower.includes('fable')) return 'claude-fable-5-2';
387
+ if (lower.includes('mythos-5-2') || lower.includes('mythos-5.2')) return 'claude-mythos-5-2';
388
+ if (lower.includes('mythos-5-1') || lower.includes('mythos-5.1')) return 'claude-mythos-5-1';
389
+ if (lower.includes('mythos')) return 'claude-mythos-5-2';
335
390
  if (lower.includes('haiku-5-5') || lower.includes('haiku-5.5')) return 'claude-haiku-5-5';
336
391
  if (lower.includes('haiku-4-5') || lower.includes('haiku-4.5')) return 'claude-haiku-4-5';
337
392
  if (lower.includes('haiku')) return 'claude-haiku-5-5';
@@ -372,6 +427,7 @@ export function normalizeEffortTier(rawEffort = '') {
372
427
  const lower = String(rawEffort || '').toLowerCase().trim();
373
428
  if (lower === 'low' || lower === 'min') return 'low';
374
429
  if (lower === 'medium' || lower === 'med') return 'medium';
430
+ if (lower === 'xhigh' || lower === 'extra-high' || lower === 'extra high') return 'xhigh';
375
431
  if (lower === 'high' || lower === 'max') return 'high';
376
432
  return 'high';
377
433
  }
@@ -576,15 +632,16 @@ export function classifyTaskComplexity(promptOrOptions = {}, maybeOptions = {})
576
632
 
577
633
  if (hasLoopSignal) {
578
634
  const isFlashLow = activeModel === 'gemini-3.8-flash' && activeEffort === 'low';
635
+ const isHydrogenLow = activeModel === 'gemini-4-hydrogen' && activeEffort === 'low';
579
636
  const isArgonLow = activeModel === 'gemini-4-argon' && activeEffort === 'low';
580
637
  const isCarbonLow = activeModel.includes('carbon') && activeEffort === 'low';
581
- if (isFlashLow || isArgonLow || isCarbonLow || recommendedModel === 'gemini-3.8-flash') {
638
+ if (isFlashLow || isHydrogenLow || isArgonLow || isCarbonLow || recommendedModel === 'gemini-3.8-flash') {
582
639
  loopEscalated = true;
583
640
  escalationReason = det01Count >= 2
584
641
  ? `DET-01 retry churn (${det01Count} consecutive failures)`
585
642
  : `DET-02 file-hash edit oscillation (${det02Count} flips)`;
586
643
  recommendedModel = isActiveCarbon ? activeModel : 'gemini-4-argon';
587
- recommendedEffort = (isArgonLow || isCarbonLow) && det01Count >= 3 ? 'high' : 'medium';
644
+ recommendedEffort = (isArgonLow || isCarbonLow || isHydrogenLow) && det01Count >= 3 ? 'high' : 'medium';
588
645
  if (complexityTier === 'LOW') {
589
646
  complexityTier = 'MEDIUM';
590
647
  }
@@ -651,7 +708,7 @@ export function resolveReadDiscountFactor(modelId = 'gemini-4-argon', options =
651
708
  /**
652
709
  * Closed-form prefix break-even calculator ($C^*$) for both quota-weight parity pairs
653
710
  * (`Argon -> Flash` = 3,529 @ 95%, 4,286 @ 90%; `Carbon -> Flash` = 3,529 @ 95%, 4,286 @ 90%)
654
- * and Anthropic explicit-cache USD pairs (`Opus 5.5 -> Sonnet 5.5` = 6,522, `Opus 4.6 -> Sonnet 4.6` = 4,615).
711
+ * and Anthropic explicit-cache USD pairs (computed dynamically from catalog pricing rates).
655
712
  */
656
713
  export function computeClosedFormBreakEven({
657
714
  currentModel = 'gemini-4-argon',
@@ -0,0 +1,412 @@
1
+ /**
2
+ * @file src/core-isomorphic/catalog/safeguardGuide.mjs
3
+ * Plain-English (grade 10-11) guidance for every Highbeam safeguard and learned rule.
4
+ *
5
+ * Every safeguard is either:
6
+ * - "action" -> something the developer should look at or do (what happened + what to do + what to avoid)
7
+ * - "info" -> handled automatically; no action needed
8
+ *
9
+ * Pure JS / ESM with strictly 0 node:* imports (isomorphic: daemon, CLI, and webview-safe).
10
+ */
11
+
12
+ /** Returns the last path segment of a Windows or POSIX path (never truncates mid-word). */
13
+ export function safeBaseName(p) {
14
+ const s = String(p || '').trim();
15
+ if (!s) return '';
16
+ const parts = s.split(/[\\/]+/).filter(Boolean);
17
+ return parts.length ? parts[parts.length - 1] : s;
18
+ }
19
+
20
+ /** Strips emoji / pictographs and collapses whitespace so mono-tag rows stay clean. */
21
+ export function stripEmoji(text) {
22
+ return String(text || '')
23
+ .replace(/[\u{1F000}-\u{1FAFF}\u{2600}-\u{27BF}\u{FE0F}\u{200D}]/gu, '')
24
+ .replace(/\s+/g, ' ')
25
+ .trim();
26
+ }
27
+
28
+ const g = (title, kind, issue, doText, avoidText) =>
29
+ Object.freeze({ title, kind, issue, doText, avoidText });
30
+
31
+ /**
32
+ * Guide for the canonical DET-01..DET-32 catalog (what the guard watches).
33
+ * `{file}` is replaced with a clean file name when one is known.
34
+ */
35
+ export const SAFEGUARD_GUIDE = Object.freeze({
36
+ 'DET-01': g(
37
+ 'Unsafe Git or shell command blocked', 'action',
38
+ 'The AI tried to run a command that can destroy work, such as git reset --hard, push --force, --no-verify, or rm -rf.',
39
+ 'Read the command in chat. Run it yourself only if you really want to overwrite work.',
40
+ 'Avoid letting the AI force-push or bypass Git hooks without checking first.'
41
+ ),
42
+ 'DET-02': g(
43
+ 'Secret or .env file protected', 'action',
44
+ 'Highbeam stopped a read or paste of credentials (.env files, SSH keys, API tokens) so secrets stay out of the chat.',
45
+ 'Use a placeholder or .env.example instead. If a real key was pasted into chat, replace that key.',
46
+ 'Avoid pasting real keys or tokens into the chat.'
47
+ ),
48
+ 'DET-03': g(
49
+ 'Lockfile or migration changed', 'action',
50
+ '{file} is a package lockfile or database migration, and it changed.',
51
+ 'Check that you meant to update dependencies or the database. If not, undo it with git checkout -- "{file}".',
52
+ 'Avoid committing lockfile or migration changes you did not ask for.'
53
+ ),
54
+ 'DET-04': g(
55
+ 'Same command failed 3 times', 'action',
56
+ 'The AI ran the same failing command three times in a row without changing its approach.',
57
+ 'Read the first error message and point the AI at the real cause, or switch to a stronger model.',
58
+ 'Avoid letting the AI keep retrying the same command.'
59
+ ),
60
+ 'DET-05': g(
61
+ 'Big deletion, weaker tests, or edit loop', 'action',
62
+ 'The AI deleted a large part of {file}, removed test checks, or kept flipping between two versions.',
63
+ 'Run git diff -- "{file}" and make sure no real code or test checks were removed just to make tests pass.',
64
+ 'Avoid accepting more edits until you know what was removed.'
65
+ ),
66
+ 'DET-06': g(
67
+ 'File read again or edited before reading', 'action',
68
+ 'The AI re-read {file} when nothing changed, or edited a file it had not read first.',
69
+ 'Ask the AI to read the file in small line ranges (StartLine and EndLine) before it edits.',
70
+ 'Avoid letting the AI edit files it has not read.'
71
+ ),
72
+ 'DET-07': g(
73
+ 'Long command output trimmed', 'info',
74
+ 'A very long terminal log was shortened to its errors and summary. The full log is saved on disk.',
75
+ 'No action needed.',
76
+ 'Nothing to avoid.'
77
+ ),
78
+ 'DET-08': g(
79
+ 'Model switch held while cache is warm', 'info',
80
+ 'Switching models now would cost more because your prompt cache is still discounted. Highbeam waits for the cache to cool.',
81
+ 'No action needed.',
82
+ 'Nothing to avoid.'
83
+ ),
84
+ 'DET-09': g(
85
+ 'Rule file change queued', 'info',
86
+ 'A non-urgent edit to AGENTS.md, CLAUDE.md, or .mcp.json is waiting so it does not erase your cache discount.',
87
+ 'No action needed. It will be applied after the cache timer ends or after /compact.',
88
+ 'Nothing to avoid.'
89
+ ),
90
+ 'DET-10': g(
91
+ 'Idle cache timer check', 'info',
92
+ 'Highbeam saves a short progress summary before your 5-minute prompt cache runs out while you are idle.',
93
+ 'No action needed.',
94
+ 'Nothing to avoid.'
95
+ ),
96
+ 'DET-11': g(
97
+ 'Old file copies or a missing file path', 'action',
98
+ 'Old copies of edited files are filling memory, or the AI mentioned a file that does not exist.',
99
+ 'Check that the file path is real, or run /compact to clear old copies.',
100
+ 'Avoid trusting file names the AI mentions without checking them.'
101
+ ),
102
+ 'DET-12': g(
103
+ 'Near a pricing jump or stuck background process', 'action',
104
+ 'Context is close to 98,000 tokens, where pricing jumps on this model, or a background process is still running.',
105
+ 'Run /compact before your next message, and stop any background process you do not need.',
106
+ 'Avoid sending large new files into chat right now.'
107
+ ),
108
+ 'DET-13': g(
109
+ 'Unused tools load at the start of every chat', 'action',
110
+ 'Connected MCP servers add large tool lists to every turn, even when you do not use them.',
111
+ 'Set unused MCP servers to load only when needed, or turn them off for this project.',
112
+ 'Avoid keeping MCP servers on that you do not use.'
113
+ ),
114
+ 'DET-14': g(
115
+ 'Code changed without running tests', 'action',
116
+ 'Source files were edited, but the tests have not been run to check the change.',
117
+ 'Ask the AI to run your test command before it finishes or you commit.',
118
+ 'Avoid committing changes that have not been tested.'
119
+ ),
120
+ 'DET-15': g(
121
+ 'Unfinished TODO left in code', 'action',
122
+ 'The AI left TODO notes or placeholder code in {file}.',
123
+ 'Open {file} and ask the AI to finish any unfinished parts.',
124
+ 'Avoid committing placeholder code.'
125
+ ),
126
+ 'DET-16': g(
127
+ 'Helper agents limited to save quota', 'info',
128
+ 'Highbeam limited how many helper agents run at once because your quota use passed 80%.',
129
+ 'No action needed.',
130
+ 'Nothing to avoid.'
131
+ ),
132
+ 'DET-17': g(
133
+ 'Waiting for edits to finish before suggesting /compact', 'info',
134
+ 'Highbeam is holding back compact suggestions until your current multi-file edit is done.',
135
+ 'No action needed.',
136
+ 'Nothing to avoid.'
137
+ ),
138
+ 'DET-18': g(
139
+ 'Unsafe editor or hook setting blocked', 'action',
140
+ 'An edit to {file} tried to turn on auto-approval or run remote shell commands.',
141
+ 'Open {file} and reject any change you did not ask for.',
142
+ 'Avoid approving changes to settings or hook files you have not read.'
143
+ ),
144
+ 'DET-19': g(
145
+ 'Hidden characters removed from helper text', 'info',
146
+ 'Invisible control characters were removed from outside text before they could steer the AI.',
147
+ 'No action needed.',
148
+ 'Nothing to avoid.'
149
+ ),
150
+ 'DET-20': g(
151
+ 'Two agents editing the same file, or quota full', 'action',
152
+ 'More than one AI agent tried to edit {file} at the same time, or your 5-hour quota is used up.',
153
+ 'Let one agent finish before the next one edits {file}, or give each agent its own files.',
154
+ 'Avoid running parallel agents on the same file.'
155
+ ),
156
+ 'DET-21': Object.freeze({
157
+ title: 'Deprecated alias of the thinking-loop guard', kind: 'info', hidden: true,
158
+ issue: 'Old name for the thinking-loop guard.', doText: 'No action needed.', avoidText: 'Nothing to avoid.'
159
+ }),
160
+ 'DET-22': g(
161
+ 'Repeated back-and-forth edits', 'action',
162
+ 'The AI undid and redid changes in {file} over the last few turns.',
163
+ 'Run git diff -- "{file}" to see what changed, then give the AI one clear goal.',
164
+ 'Avoid giving the AI conflicting instructions for the same file.'
165
+ ),
166
+ 'DET-23': g(
167
+ 'Errors may be hidden in {file}', 'action',
168
+ 'The last edit to {file} added an empty catch block or a linter-ignore comment, or removed error handling. That can hide crashes.',
169
+ 'Run git diff -- "{file}" and check that errors are still logged or handled. If the AI only moved error handling into a helper, you can keep going.',
170
+ 'Avoid approving more changes until you know no error handling was lost.'
171
+ ),
172
+ 'DET-24': g(
173
+ 'Long chat may be less accurate', 'action',
174
+ 'Chats over 30 turns collect old instructions that can make the AI less accurate.',
175
+ 'Save your progress to task.md, then run /compact at your next stopping point.',
176
+ 'Avoid starting a new, unrelated task in this same long chat.'
177
+ ),
178
+ 'DET-25': g(
179
+ 'Progress snapshot saved', 'info',
180
+ 'Your context passed 70,000 tokens, so Highbeam saved a recovery snapshot in the background.',
181
+ 'No action needed.',
182
+ 'Nothing to avoid.'
183
+ ),
184
+ 'DET-26': g(
185
+ 'Prompt asks for many things at once', 'action',
186
+ 'Asking for four or more separate goals in one message raises the chance the AI misses one.',
187
+ 'Split the work into steps, or use /plan so each part is checked off in order.',
188
+ 'Avoid bundling unrelated changes into one prompt.'
189
+ ),
190
+ 'DET-27': g(
191
+ 'Startup rule file is large', 'action',
192
+ 'Your AGENTS.md or CLAUDE.md is over 8,000 tokens, which uses up memory on every turn.',
193
+ 'Move topic-specific rules into on-demand skills (try /evolve) so only core rules load every time.',
194
+ 'Avoid adding long, rarely used rules to the startup file.'
195
+ ),
196
+ 'DET-28': g(
197
+ 'Background agent running a long time', 'action',
198
+ 'A helper agent or tool server has been running unattended for over 5 minutes.',
199
+ 'Check whether it is stuck, and stop it if you no longer need it.',
200
+ 'Avoid leaving unused background processes running.'
201
+ ),
202
+ 'DET-29': g(
203
+ 'Saved learnings applied between turns', 'info',
204
+ 'Highbeam applied pending warnings and learned rules between turns.',
205
+ 'No action needed.',
206
+ 'Nothing to avoid.'
207
+ ),
208
+ 'DET-30': g(
209
+ 'AI is thinking without making progress', 'action',
210
+ 'For two or more turns the AI used thousands of thinking tokens without changing any code.',
211
+ 'Stop and narrow the request. Name the exact file and function to change.',
212
+ 'Avoid sending vague follow-ups like "keep going".'
213
+ ),
214
+ 'DET-31': g(
215
+ 'Merge conflict between parallel branches', 'action',
216
+ 'Parallel agent branches changed overlapping lines, so they will conflict when merged.',
217
+ 'Merge or rebase one branch first, then let the other agent continue.',
218
+ 'Avoid letting two branches edit the same lines.'
219
+ ),
220
+ 'DET-32': g(
221
+ 'AI drifted from your task.md rules', 'action',
222
+ 'Recent edits go against a rule in task.md, or repeat an idea that already failed.',
223
+ 'Compare the AI\'s last step with task.md and remind it of the rule it missed.',
224
+ 'Avoid approving steps that break your written rules.'
225
+ )
226
+ });
227
+
228
+ /**
229
+ * Guide for live CircuitBreakers alerts. Their IDs use the live numbering
230
+ * (e.g. DET-03 here means "test checks removed"), so they are keyed separately.
231
+ */
232
+ export const CIRCUIT_ALERT_GUIDE = Object.freeze({
233
+ 'DET-01': g(
234
+ 'Same command keeps failing', 'action',
235
+ 'The AI ran a failing command several times in a row.',
236
+ 'Read the first error message and point the AI at the real cause, or switch to a stronger model.',
237
+ 'Avoid letting the AI retry the exact same command.'
238
+ ),
239
+ 'DET-02': g(
240
+ 'Edits are going back and forth in {file}', 'action',
241
+ '{file} returned to a version it had a few turns ago.',
242
+ 'Run git diff -- "{file}" and give the AI one clear goal for this file.',
243
+ 'Avoid giving the AI conflicting instructions for the same file.'
244
+ ),
245
+ 'DET-03': g(
246
+ 'Test checks were removed from {file}', 'action',
247
+ 'Some assert or expect lines were deleted from {file}. Tests may pass only because the checks are gone.',
248
+ 'Run git diff -- "{file}" and restore any test checks that were removed.',
249
+ 'Avoid accepting passing tests until you know the checks are still there.'
250
+ ),
251
+ 'DET-18': SAFEGUARD_GUIDE['DET-18'],
252
+ 'DET-20': SAFEGUARD_GUIDE['DET-20'],
253
+ 'DET-21': g(
254
+ 'File edited before it was read', 'action',
255
+ 'The AI changed or created {file} without reading or searching the project first.',
256
+ 'Ask the AI to read {file} (or search the project) before it makes more edits.',
257
+ 'Avoid letting the AI edit files it has not read.'
258
+ ),
259
+ 'DET-22': g(
260
+ 'Large part of {file} was deleted', 'action',
261
+ 'More than half of {file} was removed in one edit, and you did not ask for that.',
262
+ 'Run git diff -- "{file}" to see what was removed, and restore anything needed.',
263
+ 'Avoid approving more edits until you know what was lost.'
264
+ ),
265
+ 'DET-23': SAFEGUARD_GUIDE['DET-23'],
266
+ 'DET-30': SAFEGUARD_GUIDE['DET-30']
267
+ });
268
+
269
+ const fillFile = (text, file) => String(text || '').replace(/\{file\}/g, file || 'this file');
270
+
271
+ /**
272
+ * Builds display-ready guidance for a safeguard.
273
+ * @param {string} id Detector id (e.g. 'DET-23').
274
+ * @param {object} [ctx]
275
+ * @param {string} [ctx.file] Full or partial file path; only the file name is shown.
276
+ * @param {boolean} [ctx.live] true = use live-alert guide (CircuitBreakers numbering).
277
+ */
278
+ export function formatSafeguardGuidance(id, ctx = {}) {
279
+ const key = String(id || '').trim().toUpperCase();
280
+ const guide = (ctx.live ? CIRCUIT_ALERT_GUIDE[key] : null) || SAFEGUARD_GUIDE[key] || null;
281
+ const file = safeBaseName(ctx.file);
282
+ if (!guide) {
283
+ return {
284
+ id: key || 'DET',
285
+ title: 'Highbeam safeguard triggered',
286
+ kind: 'action',
287
+ issue: 'A safeguard flagged the most recent step.',
288
+ doText: 'Review the AI\'s last step before approving more work.',
289
+ avoidText: 'Avoid approving follow-up changes until you have checked it.',
290
+ file
291
+ };
292
+ }
293
+ return {
294
+ id: key,
295
+ title: fillFile(guide.title, file),
296
+ kind: guide.kind,
297
+ issue: fillFile(guide.issue, file),
298
+ doText: fillFile(guide.doText, file),
299
+ avoidText: fillFile(guide.avoidText, file),
300
+ file
301
+ };
302
+ }
303
+
304
+ /** Guidance for a live CircuitBreakers (or daemon) alert object. */
305
+ export function getAlertGuidance(alert = {}) {
306
+ return formatSafeguardGuidance(alert.detectorId || alert.id, { live: true, file: alert.filePath || alert.file });
307
+ }
308
+
309
+ /** Short plain-English summary of every canonical guard (for roster tooltips). */
310
+ export function getGuardSummary(id) {
311
+ const guide = SAFEGUARD_GUIDE[String(id || '').toUpperCase()];
312
+ if (!guide) return null;
313
+ return { title: guide.title.replace(/\{file\}/g, 'a file'), kind: guide.kind, summary: guide.issue.replace(/\{file\}/g, 'a file') };
314
+ }
315
+
316
+ /**
317
+ * Maps live CircuitBreakers alert ids onto canonical catalog ids so the roster marks the right guard as tripped.
318
+ */
319
+ export function canonicalGuardIdForAlert(alert = {}) {
320
+ const id = String(alert.detectorId || alert.id || '').toUpperCase();
321
+ if (id === 'DET-01') return 'DET-04';
322
+ if (id === 'DET-02' || id === 'DET-03') return 'DET-05';
323
+ if (id === 'DET-21') return 'DET-06';
324
+ return id;
325
+ }
326
+
327
+ /**
328
+ * Keeps only breaker alerts that are still fresh: raised after the last /compact (or checkpoint)
329
+ * and no more than `maxUserTurns` user messages ago. Alerts without a turnIndex are kept.
330
+ * When no steps are available, every alert is kept.
331
+ */
332
+ export function filterFreshAlerts(alerts = [], steps = [], { maxUserTurns = 1 } = {}) {
333
+ const list = Array.isArray(alerts) ? alerts : [];
334
+ const stepsArr = Array.isArray(steps) ? steps : [];
335
+ if (stepsArr.length === 0) return [...list];
336
+ let lastCompactIdx = -1;
337
+ const userIdxs = [];
338
+ stepsArr.forEach((st, i) => {
339
+ const idx = Number.isFinite(st?.stepIndex) ? st.stepIndex : i;
340
+ if (st?.type === 'USER_INPUT' || st?.source === 'USER_EXPLICIT') {
341
+ userIdxs.push(idx);
342
+ if (/^\/compact\b/i.test(String(st.content || '').trim())) lastCompactIdx = Math.max(lastCompactIdx, idx);
343
+ }
344
+ if (st?.type === 'CHECKPOINT') lastCompactIdx = Math.max(lastCompactIdx, idx);
345
+ });
346
+ return list.filter((a) => {
347
+ const t = Number(a?.turnIndex);
348
+ if (!Number.isFinite(t)) return true;
349
+ if (t <= lastCompactIdx) return false;
350
+ return userIdxs.filter((u) => u > t).length <= maxUserTurns;
351
+ });
352
+ }
353
+
354
+ // ---------------------------------------------------------------------------
355
+ // Learned rules (RSL) — plain-English summaries
356
+ // ---------------------------------------------------------------------------
357
+
358
+ const clip = (text, max) => {
359
+ const s = String(text || '').replace(/\s+/g, ' ').trim();
360
+ if (s.length <= max) return s;
361
+ const cut = s.slice(0, max);
362
+ const lastSpace = cut.lastIndexOf(' ');
363
+ return `${(lastSpace > max * 0.6 ? cut.slice(0, lastSpace) : cut).replace(/[\s,;:.-]+$/, '')}…`;
364
+ };
365
+
366
+ /**
367
+ * Turns a raw learned-rule ledger item into a short, readable row.
368
+ * @returns {{kind:'hook'|'skill'|'rule', title:string, detail:string, status:string}}
369
+ */
370
+ export function humanizeLearnedRule(item = {}) {
371
+ const carrier = String(item.carrier || '');
372
+ const isHook = item.promotedHook === true || carrier === 'pre_tool_hook';
373
+ const isSkill = carrier === 'skill_workflow';
374
+ const kind = isHook ? 'hook' : (isSkill ? 'skill' : 'rule');
375
+ const desc = String(item.description || '');
376
+ const when = String(item.when_condition || '');
377
+ const then = String(item.then_guidance || '');
378
+ const slug = String(item.slug || '').replace(/-[0-9a-f]{6}$/i, '').replace(/[-_]+/g, ' ').trim();
379
+
380
+ let title = '';
381
+ let detail = '';
382
+
383
+ if (isSkill) {
384
+ const steps = Array.isArray(item.steps) ? item.steps.length : 0;
385
+ const target = (desc.match(/recovery workflow for (.+?)\.\s*Do not/i) || [])[1] || '';
386
+ const tool = (when.match(/after `([^`]+)` fails/i) || [])[1] || '';
387
+ const msg = (when.match(/fails with "([^"]*)"/i) || [])[1] || '';
388
+ const stepWord = steps > 0 ? `${steps}-step recovery` : 'Recovery';
389
+ title = `${stepWord} for ${safeBaseName(target) || 'a repeated failure'}`;
390
+ detail = tool
391
+ ? `Used when ${tool} fails${msg ? ` ("${clip(msg, 60)}")` : ''}.`
392
+ : clip(when || then, 110);
393
+ } else {
394
+ const target = (desc.match(/editing (.+?) affected by/i) || [])[1] || '';
395
+ const isReview = /artifact review feedback/i.test(desc) || /^Enforce user artifact guidance/i.test(then);
396
+ const thenClean = clip(
397
+ then.replace(/^Enforce user artifact guidance:\s*/i, '').replace(/[|`*_]+/g, ' ').replace(/^[-\s]+/, ''),
398
+ 110
399
+ );
400
+ title = isReview
401
+ ? `Review feedback rule for ${safeBaseName(target) || 'this project'}`
402
+ : (clip(desc.replace(/^Use when\s+/i, '').replace(/\.\s*Do not.*$/i, ''), 70) || slug || 'Workspace rule');
403
+ detail = thenClean || clip(when, 110);
404
+ }
405
+
406
+ return {
407
+ kind,
408
+ title: stripEmoji(title) || slug || 'Learned rule',
409
+ detail: stripEmoji(detail),
410
+ status: 'active'
411
+ };
412
+ }