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
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema_version": "1.0.0",
|
|
3
|
+
"visionOverageHttp400": {
|
|
4
|
+
"enabled": true,
|
|
5
|
+
"detectorId": "DET-20",
|
|
6
|
+
"httpStatus": 400,
|
|
7
|
+
"upstreamErrorSubstring": "Unable to process input image",
|
|
8
|
+
"warningMessage": "[DET-20 Vision Overage Quirk] AI Credit Overages are active and an image/screenshot attachment was detected. Submit text-only or wait for Base Quota reset to avoid Google's HTTP 400 Bad Request (Unable to process input image) bug."
|
|
9
|
+
},
|
|
10
|
+
"hybridQuotaLockout": {
|
|
11
|
+
"enabled": true,
|
|
12
|
+
"detectorId": "DET-16",
|
|
13
|
+
"singleWorkerThrottlePct": 80,
|
|
14
|
+
"hardAskGatePct": 90,
|
|
15
|
+
"lockoutDurationHours": 168,
|
|
16
|
+
"maxSubagentTokens": 40000,
|
|
17
|
+
"maxSubagentTurns": 12
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,577 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file hooks/handlers/compact-lifecycle.mjs
|
|
3
|
+
* Tier 2 Command Hook handler for `PreCompact`, `SessionStart[compact|resume|startup|clear|fork]`,
|
|
4
|
+
* and `PostCompact` (`ISS-034`, `ISS-035`, `ISS-036`).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
handlePreCompactBatonFlush,
|
|
9
|
+
handleSessionStartHydration,
|
|
10
|
+
handlePostCompactFlush
|
|
11
|
+
} from '../../src/core-isomorphic/coach/stateBatonHydrator.mjs';
|
|
12
|
+
import {
|
|
13
|
+
evaluateDet17AutoCompactionDeferral,
|
|
14
|
+
readBreakerStateSnapshot,
|
|
15
|
+
writeBreakerStateSnapshot
|
|
16
|
+
} from '../../src/core-isomorphic/guards/circuitBreakers.mjs';
|
|
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';
|
|
24
|
+
import { loadMicroSkillsRegistry, formatMicroSkillsBatonSnippet } from '../../src/core-isomorphic/coach/microSkills.mjs';
|
|
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';
|
|
35
|
+
import {
|
|
36
|
+
isCliEntrypoint,
|
|
37
|
+
readStdinJsonAsync,
|
|
38
|
+
exitPassThrough,
|
|
39
|
+
exitDiagnosticZero,
|
|
40
|
+
exitWithStdoutJson
|
|
41
|
+
} from './hookIo.mjs';
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Scans workspace instruction files (CLAUDE.md, .claude/CLAUDE.md, AGENTS.md)
|
|
45
|
+
* for token bloat (>4k tokens or >200 lines) and direct rule contradictions.
|
|
46
|
+
*
|
|
47
|
+
* @param {string} [cwd='']
|
|
48
|
+
* @param {object} [options={}]
|
|
49
|
+
* @returns {object}
|
|
50
|
+
*/
|
|
51
|
+
export function auditWorkspaceClaudeMd(cwd = '', options = {}) {
|
|
52
|
+
const root = cwd || getCwd(options);
|
|
53
|
+
const candidateFiles = ['CLAUDE.md', '.claude/CLAUDE.md', 'AGENTS.md'];
|
|
54
|
+
let totalTokens = 0;
|
|
55
|
+
let totalLines = 0;
|
|
56
|
+
const foundFiles = [];
|
|
57
|
+
const polarContradictions = [];
|
|
58
|
+
|
|
59
|
+
for (const rel of candidateFiles) {
|
|
60
|
+
const full = resolvePath(root, rel);
|
|
61
|
+
const content = readTextSafe(full, null, options);
|
|
62
|
+
if (typeof content === 'string' && content.length > 0) {
|
|
63
|
+
foundFiles.push(rel);
|
|
64
|
+
const lines = content.split(/\r?\n/).length;
|
|
65
|
+
totalLines += lines;
|
|
66
|
+
const tokens = Math.ceil(content.length / 3.8);
|
|
67
|
+
totalTokens += tokens;
|
|
68
|
+
|
|
69
|
+
if (
|
|
70
|
+
/always\s+use\s+(?:tabs|spaces)\b/i.test(content) &&
|
|
71
|
+
/never\s+use\s+(?:tabs|spaces)\b/i.test(content)
|
|
72
|
+
) {
|
|
73
|
+
polarContradictions.push('tabs vs spaces contradiction');
|
|
74
|
+
}
|
|
75
|
+
if (
|
|
76
|
+
/always\s+use\s+default\s+exports\b/i.test(content) &&
|
|
77
|
+
/never\s+use\s+default\s+exports\b/i.test(content)
|
|
78
|
+
) {
|
|
79
|
+
polarContradictions.push('Always vs NEVER use Default Exports contradiction');
|
|
80
|
+
}
|
|
81
|
+
if (
|
|
82
|
+
/always\s+use\s+semicolons\b/i.test(content) &&
|
|
83
|
+
/never\s+use\s+semicolons\b/i.test(content)
|
|
84
|
+
) {
|
|
85
|
+
polarContradictions.push('Always vs NEVER use semicolons contradiction');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const isBloated = totalTokens > 4000 || totalLines > 200 || polarContradictions.length > 0;
|
|
91
|
+
if (!isBloated) {
|
|
92
|
+
return { triggered: false };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const reasons = [];
|
|
96
|
+
if (totalTokens > 4000 || totalLines > 200) {
|
|
97
|
+
reasons.push(`Rules file bloat: ${Math.round(totalTokens / 1000)}k tokens across ${totalLines} lines (>4k tokens / >200 lines cap)`);
|
|
98
|
+
}
|
|
99
|
+
if (polarContradictions.length > 0) {
|
|
100
|
+
reasons.push(`Contradictions detected: ${polarContradictions.join('; ')}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const advisory = `[DET-09 / RSI-01 Static Rule Bloat Advisory] ${reasons.join('. ')}. Prune stale conventions or extract domain skills via /compact.`;
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
triggered: true,
|
|
107
|
+
totalTokens,
|
|
108
|
+
totalLines,
|
|
109
|
+
foundFiles,
|
|
110
|
+
polarContradictions,
|
|
111
|
+
advisory
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Evaluates a compaction / session-start lifecycle event (`pre`, `start`, or `post`).
|
|
117
|
+
* @param {object} event
|
|
118
|
+
* @param {object} [options={}]
|
|
119
|
+
*/
|
|
120
|
+
export function runCompactLifecycleHook(event = {}, options = {}) {
|
|
121
|
+
const inferredPhase =
|
|
122
|
+
event.hook_event_name === 'SessionStart'
|
|
123
|
+
? 'start'
|
|
124
|
+
: event.hook_event_name === 'PostCompact'
|
|
125
|
+
? 'post'
|
|
126
|
+
: event.hook_event_name === 'InstructionsLoaded'
|
|
127
|
+
? 'instructions'
|
|
128
|
+
: event.hook_event_name === 'WorktreeCreate'
|
|
129
|
+
? 'worktree'
|
|
130
|
+
: 'pre';
|
|
131
|
+
const phase = String(options.phase || event.phase || inferredPhase).toLowerCase();
|
|
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
|
+
}
|
|
171
|
+
|
|
172
|
+
if (phase === 'worktree' || event.hook_event_name === 'WorktreeCreate') {
|
|
173
|
+
return {
|
|
174
|
+
exitCode: 0,
|
|
175
|
+
stdout: '',
|
|
176
|
+
stderr: '',
|
|
177
|
+
result: {
|
|
178
|
+
ok: true,
|
|
179
|
+
hookEventName: 'WorktreeCreate',
|
|
180
|
+
passThrough: true
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (phase === 'pre' || event.hook_event_name === 'PreCompact') {
|
|
186
|
+
const det17 = evaluateDet17AutoCompactionDeferral({
|
|
187
|
+
trigger: event.trigger || 'auto',
|
|
188
|
+
midBatchEditInProgress: Boolean(event.midBatchEditInProgress),
|
|
189
|
+
unbalancedSyntaxDetected: Boolean(event.unbalancedSyntaxDetected),
|
|
190
|
+
cacheExpired: Boolean(event.cacheExpired),
|
|
191
|
+
cachedTokens: Number(event.cachedTokens ?? event.cached_tokens ?? 0)
|
|
192
|
+
});
|
|
193
|
+
if (det17.triggered) {
|
|
194
|
+
// ISS-034: Never emit invalid hookSpecificOutput.permissionDecision on PreCompact!
|
|
195
|
+
const stdoutJson = {
|
|
196
|
+
decision: 'block',
|
|
197
|
+
reason: det17.reason
|
|
198
|
+
};
|
|
199
|
+
return {
|
|
200
|
+
exitCode: 0,
|
|
201
|
+
stdout: JSON.stringify(stdoutJson),
|
|
202
|
+
stdoutJson,
|
|
203
|
+
stderr: '',
|
|
204
|
+
result: det17
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const flushRes = handlePreCompactBatonFlush(event, cwdOptions);
|
|
209
|
+
return {
|
|
210
|
+
exitCode: 0,
|
|
211
|
+
stdout: '',
|
|
212
|
+
stderr: '',
|
|
213
|
+
result: flushRes
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (phase === 'start' || event.hook_event_name === 'SessionStart') {
|
|
218
|
+
const hydration = handleSessionStartHydration(event, cwdOptions);
|
|
219
|
+
const cwd = event.cwd || cwdOptions.cwd || '';
|
|
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
|
+
}
|
|
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
|
+
|
|
388
|
+
let microSkillsBaton = '';
|
|
389
|
+
if (resolveDetectorOverride('micro-skills', horizonConfig) !== 'off') {
|
|
390
|
+
const msReg = loadMicroSkillsRegistry(cwdOptions);
|
|
391
|
+
const formatted = formatMicroSkillsBatonSnippet(msReg);
|
|
392
|
+
microSkillsBaton = formatted.snippet || '';
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
let hookSpecificOutput = hydration.hookSpecificOutput || null;
|
|
396
|
+
const claudeCapabilities =
|
|
397
|
+
options.checkCapabilities === false
|
|
398
|
+
? null
|
|
399
|
+
: inspectClaudeBinaryCapabilities({ ...cwdOptions, cwd, probeVersion: false });
|
|
400
|
+
const extraBlocks = [];
|
|
401
|
+
if (microSkillsBaton) extraBlocks.push(microSkillsBaton);
|
|
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
|
+
}
|
|
410
|
+
|
|
411
|
+
if (extraBlocks.length > 0) {
|
|
412
|
+
const joinedExtra = extraBlocks.join('\n\n');
|
|
413
|
+
if (!hookSpecificOutput) {
|
|
414
|
+
hookSpecificOutput = {
|
|
415
|
+
hookEventName: 'SessionStart',
|
|
416
|
+
additionalContext: joinedExtra
|
|
417
|
+
};
|
|
418
|
+
} else {
|
|
419
|
+
hookSpecificOutput.additionalContext = hookSpecificOutput.additionalContext
|
|
420
|
+
? `${hookSpecificOutput.additionalContext}\n\n${joinedExtra}`
|
|
421
|
+
: joinedExtra;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
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
|
+
};
|
|
434
|
+
return {
|
|
435
|
+
exitCode: 0,
|
|
436
|
+
stdout: JSON.stringify(stdoutJson),
|
|
437
|
+
stdoutJson,
|
|
438
|
+
stderr: '',
|
|
439
|
+
result: {
|
|
440
|
+
...hydration,
|
|
441
|
+
ruleAudit,
|
|
442
|
+
memoryAudit,
|
|
443
|
+
agentCliffAudit,
|
|
444
|
+
idleDrainAudit,
|
|
445
|
+
thinkingTimeoutAudit,
|
|
446
|
+
testHashSnapshot,
|
|
447
|
+
microSkillsBaton,
|
|
448
|
+
claudeCapabilities,
|
|
449
|
+
surfacedPendingDownshift,
|
|
450
|
+
resumeToolsetAudit
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
return {
|
|
455
|
+
exitCode: 0,
|
|
456
|
+
stdout: '',
|
|
457
|
+
stderr: '',
|
|
458
|
+
result: {
|
|
459
|
+
...hydration,
|
|
460
|
+
memoryAudit,
|
|
461
|
+
agentCliffAudit,
|
|
462
|
+
idleDrainAudit,
|
|
463
|
+
thinkingTimeoutAudit,
|
|
464
|
+
testHashSnapshot,
|
|
465
|
+
claudeCapabilities,
|
|
466
|
+
surfacedPendingDownshift,
|
|
467
|
+
resumeToolsetAudit
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
if (phase === 'post' || event.hook_event_name === 'PostCompact') {
|
|
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
|
+
|
|
528
|
+
return {
|
|
529
|
+
exitCode: 0,
|
|
530
|
+
stdout: '',
|
|
531
|
+
stderr: '',
|
|
532
|
+
result: postRes
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
return {
|
|
537
|
+
exitCode: 0,
|
|
538
|
+
stdout: '',
|
|
539
|
+
stderr: '',
|
|
540
|
+
result: null
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* CLI runner for `compact-lifecycle` (`ISS-035`).
|
|
546
|
+
* Non-blocking lifecycle hook: logs diagnostic to stderr and exits `0` on uncaught error.
|
|
547
|
+
*
|
|
548
|
+
* @param {object} [cliOptions={}]
|
|
549
|
+
*/
|
|
550
|
+
export async function executeCompactLifecycleCli(cliOptions = {}) {
|
|
551
|
+
const readPayload = cliOptions.readPayload || readStdinJsonAsync;
|
|
552
|
+
const runHook = cliOptions.runHook || runCompactLifecycleHook;
|
|
553
|
+
const ioOverride = cliOptions.ioOverride || {};
|
|
554
|
+
try {
|
|
555
|
+
const argv = cliOptions.argv || globalThis.process?.argv || [];
|
|
556
|
+
const phaseArg = argv.find((a) => String(a).startsWith('--phase='));
|
|
557
|
+
const explicitPhase = phaseArg ? String(phaseArg).split('=')[1] : undefined;
|
|
558
|
+
const payload = await readPayload(cliOptions.timeoutMs);
|
|
559
|
+
const res = runHook(payload, {
|
|
560
|
+
...(cliOptions.hookOptions || {}),
|
|
561
|
+
...(explicitPhase ? { phase: explicitPhase } : {})
|
|
562
|
+
});
|
|
563
|
+
if (res.stdout) {
|
|
564
|
+
exitWithStdoutJson(res.stdout, ioOverride);
|
|
565
|
+
} else {
|
|
566
|
+
exitPassThrough(ioOverride.exitFn);
|
|
567
|
+
}
|
|
568
|
+
} catch (err) {
|
|
569
|
+
exitDiagnosticZero(err?.message || String(err), 'CompactLifecycle', ioOverride);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
if (isCliEntrypoint(import.meta.url)) {
|
|
574
|
+
executeCompactLifecycleCli().catch((err) => {
|
|
575
|
+
exitDiagnosticZero(err?.message || String(err), 'CompactLifecycle');
|
|
576
|
+
});
|
|
577
|
+
}
|