@loucompanion/forge-bridge 0.1.3-dev.f66395c3ac21 → 0.1.4-dev.028808a841c8

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 (243) hide show
  1. package/README.md +165 -1
  2. package/dist/bridge/bridge-chat.types.d.ts +111 -0
  3. package/dist/bridge/bridge-chat.types.js +401 -0
  4. package/dist/bridge/bridge.base.d.ts +9 -1
  5. package/dist/bridge/bridge.service.d.ts +140 -3
  6. package/dist/bridge/bridge.service.js +2471 -68
  7. package/dist/bridge/bridge.types.d.ts +224 -2
  8. package/dist/bridge/dispatch-result-outbox.d.ts +35 -0
  9. package/dist/bridge/dispatch-result-outbox.js +87 -0
  10. package/dist/bridge/dispatch-result-worker.d.ts +2 -0
  11. package/dist/bridge/dispatch-result-worker.js +122 -0
  12. package/dist/bridge/internals.d.ts +2 -0
  13. package/dist/bridge/internals.js +1 -0
  14. package/dist/bridge/readiness-result-outbox.d.ts +21 -0
  15. package/dist/bridge/readiness-result-outbox.js +54 -0
  16. package/dist/bridge/readiness-result-worker.d.ts +2 -0
  17. package/dist/bridge/readiness-result-worker.js +121 -0
  18. package/dist/bridge/runner-host-capabilities.d.ts +15 -0
  19. package/dist/bridge/runner-host-capabilities.js +93 -0
  20. package/dist/cleanup/cleanup.service.d.ts +14 -2
  21. package/dist/cleanup/cleanup.service.js +496 -3
  22. package/dist/cleanup/cleanup.types.d.ts +10 -0
  23. package/dist/cleanup/index.d.ts +1 -1
  24. package/dist/cleanup/index.js +1 -1
  25. package/dist/cleanup/internals.d.ts +2 -2
  26. package/dist/cleanup/internals.js +1 -1
  27. package/dist/cli/cli.help.d.ts +2 -0
  28. package/dist/cli/cli.help.js +217 -0
  29. package/dist/cli/cli.service.d.ts +55 -7
  30. package/dist/cli/cli.service.js +429 -219
  31. package/dist/cli/local-config.d.ts +7 -0
  32. package/dist/cli/local-config.js +51 -3
  33. package/dist/runtime/aspnet-runtime-prebuild.d.ts +36 -0
  34. package/dist/runtime/aspnet-runtime-prebuild.js +341 -0
  35. package/dist/runtime/attempt-database-broker.d.ts +89 -0
  36. package/dist/runtime/attempt-database-broker.js +390 -0
  37. package/dist/runtime/attempt-node-runtime-launcher.d.ts +18 -0
  38. package/dist/runtime/attempt-node-runtime-launcher.js +140 -0
  39. package/dist/runtime/attempt-path-operation.d.ts +21 -0
  40. package/dist/runtime/attempt-path-operation.js +94 -0
  41. package/dist/runtime/attempt-private-directory.d.ts +6 -0
  42. package/dist/runtime/attempt-private-directory.js +54 -0
  43. package/dist/runtime/attempt-process-supervisor-registry.d.ts +20 -0
  44. package/dist/runtime/attempt-process-supervisor-registry.js +64 -0
  45. package/dist/runtime/attempt-process-supervisor.d.ts +121 -0
  46. package/dist/runtime/attempt-process-supervisor.js +471 -0
  47. package/dist/runtime/canonical-source-file.d.ts +3 -0
  48. package/dist/runtime/canonical-source-file.js +54 -0
  49. package/dist/runtime/docker-engine-probe.d.ts +90 -0
  50. package/dist/runtime/docker-engine-probe.js +333 -0
  51. package/dist/runtime/generated-output-reset.d.ts +20 -0
  52. package/dist/runtime/generated-output-reset.js +157 -0
  53. package/dist/runtime/host-database-capability-boundary.d.ts +16 -0
  54. package/dist/runtime/host-database-capability-boundary.js +63 -0
  55. package/dist/runtime/host-diagnostics.d.ts +11 -0
  56. package/dist/runtime/host-diagnostics.js +192 -0
  57. package/dist/runtime/host-execution-root.d.ts +4 -0
  58. package/dist/runtime/host-execution-root.js +39 -0
  59. package/dist/runtime/host-facts.d.ts +35 -0
  60. package/dist/runtime/host-facts.js +95 -0
  61. package/dist/runtime/host-listener-inspector.d.ts +51 -0
  62. package/dist/runtime/host-listener-inspector.js +385 -0
  63. package/dist/runtime/host-load-sampler.d.ts +83 -0
  64. package/dist/runtime/host-load-sampler.js +164 -0
  65. package/dist/runtime/host-port-broker.d.ts +76 -0
  66. package/dist/runtime/host-port-broker.js +333 -0
  67. package/dist/runtime/host-pressure-stall.d.ts +41 -0
  68. package/dist/runtime/host-pressure-stall.js +121 -0
  69. package/dist/runtime/host-runtime-contract.d.ts +59 -0
  70. package/dist/runtime/host-runtime-contract.js +815 -0
  71. package/dist/runtime/host-runtime-lease.d.ts +217 -0
  72. package/dist/runtime/host-runtime-lease.js +2533 -0
  73. package/dist/runtime/host-runtime-promotion.d.ts +32 -0
  74. package/dist/runtime/host-runtime-promotion.js +206 -0
  75. package/dist/runtime/managed-command-teardown.d.ts +62 -0
  76. package/dist/runtime/managed-command-teardown.js +607 -0
  77. package/dist/runtime/memory-capacity.d.ts +70 -0
  78. package/dist/runtime/memory-capacity.js +123 -0
  79. package/dist/runtime/native-test-postgres-fallback.d.ts +25 -0
  80. package/dist/runtime/native-test-postgres-fallback.js +91 -0
  81. package/dist/runtime/node-host-runtime-adapter.d.ts +54 -0
  82. package/dist/runtime/node-host-runtime-adapter.js +286 -0
  83. package/dist/runtime/pinned-directory-process.d.ts +9 -0
  84. package/dist/runtime/pinned-directory-process.js +61 -0
  85. package/dist/runtime/pinned-source-directory.d.ts +17 -0
  86. package/dist/runtime/pinned-source-directory.js +94 -0
  87. package/dist/runtime/playwright-browser-cache.d.ts +39 -0
  88. package/dist/runtime/playwright-browser-cache.js +227 -0
  89. package/dist/runtime/playwright-host-runtime-adapter.d.ts +32 -0
  90. package/dist/runtime/playwright-host-runtime-adapter.js +262 -0
  91. package/dist/runtime/prepared-runtime-identity.d.ts +6 -0
  92. package/dist/runtime/prepared-runtime-identity.js +218 -0
  93. package/dist/runtime/prepared-runtime-readiness.d.ts +30 -0
  94. package/dist/runtime/prepared-runtime-readiness.js +285 -0
  95. package/dist/runtime/runtime-isolation-lease.d.ts +67 -0
  96. package/dist/runtime/runtime-isolation-lease.js +161 -0
  97. package/dist/runtime/workspace-resource-estimator.d.ts +17 -0
  98. package/dist/runtime/workspace-resource-estimator.js +174 -0
  99. package/dist/sandbox/command-runner.d.ts +4 -0
  100. package/dist/sandbox/command-runner.js +47 -0
  101. package/dist/sandbox/contract.d.ts +5 -0
  102. package/dist/sandbox/contract.js +276 -0
  103. package/dist/sandbox/event-budget.d.ts +11 -0
  104. package/dist/sandbox/event-budget.js +27 -0
  105. package/dist/sandbox/image-policy.d.ts +35 -0
  106. package/dist/sandbox/image-policy.js +247 -0
  107. package/dist/sandbox/index.d.ts +5 -0
  108. package/dist/sandbox/index.js +5 -0
  109. package/dist/sandbox/lease-watchdog.d.ts +18 -0
  110. package/dist/sandbox/lease-watchdog.js +67 -0
  111. package/dist/sandbox/preflight.d.ts +84 -0
  112. package/dist/sandbox/preflight.js +521 -0
  113. package/dist/sandbox/process.d.ts +20 -0
  114. package/dist/sandbox/process.js +209 -0
  115. package/dist/sandbox/provider-auth/codex.d.ts +26 -0
  116. package/dist/sandbox/provider-auth/codex.js +212 -0
  117. package/dist/sandbox/repository-lock.d.ts +6 -0
  118. package/dist/sandbox/repository-lock.js +129 -0
  119. package/dist/sandbox/runtime.d.ts +302 -0
  120. package/dist/sandbox/runtime.js +2368 -0
  121. package/dist/sandbox/sandbox.types.d.ts +93 -0
  122. package/dist/sandbox/sandbox.types.js +1 -0
  123. package/dist/sandbox/smoke.d.ts +76 -0
  124. package/dist/sandbox/smoke.js +380 -0
  125. package/dist/sandbox/worker-supervisor.d.ts +13 -0
  126. package/dist/sandbox/worker-supervisor.js +36 -0
  127. package/dist/sandbox/worker.d.ts +1 -0
  128. package/dist/sandbox/worker.js +225 -0
  129. package/dist/sandbox/workspace.service.d.ts +13 -0
  130. package/dist/sandbox/workspace.service.js +74 -0
  131. package/dist/session/managed-attempt-tools.d.ts +53 -0
  132. package/dist/session/managed-attempt-tools.js +1213 -0
  133. package/dist/session/managed-build-coordinator.d.ts +5 -0
  134. package/dist/session/managed-build-coordinator.js +109 -0
  135. package/dist/session/managed-build-receipt.d.ts +21 -0
  136. package/dist/session/managed-build-receipt.js +337 -0
  137. package/dist/session/managed-verification-timeouts.d.ts +8 -0
  138. package/dist/session/managed-verification-timeouts.js +17 -0
  139. package/dist/session/phase-completion.artifacts.d.ts +27 -0
  140. package/dist/session/phase-completion.artifacts.js +833 -0
  141. package/dist/session/phase-completion.d.ts +53 -42
  142. package/dist/session/phase-completion.helpers.d.ts +117 -0
  143. package/dist/session/phase-completion.helpers.js +707 -0
  144. package/dist/session/phase-completion.js +125 -3007
  145. package/dist/session/phase-completion.prompts.d.ts +14 -0
  146. package/dist/session/phase-completion.prompts.js +233 -0
  147. package/dist/session/phase-completion.runtime.d.ts +49 -0
  148. package/dist/session/phase-completion.runtime.js +845 -0
  149. package/dist/session/phase-completion.schemas.d.ts +3 -0
  150. package/dist/session/phase-completion.schemas.js +859 -0
  151. package/dist/session/phase-completion.validation.d.ts +38 -0
  152. package/dist/session/phase-completion.validation.js +918 -0
  153. package/dist/session/pre-publication-process.d.ts +20 -0
  154. package/dist/session/pre-publication-process.js +97 -0
  155. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  156. package/dist/session/pre-publication-skipped-tests.js +109 -0
  157. package/dist/session/pre-publication-validation.d.ts +75 -0
  158. package/dist/session/pre-publication-validation.js +631 -0
  159. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.d.ts +72 -0
  160. package/dist/session/provider-cli/bridge-cli.conformance-fixtures.js +462 -0
  161. package/dist/session/provider-cli/ci-repair-readiness.d.ts +16 -0
  162. package/dist/session/provider-cli/ci-repair-readiness.js +110 -0
  163. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +96 -0
  164. package/dist/session/provider-cli/provider-cli.artifacts.js +818 -0
  165. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  166. package/dist/session/provider-cli/provider-cli.deterministic-payloads.d.ts +12 -0
  167. package/dist/session/provider-cli/provider-cli.deterministic-payloads.js +279 -0
  168. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +14 -0
  169. package/dist/session/provider-cli/provider-cli.deterministic.js +407 -0
  170. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  171. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  172. package/dist/session/provider-cli/provider-cli.process.d.ts +128 -0
  173. package/dist/session/provider-cli/provider-cli.process.js +1140 -0
  174. package/dist/session/provider-cli/provider-cli.prompts.d.ts +57 -0
  175. package/dist/session/provider-cli/provider-cli.prompts.js +730 -0
  176. package/dist/session/provider-cli/provider-cli.qa-sidecars.d.ts +11 -0
  177. package/dist/session/provider-cli/provider-cli.qa-sidecars.js +66 -0
  178. package/dist/session/provider-cli/provider-cli.repair-epoch.d.ts +6 -0
  179. package/dist/session/provider-cli/provider-cli.repair-epoch.js +11 -0
  180. package/dist/session/provider-cli/provider-cli.runtime.d.ts +22 -0
  181. package/dist/session/provider-cli/provider-cli.runtime.js +92 -0
  182. package/dist/session/provider-cli/provider-cli.service.d.ts +47 -53
  183. package/dist/session/provider-cli/provider-cli.service.js +1344 -2506
  184. package/dist/session/provider-cli/provider-cli.types.d.ts +8 -0
  185. package/dist/session/provider-cli/provider-in-flight-work.d.ts +6 -0
  186. package/dist/session/provider-cli/provider-in-flight-work.js +47 -0
  187. package/dist/session/provider-cli/provider-output-state.d.ts +38 -0
  188. package/dist/session/provider-cli/provider-output-state.js +826 -0
  189. package/dist/session/provider-cli/provider-usage.d.ts +9 -1
  190. package/dist/session/provider-cli/provider-usage.js +28 -5
  191. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  192. package/dist/session/publishable-worktree-changes.js +193 -0
  193. package/dist/session/session-redaction.d.ts +3 -0
  194. package/dist/session/session-redaction.js +448 -0
  195. package/dist/session/session.base.d.ts +6 -1
  196. package/dist/session/session.service.d.ts +8 -2
  197. package/dist/session/session.service.js +586 -59
  198. package/dist/session/session.types.d.ts +324 -3
  199. package/dist/session/session.types.js +951 -10
  200. package/dist/session/unreferenced-exports.d.ts +12 -0
  201. package/dist/session/unreferenced-exports.js +59 -0
  202. package/dist/shared/format/format-bytes.d.ts +1 -0
  203. package/dist/shared/format/format-bytes.js +9 -0
  204. package/dist/shared/git/git.js +2 -1
  205. package/dist/shared/path/path.d.ts +1 -0
  206. package/dist/shared/path/path.js +21 -1
  207. package/dist/shared/process/dotnet-toolchain.d.ts +17 -0
  208. package/dist/shared/process/dotnet-toolchain.js +307 -0
  209. package/dist/shared/process/host-process-recovery.d.ts +12 -0
  210. package/dist/shared/process/host-process-recovery.js +79 -0
  211. package/dist/shared/process/host-process-supervisor.d.ts +59 -0
  212. package/dist/shared/process/host-process-supervisor.js +331 -0
  213. package/dist/shared/process/process.d.ts +3 -0
  214. package/dist/shared/process/process.js +13 -7
  215. package/dist/shared/process/windows-launch.d.ts +8 -0
  216. package/dist/shared/process/windows-launch.js +41 -0
  217. package/dist/shared/provider-capabilities.d.ts +4 -0
  218. package/dist/shared/provider-capabilities.js +88 -0
  219. package/dist/shared/redaction/redaction.d.ts +1 -0
  220. package/dist/shared/redaction/redaction.js +47 -4
  221. package/dist/shared/time/monotonic.d.ts +1 -0
  222. package/dist/shared/time/monotonic.js +8 -0
  223. package/dist/version.d.ts +1 -1
  224. package/dist/version.js +1 -1
  225. package/dist/worktree/artifact-injector.d.ts +3 -2
  226. package/dist/worktree/artifact-injector.js +82 -10
  227. package/dist/worktree/dependency-warmer.d.ts +53 -1
  228. package/dist/worktree/dependency-warmer.js +693 -11
  229. package/dist/worktree/index.d.ts +2 -1
  230. package/dist/worktree/index.js +1 -0
  231. package/dist/worktree/prior-phase-artifact-hydrator.d.ts +2 -0
  232. package/dist/worktree/prior-phase-artifact-hydrator.js +136 -0
  233. package/dist/worktree/story-qa-reference-hydrator.d.ts +4 -0
  234. package/dist/worktree/story-qa-reference-hydrator.js +253 -0
  235. package/dist/worktree/worktree-paths.d.ts +4 -0
  236. package/dist/worktree/worktree-paths.js +30 -0
  237. package/dist/worktree/worktree.base.d.ts +3 -0
  238. package/dist/worktree/worktree.service.d.ts +16 -3
  239. package/dist/worktree/worktree.service.js +334 -54
  240. package/dist/worktree/worktree.types.d.ts +9 -1
  241. package/package.json +12 -7
  242. package/runtime/windows-job-supervisor.ps1 +722 -0
  243. package/runtime/windows-listener-owner.ps1 +33 -0
@@ -0,0 +1,17 @@
1
+ import { runPinnedDirectoryProcess, type PinnedDirectoryIdentity } from "./pinned-directory-process.js";
2
+ export interface PinnedSourceEntry {
3
+ name: string;
4
+ kind: "directory" | "file" | "symlink" | "other";
5
+ identity: PinnedDirectoryIdentity;
6
+ size: bigint;
7
+ }
8
+ type PinnedDirectoryProcessRunner = typeof runPinnedDirectoryProcess;
9
+ export interface PinnedSourceDirectoryReadOptions {
10
+ /** Production retries are Windows-only; tests may override this explicitly. */
11
+ readonly maxAttempts?: number;
12
+ readonly processRunner?: PinnedDirectoryProcessRunner;
13
+ }
14
+ /** Enumerate from a cwd whose inode is checked by the worker, not by reopening a validated pathname. */
15
+ export declare function readPinnedSourceDirectory(directory: string, identity: PinnedDirectoryIdentity, timeoutMs?: number, terminationConfirmationMs?: number, options?: PinnedSourceDirectoryReadOptions): Promise<PinnedSourceEntry[]>;
16
+ export declare function decodePinnedSourceDirectoryInventory(output: string): PinnedSourceEntry[];
17
+ export {};
@@ -0,0 +1,94 @@
1
+ import { PinnedDirectoryProcessError, runPinnedDirectoryProcess, } from "./pinned-directory-process.js";
2
+ /** Enumerate from a cwd whose inode is checked by the worker, not by reopening a validated pathname. */
3
+ export async function readPinnedSourceDirectory(directory, identity, timeoutMs = 30_000, terminationConfirmationMs = 2_000, options = {}) {
4
+ const configuredAttempts = options.maxAttempts ?? (process.platform === "win32" ? 2 : 1);
5
+ const maxAttempts = Math.max(1, Math.min(3, Math.floor(configuredAttempts), Math.floor(timeoutMs)));
6
+ const attemptBudgetMs = Math.max(1, Math.floor(timeoutMs / maxAttempts));
7
+ const attemptTerminationConfirmationMs = Math.min(Math.max(0, terminationConfirmationMs), Math.max(0, attemptBudgetMs - 1));
8
+ const attemptTimeoutMs = Math.max(1, attemptBudgetMs - attemptTerminationConfirmationMs);
9
+ const processRunner = options.processRunner ?? runPinnedDirectoryProcess;
10
+ let lastError;
11
+ let attemptsStarted = 0;
12
+ for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
13
+ attemptsStarted = attempt;
14
+ try {
15
+ const output = await processRunner(directory, identity, worker, { kind: "source_inventory" }, undefined, 16 * 1024 * 1024, attemptTimeoutMs, attemptTerminationConfirmationMs);
16
+ return decodePinnedSourceDirectoryInventory(output);
17
+ }
18
+ catch (error) {
19
+ lastError = error;
20
+ if (!(error instanceof PinnedDirectoryProcessError)
21
+ || error.failureKind !== "timeout"
22
+ || !error.terminationConfirmed
23
+ || attempt === maxAttempts) {
24
+ break;
25
+ }
26
+ }
27
+ }
28
+ {
29
+ const error = lastError;
30
+ const detail = error instanceof Error ? error.message : String(error);
31
+ if (detail.includes("evidence inventory exceeds retention budget")) {
32
+ throw new Error("host_diagnostics_budget: evidence inventory exceeds retention budget.", { cause: error });
33
+ }
34
+ if (detail.includes("source directory identity changed") || detail.includes("invalid operation")) {
35
+ throw new Error(`host_diagnostics_source_invalid: pinned directory enumeration failed: ${detail}`, { cause: error });
36
+ }
37
+ const reason = error instanceof PinnedDirectoryProcessError && error.failureKind === "timeout"
38
+ ? `pinned directory enumeration timed out after ${attemptsStarted} attempt${attemptsStarted === 1 ? "" : "s"} within ${timeoutMs} ms recovery budget`
39
+ : "pinned directory enumeration was temporarily unavailable";
40
+ throw new Error(`host_diagnostics_temporary_unavailable: ${reason}: ${detail}`, { cause: error });
41
+ }
42
+ }
43
+ export function decodePinnedSourceDirectoryInventory(output) {
44
+ const decoded = JSON.parse(output);
45
+ if (!Array.isArray(decoded) || decoded.length > 10000) {
46
+ throw new Error("host_diagnostics_budget: evidence inventory exceeds retention budget.");
47
+ }
48
+ return decoded.map(entry => {
49
+ if (!isSingleComponent(entry.name) || !["directory", "file", "symlink", "other"].includes(entry.kind)
50
+ || !isSignedFileIdentity(entry.dev) || !isSignedFileIdentity(entry.ino) || !/^\d+$/u.test(entry.size)) {
51
+ throw new Error("host_diagnostics_source_invalid: invalid pinned directory inventory.");
52
+ }
53
+ return {
54
+ name: entry.name, kind: entry.kind, identity: { dev: BigInt(entry.dev), ino: BigInt(entry.ino) },
55
+ size: BigInt(entry.size),
56
+ };
57
+ }).sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
58
+ }
59
+ function isSignedFileIdentity(value) {
60
+ // Node exposes Windows FILE_ID_128 low words through signed bigint stat fields.
61
+ // A valid NTFS identity can therefore be negative when its high bit is set.
62
+ return /^-?\d{1,64}$/u.test(value);
63
+ }
64
+ function isSingleComponent(value) {
65
+ return Boolean(value) && value !== "." && value !== ".."
66
+ && !["/", ":", "\\", "\0"].some(character => value.includes(character));
67
+ }
68
+ const worker = String.raw `
69
+ const fs = require('node:fs');
70
+ const input = fs.readFileSync(0);
71
+ const boundary = input.indexOf(10);
72
+ const job = JSON.parse(input.subarray(0, boundary).toString('utf8'));
73
+ const same = (a, b) => a.dev === b.dev && a.ino === b.ino;
74
+ const samePath = (a, b) => process.platform === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b;
75
+ const expected = { dev: BigInt(job.dev), ino: BigInt(job.ino) };
76
+ const verify = () => {
77
+ const current = fs.statSync('.', { bigint: true });
78
+ if (!current.isDirectory() || !same(current, expected) || !samePath(fs.realpathSync('.'), job.parent))
79
+ throw new Error('source directory identity changed');
80
+ };
81
+ try {
82
+ if (job.kind !== 'source_inventory') throw new Error('invalid operation');
83
+ verify();
84
+ const entries = fs.readdirSync('.');
85
+ if (entries.length > 10000) throw new Error('evidence inventory exceeds retention budget');
86
+ const inventory = entries.map(name => {
87
+ const stat = fs.lstatSync(name, { bigint: true });
88
+ const kind = stat.isSymbolicLink() ? 'symlink' : stat.isDirectory() ? 'directory' : stat.isFile() ? 'file' : 'other';
89
+ return { name, kind, dev: stat.dev.toString(), ino: stat.ino.toString(), size: stat.size.toString() };
90
+ });
91
+ verify();
92
+ process.stdout.write(JSON.stringify(inventory));
93
+ } catch (error) { process.stderr.write(error.message); process.exitCode = 1; }
94
+ `;
@@ -0,0 +1,39 @@
1
+ import { ForgeFailureError } from "../session/session.types.js";
2
+ /** Host browser caches to try, given the directory of the project's resolved playwright-core (if any). */
3
+ export type PlaywrightBrowserCacheCandidates = (playwrightCoreDirectory: string | null) => readonly string[];
4
+ export declare function defaultPlaywrightBrowserCacheCandidates(playwrightCoreDirectory: string | null, env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform, homeDirectory?: string): readonly string[];
5
+ export interface PinnedChromiumBuilds {
6
+ readonly version: string;
7
+ readonly playwrightCoreDirectory: string;
8
+ readonly builds: readonly PinnedChromiumBuild[];
9
+ }
10
+ interface PinnedChromiumBuild {
11
+ readonly directory: string;
12
+ readonly executables: readonly string[];
13
+ }
14
+ export interface PlaywrightBrowserCacheResolution {
15
+ /** The first host cache holding every pinned build, or the legacy any-Chromium match when nothing is pinned. */
16
+ readonly cache: string | null;
17
+ readonly pinned: PinnedChromiumBuilds | null;
18
+ readonly checked: readonly string[];
19
+ }
20
+ /**
21
+ * Finds a host browser cache holding the Chromium and Chromium headless shell
22
+ * builds the project's installed Playwright pins. Only those two builds are
23
+ * checked: they are what the project's Chromium projects launch.
24
+ */
25
+ export declare function findPlaywrightBrowserCache(realWorktree: string, configDirectory: string, candidatesFor: PlaywrightBrowserCacheCandidates, hostPlatform: string): Promise<PlaywrightBrowserCacheResolution>;
26
+ export declare function missingPlaywrightBrowsersError(resolution: PlaywrightBrowserCacheResolution & {
27
+ readonly pinned: PinnedChromiumBuilds;
28
+ }, installCommand: string): ForgeFailureError;
29
+ export interface PlaywrightHostProbe {
30
+ readonly env: NodeJS.ProcessEnv;
31
+ readonly platform: NodeJS.Platform;
32
+ readonly release: string;
33
+ readonly arch: string;
34
+ readonly appleCpu: boolean;
35
+ readonly osRelease: () => string | null;
36
+ }
37
+ /** Mirrors Playwright's own host platform key, which selects `revisionOverrides` entries. */
38
+ export declare function playwrightHostPlatform(probe?: PlaywrightHostProbe): string;
39
+ export {};
@@ -0,0 +1,227 @@
1
+ import fs from "node:fs/promises";
2
+ import { readFileSync } from "node:fs";
3
+ import { createRequire } from "node:module";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import { ForgeFailureError } from "../session/session.types.js";
7
+ export function defaultPlaywrightBrowserCacheCandidates(playwrightCoreDirectory, env = process.env, platform = process.platform, homeDirectory = os.homedir()) {
8
+ const browsersPath = env.PLAYWRIGHT_BROWSERS_PATH?.trim();
9
+ return [
10
+ // PLAYWRIGHT_BROWSERS_PATH=0 makes Playwright use the browsers installed beside playwright-core.
11
+ browsersPath === "0"
12
+ ? playwrightCoreDirectory ? path.join(playwrightCoreDirectory, ".local-browsers") : null
13
+ : browsersPath || null,
14
+ env.LOCALAPPDATA ? path.join(env.LOCALAPPDATA, "ms-playwright") : null,
15
+ env.XDG_CACHE_HOME ? path.join(env.XDG_CACHE_HOME, "ms-playwright") : null,
16
+ platform === "darwin" ? path.join(homeDirectory, "Library", "Caches", "ms-playwright") : null,
17
+ path.join(homeDirectory, ".cache", "ms-playwright"),
18
+ ].filter((candidate) => Boolean(candidate?.trim()));
19
+ }
20
+ /**
21
+ * Finds a host browser cache holding the Chromium and Chromium headless shell
22
+ * builds the project's installed Playwright pins. Only those two builds are
23
+ * checked: they are what the project's Chromium projects launch.
24
+ */
25
+ export async function findPlaywrightBrowserCache(realWorktree, configDirectory, candidatesFor, hostPlatform) {
26
+ const pinned = await readPinnedChromiumBuilds(realWorktree, configDirectory, hostPlatform);
27
+ const checked = [...new Set(candidatesFor(pinned?.playwrightCoreDirectory ?? null).map(candidate => path.resolve(candidate)))];
28
+ for (const candidate of checked) {
29
+ const ready = pinned
30
+ ? await hasPinnedChromiumBuilds(candidate, pinned.builds)
31
+ : await hasChromiumExecutable(candidate);
32
+ if (ready)
33
+ return { cache: candidate, pinned, checked };
34
+ }
35
+ return { cache: null, pinned, checked };
36
+ }
37
+ export function missingPlaywrightBrowsersError(resolution, installCommand) {
38
+ const missing = resolution.pinned.builds.map(build => build.directory).join(" and ");
39
+ const checked = resolution.checked.length > 0 ? resolution.checked.join(", ") : "none";
40
+ return new ForgeFailureError("host_runtime_project_start_failed", `host_runtime_project_start_failed: playwright_browsers_missing: Playwright ${resolution.pinned.version} launches `
41
+ + `Chromium from ${missing}, and no host browser cache holds them (checked: ${checked}). Only the pinned Chromium `
42
+ + `and Chromium headless shell builds are checked. The attempt stopped before it started; install them on this `
43
+ + `host with \`${installCommand}\` and dispatch again.`, "bridge");
44
+ }
45
+ // Executable layouts Playwright launches from, per browser directory (current and legacy builds).
46
+ const chromiumExecutables = {
47
+ win32: [path.join("chrome-win64", "chrome.exe"), path.join("chrome-win", "chrome.exe")],
48
+ darwin: [
49
+ path.join("chrome-mac-arm64", "Google Chrome for Testing.app", "Contents", "MacOS", "Google Chrome for Testing"),
50
+ path.join("chrome-mac-x64", "Google Chrome for Testing.app", "Contents", "MacOS", "Google Chrome for Testing"),
51
+ path.join("chrome-mac", "Chromium.app", "Contents", "MacOS", "Chromium"),
52
+ ],
53
+ linux: [path.join("chrome-linux64", "chrome"), path.join("chrome-linux", "chrome")],
54
+ };
55
+ const headlessShellExecutables = {
56
+ win32: [path.join("chrome-headless-shell-win64", "chrome-headless-shell.exe"), path.join("chrome-win", "headless_shell.exe")],
57
+ darwin: [
58
+ path.join("chrome-headless-shell-mac-arm64", "chrome-headless-shell"),
59
+ path.join("chrome-headless-shell-mac-x64", "chrome-headless-shell"),
60
+ path.join("chrome-mac", "headless_shell"),
61
+ ],
62
+ linux: [path.join("chrome-headless-shell-linux64", "chrome-headless-shell"), path.join("chrome-linux", "headless_shell")],
63
+ };
64
+ function platformExecutables(table) {
65
+ return table[process.platform] ?? table.linux;
66
+ }
67
+ async function readPinnedChromiumBuilds(realWorktree, configDirectory, hostPlatform) {
68
+ const manifestPath = await resolvePlaywrightCoreManifest(realWorktree, configDirectory);
69
+ if (!manifestPath)
70
+ return null;
71
+ let version;
72
+ let browsers;
73
+ try {
74
+ version = String(JSON.parse(await fs.readFile(manifestPath, "utf8")).version ?? "unknown");
75
+ const parsed = JSON.parse(await fs.readFile(path.join(path.dirname(manifestPath), "browsers.json"), "utf8"));
76
+ browsers = Array.isArray(parsed.browsers) ? parsed.browsers : [];
77
+ }
78
+ catch {
79
+ return null;
80
+ }
81
+ const builds = [];
82
+ for (const [name, executables] of [
83
+ ["chromium", platformExecutables(chromiumExecutables)],
84
+ ["chromium-headless-shell", platformExecutables(headlessShellExecutables)],
85
+ ]) {
86
+ const entry = browsers.find(browser => browser.name === name);
87
+ if (!entry || typeof entry.revision !== "string")
88
+ continue;
89
+ // Playwright replaces the revision only for the host platform it runs on.
90
+ const override = entry.revisionOverrides && typeof entry.revisionOverrides === "object"
91
+ ? entry.revisionOverrides[hostPlatform]
92
+ : undefined;
93
+ const revision = typeof override === "string" ? override : entry.revision;
94
+ builds.push({ directory: `${name.replaceAll("-", "_")}-${revision}`, executables });
95
+ }
96
+ return builds.length > 0 ? { version, playwrightCoreDirectory: path.dirname(manifestPath), builds } : null;
97
+ }
98
+ async function resolvePlaywrightCoreManifest(realWorktree, configDirectory) {
99
+ // Follow the chain the project's test runner resolves first: pnpm does not
100
+ // hoist playwright-core next to @playwright/test, and a hoisted bare
101
+ // playwright-core may be a different version than the runner's own.
102
+ for (const chain of [
103
+ ["@playwright/test", "playwright", "playwright-core"],
104
+ ["playwright", "playwright-core"],
105
+ ["playwright-core"],
106
+ ]) {
107
+ let from = path.join(configDirectory, "package.json");
108
+ try {
109
+ for (const packageName of chain)
110
+ from = createRequire(from).resolve(`${packageName}/package.json`);
111
+ }
112
+ catch {
113
+ continue;
114
+ }
115
+ // A Playwright found above the worktree is not the project's own pin.
116
+ const realManifest = await fs.realpath(from).catch(() => null);
117
+ if (realManifest && isContained(realWorktree, realManifest))
118
+ return realManifest;
119
+ }
120
+ return null;
121
+ }
122
+ async function hasPinnedChromiumBuilds(cachePath, builds) {
123
+ for (const build of builds) {
124
+ if (!await anyFile(build.executables.map(executable => path.join(cachePath, build.directory, executable))))
125
+ return false;
126
+ }
127
+ return true;
128
+ }
129
+ async function hasChromiumExecutable(cachePath) {
130
+ let entries;
131
+ try {
132
+ entries = await fs.readdir(cachePath, { withFileTypes: true });
133
+ }
134
+ catch {
135
+ return false;
136
+ }
137
+ const executableSuffixes = platformExecutables(chromiumExecutables);
138
+ for (const entry of entries) {
139
+ if (!entry.isDirectory() || !entry.name.startsWith("chromium-"))
140
+ continue;
141
+ if (await anyFile(executableSuffixes.map(suffix => path.join(cachePath, entry.name, suffix))))
142
+ return true;
143
+ }
144
+ return false;
145
+ }
146
+ async function anyFile(candidates) {
147
+ for (const candidate of candidates) {
148
+ try {
149
+ if ((await fs.stat(candidate)).isFile())
150
+ return true;
151
+ }
152
+ catch {
153
+ // Continue through known Playwright layouts.
154
+ }
155
+ }
156
+ return false;
157
+ }
158
+ function isContained(parent, child) {
159
+ const relative = path.relative(parent, child);
160
+ return Boolean(relative) && !relative.startsWith("..") && !path.isAbsolute(relative);
161
+ }
162
+ const defaultHostProbe = {
163
+ env: process.env,
164
+ platform: process.platform,
165
+ release: os.release(),
166
+ arch: os.arch(),
167
+ appleCpu: os.cpus().some(cpu => cpu.model.includes("Apple")),
168
+ osRelease: () => {
169
+ try {
170
+ return readFileSync("/etc/os-release", "utf8");
171
+ }
172
+ catch {
173
+ return null;
174
+ }
175
+ },
176
+ };
177
+ /** Mirrors Playwright's own host platform key, which selects `revisionOverrides` entries. */
178
+ export function playwrightHostPlatform(probe = defaultHostProbe) {
179
+ if (probe.env.PLAYWRIGHT_HOST_PLATFORM_OVERRIDE)
180
+ return probe.env.PLAYWRIGHT_HOST_PLATFORM_OVERRIDE;
181
+ if (probe.platform === "win32")
182
+ return "win64";
183
+ if (probe.platform === "darwin") {
184
+ const major = Number.parseInt(probe.release.split(".")[0] ?? "", 10);
185
+ if (major < 18)
186
+ return "mac10.13";
187
+ if (major === 18)
188
+ return "mac10.14";
189
+ if (major === 19)
190
+ return "mac10.15";
191
+ const macVersion = major < 25 ? major - 9 : Math.min(major + 1, 26);
192
+ return `mac${macVersion}${probe.appleCpu ? "-arm64" : ""}`;
193
+ }
194
+ if (probe.platform !== "linux" || !["x64", "arm64"].includes(probe.arch))
195
+ return "<unknown>";
196
+ const suffix = `-${probe.arch}`;
197
+ const fields = new Map((probe.osRelease() ?? "").split("\n").map(line => {
198
+ const [name = "", ...rest] = line.split("=");
199
+ return [name.toLowerCase(), rest.join("=").trim().replace(/^"(.*)"$/u, "$1")];
200
+ }));
201
+ const id = fields.get("id") ?? "";
202
+ const version = fields.get("version_id") ?? "";
203
+ const major = Number.parseInt(version, 10);
204
+ if (["ubuntu", "pop", "neon", "tuxedo"].includes(id)) {
205
+ if (major < 20)
206
+ return `ubuntu18.04${suffix}`;
207
+ if (major < 22)
208
+ return `ubuntu20.04${suffix}`;
209
+ if (major < 24)
210
+ return `ubuntu22.04${suffix}`;
211
+ if (major < 26)
212
+ return `ubuntu24.04${suffix}`;
213
+ return `ubuntu${version}${suffix}`;
214
+ }
215
+ if (id === "linuxmint") {
216
+ if (major <= 20)
217
+ return `ubuntu20.04${suffix}`;
218
+ return major === 21 ? `ubuntu22.04${suffix}` : `ubuntu24.04${suffix}`;
219
+ }
220
+ if (id === "debian" || id === "raspbian") {
221
+ if (["11", "12", "13"].includes(version))
222
+ return `debian${version}${suffix}`;
223
+ if (version === "")
224
+ return `debian13${suffix}`;
225
+ }
226
+ return `ubuntu24.04${suffix}`;
227
+ }
@@ -0,0 +1,32 @@
1
+ import type { HostRuntimePlaywrightConfig } from "./host-runtime-contract.js";
2
+ import { type PlaywrightBrowserCacheCandidates } from "./playwright-browser-cache.js";
3
+ export interface PlaywrightHostRuntimeContext {
4
+ readonly worktreePath: string;
5
+ readonly temporaryDirectory: string;
6
+ readonly testOutputDirectory: string;
7
+ readonly browserProfileDirectory: string;
8
+ readonly baseUrl: string;
9
+ readonly ownershipToken: string;
10
+ }
11
+ export interface PreparedPlaywrightHostRuntime {
12
+ readonly configPath: string;
13
+ readonly environment: Readonly<Record<string, string>>;
14
+ }
15
+ /**
16
+ * Prepares a finite Playwright test boundary for a managed-host attempt.
17
+ * The generated overlay points tests at Forge's verified listener, disables
18
+ * Playwright-managed web servers, and keeps writable artifacts attempt-local.
19
+ */
20
+ export declare class PlaywrightHostRuntimeAdapter {
21
+ private readonly browserCacheCandidates;
22
+ private readonly hostPlatform;
23
+ constructor(browserCacheCandidates?: PlaywrightBrowserCacheCandidates, hostPlatform?: () => string);
24
+ /**
25
+ * Fails a host that lacks the project's pinned Chromium builds before any
26
+ * database, build, launch, or promotion work, so the attempt never runs
27
+ * toward a Playwright gate whose every spec would fail at browser launch.
28
+ */
29
+ assertBrowserCacheReady(config: HostRuntimePlaywrightConfig, worktreePath: string): Promise<void>;
30
+ private readyBrowserCache;
31
+ prepare(config: HostRuntimePlaywrightConfig, context: PlaywrightHostRuntimeContext): Promise<PreparedPlaywrightHostRuntime>;
32
+ }