@loucompanion/forge-bridge 0.1.4-dev.fb770705136a → 0.2.1-dev.0f8fb73715e8

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 (329) hide show
  1. package/README.md +183 -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 +40 -0
  5. package/dist/bridge/bridge-chat-provider-command.js +230 -0
  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.base.d.ts +9 -0
  17. package/dist/bridge/bridge.service.d.ts +102 -14
  18. package/dist/bridge/bridge.service.js +499 -471
  19. package/dist/bridge/bridge.types.d.ts +37 -0
  20. package/dist/bridge/bridge.types.js +2 -1
  21. package/dist/bridge/default-session-service.d.ts +13 -0
  22. package/dist/bridge/default-session-service.js +22 -0
  23. package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
  24. package/dist/bridge/dispatch-offer-policy.js +58 -0
  25. package/dist/bridge/in-flight-registry.d.ts +62 -0
  26. package/dist/bridge/in-flight-registry.js +207 -0
  27. package/dist/bridge/local-yield-flag.d.ts +6 -0
  28. package/dist/bridge/local-yield-flag.js +34 -0
  29. package/dist/bridge/readiness-result-outbox.d.ts +5 -1
  30. package/dist/bridge/readiness-result-outbox.js +20 -0
  31. package/dist/bridge/runner-host-capabilities.d.ts +5 -0
  32. package/dist/bridge/runner-host-capabilities.js +31 -1
  33. package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
  34. package/dist/bridge/sandbox-resource-accounting.js +150 -0
  35. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  36. package/dist/bridge/test-postgres-capability.js +120 -0
  37. package/dist/bridge/windows-bash-resolution.d.ts +31 -0
  38. package/dist/bridge/windows-bash-resolution.js +153 -0
  39. package/dist/cleanup/cleanup-wip.d.ts +12 -0
  40. package/dist/cleanup/cleanup-wip.js +66 -0
  41. package/dist/cleanup/cleanup.service.d.ts +20 -1
  42. package/dist/cleanup/cleanup.service.js +150 -169
  43. package/dist/cleanup/cleanup.types.d.ts +6 -0
  44. package/dist/cleanup/forge-owned-paths.d.ts +11 -0
  45. package/dist/cleanup/forge-owned-paths.js +62 -0
  46. package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
  47. package/dist/cleanup/host-runtime-ledger.js +130 -0
  48. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  49. package/dist/cleanup/managed-branch-sweep.js +111 -0
  50. package/dist/cli/cli.help.js +75 -13
  51. package/dist/cli/cli.service.d.ts +19 -10
  52. package/dist/cli/cli.service.js +161 -228
  53. package/dist/cli/idle-status.d.ts +84 -0
  54. package/dist/cli/idle-status.js +181 -0
  55. package/dist/cli/local-config.d.ts +18 -1
  56. package/dist/cli/local-config.js +67 -5
  57. package/dist/cli/provider-cli-advertising.d.ts +24 -0
  58. package/dist/cli/provider-cli-advertising.js +88 -0
  59. package/dist/cli/provider-cli-detection.d.ts +10 -0
  60. package/dist/cli/provider-cli-detection.js +160 -0
  61. package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
  62. package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
  63. package/dist/runtime/attempt-database-broker.d.ts +1 -1
  64. package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
  65. package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
  66. package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
  67. package/dist/runtime/attempt-process-supervisor.js +12 -6
  68. package/dist/runtime/docker-engine-probe.d.ts +5 -0
  69. package/dist/runtime/docker-engine-probe.js +7 -0
  70. package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
  71. package/dist/runtime/dotnet-build-outputs.js +402 -0
  72. package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
  73. package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
  74. package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
  75. package/dist/runtime/ephemeral-test-postgres.js +303 -0
  76. package/dist/runtime/host-facts.d.ts +2 -1
  77. package/dist/runtime/host-listener-inspector.d.ts +26 -0
  78. package/dist/runtime/host-listener-inspector.js +84 -3
  79. package/dist/runtime/host-load-admission.d.ts +72 -0
  80. package/dist/runtime/host-load-admission.js +99 -0
  81. package/dist/runtime/host-load-capacity.d.ts +198 -0
  82. package/dist/runtime/host-load-capacity.js +353 -0
  83. package/dist/runtime/host-load-child-environment.d.ts +40 -0
  84. package/dist/runtime/host-load-child-environment.js +110 -0
  85. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  86. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  87. package/dist/runtime/host-load-governor-config.d.ts +82 -0
  88. package/dist/runtime/host-load-governor-config.js +104 -0
  89. package/dist/runtime/host-load-governor.d.ts +273 -0
  90. package/dist/runtime/host-load-governor.js +831 -0
  91. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  92. package/dist/runtime/host-load-ledger-lock.js +187 -0
  93. package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
  94. package/dist/runtime/host-load-live-test-slots.js +193 -0
  95. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  96. package/dist/runtime/host-load-runtime-settings.js +80 -0
  97. package/dist/runtime/host-load-sampler.d.ts +92 -2
  98. package/dist/runtime/host-load-sampler.js +166 -8
  99. package/dist/runtime/host-load-step-class.d.ts +70 -0
  100. package/dist/runtime/host-load-step-class.js +161 -0
  101. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  102. package/dist/runtime/host-load-step-reaper.js +95 -0
  103. package/dist/runtime/host-load-step-run.d.ts +107 -0
  104. package/dist/runtime/host-load-step-run.js +158 -0
  105. package/dist/runtime/host-load-test-slot.d.ts +46 -0
  106. package/dist/runtime/host-load-test-slot.js +100 -0
  107. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  108. package/dist/runtime/host-load-token-ledger.js +453 -0
  109. package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
  110. package/dist/runtime/host-load-windows-cpu.js +85 -0
  111. package/dist/runtime/host-pressure-stall.d.ts +21 -1
  112. package/dist/runtime/host-pressure-stall.js +48 -1
  113. package/dist/runtime/host-runtime-contract.d.ts +15 -0
  114. package/dist/runtime/host-runtime-contract.js +39 -6
  115. package/dist/runtime/host-runtime-lease.d.ts +101 -6
  116. package/dist/runtime/host-runtime-lease.js +408 -294
  117. package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
  118. package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
  119. package/dist/runtime/host-runtime-promotion.d.ts +101 -2
  120. package/dist/runtime/host-runtime-promotion.js +355 -14
  121. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  122. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  123. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  124. package/dist/runtime/host-runtime-requirements.js +117 -0
  125. package/dist/runtime/managed-command-teardown.js +5 -16
  126. package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
  127. package/dist/runtime/native-test-postgres-fallback.js +60 -8
  128. package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
  129. package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
  130. package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
  131. package/dist/runtime/prepared-runtime-identity.js +130 -9
  132. package/dist/runtime/prepared-runtime-readiness.d.ts +23 -1
  133. package/dist/runtime/prepared-runtime-readiness.js +89 -18
  134. package/dist/runtime/runner-settings.d.ts +104 -0
  135. package/dist/runtime/runner-settings.js +236 -0
  136. package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
  137. package/dist/runtime/supervised-runtime-build-guard.js +112 -0
  138. package/dist/sandbox/host-capacity-broker.d.ts +115 -0
  139. package/dist/sandbox/host-capacity-broker.js +336 -0
  140. package/dist/sandbox/managed-branch.d.ts +13 -0
  141. package/dist/sandbox/managed-branch.js +90 -0
  142. package/dist/sandbox/provider-auth/codex.js +11 -11
  143. package/dist/sandbox/runtime.d.ts +11 -3
  144. package/dist/sandbox/runtime.js +53 -20
  145. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  146. package/dist/sandbox/sandbox-cgroups.js +42 -0
  147. package/dist/sandbox/sandbox-input.d.ts +22 -0
  148. package/dist/sandbox/sandbox-input.js +49 -0
  149. package/dist/sandbox/workspace.service.js +15 -2
  150. package/dist/session/architect-waits.d.ts +2 -0
  151. package/dist/session/architect-waits.js +138 -0
  152. package/dist/session/managed-attempt-tools.d.ts +2 -7
  153. package/dist/session/managed-attempt-tools.js +204 -141
  154. package/dist/session/managed-build-coordinator.d.ts +16 -0
  155. package/dist/session/managed-build-coordinator.js +10 -0
  156. package/dist/session/managed-build-receipt.d.ts +7 -0
  157. package/dist/session/managed-build-receipt.js +11 -3
  158. package/dist/session/managed-command-environment.d.ts +8 -0
  159. package/dist/session/managed-command-environment.js +28 -0
  160. package/dist/session/managed-command-host-load.d.ts +52 -0
  161. package/dist/session/managed-command-host-load.js +87 -0
  162. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  163. package/dist/session/mcp-argument-coercion.js +121 -0
  164. package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
  165. package/dist/session/phase-completion.artifact-bundle.js +167 -0
  166. package/dist/session/phase-completion.artifacts.d.ts +9 -17
  167. package/dist/session/phase-completion.artifacts.js +158 -190
  168. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  169. package/dist/session/phase-completion.command-validation.js +77 -0
  170. package/dist/session/phase-completion.d.ts +31 -2
  171. package/dist/session/phase-completion.helpers.js +18 -65
  172. package/dist/session/phase-completion.js +19 -32
  173. package/dist/session/phase-completion.mcp-args.d.ts +9 -0
  174. package/dist/session/phase-completion.mcp-args.js +195 -0
  175. package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
  176. package/dist/session/phase-completion.phase-aliases.js +43 -0
  177. package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
  178. package/dist/session/phase-completion.pr-review-schema.js +75 -0
  179. package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
  180. package/dist/session/phase-completion.pr-review-validation.js +212 -0
  181. package/dist/session/phase-completion.pr-review.d.ts +36 -0
  182. package/dist/session/phase-completion.pr-review.js +294 -0
  183. package/dist/session/phase-completion.prompts.d.ts +1 -1
  184. package/dist/session/phase-completion.prompts.js +20 -1
  185. package/dist/session/phase-completion.runtime.d.ts +13 -12
  186. package/dist/session/phase-completion.runtime.js +113 -214
  187. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  188. package/dist/session/phase-completion.schema-parts.js +188 -0
  189. package/dist/session/phase-completion.schemas.d.ts +3 -3
  190. package/dist/session/phase-completion.schemas.js +219 -232
  191. package/dist/session/phase-completion.validation.d.ts +3 -3
  192. package/dist/session/phase-completion.validation.js +58 -94
  193. package/dist/session/pr-review-diff-base.d.ts +18 -0
  194. package/dist/session/pr-review-diff-base.js +44 -0
  195. package/dist/session/pr-review-placement.d.ts +50 -0
  196. package/dist/session/pr-review-placement.js +91 -0
  197. package/dist/session/pre-publication-change-set.d.ts +62 -0
  198. package/dist/session/pre-publication-change-set.js +166 -0
  199. package/dist/session/pre-publication-host-load.d.ts +27 -0
  200. package/dist/session/pre-publication-host-load.js +112 -0
  201. package/dist/session/pre-publication-native-postgres.d.ts +30 -0
  202. package/dist/session/pre-publication-native-postgres.js +111 -0
  203. package/dist/session/pre-publication-pass.d.ts +61 -0
  204. package/dist/session/pre-publication-pass.js +148 -0
  205. package/dist/session/pre-publication-process.d.ts +3 -0
  206. package/dist/session/pre-publication-process.js +32 -19
  207. package/dist/session/pre-publication-step-execution.d.ts +12 -0
  208. package/dist/session/pre-publication-step-execution.js +50 -0
  209. package/dist/session/pre-publication-validation.d.ts +39 -22
  210. package/dist/session/pre-publication-validation.js +241 -207
  211. package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
  212. package/dist/session/provider-cli/claude-background-work.js +181 -0
  213. package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
  214. package/dist/session/provider-cli/dispatch-target-branch.js +8 -0
  215. package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
  216. package/dist/session/provider-cli/host-build-lock.js +30 -0
  217. package/dist/session/provider-cli/pr-review-credential-isolation.d.ts +83 -0
  218. package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
  219. package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
  220. package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
  221. package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
  222. package/dist/session/provider-cli/pr-review-prompt.js +119 -0
  223. package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
  224. package/dist/session/provider-cli/pre-publication-repair.js +281 -0
  225. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  226. package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
  227. package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
  228. package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
  229. package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
  230. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
  231. package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
  232. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
  233. package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
  234. package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
  235. package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
  236. package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
  237. package/dist/session/provider-cli/provider-cli.process.js +41 -432
  238. package/dist/session/provider-cli/provider-cli.prompts.d.ts +15 -3
  239. package/dist/session/provider-cli/provider-cli.prompts.js +183 -90
  240. package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
  241. package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
  242. package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
  243. package/dist/session/provider-cli/provider-cli.runtime.js +43 -1
  244. package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
  245. package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
  246. package/dist/session/provider-cli/provider-cli.service.d.ts +18 -18
  247. package/dist/session/provider-cli/provider-cli.service.js +127 -317
  248. package/dist/session/provider-cli/provider-cli.types.d.ts +35 -0
  249. package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
  250. package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
  251. package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
  252. package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
  253. package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
  254. package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
  255. package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
  256. package/dist/session/provider-cli/provider-output-pipes.js +67 -0
  257. package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
  258. package/dist/session/provider-cli/provider-output-state.js +6 -0
  259. package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
  260. package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
  261. package/dist/session/qa-sidecar-validation.d.ts +6 -0
  262. package/dist/session/qa-sidecar-validation.js +28 -0
  263. package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
  264. package/dist/session/sandbox-host-capacity-gate.js +279 -0
  265. package/dist/session/session-host-project.d.ts +22 -0
  266. package/dist/session/session-host-project.js +98 -0
  267. package/dist/session/session-redaction.js +31 -181
  268. package/dist/session/session.base.d.ts +9 -1
  269. package/dist/session/session.parse-helpers.d.ts +10 -0
  270. package/dist/session/session.parse-helpers.js +84 -0
  271. package/dist/session/session.runtime-refresh.d.ts +46 -0
  272. package/dist/session/session.runtime-refresh.js +116 -0
  273. package/dist/session/session.service.d.ts +16 -2
  274. package/dist/session/session.service.js +208 -155
  275. package/dist/session/session.types.d.ts +8 -0
  276. package/dist/session/session.types.js +13 -83
  277. package/dist/session/session.types.pr-review.d.ts +48 -0
  278. package/dist/session/session.types.pr-review.js +51 -0
  279. package/dist/session/sidecar-json-shape.d.ts +31 -0
  280. package/dist/session/sidecar-json-shape.js +217 -0
  281. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  282. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  283. package/dist/shared/fs/file-identity.d.ts +10 -0
  284. package/dist/shared/fs/file-identity.js +15 -0
  285. package/dist/shared/fs/replace-file.d.ts +7 -0
  286. package/dist/shared/fs/replace-file.js +33 -0
  287. package/dist/shared/process/host-process-recovery.d.ts +14 -3
  288. package/dist/shared/process/host-process-recovery.js +23 -3
  289. package/dist/shared/process/host-process-supervisor.d.ts +14 -1
  290. package/dist/shared/process/host-process-supervisor.js +67 -15
  291. package/dist/shared/process/process-tree.d.ts +52 -0
  292. package/dist/shared/process/process-tree.js +144 -0
  293. package/dist/shared/process/process.d.ts +67 -0
  294. package/dist/shared/process/process.js +213 -11
  295. package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
  296. package/dist/shared/process/windows-app-execution-alias.js +45 -0
  297. package/dist/shared/process/windows-launch.d.ts +18 -0
  298. package/dist/shared/process/windows-launch.js +68 -0
  299. package/dist/shared/provider-capabilities.d.ts +2 -0
  300. package/dist/shared/provider-capabilities.js +23 -7
  301. package/dist/version.d.ts +1 -1
  302. package/dist/version.js +1 -1
  303. package/dist/worktree/artifact-injector.js +24 -0
  304. package/dist/worktree/dependency-warmer.d.ts +25 -0
  305. package/dist/worktree/dependency-warmer.js +46 -10
  306. package/dist/worktree/orphan-relink.d.ts +19 -0
  307. package/dist/worktree/orphan-relink.js +106 -0
  308. package/dist/worktree/wip-git.d.ts +58 -0
  309. package/dist/worktree/wip-git.js +182 -0
  310. package/dist/worktree/wip-refs.d.ts +85 -0
  311. package/dist/worktree/wip-refs.js +169 -0
  312. package/dist/worktree/wip-restore.d.ts +51 -0
  313. package/dist/worktree/wip-restore.js +324 -0
  314. package/dist/worktree/wip-snapshot.d.ts +53 -0
  315. package/dist/worktree/wip-snapshot.js +270 -0
  316. package/dist/worktree/worktree-inputs.d.ts +8 -0
  317. package/dist/worktree/worktree-inputs.js +134 -0
  318. package/dist/worktree/worktree-origin-sync.d.ts +35 -0
  319. package/dist/worktree/worktree-origin-sync.js +128 -0
  320. package/dist/worktree/worktree-wip-events.d.ts +20 -0
  321. package/dist/worktree/worktree-wip-events.js +148 -0
  322. package/dist/worktree/worktree-wip.d.ts +57 -0
  323. package/dist/worktree/worktree-wip.js +200 -0
  324. package/dist/worktree/worktree.base.d.ts +7 -1
  325. package/dist/worktree/worktree.service.d.ts +58 -5
  326. package/dist/worktree/worktree.service.js +237 -161
  327. package/dist/worktree/worktree.types.d.ts +54 -0
  328. package/package.json +2 -2
  329. package/runtime/windows-listener-owner.ps1 +12 -1
@@ -1,5 +1,7 @@
1
1
  import path from "node:path";
2
2
  import { redactText } from "../shared/redaction/redaction.js";
3
+ import { asObject, requiredString, optionalString, requiredBoolean, optionalBoolean, optionalPositiveInteger, optionalNonNegativeInteger, requiredNumber, boundedInteger } from "./session.parse-helpers.js";
4
+ import { parsePrReview } from "./session.types.pr-review.js";
3
5
  export class ForgeFailureError extends Error {
4
6
  failureCode;
5
7
  failureSource;
@@ -28,7 +30,9 @@ export function parseRunOnceDispatchPacket(value) {
28
30
  runtimeIntent: parseRuntimeIntent(packet.runtimeIntent),
29
31
  serverLocal: parseServerLocal(packet.serverLocal),
30
32
  sandbox: parseSandbox(packet.sandbox, schemaVersion),
33
+ wipAttempt: optionalNonNegativeInteger(packet, "wipAttempt"),
31
34
  pullRequest: parsePullRequest(packet.pullRequest),
35
+ prReview: parsePrReview(packet.prReview),
32
36
  apiKeySecretGrant: parseApiKeySecretGrant(packet.apiKeySecretGrant),
33
37
  apiKeySecretGrantHandle: parseApiKeySecretGrantHandle(packet.apiKeySecretGrantHandle),
34
38
  artifacts: parseArtifacts(packet.artifacts),
@@ -469,19 +473,19 @@ function unvalidatedFailureFactsForCode(code, source) {
469
473
  if (code === "bridge.unavailable") {
470
474
  return facts(code, "transport", "offer", source, "retryable", "retry_dispatch");
471
475
  }
472
- if (["capacity_unavailable", "bridge.runner_draining", "docker_engine_unavailable", "docker_memory_low", "docker_memory_sample_unavailable", "docker_cpu_low", "docker_disk_low", "server_local.resource_pressure", "server_local.capacity_unavailable", "dispatch.preparation_resource_pressure", "sandbox_capacity_profile_unavailable", "host_runtime_admission_expired"].includes(code)) {
476
+ if (["capacity_unavailable", "bridge.runner_draining", "docker_engine_unavailable", "docker_memory_low", "docker_memory_sample_unavailable", "docker_cpu_low", "docker_disk_low", "server_local.resource_pressure", "server_local.capacity_unavailable", "dispatch.preparation_resource_pressure", "sandbox_capacity_profile_unavailable", "host_runtime_admission_expired", "placement_requirements_unmet", "runner_yielding", "runner_settings_pending", "runner_settings_apply_failed", "runner_tier_light", "runner_project_not_allowed"].includes(code)) {
473
477
  return facts(code, "resource", "offer", source, "retryable", "retry_dispatch");
474
478
  }
475
479
  if (["bridge.lease_retry_exhausted", "bridge.capacity_wait_exhausted"].includes(code)) {
476
480
  return facts(code, "resource", "offer", source, "non_retryable", "inspect_failure");
477
481
  }
478
- if (["prepublication_infrastructure_failed", "prepublication_capability_unavailable"].includes(code)) {
482
+ if (["prepublication_infrastructure_failed", "prepublication_capability_unavailable", "host_capacity_timeout", "host_capacity_token_fenced", "host_capacity_ledger_unavailable"].includes(code)) {
479
483
  return facts(code, "resource", "validation", source, "retryable", "retry_with_policy");
480
484
  }
481
485
  if (["prepublication_validation_failed", "prepublication_contract_invalid", "prepublication_execution_scope_invalid"].includes(code)) {
482
486
  return facts(code, "domain", "validation", source, "non_retryable", "fix_input");
483
487
  }
484
- if (code === "comment_repair_changed_files_mismatch") {
488
+ if (["comment_repair_changed_files_mismatch", "runner_result_sidecar_malformed"].includes(code)) {
485
489
  return facts(code, "domain", "validation", source, "non_retryable", "inspect_failure");
486
490
  }
487
491
  if (["generated_output_reset_failed", "generated_output_reset_unverified", "worktree_prepare_failed", "host_runtime_ledger_write_failed", "host_diagnostics_temporary_unavailable", "attempt_process_supervisor_start_failed", "attempt_process_supervisor_start_timeout"].includes(code)) {
@@ -496,7 +500,7 @@ function unvalidatedFailureFactsForCode(code, source) {
496
500
  if (code === "provider_configuration_invalid") {
497
501
  return facts(code, "provider", "prepare", source, "non_retryable", "fix_environment");
498
502
  }
499
- if (["host_port_collision", "host_runtime_process_exited", "host_runtime_listener_timeout", "host_runtime_http_readiness_timeout", "host_runtime_prepared_source_changed", "host_runtime_prepared_probe_incomplete", "host_runtime_prepared_probe_cleanup_unconfirmed"].includes(code)) {
503
+ if (["host_port_collision", "host_runtime_process_exited", "host_runtime_listener_timeout", "host_runtime_http_readiness_timeout", "host_runtime_prepared_source_changed", "host_runtime_contract_changed", "host_runtime_prepared_probe_incomplete", "host_runtime_prepared_probe_cleanup_unconfirmed"].includes(code)) {
500
504
  return facts(code, "resource", "prepare", source, "retryable", "retry_dispatch");
501
505
  }
502
506
  if (code === "host_runtime_project_start_failed") {
@@ -525,7 +529,7 @@ function unvalidatedFailureFactsForCode(code, source) {
525
529
  if (code === "provider_completion_tool_missing") {
526
530
  return facts(code, "provider", "agent", source, "non_retryable", "inspect_failure");
527
531
  }
528
- if (code === "provider_terminated_at_turn_ceiling") {
532
+ if (["provider_terminated_at_turn_ceiling", "provider_turn_ended_with_background_work"].includes(code)) {
529
533
  return facts(code, "provider", "agent", source, "retryable", "retry_with_policy");
530
534
  }
531
535
  if (code === "provider_context_window_exhausted") {
@@ -538,6 +542,9 @@ function unvalidatedFailureFactsForCode(code, source) {
538
542
  if (stableFailureFamilyCodes.has(code) && (code.startsWith("teardown") || code.startsWith("reaper"))) {
539
543
  return facts(code, "transport", "teardown", source, "retryable", "retry_with_policy");
540
544
  }
545
+ if (["pr_review.unsandboxed_host", "pr_review.sandbox_unavailable"].includes(code)) {
546
+ return facts(code, "domain", "offer", source, "non_retryable", "fix_environment");
547
+ }
541
548
  if (["invalid_dispatch"].includes(code)) {
542
549
  return facts(code, "domain", "offer", source, "non_retryable", "fix_input");
543
550
  }
@@ -551,10 +558,7 @@ function unvalidatedFailureFactsForCode(code, source) {
551
558
  ].includes(code)) {
552
559
  return facts(code, "domain", "prepare", source, "non_retryable", "reauthenticate");
553
560
  }
554
- if (code === "sandbox_idle_timeout") {
555
- return facts(code, "provider", "agent", source, "retryable", "retry_with_policy");
556
- }
557
- if (code === "sandbox_wall_timeout") {
561
+ if (["sandbox_idle_timeout", "sandbox_wall_timeout"].includes(code)) {
558
562
  return facts(code, "provider", "agent", source, "retryable", "retry_with_policy");
559
563
  }
560
564
  if (["sandbox_oom_killed", "sandbox_pid_exhausted", "sandbox_file_descriptor_exhausted", "sandbox_storage_exhausted"].includes(code)) {
@@ -1321,77 +1325,3 @@ function parsePriorPhaseArtifacts(value) {
1321
1325
  };
1322
1326
  });
1323
1327
  }
1324
- function asObject(value, label) {
1325
- if (!value || typeof value !== "object" || Array.isArray(value)) {
1326
- throw new Error(`${label} must be an object.`);
1327
- }
1328
- return value;
1329
- }
1330
- function requiredString(source, key) {
1331
- const value = source[key];
1332
- if (typeof value !== "string" || value.trim().length === 0) {
1333
- throw new Error(`${key} must be a non-empty string.`);
1334
- }
1335
- return value;
1336
- }
1337
- function optionalString(source, key) {
1338
- const value = source[key];
1339
- if (value === undefined || value === null) {
1340
- return null;
1341
- }
1342
- if (typeof value !== "string") {
1343
- throw new Error(`${key} must be a string when provided.`);
1344
- }
1345
- return value;
1346
- }
1347
- function requiredBoolean(source, key) {
1348
- const value = source[key];
1349
- if (typeof value !== "boolean") {
1350
- throw new Error(`${key} must be a boolean.`);
1351
- }
1352
- return value;
1353
- }
1354
- function optionalBoolean(source, key) {
1355
- const value = source[key];
1356
- if (value === undefined || value === null) {
1357
- return null;
1358
- }
1359
- if (typeof value !== "boolean") {
1360
- throw new Error(`${key} must be a boolean when provided.`);
1361
- }
1362
- return value;
1363
- }
1364
- function optionalPositiveInteger(source, key) {
1365
- const value = source[key];
1366
- if (value === undefined || value === null) {
1367
- return null;
1368
- }
1369
- if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
1370
- throw new Error(`${key} must be a positive integer when provided.`);
1371
- }
1372
- return value;
1373
- }
1374
- function optionalNonNegativeInteger(source, key) {
1375
- const value = source[key];
1376
- if (value === undefined || value === null) {
1377
- return null;
1378
- }
1379
- if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
1380
- throw new Error(`${key} must be a non-negative integer when provided.`);
1381
- }
1382
- return value;
1383
- }
1384
- function requiredNumber(source, key) {
1385
- const value = source[key];
1386
- if (typeof value !== "number" || !Number.isFinite(value)) {
1387
- throw new Error(`${key} must be a finite number.`);
1388
- }
1389
- return value;
1390
- }
1391
- function boundedInteger(source, key, minimum, maximum) {
1392
- const value = requiredNumber(source, key);
1393
- if (!Number.isSafeInteger(value) || value < minimum || value > maximum) {
1394
- throw new Error(`${key} must be an integer from ${minimum} through ${maximum}.`);
1395
- }
1396
- return value;
1397
- }
@@ -0,0 +1,48 @@
1
+ export interface DispatchPrReviewContext {
2
+ /** The pull request head commit the worktree is checked out at, detached. */
3
+ readonly headSha: string;
4
+ /** The commit the review diffs against: the merge base of the base branch tip and the head, once the bridge resolved it. */
5
+ readonly baseSha: string;
6
+ /** The base branch tip the provider reported, when the bridge replaced it with the merge base. */
7
+ readonly baseTipSha?: string;
8
+ readonly reviewKind: string;
9
+ /** The approved Story spec text, written verbatim to the Story's spec.md. */
10
+ readonly storySpec: string;
11
+ readonly pullRequestNumber: number;
12
+ readonly title: string;
13
+ /** The pull request description. Author-controlled text: treat it as untrusted. */
14
+ readonly description: string;
15
+ readonly baseBranch: string;
16
+ readonly storyWorkItemId: string | null;
17
+ readonly storySpecPath: string | null;
18
+ readonly priorReviews: readonly DispatchPrReviewPriorReview[];
19
+ readonly priorThreads: readonly DispatchPrReviewThread[];
20
+ }
21
+ export interface DispatchPrReviewPriorReview {
22
+ readonly cycleRunId: string;
23
+ readonly sessionId: string;
24
+ readonly headSha: string;
25
+ readonly status: string;
26
+ readonly completedAt: string | null;
27
+ }
28
+ export interface DispatchPrReviewThread {
29
+ readonly threadId: string;
30
+ readonly path: string | null;
31
+ readonly line: number | null;
32
+ readonly startLine: number | null;
33
+ readonly side: string | null;
34
+ /** The head the thread was raised on. */
35
+ readonly reviewedHeadSha: string | null;
36
+ readonly isResolved: boolean;
37
+ readonly isOutdated: boolean;
38
+ readonly comments: readonly DispatchPrReviewThreadComment[];
39
+ }
40
+ export interface DispatchPrReviewThreadComment {
41
+ readonly id: string;
42
+ readonly author: string | null;
43
+ /** Comment text. Author-controlled: treat it as untrusted. */
44
+ readonly body: string;
45
+ readonly url: string | null;
46
+ readonly createdAt: string | null;
47
+ }
48
+ export declare function parsePrReview(value: unknown): DispatchPrReviewContext | null;
@@ -0,0 +1,51 @@
1
+ import { asObject, optionalBoolean, optionalNonNegativeInteger, optionalObjectArray, optionalString, requiredString } from "./session.parse-helpers.js";
2
+ export function parsePrReview(value) {
3
+ if (value === undefined || value === null) {
4
+ return null;
5
+ }
6
+ const prReview = asObject(value, "prReview");
7
+ return {
8
+ headSha: requiredString(prReview, "headSha"),
9
+ baseSha: optionalString(prReview, "baseSha") ?? "",
10
+ ...(optionalString(prReview, "baseTipSha") ? { baseTipSha: optionalString(prReview, "baseTipSha") } : {}),
11
+ reviewKind: optionalString(prReview, "reviewKind") ?? "initial",
12
+ storySpec: optionalString(prReview, "storySpec") ?? "",
13
+ pullRequestNumber: optionalNonNegativeInteger(prReview, "pullRequestNumber") ?? 0,
14
+ title: optionalString(prReview, "title") ?? "",
15
+ description: optionalString(prReview, "description") ?? "",
16
+ baseBranch: optionalString(prReview, "baseBranch") ?? "",
17
+ storyWorkItemId: optionalString(prReview, "storyWorkItemId"),
18
+ storySpecPath: optionalString(prReview, "storySpecPath"),
19
+ priorReviews: optionalObjectArray(prReview, "priorReviews").map(parsePrReviewPriorReview),
20
+ priorThreads: optionalObjectArray(prReview, "priorThreads").map(parsePrReviewThread)
21
+ };
22
+ }
23
+ function parsePrReviewPriorReview(review) {
24
+ return {
25
+ cycleRunId: optionalString(review, "cycleRunId") ?? "",
26
+ sessionId: optionalString(review, "sessionId") ?? "",
27
+ headSha: requiredString(review, "headSha"),
28
+ status: optionalString(review, "status") ?? "",
29
+ completedAt: optionalString(review, "completedAt")
30
+ };
31
+ }
32
+ function parsePrReviewThread(thread) {
33
+ return {
34
+ // The server serializes the id as threadId; id is accepted for the review-finding shape.
35
+ threadId: optionalString(thread, "threadId") || requiredString(thread, "id"),
36
+ path: optionalString(thread, "path"),
37
+ line: optionalNonNegativeInteger(thread, "line"),
38
+ startLine: optionalNonNegativeInteger(thread, "startLine"),
39
+ side: optionalString(thread, "side"),
40
+ reviewedHeadSha: optionalString(thread, "reviewedHeadSha"),
41
+ isResolved: optionalBoolean(thread, "isResolved") ?? false,
42
+ isOutdated: optionalBoolean(thread, "isOutdated") ?? false,
43
+ comments: optionalObjectArray(thread, "comments").map((comment) => ({
44
+ id: optionalString(comment, "id") ?? "",
45
+ author: optionalString(comment, "author"),
46
+ body: optionalString(comment, "body") ?? "",
47
+ url: optionalString(comment, "url"),
48
+ createdAt: optionalString(comment, "createdAt")
49
+ }))
50
+ };
51
+ }
@@ -0,0 +1,31 @@
1
+ export declare const maximumIntegrityJsonBytes: number;
2
+ /** A JSON text that breaks a shape rule. `reason` names the rule and never quotes file content. */
3
+ export declare class JsonShapeError extends Error {
4
+ readonly reason: string;
5
+ constructor(reason: string);
6
+ }
7
+ export declare const oversizedJsonReason = "it is larger than the 8 MiB JSON inspection limit";
8
+ /**
9
+ * Checks a bounded JSON text and calls `onString` with every decoded string token (property names
10
+ * and values). Throws JsonShapeError for a shape problem; errors thrown by `onString` propagate.
11
+ */
12
+ export declare function inspectJsonText(value: string, onString?: (decoded: string) => void): void;
13
+ export declare function decodeJsonStringToken(value: string, openingQuoteIndex: number): {
14
+ readonly decoded: string;
15
+ readonly nextIndex: number;
16
+ };
17
+ /**
18
+ * Why a sidecar that looks like JSON is not acceptable JSON, or null when it is fine: valid JSON,
19
+ * plain text that does not start like JSON, or binary content that is not named *.json.
20
+ */
21
+ export declare function sidecarJsonShapeProblem(content: Uint8Array, path: string, onString?: (decoded: string) => void): string | null;
22
+ /** The instruction an agent gets when it records a sidecar that fails the shape check. */
23
+ export declare function sidecarJsonRepairInstruction(path: string, reason: string): string;
24
+ /**
25
+ * Best-effort decoding of every JSON escape in a text that failed the shape check, so a secret
26
+ * hidden behind escapes still gets the secret error rather than the malformed-sidecar error.
27
+ */
28
+ export declare function decodeJsonEscapesLeniently(value: string): string;
29
+ export declare function looksLikeJson(value: string, path: string): boolean;
30
+ export declare function isJsonWhitespace(code: number): boolean;
31
+ export declare function isJsonPunctuation(code: number): boolean;
@@ -0,0 +1,217 @@
1
+ import { TextDecoder } from "node:util";
2
+ // One set of JSON shape rules for result sidecars. The end-of-run secret check and the QA gate
3
+ // tools that record sidecars during the run both use it, so the agent is told about a malformed
4
+ // sidecar while it can still rewrite the file, and the end-of-run check never disagrees with it.
5
+ //
6
+ // Content sniffing is deliberate: any sidecar whose text starts like JSON ("{", "[" or '"') is
7
+ // held to strict JSON, whatever its file name, so JSON escapes cannot hide secret material from
8
+ // the byte scan. Only a parseable document can be checked token by token.
9
+ export const maximumIntegrityJsonBytes = 8 * 1024 * 1024;
10
+ const maximumIntegrityJsonDepth = 128;
11
+ const maximumIntegrityJsonTokens = 262_144;
12
+ const jsonEscapePattern = /\\(?:u([0-9a-fA-F]{4})|(["\\/bfnrt]))/gu;
13
+ const simpleJsonEscapes = {
14
+ "\"": "\"", "\\": "\\", "/": "/", b: "\b", f: "\f", n: "\n", r: "\r", t: "\t",
15
+ };
16
+ /** A JSON text that breaks a shape rule. `reason` names the rule and never quotes file content. */
17
+ export class JsonShapeError extends Error {
18
+ reason;
19
+ constructor(reason) {
20
+ super(reason);
21
+ this.reason = reason;
22
+ this.name = "JsonShapeError";
23
+ }
24
+ }
25
+ export const oversizedJsonReason = "it is larger than the 8 MiB JSON inspection limit";
26
+ /**
27
+ * Checks a bounded JSON text and calls `onString` with every decoded string token (property names
28
+ * and values). Throws JsonShapeError for a shape problem; errors thrown by `onString` propagate.
29
+ */
30
+ export function inspectJsonText(value, onString) {
31
+ if (Buffer.byteLength(value, "utf8") > maximumIntegrityJsonBytes)
32
+ throw new JsonShapeError(oversizedJsonReason);
33
+ if (value.trim().length === 0)
34
+ throw new JsonShapeError("the file is empty");
35
+ const containers = [];
36
+ let tokenCount = 0;
37
+ let index = 0;
38
+ while (index < value.length) {
39
+ const code = value.charCodeAt(index);
40
+ if (isJsonWhitespace(code) || code === 0x2c || code === 0x3a) {
41
+ index += 1;
42
+ continue;
43
+ }
44
+ tokenCount += 1;
45
+ if (tokenCount > maximumIntegrityJsonTokens) {
46
+ throw new JsonShapeError(`it has more than ${maximumIntegrityJsonTokens} JSON tokens`);
47
+ }
48
+ index = inspectJsonToken(value, index, containers, onString);
49
+ }
50
+ if (containers.length !== 0)
51
+ throw new JsonShapeError("a bracket or brace is never closed");
52
+ assertJsonParses(value);
53
+ }
54
+ function inspectJsonToken(value, index, containers, onString) {
55
+ const code = value.charCodeAt(index);
56
+ if (code === 0x22) {
57
+ const token = decodeJsonStringToken(value, index);
58
+ onString?.(token.decoded);
59
+ return token.nextIndex;
60
+ }
61
+ if (code === 0x7b || code === 0x5b) {
62
+ containers.push(code);
63
+ if (containers.length > maximumIntegrityJsonDepth) {
64
+ throw new JsonShapeError(`it nests deeper than ${maximumIntegrityJsonDepth} levels`);
65
+ }
66
+ return index + 1;
67
+ }
68
+ if (code === 0x7d || code === 0x5d) {
69
+ if (containers.pop() !== (code === 0x7d ? 0x7b : 0x5b)) {
70
+ throw new JsonShapeError(`an unmatched closing bracket or brace ${locationOf(value, index)}`);
71
+ }
72
+ return index + 1;
73
+ }
74
+ let end = index + 1;
75
+ while (end < value.length && !isJsonWhitespace(value.charCodeAt(end)) && !isJsonPunctuation(value.charCodeAt(end))) {
76
+ end += 1;
77
+ }
78
+ return end;
79
+ }
80
+ function assertJsonParses(value) {
81
+ try {
82
+ JSON.parse(value);
83
+ }
84
+ catch (error) {
85
+ // The parser's message can quote the offending text; keep only its position.
86
+ const message = error instanceof Error ? error.message : "";
87
+ const position = /\bposition (\d+)/u.exec(message);
88
+ const location = position ? ` ${locationOf(value, Number(position[1]))}` : "";
89
+ throw new JsonShapeError(message.includes("after JSON")
90
+ ? `unexpected text after the JSON value${location}`
91
+ : `invalid JSON syntax${location}`);
92
+ }
93
+ }
94
+ export function decodeJsonStringToken(value, openingQuoteIndex) {
95
+ const chunks = [];
96
+ let segmentStart = openingQuoteIndex + 1;
97
+ let index = segmentStart;
98
+ while (index < value.length) {
99
+ const code = value.charCodeAt(index);
100
+ if (code === 0x22) {
101
+ chunks.push(value.slice(segmentStart, index));
102
+ const decoded = chunks.join("");
103
+ if (!isWellFormedUnicode(decoded)) {
104
+ throw new JsonShapeError(`a string has an unpaired Unicode surrogate ${locationOf(value, openingQuoteIndex)}`);
105
+ }
106
+ return { decoded, nextIndex: index + 1 };
107
+ }
108
+ if (code < 0x20) {
109
+ throw new JsonShapeError(`a string contains a raw control character ${locationOf(value, index)}`);
110
+ }
111
+ if (code !== 0x5c) {
112
+ index += 1;
113
+ continue;
114
+ }
115
+ chunks.push(value.slice(segmentStart, index));
116
+ const escape = decodeJsonEscape(value, index);
117
+ chunks.push(escape.decoded);
118
+ index = escape.nextIndex;
119
+ segmentStart = index;
120
+ }
121
+ throw new JsonShapeError(`a string is never closed ${locationOf(value, openingQuoteIndex)}`);
122
+ }
123
+ function decodeJsonEscape(value, backslashIndex) {
124
+ const escaped = value[backslashIndex + 1];
125
+ const simple = escaped === undefined ? undefined : simpleJsonEscapes[escaped];
126
+ if (simple !== undefined)
127
+ return { decoded: simple, nextIndex: backslashIndex + 2 };
128
+ const hex = value.slice(backslashIndex + 2, backslashIndex + 6);
129
+ if (escaped !== "u" || !/^[0-9a-fA-F]{4}$/u.test(hex)) {
130
+ throw new JsonShapeError(`a string has an invalid escape sequence ${locationOf(value, backslashIndex)}`);
131
+ }
132
+ return { decoded: String.fromCharCode(Number.parseInt(hex, 16)), nextIndex: backslashIndex + 6 };
133
+ }
134
+ /**
135
+ * Why a sidecar that looks like JSON is not acceptable JSON, or null when it is fine: valid JSON,
136
+ * plain text that does not start like JSON, or binary content that is not named *.json.
137
+ */
138
+ export function sidecarJsonShapeProblem(content, path, onString) {
139
+ let decoded;
140
+ try {
141
+ decoded = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(content);
142
+ }
143
+ catch {
144
+ // Sniff the bytes anyway (invalid sequences decode to U+FFFD, which is not whitespace), so a
145
+ // file that starts like JSON cannot dodge the strict check with a stray invalid byte.
146
+ return looksLikeJson(Buffer.from(content).toString("utf8"), path) ? "the file is not valid UTF-8" : null;
147
+ }
148
+ if (!looksLikeJson(decoded, path))
149
+ return null;
150
+ if (content.length >= 3 && content[0] === 0xef && content[1] === 0xbb && content[2] === 0xbf) {
151
+ return "the file starts with a UTF-8 byte-order mark";
152
+ }
153
+ try {
154
+ inspectJsonText(decoded, onString);
155
+ return null;
156
+ }
157
+ catch (error) {
158
+ if (error instanceof JsonShapeError)
159
+ return error.reason;
160
+ throw error;
161
+ }
162
+ }
163
+ /** The instruction an agent gets when it records a sidecar that fails the shape check. */
164
+ export function sidecarJsonRepairInstruction(path, reason) {
165
+ const fix = isJsonFileName(path)
166
+ ? "Rewrite it as valid JSON (UTF-8, no byte-order mark), or save plain-text output under a name that does not end in .json"
167
+ : "Rewrite it as valid JSON, or as plain text that does not start with \"[\", \"{\" or a double quote (for example, put a title line first)";
168
+ return `${path} looks like JSON but is not valid JSON (${reason}). Forge rejects sidecars it cannot fully inspect. `
169
+ + `${fix}, then resubmit with the file's new bytes and content_hash.`;
170
+ }
171
+ /**
172
+ * Best-effort decoding of every JSON escape in a text that failed the shape check, so a secret
173
+ * hidden behind escapes still gets the secret error rather than the malformed-sidecar error.
174
+ */
175
+ export function decodeJsonEscapesLeniently(value) {
176
+ return value.replace(jsonEscapePattern, (_match, hex, simple) => hex !== undefined ? String.fromCharCode(Number.parseInt(hex, 16)) : simpleJsonEscapes[simple ?? ""] ?? "");
177
+ }
178
+ export function looksLikeJson(value, path) {
179
+ if (isJsonFileName(path))
180
+ return true;
181
+ const candidate = value.trimStart().replace(/^\uFEFF/u, "").trimStart();
182
+ return candidate.startsWith("{") || candidate.startsWith("[") || candidate.startsWith("\"");
183
+ }
184
+ function isJsonFileName(path) {
185
+ return path.toLowerCase().endsWith(".json");
186
+ }
187
+ function locationOf(value, index) {
188
+ let line = 1;
189
+ let lineStart = 0;
190
+ for (let cursor = value.indexOf("\n"); cursor >= 0 && cursor < index; cursor = value.indexOf("\n", cursor + 1)) {
191
+ line += 1;
192
+ lineStart = cursor + 1;
193
+ }
194
+ return `at line ${line}, column ${index - lineStart + 1}`;
195
+ }
196
+ function isWellFormedUnicode(value) {
197
+ for (let index = 0; index < value.length; index += 1) {
198
+ const code = value.charCodeAt(index);
199
+ if (code >= 0xd800 && code <= 0xdbff) {
200
+ const next = value.charCodeAt(index + 1);
201
+ if (!(next >= 0xdc00 && next <= 0xdfff))
202
+ return false;
203
+ index += 1;
204
+ }
205
+ else if (code >= 0xdc00 && code <= 0xdfff) {
206
+ return false;
207
+ }
208
+ }
209
+ return true;
210
+ }
211
+ export function isJsonWhitespace(code) {
212
+ return code === 0x20 || code === 0x09 || code === 0x0a || code === 0x0d;
213
+ }
214
+ export function isJsonPunctuation(code) {
215
+ return code === 0x7b || code === 0x7d || code === 0x5b || code === 0x5d
216
+ || code === 0x2c || code === 0x3a || code === 0x22;
217
+ }
@@ -0,0 +1,32 @@
1
+ import { GitClient } from "../shared/git/git.js";
2
+ /**
3
+ * What the attempt's host runtime stack was built and launched from. When the
4
+ * workspace no longer matches, the running API binary and dev server are stale:
5
+ * an uncommitted edit or an in-progress `merge --no-commit` changes the source
6
+ * without moving HEAD.
7
+ */
8
+ export interface WorkspaceRuntimeFingerprint {
9
+ readonly headSha: string;
10
+ /** Contents of MERGE_HEAD while a merge is in progress, else null. */
11
+ readonly mergeHead: string | null;
12
+ /** sha256 of `git diff HEAD --binary` (staged and unstaged changes to tracked files, mode changes included). */
13
+ readonly diffDigest: string;
14
+ /**
15
+ * sha256 over untracked, non-ignored file names, their executable bit, and their contents (or
16
+ * size and mtime for large files).
17
+ */
18
+ readonly untrackedDigest: string;
19
+ /**
20
+ * sha256 over the runtime contract as loaded now and the files its launch commands name. Git's
21
+ * views above skip ignored files, and a project may ignore its contract or a launch script; a
22
+ * change there alters what the stack runs without changing anything git reports.
23
+ */
24
+ readonly runtimeInputsDigest: string;
25
+ /** One digest over every field above. */
26
+ readonly digest: string;
27
+ }
28
+ export type WorkspaceRuntimeFingerprintReader = (worktreePath: string) => Promise<WorkspaceRuntimeFingerprint>;
29
+ export declare function readWorkspaceRuntimeFingerprint(worktreePath: string, git?: Pick<GitClient, "run">): Promise<WorkspaceRuntimeFingerprint>;
30
+ export declare function sameWorkspaceRuntimeFingerprint(left: WorkspaceRuntimeFingerprint | null, right: WorkspaceRuntimeFingerprint | null): boolean;
31
+ /** Names what changed between two fingerprints, for the restart checkpoint. */
32
+ export declare function workspaceRuntimeFingerprintChanges(previous: WorkspaceRuntimeFingerprint | null, current: WorkspaceRuntimeFingerprint): readonly string[];