ctxtop 4.0.0 → 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 +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHECKSUMS.sha256 +59 -42
- package/README.md +351 -330
- package/bin/ah-statusline.mjs +30 -0
- package/bin/ctxtop.mjs +330 -5
- package/config/default_flightcheck.json +19 -0
- package/config/modelCatalog.json +165 -0
- package/hooks/handlers/compact-lifecycle.mjs +323 -8
- package/hooks/handlers/config-change.mjs +402 -0
- package/hooks/handlers/hookIo.mjs +56 -0
- package/hooks/handlers/post-model-switch.mjs +111 -0
- package/hooks/handlers/post-tool-use.mjs +117 -16
- package/hooks/handlers/pre-model-switch.mjs +823 -24
- package/hooks/handlers/pre-tool-use.mjs +271 -4
- package/hooks/handlers/stop-gate.mjs +297 -11
- package/hooks/handlers/user-prompt-submit.mjs +224 -0
- package/hooks/hooks.json +50 -0
- package/hooks/post_tool_use.mjs +8 -0
- package/hooks/register.js +48 -9
- package/hooks/session_start.mjs +11 -1
- package/hooks/stop.mjs +11 -1
- package/package.json +11 -4
- package/packages/antigravity/package.json +1 -1
- package/packages/claude-code/package.json +1 -1
- package/packages/core/package.json +1 -1
- package/packages/engine-node/package.json +1 -1
- package/packages/mcp/package.json +1 -1
- package/packages/mcp/src/server.mjs +1 -1
- package/packages/pro/package.json +1 -1
- package/plugin.json +1 -1
- package/sidecars/horizon-daemon/server.mjs +38 -2
- package/skills/handoff/SKILL.md +8 -0
- package/src/adapters/antigravity/index.mjs +31 -1
- package/src/adapters/claude-code/index.mjs +40 -1
- package/src/cli/horizon_hud.mjs +254 -52
- package/src/config/modelCatalog.json +84 -0
- package/src/core/bucket_b_runtime.mjs +1200 -0
- package/src/core/constants.mjs +191 -4
- package/src/core/detectors_det01_to_16.mjs +54 -5
- package/src/core/doc_indexer.mjs +338 -0
- package/src/core/layer5_hygiene.mjs +118 -0
- package/src/core/parser.mjs +2 -1
- package/src/core/paths.mjs +3 -2
- 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/session_auditor.mjs +658 -0
- package/src/core/shield_manager.mjs +1417 -0
- package/src/core/task_quota_router.mjs +1 -1
- package/src/core-isomorphic/coach/cacheGravityRouter.mjs +874 -47
- package/src/core-isomorphic/coach/resumeToolsetAuditor.mjs +321 -0
- package/src/core-isomorphic/coach/smartCompactAdvisor.mjs +305 -0
- package/src/core-isomorphic/coach/ttlWatchdog.mjs +13 -6
- package/src/core-isomorphic/config/anthropicModelCatalog.json +404 -1
- package/src/core-isomorphic/config/catalogLoader.mjs +546 -46
- package/src/core-isomorphic/config/horizonConfig.mjs +47 -1
- package/src/core-isomorphic/diagnostics/prompt_hygiene_governor.mjs +266 -0
- package/src/core-isomorphic/economics/cacheGravity.mjs +18 -0
- package/src/core-isomorphic/economics/cliffBreaker.mjs +98 -12
- package/src/core-isomorphic/economics/driftLatency.mjs +114 -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 +191 -191
- package/src/core-isomorphic/guards/det01_03_shell_secret.mjs +154 -5
- package/src/core-isomorphic/guards/det04_12_thrash_rot.mjs +103 -11
- package/src/core-isomorphic/guards/det13_20_mcp_scope.mjs +311 -1
- package/src/core-isomorphic/guards/docIndexCore.mjs +446 -0
- package/src/core-isomorphic/guards/losslessPostSanitizer.mjs +16 -0
- package/src/core-isomorphic/guards/slopsquatGate.mjs +551 -0
- package/src/core-isomorphic/index.js +1 -0
- package/src/core-isomorphic/telemetry/telemetryBridge.mjs +36 -12
- package/src/core-isomorphic/ui/horizonPanelHtml.mjs +293 -237
- package/src/core-isomorphic/ui/modViews.mjs +35 -9
- package/src/diagnostics/claudeHookCapabilities.mjs +396 -0
- package/src/diagnostics/doctorEngine.mjs +95 -3
- package/src/engine-node/db/probe.mjs +234 -2
- package/src/engine-node/index.mjs +3 -0
- package/src/engine-node/sensors/blindspots.mjs +13 -6
- package/src/hooks/antigravity_rsl_hook.mjs +250 -0
- package/src/hooks/claude_rsl_hook.mjs +288 -0
- package/src/hooks/post_invocation.mjs +196 -4
- package/src/hooks/pre_invocation.mjs +732 -22
- package/src/hooks/session_start.mjs +39 -1
- package/src/utils/modelSwitchTelemetry.mjs +308 -0
- package/src/utils/sessionCalibration.mjs +657 -0
- package/src/webview/horizon_panel.html +1325 -317
|
@@ -15,9 +15,12 @@ import {
|
|
|
15
15
|
} from '../../src/core-isomorphic/guards/circuitBreakers.mjs';
|
|
16
16
|
import { loadHorizonConfig, resolveDetectorOverride } from '../../src/core-isomorphic/config/horizonConfig.mjs';
|
|
17
17
|
import { recordWorkspaceShellOutcome } from '../../src/core-isomorphic/coach/microSkills.mjs';
|
|
18
|
+
import { evaluateTaskBoundaryTurn } from '../../src/core-isomorphic/coach/smartCompactAdvisor.mjs';
|
|
18
19
|
import { recordSavingsReceipt } from '../../src/core-isomorphic/coach/savedQuotaLedger.mjs';
|
|
19
20
|
import { readLiveStateSnapshot } from '../../src/core-isomorphic/telemetry/telemetryBridge.mjs';
|
|
20
21
|
import { resolveEffectiveRates, computeTotalPromptTokens } from '../../src/core-isomorphic/config/catalogLoader.mjs';
|
|
22
|
+
import { runBucketBPostToolPass } from '../../src/core/bucket_b_runtime.mjs';
|
|
23
|
+
import { handleClaudeRslHook } from '../../src/hooks/claude_rsl_hook.mjs';
|
|
21
24
|
import {
|
|
22
25
|
isCliEntrypoint,
|
|
23
26
|
readStdinJsonAsync,
|
|
@@ -104,36 +107,92 @@ export function runPostToolUseHook(event = {}, options = {}) {
|
|
|
104
107
|
const cwdOptions = event.cwd && !options.cwd ? { ...options, cwd: event.cwd } : options;
|
|
105
108
|
const horizonConfig = options.horizonConfig || loadHorizonConfig(cwdOptions);
|
|
106
109
|
|
|
110
|
+
const hasExplicitCwd = Boolean(event.cwd || options.cwd);
|
|
111
|
+
let loadedPriorSnap = null;
|
|
107
112
|
const shouldPersistState =
|
|
108
113
|
options.persistState !== false &&
|
|
109
114
|
Boolean(event.cwd || options.cwd || options.breakerStatePath || options.persistState);
|
|
110
115
|
|
|
111
116
|
if (shouldPersistState) {
|
|
117
|
+
if (hasExplicitCwd && options.enableRsl !== false) {
|
|
118
|
+
try {
|
|
119
|
+
handleClaudeRslHook(event, { ...cwdOptions, event: 'PostToolUse' });
|
|
120
|
+
} catch {
|
|
121
|
+
// Fail open for RSL step telemetry
|
|
122
|
+
}
|
|
123
|
+
}
|
|
112
124
|
const failed = didToolExecutionFail(event);
|
|
113
125
|
const priorSnap = readBreakerStateSnapshot(sessionId, cwdOptions);
|
|
126
|
+
loadedPriorSnap = priorSnap;
|
|
114
127
|
const engine = new CircuitBreakerEngine({
|
|
115
128
|
...cwdOptions,
|
|
116
129
|
horizonConfig,
|
|
117
130
|
mode: event.mode || options.mode || horizonConfig.flightMode || 'COACH',
|
|
118
131
|
initialState: priorSnap
|
|
119
132
|
});
|
|
133
|
+
const toolInput = event.tool_input || event.toolInput || {};
|
|
134
|
+
const cmdStr = String(toolInput.command || toolInput.cmd || event.command || '');
|
|
135
|
+
const rawExit =
|
|
136
|
+
event.exit_code ??
|
|
137
|
+
event.exitCode ??
|
|
138
|
+
event.tool_response?.exit_code ??
|
|
139
|
+
event.tool_response?.exitCode;
|
|
120
140
|
engine.recordToolOutcome(!failed, toolName);
|
|
141
|
+
if (/^(Bash|PowerShell|pwsh|cmd|sh|run_command|execute_bash)$/i.test(toolName)) {
|
|
142
|
+
engine.recordVerificationOutcome({
|
|
143
|
+
succeeded: !failed,
|
|
144
|
+
command: cmdStr,
|
|
145
|
+
outputText: rawOutput
|
|
146
|
+
});
|
|
147
|
+
}
|
|
121
148
|
if (failed && engine.modifiedFilesInTurn.size > 0) {
|
|
122
149
|
// If a test command failed, code edits remain unverified
|
|
123
150
|
engine.codeEditedSinceLastTest = true;
|
|
124
151
|
}
|
|
125
|
-
|
|
152
|
+
const boundaryEval = evaluateTaskBoundaryTurn(
|
|
153
|
+
{
|
|
154
|
+
toolName,
|
|
155
|
+
command: cmdStr,
|
|
156
|
+
failed,
|
|
157
|
+
exitCode: typeof rawExit === 'number' ? rawExit : (failed ? 1 : 0)
|
|
158
|
+
},
|
|
159
|
+
engine.taskBoundaryState
|
|
160
|
+
);
|
|
161
|
+
engine.taskBoundaryState = {
|
|
162
|
+
openFailure: boundaryEval.openFailure,
|
|
163
|
+
editsSinceBoundary: boundaryEval.editsSinceBoundary,
|
|
164
|
+
lastBoundarySuggestedTurn: engine.taskBoundaryState?.lastBoundarySuggestedTurn ?? null
|
|
165
|
+
};
|
|
166
|
+
const nextTurnBoundaryReached =
|
|
167
|
+
boundaryEval.detectorState === 'mid_debug'
|
|
168
|
+
? false
|
|
169
|
+
: boundaryEval.boundaryDetected
|
|
170
|
+
? true
|
|
171
|
+
: Boolean(priorSnap?.turnBoundaryReached);
|
|
172
|
+
const nextTurnMidDebug =
|
|
173
|
+
boundaryEval.detectorState === 'mid_debug'
|
|
174
|
+
? true
|
|
175
|
+
: boundaryEval.boundaryDetected
|
|
176
|
+
? false
|
|
177
|
+
: Boolean(priorSnap?.turnMidDebug);
|
|
178
|
+
if (Array.isArray(event.active_background_tasks || event.activeBackgroundTasks)) {
|
|
179
|
+
engine.activeBackgroundTasks = (event.active_background_tasks || event.activeBackgroundTasks)
|
|
180
|
+
.filter(Boolean)
|
|
181
|
+
.map((t) => (typeof t === 'string' ? t : String(t?.id || t?.command || 'bg_task')));
|
|
182
|
+
}
|
|
183
|
+
writeBreakerStateSnapshot(
|
|
184
|
+
sessionId,
|
|
185
|
+
{
|
|
186
|
+
...engine.exportStateSnapshot(),
|
|
187
|
+
turnBoundaryReached: nextTurnBoundaryReached,
|
|
188
|
+
turnMidDebug: nextTurnMidDebug
|
|
189
|
+
},
|
|
190
|
+
cwdOptions
|
|
191
|
+
);
|
|
126
192
|
|
|
127
193
|
// RSI-04 ('micro-skills'): Capture shell failure -> recovery pairs within <= 3 turns
|
|
128
194
|
if (/^(Bash|PowerShell|pwsh|cmd|sh)$/i.test(toolName) && resolveDetectorOverride('micro-skills', horizonConfig) !== 'off') {
|
|
129
|
-
const toolInput = event.tool_input || event.toolInput || {};
|
|
130
|
-
const cmdStr = String(toolInput.command || toolInput.cmd || event.command || '');
|
|
131
195
|
if (cmdStr) {
|
|
132
|
-
const rawExit =
|
|
133
|
-
event.exit_code ??
|
|
134
|
-
event.exitCode ??
|
|
135
|
-
event.tool_response?.exit_code ??
|
|
136
|
-
event.tool_response?.exitCode;
|
|
137
196
|
recordWorkspaceShellOutcome(
|
|
138
197
|
{
|
|
139
198
|
command: cmdStr,
|
|
@@ -148,16 +207,45 @@ export function runPostToolUseHook(event = {}, options = {}) {
|
|
|
148
207
|
}
|
|
149
208
|
}
|
|
150
209
|
|
|
210
|
+
if (!loadedPriorSnap && options.bucketBShadow !== false && hasExplicitCwd && /^(?:Grep|Glob)$/i.test(toolName)) {
|
|
211
|
+
loadedPriorSnap = readBreakerStateSnapshot(sessionId, cwdOptions);
|
|
212
|
+
}
|
|
213
|
+
const bAlphaPost =
|
|
214
|
+
options.bucketBShadow === false
|
|
215
|
+
? { triggered: false, updatedOutput: rawOutput, savedTokens: 0 }
|
|
216
|
+
: runBucketBPostToolPass({
|
|
217
|
+
platform: 'claude',
|
|
218
|
+
sessionId,
|
|
219
|
+
cwd: event.cwd || options.cwd || '',
|
|
220
|
+
hasExplicitCwd,
|
|
221
|
+
toolName,
|
|
222
|
+
toolInput: event.tool_input || event.toolInput || {},
|
|
223
|
+
rawOutput,
|
|
224
|
+
lastUserPrompt: event.prompt || loadedPriorSnap?.lastUserPrompt || '',
|
|
225
|
+
activeFiles: event.activeFiles || loadedPriorSnap?.modifiedFilesInTurn || [],
|
|
226
|
+
dirtyFiles: event.dirtyFiles || [],
|
|
227
|
+
lastEditedFile:
|
|
228
|
+
event.lastEditedFile || (loadedPriorSnap?.modifiedFilesInTurn || []).slice(-1)[0] || '',
|
|
229
|
+
webFetchesInTurn: Number(event.webFetchesInTurn || 1),
|
|
230
|
+
options: {
|
|
231
|
+
...options,
|
|
232
|
+
mode: event.mode || options.mode || horizonConfig.flightMode,
|
|
233
|
+
horizonConfig
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
const effectiveRawOutput = bAlphaPost.triggered ? bAlphaPost.updatedOutput : rawOutput;
|
|
238
|
+
|
|
151
239
|
const sanitized = sanitizePostToolOutput(
|
|
152
240
|
{
|
|
153
241
|
toolName,
|
|
154
|
-
toolOutput:
|
|
242
|
+
toolOutput: effectiveRawOutput
|
|
155
243
|
},
|
|
156
244
|
cwdOptions
|
|
157
245
|
);
|
|
158
246
|
|
|
159
247
|
let finalOutput = sanitized.updatedToolOutput;
|
|
160
|
-
let wasModified = sanitized.sanitized;
|
|
248
|
+
let wasModified = sanitized.sanitized || Boolean(bAlphaPost.triggered);
|
|
161
249
|
|
|
162
250
|
// Apply DET-19 IPI sanitizer if output comes from a subagent (Task/Agent/agentId) or external WebFetch/MCP tool
|
|
163
251
|
const isSubagentSource =
|
|
@@ -180,7 +268,12 @@ export function runPostToolUseHook(event = {}, options = {}) {
|
|
|
180
268
|
}
|
|
181
269
|
}
|
|
182
270
|
|
|
183
|
-
|
|
271
|
+
const totalSavedTokens = sanitized.savedTokens + Number(bAlphaPost.savedTokens || 0);
|
|
272
|
+
if (
|
|
273
|
+
totalSavedTokens > 0 &&
|
|
274
|
+
options.recordLedger !== false &&
|
|
275
|
+
(sanitized.savedTokens > 0 || hasExplicitCwd || options.ledgerPath || options.recordLedger === true)
|
|
276
|
+
) {
|
|
184
277
|
const liveState = options.telemetryState || readLiveStateSnapshot(sessionId, cwdOptions);
|
|
185
278
|
const rawEventModel =
|
|
186
279
|
typeof event.model === 'string'
|
|
@@ -191,15 +284,23 @@ export function runPostToolUseHook(event = {}, options = {}) {
|
|
|
191
284
|
event.usage || event.context_window?.current_usage || liveState?.contextWindow || {};
|
|
192
285
|
const totalPromptTokens = computeTotalPromptTokens(usageSource);
|
|
193
286
|
const rates = resolveEffectiveRates(modelId, totalPromptTokens, cwdOptions);
|
|
287
|
+
const computedSavedUSD =
|
|
288
|
+
rates && !rates.unknownModel && Number.isFinite(rates.inputPer1M)
|
|
289
|
+
? Number(((totalSavedTokens / 1_000_000) * rates.inputPer1M).toFixed(6))
|
|
290
|
+
: 0;
|
|
194
291
|
|
|
195
292
|
recordSavingsReceipt(
|
|
196
293
|
{
|
|
197
294
|
sessionId,
|
|
198
|
-
modelId: rates.modelId,
|
|
199
|
-
category: sanitized.offloaded
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
295
|
+
modelId: rates.unknownModel ? (rates.rawModelId || modelId) : rates.modelId,
|
|
296
|
+
category: sanitized.offloaded
|
|
297
|
+
? 'ARTIFACT_OFFLOAD_4K'
|
|
298
|
+
: sanitized.savedTokens > 0
|
|
299
|
+
? 'LOSSLESS_POST_SANITIZER'
|
|
300
|
+
: bAlphaPost.code || 'BUCKET_B_POST_SHIELD',
|
|
301
|
+
savedTokens: totalSavedTokens,
|
|
302
|
+
savedUSD: computedSavedUSD,
|
|
303
|
+
detail: `${toolName} output compressed (+${totalSavedTokens} tokens saved)`
|
|
203
304
|
},
|
|
204
305
|
cwdOptions
|
|
205
306
|
);
|