context-brake 0.0.0-stage → 1.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/LICENSE +21 -0
- package/README.md +351 -2
- package/dist/assets/runtime/antigravity-cli-hook.mjs +19219 -0
- package/dist/assets/runtime/claude-code-hook.mjs +19400 -0
- package/dist/assets/runtime/claude-code-mod.mjs +18685 -0
- package/dist/assets/runtime/claude-code-statusline.mjs +18781 -0
- package/dist/assets/runtime/codex-cli-hook.mjs +19347 -0
- package/dist/assets/runtime/context-brake-runtime.mjs +6 -0
- package/dist/assets/runtime/cursor-hook.mjs +19229 -0
- package/dist/assets/runtime/github-copilot-cli-hook.mjs +19234 -0
- package/dist/assets/runtime/omp-extension.js +19284 -0
- package/dist/assets/runtime/omp-restart.js +18795 -0
- package/dist/assets/runtime/opencode-plugin.js +19247 -0
- package/dist/assets/runtime/pi-extension.js +19278 -0
- package/dist/assets/runtime/pi-restart.js +18790 -0
- package/dist/src/cli/argument-parser.d.ts +20 -0
- package/dist/src/cli/argument-parser.js +45 -0
- package/dist/src/cli/argument-validator.d.ts +8 -0
- package/dist/src/cli/argument-validator.js +24 -0
- package/dist/src/cli/assistant/ask.d.ts +10 -0
- package/dist/src/cli/assistant/ask.js +36 -0
- package/dist/src/cli/assistant/assistant-context.d.ts +9 -0
- package/dist/src/cli/assistant/assistant-context.js +25 -0
- package/dist/src/cli/assistant/assistant-questions.d.ts +3 -0
- package/dist/src/cli/assistant/assistant-questions.js +27 -0
- package/dist/src/cli/assistant/assistant-session.d.ts +5 -0
- package/dist/src/cli/assistant/assistant-session.js +27 -0
- package/dist/src/cli/assistant/clack-prompt-port.d.ts +14 -0
- package/dist/src/cli/assistant/clack-prompt-port.js +47 -0
- package/dist/src/cli/assistant/equivalent-command.d.ts +1 -0
- package/dist/src/cli/assistant/equivalent-command.js +16 -0
- package/dist/src/cli/assistant/invocation-facts.d.ts +5 -0
- package/dist/src/cli/assistant/invocation-facts.js +6 -0
- package/dist/src/cli/assistant/prompt-factory.d.ts +3 -0
- package/dist/src/cli/assistant/prompt-factory.js +16 -0
- package/dist/src/cli/assistant/prompt-port.d.ts +14 -0
- package/dist/src/cli/assistant/prompt-port.js +28 -0
- package/dist/src/cli/assistant/questions-gitignore.d.ts +7 -0
- package/dist/src/cli/assistant/questions-gitignore.js +14 -0
- package/dist/src/cli/assistant/questions-harness.d.ts +9 -0
- package/dist/src/cli/assistant/questions-harness.js +52 -0
- package/dist/src/cli/assistant/questions-misc.d.ts +11 -0
- package/dist/src/cli/assistant/questions-misc.js +26 -0
- package/dist/src/cli/assistant/questions-restart.d.ts +15 -0
- package/dist/src/cli/assistant/questions-restart.js +51 -0
- package/dist/src/cli/assistant/questions-skill.d.ts +21 -0
- package/dist/src/cli/assistant/questions-skill.js +45 -0
- package/dist/src/cli/assistant/questions-snapshot.d.ts +11 -0
- package/dist/src/cli/assistant/questions-snapshot.js +59 -0
- package/dist/src/cli/assistant/questions-trigger.d.ts +6 -0
- package/dist/src/cli/assistant/questions-trigger.js +56 -0
- package/dist/src/cli/assistant/skill-options.d.ts +20 -0
- package/dist/src/cli/assistant/skill-options.js +40 -0
- package/dist/src/cli/assistant/snapshot-specs.d.ts +10 -0
- package/dist/src/cli/assistant/snapshot-specs.js +32 -0
- package/dist/src/cli/assistant/summary-rows.d.ts +5 -0
- package/dist/src/cli/assistant/summary-rows.js +47 -0
- package/dist/src/cli/assistant/summary.d.ts +3 -0
- package/dist/src/cli/assistant/summary.js +25 -0
- package/dist/src/cli/assistant/types.d.ts +52 -0
- package/dist/src/cli/assistant/types.js +1 -0
- package/dist/src/cli/assistant/ui-prompt.d.ts +29 -0
- package/dist/src/cli/assistant/ui-prompt.js +1 -0
- package/dist/src/cli/commands/doctor.d.ts +3 -0
- package/dist/src/cli/commands/doctor.js +57 -0
- package/dist/src/cli/commands/init.d.ts +4 -0
- package/dist/src/cli/commands/init.js +26 -0
- package/dist/src/cli/commands/remove.d.ts +3 -0
- package/dist/src/cli/commands/remove.js +62 -0
- package/dist/src/cli/composition-root.d.ts +3 -0
- package/dist/src/cli/composition-root.js +62 -0
- package/dist/src/cli/confirmation.d.ts +6 -0
- package/dist/src/cli/confirmation.js +22 -0
- package/dist/src/cli/detection-collector.d.ts +14 -0
- package/dist/src/cli/detection-collector.js +31 -0
- package/dist/src/cli/exit-codes.d.ts +8 -0
- package/dist/src/cli/exit-codes.js +8 -0
- package/dist/src/cli/gitignore-findings.d.ts +3 -0
- package/dist/src/cli/gitignore-findings.js +11 -0
- package/dist/src/cli/handoff-findings.d.ts +5 -0
- package/dist/src/cli/handoff-findings.js +15 -0
- package/dist/src/cli/init-arguments.d.ts +25 -0
- package/dist/src/cli/init-arguments.js +71 -0
- package/dist/src/cli/init-config-state.d.ts +14 -0
- package/dist/src/cli/init-config-state.js +19 -0
- package/dist/src/cli/init-config-updates.d.ts +13 -0
- package/dist/src/cli/init-config-updates.js +35 -0
- package/dist/src/cli/init-flow.d.ts +14 -0
- package/dist/src/cli/init-flow.js +72 -0
- package/dist/src/cli/init-option-rules.d.ts +16 -0
- package/dist/src/cli/init-option-rules.js +45 -0
- package/dist/src/cli/main.d.ts +3 -0
- package/dist/src/cli/main.js +62 -0
- package/dist/src/cli/output/card.d.ts +8 -0
- package/dist/src/cli/output/card.js +30 -0
- package/dist/src/cli/output/detection-text.d.ts +2 -0
- package/dist/src/cli/output/detection-text.js +3 -0
- package/dist/src/cli/output/doctor-mode-text.d.ts +2 -0
- package/dist/src/cli/output/doctor-mode-text.js +18 -0
- package/dist/src/cli/output/doctor-sessions-text.d.ts +2 -0
- package/dist/src/cli/output/doctor-sessions-text.js +12 -0
- package/dist/src/cli/output/install-rows.d.ts +6 -0
- package/dist/src/cli/output/install-rows.js +31 -0
- package/dist/src/cli/output/install-text.d.ts +4 -0
- package/dist/src/cli/output/install-text.js +26 -0
- package/dist/src/cli/output/json.d.ts +1 -0
- package/dist/src/cli/output/json.js +3 -0
- package/dist/src/cli/output/style.d.ts +22 -0
- package/dist/src/cli/output/style.js +27 -0
- package/dist/src/cli/output/text.d.ts +4 -0
- package/dist/src/cli/output/text.js +41 -0
- package/dist/src/cli/snapshot-helper.d.ts +3 -0
- package/dist/src/cli/snapshot-helper.js +25 -0
- package/dist/src/cli/terminal.d.ts +9 -0
- package/dist/src/cli/terminal.js +18 -0
- package/dist/src/core/contracts/adapter.d.ts +50 -0
- package/dist/src/core/contracts/adapter.js +1 -0
- package/dist/src/core/contracts/auto-restart.d.ts +10 -0
- package/dist/src/core/contracts/auto-restart.js +10 -0
- package/dist/src/core/contracts/changes.d.ts +219 -0
- package/dist/src/core/contracts/changes.js +13 -0
- package/dist/src/core/contracts/configuration.d.ts +82 -0
- package/dist/src/core/contracts/configuration.js +44 -0
- package/dist/src/core/contracts/context-reading.d.ts +16 -0
- package/dist/src/core/contracts/context-reading.js +20 -0
- package/dist/src/core/contracts/context-window-report.d.ts +23 -0
- package/dist/src/core/contracts/context-window-report.js +10 -0
- package/dist/src/core/contracts/diagnostics.d.ts +567 -0
- package/dist/src/core/contracts/diagnostics.js +36 -0
- package/dist/src/core/contracts/handoff.d.ts +10 -0
- package/dist/src/core/contracts/handoff.js +3 -0
- package/dist/src/core/contracts/harness.d.ts +73 -0
- package/dist/src/core/contracts/harness.js +23 -0
- package/dist/src/core/contracts/hook-phase.d.ts +12 -0
- package/dist/src/core/contracts/hook-phase.js +1 -0
- package/dist/src/core/contracts/manifest.d.ts +85 -0
- package/dist/src/core/contracts/manifest.js +26 -0
- package/dist/src/core/contracts/processes.d.ts +24 -0
- package/dist/src/core/contracts/processes.js +1 -0
- package/dist/src/core/contracts/restart-host.d.ts +32 -0
- package/dist/src/core/contracts/restart-host.js +3 -0
- package/dist/src/core/contracts/restart-log.d.ts +52 -0
- package/dist/src/core/contracts/restart-log.js +15 -0
- package/dist/src/core/contracts/runtime.d.ts +52 -0
- package/dist/src/core/contracts/runtime.js +1 -0
- package/dist/src/core/contracts/session-ledger.d.ts +144 -0
- package/dist/src/core/contracts/session-ledger.js +38 -0
- package/dist/src/core/contracts/skill-catalog.d.ts +11 -0
- package/dist/src/core/contracts/skill-catalog.js +1 -0
- package/dist/src/core/contracts/skill-invocation.d.ts +3 -0
- package/dist/src/core/contracts/skill-invocation.js +1 -0
- package/dist/src/core/contracts/skill-name.d.ts +5 -0
- package/dist/src/core/contracts/skill-name.js +31 -0
- package/dist/src/core/contracts/statusline-line.d.ts +20 -0
- package/dist/src/core/contracts/statusline-line.js +13 -0
- package/dist/src/core/contracts/zones.d.ts +18 -0
- package/dist/src/core/contracts/zones.js +4 -0
- package/dist/src/core/services/active-sessions.d.ts +17 -0
- package/dist/src/core/services/active-sessions.js +35 -0
- package/dist/src/core/services/asset-currency.d.ts +17 -0
- package/dist/src/core/services/asset-currency.js +72 -0
- package/dist/src/core/services/auto-restart-merge.d.ts +26 -0
- package/dist/src/core/services/auto-restart-merge.js +30 -0
- package/dist/src/core/services/auto-restart-notices.d.ts +6 -0
- package/dist/src/core/services/auto-restart-notices.js +27 -0
- package/dist/src/core/services/auto-restart-policy.d.ts +26 -0
- package/dist/src/core/services/auto-restart-policy.js +23 -0
- package/dist/src/core/services/brake-engine.d.ts +24 -0
- package/dist/src/core/services/brake-engine.js +62 -0
- package/dist/src/core/services/change-plan-service.d.ts +11 -0
- package/dist/src/core/services/change-plan-service.js +60 -0
- package/dist/src/core/services/config-legacy-checks.d.ts +6 -0
- package/dist/src/core/services/config-legacy-checks.js +28 -0
- package/dist/src/core/services/debug-mode-merge.d.ts +25 -0
- package/dist/src/core/services/debug-mode-merge.js +21 -0
- package/dist/src/core/services/detection-service.d.ts +6 -0
- package/dist/src/core/services/detection-service.js +54 -0
- package/dist/src/core/services/doctor-checks.d.ts +6 -0
- package/dist/src/core/services/doctor-checks.js +24 -0
- package/dist/src/core/services/doctor-report-extras.d.ts +13 -0
- package/dist/src/core/services/doctor-report-extras.js +40 -0
- package/dist/src/core/services/doctor-service.d.ts +26 -0
- package/dist/src/core/services/doctor-service.js +82 -0
- package/dist/src/core/services/failure-policy.d.ts +38 -0
- package/dist/src/core/services/failure-policy.js +63 -0
- package/dist/src/core/services/gitignore-block.d.ts +10 -0
- package/dist/src/core/services/gitignore-block.js +61 -0
- package/dist/src/core/services/gitignore-merge.d.ts +23 -0
- package/dist/src/core/services/gitignore-merge.js +21 -0
- package/dist/src/core/services/gitignore-plan.d.ts +34 -0
- package/dist/src/core/services/gitignore-plan.js +65 -0
- package/dist/src/core/services/harness-exclusion.d.ts +14 -0
- package/dist/src/core/services/harness-exclusion.js +19 -0
- package/dist/src/core/services/harness-removal.d.ts +23 -0
- package/dist/src/core/services/harness-removal.js +34 -0
- package/dist/src/core/services/injection-policy.d.ts +10 -0
- package/dist/src/core/services/injection-policy.js +5 -0
- package/dist/src/core/services/installation-adapters.d.ts +22 -0
- package/dist/src/core/services/installation-adapters.js +30 -0
- package/dist/src/core/services/installation-builder.d.ts +24 -0
- package/dist/src/core/services/installation-builder.js +67 -0
- package/dist/src/core/services/installation-findings.d.ts +5 -0
- package/dist/src/core/services/installation-findings.js +19 -0
- package/dist/src/core/services/installation-service.d.ts +36 -0
- package/dist/src/core/services/installation-service.js +50 -0
- package/dist/src/core/services/manifest-change.d.ts +12 -0
- package/dist/src/core/services/manifest-change.js +17 -0
- package/dist/src/core/services/no-harness-finding.d.ts +3 -0
- package/dist/src/core/services/no-harness-finding.js +9 -0
- package/dist/src/core/services/removal-helper.d.ts +10 -0
- package/dist/src/core/services/removal-helper.js +48 -0
- package/dist/src/core/services/removal-service.d.ts +19 -0
- package/dist/src/core/services/removal-service.js +45 -0
- package/dist/src/core/services/report-service.d.ts +30 -0
- package/dist/src/core/services/report-service.js +71 -0
- package/dist/src/core/services/reset-notice.d.ts +3 -0
- package/dist/src/core/services/reset-notice.js +8 -0
- package/dist/src/core/services/restart-doctor-findings.d.ts +10 -0
- package/dist/src/core/services/restart-doctor-findings.js +24 -0
- package/dist/src/core/services/restart-flow.d.ts +13 -0
- package/dist/src/core/services/restart-flow.js +50 -0
- package/dist/src/core/services/restart-guards.d.ts +6 -0
- package/dist/src/core/services/restart-guards.js +25 -0
- package/dist/src/core/services/restart-install-extras.d.ts +27 -0
- package/dist/src/core/services/restart-install-extras.js +39 -0
- package/dist/src/core/services/restart-mode.d.ts +4 -0
- package/dist/src/core/services/restart-mode.js +6 -0
- package/dist/src/core/services/runtime-error-checks.d.ts +11 -0
- package/dist/src/core/services/runtime-error-checks.js +20 -0
- package/dist/src/core/services/session-counters.d.ts +15 -0
- package/dist/src/core/services/session-counters.js +33 -0
- package/dist/src/core/services/session-reset-handler.d.ts +18 -0
- package/dist/src/core/services/session-reset-handler.js +24 -0
- package/dist/src/core/services/session-zone.d.ts +30 -0
- package/dist/src/core/services/session-zone.js +25 -0
- package/dist/src/core/services/skill-candidates.d.ts +16 -0
- package/dist/src/core/services/skill-candidates.js +14 -0
- package/dist/src/core/services/skill-invocation.d.ts +4 -0
- package/dist/src/core/services/skill-invocation.js +12 -0
- package/dist/src/core/services/skill-ranking.d.ts +7 -0
- package/dist/src/core/services/skill-ranking.js +25 -0
- package/dist/src/core/services/snapshot-merge.d.ts +23 -0
- package/dist/src/core/services/snapshot-merge.js +32 -0
- package/dist/src/core/services/statusline-summary.d.ts +10 -0
- package/dist/src/core/services/statusline-summary.js +13 -0
- package/dist/src/core/services/support-service.d.ts +2 -0
- package/dist/src/core/services/support-service.js +57 -0
- package/dist/src/core/services/telemetry-block.d.ts +14 -0
- package/dist/src/core/services/telemetry-block.js +17 -0
- package/dist/src/core/services/trigger-text.d.ts +5 -0
- package/dist/src/core/services/trigger-text.js +4 -0
- package/dist/src/core/services/usage-resolver.d.ts +20 -0
- package/dist/src/core/services/usage-resolver.js +23 -0
- package/dist/src/core/services/version-service.d.ts +14 -0
- package/dist/src/core/services/version-service.js +45 -0
- package/dist/src/core/services/window-trust.d.ts +2 -0
- package/dist/src/core/services/window-trust.js +3 -0
- package/dist/src/core/services/zone-classifier.d.ts +11 -0
- package/dist/src/core/services/zone-classifier.js +24 -0
- package/dist/src/core/services/zone-guidance.d.ts +17 -0
- package/dist/src/core/services/zone-guidance.js +38 -0
- package/dist/src/core/validation/configuration-sanitizer.d.ts +10 -0
- package/dist/src/core/validation/configuration-sanitizer.js +31 -0
- package/dist/src/core/validation/configuration-validator.d.ts +18 -0
- package/dist/src/core/validation/configuration-validator.js +45 -0
- package/dist/src/infrastructure/diagnostics/in-process-sampler.d.ts +18 -0
- package/dist/src/infrastructure/diagnostics/in-process-sampler.js +63 -0
- package/dist/src/infrastructure/diagnostics/overhead-measurer.d.ts +12 -0
- package/dist/src/infrastructure/diagnostics/overhead-measurer.js +77 -0
- package/dist/src/infrastructure/diagnostics/p95.d.ts +1 -0
- package/dist/src/infrastructure/diagnostics/p95.js +9 -0
- package/dist/src/infrastructure/diagnostics/process-sampler.d.ts +7 -0
- package/dist/src/infrastructure/diagnostics/process-sampler.js +69 -0
- package/dist/src/infrastructure/diagnostics/sample-failure.d.ts +10 -0
- package/dist/src/infrastructure/diagnostics/sample-failure.js +19 -0
- package/dist/src/infrastructure/git/git-context.d.ts +3 -0
- package/dist/src/infrastructure/git/git-context.js +25 -0
- package/dist/src/infrastructure/harnesses/antigravity-cli/adapter.d.ts +14 -0
- package/dist/src/infrastructure/harnesses/antigravity-cli/adapter.js +84 -0
- package/dist/src/infrastructure/harnesses/antigravity-cli/capabilities.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/antigravity-cli/capabilities.js +6 -0
- package/dist/src/infrastructure/harnesses/antigravity-cli/detector.d.ts +4 -0
- package/dist/src/infrastructure/harnesses/antigravity-cli/detector.js +56 -0
- package/dist/src/infrastructure/harnesses/antigravity-cli/planner.d.ts +7 -0
- package/dist/src/infrastructure/harnesses/antigravity-cli/planner.js +62 -0
- package/dist/src/infrastructure/harnesses/antigravity-cli/runtime.d.ts +9 -0
- package/dist/src/infrastructure/harnesses/antigravity-cli/runtime.js +52 -0
- package/dist/src/infrastructure/harnesses/antigravity-cli/schemas.d.ts +31 -0
- package/dist/src/infrastructure/harnesses/antigravity-cli/schemas.js +19 -0
- package/dist/src/infrastructure/harnesses/antigravity-cli/skill-folders.d.ts +1 -0
- package/dist/src/infrastructure/harnesses/antigravity-cli/skill-folders.js +1 -0
- package/dist/src/infrastructure/harnesses/antigravity-cli/skill-invocation.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/antigravity-cli/skill-invocation.js +2 -0
- package/dist/src/infrastructure/harnesses/claude-code/adapter.d.ts +14 -0
- package/dist/src/infrastructure/harnesses/claude-code/adapter.js +86 -0
- package/dist/src/infrastructure/harnesses/claude-code/auto-restart-diagnostics.d.ts +10 -0
- package/dist/src/infrastructure/harnesses/claude-code/auto-restart-diagnostics.js +60 -0
- package/dist/src/infrastructure/harnesses/claude-code/auto-restart-files.d.ts +12 -0
- package/dist/src/infrastructure/harnesses/claude-code/auto-restart-files.js +24 -0
- package/dist/src/infrastructure/harnesses/claude-code/auto-restart-ownership.d.ts +5 -0
- package/dist/src/infrastructure/harnesses/claude-code/auto-restart-ownership.js +41 -0
- package/dist/src/infrastructure/harnesses/claude-code/auto-restart-planner.d.ts +11 -0
- package/dist/src/infrastructure/harnesses/claude-code/auto-restart-planner.js +81 -0
- package/dist/src/infrastructure/harnesses/claude-code/auto-restart-settings.d.ts +4 -0
- package/dist/src/infrastructure/harnesses/claude-code/auto-restart-settings.js +29 -0
- package/dist/src/infrastructure/harnesses/claude-code/capabilities.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/claude-code/capabilities.js +6 -0
- package/dist/src/infrastructure/harnesses/claude-code/claude-hooks-config.d.ts +1 -0
- package/dist/src/infrastructure/harnesses/claude-code/claude-hooks-config.js +25 -0
- package/dist/src/infrastructure/harnesses/claude-code/claude-merger.d.ts +14 -0
- package/dist/src/infrastructure/harnesses/claude-code/claude-merger.js +44 -0
- package/dist/src/infrastructure/harnesses/claude-code/context-readings-scan.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/claude-code/context-readings-scan.js +21 -0
- package/dist/src/infrastructure/harnesses/claude-code/context-source.d.ts +10 -0
- package/dist/src/infrastructure/harnesses/claude-code/context-source.js +16 -0
- package/dist/src/infrastructure/harnesses/claude-code/detector.d.ts +6 -0
- package/dist/src/infrastructure/harnesses/claude-code/detector.js +14 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/context-reading.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/context-reading.js +67 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/hooks.d.ts +6 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/hooks.js +43 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/host.d.ts +65 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/host.js +1 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/mod-config.d.ts +8 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/mod-config.js +31 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/mod-guards.d.ts +3 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/mod-guards.js +13 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/mod-info.d.ts +4 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/mod-info.js +5 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/mod-log.d.ts +5 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/mod-log.js +37 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/register.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/register.js +28 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/restart-facts.d.ts +3 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/restart-facts.js +12 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/restart-flow.d.ts +4 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/restart-flow.js +22 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/restart-host.d.ts +7 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/restart-host.js +35 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/turn-state.d.ts +7 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod/turn-state.js +12 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod-reading.d.ts +6 -0
- package/dist/src/infrastructure/harnesses/claude-code/mod-reading.js +37 -0
- package/dist/src/infrastructure/harnesses/claude-code/planner.d.ts +8 -0
- package/dist/src/infrastructure/harnesses/claude-code/planner.js +72 -0
- package/dist/src/infrastructure/harnesses/claude-code/project-root.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/claude-code/project-root.js +5 -0
- package/dist/src/infrastructure/harnesses/claude-code/runtime.d.ts +10 -0
- package/dist/src/infrastructure/harnesses/claude-code/runtime.js +87 -0
- package/dist/src/infrastructure/harnesses/claude-code/schemas.d.ts +42 -0
- package/dist/src/infrastructure/harnesses/claude-code/schemas.js +30 -0
- package/dist/src/infrastructure/harnesses/claude-code/skill-folders.d.ts +1 -0
- package/dist/src/infrastructure/harnesses/claude-code/skill-folders.js +1 -0
- package/dist/src/infrastructure/harnesses/claude-code/skill-invocation.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/claude-code/skill-invocation.js +2 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-bridge.d.ts +12 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-bridge.js +78 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-context-window.d.ts +5 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-context-window.js +63 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-default.d.ts +6 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-default.js +38 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-diagnostics.d.ts +3 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-diagnostics.js +70 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-migration.d.ts +3 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-migration.js +23 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-output.d.ts +9 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-output.js +15 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-payload.d.ts +7 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-payload.js +36 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-planner.d.ts +5 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-planner.js +85 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-previous.d.ts +17 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-previous.js +41 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-restore.d.ts +9 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-restore.js +31 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-settings.d.ts +33 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-settings.js +63 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-shell.d.ts +13 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-shell.js +28 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-state.d.ts +21 -0
- package/dist/src/infrastructure/harnesses/claude-code/statusline-state.js +29 -0
- package/dist/src/infrastructure/harnesses/claude-code/transcript-usage.d.ts +6 -0
- package/dist/src/infrastructure/harnesses/claude-code/transcript-usage.js +24 -0
- package/dist/src/infrastructure/harnesses/claude-code/user-settings.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/claude-code/user-settings.js +11 -0
- package/dist/src/infrastructure/harnesses/codex-cli/adapter.d.ts +14 -0
- package/dist/src/infrastructure/harnesses/codex-cli/adapter.js +91 -0
- package/dist/src/infrastructure/harnesses/codex-cli/capabilities.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/codex-cli/capabilities.js +6 -0
- package/dist/src/infrastructure/harnesses/codex-cli/detector.d.ts +6 -0
- package/dist/src/infrastructure/harnesses/codex-cli/detector.js +13 -0
- package/dist/src/infrastructure/harnesses/codex-cli/planner.d.ts +7 -0
- package/dist/src/infrastructure/harnesses/codex-cli/planner.js +75 -0
- package/dist/src/infrastructure/harnesses/codex-cli/rollout-usage.d.ts +6 -0
- package/dist/src/infrastructure/harnesses/codex-cli/rollout-usage.js +27 -0
- package/dist/src/infrastructure/harnesses/codex-cli/runtime.d.ts +10 -0
- package/dist/src/infrastructure/harnesses/codex-cli/runtime.js +86 -0
- package/dist/src/infrastructure/harnesses/codex-cli/schemas.d.ts +47 -0
- package/dist/src/infrastructure/harnesses/codex-cli/schemas.js +25 -0
- package/dist/src/infrastructure/harnesses/codex-cli/skill-folders.d.ts +1 -0
- package/dist/src/infrastructure/harnesses/codex-cli/skill-folders.js +1 -0
- package/dist/src/infrastructure/harnesses/codex-cli/skill-invocation.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/codex-cli/skill-invocation.js +2 -0
- package/dist/src/infrastructure/harnesses/common/antigravity-hooks-updater.d.ts +4 -0
- package/dist/src/infrastructure/harnesses/common/antigravity-hooks-updater.js +57 -0
- package/dist/src/infrastructure/harnesses/common/change-target.d.ts +1 -0
- package/dist/src/infrastructure/harnesses/common/change-target.js +40 -0
- package/dist/src/infrastructure/harnesses/common/codex-hooks-updater.d.ts +13 -0
- package/dist/src/infrastructure/harnesses/common/codex-hooks-updater.js +79 -0
- package/dist/src/infrastructure/harnesses/common/config-origin.d.ts +10 -0
- package/dist/src/infrastructure/harnesses/common/config-origin.js +52 -0
- package/dist/src/infrastructure/harnesses/common/cursor-hooks-updater.d.ts +3 -0
- package/dist/src/infrastructure/harnesses/common/cursor-hooks-updater.js +63 -0
- package/dist/src/infrastructure/harnesses/common/diagnostic-helpers.d.ts +7 -0
- package/dist/src/infrastructure/harnesses/common/diagnostic-helpers.js +60 -0
- package/dist/src/infrastructure/harnesses/common/hook-event-cleanup.d.ts +3 -0
- package/dist/src/infrastructure/harnesses/common/hook-event-cleanup.js +50 -0
- package/dist/src/infrastructure/harnesses/common/in-process-restart-log.d.ts +9 -0
- package/dist/src/infrastructure/harnesses/common/in-process-restart-log.js +36 -0
- package/dist/src/infrastructure/harnesses/common/in-process-restart-state.d.ts +11 -0
- package/dist/src/infrastructure/harnesses/common/in-process-restart-state.js +50 -0
- package/dist/src/infrastructure/harnesses/common/in-process-restart-support.d.ts +13 -0
- package/dist/src/infrastructure/harnesses/common/in-process-restart-support.js +15 -0
- package/dist/src/infrastructure/harnesses/common/in-process-support.d.ts +18 -0
- package/dist/src/infrastructure/harnesses/common/in-process-support.js +40 -0
- package/dist/src/infrastructure/harnesses/common/jsonl-tail-reader.d.ts +6 -0
- package/dist/src/infrastructure/harnesses/common/jsonl-tail-reader.js +76 -0
- package/dist/src/infrastructure/harnesses/common/path-helpers.d.ts +6 -0
- package/dist/src/infrastructure/harnesses/common/path-helpers.js +51 -0
- package/dist/src/infrastructure/harnesses/common/removal-config-validator.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/common/removal-config-validator.js +14 -0
- package/dist/src/infrastructure/harnesses/common/restart-asset-plan.d.ts +12 -0
- package/dist/src/infrastructure/harnesses/common/restart-asset-plan.js +37 -0
- package/dist/src/infrastructure/harnesses/common/restart-diagnostics.d.ts +12 -0
- package/dist/src/infrastructure/harnesses/common/restart-diagnostics.js +49 -0
- package/dist/src/infrastructure/harnesses/common/runtime-assets.d.ts +1 -0
- package/dist/src/infrastructure/harnesses/common/runtime-assets.js +23 -0
- package/dist/src/infrastructure/harnesses/common/runtime-support.d.ts +8 -0
- package/dist/src/infrastructure/harnesses/common/runtime-support.js +44 -0
- package/dist/src/infrastructure/harnesses/common/version-probes.d.ts +3 -0
- package/dist/src/infrastructure/harnesses/common/version-probes.js +21 -0
- package/dist/src/infrastructure/harnesses/cursor/adapter.d.ts +14 -0
- package/dist/src/infrastructure/harnesses/cursor/adapter.js +71 -0
- package/dist/src/infrastructure/harnesses/cursor/capabilities.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/cursor/capabilities.js +6 -0
- package/dist/src/infrastructure/harnesses/cursor/detector.d.ts +6 -0
- package/dist/src/infrastructure/harnesses/cursor/detector.js +13 -0
- package/dist/src/infrastructure/harnesses/cursor/planner.d.ts +7 -0
- package/dist/src/infrastructure/harnesses/cursor/planner.js +66 -0
- package/dist/src/infrastructure/harnesses/cursor/runtime.d.ts +9 -0
- package/dist/src/infrastructure/harnesses/cursor/runtime.js +50 -0
- package/dist/src/infrastructure/harnesses/cursor/schemas.d.ts +39 -0
- package/dist/src/infrastructure/harnesses/cursor/schemas.js +23 -0
- package/dist/src/infrastructure/harnesses/cursor/skill-folders.d.ts +1 -0
- package/dist/src/infrastructure/harnesses/cursor/skill-folders.js +1 -0
- package/dist/src/infrastructure/harnesses/cursor/skill-invocation.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/cursor/skill-invocation.js +2 -0
- package/dist/src/infrastructure/harnesses/github-copilot-cli/adapter.d.ts +14 -0
- package/dist/src/infrastructure/harnesses/github-copilot-cli/adapter.js +69 -0
- package/dist/src/infrastructure/harnesses/github-copilot-cli/capabilities.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/github-copilot-cli/capabilities.js +6 -0
- package/dist/src/infrastructure/harnesses/github-copilot-cli/detector.d.ts +6 -0
- package/dist/src/infrastructure/harnesses/github-copilot-cli/detector.js +15 -0
- package/dist/src/infrastructure/harnesses/github-copilot-cli/planner.d.ts +7 -0
- package/dist/src/infrastructure/harnesses/github-copilot-cli/planner.js +66 -0
- package/dist/src/infrastructure/harnesses/github-copilot-cli/runtime.d.ts +9 -0
- package/dist/src/infrastructure/harnesses/github-copilot-cli/runtime.js +68 -0
- package/dist/src/infrastructure/harnesses/github-copilot-cli/schemas.d.ts +35 -0
- package/dist/src/infrastructure/harnesses/github-copilot-cli/schemas.js +21 -0
- package/dist/src/infrastructure/harnesses/github-copilot-cli/skill-folders.d.ts +1 -0
- package/dist/src/infrastructure/harnesses/github-copilot-cli/skill-folders.js +1 -0
- package/dist/src/infrastructure/harnesses/github-copilot-cli/skill-invocation.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/github-copilot-cli/skill-invocation.js +2 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/adapter.d.ts +14 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/adapter.js +64 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/capabilities.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/capabilities.js +6 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/detector.d.ts +6 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/detector.js +13 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/events.d.ts +8 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/events.js +65 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/planner.d.ts +7 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/planner.js +32 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/restart.d.ts +28 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/restart.js +79 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/runtime.d.ts +17 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/runtime.js +70 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/schemas.d.ts +50 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/schemas.js +17 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/skill-folders.d.ts +1 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/skill-folders.js +1 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/skill-invocation.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/oh-my-pi/skill-invocation.js +2 -0
- package/dist/src/infrastructure/harnesses/opencode/adapter.d.ts +14 -0
- package/dist/src/infrastructure/harnesses/opencode/adapter.js +64 -0
- package/dist/src/infrastructure/harnesses/opencode/capabilities.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/opencode/capabilities.js +6 -0
- package/dist/src/infrastructure/harnesses/opencode/detector.d.ts +6 -0
- package/dist/src/infrastructure/harnesses/opencode/detector.js +16 -0
- package/dist/src/infrastructure/harnesses/opencode/events.d.ts +8 -0
- package/dist/src/infrastructure/harnesses/opencode/events.js +36 -0
- package/dist/src/infrastructure/harnesses/opencode/planner.d.ts +6 -0
- package/dist/src/infrastructure/harnesses/opencode/planner.js +23 -0
- package/dist/src/infrastructure/harnesses/opencode/runtime.d.ts +20 -0
- package/dist/src/infrastructure/harnesses/opencode/runtime.js +52 -0
- package/dist/src/infrastructure/harnesses/opencode/schemas.d.ts +51 -0
- package/dist/src/infrastructure/harnesses/opencode/schemas.js +32 -0
- package/dist/src/infrastructure/harnesses/opencode/skill-folders.d.ts +1 -0
- package/dist/src/infrastructure/harnesses/opencode/skill-folders.js +1 -0
- package/dist/src/infrastructure/harnesses/opencode/skill-invocation.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/opencode/skill-invocation.js +2 -0
- package/dist/src/infrastructure/harnesses/pi/adapter.d.ts +14 -0
- package/dist/src/infrastructure/harnesses/pi/adapter.js +64 -0
- package/dist/src/infrastructure/harnesses/pi/capabilities.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/pi/capabilities.js +6 -0
- package/dist/src/infrastructure/harnesses/pi/detector.d.ts +6 -0
- package/dist/src/infrastructure/harnesses/pi/detector.js +10 -0
- package/dist/src/infrastructure/harnesses/pi/events.d.ts +8 -0
- package/dist/src/infrastructure/harnesses/pi/events.js +65 -0
- package/dist/src/infrastructure/harnesses/pi/planner.d.ts +7 -0
- package/dist/src/infrastructure/harnesses/pi/planner.js +32 -0
- package/dist/src/infrastructure/harnesses/pi/restart.d.ts +33 -0
- package/dist/src/infrastructure/harnesses/pi/restart.js +69 -0
- package/dist/src/infrastructure/harnesses/pi/runtime.d.ts +17 -0
- package/dist/src/infrastructure/harnesses/pi/runtime.js +68 -0
- package/dist/src/infrastructure/harnesses/pi/schemas.d.ts +50 -0
- package/dist/src/infrastructure/harnesses/pi/schemas.js +17 -0
- package/dist/src/infrastructure/harnesses/pi/skill-folders.d.ts +1 -0
- package/dist/src/infrastructure/harnesses/pi/skill-folders.js +1 -0
- package/dist/src/infrastructure/harnesses/pi/skill-invocation.d.ts +2 -0
- package/dist/src/infrastructure/harnesses/pi/skill-invocation.js +2 -0
- package/dist/src/infrastructure/harnesses/registry.d.ts +6 -0
- package/dist/src/infrastructure/harnesses/registry.js +94 -0
- package/dist/src/infrastructure/harnesses/skill-folders.d.ts +3 -0
- package/dist/src/infrastructure/harnesses/skill-folders.js +21 -0
- package/dist/src/infrastructure/harnesses/skill-invocations.d.ts +4 -0
- package/dist/src/infrastructure/harnesses/skill-invocations.js +21 -0
- package/dist/src/infrastructure/process/node-process-runner.d.ts +8 -0
- package/dist/src/infrastructure/process/node-process-runner.js +66 -0
- package/dist/src/infrastructure/process/process-tree.d.ts +2 -0
- package/dist/src/infrastructure/process/process-tree.js +28 -0
- package/dist/src/infrastructure/runtime/hook-deadline.d.ts +26 -0
- package/dist/src/infrastructure/runtime/hook-deadline.js +55 -0
- package/dist/src/infrastructure/runtime/hook-failure.d.ts +14 -0
- package/dist/src/infrastructure/runtime/hook-failure.js +22 -0
- package/dist/src/infrastructure/runtime/in-process-host.d.ts +16 -0
- package/dist/src/infrastructure/runtime/in-process-host.js +75 -0
- package/dist/src/infrastructure/runtime/node-runtime-logs.d.ts +8 -0
- package/dist/src/infrastructure/runtime/node-runtime-logs.js +21 -0
- package/dist/src/infrastructure/runtime/node-session-ledger.d.ts +17 -0
- package/dist/src/infrastructure/runtime/node-session-ledger.js +68 -0
- package/dist/src/infrastructure/runtime/process-hook-host.d.ts +25 -0
- package/dist/src/infrastructure/runtime/process-hook-host.js +79 -0
- package/dist/src/infrastructure/runtime/runtime-composition.d.ts +29 -0
- package/dist/src/infrastructure/runtime/runtime-composition.js +41 -0
- package/dist/src/infrastructure/runtime/runtime-paths.d.ts +12 -0
- package/dist/src/infrastructure/runtime/runtime-paths.js +46 -0
- package/dist/src/infrastructure/runtime/runtime-state-reader.d.ts +9 -0
- package/dist/src/infrastructure/runtime/runtime-state-reader.js +82 -0
- package/dist/src/infrastructure/skills/frontmatter.d.ts +5 -0
- package/dist/src/infrastructure/skills/frontmatter.js +25 -0
- package/dist/src/infrastructure/skills/skill-catalog-reader.d.ts +4 -0
- package/dist/src/infrastructure/skills/skill-catalog-reader.js +78 -0
- package/dist/src/infrastructure/skills/skill-catalog.d.ts +2 -0
- package/dist/src/infrastructure/skills/skill-catalog.js +5 -0
- package/dist/src/infrastructure/storage/atomic-writer.d.ts +2 -0
- package/dist/src/infrastructure/storage/atomic-writer.js +35 -0
- package/dist/src/infrastructure/storage/change-applier.d.ts +11 -0
- package/dist/src/infrastructure/storage/change-applier.js +81 -0
- package/dist/src/infrastructure/storage/directory-pruner.d.ts +8 -0
- package/dist/src/infrastructure/storage/directory-pruner.js +76 -0
- package/dist/src/infrastructure/storage/handoff-claim-lock.d.ts +3 -0
- package/dist/src/infrastructure/storage/handoff-claim-lock.js +32 -0
- package/dist/src/infrastructure/storage/json-document-editor.d.ts +5 -0
- package/dist/src/infrastructure/storage/json-document-editor.js +53 -0
- package/dist/src/infrastructure/storage/json-node-removal.d.ts +2 -0
- package/dist/src/infrastructure/storage/json-node-removal.js +70 -0
- package/dist/src/infrastructure/storage/json-span-utils.d.ts +24 -0
- package/dist/src/infrastructure/storage/json-span-utils.js +57 -0
- package/dist/src/infrastructure/storage/json-validator.d.ts +13 -0
- package/dist/src/infrastructure/storage/json-validator.js +61 -0
- package/dist/src/infrastructure/storage/manifest-store.d.ts +11 -0
- package/dist/src/infrastructure/storage/manifest-store.js +45 -0
- package/dist/src/infrastructure/storage/node-file-system.d.ts +4 -0
- package/dist/src/infrastructure/storage/node-file-system.js +33 -0
- package/dist/src/infrastructure/storage/node-handoff-store.d.ts +11 -0
- package/dist/src/infrastructure/storage/node-handoff-store.js +96 -0
- package/dist/src/infrastructure/storage/package-metadata.d.ts +7 -0
- package/dist/src/infrastructure/storage/package-metadata.js +58 -0
- package/dist/src/infrastructure/storage/path-boundary.d.ts +11 -0
- package/dist/src/infrastructure/storage/path-boundary.js +73 -0
- package/dist/src/infrastructure/storage/project-config-store.d.ts +9 -0
- package/dist/src/infrastructure/storage/project-config-store.js +24 -0
- package/dist/src/infrastructure/storage/runtime-state-files.d.ts +12 -0
- package/dist/src/infrastructure/storage/runtime-state-files.js +22 -0
- package/docs/telemetry-block.md +151 -0
- package/package.json +65 -4
- package/schemas/context-brake.config.schema.json +182 -0
- package/schemas/doctor-report.schema.json +646 -0
- package/schemas/install-report.schema.json +458 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { realpath } from 'node:fs/promises';
|
|
2
|
+
import { basename, dirname, resolve } from 'node:path';
|
|
3
|
+
import { assertWithinRepository, normalizeSeparators } from '../../storage/path-boundary.js';
|
|
4
|
+
async function findExistingAncestor(startPath) {
|
|
5
|
+
let current = startPath;
|
|
6
|
+
const missing = [];
|
|
7
|
+
while (true) {
|
|
8
|
+
missing.unshift(basename(current));
|
|
9
|
+
const parent = dirname(current);
|
|
10
|
+
if (parent === current) {
|
|
11
|
+
return { ancestor: current, missing };
|
|
12
|
+
}
|
|
13
|
+
current = parent;
|
|
14
|
+
try {
|
|
15
|
+
const canonical = await realpath(current);
|
|
16
|
+
return { ancestor: canonical, missing };
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
/* climb up */
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async function resolveCanonicalTarget(fullPath) {
|
|
24
|
+
try {
|
|
25
|
+
const existing = await realpath(fullPath);
|
|
26
|
+
return normalizeSeparators(existing);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
const { ancestor, missing } = await findExistingAncestor(fullPath);
|
|
30
|
+
const target = missing.length > 0 ? resolve(ancestor, ...missing) : ancestor;
|
|
31
|
+
return normalizeSeparators(target);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export async function resolveChangeTarget(projectRoot, targetPath) {
|
|
35
|
+
await assertWithinRepository(projectRoot, targetPath);
|
|
36
|
+
const fullPath = resolve(projectRoot, targetPath);
|
|
37
|
+
const canonical = await resolveCanonicalTarget(fullPath);
|
|
38
|
+
await assertWithinRepository(projectRoot, canonical);
|
|
39
|
+
return canonical;
|
|
40
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const CODEX_HOOK_FILE = ".codex/hooks/context-brake.mjs";
|
|
2
|
+
export declare const CODEX_EVENTS: readonly ["PostToolUse", "SessionStart", "Stop"];
|
|
3
|
+
export type CodexHook = {
|
|
4
|
+
type: string;
|
|
5
|
+
command: string;
|
|
6
|
+
commandWindows?: string;
|
|
7
|
+
};
|
|
8
|
+
export type CodexGroup = {
|
|
9
|
+
matcher: string;
|
|
10
|
+
hooks: CodexHook[];
|
|
11
|
+
};
|
|
12
|
+
export declare function isCodexOwnedHandler(handler: unknown): boolean;
|
|
13
|
+
export declare function updateCodexHooks(content: string, clear: boolean, buildGroup: (event: string) => CodexGroup): string;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { findNodeAtLocation, getNodeValue } from 'jsonc-parser';
|
|
2
|
+
import { removeOwnedFromOtherEvents } from './hook-event-cleanup.js';
|
|
3
|
+
import { appendJsonArrayItem, parseAndValidateJson, removeJsonArrayItem, removeJsonProperty, setJsonProperty } from '../../storage/json-document-editor.js';
|
|
4
|
+
export const CODEX_HOOK_FILE = '.codex/hooks/context-brake.mjs';
|
|
5
|
+
export const CODEX_EVENTS = ['PostToolUse', 'SessionStart', 'Stop'];
|
|
6
|
+
export function isCodexOwnedHandler(handler) {
|
|
7
|
+
if (typeof handler !== 'object' || handler === null)
|
|
8
|
+
return false;
|
|
9
|
+
const h = handler;
|
|
10
|
+
return (typeof h.command === 'string' && h.command.includes(CODEX_HOOK_FILE)) ||
|
|
11
|
+
(typeof h.commandWindows === 'string' && h.commandWindows.includes(CODEX_HOOK_FILE));
|
|
12
|
+
}
|
|
13
|
+
function isGroupPurelyOwned(group) {
|
|
14
|
+
if (typeof group !== 'object' || group === null)
|
|
15
|
+
return false;
|
|
16
|
+
const g = group;
|
|
17
|
+
return Array.isArray(g.hooks) && g.hooks.length > 0 && g.hooks.every(isCodexOwnedHandler);
|
|
18
|
+
}
|
|
19
|
+
function groupHasOwnedHandler(group) {
|
|
20
|
+
if (typeof group !== 'object' || group === null)
|
|
21
|
+
return false;
|
|
22
|
+
const g = group;
|
|
23
|
+
return Array.isArray(g.hooks) && g.hooks.some(isCodexOwnedHandler);
|
|
24
|
+
}
|
|
25
|
+
function groupMatchesDesired(group, desired) {
|
|
26
|
+
if (typeof group !== 'object' || group === null)
|
|
27
|
+
return false;
|
|
28
|
+
const g = group;
|
|
29
|
+
if (g.matcher !== desired.matcher || !Array.isArray(g.hooks) || g.hooks.length !== 1)
|
|
30
|
+
return false;
|
|
31
|
+
const h = g.hooks[0];
|
|
32
|
+
return h.type === desired.hooks[0].type && h.command === desired.hooks[0].command && h.commandWindows === desired.hooks[0].commandWindows;
|
|
33
|
+
}
|
|
34
|
+
function removeOwnedFromEvent(content, event) {
|
|
35
|
+
let text = content;
|
|
36
|
+
while (true) {
|
|
37
|
+
const next = removeJsonArrayItem(text, ['hooks', event], isGroupPurelyOwned);
|
|
38
|
+
if (next === text)
|
|
39
|
+
break;
|
|
40
|
+
text = next;
|
|
41
|
+
}
|
|
42
|
+
const tree = parseAndValidateJson(text);
|
|
43
|
+
const eventNode = findNodeAtLocation(tree, ['hooks', event]);
|
|
44
|
+
if (!eventNode)
|
|
45
|
+
return text;
|
|
46
|
+
const groups = Array.isArray(getNodeValue(eventNode)) ? getNodeValue(eventNode) : [];
|
|
47
|
+
for (let i = 0; i < groups.length; i++) {
|
|
48
|
+
while (true) {
|
|
49
|
+
const next = removeJsonArrayItem(text, ['hooks', event, i, 'hooks'], isCodexOwnedHandler);
|
|
50
|
+
if (next === text)
|
|
51
|
+
break;
|
|
52
|
+
text = next;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return groups.length === 0 ? removeJsonProperty(text, ['hooks', event]) : text;
|
|
56
|
+
}
|
|
57
|
+
export function updateCodexHooks(content, clear, buildGroup) {
|
|
58
|
+
let text = content;
|
|
59
|
+
for (const event of CODEX_EVENTS) {
|
|
60
|
+
const desired = buildGroup(event);
|
|
61
|
+
const tree = parseAndValidateJson(text);
|
|
62
|
+
const eventNode = findNodeAtLocation(tree, ['hooks', event]);
|
|
63
|
+
if (!eventNode) {
|
|
64
|
+
if (!clear)
|
|
65
|
+
text = setJsonProperty(text, ['hooks', event], [desired]);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const groups = Array.isArray(getNodeValue(eventNode)) ? getNodeValue(eventNode) : [];
|
|
69
|
+
const ownedGroups = groups.filter(groupHasOwnedHandler);
|
|
70
|
+
if (!clear && ownedGroups.length === 1 && groupMatchesDesired(ownedGroups[0], desired)) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
text = removeOwnedFromEvent(text, event);
|
|
74
|
+
if (!clear) {
|
|
75
|
+
text = appendJsonArrayItem(text, ['hooks', event], desired);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return removeOwnedFromOtherEvents(text, CODEX_EVENTS, isCodexOwnedHandler);
|
|
79
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AdapterPlan } from '../../../core/contracts/adapter.js';
|
|
2
|
+
import type { InstallationManifest } from '../../../core/contracts/manifest.js';
|
|
3
|
+
export type ScalarDefaults = Readonly<Record<string, string | number | boolean>>;
|
|
4
|
+
export type OriginTarget = {
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly manifest?: InstallationManifest | null | undefined;
|
|
7
|
+
readonly defaults?: ScalarDefaults;
|
|
8
|
+
};
|
|
9
|
+
export declare function attachConfigOrigin(plan: AdapterPlan, target: OriginTarget): Promise<AdapterPlan>;
|
|
10
|
+
export declare function applyConfigOrigin(plan: AdapterPlan, target: OriginTarget): AdapterPlan;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { findNodeAtLocation, getNodeValue, parseTree } from 'jsonc-parser';
|
|
3
|
+
import { parseAndValidateJson, removeJsonProperty } from '../../storage/json-document-editor.js';
|
|
4
|
+
function topLevelKeys(text) {
|
|
5
|
+
const root = parseTree(text, [], { disallowComments: false });
|
|
6
|
+
if (root?.type !== 'object')
|
|
7
|
+
return [];
|
|
8
|
+
return (root.children ?? []).map((property) => String(property.children?.[0]?.value));
|
|
9
|
+
}
|
|
10
|
+
function isEmptyContainer(value) {
|
|
11
|
+
if (Array.isArray(value))
|
|
12
|
+
return value.length === 0;
|
|
13
|
+
return typeof value === 'object' && value !== null && Object.keys(value).length === 0;
|
|
14
|
+
}
|
|
15
|
+
function removeAddedKeys(text, origin, defaults) {
|
|
16
|
+
return origin.addedKeys.reduce((current, key) => {
|
|
17
|
+
const node = findNodeAtLocation(parseAndValidateJson(current), [key]);
|
|
18
|
+
if (!node)
|
|
19
|
+
return current;
|
|
20
|
+
const value = getNodeValue(node);
|
|
21
|
+
return isEmptyContainer(value) || value === defaults[key] ? removeJsonProperty(current, [key]) : current;
|
|
22
|
+
}, text);
|
|
23
|
+
}
|
|
24
|
+
function restoreChange(change, origin, defaults) {
|
|
25
|
+
if (change.path !== origin.path || change.kind !== 'update' || change.content === null)
|
|
26
|
+
return change;
|
|
27
|
+
const content = removeAddedKeys(change.content, origin, defaults);
|
|
28
|
+
if (origin.created && /^\s*\{\s*\}\s*$/.test(content))
|
|
29
|
+
return { ...change, kind: 'delete', content: null, preview: { summary: `Delete ${origin.path}, created by init` } };
|
|
30
|
+
return { ...change, content };
|
|
31
|
+
}
|
|
32
|
+
function recordConfigOrigin(target, original, installed) {
|
|
33
|
+
const path = target.path;
|
|
34
|
+
const recorded = target.manifest?.configOrigins?.find((origin) => origin.path === path);
|
|
35
|
+
if (recorded)
|
|
36
|
+
return recorded;
|
|
37
|
+
const before = new Set(original === null ? [] : topLevelKeys(original));
|
|
38
|
+
return { path, created: original === null, addedKeys: topLevelKeys(installed).filter((key) => !before.has(key)) };
|
|
39
|
+
}
|
|
40
|
+
export async function attachConfigOrigin(plan, target) {
|
|
41
|
+
const change = plan.changes.find((item) => item.path === target.path);
|
|
42
|
+
if (!change || change.content === null)
|
|
43
|
+
return plan;
|
|
44
|
+
const original = await readFile(change.realPath, 'utf8').catch(() => null);
|
|
45
|
+
return { ...plan, configOrigins: [recordConfigOrigin(target, original, change.content)] };
|
|
46
|
+
}
|
|
47
|
+
export function applyConfigOrigin(plan, target) {
|
|
48
|
+
const origin = target.manifest?.configOrigins?.find((item) => item.path === target.path);
|
|
49
|
+
if (!origin)
|
|
50
|
+
return plan;
|
|
51
|
+
return { ...plan, changes: plan.changes.map((change) => restoreChange(change, origin, target.defaults ?? {})) };
|
|
52
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { findNodeAtLocation, getNodeValue } from 'jsonc-parser';
|
|
2
|
+
import { removeOwnedFromOtherEvents } from './hook-event-cleanup.js';
|
|
3
|
+
import { appendJsonArrayItem, parseAndValidateJson, removeJsonArrayItem, removeJsonProperty, setJsonProperty } from '../../storage/json-document-editor.js';
|
|
4
|
+
export const CURSOR_HOOK_FILE = '.cursor/hooks/context-brake.mjs';
|
|
5
|
+
const CURSOR_EVENTS = ['postToolUse', 'sessionStart', 'preCompact'];
|
|
6
|
+
const CURSOR_DESIRED = {
|
|
7
|
+
postToolUse: { command: `node ${CURSOR_HOOK_FILE} postToolUse` },
|
|
8
|
+
sessionStart: { command: `node ${CURSOR_HOOK_FILE} sessionStart` },
|
|
9
|
+
preCompact: { command: `node ${CURSOR_HOOK_FILE} preCompact` },
|
|
10
|
+
};
|
|
11
|
+
export function isCursorOwned(entry) {
|
|
12
|
+
if (typeof entry !== 'object' || entry === null)
|
|
13
|
+
return false;
|
|
14
|
+
const cmd = entry.command;
|
|
15
|
+
return typeof cmd === 'string' && cmd.includes(CURSOR_HOOK_FILE);
|
|
16
|
+
}
|
|
17
|
+
function matchesDesired(entry, desired) {
|
|
18
|
+
if (typeof entry !== 'object' || entry === null)
|
|
19
|
+
return false;
|
|
20
|
+
return entry.command === desired.command;
|
|
21
|
+
}
|
|
22
|
+
function isEmptyEventArray(text, event) {
|
|
23
|
+
const tree = parseAndValidateJson(text);
|
|
24
|
+
const eventNode = findNodeAtLocation(tree, ['hooks', event]);
|
|
25
|
+
if (!eventNode)
|
|
26
|
+
return false;
|
|
27
|
+
const value = getNodeValue(eventNode);
|
|
28
|
+
return Array.isArray(value) && value.length === 0;
|
|
29
|
+
}
|
|
30
|
+
function updateCursorEvent(text, event, clear) {
|
|
31
|
+
const desired = CURSOR_DESIRED[event];
|
|
32
|
+
const tree = parseAndValidateJson(text);
|
|
33
|
+
const eventNode = findNodeAtLocation(tree, ['hooks', event]);
|
|
34
|
+
if (!eventNode) {
|
|
35
|
+
return clear ? text : setJsonProperty(text, ['hooks', event], [desired]);
|
|
36
|
+
}
|
|
37
|
+
const val = getNodeValue(eventNode);
|
|
38
|
+
const arr = Array.isArray(val) ? val : [];
|
|
39
|
+
const owned = arr.filter(isCursorOwned);
|
|
40
|
+
if (!clear && owned.length === 1 && matchesDesired(owned[0], desired))
|
|
41
|
+
return text;
|
|
42
|
+
let cur = text;
|
|
43
|
+
while (true) {
|
|
44
|
+
const next = removeJsonArrayItem(cur, ['hooks', event], isCursorOwned);
|
|
45
|
+
if (next === cur)
|
|
46
|
+
break;
|
|
47
|
+
cur = next;
|
|
48
|
+
}
|
|
49
|
+
if (!clear)
|
|
50
|
+
return appendJsonArrayItem(cur, ['hooks', event], desired);
|
|
51
|
+
return isEmptyEventArray(cur, event) ? removeJsonProperty(cur, ['hooks', event]) : cur;
|
|
52
|
+
}
|
|
53
|
+
export function updateCursorHooks(content, clear) {
|
|
54
|
+
let text = content;
|
|
55
|
+
const rootNode = parseAndValidateJson(text);
|
|
56
|
+
if (!clear && !findNodeAtLocation(rootNode, ['version'])) {
|
|
57
|
+
text = setJsonProperty(text, ['version'], 1);
|
|
58
|
+
}
|
|
59
|
+
for (const event of CURSOR_EVENTS) {
|
|
60
|
+
text = updateCursorEvent(text, event, clear);
|
|
61
|
+
}
|
|
62
|
+
return removeOwnedFromOtherEvents(text, CURSOR_EVENTS, isCursorOwned);
|
|
63
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DiagnosticFinding } from '../../../core/contracts/diagnostics.js';
|
|
2
|
+
import type { HarnessId } from '../../../core/contracts/harness.js';
|
|
3
|
+
export declare function createIntegrationMissingFinding(harness: HarnessId, path: string): DiagnosticFinding;
|
|
4
|
+
export declare function createAssetMissingFinding(harness: HarnessId, path: string): DiagnosticFinding;
|
|
5
|
+
export declare function createInvalidConfigFinding(harness: HarnessId, path: string, detail: string): DiagnosticFinding;
|
|
6
|
+
export declare function createLimitationFinding(harness: HarnessId, code: string, impact: string): DiagnosticFinding;
|
|
7
|
+
export declare function createCodexRootNotGitWarning(): DiagnosticFinding;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export function createIntegrationMissingFinding(harness, path) {
|
|
2
|
+
return {
|
|
3
|
+
code: 'INTEGRATION_MISSING',
|
|
4
|
+
severity: 'error',
|
|
5
|
+
scope: 'harness',
|
|
6
|
+
harness,
|
|
7
|
+
path,
|
|
8
|
+
message: `The ${harness} integration is missing from ${path}.`,
|
|
9
|
+
impact: 'ContextBrake cannot stop or annotate tool calls in this harness.',
|
|
10
|
+
remediation: `Run context-brake init --harness ${harness} --yes.`,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function createAssetMissingFinding(harness, path) {
|
|
14
|
+
return {
|
|
15
|
+
code: 'ASSET_MISSING',
|
|
16
|
+
severity: 'error',
|
|
17
|
+
scope: 'harness',
|
|
18
|
+
harness,
|
|
19
|
+
path,
|
|
20
|
+
message: `The runtime asset ${path} for ${harness} is missing.`,
|
|
21
|
+
impact: 'The harness cannot execute the ContextBrake hook or plugin.',
|
|
22
|
+
remediation: `Run context-brake init --harness ${harness} --yes.`,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function createInvalidConfigFinding(harness, path, detail) {
|
|
26
|
+
return {
|
|
27
|
+
code: 'INVALID_HARNESS_CONFIG',
|
|
28
|
+
severity: 'error',
|
|
29
|
+
scope: 'file',
|
|
30
|
+
harness,
|
|
31
|
+
path,
|
|
32
|
+
message: `Configuration file ${path} for ${harness} is invalid: ${detail}`,
|
|
33
|
+
impact: 'ContextBrake cannot safely read or modify this configuration.',
|
|
34
|
+
remediation: `Fix syntax or structure errors in ${path}.`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function createLimitationFinding(harness, code, impact) {
|
|
38
|
+
return {
|
|
39
|
+
code,
|
|
40
|
+
severity: 'warning',
|
|
41
|
+
scope: 'harness',
|
|
42
|
+
harness,
|
|
43
|
+
path: null,
|
|
44
|
+
message: `Harness ${harness} has an active limitation.`,
|
|
45
|
+
impact,
|
|
46
|
+
remediation: null,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export function createCodexRootNotGitWarning() {
|
|
50
|
+
return {
|
|
51
|
+
code: 'CODEX_ROOT_NOT_GIT_TOPLEVEL',
|
|
52
|
+
severity: 'warning',
|
|
53
|
+
scope: 'harness',
|
|
54
|
+
harness: 'codex-cli',
|
|
55
|
+
path: null,
|
|
56
|
+
message: 'The project root is not a git repository root, so Codex CLI hooks cannot locate the ContextBrake hook script.',
|
|
57
|
+
impact: 'Codex CLI reports a hook failure on every event and runs the tool call without ContextBrake.',
|
|
58
|
+
remediation: 'Run context-brake init from the git repository root, or run git init here.',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type OwnedHandlerPredicate = (handler: unknown) => boolean;
|
|
2
|
+
export declare function removeOwnedFromEvent(text: string, event: string, isOwned: OwnedHandlerPredicate): string;
|
|
3
|
+
export declare function removeOwnedFromOtherEvents(text: string, currentEvents: readonly string[], isOwned: OwnedHandlerPredicate): string;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { findNodeAtLocation, getNodeValue } from 'jsonc-parser';
|
|
2
|
+
import { parseAndValidateJson, removeJsonArrayItem, removeJsonProperty } from '../../storage/json-document-editor.js';
|
|
3
|
+
function groupHandlers(item) {
|
|
4
|
+
if (typeof item !== 'object' || item === null)
|
|
5
|
+
return null;
|
|
6
|
+
const handlers = item.hooks;
|
|
7
|
+
return Array.isArray(handlers) ? handlers : null;
|
|
8
|
+
}
|
|
9
|
+
function isRemovableItem(item, isOwned) {
|
|
10
|
+
const handlers = groupHandlers(item);
|
|
11
|
+
if (handlers === null)
|
|
12
|
+
return isOwned(item);
|
|
13
|
+
return handlers.length > 0 && handlers.every(isOwned);
|
|
14
|
+
}
|
|
15
|
+
function hasOwnedHandler(item, isOwned) {
|
|
16
|
+
const handlers = groupHandlers(item);
|
|
17
|
+
if (handlers === null)
|
|
18
|
+
return isOwned(item);
|
|
19
|
+
return handlers.some(isOwned);
|
|
20
|
+
}
|
|
21
|
+
function readEventItems(text, event) {
|
|
22
|
+
const node = findNodeAtLocation(parseAndValidateJson(text), ['hooks', event]);
|
|
23
|
+
const value = node ? getNodeValue(node) : undefined;
|
|
24
|
+
return Array.isArray(value) ? value : [];
|
|
25
|
+
}
|
|
26
|
+
function removeRepeatedly(text, remove) {
|
|
27
|
+
const next = remove(text);
|
|
28
|
+
return next === text ? text : removeRepeatedly(next, remove);
|
|
29
|
+
}
|
|
30
|
+
export function removeOwnedFromEvent(text, event, isOwned) {
|
|
31
|
+
const path = ['hooks', event];
|
|
32
|
+
const withoutGroups = removeRepeatedly(text, (current) => removeJsonArrayItem(current, path, (item) => isRemovableItem(item, isOwned)));
|
|
33
|
+
const remaining = readEventItems(withoutGroups, event).length;
|
|
34
|
+
let cleaned = withoutGroups;
|
|
35
|
+
for (let index = 0; index < remaining; index++) {
|
|
36
|
+
cleaned = removeRepeatedly(cleaned, (current) => removeJsonArrayItem(current, [...path, index, 'hooks'], isOwned));
|
|
37
|
+
}
|
|
38
|
+
return remaining === 0 ? removeJsonProperty(cleaned, path) : cleaned;
|
|
39
|
+
}
|
|
40
|
+
export function removeOwnedFromOtherEvents(text, currentEvents, isOwned) {
|
|
41
|
+
const hooksNode = findNodeAtLocation(parseAndValidateJson(text), ['hooks']);
|
|
42
|
+
const hooks = hooksNode ? getNodeValue(hooksNode) : undefined;
|
|
43
|
+
if (typeof hooks !== 'object' || hooks === null || Array.isArray(hooks))
|
|
44
|
+
return text;
|
|
45
|
+
const retired = Object.keys(hooks).filter((event) => !currentEvents.includes(event));
|
|
46
|
+
return retired.reduce((acc, event) => {
|
|
47
|
+
const isOwnedHere = readEventItems(acc, event).some((item) => hasOwnedHandler(item, isOwned));
|
|
48
|
+
return isOwnedHere ? removeOwnedFromEvent(acc, event, isOwned) : acc;
|
|
49
|
+
}, text);
|
|
50
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RestartReasonCode } from '../../../core/contracts/auto-restart.js';
|
|
2
|
+
import type { HarnessId } from '../../../core/contracts/harness.js';
|
|
3
|
+
export type RestartLogTarget = {
|
|
4
|
+
readonly root: string;
|
|
5
|
+
readonly harness: HarnessId;
|
|
6
|
+
readonly sessionId: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function recordInProcessLoaded(target: RestartLogTarget): Promise<void>;
|
|
9
|
+
export declare function recordInProcessDecision(target: RestartLogTarget, code: RestartReasonCode, at: Date): Promise<void>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { RESTART_LOG_RELATIVE_DIR, RESTART_LOG_VERSION, restartLogSchema, UNKNOWN_HARNESS_VERSION } from '../../../core/contracts/restart-log.js';
|
|
4
|
+
import { appendLogRecord, buildLogRecord } from '../../../core/services/auto-restart-notices.js';
|
|
5
|
+
import { ensureRuntimeDirectory, isMissingFileError } from '../../runtime/runtime-paths.js';
|
|
6
|
+
import { RESTART_COMPONENT_VERSION } from './in-process-restart-state.js';
|
|
7
|
+
const LINE_END = '\n';
|
|
8
|
+
function logPath(target) {
|
|
9
|
+
return join(target.root, RESTART_LOG_RELATIVE_DIR, target.harness, `${target.sessionId}.json`);
|
|
10
|
+
}
|
|
11
|
+
function emptyLog(harness) {
|
|
12
|
+
return { v: RESTART_LOG_VERSION, harness, componentVersion: RESTART_COMPONENT_VERSION, harnessVersion: UNKNOWN_HARNESS_VERSION, records: [] };
|
|
13
|
+
}
|
|
14
|
+
async function readLog(target) {
|
|
15
|
+
try {
|
|
16
|
+
const parsed = restartLogSchema.safeParse(JSON.parse(await readFile(logPath(target), 'utf8')));
|
|
17
|
+
return parsed.success ? parsed.data : emptyLog(target.harness);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (isMissingFileError(error) || error instanceof SyntaxError)
|
|
21
|
+
return emptyLog(target.harness);
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function writeLog(target, log) {
|
|
26
|
+
await ensureRuntimeDirectory(target.root);
|
|
27
|
+
await mkdir(join(target.root, RESTART_LOG_RELATIVE_DIR, target.harness), { recursive: true });
|
|
28
|
+
await writeFile(logPath(target), JSON.stringify({ ...log, componentVersion: RESTART_COMPONENT_VERSION }, null, 2) + LINE_END, 'utf8');
|
|
29
|
+
}
|
|
30
|
+
export async function recordInProcessLoaded(target) {
|
|
31
|
+
await writeLog(target, await readLog(target));
|
|
32
|
+
}
|
|
33
|
+
export async function recordInProcessDecision(target, code, at) {
|
|
34
|
+
const log = await readLog(target);
|
|
35
|
+
await writeLog(target, { ...log, records: [...appendLogRecord(log.records, buildLogRecord(code, at.toISOString()))] });
|
|
36
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type RestartGuardStore, type StandDownFacts } from '../../../core/contracts/restart-host.js';
|
|
2
|
+
import type { RestartSettings } from '../../../core/services/restart-flow.js';
|
|
3
|
+
export declare const RESTART_COMMAND = "context-brake-restart";
|
|
4
|
+
export declare const RESTART_COMPONENT_VERSION = "1.0.0";
|
|
5
|
+
export declare function memoryGuardStore(root: string): RestartGuardStore;
|
|
6
|
+
export declare function startTurn(root: string, at: number): void;
|
|
7
|
+
export declare function countToolCall(root: string): void;
|
|
8
|
+
export declare function turnStartedAt(root: string): number | undefined;
|
|
9
|
+
export declare function takeToolCalls(root: string): number;
|
|
10
|
+
export declare function inProcessStandDown(interactive: boolean): StandDownFacts;
|
|
11
|
+
export declare function readRestartSettings(root: string): Promise<RestartSettings | undefined>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { configurationSchema } from '../../../core/contracts/configuration.js';
|
|
4
|
+
import { IDLE_GUARD_STATE } from '../../../core/contracts/restart-host.js';
|
|
5
|
+
import { restartMode } from '../../../core/services/restart-mode.js';
|
|
6
|
+
import { isMissingFileError } from '../../runtime/runtime-paths.js';
|
|
7
|
+
export const RESTART_COMMAND = 'context-brake-restart';
|
|
8
|
+
export const RESTART_COMPONENT_VERSION = '1.0.0';
|
|
9
|
+
const CONFIG_FILE = 'context-brake.config.json';
|
|
10
|
+
const SWITCHED_OFF = '0';
|
|
11
|
+
const guards = new Map();
|
|
12
|
+
const turnStarts = new Map();
|
|
13
|
+
const turnToolCalls = new Map();
|
|
14
|
+
export function memoryGuardStore(root) {
|
|
15
|
+
return {
|
|
16
|
+
read: async () => guards.get(root) ?? IDLE_GUARD_STATE,
|
|
17
|
+
write: async (state) => { guards.set(root, state); },
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function startTurn(root, at) {
|
|
21
|
+
turnStarts.set(root, at);
|
|
22
|
+
turnToolCalls.set(root, 0);
|
|
23
|
+
}
|
|
24
|
+
export function countToolCall(root) {
|
|
25
|
+
turnToolCalls.set(root, (turnToolCalls.get(root) ?? 0) + 1);
|
|
26
|
+
}
|
|
27
|
+
export function turnStartedAt(root) {
|
|
28
|
+
return turnStarts.get(root);
|
|
29
|
+
}
|
|
30
|
+
export function takeToolCalls(root) {
|
|
31
|
+
const calls = turnToolCalls.get(root) ?? 0;
|
|
32
|
+
turnToolCalls.set(root, 0);
|
|
33
|
+
return calls;
|
|
34
|
+
}
|
|
35
|
+
export function inProcessStandDown(interactive) {
|
|
36
|
+
return { disabledByEnv: process.env['CONTEXT_BRAKE_AUTO_RESTART'] === SWITCHED_OFF, interactive };
|
|
37
|
+
}
|
|
38
|
+
export async function readRestartSettings(root) {
|
|
39
|
+
try {
|
|
40
|
+
const parsed = configurationSchema.safeParse(JSON.parse(await readFile(join(root, CONFIG_FILE), 'utf8')));
|
|
41
|
+
if (!parsed.success || parsed.data.autoRestart === undefined)
|
|
42
|
+
return undefined;
|
|
43
|
+
return { maxConsecutive: parsed.data.autoRestart.maxConsecutiveRestarts, mode: restartMode(parsed.data) };
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (isMissingFileError(error) || error instanceof SyntaxError)
|
|
47
|
+
return undefined;
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { HarnessId } from '../../../core/contracts/harness.js';
|
|
2
|
+
export type RestartSessionContext = {
|
|
3
|
+
readonly cwd?: string | undefined;
|
|
4
|
+
readonly sessionManager?: {
|
|
5
|
+
readonly getSessionId?: () => string;
|
|
6
|
+
} | undefined;
|
|
7
|
+
readonly ui?: {
|
|
8
|
+
readonly notify?: (message: string, level?: string) => void;
|
|
9
|
+
} | undefined;
|
|
10
|
+
};
|
|
11
|
+
export declare function sessionIdOf(context: RestartSessionContext): string;
|
|
12
|
+
export declare function recordRestartLoaded(context: RestartSessionContext, harness: HarnessId): Promise<void>;
|
|
13
|
+
export declare function reportFailures(context: RestartSessionContext, step: () => Promise<void>): Promise<void>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { renderRestartNotice } from '../../../core/services/auto-restart-notices.js';
|
|
2
|
+
import { recordInProcessLoaded } from './in-process-restart-log.js';
|
|
3
|
+
import { readRestartSettings } from './in-process-restart-state.js';
|
|
4
|
+
import { textValue } from './runtime-support.js';
|
|
5
|
+
export function sessionIdOf(context) {
|
|
6
|
+
return context.sessionManager?.getSessionId?.() ?? 'unknown';
|
|
7
|
+
}
|
|
8
|
+
export async function recordRestartLoaded(context, harness) {
|
|
9
|
+
const root = textValue(context.cwd);
|
|
10
|
+
if (root !== null && (await readRestartSettings(root)) !== undefined)
|
|
11
|
+
await recordInProcessLoaded({ root, harness, sessionId: sessionIdOf(context) });
|
|
12
|
+
}
|
|
13
|
+
export function reportFailures(context, step) {
|
|
14
|
+
return step().catch(() => context.ui?.notify?.(renderRestartNotice('ERROR_INTERNAL') ?? '', 'info'));
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RuntimeDecision, RuntimeDescriptor, RuntimeEvent } from '../../../core/contracts/runtime.js';
|
|
2
|
+
import type { Clock } from '../../../core/contracts/session-ledger.js';
|
|
3
|
+
import type { RuntimeInput } from '../../../core/services/brake-engine.js';
|
|
4
|
+
import { type InProcessRuntime } from '../../runtime/in-process-host.js';
|
|
5
|
+
export type InProcessRuntimeResolver = (projectRoot: string) => Promise<InProcessRuntime>;
|
|
6
|
+
export type MeasuredUsageInput = {
|
|
7
|
+
readonly tokens: number | null;
|
|
8
|
+
readonly contextWindow: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function createRuntimeResolver(descriptor: RuntimeDescriptor, clock?: Clock): InProcessRuntimeResolver;
|
|
11
|
+
export type InProcessEventInput = {
|
|
12
|
+
readonly resolver: InProcessRuntimeResolver;
|
|
13
|
+
readonly projectRoot: string | null;
|
|
14
|
+
readonly event: RuntimeEvent;
|
|
15
|
+
readonly engineInput?: RuntimeInput | undefined;
|
|
16
|
+
};
|
|
17
|
+
export declare function runInProcessEvent(input: InProcessEventInput): Promise<RuntimeDecision>;
|
|
18
|
+
export declare function measuredUsageFrom(value: unknown): MeasuredUsageInput | undefined;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { failureDetail, failureErrorCode, resolveFailure } from '../../../core/services/failure-policy.js';
|
|
2
|
+
import { createInProcessRuntime } from '../../runtime/in-process-host.js';
|
|
3
|
+
import { createRuntimePorts, loadRuntimeConfiguration, systemClock } from '../../runtime/runtime-composition.js';
|
|
4
|
+
import { asRecord } from './runtime-support.js';
|
|
5
|
+
export function createRuntimeResolver(descriptor, clock = systemClock) {
|
|
6
|
+
let currentRoot = null;
|
|
7
|
+
let current = null;
|
|
8
|
+
return (projectRoot) => {
|
|
9
|
+
if (current === null || currentRoot !== projectRoot) {
|
|
10
|
+
currentRoot = projectRoot;
|
|
11
|
+
current = loadRuntimeConfiguration(projectRoot)
|
|
12
|
+
.then((config) => createInProcessRuntime({ projectRoot, descriptor, config, clock }))
|
|
13
|
+
.catch((error) => { current = null; throw error; });
|
|
14
|
+
}
|
|
15
|
+
return current;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export async function runInProcessEvent(input) {
|
|
19
|
+
if (input.projectRoot === null)
|
|
20
|
+
return { kind: 'neutral' };
|
|
21
|
+
try {
|
|
22
|
+
const runtime = await input.resolver(input.projectRoot);
|
|
23
|
+
return await runtime.handle(input.event, input.engineInput);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
return await resolveInProcessFailure(input.projectRoot, input.event, error);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function measuredUsageFrom(value) {
|
|
30
|
+
const record = asRecord(value);
|
|
31
|
+
const contextWindow = record?.['contextWindow'];
|
|
32
|
+
if (typeof contextWindow !== 'number' || contextWindow <= 0)
|
|
33
|
+
return undefined;
|
|
34
|
+
const tokens = record?.['tokens'];
|
|
35
|
+
return { tokens: typeof tokens === 'number' ? tokens : null, contextWindow };
|
|
36
|
+
}
|
|
37
|
+
async function resolveInProcessFailure(projectRoot, event, error) {
|
|
38
|
+
const ports = createRuntimePorts({ projectRoot, config: null, clock: systemClock });
|
|
39
|
+
return await resolveFailure({ event, code: failureErrorCode(error), detail: failureDetail(error), config: null, descriptor: null, ledger: ports.ledger, errors: ports.errors });
|
|
40
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type LineReader<T> = (line: string) => T | null;
|
|
2
|
+
export declare class TranscriptUnreadableError extends Error {
|
|
3
|
+
constructor(options?: ErrorOptions);
|
|
4
|
+
}
|
|
5
|
+
export declare function readLatestLine<T>(path: string | undefined, readLine: LineReader<T>): Promise<T | null>;
|
|
6
|
+
export declare function parseJsonLine(line: string): unknown;
|