@loucompanion/forge-bridge 0.1.4-dev.f22f5e3d01fe → 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.
Files changed (260) hide show
  1. package/README.md +128 -4
  2. package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
  3. package/dist/bridge/bridge-chat-giphy-look.js +55 -0
  4. package/dist/bridge/bridge-chat-provider-command.d.ts +27 -3
  5. package/dist/bridge/bridge-chat-provider-command.js +131 -26
  6. package/dist/bridge/bridge-chat.types.d.ts +20 -0
  7. package/dist/bridge/bridge-chat.types.js +28 -1
  8. package/dist/bridge/bridge-state-file.d.ts +161 -0
  9. package/dist/bridge/bridge-state-file.js +376 -0
  10. package/dist/bridge/bridge-state-io.d.ts +15 -0
  11. package/dist/bridge/bridge-state-io.js +68 -0
  12. package/dist/bridge/bridge-state-lock.d.ts +11 -0
  13. package/dist/bridge/bridge-state-lock.js +102 -0
  14. package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
  15. package/dist/bridge/bridge-state-unpublished.js +111 -0
  16. package/dist/bridge/bridge.service.d.ts +29 -12
  17. package/dist/bridge/bridge.service.js +215 -380
  18. package/dist/bridge/bridge.types.d.ts +21 -0
  19. package/dist/bridge/bridge.types.js +2 -1
  20. package/dist/bridge/default-session-service.d.ts +13 -0
  21. package/dist/bridge/default-session-service.js +22 -0
  22. package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
  23. package/dist/bridge/dispatch-offer-policy.js +58 -0
  24. package/dist/bridge/in-flight-registry.d.ts +62 -0
  25. package/dist/bridge/in-flight-registry.js +207 -0
  26. package/dist/bridge/readiness-result-outbox.d.ts +5 -1
  27. package/dist/bridge/readiness-result-outbox.js +20 -0
  28. package/dist/bridge/runner-host-capabilities.js +14 -1
  29. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  30. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  31. package/dist/bridge/windows-bash-resolution.d.ts +31 -0
  32. package/dist/bridge/windows-bash-resolution.js +153 -0
  33. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  34. package/dist/cleanup/cleanup-wip.js +66 -0
  35. package/dist/cleanup/cleanup.service.d.ts +11 -1
  36. package/dist/cleanup/cleanup.service.js +80 -62
  37. package/dist/cleanup/cleanup.types.d.ts +2 -0
  38. package/dist/cleanup/forge-owned-paths.d.ts +2 -0
  39. package/dist/cleanup/forge-owned-paths.js +9 -0
  40. package/dist/cleanup/host-runtime-ledger.d.ts +2 -0
  41. package/dist/cleanup/host-runtime-ledger.js +30 -9
  42. package/dist/cli/cli.help.js +57 -13
  43. package/dist/cli/cli.service.d.ts +3 -10
  44. package/dist/cli/cli.service.js +20 -213
  45. package/dist/cli/idle-status.d.ts +84 -0
  46. package/dist/cli/idle-status.js +181 -0
  47. package/dist/cli/local-config.d.ts +14 -1
  48. package/dist/cli/local-config.js +42 -2
  49. package/dist/cli/provider-cli-advertising.d.ts +24 -0
  50. package/dist/cli/provider-cli-advertising.js +88 -0
  51. package/dist/cli/provider-cli-detection.d.ts +10 -0
  52. package/dist/cli/provider-cli-detection.js +160 -0
  53. package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
  54. package/dist/runtime/aspnet-runtime-prebuild.js +104 -26
  55. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  56. package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
  57. package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
  58. package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
  59. package/dist/runtime/attempt-process-supervisor.js +12 -6
  60. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  61. package/dist/runtime/docker-engine-probe.js +7 -0
  62. package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
  63. package/dist/runtime/dotnet-build-outputs.js +402 -0
  64. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  65. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  66. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  67. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  68. package/dist/runtime/host-listener-inspector.d.ts +26 -0
  69. package/dist/runtime/host-listener-inspector.js +84 -3
  70. package/dist/runtime/host-load-admission.d.ts +5 -0
  71. package/dist/runtime/host-load-capacity.d.ts +198 -0
  72. package/dist/runtime/host-load-capacity.js +353 -0
  73. package/dist/runtime/host-load-child-environment.d.ts +13 -0
  74. package/dist/runtime/host-load-child-environment.js +35 -1
  75. package/dist/runtime/host-load-governor-config.d.ts +33 -3
  76. package/dist/runtime/host-load-governor-config.js +24 -3
  77. package/dist/runtime/host-load-governor.d.ts +91 -2
  78. package/dist/runtime/host-load-governor.js +217 -18
  79. package/dist/runtime/host-load-ledger-lock.js +6 -4
  80. package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
  81. package/dist/runtime/host-load-live-test-slots.js +193 -0
  82. package/dist/runtime/host-load-runtime-settings.js +4 -2
  83. package/dist/runtime/host-load-sampler.d.ts +25 -1
  84. package/dist/runtime/host-load-sampler.js +38 -7
  85. package/dist/runtime/host-load-step-run.d.ts +37 -3
  86. package/dist/runtime/host-load-step-run.js +63 -7
  87. package/dist/runtime/host-load-test-slot.d.ts +3 -0
  88. package/dist/runtime/host-load-test-slot.js +26 -7
  89. package/dist/runtime/host-runtime-contract.d.ts +12 -0
  90. package/dist/runtime/host-runtime-contract.js +35 -5
  91. package/dist/runtime/host-runtime-lease.d.ts +28 -3
  92. package/dist/runtime/host-runtime-lease.js +140 -296
  93. package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
  94. package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
  95. package/dist/runtime/host-runtime-promotion.d.ts +78 -2
  96. package/dist/runtime/host-runtime-promotion.js +307 -14
  97. package/dist/runtime/managed-command-teardown.js +5 -16
  98. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  99. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  100. package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
  101. package/dist/runtime/prepared-runtime-identity.js +130 -9
  102. package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
  103. package/dist/runtime/prepared-runtime-readiness.js +89 -18
  104. package/dist/runtime/runner-settings.d.ts +4 -0
  105. package/dist/runtime/runner-settings.js +22 -0
  106. package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
  107. package/dist/runtime/supervised-runtime-build-guard.js +112 -0
  108. package/dist/sandbox/host-capacity-broker.d.ts +3 -1
  109. package/dist/sandbox/host-capacity-broker.js +4 -2
  110. package/dist/sandbox/managed-branch.d.ts +13 -0
  111. package/dist/sandbox/managed-branch.js +90 -0
  112. package/dist/sandbox/provider-auth/codex.js +11 -11
  113. package/dist/sandbox/runtime.d.ts +1 -2
  114. package/dist/sandbox/runtime.js +9 -19
  115. package/dist/sandbox/sandbox-input.d.ts +22 -0
  116. package/dist/sandbox/sandbox-input.js +49 -0
  117. package/dist/sandbox/workspace.service.js +15 -2
  118. package/dist/session/managed-attempt-tools.d.ts +0 -7
  119. package/dist/session/managed-attempt-tools.js +54 -109
  120. package/dist/session/managed-build-coordinator.d.ts +16 -0
  121. package/dist/session/managed-build-coordinator.js +10 -0
  122. package/dist/session/managed-build-receipt.d.ts +7 -0
  123. package/dist/session/managed-build-receipt.js +11 -3
  124. package/dist/session/managed-command-environment.d.ts +8 -0
  125. package/dist/session/managed-command-environment.js +28 -0
  126. package/dist/session/managed-command-host-load.d.ts +10 -5
  127. package/dist/session/managed-command-host-load.js +18 -14
  128. package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
  129. package/dist/session/phase-completion.artifact-bundle.js +167 -0
  130. package/dist/session/phase-completion.artifacts.d.ts +2 -17
  131. package/dist/session/phase-completion.artifacts.js +65 -166
  132. package/dist/session/phase-completion.d.ts +27 -2
  133. package/dist/session/phase-completion.helpers.js +5 -53
  134. package/dist/session/phase-completion.js +15 -32
  135. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  136. package/dist/session/phase-completion.mcp-args.js +195 -0
  137. package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
  138. package/dist/session/phase-completion.phase-aliases.js +43 -0
  139. package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
  140. package/dist/session/phase-completion.pr-review-schema.js +75 -0
  141. package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
  142. package/dist/session/phase-completion.pr-review-validation.js +212 -0
  143. package/dist/session/phase-completion.pr-review.d.ts +36 -0
  144. package/dist/session/phase-completion.pr-review.js +294 -0
  145. package/dist/session/phase-completion.prompts.d.ts +1 -1
  146. package/dist/session/phase-completion.prompts.js +14 -0
  147. package/dist/session/phase-completion.runtime.d.ts +8 -9
  148. package/dist/session/phase-completion.runtime.js +65 -196
  149. package/dist/session/phase-completion.schemas.js +12 -2
  150. package/dist/session/phase-completion.validation.d.ts +1 -0
  151. package/dist/session/phase-completion.validation.js +9 -1
  152. package/dist/session/pr-review-diff-base.d.ts +18 -0
  153. package/dist/session/pr-review-diff-base.js +44 -0
  154. package/dist/session/pr-review-placement.d.ts +50 -0
  155. package/dist/session/pr-review-placement.js +91 -0
  156. package/dist/session/pre-publication-change-set.d.ts +62 -0
  157. package/dist/session/pre-publication-change-set.js +166 -0
  158. package/dist/session/pre-publication-host-load.js +6 -5
  159. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  160. package/dist/session/pre-publication-native-postgres.js +111 -0
  161. package/dist/session/pre-publication-process.js +13 -12
  162. package/dist/session/pre-publication-step-execution.d.ts +2 -1
  163. package/dist/session/pre-publication-step-execution.js +6 -5
  164. package/dist/session/pre-publication-validation.d.ts +9 -4
  165. package/dist/session/pre-publication-validation.js +62 -65
  166. package/dist/session/provider-cli/claude-background-work.d.ts +3 -2
  167. package/dist/session/provider-cli/claude-background-work.js +4 -3
  168. package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
  169. package/dist/session/provider-cli/dispatch-target-branch.js +8 -0
  170. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  171. package/dist/session/provider-cli/host-build-lock.js +30 -0
  172. package/dist/session/provider-cli/pr-review-credential-isolation.d.ts +83 -0
  173. package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
  174. package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
  175. package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
  176. package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
  177. package/dist/session/provider-cli/pr-review-prompt.js +119 -0
  178. package/dist/session/provider-cli/pre-publication-repair.d.ts +16 -0
  179. package/dist/session/provider-cli/pre-publication-repair.js +41 -3
  180. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  181. package/dist/session/provider-cli/provider-cli.child-environment.js +4 -2
  182. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
  183. package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
  184. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
  185. package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
  186. package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
  187. package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
  188. package/dist/session/provider-cli/provider-cli.process.d.ts +2 -14
  189. package/dist/session/provider-cli/provider-cli.process.js +4 -94
  190. package/dist/session/provider-cli/provider-cli.prompts.d.ts +13 -3
  191. package/dist/session/provider-cli/provider-cli.prompts.js +137 -84
  192. package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
  193. package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
  194. package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
  195. package/dist/session/provider-cli/provider-cli.runtime.js +37 -2
  196. package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
  197. package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
  198. package/dist/session/provider-cli/provider-cli.service.d.ts +15 -18
  199. package/dist/session/provider-cli/provider-cli.service.js +59 -190
  200. package/dist/session/provider-cli/provider-cli.types.d.ts +7 -2
  201. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  202. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  203. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  204. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  205. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  206. package/dist/session/qa-sidecar-validation.js +28 -0
  207. package/dist/session/sandbox-host-capacity-gate.d.ts +22 -1
  208. package/dist/session/sandbox-host-capacity-gate.js +63 -22
  209. package/dist/session/session-host-project.d.ts +22 -0
  210. package/dist/session/session-host-project.js +98 -0
  211. package/dist/session/session-redaction.js +31 -181
  212. package/dist/session/session.parse-helpers.d.ts +10 -0
  213. package/dist/session/session.parse-helpers.js +84 -0
  214. package/dist/session/session.runtime-refresh.d.ts +46 -0
  215. package/dist/session/session.runtime-refresh.js +116 -0
  216. package/dist/session/session.service.d.ts +8 -1
  217. package/dist/session/session.service.js +177 -239
  218. package/dist/session/session.types.d.ts +5 -0
  219. package/dist/session/session.types.js +9 -79
  220. package/dist/session/session.types.pr-review.d.ts +48 -0
  221. package/dist/session/session.types.pr-review.js +51 -0
  222. package/dist/session/sidecar-json-shape.d.ts +31 -0
  223. package/dist/session/sidecar-json-shape.js +217 -0
  224. package/dist/shared/fs/file-identity.d.ts +10 -0
  225. package/dist/shared/fs/file-identity.js +15 -0
  226. package/dist/shared/fs/replace-file.d.ts +7 -0
  227. package/dist/shared/fs/replace-file.js +33 -0
  228. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  229. package/dist/shared/process/host-process-recovery.js +23 -3
  230. package/dist/shared/process/host-process-supervisor.d.ts +13 -1
  231. package/dist/shared/process/host-process-supervisor.js +66 -14
  232. package/dist/shared/provider-capabilities.d.ts +2 -0
  233. package/dist/shared/provider-capabilities.js +18 -1
  234. package/dist/version.d.ts +1 -1
  235. package/dist/version.js +1 -1
  236. package/dist/worktree/artifact-injector.js +24 -0
  237. package/dist/worktree/orphan-relink.d.ts +19 -0
  238. package/dist/worktree/orphan-relink.js +106 -0
  239. package/dist/worktree/wip-git.d.ts +58 -0
  240. package/dist/worktree/wip-git.js +182 -0
  241. package/dist/worktree/wip-refs.d.ts +85 -0
  242. package/dist/worktree/wip-refs.js +169 -0
  243. package/dist/worktree/wip-restore.d.ts +51 -0
  244. package/dist/worktree/wip-restore.js +324 -0
  245. package/dist/worktree/wip-snapshot.d.ts +53 -0
  246. package/dist/worktree/wip-snapshot.js +270 -0
  247. package/dist/worktree/worktree-inputs.d.ts +8 -0
  248. package/dist/worktree/worktree-inputs.js +134 -0
  249. package/dist/worktree/worktree-origin-sync.d.ts +35 -0
  250. package/dist/worktree/worktree-origin-sync.js +128 -0
  251. package/dist/worktree/worktree-wip-events.d.ts +20 -0
  252. package/dist/worktree/worktree-wip-events.js +148 -0
  253. package/dist/worktree/worktree-wip.d.ts +57 -0
  254. package/dist/worktree/worktree-wip.js +200 -0
  255. package/dist/worktree/worktree.base.d.ts +7 -1
  256. package/dist/worktree/worktree.service.d.ts +49 -5
  257. package/dist/worktree/worktree.service.js +223 -187
  258. package/dist/worktree/worktree.types.d.ts +47 -0
  259. package/package.json +1 -1
  260. package/runtime/windows-listener-owner.ps1 +12 -1
@@ -0,0 +1,98 @@
1
+ import { hostRuntimeEventResources } from "../runtime/host-runtime-lease.js";
2
+ import { configuredLaunchPortNames } from "../runtime/host-runtime-promotion.js";
3
+ import { deferredProjectStartEvent } from "../worktree/worktree.service.js";
4
+ // The attempt's configured project on a managed host: its first start (or its deferral while a WIP
5
+ // re-apply left unresolved conflicts), the checkpoint text for a validation-time restart, and the
6
+ // Browser QA target it serves.
7
+ /**
8
+ * Builds and launches the attempt's configured project from the prepared worktree and reports the
9
+ * verified port; or, while a WIP re-apply left unresolved conflicts that would fail its build,
10
+ * defers the start to pre-publication validation (deferredProjectStartEvent) so the agent runs first.
11
+ */
12
+ export async function startOrDeferConfiguredProject(hostRuntime, hostLease, dispatch, reapplyConflicts, signal, emitLifecycle) {
13
+ // Only a managed runtime with a port to launch builds anything here (launchConfiguredProject returns
14
+ // at once for analysis_only or no launch config), so no other setup has a build to defer.
15
+ const deferred = (reapplyConflicts?.length ?? 0) > 0 && Boolean(hostRuntime.restartConfiguredProject)
16
+ && hostLease.executionClass === "managed_runtime"
17
+ && configuredLaunchPortNames(hostLease.runtimeContract).length > 0;
18
+ if (deferred) {
19
+ await emitLifecycle(deferredProjectStartEvent(reapplyConflicts));
20
+ return { hostLease, deferred };
21
+ }
22
+ const unconfiguredPortCount = hostLease.lease.resources.ports.length;
23
+ const started = await hostRuntime.startConfiguredProject(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken, signal, async (checkpoint) => {
24
+ await emitLifecycle({
25
+ role: "runner",
26
+ kind: "checkpoint",
27
+ content: checkpoint.message,
28
+ eventType: checkpoint.code,
29
+ data: checkpoint.data ? JSON.stringify(checkpoint.data) : undefined,
30
+ });
31
+ });
32
+ if (started.lease.resources.ports.length > unconfiguredPortCount) {
33
+ const assigned = started.lease.resources.ports.at(-1);
34
+ await emitLifecycle({
35
+ role: "runner",
36
+ kind: "checkpoint",
37
+ content: `Verified supervised project runtime ${assigned.name} on ${assigned.hostIp}:${assigned.hostPort}.`,
38
+ eventType: "host_runtime_project_ready",
39
+ data: JSON.stringify(hostRuntimeEventResources(started.lease, started.runtimeContract, started.executionClass)),
40
+ });
41
+ }
42
+ return { hostLease: started, deferred };
43
+ }
44
+ export function managedQaLaunchTarget(runtimeContract) {
45
+ const playwright = runtimeContract.contract.runtime.playwright;
46
+ if (!playwright)
47
+ return null;
48
+ const port = runtimeContract.contract.runtime.ports.find(candidate => candidate.name === playwright.baseUrlPort);
49
+ return port?.launch && port.baseUrlEnv && port.format
50
+ ? { managedRuntimePort: port.name, routes: ["/"] }
51
+ : null;
52
+ }
53
+ /** The host_runtime_restart_started checkpoint text for the first cause of a validation-time restart. */
54
+ export function runtimeRestartStartedMessage(reason, changes) {
55
+ const current = "so validation runs against the current source.";
56
+ switch (reason) {
57
+ case "deferred_start":
58
+ return `Starting the attempt runtime stack, deferred until the restored work's re-apply conflicts were resolved, ${current}`;
59
+ case "workspace_changed":
60
+ return `The workspace changed since the attempt runtime stack was launched (${changes.join(", ")}); restarting it ${current}`;
61
+ case "previous_restart_incomplete":
62
+ return `The previous attempt runtime restart did not complete; restarting it again ${current}`
63
+ + (changes.length > 0 ? ` The workspace also changed since launch (${changes.join(", ")}).` : "");
64
+ default:
65
+ return `The workspace state could not be compared with the attempt runtime stack; restarting it ${current}`;
66
+ }
67
+ }
68
+ /**
69
+ * The dispatch with its managed Browser QA target's URL from the started stack. While the first start
70
+ * is deferred (startOrDeferConfiguredProject) the stack has no URL yet: the target keeps its port,
71
+ * and validation starts the stack once the agent has resolved the conflicts.
72
+ */
73
+ export function withMaterializedManagedQaTarget(dispatch, hostLease, projectStartDeferred = false) {
74
+ const target = dispatch.qaBrowser?.launchTarget;
75
+ const portName = target?.managed_runtime_port?.trim().toLowerCase();
76
+ if (!target || !portName)
77
+ return dispatch;
78
+ if (!hostLease) {
79
+ throw new Error("qa_managed_runtime_unavailable: Browser QA requires the verified managed host runtime selected during readiness.");
80
+ }
81
+ const normalizedName = portName.toUpperCase().replaceAll(/[^A-Z0-9]/gu, "_");
82
+ const url = hostLease.environment[`FORGE_${normalizedName}_URL`];
83
+ if (!url && projectStartDeferred)
84
+ return withQaTargetNote(dispatch, target, "Forge starts this port's stack at validation, after the conflicts from restored work are resolved; it has no URL before then.");
85
+ if (!url) {
86
+ throw new Error(`qa_managed_runtime_unavailable: verified runtime port '${portName}' was not launched for this attempt.`);
87
+ }
88
+ return withQaTargetNote(dispatch, { ...target, url: target.url ?? url, ready_url: target.ready_url ?? url }, "Forge launched and verified this URL inside the current fenced attempt.");
89
+ }
90
+ function withQaTargetNote(dispatch, target, note) {
91
+ return {
92
+ ...dispatch,
93
+ qaBrowser: dispatch.qaBrowser ? {
94
+ ...dispatch.qaBrowser,
95
+ launchTarget: { ...target, notes: [target.notes, note].filter(Boolean).join(" ") },
96
+ } : dispatch.qaBrowser,
97
+ };
98
+ }
@@ -1,14 +1,14 @@
1
1
  import { redactText, shouldRedactJsonProperty } from "../shared/redaction/redaction.js";
2
- import { TextDecoder } from "node:util";
2
+ import { decodeJsonEscapesLeniently, decodeJsonStringToken, inspectJsonText, isJsonPunctuation, isJsonWhitespace, JsonShapeError, sidecarJsonShapeProblem, } from "./sidecar-json-shape.js";
3
+ import { ForgeFailureError } from "./session.types.js";
3
4
  const integrityProtectedEventDataTypes = new Set(["sandbox_started"]);
4
5
  const structuralSecretMessage = "runner result structural metadata contains protected secret material and cannot be redacted without changing protocol identity.";
5
6
  const sidecarSecretMessage = "runner result sidecar contains protected secret material and cannot be redacted without invalidating integrity metadata.";
6
7
  const artifactJsonMessage = "runner result artifact JSON is invalid or exceeds safe inspection limits; transport was rejected.";
7
8
  const artifactJsonKeySecretMessage = "runner result artifact JSON property name contains protected secret material and cannot be redacted without changing protocol identity.";
8
9
  const artifactJsonPrimitiveSecretMessage = "runner result artifact JSON primitive contains protected secret material and cannot be redacted without changing protocol identity.";
9
- const maximumIntegrityJsonBytes = 8 * 1024 * 1024;
10
- const maximumIntegrityJsonDepth = 128;
11
- const maximumIntegrityJsonTokens = 262_144;
10
+ // Stable failure code for a sidecar that starts like JSON but does not parse (see sidecar-json-shape.ts).
11
+ const malformedSidecarFailureCode = "runner_result_sidecar_malformed";
12
12
  export function redactRunnerDispatchEvent(event, exactSecrets = []) {
13
13
  assertStructuralFieldsDoNotContainSecrets([
14
14
  event.role,
@@ -149,7 +149,7 @@ function redactArtifactJson(value, exactSecrets) {
149
149
  }
150
150
  continue;
151
151
  }
152
- const token = decodeJsonStringToken(value, index, artifactJsonMessage);
152
+ const token = decodeArtifactJsonStringToken(value, index);
153
153
  const afterToken = skipJsonWhitespace(value, token.nextIndex);
154
154
  if (value.charCodeAt(afterToken) === 0x3a) {
155
155
  assertJsonStringDoesNotContainSecrets(token.decoded, exactSecrets, artifactJsonKeySecretMessage);
@@ -159,7 +159,7 @@ function redactArtifactJson(value, exactSecrets) {
159
159
  const valueStart = skipJsonWhitespace(value, afterToken + 1);
160
160
  const valueEnd = jsonValueEnd(value, valueStart);
161
161
  if (value[valueStart] !== '"'
162
- || decodeJsonStringToken(value, valueStart, artifactJsonMessage).decoded !== "[REDACTED]") {
162
+ || decodeArtifactJsonStringToken(value, valueStart).decoded !== "[REDACTED]") {
163
163
  replace(valueStart, valueEnd, '"[REDACTED]"');
164
164
  }
165
165
  index = valueEnd;
@@ -193,13 +193,13 @@ function skipJsonWhitespace(value, start) {
193
193
  // value (including objects/arrays) without decoding or rewriting adjacent data.
194
194
  function jsonValueEnd(value, start) {
195
195
  if (value.charCodeAt(start) === 0x22) {
196
- return decodeJsonStringToken(value, start, artifactJsonMessage).nextIndex;
196
+ return decodeArtifactJsonStringToken(value, start).nextIndex;
197
197
  }
198
198
  if (value[start] === "{" || value[start] === "[") {
199
199
  let depth = 0;
200
200
  for (let index = start; index < value.length; index += 1) {
201
201
  if (value[index] === '"') {
202
- index = decodeJsonStringToken(value, index, artifactJsonMessage).nextIndex - 1;
202
+ index = decodeArtifactJsonStringToken(value, index).nextIndex - 1;
203
203
  }
204
204
  else if (value[index] === "{" || value[index] === "[") {
205
205
  depth += 1;
@@ -248,7 +248,7 @@ function assertSidecarsDoNotContainSecrets(sidecars, exactSecrets) {
248
248
  throw new Error(sidecarSecretMessage);
249
249
  }
250
250
  }
251
- assertSidecarJsonDoesNotContainSecrets(decoded, sidecar.path, exactSecrets, sidecarSecretMessage);
251
+ assertSidecarJsonShape(decoded, sidecar.path, exactSecrets);
252
252
  }
253
253
  }
254
254
  function assertSerializedJsonDoesNotContainSecrets(value, exactSecrets, errorMessage) {
@@ -257,187 +257,37 @@ function assertSerializedJsonDoesNotContainSecrets(value, exactSecrets, errorMes
257
257
  assertJsonStringDoesNotContainSecrets(value, exactSecrets, errorMessage);
258
258
  inspectJsonStringTokens(value, exactSecrets, errorMessage);
259
259
  }
260
- function assertSidecarJsonDoesNotContainSecrets(value, path, exactSecrets, errorMessage) {
261
- let decoded;
262
- try {
263
- decoded = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(value);
264
- }
265
- catch {
266
- if (path.toLowerCase().endsWith(".json"))
267
- throw new Error(errorMessage);
260
+ function assertSidecarJsonShape(content, path, exactSecrets) {
261
+ const problem = sidecarJsonShapeProblem(content, path, decoded => assertJsonStringDoesNotContainSecrets(decoded, exactSecrets, sidecarSecretMessage));
262
+ if (problem === null)
268
263
  return;
269
- }
270
- if (!looksLikeJson(decoded, path))
271
- return;
272
- const hasUtf8Bom = value.length >= 3
273
- && value[0] === 0xef
274
- && value[1] === 0xbb
275
- && value[2] === 0xbf;
276
- if (hasUtf8Bom)
277
- throw new Error(errorMessage);
278
- inspectJsonStringTokens(decoded, exactSecrets, errorMessage);
264
+ // A malformed file cannot be read token by token, so decode its escapes leniently first: a
265
+ // secret hidden behind JSON escapes keeps the secret error instead of the malformed one.
266
+ assertJsonStringDoesNotContainSecrets(decodeJsonEscapesLeniently(content.toString("utf8")), exactSecrets, sidecarSecretMessage);
267
+ // Still fail closed: the bytes cannot be redacted, so the result is rejected either way. The
268
+ // distinct code and message say the file is malformed, not that a secret was found.
269
+ throw new ForgeFailureError(malformedSidecarFailureCode, `runner result sidecar ${path} looks like JSON but is not valid JSON (${problem}); `
270
+ + "Forge rejects sidecars it cannot fully inspect, so the result was not accepted.");
279
271
  }
280
272
  function inspectJsonStringTokens(value, exactSecrets, errorMessage) {
281
- if (Buffer.byteLength(value, "utf8") > maximumIntegrityJsonBytes) {
282
- throw new Error(errorMessage);
283
- }
284
- const containers = [];
285
- let index = 0;
286
- let tokenCount = 0;
287
- const countToken = () => {
288
- tokenCount += 1;
289
- if (tokenCount > maximumIntegrityJsonTokens)
290
- throw new Error(errorMessage);
291
- };
292
- while (index < value.length) {
293
- const code = value.charCodeAt(index);
294
- if (code === 0x22) {
295
- countToken();
296
- const token = decodeJsonStringToken(value, index, errorMessage);
297
- assertJsonStringDoesNotContainSecrets(token.decoded, exactSecrets, errorMessage);
298
- index = token.nextIndex;
299
- continue;
300
- }
301
- if (code === 0x7b || code === 0x5b) {
302
- countToken();
303
- containers.push(code);
304
- if (containers.length > maximumIntegrityJsonDepth)
305
- throw new Error(errorMessage);
306
- index += 1;
307
- continue;
308
- }
309
- if (code === 0x7d || code === 0x5d) {
310
- countToken();
311
- const expected = code === 0x7d ? 0x7b : 0x5b;
312
- if (containers.pop() !== expected)
313
- throw new Error(errorMessage);
314
- index += 1;
315
- continue;
316
- }
317
- if (code === 0x2c || code === 0x3a) {
318
- index += 1;
319
- continue;
320
- }
321
- if (isJsonWhitespace(code)) {
322
- index += 1;
323
- continue;
324
- }
325
- countToken();
326
- do {
327
- index += 1;
328
- } while (index < value.length
329
- && !isJsonWhitespace(value.charCodeAt(index))
330
- && !isJsonPunctuation(value.charCodeAt(index)));
331
- }
332
- if (containers.length !== 0)
333
- throw new Error(errorMessage);
334
273
  try {
335
- JSON.parse(value);
274
+ inspectJsonText(value, decoded => assertJsonStringDoesNotContainSecrets(decoded, exactSecrets, errorMessage));
336
275
  }
337
- catch {
338
- throw new Error(errorMessage);
276
+ catch (error) {
277
+ if (error instanceof JsonShapeError)
278
+ throw new Error(errorMessage, { cause: error });
279
+ throw error;
339
280
  }
340
281
  }
341
- function decodeJsonStringToken(value, openingQuoteIndex, errorMessage) {
342
- const chunks = [];
343
- let segmentStart = openingQuoteIndex + 1;
344
- let index = segmentStart;
345
- while (index < value.length) {
346
- const code = value.charCodeAt(index);
347
- if (code === 0x22) {
348
- chunks.push(value.slice(segmentStart, index));
349
- const decoded = chunks.join("");
350
- if (!isWellFormedUnicode(decoded))
351
- throw new Error(errorMessage);
352
- return { decoded, nextIndex: index + 1 };
353
- }
354
- if (code < 0x20)
355
- throw new Error(errorMessage);
356
- if (code !== 0x5c) {
357
- index += 1;
358
- continue;
359
- }
360
- chunks.push(value.slice(segmentStart, index));
361
- index += 1;
362
- if (index >= value.length)
363
- throw new Error(errorMessage);
364
- const escaped = value[index];
365
- switch (escaped) {
366
- case "\"":
367
- chunks.push("\"");
368
- index += 1;
369
- break;
370
- case "\\":
371
- chunks.push("\\");
372
- index += 1;
373
- break;
374
- case "/":
375
- chunks.push("/");
376
- index += 1;
377
- break;
378
- case "b":
379
- chunks.push("\b");
380
- index += 1;
381
- break;
382
- case "f":
383
- chunks.push("\f");
384
- index += 1;
385
- break;
386
- case "n":
387
- chunks.push("\n");
388
- index += 1;
389
- break;
390
- case "r":
391
- chunks.push("\r");
392
- index += 1;
393
- break;
394
- case "t":
395
- chunks.push("\t");
396
- index += 1;
397
- break;
398
- case "u": {
399
- const hex = value.slice(index + 1, index + 5);
400
- if (!/^[0-9a-fA-F]{4}$/u.test(hex))
401
- throw new Error(errorMessage);
402
- chunks.push(String.fromCharCode(Number.parseInt(hex, 16)));
403
- index += 5;
404
- break;
405
- }
406
- default: throw new Error(errorMessage);
407
- }
408
- segmentStart = index;
282
+ function decodeArtifactJsonStringToken(value, openingQuoteIndex) {
283
+ try {
284
+ return decodeJsonStringToken(value, openingQuoteIndex);
409
285
  }
410
- throw new Error(errorMessage);
411
- }
412
- function isWellFormedUnicode(value) {
413
- for (let index = 0; index < value.length; index += 1) {
414
- const code = value.charCodeAt(index);
415
- if (code >= 0xd800 && code <= 0xdbff) {
416
- if (index + 1 >= value.length)
417
- return false;
418
- const next = value.charCodeAt(index + 1);
419
- if (next < 0xdc00 || next > 0xdfff)
420
- return false;
421
- index += 1;
422
- }
423
- else if (code >= 0xdc00 && code <= 0xdfff) {
424
- return false;
425
- }
286
+ catch (error) {
287
+ if (error instanceof JsonShapeError)
288
+ throw new Error(artifactJsonMessage, { cause: error });
289
+ throw error;
426
290
  }
427
- return true;
428
- }
429
- function looksLikeJson(value, path) {
430
- if (path.toLowerCase().endsWith(".json"))
431
- return true;
432
- const candidate = value.trimStart().replace(/^\uFEFF/u, "").trimStart();
433
- return candidate.startsWith("{") || candidate.startsWith("[") || candidate.startsWith("\"");
434
- }
435
- function isJsonWhitespace(code) {
436
- return code === 0x20 || code === 0x09 || code === 0x0a || code === 0x0d;
437
- }
438
- function isJsonPunctuation(code) {
439
- return code === 0x7b || code === 0x7d || code === 0x5b || code === 0x5d
440
- || code === 0x2c || code === 0x3a || code === 0x22;
441
291
  }
442
292
  function assertJsonStringDoesNotContainSecrets(value, exactSecrets, errorMessage) {
443
293
  for (const secret of exactSecrets) {
@@ -0,0 +1,10 @@
1
+ export declare function asObject(value: unknown, label: string): Record<string, unknown>;
2
+ export declare function requiredString(source: Record<string, unknown>, key: string): string;
3
+ export declare function optionalString(source: Record<string, unknown>, key: string): string | null;
4
+ export declare function requiredBoolean(source: Record<string, unknown>, key: string): boolean;
5
+ export declare function optionalBoolean(source: Record<string, unknown>, key: string): boolean | null;
6
+ export declare function optionalPositiveInteger(source: Record<string, unknown>, key: string): number | null;
7
+ export declare function optionalNonNegativeInteger(source: Record<string, unknown>, key: string): number | null;
8
+ export declare function requiredNumber(source: Record<string, unknown>, key: string): number;
9
+ export declare function boundedInteger(source: Record<string, unknown>, key: string, minimum: number, maximum: number): number;
10
+ export declare function optionalObjectArray(source: Record<string, unknown>, key: string): Record<string, unknown>[];
@@ -0,0 +1,84 @@
1
+ export function asObject(value, label) {
2
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
3
+ throw new Error(`${label} must be an object.`);
4
+ }
5
+ return value;
6
+ }
7
+ export function requiredString(source, key) {
8
+ const value = source[key];
9
+ if (typeof value !== "string" || value.trim().length === 0) {
10
+ throw new Error(`${key} must be a non-empty string.`);
11
+ }
12
+ return value;
13
+ }
14
+ export function optionalString(source, key) {
15
+ const value = source[key];
16
+ if (value === undefined || value === null) {
17
+ return null;
18
+ }
19
+ if (typeof value !== "string") {
20
+ throw new Error(`${key} must be a string when provided.`);
21
+ }
22
+ return value;
23
+ }
24
+ export function requiredBoolean(source, key) {
25
+ const value = source[key];
26
+ if (typeof value !== "boolean") {
27
+ throw new Error(`${key} must be a boolean.`);
28
+ }
29
+ return value;
30
+ }
31
+ export function optionalBoolean(source, key) {
32
+ const value = source[key];
33
+ if (value === undefined || value === null) {
34
+ return null;
35
+ }
36
+ if (typeof value !== "boolean") {
37
+ throw new Error(`${key} must be a boolean when provided.`);
38
+ }
39
+ return value;
40
+ }
41
+ export function optionalPositiveInteger(source, key) {
42
+ const value = source[key];
43
+ if (value === undefined || value === null) {
44
+ return null;
45
+ }
46
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
47
+ throw new Error(`${key} must be a positive integer when provided.`);
48
+ }
49
+ return value;
50
+ }
51
+ export function optionalNonNegativeInteger(source, key) {
52
+ const value = source[key];
53
+ if (value === undefined || value === null) {
54
+ return null;
55
+ }
56
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
57
+ throw new Error(`${key} must be a non-negative integer when provided.`);
58
+ }
59
+ return value;
60
+ }
61
+ export function requiredNumber(source, key) {
62
+ const value = source[key];
63
+ if (typeof value !== "number" || !Number.isFinite(value)) {
64
+ throw new Error(`${key} must be a finite number.`);
65
+ }
66
+ return value;
67
+ }
68
+ export function boundedInteger(source, key, minimum, maximum) {
69
+ const value = requiredNumber(source, key);
70
+ if (!Number.isSafeInteger(value) || value < minimum || value > maximum) {
71
+ throw new Error(`${key} must be an integer from ${minimum} through ${maximum}.`);
72
+ }
73
+ return value;
74
+ }
75
+ export function optionalObjectArray(source, key) {
76
+ const value = source[key];
77
+ if (value === undefined || value === null) {
78
+ return [];
79
+ }
80
+ if (!Array.isArray(value)) {
81
+ throw new Error(`${key} must be an array when provided.`);
82
+ }
83
+ return value.map((item, index) => asObject(item, `${key}[${index}]`));
84
+ }
@@ -0,0 +1,46 @@
1
+ import type { RuntimeEnvironmentRefresh } from "./provider-cli/provider-cli.types.js";
2
+ import type { RunOnceDispatchPacket, RunnerDispatchEvent } from "./session.types.js";
3
+ import type { HostRuntimeLeaseRuntime, HostRuntimeLeaseStart } from "../runtime/host-runtime-lease.js";
4
+ import { readWorkspaceRuntimeFingerprint, type WorkspaceRuntimeFingerprintReader } from "./workspace-runtime-fingerprint.js";
5
+ export { readWorkspaceRuntimeFingerprint, type WorkspaceRuntimeFingerprintReader };
6
+ export interface RuntimeEnvironmentRefreshInput {
7
+ readonly worktreePath: string;
8
+ readonly dispatchAttemptId: string;
9
+ readonly fencingToken: string;
10
+ readonly restartConfiguredProject: NonNullable<HostRuntimeLeaseRuntime["restartConfiguredProject"]>;
11
+ readonly readFingerprint: WorkspaceRuntimeFingerprintReader;
12
+ readonly emitLifecycle: (event: RunnerDispatchEvent) => Promise<void>;
13
+ readonly signal?: AbortSignal;
14
+ /** Throws when the attempt was aborted or a late isolation violation stopped its stack. */
15
+ readonly assertRunning?: () => void;
16
+ /** Called with the restarted lease so the caller keeps serving the current stack. */
17
+ readonly onRestarted: (restarted: HostRuntimeLeaseStart) => void;
18
+ /**
19
+ * True while the first start of the stack is deferred (re-apply conflicts): the stack has never run,
20
+ * so the first pass starts it. Cleared after a successful restart.
21
+ */
22
+ readonly startDeferred?: boolean;
23
+ }
24
+ /**
25
+ * Builds the pre-publication hook that restarts the attempt runtime stack when the provider has
26
+ * changed the workspace since the stack was launched. The stack was built and launched from the
27
+ * workspace state read here.
28
+ */
29
+ export declare function createRuntimeEnvironmentRefresh(input: RuntimeEnvironmentRefreshInput): Promise<(refreshSignal?: AbortSignal) => Promise<RuntimeEnvironmentRefresh | null>>;
30
+ export interface ConfiguredRuntimeRefreshInput {
31
+ readonly hostLease: HostRuntimeLeaseStart | null;
32
+ readonly dispatch: RunOnceDispatchPacket;
33
+ readonly hostRuntime: HostRuntimeLeaseRuntime | undefined;
34
+ readonly worktreePath: string;
35
+ readonly readFingerprint: WorkspaceRuntimeFingerprintReader;
36
+ readonly emitLifecycle: (event: RunnerDispatchEvent) => Promise<void>;
37
+ readonly signal?: AbortSignal;
38
+ readonly assertRunning?: () => void;
39
+ readonly onRestarted: (restarted: HostRuntimeLeaseStart) => void;
40
+ readonly startDeferred?: boolean;
41
+ }
42
+ /**
43
+ * The refresh hook for a managed runtime lease with configured launch ports, or undefined when the
44
+ * attempt has no restartable project stack.
45
+ */
46
+ export declare function createConfiguredRuntimeRefresh(input: ConfiguredRuntimeRefreshInput): Promise<((refreshSignal?: AbortSignal) => Promise<RuntimeEnvironmentRefresh | null>) | undefined>;
@@ -0,0 +1,116 @@
1
+ import { configuredLaunchPortNames } from "../runtime/host-runtime-promotion.js";
2
+ import { hostRuntimeEventResources } from "../runtime/host-runtime-lease.js";
3
+ import { runtimeRestartStartedMessage } from "./session-host-project.js";
4
+ import { readWorkspaceRuntimeFingerprint, sameWorkspaceRuntimeFingerprint, workspaceRuntimeFingerprintChanges, } from "./workspace-runtime-fingerprint.js";
5
+ // Re-exported so the session service reaches the workspace fingerprint reader through this module.
6
+ export { readWorkspaceRuntimeFingerprint };
7
+ function failureMessage(error) {
8
+ return error instanceof Error ? error.message : String(error);
9
+ }
10
+ /**
11
+ * Builds the pre-publication hook that restarts the attempt runtime stack when the provider has
12
+ * changed the workspace since the stack was launched. The stack was built and launched from the
13
+ * workspace state read here.
14
+ */
15
+ export async function createRuntimeEnvironmentRefresh(input) {
16
+ const { worktreePath, dispatchAttemptId, fencingToken, restartConfiguredProject, readFingerprint, emitLifecycle, signal, assertRunning, onRestarted } = input;
17
+ let launchFingerprint = await readFingerprint(worktreePath)
18
+ .catch(() => null);
19
+ // Set while the stack may not match the workspace: a failed restart is retried on the next pass.
20
+ let restartPending = false;
21
+ // Set until the deferred first start (re-apply conflicts) succeeds: the stack has never run.
22
+ let startDeferred = input.startDeferred ?? false;
23
+ return async (refreshSignal) => {
24
+ // A late violation stopped the stack: fail this validation pass rather than run it against closed ports.
25
+ assertRunning?.();
26
+ const current = await readFingerprint(worktreePath).catch(() => null);
27
+ if (!restartPending && !startDeferred && sameWorkspaceRuntimeFingerprint(launchFingerprint, current))
28
+ return null;
29
+ // Every cause that applies is reported; `reason` is the first of them. Changes are named
30
+ // only when both states were read: an unreadable baseline is not a workspace change.
31
+ const comparable = launchFingerprint !== null && current !== null;
32
+ const changes = comparable ? workspaceRuntimeFingerprintChanges(launchFingerprint, current) : [];
33
+ const causes = [
34
+ ...(startDeferred ? ["deferred_start"] : []),
35
+ ...(restartPending ? ["previous_restart_incomplete"] : []),
36
+ ...(comparable ? [] : ["fingerprint_unavailable"]),
37
+ ...(changes.length > 0 ? ["workspace_changed"] : []),
38
+ ];
39
+ const reason = causes[0] ?? "workspace_changed";
40
+ await emitLifecycle({
41
+ role: "runner",
42
+ kind: "checkpoint",
43
+ content: runtimeRestartStartedMessage(reason, changes),
44
+ eventType: "host_runtime_restart_started",
45
+ data: JSON.stringify({
46
+ reason,
47
+ causes,
48
+ changes,
49
+ head_sha: current?.headSha ?? null,
50
+ merge_in_progress: Boolean(current?.mergeHead),
51
+ }),
52
+ });
53
+ restartPending = true;
54
+ let restarted;
55
+ try {
56
+ restarted = await restartConfiguredProject(dispatchAttemptId, fencingToken, refreshSignal ?? signal, async (checkpoint) => {
57
+ await emitLifecycle({
58
+ role: "runner",
59
+ kind: "checkpoint",
60
+ content: checkpoint.message,
61
+ eventType: checkpoint.code,
62
+ data: checkpoint.data ? JSON.stringify(checkpoint.data) : undefined,
63
+ });
64
+ });
65
+ }
66
+ catch (error) {
67
+ await emitLifecycle({
68
+ role: "runner",
69
+ kind: "error",
70
+ content: `Restarting the attempt runtime stack failed: ${failureMessage(error)}`,
71
+ eventType: "host_runtime_restart_failed",
72
+ data: JSON.stringify({ reason, causes, changes }),
73
+ }).catch(() => undefined);
74
+ throw error;
75
+ }
76
+ onRestarted(restarted);
77
+ // The restarted stack serves the workspace as it is now. Read that state again rather than
78
+ // keep the pre-restart reading, which is null when it could not be collected; a null
79
+ // baseline never matches, so every later pass would restart and rotate ports again.
80
+ launchFingerprint = await readFingerprint(worktreePath).catch(() => current);
81
+ restartPending = false;
82
+ startDeferred = false;
83
+ await emitLifecycle({
84
+ role: "runner",
85
+ kind: "checkpoint",
86
+ content: `Restarted the supervised project runtime on ${restarted.lease.resources.ports.map(port => `${port.name} ${port.hostIp}:${port.hostPort}`).join(", ") || "no ports"}.`,
87
+ eventType: "host_runtime_restarted",
88
+ data: JSON.stringify(hostRuntimeEventResources(restarted.lease, restarted.runtimeContract, restarted.executionClass)),
89
+ });
90
+ return { environment: restarted.environment, reason, changes };
91
+ };
92
+ }
93
+ /**
94
+ * The refresh hook for a managed runtime lease with configured launch ports, or undefined when the
95
+ * attempt has no restartable project stack.
96
+ */
97
+ export async function createConfiguredRuntimeRefresh(input) {
98
+ const { hostLease, dispatch, hostRuntime } = input;
99
+ if (!hostLease || !dispatch.sandbox || !hostRuntime?.restartConfiguredProject
100
+ || hostLease.executionClass !== "managed_runtime"
101
+ || configuredLaunchPortNames(hostLease.runtimeContract).length === 0) {
102
+ return undefined;
103
+ }
104
+ return await createRuntimeEnvironmentRefresh({
105
+ worktreePath: input.worktreePath,
106
+ dispatchAttemptId: dispatch.sandbox.dispatchAttemptId,
107
+ fencingToken: dispatch.lease.fencingToken,
108
+ restartConfiguredProject: hostRuntime.restartConfiguredProject.bind(hostRuntime),
109
+ readFingerprint: input.readFingerprint,
110
+ emitLifecycle: input.emitLifecycle,
111
+ signal: input.signal,
112
+ assertRunning: input.assertRunning,
113
+ onRestarted: input.onRestarted,
114
+ startDeferred: input.startDeferred
115
+ });
116
+ }
@@ -1,3 +1,4 @@
1
+ export { runOnceWithReviewPlacement } from "./pr-review-placement.js";
1
2
  import type { HostRequirementsCheck } from "../runtime/host-runtime-requirements-check.js";
2
3
  import type { ProviderCliService } from "./provider-cli/provider-cli.base.js";
3
4
  import type { SessionEventSink, SessionService } from "./session.base.js";
@@ -5,7 +6,7 @@ import type { HostRuntimeReadinessProbeRequest, HostRuntimeReadinessProbeResult,
5
6
  import type { WorktreeService } from "../worktree/worktree.base.js";
6
7
  import { type HostCapacityLimits, type HostRuntimeCapacitySnapshot, type HostRuntimeLeaseRuntime, type HostRuntimeReapOptions, type HostRuntimeReapReport } from "../runtime/host-runtime-lease.js";
7
8
  import type { RunnerHostDefaults } from "../runtime/runner-settings.js";
8
- import { type WorkspaceRuntimeFingerprintReader } from "./workspace-runtime-fingerprint.js";
9
+ import { type WorkspaceRuntimeFingerprintReader } from "./session.runtime-refresh.js";
9
10
  export declare class BridgeSessionService implements SessionService {
10
11
  private readonly worktrees;
11
12
  private readonly providerCli;
@@ -20,4 +21,10 @@ export declare class BridgeSessionService implements SessionService {
20
21
  runtimeCapacity(): HostRuntimeCapacitySnapshot | null;
21
22
  probeHostRuntime(request: HostRuntimeReadinessProbeRequest, signal?: AbortSignal): Promise<HostRuntimeReadinessProbeResult>;
22
23
  runOnce(dispatch: RunOnceDispatchPacket, sink: SessionEventSink, signal?: AbortSignal): Promise<RunOnceResultPacket>;
24
+ /** Launches a parallel-eligible probe's project, unless its contract is quarantined and so could never earn proof. */
25
+ private probeConfiguredProject;
26
+ /** A late isolation violation stopped the attempt's project in the background: fail rather than report success. */
27
+ private throwIfAbortedOrIsolationViolated;
28
+ /** Reports the provider's peak memory and releases the attempt's host runtime lease. */
29
+ private releaseHostRuntime;
23
30
  }