@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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
1
2
|
import fs from "node:fs/promises";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { RepositoryCoordinatorLock } from "../sandbox/repository-lock.js";
|
|
@@ -5,14 +6,27 @@ import { GitClient } from "../shared/git/git.js";
|
|
|
5
6
|
import { ensureDirectory, isSubPath, resolveExistingDirectoryPath, safeSegment } from "../shared/path/path.js";
|
|
6
7
|
import { filterArtifactsForLane, injectWorktreeArtifacts } from "./artifact-injector.js";
|
|
7
8
|
import { hydratePriorPhaseArtifacts } from "./prior-phase-artifact-hydrator.js";
|
|
9
|
+
import { materializeStoryQaReferences } from "./story-qa-reference-hydrator.js";
|
|
8
10
|
import { warmWorktreeDependencies } from "./dependency-warmer.js";
|
|
11
|
+
import { guardBranchReset, guardWorktreeRelease, guardWorktreeReset, restoreWorktreeWip, settleSessionWip, sweepBranchesAfterRelease, worktreeReleased, } from "./worktree-wip.js";
|
|
9
12
|
import { defaultWorktreeCoordinatorStateRoot, managedRepoRoot, resolveManagedWorktreeRoot, } from "./worktree-paths.js";
|
|
13
|
+
export { emitWipRestoreEvent, sessionWipOutcome, settleWorktree } from "./worktree-wip-events.js";
|
|
14
|
+
// Bounds the branch sweep that runs after each release, so one release never holds the repository lock long.
|
|
15
|
+
const releaseSweepLimit = 25;
|
|
10
16
|
export class GitWorktreeService {
|
|
11
17
|
git;
|
|
12
18
|
coordinator;
|
|
13
|
-
|
|
19
|
+
hostLoadGate;
|
|
20
|
+
leaseStateRoot;
|
|
21
|
+
constructor(git = new GitClient(), coordinator = new RepositoryCoordinatorLock(defaultWorktreeCoordinatorStateRoot()),
|
|
22
|
+
/** Gates dependency install fallbacks; inert unless the governor is on. */
|
|
23
|
+
hostLoadGate,
|
|
24
|
+
/** Holds the host runtime lease ledger; branches of live leases are never swept on release. */
|
|
25
|
+
leaseStateRoot = defaultWorktreeCoordinatorStateRoot()) {
|
|
14
26
|
this.git = git;
|
|
15
27
|
this.coordinator = coordinator;
|
|
28
|
+
this.hostLoadGate = hostLoadGate;
|
|
29
|
+
this.leaseStateRoot = leaseStateRoot;
|
|
16
30
|
}
|
|
17
31
|
async prepare(request) {
|
|
18
32
|
const allowedRoot = await ensureDirectory(request.allowedRepoRoot);
|
|
@@ -27,7 +41,7 @@ export class GitWorktreeService {
|
|
|
27
41
|
const repoPath = await this.coordinator.withLock(creationCoordinationPath, async () => {
|
|
28
42
|
return await this.resolveRepoPath(request.repo, allowedRoot, baseBranch);
|
|
29
43
|
});
|
|
30
|
-
const resolvedWorktreePath = await this.coordinator.withLock(repoPath, async () => {
|
|
44
|
+
const { worktreePath: resolvedWorktreePath, wipRestore } = await this.coordinator.withLock(repoPath, async () => {
|
|
31
45
|
await this.ensureGitIdentity(repoPath);
|
|
32
46
|
const baseStartPoint = await this.resolveBaseStartPoint(repoPath, baseBranch);
|
|
33
47
|
const worktreeRoot = resolveManagedWorktreeRoot(allowedRoot, repoPath);
|
|
@@ -36,37 +50,68 @@ export class GitWorktreeService {
|
|
|
36
50
|
if (!isSubPath(allowedRoot, resolvedWorktreeParent)) {
|
|
37
51
|
throw new Error(`Worktree path must stay under ${allowedRoot}.`);
|
|
38
52
|
}
|
|
53
|
+
let selectedWorktreePath = worktreePath;
|
|
39
54
|
if (!(await directoryExists(worktreePath))) {
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
// A prior runner can disappear after Git registers its worktree but before
|
|
56
|
+
// normal cleanup completes. Release that missing-directory registration
|
|
57
|
+
// immediately so retrying the same lease remains idempotent.
|
|
58
|
+
await this.git.run(repoPath, ["worktree", "prune", "--expire", "now"]);
|
|
59
|
+
const registeredWorktreePath = await this.registeredManagedWorktreePath(repoPath, branchName, allowedRoot, worktreeSegments);
|
|
60
|
+
if (!registeredWorktreePath) {
|
|
61
|
+
const branchRef = `refs/heads/${branchName}`;
|
|
62
|
+
if (request.preserveExistingState && await this.gitRefExists(repoPath, branchRef)) {
|
|
63
|
+
// The checkout directory can disappear while its branch still
|
|
64
|
+
// contains completed agent work. Reattach that branch verbatim;
|
|
65
|
+
// `-B ... baseStartPoint` would silently reset it and lose progress.
|
|
66
|
+
await this.git.run(repoPath, ["worktree", "add", worktreePath, branchName]);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
await guardBranchReset(this.git, repoPath, branchName, baseStartPoint);
|
|
70
|
+
await this.git.run(repoPath, ["worktree", "add", "-B", branchName, worktreePath, baseStartPoint]);
|
|
71
|
+
}
|
|
72
|
+
return await this.withRestoredWip(request, repoPath, branchName, await resolveExistingDirectoryPath(worktreePath));
|
|
73
|
+
}
|
|
74
|
+
// The selected checkout can change when a Bridge reconnects or a local
|
|
75
|
+
// runner takes over. Its managed root therefore changes even though the
|
|
76
|
+
// deterministic lease branch does not. Reattach to the registered,
|
|
77
|
+
// Forge-owned worktree instead of trying to check out that branch twice.
|
|
78
|
+
selectedWorktreePath = registeredWorktreePath;
|
|
42
79
|
}
|
|
43
|
-
const existingWorktreePath = await resolveExistingDirectoryPath(
|
|
80
|
+
const existingWorktreePath = await resolveExistingDirectoryPath(selectedWorktreePath);
|
|
44
81
|
if (!isSubPath(allowedRoot, existingWorktreePath)) {
|
|
45
82
|
throw new Error(`Worktree path must stay under ${allowedRoot}.`);
|
|
46
83
|
}
|
|
84
|
+
if (!(await gitMetadataExists(existingWorktreePath, allowedRoot))) {
|
|
85
|
+
await this.restoreOrphanedWorktree({
|
|
86
|
+
repoPath,
|
|
87
|
+
worktreePath: existingWorktreePath,
|
|
88
|
+
branchName,
|
|
89
|
+
baseStartPoint,
|
|
90
|
+
allowedRoot,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
47
93
|
const currentBranch = await this.currentBranch(existingWorktreePath);
|
|
48
94
|
if (currentBranch !== branchName) {
|
|
49
95
|
throw new Error(`Existing worktree ${existingWorktreePath} is on branch '${currentBranch}', expected '${branchName}'.`);
|
|
50
96
|
}
|
|
51
|
-
if (shouldResetExistingWorktree(request)) {
|
|
97
|
+
if (!request.preserveExistingState && shouldResetExistingWorktree(request)) {
|
|
98
|
+
await guardWorktreeReset(existingWorktreePath, branchName, request);
|
|
52
99
|
await this.resetWorktreeToBase(existingWorktreePath, baseStartPoint);
|
|
53
100
|
}
|
|
54
|
-
return existingWorktreePath;
|
|
101
|
+
return await this.withRestoredWip(request, repoPath, branchName, existingWorktreePath);
|
|
55
102
|
});
|
|
56
|
-
|
|
57
|
-
await
|
|
103
|
+
// Reference inputs and an exact-tree local repair checkpoint must survive output cleanup.
|
|
104
|
+
await materializeStoryQaReferences(resolvedWorktreePath, request, this.git);
|
|
105
|
+
if (!request.preserveExistingState) {
|
|
106
|
+
await clearRunArtifactRoots(resolvedWorktreePath, request);
|
|
107
|
+
}
|
|
58
108
|
const hydratedPriorPhaseArtifactCount = await hydratePriorPhaseArtifacts(resolvedWorktreePath, request.priorPhaseArtifacts);
|
|
59
109
|
const qaReworkPacketPath = await materializeQaReworkPacket(resolvedWorktreePath, request);
|
|
60
110
|
const artifacts = filterArtifactsForLane(request.artifacts, request.lane, request.phase);
|
|
61
111
|
if (artifacts.length > 0) {
|
|
62
112
|
await injectWorktreeArtifacts(resolvedWorktreePath, artifacts, await this.trackedForgePaths(resolvedWorktreePath));
|
|
63
113
|
}
|
|
64
|
-
const dependencyWarm = await
|
|
65
|
-
baseCheckoutPath: repoPath,
|
|
66
|
-
worktreePath: resolvedWorktreePath,
|
|
67
|
-
allowedRoot,
|
|
68
|
-
warmPathOverrides: request.warmPathOverrides
|
|
69
|
-
});
|
|
114
|
+
const dependencyWarm = await this.warmDependencies(request, repoPath, resolvedWorktreePath, allowedRoot);
|
|
70
115
|
return {
|
|
71
116
|
repoPath,
|
|
72
117
|
worktreePath: resolvedWorktreePath,
|
|
@@ -75,13 +120,55 @@ export class GitWorktreeService {
|
|
|
75
120
|
cleanupWorktrees: request.cleanupWorktrees,
|
|
76
121
|
dependencyWarm,
|
|
77
122
|
qaReworkPacketPath,
|
|
78
|
-
hydratedPriorPhaseArtifactCount
|
|
123
|
+
hydratedPriorPhaseArtifactCount,
|
|
124
|
+
sessionId: request.sessionId ?? null,
|
|
125
|
+
lane: request.lane,
|
|
126
|
+
...(wipRestore ? { wipRestore } : {}),
|
|
79
127
|
};
|
|
80
128
|
}
|
|
129
|
+
async warmDependencies(request, repoPath, worktreePath, allowedRoot) {
|
|
130
|
+
if (!requiresMutableEnvironmentPreparation(request))
|
|
131
|
+
return undefined;
|
|
132
|
+
return await warmWorktreeDependencies({
|
|
133
|
+
baseCheckoutPath: repoPath,
|
|
134
|
+
worktreePath,
|
|
135
|
+
allowedRoot,
|
|
136
|
+
warmPathOverrides: request.warmPathOverrides,
|
|
137
|
+
hostLoad: this.hostLoadGate?.enabled
|
|
138
|
+
? {
|
|
139
|
+
gate: this.hostLoadGate,
|
|
140
|
+
dispatchAttemptId: request.hostLoadOwner?.dispatchAttemptId ?? null,
|
|
141
|
+
priority: request.hostLoadOwner?.priority ?? "foreground",
|
|
142
|
+
}
|
|
143
|
+
: undefined,
|
|
144
|
+
signal: request.signal,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/** Restores the story's saved WIP (still under the repository lock, before the provider starts). */
|
|
148
|
+
async withRestoredWip(request, repoPath, branchName, worktreePath) {
|
|
149
|
+
const wipRestore = await restoreWorktreeWip({ worktreePath, repoPath, branchName, sessionId: request.sessionId, lane: request.lane });
|
|
150
|
+
return { worktreePath, ...(wipRestore ? { wipRestore } : {}) };
|
|
151
|
+
}
|
|
152
|
+
async settleWip(handle, outcome) {
|
|
153
|
+
return await settleSessionWip(handle, outcome);
|
|
154
|
+
}
|
|
81
155
|
async trackedForgePaths(worktreePath) {
|
|
82
156
|
const output = await this.git.run(worktreePath, ["ls-files", "-z", "--", ".forge"]);
|
|
83
157
|
return new Set(output.split("\0").filter(Boolean).map(value => value.replaceAll("\\", "/")));
|
|
84
158
|
}
|
|
159
|
+
async registeredManagedWorktreePath(repoPath, branchName, allowedRoot, worktreeSegments) {
|
|
160
|
+
const listing = await this.git.run(repoPath, ["worktree", "list", "--porcelain", "-z"]);
|
|
161
|
+
const registered = parseRegisteredWorktrees(repoPath, listing)
|
|
162
|
+
.find(entry => entry.branchName === `refs/heads/${branchName}`);
|
|
163
|
+
if (!registered) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
const resolved = await resolveExistingDirectoryPath(registered.worktreePath);
|
|
167
|
+
if (!isManagedLeaseWorktreePath(allowedRoot, resolved, worktreeSegments)) {
|
|
168
|
+
throw new Error(`Branch '${branchName}' is already checked out outside its Forge-managed lease path at ${resolved}.`);
|
|
169
|
+
}
|
|
170
|
+
return resolved;
|
|
171
|
+
}
|
|
85
172
|
repoCreationCoordinationPath(repo, allowedRoot) {
|
|
86
173
|
if (repo.serverLocalPath && repo.serverLocalPath.trim().length > 0) {
|
|
87
174
|
return path.resolve(repo.serverLocalPath);
|
|
@@ -93,18 +180,67 @@ export class GitWorktreeService {
|
|
|
93
180
|
return;
|
|
94
181
|
}
|
|
95
182
|
await this.coordinator.withLock(handle.repoPath, async () => {
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
183
|
+
if (await directoryExists(handle.worktreePath)) {
|
|
184
|
+
// Never delete work that could not be saved: this throws and keeps the worktree.
|
|
185
|
+
await guardWorktreeRelease(handle);
|
|
186
|
+
// On Windows, `git worktree remove` can delete the `.git` link and then
|
|
187
|
+
// fail on a locked build output. That leaves a full source tree which is
|
|
188
|
+
// no longer a Git worktree and makes every retry fail during prepare.
|
|
189
|
+
// Move the tree out of its stable lease path first. If the rename fails,
|
|
190
|
+
// leave the valid worktree untouched rather than partially unregistering it.
|
|
191
|
+
const releasePath = `${handle.worktreePath}.forge-release-${randomUUID()}`;
|
|
192
|
+
await renameWorktreeForRelease(handle.worktreePath, releasePath);
|
|
193
|
+
await this.git.run(handle.repoPath, ["worktree", "prune", "--expire", "now"]);
|
|
194
|
+
await fs.rm(releasePath, {
|
|
195
|
+
recursive: true,
|
|
196
|
+
force: true,
|
|
197
|
+
maxRetries: 10,
|
|
198
|
+
retryDelay: 100,
|
|
199
|
+
}).catch(() => undefined);
|
|
105
200
|
}
|
|
201
|
+
// The process can disappear after Git registers a worktree but before the
|
|
202
|
+
// directory is fully materialized (or after an external cleanup removes it).
|
|
203
|
+
// Always prune so those missing-directory registrations do not accumulate.
|
|
204
|
+
await this.git.run(handle.repoPath, ["worktree", "prune", "--expire", "now"]).catch(() => undefined);
|
|
205
|
+
worktreeReleased(handle);
|
|
206
|
+
// A readiness probe's branch goes with its worktree. Other Forge branches on this device
|
|
207
|
+
// whose work is already merged into the base go too; branches with unmerged work stay.
|
|
208
|
+
// A lease can be live while its worktree is briefly missing, so its branch is protected
|
|
209
|
+
// even when no worktree has it checked out. If the ledger can't be read, sweep nothing.
|
|
210
|
+
await sweepBranchesAfterRelease(this.git, handle, this.leaseStateRoot, releaseSweepLimit);
|
|
106
211
|
});
|
|
107
212
|
}
|
|
213
|
+
async restoreOrphanedWorktree(input) {
|
|
214
|
+
const orphanStat = await fs.lstat(input.worktreePath);
|
|
215
|
+
if (orphanStat.isSymbolicLink() || !orphanStat.isDirectory()) {
|
|
216
|
+
throw new Error(`Refusing to recover redirected or non-directory worktree ${input.worktreePath}.`);
|
|
217
|
+
}
|
|
218
|
+
const quarantinePath = `${input.worktreePath}.forge-orphan-${randomUUID()}`;
|
|
219
|
+
if (!isSubPath(input.allowedRoot, quarantinePath)) {
|
|
220
|
+
throw new Error(`Worktree recovery path must stay under ${input.allowedRoot}.`);
|
|
221
|
+
}
|
|
222
|
+
await guardBranchReset(this.git, input.repoPath, input.branchName, input.baseStartPoint);
|
|
223
|
+
await fs.rename(input.worktreePath, quarantinePath);
|
|
224
|
+
try {
|
|
225
|
+
await this.git.run(input.repoPath, ["worktree", "prune", "--expire", "now"]);
|
|
226
|
+
await this.git.run(input.repoPath, [
|
|
227
|
+
"worktree",
|
|
228
|
+
"add",
|
|
229
|
+
"-B",
|
|
230
|
+
input.branchName,
|
|
231
|
+
input.worktreePath,
|
|
232
|
+
input.baseStartPoint,
|
|
233
|
+
]);
|
|
234
|
+
await overlayOrphanedWorktree(input.worktreePath, quarantinePath);
|
|
235
|
+
await fs.rm(quarantinePath, { recursive: true, force: true });
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
await this.git.run(input.repoPath, ["worktree", "remove", "--force", input.worktreePath]).catch(() => undefined);
|
|
239
|
+
await fs.rm(input.worktreePath, { recursive: true, force: true }).catch(() => undefined);
|
|
240
|
+
await fs.rename(quarantinePath, input.worktreePath).catch(() => undefined);
|
|
241
|
+
throw new Error(`Failed to recover orphaned worktree ${input.worktreePath}.`, { cause: error });
|
|
242
|
+
}
|
|
243
|
+
}
|
|
108
244
|
async resolveRepoPath(repo, allowedRoot, baseBranch) {
|
|
109
245
|
if (repo.serverLocalPath && repo.serverLocalPath.trim().length > 0) {
|
|
110
246
|
const requestedPath = await resolveExistingDirectoryPath(repo.serverLocalPath);
|
|
@@ -233,6 +369,32 @@ export class GitWorktreeService {
|
|
|
233
369
|
await this.git.run(repoPath, ["config", "user.name", "Forge Bridge"]);
|
|
234
370
|
}
|
|
235
371
|
}
|
|
372
|
+
export async function renameWorktreeForRelease(source, destination, rename = fs.rename, wait = milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds)), maxAttempts = 8) {
|
|
373
|
+
const attempts = Number.isFinite(maxAttempts) && maxAttempts > 0
|
|
374
|
+
? Math.max(1, Math.floor(maxAttempts))
|
|
375
|
+
: 1;
|
|
376
|
+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
377
|
+
try {
|
|
378
|
+
await rename(source, destination);
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
catch (error) {
|
|
382
|
+
if (!isTransientWorktreeRenameError(error) || attempt === attempts)
|
|
383
|
+
throw error;
|
|
384
|
+
await wait(Math.min(1_000, 100 * (2 ** (attempt - 1))));
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
function isTransientWorktreeRenameError(error) {
|
|
389
|
+
if (!error || typeof error !== "object" || !("code" in error))
|
|
390
|
+
return false;
|
|
391
|
+
const code = String(error.code ?? "").toUpperCase();
|
|
392
|
+
return code === "EPERM" || code === "EACCES" || code === "EBUSY" || code === "ENOTEMPTY";
|
|
393
|
+
}
|
|
394
|
+
export function requiresMutableEnvironmentPreparation(request) {
|
|
395
|
+
// Missing runtime intent is treated conservatively for older dispatch packets.
|
|
396
|
+
return request.applicationRuntimeRequired !== false;
|
|
397
|
+
}
|
|
236
398
|
function isCloneableRemote(remoteUrl) {
|
|
237
399
|
const trimmed = remoteUrl?.trim() ?? "";
|
|
238
400
|
if (trimmed.length === 0 || trimmed.startsWith("local://")) {
|
|
@@ -317,6 +479,121 @@ function shouldResetExistingWorktree(request) {
|
|
|
317
479
|
}
|
|
318
480
|
return true;
|
|
319
481
|
}
|
|
482
|
+
function parseRegisteredWorktrees(repoPath, output) {
|
|
483
|
+
const worktrees = [];
|
|
484
|
+
let current = null;
|
|
485
|
+
for (const field of output.split("\0")) {
|
|
486
|
+
if (field.startsWith("worktree ")) {
|
|
487
|
+
if (current)
|
|
488
|
+
worktrees.push(current);
|
|
489
|
+
const rawPath = field.slice("worktree ".length);
|
|
490
|
+
current = {
|
|
491
|
+
worktreePath: path.resolve(path.isAbsolute(rawPath) ? rawPath : path.join(repoPath, rawPath)),
|
|
492
|
+
branchName: null,
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
else if (field.startsWith("branch ") && current) {
|
|
496
|
+
current.branchName = field.slice("branch ".length).trim();
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
if (current)
|
|
500
|
+
worktrees.push(current);
|
|
501
|
+
return worktrees;
|
|
502
|
+
}
|
|
503
|
+
function isManagedLeaseWorktreePath(allowedRoot, candidate, worktreeSegments) {
|
|
504
|
+
if (!isSubPath(allowedRoot, candidate)) {
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
const relativeSegments = path.relative(path.resolve(allowedRoot), path.resolve(candidate))
|
|
508
|
+
.split(path.sep)
|
|
509
|
+
.filter(Boolean);
|
|
510
|
+
const normalize = (value) => process.platform === "win32" ? value.toLowerCase() : value;
|
|
511
|
+
if (normalize(relativeSegments[0] ?? "") !== ".forge-worktrees"
|
|
512
|
+
|| relativeSegments.length !== 2 + worktreeSegments.length) {
|
|
513
|
+
return false;
|
|
514
|
+
}
|
|
515
|
+
const suffix = relativeSegments.slice(-worktreeSegments.length).map(normalize);
|
|
516
|
+
return suffix.every((segment, index) => segment === normalize(worktreeSegments[index] ?? ""));
|
|
517
|
+
}
|
|
518
|
+
async function overlayOrphanedWorktree(worktreePath, orphanPath) {
|
|
519
|
+
// A failed Windows cleanup can remove only part of a worktree before its
|
|
520
|
+
// `.git` link disappears. Start from Git's clean checkout so missing tracked
|
|
521
|
+
// files are restored, then overlay every surviving agent file. Moving entries
|
|
522
|
+
// on the same volume preserves pnpm junctions without requiring symlink
|
|
523
|
+
// privileges, unlike fs.cp.
|
|
524
|
+
const backupRoot = `${worktreePath}.forge-base-${randomUUID()}`;
|
|
525
|
+
const moves = [];
|
|
526
|
+
try {
|
|
527
|
+
await fs.mkdir(backupRoot, { recursive: true });
|
|
528
|
+
const orphanEntries = await fs.readdir(orphanPath, { withFileTypes: true });
|
|
529
|
+
for (const entry of orphanEntries) {
|
|
530
|
+
if (entry.name === ".git") {
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
await overlayEntry({
|
|
534
|
+
sourcePath: path.join(orphanPath, entry.name),
|
|
535
|
+
destinationPath: path.join(worktreePath, entry.name),
|
|
536
|
+
backupPath: path.join(backupRoot, entry.name),
|
|
537
|
+
moves,
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
await fs.rm(backupRoot, { recursive: true, force: true });
|
|
541
|
+
}
|
|
542
|
+
catch (error) {
|
|
543
|
+
for (const move of moves.reverse()) {
|
|
544
|
+
await fs.mkdir(path.dirname(move.sourcePath), { recursive: true }).catch(() => undefined);
|
|
545
|
+
await fs.rename(move.destinationPath, move.sourcePath).catch(() => undefined);
|
|
546
|
+
if (move.backupPath) {
|
|
547
|
+
await fs.mkdir(path.dirname(move.destinationPath), { recursive: true }).catch(() => undefined);
|
|
548
|
+
await fs.rename(move.backupPath, move.destinationPath).catch(() => undefined);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
await fs.rm(backupRoot, { recursive: true, force: true }).catch(() => undefined);
|
|
552
|
+
throw error;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
async function overlayEntry(input) {
|
|
556
|
+
const sourceStat = await fs.lstat(input.sourcePath);
|
|
557
|
+
const destinationStat = await fs.lstat(input.destinationPath).catch(() => null);
|
|
558
|
+
if (sourceStat.isDirectory() &&
|
|
559
|
+
!sourceStat.isSymbolicLink() &&
|
|
560
|
+
destinationStat?.isDirectory() &&
|
|
561
|
+
!destinationStat.isSymbolicLink()) {
|
|
562
|
+
const entries = await fs.readdir(input.sourcePath, { withFileTypes: true });
|
|
563
|
+
for (const entry of entries) {
|
|
564
|
+
await overlayEntry({
|
|
565
|
+
sourcePath: path.join(input.sourcePath, entry.name),
|
|
566
|
+
destinationPath: path.join(input.destinationPath, entry.name),
|
|
567
|
+
backupPath: path.join(input.backupPath, entry.name),
|
|
568
|
+
moves: input.moves,
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
let preservedBasePath;
|
|
574
|
+
if (destinationStat) {
|
|
575
|
+
await fs.mkdir(path.dirname(input.backupPath), { recursive: true });
|
|
576
|
+
await fs.rename(input.destinationPath, input.backupPath);
|
|
577
|
+
preservedBasePath = input.backupPath;
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
await fs.mkdir(path.dirname(input.destinationPath), { recursive: true });
|
|
581
|
+
}
|
|
582
|
+
try {
|
|
583
|
+
await fs.rename(input.sourcePath, input.destinationPath);
|
|
584
|
+
}
|
|
585
|
+
catch (error) {
|
|
586
|
+
if (preservedBasePath) {
|
|
587
|
+
await fs.rename(preservedBasePath, input.destinationPath).catch(() => undefined);
|
|
588
|
+
}
|
|
589
|
+
throw error;
|
|
590
|
+
}
|
|
591
|
+
input.moves.push({
|
|
592
|
+
sourcePath: input.sourcePath,
|
|
593
|
+
destinationPath: input.destinationPath,
|
|
594
|
+
backupPath: preservedBasePath,
|
|
595
|
+
});
|
|
596
|
+
}
|
|
320
597
|
function qaReworkPacketFileName(packetPath) {
|
|
321
598
|
const normalized = packetPath.trim().replace(/\\/g, "/");
|
|
322
599
|
const fileName = normalized.split("/").filter(Boolean).at(-1) ?? "";
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type { DispatchQaReworkContext, DispatchPriorPhaseArtifact, DispatchRepo, DispatchWorkItem, DispatchResolvedArtifact } from "../session/session.types.js";
|
|
1
|
+
import type { DispatchQaReworkContext, DispatchPriorPhaseArtifact, DispatchRepo, DispatchWorkItem, DispatchResolvedArtifact, DispatchStoryQaContext } from "../session/session.types.js";
|
|
2
2
|
import type { WarmDependenciesResult } from "./dependency-warmer.js";
|
|
3
|
+
import type { WipSnapshotReason } from "./wip-refs.js";
|
|
4
|
+
import type { WipRestoreOutcome } from "./wip-restore.js";
|
|
5
|
+
import type { WipSnapshotResult } from "./wip-snapshot.js";
|
|
3
6
|
export interface WorktreePrepareRequest {
|
|
4
7
|
readonly repo: DispatchRepo;
|
|
5
8
|
readonly workItem: DispatchWorkItem;
|
|
@@ -13,8 +16,23 @@ export interface WorktreePrepareRequest {
|
|
|
13
16
|
readonly cleanupWorktrees: boolean;
|
|
14
17
|
readonly artifacts: readonly DispatchResolvedArtifact[];
|
|
15
18
|
readonly priorPhaseArtifacts?: readonly DispatchPriorPhaseArtifact[];
|
|
19
|
+
readonly storyQa?: DispatchStoryQaContext | null;
|
|
20
|
+
readonly referenceRunId?: string;
|
|
21
|
+
readonly referenceCycleRunId?: string;
|
|
22
|
+
readonly effectivePlanAmendmentHash?: string | null;
|
|
16
23
|
readonly qaRework?: DispatchQaReworkContext | null;
|
|
17
24
|
readonly warmPathOverrides?: readonly string[];
|
|
25
|
+
readonly applicationRuntimeRequired?: boolean;
|
|
26
|
+
readonly preserveExistingState?: boolean;
|
|
27
|
+
/** The session this worktree is prepared for; names its WIP snapshots and enables restoring one. */
|
|
28
|
+
readonly sessionId?: string | null;
|
|
29
|
+
/** The attempt dependency installs reserve host capacity for (decision 0013). */
|
|
30
|
+
readonly hostLoadOwner?: {
|
|
31
|
+
readonly dispatchAttemptId: string | null;
|
|
32
|
+
readonly priority: "foreground" | "background";
|
|
33
|
+
};
|
|
34
|
+
/** The attempt's cancellation: queued installs stop waiting and running ones are stopped. */
|
|
35
|
+
readonly signal?: AbortSignal;
|
|
18
36
|
}
|
|
19
37
|
export interface WorktreeHandle {
|
|
20
38
|
readonly repoPath: string;
|
|
@@ -25,4 +43,21 @@ export interface WorktreeHandle {
|
|
|
25
43
|
readonly dependencyWarm?: WarmDependenciesResult;
|
|
26
44
|
readonly qaReworkPacketPath?: string;
|
|
27
45
|
readonly hydratedPriorPhaseArtifactCount?: number;
|
|
46
|
+
readonly sessionId?: string | null;
|
|
47
|
+
readonly lane?: string;
|
|
48
|
+
/** What happened to the story's saved WIP when this worktree was prepared. */
|
|
49
|
+
readonly wipRestore?: WipRestoreOutcome;
|
|
50
|
+
}
|
|
51
|
+
/** How a session ended, for its WIP snapshot: null when it succeeded. */
|
|
52
|
+
export interface WipSessionOutcome {
|
|
53
|
+
readonly reason: WipSnapshotReason | null;
|
|
54
|
+
}
|
|
55
|
+
export interface WipSettlement {
|
|
56
|
+
readonly snapshot?: WipSnapshotResult;
|
|
57
|
+
readonly error?: {
|
|
58
|
+
readonly code: string;
|
|
59
|
+
readonly message: string;
|
|
60
|
+
};
|
|
61
|
+
/** The restored snapshot's ref, deleted because this session's work supersedes it. */
|
|
62
|
+
readonly retiredRef?: string | null;
|
|
28
63
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loucompanion/forge-bridge",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4-dev.0098fdb4e213",
|
|
4
4
|
"description": "Forge runner bridge CLI for connecting local developer machines to Forge dispatch.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -32,17 +32,18 @@
|
|
|
32
32
|
"url": "https://github.com/coleman399/Forge/issues"
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
|
35
|
-
"node": "
|
|
35
|
+
"node": "^22.13.0 || >=24.0.0"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsc -p tsconfig.json",
|
|
42
|
-
"test": "
|
|
42
|
+
"test": "node scripts/run-owned-tests.mjs",
|
|
43
|
+
"test:residue": "node scripts/run-owned-residue-gate.mjs",
|
|
43
44
|
"test:watch": "vitest",
|
|
44
|
-
"smoke:package": "
|
|
45
|
-
"lint": "eslint \"src/**/*.ts\" \"scripts/**/*.mjs\" \"vitest.config.ts\" \"vitest.setup.ts\""
|
|
45
|
+
"smoke:package": "tsc -p tsconfig.json && node scripts/smoke-package.mjs",
|
|
46
|
+
"lint": "eslint \"src/**/*.ts\" \"scripts/**/*.mjs\" \"vitest.config.ts\" \"vitest.setup.ts\" && node ../../scripts/class-design/check-eslint-ratchet.mjs bridge"
|
|
46
47
|
},
|
|
47
48
|
"dependencies": {
|
|
48
49
|
"@microsoft/signalr": "^8.0.17",
|
|
@@ -55,6 +56,7 @@
|
|
|
55
56
|
"globals": "^17.6.0",
|
|
56
57
|
"typescript": "^5.8.3",
|
|
57
58
|
"typescript-eslint": "^8.61.1",
|
|
58
|
-
"
|
|
59
|
+
"vite": "^7.3.7",
|
|
60
|
+
"vitest": "^4.1.12"
|
|
59
61
|
}
|
|
60
62
|
}
|