@loucompanion/forge-bridge 0.1.3-dev.fbe15023cdfe → 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 +232 -5
- 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 +13 -1
- package/dist/bridge/bridge.service.d.ts +169 -14
- package/dist/bridge/bridge.service.js +1868 -330
- package/dist/bridge/bridge.types.d.ts +73 -1
- 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 +21 -1
- package/dist/cleanup/cleanup.service.js +185 -143
- package/dist/cleanup/cleanup.types.d.ts +6 -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/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +78 -16
- package/dist/cli/cli.service.d.ts +32 -15
- package/dist/cli/cli.service.js +206 -182
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +7 -0
- package/dist/cli/local-config.js +36 -4
- 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 +2 -1
- package/dist/runtime/attempt-node-runtime-launcher.js +57 -18
- 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.d.ts +35 -0
- package/dist/runtime/attempt-process-supervisor.js +144 -23
- 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 +10 -0
- package/dist/runtime/generated-output-reset.js +62 -8
- 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 +8 -1
- package/dist/runtime/host-listener-inspector.js +121 -60
- 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-pressure-stall.d.ts +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +28 -1
- package/dist/runtime/host-runtime-contract.js +203 -57
- package/dist/runtime/host-runtime-lease.d.ts +163 -9
- package/dist/runtime/host-runtime-lease.js +1427 -124
- package/dist/runtime/host-runtime-promotion.d.ts +35 -3
- package/dist/runtime/host-runtime-promotion.js +107 -12
- 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 +3 -0
- package/dist/runtime/node-host-runtime-adapter.js +29 -11
- 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 +19 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +113 -59
- 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.js +4 -1
- package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
- package/dist/runtime/workspace-resource-estimator.js +174 -0
- package/dist/sandbox/host-capacity-broker.d.ts +115 -0
- package/dist/sandbox/host-capacity-broker.js +336 -0
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +36 -0
- package/dist/sandbox/preflight.d.ts +31 -1
- package/dist/sandbox/preflight.js +237 -51
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/repository-lock.d.ts +2 -1
- package/dist/sandbox/repository-lock.js +19 -9
- package/dist/sandbox/runtime.d.ts +16 -2
- package/dist/sandbox/runtime.js +183 -114
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/sandbox/sandbox.types.d.ts +7 -0
- package/dist/sandbox/workspace.service.js +2 -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 +37 -1
- package/dist/session/managed-attempt-tools.js +822 -84
- 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 +24 -0
- package/dist/session/phase-completion.artifacts.js +321 -45
- 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 +23 -1
- package/dist/session/phase-completion.helpers.d.ts +5 -0
- package/dist/session/phase-completion.helpers.js +43 -19
- package/dist/session/phase-completion.js +19 -3
- 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.js +22 -18
- package/dist/session/phase-completion.runtime.d.ts +6 -10
- package/dist/session/phase-completion.runtime.js +214 -224
- 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 -3
- package/dist/session/phase-completion.schemas.js +250 -226
- package/dist/session/phase-completion.validation.d.ts +3 -3
- package/dist/session/phase-completion.validation.js +135 -89
- 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 +8 -0
- package/dist/session/provider-cli/ci-repair-readiness.js +23 -3
- 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 +6 -3
- package/dist/session/provider-cli/provider-cli.artifacts.js +62 -22
- 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.js +34 -2
- 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 +85 -19
- package/dist/session/provider-cli/provider-cli.process.js +566 -283
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +211 -36
- 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 +22 -1
- package/dist/session/provider-cli/provider-cli.runtime.js +83 -4
- package/dist/session/provider-cli/provider-cli.service.d.ts +36 -5
- package/dist/session/provider-cli/provider-cli.service.js +818 -99
- package/dist/session/provider-cli/provider-cli.types.d.ts +32 -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 +18 -0
- package/dist/session/provider-cli/provider-output-state.js +376 -17
- 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.js +284 -9
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +11 -2
- package/dist/session/session.service.js +301 -58
- package/dist/session/session.types.d.ts +150 -2
- package/dist/session/session.types.js +599 -7
- 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 +18 -0
- 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 +14 -3
- package/dist/shared/process/host-process-recovery.js +26 -5
- package/dist/shared/process/host-process-supervisor.d.ts +16 -1
- package/dist/shared/process/host-process-supervisor.js +124 -23
- 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 +69 -0
- package/dist/shared/process/process.js +223 -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 +18 -0
- package/dist/shared/process/windows-launch.js +68 -0
- package/dist/shared/provider-capabilities.d.ts +3 -0
- package/dist/shared/provider-capabilities.js +92 -0
- package/dist/shared/redaction/redaction.d.ts +1 -0
- package/dist/shared/redaction/redaction.js +39 -3
- 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/dependency-warmer.d.ts +66 -9
- package/dist/worktree/dependency-warmer.js +609 -24
- package/dist/worktree/index.d.ts +1 -1
- 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-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 +7 -1
- package/dist/worktree/worktree.service.d.ts +22 -2
- package/dist/worktree/worktree.service.js +302 -25
- package/dist/worktree/worktree.types.d.ts +36 -1
- package/package.json +8 -6
- package/runtime/windows-job-supervisor.ps1 +380 -14
|
@@ -2,6 +2,12 @@ import { addUsage, emptyUsage, readUsageNumber } from "./provider-usage.js";
|
|
|
2
2
|
export function messageFromError(error) {
|
|
3
3
|
return error instanceof Error ? error.message : String(error);
|
|
4
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
|
+
}
|
|
5
11
|
export function clip(value, maxLength) {
|
|
6
12
|
if (maxLength <= 0) {
|
|
7
13
|
return "";
|
|
@@ -16,9 +22,14 @@ export function clip(value, maxLength) {
|
|
|
16
22
|
return `${value.slice(0, maxLength - ellipsis.length)}${ellipsis}`;
|
|
17
23
|
}
|
|
18
24
|
export function createProviderOutputState(provider) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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();
|
|
22
33
|
}
|
|
23
34
|
class CursorStreamJsonState {
|
|
24
35
|
sessionId = null;
|
|
@@ -29,12 +40,18 @@ class CursorStreamJsonState {
|
|
|
29
40
|
get sessionLabel() {
|
|
30
41
|
return this.sessionId ? `session ${this.sessionId}` : null;
|
|
31
42
|
}
|
|
43
|
+
get providerThreadId() {
|
|
44
|
+
return this.sessionId;
|
|
45
|
+
}
|
|
32
46
|
get usage() {
|
|
33
47
|
return this.accumulatedUsage;
|
|
34
48
|
}
|
|
35
49
|
get hasActiveToolCall() {
|
|
36
50
|
return this.activeToolCallCount > 0;
|
|
37
51
|
}
|
|
52
|
+
resetActiveToolCalls() {
|
|
53
|
+
this.activeToolCallCount = 0;
|
|
54
|
+
}
|
|
38
55
|
consume(line) {
|
|
39
56
|
const event = parseJsonLine(line);
|
|
40
57
|
if (!event) {
|
|
@@ -49,7 +66,8 @@ class CursorStreamJsonState {
|
|
|
49
66
|
role: "runner",
|
|
50
67
|
kind: "checkpoint",
|
|
51
68
|
content: `Cursor session started: ${this.sessionId}.`,
|
|
52
|
-
eventType: "provider_thread_started"
|
|
69
|
+
eventType: "provider_thread_started",
|
|
70
|
+
data: JSON.stringify({ threadId: this.sessionId })
|
|
53
71
|
}];
|
|
54
72
|
}
|
|
55
73
|
}
|
|
@@ -116,13 +134,19 @@ class CursorStreamJsonState {
|
|
|
116
134
|
if (Object.keys(usage).length === 0 && durationMs === 0) {
|
|
117
135
|
return;
|
|
118
136
|
}
|
|
137
|
+
const uncachedInputTokens = readUsageNumber(usage, "inputTokens");
|
|
138
|
+
const cacheReadTokens = readUsageNumber(usage, "cacheReadTokens");
|
|
139
|
+
const cacheCreationTokens = readUsageNumber(usage, "cacheWriteTokens");
|
|
119
140
|
this.accumulatedUsage = addUsage(this.accumulatedUsage ?? emptyUsage("provider_reported"), {
|
|
120
|
-
inputTokens:
|
|
141
|
+
inputTokens: uncachedInputTokens + cacheReadTokens + cacheCreationTokens,
|
|
142
|
+
uncachedInputTokens,
|
|
121
143
|
outputTokens: readUsageNumber(usage, "outputTokens"),
|
|
122
|
-
cacheReadTokens
|
|
123
|
-
cacheCreationTokens
|
|
144
|
+
cacheReadTokens,
|
|
145
|
+
cacheCreationTokens,
|
|
124
146
|
providerDurationMs: durationMs > 0 ? durationMs : null,
|
|
125
|
-
source: "provider_reported"
|
|
147
|
+
source: "provider_reported",
|
|
148
|
+
inputTokenSemantics: "excludes_cache_tokens",
|
|
149
|
+
rawUsage: [{ provider: "cursor", usage }]
|
|
126
150
|
});
|
|
127
151
|
}
|
|
128
152
|
}
|
|
@@ -225,6 +249,295 @@ export function parseJsonLine(line) {
|
|
|
225
249
|
? parsed
|
|
226
250
|
: null;
|
|
227
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
|
+
}
|
|
228
541
|
class CodexJsonState {
|
|
229
542
|
threadId = null;
|
|
230
543
|
finalMessage = null;
|
|
@@ -234,12 +547,18 @@ class CodexJsonState {
|
|
|
234
547
|
get sessionLabel() {
|
|
235
548
|
return this.threadId ? `thread ${this.threadId}` : null;
|
|
236
549
|
}
|
|
550
|
+
get providerThreadId() {
|
|
551
|
+
return this.threadId;
|
|
552
|
+
}
|
|
237
553
|
get usage() {
|
|
238
554
|
return this.accumulatedUsage;
|
|
239
555
|
}
|
|
240
556
|
get hasActiveToolCall() {
|
|
241
557
|
return this.activeToolCallCount > 0;
|
|
242
558
|
}
|
|
559
|
+
resetActiveToolCalls() {
|
|
560
|
+
this.activeToolCallCount = 0;
|
|
561
|
+
}
|
|
243
562
|
consume(line) {
|
|
244
563
|
const event = parseJsonLine(line);
|
|
245
564
|
if (!event) {
|
|
@@ -255,7 +574,8 @@ class CodexJsonState {
|
|
|
255
574
|
role: "runner",
|
|
256
575
|
kind: "checkpoint",
|
|
257
576
|
content: `Codex thread started: ${this.threadId}.`,
|
|
258
|
-
eventType: "provider_thread_started"
|
|
577
|
+
eventType: "provider_thread_started",
|
|
578
|
+
data: JSON.stringify({ threadId: this.threadId })
|
|
259
579
|
}];
|
|
260
580
|
}
|
|
261
581
|
}
|
|
@@ -332,12 +652,17 @@ class CodexJsonState {
|
|
|
332
652
|
if (Object.keys(usage).length === 0) {
|
|
333
653
|
return;
|
|
334
654
|
}
|
|
655
|
+
const inputTokens = readUsageNumber(usage, "input_tokens");
|
|
656
|
+
const cacheReadTokens = readUsageNumber(usage, "cached_input_tokens");
|
|
335
657
|
this.accumulatedUsage = addUsage(this.accumulatedUsage ?? emptyUsage("provider_reported"), {
|
|
336
|
-
inputTokens
|
|
658
|
+
inputTokens,
|
|
659
|
+
uncachedInputTokens: Math.max(0, inputTokens - cacheReadTokens),
|
|
337
660
|
outputTokens: readUsageNumber(usage, "output_tokens"),
|
|
338
|
-
cacheReadTokens
|
|
661
|
+
cacheReadTokens,
|
|
339
662
|
reasoningOutputTokens: readUsageNumber(usage, "reasoning_output_tokens"),
|
|
340
|
-
source: "provider_reported"
|
|
663
|
+
source: "provider_reported",
|
|
664
|
+
inputTokenSemantics: "includes_cached_input",
|
|
665
|
+
rawUsage: [{ provider: "codex", usage }]
|
|
341
666
|
});
|
|
342
667
|
}
|
|
343
668
|
}
|
|
@@ -425,11 +750,45 @@ function mcpErrorSummary(item) {
|
|
|
425
750
|
if (direct) {
|
|
426
751
|
return clip(direct, 600);
|
|
427
752
|
}
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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;
|
|
433
792
|
}
|
|
434
793
|
function safeProviderMcpData(item, serverName, toolName, status) {
|
|
435
794
|
const elapsedMs = numericField(item, "elapsed_ms") ?? numericField(item, "duration_ms");
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import type { RunOnceDispatchPacket, RunnerDispatchEvent } from "../session.types.js";
|
|
2
2
|
export type UsageSource = "provider_reported" | "cli_reported" | "estimated" | "unknown";
|
|
3
|
+
export type InputTokenSemantics = "includes_cached_input" | "excludes_cache_tokens" | "unknown";
|
|
4
|
+
export declare const PROVIDER_USAGE_SCHEMA_VERSION = 1;
|
|
3
5
|
/**
|
|
4
6
|
* Normalized, provider-agnostic token usage accumulated for a dispatch. Cost is never computed
|
|
5
|
-
* here; the API recomputes cost from these tokens x model rates (
|
|
7
|
+
* here; the API recomputes cost from these tokens x model rates (legacy
|
|
8
|
+
* ADR-0006, .forge-designer/decisions/legacy/0006-cost-capture.md).
|
|
6
9
|
*/
|
|
7
10
|
export interface ProviderUsage {
|
|
11
|
+
/** Normalized total input. Cached input is a subset, never an additive peer. */
|
|
8
12
|
readonly inputTokens: number;
|
|
13
|
+
readonly uncachedInputTokens: number | null;
|
|
9
14
|
readonly outputTokens: number;
|
|
10
15
|
readonly cacheReadTokens: number;
|
|
11
16
|
readonly cacheCreationTokens: number;
|
|
12
17
|
readonly reasoningOutputTokens: number;
|
|
13
18
|
readonly providerDurationMs: number | null;
|
|
14
19
|
readonly source: UsageSource;
|
|
20
|
+
readonly inputTokenSemantics: InputTokenSemantics;
|
|
21
|
+
/** Exact provider usage objects retained for audit/re-normalization. */
|
|
22
|
+
readonly rawUsage: readonly Record<string, unknown>[];
|
|
15
23
|
}
|
|
16
24
|
export declare function emptyUsage(source?: UsageSource): ProviderUsage;
|
|
17
25
|
export declare function addUsage(base: ProviderUsage, next: Partial<ProviderUsage>): ProviderUsage;
|
|
@@ -1,27 +1,38 @@
|
|
|
1
|
+
export const PROVIDER_USAGE_SCHEMA_VERSION = 1;
|
|
1
2
|
export function emptyUsage(source = "unknown") {
|
|
2
3
|
return {
|
|
3
4
|
inputTokens: 0,
|
|
5
|
+
uncachedInputTokens: 0,
|
|
4
6
|
outputTokens: 0,
|
|
5
7
|
cacheReadTokens: 0,
|
|
6
8
|
cacheCreationTokens: 0,
|
|
7
9
|
reasoningOutputTokens: 0,
|
|
8
10
|
providerDurationMs: null,
|
|
9
|
-
source
|
|
11
|
+
source,
|
|
12
|
+
inputTokenSemantics: "unknown",
|
|
13
|
+
rawUsage: []
|
|
10
14
|
};
|
|
11
15
|
}
|
|
12
16
|
export function addUsage(base, next) {
|
|
17
|
+
const nextUncached = next.uncachedInputTokens;
|
|
18
|
+
const uncachedInputTokens = base.uncachedInputTokens === null || nextUncached === null
|
|
19
|
+
? null
|
|
20
|
+
: base.uncachedInputTokens + nonNegative(nextUncached);
|
|
13
21
|
return {
|
|
14
22
|
inputTokens: base.inputTokens + nonNegative(next.inputTokens),
|
|
23
|
+
uncachedInputTokens,
|
|
15
24
|
outputTokens: base.outputTokens + nonNegative(next.outputTokens),
|
|
16
25
|
cacheReadTokens: base.cacheReadTokens + nonNegative(next.cacheReadTokens),
|
|
17
26
|
cacheCreationTokens: base.cacheCreationTokens + nonNegative(next.cacheCreationTokens),
|
|
18
27
|
reasoningOutputTokens: base.reasoningOutputTokens + nonNegative(next.reasoningOutputTokens),
|
|
19
28
|
providerDurationMs: next.providerDurationMs ?? base.providerDurationMs,
|
|
20
|
-
source: next.source ?? base.source
|
|
29
|
+
source: next.source ?? base.source,
|
|
30
|
+
inputTokenSemantics: mergeSemantics(base.inputTokenSemantics, next.inputTokenSemantics),
|
|
31
|
+
rawUsage: [...base.rawUsage, ...(next.rawUsage ?? [])]
|
|
21
32
|
};
|
|
22
33
|
}
|
|
23
34
|
export function totalTokens(usage) {
|
|
24
|
-
return usage.inputTokens + usage.outputTokens
|
|
35
|
+
return usage.inputTokens + usage.outputTokens;
|
|
25
36
|
}
|
|
26
37
|
export function hasUsage(usage) {
|
|
27
38
|
return usage !== null && totalTokens(usage) > 0;
|
|
@@ -37,20 +48,26 @@ export function buildProviderUsageEvent(dispatch, usage) {
|
|
|
37
48
|
lane: dispatch.execution.lane,
|
|
38
49
|
phase: dispatch.cycleRun.phase,
|
|
39
50
|
attempt: dispatch.cycleRun.attempt,
|
|
51
|
+
usage_schema_version: PROVIDER_USAGE_SCHEMA_VERSION,
|
|
52
|
+
input_token_semantics: usage.inputTokenSemantics,
|
|
40
53
|
input_tokens: usage.inputTokens,
|
|
54
|
+
uncached_input_tokens: usage.uncachedInputTokens,
|
|
41
55
|
output_tokens: usage.outputTokens,
|
|
42
56
|
cache_read_tokens: usage.cacheReadTokens,
|
|
43
57
|
cache_creation_tokens: usage.cacheCreationTokens,
|
|
44
58
|
reasoning_output_tokens: usage.reasoningOutputTokens,
|
|
45
59
|
metered: dispatch.execution.authKind === "api_key",
|
|
46
60
|
usage_source: usage.source,
|
|
47
|
-
provider_duration_ms: usage.providerDurationMs
|
|
61
|
+
provider_duration_ms: usage.providerDurationMs,
|
|
62
|
+
normalized_total_tokens: totalTokens(usage),
|
|
63
|
+
normalized_total_formula: "total_input + output; cached_input is a subset of total_input",
|
|
64
|
+
raw_usage: usage.rawUsage
|
|
48
65
|
};
|
|
49
66
|
const total = totalTokens(usage);
|
|
50
67
|
return {
|
|
51
68
|
role: "runner",
|
|
52
69
|
kind: "checkpoint",
|
|
53
|
-
content: `Provider usage: ${total} tokens (${usage.inputTokens} in / ${usage.outputTokens} out) for ${dispatch.execution.model}.`,
|
|
70
|
+
content: `Provider usage: ${total} tokens (${usage.inputTokens} total in, including ${usage.cacheReadTokens} cached / ${usage.outputTokens} out) for ${dispatch.execution.model}.`,
|
|
54
71
|
eventType: "provider_usage",
|
|
55
72
|
data: JSON.stringify(data)
|
|
56
73
|
};
|
|
@@ -62,3 +79,9 @@ export function readUsageNumber(source, key) {
|
|
|
62
79
|
function nonNegative(value) {
|
|
63
80
|
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
|
|
64
81
|
}
|
|
82
|
+
function mergeSemantics(base, next) {
|
|
83
|
+
if (!next || next === "unknown") {
|
|
84
|
+
return base;
|
|
85
|
+
}
|
|
86
|
+
return base === "unknown" || base === next ? next : "unknown";
|
|
87
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { ForgeFailureError } from "../session.types.js";
|
|
3
|
+
/** Providers whose user configuration the helpers below shut out. Any other provider is refused. */
|
|
4
|
+
export declare const userConfigIsolatedProviders: readonly string[];
|
|
5
|
+
/**
|
|
6
|
+
* Variables that choose where a provider CLI finds the user's configuration: Claude Code's config
|
|
7
|
+
* directory, and the home directory under which Claude reads `.claude` and `.claude.json` (HOME;
|
|
8
|
+
* USERPROFILE on Windows, which HOMEDRIVE and HOMEPATH resolve to when it is unset). Only the
|
|
9
|
+
* bridge's own environment sets them (provider-cli.child-environment.ts); a project's runtime
|
|
10
|
+
* environment can't, or it could point the provider at another user's configuration.
|
|
11
|
+
*/
|
|
12
|
+
export declare const providerConfigLocationVariables: readonly string[];
|
|
13
|
+
/** A strict MCP configuration with no servers, for Claude turns that get no Forge tools. */
|
|
14
|
+
export declare const emptyClaudeMcpConfig: string;
|
|
15
|
+
/**
|
|
16
|
+
* Claude Code launch arguments:
|
|
17
|
+
* - `--setting-sources project,local` drops the user settings source: `~/.claude/settings.json`
|
|
18
|
+
* (hooks, env, permissions, enabled and claude.ai-synced plugins), `~/.claude/CLAUDE.md`,
|
|
19
|
+
* user rules, skills, agents, commands and output styles.
|
|
20
|
+
* - `--mcp-config` plus `--strict-mcp-config` load only Forge's own MCP server (or none), never
|
|
21
|
+
* `~/.claude.json`, plugin or claude.ai connector servers.
|
|
22
|
+
*/
|
|
23
|
+
export declare function claudeUserConfigIsolationArgs(forgeMcpConfigPath?: string | null): readonly string[];
|
|
24
|
+
/**
|
|
25
|
+
* Claude Code settings, passed with `--settings`:
|
|
26
|
+
* - `claudeMdExcludes` drops the instruction files Claude Code reads from every directory above
|
|
27
|
+
* the working directory (the user's home and folders such as `~/Repos`). They belong to the
|
|
28
|
+
* host, not to the repository, and the project settings source would otherwise load them.
|
|
29
|
+
* - `autoMemoryEnabled: false`: without the user settings source auto memory falls back to its
|
|
30
|
+
* default, and its memory files accumulate outside the repository between sessions.
|
|
31
|
+
*/
|
|
32
|
+
export declare function claudeUserConfigIsolationSettings(workingDirectory: string, pathApi?: path.PlatformPath): Readonly<Record<string, unknown>>;
|
|
33
|
+
/**
|
|
34
|
+
* Every Claude Code agent launch: the isolation arguments, then one `--settings` value that carries
|
|
35
|
+
* the isolation settings and, for headless agent turns, the background-work restrictions with
|
|
36
|
+
* their tool deny list (`claude-background-work.ts`).
|
|
37
|
+
*/
|
|
38
|
+
export declare function claudeIsolatedLaunchArgs(options: {
|
|
39
|
+
readonly workingDirectory: string;
|
|
40
|
+
readonly forgeMcpConfigPath?: string | null;
|
|
41
|
+
readonly headless: boolean;
|
|
42
|
+
}): readonly string[];
|
|
43
|
+
/**
|
|
44
|
+
* Instruction-file patterns for each directory strictly above the working directory. Windows
|
|
45
|
+
* paths are listed both as written and with forward slashes, the form glob matchers expect.
|
|
46
|
+
*/
|
|
47
|
+
export declare function ancestorInstructionExcludes(workingDirectory: string, pathApi?: path.PlatformPath): readonly string[];
|
|
48
|
+
/**
|
|
49
|
+
* Codex reads `config.toml` (MCP servers, profiles, plugins), `AGENTS.md`, `AGENTS.override.md`,
|
|
50
|
+
* rules and skills from `CODEX_HOME`, so Forge runs it with a home of its own on each runner
|
|
51
|
+
* instead of the user's `~/.codex`. Codex's `--ignore-user-config` still loads the global
|
|
52
|
+
* `AGENTS.md`, so a separate home is the only full isolation. API-key turns authenticate through
|
|
53
|
+
* the environment; a local Codex CLI login is made once into this home
|
|
54
|
+
* (`CODEX_HOME=<path> codex login`).
|
|
55
|
+
*
|
|
56
|
+
* In a Forge sandbox container (`FORGE_RUNTIME_MODE=docker`) `~/.codex` is already Forge's own:
|
|
57
|
+
* an attempt-scoped volume that holds only the copied `auth.json` (sandbox/provider-auth/codex.ts).
|
|
58
|
+
*/
|
|
59
|
+
export declare function forgeCodexHome(homeDirectory?: string, environment?: NodeJS.ProcessEnv): string;
|
|
60
|
+
export declare function codexUserConfigIsolationEnv(homeDirectory?: string, environment?: NodeJS.ProcessEnv): Readonly<Record<string, string>>;
|
|
61
|
+
/** The provider environment that shuts out the user's own configuration. */
|
|
62
|
+
export declare function providerUserConfigIsolationEnv(provider: string, homeDirectory?: string, environment?: NodeJS.ProcessEnv): Readonly<Record<string, string>>;
|
|
63
|
+
/**
|
|
64
|
+
* cursor-agent has no flag or environment variable that keeps it from reading `~/.cursor`
|
|
65
|
+
* (`mcp.json`, `cli-config.json`, rules), and `--approve-mcps` would approve every server there;
|
|
66
|
+
* other CLIs are unknown. Forge refuses to launch them.
|
|
67
|
+
*/
|
|
68
|
+
export declare function providerUserConfigIsolationUnsupported(provider: string): ForgeFailureError;
|
|
69
|
+
export declare function isProviderUserConfigIsolated(provider: string): boolean;
|