ctxtop 0.0.0-stage → 4.1.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 +166 -0
- package/LICENSE +27 -0
- package/README.md +350 -2
- 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 +175 -0
- package/bin/cli.mjs +3 -0
- package/bin/ctxtop.mjs +1799 -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 +133 -0
- package/config/modelCatalog.json +785 -0
- package/config/platformQuirks.json +19 -0
- package/hooks/handlers/compact-lifecycle.mjs +577 -0
- package/hooks/handlers/config-change.mjs +402 -0
- package/hooks/handlers/hookIo.mjs +311 -0
- package/hooks/handlers/hookIpcClient.mjs +83 -0
- package/hooks/handlers/post-model-switch.mjs +111 -0
- package/hooks/handlers/post-tool-use.mjs +366 -0
- package/hooks/handlers/pre-model-switch.mjs +1048 -0
- package/hooks/handlers/pre-tool-use.mjs +632 -0
- package/hooks/handlers/stop-gate.mjs +526 -0
- package/hooks/handlers/user-prompt-submit.mjs +367 -0
- package/hooks/hooks.json +131 -0
- package/hooks/post_invocation.mjs +13 -0
- package/hooks/post_tool_use.mjs +25 -0
- package/hooks/pre_invocation.mjs +14 -0
- package/hooks/pre_tool_use.mjs +97 -0
- package/hooks/register.js +726 -0
- package/hooks/session_start.mjs +24 -0
- package/hooks/stop.mjs +23 -0
- package/hooks.json +56 -0
- package/package.json +110 -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 +2038 -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 +50 -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 +109 -0
- package/src/adapters/claude-code/index.mjs +194 -0
- package/src/cli/cost_radar.mjs +70 -0
- package/src/cli/doctor.mjs +351 -0
- package/src/cli/horizon_hud.mjs +888 -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 +704 -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/bucket_b_runtime.mjs +1200 -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 +1987 -0
- package/src/core/detectors_det01_to_16.mjs +1523 -0
- package/src/core/doc_indexer.mjs +338 -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 +1084 -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 +1997 -0
- package/src/core/path_canonicalizer.mjs +73 -0
- package/src/core/paths.mjs +311 -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/rsl_clash_auditor.mjs +423 -0
- package/src/core/rsl_distiller.mjs +372 -0
- package/src/core/rsl_ledger.mjs +969 -0
- package/src/core/rsl_triage.mjs +909 -0
- package/src/core/sanitizer.mjs +121 -0
- package/src/core/session_auditor.mjs +658 -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/shield_manager.mjs +1417 -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 +1547 -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/resumeToolsetAuditor.mjs +321 -0
- package/src/core-isomorphic/coach/savedQuotaLedger.mjs +527 -0
- package/src/core-isomorphic/coach/smartCompactAdvisor.mjs +305 -0
- package/src/core-isomorphic/coach/stateBatonHydrator.mjs +810 -0
- package/src/core-isomorphic/coach/ttlWatchdog.mjs +464 -0
- package/src/core-isomorphic/config/anthropicModelCatalog.json +606 -0
- package/src/core-isomorphic/config/catalogLoader.mjs +1268 -0
- package/src/core-isomorphic/config/horizonConfig.mjs +1055 -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 +888 -0
- package/src/core-isomorphic/economics/billingBlocks.mjs +251 -0
- package/src/core-isomorphic/economics/cacheGravity.mjs +369 -0
- package/src/core-isomorphic/economics/cliffBreaker.mjs +256 -0
- package/src/core-isomorphic/economics/driftLatency.mjs +433 -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/bucketBAlphaBeta.mjs +860 -0
- package/src/core-isomorphic/guards/bucketBGamma.mjs +442 -0
- package/src/core-isomorphic/guards/bucketBHeuristics.mjs +37 -0
- package/src/core-isomorphic/guards/circuitBreakers.mjs +1202 -0
- package/src/core-isomorphic/guards/det01_03_shell_secret.mjs +1184 -0
- package/src/core-isomorphic/guards/det04_12_thrash_rot.mjs +572 -0
- package/src/core-isomorphic/guards/det13_20_mcp_scope.mjs +913 -0
- package/src/core-isomorphic/guards/docIndexCore.mjs +446 -0
- package/src/core-isomorphic/guards/losslessPostSanitizer.mjs +317 -0
- package/src/core-isomorphic/guards/slopsquatGate.mjs +551 -0
- package/src/core-isomorphic/index.js +27 -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 +1156 -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 +1237 -0
- package/src/core-isomorphic/ui/modViews.mjs +1504 -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/claudeHookCapabilities.mjs +396 -0
- package/src/diagnostics/doctorEngine.mjs +295 -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 +342 -0
- package/src/engine-node/db/sqlite_wrapper.mjs +122 -0
- package/src/engine-node/index.mjs +12 -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 +376 -0
- package/src/engine-node/sensors/git_merge_tree.mjs +223 -0
- package/src/engine-node/sensors/index.mjs +7 -0
- package/src/hooks/antigravity_rsl_hook.mjs +250 -0
- package/src/hooks/claude_rsl_hook.mjs +288 -0
- package/src/hooks/portfolio_runtime.mjs +858 -0
- package/src/hooks/post_invocation.mjs +611 -0
- package/src/hooks/pre_invocation.mjs +1725 -0
- package/src/hooks/session_start.mjs +199 -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/modelSwitchTelemetry.mjs +308 -0
- package/src/utils/nodeIo.mjs +59 -0
- package/src/utils/runtime.mjs +1 -0
- package/src/utils/sessionCalibration.mjs +657 -0
- package/src/webview/advanced_view.html +1808 -0
- package/src/webview/horizon_panel.html +12397 -0
- package/src/webview/registry.mjs +80 -0
- package/src/webview/simple_view.html +1370 -0
package/src/cli/init.mjs
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { exec } from 'node:child_process';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { getHomeDir, ensureSupportedNodeVersion, parseCliHarnessArg } from '../core/paths.mjs';
|
|
7
|
+
import { findSessionDirectory } from '../core/parser.mjs';
|
|
8
|
+
import { atomicWriteFileSync } from '../core/atomic_io.mjs';
|
|
9
|
+
import { runCLI, runDemoShowcase, formatActionQueueAnsi } from './horizon_hud.mjs';
|
|
10
|
+
import { startServer } from '../../sidecars/horizon-daemon/server.mjs';
|
|
11
|
+
import { runPostmortem, printPostmortemSummary } from './postmortem.mjs';
|
|
12
|
+
import { runDoctor, parseDoctorArgs } from './doctor.mjs';
|
|
13
|
+
import { runCostRadar, parseCostRadarArgs } from './cost_radar.mjs';
|
|
14
|
+
import { compressCliOutputFts5, searchToolLogsFts5 } from '../core/fts5_output_compressor.mjs';
|
|
15
|
+
import {
|
|
16
|
+
SWARM_TOOL_MATCHER,
|
|
17
|
+
FULL_TOOL_HOOK_MATCHER,
|
|
18
|
+
LEAN_PRE_TOOL_HOOK_MATCHER,
|
|
19
|
+
LEAN_POST_TOOL_HOOK_MATCHER,
|
|
20
|
+
ULTRA_LEAN_PRE_TOOL_HOOK_MATCHER,
|
|
21
|
+
validateAntigravityHooksSchema
|
|
22
|
+
} from '../core/layer5_hygiene.mjs';
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
SWARM_TOOL_MATCHER,
|
|
26
|
+
FULL_TOOL_HOOK_MATCHER,
|
|
27
|
+
LEAN_PRE_TOOL_HOOK_MATCHER,
|
|
28
|
+
LEAN_POST_TOOL_HOOK_MATCHER,
|
|
29
|
+
ULTRA_LEAN_PRE_TOOL_HOOK_MATCHER,
|
|
30
|
+
validateAntigravityHooksSchema
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
34
|
+
const PACKAGE_ROOT = path.resolve(__dirname, '../..');
|
|
35
|
+
|
|
36
|
+
function getVersion() {
|
|
37
|
+
try {
|
|
38
|
+
const p = path.join(PACKAGE_ROOT, 'package.json');
|
|
39
|
+
if (fs.existsSync(p)) {
|
|
40
|
+
const data = JSON.parse(fs.readFileSync(p, 'utf8'));
|
|
41
|
+
if (data.version) return data.version;
|
|
42
|
+
}
|
|
43
|
+
} catch (err) {
|
|
44
|
+
if (process.env.DEBUG) console.error('[init] getVersion fallback:', err);
|
|
45
|
+
}
|
|
46
|
+
return '3.4.0';
|
|
47
|
+
}
|
|
48
|
+
const VERSION = getVersion();
|
|
49
|
+
|
|
50
|
+
export function buildHooksConfig(targetPluginDir = '.', options = {}) {
|
|
51
|
+
const useRelative = !targetPluginDir || targetPluginDir === '.';
|
|
52
|
+
const preMatcher = options.fullHooks
|
|
53
|
+
? FULL_TOOL_HOOK_MATCHER
|
|
54
|
+
: (options.leanHooks ? ULTRA_LEAN_PRE_TOOL_HOOK_MATCHER : LEAN_PRE_TOOL_HOOK_MATCHER);
|
|
55
|
+
const postMatcher = options.fullHooks ? FULL_TOOL_HOOK_MATCHER : LEAN_POST_TOOL_HOOK_MATCHER;
|
|
56
|
+
const cmdFor = (relHook, fallbackScript, extraArg = '') => {
|
|
57
|
+
const suffix = extraArg ? ` ${extraArg}` : '';
|
|
58
|
+
if (useRelative) return `node ./hooks/${relHook}`;
|
|
59
|
+
const norm = path.join(targetPluginDir, 'src/hooks', fallbackScript).replace(/\\/g, '/');
|
|
60
|
+
const safePath = /\s/.test(norm) ? `"${norm}"` : norm;
|
|
61
|
+
return `node --no-warnings ${safePath}${suffix}`;
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
hooks: {
|
|
65
|
+
SessionStart: [
|
|
66
|
+
{
|
|
67
|
+
type: 'command',
|
|
68
|
+
command: cmdFor('session_start.mjs', 'session_start.mjs'),
|
|
69
|
+
timeout: 5
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
PreInvocation: [
|
|
73
|
+
{
|
|
74
|
+
type: 'command',
|
|
75
|
+
command: cmdFor('pre_invocation.mjs', 'pre_invocation.mjs'),
|
|
76
|
+
timeout: 5
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
PostInvocation: [
|
|
80
|
+
{
|
|
81
|
+
type: 'command',
|
|
82
|
+
command: cmdFor('post_invocation.mjs', 'post_invocation.mjs'),
|
|
83
|
+
timeout: 5
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
Stop: [
|
|
87
|
+
{
|
|
88
|
+
type: 'command',
|
|
89
|
+
command: cmdFor('stop.mjs', 'post_invocation.mjs'),
|
|
90
|
+
timeout: 5
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
PreToolUse: [
|
|
94
|
+
{
|
|
95
|
+
matcher: preMatcher,
|
|
96
|
+
hooks: [
|
|
97
|
+
{
|
|
98
|
+
type: 'command',
|
|
99
|
+
command: cmdFor('pre_tool_use.mjs', 'pre_invocation.mjs', '--event=PreToolUse'),
|
|
100
|
+
timeout: 5
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
PostToolUse: [
|
|
106
|
+
{
|
|
107
|
+
matcher: postMatcher,
|
|
108
|
+
hooks: [
|
|
109
|
+
{
|
|
110
|
+
type: 'command',
|
|
111
|
+
command: cmdFor('post_tool_use.mjs', 'post_invocation.mjs'),
|
|
112
|
+
timeout: 5
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function installPlugin(options = {}) {
|
|
122
|
+
const {
|
|
123
|
+
dryRun = false,
|
|
124
|
+
workspace = false,
|
|
125
|
+
dedupe = false,
|
|
126
|
+
leanHooks = false,
|
|
127
|
+
fullHooks = false,
|
|
128
|
+
cwd = process.cwd(),
|
|
129
|
+
homeDir = options.home || getHomeDir()
|
|
130
|
+
} = options;
|
|
131
|
+
const home = homeDir;
|
|
132
|
+
const targetPluginDir = workspace
|
|
133
|
+
? path.resolve(cwd, '.agents', 'plugins', 'agy-horizon-flightcheck')
|
|
134
|
+
: path.join(home, '.gemini', 'config', 'plugins', 'agy-horizon-flightcheck');
|
|
135
|
+
|
|
136
|
+
console.log(`\n\x1b[1m\x1b[38;5;51m⚡ Highbeam (attention-horizon-antigravity v${VERSION}) — Zero-Config Installer\x1b[0m`);
|
|
137
|
+
console.log(` • Mode : ${workspace ? 'Workspace (.agents/plugins)' : 'Global (~/.gemini/config/plugins)'}${dryRun ? ' [DRY RUN]' : ''}`);
|
|
138
|
+
console.log(` • Source : ${PACKAGE_ROOT}`);
|
|
139
|
+
console.log(` • Target : ${targetPluginDir}`);
|
|
140
|
+
|
|
141
|
+
// Deduplicate legacy duplicate plugin folder (~/.gemini/config/plugins/agy-horizon)
|
|
142
|
+
if (!workspace) {
|
|
143
|
+
const legacyPluginDir = path.join(home, '.gemini', 'config', 'plugins', 'agy-horizon');
|
|
144
|
+
if (fs.existsSync(legacyPluginDir)) {
|
|
145
|
+
if (!dryRun) {
|
|
146
|
+
try {
|
|
147
|
+
fs.rmSync(legacyPluginDir, { recursive: true, force: true });
|
|
148
|
+
console.log(` \x1b[38;5;82m✓\x1b[0m Removed legacy duplicate plugin directory (~/.gemini/config/plugins/agy-horizon)`);
|
|
149
|
+
} catch (err) {
|
|
150
|
+
console.log(` \x1b[38;5;214m▲\x1b[0m Legacy directory in use; recommend manual deletion of ~/.gemini/config/plugins/agy-horizon: ${err.message}`);
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
console.log(` \x1b[38;5;82m✓\x1b[0m [DRY RUN] Would remove legacy duplicate plugin directory (~/.gemini/config/plugins/agy-horizon)`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const toCopy = [
|
|
159
|
+
'plugin.json',
|
|
160
|
+
'package.json',
|
|
161
|
+
'README.md',
|
|
162
|
+
'bin',
|
|
163
|
+
'config',
|
|
164
|
+
'assets',
|
|
165
|
+
'rules',
|
|
166
|
+
'skills',
|
|
167
|
+
'sidecars',
|
|
168
|
+
'src',
|
|
169
|
+
'hooks',
|
|
170
|
+
'commands'
|
|
171
|
+
];
|
|
172
|
+
|
|
173
|
+
if (!dryRun) {
|
|
174
|
+
fs.mkdirSync(targetPluginDir, { recursive: true });
|
|
175
|
+
for (const item of toCopy) {
|
|
176
|
+
const srcItem = path.join(PACKAGE_ROOT, item);
|
|
177
|
+
const destItem = path.join(targetPluginDir, item);
|
|
178
|
+
if (fs.existsSync(srcItem)) {
|
|
179
|
+
fs.cpSync(srcItem, destItem, { recursive: true });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Write dynamically resolved hooks.json so both global and workspace installs work across Windows/macOS/Linux
|
|
184
|
+
const resolvedHooks = buildHooksConfig(targetPluginDir, { leanHooks, fullHooks });
|
|
185
|
+
atomicWriteFileSync(
|
|
186
|
+
path.join(targetPluginDir, 'hooks.json'),
|
|
187
|
+
JSON.stringify(resolvedHooks, null, 2) + '\n',
|
|
188
|
+
{ encoding: 'utf8' }
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
console.log(' \x1b[38;5;82m✓\x1b[0m Deployed plugin files & cross-platform lifecycle hooks (SessionStart, PreInvocation, PostInvocation)');
|
|
192
|
+
|
|
193
|
+
const settingsPaths = [
|
|
194
|
+
path.join(home, '.gemini', 'antigravity', 'settings.json'),
|
|
195
|
+
path.join(home, '.gemini', 'antigravity-cli', 'settings.json')
|
|
196
|
+
];
|
|
197
|
+
|
|
198
|
+
const hudScriptPath = path.join(targetPluginDir, 'src', 'cli', 'horizon_hud.mjs').replace(/\\/g, '/');
|
|
199
|
+
for (const sPath of settingsPaths) {
|
|
200
|
+
let settings = {};
|
|
201
|
+
if (fs.existsSync(sPath)) {
|
|
202
|
+
try {
|
|
203
|
+
settings = JSON.parse(fs.readFileSync(sPath, 'utf8'));
|
|
204
|
+
if (!dryRun) {
|
|
205
|
+
atomicWriteFileSync(`${sPath}.bak`, JSON.stringify(settings, null, 2) + '\n', { encoding: 'utf8' });
|
|
206
|
+
}
|
|
207
|
+
} catch (err) {
|
|
208
|
+
settings = {};
|
|
209
|
+
if (process.env.DEBUG) console.error(`[init] Failed parsing ${sPath}:`, err);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
settings.statusLine = {
|
|
214
|
+
type: 'command',
|
|
215
|
+
command: `node --no-warnings "${hudScriptPath}"`,
|
|
216
|
+
interval_ms: 300,
|
|
217
|
+
stack_with_default: true
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
if (!dryRun) {
|
|
221
|
+
atomicWriteFileSync(sPath, JSON.stringify(settings, null, 2) + '\n', { encoding: 'utf8' });
|
|
222
|
+
}
|
|
223
|
+
console.log(` \x1b[38;5;82m✓\x1b[0m Configured CLI statusLine in ${sPath}`);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
console.log('\n\x1b[1m\x1b[38;5;82m✓ Installation complete in <2 seconds!\x1b[0m');
|
|
227
|
+
return { success: true, targetPluginDir, dryRun, leanHooks: Boolean(leanHooks), fullHooks: Boolean(fullHooks) };
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export async function runContextRoast() {
|
|
231
|
+
const result = await runPostmortem({ last: 15, writeFiles: false });
|
|
232
|
+
const isSynthetic = result.isSynthetic;
|
|
233
|
+
const auditedSessions = result.sessionCount;
|
|
234
|
+
const estTokensM = result.estTokensM;
|
|
235
|
+
const dupCount = result.totalDuplicateReads;
|
|
236
|
+
const errCount = result.totalDeadErrors;
|
|
237
|
+
const ampCount = result.amputationSessionsCount;
|
|
238
|
+
const worstPurity = `${result.worstPurityPct}%`;
|
|
239
|
+
const sludgeUsd = result.sludgeUsdFormatted;
|
|
240
|
+
|
|
241
|
+
console.log(`\n\x1b[1m\x1b[38;5;208m╭── HIGHBEAM FORENSIC AUDIT (ctxtop v${VERSION}) ───────────────────────╮\x1b[0m`);
|
|
242
|
+
console.log(`\x1b[38;5;208m│\x1b[0m Sessions Audited : \x1b[1m${auditedSessions} sessions\x1b[0m (${estTokensM} cumulative tokens inspected)${isSynthetic ? ' [Demo]' : ''}`);
|
|
243
|
+
console.log(`\x1b[38;5;208m│\x1b[0m Useful Context % : \x1b[38;5;196m\x1b[1m${worstPurity} worst\x1b[0m (${result.avgPurityPct}% avg across sessions)`);
|
|
244
|
+
console.log(`\x1b[38;5;208m│\x1b[0m Redundant Reads : \x1b[38;5;214m${dupCount} duplicate file reads\x1b[0m + \x1b[38;5;196m${errCount} dead stack traces\x1b[0m kept in memory`);
|
|
245
|
+
console.log(`\x1b[38;5;208m│\x1b[0m Wasted Tokens : \x1b[38;5;214m\x1b[1m${sludgeUsd}\x1b[0m wasted re-sending stale context to the model`);
|
|
246
|
+
console.log(`\x1b[38;5;208m│\x1b[0m Truncation Risk : \x1b[38;5;196m${ampCount} sessions crossed safe horizon\x1b[0m (oldest rules at risk)`);
|
|
247
|
+
console.log('\x1b[1m\x1b[38;5;208m╰───────────────────────────────────────────────────────────────────────────╯\x1b[0m');
|
|
248
|
+
|
|
249
|
+
if (result.hotspots && result.hotspots.length > 0) {
|
|
250
|
+
console.log('\x1b[1mTop Duplicate-Read Offenders:\x1b[0m');
|
|
251
|
+
for (const h of result.hotspots.slice(0, 3)) {
|
|
252
|
+
const wastedK = Math.max(0.1, (h.wastedTokens / 1000).toFixed(1));
|
|
253
|
+
console.log(` • ${h.path} (${h.occurrences}x reads, ~${wastedK}k tok wasted across ${h.sessionsAffected} session(s))`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (result.recommendations && result.recommendations.length > 0) {
|
|
258
|
+
console.log('\n\x1b[1mActionable Remediations:\x1b[0m');
|
|
259
|
+
for (const [idx, rec] of result.recommendations.slice(0, 3).entries()) {
|
|
260
|
+
console.log(` ${idx + 1}. [\x1b[38;5;51m${rec.id}\x1b[0m] ${rec.change_to_make}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
console.log('');
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function printHelp() {
|
|
267
|
+
console.log(`
|
|
268
|
+
\x1b[1m\x1b[38;5;51m⚡ Highbeam (attention-horizon-antigravity / ctxtop v${VERSION})\x1b[0m — htop for AI Coding Agent Context Windows
|
|
269
|
+
|
|
270
|
+
\x1b[1mUSAGE:\x1b[0m
|
|
271
|
+
npx attention-horizon-antigravity [--harness=claude|cursor] Auto-discover active Antigravity session & print live 40-cell HUD
|
|
272
|
+
npx attention-horizon-antigravity ui [--open] Launch local Simple View Web UI on 127.0.0.1:62935 & open in browser
|
|
273
|
+
npx attention-horizon-antigravity init [--workspace] Install plugin, hooks & CLI statusLine
|
|
274
|
+
npx attention-horizon-antigravity --demo [--scenario 1..8] Preview 40-cell HUD & Flight Check Scorecard
|
|
275
|
+
npx attention-horizon-antigravity --demo-animate Play live 5-stage terminal crisis animation
|
|
276
|
+
npx attention-horizon-antigravity --roast Audit local logs & print shareable Context Roast Card
|
|
277
|
+
npx attention-horizon-antigravity doctor Diagnose hooks, configuration, mirrors & transcript health
|
|
278
|
+
npx attention-horizon-antigravity prune [--dry-run] Prune stale tool outputs and fold AST stubs in active transcript
|
|
279
|
+
npx attention-horizon-antigravity postmortem [--last N] Generate forensic report & diagnostic dataset
|
|
280
|
+
`);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export function openBrowserUrl(url) {
|
|
284
|
+
if (process.env.CTXTOP_NO_BROWSER === '1') return;
|
|
285
|
+
try {
|
|
286
|
+
const cmd = process.platform === 'win32'
|
|
287
|
+
? `cmd /c start "" "${url}"`
|
|
288
|
+
: (process.platform === 'darwin' ? `open "${url}"` : `xdg-open "${url}"`);
|
|
289
|
+
exec(cmd, () => {});
|
|
290
|
+
} catch (err) {
|
|
291
|
+
if (process.env.DEBUG) console.error('[init] openBrowserUrl fallback:', err);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export async function runLiveOrDemoCli(options = {}) {
|
|
296
|
+
const home = options.homeDir || getHomeDir();
|
|
297
|
+
const discoveryOpts = {
|
|
298
|
+
harness: options.harness || null,
|
|
299
|
+
includeCrossHost: Boolean(options.includeCrossHost)
|
|
300
|
+
};
|
|
301
|
+
const sessionInfo = findSessionDirectory(options.sessionId || null, home, discoveryOpts);
|
|
302
|
+
if (sessionInfo && sessionInfo.sessionDir && fs.existsSync(sessionInfo.sessionDir)) {
|
|
303
|
+
const res = await runCLI({
|
|
304
|
+
silent: true,
|
|
305
|
+
sessionDirOverride: sessionInfo.sessionDir,
|
|
306
|
+
useNativeCeiling: true
|
|
307
|
+
});
|
|
308
|
+
if (res && res.state) {
|
|
309
|
+
const sTag = res.state.surfaceTag || sessionInfo.surfaceTag || '[App]';
|
|
310
|
+
const title = res.state.sessionTitle ? ` · "${res.state.sessionTitle}"` : '';
|
|
311
|
+
console.log(`\n\x1b[1m\x1b[38;5;51m⚡ HIGHBEAM (ctxtop v${VERSION})\x1b[0m — Live ${sTag} Session (${res.state.sessionId.slice(0, 8)})${title}`);
|
|
312
|
+
console.log(res.output);
|
|
313
|
+
const aq = formatActionQueueAnsi(res.state);
|
|
314
|
+
if (aq) console.log(aq);
|
|
315
|
+
console.log(`\x1b[38;5;245mTip: Run 'npx attention-horizon-antigravity ui' for interactive browser view | 'npx ctxtop --roast' for multi-session audit\x1b[0m\n`);
|
|
316
|
+
return { mode: 'live', state: res.state, output: res.output };
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
console.log('\x1b[38;5;245mℹ No active Antigravity session found on disk — showing interactive demo:\x1b[0m');
|
|
320
|
+
await runDemoShowcase({ scenarioId: 5, animate: false });
|
|
321
|
+
return { mode: 'demo', state: null };
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export function isCliMain(argv1 = process.argv[1], metaUrl = import.meta.url) {
|
|
325
|
+
if (!argv1) return false;
|
|
326
|
+
try {
|
|
327
|
+
return fs.realpathSync(argv1) === fs.realpathSync(fileURLToPath(metaUrl));
|
|
328
|
+
} catch {
|
|
329
|
+
return path.resolve(argv1) === path.resolve(fileURLToPath(metaUrl));
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const isMain = isCliMain();
|
|
334
|
+
|
|
335
|
+
if (isMain) {
|
|
336
|
+
ensureSupportedNodeVersion();
|
|
337
|
+
const binName = path.basename(process.argv[1] || '');
|
|
338
|
+
const args = process.argv.slice(2);
|
|
339
|
+
const cmd = binName.includes('agy-horizon-exec')
|
|
340
|
+
? 'exec'
|
|
341
|
+
: (binName.includes('agy-log-search') ? 'log-search' : (args[0] || 'live'));
|
|
342
|
+
|
|
343
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
344
|
+
printHelp();
|
|
345
|
+
} else if (cmd === 'log-search' || cmd === 'agy-log-search') {
|
|
346
|
+
const offset = (args[0] === 'log-search' || args[0] === 'agy-log-search') ? 1 : 0;
|
|
347
|
+
const turnId = args[offset] || '';
|
|
348
|
+
const keyword = args.slice(offset + 1).join(' ');
|
|
349
|
+
searchToolLogsFts5(null, { turnId, keyword }).then(res => {
|
|
350
|
+
for (const m of res.matchedLines) {
|
|
351
|
+
console.log(`[${m.turnId}:${m.lineNumber}] ${m.text}`);
|
|
352
|
+
}
|
|
353
|
+
process.exit(0);
|
|
354
|
+
});
|
|
355
|
+
} else if (cmd === 'exec' || cmd === 'agy-horizon-exec') {
|
|
356
|
+
const offset = (args[0] === 'exec' || args[0] === 'agy-horizon-exec') ? 1 : 0;
|
|
357
|
+
const execCmd = args.slice(offset).join(' ');
|
|
358
|
+
exec(execCmd, { maxBuffer: 16 * 1024 * 1024 }, async (err, stdout, stderr) => {
|
|
359
|
+
const rawOutput = `${stdout || ''}${stderr ? `\n${stderr}` : ''}`;
|
|
360
|
+
const exitCode = err && typeof err.code === 'number' ? err.code : (err ? 1 : 0);
|
|
361
|
+
const comp = await compressCliOutputFts5({
|
|
362
|
+
command: execCmd,
|
|
363
|
+
exitCode,
|
|
364
|
+
rawOutput,
|
|
365
|
+
turnId: `turn-${Date.now()}`
|
|
366
|
+
});
|
|
367
|
+
process.stdout.write(comp.output + '\n');
|
|
368
|
+
process.exit(exitCode);
|
|
369
|
+
});
|
|
370
|
+
} else if (cmd === 'init' || args.includes('--install')) {
|
|
371
|
+
const dryRun = args.includes('--dry-run');
|
|
372
|
+
const workspace = args.includes('--workspace');
|
|
373
|
+
const leanHooks = args.includes('--lean-hooks');
|
|
374
|
+
const fullHooks = args.includes('--full-hooks');
|
|
375
|
+
installPlugin({ dryRun, workspace, leanHooks, fullHooks });
|
|
376
|
+
runDemoShowcase({ scenarioId: 5, animate: false });
|
|
377
|
+
} else if (cmd === 'roast' || args.includes('--roast')) {
|
|
378
|
+
runContextRoast();
|
|
379
|
+
} else if (cmd === 'prune' || args.includes('--prune') || args.includes('--prune-tools')) {
|
|
380
|
+
const dryRun = args.includes('--dry-run');
|
|
381
|
+
runDoctor({ pruneTools: true, dryRun }).then(res => {
|
|
382
|
+
process.exit(res.ok === false ? 1 : 0);
|
|
383
|
+
});
|
|
384
|
+
} else if (cmd === 'doctor' || args.includes('--doctor')) {
|
|
385
|
+
const cliOpts = parseDoctorArgs(args);
|
|
386
|
+
runDoctor(cliOpts).then(res => {
|
|
387
|
+
process.exit(res.ok === false ? 1 : 0);
|
|
388
|
+
});
|
|
389
|
+
} else if (cmd === 'cost-radar' || args.includes('--cost-radar')) {
|
|
390
|
+
runCostRadar(parseCostRadarArgs(args)).then(res => {
|
|
391
|
+
process.exit(res && res.ok ? 0 : 1);
|
|
392
|
+
}).catch(err => {
|
|
393
|
+
console.error(`cost-radar failed: ${err?.message || err}`);
|
|
394
|
+
process.exit(1);
|
|
395
|
+
});
|
|
396
|
+
} else if (cmd === 'postmortem' || args.includes('--postmortem')) {
|
|
397
|
+
const lastIdx = args.indexOf('--last');
|
|
398
|
+
const last = lastIdx !== -1 ? Number(args[lastIdx + 1]) : 15;
|
|
399
|
+
const json = args.includes('--json');
|
|
400
|
+
runPostmortem({ last, json, writeFiles: true }).then(res => {
|
|
401
|
+
if (!json) {
|
|
402
|
+
printPostmortemSummary(res);
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
} else if (cmd === 'ui' || cmd === 'serve' || args.includes('--serve') || args.includes('--open')) {
|
|
406
|
+
if (args.includes('--demo')) {
|
|
407
|
+
process.env.HORIZON_DEMO = '1';
|
|
408
|
+
}
|
|
409
|
+
const shouldOpenBrowser = (cmd === 'ui' || args.includes('ui') || args.includes('--open')) && !args.includes('--no-open');
|
|
410
|
+
startServer().then(({ port }) => {
|
|
411
|
+
const url = `http://127.0.0.1:${port}`;
|
|
412
|
+
console.log(`\x1b[1m\x1b[38;5;82m✓ Highbeam Web UI Live at:\x1b[0m \x1b[38;5;51m${url}\x1b[0m (Press Ctrl+C to stop)`);
|
|
413
|
+
if (shouldOpenBrowser) {
|
|
414
|
+
openBrowserUrl(url);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
} else if (cmd === '--demo' || cmd === 'demo' || args.includes('--demo') || args.includes('--demo-animate') || args.includes('--scenario')) {
|
|
418
|
+
const scenIdx = args.indexOf('--scenario');
|
|
419
|
+
const scenarioId = scenIdx !== -1 ? Number(args[scenIdx + 1]) : null;
|
|
420
|
+
runDemoShowcase({ scenarioId, animate: args.includes('--demo-animate') });
|
|
421
|
+
} else {
|
|
422
|
+
const cliHarness = parseCliHarnessArg(args);
|
|
423
|
+
runLiveOrDemoCli({ harness: cliHarness });
|
|
424
|
+
}
|
|
425
|
+
}
|