ctxtop 0.0.0-stage → 4.0.0

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 (240) hide show
  1. package/.antigravity-plugin/plugin.json +36 -0
  2. package/.claude-plugin/plugin.json +18 -0
  3. package/CHECKSUMS.sha256 +149 -0
  4. package/LICENSE +27 -0
  5. package/README.md +330 -3
  6. package/SECURITY.md +22 -0
  7. package/agents/ah-flash-scout.md +25 -0
  8. package/assets/advanced_view_loaded_420px.png +0 -0
  9. package/assets/hero-demo.svg +188 -0
  10. package/assets/logo.svg +19 -0
  11. package/assets/simple_view_lean_420px.png +0 -0
  12. package/assets/simple_view_loaded_420px.png +0 -0
  13. package/assets/social-preview.svg +72 -0
  14. package/assets/zone_c_step3_shield_full.png +0 -0
  15. package/bin/ah-statusline.mjs +145 -0
  16. package/bin/cli.mjs +3 -0
  17. package/bin/ctxtop.mjs +1474 -0
  18. package/commands/cost-radar.md +11 -0
  19. package/commands/evolve.md +10 -0
  20. package/commands/handoff.md +10 -0
  21. package/commands/horizon.md +10 -0
  22. package/commands/inspect.md +10 -0
  23. package/commands/precheck.md +10 -0
  24. package/config/default_flightcheck.json +114 -0
  25. package/config/modelCatalog.json +620 -0
  26. package/config/platformQuirks.json +19 -0
  27. package/hooks/handlers/compact-lifecycle.mjs +262 -0
  28. package/hooks/handlers/hookIo.mjs +255 -0
  29. package/hooks/handlers/hookIpcClient.mjs +83 -0
  30. package/hooks/handlers/post-tool-use.mjs +265 -0
  31. package/hooks/handlers/pre-model-switch.mjs +249 -0
  32. package/hooks/handlers/pre-tool-use.mjs +365 -0
  33. package/hooks/handlers/stop-gate.mjs +240 -0
  34. package/hooks/handlers/user-prompt-submit.mjs +143 -0
  35. package/hooks/hooks.json +81 -0
  36. package/hooks/post_invocation.mjs +13 -0
  37. package/hooks/post_tool_use.mjs +17 -0
  38. package/hooks/pre_invocation.mjs +14 -0
  39. package/hooks/pre_tool_use.mjs +97 -0
  40. package/hooks/register.js +687 -0
  41. package/hooks/session_start.mjs +14 -0
  42. package/hooks/stop.mjs +13 -0
  43. package/hooks.json +56 -0
  44. package/package.json +103 -4
  45. package/packages/antigravity/package.json +14 -0
  46. package/packages/antigravity/src/index.mjs +1 -0
  47. package/packages/claude-code/package.json +14 -0
  48. package/packages/claude-code/src/index.mjs +2 -0
  49. package/packages/core/package.json +14 -0
  50. package/packages/core/src/index.mjs +1 -0
  51. package/packages/engine-node/package.json +14 -0
  52. package/packages/engine-node/src/index.mjs +1 -0
  53. package/packages/mcp/package.json +17 -0
  54. package/packages/mcp/src/server.mjs +396 -0
  55. package/packages/pro/LICENSE-COMMERCIAL.md +19 -0
  56. package/packages/pro/README-SIGNING.md +30 -0
  57. package/packages/pro/package.json +16 -0
  58. package/packages/pro/src/index.mjs +3 -0
  59. package/packages/pro/src/team_finops_pack.mjs +241 -0
  60. package/packages/pro/workers/polar_webhook_worker.mjs +215 -0
  61. package/plugin.json +36 -0
  62. package/rules/AGENTS.md +10 -0
  63. package/sidecars/horizon-daemon/ipcServer.mjs +24 -0
  64. package/sidecars/horizon-daemon/server.mjs +2002 -0
  65. package/sidecars/horizon-daemon/sidecar.json +19 -0
  66. package/skills/cost-radar/SKILL.md +21 -0
  67. package/skills/evolve/SKILL.md +21 -0
  68. package/skills/handoff/SKILL.md +42 -0
  69. package/skills/horizon/SKILL.md +17 -0
  70. package/skills/inspect/SKILL.md +18 -0
  71. package/skills/precheck/SKILL.md +44 -0
  72. package/src/adapters/antigravity/index.mjs +79 -0
  73. package/src/adapters/claude-code/index.mjs +155 -0
  74. package/src/cli/cost_radar.mjs +70 -0
  75. package/src/cli/doctor.mjs +351 -0
  76. package/src/cli/horizon_hud.mjs +686 -0
  77. package/src/cli/init.mjs +425 -0
  78. package/src/cli/postmortem.mjs +515 -0
  79. package/src/coach/cacheGravityRouter.mjs +12 -0
  80. package/src/config/modelCatalog.json +620 -0
  81. package/src/config/platformQuirks.json +19 -0
  82. package/src/core/action_queue.mjs +264 -0
  83. package/src/core/ag_bridge.mjs +346 -0
  84. package/src/core/atomic_io.mjs +124 -0
  85. package/src/core/baseline.mjs +607 -0
  86. package/src/core/blindspot_sensors.mjs +399 -0
  87. package/src/core/classifier.mjs +1757 -0
  88. package/src/core/coach/circuit_breakers.mjs +650 -0
  89. package/src/core/coach/contradiction_auditor.mjs +239 -0
  90. package/src/core/coach/effort_advisor.mjs +143 -0
  91. package/src/core/coach/handoff_hydrator.mjs +483 -0
  92. package/src/core/coach/progressive_checkpointer.mjs +551 -0
  93. package/src/core/coach/prompt_decomposer_coach.mjs +141 -0
  94. package/src/core/coach/reflector_queue.mjs +505 -0
  95. package/src/core/coach/saved_quota_ledger.mjs +615 -0
  96. package/src/core/coach/subagent_ipi_sanitizer.mjs +200 -0
  97. package/src/core/coach/subagent_phantom_auditor.mjs +261 -0
  98. package/src/core/coach/task_quota_router.mjs +955 -0
  99. package/src/core/coach/turn_zero_gate.mjs +574 -0
  100. package/src/core/compaction_coach.mjs +1126 -0
  101. package/src/core/config.mjs +214 -0
  102. package/src/core/constants.mjs +1800 -0
  103. package/src/core/detectors_det01_to_16.mjs +1474 -0
  104. package/src/core/episodic_memory.mjs +135 -0
  105. package/src/core/fts5_output_compressor.mjs +359 -0
  106. package/src/core/git_ledger.mjs +189 -0
  107. package/src/core/handoff_audit.mjs +558 -0
  108. package/src/core/history.mjs +221 -0
  109. package/src/core/hook_diagnostics.mjs +158 -0
  110. package/src/core/horizon_classifier.mjs +326 -0
  111. package/src/core/horizon_config.mjs +802 -0
  112. package/src/core/host_watchdog.mjs +200 -0
  113. package/src/core/layer5_hygiene.mjs +966 -0
  114. package/src/core/log_resolver.mjs +231 -0
  115. package/src/core/mcp_auditor.mjs +138 -0
  116. package/src/core/micro_skills_store.mjs +91 -0
  117. package/src/core/offenders.mjs +161 -0
  118. package/src/core/parser.mjs +1996 -0
  119. package/src/core/path_canonicalizer.mjs +73 -0
  120. package/src/core/paths.mjs +310 -0
  121. package/src/core/prefix_cache_shield.mjs +386 -0
  122. package/src/core/pro_license.mjs +385 -0
  123. package/src/core/prompt_rubric.mjs +518 -0
  124. package/src/core/pruner.mjs +433 -0
  125. package/src/core/quota.mjs +1860 -0
  126. package/src/core/rsi_instinct_engine.mjs +1197 -0
  127. package/src/core/sanitizer.mjs +121 -0
  128. package/src/core/session_forensics.mjs +303 -0
  129. package/src/core/session_timeline.mjs +358 -0
  130. package/src/core/settings.mjs +99 -0
  131. package/src/core/shared/detectors.mjs +1342 -0
  132. package/src/core/shared/fnv1a64.mjs +85 -0
  133. package/src/core/shared/handoff_schema.mjs +123 -0
  134. package/src/core/shared/index.mjs +5 -0
  135. package/src/core/shared/ipi_sanitizer.mjs +165 -0
  136. package/src/core/shared/micro_skills.mjs +1 -0
  137. package/src/core/shared/plugin_validator.mjs +202 -0
  138. package/src/core/shared/prompt_hygiene_governor.mjs +1 -0
  139. package/src/core/sidecar_store.mjs +302 -0
  140. package/src/core/sprint_metrics.mjs +366 -0
  141. package/src/core/sqlite_client.mjs +283 -0
  142. package/src/core/storage_doctor.mjs +358 -0
  143. package/src/core/subagents.mjs +609 -0
  144. package/src/core/swarm_topology.mjs +360 -0
  145. package/src/core/task_quota_router.mjs +1656 -0
  146. package/src/core/telemetry/cache_ttl_watchdog.mjs +284 -0
  147. package/src/core/telemetry/scope_lock_registry.mjs +578 -0
  148. package/src/core/telemetry/shadow_file_detector.mjs +291 -0
  149. package/src/core/telemetry/trajectory_watcher.mjs +259 -0
  150. package/src/core/timeline_svg.mjs +236 -0
  151. package/src/core/tool_surgeon.mjs +305 -0
  152. package/src/core/trajectory_stitcher.mjs +645 -0
  153. package/src/core/u_shaped_optimizer.mjs +789 -0
  154. package/src/core/wal_hygiene.mjs +233 -0
  155. package/src/core-isomorphic/catalog/detectorCatalog.mjs +558 -0
  156. package/src/core-isomorphic/catalog/index.mjs +1 -0
  157. package/src/core-isomorphic/coach/cacheGravityRouter.mjs +720 -0
  158. package/src/core-isomorphic/coach/microSkills.mjs +1 -0
  159. package/src/core-isomorphic/coach/promptHygieneGovernor.mjs +1 -0
  160. package/src/core-isomorphic/coach/repoCalibration.mjs +254 -0
  161. package/src/core-isomorphic/coach/savedQuotaLedger.mjs +527 -0
  162. package/src/core-isomorphic/coach/stateBatonHydrator.mjs +810 -0
  163. package/src/core-isomorphic/coach/ttlWatchdog.mjs +457 -0
  164. package/src/core-isomorphic/config/anthropicModelCatalog.json +203 -0
  165. package/src/core-isomorphic/config/catalogLoader.mjs +768 -0
  166. package/src/core-isomorphic/config/horizonConfig.mjs +1009 -0
  167. package/src/core-isomorphic/control/callTree.mjs +338 -0
  168. package/src/core-isomorphic/control/coachLatches.mjs +126 -0
  169. package/src/core-isomorphic/control/controlStateMachine.mjs +205 -0
  170. package/src/core-isomorphic/control/index.mjs +49 -0
  171. package/src/core-isomorphic/control/swarmWorktree.mjs +109 -0
  172. package/src/core-isomorphic/control/toolSuspension.mjs +197 -0
  173. package/src/core-isomorphic/diagnostics/drift_guard.mjs +382 -0
  174. package/src/core-isomorphic/diagnostics/index.mjs +9 -0
  175. package/src/core-isomorphic/diagnostics/micro_skills.mjs +471 -0
  176. package/src/core-isomorphic/diagnostics/prompt_hygiene_governor.mjs +622 -0
  177. package/src/core-isomorphic/economics/billingBlocks.mjs +251 -0
  178. package/src/core-isomorphic/economics/cacheGravity.mjs +351 -0
  179. package/src/core-isomorphic/economics/cliffBreaker.mjs +170 -0
  180. package/src/core-isomorphic/economics/driftLatency.mjs +319 -0
  181. package/src/core-isomorphic/economics/dualTtl.mjs +198 -0
  182. package/src/core-isomorphic/economics/index.mjs +47 -0
  183. package/src/core-isomorphic/economics/retentionRadar.mjs +348 -0
  184. package/src/core-isomorphic/guards/circuitBreakers.mjs +1202 -0
  185. package/src/core-isomorphic/guards/det01_03_shell_secret.mjs +1035 -0
  186. package/src/core-isomorphic/guards/det04_12_thrash_rot.mjs +480 -0
  187. package/src/core-isomorphic/guards/det13_20_mcp_scope.mjs +603 -0
  188. package/src/core-isomorphic/guards/losslessPostSanitizer.mjs +301 -0
  189. package/src/core-isomorphic/index.js +26 -0
  190. package/src/core-isomorphic/telemetry/otelExporter.mjs +187 -0
  191. package/src/core-isomorphic/telemetry/scopeLockRegistry.mjs +522 -0
  192. package/src/core-isomorphic/telemetry/sprintMetrics.mjs +327 -0
  193. package/src/core-isomorphic/telemetry/swarmTopology.mjs +152 -0
  194. package/src/core-isomorphic/telemetry/telemetryBridge.mjs +1132 -0
  195. package/src/core-isomorphic/ui/brailleSparkline.mjs +142 -0
  196. package/src/core-isomorphic/ui/costRadarSvg.mjs +276 -0
  197. package/src/core-isomorphic/ui/horizonGrid.mjs +475 -0
  198. package/src/core-isomorphic/ui/horizonPanelHtml.mjs +1181 -0
  199. package/src/core-isomorphic/ui/modViews.mjs +1478 -0
  200. package/src/core-isomorphic/ui/pdfReceiptGenerator.mjs +329 -0
  201. package/src/core-isomorphic/ustf/index.mjs +7 -0
  202. package/src/core-isomorphic/ustf/normalizer.mjs +512 -0
  203. package/src/core-isomorphic/ustf/schema.mjs +186 -0
  204. package/src/core-isomorphic/utils/runtime.mjs +962 -0
  205. package/src/demo/synthetic_states.mjs +661 -0
  206. package/src/diagnostics/bugReportGenerator.mjs +253 -0
  207. package/src/diagnostics/doctorEngine.mjs +203 -0
  208. package/src/engine-node/db/index.mjs +58 -0
  209. package/src/engine-node/db/jsonl_fallback.mjs +184 -0
  210. package/src/engine-node/db/probe.mjs +110 -0
  211. package/src/engine-node/db/sqlite_wrapper.mjs +122 -0
  212. package/src/engine-node/index.mjs +9 -0
  213. package/src/engine-node/ipc/client.mjs +447 -0
  214. package/src/engine-node/ipc/index.mjs +22 -0
  215. package/src/engine-node/ipc/protocol.mjs +177 -0
  216. package/src/engine-node/ipc/server.mjs +445 -0
  217. package/src/engine-node/offloader/index.mjs +6 -0
  218. package/src/engine-node/offloader/tool_offloader.mjs +241 -0
  219. package/src/engine-node/sensors/blindspots.mjs +369 -0
  220. package/src/engine-node/sensors/git_merge_tree.mjs +223 -0
  221. package/src/engine-node/sensors/index.mjs +7 -0
  222. package/src/hooks/portfolio_runtime.mjs +858 -0
  223. package/src/hooks/post_invocation.mjs +419 -0
  224. package/src/hooks/pre_invocation.mjs +1015 -0
  225. package/src/hooks/session_start.mjs +161 -0
  226. package/src/shims/agy_cli_compressor.mjs +705 -0
  227. package/src/shims/agy_git_guard.mjs +749 -0
  228. package/src/shims/ah_log_query.mjs +39 -0
  229. package/src/ui/costRadarSvg.mjs +6 -0
  230. package/src/ui/horizonGrid.mjs +1 -0
  231. package/src/ui/horizonPanelHtml.mjs +1 -0
  232. package/src/ui/horizon_panel.css +167 -0
  233. package/src/ui/horizon_panel.js +212 -0
  234. package/src/ui/modViews.mjs +1 -0
  235. package/src/utils/nodeIo.mjs +59 -0
  236. package/src/utils/runtime.mjs +1 -0
  237. package/src/webview/advanced_view.html +1808 -0
  238. package/src/webview/horizon_panel.html +11389 -0
  239. package/src/webview/registry.mjs +80 -0
  240. package/src/webview/simple_view.html +1370 -0
@@ -0,0 +1,25 @@
1
+ ---
2
+ name: ah-flash-scout
3
+ description: Lean Flash repository scout returning <200-token File:Line summaries to protect main-thread Frontier KV cache.
4
+ model: flash
5
+ mainAgent: false
6
+ subagent: true
7
+ excludeDefaultComponents: true
8
+ commandExecutionPolicy: off
9
+ tools:
10
+ - view_file
11
+ - grep_search
12
+ - find_by_name
13
+ - list_dir
14
+ ---
15
+
16
+ # Highbeam Flash Scout (`@ah-flash-scout`)
17
+
18
+ You are a lean, read-only codebase scout running on Gemini Flash so the parent Frontier session (`gemini-4-carbon` / `gemini-4-argon`) preserves its warm implicit KV cache without ingesting raw exploratory search output.
19
+
20
+ ## Strict Operating Contract
21
+ 1. **Read-Only Tools Only:** Use ONLY `grep_search`, `find_by_name`, `list_dir`, and targeted `view_file` (`StartLine`/`EndLine`). Never attempt shell execution or file writes.
22
+ 2. **Hard `< 200`-Token Response Ceiling:** Return ONLY exact `File:StartLine-EndLine` coordinates and 1-line symbol descriptions. Never paste raw multi-line file dumps back to the coordinator.
23
+ 3. **Output Format:**
24
+ - `path/to/file.mjs:L10-L42` — Symbol / invariant summary
25
+ - `path/to/other.mjs:L88-L105` — Call-site / dependency note
@@ -0,0 +1,188 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 520" width="100%" height="100%">
2
+ <defs>
3
+ <linearGradient id="bgGrad" x1="0" y1="0" x2="1" y2="1">
4
+ <stop offset="0%" stop-color="#090d16"/>
5
+ <stop offset="100%" stop-color="#0f172a"/>
6
+ </linearGradient>
7
+ <linearGradient id="cardGrad" x1="0" y1="0" x2="0" y2="1">
8
+ <stop offset="0%" stop-color="#131c2e"/>
9
+ <stop offset="100%" stop-color="#0b1120"/>
10
+ </linearGradient>
11
+ <style>
12
+ .mono { font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace; }
13
+ .sans { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, sans-serif; }
14
+ @keyframes blinkAmber {
15
+ 0%, 100% { fill-opacity: 1; stroke: #facc15; stroke-width: 1.5px; }
16
+ 50% { fill-opacity: 0.35; stroke-width: 0px; }
17
+ }
18
+ @keyframes pulseDanger {
19
+ 0%, 100% { filter: drop-shadow(0 0 4px rgba(239, 68, 68, 0.85)); }
20
+ 50% { filter: drop-shadow(0 0 0px rgba(239, 68, 68, 0)); }
21
+ }
22
+ .blink-amber { animation: blinkAmber 1.4s infinite ease-in-out; }
23
+ .pulse-danger { animation: pulseDanger 1.8s infinite ease-in-out; }
24
+ </style>
25
+ </defs>
26
+
27
+ <!-- Outer Window Frame -->
28
+ <rect width="960" height="520" rx="12" fill="url(#bgGrad)" stroke="#1e293b" stroke-width="2"/>
29
+ <rect x="1" y="1" width="958" height="38" rx="11" fill="#111827"/>
30
+ <circle cx="22" cy="20" r="6" fill="#ef4444"/>
31
+ <circle cx="42" cy="20" r="6" fill="#f59e0b"/>
32
+ <circle cx="62" cy="20" r="6" fill="#22c55e"/>
33
+ <text x="480" y="25" text-anchor="middle" fill="#94a3b8" font-size="13" font-weight="600" class="mono">
34
+ Highbeam (ctxtop v3.4.0) — 40-Cell Context Telemetry HUD &amp; PreInvocation Flight Check
35
+ </text>
36
+
37
+ <!-- Section 1: Turn 50 Prefix Amputation & Sludge Crisis -->
38
+ <g transform="translate(24, 54)">
39
+ <rect width="912" height="205" rx="8" fill="url(#cardGrad)" stroke="#ef4444" stroke-opacity="0.55" stroke-width="1.5"/>
40
+
41
+ <!-- Top Status Strip -->
42
+ <rect x="16" y="14" width="218" height="22" rx="4" fill="#ef4444" fill-opacity="0.18" stroke="#ef4444" stroke-width="1"/>
43
+ <text x="26" y="29" fill="#fca5a5" font-size="11.5" font-weight="700" class="mono">🚨 AMPUTATION CRISIS (TURN 50)</text>
44
+ <text x="250" y="29" fill="#e2e8f0" font-size="12" font-weight="600" class="mono"><tspan fill="#f87171">145k / 200k · 73%</tspan> | Cache Hit: <tspan fill="#fbbf24">41.2%</tspan> | Waste: <tspan fill="#f87171">84k tok</tspan> | TTL: <tspan fill="#f87171">0s (5m)</tspan> | <tspan fill="#38bdf8">[Mode: Read-Heavy Audit]</tspan></text>
45
+
46
+ <!-- Amputation Bracket Label -->
47
+ <path d="M 16 54 L 16 47 L 188 47 L 188 54" fill="none" stroke="#ef4444" stroke-width="1.8"/>
48
+ <text x="102" y="44" text-anchor="middle" fill="#f87171" font-size="10" font-weight="700" class="mono">![ CELLS 1-8: AGENTS.md AT RISK ]!</text>
49
+
50
+ <!-- 40-Cell Chronological Bar -->
51
+ <g>
52
+ <rect x="16" y="58" width="19.5" height="26" rx="3" fill="#00d7ff" fill-opacity="1" class="pulse-danger" />
53
+ <rect x="38" y="58" width="19.5" height="26" rx="3" fill="#00d7ff" fill-opacity="1" class="pulse-danger" />
54
+ <rect x="60" y="58" width="19.5" height="26" rx="3" fill="#00d7ff" fill-opacity="1" class="pulse-danger" />
55
+ <rect x="82" y="58" width="19.5" height="26" rx="3" fill="#ff0087" fill-opacity="1" class="pulse-danger" />
56
+ <rect x="104" y="58" width="19.5" height="26" rx="3" fill="#ffaf00" fill-opacity="0.95" class="pulse-danger" />
57
+ <rect x="126" y="58" width="19.5" height="26" rx="3" fill="#ffaf00" fill-opacity="0.95" class="pulse-danger" />
58
+ <rect x="148" y="58" width="19.5" height="26" rx="3" fill="#ffaf00" fill-opacity="0.95" class="pulse-danger" />
59
+ <rect x="170" y="58" width="19.5" height="26" rx="3" fill="#ffaf00" fill-opacity="0.95" class="pulse-danger" />
60
+ <rect x="192" y="58" width="19.5" height="26" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
61
+ <rect x="214" y="58" width="19.5" height="26" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
62
+ <rect x="236" y="58" width="19.5" height="26" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
63
+ <rect x="258" y="58" width="19.5" height="26" rx="3" fill="#ef4444" fill-opacity="0.95" class="" />
64
+ <rect x="280" y="58" width="19.5" height="26" rx="3" fill="#ef4444" fill-opacity="0.95" class="" />
65
+ <rect x="302" y="58" width="19.5" height="26" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
66
+ <rect x="324" y="58" width="19.5" height="26" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
67
+ <rect x="346" y="58" width="19.5" height="26" rx="3" fill="#f97316" fill-opacity="1" class="blink-amber" />
68
+ <rect x="368" y="58" width="19.5" height="26" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
69
+ <rect x="390" y="58" width="19.5" height="26" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
70
+ <rect x="412" y="58" width="19.5" height="26" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
71
+ <rect x="434" y="58" width="19.5" height="26" rx="3" fill="#ef4444" fill-opacity="0.95" class="" />
72
+ <rect x="456" y="58" width="19.5" height="26" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
73
+ <rect x="478" y="58" width="19.5" height="26" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
74
+ <rect x="500" y="58" width="19.5" height="26" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
75
+ <rect x="522" y="58" width="19.5" height="26" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
76
+ <rect x="544" y="58" width="19.5" height="26" rx="3" fill="#22c55e" fill-opacity="1" class="" />
77
+ <rect x="566" y="58" width="19.5" height="26" rx="3" fill="#22c55e" fill-opacity="1" class="" />
78
+ <rect x="588" y="58" width="19.5" height="26" rx="3" fill="#22c55e" fill-opacity="1" class="" />
79
+ <rect x="610" y="58" width="19.5" height="26" rx="3" fill="#22c55e" fill-opacity="1" class="" />
80
+ <rect x="632" y="58" width="19.5" height="26" rx="3" fill="#22c55e" fill-opacity="1" class="" />
81
+ <rect x="654" y="58" width="19.5" height="26" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
82
+ <rect x="676" y="58" width="19.5" height="26" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
83
+ <rect x="698" y="58" width="19.5" height="26" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
84
+ <rect x="720" y="58" width="19.5" height="26" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
85
+ <rect x="742" y="58" width="19.5" height="26" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
86
+ <rect x="764" y="58" width="19.5" height="26" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
87
+ <rect x="786" y="58" width="19.5" height="26" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
88
+ <rect x="808" y="58" width="19.5" height="26" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
89
+ <rect x="830" y="58" width="19.5" height="26" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
90
+ <rect x="852" y="58" width="19.5" height="26" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
91
+ <rect x="874" y="58" width="19.5" height="26" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
92
+ </g>
93
+
94
+ <!-- Cell Zone Annotations -->
95
+ <text x="16" y="100" fill="#00d7ff" font-size="10.5" class="mono">█ Anchor Rules</text>
96
+ <text x="122" y="100" fill="#ff0087" font-size="10.5" class="mono">▓ Foreign KI Bleed</text>
97
+ <text x="255" y="100" fill="#f59e0b" font-size="10.5" class="mono">▒ 58k Duplicate File Reads</text>
98
+ <text x="442" y="100" fill="#ef4444" font-size="10.5" class="mono">▓ Dead Stack Traces</text>
99
+ <text x="585" y="100" fill="#f97316" font-size="10.5" class="mono">▒ Dirty Disk Snapshot</text>
100
+ <text x="735" y="100" fill="#22c55e" font-size="10.5" class="mono">█ Active Working Set</text>
101
+
102
+ <!-- 4-Line Flight Check Scorecard Box -->
103
+ <rect x="16" y="112" width="880" height="80" rx="6" fill="#090d16" stroke="#334155" stroke-width="1"/>
104
+ <text x="28" y="130" fill="#38bdf8" font-size="11.5" font-weight="700" class="mono">╭── Flight Check v3.1 PreInvocation Router (4.2ms) ── State: HALT_HYGIENE_OR_SAFETY ──────────────────╮</text>
105
+ <text x="28" y="146" fill="#cbd5e1" font-size="11.5" class="mono">│ 1. SENSORS: <tspan fill="#f87171">AMPUTATION_RISK (&gt;140k)</tspan> • <tspan fill="#fbbf24">DIRTY_SNAP (src/routes.mjs)</tspan> • <tspan fill="#f472b6">UNSEEN_CALLER (src/app.mjs)</tspan></text>
106
+ <text x="28" y="162" fill="#cbd5e1" font-size="11.5" class="mono">│ 2. ACTION : <tspan fill="#4ade80" font-weight="700">Type /compact in chat (or run Surgical Pruner) to reclaim 84,000 sludge tokens</tspan></text>
107
+ <text x="28" y="178" fill="#cbd5e1" font-size="11.5" class="mono">╰── Bypass once: prefix with <tspan fill="#fbbf24">!</tspan> • Lock model/effort: <tspan fill="#fbbf24">!lock</tspan> • Force scorecard rewrite: <tspan fill="#38bdf8">#check</tspan> ───────╯</text>
108
+ </g>
109
+
110
+ <!-- Section 2: Post-Compact & Surgical Pruner Recovery + Tufte Telemetry Strip -->
111
+ <g transform="translate(24, 274)">
112
+ <rect width="912" height="222" rx="8" fill="url(#cardGrad)" stroke="#22c55e" stroke-opacity="0.5" stroke-width="1.5"/>
113
+
114
+ <rect x="16" y="14" width="235" height="22" rx="4" fill="#22c55e" fill-opacity="0.16" stroke="#22c55e" stroke-width="1"/>
115
+ <text x="26" y="29" fill="#86efac" font-size="11.5" font-weight="700" class="mono">✓ AFTER /compact + SURGICAL PRUNE</text>
116
+ <text x="268" y="29" fill="#e2e8f0" font-size="12.5" font-weight="600" class="mono">Tokens: <tspan fill="#4ade80">64k / 200k (-81k reclaimed)</tspan> | Purity: <tspan fill="#4ade80">91%</tspan> | Sludge Tax: <tspan fill="#4ade80">$0.00/turn</tspan></text>
117
+
118
+ <!-- Recovered 40-Cell Bar -->
119
+ <g>
120
+ <rect x="16" y="48" width="19.5" height="24" rx="3" fill="#00d7ff" fill-opacity="1" class="" />
121
+ <rect x="38" y="48" width="19.5" height="24" rx="3" fill="#00d7ff" fill-opacity="1" class="" />
122
+ <rect x="60" y="48" width="19.5" height="24" rx="3" fill="#00d7ff" fill-opacity="1" class="" />
123
+ <rect x="82" y="48" width="19.5" height="24" rx="3" fill="#a855f7" fill-opacity="0.95" class="" />
124
+ <rect x="104" y="48" width="19.5" height="24" rx="3" fill="#f59e0b" fill-opacity="0.75" class="" />
125
+ <rect x="126" y="48" width="19.5" height="24" rx="3" fill="#22c55e" fill-opacity="1" class="" />
126
+ <rect x="148" y="48" width="19.5" height="24" rx="3" fill="#22c55e" fill-opacity="1" class="" />
127
+ <rect x="170" y="48" width="19.5" height="24" rx="3" fill="#22c55e" fill-opacity="1" class="" />
128
+ <rect x="192" y="48" width="19.5" height="24" rx="3" fill="#22c55e" fill-opacity="1" class="" />
129
+ <rect x="214" y="48" width="19.5" height="24" rx="3" fill="#22c55e" fill-opacity="1" class="" />
130
+ <rect x="236" y="48" width="19.5" height="24" rx="3" fill="#22c55e" fill-opacity="1" class="" />
131
+ <rect x="258" y="48" width="19.5" height="24" rx="3" fill="#22c55e" fill-opacity="1" class="" />
132
+ <rect x="280" y="48" width="19.5" height="24" rx="3" fill="#22c55e" fill-opacity="1" class="" />
133
+ <rect x="302" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
134
+ <rect x="324" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
135
+ <rect x="346" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
136
+ <rect x="368" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
137
+ <rect x="390" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
138
+ <rect x="412" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
139
+ <rect x="434" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
140
+ <rect x="456" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
141
+ <rect x="478" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
142
+ <rect x="500" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
143
+ <rect x="522" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
144
+ <rect x="544" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
145
+ <rect x="566" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
146
+ <rect x="588" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
147
+ <rect x="610" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
148
+ <rect x="632" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
149
+ <rect x="654" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
150
+ <rect x="676" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
151
+ <rect x="698" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
152
+ <rect x="720" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
153
+ <rect x="742" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
154
+ <rect x="764" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
155
+ <rect x="786" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
156
+ <rect x="808" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
157
+ <rect x="830" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
158
+ <rect x="852" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
159
+ <rect x="874" y="48" width="19.5" height="24" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
160
+ </g>
161
+
162
+ <!-- Bottom 3 Small-Multiple Tufte Panels -->
163
+ <!-- Panel A: U-Shaped Attention Curve -->
164
+ <rect x="16" y="86" width="282" height="122" rx="6" fill="#090d16" stroke="#1e293b" stroke-width="1"/>
165
+ <text x="28" y="105" fill="#94a3b8" font-size="11" font-weight="700" class="mono">U-SHAPED ATTENTION RECALL CURVE</text>
166
+ <path d="M 32 120 Q 155 188 282 118" fill="none" stroke="#38bdf8" stroke-width="2.5"/>
167
+ <circle cx="42" cy="126" r="4" fill="#00d7ff"/>
168
+ <circle cx="155" cy="154" r="4" fill="#f59e0b"/>
169
+ <circle cx="268" cy="124" r="4" fill="#22c55e"/>
170
+ <text x="32" y="196" fill="#64748b" font-size="10" class="mono">Turn 0 Anchors (96%) Middle (42%) Tail (98%)</text>
171
+
172
+ <!-- Panel B: Top Token Offenders Pruned -->
173
+ <rect x="314" y="86" width="292" height="122" rx="6" fill="#090d16" stroke="#1e293b" stroke-width="1"/>
174
+ <text x="326" y="105" fill="#94a3b8" font-size="11" font-weight="700" class="mono">SURGICAL PRUNER LEDGER (SAVED 81k)</text>
175
+ <text x="326" y="128" fill="#cbd5e1" font-size="11" class="mono">1. src/core/router.mjs (x6) <tspan fill="#4ade80">-34.2k</tspan></text>
176
+ <text x="326" y="148" fill="#cbd5e1" font-size="11" class="mono">2. Dead test stack traces (x3)<tspan fill="#4ade80">-22.8k</tspan></text>
177
+ <text x="326" y="168" fill="#cbd5e1" font-size="11" class="mono">3. Stale chat turns (&gt;25 old) <tspan fill="#4ade80">-17.2k</tspan></text>
178
+ <text x="326" y="188" fill="#cbd5e1" font-size="11" class="mono">4. Unused MCP cold schemas <tspan fill="#4ade80"> -6.8k</tspan></text>
179
+
180
+ <!-- Panel C: Instant CLI Quickstart -->
181
+ <rect x="622" y="86" width="274" height="122" rx="6" fill="#090d16" stroke="#1e293b" stroke-width="1"/>
182
+ <text x="634" y="105" fill="#94a3b8" font-size="11" font-weight="700" class="mono">ZERO-CONFIG CLI (NODE 22.5+)</text>
183
+ <text x="634" y="129" fill="#38bdf8" font-size="10.5" class="mono">$ npx attention-horizon-antigravity --demo</text>
184
+ <text x="634" y="151" fill="#4ade80" font-size="10.5" class="mono">$ npx attention-horizon-antigravity init</text>
185
+ <text x="634" y="173" fill="#f472b6" font-size="11" class="mono">$ npx ctxtop --roast</text>
186
+ <text x="634" y="195" fill="#64748b" font-size="10" class="mono">0 deps • &lt;15ms hooks • 100% local</text>
187
+ </g>
188
+ </svg>
@@ -0,0 +1,19 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" width="128" height="128">
2
+ <rect width="128" height="128" rx="24" fill="#090d16" />
3
+ <circle cx="64" cy="64" r="52" fill="none" stroke="#1e293b" stroke-width="2" stroke-dasharray="4 4" />
4
+ <path d="M 20 44 Q 64 96 108 44" fill="none" stroke="#38bdf8" stroke-width="3" stroke-linecap="round" />
5
+ <g transform="translate(18, 58)">
6
+ <rect x="0" y="0" width="8" height="12" rx="2" fill="#00d7ff" />
7
+ <rect x="10" y="0" width="8" height="12" rx="2" fill="#00d7ff" />
8
+ <rect x="20" y="0" width="8" height="12" rx="2" fill="#af5fff" />
9
+ <rect x="30" y="0" width="8" height="12" rx="2" fill="#ffaf00" />
10
+ <rect x="40" y="0" width="8" height="12" rx="2" fill="#ffaf00" />
11
+ <rect x="50" y="0" width="8" height="12" rx="2" fill="#ff0000" />
12
+ <rect x="60" y="0" width="8" height="12" rx="2" fill="#ff0000" />
13
+ <rect x="70" y="0" width="8" height="12" rx="2" fill="#00ff00" />
14
+ <rect x="80" y="0" width="8" height="12" rx="2" fill="#00ff00" />
15
+ </g>
16
+ <text x="64" y="94" font-family="system-ui, -apple-system, sans-serif" font-size="11" font-weight="700" fill="#f8fafc" text-anchor="middle" letter-spacing="1.5">HORIZON</text>
17
+ <circle cx="20" cy="44" r="4" fill="#38bdf8" />
18
+ <circle cx="108" cy="44" r="4" fill="#38bdf8" />
19
+ </svg>
@@ -0,0 +1,72 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1280 640" width="1280" height="640">
2
+ <defs>
3
+ <linearGradient id="bg" x1="0" y1="0" x2="1" y2="1">
4
+ <stop offset="0%" stop-color="#070a12"/>
5
+ <stop offset="100%" stop-color="#0f172a"/>
6
+ </linearGradient>
7
+ <style>
8
+ .mono { font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace; }
9
+ .sans { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
10
+ </style>
11
+ </defs>
12
+ <rect width="1280" height="640" fill="url(#bg)"/>
13
+ <rect x="36" y="36" width="1208" height="568" rx="20" fill="#0b1120" stroke="#1e293b" stroke-width="3"/>
14
+
15
+ <!-- Top Pill -->
16
+ <rect x="84" y="82" width="460" height="38" rx="19" fill="#00d7ff" fill-opacity="0.12" stroke="#00d7ff" stroke-width="1.5"/>
17
+ <text x="314" y="107" text-anchor="middle" fill="#38bdf8" font-size="18" font-weight="700" class="mono">⚡ Highbeam (ctxtop v3.3)</text>
18
+
19
+ <!-- Main Headline -->
20
+ <text x="84" y="185" fill="#f8fafc" font-size="52" font-weight="800" class="sans">htop for AI Coding Agent</text>
21
+ <text x="84" y="248" fill="#38bdf8" font-size="52" font-weight="800" class="sans">Context Windows.</text>
22
+ <text x="84" y="302" fill="#94a3b8" font-size="24" class="sans">Stop silent AGENTS.md prefix amputation, stale-file overwrites, and 5-hour quota burn.</text>
23
+
24
+ <!-- 40-Cell Visual Bar -->
25
+ <g transform="translate(68, 340) scale(1.28)">
26
+ <rect x="12" y="0" width="19.5" height="32" rx="3" fill="#00d7ff" fill-opacity="1" class="pulse-danger" />
27
+ <rect x="34" y="0" width="19.5" height="32" rx="3" fill="#00d7ff" fill-opacity="1" class="pulse-danger" />
28
+ <rect x="56" y="0" width="19.5" height="32" rx="3" fill="#00d7ff" fill-opacity="1" class="pulse-danger" />
29
+ <rect x="78" y="0" width="19.5" height="32" rx="3" fill="#ff0087" fill-opacity="1" class="pulse-danger" />
30
+ <rect x="100" y="0" width="19.5" height="32" rx="3" fill="#ffaf00" fill-opacity="0.95" class="pulse-danger" />
31
+ <rect x="122" y="0" width="19.5" height="32" rx="3" fill="#ffaf00" fill-opacity="0.95" class="pulse-danger" />
32
+ <rect x="144" y="0" width="19.5" height="32" rx="3" fill="#ffaf00" fill-opacity="0.95" class="pulse-danger" />
33
+ <rect x="166" y="0" width="19.5" height="32" rx="3" fill="#ffaf00" fill-opacity="0.95" class="pulse-danger" />
34
+ <rect x="188" y="0" width="19.5" height="32" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
35
+ <rect x="210" y="0" width="19.5" height="32" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
36
+ <rect x="232" y="0" width="19.5" height="32" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
37
+ <rect x="254" y="0" width="19.5" height="32" rx="3" fill="#ef4444" fill-opacity="0.95" class="" />
38
+ <rect x="276" y="0" width="19.5" height="32" rx="3" fill="#ef4444" fill-opacity="0.95" class="" />
39
+ <rect x="298" y="0" width="19.5" height="32" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
40
+ <rect x="320" y="0" width="19.5" height="32" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
41
+ <rect x="342" y="0" width="19.5" height="32" rx="3" fill="#f97316" fill-opacity="1" class="blink-amber" />
42
+ <rect x="364" y="0" width="19.5" height="32" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
43
+ <rect x="386" y="0" width="19.5" height="32" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
44
+ <rect x="408" y="0" width="19.5" height="32" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
45
+ <rect x="430" y="0" width="19.5" height="32" rx="3" fill="#ef4444" fill-opacity="0.95" class="" />
46
+ <rect x="452" y="0" width="19.5" height="32" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
47
+ <rect x="474" y="0" width="19.5" height="32" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
48
+ <rect x="496" y="0" width="19.5" height="32" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
49
+ <rect x="518" y="0" width="19.5" height="32" rx="3" fill="#f59e0b" fill-opacity="0.88" class="" />
50
+ <rect x="540" y="0" width="19.5" height="32" rx="3" fill="#22c55e" fill-opacity="1" class="" />
51
+ <rect x="562" y="0" width="19.5" height="32" rx="3" fill="#22c55e" fill-opacity="1" class="" />
52
+ <rect x="584" y="0" width="19.5" height="32" rx="3" fill="#22c55e" fill-opacity="1" class="" />
53
+ <rect x="606" y="0" width="19.5" height="32" rx="3" fill="#22c55e" fill-opacity="1" class="" />
54
+ <rect x="628" y="0" width="19.5" height="32" rx="3" fill="#22c55e" fill-opacity="1" class="" />
55
+ <rect x="650" y="0" width="19.5" height="32" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
56
+ <rect x="672" y="0" width="19.5" height="32" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
57
+ <rect x="694" y="0" width="19.5" height="32" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
58
+ <rect x="716" y="0" width="19.5" height="32" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
59
+ <rect x="738" y="0" width="19.5" height="32" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
60
+ <rect x="760" y="0" width="19.5" height="32" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
61
+ <rect x="782" y="0" width="19.5" height="32" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
62
+ <rect x="804" y="0" width="19.5" height="32" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
63
+ <rect x="826" y="0" width="19.5" height="32" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
64
+ <rect x="848" y="0" width="19.5" height="32" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
65
+ <rect x="870" y="0" width="19.5" height="32" rx="3" fill="#1e293b" fill-opacity="0.65" class="" />
66
+ </g>
67
+
68
+ <!-- Bottom Metrics Strip -->
69
+ <rect x="84" y="445" width="1112" height="108" rx="12" fill="#111827" stroke="#334155" stroke-width="1.5"/>
70
+ <text x="116" y="490" fill="#4ade80" font-size="24" font-weight="700" class="mono">$ npx attention-horizon-antigravity init</text>
71
+ <text x="116" y="528" fill="#cbd5e1" font-size="19" class="mono">40-Cell ANSI HUD • Edward Tufte Webview • 6 Blind-Spot Sensors • 0 Dependencies • &lt;15ms SLA</text>
72
+ </svg>
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @file bin/ah-statusline.mjs
4
+ * Standalone `statusLine` JSON bridge for Claude Code Highbeam.
5
+ *
6
+ * Reads Claude Code's `statusLine` JSON payload from `stdin`, updates the atomic
7
+ * bridge snapshot at `.claude/cache/ah_live_state_<sessionId>.json`, and prints
8
+ * a responsive single-line ANSI status bar adapting to terminal column width
9
+ * (80 / 110 / 144 columns).
10
+ */
11
+
12
+ import { fs, path, url } from '../src/utils/nodeIo.mjs';
13
+ import { readStdinJsonAsync } from '../hooks/handlers/hookIo.mjs';
14
+ import {
15
+ createInitialTelemetryState,
16
+ readLiveStateSnapshot,
17
+ ingestStatusLinePayload,
18
+ writeLiveStateSnapshot
19
+ } from '../src/core-isomorphic/telemetry/telemetryBridge.mjs';
20
+ import { renderStatusLine } from '../src/core-isomorphic/ui/modViews.mjs';
21
+
22
+ /**
23
+ * Programmatic entrypoint for the `statusLine` bridge.
24
+ *
25
+ * @param {object} [payload={}] - Parsed `statusLine` stdin JSON payload
26
+ * @param {object} [options={}]
27
+ * @param {number} [options.columns]
28
+ * @param {boolean} [options.ansi=true]
29
+ * @param {string} [options.cwd]
30
+ * @param {number} [options.nowMs]
31
+ * @returns {{
32
+ * line: string,
33
+ * plainLine: string,
34
+ * visibleLength: number,
35
+ * columns: number,
36
+ * layoutTier: string,
37
+ * state: object,
38
+ * sessionPath: string
39
+ * }}
40
+ */
41
+ export function executeStatusLineBridge(payload = {}, options = {}) {
42
+ const sessionId = payload.session_id || payload.sessionId || 'default';
43
+ const currentState = readLiveStateSnapshot(sessionId, options);
44
+ const nextState = ingestStatusLinePayload(currentState, payload, options);
45
+ const persisted = writeLiveStateSnapshot(nextState.sessionId, nextState, options);
46
+
47
+ const envCols = Number(globalThis.process?.env?.AH_COLUMNS || 0);
48
+ const stdoutCols = Number(globalThis.process?.stdout?.columns || 0);
49
+ const payloadCols = Number(payload.terminal?.columns || payload.columns || 0);
50
+
51
+ const columns =
52
+ options.columns ||
53
+ (payloadCols > 0 ? payloadCols : envCols > 0 ? envCols : stdoutCols > 0 ? stdoutCols : 110);
54
+
55
+ const rendered = renderStatusLine(nextState, {
56
+ ...options,
57
+ columns,
58
+ ansi: options.ansi !== false
59
+ });
60
+
61
+ return {
62
+ ...rendered,
63
+ state: nextState,
64
+ sessionPath: persisted.sessionPath
65
+ };
66
+ }
67
+
68
+ /**
69
+ * Symlink-safe CLI main guard (`ISS-014`).
70
+ * Resolves `node_modules/.bin/ah-statusline` symlinks via `realpathSync`
71
+ * with a `path.resolve` fallback when `realpathSync` is unavailable.
72
+ *
73
+ * @param {string} [argv1=globalThis.process?.argv?.[1]]
74
+ * @param {string} [metaUrl=import.meta.url]
75
+ * @param {{ realpathSync?: Function }} [fsImpl=fs]
76
+ * @returns {boolean}
77
+ */
78
+ export function isCliMain(
79
+ argv1 = globalThis.process?.argv?.[1],
80
+ metaUrl = import.meta.url,
81
+ fsImpl = fs
82
+ ) {
83
+ if (!argv1 || !metaUrl) return false;
84
+ try {
85
+ return fsImpl.realpathSync(argv1) === fsImpl.realpathSync(url.fileURLToPath(metaUrl));
86
+ } catch {
87
+ try {
88
+ return path.resolve(String(argv1)) === path.resolve(url.fileURLToPath(metaUrl));
89
+ } catch {
90
+ return false;
91
+ }
92
+ }
93
+ }
94
+
95
+ /**
96
+ * CLI runner when invoked directly as `node bin/ah-statusline.mjs` or symlinked `ah-statusline`.
97
+ */
98
+ export async function runStatusLineCli(args = globalThis.process?.argv?.slice(2) || []) {
99
+ try {
100
+ const colIdx = Array.isArray(args)
101
+ ? (args.indexOf('--columns') !== -1 ? args.indexOf('--columns') : args.indexOf('--cols'))
102
+ : -1;
103
+ const cliCols = colIdx !== -1 && args[colIdx + 1] ? Number(args[colIdx + 1]) : null;
104
+ const columns = (cliCols && Number.isFinite(cliCols) && cliCols > 0)
105
+ ? cliCols
106
+ : Number(globalThis.process?.env?.AH_COLUMNS || globalThis.process?.stdout?.columns || 80);
107
+
108
+ if (Array.isArray(args) && args.includes('--demo')) {
109
+ const demoState = createInitialTelemetryState('demo', 'claude-sonnet-5-5');
110
+ demoState.contextWindow.totalInputTokens = 64000;
111
+ demoState.contextWindow.cachedTokens = 56000;
112
+ demoState.contextWindow.cacheReadTokens = 56000;
113
+ demoState.contextWindow.systemAndMcpTokens = 8000;
114
+ demoState.promptCache.warm = true;
115
+ demoState.promptCache.ttlSeconds = 252;
116
+ const demoRendered = renderStatusLine(demoState, {
117
+ columns,
118
+ includeDiskLedger: false,
119
+ savedUSD: 1.84
120
+ });
121
+ globalThis.process?.stdout?.write?.(`${demoRendered.line}\n`);
122
+ return demoRendered;
123
+ }
124
+ const payload = await readStdinJsonAsync(1500);
125
+ const result = executeStatusLineBridge(payload, cliCols ? { columns: cliCols } : {});
126
+ globalThis.process?.stdout?.write?.(`${result.line}\n`);
127
+ return result;
128
+ } catch (_err) {
129
+ // Graceful statusLine fallback
130
+ return null;
131
+ }
132
+ }
133
+
134
+ export const main = runStatusLineCli;
135
+
136
+ if (isCliMain()) {
137
+ runStatusLineCli();
138
+ }
139
+
140
+ export default {
141
+ executeStatusLineBridge,
142
+ runStatusLineCli,
143
+ isCliMain,
144
+ main
145
+ };
package/bin/cli.mjs ADDED
@@ -0,0 +1,3 @@
1
+ export * from './ctxtop.mjs';
2
+ import ctxtop from './ctxtop.mjs';
3
+ export default ctxtop;