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.
- package/.antigravity-plugin/plugin.json +36 -0
- package/.claude-plugin/plugin.json +18 -0
- package/CHECKSUMS.sha256 +149 -0
- package/LICENSE +27 -0
- package/README.md +330 -3
- package/SECURITY.md +22 -0
- package/agents/ah-flash-scout.md +25 -0
- package/assets/advanced_view_loaded_420px.png +0 -0
- package/assets/hero-demo.svg +188 -0
- package/assets/logo.svg +19 -0
- package/assets/simple_view_lean_420px.png +0 -0
- package/assets/simple_view_loaded_420px.png +0 -0
- package/assets/social-preview.svg +72 -0
- package/assets/zone_c_step3_shield_full.png +0 -0
- package/bin/ah-statusline.mjs +145 -0
- package/bin/cli.mjs +3 -0
- package/bin/ctxtop.mjs +1474 -0
- package/commands/cost-radar.md +11 -0
- package/commands/evolve.md +10 -0
- package/commands/handoff.md +10 -0
- package/commands/horizon.md +10 -0
- package/commands/inspect.md +10 -0
- package/commands/precheck.md +10 -0
- package/config/default_flightcheck.json +114 -0
- package/config/modelCatalog.json +620 -0
- package/config/platformQuirks.json +19 -0
- package/hooks/handlers/compact-lifecycle.mjs +262 -0
- package/hooks/handlers/hookIo.mjs +255 -0
- package/hooks/handlers/hookIpcClient.mjs +83 -0
- package/hooks/handlers/post-tool-use.mjs +265 -0
- package/hooks/handlers/pre-model-switch.mjs +249 -0
- package/hooks/handlers/pre-tool-use.mjs +365 -0
- package/hooks/handlers/stop-gate.mjs +240 -0
- package/hooks/handlers/user-prompt-submit.mjs +143 -0
- package/hooks/hooks.json +81 -0
- package/hooks/post_invocation.mjs +13 -0
- package/hooks/post_tool_use.mjs +17 -0
- package/hooks/pre_invocation.mjs +14 -0
- package/hooks/pre_tool_use.mjs +97 -0
- package/hooks/register.js +687 -0
- package/hooks/session_start.mjs +14 -0
- package/hooks/stop.mjs +13 -0
- package/hooks.json +56 -0
- package/package.json +103 -4
- package/packages/antigravity/package.json +14 -0
- package/packages/antigravity/src/index.mjs +1 -0
- package/packages/claude-code/package.json +14 -0
- package/packages/claude-code/src/index.mjs +2 -0
- package/packages/core/package.json +14 -0
- package/packages/core/src/index.mjs +1 -0
- package/packages/engine-node/package.json +14 -0
- package/packages/engine-node/src/index.mjs +1 -0
- package/packages/mcp/package.json +17 -0
- package/packages/mcp/src/server.mjs +396 -0
- package/packages/pro/LICENSE-COMMERCIAL.md +19 -0
- package/packages/pro/README-SIGNING.md +30 -0
- package/packages/pro/package.json +16 -0
- package/packages/pro/src/index.mjs +3 -0
- package/packages/pro/src/team_finops_pack.mjs +241 -0
- package/packages/pro/workers/polar_webhook_worker.mjs +215 -0
- package/plugin.json +36 -0
- package/rules/AGENTS.md +10 -0
- package/sidecars/horizon-daemon/ipcServer.mjs +24 -0
- package/sidecars/horizon-daemon/server.mjs +2002 -0
- package/sidecars/horizon-daemon/sidecar.json +19 -0
- package/skills/cost-radar/SKILL.md +21 -0
- package/skills/evolve/SKILL.md +21 -0
- package/skills/handoff/SKILL.md +42 -0
- package/skills/horizon/SKILL.md +17 -0
- package/skills/inspect/SKILL.md +18 -0
- package/skills/precheck/SKILL.md +44 -0
- package/src/adapters/antigravity/index.mjs +79 -0
- package/src/adapters/claude-code/index.mjs +155 -0
- package/src/cli/cost_radar.mjs +70 -0
- package/src/cli/doctor.mjs +351 -0
- package/src/cli/horizon_hud.mjs +686 -0
- package/src/cli/init.mjs +425 -0
- package/src/cli/postmortem.mjs +515 -0
- package/src/coach/cacheGravityRouter.mjs +12 -0
- package/src/config/modelCatalog.json +620 -0
- package/src/config/platformQuirks.json +19 -0
- package/src/core/action_queue.mjs +264 -0
- package/src/core/ag_bridge.mjs +346 -0
- package/src/core/atomic_io.mjs +124 -0
- package/src/core/baseline.mjs +607 -0
- package/src/core/blindspot_sensors.mjs +399 -0
- package/src/core/classifier.mjs +1757 -0
- package/src/core/coach/circuit_breakers.mjs +650 -0
- package/src/core/coach/contradiction_auditor.mjs +239 -0
- package/src/core/coach/effort_advisor.mjs +143 -0
- package/src/core/coach/handoff_hydrator.mjs +483 -0
- package/src/core/coach/progressive_checkpointer.mjs +551 -0
- package/src/core/coach/prompt_decomposer_coach.mjs +141 -0
- package/src/core/coach/reflector_queue.mjs +505 -0
- package/src/core/coach/saved_quota_ledger.mjs +615 -0
- package/src/core/coach/subagent_ipi_sanitizer.mjs +200 -0
- package/src/core/coach/subagent_phantom_auditor.mjs +261 -0
- package/src/core/coach/task_quota_router.mjs +955 -0
- package/src/core/coach/turn_zero_gate.mjs +574 -0
- package/src/core/compaction_coach.mjs +1126 -0
- package/src/core/config.mjs +214 -0
- package/src/core/constants.mjs +1800 -0
- package/src/core/detectors_det01_to_16.mjs +1474 -0
- package/src/core/episodic_memory.mjs +135 -0
- package/src/core/fts5_output_compressor.mjs +359 -0
- package/src/core/git_ledger.mjs +189 -0
- package/src/core/handoff_audit.mjs +558 -0
- package/src/core/history.mjs +221 -0
- package/src/core/hook_diagnostics.mjs +158 -0
- package/src/core/horizon_classifier.mjs +326 -0
- package/src/core/horizon_config.mjs +802 -0
- package/src/core/host_watchdog.mjs +200 -0
- package/src/core/layer5_hygiene.mjs +966 -0
- package/src/core/log_resolver.mjs +231 -0
- package/src/core/mcp_auditor.mjs +138 -0
- package/src/core/micro_skills_store.mjs +91 -0
- package/src/core/offenders.mjs +161 -0
- package/src/core/parser.mjs +1996 -0
- package/src/core/path_canonicalizer.mjs +73 -0
- package/src/core/paths.mjs +310 -0
- package/src/core/prefix_cache_shield.mjs +386 -0
- package/src/core/pro_license.mjs +385 -0
- package/src/core/prompt_rubric.mjs +518 -0
- package/src/core/pruner.mjs +433 -0
- package/src/core/quota.mjs +1860 -0
- package/src/core/rsi_instinct_engine.mjs +1197 -0
- package/src/core/sanitizer.mjs +121 -0
- package/src/core/session_forensics.mjs +303 -0
- package/src/core/session_timeline.mjs +358 -0
- package/src/core/settings.mjs +99 -0
- package/src/core/shared/detectors.mjs +1342 -0
- package/src/core/shared/fnv1a64.mjs +85 -0
- package/src/core/shared/handoff_schema.mjs +123 -0
- package/src/core/shared/index.mjs +5 -0
- package/src/core/shared/ipi_sanitizer.mjs +165 -0
- package/src/core/shared/micro_skills.mjs +1 -0
- package/src/core/shared/plugin_validator.mjs +202 -0
- package/src/core/shared/prompt_hygiene_governor.mjs +1 -0
- package/src/core/sidecar_store.mjs +302 -0
- package/src/core/sprint_metrics.mjs +366 -0
- package/src/core/sqlite_client.mjs +283 -0
- package/src/core/storage_doctor.mjs +358 -0
- package/src/core/subagents.mjs +609 -0
- package/src/core/swarm_topology.mjs +360 -0
- package/src/core/task_quota_router.mjs +1656 -0
- package/src/core/telemetry/cache_ttl_watchdog.mjs +284 -0
- package/src/core/telemetry/scope_lock_registry.mjs +578 -0
- package/src/core/telemetry/shadow_file_detector.mjs +291 -0
- package/src/core/telemetry/trajectory_watcher.mjs +259 -0
- package/src/core/timeline_svg.mjs +236 -0
- package/src/core/tool_surgeon.mjs +305 -0
- package/src/core/trajectory_stitcher.mjs +645 -0
- package/src/core/u_shaped_optimizer.mjs +789 -0
- package/src/core/wal_hygiene.mjs +233 -0
- package/src/core-isomorphic/catalog/detectorCatalog.mjs +558 -0
- package/src/core-isomorphic/catalog/index.mjs +1 -0
- package/src/core-isomorphic/coach/cacheGravityRouter.mjs +720 -0
- package/src/core-isomorphic/coach/microSkills.mjs +1 -0
- package/src/core-isomorphic/coach/promptHygieneGovernor.mjs +1 -0
- package/src/core-isomorphic/coach/repoCalibration.mjs +254 -0
- package/src/core-isomorphic/coach/savedQuotaLedger.mjs +527 -0
- package/src/core-isomorphic/coach/stateBatonHydrator.mjs +810 -0
- package/src/core-isomorphic/coach/ttlWatchdog.mjs +457 -0
- package/src/core-isomorphic/config/anthropicModelCatalog.json +203 -0
- package/src/core-isomorphic/config/catalogLoader.mjs +768 -0
- package/src/core-isomorphic/config/horizonConfig.mjs +1009 -0
- package/src/core-isomorphic/control/callTree.mjs +338 -0
- package/src/core-isomorphic/control/coachLatches.mjs +126 -0
- package/src/core-isomorphic/control/controlStateMachine.mjs +205 -0
- package/src/core-isomorphic/control/index.mjs +49 -0
- package/src/core-isomorphic/control/swarmWorktree.mjs +109 -0
- package/src/core-isomorphic/control/toolSuspension.mjs +197 -0
- package/src/core-isomorphic/diagnostics/drift_guard.mjs +382 -0
- package/src/core-isomorphic/diagnostics/index.mjs +9 -0
- package/src/core-isomorphic/diagnostics/micro_skills.mjs +471 -0
- package/src/core-isomorphic/diagnostics/prompt_hygiene_governor.mjs +622 -0
- package/src/core-isomorphic/economics/billingBlocks.mjs +251 -0
- package/src/core-isomorphic/economics/cacheGravity.mjs +351 -0
- package/src/core-isomorphic/economics/cliffBreaker.mjs +170 -0
- package/src/core-isomorphic/economics/driftLatency.mjs +319 -0
- package/src/core-isomorphic/economics/dualTtl.mjs +198 -0
- package/src/core-isomorphic/economics/index.mjs +47 -0
- package/src/core-isomorphic/economics/retentionRadar.mjs +348 -0
- package/src/core-isomorphic/guards/circuitBreakers.mjs +1202 -0
- package/src/core-isomorphic/guards/det01_03_shell_secret.mjs +1035 -0
- package/src/core-isomorphic/guards/det04_12_thrash_rot.mjs +480 -0
- package/src/core-isomorphic/guards/det13_20_mcp_scope.mjs +603 -0
- package/src/core-isomorphic/guards/losslessPostSanitizer.mjs +301 -0
- package/src/core-isomorphic/index.js +26 -0
- package/src/core-isomorphic/telemetry/otelExporter.mjs +187 -0
- package/src/core-isomorphic/telemetry/scopeLockRegistry.mjs +522 -0
- package/src/core-isomorphic/telemetry/sprintMetrics.mjs +327 -0
- package/src/core-isomorphic/telemetry/swarmTopology.mjs +152 -0
- package/src/core-isomorphic/telemetry/telemetryBridge.mjs +1132 -0
- package/src/core-isomorphic/ui/brailleSparkline.mjs +142 -0
- package/src/core-isomorphic/ui/costRadarSvg.mjs +276 -0
- package/src/core-isomorphic/ui/horizonGrid.mjs +475 -0
- package/src/core-isomorphic/ui/horizonPanelHtml.mjs +1181 -0
- package/src/core-isomorphic/ui/modViews.mjs +1478 -0
- package/src/core-isomorphic/ui/pdfReceiptGenerator.mjs +329 -0
- package/src/core-isomorphic/ustf/index.mjs +7 -0
- package/src/core-isomorphic/ustf/normalizer.mjs +512 -0
- package/src/core-isomorphic/ustf/schema.mjs +186 -0
- package/src/core-isomorphic/utils/runtime.mjs +962 -0
- package/src/demo/synthetic_states.mjs +661 -0
- package/src/diagnostics/bugReportGenerator.mjs +253 -0
- package/src/diagnostics/doctorEngine.mjs +203 -0
- package/src/engine-node/db/index.mjs +58 -0
- package/src/engine-node/db/jsonl_fallback.mjs +184 -0
- package/src/engine-node/db/probe.mjs +110 -0
- package/src/engine-node/db/sqlite_wrapper.mjs +122 -0
- package/src/engine-node/index.mjs +9 -0
- package/src/engine-node/ipc/client.mjs +447 -0
- package/src/engine-node/ipc/index.mjs +22 -0
- package/src/engine-node/ipc/protocol.mjs +177 -0
- package/src/engine-node/ipc/server.mjs +445 -0
- package/src/engine-node/offloader/index.mjs +6 -0
- package/src/engine-node/offloader/tool_offloader.mjs +241 -0
- package/src/engine-node/sensors/blindspots.mjs +369 -0
- package/src/engine-node/sensors/git_merge_tree.mjs +223 -0
- package/src/engine-node/sensors/index.mjs +7 -0
- package/src/hooks/portfolio_runtime.mjs +858 -0
- package/src/hooks/post_invocation.mjs +419 -0
- package/src/hooks/pre_invocation.mjs +1015 -0
- package/src/hooks/session_start.mjs +161 -0
- package/src/shims/agy_cli_compressor.mjs +705 -0
- package/src/shims/agy_git_guard.mjs +749 -0
- package/src/shims/ah_log_query.mjs +39 -0
- package/src/ui/costRadarSvg.mjs +6 -0
- package/src/ui/horizonGrid.mjs +1 -0
- package/src/ui/horizonPanelHtml.mjs +1 -0
- package/src/ui/horizon_panel.css +167 -0
- package/src/ui/horizon_panel.js +212 -0
- package/src/ui/modViews.mjs +1 -0
- package/src/utils/nodeIo.mjs +59 -0
- package/src/utils/runtime.mjs +1 -0
- package/src/webview/advanced_view.html +1808 -0
- package/src/webview/horizon_panel.html +11389 -0
- package/src/webview/registry.mjs +80 -0
- package/src/webview/simple_view.html +1370 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "horizon-daemon",
|
|
3
|
+
"display_name": "Highbeam",
|
|
4
|
+
"description": "40-cell chronological context window analyzer, U-shaped attention recall curve, and wasted context ledger.",
|
|
5
|
+
"command": "node",
|
|
6
|
+
"args": ["--no-warnings", "server.mjs"],
|
|
7
|
+
"port": 62935,
|
|
8
|
+
"port_range": [62935, 62945],
|
|
9
|
+
"has_web_ui": true,
|
|
10
|
+
"ui_config": {
|
|
11
|
+
"views": [
|
|
12
|
+
{
|
|
13
|
+
"entrypoint": "SIDECAR_UI_ENTRYPOINT_AUX_PANE",
|
|
14
|
+
"path": "/",
|
|
15
|
+
"title": "Highbeam"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cost-radar
|
|
3
|
+
description: Render the Cost Radar HTML/SVG timeline (prefix-cache retention, thinking drift / DET-30 loops, swarm & worktree topology) as a Studio artifact.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Cost Radar (`/cost-radar`)
|
|
7
|
+
|
|
8
|
+
When this command is invoked, render a self-contained HTML/SVG timeline of where the current session spends (and saves) tokens.
|
|
9
|
+
|
|
10
|
+
## Steps:
|
|
11
|
+
1. Run `node --no-warnings ./src/cli/init.mjs cost-radar --json --out <artifactDirectoryPath>/cost_radar.html`.
|
|
12
|
+
- Read-only: it parses local transcripts and `git worktree list`; it makes no network calls.
|
|
13
|
+
2. Output an inline visual embed of the generated artifact:
|
|
14
|
+
```html
|
|
15
|
+
<agent-embed src="file:///<artifactDirectoryPath>/cost_radar.html"></agent-embed>
|
|
16
|
+
```
|
|
17
|
+
3. Summarize in at most 3 lines using the JSON fields `retention`, `drift`, and `swarm`.
|
|
18
|
+
- If `loopTriggered` is `true`, lead with the DET-30 scratchpad-loop warning and recommend injecting a concrete constraint (target file + acceptance test) or stepping effort down.
|
|
19
|
+
- Values shown as `—` are unmeasured — never invent numbers for them.
|
|
20
|
+
4. Offer the live side pane pill:
|
|
21
|
+
[Open Highbeam](sidecar://agy-horizon-flightcheck/horizon-daemon/)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: evolve
|
|
3
|
+
description: Audit static AGENTS.md prefix bloat (>8,000 tokens), route post-skill corrections to domain SKILL.md files, and synthesize >=5 validated instincts via 1-click user diff approval gated by TurnZeroGate.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Highbeam Prefix Diet & Skill Fault Router (`/evolve`)
|
|
7
|
+
|
|
8
|
+
Use `/evolve` when static workspace rules (`AGENTS.md` / `.agents/rules/*.md`) exceed the **8,000-token** static prefix budget, or after repeated domain corrections have accumulated at least **5 validated Atomic Instincts**.
|
|
9
|
+
|
|
10
|
+
## Guardrails & Execution Rules (`RSI-01`)
|
|
11
|
+
1. **Static Prefix Diet (`> 8,000` Tokens):**
|
|
12
|
+
- Measure static rule overhead across `AGENTS.md` and `.agents/rules/*.md`.
|
|
13
|
+
- When static overhead exceeds `8,000` tokens, propose extracting domain-specific sections into lazy-loaded `.agents/skills/<domain>/SKILL.md` bundles so Turn-0 prefix tokens stay lean.
|
|
14
|
+
2. **Skill Fault Delta Routing:**
|
|
15
|
+
- When a user correction immediately follows an executed skill (`<skill-name>`), route the proposed rule delta to `.agents/skills/<skill-name>/SKILL.md` rather than polluting global `AGENTS.md`.
|
|
16
|
+
3. **5-Instinct Synthesis Floor & Zero Recursive Critique:**
|
|
17
|
+
- Synthesize a new domain `SKILL.md` draft **only** when `>= 5` validated domain instincts exist (`confidence >= 0.55`, `harmful_count == 0`).
|
|
18
|
+
- **Strictly forbidden:** Never spawn recursive LLM self-critique subagents during skill evolution.
|
|
19
|
+
4. **Mandatory 1-Click User Diff Approval + `TurnZeroGate`:**
|
|
20
|
+
- Present a unified diff for explicit user approval before any file write.
|
|
21
|
+
- Route approved writes exclusively through `TurnZeroGate` so `AGENTS.md` and active rule prefixes are never mutated while a session KV cache is warm.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: handoff
|
|
3
|
+
description: Audit and write a compressed, actionable task.md checkpoint before running /compact or handing off across sessions.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Session Handoff & State Compression (`/handoff`)
|
|
7
|
+
|
|
8
|
+
The `/handoff` command audits the current session checkpoint in `task.md`, `STATE.md`, or `HANDOFF.md` to guarantee that all architectural decisions, active blockers, and immediate next steps are preserved before context compaction or session rotation.
|
|
9
|
+
|
|
10
|
+
## State Compressor Taxonomy
|
|
11
|
+
|
|
12
|
+
When writing or updating `task.md`, apply the **KEEP / DROP** filter:
|
|
13
|
+
|
|
14
|
+
### KEEP
|
|
15
|
+
- **Decisions:** Every architectural or design choice with a 1-sentence rationale and alternatives considered.
|
|
16
|
+
- **Blockers:** Active error loops or unresolved impediments with severity (`Low`, `Medium`, `High`) and context.
|
|
17
|
+
- **Artifacts:** Specific files created, modified, or deleted with explicit paths.
|
|
18
|
+
- **State Changes:** Milestone progress and deliverables verified.
|
|
19
|
+
- **Next Action:** Single, specific, unblocked next action with exact file target (`@file` or symbol).
|
|
20
|
+
|
|
21
|
+
### DROP
|
|
22
|
+
- **Reasoning Traces:** Exploration narratives ("I tried X, then Y, then Z worked — record only Z").
|
|
23
|
+
- **Dead-End Scaffolding:** Resolved temporary debug scripts and raw stack traces.
|
|
24
|
+
- **Vague Directives:** "Continue working", "Finish implementation", or "WIP".
|
|
25
|
+
|
|
26
|
+
## 5-Point Handoff Audit Checklist
|
|
27
|
+
|
|
28
|
+
1. **Next Action Clarity:** The first unchecked item `- [ ]` or `## Next Action` specifies an exact file target and concrete action verb.
|
|
29
|
+
2. **Incomplete Coverage:** In-progress items `[/]` document the specific files being modified.
|
|
30
|
+
3. **Blocker Accuracy:** Any unresolved command failures or error loops are recorded in `## Blockers`.
|
|
31
|
+
4. **Decision Completeness:** If the plan changed, the decision rationale is captured in `## Decisions`.
|
|
32
|
+
5. **Freshness:** `task.md` reflects the current user turn and latest verified state.
|
|
33
|
+
|
|
34
|
+
## Recommended Usage
|
|
35
|
+
|
|
36
|
+
1. Write or update `task.md`, `implementation_plan.md`, and `walkthrough.md` in the session brain directory using the State Compressor format, and verify working-tree git status (`git status --porcelain`).
|
|
37
|
+
2. Generate a structured Baton Pass handoff artifact (`docs/HANDOFF_<timestamp>.md`) via the Highbeam panel's **"Generate Handoff Markdown"** button (`POST /api/handoff/generate`) or run audit verification:
|
|
38
|
+
```bash
|
|
39
|
+
node --no-warnings ./src/cli/init.mjs --demo
|
|
40
|
+
```
|
|
41
|
+
3. When the audit reports `CLEAN ✅` and the KV cache window is ready, advise the user with the parameterized compaction prompt:
|
|
42
|
+
> Type `/compact` in the chat box and press Enter (preserving active exported symbols, `task.md` checklist state, and explicit in-chat constraints).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: horizon
|
|
3
|
+
description: Inspect real-time 40-cell context health, Context Truncation risk, and Wasted Tokens.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Highbeam (`/horizon`)
|
|
7
|
+
|
|
8
|
+
When this command is invoked, visualize the current conversation context health.
|
|
9
|
+
|
|
10
|
+
## Steps:
|
|
11
|
+
1. Run `node --no-warnings ./src/cli/horizon_hud.mjs --emit-widget` to produce the self-contained HTML card at `<artifactDirectoryPath>/horizon_widget.html`.
|
|
12
|
+
2. Output an inline visual embed:
|
|
13
|
+
```html
|
|
14
|
+
<agent-embed src="file:///<artifactDirectoryPath>/horizon_widget.html"></agent-embed>
|
|
15
|
+
```
|
|
16
|
+
3. Offer a one-click auxiliary side pane pill:
|
|
17
|
+
[Open Highbeam](sidecar://agy-horizon-flightcheck/horizon-daemon/)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: inspect
|
|
3
|
+
description: Inspect session trajectory call-tree spans, tool latencies, and swarm topology as a Studio artifact.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Session Inspection (`/inspect`)
|
|
7
|
+
|
|
8
|
+
When this command is invoked, inspect the execution spans, tool calls, and swarm topology of the current session.
|
|
9
|
+
|
|
10
|
+
## Steps:
|
|
11
|
+
1. Run `node --no-warnings ./bin/ctxtop.mjs inspect --last --out <artifactDirectoryPath>/inspect_call_tree.json`.
|
|
12
|
+
- Read-only: it parses local USTF v1 trajectories and transcript snapshots; it makes no network calls.
|
|
13
|
+
2. Output an inline visual embed:
|
|
14
|
+
```html
|
|
15
|
+
<agent-embed src="file:///<artifactDirectoryPath>/inspect_call_tree.json"></agent-embed>
|
|
16
|
+
```
|
|
17
|
+
3. Offer the live side pane pill:
|
|
18
|
+
[Open Highbeam](sidecar://agy-horizon-flightcheck/horizon-daemon/)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: precheck
|
|
3
|
+
description: Analyze a prompt for best practices, context hygiene, and optimal Antigravity model/effort configuration before execution.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Flight Check Prompt Precheck (`/precheck`)
|
|
7
|
+
|
|
8
|
+
The `/precheck` command evaluates draft user prompts, current context window health, and active attention hygiene to prevent token waste, prompt ambiguity, and server-side prefix amputation before spending high-effort quota.
|
|
9
|
+
|
|
10
|
+
## How It Works
|
|
11
|
+
|
|
12
|
+
1. **Context Telemetry Inspection:**
|
|
13
|
+
Reads the local session sidecar at `~/.gemini/flightcheck/sessions/<conversationId>.sidecar.json` (<2ms) to extract:
|
|
14
|
+
- 40-cell attention window (Signal Purity %, Sludge Tax $/turn, Amputation Risk).
|
|
15
|
+
- 6 blind-spot hazards (`DIRTY_SNAP`, `SCHEMA_TAX`, `UNSEEN_CALLERS`, `LEGACY_POISON`, `QUOTA_AND_STREAM_SHIELD`, `LOOP_AND_GIT_GUARD`).
|
|
16
|
+
- Active recency tail (`ACTIVE_SET`) vs stale reads (`STALE_DUP`).
|
|
17
|
+
|
|
18
|
+
2. **The 8-State Decision Rubric:**
|
|
19
|
+
- `ALLOW_SILENT`: Prompt is clean, scoped, or prefixed with `!` / `!force`.
|
|
20
|
+
- `ALLOW_ACTIVE_SET`: Explicit file tags omitted, but targets exist in Green `ACTIVE_SET`.
|
|
21
|
+
- `ALLOW_PLAN_OR_SUBAGENT`: Session is actively in `/plan` mode or delegated to `invoke_subagent`.
|
|
22
|
+
- `INJECT_CONTEXT_GUARD`: Injects background system guardrails for external file modifications or unseen importers.
|
|
23
|
+
- `STEER_SUBAGENT`: Context is warm (>25k tokens, >70% Purity) on low/medium effort; delegates complex concurrency or architecture refactors to `invoke_subagent` to avoid wiping the KV cache.
|
|
24
|
+
- `HALT_HYGIENE_OR_SAFETY`: Stops execution when Amputation risk is active (>140k tokens), Purity is <45% on high effort, 3-strike loops occur, or foreign KI memory is detected.
|
|
25
|
+
- `HALT_EFFORT_OR_QUOTA`: Stops cold-cache pro/max overkill on trivial edits or when 5-hour quota drops below 10%.
|
|
26
|
+
- `HALT_REWRITE_SCORECARD`: Formats the 4-Line Scorecard with an improved, scoped rewrite.
|
|
27
|
+
|
|
28
|
+
## Output Format: 4-Line Scorecard UX
|
|
29
|
+
|
|
30
|
+
```text
|
|
31
|
+
╭─ Flight Check v3.1 ──────────────────────────────────────────────────────────╮
|
|
32
|
+
│ 1. PROMPT : [Score XX/100] Scope: <ScopeStatus> | Target: <TargetFiles> │
|
|
33
|
+
│ 2. HORIZON: [Purity: XX% | Sludge: +$0.XX/t | Tokens: XXk/200k | Quota: XX%]│
|
|
34
|
+
│ 3. ACTION : /model <recommended_model> • /effort <recommended_effort> │
|
|
35
|
+
│ 4. REWRITE: "<copy-pasteable scoped prompt or remediation command>" │
|
|
36
|
+
╰──────────────────────────────────────────────────────────────────────────────╯
|
|
37
|
+
Bypass once: prefix with `!` • Lock model/effort: include `!lock`
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Control Flags
|
|
41
|
+
|
|
42
|
+
- `! <prompt>` or `!force <prompt>`: Bypasses Flight Check gating for one turn.
|
|
43
|
+
- `!lock <prompt>`: Locks the current `/model` and `/effort` for the duration of the conversation.
|
|
44
|
+
- `#check <prompt>`: Forces Tier 2 semantic analysis, prompt scoring, and scorecard rewriting.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Antigravity Adapter (`src/adapters/antigravity/index.mjs`)
|
|
3
|
+
*
|
|
4
|
+
* Bridges Antigravity IDE / CLI lifecycle hooks (`SessionStart`, `PreInvocation`,
|
|
5
|
+
* `PostInvocation`, `Stop`, `PreToolUse`, `PostToolUse`), Turn-Boundary Model Switch
|
|
6
|
+
* Buffering, and `/swarm` Idle-TTL + Cold-Cache Wakeup sensors.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
handlePreInvocation,
|
|
11
|
+
handlePreToolUse
|
|
12
|
+
} from '../../hooks/pre_invocation.mjs';
|
|
13
|
+
import {
|
|
14
|
+
handlePostInvocation,
|
|
15
|
+
handlePostToolUse
|
|
16
|
+
} from '../../hooks/post_invocation.mjs';
|
|
17
|
+
import {
|
|
18
|
+
TurnBoundaryModelSwitchBuffer,
|
|
19
|
+
trackModelCachePools,
|
|
20
|
+
detectRouterThrash,
|
|
21
|
+
computeQuotaAndCacheTelemetry
|
|
22
|
+
} from '../../core/quota.mjs';
|
|
23
|
+
import {
|
|
24
|
+
SwarmIdleTtlTracker,
|
|
25
|
+
evaluateSwarmColdCacheWakeup,
|
|
26
|
+
computeSwarmRosterTtlBadges,
|
|
27
|
+
SWARM_IDLE_TTL_CONSTANTS
|
|
28
|
+
} from '../../core/subagents.mjs';
|
|
29
|
+
import {
|
|
30
|
+
SWARM_TOOL_MATCHER,
|
|
31
|
+
FLAT_LIFECYCLE_EVENTS,
|
|
32
|
+
validateAntigravityHooksSchema
|
|
33
|
+
} from '../../core/layer5_hygiene.mjs';
|
|
34
|
+
import { buildHooksConfig } from '../../cli/init.mjs';
|
|
35
|
+
import {
|
|
36
|
+
formatAgentCacheKey,
|
|
37
|
+
formatAgentStreamKey,
|
|
38
|
+
parseAgentCacheKey,
|
|
39
|
+
resolveModelDescriptor,
|
|
40
|
+
resolveModelRates,
|
|
41
|
+
calculateModelCost,
|
|
42
|
+
computeUnifiedContextPool,
|
|
43
|
+
evaluateCarbonVerbosityGuardrail
|
|
44
|
+
} from '../../core/constants.mjs';
|
|
45
|
+
import {
|
|
46
|
+
readSidecarSync,
|
|
47
|
+
writeSidecarAtomicSync,
|
|
48
|
+
updateSwarmAgentStateAtomicSync
|
|
49
|
+
} from '../../core/sidecar_store.mjs';
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
handlePreInvocation,
|
|
53
|
+
handlePreToolUse,
|
|
54
|
+
handlePostInvocation,
|
|
55
|
+
handlePostToolUse,
|
|
56
|
+
TurnBoundaryModelSwitchBuffer,
|
|
57
|
+
trackModelCachePools,
|
|
58
|
+
detectRouterThrash,
|
|
59
|
+
computeQuotaAndCacheTelemetry,
|
|
60
|
+
SwarmIdleTtlTracker,
|
|
61
|
+
evaluateSwarmColdCacheWakeup,
|
|
62
|
+
computeSwarmRosterTtlBadges,
|
|
63
|
+
SWARM_IDLE_TTL_CONSTANTS,
|
|
64
|
+
SWARM_TOOL_MATCHER,
|
|
65
|
+
FLAT_LIFECYCLE_EVENTS,
|
|
66
|
+
validateAntigravityHooksSchema,
|
|
67
|
+
buildHooksConfig,
|
|
68
|
+
formatAgentCacheKey,
|
|
69
|
+
formatAgentStreamKey,
|
|
70
|
+
parseAgentCacheKey,
|
|
71
|
+
resolveModelDescriptor,
|
|
72
|
+
resolveModelRates,
|
|
73
|
+
calculateModelCost,
|
|
74
|
+
computeUnifiedContextPool,
|
|
75
|
+
evaluateCarbonVerbosityGuardrail,
|
|
76
|
+
readSidecarSync,
|
|
77
|
+
writeSidecarAtomicSync,
|
|
78
|
+
updateSwarmAgentStateAtomicSync
|
|
79
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code Adapter (`src/adapters/claude-code/index.mjs`)
|
|
3
|
+
*
|
|
4
|
+
* Normalizes single-agent and subagent Claude Code CLI payloads so `agent_id`
|
|
5
|
+
* defaults to `"primary"` when absent, constructs composite cache keys
|
|
6
|
+
* `${session_id}::${agent_id}::${model_id}`, and delegates cache/thrash tracking
|
|
7
|
+
* to Shared Core.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
formatAgentCacheKey,
|
|
12
|
+
formatAgentStreamKey,
|
|
13
|
+
parseAgentCacheKey,
|
|
14
|
+
normalizeModelKey,
|
|
15
|
+
resolveModelDescriptor,
|
|
16
|
+
resolveModelRates,
|
|
17
|
+
calculateModelCost
|
|
18
|
+
} from '../../core/constants.mjs';
|
|
19
|
+
import {
|
|
20
|
+
resolveStepAgentId,
|
|
21
|
+
trackModelCachePools,
|
|
22
|
+
detectRouterThrash,
|
|
23
|
+
computeQuotaAndCacheTelemetry
|
|
24
|
+
} from '../../core/quota.mjs';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Normalizes a Claude Code event payload, defaulting `agent_id` to `"primary"`
|
|
28
|
+
* when absent and computing its composite cache key `${session_id}::${agent_id}::${model_id}`.
|
|
29
|
+
*/
|
|
30
|
+
export function normalizeClaudeCodePayload(payload = {}) {
|
|
31
|
+
const sessionId = String(payload.session_id || payload.sessionId || payload.conversationId || 'default_session').trim() || 'default_session';
|
|
32
|
+
const agentId = resolveStepAgentId(payload);
|
|
33
|
+
const rawModel = payload.model?.id || payload.message?.model || payload.model_id || payload.modelId || payload.model || 'claude-sonnet-5-5';
|
|
34
|
+
const modelId = normalizeModelKey(rawModel);
|
|
35
|
+
const compositeCacheKey = formatAgentCacheKey(sessionId, agentId, modelId);
|
|
36
|
+
const streamKey = formatAgentStreamKey(sessionId, agentId);
|
|
37
|
+
|
|
38
|
+
const usage = payload.message?.usage || payload.usage || payload.token_usage || {};
|
|
39
|
+
const nestedCreate = (usage.cache_creation && typeof usage.cache_creation === 'object')
|
|
40
|
+
? usage.cache_creation
|
|
41
|
+
: ((payload.cache_creation && typeof payload.cache_creation === 'object') ? payload.cache_creation : null);
|
|
42
|
+
const write5mTokens = Math.max(0, Number(
|
|
43
|
+
payload.cacheCreationEphemeral5mInputTokens ??
|
|
44
|
+
payload.cache_creation_ephemeral_5m_input_tokens ??
|
|
45
|
+
usage.cache_creation_ephemeral_5m_input_tokens ??
|
|
46
|
+
nestedCreate?.ephemeral_5m_input_tokens ??
|
|
47
|
+
0
|
|
48
|
+
) || 0);
|
|
49
|
+
const write1hTokens = Math.max(0, Number(
|
|
50
|
+
payload.cacheCreationEphemeral1hInputTokens ??
|
|
51
|
+
payload.cache_creation_ephemeral_1h_input_tokens ??
|
|
52
|
+
usage.cache_creation_ephemeral_1h_input_tokens ??
|
|
53
|
+
nestedCreate?.ephemeral_1h_input_tokens ??
|
|
54
|
+
0
|
|
55
|
+
) || 0);
|
|
56
|
+
const inputTokens = Math.max(0, Number(
|
|
57
|
+
payload.inputTokens ??
|
|
58
|
+
payload.input_tokens ??
|
|
59
|
+
usage.input_tokens ??
|
|
60
|
+
0
|
|
61
|
+
) || 0);
|
|
62
|
+
const cacheReadTokens = Math.max(0, Number(
|
|
63
|
+
payload.cacheReadTokens ??
|
|
64
|
+
payload.cache_read_input_tokens ??
|
|
65
|
+
usage.cache_read_input_tokens ??
|
|
66
|
+
0
|
|
67
|
+
) || 0);
|
|
68
|
+
const flatCreate = Math.max(0, Number(
|
|
69
|
+
payload.cacheCreationTokens ??
|
|
70
|
+
payload.cache_creation_input_tokens ??
|
|
71
|
+
usage.cache_creation_input_tokens ??
|
|
72
|
+
0
|
|
73
|
+
) || 0);
|
|
74
|
+
const cacheCreationTokens = flatCreate > 0 ? flatCreate : (write5mTokens + write1hTokens);
|
|
75
|
+
const outputTokens = Math.max(0, Number(
|
|
76
|
+
payload.outputTokens ??
|
|
77
|
+
payload.output_tokens ??
|
|
78
|
+
usage.output_tokens ??
|
|
79
|
+
0
|
|
80
|
+
) || 0);
|
|
81
|
+
const totalPromptTokens = inputTokens + cacheReadTokens + cacheCreationTokens;
|
|
82
|
+
const messageId = payload.message?.id || payload.message_id || payload.messageId || null;
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
...payload,
|
|
86
|
+
session_id: sessionId,
|
|
87
|
+
agent_id: agentId,
|
|
88
|
+
model_id: modelId,
|
|
89
|
+
modelId,
|
|
90
|
+
messageId,
|
|
91
|
+
freshInputTokens: inputTokens,
|
|
92
|
+
inputTokens,
|
|
93
|
+
cacheReadTokens,
|
|
94
|
+
cacheCreationTokens,
|
|
95
|
+
write5mTokens: (write5mTokens > 0 || write1hTokens > 0) ? write5mTokens : cacheCreationTokens,
|
|
96
|
+
write1hTokens,
|
|
97
|
+
outputTokens,
|
|
98
|
+
totalPromptTokens,
|
|
99
|
+
ttlSeconds: write1hTokens > 0 ? 3600 : 300,
|
|
100
|
+
compositeCacheKey,
|
|
101
|
+
streamKey
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Tracks cache state and router thrash across a sequence of Claude Code events
|
|
107
|
+
* using composite keys `${session_id}::${agent_id}::${model_id}`, deduplicating
|
|
108
|
+
* streaming assistant chunks by `message.id` so only the final chunk's usage is counted.
|
|
109
|
+
*/
|
|
110
|
+
export function trackClaudeCodeSessionCache(events = [], options = {}) {
|
|
111
|
+
const list = Array.isArray(events) ? events : [];
|
|
112
|
+
const rawNormalized = list.map(e => normalizeClaudeCodePayload(e));
|
|
113
|
+
const normalized = [];
|
|
114
|
+
const msgIdxMap = new Map();
|
|
115
|
+
|
|
116
|
+
for (const ev of rawNormalized) {
|
|
117
|
+
const key = ev.messageId ? `${ev.streamKey}::${ev.messageId}` : '';
|
|
118
|
+
if (key && msgIdxMap.has(key)) {
|
|
119
|
+
normalized[msgIdxMap.get(key)] = ev;
|
|
120
|
+
} else {
|
|
121
|
+
if (key) msgIdxMap.set(key, normalized.length);
|
|
122
|
+
normalized.push(ev);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const sessionId = options.sessionId || normalized[0]?.session_id || 'default_session';
|
|
127
|
+
const isAutoMode = Boolean(options.isAutoMode ?? false);
|
|
128
|
+
|
|
129
|
+
const pools = trackModelCachePools(normalized, { sessionId, nowMs: options.nowMs });
|
|
130
|
+
const thrash = detectRouterThrash(normalized, isAutoMode, {
|
|
131
|
+
sessionId,
|
|
132
|
+
standbyCache: pools.standbyCache,
|
|
133
|
+
lastSwitchEvent: pools.lastSwitchEvent
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
sessionId,
|
|
138
|
+
normalizedEvents: normalized,
|
|
139
|
+
...pools,
|
|
140
|
+
...thrash
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export {
|
|
145
|
+
formatAgentCacheKey,
|
|
146
|
+
formatAgentStreamKey,
|
|
147
|
+
parseAgentCacheKey,
|
|
148
|
+
resolveStepAgentId,
|
|
149
|
+
trackModelCachePools,
|
|
150
|
+
detectRouterThrash,
|
|
151
|
+
computeQuotaAndCacheTelemetry,
|
|
152
|
+
resolveModelDescriptor,
|
|
153
|
+
resolveModelRates,
|
|
154
|
+
calculateModelCost
|
|
155
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { runCLI } from './horizon_hud.mjs';
|
|
4
|
+
import { atomicWriteFileSync } from '../core/atomic_io.mjs';
|
|
5
|
+
import { getFlightcheckDir } from '../core/sidecar_store.mjs';
|
|
6
|
+
import { renderCostRadarHtml } from '../core/timeline_svg.mjs';
|
|
7
|
+
import { formatRetentionLabel, formatDriftLabel } from '../core/sprint_metrics.mjs';
|
|
8
|
+
import { formatSwarmLabel } from '../core/swarm_topology.mjs';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Sprint 2.2 — `ctxtop cost-radar` / `/cost-radar` skill backend.
|
|
12
|
+
* Builds the HTML/SVG timeline artifact from the live classifier state (read-only).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export function buildCostRadarFromState(state = {}, { edition = 'Antigravity', generatedAt = null } = {}) {
|
|
16
|
+
const retention = state?.quota?.cache?.prefixRetention || null;
|
|
17
|
+
const drift = state?.quota?.thinkingDrift || null;
|
|
18
|
+
const topology = state?.swarmTopology || null;
|
|
19
|
+
const modelLabel = state?.model?.label || state?.model?.id || (typeof state?.model === 'string' ? state.model : '');
|
|
20
|
+
const html = renderCostRadarHtml({
|
|
21
|
+
retention,
|
|
22
|
+
drift,
|
|
23
|
+
topology,
|
|
24
|
+
meta: {
|
|
25
|
+
sessionTitle: state?.sessionTitle || '',
|
|
26
|
+
model: modelLabel,
|
|
27
|
+
edition,
|
|
28
|
+
generatedAt: generatedAt || new Date().toISOString()
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const summary = {
|
|
32
|
+
retention: retention ? (retention.label || formatRetentionLabel(retention)) : 'Retain —',
|
|
33
|
+
drift: drift ? (drift.label || formatDriftLabel(drift)) : 'Think —',
|
|
34
|
+
swarm: formatSwarmLabel(topology) || 'Solo',
|
|
35
|
+
loopTriggered: Boolean(drift?.loop?.triggered)
|
|
36
|
+
};
|
|
37
|
+
return { html, summary };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function parseCostRadarArgs(args = []) {
|
|
41
|
+
const outIdx = args.indexOf('--out');
|
|
42
|
+
const convIdx = args.indexOf('--conversation');
|
|
43
|
+
return {
|
|
44
|
+
out: outIdx !== -1 && args[outIdx + 1] ? args[outIdx + 1] : null,
|
|
45
|
+
conversationId: convIdx !== -1 && args[convIdx + 1] ? args[convIdx + 1] : null,
|
|
46
|
+
json: args.includes('--json'),
|
|
47
|
+
demo: args.includes('--demo')
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function runCostRadar({ out = null, conversationId = null, json = false, demo = false } = {}) {
|
|
52
|
+
const res = await runCLI({
|
|
53
|
+
silent: true,
|
|
54
|
+
useNativeCeiling: true,
|
|
55
|
+
demoScenario: demo ? 5 : null,
|
|
56
|
+
stdinData: conversationId ? { conversation_id: conversationId } : null
|
|
57
|
+
});
|
|
58
|
+
const state = res?.state || {};
|
|
59
|
+
const { html, summary } = buildCostRadarFromState(state);
|
|
60
|
+
const target = path.resolve(out || path.join(getFlightcheckDir(), 'cost_radar.html'));
|
|
61
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
62
|
+
atomicWriteFileSync(target, html, { encoding: 'utf8' });
|
|
63
|
+
const result = { ok: true, path: target, fileUri: `file:///${target.replace(/\\/g, '/').replace(/^\/+/, '')}`, ...summary };
|
|
64
|
+
if (json) {
|
|
65
|
+
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
|
|
66
|
+
} else {
|
|
67
|
+
process.stdout.write(`Cost Radar written: ${result.fileUri}\n ${summary.retention}\n ${summary.drift}\n ${summary.swarm}\n`);
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|