@loucompanion/forge-bridge 0.1.3-dev.f66395c3ac21 → 0.1.4-dev.0098fdb4e213
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/README.md +306 -1
- package/dist/bridge/bridge-chat-provider-command.d.ts +19 -0
- package/dist/bridge/bridge-chat-provider-command.js +132 -0
- package/dist/bridge/bridge-chat.types.d.ts +121 -0
- package/dist/bridge/bridge-chat.types.js +416 -0
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +11 -0
- package/dist/bridge/bridge-state-io.js +50 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.base.d.ts +18 -1
- package/dist/bridge/bridge.service.d.ts +216 -4
- package/dist/bridge/bridge.service.js +2574 -90
- package/dist/bridge/bridge.types.d.ts +245 -2
- package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
- package/dist/bridge/dispatch-result-outbox.js +87 -0
- package/dist/bridge/dispatch-result-worker.d.ts +2 -0
- package/dist/bridge/dispatch-result-worker.js +122 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/internals.d.ts +2 -0
- package/dist/bridge/internals.js +1 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/readiness-result-outbox.d.ts +25 -0
- package/dist/bridge/readiness-result-outbox.js +74 -0
- package/dist/bridge/readiness-result-worker.d.ts +2 -0
- package/dist/bridge/readiness-result-worker.js +121 -0
- package/dist/bridge/runner-host-capabilities.d.ts +20 -0
- package/dist/bridge/runner-host-capabilities.js +110 -0
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +33 -2
- package/dist/cleanup/cleanup.service.js +477 -3
- package/dist/cleanup/cleanup.types.d.ts +16 -0
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
- package/dist/cleanup/host-runtime-ledger.js +130 -0
- package/dist/cleanup/index.d.ts +1 -1
- package/dist/cleanup/index.js +1 -1
- package/dist/cleanup/internals.d.ts +2 -2
- package/dist/cleanup/internals.js +1 -1
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.d.ts +2 -0
- package/dist/cli/cli.help.js +279 -0
- package/dist/cli/cli.service.d.ts +69 -12
- package/dist/cli/cli.service.js +557 -382
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +13 -0
- package/dist/cli/local-config.js +82 -6
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +41 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +474 -0
- package/dist/runtime/attempt-database-broker.d.ts +89 -0
- package/dist/runtime/attempt-database-broker.js +390 -0
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +18 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +140 -0
- package/dist/runtime/attempt-path-operation.d.ts +21 -0
- package/dist/runtime/attempt-path-operation.js +94 -0
- package/dist/runtime/attempt-private-directory.d.ts +6 -0
- package/dist/runtime/attempt-private-directory.js +54 -0
- package/dist/runtime/attempt-process-supervisor-registry.d.ts +20 -0
- package/dist/runtime/attempt-process-supervisor-registry.js +64 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +121 -0
- package/dist/runtime/attempt-process-supervisor.js +471 -0
- package/dist/runtime/canonical-source-file.d.ts +3 -0
- package/dist/runtime/canonical-source-file.js +54 -0
- package/dist/runtime/docker-engine-probe.d.ts +95 -0
- package/dist/runtime/docker-engine-probe.js +340 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/generated-output-reset.d.ts +20 -0
- package/dist/runtime/generated-output-reset.js +157 -0
- package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
- package/dist/runtime/host-database-capability-boundary.js +63 -0
- package/dist/runtime/host-diagnostics.d.ts +11 -0
- package/dist/runtime/host-diagnostics.js +192 -0
- package/dist/runtime/host-execution-root.d.ts +4 -0
- package/dist/runtime/host-execution-root.js +39 -0
- package/dist/runtime/host-facts.d.ts +36 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-listener-inspector.d.ts +51 -0
- package/dist/runtime/host-listener-inspector.js +385 -0
- package/dist/runtime/host-load-admission.d.ts +67 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +27 -0
- package/dist/runtime/host-load-child-environment.js +76 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +52 -0
- package/dist/runtime/host-load-governor-config.js +83 -0
- package/dist/runtime/host-load-governor.d.ts +186 -0
- package/dist/runtime/host-load-governor.js +632 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +187 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +80 -0
- package/dist/runtime/host-load-sampler.d.ts +156 -0
- package/dist/runtime/host-load-sampler.js +298 -0
- package/dist/runtime/host-load-step-class.d.ts +70 -0
- package/dist/runtime/host-load-step-class.js +161 -0
- package/dist/runtime/host-load-step-reaper.d.ts +27 -0
- package/dist/runtime/host-load-step-reaper.js +95 -0
- package/dist/runtime/host-load-step-run.d.ts +73 -0
- package/dist/runtime/host-load-step-run.js +102 -0
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +200 -0
- package/dist/runtime/host-load-token-ledger.js +453 -0
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-port-broker.d.ts +76 -0
- package/dist/runtime/host-port-broker.js +333 -0
- package/dist/runtime/host-pressure-stall.d.ts +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +74 -0
- package/dist/runtime/host-runtime-contract.js +846 -0
- package/dist/runtime/host-runtime-lease.d.ts +287 -0
- package/dist/runtime/host-runtime-lease.js +2763 -0
- package/dist/runtime/host-runtime-promotion.d.ts +55 -0
- package/dist/runtime/host-runtime-promotion.js +254 -0
- package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
- package/dist/runtime/host-runtime-requirements-check.js +29 -0
- package/dist/runtime/host-runtime-requirements.d.ts +36 -0
- package/dist/runtime/host-runtime-requirements.js +117 -0
- package/dist/runtime/managed-command-teardown.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +596 -0
- package/dist/runtime/memory-capacity.d.ts +70 -0
- package/dist/runtime/memory-capacity.js +123 -0
- package/dist/runtime/native-test-postgres-fallback.d.ts +69 -0
- package/dist/runtime/native-test-postgres-fallback.js +143 -0
- package/dist/runtime/node-host-runtime-adapter.d.ts +54 -0
- package/dist/runtime/node-host-runtime-adapter.js +286 -0
- package/dist/runtime/pinned-directory-process.d.ts +9 -0
- package/dist/runtime/pinned-directory-process.js +61 -0
- package/dist/runtime/pinned-source-directory.d.ts +17 -0
- package/dist/runtime/pinned-source-directory.js +94 -0
- package/dist/runtime/playwright-browser-cache.d.ts +39 -0
- package/dist/runtime/playwright-browser-cache.js +227 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +39 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +274 -0
- package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
- package/dist/runtime/prepared-runtime-identity.js +218 -0
- package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
- package/dist/runtime/prepared-runtime-readiness.js +285 -0
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/runtime-isolation-lease.d.ts +67 -0
- package/dist/runtime/runtime-isolation-lease.js +161 -0
- package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
- package/dist/runtime/workspace-resource-estimator.js +174 -0
- package/dist/sandbox/command-runner.d.ts +4 -0
- package/dist/sandbox/command-runner.js +47 -0
- package/dist/sandbox/contract.d.ts +5 -0
- package/dist/sandbox/contract.js +276 -0
- package/dist/sandbox/event-budget.d.ts +11 -0
- package/dist/sandbox/event-budget.js +27 -0
- package/dist/sandbox/host-capacity-broker.d.ts +115 -0
- package/dist/sandbox/host-capacity-broker.js +336 -0
- package/dist/sandbox/image-policy.d.ts +35 -0
- package/dist/sandbox/image-policy.js +247 -0
- package/dist/sandbox/index.d.ts +5 -0
- package/dist/sandbox/index.js +5 -0
- package/dist/sandbox/lease-watchdog.d.ts +18 -0
- package/dist/sandbox/lease-watchdog.js +67 -0
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +36 -0
- package/dist/sandbox/preflight.d.ts +84 -0
- package/dist/sandbox/preflight.js +521 -0
- package/dist/sandbox/process.d.ts +20 -0
- package/dist/sandbox/process.js +209 -0
- package/dist/sandbox/provider-auth/codex.d.ts +26 -0
- package/dist/sandbox/provider-auth/codex.js +212 -0
- package/dist/sandbox/repository-lock.d.ts +6 -0
- package/dist/sandbox/repository-lock.js +129 -0
- package/dist/sandbox/runtime.d.ts +311 -0
- package/dist/sandbox/runtime.js +2407 -0
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/sandbox/sandbox.types.d.ts +93 -0
- package/dist/sandbox/sandbox.types.js +1 -0
- package/dist/sandbox/smoke.d.ts +76 -0
- package/dist/sandbox/smoke.js +380 -0
- package/dist/sandbox/worker-supervisor.d.ts +13 -0
- package/dist/sandbox/worker-supervisor.js +36 -0
- package/dist/sandbox/worker.d.ts +1 -0
- package/dist/sandbox/worker.js +225 -0
- package/dist/sandbox/workspace.service.d.ts +13 -0
- package/dist/sandbox/workspace.service.js +74 -0
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +48 -0
- package/dist/session/managed-attempt-tools.js +1299 -0
- package/dist/session/managed-build-coordinator.d.ts +5 -0
- package/dist/session/managed-build-coordinator.js +109 -0
- package/dist/session/managed-build-receipt.d.ts +26 -0
- package/dist/session/managed-build-receipt.js +342 -0
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/managed-verification-timeouts.d.ts +8 -0
- package/dist/session/managed-verification-timeouts.js +17 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +34 -0
- package/dist/session/phase-completion.artifacts.js +903 -0
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +65 -42
- package/dist/session/phase-completion.helpers.d.ts +117 -0
- package/dist/session/phase-completion.helpers.js +708 -0
- package/dist/session/phase-completion.js +130 -3007
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.prompts.d.ts +14 -0
- package/dist/session/phase-completion.prompts.js +238 -0
- package/dist/session/phase-completion.runtime.d.ts +43 -0
- package/dist/session/phase-completion.runtime.js +721 -0
- package/dist/session/phase-completion.schema-parts.d.ts +19 -0
- package/dist/session/phase-completion.schema-parts.js +188 -0
- package/dist/session/phase-completion.schemas.d.ts +3 -0
- package/dist/session/phase-completion.schemas.js +836 -0
- package/dist/session/phase-completion.validation.d.ts +37 -0
- package/dist/session/phase-completion.validation.js +874 -0
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-process.d.ts +23 -0
- package/dist/session/pre-publication-process.js +109 -0
- package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
- package/dist/session/pre-publication-skipped-tests.js +109 -0
- package/dist/session/pre-publication-step-execution.d.ts +12 -0
- package/dist/session/pre-publication-step-execution.js +50 -0
- package/dist/session/pre-publication-validation.d.ts +91 -0
- package/dist/session/pre-publication-validation.js +670 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
- package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
- package/dist/session/provider-cli/ci-repair-readiness.d.ts +16 -0
- package/dist/session/provider-cli/ci-repair-readiness.js +110 -0
- package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
- package/dist/session/provider-cli/claude-background-work.js +181 -0
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +276 -0
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +96 -0
- package/dist/session/provider-cli/provider-cli.artifacts.js +818 -0
- package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.deterministic-payloads.d.ts +12 -0
- package/dist/session/provider-cli/provider-cli.deterministic-payloads.js +279 -0
- package/dist/session/provider-cli/provider-cli.deterministic.d.ts +14 -0
- package/dist/session/provider-cli/provider-cli.deterministic.js +407 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +114 -0
- package/dist/session/provider-cli/provider-cli.process.js +757 -0
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +62 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +770 -0
- package/dist/session/provider-cli/provider-cli.qa-sidecars.d.ts +11 -0
- package/dist/session/provider-cli/provider-cli.qa-sidecars.js +66 -0
- package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
- package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +30 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +120 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +53 -53
- package/dist/session/provider-cli/provider-cli.service.js +1299 -2523
- package/dist/session/provider-cli/provider-cli.types.d.ts +38 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +40 -0
- package/dist/session/provider-cli/provider-output-state.js +832 -0
- package/dist/session/provider-cli/provider-usage.d.ts +9 -1
- package/dist/session/provider-cli/provider-usage.js +28 -5
- package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
- package/dist/session/sandbox-host-capacity-gate.js +257 -0
- package/dist/session/session-redaction.d.ts +3 -0
- package/dist/session/session-redaction.js +298 -0
- package/dist/session/session.base.d.ts +14 -1
- package/dist/session/session.service.d.ts +17 -2
- package/dist/session/session.service.js +708 -60
- package/dist/session/session.types.d.ts +327 -3
- package/dist/session/session.types.js +951 -10
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/unreferenced-exports.d.ts +12 -0
- package/dist/session/unreferenced-exports.js +59 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/format/format-bytes.d.ts +1 -0
- package/dist/shared/format/format-bytes.js +9 -0
- package/dist/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/git/git.js +2 -1
- package/dist/shared/path/path.d.ts +1 -0
- package/dist/shared/path/path.js +21 -1
- package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
- package/dist/shared/process/dotnet-toolchain.js +307 -0
- package/dist/shared/process/host-process-recovery.d.ts +23 -0
- package/dist/shared/process/host-process-recovery.js +99 -0
- package/dist/shared/process/host-process-supervisor.d.ts +72 -0
- package/dist/shared/process/host-process-supervisor.js +383 -0
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +70 -0
- package/dist/shared/process/process.js +224 -16
- package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
- package/dist/shared/process/windows-app-execution-alias.js +45 -0
- package/dist/shared/process/windows-launch.d.ts +26 -0
- package/dist/shared/process/windows-launch.js +109 -0
- package/dist/shared/provider-capabilities.d.ts +4 -0
- package/dist/shared/provider-capabilities.js +95 -0
- package/dist/shared/redaction/redaction.d.ts +1 -0
- package/dist/shared/redaction/redaction.js +47 -4
- package/dist/shared/time/monotonic.d.ts +1 -0
- package/dist/shared/time/monotonic.js +8 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/artifact-injector.d.ts +3 -2
- package/dist/worktree/artifact-injector.js +82 -10
- package/dist/worktree/dependency-warmer.d.ts +78 -1
- package/dist/worktree/dependency-warmer.js +731 -13
- package/dist/worktree/index.d.ts +2 -1
- package/dist/worktree/index.js +1 -0
- package/dist/worktree/prior-phase-artifact-hydrator.d.ts +2 -0
- package/dist/worktree/prior-phase-artifact-hydrator.js +136 -0
- package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
- package/dist/worktree/story-qa-reference-hydrator.js +253 -0
- package/dist/worktree/wip-git.d.ts +33 -0
- package/dist/worktree/wip-git.js +122 -0
- package/dist/worktree/wip-refs.d.ts +62 -0
- package/dist/worktree/wip-refs.js +119 -0
- package/dist/worktree/wip-restore.d.ts +38 -0
- package/dist/worktree/wip-restore.js +190 -0
- package/dist/worktree/wip-snapshot.d.ts +50 -0
- package/dist/worktree/wip-snapshot.js +268 -0
- package/dist/worktree/worktree-paths.d.ts +4 -0
- package/dist/worktree/worktree-paths.js +30 -0
- package/dist/worktree/worktree-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +98 -0
- package/dist/worktree/worktree-wip.d.ts +49 -0
- package/dist/worktree/worktree-wip.js +182 -0
- package/dist/worktree/worktree.base.d.ts +10 -1
- package/dist/worktree/worktree.service.d.ts +30 -4
- package/dist/worktree/worktree.service.js +379 -54
- package/dist/worktree/worktree.types.d.ts +38 -1
- package/package.json +12 -7
- package/runtime/windows-job-supervisor.ps1 +722 -0
- package/runtime/windows-listener-owner.ps1 +33 -0
|
@@ -0,0 +1,832 @@
|
|
|
1
|
+
import { addUsage, emptyUsage, readUsageNumber } from "./provider-usage.js";
|
|
2
|
+
export function messageFromError(error) {
|
|
3
|
+
return error instanceof Error ? error.message : String(error);
|
|
4
|
+
}
|
|
5
|
+
/** Keeps the end of `value`, where a process's failure detail is, within `maximumLength`. */
|
|
6
|
+
export function clipTail(value, maximumLength) {
|
|
7
|
+
if (value.length <= maximumLength)
|
|
8
|
+
return value;
|
|
9
|
+
return `...${value.slice(-(maximumLength - 3))}`;
|
|
10
|
+
}
|
|
11
|
+
export function clip(value, maxLength) {
|
|
12
|
+
if (maxLength <= 0) {
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
if (value.length <= maxLength) {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
const ellipsis = "...";
|
|
19
|
+
if (maxLength <= ellipsis.length) {
|
|
20
|
+
return ellipsis.slice(0, maxLength);
|
|
21
|
+
}
|
|
22
|
+
return `${value.slice(0, maxLength - ellipsis.length)}${ellipsis}`;
|
|
23
|
+
}
|
|
24
|
+
export function createProviderOutputState(provider) {
|
|
25
|
+
const normalized = provider.trim().toLowerCase();
|
|
26
|
+
if (normalized === "cursor") {
|
|
27
|
+
return new CursorStreamJsonState();
|
|
28
|
+
}
|
|
29
|
+
if (normalized === "claude") {
|
|
30
|
+
return new ClaudeStreamJsonState();
|
|
31
|
+
}
|
|
32
|
+
return new CodexJsonState();
|
|
33
|
+
}
|
|
34
|
+
class CursorStreamJsonState {
|
|
35
|
+
sessionId = null;
|
|
36
|
+
finalMessage = null;
|
|
37
|
+
emittedSession = false;
|
|
38
|
+
accumulatedUsage = null;
|
|
39
|
+
activeToolCallCount = 0;
|
|
40
|
+
get sessionLabel() {
|
|
41
|
+
return this.sessionId ? `session ${this.sessionId}` : null;
|
|
42
|
+
}
|
|
43
|
+
get providerThreadId() {
|
|
44
|
+
return this.sessionId;
|
|
45
|
+
}
|
|
46
|
+
get usage() {
|
|
47
|
+
return this.accumulatedUsage;
|
|
48
|
+
}
|
|
49
|
+
get hasActiveToolCall() {
|
|
50
|
+
return this.activeToolCallCount > 0;
|
|
51
|
+
}
|
|
52
|
+
resetActiveToolCalls() {
|
|
53
|
+
this.activeToolCallCount = 0;
|
|
54
|
+
}
|
|
55
|
+
consume(line) {
|
|
56
|
+
const event = parseJsonLine(line);
|
|
57
|
+
if (!event) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
const type = stringField(event, "type");
|
|
61
|
+
if (type === "system" && stringField(event, "subtype") === "init") {
|
|
62
|
+
this.sessionId = stringField(event, "session_id");
|
|
63
|
+
if (this.sessionId && !this.emittedSession) {
|
|
64
|
+
this.emittedSession = true;
|
|
65
|
+
return [{
|
|
66
|
+
role: "runner",
|
|
67
|
+
kind: "checkpoint",
|
|
68
|
+
content: `Cursor session started: ${this.sessionId}.`,
|
|
69
|
+
eventType: "provider_thread_started",
|
|
70
|
+
data: JSON.stringify({ threadId: this.sessionId })
|
|
71
|
+
}];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (type === "assistant") {
|
|
75
|
+
const text = assistantMessageText(event);
|
|
76
|
+
if (text) {
|
|
77
|
+
this.finalMessage = text;
|
|
78
|
+
return [{
|
|
79
|
+
role: "assistant",
|
|
80
|
+
kind: "message",
|
|
81
|
+
content: clip(text, 4000),
|
|
82
|
+
eventType: "provider_message"
|
|
83
|
+
}];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (type === "tool_call") {
|
|
87
|
+
const subtype = stringField(event, "subtype");
|
|
88
|
+
const toolCall = objectField(event, "tool_call");
|
|
89
|
+
if (subtype === "started") {
|
|
90
|
+
this.activeToolCallCount += 1;
|
|
91
|
+
const summary = formatCursorToolCallStarted(toolCall);
|
|
92
|
+
if (summary) {
|
|
93
|
+
return [{
|
|
94
|
+
role: "worker",
|
|
95
|
+
kind: "checkpoint",
|
|
96
|
+
content: summary,
|
|
97
|
+
eventType: "provider_tool_call"
|
|
98
|
+
}];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (subtype === "completed") {
|
|
102
|
+
this.activeToolCallCount = Math.max(0, this.activeToolCallCount - 1);
|
|
103
|
+
const completed = formatCursorToolCallCompleted(toolCall);
|
|
104
|
+
if (completed) {
|
|
105
|
+
return [{
|
|
106
|
+
role: "worker",
|
|
107
|
+
kind: completed.kind,
|
|
108
|
+
content: completed.content,
|
|
109
|
+
eventType: completed.kind === "file_edit" ? "provider_file_edit" : "provider_tool_call"
|
|
110
|
+
}];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (type === "result" && stringField(event, "subtype") === "success") {
|
|
115
|
+
const result = stringField(event, "result");
|
|
116
|
+
if (result) {
|
|
117
|
+
this.finalMessage = result;
|
|
118
|
+
}
|
|
119
|
+
this.accumulateUsage(event);
|
|
120
|
+
}
|
|
121
|
+
if (type === "error" || (type === "result" && event.is_error === true)) {
|
|
122
|
+
return [{
|
|
123
|
+
role: "runner",
|
|
124
|
+
kind: "error",
|
|
125
|
+
content: clip(line.trim(), 1000),
|
|
126
|
+
eventType: "provider_cli_error"
|
|
127
|
+
}];
|
|
128
|
+
}
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
accumulateUsage(event) {
|
|
132
|
+
const usage = objectField(event, "usage");
|
|
133
|
+
const durationMs = readUsageNumber(event, "duration_ms") || readUsageNumber(event, "duration_api_ms");
|
|
134
|
+
if (Object.keys(usage).length === 0 && durationMs === 0) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const uncachedInputTokens = readUsageNumber(usage, "inputTokens");
|
|
138
|
+
const cacheReadTokens = readUsageNumber(usage, "cacheReadTokens");
|
|
139
|
+
const cacheCreationTokens = readUsageNumber(usage, "cacheWriteTokens");
|
|
140
|
+
this.accumulatedUsage = addUsage(this.accumulatedUsage ?? emptyUsage("provider_reported"), {
|
|
141
|
+
inputTokens: uncachedInputTokens + cacheReadTokens + cacheCreationTokens,
|
|
142
|
+
uncachedInputTokens,
|
|
143
|
+
outputTokens: readUsageNumber(usage, "outputTokens"),
|
|
144
|
+
cacheReadTokens,
|
|
145
|
+
cacheCreationTokens,
|
|
146
|
+
providerDurationMs: durationMs > 0 ? durationMs : null,
|
|
147
|
+
source: "provider_reported",
|
|
148
|
+
inputTokenSemantics: "excludes_cache_tokens",
|
|
149
|
+
rawUsage: [{ provider: "cursor", usage }]
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function formatCursorToolCallStarted(toolCall) {
|
|
154
|
+
const readArgs = objectField(objectField(toolCall, "readToolCall"), "args");
|
|
155
|
+
const readPath = stringField(readArgs, "path");
|
|
156
|
+
if (readPath) {
|
|
157
|
+
return `Reading ${readPath}`;
|
|
158
|
+
}
|
|
159
|
+
const writeArgs = objectField(objectField(toolCall, "writeToolCall"), "args");
|
|
160
|
+
const writePath = stringField(writeArgs, "path");
|
|
161
|
+
if (writePath) {
|
|
162
|
+
return `Writing ${writePath}`;
|
|
163
|
+
}
|
|
164
|
+
const shellArgs = objectField(objectField(toolCall, "shellToolCall"), "args");
|
|
165
|
+
const command = stringField(shellArgs, "command");
|
|
166
|
+
if (command) {
|
|
167
|
+
return `Shell command started: ${clip(command, 500)}`;
|
|
168
|
+
}
|
|
169
|
+
const fn = objectField(toolCall, "function");
|
|
170
|
+
const name = stringField(fn, "name");
|
|
171
|
+
if (name) {
|
|
172
|
+
return `Tool call started: ${name}`;
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
function formatCursorToolCallCompleted(toolCall) {
|
|
177
|
+
const writeArgs = objectField(objectField(toolCall, "writeToolCall"), "args");
|
|
178
|
+
const writePath = stringField(writeArgs, "path");
|
|
179
|
+
const writeResult = objectField(objectField(objectField(toolCall, "writeToolCall"), "result"), "success");
|
|
180
|
+
const writtenPath = stringField(writeResult, "path") ?? writePath;
|
|
181
|
+
if (writtenPath) {
|
|
182
|
+
return {
|
|
183
|
+
kind: "file_edit",
|
|
184
|
+
content: `Wrote ${writtenPath}`
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const readArgs = objectField(objectField(toolCall, "readToolCall"), "args");
|
|
188
|
+
const readPath = stringField(readArgs, "path");
|
|
189
|
+
if (readPath) {
|
|
190
|
+
const readResult = objectField(objectField(objectField(toolCall, "readToolCall"), "result"), "success");
|
|
191
|
+
const totalLines = readResult.totalLines;
|
|
192
|
+
const lineSummary = typeof totalLines === "number" ? ` (${totalLines} lines)` : "";
|
|
193
|
+
return {
|
|
194
|
+
kind: "checkpoint",
|
|
195
|
+
content: `Read ${readPath}${lineSummary}`
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
const shellArgs = objectField(objectField(toolCall, "shellToolCall"), "args");
|
|
199
|
+
const command = stringField(shellArgs, "command");
|
|
200
|
+
if (command) {
|
|
201
|
+
return {
|
|
202
|
+
kind: "checkpoint",
|
|
203
|
+
content: `Shell command completed: ${clip(command, 500)}`
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
const fn = objectField(toolCall, "function");
|
|
207
|
+
const name = stringField(fn, "name");
|
|
208
|
+
if (name) {
|
|
209
|
+
return {
|
|
210
|
+
kind: "checkpoint",
|
|
211
|
+
content: `Tool call completed: ${name}`
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
function assistantMessageText(event) {
|
|
217
|
+
const message = objectField(event, "message");
|
|
218
|
+
const content = message.content;
|
|
219
|
+
if (!Array.isArray(content)) {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
const parts = content
|
|
223
|
+
.map((entry) => {
|
|
224
|
+
if (!entry || typeof entry !== "object") {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
const block = entry;
|
|
228
|
+
return stringField(block, "text");
|
|
229
|
+
})
|
|
230
|
+
.filter((text) => Boolean(text));
|
|
231
|
+
if (parts.length === 0) {
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
return parts.join("");
|
|
235
|
+
}
|
|
236
|
+
export function parseJsonLine(line) {
|
|
237
|
+
const trimmed = line.trim();
|
|
238
|
+
if (!trimmed.startsWith("{")) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
let parsed;
|
|
242
|
+
try {
|
|
243
|
+
parsed = JSON.parse(trimmed);
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed)
|
|
249
|
+
? parsed
|
|
250
|
+
: null;
|
|
251
|
+
}
|
|
252
|
+
const claudeFileEditTools = new Set(["edit", "multiedit", "write", "notebookedit"]);
|
|
253
|
+
/**
|
|
254
|
+
* Parses `claude -p --output-format stream-json --verbose` output. Each line is one of:
|
|
255
|
+
* `system/init`, `assistant` (text + tool_use blocks), `user` (tool_result blocks), or the
|
|
256
|
+
* terminal `result` event that carries the aggregated usage for the whole run.
|
|
257
|
+
*/
|
|
258
|
+
class ClaudeStreamJsonState {
|
|
259
|
+
sessionId = null;
|
|
260
|
+
finalMessage = null;
|
|
261
|
+
emittedSession = false;
|
|
262
|
+
accumulatedUsage = null;
|
|
263
|
+
activeToolUses = new Map();
|
|
264
|
+
get sessionLabel() {
|
|
265
|
+
return this.sessionId ? `session ${this.sessionId}` : null;
|
|
266
|
+
}
|
|
267
|
+
get providerThreadId() {
|
|
268
|
+
return this.sessionId;
|
|
269
|
+
}
|
|
270
|
+
get usage() {
|
|
271
|
+
return this.accumulatedUsage;
|
|
272
|
+
}
|
|
273
|
+
get hasActiveToolCall() {
|
|
274
|
+
return this.activeToolUses.size > 0;
|
|
275
|
+
}
|
|
276
|
+
resetActiveToolCalls() {
|
|
277
|
+
this.activeToolUses.clear();
|
|
278
|
+
}
|
|
279
|
+
consume(line) {
|
|
280
|
+
const event = parseJsonLine(line);
|
|
281
|
+
if (!event) {
|
|
282
|
+
return [];
|
|
283
|
+
}
|
|
284
|
+
const type = stringField(event, "type");
|
|
285
|
+
if (type === "system" && stringField(event, "subtype") === "init") {
|
|
286
|
+
return this.consumeInit(event);
|
|
287
|
+
}
|
|
288
|
+
if (type === "assistant") {
|
|
289
|
+
return this.consumeAssistant(event);
|
|
290
|
+
}
|
|
291
|
+
if (type === "user") {
|
|
292
|
+
return this.consumeToolResults(event);
|
|
293
|
+
}
|
|
294
|
+
if (type === "result") {
|
|
295
|
+
return this.consumeResult(event, line);
|
|
296
|
+
}
|
|
297
|
+
if (type === "error") {
|
|
298
|
+
return [providerCliError(line)];
|
|
299
|
+
}
|
|
300
|
+
return [];
|
|
301
|
+
}
|
|
302
|
+
consumeInit(event) {
|
|
303
|
+
const events = [];
|
|
304
|
+
this.sessionId = stringField(event, "session_id") ?? this.sessionId;
|
|
305
|
+
if (this.sessionId && !this.emittedSession) {
|
|
306
|
+
this.emittedSession = true;
|
|
307
|
+
events.push({
|
|
308
|
+
role: "runner",
|
|
309
|
+
kind: "checkpoint",
|
|
310
|
+
content: `Claude session started: ${this.sessionId}.`,
|
|
311
|
+
eventType: "provider_thread_started"
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
const servers = Array.isArray(event.mcp_servers) ? event.mcp_servers : [];
|
|
315
|
+
for (const entry of servers) {
|
|
316
|
+
if (!entry || typeof entry !== "object") {
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
const server = entry;
|
|
320
|
+
const name = stringField(server, "name");
|
|
321
|
+
const status = stringField(server, "status");
|
|
322
|
+
if (name && status && status !== "connected") {
|
|
323
|
+
events.push({
|
|
324
|
+
role: "runner",
|
|
325
|
+
kind: "checkpoint",
|
|
326
|
+
content: `Claude MCP server ${name} is ${status}.`,
|
|
327
|
+
eventType: "provider_mcp_server_status",
|
|
328
|
+
data: JSON.stringify({ server_name: name, status })
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return events;
|
|
333
|
+
}
|
|
334
|
+
consumeAssistant(event) {
|
|
335
|
+
const events = [];
|
|
336
|
+
const text = assistantMessageText(event);
|
|
337
|
+
if (text) {
|
|
338
|
+
this.finalMessage = text;
|
|
339
|
+
events.push({
|
|
340
|
+
role: "assistant",
|
|
341
|
+
kind: "message",
|
|
342
|
+
content: clip(text, 4000),
|
|
343
|
+
eventType: "provider_message"
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
for (const block of messageContentBlocks(event)) {
|
|
347
|
+
if (stringField(block, "type") !== "tool_use") {
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
const id = stringField(block, "id");
|
|
351
|
+
const name = stringField(block, "name");
|
|
352
|
+
if (!id || !name) {
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
const toolUse = { name, input: objectField(block, "input") };
|
|
356
|
+
this.activeToolUses.set(id, toolUse);
|
|
357
|
+
events.push(...formatClaudeToolUseStarted(toolUse));
|
|
358
|
+
}
|
|
359
|
+
return events;
|
|
360
|
+
}
|
|
361
|
+
consumeToolResults(event) {
|
|
362
|
+
const events = [];
|
|
363
|
+
for (const block of messageContentBlocks(event)) {
|
|
364
|
+
if (stringField(block, "type") !== "tool_result") {
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
const id = stringField(block, "tool_use_id");
|
|
368
|
+
const toolUse = id ? this.activeToolUses.get(id) : undefined;
|
|
369
|
+
if (!id || !toolUse) {
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
this.activeToolUses.delete(id);
|
|
373
|
+
events.push(...formatClaudeToolUseCompleted(toolUse, block.is_error === true, toolResultText(block)));
|
|
374
|
+
}
|
|
375
|
+
return events;
|
|
376
|
+
}
|
|
377
|
+
consumeResult(event, line) {
|
|
378
|
+
this.activeToolUses.clear();
|
|
379
|
+
this.accumulateUsage(event);
|
|
380
|
+
const result = stringField(event, "result");
|
|
381
|
+
const subtype = stringField(event, "subtype") ?? "";
|
|
382
|
+
const failed = event.is_error === true || subtype.startsWith("error");
|
|
383
|
+
if (!failed) {
|
|
384
|
+
if (result) {
|
|
385
|
+
this.finalMessage = result;
|
|
386
|
+
}
|
|
387
|
+
return [{
|
|
388
|
+
role: "runner",
|
|
389
|
+
kind: "checkpoint",
|
|
390
|
+
content: "Claude turn completed.",
|
|
391
|
+
eventType: "provider_turn_completed"
|
|
392
|
+
}];
|
|
393
|
+
}
|
|
394
|
+
return [providerCliError(line)];
|
|
395
|
+
}
|
|
396
|
+
accumulateUsage(event) {
|
|
397
|
+
const usage = objectField(event, "usage");
|
|
398
|
+
const durationMs = readUsageNumber(event, "duration_ms") || readUsageNumber(event, "duration_api_ms");
|
|
399
|
+
if (Object.keys(usage).length === 0 && durationMs === 0) {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
// Anthropic's input_tokens excludes cache reads and writes; normalize to a cache-inclusive total.
|
|
403
|
+
const uncachedInputTokens = readUsageNumber(usage, "input_tokens");
|
|
404
|
+
const cacheReadTokens = readUsageNumber(usage, "cache_read_input_tokens");
|
|
405
|
+
const cacheCreationTokens = readUsageNumber(usage, "cache_creation_input_tokens");
|
|
406
|
+
this.accumulatedUsage = addUsage(this.accumulatedUsage ?? emptyUsage("provider_reported"), {
|
|
407
|
+
inputTokens: uncachedInputTokens + cacheReadTokens + cacheCreationTokens,
|
|
408
|
+
uncachedInputTokens,
|
|
409
|
+
outputTokens: readUsageNumber(usage, "output_tokens"),
|
|
410
|
+
cacheReadTokens,
|
|
411
|
+
cacheCreationTokens,
|
|
412
|
+
providerDurationMs: durationMs > 0 ? durationMs : null,
|
|
413
|
+
source: "provider_reported",
|
|
414
|
+
inputTokenSemantics: "excludes_cache_tokens",
|
|
415
|
+
rawUsage: [{ provider: "claude", usage }]
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
function providerCliError(line) {
|
|
420
|
+
return {
|
|
421
|
+
role: "runner",
|
|
422
|
+
kind: "error",
|
|
423
|
+
content: clip(line.trim(), 1000),
|
|
424
|
+
eventType: "provider_cli_error"
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
function messageContentBlocks(event) {
|
|
428
|
+
const content = objectField(event, "message").content;
|
|
429
|
+
if (!Array.isArray(content)) {
|
|
430
|
+
return [];
|
|
431
|
+
}
|
|
432
|
+
return content.filter((entry) => Boolean(entry) && typeof entry === "object" && !Array.isArray(entry));
|
|
433
|
+
}
|
|
434
|
+
function toolResultText(block) {
|
|
435
|
+
const content = block.content;
|
|
436
|
+
if (typeof content === "string") {
|
|
437
|
+
return content.trim() || null;
|
|
438
|
+
}
|
|
439
|
+
if (!Array.isArray(content)) {
|
|
440
|
+
return null;
|
|
441
|
+
}
|
|
442
|
+
const text = content
|
|
443
|
+
.map((entry) => entry && typeof entry === "object" ? stringField(entry, "text") : null)
|
|
444
|
+
.filter((part) => Boolean(part))
|
|
445
|
+
.join("\n")
|
|
446
|
+
.trim();
|
|
447
|
+
return text || null;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Claude Code exposes MCP tools as `mcp__<server>__<tool>` and replaces characters outside
|
|
451
|
+
* `[A-Za-z0-9_-]` with `_`, so `forge.complete_qa` arrives as `mcp__forge__forge_complete_qa`.
|
|
452
|
+
*/
|
|
453
|
+
export function parseClaudeMcpToolName(name) {
|
|
454
|
+
const match = /^mcp__(.+?)__(.+)$/u.exec(name);
|
|
455
|
+
if (!match) {
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
const server = match[1] ?? "";
|
|
459
|
+
const rawTool = match[2] ?? "";
|
|
460
|
+
const tool = server === "forge" && rawTool.startsWith("forge_") ? `forge.${rawTool.slice("forge_".length)}` : rawTool;
|
|
461
|
+
return server && tool ? { server, tool } : null;
|
|
462
|
+
}
|
|
463
|
+
function claudeMcpEvents(toolUse, phase, errorText) {
|
|
464
|
+
const mcp = parseClaudeMcpToolName(toolUse.name);
|
|
465
|
+
if (!mcp) {
|
|
466
|
+
return null;
|
|
467
|
+
}
|
|
468
|
+
const item = {
|
|
469
|
+
type: "mcp_tool_call",
|
|
470
|
+
server: mcp.server,
|
|
471
|
+
tool: mcp.tool,
|
|
472
|
+
status: phase
|
|
473
|
+
};
|
|
474
|
+
if (phase === "failed") {
|
|
475
|
+
item.error = errorText ? clip(errorText, 600) : "MCP tool call failed.";
|
|
476
|
+
}
|
|
477
|
+
return formatCodexMcpToolCallEvents(phase === "started" ? "item.started" : "item.completed", { item });
|
|
478
|
+
}
|
|
479
|
+
function formatClaudeToolUseStarted(toolUse) {
|
|
480
|
+
const mcp = claudeMcpEvents(toolUse, "started", null);
|
|
481
|
+
if (mcp) {
|
|
482
|
+
return mcp;
|
|
483
|
+
}
|
|
484
|
+
const normalized = toolUse.name.toLowerCase();
|
|
485
|
+
const filePath = stringField(toolUse.input, "file_path") ?? stringField(toolUse.input, "notebook_path") ?? stringField(toolUse.input, "path");
|
|
486
|
+
let content;
|
|
487
|
+
if (normalized === "bash") {
|
|
488
|
+
const command = stringField(toolUse.input, "command");
|
|
489
|
+
content = command ? `Shell command started: ${clip(command, 500)}` : "Shell command started.";
|
|
490
|
+
}
|
|
491
|
+
else if (normalized === "read" && filePath) {
|
|
492
|
+
content = `Reading ${filePath}`;
|
|
493
|
+
}
|
|
494
|
+
else if (claudeFileEditTools.has(normalized) && filePath) {
|
|
495
|
+
content = `Writing ${filePath}`;
|
|
496
|
+
}
|
|
497
|
+
else {
|
|
498
|
+
content = `Tool call started: ${toolUse.name}`;
|
|
499
|
+
}
|
|
500
|
+
return [{
|
|
501
|
+
role: "worker",
|
|
502
|
+
kind: "checkpoint",
|
|
503
|
+
content,
|
|
504
|
+
eventType: normalized === "bash" ? "provider_command" : "provider_tool_call"
|
|
505
|
+
}];
|
|
506
|
+
}
|
|
507
|
+
function formatClaudeToolUseCompleted(toolUse, isError, resultText) {
|
|
508
|
+
const mcp = claudeMcpEvents(toolUse, isError ? "failed" : "completed", resultText);
|
|
509
|
+
if (mcp) {
|
|
510
|
+
return mcp;
|
|
511
|
+
}
|
|
512
|
+
const normalized = toolUse.name.toLowerCase();
|
|
513
|
+
const filePath = stringField(toolUse.input, "file_path") ?? stringField(toolUse.input, "notebook_path") ?? stringField(toolUse.input, "path");
|
|
514
|
+
if (claudeFileEditTools.has(normalized) && filePath && !isError) {
|
|
515
|
+
return [{
|
|
516
|
+
role: "worker",
|
|
517
|
+
kind: "file_edit",
|
|
518
|
+
content: `Wrote ${filePath}`,
|
|
519
|
+
eventType: "provider_file_edit"
|
|
520
|
+
}];
|
|
521
|
+
}
|
|
522
|
+
const status = isError ? "failed" : "completed";
|
|
523
|
+
let content;
|
|
524
|
+
if (normalized === "bash") {
|
|
525
|
+
const command = stringField(toolUse.input, "command");
|
|
526
|
+
content = command ? `Shell command ${status}: ${clip(command, 500)}` : `Shell command ${status}.`;
|
|
527
|
+
}
|
|
528
|
+
else if (normalized === "read" && filePath) {
|
|
529
|
+
content = isError ? `Read failed: ${filePath}` : `Read ${filePath}`;
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
content = `Tool call ${status}: ${toolUse.name}`;
|
|
533
|
+
}
|
|
534
|
+
return [{
|
|
535
|
+
role: "worker",
|
|
536
|
+
kind: "checkpoint",
|
|
537
|
+
content,
|
|
538
|
+
eventType: normalized === "bash" ? "provider_command" : "provider_tool_call"
|
|
539
|
+
}];
|
|
540
|
+
}
|
|
541
|
+
class CodexJsonState {
|
|
542
|
+
threadId = null;
|
|
543
|
+
finalMessage = null;
|
|
544
|
+
emittedThread = false;
|
|
545
|
+
accumulatedUsage = null;
|
|
546
|
+
activeToolCallCount = 0;
|
|
547
|
+
get sessionLabel() {
|
|
548
|
+
return this.threadId ? `thread ${this.threadId}` : null;
|
|
549
|
+
}
|
|
550
|
+
get providerThreadId() {
|
|
551
|
+
return this.threadId;
|
|
552
|
+
}
|
|
553
|
+
get usage() {
|
|
554
|
+
return this.accumulatedUsage;
|
|
555
|
+
}
|
|
556
|
+
get hasActiveToolCall() {
|
|
557
|
+
return this.activeToolCallCount > 0;
|
|
558
|
+
}
|
|
559
|
+
resetActiveToolCalls() {
|
|
560
|
+
this.activeToolCallCount = 0;
|
|
561
|
+
}
|
|
562
|
+
consume(line) {
|
|
563
|
+
const event = parseJsonLine(line);
|
|
564
|
+
if (!event) {
|
|
565
|
+
return [];
|
|
566
|
+
}
|
|
567
|
+
const type = stringField(event, "type") ?? "";
|
|
568
|
+
this.trackToolActivity(type, event);
|
|
569
|
+
if (type === "thread.started") {
|
|
570
|
+
this.threadId = stringField(event, "thread_id");
|
|
571
|
+
if (this.threadId && !this.emittedThread) {
|
|
572
|
+
this.emittedThread = true;
|
|
573
|
+
return [{
|
|
574
|
+
role: "runner",
|
|
575
|
+
kind: "checkpoint",
|
|
576
|
+
content: `Codex thread started: ${this.threadId}.`,
|
|
577
|
+
eventType: "provider_thread_started",
|
|
578
|
+
data: JSON.stringify({ threadId: this.threadId })
|
|
579
|
+
}];
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
if (type === "turn.completed") {
|
|
583
|
+
this.accumulateUsage(event);
|
|
584
|
+
return [{
|
|
585
|
+
role: "runner",
|
|
586
|
+
kind: "checkpoint",
|
|
587
|
+
content: "Codex turn completed.",
|
|
588
|
+
eventType: "provider_turn_completed"
|
|
589
|
+
}];
|
|
590
|
+
}
|
|
591
|
+
if (type === "turn.failed" || type === "error") {
|
|
592
|
+
return [{
|
|
593
|
+
role: "runner",
|
|
594
|
+
kind: "error",
|
|
595
|
+
content: clip(line.trim(), 1000),
|
|
596
|
+
eventType: "provider_cli_error"
|
|
597
|
+
}];
|
|
598
|
+
}
|
|
599
|
+
if (type === "item.started" || type === "item.completed" || type === "item.updated") {
|
|
600
|
+
const item = objectField(event, "item");
|
|
601
|
+
const itemType = stringField(item, "type");
|
|
602
|
+
if (itemType === "agent_message") {
|
|
603
|
+
const text = stringField(item, "text");
|
|
604
|
+
if (text) {
|
|
605
|
+
this.finalMessage = text;
|
|
606
|
+
return [{
|
|
607
|
+
role: "assistant",
|
|
608
|
+
kind: "message",
|
|
609
|
+
content: clip(text, 4000),
|
|
610
|
+
eventType: "provider_message"
|
|
611
|
+
}];
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
if (itemType === "command_execution") {
|
|
615
|
+
const command = stringField(item, "command");
|
|
616
|
+
const status = stringField(item, "status");
|
|
617
|
+
if (command) {
|
|
618
|
+
return [{
|
|
619
|
+
role: "worker",
|
|
620
|
+
kind: "checkpoint",
|
|
621
|
+
content: `Codex command ${status || (type === "item.started" ? "started" : "completed")}: ${clip(command, 500)}`,
|
|
622
|
+
eventType: "provider_command"
|
|
623
|
+
}];
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
const mcpEvents = formatCodexMcpToolCallEvents(type, event);
|
|
628
|
+
if (mcpEvents.length > 0) {
|
|
629
|
+
return mcpEvents;
|
|
630
|
+
}
|
|
631
|
+
return [];
|
|
632
|
+
}
|
|
633
|
+
trackToolActivity(type, event) {
|
|
634
|
+
if (type !== "item.started" && type !== "item.completed") {
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
const item = objectField(event, "item");
|
|
638
|
+
const itemType = (stringField(item, "type") ?? "").toLowerCase();
|
|
639
|
+
const toolName = mcpToolName(item);
|
|
640
|
+
const isTool = itemType === "command_execution"
|
|
641
|
+
|| itemType.includes("mcp")
|
|
642
|
+
|| Boolean(toolName);
|
|
643
|
+
if (!isTool) {
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
this.activeToolCallCount = type === "item.started"
|
|
647
|
+
? this.activeToolCallCount + 1
|
|
648
|
+
: Math.max(0, this.activeToolCallCount - 1);
|
|
649
|
+
}
|
|
650
|
+
accumulateUsage(event) {
|
|
651
|
+
const usage = objectField(event, "usage");
|
|
652
|
+
if (Object.keys(usage).length === 0) {
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
const inputTokens = readUsageNumber(usage, "input_tokens");
|
|
656
|
+
const cacheReadTokens = readUsageNumber(usage, "cached_input_tokens");
|
|
657
|
+
this.accumulatedUsage = addUsage(this.accumulatedUsage ?? emptyUsage("provider_reported"), {
|
|
658
|
+
inputTokens,
|
|
659
|
+
uncachedInputTokens: Math.max(0, inputTokens - cacheReadTokens),
|
|
660
|
+
outputTokens: readUsageNumber(usage, "output_tokens"),
|
|
661
|
+
cacheReadTokens,
|
|
662
|
+
reasoningOutputTokens: readUsageNumber(usage, "reasoning_output_tokens"),
|
|
663
|
+
source: "provider_reported",
|
|
664
|
+
inputTokenSemantics: "includes_cached_input",
|
|
665
|
+
rawUsage: [{ provider: "codex", usage }]
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
export function formatCodexMcpToolCallEvents(type, event) {
|
|
670
|
+
if (type !== "item.started" && type !== "item.updated" && type !== "item.completed") {
|
|
671
|
+
return [];
|
|
672
|
+
}
|
|
673
|
+
const item = objectField(event, "item");
|
|
674
|
+
const itemType = stringField(item, "type") ?? "";
|
|
675
|
+
const serverName = mcpServerName(item);
|
|
676
|
+
const toolName = mcpToolName(item);
|
|
677
|
+
const isMcpItem = itemType.toLowerCase().includes("mcp")
|
|
678
|
+
|| Boolean(serverName)
|
|
679
|
+
|| (toolName ? isForgeCompletionTool(toolName) || toolName.toLowerCase().includes("mcp") : false);
|
|
680
|
+
if (!isMcpItem || !toolName) {
|
|
681
|
+
return [];
|
|
682
|
+
}
|
|
683
|
+
const status = normalizedString(stringField(item, "status")
|
|
684
|
+
?? stringField(event, "status")
|
|
685
|
+
?? (type === "item.started" ? "started" : type === "item.completed" ? "completed" : "updated"));
|
|
686
|
+
const failed = status === "failed" || status === "error" || status === "cancelled" || Boolean(item.error);
|
|
687
|
+
const completed = failed || type === "item.completed" || status === "completed" || status === "succeeded" || status === "success";
|
|
688
|
+
const started = type === "item.started" || status === "started" || status === "running" || status === "in_progress";
|
|
689
|
+
const data = safeProviderMcpData(item, serverName ?? "unknown", toolName, status);
|
|
690
|
+
const label = `${serverName ?? "unknown"}.${toolName}`;
|
|
691
|
+
if (failed) {
|
|
692
|
+
const summary = mcpErrorSummary(item) ?? "MCP tool call failed.";
|
|
693
|
+
const events = [{
|
|
694
|
+
role: "tool",
|
|
695
|
+
kind: "error",
|
|
696
|
+
content: `MCP tool call failed: ${label} - ${summary}`,
|
|
697
|
+
eventType: "provider_mcp_call_failed",
|
|
698
|
+
data
|
|
699
|
+
}];
|
|
700
|
+
if (isForgeCompletionTool(toolName)) {
|
|
701
|
+
events.push({
|
|
702
|
+
role: "tool",
|
|
703
|
+
kind: "error",
|
|
704
|
+
content: `Forge completion tool validation failed: ${label} - ${summary}`,
|
|
705
|
+
eventType: "completion_tool_validation_failed",
|
|
706
|
+
data
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
return events;
|
|
710
|
+
}
|
|
711
|
+
if (completed) {
|
|
712
|
+
return [{
|
|
713
|
+
role: "tool",
|
|
714
|
+
kind: "checkpoint",
|
|
715
|
+
content: `MCP tool call completed: ${label}.`,
|
|
716
|
+
eventType: "provider_mcp_call_completed",
|
|
717
|
+
data
|
|
718
|
+
}];
|
|
719
|
+
}
|
|
720
|
+
if (started) {
|
|
721
|
+
return [{
|
|
722
|
+
role: "tool",
|
|
723
|
+
kind: "checkpoint",
|
|
724
|
+
content: `MCP tool call started: ${label}.`,
|
|
725
|
+
eventType: "provider_mcp_call_started",
|
|
726
|
+
data
|
|
727
|
+
}];
|
|
728
|
+
}
|
|
729
|
+
return [];
|
|
730
|
+
}
|
|
731
|
+
function mcpServerName(item) {
|
|
732
|
+
return stringField(item, "server")
|
|
733
|
+
?? stringField(item, "server_name")
|
|
734
|
+
?? stringField(item, "mcp_server")
|
|
735
|
+
?? stringField(objectField(item, "mcp"), "server")
|
|
736
|
+
?? stringField(objectField(item, "mcp"), "server_name");
|
|
737
|
+
}
|
|
738
|
+
function mcpToolName(item) {
|
|
739
|
+
return stringField(item, "tool")
|
|
740
|
+
?? stringField(item, "tool_name")
|
|
741
|
+
?? stringField(item, "name")
|
|
742
|
+
?? stringField(objectField(item, "function"), "name")
|
|
743
|
+
?? stringField(objectField(item, "mcp"), "tool")
|
|
744
|
+
?? stringField(objectField(item, "mcp"), "tool_name");
|
|
745
|
+
}
|
|
746
|
+
function mcpErrorSummary(item) {
|
|
747
|
+
const direct = stringField(item, "error")
|
|
748
|
+
?? stringField(item, "error_message")
|
|
749
|
+
?? stringField(item, "message");
|
|
750
|
+
if (direct) {
|
|
751
|
+
return clip(direct, 600);
|
|
752
|
+
}
|
|
753
|
+
const messages = uniqueErrorMessages([
|
|
754
|
+
item.error,
|
|
755
|
+
item.result,
|
|
756
|
+
item.content,
|
|
757
|
+
]);
|
|
758
|
+
return messages.length > 0 ? clip(messages.join(" Caused by: "), 600) : null;
|
|
759
|
+
}
|
|
760
|
+
function uniqueErrorMessages(values) {
|
|
761
|
+
const messages = [];
|
|
762
|
+
const seenMessages = new Set();
|
|
763
|
+
const seenObjects = new Set();
|
|
764
|
+
const visit = (value, depth) => {
|
|
765
|
+
if (depth > 8 || value === null || value === undefined)
|
|
766
|
+
return;
|
|
767
|
+
if (typeof value === "string") {
|
|
768
|
+
const message = value.trim();
|
|
769
|
+
if (message.length > 0 && !seenMessages.has(message)) {
|
|
770
|
+
seenMessages.add(message);
|
|
771
|
+
messages.push(message);
|
|
772
|
+
}
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
if (typeof value !== "object" || seenObjects.has(value))
|
|
776
|
+
return;
|
|
777
|
+
seenObjects.add(value);
|
|
778
|
+
if (Array.isArray(value)) {
|
|
779
|
+
for (const entry of value)
|
|
780
|
+
visit(entry, depth + 1);
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
const record = value;
|
|
784
|
+
for (const key of ["message", "summary", "error", "cause", "data", "details", "result", "content"]) {
|
|
785
|
+
if (key in record)
|
|
786
|
+
visit(record[key], depth + 1);
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
for (const value of values)
|
|
790
|
+
visit(value, 0);
|
|
791
|
+
return messages;
|
|
792
|
+
}
|
|
793
|
+
function safeProviderMcpData(item, serverName, toolName, status) {
|
|
794
|
+
const elapsedMs = numericField(item, "elapsed_ms") ?? numericField(item, "duration_ms");
|
|
795
|
+
return JSON.stringify(stripUndefined({
|
|
796
|
+
server_name: serverName,
|
|
797
|
+
tool_name: toolName,
|
|
798
|
+
status,
|
|
799
|
+
elapsed_ms: elapsedMs,
|
|
800
|
+
error_summary: mcpErrorSummary(item)
|
|
801
|
+
}));
|
|
802
|
+
}
|
|
803
|
+
function isForgeCompletionTool(toolName) {
|
|
804
|
+
const normalized = toolName.trim().toLowerCase();
|
|
805
|
+
return normalized.startsWith("forge.complete_")
|
|
806
|
+
|| normalized.startsWith("complete_")
|
|
807
|
+
|| normalized.includes("forge.complete_")
|
|
808
|
+
|| normalized.includes("complete_architect_plan");
|
|
809
|
+
}
|
|
810
|
+
export function objectField(source, key) {
|
|
811
|
+
const value = source[key];
|
|
812
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
813
|
+
? value
|
|
814
|
+
: {};
|
|
815
|
+
}
|
|
816
|
+
export function stringField(source, key) {
|
|
817
|
+
const value = source[key];
|
|
818
|
+
return typeof value === "string" && value.trim().length > 0 ? value : null;
|
|
819
|
+
}
|
|
820
|
+
export function numericField(source, key) {
|
|
821
|
+
const value = source[key];
|
|
822
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
823
|
+
}
|
|
824
|
+
export function stripUndefined(value) {
|
|
825
|
+
return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined));
|
|
826
|
+
}
|
|
827
|
+
export function normalizedString(value) {
|
|
828
|
+
return value.trim().toLowerCase().replace(/-/g, "_");
|
|
829
|
+
}
|
|
830
|
+
export function isNodeError(error) {
|
|
831
|
+
return error instanceof Error && "code" in error;
|
|
832
|
+
}
|