@loucompanion/forge-bridge 0.1.4-dev.fb770705136a → 0.2.1-dev.0f07274d438b
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 +183 -4
- package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
- package/dist/bridge/bridge-chat-giphy-look.js +55 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +40 -0
- package/dist/bridge/bridge-chat-provider-command.js +230 -0
- package/dist/bridge/bridge-chat.types.d.ts +20 -0
- package/dist/bridge/bridge-chat.types.js +28 -1
- 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 +15 -0
- package/dist/bridge/bridge-state-io.js +68 -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 +9 -0
- package/dist/bridge/bridge.service.d.ts +102 -14
- package/dist/bridge/bridge.service.js +499 -471
- package/dist/bridge/bridge.types.d.ts +37 -0
- package/dist/bridge/bridge.types.js +2 -1
- package/dist/bridge/default-session-service.d.ts +13 -0
- package/dist/bridge/default-session-service.js +22 -0
- package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
- package/dist/bridge/dispatch-offer-policy.js +58 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -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 +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.d.ts +5 -0
- package/dist/bridge/runner-host-capabilities.js +31 -1
- 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/bridge/windows-bash-resolution.d.ts +31 -0
- package/dist/bridge/windows-bash-resolution.js +153 -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 +20 -1
- package/dist/cleanup/cleanup.service.js +150 -169
- package/dist/cleanup/cleanup.types.d.ts +6 -0
- package/dist/cleanup/forge-owned-paths.d.ts +11 -0
- package/dist/cleanup/forge-owned-paths.js +62 -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 +75 -13
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +161 -228
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +18 -1
- package/dist/cli/local-config.js +67 -5
- package/dist/cli/provider-cli-advertising.d.ts +24 -0
- package/dist/cli/provider-cli-advertising.js +88 -0
- 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 +20 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
- package/dist/runtime/attempt-process-supervisor.js +12 -6
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -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/host-facts.d.ts +2 -1
- package/dist/runtime/host-listener-inspector.d.ts +26 -0
- package/dist/runtime/host-listener-inspector.js +84 -3
- package/dist/runtime/host-load-admission.d.ts +72 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-capacity.d.ts +198 -0
- package/dist/runtime/host-load-capacity.js +353 -0
- package/dist/runtime/host-load-child-environment.d.ts +40 -0
- package/dist/runtime/host-load-child-environment.js +110 -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 +82 -0
- package/dist/runtime/host-load-governor-config.js +104 -0
- package/dist/runtime/host-load-governor.d.ts +273 -0
- package/dist/runtime/host-load-governor.js +831 -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-live-test-slots.d.ts +61 -0
- package/dist/runtime/host-load-live-test-slots.js +193 -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 +92 -2
- package/dist/runtime/host-load-sampler.js +166 -8
- 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 +107 -0
- package/dist/runtime/host-load-step-run.js +158 -0
- package/dist/runtime/host-load-test-slot.d.ts +46 -0
- package/dist/runtime/host-load-test-slot.js +100 -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 +21 -1
- package/dist/runtime/host-pressure-stall.js +48 -1
- package/dist/runtime/host-runtime-contract.d.ts +15 -0
- package/dist/runtime/host-runtime-contract.js +39 -6
- package/dist/runtime/host-runtime-lease.d.ts +101 -6
- package/dist/runtime/host-runtime-lease.js +408 -294
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/host-runtime-promotion.d.ts +101 -2
- package/dist/runtime/host-runtime-promotion.js +355 -14
- 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.js +5 -16
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
- package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
- package/dist/runtime/prepared-runtime-identity.js +130 -9
- package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
- package/dist/runtime/prepared-runtime-readiness.js +89 -18
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -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 +90 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.d.ts +11 -3
- package/dist/sandbox/runtime.js +53 -20
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/sandbox/sandbox-input.d.ts +22 -0
- package/dist/sandbox/sandbox-input.js +49 -0
- package/dist/sandbox/workspace.service.js +15 -2
- 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 +2 -7
- package/dist/session/managed-attempt-tools.js +204 -141
- package/dist/session/managed-build-coordinator.d.ts +16 -0
- package/dist/session/managed-build-coordinator.js +10 -0
- package/dist/session/managed-build-receipt.d.ts +7 -0
- package/dist/session/managed-build-receipt.js +11 -3
- package/dist/session/managed-command-environment.d.ts +8 -0
- package/dist/session/managed-command-environment.js +28 -0
- package/dist/session/managed-command-host-load.d.ts +52 -0
- package/dist/session/managed-command-host-load.js +87 -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.artifact-bundle.d.ts +20 -0
- package/dist/session/phase-completion.artifact-bundle.js +167 -0
- package/dist/session/phase-completion.artifacts.d.ts +9 -17
- package/dist/session/phase-completion.artifacts.js +158 -190
- 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 +31 -2
- package/dist/session/phase-completion.helpers.js +18 -65
- package/dist/session/phase-completion.js +19 -32
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +195 -0
- package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
- package/dist/session/phase-completion.phase-aliases.js +43 -0
- package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
- package/dist/session/phase-completion.pr-review-schema.js +75 -0
- package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
- package/dist/session/phase-completion.pr-review-validation.js +212 -0
- package/dist/session/phase-completion.pr-review.d.ts +36 -0
- package/dist/session/phase-completion.pr-review.js +294 -0
- package/dist/session/phase-completion.prompts.d.ts +1 -1
- package/dist/session/phase-completion.prompts.js +20 -1
- package/dist/session/phase-completion.runtime.d.ts +13 -12
- package/dist/session/phase-completion.runtime.js +113 -214
- 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 +219 -232
- package/dist/session/phase-completion.validation.d.ts +3 -3
- package/dist/session/phase-completion.validation.js +58 -94
- package/dist/session/pr-review-diff-base.d.ts +18 -0
- package/dist/session/pr-review-diff-base.js +44 -0
- package/dist/session/pr-review-placement.d.ts +50 -0
- package/dist/session/pr-review-placement.js +91 -0
- package/dist/session/pre-publication-change-set.d.ts +62 -0
- package/dist/session/pre-publication-change-set.js +166 -0
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +112 -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 +3 -0
- package/dist/session/pre-publication-process.js +32 -19
- 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 +39 -22
- package/dist/session/pre-publication-validation.js +241 -207
- 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/dispatch-target-branch.d.ts +7 -0
- package/dist/session/provider-cli/dispatch-target-branch.js +8 -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/pr-review-credential-isolation.d.ts +83 -0
- package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
- package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
- package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
- package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
- package/dist/session/provider-cli/pr-review-prompt.js +119 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +281 -0
- package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
- package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
- package/dist/session/provider-cli/provider-cli.process.js +41 -432
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -3
- package/dist/session/provider-cli/provider-cli.prompts.js +183 -90
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +43 -1
- package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
- package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +18 -18
- package/dist/session/provider-cli/provider-cli.service.js +127 -317
- package/dist/session/provider-cli/provider-cli.types.d.ts +35 -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 +4 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +45 -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 +2 -0
- package/dist/session/provider-cli/provider-output-state.js +6 -0
- 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/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 +279 -0
- package/dist/session/session-host-project.d.ts +22 -0
- package/dist/session/session-host-project.js +98 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.parse-helpers.d.ts +10 -0
- package/dist/session/session.parse-helpers.js +84 -0
- package/dist/session/session.runtime-refresh.d.ts +46 -0
- package/dist/session/session.runtime-refresh.js +116 -0
- package/dist/session/session.service.d.ts +16 -2
- package/dist/session/session.service.js +208 -155
- package/dist/session/session.types.d.ts +8 -0
- package/dist/session/session.types.js +13 -83
- package/dist/session/session.types.pr-review.d.ts +48 -0
- package/dist/session/session.types.pr-review.js +51 -0
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -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/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +14 -1
- package/dist/shared/process/host-process-supervisor.js +67 -15
- 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 +67 -0
- package/dist/shared/process/process.js +213 -11
- 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 +2 -0
- package/dist/shared/provider-capabilities.js +23 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/artifact-injector.js +24 -0
- package/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +46 -10
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +58 -0
- package/dist/worktree/wip-git.js +182 -0
- package/dist/worktree/wip-refs.d.ts +85 -0
- package/dist/worktree/wip-refs.js +169 -0
- package/dist/worktree/wip-restore.d.ts +51 -0
- package/dist/worktree/wip-restore.js +324 -0
- package/dist/worktree/wip-snapshot.d.ts +53 -0
- package/dist/worktree/wip-snapshot.js +270 -0
- package/dist/worktree/worktree-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +35 -0
- package/dist/worktree/worktree-origin-sync.js +128 -0
- package/dist/worktree/worktree-wip-events.d.ts +20 -0
- package/dist/worktree/worktree-wip-events.js +148 -0
- package/dist/worktree/worktree-wip.d.ts +57 -0
- package/dist/worktree/worktree-wip.js +200 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +58 -5
- package/dist/worktree/worktree.service.js +237 -161
- package/dist/worktree/worktree.types.d.ts +54 -0
- package/package.json +2 -2
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -4,34 +4,53 @@ import path from "node:path";
|
|
|
4
4
|
import { RepositoryCoordinatorLock } from "../sandbox/repository-lock.js";
|
|
5
5
|
import { GitClient } from "../shared/git/git.js";
|
|
6
6
|
import { ensureDirectory, isSubPath, resolveExistingDirectoryPath, safeSegment } from "../shared/path/path.js";
|
|
7
|
-
import { filterArtifactsForLane, injectWorktreeArtifacts } from "./artifact-injector.js";
|
|
8
|
-
import { hydratePriorPhaseArtifacts } from "./prior-phase-artifact-hydrator.js";
|
|
9
|
-
import { materializeStoryQaReferences } from "./story-qa-reference-hydrator.js";
|
|
10
7
|
import { warmWorktreeDependencies } from "./dependency-warmer.js";
|
|
8
|
+
import { materializeWorktreeInputs } from "./worktree-inputs.js";
|
|
9
|
+
import { guardBranchReset, guardWorktreeRelease, guardWorktreeReset, relinkOrphanedWorktree, restoreWorktreeWip, unresolvedWorktreeReapplyConflicts, settleSessionWip, sweepBranchesAfterRelease, worktreeReleased, } from "./worktree-wip.js";
|
|
11
10
|
import { defaultWorktreeCoordinatorStateRoot, managedRepoRoot, resolveManagedWorktreeRoot, } from "./worktree-paths.js";
|
|
11
|
+
import { describeNewWorktreeStart, refuseStaleFallbackAfterFetchFailure, syncReusedWorktreeToOrigin, writeBridgeLog, } from "./worktree-origin-sync.js";
|
|
12
|
+
export { deferredProjectStartEvent, emitWipRestoreEvent, sessionWipOutcome, settleWorktree } from "./worktree-wip-events.js";
|
|
13
|
+
export { emitWorktreePreparedEvents } from "./worktree-origin-sync.js";
|
|
14
|
+
export { clearRunArtifactRoots } from "./worktree-inputs.js";
|
|
15
|
+
// Bounds the branch sweep that runs after each release, so one release never holds the repository lock long.
|
|
16
|
+
const releaseSweepLimit = 25;
|
|
12
17
|
export class GitWorktreeService {
|
|
13
18
|
git;
|
|
14
19
|
coordinator;
|
|
15
|
-
|
|
20
|
+
hostLoadGate;
|
|
21
|
+
leaseStateRoot;
|
|
22
|
+
log;
|
|
23
|
+
constructor(git = new GitClient(), coordinator = new RepositoryCoordinatorLock(defaultWorktreeCoordinatorStateRoot()),
|
|
24
|
+
/** Gates dependency install fallbacks; inert unless the governor is on. */
|
|
25
|
+
hostLoadGate,
|
|
26
|
+
/** Holds the host runtime lease ledger; branches of live leases are never swept on release. */
|
|
27
|
+
leaseStateRoot = defaultWorktreeCoordinatorStateRoot(),
|
|
28
|
+
/** The bridge log: prepare records its start point and what it did to a reused worktree. */
|
|
29
|
+
log = writeBridgeLog) {
|
|
16
30
|
this.git = git;
|
|
17
31
|
this.coordinator = coordinator;
|
|
32
|
+
this.hostLoadGate = hostLoadGate;
|
|
33
|
+
this.leaseStateRoot = leaseStateRoot;
|
|
34
|
+
this.log = log;
|
|
18
35
|
}
|
|
19
36
|
async prepare(request) {
|
|
20
37
|
const allowedRoot = await ensureDirectory(request.allowedRepoRoot);
|
|
21
38
|
const baseBranch = normalizeBranchName(request.baseBranch, "develop");
|
|
39
|
+
const detachedHeadSha = normalizeDetachedHeadSha(request.detachedHeadSha);
|
|
22
40
|
const shortId = request.workItem.id.replace(/-/g, "").slice(0, 12);
|
|
23
41
|
const kind = safeSegment(request.workItem.kind, "work-item");
|
|
24
|
-
const
|
|
25
|
-
const worktreeKey = request.worktreeKey?.trim() || fallbackWorktreeKey;
|
|
42
|
+
const worktreeKey = request.worktreeKey?.trim() || `${kind}/${shortId}`;
|
|
26
43
|
const worktreeSegments = worktreeKeySegments(worktreeKey, kind, shortId);
|
|
27
44
|
const branchName = normalizeBranchName(worktreeSegments.join("/"), "work-item/unknown");
|
|
28
45
|
const creationCoordinationPath = this.repoCreationCoordinationPath(request.repo, allowedRoot);
|
|
29
46
|
const repoPath = await this.coordinator.withLock(creationCoordinationPath, async () => {
|
|
30
47
|
return await this.resolveRepoPath(request.repo, allowedRoot, baseBranch);
|
|
31
48
|
});
|
|
32
|
-
const resolvedWorktreePath = await this.coordinator.withLock(repoPath, async () => {
|
|
49
|
+
const { worktreePath: resolvedWorktreePath, ...preparedState } = await this.coordinator.withLock(repoPath, async () => {
|
|
33
50
|
await this.ensureGitIdentity(repoPath);
|
|
34
|
-
const baseStartPoint =
|
|
51
|
+
const baseStartPoint = detachedHeadSha
|
|
52
|
+
? await this.resolveReviewHead(repoPath, detachedHeadSha)
|
|
53
|
+
: await this.resolveBaseStartPoint(repoPath, baseBranch, branchName);
|
|
35
54
|
const worktreeRoot = resolveManagedWorktreeRoot(allowedRoot, repoPath);
|
|
36
55
|
const worktreePath = path.join(worktreeRoot, ...worktreeSegments);
|
|
37
56
|
const resolvedWorktreeParent = await ensureDirectory(path.dirname(worktreePath));
|
|
@@ -46,17 +65,7 @@ export class GitWorktreeService {
|
|
|
46
65
|
await this.git.run(repoPath, ["worktree", "prune", "--expire", "now"]);
|
|
47
66
|
const registeredWorktreePath = await this.registeredManagedWorktreePath(repoPath, branchName, allowedRoot, worktreeSegments);
|
|
48
67
|
if (!registeredWorktreePath) {
|
|
49
|
-
|
|
50
|
-
if (request.preserveExistingState && await this.gitRefExists(repoPath, branchRef)) {
|
|
51
|
-
// The checkout directory can disappear while its branch still
|
|
52
|
-
// contains completed agent work. Reattach that branch verbatim;
|
|
53
|
-
// `-B ... baseStartPoint` would silently reset it and lose progress.
|
|
54
|
-
await this.git.run(repoPath, ["worktree", "add", worktreePath, branchName]);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
await this.git.run(repoPath, ["worktree", "add", "-B", branchName, worktreePath, baseStartPoint]);
|
|
58
|
-
}
|
|
59
|
-
return await resolveExistingDirectoryPath(worktreePath);
|
|
68
|
+
return await this.createWorktree(request, { repoPath, branchName, worktreePath, baseStartPoint, detachedHeadSha });
|
|
60
69
|
}
|
|
61
70
|
// The selected checkout can change when a Bridge reconnects or a local
|
|
62
71
|
// runner takes over. Its managed root therefore changes even though the
|
|
@@ -77,34 +86,19 @@ export class GitWorktreeService {
|
|
|
77
86
|
allowedRoot,
|
|
78
87
|
});
|
|
79
88
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
return existingWorktreePath;
|
|
89
|
+
return await this.reuseWorktree(request, {
|
|
90
|
+
repoPath,
|
|
91
|
+
branchName,
|
|
92
|
+
worktreePath: existingWorktreePath,
|
|
93
|
+
baseStartPoint,
|
|
94
|
+
detachedHeadSha,
|
|
95
|
+
});
|
|
88
96
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const hydratedPriorPhaseArtifactCount = await hydratePriorPhaseArtifacts(resolvedWorktreePath, request.priorPhaseArtifacts);
|
|
95
|
-
const qaReworkPacketPath = await materializeQaReworkPacket(resolvedWorktreePath, request);
|
|
96
|
-
const artifacts = filterArtifactsForLane(request.artifacts, request.lane, request.phase);
|
|
97
|
-
if (artifacts.length > 0) {
|
|
98
|
-
await injectWorktreeArtifacts(resolvedWorktreePath, artifacts, await this.trackedForgePaths(resolvedWorktreePath));
|
|
99
|
-
}
|
|
100
|
-
const dependencyWarm = requiresMutableEnvironmentPreparation(request)
|
|
101
|
-
? await warmWorktreeDependencies({
|
|
102
|
-
baseCheckoutPath: repoPath,
|
|
103
|
-
worktreePath: resolvedWorktreePath,
|
|
104
|
-
allowedRoot,
|
|
105
|
-
warmPathOverrides: request.warmPathOverrides
|
|
106
|
-
})
|
|
107
|
-
: undefined;
|
|
97
|
+
if (detachedHeadSha) {
|
|
98
|
+
await this.assertDetachedAtHead(resolvedWorktreePath, detachedHeadSha);
|
|
99
|
+
}
|
|
100
|
+
const { hydratedPriorPhaseArtifactCount, qaReworkPacketPath } = await materializeWorktreeInputs(resolvedWorktreePath, request, this.git);
|
|
101
|
+
const dependencyWarm = await this.warmDependencies(request, repoPath, resolvedWorktreePath, allowedRoot);
|
|
108
102
|
return {
|
|
109
103
|
repoPath,
|
|
110
104
|
worktreePath: resolvedWorktreePath,
|
|
@@ -113,12 +107,156 @@ export class GitWorktreeService {
|
|
|
113
107
|
cleanupWorktrees: request.cleanupWorktrees,
|
|
114
108
|
dependencyWarm,
|
|
115
109
|
qaReworkPacketPath,
|
|
116
|
-
hydratedPriorPhaseArtifactCount
|
|
110
|
+
hydratedPriorPhaseArtifactCount,
|
|
111
|
+
sessionId: request.sessionId ?? null,
|
|
112
|
+
lane: request.lane,
|
|
113
|
+
wipAttempt: request.wipAttempt ?? null,
|
|
114
|
+
...preparedState,
|
|
115
|
+
...(detachedHeadSha ? { detachedHeadSha } : {}),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Creates the lease's worktree. A review's is detached at the review head: no lease branch is
|
|
120
|
+
* created and no WIP is restored. Any other is on the lease branch with the story's WIP restored.
|
|
121
|
+
*/
|
|
122
|
+
async createWorktree(request, checkout) {
|
|
123
|
+
const { repoPath, branchName, worktreePath, baseStartPoint, detachedHeadSha } = checkout;
|
|
124
|
+
if (detachedHeadSha) {
|
|
125
|
+
await this.git.run(repoPath, ["worktree", "add", "--detach", worktreePath, detachedHeadSha]);
|
|
126
|
+
return { worktreePath: await resolveExistingDirectoryPath(worktreePath) };
|
|
127
|
+
}
|
|
128
|
+
const originSync = await this.addWorktree(request, repoPath, branchName, worktreePath, baseStartPoint);
|
|
129
|
+
return await this.withRestoredWip(request, repoPath, branchName, await resolveExistingDirectoryPath(worktreePath), originSync);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Readies a surviving worktree. A review reads one exact commit, so whatever state a prior attempt
|
|
133
|
+
* left behind is discarded. Any other must still be on the lease branch; it is refreshed for this
|
|
134
|
+
* pass and given the story's WIP.
|
|
135
|
+
*/
|
|
136
|
+
async reuseWorktree(request, checkout) {
|
|
137
|
+
const { repoPath, branchName, worktreePath, baseStartPoint, detachedHeadSha } = checkout;
|
|
138
|
+
if (detachedHeadSha) {
|
|
139
|
+
await this.git.run(worktreePath, ["checkout", "--force", "--detach", detachedHeadSha]);
|
|
140
|
+
await this.git.run(worktreePath, ["reset", "--hard", detachedHeadSha]);
|
|
141
|
+
await this.git.run(worktreePath, ["clean", "-fd"]);
|
|
142
|
+
return { worktreePath };
|
|
143
|
+
}
|
|
144
|
+
const currentBranch = await this.currentBranch(worktreePath);
|
|
145
|
+
if (currentBranch !== branchName) {
|
|
146
|
+
throw new Error(`Existing worktree ${worktreePath} is on branch '${currentBranch}', expected '${branchName}'.`);
|
|
147
|
+
}
|
|
148
|
+
const originSync = await this.refreshReusedWorktree(request, worktreePath, branchName, baseStartPoint);
|
|
149
|
+
return await this.withRestoredWip(request, repoPath, branchName, worktreePath, originSync);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Finds the review head in the repository, fetching it when the local clone has not seen it
|
|
153
|
+
* yet, and returns the full commit id.
|
|
154
|
+
*/
|
|
155
|
+
async resolveReviewHead(repoPath, headSha) {
|
|
156
|
+
const resolve = async () => {
|
|
157
|
+
const resolved = await this.git.run(repoPath, ["rev-parse", "--verify", "--quiet", `${headSha}^{commit}`])
|
|
158
|
+
.then((value) => value.trim())
|
|
159
|
+
.catch(() => "");
|
|
160
|
+
return /^[0-9a-f]{40,64}$/iu.test(resolved) ? resolved : null;
|
|
117
161
|
};
|
|
162
|
+
const local = await resolve();
|
|
163
|
+
if (local) {
|
|
164
|
+
return local;
|
|
165
|
+
}
|
|
166
|
+
const origin = await this.git.run(repoPath, ["remote", "get-url", "origin"]).catch(() => "");
|
|
167
|
+
if (origin.trim().length > 0) {
|
|
168
|
+
await this.git.run(repoPath, ["fetch", "--prune", "origin"]).catch(() => undefined);
|
|
169
|
+
const afterFetch = await resolve();
|
|
170
|
+
if (afterFetch) {
|
|
171
|
+
return afterFetch;
|
|
172
|
+
}
|
|
173
|
+
await this.git.run(repoPath, ["fetch", "origin", headSha]).catch(() => undefined);
|
|
174
|
+
const afterShaFetch = await resolve();
|
|
175
|
+
if (afterShaFetch) {
|
|
176
|
+
return afterShaFetch;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
throw new Error(`Review head ${headSha} was not found in the repository or on origin.`);
|
|
180
|
+
}
|
|
181
|
+
async assertDetachedAtHead(worktreePath, headSha) {
|
|
182
|
+
const head = (await this.git.run(worktreePath, ["rev-parse", "HEAD"])).trim().toLowerCase();
|
|
183
|
+
const detached = await this.git.run(worktreePath, ["symbolic-ref", "--quiet", "HEAD"]).then(() => false).catch(() => true);
|
|
184
|
+
const expected = (await this.git.run(worktreePath, ["rev-parse", "--verify", `${headSha}^{commit}`])).trim().toLowerCase();
|
|
185
|
+
if (head !== expected || !detached) {
|
|
186
|
+
throw new Error(`Review worktree ${worktreePath} must be detached at ${headSha}, found ${detached ? "detached" : "a branch"} HEAD ${head}.`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async warmDependencies(request, repoPath, worktreePath, allowedRoot) {
|
|
190
|
+
if (!requiresMutableEnvironmentPreparation(request))
|
|
191
|
+
return undefined;
|
|
192
|
+
return await warmWorktreeDependencies({
|
|
193
|
+
baseCheckoutPath: repoPath,
|
|
194
|
+
worktreePath,
|
|
195
|
+
allowedRoot,
|
|
196
|
+
warmPathOverrides: request.warmPathOverrides,
|
|
197
|
+
hostLoad: this.hostLoadGate?.enabled
|
|
198
|
+
? {
|
|
199
|
+
gate: this.hostLoadGate,
|
|
200
|
+
dispatchAttemptId: request.hostLoadOwner?.dispatchAttemptId ?? null,
|
|
201
|
+
priority: request.hostLoadOwner?.priority ?? "foreground",
|
|
202
|
+
}
|
|
203
|
+
: undefined,
|
|
204
|
+
signal: request.signal,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/** Restores the story's saved WIP (still under the repository lock, before the provider starts). */
|
|
208
|
+
async withRestoredWip(request, repoPath, branchName, worktreePath, originSync) {
|
|
209
|
+
const wipRestore = await restoreWorktreeWip({ worktreePath, repoPath, branchName, sessionId: request.sessionId, lane: request.lane });
|
|
210
|
+
const reapplyConflicts = await unresolvedWorktreeReapplyConflicts(worktreePath);
|
|
211
|
+
return { worktreePath, reapplyConflicts, ...(wipRestore ? { wipRestore } : {}), ...(originSync ? { originSync } : {}) };
|
|
212
|
+
}
|
|
213
|
+
/** Creates the lease's worktree; see describeNewWorktreeStart for what it reports. */
|
|
214
|
+
async addWorktree(request, repoPath, branchName, worktreePath, baseStartPoint) {
|
|
215
|
+
if (request.preserveExistingState && await this.gitRefExists(repoPath, `refs/heads/${branchName}`)) {
|
|
216
|
+
// The checkout directory can disappear while its branch still
|
|
217
|
+
// contains completed agent work. Reattach that branch verbatim;
|
|
218
|
+
// `-B ... baseStartPoint` would silently reset it and lose progress.
|
|
219
|
+
this.log(`Worktree prepare: reattaching '${branchName}' verbatim at ${worktreePath} for a resumed session.`);
|
|
220
|
+
await this.git.run(repoPath, ["worktree", "add", worktreePath, branchName]);
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
const originSync = await describeNewWorktreeStart(this.git, repoPath, branchName, baseStartPoint, this.log);
|
|
224
|
+
await guardBranchReset(this.git, repoPath, branchName, baseStartPoint);
|
|
225
|
+
await this.git.run(repoPath, ["worktree", "add", "-B", branchName, worktreePath, baseStartPoint]);
|
|
226
|
+
return originSync;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Readies a surviving worktree for this pass: lanes that start from their base are reset to it;
|
|
230
|
+
* the others keep their state but are brought up to origin's head when only behind it
|
|
231
|
+
* (worktree-origin-sync.ts). A resumed session keeps its worktree exactly as it was.
|
|
232
|
+
*/
|
|
233
|
+
async refreshReusedWorktree(request, worktreePath, branchName, baseStartPoint) {
|
|
234
|
+
if (request.preserveExistingState) {
|
|
235
|
+
this.log(`Worktree prepare: reattaching ${worktreePath} on '${branchName}' unchanged for a resumed session.`);
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
if (shouldResetExistingWorktree(request)) {
|
|
239
|
+
await guardWorktreeReset(worktreePath, branchName, request);
|
|
240
|
+
await this.resetWorktreeToBase(worktreePath, baseStartPoint);
|
|
241
|
+
this.log(`Worktree prepare: reset reused worktree ${worktreePath} on '${branchName}' to ${baseStartPoint}.`);
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
return await syncReusedWorktreeToOrigin({
|
|
245
|
+
git: this.git,
|
|
246
|
+
worktreePath,
|
|
247
|
+
branchName,
|
|
248
|
+
sessionId: request.sessionId,
|
|
249
|
+
lane: request.lane,
|
|
250
|
+
wipAttempt: request.wipAttempt,
|
|
251
|
+
log: this.log,
|
|
252
|
+
});
|
|
118
253
|
}
|
|
119
|
-
async
|
|
120
|
-
|
|
121
|
-
|
|
254
|
+
async settleWip(handle, outcome) {
|
|
255
|
+
// A review worktree holds the reviewed head plus whatever the review session left in it. That is
|
|
256
|
+
// never saved or published: a WIP snapshot would push it to a ref anyone who can read the repo can list.
|
|
257
|
+
if (handle.detachedHeadSha)
|
|
258
|
+
return {};
|
|
259
|
+
return await settleSessionWip(handle, outcome);
|
|
122
260
|
}
|
|
123
261
|
async registeredManagedWorktreePath(repoPath, branchName, allowedRoot, worktreeSegments) {
|
|
124
262
|
const listing = await this.git.run(repoPath, ["worktree", "list", "--porcelain", "-z"]);
|
|
@@ -144,7 +282,12 @@ export class GitWorktreeService {
|
|
|
144
282
|
return;
|
|
145
283
|
}
|
|
146
284
|
await this.coordinator.withLock(handle.repoPath, async () => {
|
|
147
|
-
if (
|
|
285
|
+
if (handle.detachedHeadSha) {
|
|
286
|
+
await this.removeReviewWorktree(handle);
|
|
287
|
+
}
|
|
288
|
+
else if (await directoryExists(handle.worktreePath)) {
|
|
289
|
+
// Never delete work that could not be saved: this throws and keeps the worktree.
|
|
290
|
+
await guardWorktreeRelease(handle);
|
|
148
291
|
// On Windows, `git worktree remove` can delete the `.git` link and then
|
|
149
292
|
// fail on a locked build output. That leaves a full source tree which is
|
|
150
293
|
// no longer a Git worktree and makes every retry fail during prepare.
|
|
@@ -164,17 +307,38 @@ export class GitWorktreeService {
|
|
|
164
307
|
// directory is fully materialized (or after an external cleanup removes it).
|
|
165
308
|
// Always prune so those missing-directory registrations do not accumulate.
|
|
166
309
|
await this.git.run(handle.repoPath, ["worktree", "prune", "--expire", "now"]).catch(() => undefined);
|
|
310
|
+
worktreeReleased(handle);
|
|
311
|
+
// A readiness probe's branch goes with its worktree. Other Forge branches on this device
|
|
312
|
+
// whose work is already merged into the base go too; branches with unmerged work stay.
|
|
313
|
+
// A lease can be live while its worktree is briefly missing, so its branch is protected
|
|
314
|
+
// even when no worktree has it checked out. If the ledger can't be read, sweep nothing.
|
|
315
|
+
await sweepBranchesAfterRelease(this.git, handle, this.leaseStateRoot, releaseSweepLimit);
|
|
167
316
|
});
|
|
168
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Removes a review worktree without saving anything from it (see settleWip). A failed removal leaves
|
|
320
|
+
* the folder for the next prepare of that head, which resets and cleans it, or for stale cleanup.
|
|
321
|
+
*/
|
|
322
|
+
async removeReviewWorktree(handle) {
|
|
323
|
+
if (!(await directoryExists(handle.worktreePath)))
|
|
324
|
+
return;
|
|
325
|
+
await this.git.run(handle.repoPath, ["worktree", "remove", "--force", handle.worktreePath]).catch(() => undefined);
|
|
326
|
+
await fs.rm(handle.worktreePath, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 }).catch(() => undefined);
|
|
327
|
+
}
|
|
169
328
|
async restoreOrphanedWorktree(input) {
|
|
170
329
|
const orphanStat = await fs.lstat(input.worktreePath);
|
|
171
330
|
if (orphanStat.isSymbolicLink() || !orphanStat.isDirectory()) {
|
|
172
331
|
throw new Error(`Refusing to recover redirected or non-directory worktree ${input.worktreePath}.`);
|
|
173
332
|
}
|
|
333
|
+
// Git still has this checkout's admin directory (its index and MERGE_HEAD): point the checkout
|
|
334
|
+
// back at it rather than recreating the checkout, which would prune it.
|
|
335
|
+
if (await relinkOrphanedWorktree(this.git, input))
|
|
336
|
+
return;
|
|
174
337
|
const quarantinePath = `${input.worktreePath}.forge-orphan-${randomUUID()}`;
|
|
175
338
|
if (!isSubPath(input.allowedRoot, quarantinePath)) {
|
|
176
339
|
throw new Error(`Worktree recovery path must stay under ${input.allowedRoot}.`);
|
|
177
340
|
}
|
|
341
|
+
await guardBranchReset(this.git, input.repoPath, input.branchName, input.baseStartPoint);
|
|
178
342
|
await fs.rename(input.worktreePath, quarantinePath);
|
|
179
343
|
try {
|
|
180
344
|
await this.git.run(input.repoPath, ["worktree", "prune", "--expire", "now"]);
|
|
@@ -285,7 +449,12 @@ export class GitWorktreeService {
|
|
|
285
449
|
const resolved = await resolveExistingDirectoryPath(candidate);
|
|
286
450
|
return isSubPath(allowedRoot, resolved) ? resolved : null;
|
|
287
451
|
}
|
|
288
|
-
|
|
452
|
+
/**
|
|
453
|
+
* The start point for the lease's base: origin's freshly fetched head when origin has the
|
|
454
|
+
* branch, else the local branch. When the fetch fails, the local branch is used only if origin
|
|
455
|
+
* has never had the base or the lease branch: otherwise the worktree could run on stale code.
|
|
456
|
+
*/
|
|
457
|
+
async resolveBaseStartPoint(repoPath, baseBranch, branchName) {
|
|
289
458
|
if (baseBranch === "HEAD") {
|
|
290
459
|
const head = (await this.git.run(repoPath, ["rev-parse", "--verify", "HEAD^{commit}"])).trim();
|
|
291
460
|
if (!/^[0-9a-f]{40,64}$/iu.test(head)) {
|
|
@@ -297,14 +466,17 @@ export class GitWorktreeService {
|
|
|
297
466
|
const remoteRef = `refs/remotes/origin/${baseBranch}`;
|
|
298
467
|
const origin = await this.git.run(repoPath, ["remote", "get-url", "origin"]).catch(() => "");
|
|
299
468
|
if (origin.trim().length > 0) {
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
.
|
|
303
|
-
|
|
469
|
+
const fetchError = await this.git.run(repoPath, ["fetch", "--prune", "origin"]).then(() => null, (error) => error ?? "fetch failed");
|
|
470
|
+
if (fetchError) {
|
|
471
|
+
await refuseStaleFallbackAfterFetchFailure(this.git, repoPath, [baseBranch, branchName], fetchError, this.log);
|
|
472
|
+
}
|
|
473
|
+
else if (await this.gitRefExists(repoPath, remoteRef)) {
|
|
474
|
+
this.log(`Worktree prepare: fetched origin in ${repoPath}; '${baseBranch}' starts from ${remoteRef}.`);
|
|
304
475
|
return remoteRef;
|
|
305
476
|
}
|
|
306
477
|
}
|
|
307
478
|
if (await this.gitRefExists(repoPath, localRef)) {
|
|
479
|
+
this.log(`Worktree prepare: '${baseBranch}' starts from the local ${localRef} in ${repoPath} (origin has no such branch).`);
|
|
308
480
|
return localRef;
|
|
309
481
|
}
|
|
310
482
|
throw new Error(`Base branch '${baseBranch}' was not found locally or on origin.`);
|
|
@@ -357,72 +529,6 @@ function isCloneableRemote(remoteUrl) {
|
|
|
357
529
|
}
|
|
358
530
|
return trimmed.startsWith("git@") || trimmed.includes("://") || path.isAbsolute(trimmed);
|
|
359
531
|
}
|
|
360
|
-
export async function clearRunArtifactRoots(worktreePath, request) {
|
|
361
|
-
const roots = new Set();
|
|
362
|
-
roots.add(workItemArtifactRoot(worktreePath, request.workItem.id));
|
|
363
|
-
for (const artifact of request.priorPhaseArtifacts ?? []) {
|
|
364
|
-
roots.add(workItemArtifactRoot(worktreePath, artifact.workItemId));
|
|
365
|
-
}
|
|
366
|
-
const ownerType = normalizeOwnerType(request.ownerType);
|
|
367
|
-
const ownerId = request.ownerId?.trim();
|
|
368
|
-
if (ownerType && ownerId) {
|
|
369
|
-
roots.add(ownerArtifactRoot(worktreePath, ownerType, ownerId));
|
|
370
|
-
}
|
|
371
|
-
for (const root of roots) {
|
|
372
|
-
const resolvedRoot = path.resolve(root);
|
|
373
|
-
if (!isSubPath(worktreePath, resolvedRoot)) {
|
|
374
|
-
throw new Error(`Artifact root must stay under ${worktreePath}.`);
|
|
375
|
-
}
|
|
376
|
-
await ensureNoSymlinkPathSegments(worktreePath, resolvedRoot, "Artifact root must not traverse symlinked path segments.");
|
|
377
|
-
await fs.rm(resolvedRoot, { recursive: true, force: true });
|
|
378
|
-
await fs.mkdir(resolvedRoot, { recursive: true });
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
async function materializeQaReworkPacket(worktreePath, request) {
|
|
382
|
-
const qaRework = request.qaRework;
|
|
383
|
-
if (!qaRework) {
|
|
384
|
-
return undefined;
|
|
385
|
-
}
|
|
386
|
-
const artifactRoot = artifactRootForRequest(worktreePath, request);
|
|
387
|
-
const packetFileName = qaReworkPacketFileName(qaRework.packetPath);
|
|
388
|
-
const packetPath = path.join(artifactRoot, packetFileName);
|
|
389
|
-
const paths = new Set([packetPath, path.join(artifactRoot, "qa-rework-packet.json")]);
|
|
390
|
-
const packetJson = qaRework.packetJson.endsWith("\n") ? qaRework.packetJson : `${qaRework.packetJson}\n`;
|
|
391
|
-
for (const target of paths) {
|
|
392
|
-
const resolvedTarget = path.resolve(target);
|
|
393
|
-
if (!isSubPath(worktreePath, resolvedTarget)) {
|
|
394
|
-
throw new Error(`QA rework packet path must stay under ${worktreePath}.`);
|
|
395
|
-
}
|
|
396
|
-
await ensureNoSymlinkPathSegments(worktreePath, path.dirname(resolvedTarget), "QA rework packet path must not traverse symlinked path segments.");
|
|
397
|
-
await fs.mkdir(path.dirname(resolvedTarget), { recursive: true });
|
|
398
|
-
await fs.writeFile(resolvedTarget, packetJson, "utf8");
|
|
399
|
-
}
|
|
400
|
-
return path.resolve(packetPath);
|
|
401
|
-
}
|
|
402
|
-
function artifactRootForRequest(worktreePath, request) {
|
|
403
|
-
const ownerType = normalizeOwnerType(request.ownerType);
|
|
404
|
-
const ownerId = request.ownerId?.trim();
|
|
405
|
-
if (ownerType && ownerId) {
|
|
406
|
-
return ownerArtifactRoot(worktreePath, ownerType, ownerId);
|
|
407
|
-
}
|
|
408
|
-
return workItemArtifactRoot(worktreePath, request.workItem.id);
|
|
409
|
-
}
|
|
410
|
-
function workItemArtifactRoot(worktreePath, workItemId) {
|
|
411
|
-
return path.join(worktreePath, ".forge", "work-items", safeSegment(workItemId, "work item id"), "artifacts");
|
|
412
|
-
}
|
|
413
|
-
function ownerArtifactRoot(worktreePath, ownerType, ownerId) {
|
|
414
|
-
return path.join(worktreePath, ".forge", ownerType === "story" ? "stories" : "work-items", safeSegment(ownerId, "owner id"), "artifacts");
|
|
415
|
-
}
|
|
416
|
-
function normalizeOwnerType(value) {
|
|
417
|
-
const normalized = (value ?? "").trim().toLowerCase().replace(/-/g, "_");
|
|
418
|
-
if (normalized === "story") {
|
|
419
|
-
return "story";
|
|
420
|
-
}
|
|
421
|
-
if (normalized === "work_item" || normalized === "workitem" || normalized === "work item") {
|
|
422
|
-
return "work_item";
|
|
423
|
-
}
|
|
424
|
-
return null;
|
|
425
|
-
}
|
|
426
532
|
function shouldResetExistingWorktree(request) {
|
|
427
533
|
const lane = request.lane.trim().toLowerCase();
|
|
428
534
|
const phase = request.phase.trim().toLowerCase().replace(/-/g, "_");
|
|
@@ -549,12 +655,15 @@ async function overlayEntry(input) {
|
|
|
549
655
|
backupPath: preservedBasePath,
|
|
550
656
|
});
|
|
551
657
|
}
|
|
552
|
-
function
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
658
|
+
function normalizeDetachedHeadSha(value) {
|
|
659
|
+
const trimmed = value?.trim().toLowerCase() ?? "";
|
|
660
|
+
if (trimmed.length === 0) {
|
|
661
|
+
return null;
|
|
662
|
+
}
|
|
663
|
+
if (!/^[0-9a-f]{40}$|^[0-9a-f]{64}$/u.test(trimmed)) {
|
|
664
|
+
throw new Error("Review head_sha must be a full 40 or 64 character commit id.");
|
|
665
|
+
}
|
|
666
|
+
return trimmed;
|
|
558
667
|
}
|
|
559
668
|
export function normalizeBranchName(value, fallback) {
|
|
560
669
|
const branch = (value?.trim() || fallback).trim();
|
|
@@ -605,39 +714,6 @@ async function gitMetadataExists(repoPath, allowedRoot) {
|
|
|
605
714
|
const resolvedGitDir = await resolveExistingDirectoryPath(gitDirPath);
|
|
606
715
|
return isSubPath(allowedRoot, resolvedGitDir);
|
|
607
716
|
}
|
|
608
|
-
async function ensureNoSymlinkPathSegments(root, targetPath, errorMessage) {
|
|
609
|
-
const resolvedRoot = path.resolve(root);
|
|
610
|
-
const resolvedTarget = path.resolve(targetPath);
|
|
611
|
-
const relative = path.relative(resolvedRoot, resolvedTarget);
|
|
612
|
-
if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
613
|
-
throw new Error(errorMessage);
|
|
614
|
-
}
|
|
615
|
-
let current = resolvedRoot;
|
|
616
|
-
const rootStat = await fs.lstat(current);
|
|
617
|
-
if (rootStat.isSymbolicLink()) {
|
|
618
|
-
throw new Error(errorMessage);
|
|
619
|
-
}
|
|
620
|
-
if (!relative) {
|
|
621
|
-
return;
|
|
622
|
-
}
|
|
623
|
-
for (const segment of relative.split(path.sep)) {
|
|
624
|
-
if (!segment) {
|
|
625
|
-
continue;
|
|
626
|
-
}
|
|
627
|
-
current = path.join(current, segment);
|
|
628
|
-
const stat = await fs.lstat(current).catch((error) => {
|
|
629
|
-
if (error.code === "ENOENT")
|
|
630
|
-
return null;
|
|
631
|
-
throw error;
|
|
632
|
-
});
|
|
633
|
-
if (!stat) {
|
|
634
|
-
return;
|
|
635
|
-
}
|
|
636
|
-
if (stat.isSymbolicLink()) {
|
|
637
|
-
throw new Error(errorMessage);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
717
|
async function pathExists(inputPath) {
|
|
642
718
|
return fs.stat(inputPath).then(() => true).catch(() => false);
|
|
643
719
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
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;
|
|
@@ -21,6 +24,22 @@ export interface WorktreePrepareRequest {
|
|
|
21
24
|
readonly warmPathOverrides?: readonly string[];
|
|
22
25
|
readonly applicationRuntimeRequired?: boolean;
|
|
23
26
|
readonly preserveExistingState?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Review-only checkout: the worktree is detached at exactly this commit and verified with
|
|
29
|
+
* `git rev-parse HEAD`. The lease branch is never created or advanced.
|
|
30
|
+
*/
|
|
31
|
+
readonly detachedHeadSha?: string | null;
|
|
32
|
+
/** The session this worktree is prepared for; names its WIP snapshots and enables restoring one. */
|
|
33
|
+
readonly sessionId?: string | null;
|
|
34
|
+
/** Forge's issued attempt for this dispatch (sandbox.wipAttempt), stamped on its WIP refs: newest work wins. */
|
|
35
|
+
readonly wipAttempt?: number | null;
|
|
36
|
+
/** The attempt dependency installs reserve host capacity for (decision 0013). */
|
|
37
|
+
readonly hostLoadOwner?: {
|
|
38
|
+
readonly dispatchAttemptId: string | null;
|
|
39
|
+
readonly priority: "foreground" | "background";
|
|
40
|
+
};
|
|
41
|
+
/** The attempt's cancellation: queued installs stop waiting and running ones are stopped. */
|
|
42
|
+
readonly signal?: AbortSignal;
|
|
24
43
|
}
|
|
25
44
|
export interface WorktreeHandle {
|
|
26
45
|
readonly repoPath: string;
|
|
@@ -31,4 +50,39 @@ export interface WorktreeHandle {
|
|
|
31
50
|
readonly dependencyWarm?: WarmDependenciesResult;
|
|
32
51
|
readonly qaReworkPacketPath?: string;
|
|
33
52
|
readonly hydratedPriorPhaseArtifactCount?: number;
|
|
53
|
+
/** Set when the worktree was checked out detached at a review head. */
|
|
54
|
+
readonly detachedHeadSha?: string;
|
|
55
|
+
readonly sessionId?: string | null;
|
|
56
|
+
readonly lane?: string;
|
|
57
|
+
/** Forge's issued attempt for the dispatch the worktree was prepared for; null from older servers. */
|
|
58
|
+
readonly wipAttempt?: number | null;
|
|
59
|
+
/** What happened to the story's saved WIP when this worktree was prepared. */
|
|
60
|
+
readonly wipRestore?: WipRestoreOutcome;
|
|
61
|
+
/**
|
|
62
|
+
* Recorded WIP re-apply conflicts the worktree still has (unresolvedWorktreeReapplyConflicts); the
|
|
63
|
+
* session defers the project start on them. Prepare fails when they cannot be read.
|
|
64
|
+
*/
|
|
65
|
+
readonly reapplyConflicts?: readonly string[];
|
|
66
|
+
/** Set when prepare moved a stale local branch or reused worktree up to origin's head. */
|
|
67
|
+
readonly originSync?: OriginSync;
|
|
68
|
+
}
|
|
69
|
+
/** A move of a prepared worktree's branch from a stale local commit to origin's head. */
|
|
70
|
+
export interface OriginSync {
|
|
71
|
+
readonly from: string;
|
|
72
|
+
readonly to: string;
|
|
73
|
+
/** Where the reused worktree's uncommitted work was saved before the move; null when it had none. */
|
|
74
|
+
readonly wipRef: string | null;
|
|
75
|
+
}
|
|
76
|
+
/** How a session ended, for its WIP snapshot: null when it succeeded. */
|
|
77
|
+
export interface WipSessionOutcome {
|
|
78
|
+
readonly reason: WipSnapshotReason | null;
|
|
79
|
+
}
|
|
80
|
+
export interface WipSettlement {
|
|
81
|
+
readonly snapshot?: WipSnapshotResult;
|
|
82
|
+
readonly error?: {
|
|
83
|
+
readonly code: string;
|
|
84
|
+
readonly message: string;
|
|
85
|
+
};
|
|
86
|
+
/** The restored snapshot's ref, deleted because this session's work supersedes it. */
|
|
87
|
+
readonly retiredRef?: string | null;
|
|
34
88
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loucompanion/forge-bridge",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1-dev.0f07274d438b",
|
|
4
4
|
"description": "Forge runner bridge CLI for connecting local developer machines to Forge dispatch.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"test:residue": "node scripts/run-owned-residue-gate.mjs",
|
|
44
44
|
"test:watch": "vitest",
|
|
45
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\""
|
|
46
|
+
"lint": "eslint \"src/**/*.ts\" \"scripts/**/*.mjs\" \"vitest.config.ts\" \"vitest.setup.ts\" && node ../../scripts/class-design/check-eslint-ratchet.mjs bridge"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@microsoft/signalr": "^8.0.17",
|
|
@@ -7,8 +7,10 @@ param(
|
|
|
7
7
|
|
|
8
8
|
$ErrorActionPreference = "Stop"
|
|
9
9
|
$parents = @{}
|
|
10
|
+
$created = @{}
|
|
10
11
|
Get-CimInstance Win32_Process | ForEach-Object {
|
|
11
12
|
$parents[[int]$_.ProcessId] = [int]$_.ParentProcessId
|
|
13
|
+
$created[[int]$_.ProcessId] = $_.CreationDate
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
$results = @()
|
|
@@ -25,7 +27,16 @@ foreach ($listenerText in $ListenerProcessIds.Split(',')) {
|
|
|
25
27
|
if (-not $parents.ContainsKey($current)) {
|
|
26
28
|
break
|
|
27
29
|
}
|
|
28
|
-
$
|
|
30
|
+
$parent = [int]$parents[$current]
|
|
31
|
+
# Windows keeps a child's ParentProcessId after the parent exits, and PIDs are reused. A
|
|
32
|
+
# "parent" created after the child is a different process that took the dead parent's PID,
|
|
33
|
+
# so the chain ends here; following it could attribute a foreign listener to the root.
|
|
34
|
+
if ($created.ContainsKey($parent) -and $created.ContainsKey($current) `
|
|
35
|
+
-and $null -ne $created[$parent] -and $null -ne $created[$current] `
|
|
36
|
+
-and $created[$parent] -gt $created[$current]) {
|
|
37
|
+
break
|
|
38
|
+
}
|
|
39
|
+
$current = $parent
|
|
29
40
|
}
|
|
30
41
|
$results += $owned
|
|
31
42
|
}
|