@loucompanion/forge-bridge 0.1.4-dev.63db04bcffca → 0.1.4-dev.800627ea0931

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 (170) hide show
  1. package/README.md +54 -2
  2. package/dist/bridge/bridge-chat-provider-command.d.ts +16 -0
  3. package/dist/bridge/bridge-chat-provider-command.js +125 -0
  4. package/dist/bridge/bridge.base.d.ts +9 -0
  5. package/dist/bridge/bridge.service.d.ts +85 -3
  6. package/dist/bridge/bridge.service.js +361 -122
  7. package/dist/bridge/bridge.types.d.ts +22 -0
  8. package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
  9. package/dist/bridge/dispatch-result-outbox.js +31 -6
  10. package/dist/bridge/local-yield-flag.d.ts +6 -0
  11. package/dist/bridge/local-yield-flag.js +34 -0
  12. package/dist/bridge/runner-host-capabilities.d.ts +2 -0
  13. package/dist/bridge/runner-host-capabilities.js +4 -0
  14. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  15. package/dist/bridge/test-postgres-capability.js +120 -0
  16. package/dist/cleanup/cleanup.service.d.ts +9 -0
  17. package/dist/cleanup/cleanup.service.js +72 -109
  18. package/dist/cleanup/cleanup.types.d.ts +4 -0
  19. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  20. package/dist/cleanup/forge-owned-paths.js +53 -0
  21. package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
  22. package/dist/cleanup/host-runtime-ledger.js +109 -0
  23. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  24. package/dist/cleanup/managed-branch-sweep.js +111 -0
  25. package/dist/cli/cli.help.js +18 -0
  26. package/dist/cli/cli.service.d.ts +16 -0
  27. package/dist/cli/cli.service.js +142 -16
  28. package/dist/cli/local-config.d.ts +4 -0
  29. package/dist/cli/local-config.js +26 -4
  30. package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
  31. package/dist/runtime/attempt-process-supervisor.d.ts +19 -0
  32. package/dist/runtime/attempt-process-supervisor.js +50 -0
  33. package/dist/runtime/host-database-capability-boundary.d.ts +1 -1
  34. package/dist/runtime/host-database-capability-boundary.js +1 -0
  35. package/dist/runtime/host-facts.d.ts +35 -0
  36. package/dist/runtime/host-facts.js +95 -0
  37. package/dist/runtime/host-load-admission.d.ts +64 -0
  38. package/dist/runtime/host-load-admission.js +99 -0
  39. package/dist/runtime/host-load-child-environment.d.ts +27 -0
  40. package/dist/runtime/host-load-child-environment.js +76 -0
  41. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  42. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  43. package/dist/runtime/host-load-governor-config.d.ts +52 -0
  44. package/dist/runtime/host-load-governor-config.js +83 -0
  45. package/dist/runtime/host-load-governor.d.ts +184 -0
  46. package/dist/runtime/host-load-governor.js +632 -0
  47. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  48. package/dist/runtime/host-load-ledger-lock.js +185 -0
  49. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  50. package/dist/runtime/host-load-runtime-settings.js +78 -0
  51. package/dist/runtime/host-load-sampler.d.ts +126 -0
  52. package/dist/runtime/host-load-sampler.js +232 -0
  53. package/dist/runtime/host-load-step-class.d.ts +70 -0
  54. package/dist/runtime/host-load-step-class.js +161 -0
  55. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  56. package/dist/runtime/host-load-step-reaper.js +95 -0
  57. package/dist/runtime/host-load-step-run.d.ts +73 -0
  58. package/dist/runtime/host-load-step-run.js +102 -0
  59. package/dist/runtime/host-load-test-slot.d.ts +43 -0
  60. package/dist/runtime/host-load-test-slot.js +81 -0
  61. package/dist/runtime/host-load-token-ledger.d.ts +200 -0
  62. package/dist/runtime/host-load-token-ledger.js +453 -0
  63. package/dist/runtime/host-pressure-stall.d.ts +61 -0
  64. package/dist/runtime/host-pressure-stall.js +168 -0
  65. package/dist/runtime/host-runtime-contract.d.ts +4 -0
  66. package/dist/runtime/host-runtime-contract.js +6 -1
  67. package/dist/runtime/host-runtime-lease.d.ts +74 -4
  68. package/dist/runtime/host-runtime-lease.js +336 -20
  69. package/dist/runtime/host-runtime-promotion.d.ts +23 -0
  70. package/dist/runtime/host-runtime-promotion.js +48 -0
  71. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  72. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  73. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  74. package/dist/runtime/host-runtime-requirements.js +117 -0
  75. package/dist/runtime/managed-command-teardown.d.ts +62 -0
  76. package/dist/runtime/managed-command-teardown.js +607 -0
  77. package/dist/runtime/playwright-browser-cache.d.ts +39 -0
  78. package/dist/runtime/playwright-browser-cache.js +227 -0
  79. package/dist/runtime/playwright-host-runtime-adapter.d.ts +18 -0
  80. package/dist/runtime/playwright-host-runtime-adapter.js +61 -55
  81. package/dist/runtime/runner-settings.d.ts +100 -0
  82. package/dist/runtime/runner-settings.js +214 -0
  83. package/dist/sandbox/host-capacity-broker.d.ts +113 -0
  84. package/dist/sandbox/host-capacity-broker.js +334 -0
  85. package/dist/sandbox/runtime.d.ts +10 -1
  86. package/dist/sandbox/runtime.js +45 -2
  87. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  88. package/dist/sandbox/sandbox-cgroups.js +42 -0
  89. package/dist/session/managed-attempt-tools.d.ts +27 -0
  90. package/dist/session/managed-attempt-tools.js +356 -41
  91. package/dist/session/managed-build-coordinator.d.ts +1 -1
  92. package/dist/session/managed-build-coordinator.js +4 -1
  93. package/dist/session/managed-command-host-load.d.ts +47 -0
  94. package/dist/session/managed-command-host-load.js +83 -0
  95. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  96. package/dist/session/mcp-argument-coercion.js +121 -0
  97. package/dist/session/phase-completion.artifacts.d.ts +7 -0
  98. package/dist/session/phase-completion.artifacts.js +98 -25
  99. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  100. package/dist/session/phase-completion.command-validation.js +77 -0
  101. package/dist/session/phase-completion.d.ts +4 -0
  102. package/dist/session/phase-completion.helpers.js +13 -12
  103. package/dist/session/phase-completion.js +4 -0
  104. package/dist/session/phase-completion.prompts.js +6 -1
  105. package/dist/session/phase-completion.runtime.d.ts +5 -3
  106. package/dist/session/phase-completion.runtime.js +70 -35
  107. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  108. package/dist/session/phase-completion.schema-parts.js +188 -0
  109. package/dist/session/phase-completion.schemas.d.ts +3 -3
  110. package/dist/session/phase-completion.schemas.js +206 -221
  111. package/dist/session/phase-completion.validation.d.ts +2 -3
  112. package/dist/session/phase-completion.validation.js +46 -92
  113. package/dist/session/pre-publication-host-load.d.ts +27 -0
  114. package/dist/session/pre-publication-host-load.js +111 -0
  115. package/dist/session/pre-publication-pass.d.ts +60 -0
  116. package/dist/session/pre-publication-pass.js +145 -0
  117. package/dist/session/pre-publication-process.d.ts +23 -0
  118. package/dist/session/pre-publication-process.js +109 -0
  119. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  120. package/dist/session/pre-publication-skipped-tests.js +109 -0
  121. package/dist/session/pre-publication-step-execution.d.ts +11 -0
  122. package/dist/session/pre-publication-step-execution.js +49 -0
  123. package/dist/session/pre-publication-validation.d.ts +30 -20
  124. package/dist/session/pre-publication-validation.js +173 -192
  125. package/dist/session/provider-cli/claude-background-work.d.ts +66 -0
  126. package/dist/session/provider-cli/claude-background-work.js +180 -0
  127. package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
  128. package/dist/session/provider-cli/pre-publication-repair.js +243 -0
  129. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
  130. package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
  131. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  132. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  133. package/dist/session/provider-cli/provider-cli.process.d.ts +39 -2
  134. package/dist/session/provider-cli/provider-cli.process.js +276 -42
  135. package/dist/session/provider-cli/provider-cli.prompts.d.ts +7 -0
  136. package/dist/session/provider-cli/provider-cli.prompts.js +65 -10
  137. package/dist/session/provider-cli/provider-cli.runtime.js +7 -0
  138. package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
  139. package/dist/session/provider-cli/provider-cli.service.js +203 -172
  140. package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
  141. package/dist/session/provider-cli/provider-in-flight-work.d.ts +10 -0
  142. package/dist/session/provider-cli/provider-in-flight-work.js +92 -0
  143. package/dist/session/provider-cli/provider-output-state.d.ts +8 -0
  144. package/dist/session/provider-cli/provider-output-state.js +15 -0
  145. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  146. package/dist/session/publishable-worktree-changes.js +193 -0
  147. package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
  148. package/dist/session/sandbox-host-capacity-gate.js +231 -0
  149. package/dist/session/session.base.d.ts +9 -1
  150. package/dist/session/session.service.d.ts +9 -2
  151. package/dist/session/session.service.js +120 -5
  152. package/dist/session/session.types.d.ts +3 -0
  153. package/dist/session/session.types.js +15 -3
  154. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  155. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  156. package/dist/shared/process/host-process-supervisor.d.ts +1 -0
  157. package/dist/shared/process/host-process-supervisor.js +1 -1
  158. package/dist/shared/process/process-tree.d.ts +52 -0
  159. package/dist/shared/process/process-tree.js +144 -0
  160. package/dist/shared/process/process.d.ts +67 -0
  161. package/dist/shared/process/process.js +213 -11
  162. package/dist/shared/provider-capabilities.js +5 -6
  163. package/dist/version.d.ts +1 -1
  164. package/dist/version.js +1 -1
  165. package/dist/worktree/dependency-warmer.d.ts +25 -0
  166. package/dist/worktree/dependency-warmer.js +46 -10
  167. package/dist/worktree/worktree.service.d.ts +10 -1
  168. package/dist/worktree/worktree.service.js +42 -2
  169. package/dist/worktree/worktree.types.d.ts +7 -0
  170. package/package.json +2 -2
@@ -1,4 +1,6 @@
1
1
  import { type CompletionPhase, type DebugCompletionPhase, type QaCompletionGate } from "./phase-completion.js";
2
+ export { validateQaGatePassingCommands } from "./phase-completion.command-validation.js";
3
+ export declare const qaEvidenceGates: ReadonlySet<QaCompletionGate>;
2
4
  export declare function normalizeCompletionStatus(value: string, phase?: CompletionPhase): string;
3
5
  export declare function normalizeQaGateStatus(value: string): string;
4
6
  export declare function validatePayloadShape(phase: CompletionPhase, payload: Record<string, unknown>): void;
@@ -6,9 +8,6 @@ export declare function validateCommentRepairPayloadShape(payload: Record<string
6
8
  export declare function validateCiRepairPayloadShape(payload: Record<string, unknown>): void;
7
9
  export declare function validateDebugPayloadShape(phase: DebugCompletionPhase, payload: Record<string, unknown>): void;
8
10
  export declare function validateQaGatePayloadShape(gate: QaCompletionGate, payload: Record<string, unknown>, status: string): void;
9
- export declare function validateQaGatePassingCommands(commands: readonly unknown[], options?: {
10
- readonly allowClassifiedNonBlockingFailures?: boolean;
11
- }): void;
12
11
  export declare function validateArchitectPayloadShape(payload: Record<string, unknown>, status: string): void;
13
12
  export declare function validateArchitectTaskDevelopScope(task: Record<string, unknown>, taskId: string): void;
14
13
  export declare function validateArchitectVerificationScope(task: Record<string, unknown>, taskId: string): void;
@@ -1,4 +1,8 @@
1
1
  import { qaBlockerReasons, qaCandidateBugActions, qaFindingScopes, qaFindingSeverities, qaGateToolNames, qaScopeAuthorities, qaScopeCapabilities, qaScopeConfidence, qaScopeEvidence, qaScopeFields, qaScopeSources, qaScopeSurfaces } from "./phase-completion.js";
2
+ import { structuredTypeHint } from "./mcp-argument-coercion.js";
3
+ import { validateQaGatePassingCommands } from "./phase-completion.command-validation.js";
4
+ export { validateQaGatePassingCommands } from "./phase-completion.command-validation.js";
5
+ export const qaEvidenceGates = new Set(["qa_regression", "qa_api", "qa_manual_web", "qa_bug_repro"]);
2
6
  export function normalizeCompletionStatus(value, phase) {
3
7
  const normalized = value.trim().toLowerCase().replace(/-/g, "_");
4
8
  if (phase === "qa") {
@@ -157,11 +161,11 @@ export function validateCommentRepairPayloadShape(payload) {
157
161
  requireNonEmptyStringRecord(record, "summary", `changed_files[${index}].`);
158
162
  }
159
163
  if (hasFixed && arrayLength(payload, "changed_files") === 0) {
160
- throw new Error("fixed comment dispositions require changed_files evidence.");
164
+ throw new Error("changed_files must include at least one entry when any disposition is fixed.");
161
165
  }
162
166
  if (arrayLength(payload, "changed_files") > 0) {
163
167
  requireNonEmptyArray(payload, "validation");
164
- validateQaGatePassingCommands(payload.validation);
168
+ validateQaGatePassingCommands(payload.validation, { label: "validation", context: "status is pass" });
165
169
  }
166
170
  }
167
171
  export function validateCiRepairPayloadShape(payload) {
@@ -196,7 +200,7 @@ export function validateCiRepairPayloadShape(payload) {
196
200
  for (const key of ["narrow_validation", "broader_validation"]) {
197
201
  requireArray(payload, key);
198
202
  requireNonEmptyArray(payload, key);
199
- validateQaGatePassingCommands(payload[key]);
203
+ validateQaGatePassingCommands(payload[key], { label: key, context: "status is pass" });
200
204
  }
201
205
  requireArray(payload, "workflow_validation");
202
206
  requireNonEmptyArray(payload, "workflow_validation");
@@ -276,6 +280,34 @@ export function validateDebugPayloadShape(phase, payload) {
276
280
  requireNonEmptyArray(payload, "required_regressions");
277
281
  requirePassingCommands(payload);
278
282
  }
283
+ // Shared by the QA evidence gates and the final verdict: gate evidence is inherited into the
284
+ // verdict, so a gate must reject what the verdict would reject.
285
+ function validateQaBrowserCheckEntries(browserChecks, status) {
286
+ for (const [index, browserCheck] of browserChecks.entries()) {
287
+ requireEvidenceRecord(browserCheck, `browser_checks[${index}]`);
288
+ const record = browserCheck;
289
+ requireNonEmptyStringRecord(record, "summary", `browser_checks[${index}].`);
290
+ requireNonEmptyStringRecord(record, "status", `browser_checks[${index}].`);
291
+ const checkStatus = optionalString(record, "status");
292
+ if (status === "pass" && checkStatus && normalizedString(checkStatus) !== "pass") {
293
+ throw new Error(`browser_checks[${index}].status must be pass when QA status is pass.`);
294
+ }
295
+ if (!optionalString(record, "url") && !optionalString(record, "route")) {
296
+ throw new Error(`browser_checks[${index}].url is required unless browser_checks[${index}].route is given.`);
297
+ }
298
+ }
299
+ }
300
+ function validateQaSidecarEntries(sidecars) {
301
+ for (const [index, sidecar] of sidecars.entries()) {
302
+ requireEvidenceRecord(sidecar, `sidecars[${index}]`);
303
+ const record = sidecar;
304
+ requireNonEmptyStringRecord(record, "path", `sidecars[${index}].`);
305
+ requireNonEmptyStringRecord(record, "content_hash", `sidecars[${index}].`);
306
+ if (typeof record.bytes !== "number" || !Number.isFinite(record.bytes) || record.bytes <= 0) {
307
+ throw new Error(`sidecars[${index}].bytes must be greater than 0.`);
308
+ }
309
+ }
310
+ }
279
311
  export function validateQaGatePayloadShape(gate, payload, status) {
280
312
  requireField(payload, "summary");
281
313
  if (status === "skipped") {
@@ -293,6 +325,12 @@ export function validateQaGatePayloadShape(gate, payload, status) {
293
325
  throw new Error("complete_qa_plan pass requires checklist with at least one entry.");
294
326
  }
295
327
  }
328
+ if (qaEvidenceGates.has(gate)) {
329
+ // Every evidence gate's sidecars are merged into the final verdict, so a
330
+ // malformed value must be rejected here, not when the verdict is assembled.
331
+ validateQaSidecarEntries(qaArray(payload, "sidecars", qaEvidenceSource(payload)));
332
+ validateQaBrowserCheckEntries(qaArray(payload, "browser_checks"), status);
333
+ }
296
334
  if (gate === "qa_findings" && status !== "blocked") {
297
335
  qaObjectArray(payload, "findings");
298
336
  qaObjectArray(payload, "candidate_bugs");
@@ -314,70 +352,6 @@ export function validateQaGatePayloadShape(gate, payload, status) {
314
352
  }
315
353
  }
316
354
  }
317
- export function validateQaGatePassingCommands(commands, options = {}) {
318
- const issues = [];
319
- for (const [index, command] of commands.entries()) {
320
- if (!command || typeof command !== "object" || Array.isArray(command)) {
321
- issues.push(`commands[${index}] must be an object.`);
322
- continue;
323
- }
324
- const record = command;
325
- if (!optionalString(record, "command"))
326
- issues.push(`commands[${index}].command is required.`);
327
- if (!optionalString(record, "status"))
328
- issues.push(`commands[${index}].status is required.`);
329
- if (!optionalString(record, "summary"))
330
- issues.push(`commands[${index}].summary is required.`);
331
- if (typeof record.exit_code !== "number" || !Number.isFinite(record.exit_code)) {
332
- issues.push(`commands[${index}].exit_code is required.`);
333
- continue;
334
- }
335
- const passed = record.exit_code === 0 && normalizedString(record.status) === "pass";
336
- if (!passed
337
- && options.allowClassifiedNonBlockingFailures
338
- && optionalString(record, "classification")) {
339
- try {
340
- validateClassifiedNonBlockingQaFailure(record, index);
341
- }
342
- catch (error) {
343
- issues.push(error instanceof Error ? error.message : String(error));
344
- }
345
- continue;
346
- }
347
- if (record.exit_code !== 0) {
348
- issues.push(`commands[${index}].exit_code must be 0 when QA gate status is pass.`);
349
- }
350
- if (normalizedString(record.status) !== "pass") {
351
- issues.push(`commands[${index}].status must be pass when QA gate status is pass.`);
352
- }
353
- }
354
- throwCompletionPayloadIssues(issues);
355
- }
356
- function validateClassifiedNonBlockingQaFailure(record, index) {
357
- const classification = normalizedString(optionalString(record, "classification"));
358
- if (classification !== "out_of_scope_failure" && classification !== "baseline_failure") {
359
- throw new Error(`commands[${index}] is non-passing; QA regression pass requires classification out_of_scope_failure or baseline_failure with corroborating evidence.`);
360
- }
361
- requireNonEmptyStringRecord(record, "candidate_bug_id", `commands[${index}].`);
362
- requireNonEmptyStringRecord(record, "scope_evidence", `commands[${index}].`);
363
- if (record.acceptance_criteria_independent !== true) {
364
- throw new Error(`commands[${index}].acceptance_criteria_independent must be true for a non-blocking QA regression failure.`);
365
- }
366
- if (classification === "out_of_scope_failure") {
367
- requireNonEmptyStringRecord(record, "repro_command", `commands[${index}].`);
368
- if (typeof record.repro_exit_code !== "number" || !Number.isFinite(record.repro_exit_code) || record.repro_exit_code === 0) {
369
- throw new Error(`commands[${index}].repro_exit_code must be a non-zero number for an out-of-scope failure.`);
370
- }
371
- return;
372
- }
373
- requireNonEmptyStringRecord(record, "baseline_ref", `commands[${index}].`);
374
- if (typeof record.baseline_exit_code !== "number" || !Number.isFinite(record.baseline_exit_code) || record.baseline_exit_code === 0) {
375
- throw new Error(`commands[${index}].baseline_exit_code must be a non-zero number for a baseline failure.`);
376
- }
377
- if (record.failure_signature_match !== true) {
378
- throw new Error(`commands[${index}].failure_signature_match must be true for a baseline failure.`);
379
- }
380
- }
381
355
  export function validateArchitectPayloadShape(payload, status) {
382
356
  if (status !== "pass") {
383
357
  requireArchitectNonPassEvidence(payload);
@@ -794,13 +768,13 @@ export function validateQaPayloadShape(payload, status) {
794
768
  throw new Error("QA pass/needs_rework requires tested_acceptance_criteria with at least one criterion.");
795
769
  }
796
770
  if (commands.length === 0 && browserChecks.length === 0 && notes.length === 0) {
797
- throw new Error("QA pass/needs_rework requires at least one command, browser check, or evidence note.");
771
+ throw new Error("QA pass/needs_rework requires at least one entry in commands or browser_checks, or a non-empty notes string.");
798
772
  }
799
773
  }
800
774
  const commandIssues = [];
801
775
  for (const [index, command] of commands.entries()) {
802
776
  if (!command || typeof command !== "object" || Array.isArray(command)) {
803
- commandIssues.push(`commands[${index}] must be an object.`);
777
+ commandIssues.push(`commands[${index}] must be an object${structuredTypeHint(command, "object")}.`);
804
778
  continue;
805
779
  }
806
780
  const record = command;
@@ -821,28 +795,8 @@ export function validateQaPayloadShape(payload, status) {
821
795
  }
822
796
  }
823
797
  throwCompletionPayloadIssues(commandIssues);
824
- for (const [index, browserCheck] of browserChecks.entries()) {
825
- requireEvidenceRecord(browserCheck, `browser_checks[${index}]`);
826
- const record = browserCheck;
827
- requireNonEmptyStringRecord(record, "summary", `browser_checks[${index}].`);
828
- requireNonEmptyStringRecord(record, "status", `browser_checks[${index}].`);
829
- const checkStatus = optionalString(record, "status");
830
- if (status === "pass" && checkStatus && normalizedString(checkStatus) !== "pass") {
831
- throw new Error(`browser_checks[${index}].status must be pass when QA status is pass.`);
832
- }
833
- if (!optionalString(record, "url") && !optionalString(record, "route")) {
834
- throw new Error(`browser_checks[${index}] must include url or route.`);
835
- }
836
- }
837
- for (const [index, sidecar] of sidecars.entries()) {
838
- requireEvidenceRecord(sidecar, `sidecars[${index}]`);
839
- const record = sidecar;
840
- requireNonEmptyStringRecord(record, "path", `sidecars[${index}].`);
841
- requireNonEmptyStringRecord(record, "content_hash", `sidecars[${index}].`);
842
- if (typeof record.bytes !== "number" || !Number.isFinite(record.bytes) || record.bytes <= 0) {
843
- throw new Error(`sidecars[${index}].bytes must be greater than 0.`);
844
- }
845
- }
798
+ validateQaBrowserCheckEntries(browserChecks, status);
799
+ validateQaSidecarEntries(sidecars);
846
800
  for (const [index, finding] of findings.entries()) {
847
801
  requireNonEmptyStringRecord(finding, "id", `findings[${index}].`);
848
802
  requireNonEmptyStringRecord(finding, "title", `findings[${index}].`);
@@ -884,7 +838,7 @@ export function validateQaPayloadShape(payload, status) {
884
838
  }
885
839
  if (status === "needs_rework") {
886
840
  if (inScopeFindingIds.length === 0) {
887
- throw new Error("QA needs_rework requires at least one actionable in-scope finding.");
841
+ throw new Error("QA needs_rework requires at least one actionable in-scope finding: add an entry to findings with scope: in_scope.");
888
842
  }
889
843
  if (optionalString(payload, "blocker_reason")) {
890
844
  throw new Error("QA needs_rework must not include blocker_reason.");
@@ -0,0 +1,27 @@
1
+ import { type HostLoadStepGate } from "../runtime/host-load-governor.js";
2
+ import { type HostLoadTokenPriority } from "../runtime/host-load-token-ledger.js";
3
+ import type { RunnerDispatchEvent } from "./session.types.js";
4
+ /** Which attempt a governed validation step belongs to, and its queue class. */
5
+ export interface PrePublicationHostLoadOwner {
6
+ readonly dispatchAttemptId: string | null;
7
+ readonly priority: HostLoadTokenPriority;
8
+ }
9
+ export interface GovernedValidationStep {
10
+ readonly checkId: string;
11
+ readonly command: string;
12
+ readonly args: readonly string[];
13
+ readonly owner?: PrePublicationHostLoadOwner;
14
+ readonly signal?: AbortSignal;
15
+ readonly emit?: (event: RunnerDispatchEvent) => Promise<void>;
16
+ }
17
+ /**
18
+ * Runs one pre-publication step behind the host load governor (decision 0013).
19
+ * With the governor off this is a direct call, so behavior is unchanged. With
20
+ * it on, the step waits for admission first; queue time is reported as
21
+ * `host_load_wait_ms` with status `waiting_for_host_capacity`, and the step's
22
+ * own clock (`elapsed_ms`) starts only once it is admitted. `run` gets the
23
+ * signal to launch with: it also aborts when the step's reservation is lost
24
+ * (token fenced, or not renewable for a lease), and the step then fails with
25
+ * that error instead of running on unaccounted.
26
+ */
27
+ export declare function runHostGovernedValidationStep<T>(gate: HostLoadStepGate | undefined, step: GovernedValidationStep, run: (signal: AbortSignal | undefined) => Promise<T>): Promise<T>;
@@ -0,0 +1,111 @@
1
+ import { monotonicNowMs } from "../shared/time/monotonic.js";
2
+ import { HostCapacityTimeoutError } from "../runtime/host-load-governor.js";
3
+ import { HostCapacityLedgerUnavailableError } from "../runtime/host-load-ledger-lock.js";
4
+ import { retentionFor, returnHostLoadToken } from "../runtime/host-load-step-run.js";
5
+ import { classifyValidationStep } from "../runtime/host-load-step-class.js";
6
+ import { HostCapacityTokenFencedError } from "../runtime/host-load-token-ledger.js";
7
+ /**
8
+ * Runs one pre-publication step behind the host load governor (decision 0013).
9
+ * With the governor off this is a direct call, so behavior is unchanged. With
10
+ * it on, the step waits for admission first; queue time is reported as
11
+ * `host_load_wait_ms` with status `waiting_for_host_capacity`, and the step's
12
+ * own clock (`elapsed_ms`) starts only once it is admitted. `run` gets the
13
+ * signal to launch with: it also aborts when the step's reservation is lost
14
+ * (token fenced, or not renewable for a lease), and the step then fails with
15
+ * that error instead of running on unaccounted.
16
+ */
17
+ export async function runHostGovernedValidationStep(gate, step, run) {
18
+ if (!gate?.enabled)
19
+ return await run(step.signal);
20
+ const { stepClass, cost } = classifyValidationStep(step.checkId, step.command, step.args);
21
+ const base = { checkId: step.checkId, contractId: "forge-ci-parity-v1", stepClass };
22
+ const emit = async (eventType, content, data, kind = "checkpoint") => {
23
+ await step.emit?.({ role: "runner", kind, content, eventType, data: JSON.stringify({ ...base, ...data }) })
24
+ .catch(() => undefined);
25
+ };
26
+ let admission;
27
+ try {
28
+ admission = await gate.acquire({
29
+ stepClass,
30
+ label: step.checkId,
31
+ cost,
32
+ dispatchAttemptId: step.owner?.dispatchAttemptId ?? null,
33
+ priority: step.owner?.priority ?? "foreground",
34
+ }, {
35
+ signal: step.signal,
36
+ onWaiting: async (decision) => await emit("prepublication_host_capacity_waiting", `Pre-publication step '${step.checkId}' (${stepClass}) is waiting for host capacity: ${decision.detail}`, { status: "waiting_for_host_capacity", reason: decision.reason, cpuCores: cost.cpuCores, memoryBytes: cost.memoryBytes }),
37
+ });
38
+ }
39
+ catch (error) {
40
+ if (error instanceof HostCapacityTimeoutError) {
41
+ await emit("prepublication_host_capacity_timeout", error.message, { status: "host_capacity_timeout", host_load_wait_ms: Math.round(error.waitMs) }, "error");
42
+ }
43
+ else if (error instanceof HostCapacityLedgerUnavailableError) {
44
+ await emit("prepublication_host_capacity_ledger_unavailable", error.message, { status: "host_capacity_ledger_unavailable" }, "error");
45
+ }
46
+ throw error;
47
+ }
48
+ const waitMs = Math.round(admission.waitMs);
49
+ await emit("prepublication_host_capacity_admitted", `Pre-publication step '${step.checkId}' (${stepClass}) was admitted after ${waitMs}ms waiting for host capacity.`, { status: "running", reason: admission.decision.reason, host_load_wait_ms: waitMs });
50
+ // Step timers start here, after admission: a step can never time out because it waited.
51
+ const startedAtMs = monotonicNowMs();
52
+ const runSignal = step.signal ? AbortSignal.any([step.signal, admission.fenced]) : admission.fenced;
53
+ const reservationLost = async () => {
54
+ const reason = admission.fenced.reason;
55
+ await emit("prepublication_host_capacity_lost", `Pre-publication step '${step.checkId}' (${stepClass}) was stopped because its host capacity reservation was lost: ${reason instanceof Error ? reason.message : String(reason)}`, { status: "host_capacity_lost" }, "error");
56
+ throw reason;
57
+ };
58
+ let unstopped = null;
59
+ try {
60
+ let result;
61
+ try {
62
+ result = await run(runSignal);
63
+ }
64
+ catch (error) {
65
+ // Part of the step may still run: that, not a fence, is what it failed with.
66
+ // Also a supervised runner's failed proof, which arrives sanitized and wrapped.
67
+ const retention = retentionFor(error);
68
+ if (retention) {
69
+ unstopped = retention;
70
+ throw error;
71
+ }
72
+ if (admission.fenced.aborted)
73
+ return await reservationLost();
74
+ throw error;
75
+ }
76
+ // A result produced after the reservation was lost is not trusted either.
77
+ if (admission.fenced.aborted)
78
+ return await reservationLost();
79
+ return result;
80
+ }
81
+ finally {
82
+ const elapsedMs = Math.round(monotonicNowMs() - startedAtMs);
83
+ // Assigned in the catch above; widened, since control-flow narrowing does not see it here.
84
+ const treeLeft = unstopped;
85
+ const returned = {
86
+ failure: treeLeft ? { kind: "retained", message: treeLeft.reason.message } : null,
87
+ };
88
+ // The token is kept, with its cost, while part of the step's tree may still run.
89
+ await returnHostLoadToken(admission, treeLeft, error => {
90
+ returned.failure = {
91
+ kind: error instanceof HostCapacityTokenFencedError ? "fenced" : "ledger_unavailable",
92
+ message: error instanceof Error ? error.message : String(error),
93
+ };
94
+ });
95
+ const failure = returned.failure;
96
+ await emit("prepublication_host_capacity_released", failure?.kind === "retained"
97
+ ? `Pre-publication step '${step.checkId}' ended, but part of its process tree did not stop; its host capacity stays reserved until it is gone: ${failure.message}`
98
+ : failure?.kind === "fenced"
99
+ ? `Pre-publication step '${step.checkId}' finished, but its host capacity token had been reclaimed: ${failure.message}`
100
+ : failure
101
+ ? `Pre-publication step '${step.checkId}' finished, but its host capacity token could not be returned yet (the governor keeps retrying): ${failure.message}`
102
+ : `Pre-publication step '${step.checkId}' (${stepClass}) ran ${elapsedMs}ms after waiting ${waitMs}ms for host capacity.`, {
103
+ status: "completed",
104
+ host_load_wait_ms: waitMs,
105
+ elapsed_ms: elapsedMs,
106
+ tokenFenced: failure?.kind === "fenced",
107
+ releaseFailed: failure?.kind === "ledger_unavailable",
108
+ tokenRetained: failure?.kind === "retained",
109
+ });
110
+ }
111
+ }
@@ -0,0 +1,60 @@
1
+ import type { ValidationStep } from "./pre-publication-step-execution.js";
2
+ import { ForgeFailureError, type RunnerDispatchEvent } from "./session.types.js";
3
+ /** The check id a failed restart of the attempt's runtime stack before the pass is reported under. */
4
+ export declare const runtimeRestartCheckId = "host-runtime-restart";
5
+ /** One check that failed in a pass: the step that failed and its clipped diagnostics. */
6
+ export interface PrePublicationCheckFailure {
7
+ readonly checkId: string;
8
+ readonly exitCode: number;
9
+ readonly command: string;
10
+ readonly args: readonly string[];
11
+ readonly detail: string;
12
+ }
13
+ /**
14
+ * A failed validation pass. The single-check fields name the first failure, as they always have;
15
+ * `failures` lists every check that failed in the pass, in the order the checks ran.
16
+ */
17
+ export declare class PrePublicationValidationError extends ForgeFailureError {
18
+ readonly checkId: string;
19
+ readonly exitCode: number;
20
+ readonly command: string;
21
+ readonly args: readonly string[];
22
+ readonly detail: string;
23
+ readonly code = "prepublication_validation_failed";
24
+ readonly failures: readonly PrePublicationCheckFailure[];
25
+ constructor(checkId: string, exitCode: number, command: string, args: readonly string[], detail: string, additionalFailures?: readonly PrePublicationCheckFailure[]);
26
+ /** Every failed check's id, first failure first. */
27
+ get checkIds(): readonly string[];
28
+ }
29
+ export declare class PrePublicationPass {
30
+ private readonly runtimeRestartFailure?;
31
+ private readonly failures;
32
+ private dotnetCompileFailed;
33
+ /** A failed runtime restart before the pass is its first failure. */
34
+ constructor(runtimeRestartFailure?: PrePublicationValidationError | undefined);
35
+ record(failure: PrePublicationCheckFailure, failedStep?: ValidationStep): void;
36
+ /** The failed checks that keep this check from running meaningfully in this pass. */
37
+ blockers(checkId: string): readonly string[];
38
+ /**
39
+ * Whether an error ends the pass with the failures it already found. Only a classified retryable
40
+ * failure (a resource hold, lost infrastructure, a supervisor that did not start) does, once the
41
+ * pass has found a failure: the repair turn can fix those failures now, and the next pass meets
42
+ * the condition again. Any other error, or cancellation, still ends the attempt as it did.
43
+ */
44
+ stopsAt(error: unknown, signal?: AbortSignal): error is ForgeFailureError;
45
+ stoppedEvent(checkId: string, error: ForgeFailureError): RunnerDispatchEvent;
46
+ /** Throws every failure the pass found as one validation failure. */
47
+ throwIfFailed(): void;
48
+ }
49
+ export declare function skippedCheckEvent(checkId: string, blockedBy: readonly string[]): RunnerDispatchEvent;
50
+ /** The tests a check's steps skipped, so a check that passed with skips says so with each reason. */
51
+ export declare class SkippedTestTally {
52
+ private readonly worktreePath;
53
+ private readonly environment?;
54
+ private summary;
55
+ constructor(worktreePath: string, environment?: Readonly<Record<string, string>> | undefined);
56
+ /** The invocation's own arguments: a managed attempt may direct results to its test-output root. */
57
+ add(args: readonly string[], stepStartedMs: number): Promise<void>;
58
+ passedEvent(checkId: string, secrets: readonly string[]): RunnerDispatchEvent;
59
+ }
60
+ export declare function validationEvent(eventType: string, checkId: string, content: string, detail?: Readonly<Record<string, unknown>>): RunnerDispatchEvent;
@@ -0,0 +1,145 @@
1
+ import { redactText } from "../shared/redaction/redaction.js";
2
+ import { describeSkippedTests, mergeSkippedTests, readSkippedTests, } from "./pre-publication-skipped-tests.js";
3
+ import { ForgeFailureError, failureFactsFromError } from "./session.types.js";
4
+ // One pre-publication validation pass. A failed check no longer ends the pass: the remaining checks
5
+ // that can still meaningfully run keep going, so one in-place repair turn sees every independent
6
+ // failure at once instead of one per turn. The pass records each failure, says which checks it
7
+ // could not run because a check they depend on failed, and reports them all as one failure.
8
+ /** The check id a failed restart of the attempt's runtime stack before the pass is reported under. */
9
+ export const runtimeRestartCheckId = "host-runtime-restart";
10
+ const dotnetBuildCheckId = "dotnet-build-and-unit";
11
+ // Checks that build the .NET solution themselves and would only repeat the compiler errors once its
12
+ // compile step fails: the OpenAPI export builds Forge.Api and the E2E suite publishes it.
13
+ const dotnetBuildConsumers = new Set(["openapi-and-generated-types", "playwright-e2e"]);
14
+ // Checks that run against the attempt's application stack, which a failed restart left stopped.
15
+ const runtimeStackConsumers = new Set(["playwright-e2e"]);
16
+ // The diagnostics of each further failure that the error message carries; the repair prompt
17
+ // carries every failure's diagnostics in full.
18
+ const additionalFailureMessageDetail = 1500;
19
+ /**
20
+ * A failed validation pass. The single-check fields name the first failure, as they always have;
21
+ * `failures` lists every check that failed in the pass, in the order the checks ran.
22
+ */
23
+ export class PrePublicationValidationError extends ForgeFailureError {
24
+ checkId;
25
+ exitCode;
26
+ command;
27
+ args;
28
+ detail;
29
+ code = "prepublication_validation_failed";
30
+ failures;
31
+ constructor(checkId, exitCode, command, args, detail, additionalFailures = []) {
32
+ super("prepublication_validation_failed", validationFailureMessage([{ checkId, exitCode, command, args, detail }, ...additionalFailures]), "bridge");
33
+ this.checkId = checkId;
34
+ this.exitCode = exitCode;
35
+ this.command = command;
36
+ this.args = args;
37
+ this.detail = detail;
38
+ this.name = "PrePublicationValidationError";
39
+ this.failures = [{ checkId, exitCode, command, args, detail }, ...additionalFailures];
40
+ }
41
+ /** Every failed check's id, first failure first. */
42
+ get checkIds() {
43
+ return this.failures.map(failure => failure.checkId);
44
+ }
45
+ }
46
+ function validationFailureMessage(failures) {
47
+ const [first, ...others] = failures;
48
+ const summary = (failure, detail) => `${failure.checkId} exited ${failure.exitCode}${detail ? `: ${detail}` : ""}`;
49
+ if (others.length === 0)
50
+ return `prepublication_validation_failed: ${summary(first, first.detail)}`;
51
+ // The other check ids come before the first detail, so a clipped failure message still names them.
52
+ const also = `[also failed: ${others.map(failure => failure.checkId).join(", ")}]`;
53
+ const more = others.map(failure => summary(failure, clipDetail(failure.detail)));
54
+ return `prepublication_validation_failed: ${first.checkId} exited ${first.exitCode} ${also}${first.detail ? `: ${first.detail}` : ""}`
55
+ + `\n\nAlso failed in the same validation pass: ${more.join("\n\n")}`;
56
+ }
57
+ function clipDetail(detail) {
58
+ return detail.length <= additionalFailureMessageDetail
59
+ ? detail
60
+ : `${detail.slice(0, additionalFailureMessageDetail)}… (clipped)`;
61
+ }
62
+ export class PrePublicationPass {
63
+ runtimeRestartFailure;
64
+ failures = [];
65
+ dotnetCompileFailed = false;
66
+ /** A failed runtime restart before the pass is its first failure. */
67
+ constructor(runtimeRestartFailure) {
68
+ this.runtimeRestartFailure = runtimeRestartFailure;
69
+ this.failures.push(...runtimeRestartFailure?.failures ?? []);
70
+ }
71
+ record(failure, failedStep) {
72
+ this.failures.push(failure);
73
+ if (failure.checkId === dotnetBuildCheckId && failedStep?.command === "dotnet" && failedStep.args[0] === "build") {
74
+ this.dotnetCompileFailed = true;
75
+ }
76
+ }
77
+ /** The failed checks that keep this check from running meaningfully in this pass. */
78
+ blockers(checkId) {
79
+ return [
80
+ ...(this.dotnetCompileFailed && dotnetBuildConsumers.has(checkId) ? [dotnetBuildCheckId] : []),
81
+ ...(this.runtimeRestartFailure && runtimeStackConsumers.has(checkId) ? [runtimeRestartCheckId] : []),
82
+ ];
83
+ }
84
+ /**
85
+ * Whether an error ends the pass with the failures it already found. Only a classified retryable
86
+ * failure (a resource hold, lost infrastructure, a supervisor that did not start) does, once the
87
+ * pass has found a failure: the repair turn can fix those failures now, and the next pass meets
88
+ * the condition again. Any other error, or cancellation, still ends the attempt as it did.
89
+ */
90
+ stopsAt(error, signal) {
91
+ if (this.failures.length === 0 || signal?.aborted || !(error instanceof ForgeFailureError))
92
+ return false;
93
+ return failureFactsFromError(error).retryability === "retryable";
94
+ }
95
+ stoppedEvent(checkId, error) {
96
+ const failedCheckIds = this.failures.map(failure => failure.checkId);
97
+ return validationEvent("prepublication_validation_pass_stopped", checkId, `Stopped this pre-publication pass at '${checkId}' (${error.failureCode}). Reporting the ${failedCheckIds.length} failed check${failedCheckIds.length === 1 ? "" : "s"} it already found (${failedCheckIds.join(", ")}) for repair; the next pass runs '${checkId}' again.`, { failureCode: error.failureCode, failedCheckIds });
98
+ }
99
+ /** Throws every failure the pass found as one validation failure. */
100
+ throwIfFailed() {
101
+ const [first, ...others] = this.failures;
102
+ if (!first)
103
+ return;
104
+ throw new PrePublicationValidationError(first.checkId, first.exitCode, first.command, first.args, first.detail, others);
105
+ }
106
+ }
107
+ export function skippedCheckEvent(checkId, blockedBy) {
108
+ const reason = blockedBy.map(blocker => blocker === runtimeRestartCheckId
109
+ ? "the attempt's runtime stack, whose restart failed"
110
+ : `the .NET build, which failed in '${blocker}'`).join(" and ");
111
+ return validationEvent("prepublication_validation_skipped", checkId, `Skipped pre-publication CI parity check '${checkId}' in this pass: it needs ${reason}. The next pass runs it again.`, { blockedBy });
112
+ }
113
+ /** The tests a check's steps skipped, so a check that passed with skips says so with each reason. */
114
+ export class SkippedTestTally {
115
+ worktreePath;
116
+ environment;
117
+ summary = { count: 0, reasons: [] };
118
+ constructor(worktreePath, environment) {
119
+ this.worktreePath = worktreePath;
120
+ this.environment = environment;
121
+ }
122
+ /** The invocation's own arguments: a managed attempt may direct results to its test-output root. */
123
+ async add(args, stepStartedMs) {
124
+ this.summary = mergeSkippedTests(this.summary, await readSkippedTests(this.worktreePath, args, stepStartedMs, this.environment));
125
+ }
126
+ passedEvent(checkId, secrets) {
127
+ const skipped = {
128
+ ...this.summary,
129
+ reasons: this.summary.reasons.map(entry => ({ ...entry, reason: redactText(entry.reason, secrets) })),
130
+ };
131
+ if (skipped.count === 0) {
132
+ return validationEvent("prepublication_validation_passed", checkId, `Pre-publication CI parity check '${checkId}' passed.`);
133
+ }
134
+ return validationEvent("prepublication_validation_passed", checkId, `Pre-publication CI parity check '${checkId}' passed with ${describeSkippedTests(skipped)}.`, { skippedTests: skipped.count, skippedReasons: skipped.reasons });
135
+ }
136
+ }
137
+ export function validationEvent(eventType, checkId, content, detail) {
138
+ return {
139
+ role: "runner",
140
+ kind: "checkpoint",
141
+ content,
142
+ eventType,
143
+ data: JSON.stringify({ checkId, contractId: "forge-ci-parity-v1", ...detail }),
144
+ };
145
+ }
@@ -0,0 +1,23 @@
1
+ import type { PrePublicationCommandResult, PrePublicationCommandRunner } from "./pre-publication-validation.js";
2
+ /** Output kept per stream for one validation step (the tail). */
3
+ export declare const prePublicationOutputLimitChars: number;
4
+ export declare class ProcessPrePublicationCommandRunner implements PrePublicationCommandRunner {
5
+ run(command: string, args: readonly string[], cwd: string, signal?: AbortSignal, environment?: Readonly<Record<string, string>>): Promise<PrePublicationCommandResult>;
6
+ }
7
+ export declare function prePublicationChildEnvironment(environment?: Readonly<Record<string, string>>): NodeJS.ProcessEnv;
8
+ interface PackageManagerLaunchLocation {
9
+ readonly args: readonly string[];
10
+ readonly cwd: string;
11
+ }
12
+ /**
13
+ * Corepack picks the pnpm version from the nearest package.json `packageManager`
14
+ * pin at or above the process working directory; pnpm's own `--dir` is not
15
+ * consulted. The repository root carries no pin, so `pnpm --dir client ...`
16
+ * launched from the root would run Corepack's host-global default, and pnpm
17
+ * then refuses client's pin (ERR_PNPM_BAD_PM_VERSION). `pnpm --dir X cmd` is
18
+ * `pnpm cmd` run from X, so launch from X and let Corepack walk up from there
19
+ * to the nearest pin. Targets that are absolute, leave the worktree, or do not
20
+ * exist stay unchanged so pnpm reports them itself.
21
+ */
22
+ export declare function pnpmDirectoryLaunch(command: string, args: readonly string[], cwd: string): Promise<PackageManagerLaunchLocation>;
23
+ export {};