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
|
@@ -12,6 +12,11 @@ import { loadHorizonConfig } from '../../src/core-isomorphic/config/horizonConfi
|
|
|
12
12
|
import { recordInterventionSavings } from '../../src/core-isomorphic/coach/savedQuotaLedger.mjs';
|
|
13
13
|
import { requireProFeature } from '../../src/core/pro_license.mjs';
|
|
14
14
|
import { foldCodeToSignatureStub, computeCompactLineDiff } from '../../src/core/pruner.mjs';
|
|
15
|
+
import {
|
|
16
|
+
evaluateShieldReadGuard,
|
|
17
|
+
inspectAndSanitizeMultimodalRead
|
|
18
|
+
} from '../../src/core/shield_manager.mjs';
|
|
19
|
+
import { runBucketBPreToolShadowPass } from '../../src/core/bucket_b_runtime.mjs';
|
|
15
20
|
import {
|
|
16
21
|
CircuitBreakerEngine,
|
|
17
22
|
readBreakerStateSnapshot,
|
|
@@ -105,14 +110,163 @@ export function runPreToolUseHook(event = {}, options = {}) {
|
|
|
105
110
|
});
|
|
106
111
|
|
|
107
112
|
// Playbook Step 4 & VC Gap 4: Post-Edit Unified Delta Diff + 3rd-Read AST Signature Stub Interception
|
|
108
|
-
const isReadTool = /^(Read|read_file)$/i.test(toolName);
|
|
113
|
+
const isReadTool = /^(Read|read_file|view_file)$/i.test(toolName);
|
|
109
114
|
const tIn = event.tool_input || event.toolInput || event.args || {};
|
|
110
115
|
const hasLineBounds =
|
|
111
116
|
tIn.StartLine !== undefined ||
|
|
112
117
|
tIn.EndLine !== undefined ||
|
|
113
118
|
tIn.offset !== undefined ||
|
|
114
|
-
tIn.limit !== undefined
|
|
115
|
-
|
|
119
|
+
tIn.limit !== undefined ||
|
|
120
|
+
tIn.pages !== undefined;
|
|
121
|
+
const rawReadPath = String(tIn.file_path || tIn.Path || tIn.AbsolutePath || tIn.path || '').trim();
|
|
122
|
+
|
|
123
|
+
// Item A8 (#14): Multimodal .ipynb Base64 Stripper (`updatedInput`) & Unbounded >10-page .pdf Blocker
|
|
124
|
+
if (
|
|
125
|
+
isReadTool &&
|
|
126
|
+
rawReadPath &&
|
|
127
|
+
verdict.decision !== 'deny' &&
|
|
128
|
+
verdict.decision !== 'ask' &&
|
|
129
|
+
verdict.decision !== 'defer' &&
|
|
130
|
+
/\.(?:ipynb|pdf)$/i.test(rawReadPath)
|
|
131
|
+
) {
|
|
132
|
+
const baseCwdForMm = event.cwd || options.cwd || process.cwd();
|
|
133
|
+
const mmVerdict = inspectAndSanitizeMultimodalRead({
|
|
134
|
+
platform: 'claude',
|
|
135
|
+
cwd: baseCwdForMm,
|
|
136
|
+
filePath: rawReadPath,
|
|
137
|
+
pages: tIn.pages,
|
|
138
|
+
hasPageBounds: tIn.pages !== undefined
|
|
139
|
+
});
|
|
140
|
+
if (mmVerdict.action === 'deny') {
|
|
141
|
+
if (shouldPersistState) {
|
|
142
|
+
writeBreakerStateSnapshot(sessionId, engine.exportStateSnapshot(), cwdOptions);
|
|
143
|
+
}
|
|
144
|
+
const denyOut = {
|
|
145
|
+
hookSpecificOutput: {
|
|
146
|
+
hookEventName: 'PreToolUse',
|
|
147
|
+
permissionDecision: 'deny',
|
|
148
|
+
permissionDecisionReason: mmVerdict.reason
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
return {
|
|
152
|
+
exitCode: 0,
|
|
153
|
+
stdout: JSON.stringify(denyOut),
|
|
154
|
+
stderr: '',
|
|
155
|
+
verdict: {
|
|
156
|
+
triggered: true,
|
|
157
|
+
detectorId: mmVerdict.detectorId,
|
|
158
|
+
subType: mmVerdict.subType,
|
|
159
|
+
decision: 'deny',
|
|
160
|
+
pageCount: mmVerdict.pageCount,
|
|
161
|
+
savedTokens: mmVerdict.savedTokens,
|
|
162
|
+
reason: mmVerdict.reason
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
if (mmVerdict.action === 'rewrite' && mmVerdict.sanitizedPath) {
|
|
167
|
+
if (shouldPersistState) {
|
|
168
|
+
writeBreakerStateSnapshot(sessionId, engine.exportStateSnapshot(), cwdOptions);
|
|
169
|
+
}
|
|
170
|
+
if (
|
|
171
|
+
mmVerdict.savedTokens > 0 &&
|
|
172
|
+
options.recordLedger !== false &&
|
|
173
|
+
Boolean(event.cwd || options.cwd || options.ledgerPath || options.recordLedger)
|
|
174
|
+
) {
|
|
175
|
+
recordInterventionSavings(
|
|
176
|
+
{
|
|
177
|
+
sessionId,
|
|
178
|
+
category: 'BOUNDED_READ_ENFORCED',
|
|
179
|
+
modelId: event.model || event.modelId || liveState?.modelId || 'claude-sonnet-4-6',
|
|
180
|
+
savedTokens: mmVerdict.savedTokens,
|
|
181
|
+
detail: `Sanitized .ipynb base64 blobs in ${path.basename(rawReadPath)}`
|
|
182
|
+
},
|
|
183
|
+
cwdOptions
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
const updatedInput = {
|
|
187
|
+
...tIn,
|
|
188
|
+
file_path: mmVerdict.sanitizedPath
|
|
189
|
+
};
|
|
190
|
+
const rewriteOut = {
|
|
191
|
+
hookSpecificOutput: {
|
|
192
|
+
hookEventName: 'PreToolUse',
|
|
193
|
+
permissionDecision: 'allow',
|
|
194
|
+
updatedInput,
|
|
195
|
+
additionalContext: mmVerdict.reason
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
return {
|
|
199
|
+
exitCode: 0,
|
|
200
|
+
stdout: JSON.stringify(rewriteOut),
|
|
201
|
+
stderr: '',
|
|
202
|
+
verdict: {
|
|
203
|
+
triggered: true,
|
|
204
|
+
detectorId: mmVerdict.detectorId,
|
|
205
|
+
subType: mmVerdict.subType,
|
|
206
|
+
decision: 'allow',
|
|
207
|
+
sanitizedPath: mmVerdict.sanitizedPath,
|
|
208
|
+
savedTokens: mmVerdict.savedTokens,
|
|
209
|
+
updatedInput,
|
|
210
|
+
reason: mmVerdict.reason
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (
|
|
217
|
+
isReadTool &&
|
|
218
|
+
!hasLineBounds &&
|
|
219
|
+
rawReadPath &&
|
|
220
|
+
verdict.decision !== 'deny' &&
|
|
221
|
+
verdict.decision !== 'ask' &&
|
|
222
|
+
verdict.decision !== 'defer'
|
|
223
|
+
) {
|
|
224
|
+
const baseCwdForShield = event.cwd || options.cwd || process.cwd();
|
|
225
|
+
const shieldVerdict = evaluateShieldReadGuard({
|
|
226
|
+
platform: 'claude',
|
|
227
|
+
sessionId,
|
|
228
|
+
cwd: baseCwdForShield,
|
|
229
|
+
filePath: rawReadPath,
|
|
230
|
+
hasSliceBounds: false,
|
|
231
|
+
currentPromptTokens:
|
|
232
|
+
computedEventPromptTokens || Number(liveState?.contextWindow?.totalInputTokens || 0),
|
|
233
|
+
modelId: event.model || event.modelId || liveState?.modelId || 'claude-sonnet-4-6',
|
|
234
|
+
shieldConfig: options.shieldConfig,
|
|
235
|
+
forceActive: Boolean(options.shieldForceActive),
|
|
236
|
+
recordLedger:
|
|
237
|
+
options.recordLedger !== false &&
|
|
238
|
+
Boolean(event.cwd || options.cwd || options.ledgerPath || options.recordLedger),
|
|
239
|
+
ledgerPath: options.ledgerPath
|
|
240
|
+
});
|
|
241
|
+
if (shieldVerdict.action === 'deny') {
|
|
242
|
+
if (shouldPersistState) {
|
|
243
|
+
writeBreakerStateSnapshot(sessionId, engine.exportStateSnapshot(), cwdOptions);
|
|
244
|
+
}
|
|
245
|
+
const denyOut = {
|
|
246
|
+
permissionDecision: 'deny',
|
|
247
|
+
reason: shieldVerdict.reason,
|
|
248
|
+
hookSpecificOutput: {
|
|
249
|
+
hookEventName: 'PreToolUse',
|
|
250
|
+
permissionDecision: 'deny',
|
|
251
|
+
permissionDecisionReason: shieldVerdict.reason
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
return {
|
|
255
|
+
exitCode: 0,
|
|
256
|
+
stdout: JSON.stringify(denyOut),
|
|
257
|
+
stderr: '',
|
|
258
|
+
verdict: {
|
|
259
|
+
triggered: true,
|
|
260
|
+
detectorId: shieldVerdict.detectorId,
|
|
261
|
+
decision: 'deny',
|
|
262
|
+
reason: shieldVerdict.reason,
|
|
263
|
+
indexPath: shieldVerdict.indexPath,
|
|
264
|
+
savedTokens: shieldVerdict.savedTokens,
|
|
265
|
+
savedUSD: shieldVerdict.savedUSD
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
}
|
|
116
270
|
|
|
117
271
|
if (isReadTool && !hasLineBounds && rawReadPath) {
|
|
118
272
|
try {
|
|
@@ -188,9 +342,120 @@ export function runPreToolUseHook(event = {}, options = {}) {
|
|
|
188
342
|
}
|
|
189
343
|
}
|
|
190
344
|
|
|
345
|
+
const hasExplicitCwd = Boolean(event.cwd || options.cwd);
|
|
346
|
+
|
|
347
|
+
// Bucket B Coach/Shadow Pass (B-Alpha defaults to COACH; B-Beta & B-Gamma default to SHADOW)
|
|
348
|
+
if (!verdict.triggered && options.bucketBShadow !== false) {
|
|
349
|
+
try {
|
|
350
|
+
const priorUnverifiedEdits = Array.isArray(event.editsSinceVerify)
|
|
351
|
+
? event.editsSinceVerify
|
|
352
|
+
: engine.codeEditedSinceLastTest
|
|
353
|
+
? engine.unverifiedEdits
|
|
354
|
+
: [];
|
|
355
|
+
const shadowRes = runBucketBPreToolShadowPass({
|
|
356
|
+
platform: 'claude',
|
|
357
|
+
sessionId,
|
|
358
|
+
cwd: event.cwd || options.cwd || '',
|
|
359
|
+
hasExplicitCwd,
|
|
360
|
+
toolName,
|
|
361
|
+
toolInput: tIn,
|
|
362
|
+
lastUserPrompt: event.prompt || engine.lastUserPrompt || '',
|
|
363
|
+
editsSinceVerify: priorUnverifiedEdits,
|
|
364
|
+
options: {
|
|
365
|
+
...options,
|
|
366
|
+
cliCapabilities: event.cliCapabilities || options.cliCapabilities,
|
|
367
|
+
lspCapabilities: event.lspCapabilities || options.lspCapabilities,
|
|
368
|
+
bucketBStage: event.bucketBStage ?? options.bucketBStage,
|
|
369
|
+
bucketBGammaStage: event.bucketBGammaStage ?? options.bucketBGammaStage,
|
|
370
|
+
bucketBLspStage: event.bucketBLspStage ?? options.bucketBLspStage,
|
|
371
|
+
persistState: shouldPersistState,
|
|
372
|
+
mode: effectiveMode,
|
|
373
|
+
horizonConfig
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
if (shadowRes.triggered && shadowRes.activeRecords.length > 0) {
|
|
377
|
+
const primaryEntry =
|
|
378
|
+
shadowRes.activeRecords.find((r) => r.verdict.decision === 'ask') ||
|
|
379
|
+
shadowRes.activeRecords[0];
|
|
380
|
+
const topRec = primaryEntry.verdict;
|
|
381
|
+
verdict.triggered = true;
|
|
382
|
+
verdict.decision = topRec.decision === 'ask' ? 'ask' : 'allow';
|
|
383
|
+
verdict.detectorId = topRec.code || 'BUCKET_B_GUARD';
|
|
384
|
+
verdict.reason = shadowRes.activeRecords
|
|
385
|
+
.map((r) => r.verdict.reason)
|
|
386
|
+
.filter(Boolean)
|
|
387
|
+
.join('\n');
|
|
388
|
+
const maxSavedTokens = Math.max(
|
|
389
|
+
0,
|
|
390
|
+
...shadowRes.activeRecords.map((r) => Number(r.verdict.tokensSavedEst || 0))
|
|
391
|
+
);
|
|
392
|
+
if (maxSavedTokens > 0) {
|
|
393
|
+
verdict.savedTokens = Math.max(
|
|
394
|
+
Number(verdict.savedTokens || 0),
|
|
395
|
+
maxSavedTokens
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
} catch (_shadowErr) {
|
|
400
|
+
// Non-fatal Bucket B shadow/coach pass
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (
|
|
405
|
+
shouldPersistState &&
|
|
406
|
+
/^(?:Edit|MultiEdit|Write)$/i.test(toolName) &&
|
|
407
|
+
verdict.decision !== 'deny' &&
|
|
408
|
+
verdict.decision !== 'ask'
|
|
409
|
+
) {
|
|
410
|
+
const rawEditPath = String(
|
|
411
|
+
tIn.file_path || tIn.Path || tIn.path || tIn.filePath || ''
|
|
412
|
+
).trim();
|
|
413
|
+
if (rawEditPath) {
|
|
414
|
+
const addedTxt = String(
|
|
415
|
+
tIn.new_string ??
|
|
416
|
+
tIn.content ??
|
|
417
|
+
tIn.newText ??
|
|
418
|
+
(Array.isArray(tIn.edits) ? tIn.edits.map((e) => e?.new_string ?? '').join('\n') : '') ??
|
|
419
|
+
''
|
|
420
|
+
);
|
|
421
|
+
const oldTxt = String(
|
|
422
|
+
tIn.old_string ??
|
|
423
|
+
tIn.oldText ??
|
|
424
|
+
(Array.isArray(tIn.edits) ? tIn.edits.map((e) => e?.old_string ?? '').join('\n') : '') ??
|
|
425
|
+
''
|
|
426
|
+
);
|
|
427
|
+
const changedLines = addedTxt.split(/\r?\n/);
|
|
428
|
+
const netLines = changedLines.filter((l) => l.trim().length > 0).length;
|
|
429
|
+
const deletedLineCount = oldTxt ? oldTxt.split(/\r?\n/).length : 0;
|
|
430
|
+
if (!Array.isArray(engine.unverifiedEdits)) engine.unverifiedEdits = [];
|
|
431
|
+
engine.unverifiedEdits.push({
|
|
432
|
+
filePath: rawEditPath,
|
|
433
|
+
netLines,
|
|
434
|
+
changedLines: changedLines.slice(0, 64)
|
|
435
|
+
});
|
|
436
|
+
if (engine.unverifiedEdits.length > 32) {
|
|
437
|
+
engine.unverifiedEdits = engine.unverifiedEdits.slice(-32);
|
|
438
|
+
}
|
|
439
|
+
if (!Array.isArray(engine.turnFileDiffs)) engine.turnFileDiffs = [];
|
|
440
|
+
engine.turnFileDiffs.push({
|
|
441
|
+
filePath: rawEditPath,
|
|
442
|
+
addedLines: addedTxt ? changedLines.slice(0, 400) : [],
|
|
443
|
+
deletedLineCount
|
|
444
|
+
});
|
|
445
|
+
if (engine.turnFileDiffs.length > 32) {
|
|
446
|
+
engine.turnFileDiffs = engine.turnFileDiffs.slice(-32);
|
|
447
|
+
}
|
|
448
|
+
if (event.prompt) {
|
|
449
|
+
engine.lastUserPrompt = String(event.prompt);
|
|
450
|
+
}
|
|
451
|
+
engine.codeEditedSinceLastTest = true;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
191
455
|
if (shouldPersistState) {
|
|
192
456
|
writeBreakerStateSnapshot(sessionId, engine.exportStateSnapshot(), cwdOptions);
|
|
193
457
|
}
|
|
458
|
+
|
|
194
459
|
if (!verdict.triggered) {
|
|
195
460
|
return {
|
|
196
461
|
exitCode: 0,
|
|
@@ -202,7 +467,9 @@ export function runPreToolUseHook(event = {}, options = {}) {
|
|
|
202
467
|
|
|
203
468
|
const detId = String(verdict.detectorId || '');
|
|
204
469
|
const isQuotaSavingGuard =
|
|
205
|
-
/^(DET-04|DET-06|DET-09|DET-10|DET-11|DET-12|DET-13|DET-14|DET-20)$/.test(
|
|
470
|
+
/^(DET-04|DET-06|DET-09|DET-10|DET-11|DET-12|DET-13|DET-14|DET-20|SLOPSQUAT_DEP_GATE|BLAST_RADIUS_BREAKER|DUPLICATE_CLONE_DETECTOR|EVILGENIE_HARDCODED_ORACLE|SUBAGENT_TEAM_GOVERNOR|MCP_CLI_ROUTER)$/.test(
|
|
471
|
+
detId
|
|
472
|
+
);
|
|
206
473
|
if (
|
|
207
474
|
isQuotaSavingGuard &&
|
|
208
475
|
(verdict.decision === 'deny' || verdict.decision === 'ask' || verdict.decision === 'defer' || Boolean(verdict.astSignatureStub) || Boolean(verdict.deltaDiffStub)) &&
|