@loucompanion/forge-bridge 0.1.3-dev.fbe15023cdfe → 0.1.4-dev.03584818ede5
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 +146 -5
- package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
- package/dist/bridge/bridge-chat-provider-command.js +137 -0
- package/dist/bridge/bridge-chat.types.d.ts +121 -0
- package/dist/bridge/bridge-chat.types.js +416 -0
- package/dist/bridge/bridge.base.d.ts +13 -1
- package/dist/bridge/bridge.service.d.ts +155 -4
- package/dist/bridge/bridge.service.js +1805 -155
- package/dist/bridge/bridge.types.d.ts +68 -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/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 +21 -0
- package/dist/bridge/readiness-result-outbox.js +54 -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/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup.service.d.ts +10 -0
- package/dist/cleanup/cleanup.service.js +128 -104
- package/dist/cleanup/cleanup.types.d.ts +4 -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 +5 -0
- package/dist/cleanup/host-runtime-ledger.js +109 -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 +22 -4
- package/dist/cli/cli.service.d.ts +30 -6
- package/dist/cli/cli.service.js +216 -31
- package/dist/cli/local-config.d.ts +5 -0
- package/dist/cli/local-config.js +30 -4
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +36 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +429 -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 +90 -0
- package/dist/runtime/docker-engine-probe.js +333 -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 +184 -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 +185 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +78 -0
- package/dist/runtime/host-load-sampler.d.ts +149 -0
- package/dist/runtime/host-load-sampler.js +291 -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 +16 -1
- package/dist/runtime/host-runtime-contract.js +174 -56
- package/dist/runtime/host-runtime-lease.d.ts +163 -9
- package/dist/runtime/host-runtime-lease.js +1464 -121
- 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 +607 -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 +25 -0
- package/dist/runtime/native-test-postgres-fallback.js +91 -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 +100 -0
- package/dist/runtime/runner-settings.js +214 -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 +113 -0
- package/dist/sandbox/host-capacity-broker.js +334 -0
- package/dist/sandbox/preflight.d.ts +31 -1
- package/dist/sandbox/preflight.js +237 -51
- 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 +182 -109
- 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 +44 -1
- package/dist/session/managed-attempt-tools.js +816 -46
- 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 +21 -0
- package/dist/session/managed-build-receipt.js +337 -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 +319 -44
- 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 +15 -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 +18 -3
- package/dist/session/phase-completion.prompts.js +22 -18
- package/dist/session/phase-completion.runtime.d.ts +6 -2
- package/dist/session/phase-completion.runtime.js +191 -47
- 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-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 +11 -0
- package/dist/session/pre-publication-step-execution.js +49 -0
- package/dist/session/pre-publication-validation.d.ts +87 -0
- package/dist/session/pre-publication-validation.js +668 -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 +66 -0
- package/dist/session/provider-cli/claude-background-work.js +180 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
- package/dist/session/provider-cli/pre-publication-repair.js +243 -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 +73 -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 +92 -14
- package/dist/session/provider-cli/provider-cli.process.js +583 -210
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +12 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +200 -25
- 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 +14 -1
- package/dist/session/provider-cli/provider-cli.runtime.js +61 -3
- package/dist/session/provider-cli/provider-cli.service.d.ts +33 -5
- package/dist/session/provider-cli/provider-cli.service.js +819 -84
- 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-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/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
- package/dist/session/sandbox-host-capacity-gate.js +238 -0
- package/dist/session/session-redaction.js +434 -9
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +9 -2
- package/dist/session/session.service.js +264 -27
- package/dist/session/session.types.d.ts +150 -2
- package/dist/session/session.types.js +599 -7
- 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/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.js +3 -2
- package/dist/shared/process/host-process-supervisor.d.ts +3 -0
- package/dist/shared/process/host-process-supervisor.js +61 -12
- 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 +84 -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/worktree.service.d.ts +17 -1
- package/dist/worktree/worktree.service.js +293 -21
- package/dist/worktree/worktree.types.d.ts +14 -1
- package/package.json +8 -6
- package/runtime/windows-job-supervisor.ps1 +380 -14
|
@@ -1,18 +1,32 @@
|
|
|
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";
|
|
4
5
|
import { GitClient } from "../shared/git/git.js";
|
|
6
|
+
import { liveLeaseBranches, readHostRuntimeLeases } from "../cleanup/host-runtime-ledger.js";
|
|
7
|
+
import { deleteBranchIfUnused, isRuntimeReadinessBranch, sweepManagedBranches } from "../cleanup/managed-branch-sweep.js";
|
|
5
8
|
import { ensureDirectory, isSubPath, resolveExistingDirectoryPath, safeSegment } from "../shared/path/path.js";
|
|
6
9
|
import { filterArtifactsForLane, injectWorktreeArtifacts } from "./artifact-injector.js";
|
|
7
10
|
import { hydratePriorPhaseArtifacts } from "./prior-phase-artifact-hydrator.js";
|
|
11
|
+
import { materializeStoryQaReferences } from "./story-qa-reference-hydrator.js";
|
|
8
12
|
import { warmWorktreeDependencies } from "./dependency-warmer.js";
|
|
9
13
|
import { defaultWorktreeCoordinatorStateRoot, managedRepoRoot, resolveManagedWorktreeRoot, } from "./worktree-paths.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);
|
|
@@ -36,37 +50,81 @@ 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 this.git.run(repoPath, ["worktree", "add", "-B", branchName, worktreePath, baseStartPoint]);
|
|
70
|
+
}
|
|
71
|
+
return await resolveExistingDirectoryPath(worktreePath);
|
|
72
|
+
}
|
|
73
|
+
// The selected checkout can change when a Bridge reconnects or a local
|
|
74
|
+
// runner takes over. Its managed root therefore changes even though the
|
|
75
|
+
// deterministic lease branch does not. Reattach to the registered,
|
|
76
|
+
// Forge-owned worktree instead of trying to check out that branch twice.
|
|
77
|
+
selectedWorktreePath = registeredWorktreePath;
|
|
42
78
|
}
|
|
43
|
-
const existingWorktreePath = await resolveExistingDirectoryPath(
|
|
79
|
+
const existingWorktreePath = await resolveExistingDirectoryPath(selectedWorktreePath);
|
|
44
80
|
if (!isSubPath(allowedRoot, existingWorktreePath)) {
|
|
45
81
|
throw new Error(`Worktree path must stay under ${allowedRoot}.`);
|
|
46
82
|
}
|
|
83
|
+
if (!(await gitMetadataExists(existingWorktreePath, allowedRoot))) {
|
|
84
|
+
await this.restoreOrphanedWorktree({
|
|
85
|
+
repoPath,
|
|
86
|
+
worktreePath: existingWorktreePath,
|
|
87
|
+
branchName,
|
|
88
|
+
baseStartPoint,
|
|
89
|
+
allowedRoot,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
47
92
|
const currentBranch = await this.currentBranch(existingWorktreePath);
|
|
48
93
|
if (currentBranch !== branchName) {
|
|
49
94
|
throw new Error(`Existing worktree ${existingWorktreePath} is on branch '${currentBranch}', expected '${branchName}'.`);
|
|
50
95
|
}
|
|
51
|
-
if (shouldResetExistingWorktree(request)) {
|
|
96
|
+
if (!request.preserveExistingState && shouldResetExistingWorktree(request)) {
|
|
52
97
|
await this.resetWorktreeToBase(existingWorktreePath, baseStartPoint);
|
|
53
98
|
}
|
|
54
99
|
return existingWorktreePath;
|
|
55
100
|
});
|
|
56
|
-
|
|
57
|
-
await
|
|
101
|
+
// Reference inputs and an exact-tree local repair checkpoint must survive output cleanup.
|
|
102
|
+
await materializeStoryQaReferences(resolvedWorktreePath, request, this.git);
|
|
103
|
+
if (!request.preserveExistingState) {
|
|
104
|
+
await clearRunArtifactRoots(resolvedWorktreePath, request);
|
|
105
|
+
}
|
|
58
106
|
const hydratedPriorPhaseArtifactCount = await hydratePriorPhaseArtifacts(resolvedWorktreePath, request.priorPhaseArtifacts);
|
|
59
107
|
const qaReworkPacketPath = await materializeQaReworkPacket(resolvedWorktreePath, request);
|
|
60
108
|
const artifacts = filterArtifactsForLane(request.artifacts, request.lane, request.phase);
|
|
61
109
|
if (artifacts.length > 0) {
|
|
62
110
|
await injectWorktreeArtifacts(resolvedWorktreePath, artifacts, await this.trackedForgePaths(resolvedWorktreePath));
|
|
63
111
|
}
|
|
64
|
-
const dependencyWarm =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
112
|
+
const dependencyWarm = requiresMutableEnvironmentPreparation(request)
|
|
113
|
+
? await warmWorktreeDependencies({
|
|
114
|
+
baseCheckoutPath: repoPath,
|
|
115
|
+
worktreePath: resolvedWorktreePath,
|
|
116
|
+
allowedRoot,
|
|
117
|
+
warmPathOverrides: request.warmPathOverrides,
|
|
118
|
+
hostLoad: this.hostLoadGate?.enabled
|
|
119
|
+
? {
|
|
120
|
+
gate: this.hostLoadGate,
|
|
121
|
+
dispatchAttemptId: request.hostLoadOwner?.dispatchAttemptId ?? null,
|
|
122
|
+
priority: request.hostLoadOwner?.priority ?? "foreground",
|
|
123
|
+
}
|
|
124
|
+
: undefined,
|
|
125
|
+
signal: request.signal,
|
|
126
|
+
})
|
|
127
|
+
: undefined;
|
|
70
128
|
return {
|
|
71
129
|
repoPath,
|
|
72
130
|
worktreePath: resolvedWorktreePath,
|
|
@@ -82,6 +140,19 @@ export class GitWorktreeService {
|
|
|
82
140
|
const output = await this.git.run(worktreePath, ["ls-files", "-z", "--", ".forge"]);
|
|
83
141
|
return new Set(output.split("\0").filter(Boolean).map(value => value.replaceAll("\\", "/")));
|
|
84
142
|
}
|
|
143
|
+
async registeredManagedWorktreePath(repoPath, branchName, allowedRoot, worktreeSegments) {
|
|
144
|
+
const listing = await this.git.run(repoPath, ["worktree", "list", "--porcelain", "-z"]);
|
|
145
|
+
const registered = parseRegisteredWorktrees(repoPath, listing)
|
|
146
|
+
.find(entry => entry.branchName === `refs/heads/${branchName}`);
|
|
147
|
+
if (!registered) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
const resolved = await resolveExistingDirectoryPath(registered.worktreePath);
|
|
151
|
+
if (!isManagedLeaseWorktreePath(allowedRoot, resolved, worktreeSegments)) {
|
|
152
|
+
throw new Error(`Branch '${branchName}' is already checked out outside its Forge-managed lease path at ${resolved}.`);
|
|
153
|
+
}
|
|
154
|
+
return resolved;
|
|
155
|
+
}
|
|
85
156
|
repoCreationCoordinationPath(repo, allowedRoot) {
|
|
86
157
|
if (repo.serverLocalPath && repo.serverLocalPath.trim().length > 0) {
|
|
87
158
|
return path.resolve(repo.serverLocalPath);
|
|
@@ -93,18 +164,78 @@ export class GitWorktreeService {
|
|
|
93
164
|
return;
|
|
94
165
|
}
|
|
95
166
|
await this.coordinator.withLock(handle.repoPath, async () => {
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
167
|
+
if (await directoryExists(handle.worktreePath)) {
|
|
168
|
+
// On Windows, `git worktree remove` can delete the `.git` link and then
|
|
169
|
+
// fail on a locked build output. That leaves a full source tree which is
|
|
170
|
+
// no longer a Git worktree and makes every retry fail during prepare.
|
|
171
|
+
// Move the tree out of its stable lease path first. If the rename fails,
|
|
172
|
+
// leave the valid worktree untouched rather than partially unregistering it.
|
|
173
|
+
const releasePath = `${handle.worktreePath}.forge-release-${randomUUID()}`;
|
|
174
|
+
await renameWorktreeForRelease(handle.worktreePath, releasePath);
|
|
175
|
+
await this.git.run(handle.repoPath, ["worktree", "prune", "--expire", "now"]);
|
|
176
|
+
await fs.rm(releasePath, {
|
|
177
|
+
recursive: true,
|
|
178
|
+
force: true,
|
|
179
|
+
maxRetries: 10,
|
|
180
|
+
retryDelay: 100,
|
|
181
|
+
}).catch(() => undefined);
|
|
102
182
|
}
|
|
103
|
-
|
|
104
|
-
|
|
183
|
+
// The process can disappear after Git registers a worktree but before the
|
|
184
|
+
// directory is fully materialized (or after an external cleanup removes it).
|
|
185
|
+
// Always prune so those missing-directory registrations do not accumulate.
|
|
186
|
+
await this.git.run(handle.repoPath, ["worktree", "prune", "--expire", "now"]).catch(() => undefined);
|
|
187
|
+
// A readiness probe's branch goes with its worktree. Other Forge branches on this device
|
|
188
|
+
// whose work is already merged into the base go too; branches with unmerged work stay.
|
|
189
|
+
// A lease can be live while its worktree is briefly missing, so its branch is protected
|
|
190
|
+
// even when no worktree has it checked out. If the ledger can't be read, sweep nothing.
|
|
191
|
+
const protectedBranches = await readHostRuntimeLeases(this.leaseStateRoot)
|
|
192
|
+
.then(liveLeaseBranches)
|
|
193
|
+
.catch(() => null);
|
|
194
|
+
if (!protectedBranches)
|
|
195
|
+
return;
|
|
196
|
+
let budget = releaseSweepLimit;
|
|
197
|
+
if (isRuntimeReadinessBranch(handle.branchName) && !protectedBranches.has(handle.branchName)
|
|
198
|
+
&& await deleteBranchIfUnused(this.git, handle.repoPath, handle.branchName)) {
|
|
199
|
+
budget -= 1;
|
|
105
200
|
}
|
|
201
|
+
await sweepManagedBranches(this.git, handle.repoPath, {
|
|
202
|
+
baseBranch: handle.baseBranch,
|
|
203
|
+
includeMergedWorkBranches: true,
|
|
204
|
+
protectedBranches,
|
|
205
|
+
limit: budget,
|
|
206
|
+
}).catch(() => undefined);
|
|
106
207
|
});
|
|
107
208
|
}
|
|
209
|
+
async restoreOrphanedWorktree(input) {
|
|
210
|
+
const orphanStat = await fs.lstat(input.worktreePath);
|
|
211
|
+
if (orphanStat.isSymbolicLink() || !orphanStat.isDirectory()) {
|
|
212
|
+
throw new Error(`Refusing to recover redirected or non-directory worktree ${input.worktreePath}.`);
|
|
213
|
+
}
|
|
214
|
+
const quarantinePath = `${input.worktreePath}.forge-orphan-${randomUUID()}`;
|
|
215
|
+
if (!isSubPath(input.allowedRoot, quarantinePath)) {
|
|
216
|
+
throw new Error(`Worktree recovery path must stay under ${input.allowedRoot}.`);
|
|
217
|
+
}
|
|
218
|
+
await fs.rename(input.worktreePath, quarantinePath);
|
|
219
|
+
try {
|
|
220
|
+
await this.git.run(input.repoPath, ["worktree", "prune", "--expire", "now"]);
|
|
221
|
+
await this.git.run(input.repoPath, [
|
|
222
|
+
"worktree",
|
|
223
|
+
"add",
|
|
224
|
+
"-B",
|
|
225
|
+
input.branchName,
|
|
226
|
+
input.worktreePath,
|
|
227
|
+
input.baseStartPoint,
|
|
228
|
+
]);
|
|
229
|
+
await overlayOrphanedWorktree(input.worktreePath, quarantinePath);
|
|
230
|
+
await fs.rm(quarantinePath, { recursive: true, force: true });
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
await this.git.run(input.repoPath, ["worktree", "remove", "--force", input.worktreePath]).catch(() => undefined);
|
|
234
|
+
await fs.rm(input.worktreePath, { recursive: true, force: true }).catch(() => undefined);
|
|
235
|
+
await fs.rename(quarantinePath, input.worktreePath).catch(() => undefined);
|
|
236
|
+
throw new Error(`Failed to recover orphaned worktree ${input.worktreePath}.`, { cause: error });
|
|
237
|
+
}
|
|
238
|
+
}
|
|
108
239
|
async resolveRepoPath(repo, allowedRoot, baseBranch) {
|
|
109
240
|
if (repo.serverLocalPath && repo.serverLocalPath.trim().length > 0) {
|
|
110
241
|
const requestedPath = await resolveExistingDirectoryPath(repo.serverLocalPath);
|
|
@@ -233,6 +364,32 @@ export class GitWorktreeService {
|
|
|
233
364
|
await this.git.run(repoPath, ["config", "user.name", "Forge Bridge"]);
|
|
234
365
|
}
|
|
235
366
|
}
|
|
367
|
+
export async function renameWorktreeForRelease(source, destination, rename = fs.rename, wait = milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds)), maxAttempts = 8) {
|
|
368
|
+
const attempts = Number.isFinite(maxAttempts) && maxAttempts > 0
|
|
369
|
+
? Math.max(1, Math.floor(maxAttempts))
|
|
370
|
+
: 1;
|
|
371
|
+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
372
|
+
try {
|
|
373
|
+
await rename(source, destination);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
if (!isTransientWorktreeRenameError(error) || attempt === attempts)
|
|
378
|
+
throw error;
|
|
379
|
+
await wait(Math.min(1_000, 100 * (2 ** (attempt - 1))));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
function isTransientWorktreeRenameError(error) {
|
|
384
|
+
if (!error || typeof error !== "object" || !("code" in error))
|
|
385
|
+
return false;
|
|
386
|
+
const code = String(error.code ?? "").toUpperCase();
|
|
387
|
+
return code === "EPERM" || code === "EACCES" || code === "EBUSY" || code === "ENOTEMPTY";
|
|
388
|
+
}
|
|
389
|
+
export function requiresMutableEnvironmentPreparation(request) {
|
|
390
|
+
// Missing runtime intent is treated conservatively for older dispatch packets.
|
|
391
|
+
return request.applicationRuntimeRequired !== false;
|
|
392
|
+
}
|
|
236
393
|
function isCloneableRemote(remoteUrl) {
|
|
237
394
|
const trimmed = remoteUrl?.trim() ?? "";
|
|
238
395
|
if (trimmed.length === 0 || trimmed.startsWith("local://")) {
|
|
@@ -317,6 +474,121 @@ function shouldResetExistingWorktree(request) {
|
|
|
317
474
|
}
|
|
318
475
|
return true;
|
|
319
476
|
}
|
|
477
|
+
function parseRegisteredWorktrees(repoPath, output) {
|
|
478
|
+
const worktrees = [];
|
|
479
|
+
let current = null;
|
|
480
|
+
for (const field of output.split("\0")) {
|
|
481
|
+
if (field.startsWith("worktree ")) {
|
|
482
|
+
if (current)
|
|
483
|
+
worktrees.push(current);
|
|
484
|
+
const rawPath = field.slice("worktree ".length);
|
|
485
|
+
current = {
|
|
486
|
+
worktreePath: path.resolve(path.isAbsolute(rawPath) ? rawPath : path.join(repoPath, rawPath)),
|
|
487
|
+
branchName: null,
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
else if (field.startsWith("branch ") && current) {
|
|
491
|
+
current.branchName = field.slice("branch ".length).trim();
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (current)
|
|
495
|
+
worktrees.push(current);
|
|
496
|
+
return worktrees;
|
|
497
|
+
}
|
|
498
|
+
function isManagedLeaseWorktreePath(allowedRoot, candidate, worktreeSegments) {
|
|
499
|
+
if (!isSubPath(allowedRoot, candidate)) {
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
const relativeSegments = path.relative(path.resolve(allowedRoot), path.resolve(candidate))
|
|
503
|
+
.split(path.sep)
|
|
504
|
+
.filter(Boolean);
|
|
505
|
+
const normalize = (value) => process.platform === "win32" ? value.toLowerCase() : value;
|
|
506
|
+
if (normalize(relativeSegments[0] ?? "") !== ".forge-worktrees"
|
|
507
|
+
|| relativeSegments.length !== 2 + worktreeSegments.length) {
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
const suffix = relativeSegments.slice(-worktreeSegments.length).map(normalize);
|
|
511
|
+
return suffix.every((segment, index) => segment === normalize(worktreeSegments[index] ?? ""));
|
|
512
|
+
}
|
|
513
|
+
async function overlayOrphanedWorktree(worktreePath, orphanPath) {
|
|
514
|
+
// A failed Windows cleanup can remove only part of a worktree before its
|
|
515
|
+
// `.git` link disappears. Start from Git's clean checkout so missing tracked
|
|
516
|
+
// files are restored, then overlay every surviving agent file. Moving entries
|
|
517
|
+
// on the same volume preserves pnpm junctions without requiring symlink
|
|
518
|
+
// privileges, unlike fs.cp.
|
|
519
|
+
const backupRoot = `${worktreePath}.forge-base-${randomUUID()}`;
|
|
520
|
+
const moves = [];
|
|
521
|
+
try {
|
|
522
|
+
await fs.mkdir(backupRoot, { recursive: true });
|
|
523
|
+
const orphanEntries = await fs.readdir(orphanPath, { withFileTypes: true });
|
|
524
|
+
for (const entry of orphanEntries) {
|
|
525
|
+
if (entry.name === ".git") {
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
await overlayEntry({
|
|
529
|
+
sourcePath: path.join(orphanPath, entry.name),
|
|
530
|
+
destinationPath: path.join(worktreePath, entry.name),
|
|
531
|
+
backupPath: path.join(backupRoot, entry.name),
|
|
532
|
+
moves,
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
await fs.rm(backupRoot, { recursive: true, force: true });
|
|
536
|
+
}
|
|
537
|
+
catch (error) {
|
|
538
|
+
for (const move of moves.reverse()) {
|
|
539
|
+
await fs.mkdir(path.dirname(move.sourcePath), { recursive: true }).catch(() => undefined);
|
|
540
|
+
await fs.rename(move.destinationPath, move.sourcePath).catch(() => undefined);
|
|
541
|
+
if (move.backupPath) {
|
|
542
|
+
await fs.mkdir(path.dirname(move.destinationPath), { recursive: true }).catch(() => undefined);
|
|
543
|
+
await fs.rename(move.backupPath, move.destinationPath).catch(() => undefined);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
await fs.rm(backupRoot, { recursive: true, force: true }).catch(() => undefined);
|
|
547
|
+
throw error;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
async function overlayEntry(input) {
|
|
551
|
+
const sourceStat = await fs.lstat(input.sourcePath);
|
|
552
|
+
const destinationStat = await fs.lstat(input.destinationPath).catch(() => null);
|
|
553
|
+
if (sourceStat.isDirectory() &&
|
|
554
|
+
!sourceStat.isSymbolicLink() &&
|
|
555
|
+
destinationStat?.isDirectory() &&
|
|
556
|
+
!destinationStat.isSymbolicLink()) {
|
|
557
|
+
const entries = await fs.readdir(input.sourcePath, { withFileTypes: true });
|
|
558
|
+
for (const entry of entries) {
|
|
559
|
+
await overlayEntry({
|
|
560
|
+
sourcePath: path.join(input.sourcePath, entry.name),
|
|
561
|
+
destinationPath: path.join(input.destinationPath, entry.name),
|
|
562
|
+
backupPath: path.join(input.backupPath, entry.name),
|
|
563
|
+
moves: input.moves,
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
let preservedBasePath;
|
|
569
|
+
if (destinationStat) {
|
|
570
|
+
await fs.mkdir(path.dirname(input.backupPath), { recursive: true });
|
|
571
|
+
await fs.rename(input.destinationPath, input.backupPath);
|
|
572
|
+
preservedBasePath = input.backupPath;
|
|
573
|
+
}
|
|
574
|
+
else {
|
|
575
|
+
await fs.mkdir(path.dirname(input.destinationPath), { recursive: true });
|
|
576
|
+
}
|
|
577
|
+
try {
|
|
578
|
+
await fs.rename(input.sourcePath, input.destinationPath);
|
|
579
|
+
}
|
|
580
|
+
catch (error) {
|
|
581
|
+
if (preservedBasePath) {
|
|
582
|
+
await fs.rename(preservedBasePath, input.destinationPath).catch(() => undefined);
|
|
583
|
+
}
|
|
584
|
+
throw error;
|
|
585
|
+
}
|
|
586
|
+
input.moves.push({
|
|
587
|
+
sourcePath: input.sourcePath,
|
|
588
|
+
destinationPath: input.destinationPath,
|
|
589
|
+
backupPath: preservedBasePath,
|
|
590
|
+
});
|
|
591
|
+
}
|
|
320
592
|
function qaReworkPacketFileName(packetPath) {
|
|
321
593
|
const normalized = packetPath.trim().replace(/\\/g, "/");
|
|
322
594
|
const fileName = normalized.split("/").filter(Boolean).at(-1) ?? "";
|
|
@@ -1,4 +1,4 @@
|
|
|
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
3
|
export interface WorktreePrepareRequest {
|
|
4
4
|
readonly repo: DispatchRepo;
|
|
@@ -13,8 +13,21 @@ export interface WorktreePrepareRequest {
|
|
|
13
13
|
readonly cleanupWorktrees: boolean;
|
|
14
14
|
readonly artifacts: readonly DispatchResolvedArtifact[];
|
|
15
15
|
readonly priorPhaseArtifacts?: readonly DispatchPriorPhaseArtifact[];
|
|
16
|
+
readonly storyQa?: DispatchStoryQaContext | null;
|
|
17
|
+
readonly referenceRunId?: string;
|
|
18
|
+
readonly referenceCycleRunId?: string;
|
|
19
|
+
readonly effectivePlanAmendmentHash?: string | null;
|
|
16
20
|
readonly qaRework?: DispatchQaReworkContext | null;
|
|
17
21
|
readonly warmPathOverrides?: readonly string[];
|
|
22
|
+
readonly applicationRuntimeRequired?: boolean;
|
|
23
|
+
readonly preserveExistingState?: boolean;
|
|
24
|
+
/** The attempt dependency installs reserve host capacity for (decision 0013). */
|
|
25
|
+
readonly hostLoadOwner?: {
|
|
26
|
+
readonly dispatchAttemptId: string | null;
|
|
27
|
+
readonly priority: "foreground" | "background";
|
|
28
|
+
};
|
|
29
|
+
/** The attempt's cancellation: queued installs stop waiting and running ones are stopped. */
|
|
30
|
+
readonly signal?: AbortSignal;
|
|
18
31
|
}
|
|
19
32
|
export interface WorktreeHandle {
|
|
20
33
|
readonly repoPath: string;
|
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.03584818ede5",
|
|
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
|
}
|