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
package/config/modelCatalog.json
CHANGED
|
@@ -418,6 +418,171 @@
|
|
|
418
418
|
}
|
|
419
419
|
]
|
|
420
420
|
},
|
|
421
|
+
"claude-fable-5": {
|
|
422
|
+
"id": "claude-fable-5",
|
|
423
|
+
"aliases": ["fable-5"],
|
|
424
|
+
"family": "fable",
|
|
425
|
+
"label": "Claude Fable 5",
|
|
426
|
+
"supported_efforts": ["low", "medium", "high"],
|
|
427
|
+
"caching_mode": "explicit_and_implicit",
|
|
428
|
+
"supports_explicit_cache": true,
|
|
429
|
+
"antigravity_min_tier": "ultra",
|
|
430
|
+
"shared_pool_ceiling": 1000000,
|
|
431
|
+
"deprecated_after": null,
|
|
432
|
+
"quota_multipliers": { "low": 12.0, "med": 18.0, "medium": 18.0, "high": 26.0 },
|
|
433
|
+
"rate_schedules": [
|
|
434
|
+
{
|
|
435
|
+
"effective_from_utc": null,
|
|
436
|
+
"effective_until_utc": null,
|
|
437
|
+
"standard": {
|
|
438
|
+
"input_per_1m": 10.00,
|
|
439
|
+
"output_per_1m": 50.00,
|
|
440
|
+
"write_5m_per_1m": 12.50,
|
|
441
|
+
"write_1h_per_1m": 20.00,
|
|
442
|
+
"cached_read_per_1m": 1.00
|
|
443
|
+
},
|
|
444
|
+
"priority": {
|
|
445
|
+
"input_per_1m": 10.00,
|
|
446
|
+
"output_per_1m": 50.00,
|
|
447
|
+
"write_5m_per_1m": 12.50,
|
|
448
|
+
"write_1h_per_1m": 20.00,
|
|
449
|
+
"cached_read_per_1m": 1.00
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
]
|
|
453
|
+
},
|
|
454
|
+
"claude-opus-5": {
|
|
455
|
+
"id": "claude-opus-5",
|
|
456
|
+
"aliases": ["opus-5"],
|
|
457
|
+
"family": "opus",
|
|
458
|
+
"label": "Claude Opus 5",
|
|
459
|
+
"supported_efforts": ["low", "medium", "high"],
|
|
460
|
+
"caching_mode": "explicit_and_implicit",
|
|
461
|
+
"supports_explicit_cache": true,
|
|
462
|
+
"antigravity_min_tier": "pro",
|
|
463
|
+
"shared_pool_ceiling": 1000000,
|
|
464
|
+
"deprecated_after": null,
|
|
465
|
+
"quota_multipliers": { "low": 7.5, "med": 11.0, "medium": 11.0, "high": 16.0 },
|
|
466
|
+
"rate_schedules": [
|
|
467
|
+
{
|
|
468
|
+
"effective_from_utc": null,
|
|
469
|
+
"effective_until_utc": null,
|
|
470
|
+
"standard": {
|
|
471
|
+
"input_per_1m": 5.00,
|
|
472
|
+
"output_per_1m": 25.00,
|
|
473
|
+
"write_5m_per_1m": 6.25,
|
|
474
|
+
"write_1h_per_1m": 10.00,
|
|
475
|
+
"cached_read_per_1m": 0.50
|
|
476
|
+
},
|
|
477
|
+
"priority": {
|
|
478
|
+
"input_per_1m": 5.00,
|
|
479
|
+
"output_per_1m": 25.00,
|
|
480
|
+
"write_5m_per_1m": 6.25,
|
|
481
|
+
"write_1h_per_1m": 10.00,
|
|
482
|
+
"cached_read_per_1m": 0.50
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
]
|
|
486
|
+
},
|
|
487
|
+
"claude-sonnet-5": {
|
|
488
|
+
"id": "claude-sonnet-5",
|
|
489
|
+
"aliases": ["sonnet-5"],
|
|
490
|
+
"family": "sonnet",
|
|
491
|
+
"label": "Claude Sonnet 5",
|
|
492
|
+
"supported_efforts": ["low", "medium", "high"],
|
|
493
|
+
"caching_mode": "explicit_and_implicit",
|
|
494
|
+
"supports_explicit_cache": true,
|
|
495
|
+
"antigravity_min_tier": "pro",
|
|
496
|
+
"shared_pool_ceiling": 1000000,
|
|
497
|
+
"deprecated_after": null,
|
|
498
|
+
"quota_multipliers": { "low": 3.0, "med": 4.5, "medium": 4.5, "high": 7.0 },
|
|
499
|
+
"rate_schedules": [
|
|
500
|
+
{
|
|
501
|
+
"effective_from_utc": null,
|
|
502
|
+
"effective_until_utc": null,
|
|
503
|
+
"standard": {
|
|
504
|
+
"input_per_1m": 2.00,
|
|
505
|
+
"output_per_1m": 10.00,
|
|
506
|
+
"write_5m_per_1m": 2.50,
|
|
507
|
+
"write_1h_per_1m": 4.00,
|
|
508
|
+
"cached_read_per_1m": 0.20
|
|
509
|
+
},
|
|
510
|
+
"priority": {
|
|
511
|
+
"input_per_1m": 2.00,
|
|
512
|
+
"output_per_1m": 10.00,
|
|
513
|
+
"write_5m_per_1m": 2.50,
|
|
514
|
+
"write_1h_per_1m": 4.00,
|
|
515
|
+
"cached_read_per_1m": 0.20
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
]
|
|
519
|
+
},
|
|
520
|
+
"claude-opus-4-8": {
|
|
521
|
+
"id": "claude-opus-4-8",
|
|
522
|
+
"aliases": ["claude-opus-4.8", "opus-4-8", "opus-4.8"],
|
|
523
|
+
"family": "opus",
|
|
524
|
+
"label": "Claude Opus 4.8",
|
|
525
|
+
"supported_efforts": ["low", "medium", "high"],
|
|
526
|
+
"caching_mode": "explicit_and_implicit",
|
|
527
|
+
"supports_explicit_cache": true,
|
|
528
|
+
"antigravity_min_tier": "pro",
|
|
529
|
+
"shared_pool_ceiling": 1000000,
|
|
530
|
+
"deprecated_after": null,
|
|
531
|
+
"quota_multipliers": { "low": 7.5, "med": 11.0, "medium": 11.0, "high": 16.0 },
|
|
532
|
+
"rate_schedules": [
|
|
533
|
+
{
|
|
534
|
+
"effective_from_utc": null,
|
|
535
|
+
"effective_until_utc": null,
|
|
536
|
+
"standard": {
|
|
537
|
+
"input_per_1m": 5.00,
|
|
538
|
+
"output_per_1m": 25.00,
|
|
539
|
+
"write_5m_per_1m": 6.25,
|
|
540
|
+
"write_1h_per_1m": 10.00,
|
|
541
|
+
"cached_read_per_1m": 0.50
|
|
542
|
+
},
|
|
543
|
+
"priority": {
|
|
544
|
+
"input_per_1m": 5.00,
|
|
545
|
+
"output_per_1m": 25.00,
|
|
546
|
+
"write_5m_per_1m": 6.25,
|
|
547
|
+
"write_1h_per_1m": 10.00,
|
|
548
|
+
"cached_read_per_1m": 0.50
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
]
|
|
552
|
+
},
|
|
553
|
+
"claude-opus-4-7": {
|
|
554
|
+
"id": "claude-opus-4-7",
|
|
555
|
+
"aliases": ["claude-opus-4.7", "opus-4-7", "opus-4.7"],
|
|
556
|
+
"family": "opus",
|
|
557
|
+
"label": "Claude Opus 4.7",
|
|
558
|
+
"supported_efforts": ["low", "medium", "high"],
|
|
559
|
+
"caching_mode": "explicit_and_implicit",
|
|
560
|
+
"supports_explicit_cache": true,
|
|
561
|
+
"antigravity_min_tier": "pro",
|
|
562
|
+
"shared_pool_ceiling": 1000000,
|
|
563
|
+
"deprecated_after": null,
|
|
564
|
+
"quota_multipliers": { "low": 7.5, "med": 11.0, "medium": 11.0, "high": 16.0 },
|
|
565
|
+
"rate_schedules": [
|
|
566
|
+
{
|
|
567
|
+
"effective_from_utc": null,
|
|
568
|
+
"effective_until_utc": null,
|
|
569
|
+
"standard": {
|
|
570
|
+
"input_per_1m": 5.00,
|
|
571
|
+
"output_per_1m": 25.00,
|
|
572
|
+
"write_5m_per_1m": 6.25,
|
|
573
|
+
"write_1h_per_1m": 10.00,
|
|
574
|
+
"cached_read_per_1m": 0.50
|
|
575
|
+
},
|
|
576
|
+
"priority": {
|
|
577
|
+
"input_per_1m": 5.00,
|
|
578
|
+
"output_per_1m": 25.00,
|
|
579
|
+
"write_5m_per_1m": 6.25,
|
|
580
|
+
"write_1h_per_1m": 10.00,
|
|
581
|
+
"cached_read_per_1m": 0.50
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
]
|
|
585
|
+
},
|
|
421
586
|
"claude-opus-4-6": {
|
|
422
587
|
"id": "claude-opus-4-6",
|
|
423
588
|
"aliases": ["claude-opus-4.6", "claude-opus-4-6-thinking", "opus-4-6", "opus-4.6"],
|
|
@@ -9,10 +9,29 @@ import {
|
|
|
9
9
|
handleSessionStartHydration,
|
|
10
10
|
handlePostCompactFlush
|
|
11
11
|
} from '../../src/core-isomorphic/coach/stateBatonHydrator.mjs';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
evaluateDet17AutoCompactionDeferral,
|
|
14
|
+
readBreakerStateSnapshot,
|
|
15
|
+
writeBreakerStateSnapshot
|
|
16
|
+
} from '../../src/core-isomorphic/guards/circuitBreakers.mjs';
|
|
13
17
|
import { loadHorizonConfig, resolveDetectorOverride } from '../../src/core-isomorphic/config/horizonConfig.mjs';
|
|
18
|
+
import { isSilentOrOffMode } from '../../src/core-isomorphic/coach/cacheGravityRouter.mjs';
|
|
19
|
+
import {
|
|
20
|
+
computeActiveToolsetHash,
|
|
21
|
+
evaluateResumeToolsetChange
|
|
22
|
+
} from '../../src/core-isomorphic/coach/resumeToolsetAuditor.mjs';
|
|
23
|
+
import { readLiveStateSnapshot } from '../../src/core-isomorphic/telemetry/telemetryBridge.mjs';
|
|
14
24
|
import { loadMicroSkillsRegistry, formatMicroSkillsBatonSnippet } from '../../src/core-isomorphic/coach/microSkills.mjs';
|
|
15
25
|
import { readTextSafe, resolvePath, getCwd } from '../../src/core-isomorphic/utils/runtime.mjs';
|
|
26
|
+
import { inspectClaudeBinaryCapabilities } from '../../src/diagnostics/claudeHookCapabilities.mjs';
|
|
27
|
+
import {
|
|
28
|
+
auditClaudeIdleDrainSettings,
|
|
29
|
+
auditClaudeAgentAutoCompactWindows,
|
|
30
|
+
auditClaudeAutoMemory,
|
|
31
|
+
snapshotWorkspaceTestHashes
|
|
32
|
+
} from '../../src/core/shield_manager.mjs';
|
|
33
|
+
import { handleClaudeRslHook } from '../../src/hooks/claude_rsl_hook.mjs';
|
|
34
|
+
import { evaluateGeminiThinkingTimeoutRisk } from '../../src/core-isomorphic/economics/driftLatency.mjs';
|
|
16
35
|
import {
|
|
17
36
|
isCliEntrypoint,
|
|
18
37
|
readStdinJsonAsync,
|
|
@@ -104,11 +123,51 @@ export function runCompactLifecycleHook(event = {}, options = {}) {
|
|
|
104
123
|
? 'start'
|
|
105
124
|
: event.hook_event_name === 'PostCompact'
|
|
106
125
|
? 'post'
|
|
107
|
-
: event.hook_event_name === '
|
|
108
|
-
? '
|
|
109
|
-
: '
|
|
126
|
+
: event.hook_event_name === 'InstructionsLoaded'
|
|
127
|
+
? 'instructions'
|
|
128
|
+
: event.hook_event_name === 'WorktreeCreate'
|
|
129
|
+
? 'worktree'
|
|
130
|
+
: 'pre';
|
|
110
131
|
const phase = String(options.phase || event.phase || inferredPhase).toLowerCase();
|
|
111
132
|
const cwdOptions = event.cwd && !options.cwd ? { ...options, cwd: event.cwd } : options;
|
|
133
|
+
const sessionId = event.session_id || event.sessionId || 'default';
|
|
134
|
+
|
|
135
|
+
if (phase === 'instructions' || event.hook_event_name === 'InstructionsLoaded') {
|
|
136
|
+
const cwd = event.cwd || cwdOptions.cwd || '';
|
|
137
|
+
const ruleAudit = auditWorkspaceClaudeMd(cwd, cwdOptions);
|
|
138
|
+
const memoryAudit = auditClaudeAutoMemory({
|
|
139
|
+
cwd: cwd || process.cwd(),
|
|
140
|
+
homeDir: cwdOptions.homeDir,
|
|
141
|
+
memoryDir: event.memoryDir || cwdOptions.memoryDir,
|
|
142
|
+
memoryFilePath: event.memoryFilePath || cwdOptions.memoryFilePath
|
|
143
|
+
});
|
|
144
|
+
const agentCliffAudit = cwd ? auditClaudeAgentAutoCompactWindows({ cwd }) : { triggered: false };
|
|
145
|
+
const blocks = [];
|
|
146
|
+
if (ruleAudit.triggered) blocks.push(ruleAudit.advisory);
|
|
147
|
+
if (memoryAudit.triggered) blocks.push(memoryAudit.advisory);
|
|
148
|
+
if (agentCliffAudit.triggered) blocks.push(agentCliffAudit.advisory);
|
|
149
|
+
if (blocks.length > 0) {
|
|
150
|
+
const stdoutJson = {
|
|
151
|
+
hookSpecificOutput: {
|
|
152
|
+
hookEventName: 'InstructionsLoaded',
|
|
153
|
+
additionalContext: blocks.join('\n\n')
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
return {
|
|
157
|
+
exitCode: 0,
|
|
158
|
+
stdout: JSON.stringify(stdoutJson),
|
|
159
|
+
stdoutJson,
|
|
160
|
+
stderr: '',
|
|
161
|
+
result: { ruleAudit, memoryAudit, agentCliffAudit }
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
exitCode: 0,
|
|
166
|
+
stdout: '',
|
|
167
|
+
stderr: '',
|
|
168
|
+
result: { ruleAudit, memoryAudit, agentCliffAudit }
|
|
169
|
+
};
|
|
170
|
+
}
|
|
112
171
|
|
|
113
172
|
if (phase === 'worktree' || event.hook_event_name === 'WorktreeCreate') {
|
|
114
173
|
return {
|
|
@@ -159,7 +218,173 @@ export function runCompactLifecycleHook(event = {}, options = {}) {
|
|
|
159
218
|
const hydration = handleSessionStartHydration(event, cwdOptions);
|
|
160
219
|
const cwd = event.cwd || cwdOptions.cwd || '';
|
|
161
220
|
const ruleAudit = auditWorkspaceClaudeMd(cwd, cwdOptions);
|
|
221
|
+
const memoryAudit = auditClaudeAutoMemory({
|
|
222
|
+
cwd: cwd || process.cwd(),
|
|
223
|
+
homeDir: cwdOptions.homeDir,
|
|
224
|
+
memoryDir: event.memoryDir || cwdOptions.memoryDir,
|
|
225
|
+
memoryFilePath: event.memoryFilePath || cwdOptions.memoryFilePath
|
|
226
|
+
});
|
|
227
|
+
const agentCliffAudit = cwd ? auditClaudeAgentAutoCompactWindows({ cwd }) : { triggered: false };
|
|
228
|
+
const idleDrainAudit = cwd ? auditClaudeIdleDrainSettings({ cwd }) : { triggered: false };
|
|
229
|
+
const thinkingTimeoutAudit = evaluateGeminiThinkingTimeoutRisk({
|
|
230
|
+
modelId: event.model || event.modelId || '',
|
|
231
|
+
maxOutputTokens: event.maxOutputTokens ?? event.max_output_tokens ?? 0,
|
|
232
|
+
thinkingBudget: event.thinkingBudget ?? event.thinking_budget ?? 0,
|
|
233
|
+
timeoutMs: event.timeoutMs ?? event.timeout_ms ?? 0
|
|
234
|
+
});
|
|
235
|
+
const testHashSnapshot =
|
|
236
|
+
cwd && options.snapshotTestHashes !== false
|
|
237
|
+
? snapshotWorkspaceTestHashes({ cwd, sessionId })
|
|
238
|
+
: null;
|
|
239
|
+
if (cwd && options.persistState !== false && options.enableRsl !== false && !testHashSnapshot) {
|
|
240
|
+
try {
|
|
241
|
+
handleClaudeRslHook(event, { ...cwdOptions, event: 'SessionStart' });
|
|
242
|
+
} catch {
|
|
243
|
+
// Fail open for RSL baseline capture
|
|
244
|
+
}
|
|
245
|
+
}
|
|
162
246
|
const horizonConfig = options.horizonConfig || loadHorizonConfig(cwdOptions);
|
|
247
|
+
const effectiveMode = event.mode || options.mode || horizonConfig?.flightMode || 'COACH';
|
|
248
|
+
const sessionStartSource = String(event.source || event.trigger || '').toLowerCase();
|
|
249
|
+
const shouldPersistState =
|
|
250
|
+
options.persistState !== false &&
|
|
251
|
+
Boolean(event.cwd || cwdOptions.cwd || options.breakerStatePath || options.cliInvocation);
|
|
252
|
+
|
|
253
|
+
let compactSystemMessage = null;
|
|
254
|
+
let resumeSystemMessage = null;
|
|
255
|
+
let resumeToolsetAudit = null;
|
|
256
|
+
let surfacedPendingDownshift = null;
|
|
257
|
+
const priorSnap =
|
|
258
|
+
sessionStartSource === 'compact' || sessionStartSource === 'resume' || shouldPersistState
|
|
259
|
+
? readBreakerStateSnapshot(sessionId, cwdOptions)
|
|
260
|
+
: null;
|
|
261
|
+
const currentToolsetHash =
|
|
262
|
+
event.cwd || cwdOptions.cwd || event.tools || event.mcp_servers || options.cliArgs || event.cliArgs
|
|
263
|
+
? computeActiveToolsetHash(event, cwdOptions)
|
|
264
|
+
: null;
|
|
265
|
+
|
|
266
|
+
if (sessionStartSource === 'compact') {
|
|
267
|
+
const explicitPending = event.pending_downshift_model || event.pendingDownshiftModel || null;
|
|
268
|
+
const pendingRecord =
|
|
269
|
+
priorSnap?.pending_downshift ||
|
|
270
|
+
(priorSnap?.pendingDownshiftModel
|
|
271
|
+
? {
|
|
272
|
+
fromModel: priorSnap.lastModelId || null,
|
|
273
|
+
toModel: priorSnap.pendingDownshiftModel,
|
|
274
|
+
recordedAt: null
|
|
275
|
+
}
|
|
276
|
+
: null) ||
|
|
277
|
+
(explicitPending ? { fromModel: null, toModel: String(explicitPending), recordedAt: null } : null) ||
|
|
278
|
+
(Array.isArray(priorSnap?.queuedMutations)
|
|
279
|
+
? (() => {
|
|
280
|
+
const m = priorSnap.queuedMutations.find((x) => x && x.type === 'model' && x.value);
|
|
281
|
+
return m ? { fromModel: priorSnap.lastModelId || null, toModel: String(m.value), recordedAt: null } : null;
|
|
282
|
+
})()
|
|
283
|
+
: null);
|
|
284
|
+
|
|
285
|
+
if (shouldPersistState) {
|
|
286
|
+
writeBreakerStateSnapshot(
|
|
287
|
+
sessionId,
|
|
288
|
+
{
|
|
289
|
+
...(priorSnap || {}),
|
|
290
|
+
updatedAt: Date.now(),
|
|
291
|
+
justCompacted: true,
|
|
292
|
+
turnsSinceLastCompact: 0,
|
|
293
|
+
taskBoundaryState: {
|
|
294
|
+
openFailure: false,
|
|
295
|
+
editsSinceBoundary: 0,
|
|
296
|
+
lastBoundarySuggestedTurn: null
|
|
297
|
+
},
|
|
298
|
+
...(currentToolsetHash ? { lastToolsetHash: currentToolsetHash } : {}),
|
|
299
|
+
pending_downshift: null,
|
|
300
|
+
pendingDownshiftModel: null,
|
|
301
|
+
queuedMutations: []
|
|
302
|
+
},
|
|
303
|
+
cwdOptions
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (pendingRecord?.toModel && !isSilentOrOffMode(effectiveMode)) {
|
|
308
|
+
surfacedPendingDownshift = pendingRecord;
|
|
309
|
+
const pairLabel = pendingRecord.fromModel
|
|
310
|
+
? ` (${pendingRecord.fromModel} -> ${pendingRecord.toModel})`
|
|
311
|
+
: '';
|
|
312
|
+
// Verified at $0 on claude.exe@2.1.325: SessionStart:compact systemMessage displays
|
|
313
|
+
// notice to user with 0 tokens injected into post-compaction /v1/messages wire requests.
|
|
314
|
+
compactSystemMessage =
|
|
315
|
+
`[Highbeam] Compaction cleared the large warm cache; run /model ${pendingRecord.toModel} ` +
|
|
316
|
+
`to apply held downshift${pairLabel} without rewriting the pre-compact prefix (H6).`;
|
|
317
|
+
}
|
|
318
|
+
} else if (sessionStartSource === 'resume' && currentToolsetHash) {
|
|
319
|
+
const liveForResume =
|
|
320
|
+
event.context_tokens !== undefined || priorSnap?.lastContextTokens !== undefined
|
|
321
|
+
? null
|
|
322
|
+
: (options.telemetryState || readLiveStateSnapshot(sessionId, cwdOptions));
|
|
323
|
+
const resumeContextTokens = Number(
|
|
324
|
+
event.context_tokens ??
|
|
325
|
+
event.contextTokens ??
|
|
326
|
+
event.cached_tokens ??
|
|
327
|
+
event.cachedTokens ??
|
|
328
|
+
priorSnap?.lastContextTokens ??
|
|
329
|
+
liveForResume?.contextWindow?.cachedTokens ??
|
|
330
|
+
0
|
|
331
|
+
);
|
|
332
|
+
const resumeCacheExpired = Boolean(
|
|
333
|
+
event.prompt_cache_likely_expired ??
|
|
334
|
+
event.cacheExpired ??
|
|
335
|
+
liveForResume?.promptCache?.expired
|
|
336
|
+
);
|
|
337
|
+
const resumeModelId = String(
|
|
338
|
+
event.model ||
|
|
339
|
+
event.modelId ||
|
|
340
|
+
priorSnap?.lastModelId ||
|
|
341
|
+
liveForResume?.modelId ||
|
|
342
|
+
'claude-sonnet-5-5'
|
|
343
|
+
);
|
|
344
|
+
resumeToolsetAudit = evaluateResumeToolsetChange(
|
|
345
|
+
{
|
|
346
|
+
previousHashRecord: priorSnap?.lastToolsetHash || null,
|
|
347
|
+
currentHashRecord: currentToolsetHash,
|
|
348
|
+
contextTokens: resumeContextTokens,
|
|
349
|
+
cacheExpired: resumeCacheExpired,
|
|
350
|
+
modelId: resumeModelId,
|
|
351
|
+
cacheTtlTier: liveForResume?.promptCache?.ttlTier === '1h' ? '1h' : '5m',
|
|
352
|
+
minContextTokens: Number(horizonConfig?.thresholds?.resumeToolsetWarnMinTokens ?? 10_000)
|
|
353
|
+
},
|
|
354
|
+
cwdOptions
|
|
355
|
+
);
|
|
356
|
+
if (
|
|
357
|
+
resumeToolsetAudit.shouldWarn &&
|
|
358
|
+
resumeToolsetAudit.advisory &&
|
|
359
|
+
!isSilentOrOffMode(effectiveMode)
|
|
360
|
+
) {
|
|
361
|
+
resumeSystemMessage = resumeToolsetAudit.advisory;
|
|
362
|
+
}
|
|
363
|
+
if (shouldPersistState) {
|
|
364
|
+
writeBreakerStateSnapshot(
|
|
365
|
+
sessionId,
|
|
366
|
+
{
|
|
367
|
+
...(priorSnap || {}),
|
|
368
|
+
updatedAt: Date.now(),
|
|
369
|
+
lastToolsetHash: currentToolsetHash,
|
|
370
|
+
...(resumeContextTokens > 0 ? { lastContextTokens: resumeContextTokens } : {}),
|
|
371
|
+
...(resumeModelId ? { lastModelId: resumeModelId } : {})
|
|
372
|
+
},
|
|
373
|
+
cwdOptions
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
} else if (shouldPersistState && currentToolsetHash) {
|
|
377
|
+
writeBreakerStateSnapshot(
|
|
378
|
+
sessionId,
|
|
379
|
+
{
|
|
380
|
+
...(priorSnap || {}),
|
|
381
|
+
updatedAt: Date.now(),
|
|
382
|
+
lastToolsetHash: currentToolsetHash
|
|
383
|
+
},
|
|
384
|
+
cwdOptions
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
|
|
163
388
|
let microSkillsBaton = '';
|
|
164
389
|
if (resolveDetectorOverride('micro-skills', horizonConfig) !== 'off') {
|
|
165
390
|
const msReg = loadMicroSkillsRegistry(cwdOptions);
|
|
@@ -168,9 +393,20 @@ export function runCompactLifecycleHook(event = {}, options = {}) {
|
|
|
168
393
|
}
|
|
169
394
|
|
|
170
395
|
let hookSpecificOutput = hydration.hookSpecificOutput || null;
|
|
396
|
+
const claudeCapabilities =
|
|
397
|
+
options.checkCapabilities === false
|
|
398
|
+
? null
|
|
399
|
+
: inspectClaudeBinaryCapabilities({ ...cwdOptions, cwd, probeVersion: false });
|
|
171
400
|
const extraBlocks = [];
|
|
172
401
|
if (microSkillsBaton) extraBlocks.push(microSkillsBaton);
|
|
173
402
|
if (ruleAudit.triggered) extraBlocks.push(ruleAudit.advisory);
|
|
403
|
+
if (memoryAudit.triggered) extraBlocks.push(memoryAudit.advisory);
|
|
404
|
+
if (agentCliffAudit.triggered) extraBlocks.push(agentCliffAudit.advisory);
|
|
405
|
+
if (idleDrainAudit.triggered) extraBlocks.push(idleDrainAudit.advisory);
|
|
406
|
+
if (thinkingTimeoutAudit.triggered) extraBlocks.push(thinkingTimeoutAudit.advisory);
|
|
407
|
+
if (claudeCapabilities?.found && !claudeCapabilities.contractValid && claudeCapabilities.warning) {
|
|
408
|
+
extraBlocks.push(claudeCapabilities.warning);
|
|
409
|
+
}
|
|
174
410
|
|
|
175
411
|
if (extraBlocks.length > 0) {
|
|
176
412
|
const joinedExtra = extraBlocks.join('\n\n');
|
|
@@ -186,8 +422,15 @@ export function runCompactLifecycleHook(event = {}, options = {}) {
|
|
|
186
422
|
}
|
|
187
423
|
}
|
|
188
424
|
|
|
189
|
-
|
|
190
|
-
|
|
425
|
+
const combinedSystemMessage = [compactSystemMessage, resumeSystemMessage]
|
|
426
|
+
.filter(Boolean)
|
|
427
|
+
.join(' | ');
|
|
428
|
+
|
|
429
|
+
if (hookSpecificOutput || combinedSystemMessage) {
|
|
430
|
+
const stdoutJson = {
|
|
431
|
+
...(combinedSystemMessage ? { systemMessage: combinedSystemMessage } : {}),
|
|
432
|
+
...(hookSpecificOutput ? { hookSpecificOutput } : {})
|
|
433
|
+
};
|
|
191
434
|
return {
|
|
192
435
|
exitCode: 0,
|
|
193
436
|
stdout: JSON.stringify(stdoutJson),
|
|
@@ -196,7 +439,15 @@ export function runCompactLifecycleHook(event = {}, options = {}) {
|
|
|
196
439
|
result: {
|
|
197
440
|
...hydration,
|
|
198
441
|
ruleAudit,
|
|
199
|
-
|
|
442
|
+
memoryAudit,
|
|
443
|
+
agentCliffAudit,
|
|
444
|
+
idleDrainAudit,
|
|
445
|
+
thinkingTimeoutAudit,
|
|
446
|
+
testHashSnapshot,
|
|
447
|
+
microSkillsBaton,
|
|
448
|
+
claudeCapabilities,
|
|
449
|
+
surfacedPendingDownshift,
|
|
450
|
+
resumeToolsetAudit
|
|
200
451
|
}
|
|
201
452
|
};
|
|
202
453
|
}
|
|
@@ -204,12 +455,76 @@ export function runCompactLifecycleHook(event = {}, options = {}) {
|
|
|
204
455
|
exitCode: 0,
|
|
205
456
|
stdout: '',
|
|
206
457
|
stderr: '',
|
|
207
|
-
result:
|
|
458
|
+
result: {
|
|
459
|
+
...hydration,
|
|
460
|
+
memoryAudit,
|
|
461
|
+
agentCliffAudit,
|
|
462
|
+
idleDrainAudit,
|
|
463
|
+
thinkingTimeoutAudit,
|
|
464
|
+
testHashSnapshot,
|
|
465
|
+
claudeCapabilities,
|
|
466
|
+
surfacedPendingDownshift,
|
|
467
|
+
resumeToolsetAudit
|
|
468
|
+
}
|
|
208
469
|
};
|
|
209
470
|
}
|
|
210
471
|
|
|
211
472
|
if (phase === 'post' || event.hook_event_name === 'PostCompact') {
|
|
212
473
|
const postRes = handlePostCompactFlush(event, cwdOptions);
|
|
474
|
+
const snap = readBreakerStateSnapshot(sessionId, cwdOptions);
|
|
475
|
+
const pendingModel =
|
|
476
|
+
event.pending_downshift_model ||
|
|
477
|
+
event.pendingDownshiftModel ||
|
|
478
|
+
snap?.pending_downshift?.toModel ||
|
|
479
|
+
snap?.pendingDownshiftModel ||
|
|
480
|
+
(Array.isArray(snap?.queuedMutations)
|
|
481
|
+
? snap.queuedMutations.find((m) => m && m.type === 'model')?.value || null
|
|
482
|
+
: null);
|
|
483
|
+
|
|
484
|
+
if (
|
|
485
|
+
options.persistState !== false &&
|
|
486
|
+
Boolean(event.cwd || cwdOptions.cwd || options.breakerStatePath || options.cliInvocation)
|
|
487
|
+
) {
|
|
488
|
+
writeBreakerStateSnapshot(
|
|
489
|
+
sessionId,
|
|
490
|
+
{
|
|
491
|
+
...(snap || {}),
|
|
492
|
+
updatedAt: Date.now(),
|
|
493
|
+
justCompacted: true,
|
|
494
|
+
turnsSinceLastCompact: 0,
|
|
495
|
+
taskBoundaryState: {
|
|
496
|
+
openFailure: false,
|
|
497
|
+
editsSinceBoundary: 0,
|
|
498
|
+
lastBoundarySuggestedTurn: null
|
|
499
|
+
},
|
|
500
|
+
pending_downshift: null,
|
|
501
|
+
pendingDownshiftModel: null,
|
|
502
|
+
queuedMutations: []
|
|
503
|
+
},
|
|
504
|
+
cwdOptions
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
if (pendingModel) {
|
|
509
|
+
const actuatedMsg =
|
|
510
|
+
`[Highbeam] Compaction cleared the large warm cache; run /model ${pendingModel} ` +
|
|
511
|
+
`to apply held downshift without rewriting the pre-compact prefix (H6).`;
|
|
512
|
+
// PostCompact lacks hookSpecificOutput in Claude Code 2.1.325 (qY); emit systemMessage only.
|
|
513
|
+
const stdoutJson = {
|
|
514
|
+
systemMessage: actuatedMsg
|
|
515
|
+
};
|
|
516
|
+
return {
|
|
517
|
+
exitCode: 0,
|
|
518
|
+
stdout: JSON.stringify(stdoutJson),
|
|
519
|
+
stdoutJson,
|
|
520
|
+
stderr: '',
|
|
521
|
+
result: {
|
|
522
|
+
...postRes,
|
|
523
|
+
actuatedDownshiftModel: pendingModel
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
|
|
213
528
|
return {
|
|
214
529
|
exitCode: 0,
|
|
215
530
|
stdout: '',
|