@loucompanion/forge-bridge 0.1.3-dev.b6be5e7f9668 → 0.1.3-dev.ba293ccf876b

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.
Files changed (196) hide show
  1. package/README.md +127 -0
  2. package/dist/bridge/bridge.base.d.ts +8 -1
  3. package/dist/bridge/bridge.service.d.ts +98 -3
  4. package/dist/bridge/bridge.service.js +1445 -48
  5. package/dist/bridge/bridge.types.d.ts +209 -1
  6. package/dist/bridge/readiness-result-outbox.d.ts +21 -0
  7. package/dist/bridge/readiness-result-outbox.js +54 -0
  8. package/dist/bridge/readiness-result-worker.d.ts +2 -0
  9. package/dist/bridge/readiness-result-worker.js +100 -0
  10. package/dist/bridge/runner-host-capabilities.d.ts +15 -0
  11. package/dist/bridge/runner-host-capabilities.js +93 -0
  12. package/dist/cleanup/cleanup.service.d.ts +14 -2
  13. package/dist/cleanup/cleanup.service.js +496 -3
  14. package/dist/cleanup/cleanup.types.d.ts +10 -0
  15. package/dist/cleanup/index.d.ts +1 -1
  16. package/dist/cleanup/index.js +1 -1
  17. package/dist/cleanup/internals.d.ts +2 -2
  18. package/dist/cleanup/internals.js +1 -1
  19. package/dist/cli/cli.help.d.ts +2 -0
  20. package/dist/cli/cli.help.js +217 -0
  21. package/dist/cli/cli.service.d.ts +45 -2
  22. package/dist/cli/cli.service.js +383 -209
  23. package/dist/cli/local-config.d.ts +7 -0
  24. package/dist/cli/local-config.js +51 -3
  25. package/dist/runtime/aspnet-runtime-prebuild.d.ts +36 -0
  26. package/dist/runtime/aspnet-runtime-prebuild.js +340 -0
  27. package/dist/runtime/attempt-node-runtime-launcher.d.ts +17 -0
  28. package/dist/runtime/attempt-node-runtime-launcher.js +105 -0
  29. package/dist/runtime/attempt-path-operation.d.ts +21 -0
  30. package/dist/runtime/attempt-path-operation.js +94 -0
  31. package/dist/runtime/attempt-private-directory.d.ts +6 -0
  32. package/dist/runtime/attempt-private-directory.js +54 -0
  33. package/dist/runtime/attempt-process-supervisor-registry.d.ts +20 -0
  34. package/dist/runtime/attempt-process-supervisor-registry.js +64 -0
  35. package/dist/runtime/attempt-process-supervisor.d.ts +97 -0
  36. package/dist/runtime/attempt-process-supervisor.js +386 -0
  37. package/dist/runtime/canonical-source-file.d.ts +3 -0
  38. package/dist/runtime/canonical-source-file.js +54 -0
  39. package/dist/runtime/docker-engine-probe.d.ts +83 -0
  40. package/dist/runtime/docker-engine-probe.js +300 -0
  41. package/dist/runtime/generated-output-reset.d.ts +10 -0
  42. package/dist/runtime/generated-output-reset.js +103 -0
  43. package/dist/runtime/host-diagnostics.d.ts +4 -0
  44. package/dist/runtime/host-diagnostics.js +95 -0
  45. package/dist/runtime/host-listener-inspector.d.ts +46 -0
  46. package/dist/runtime/host-listener-inspector.js +349 -0
  47. package/dist/runtime/host-port-broker.d.ts +76 -0
  48. package/dist/runtime/host-port-broker.js +333 -0
  49. package/dist/runtime/host-runtime-contract.d.ts +56 -0
  50. package/dist/runtime/host-runtime-contract.js +709 -0
  51. package/dist/runtime/host-runtime-lease.d.ts +201 -0
  52. package/dist/runtime/host-runtime-lease.js +2314 -0
  53. package/dist/runtime/host-runtime-promotion.d.ts +32 -0
  54. package/dist/runtime/host-runtime-promotion.js +206 -0
  55. package/dist/runtime/memory-capacity.d.ts +68 -0
  56. package/dist/runtime/memory-capacity.js +121 -0
  57. package/dist/runtime/node-host-runtime-adapter.d.ts +54 -0
  58. package/dist/runtime/node-host-runtime-adapter.js +284 -0
  59. package/dist/runtime/pinned-directory-process.d.ts +4 -0
  60. package/dist/runtime/pinned-directory-process.js +20 -0
  61. package/dist/runtime/pinned-source-directory.d.ts +9 -0
  62. package/dist/runtime/pinned-source-directory.js +56 -0
  63. package/dist/runtime/playwright-host-runtime-adapter.d.ts +21 -0
  64. package/dist/runtime/playwright-host-runtime-adapter.js +268 -0
  65. package/dist/runtime/prepared-runtime-identity.d.ts +3 -0
  66. package/dist/runtime/prepared-runtime-identity.js +191 -0
  67. package/dist/runtime/prepared-runtime-readiness.d.ts +22 -0
  68. package/dist/runtime/prepared-runtime-readiness.js +191 -0
  69. package/dist/runtime/runtime-isolation-lease.d.ts +67 -0
  70. package/dist/runtime/runtime-isolation-lease.js +158 -0
  71. package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
  72. package/dist/runtime/workspace-resource-estimator.js +174 -0
  73. package/dist/sandbox/command-runner.d.ts +4 -0
  74. package/dist/sandbox/command-runner.js +47 -0
  75. package/dist/sandbox/contract.d.ts +5 -0
  76. package/dist/sandbox/contract.js +276 -0
  77. package/dist/sandbox/event-budget.d.ts +11 -0
  78. package/dist/sandbox/event-budget.js +27 -0
  79. package/dist/sandbox/image-policy.d.ts +35 -0
  80. package/dist/sandbox/image-policy.js +247 -0
  81. package/dist/sandbox/index.d.ts +5 -0
  82. package/dist/sandbox/index.js +5 -0
  83. package/dist/sandbox/lease-watchdog.d.ts +18 -0
  84. package/dist/sandbox/lease-watchdog.js +67 -0
  85. package/dist/sandbox/preflight.d.ts +84 -0
  86. package/dist/sandbox/preflight.js +521 -0
  87. package/dist/sandbox/process.d.ts +20 -0
  88. package/dist/sandbox/process.js +209 -0
  89. package/dist/sandbox/provider-auth/codex.d.ts +26 -0
  90. package/dist/sandbox/provider-auth/codex.js +212 -0
  91. package/dist/sandbox/repository-lock.d.ts +5 -0
  92. package/dist/sandbox/repository-lock.js +121 -0
  93. package/dist/sandbox/runtime.d.ts +297 -0
  94. package/dist/sandbox/runtime.js +2338 -0
  95. package/dist/sandbox/sandbox.types.d.ts +93 -0
  96. package/dist/sandbox/sandbox.types.js +1 -0
  97. package/dist/sandbox/smoke.d.ts +76 -0
  98. package/dist/sandbox/smoke.js +380 -0
  99. package/dist/sandbox/worker-supervisor.d.ts +13 -0
  100. package/dist/sandbox/worker-supervisor.js +36 -0
  101. package/dist/sandbox/worker.d.ts +1 -0
  102. package/dist/sandbox/worker.js +225 -0
  103. package/dist/sandbox/workspace.service.d.ts +13 -0
  104. package/dist/sandbox/workspace.service.js +72 -0
  105. package/dist/session/managed-attempt-tools.d.ts +21 -0
  106. package/dist/session/managed-attempt-tools.js +912 -0
  107. package/dist/session/managed-build-coordinator.d.ts +5 -0
  108. package/dist/session/managed-build-coordinator.js +105 -0
  109. package/dist/session/managed-build-receipt.d.ts +21 -0
  110. package/dist/session/managed-build-receipt.js +335 -0
  111. package/dist/session/phase-completion.artifacts.d.ts +27 -0
  112. package/dist/session/phase-completion.artifacts.js +829 -0
  113. package/dist/session/phase-completion.d.ts +44 -46
  114. package/dist/session/phase-completion.helpers.d.ts +117 -0
  115. package/dist/session/phase-completion.helpers.js +701 -0
  116. package/dist/session/phase-completion.js +42 -3488
  117. package/dist/session/phase-completion.prompts.d.ts +14 -0
  118. package/dist/session/phase-completion.prompts.js +236 -0
  119. package/dist/session/phase-completion.runtime.d.ts +48 -0
  120. package/dist/session/phase-completion.runtime.js +790 -0
  121. package/dist/session/phase-completion.schemas.d.ts +3 -0
  122. package/dist/session/phase-completion.schemas.js +820 -0
  123. package/dist/session/phase-completion.validation.d.ts +37 -0
  124. package/dist/session/phase-completion.validation.js +855 -0
  125. package/dist/session/pre-publication-validation.d.ts +47 -0
  126. package/dist/session/pre-publication-validation.js +249 -0
  127. package/dist/session/provider-cli/ci-repair-readiness.d.ts +16 -0
  128. package/dist/session/provider-cli/ci-repair-readiness.js +110 -0
  129. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +94 -0
  130. package/dist/session/provider-cli/provider-cli.artifacts.js +812 -0
  131. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  132. package/dist/session/provider-cli/provider-cli.deterministic-payloads.d.ts +12 -0
  133. package/dist/session/provider-cli/provider-cli.deterministic-payloads.js +279 -0
  134. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +14 -0
  135. package/dist/session/provider-cli/provider-cli.deterministic.js +377 -0
  136. package/dist/session/provider-cli/provider-cli.process.d.ts +57 -0
  137. package/dist/session/provider-cli/provider-cli.process.js +716 -0
  138. package/dist/session/provider-cli/provider-cli.prompts.d.ts +47 -0
  139. package/dist/session/provider-cli/provider-cli.prompts.js +611 -0
  140. package/dist/session/provider-cli/provider-cli.qa-sidecars.d.ts +11 -0
  141. package/dist/session/provider-cli/provider-cli.qa-sidecars.js +66 -0
  142. package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
  143. package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
  144. package/dist/session/provider-cli/provider-cli.runtime.d.ts +9 -0
  145. package/dist/session/provider-cli/provider-cli.runtime.js +43 -0
  146. package/dist/session/provider-cli/provider-cli.service.d.ts +29 -53
  147. package/dist/session/provider-cli/provider-cli.service.js +640 -2581
  148. package/dist/session/provider-cli/provider-cli.types.d.ts +6 -0
  149. package/dist/session/provider-cli/provider-output-state.d.ts +22 -0
  150. package/dist/session/provider-cli/provider-output-state.js +520 -0
  151. package/dist/session/provider-cli/provider-usage.d.ts +7 -0
  152. package/dist/session/provider-cli/provider-usage.js +28 -5
  153. package/dist/session/session-redaction.d.ts +3 -0
  154. package/dist/session/session-redaction.js +38 -0
  155. package/dist/session/session.base.d.ts +6 -1
  156. package/dist/session/session.service.d.ts +8 -2
  157. package/dist/session/session.service.js +550 -58
  158. package/dist/session/session.types.d.ts +180 -1
  159. package/dist/session/session.types.js +323 -4
  160. package/dist/shared/format/format-bytes.d.ts +1 -0
  161. package/dist/shared/format/format-bytes.js +9 -0
  162. package/dist/shared/git/git.js +2 -1
  163. package/dist/shared/path/path.d.ts +1 -0
  164. package/dist/shared/path/path.js +21 -1
  165. package/dist/shared/process/dotnet-toolchain.d.ts +14 -0
  166. package/dist/shared/process/dotnet-toolchain.js +179 -0
  167. package/dist/shared/process/host-process-recovery.d.ts +12 -0
  168. package/dist/shared/process/host-process-recovery.js +78 -0
  169. package/dist/shared/process/host-process-supervisor.d.ts +59 -0
  170. package/dist/shared/process/host-process-supervisor.js +330 -0
  171. package/dist/shared/process/process.d.ts +2 -0
  172. package/dist/shared/process/process.js +11 -6
  173. package/dist/shared/process/windows-launch.d.ts +8 -0
  174. package/dist/shared/process/windows-launch.js +41 -0
  175. package/dist/shared/provider-capabilities.d.ts +1 -0
  176. package/dist/shared/provider-capabilities.js +3 -0
  177. package/dist/shared/redaction/redaction.js +16 -4
  178. package/dist/version.d.ts +1 -1
  179. package/dist/version.js +1 -1
  180. package/dist/worktree/artifact-injector.d.ts +3 -2
  181. package/dist/worktree/artifact-injector.js +82 -10
  182. package/dist/worktree/dependency-warmer.d.ts +39 -1
  183. package/dist/worktree/dependency-warmer.js +351 -8
  184. package/dist/worktree/index.d.ts +2 -1
  185. package/dist/worktree/index.js +1 -0
  186. package/dist/worktree/prior-phase-artifact-hydrator.d.ts +2 -0
  187. package/dist/worktree/prior-phase-artifact-hydrator.js +136 -0
  188. package/dist/worktree/worktree-paths.d.ts +4 -0
  189. package/dist/worktree/worktree-paths.js +30 -0
  190. package/dist/worktree/worktree.base.d.ts +3 -0
  191. package/dist/worktree/worktree.service.d.ts +16 -3
  192. package/dist/worktree/worktree.service.js +323 -54
  193. package/dist/worktree/worktree.types.d.ts +5 -1
  194. package/package.json +8 -4
  195. package/runtime/windows-job-supervisor.ps1 +444 -0
  196. package/runtime/windows-listener-owner.ps1 +33 -0
@@ -1,7 +1,13 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { existsSync, realpathSync } from "node:fs";
1
3
  import fs from "node:fs/promises";
4
+ import os from "node:os";
2
5
  import path from "node:path";
6
+ import { RepositoryCoordinatorLock } from "../sandbox/repository-lock.js";
3
7
  import { NodeProcessRunner } from "../shared/process/process.js";
8
+ import { buildWindowsCmdLaunch } from "../shared/process/windows-launch.js";
4
9
  import { isSubPath } from "../shared/path/path.js";
10
+ import { defaultWorktreeCoordinatorStateRoot } from "./worktree-paths.js";
5
11
  const SKIP_DIR_NAMES = new Set([
6
12
  ".git",
7
13
  "node_modules",
@@ -20,6 +26,10 @@ const NATIVE_MODULE_HINTS = [
20
26
  "better-sqlite3",
21
27
  "@swc/core"
22
28
  ];
29
+ const MAX_COMMAND_FAILURE_OUTPUT_LENGTH = 8_000;
30
+ const DEPENDENCY_RECEIPT_SCHEMA_VERSION = 1;
31
+ const DEPENDENCY_PREPARATION_CONTRACT = "managed-worktree-isolated-v1";
32
+ const dependencyPreparationCoordinator = new RepositoryCoordinatorLock(defaultWorktreeCoordinatorStateRoot());
23
33
  export async function detectWarmPaths(repoRoot, warmPathOverrides = []) {
24
34
  const entries = new Map();
25
35
  await collectDetectedPaths(repoRoot, repoRoot, entries, 0);
@@ -47,15 +57,51 @@ export async function warmWorktreeDependencies(request, executor = defaultComman
47
57
  const linked = [];
48
58
  const skipped = [];
49
59
  const fallbacks = [];
60
+ const receipts = [];
61
+ const restoredDotNetRoots = new Set();
62
+ const installedNodeRoots = new Set();
50
63
  for (const entry of warmPaths) {
51
64
  const sourcePath = path.join(baseCheckoutPath, entry.relativePath);
52
65
  const targetPath = path.join(worktreePath, entry.relativePath);
53
66
  assertWithinRoot(allowedRoot, targetPath, "Warm target");
67
+ if (entry.ecosystem === "node" && path.basename(entry.relativePath) === "node_modules") {
68
+ await removeLegacyDirectoryLink(targetPath, allowedRoot);
69
+ const installPackageRoot = await resolveNodeInstallPackageRoot(worktreePath, entry.packageRoot);
70
+ const packageRoot = path.resolve(worktreePath, installPackageRoot === "." ? "" : installPackageRoot);
71
+ const packageKey = process.platform === "win32" ? packageRoot.toLowerCase() : packageRoot;
72
+ if (installedNodeRoots.has(packageKey)) {
73
+ skipped.push(entry.relativePath);
74
+ continue;
75
+ }
76
+ installedNodeRoots.add(packageKey);
77
+ const preparation = await ensureInstallFallback({ ...entry, packageRoot: installPackageRoot }, worktreePath, "Managed worktrees require isolated Node dependencies.", executor, request.preparationPolicy);
78
+ receipts.push(preparation.receipt);
79
+ if (preparation.install)
80
+ fallbacks.push(preparation.install);
81
+ continue;
82
+ }
83
+ if (entry.ecosystem === "dotnet") {
84
+ await removeLegacyDirectoryLink(targetPath, allowedRoot);
85
+ const packageRoot = path.resolve(worktreePath, entry.packageRoot === "." ? "" : entry.packageRoot);
86
+ const packageKey = process.platform === "win32" ? packageRoot.toLowerCase() : packageRoot;
87
+ if (restoredDotNetRoots.has(packageKey)) {
88
+ skipped.push(entry.relativePath);
89
+ continue;
90
+ }
91
+ restoredDotNetRoots.add(packageKey);
92
+ const preparation = await ensureInstallFallback(entry, worktreePath, "Managed worktrees require isolated .NET build outputs.", executor, request.preparationPolicy);
93
+ receipts.push(preparation.receipt);
94
+ if (preparation.install)
95
+ fallbacks.push(preparation.install);
96
+ continue;
97
+ }
54
98
  const sourceExists = await directoryExists(sourcePath);
55
99
  const fallbackReason = await resolveFallbackReason(entry, baseCheckoutPath, worktreePath, sourceExists);
56
100
  if (fallbackReason) {
57
- const install = await runInstallFallback(entry, worktreePath, fallbackReason, executor);
58
- fallbacks.push(install);
101
+ const preparation = await ensureInstallFallback(entry, worktreePath, fallbackReason, executor, request.preparationPolicy);
102
+ receipts.push(preparation.receipt);
103
+ if (preparation.install)
104
+ fallbacks.push(preparation.install);
59
105
  continue;
60
106
  }
61
107
  if (!sourceExists) {
@@ -65,7 +111,17 @@ export async function warmWorktreeDependencies(request, executor = defaultComman
65
111
  await createDirectoryLink(sourcePath, targetPath, allowedRoot);
66
112
  linked.push(entry.relativePath);
67
113
  }
68
- return { linked, skipped, fallbacks };
114
+ return { linked, skipped, fallbacks, receipts };
115
+ }
116
+ async function removeLegacyDirectoryLink(targetPath, allowedRoot) {
117
+ const resolvedTarget = path.resolve(targetPath);
118
+ const resolvedRoot = path.resolve(allowedRoot);
119
+ assertWithinRoot(resolvedRoot, resolvedTarget, "Legacy warm target");
120
+ const stat = await fs.lstat(resolvedTarget).catch(() => null);
121
+ if (!stat?.isSymbolicLink()) {
122
+ return;
123
+ }
124
+ await fs.rm(resolvedTarget, { force: true });
69
125
  }
70
126
  export async function createDirectoryLink(sourcePath, targetPath, allowedRoot) {
71
127
  const resolvedSource = path.resolve(sourcePath);
@@ -78,7 +134,10 @@ export async function createDirectoryLink(sourcePath, targetPath, allowedRoot) {
78
134
  if (!stat?.isDirectory()) {
79
135
  throw new Error(`Link source must be an existing directory: ${resolvedSource}`);
80
136
  }
81
- await fs.rm(resolvedTarget, { recursive: true, force: true });
137
+ const existingTarget = await fs.lstat(resolvedTarget).catch(() => null);
138
+ await fs.rm(resolvedTarget, existingTarget?.isSymbolicLink()
139
+ ? { force: true }
140
+ : { recursive: true, force: true });
82
141
  await fs.mkdir(path.dirname(resolvedTarget), { recursive: true });
83
142
  if (process.platform === "win32") {
84
143
  await fs.symlink(resolvedSource, resolvedTarget, "junction");
@@ -179,12 +238,217 @@ export async function lockfilesDiffer(baseCheckoutPath, worktreePath, packageRoo
179
238
  }
180
239
  return false;
181
240
  }
241
+ async function ensureInstallFallback(entry, worktreePath, reason, executor, policy) {
242
+ const startedAt = performance.now();
243
+ const cwd = path.resolve(worktreePath, entry.packageRoot === "." ? "" : entry.packageRoot);
244
+ assertWithinRoot(path.resolve(worktreePath), cwd, "Dependency package root");
245
+ const command = await installFallbackCommand(entry, cwd);
246
+ const outputMarker = dependencyOutputMarker(entry.ecosystem, cwd);
247
+ const receiptPath = path.join(outputMarker, ".forge-dependency-preparation.json");
248
+ const fingerprint = await dependencyPreparationFingerprint(entry, worktreePath, cwd, command, policy);
249
+ return await dependencyPreparationCoordinator.withLock(receiptPath, async () => {
250
+ const existing = await readDependencyPreparationReceipt(receiptPath);
251
+ if (existing?.fingerprint === fingerprint
252
+ && existing.ecosystem === entry.ecosystem
253
+ && existing.packageRoot === entry.packageRoot
254
+ && existing.command === command
255
+ && await directoryExists(outputMarker)) {
256
+ return {
257
+ install: null,
258
+ receipt: {
259
+ ecosystem: entry.ecosystem,
260
+ packageRoot: entry.packageRoot,
261
+ command,
262
+ cacheHit: true,
263
+ fingerprint,
264
+ receiptPath,
265
+ durationMs: elapsedMilliseconds(startedAt),
266
+ },
267
+ };
268
+ }
269
+ const install = await runInstallFallback(entry, worktreePath, reason, executor);
270
+ // npm is allowed to omit node_modules when the package graph is empty. Keep
271
+ // an isolated, ignored output directory so the durable receipt still has a
272
+ // concrete marker whose removal invalidates reuse.
273
+ if (entry.ecosystem === "node") {
274
+ await fs.mkdir(outputMarker, { recursive: true });
275
+ }
276
+ if (!(await directoryExists(outputMarker))) {
277
+ throw new Error(`dependency_preparation_output_missing: ${install.command} succeeded without creating ${outputMarker}.`);
278
+ }
279
+ const receipt = {
280
+ schemaVersion: DEPENDENCY_RECEIPT_SCHEMA_VERSION,
281
+ fingerprint,
282
+ ecosystem: entry.ecosystem,
283
+ packageRoot: entry.packageRoot,
284
+ command,
285
+ outputMarker: path.relative(cwd, outputMarker).replaceAll("\\", "/"),
286
+ completedAt: new Date().toISOString(),
287
+ };
288
+ await persistDependencyPreparationReceipt(receiptPath, receipt);
289
+ return {
290
+ install,
291
+ receipt: {
292
+ ecosystem: entry.ecosystem,
293
+ packageRoot: entry.packageRoot,
294
+ command,
295
+ cacheHit: false,
296
+ fingerprint,
297
+ receiptPath,
298
+ durationMs: elapsedMilliseconds(startedAt),
299
+ },
300
+ };
301
+ });
302
+ }
303
+ function elapsedMilliseconds(startedAt) {
304
+ return Math.max(0, Math.round((performance.now() - startedAt) * 1000) / 1000);
305
+ }
306
+ async function installFallbackCommand(entry, cwd) {
307
+ if (entry.ecosystem === "node") {
308
+ if (await pathExists(path.join(cwd, "pnpm-lock.yaml")))
309
+ return "pnpm install --frozen-lockfile";
310
+ return await pathExists(path.join(cwd, "package-lock.json")) ? "npm ci" : "npm install";
311
+ }
312
+ if (entry.ecosystem === "python") {
313
+ return await pathExists(path.join(cwd, "requirements.txt"))
314
+ ? "python -m venv .venv && pip install -r requirements.txt"
315
+ : "python -m venv .venv";
316
+ }
317
+ return "dotnet restore";
318
+ }
319
+ function dependencyOutputMarker(ecosystem, cwd) {
320
+ if (ecosystem === "node")
321
+ return path.join(cwd, "node_modules");
322
+ if (ecosystem === "python")
323
+ return path.join(cwd, ".venv");
324
+ return path.join(cwd, "obj");
325
+ }
326
+ async function dependencyPreparationFingerprint(entry, worktreePath, cwd, command, policy) {
327
+ const inputFiles = await dependencyInputFiles(entry.ecosystem, worktreePath, cwd);
328
+ const inputDigests = await Promise.all(inputFiles.map(async (file) => ({
329
+ path: path.relative(worktreePath, file).replaceAll("\\", "/"),
330
+ digest: await sha256File(file),
331
+ })));
332
+ const toolchainVersion = await dependencyToolchainVersion(entry.ecosystem, cwd, policy);
333
+ const trustDomain = policy?.trustDomain ?? process.env.FORGE_TRUST_DOMAIN_ID ?? "default";
334
+ const invalidationEpoch = policy?.invalidationEpoch ?? process.env.FORGE_DEPENDENCY_CACHE_EPOCH ?? "default";
335
+ const contract = {
336
+ schemaVersion: DEPENDENCY_RECEIPT_SCHEMA_VERSION,
337
+ preparationContract: DEPENDENCY_PREPARATION_CONTRACT,
338
+ ecosystem: entry.ecosystem,
339
+ packageRoot: entry.packageRoot.replaceAll("\\", "/"),
340
+ command,
341
+ inputDigests,
342
+ toolchainVersion,
343
+ nodeRuntime: process.version,
344
+ platform: process.platform,
345
+ architecture: process.arch,
346
+ osRelease: os.release(),
347
+ isolation: policy?.isolation ?? process.env.FORGE_RUNTIME_MODE ?? "managed_host_process",
348
+ trustDomainFingerprint: sha256Text(trustDomain),
349
+ invalidationEpochFingerprint: sha256Text(invalidationEpoch),
350
+ };
351
+ return `sha256:${sha256Text(JSON.stringify(contract))}`;
352
+ }
353
+ async function dependencyInputFiles(ecosystem, worktreePath, cwd) {
354
+ const result = new Set();
355
+ const directNames = ecosystem === "node"
356
+ ? ["package.json", "package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "pnpm-workspace.yaml", "yarn.lock", ".npmrc", ".yarnrc", ".yarnrc.yml", ".nvmrc", ".node-version"]
357
+ : ecosystem === "python"
358
+ ? ["pyproject.toml", "requirements.txt", "requirements-dev.txt", "poetry.lock", "Pipfile", "Pipfile.lock", "uv.lock", "pip.conf", "pyvenv.cfg"]
359
+ : ["global.json", "NuGet.Config", "nuget.config", "Directory.Build.props", "Directory.Build.targets", "Directory.Packages.props", "packages.lock.json"];
360
+ let current = cwd;
361
+ const root = path.resolve(worktreePath);
362
+ while (isSubPath(root, current)) {
363
+ for (const name of directNames) {
364
+ const candidate = path.join(current, name);
365
+ if (await pathExists(candidate))
366
+ result.add(candidate);
367
+ }
368
+ if (ecosystem === "dotnet" && current === cwd) {
369
+ const entries = await fs.readdir(current, { withFileTypes: true }).catch(() => []);
370
+ for (const item of entries) {
371
+ if (item.isFile() && (/\.(?:csproj|fsproj|vbproj|sln|slnx)$/iu.test(item.name))) {
372
+ result.add(path.join(current, item.name));
373
+ }
374
+ }
375
+ }
376
+ if (current === root)
377
+ break;
378
+ current = path.dirname(current);
379
+ }
380
+ return [...result].sort((left, right) => left.localeCompare(right));
381
+ }
382
+ async function dependencyToolchainVersion(ecosystem, cwd, policy) {
383
+ if (ecosystem === "node") {
384
+ const manager = await pathExists(path.join(cwd, "pnpm-lock.yaml")) ? "pnpm" : "npm";
385
+ const override = policy?.toolchainVersions?.[manager];
386
+ if (override)
387
+ return `${manager}@${override};node@${process.version}`;
388
+ const launch = manager === "pnpm" ? resolvePnpmLaunch(["--version"]) : resolveNpmLaunch(["--version"]);
389
+ return `${manager}@${await readToolVersion(cwd, launch.command, launch.args)};node@${process.version}`;
390
+ }
391
+ const override = policy?.toolchainVersions?.[ecosystem];
392
+ if (override)
393
+ return `${ecosystem}@${override}`;
394
+ const launch = ecosystem === "dotnet"
395
+ ? { command: "dotnet", args: ["--version"] }
396
+ : { command: "python", args: ["--version"] };
397
+ return `${ecosystem}@${await readToolVersion(cwd, launch.command, launch.args)}`;
398
+ }
399
+ async function readToolVersion(cwd, command, args) {
400
+ return await defaultProcessRunner.run({ command, cwd, args })
401
+ .then(result => result.exitCode === 0
402
+ ? (result.stdout.trim() || result.stderr.trim() || "unknown").slice(0, 256)
403
+ : `unavailable:${result.exitCode}`)
404
+ .catch(() => "unavailable");
405
+ }
406
+ async function readDependencyPreparationReceipt(receiptPath) {
407
+ try {
408
+ const parsed = JSON.parse(await fs.readFile(receiptPath, "utf8"));
409
+ return parsed.schemaVersion === DEPENDENCY_RECEIPT_SCHEMA_VERSION
410
+ && typeof parsed.fingerprint === "string"
411
+ && typeof parsed.ecosystem === "string"
412
+ && typeof parsed.packageRoot === "string"
413
+ && typeof parsed.command === "string"
414
+ && typeof parsed.outputMarker === "string"
415
+ ? parsed
416
+ : null;
417
+ }
418
+ catch (error) {
419
+ if (error.code === "ENOENT" || error instanceof SyntaxError)
420
+ return null;
421
+ throw error;
422
+ }
423
+ }
424
+ async function persistDependencyPreparationReceipt(receiptPath, receipt) {
425
+ await fs.mkdir(path.dirname(receiptPath), { recursive: true });
426
+ const temporaryPath = `${receiptPath}.${randomUUID()}.tmp`;
427
+ await fs.writeFile(temporaryPath, `${JSON.stringify(receipt, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
428
+ try {
429
+ await fs.rename(temporaryPath, receiptPath);
430
+ }
431
+ finally {
432
+ await fs.rm(temporaryPath, { force: true }).catch(() => undefined);
433
+ }
434
+ }
435
+ function sha256Text(value) {
436
+ return createHash("sha256").update(value).digest("hex");
437
+ }
182
438
  async function runInstallFallback(entry, worktreePath, reason, executor) {
183
439
  const cwd = path.join(worktreePath, entry.packageRoot === "." ? "" : entry.packageRoot);
184
440
  if (entry.ecosystem === "node") {
441
+ const pnpmLockPath = path.join(cwd, "pnpm-lock.yaml");
442
+ if (await pathExists(pnpmLockPath)) {
443
+ const args = ["install", "--frozen-lockfile"];
444
+ const launch = resolvePnpmLaunch(args);
445
+ await executor.run(cwd, launch.command, launch.args, { env: unattendedPackageManagerEnvironment() });
446
+ return { ecosystem: entry.ecosystem, packageRoot: entry.packageRoot, reason, command: `pnpm ${args.join(" ")}` };
447
+ }
185
448
  const lockPath = path.join(cwd, "package-lock.json");
186
449
  const args = (await pathExists(lockPath)) ? ["ci"] : ["install"];
187
- await executor.run(cwd, "npm", args);
450
+ const launch = resolveNpmLaunch(args);
451
+ await executor.run(cwd, launch.command, launch.args, { env: unattendedPackageManagerEnvironment() });
188
452
  return { ecosystem: entry.ecosystem, packageRoot: entry.packageRoot, reason, command: `npm ${args.join(" ")}` };
189
453
  }
190
454
  if (entry.ecosystem === "python") {
@@ -215,6 +479,23 @@ async function runInstallFallback(entry, worktreePath, reason, executor) {
215
479
  command: "dotnet restore"
216
480
  };
217
481
  }
482
+ async function resolveNodeInstallPackageRoot(worktreePath, packageRoot) {
483
+ const resolvedWorktree = path.resolve(worktreePath);
484
+ let current = path.resolve(resolvedWorktree, packageRoot === "." ? "" : packageRoot);
485
+ assertWithinRoot(resolvedWorktree, current, "Node package root");
486
+ while (isSubPath(resolvedWorktree, current)) {
487
+ if (await pathExists(path.join(current, "pnpm-lock.yaml"))
488
+ || await pathExists(path.join(current, "pnpm-workspace.yaml"))
489
+ || await pathExists(path.join(current, "package-lock.json"))) {
490
+ const relative = normalizeRelativePath(path.relative(resolvedWorktree, current));
491
+ return relative || ".";
492
+ }
493
+ if (current === resolvedWorktree)
494
+ break;
495
+ current = path.dirname(current);
496
+ }
497
+ return packageRoot;
498
+ }
218
499
  export async function requiresInstallFallback(entry, baseCheckoutPath, worktreePath, sourceExists) {
219
500
  return resolveFallbackReason(entry, baseCheckoutPath, worktreePath, sourceExists);
220
501
  }
@@ -286,11 +567,73 @@ async function sha256File(filePath) {
286
567
  const content = await fs.readFile(filePath);
287
568
  return crypto.createHash("sha256").update(content).digest("hex");
288
569
  }
570
+ export function resolveNpmLaunch(args, options = {}) {
571
+ const env = options.env ?? process.env;
572
+ const execPath = options.execPath ?? process.execPath;
573
+ const npmExecPath = env.npm_execpath;
574
+ if (npmExecPath && path.basename(npmExecPath).toLowerCase() === "npm-cli.js") {
575
+ return { command: execPath, args: [npmExecPath, ...args] };
576
+ }
577
+ const platform = options.platform ?? process.platform;
578
+ if (platform === "win32") {
579
+ const comSpec = options.env ? env.ComSpec ?? "cmd.exe" : env.ComSpec;
580
+ return buildWindowsCmdLaunch("npm.cmd", args, comSpec);
581
+ }
582
+ for (const candidate of options.candidates ?? defaultNpmCliCandidates(execPath, options.homeDir ?? os.homedir())) {
583
+ const resolvedCandidate = tryResolveNpmCandidate(candidate);
584
+ if (resolvedCandidate) {
585
+ return { command: execPath, args: [resolvedCandidate, ...args] };
586
+ }
587
+ }
588
+ return { command: "npm", args };
589
+ }
590
+ export function resolvePnpmLaunch(args) {
591
+ if (process.platform === "win32") {
592
+ return buildWindowsCmdLaunch("pnpm.cmd", args, process.env.ComSpec);
593
+ }
594
+ return { command: "pnpm", args };
595
+ }
596
+ export function formatCommandFailureOutput(stdout, stderr) {
597
+ const sections = [
598
+ stderr.trim().length > 0 ? `stderr:\n${stderr.trim()}` : null,
599
+ stdout.trim().length > 0 ? `stdout:\n${stdout.trim()}` : null,
600
+ ].filter((section) => section !== null);
601
+ const output = sections.join("\n");
602
+ if (output.length <= MAX_COMMAND_FAILURE_OUTPUT_LENGTH) {
603
+ return output;
604
+ }
605
+ return `[last ${MAX_COMMAND_FAILURE_OUTPUT_LENGTH} characters]\n${output.slice(-MAX_COMMAND_FAILURE_OUTPUT_LENGTH)}`;
606
+ }
607
+ export function unattendedPackageManagerEnvironment(env = process.env) {
608
+ return { ...env, CI: "true" };
609
+ }
610
+ function tryResolveNpmCandidate(candidate) {
611
+ try {
612
+ if (!existsSync(candidate)) {
613
+ return null;
614
+ }
615
+ return realpathSync(candidate);
616
+ }
617
+ catch {
618
+ return null;
619
+ }
620
+ }
621
+ function defaultNpmCliCandidates(execPath, homeDir) {
622
+ const candidates = [];
623
+ const execDir = path.dirname(execPath);
624
+ if (path.isAbsolute(execDir)) {
625
+ candidates.push(path.join(execDir, "npm"), path.join(execDir, "npm-cli.js"), path.join(execDir, "..", "lib", "node_modules", "npm", "bin", "npm-cli.js"));
626
+ }
627
+ candidates.push("/usr/bin/npm", "/usr/local/bin/npm", path.join(homeDir, ".npm-global", "bin", "npm"), path.join(homeDir, ".npm-global", "lib", "node_modules", "npm", "bin", "npm-cli.js"));
628
+ return candidates;
629
+ }
289
630
  const defaultCommandExecutor = {
290
- async run(cwd, command, args) {
291
- const result = await defaultProcessRunner.run({ command, cwd, args });
631
+ async run(cwd, command, args, options) {
632
+ const result = await defaultProcessRunner.run({ command, cwd, args, env: options?.env });
292
633
  if (result.exitCode !== 0) {
293
- throw new Error(`${command} ${args.join(" ")} failed (${result.exitCode}): ${result.stderr.trim()}`);
634
+ const output = formatCommandFailureOutput(result.stdout, result.stderr);
635
+ const details = output.length > 0 ? `\n${output}` : " no output was captured";
636
+ throw new Error(`${command} ${args.join(" ")} failed (${result.exitCode}) in ${cwd}:${details}`);
294
637
  }
295
638
  }
296
639
  };
@@ -1,4 +1,5 @@
1
1
  export { GitWorktreeService } from "./worktree.service.js";
2
+ export { managedRepoRoot, resolveManagedWorktreeRoot, resolveManagedWorktreeRootForRepo, } from "./worktree-paths.js";
2
3
  export { detectWarmPaths, warmWorktreeDependencies, createDirectoryLink, lockfilesDiffer, requiresInstallFallback } from "./dependency-warmer.js";
3
- export type { WarmDependenciesResult, WarmPathEntry, InstallFallbackResult } from "./dependency-warmer.js";
4
+ export type { WarmDependenciesResult, WarmPathEntry, InstallFallbackResult, DependencyPreparationPolicy, DependencyPreparationReceiptResult, } from "./dependency-warmer.js";
4
5
  export type { WorktreeService } from "./worktree.base.js";
@@ -1,2 +1,3 @@
1
1
  export { GitWorktreeService } from "./worktree.service.js";
2
+ export { managedRepoRoot, resolveManagedWorktreeRoot, resolveManagedWorktreeRootForRepo, } from "./worktree-paths.js";
2
3
  export { detectWarmPaths, warmWorktreeDependencies, createDirectoryLink, lockfilesDiffer, requiresInstallFallback } from "./dependency-warmer.js";
@@ -0,0 +1,2 @@
1
+ import type { DispatchPriorPhaseArtifact } from "../session/session.types.js";
2
+ export declare function hydratePriorPhaseArtifacts(worktreePath: string, artifacts?: readonly DispatchPriorPhaseArtifact[]): Promise<number>;
@@ -0,0 +1,136 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { isSubPath } from "../shared/path/path.js";
5
+ const MAX_ARTIFACT_COUNT = 128;
6
+ const MAX_CONTENT_BYTES = 2 * 1024 * 1024;
7
+ const MAX_TOTAL_BYTES = 12 * 1024 * 1024;
8
+ const phaseFiles = {
9
+ implementation: {
10
+ verdict: "implementation.completeness.json",
11
+ report: "implementation.report.md"
12
+ },
13
+ self_review: {
14
+ verdict: "self-review.report.json",
15
+ report: "self-review.summary.md"
16
+ },
17
+ validation: {
18
+ verdict: "validation.verdict.json",
19
+ report: "validation.report.md"
20
+ }
21
+ };
22
+ export async function hydratePriorPhaseArtifacts(worktreePath, artifacts = []) {
23
+ if (artifacts.length === 0)
24
+ return 0;
25
+ if (artifacts.length > MAX_ARTIFACT_COUNT) {
26
+ throw new Error(`Prior phase artifact handoff exceeds ${MAX_ARTIFACT_COUNT} artifacts.`);
27
+ }
28
+ const targets = new Set();
29
+ let totalBytes = 0;
30
+ for (const artifact of artifacts) {
31
+ const workItemId = safeArtifactSegment(artifact.workItemId, "work item id");
32
+ const files = phaseFiles[artifact.phase];
33
+ if (!files) {
34
+ throw new Error(`Unsupported prior phase artifact phase '${artifact.phase}'.`);
35
+ }
36
+ const verdictBytes = Buffer.byteLength(artifact.verdictJson, "utf8");
37
+ const reportBytes = Buffer.byteLength(artifact.report, "utf8");
38
+ if (verdictBytes > MAX_CONTENT_BYTES || reportBytes > MAX_CONTENT_BYTES) {
39
+ throw new Error(`Prior phase artifact '${artifact.artifactId}' exceeds the per-file hydration limit.`);
40
+ }
41
+ totalBytes += verdictBytes + reportBytes;
42
+ if (totalBytes > MAX_TOTAL_BYTES) {
43
+ throw new Error("Prior phase artifact handoff exceeds the total hydration limit.");
44
+ }
45
+ verifyContentHash(artifact.verdictJson, artifact.verdictContentHash, artifact.artifactId, "verdict");
46
+ verifyContentHash(artifact.report, artifact.reportContentHash, artifact.artifactId, "report");
47
+ validateVerdict(artifact);
48
+ const artifactRoot = path.resolve(worktreePath, ".forge", "work-items", workItemId, "artifacts");
49
+ if (!isSubPath(worktreePath, artifactRoot)) {
50
+ throw new Error("Prior phase artifact target must stay under the worktree.");
51
+ }
52
+ await ensureNoSymlinkPathSegments(worktreePath, artifactRoot);
53
+ await fs.mkdir(artifactRoot, { recursive: true });
54
+ await ensureNoSymlinkPathSegments(worktreePath, artifactRoot);
55
+ const verdictPath = path.join(artifactRoot, files.verdict);
56
+ const reportPath = path.join(artifactRoot, files.report);
57
+ const targetKey = verdictPath.toLowerCase();
58
+ if (targets.has(targetKey)) {
59
+ throw new Error(`Duplicate prior phase artifact target for work item '${workItemId}' phase '${artifact.phase}'.`);
60
+ }
61
+ targets.add(targetKey);
62
+ await writeAtomic(verdictPath, artifact.verdictJson);
63
+ await writeAtomic(reportPath, artifact.report);
64
+ }
65
+ return artifacts.length;
66
+ }
67
+ function validateVerdict(artifact) {
68
+ let parsed;
69
+ try {
70
+ parsed = JSON.parse(artifact.verdictJson);
71
+ }
72
+ catch {
73
+ throw new Error(`Prior phase artifact '${artifact.artifactId}' verdict is not valid JSON.`);
74
+ }
75
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
76
+ throw new Error(`Prior phase artifact '${artifact.artifactId}' verdict must be a JSON object.`);
77
+ }
78
+ const recordedPhase = parsed["phase"];
79
+ const normalizedPhase = typeof recordedPhase === "string"
80
+ ? recordedPhase.trim().toLowerCase().replace(/-/g, "_")
81
+ : "";
82
+ if (normalizedPhase !== artifact.phase) {
83
+ throw new Error(`Prior phase artifact '${artifact.artifactId}' phase does not match its verdict.`);
84
+ }
85
+ }
86
+ function verifyContentHash(content, expected, artifactId, label) {
87
+ const normalizedExpected = expected.trim().toLowerCase().replace(/^sha256:/, "");
88
+ if (!/^[0-9a-f]{64}$/.test(normalizedExpected)) {
89
+ throw new Error(`Prior phase artifact '${artifactId}' ${label} hash is invalid.`);
90
+ }
91
+ const actual = createHash("sha256").update(content, "utf8").digest("hex");
92
+ if (actual !== normalizedExpected) {
93
+ throw new Error(`Prior phase artifact '${artifactId}' ${label} content_hash mismatch.`);
94
+ }
95
+ }
96
+ function safeArtifactSegment(value, label) {
97
+ const trimmed = value.trim();
98
+ if (!/^[a-zA-Z0-9_-]{1,128}$/.test(trimmed)) {
99
+ throw new Error(`Prior phase artifact ${label} is not a safe path segment.`);
100
+ }
101
+ return trimmed;
102
+ }
103
+ async function writeAtomic(targetPath, content) {
104
+ const temporaryPath = `${targetPath}.tmp-${randomUUID()}`;
105
+ try {
106
+ await fs.writeFile(temporaryPath, content, { encoding: "utf8", mode: 0o600, flag: "wx" });
107
+ await fs.rename(temporaryPath, targetPath);
108
+ }
109
+ finally {
110
+ await fs.rm(temporaryPath, { force: true }).catch(() => undefined);
111
+ }
112
+ }
113
+ async function ensureNoSymlinkPathSegments(root, targetPath) {
114
+ const resolvedRoot = path.resolve(root);
115
+ const resolvedTarget = path.resolve(targetPath);
116
+ const relative = path.relative(resolvedRoot, resolvedTarget);
117
+ if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
118
+ throw new Error("Prior phase artifact path must stay under the worktree.");
119
+ }
120
+ let current = resolvedRoot;
121
+ for (const segment of relative.split(path.sep)) {
122
+ if (!segment)
123
+ continue;
124
+ current = path.join(current, segment);
125
+ const stat = await fs.lstat(current).catch((error) => {
126
+ if (error.code === "ENOENT")
127
+ return null;
128
+ throw error;
129
+ });
130
+ if (!stat)
131
+ return;
132
+ if (stat.isSymbolicLink()) {
133
+ throw new Error("Prior phase artifact path must not traverse symlinked path segments.");
134
+ }
135
+ }
136
+ }
@@ -0,0 +1,4 @@
1
+ export declare function managedRepoRoot(allowedRoot: string): string;
2
+ export declare function resolveManagedWorktreeRoot(allowedRoot: string, repoPath: string): string;
3
+ export declare function resolveManagedWorktreeRootForRepo(repoPath: string, allowedRoot?: string): string;
4
+ export declare function defaultWorktreeCoordinatorStateRoot(): string;
@@ -0,0 +1,30 @@
1
+ import os from "node:os";
2
+ import path from "node:path";
3
+ import { isSubPath } from "../shared/path/path.js";
4
+ export function managedRepoRoot(allowedRoot) {
5
+ return path.join(path.resolve(allowedRoot), ".forge-worktrees", "_repos");
6
+ }
7
+ export function resolveManagedWorktreeRoot(allowedRoot, repoPath) {
8
+ const resolvedAllowedRoot = path.resolve(allowedRoot);
9
+ const resolvedRepoPath = path.resolve(repoPath);
10
+ const baseName = path.basename(resolvedRepoPath);
11
+ return isSubPath(managedRepoRoot(resolvedAllowedRoot), resolvedRepoPath)
12
+ ? path.join(resolvedAllowedRoot, ".forge-worktrees", baseName)
13
+ : path.join(path.dirname(resolvedRepoPath), ".forge-worktrees", baseName);
14
+ }
15
+ export function resolveManagedWorktreeRootForRepo(repoPath, allowedRoot) {
16
+ const resolvedRepoPath = path.resolve(repoPath);
17
+ if (allowedRoot && isSubPath(path.resolve(allowedRoot), resolvedRepoPath)) {
18
+ return resolveManagedWorktreeRoot(allowedRoot, resolvedRepoPath);
19
+ }
20
+ const repoParent = path.dirname(resolvedRepoPath);
21
+ const managedRoot = path.dirname(repoParent);
22
+ if (path.basename(repoParent) === "_repos" && path.basename(managedRoot) === ".forge-worktrees") {
23
+ return path.join(managedRoot, path.basename(resolvedRepoPath));
24
+ }
25
+ return path.join(repoParent, ".forge-worktrees", path.basename(resolvedRepoPath));
26
+ }
27
+ export function defaultWorktreeCoordinatorStateRoot() {
28
+ return process.env.FORGE_SANDBOX_STATE_ROOT
29
+ ?? path.join(os.homedir(), ".forge", "bridge", "sandboxes");
30
+ }
@@ -3,3 +3,6 @@ export interface WorktreeService {
3
3
  prepare(request: WorktreePrepareRequest): Promise<WorktreeHandle>;
4
4
  release(handle: WorktreeHandle): Promise<void>;
5
5
  }
6
+ export interface WorktreeLifecycleCoordinator {
7
+ withLock<T>(repoPath: string, action: () => Promise<T>, signal?: AbortSignal): Promise<T>;
8
+ }
@@ -1,17 +1,30 @@
1
1
  import { GitClient } from "../shared/git/git.js";
2
- import type { WorktreeService } from "./worktree.base.js";
2
+ import type { WorktreeLifecycleCoordinator, WorktreeService } from "./worktree.base.js";
3
3
  import type { WorktreeHandle, WorktreePrepareRequest } from "./worktree.types.js";
4
4
  export declare class GitWorktreeService implements WorktreeService {
5
5
  private readonly git;
6
- constructor(git?: GitClient);
6
+ private readonly coordinator;
7
+ constructor(git?: GitClient, coordinator?: WorktreeLifecycleCoordinator);
7
8
  prepare(request: WorktreePrepareRequest): Promise<WorktreeHandle>;
9
+ private trackedForgePaths;
10
+ private registeredManagedWorktreePath;
11
+ private repoCreationCoordinationPath;
8
12
  release(handle: WorktreeHandle): Promise<void>;
13
+ private restoreOrphanedWorktree;
9
14
  private resolveRepoPath;
15
+ private managedRepoPath;
10
16
  private findExistingRepoPath;
11
17
  private resolveMatchingRepo;
12
- private ensureBaseBranch;
18
+ private resolveBaseStartPoint;
19
+ private resetWorktreeToBase;
13
20
  private gitRefExists;
14
21
  private currentBranch;
15
22
  private ensureGitIdentity;
16
23
  }
24
+ type WorktreeRename = (source: string, destination: string) => Promise<void>;
25
+ type WorktreeRenameDelay = (milliseconds: number) => Promise<void>;
26
+ export declare function renameWorktreeForRelease(source: string, destination: string, rename?: WorktreeRename, wait?: WorktreeRenameDelay, maxAttempts?: number): Promise<void>;
27
+ export declare function requiresMutableEnvironmentPreparation(request: Pick<WorktreePrepareRequest, "applicationRuntimeRequired">): boolean;
28
+ export declare function clearRunArtifactRoots(worktreePath: string, request: WorktreePrepareRequest): Promise<void>;
17
29
  export declare function normalizeBranchName(value: string | null | undefined, fallback: string): string;
30
+ export {};