@loucompanion/forge-bridge 0.2.1-dev.4f11ffc822f9 → 0.2.1-dev.7171bf414613

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 (152) hide show
  1. package/README.md +41 -3
  2. package/dist/bridge/bridge-state-io.d.ts +6 -2
  3. package/dist/bridge/bridge-state-io.js +22 -4
  4. package/dist/bridge/bridge.service.d.ts +10 -0
  5. package/dist/bridge/bridge.service.js +63 -101
  6. package/dist/bridge/bridge.types.d.ts +16 -0
  7. package/dist/bridge/bridge.types.js +2 -1
  8. package/dist/bridge/default-session-service.d.ts +13 -0
  9. package/dist/bridge/default-session-service.js +22 -0
  10. package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
  11. package/dist/bridge/dispatch-offer-policy.js +58 -0
  12. package/dist/bridge/runner-host-capabilities.js +14 -1
  13. package/dist/bridge/windows-bash-resolution.d.ts +31 -0
  14. package/dist/bridge/windows-bash-resolution.js +153 -0
  15. package/dist/cleanup/cleanup-wip.js +3 -3
  16. package/dist/cleanup/forge-owned-paths.d.ts +2 -0
  17. package/dist/cleanup/forge-owned-paths.js +9 -0
  18. package/dist/cli/cli.help.js +1 -1
  19. package/dist/cli/cli.service.js +11 -43
  20. package/dist/cli/local-config.d.ts +12 -1
  21. package/dist/cli/local-config.js +35 -1
  22. package/dist/cli/provider-cli-advertising.d.ts +24 -0
  23. package/dist/cli/provider-cli-advertising.js +88 -0
  24. package/dist/runtime/host-load-admission.d.ts +5 -0
  25. package/dist/runtime/host-load-capacity.d.ts +198 -0
  26. package/dist/runtime/host-load-capacity.js +353 -0
  27. package/dist/runtime/host-load-child-environment.d.ts +13 -0
  28. package/dist/runtime/host-load-child-environment.js +35 -1
  29. package/dist/runtime/host-load-governor-config.d.ts +33 -3
  30. package/dist/runtime/host-load-governor-config.js +24 -3
  31. package/dist/runtime/host-load-governor.d.ts +89 -2
  32. package/dist/runtime/host-load-governor.js +217 -18
  33. package/dist/runtime/host-load-live-test-slots.d.ts +61 -0
  34. package/dist/runtime/host-load-live-test-slots.js +193 -0
  35. package/dist/runtime/host-load-sampler.d.ts +17 -0
  36. package/dist/runtime/host-load-sampler.js +24 -0
  37. package/dist/runtime/host-load-step-run.d.ts +37 -3
  38. package/dist/runtime/host-load-step-run.js +63 -7
  39. package/dist/runtime/host-load-test-slot.d.ts +3 -0
  40. package/dist/runtime/host-load-test-slot.js +26 -7
  41. package/dist/runtime/host-runtime-contract.js +6 -4
  42. package/dist/runtime/prepared-runtime-readiness.d.ts +12 -2
  43. package/dist/runtime/prepared-runtime-readiness.js +35 -11
  44. package/dist/sandbox/runtime.d.ts +1 -2
  45. package/dist/sandbox/runtime.js +8 -14
  46. package/dist/sandbox/sandbox-input.d.ts +22 -0
  47. package/dist/sandbox/sandbox-input.js +49 -0
  48. package/dist/sandbox/workspace.service.js +15 -2
  49. package/dist/session/managed-attempt-tools.js +6 -29
  50. package/dist/session/managed-build-receipt.d.ts +3 -1
  51. package/dist/session/managed-build-receipt.js +5 -2
  52. package/dist/session/managed-command-environment.d.ts +8 -0
  53. package/dist/session/managed-command-environment.js +28 -0
  54. package/dist/session/managed-command-host-load.d.ts +10 -5
  55. package/dist/session/managed-command-host-load.js +18 -14
  56. package/dist/session/phase-completion.artifact-bundle.d.ts +20 -0
  57. package/dist/session/phase-completion.artifact-bundle.js +167 -0
  58. package/dist/session/phase-completion.artifacts.d.ts +2 -17
  59. package/dist/session/phase-completion.artifacts.js +63 -165
  60. package/dist/session/phase-completion.d.ts +25 -2
  61. package/dist/session/phase-completion.helpers.js +5 -53
  62. package/dist/session/phase-completion.js +15 -32
  63. package/dist/session/phase-completion.mcp-args.js +69 -2
  64. package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
  65. package/dist/session/phase-completion.phase-aliases.js +43 -0
  66. package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
  67. package/dist/session/phase-completion.pr-review-schema.js +75 -0
  68. package/dist/session/phase-completion.pr-review-threads.d.ts +34 -0
  69. package/dist/session/phase-completion.pr-review-threads.js +90 -0
  70. package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
  71. package/dist/session/phase-completion.pr-review-validation.js +215 -0
  72. package/dist/session/phase-completion.pr-review.d.ts +36 -0
  73. package/dist/session/phase-completion.pr-review.js +294 -0
  74. package/dist/session/phase-completion.prompts.d.ts +1 -1
  75. package/dist/session/phase-completion.prompts.js +14 -0
  76. package/dist/session/phase-completion.runtime.js +9 -3
  77. package/dist/session/phase-completion.schemas.js +12 -2
  78. package/dist/session/phase-completion.validation.d.ts +1 -0
  79. package/dist/session/phase-completion.validation.js +9 -1
  80. package/dist/session/pr-review-diff-base.d.ts +18 -0
  81. package/dist/session/pr-review-diff-base.js +45 -0
  82. package/dist/session/pr-review-placement.d.ts +50 -0
  83. package/dist/session/pr-review-placement.js +91 -0
  84. package/dist/session/pre-publication-change-set.d.ts +62 -0
  85. package/dist/session/pre-publication-change-set.js +166 -0
  86. package/dist/session/pre-publication-host-load.js +6 -5
  87. package/dist/session/pre-publication-process.js +3 -2
  88. package/dist/session/pre-publication-validation.d.ts +2 -1
  89. package/dist/session/pre-publication-validation.js +31 -36
  90. package/dist/session/provider-cli/dispatch-target-branch.d.ts +7 -0
  91. package/dist/session/provider-cli/dispatch-target-branch.js +8 -0
  92. package/dist/session/provider-cli/pr-review-credential-isolation.d.ts +83 -0
  93. package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
  94. package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
  95. package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
  96. package/dist/session/provider-cli/pr-review-prompt.d.ts +11 -0
  97. package/dist/session/provider-cli/pr-review-prompt.js +132 -0
  98. package/dist/session/provider-cli/pre-publication-repair.js +8 -3
  99. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  100. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +1 -0
  101. package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
  102. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
  103. package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
  104. package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
  105. package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
  106. package/dist/session/provider-cli/provider-cli.prompts.d.ts +10 -3
  107. package/dist/session/provider-cli/provider-cli.prompts.js +123 -70
  108. package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
  109. package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
  110. package/dist/session/provider-cli/provider-cli.runtime.d.ts +7 -0
  111. package/dist/session/provider-cli/provider-cli.runtime.js +14 -0
  112. package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
  113. package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
  114. package/dist/session/provider-cli/provider-cli.service.d.ts +11 -17
  115. package/dist/session/provider-cli/provider-cli.service.js +33 -148
  116. package/dist/session/provider-cli/provider-cli.types.d.ts +7 -2
  117. package/dist/session/sandbox-host-capacity-gate.js +29 -7
  118. package/dist/session/session-host-project.d.ts +22 -0
  119. package/dist/session/session-host-project.js +98 -0
  120. package/dist/session/session.parse-helpers.d.ts +10 -0
  121. package/dist/session/session.parse-helpers.js +84 -0
  122. package/dist/session/session.runtime-refresh.d.ts +46 -0
  123. package/dist/session/session.runtime-refresh.js +116 -0
  124. package/dist/session/session.service.d.ts +2 -1
  125. package/dist/session/session.service.js +57 -158
  126. package/dist/session/session.types.d.ts +5 -0
  127. package/dist/session/session.types.js +8 -78
  128. package/dist/session/session.types.pr-review.d.ts +59 -0
  129. package/dist/session/session.types.pr-review.js +53 -0
  130. package/dist/shared/provider-capabilities.d.ts +2 -0
  131. package/dist/shared/provider-capabilities.js +9 -0
  132. package/dist/version.d.ts +1 -1
  133. package/dist/version.js +1 -1
  134. package/dist/worktree/artifact-injector.js +24 -0
  135. package/dist/worktree/wip-git.d.ts +25 -0
  136. package/dist/worktree/wip-git.js +64 -4
  137. package/dist/worktree/wip-refs.d.ts +23 -0
  138. package/dist/worktree/wip-refs.js +52 -2
  139. package/dist/worktree/wip-restore.d.ts +13 -0
  140. package/dist/worktree/wip-restore.js +159 -25
  141. package/dist/worktree/wip-snapshot.d.ts +5 -2
  142. package/dist/worktree/wip-snapshot.js +15 -13
  143. package/dist/worktree/worktree-origin-sync.d.ts +1 -0
  144. package/dist/worktree/worktree-origin-sync.js +1 -0
  145. package/dist/worktree/worktree-wip-events.d.ts +2 -0
  146. package/dist/worktree/worktree-wip-events.js +53 -3
  147. package/dist/worktree/worktree-wip.d.ts +7 -0
  148. package/dist/worktree/worktree-wip.js +17 -2
  149. package/dist/worktree/worktree.service.d.ts +23 -1
  150. package/dist/worktree/worktree.service.js +122 -15
  151. package/dist/worktree/worktree.types.d.ts +16 -0
  152. package/package.json +1 -1
@@ -0,0 +1,294 @@
1
+ import path from "node:path";
2
+ import { NodeProcessRunner } from "../shared/process/process.js";
3
+ import { normalizedString, optionalString, sha256, stableStringify } from "./phase-completion.helpers.js";
4
+ import { validatePrReviewPayloadShape } from "./phase-completion.pr-review-validation.js";
5
+ const maxListedRanges = 8;
6
+ const maxListedFiles = 20;
7
+ /**
8
+ * Parses `git diff --unified=3` output into the new-side line ranges of every hunk.
9
+ * Added and context lines both count: GitHub lets a review comment land on either.
10
+ * Hunk header counts drive the walk, so a content line that starts with `+++` is not mistaken for a file header.
11
+ */
12
+ export function parseNewSideDiffLines(diff) {
13
+ const files = new Map();
14
+ const lines = diff.split("\n");
15
+ let currentFile = null;
16
+ let index = 0;
17
+ while (index < lines.length) {
18
+ const line = lines[index];
19
+ if (line.startsWith("diff --git ")) {
20
+ currentFile = null;
21
+ index += 1;
22
+ continue;
23
+ }
24
+ if (line.startsWith("+++ ")) {
25
+ const target = line.slice(4).replace(/\t.*$/u, "").replace(/\r$/u, "");
26
+ currentFile = target === "/dev/null" ? null : target.replace(/^b\//u, "");
27
+ index += 1;
28
+ continue;
29
+ }
30
+ const header = /^@@ -\d+(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/u.exec(line);
31
+ if (!header || currentFile === null) {
32
+ index += 1;
33
+ continue;
34
+ }
35
+ let oldRemaining = header[1] === undefined ? 1 : Number(header[1]);
36
+ let newRemaining = header[3] === undefined ? 1 : Number(header[3]);
37
+ let newLine = Number(header[2]);
38
+ const hunkStart = newLine;
39
+ index += 1;
40
+ while (index < lines.length && (oldRemaining > 0 || newRemaining > 0)) {
41
+ const body = lines[index];
42
+ const marker = body[0];
43
+ if (marker === "\\") {
44
+ index += 1;
45
+ continue;
46
+ }
47
+ if (marker === "+") {
48
+ newRemaining -= 1;
49
+ newLine += 1;
50
+ }
51
+ else if (marker === "-") {
52
+ oldRemaining -= 1;
53
+ }
54
+ else {
55
+ // A context line, or a blank one whose leading space was stripped.
56
+ oldRemaining -= 1;
57
+ newRemaining -= 1;
58
+ newLine += 1;
59
+ }
60
+ index += 1;
61
+ }
62
+ if (newLine > hunkStart) {
63
+ const ranges = files.get(currentFile) ?? [];
64
+ ranges.push({ start: hunkStart, end: newLine - 1 });
65
+ files.set(currentFile, ranges);
66
+ }
67
+ }
68
+ return files;
69
+ }
70
+ export function isLineInRanges(ranges, line) {
71
+ return Boolean(ranges?.some((range) => line >= range.start && line <= range.end));
72
+ }
73
+ /** Messages for every finding whose anchor GitHub would reject, each with how to re-anchor. */
74
+ export function offDiffAnchorProblems(findings, diffLines, range) {
75
+ const problems = [];
76
+ for (const [index, finding] of findings.entries()) {
77
+ const findingPath = normalizeFindingPath(optionalString(finding, "path") ?? "");
78
+ const line = finding.line;
79
+ const startLine = typeof finding.start_line === "number" ? finding.start_line : null;
80
+ const ranges = diffLines.get(findingPath);
81
+ const label = `findings[${index}] (${findingPath}:${line})`;
82
+ if (!ranges || ranges.length === 0) {
83
+ const changed = [...diffLines.keys()];
84
+ const listed = changed.slice(0, maxListedFiles).join(", ");
85
+ problems.push(`${label}: ${findingPath} has no changed lines in ${range}. Re-anchor at the changed line that introduces the problem, and name the unchanged location in the body as path:line. Files in the diff: ${listed || "none"}${changed.length > maxListedFiles ? `, and ${changed.length - maxListedFiles} more` : ""}.`);
86
+ continue;
87
+ }
88
+ const containing = ranges.find((candidate) => line >= candidate.start && line <= candidate.end);
89
+ if (!containing) {
90
+ problems.push(`${label}: line ${line} is not on the new side of the diff. Re-anchor at a changed line (side RIGHT); ${describeRanges(findingPath, ranges)}`);
91
+ continue;
92
+ }
93
+ if (startLine !== null && (startLine < containing.start || startLine > containing.end)) {
94
+ problems.push(`${label}: start_line ${startLine} is outside the hunk that contains line ${line} (${containing.start}-${containing.end}). A multi-line comment must stay inside one hunk; move start_line into ${containing.start}-${containing.end} or set it to null.`);
95
+ }
96
+ }
97
+ return problems;
98
+ }
99
+ function describeRanges(filePath, ranges) {
100
+ const listed = ranges.slice(0, maxListedRanges).map((range) => range.start === range.end ? `${range.start}` : `${range.start}-${range.end}`);
101
+ return `lines you can anchor to in ${filePath}: ${listed.join(", ")}${ranges.length > maxListedRanges ? `, and ${ranges.length - maxListedRanges} more ranges` : ""}.`;
102
+ }
103
+ export function normalizeFindingPath(value) {
104
+ return value.trim().replaceAll("\\", "/").replace(/^\.\//u, "");
105
+ }
106
+ /**
107
+ * Checks what a `reviewed` payload claims against the worktree: the review must be bound to the
108
+ * commit that is checked out (and to the dispatched head when Forge supplied one), `base_sha`
109
+ * must be a real commit, and every inline comment must land on a line of the PR diff.
110
+ * Throws an error that tells the agent how to repair the payload.
111
+ */
112
+ export async function assertPrReviewMatchesRepository(worktreePath, payload, context, processRunner = new NodeProcessRunner()) {
113
+ const git = gitRunner(worktreePath, processRunner);
114
+ const headSha = (optionalString(payload, "head_sha") ?? "").trim().toLowerCase();
115
+ const baseSha = (optionalString(payload, "base_sha") ?? "").trim().toLowerCase();
116
+ const worktreeHead = await git(["rev-parse", "--verify", "--quiet", "HEAD^{commit}"]);
117
+ const checkedOut = worktreeHead.ok ? worktreeHead.out.trim().toLowerCase() : null;
118
+ assertHeadBinding(headSha, checkedOut, context);
119
+ if (checkedOut === null) {
120
+ // Nothing to diff against without a checkout; the dispatched-head comparison above is all that can be proven.
121
+ return;
122
+ }
123
+ const resolvedBase = await resolveReviewBase(git, baseSha, context);
124
+ const findings = (payload.findings ?? []);
125
+ if (findings.length === 0)
126
+ return;
127
+ await assertFindingsOnDiff(git, findings, resolvedBase, checkedOut);
128
+ }
129
+ function gitRunner(worktreePath, processRunner) {
130
+ return async (args) => {
131
+ try {
132
+ const result = await processRunner.run({ command: "git", args: ["-c", "core.quotepath=off", ...args], cwd: path.resolve(worktreePath), rawOutput: true });
133
+ return { ok: result.exitCode === 0, out: result.stdout, error: result.stderr.trim() };
134
+ }
135
+ catch (error) {
136
+ return { ok: false, out: "", error: error instanceof Error ? error.message : String(error) };
137
+ }
138
+ };
139
+ }
140
+ function assertHeadBinding(headSha, checkedOut, context) {
141
+ if (checkedOut === null && !context?.headSha) {
142
+ throw new Error("Forge could not read HEAD in the review worktree, so it cannot confirm which commit you reviewed. Complete with status \"blocked\" and a reason if the repository is unreadable.");
143
+ }
144
+ if (checkedOut === null) {
145
+ return;
146
+ }
147
+ if (!sameCommit(headSha, checkedOut)) {
148
+ throw new Error(`head_sha ${headSha} is not the commit checked out in the review worktree (${checkedOut}). A review is bound to the head you read: set head_sha to the output of \`git rev-parse HEAD\` after reviewing that commit. If the worktree is not at the dispatched head, complete with status "stale_head" and head_sha set to ${checkedOut} instead of reviewing it.`);
149
+ }
150
+ if (context?.headSha && !sameCommit(context.headSha.trim().toLowerCase(), checkedOut)) {
151
+ throw new Error(`The review worktree is at ${checkedOut}, not the dispatched head ${context.headSha}. Complete with status "stale_head" and head_sha ${checkedOut}; a review of the wrong commit is worse than none.`);
152
+ }
153
+ }
154
+ async function resolveReviewBase(git, baseSha, context) {
155
+ const base = await git(["rev-parse", "--verify", "--quiet", `${baseSha}^{commit}`]);
156
+ if (!base.ok) {
157
+ throw new Error(`base_sha ${baseSha} is not a commit in the review worktree${base.error ? ` (${base.error})` : ""}. Use the dispatch's base_sha exactly, or complete with status "blocked" and a reason if the base commit is missing from the worktree.`);
158
+ }
159
+ const resolvedBase = base.out.trim().toLowerCase();
160
+ if (context?.baseSha && !sameCommit(context.baseSha.trim().toLowerCase(), resolvedBase)) {
161
+ throw new Error(`base_sha ${baseSha} is not the dispatched base ${context.baseSha}. Diff and review against the dispatched base.`);
162
+ }
163
+ return resolvedBase;
164
+ }
165
+ async function assertFindingsOnDiff(git, findings, resolvedBase, checkedOut) {
166
+ const diff = await git(["diff", "--no-color", "--no-ext-diff", "--no-renames", "--unified=3", "--src-prefix=a/", "--dst-prefix=b/", `${resolvedBase}...${checkedOut}`]);
167
+ if (!diff.ok) {
168
+ throw new Error(`Forge could not read the diff ${resolvedBase}...${checkedOut} to check your inline comments${diff.error ? ` (${diff.error})` : ""}. Complete with status "blocked" and a reason if the diff cannot be read.`);
169
+ }
170
+ const problems = offDiffAnchorProblems(findings, parseNewSideDiffLines(diff.out), `${resolvedBase.slice(0, 12)}...${checkedOut.slice(0, 12)}`);
171
+ if (problems.length > 0) {
172
+ throw new Error(`Inline comments must land on a line of the pull request diff, on the new side (side RIGHT), or GitHub rejects them. Re-anchor these and call forge.complete_pr_review again:\n- ${problems.join("\n- ")}`);
173
+ }
174
+ }
175
+ function sameCommit(claimed, actual) {
176
+ return claimed === actual;
177
+ }
178
+ const recordedPrReviewStatuses = new Set(["reviewed", "stale_head", "blocked"]);
179
+ /**
180
+ * Re-checks the recorded pr-review.result.json as if it had just been submitted. The completion tool
181
+ * validates what it writes, but the session can also write that file itself (the post-run worktree
182
+ * check skips Forge's artifact directory), so the file Forge hands on must pass the same shape,
183
+ * head, base and diff-anchor rules, name this work item and phase, and carry the content hash the tool
184
+ * computes. Returns the reason it is rejected, or null.
185
+ */
186
+ export async function recordedPrReviewArtifactProblem(worktreePath, workItemId, verdictJson, context, processRunner = new NodeProcessRunner()) {
187
+ let payload;
188
+ try {
189
+ const parsed = JSON.parse(verdictJson);
190
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
191
+ return "the recorded review is not a JSON object";
192
+ payload = parsed;
193
+ }
194
+ catch {
195
+ return "the recorded review is not valid JSON";
196
+ }
197
+ const status = optionalString(payload, "status")?.trim() ?? "";
198
+ if (!recordedPrReviewStatuses.has(status))
199
+ return `the recorded review has status '${status}', not reviewed, stale_head or blocked`;
200
+ if (optionalString(payload, "phase") !== "pr_review")
201
+ return "the recorded review is not a pr_review artifact";
202
+ if (optionalString(payload, "work_item_id") !== workItemId)
203
+ return `the recorded review names work item '${optionalString(payload, "work_item_id") ?? ""}', not ${workItemId}`;
204
+ const { content_hash: contentHash, ...withoutHash } = payload;
205
+ if (typeof contentHash !== "string" || contentHash !== sha256(stableStringify(withoutHash))) {
206
+ return "the recorded review's content_hash does not match its content, so forge.complete_pr_review did not write it";
207
+ }
208
+ try {
209
+ validatePrReviewPayloadShape(payload, status, context);
210
+ if (status === "reviewed") {
211
+ await assertPrReviewMatchesRepository(worktreePath, payload, context, processRunner);
212
+ }
213
+ }
214
+ catch (error) {
215
+ return error instanceof Error ? error.message : String(error);
216
+ }
217
+ return null;
218
+ }
219
+ /** Renders the pr-review.report.md that sits next to pr-review.result.json. */
220
+ export function prReviewReportMarkdown(artifact, contentHash) {
221
+ const status = normalizedString(optionalString(artifact, "status"));
222
+ const lines = ["# Forge PR review", ""];
223
+ lines.push(`Status: ${status}`);
224
+ const head = optionalString(artifact, "head_sha");
225
+ if (head)
226
+ lines.push(`Head: ${head}`);
227
+ const base = optionalString(artifact, "base_sha");
228
+ if (base)
229
+ lines.push(`Base: ${base}`);
230
+ lines.push(`Produced by: ${optionalString(artifact, "produced_by") ?? "forge-completion-tool"}`);
231
+ lines.push(`Content hash: ${contentHash}`, "");
232
+ if (status !== "reviewed") {
233
+ const reason = optionalString(artifact, "reason") ?? optionalString(artifact, "summary") ?? optionalString(artifact, "verdict_reason");
234
+ lines.push(status === "stale_head" ? "## Stale head" : "## Blocked", "", reason ?? "No reason recorded.", "");
235
+ return `${lines.join("\n")}\n`;
236
+ }
237
+ appendReviewedOverview(lines, artifact);
238
+ appendFindingsSection(lines, recordList(artifact.findings));
239
+ appendPriorThreadsSection(lines, recordList(artifact.prior_threads));
240
+ appendSecuritySection(lines, (artifact.security_review ?? {}));
241
+ const skipped = recordList(artifact.skipped_files);
242
+ if (skipped.length > 0) {
243
+ lines.push("## Skipped files", "");
244
+ lines.push(...skipped.map((file) => `- ${optionalString(file, "path")}: ${optionalString(file, "reason")}`), "");
245
+ }
246
+ return `${lines.join("\n").replace(/\n{3,}/gu, "\n\n")}\n`;
247
+ }
248
+ function appendReviewedOverview(lines, artifact) {
249
+ lines.push(`Verdict: ${optionalString(artifact, "verdict") ?? "unknown"}${optionalString(artifact, "review_effort") ? ` (${optionalString(artifact, "review_effort")} review)` : ""}`, "");
250
+ lines.push(optionalString(artifact, "verdict_reason") ?? "", "");
251
+ lines.push("## Overview", "", optionalString(artifact, "summary") ?? "", "");
252
+ const changes = stringList(artifact.changes);
253
+ if (changes.length > 0)
254
+ lines.push(...changes.map((change) => `- ${change}`), "");
255
+ const files = recordList(artifact.files);
256
+ if (files.length > 0) {
257
+ lines.push("| File | Description |", "| --- | --- |");
258
+ lines.push(...files.map((file) => `| ${tableCell(optionalString(file, "path"))} | ${tableCell(optionalString(file, "description"))} |`), "");
259
+ }
260
+ }
261
+ function appendFindingsSection(lines, findings) {
262
+ lines.push(`## Findings (${findings.length})`, "");
263
+ if (findings.length === 0)
264
+ lines.push("No new findings.", "");
265
+ for (const finding of findings) {
266
+ lines.push(`### ${optionalString(finding, "title") ?? "Finding"}`, "");
267
+ lines.push(`${String(finding.severity)} ${String(finding.category)} at \`${optionalString(finding, "path")}:${String(finding.line)}\``, "");
268
+ lines.push(optionalString(finding, "body") ?? "", "");
269
+ }
270
+ }
271
+ function appendPriorThreadsSection(lines, threads) {
272
+ if (threads.length === 0)
273
+ return;
274
+ lines.push("## Prior threads", "");
275
+ lines.push(...threads.map((thread) => `- ${optionalString(thread, "thread_id")}: ${optionalString(thread, "status")}`), "");
276
+ }
277
+ function appendSecuritySection(lines, security) {
278
+ lines.push("## Security review", "", `Status: ${optionalString(security, "status") ?? "unknown"}`, "");
279
+ const checked = stringList(security.checked);
280
+ if (checked.length > 0)
281
+ lines.push(`Checked: ${checked.join(", ")}`, "");
282
+ lines.push(optionalString(security, "notes") ?? "", "");
283
+ }
284
+ function stringList(value) {
285
+ return Array.isArray(value) ? value.filter((entry) => typeof entry === "string" && entry.trim().length > 0) : [];
286
+ }
287
+ function recordList(value) {
288
+ return Array.isArray(value)
289
+ ? value.filter((entry) => Boolean(entry) && typeof entry === "object" && !Array.isArray(entry))
290
+ : [];
291
+ }
292
+ function tableCell(value) {
293
+ return (value ?? "").replace(/\|/gu, "\\|").replace(/\r?\n/gu, " ");
294
+ }
@@ -7,7 +7,7 @@ export declare function completionPromptForDecomposeCycle(currentGate?: Decompos
7
7
  export declare function completionPromptForDebugCycle(currentGate?: DebugCompletionPhase): string;
8
8
  export declare function nextPhaseAfter(phase: CompletionPhase): DevelopCompletionPhase | null;
9
9
  export declare function nextDebugPhaseAfter(phase: DebugCompletionPhase): DebugCompletionPhase | null;
10
- export declare function completionToolNextInstruction(completedPhase: CompletionPhase, status: string, nextPhase: CompletionPhase | "dev_test_ready" | "qa_ready" | "sign_off_ready" | "provider_checks_ready"): string;
10
+ export declare function completionToolNextInstruction(completedPhase: CompletionPhase, status: string, nextPhase: CompletionPhase | "dev_test_ready" | "qa_ready" | "sign_off_ready" | "provider_checks_ready" | "pr_review_complete"): string;
11
11
  export declare function completionToolNextInstructionForDraftGate(completedGate: DraftCompletionGate, status: string, nextGate: DraftCompletionGate | null): string;
12
12
  export declare function completionToolNextInstructionForQaGate(completedGate: QaCompletionGate, status: string, nextGate: QaCompletionGate | null): string;
13
13
  export declare function completionToolNextInstructionForDecomposeGate(completedGate: DecomposeCompletionGate, status: string, nextGate: DecomposeCompletionGate | null): string;
@@ -23,6 +23,13 @@ When a task's implementation or validation starts containers or otherwise needs
23
23
  Dependency entries use canonical \`before\` and \`after\` task ids, for example \`{ "before": "task-1", "after": "task-2" }\`. Forge accepts \`from\`/\`to\` only as aliases and normalizes them before writing artifacts.
24
24
  Use \`status: "pass"\` for a valid pending-approval plan, \`needs_revision\` when story/design input must change, or \`blocked\` with a concrete blocker.
25
25
  Forge will mirror only the tool-written Architect artifacts; reporting the plan in prose is not enough.`;
26
+ }
27
+ if (phase === "pr_review") {
28
+ return `Forge completion tools are available through the MCP server named \`${toolServerName}\`.
29
+ Review only: do not edit, commit, push, or post to GitHub, and do not write the review artifact by hand. When the review is complete, call \`${toolName}(...)\`${alias ? ` (or \`${alias}\` if your client shows unqualified MCP tool names)` : ""} with the review payload from the pr-review skill, bound to the head you reviewed.
30
+ That tool writes \`${artifactRoot}/${artifactName}\` and \`${phaseFiles[phase].reportFileName}\`. Forge posts the review afterwards; the tool itself publishes nothing.
31
+ Use \`status: "reviewed"\` for a completed review, \`status: "stale_head"\` (with head_sha set to the commit you found) when HEAD differs from the dispatched head, and \`status: "blocked"\` with a reason when the diff cannot be read.
32
+ If the tool rejects the payload, it names the fields to correct: a head_sha that is not the checked-out head, a side other than RIGHT, a line that is not in the diff (re-anchor at a changed line), a verdict that contradicts the open issues, or an unknown prior thread id. Fix them and call again. Ending your turn without an accepted call records no review.`;
26
33
  }
27
34
  if (phase === "ci_repair") {
28
35
  return `Forge completion tools are available through the MCP server named \`${toolServerName}\`.
@@ -127,6 +134,13 @@ export function completionToolNextInstruction(completedPhase, status, nextPhase)
127
134
  ? "CI repair handoff accepted. Forge Bridge may now commit, push, and return the PR to provider checks."
128
135
  : "Stay in CI repair, address the exact missing evidence returned by this gate, then call forge.complete_ci_repair again.";
129
136
  }
137
+ if (completedPhase === "pr_review") {
138
+ return status === "stale_head"
139
+ ? "Stale head recorded. Forge will re-dispatch the review at the current head. Do not post anything to GitHub; end your turn with a one-line summary."
140
+ : status === "blocked"
141
+ ? "Blocked review recorded. Do not post anything to GitHub; end your turn with a one-line summary naming the blocker."
142
+ : "Review recorded. Forge will post it as one comment-only review on the reviewed head; do not post anything to GitHub yourself. End your turn with a concise summary of the verdict, the number of findings, and the completion status.";
143
+ }
130
144
  if (status !== "pass") {
131
145
  return `Stay in ${completedPhase}, address the recorded blockers, then call ${expectedCompletionToolName(completedPhase)} again.`;
132
146
  }
@@ -1,7 +1,7 @@
1
1
  import fs from "node:fs/promises";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
- import { completionPhaseFromDispatch, completionPhaseOrder, completionRedactionSecretsEnv, completionToolNamesForDebugGate, completionToolNamesForDecomposeGate, completionToolNamesForDraftGate, completionToolNamesForPhase, completionToolNamesForQaGate, debugCompletionPhaseOrder, decomposeCompletionGateOrder, draftCompletionGateOrder, qaCompletionGateOrder, toolServerName, usesArchitectCycleCompletion, usesDebugCycleCompletion, usesDevelopCycleCompletion, usesQaCycleCompletion } from "./phase-completion.js";
4
+ import { completionPhaseFromDispatch, completionPhaseOrder, completionRedactionSecretsEnv, completionToolNamesForDebugGate, completionToolNamesForDecomposeGate, completionToolNamesForDraftGate, completionToolNamesForPhase, completionToolNamesForQaGate, debugCompletionPhaseOrder, decomposeCompletionGateOrder, draftCompletionGateOrder, prReviewContextFromDispatch, qaCompletionGateOrder, toolServerName, usesArchitectCycleCompletion, usesDebugCycleCompletion, usesDevelopCycleCompletion, usesQaCycleCompletion } from "./phase-completion.js";
5
5
  import { CompletionPayloadValidationError, asDebugCompletionPhase, asJsonRpcMessage, asMutableRecord, asRecord, artifactOwnerRelativeRoot, decomposeGateFromToolName, draftGateFromToolName, errorMessage, forgeBridgeCliBinPath, isDebugCompletionPhase, isDecomposeDispatch, normalizedOwnerType, phaseFromToolName, qaGateFromToolName, requiredString, rpcError, tomlString, tomlStringArray, writeJsonRpc } from "./phase-completion.validation.js";
6
6
  import { completionPromptForDebugCycle, completionPromptForDecomposeCycle, completionPromptForDevelopCycle, completionPromptForDraftCycle, completionPromptForPhase, completionPromptForQaCycle, completionToolNextInstruction, completionToolNextInstructionForDebugGate, completionToolNextInstructionForDecomposeGate, completionToolNextInstructionForDraftGate, completionToolNextInstructionForQaGate, nextDebugPhaseAfter, nextPhaseAfter } from "./phase-completion.prompts.js";
7
7
  import { configuredNativeTestPostgresFallbackPath, nativeTestPostgresFallbackConfigEnvironment, } from "../runtime/native-test-postgres-fallback.js";
@@ -37,7 +37,8 @@ export async function prepareCompletionToolRuntime(options) {
37
37
  || options.dispatch.execution.lane.trim().toLowerCase() === "draft"
38
38
  || options.dispatch.cycleRun.kind.trim().toLowerCase() === "draft")
39
39
  && !isDecomposeDispatch(options.dispatch),
40
- decomposeCycle: cycles && isDecomposeDispatch(options.dispatch)
40
+ decomposeCycle: cycles && isDecomposeDispatch(options.dispatch),
41
+ prReview: phase === "pr_review" ? prReviewContextFromDispatch(options.dispatch) : undefined
41
42
  });
42
43
  const runtime = {
43
44
  serverName: toolServerName,
@@ -182,7 +183,8 @@ export class CompletionToolServerSession {
182
183
  const completedPhase = this.currentPhase;
183
184
  const reference = await writeCompletionArtifact({ ...this.config, phase: completedPhase }, toolName, input);
184
185
  const status = reference.status.trim().toLowerCase();
185
- const pass = status === "pass";
186
+ // pr_review accepts reviewed, stale_head and blocked; each ends the lane, and an invalid payload throws above.
187
+ const pass = completedPhase === "pr_review" || status === "pass";
186
188
  const nextPhase = pass
187
189
  ? this.advanceAfterPass(completedPhase)
188
190
  : completedPhase;
@@ -365,6 +367,10 @@ export class CompletionToolServerSession {
365
367
  };
366
368
  }
367
369
  advanceAfterPass(phase) {
370
+ if (phase === "pr_review") {
371
+ this.completed = true;
372
+ return "pr_review_complete";
373
+ }
368
374
  if (phase === "qa") {
369
375
  this.completed = true;
370
376
  return "sign_off_ready";
@@ -1,5 +1,6 @@
1
1
  import { decomposeGateFileNames, decomposeStatuses, draftStatuses, isDebugCompletionPhase, phaseFiles, qaBlockerReasons, qaGateFileNames } from "./phase-completion.js";
2
2
  import { browserCheckSchema, qaSidecarsSchema, qaEvidenceWrapperSchema, qaGateEvidenceWrapperSchema, findingEvidenceSchema, objectToolSchema, evidenceObjectSchema, qaScopeSchema, commandEvidenceSchema, resolvedFindingSchema, acceptanceCriteriaSchema, reviewSectionSchema, reviewSectionProperties } from "./phase-completion.schema-parts.js";
3
+ import { prReviewToolInputSchema } from "./phase-completion.pr-review-schema.js";
3
4
  import { architectNonPassProperties } from "./architect-waits.js";
4
5
  export function toolDescription(phase, qaGate = null, decomposeGate = null, draftGate = null) {
5
6
  if (qaGate) {
@@ -30,6 +31,9 @@ export function toolDescription(phase, qaGate = null, decomposeGate = null, draf
30
31
  if (phase === "comment_repair") {
31
32
  return "Complete Forge pull-request comment repair by recording one evidence-backed disposition for every actionable finding in the dispatch snapshot.";
32
33
  }
34
+ if (phase === "pr_review") {
35
+ return "Complete Forge pull-request review by recording one comment-only review bound to the reviewed head: a verdict, overview, security summary, and inline comments anchored on new-side diff lines. Forge posts it afterwards; this tool does not publish. Use stale_head when the worktree is not at the dispatched head and blocked when the diff cannot be read.";
36
+ }
33
37
  if (phase === "self_review") {
34
38
  return "Complete Forge self-review by writing self-review.report.json with diff review, findings, security, edge-case, design, deterministic-comparison, fixes, and remaining-risk evidence.";
35
39
  }
@@ -41,8 +45,8 @@ export function toolDescription(phase, qaGate = null, decomposeGate = null, draf
41
45
  }
42
46
  return "Complete Forge validation by writing validation.verdict.json with command, build/test/lint/design, drift, acceptance-criteria, and ready-for-dev-test evidence.";
43
47
  }
44
- export function toolInputSchema(phase, qaGate = null, decomposeGate = null, draftGate = null) {
45
- const baseProperties = {
48
+ function baseToolProperties() {
49
+ return {
46
50
  status: {
47
51
  type: "string",
48
52
  enum: ["pass", "needs_rework", "fail", "failed"],
@@ -60,6 +64,9 @@ export function toolInputSchema(phase, qaGate = null, decomposeGate = null, draf
60
64
  })
61
65
  }
62
66
  };
67
+ }
68
+ export function toolInputSchema(phase, qaGate = null, decomposeGate = null, draftGate = null) {
69
+ const baseProperties = baseToolProperties();
63
70
  if (qaGate && qaGate !== "qa_verdict") {
64
71
  return qaGateToolInputSchema(qaGate);
65
72
  }
@@ -204,6 +211,9 @@ export function toolInputSchema(phase, qaGate = null, decomposeGate = null, draf
204
211
  }
205
212
  }, ["status", "summary", "repair_head_sha", "repair_issue_key", "dispositions", "changed_files", "validation"], "Use status pass after every actionable finding has an evidence-backed disposition. Rejected and needs_decision are legitimate outcomes and must not be disguised as code changes.");
206
213
  }
214
+ if (phase === "pr_review") {
215
+ return prReviewToolInputSchema();
216
+ }
207
217
  if (phase === "implementation") {
208
218
  return objectToolSchema({
209
219
  ...baseProperties,
@@ -1,5 +1,6 @@
1
1
  import { type CompletionPhase, type DebugCompletionPhase, type QaCompletionGate } from "./phase-completion.js";
2
2
  export { validateQaGatePassingCommands } from "./phase-completion.command-validation.js";
3
+ export { validatePrReviewPayloadShape } from "./phase-completion.pr-review-validation.js";
3
4
  export declare const qaEvidenceGates: ReadonlySet<QaCompletionGate>;
4
5
  export declare function normalizeCompletionStatus(value: string, phase?: CompletionPhase): string;
5
6
  export declare function normalizeQaGateStatus(value: string): string;
@@ -1,8 +1,9 @@
1
- import { qaBlockerReasons, qaCandidateBugActions, qaFindingScopes, qaFindingSeverities, qaGateToolNames, qaScopeAuthorities, qaScopeCapabilities, qaScopeConfidence, qaScopeEvidence, qaScopeFields, qaScopeSources, qaScopeSurfaces } from "./phase-completion.js";
1
+ import { qaBlockerReasons, qaCandidateBugActions, qaFindingScopes, qaFindingSeverities, qaGateToolNames, qaScopeAuthorities, qaScopeCapabilities, qaScopeConfidence, qaScopeEvidence, qaScopeFields, qaScopeSources, qaScopeSurfaces, prReviewStatuses } from "./phase-completion.js";
2
2
  import { structuredTypeHint } from "./mcp-argument-coercion.js";
3
3
  import { validateArchitectWaits } from "./architect-waits.js";
4
4
  import { validateQaGatePassingCommands } from "./phase-completion.command-validation.js";
5
5
  export { validateQaGatePassingCommands } from "./phase-completion.command-validation.js";
6
+ export { validatePrReviewPayloadShape } from "./phase-completion.pr-review-validation.js";
6
7
  export const qaEvidenceGates = new Set(["qa_regression", "qa_api", "qa_manual_web", "qa_bug_repro"]);
7
8
  export function normalizeCompletionStatus(value, phase) {
8
9
  const normalized = value.trim().toLowerCase().replace(/-/g, "_");
@@ -13,6 +14,13 @@ export function normalizeCompletionStatus(value, phase) {
13
14
  }
14
15
  return canonical;
15
16
  }
17
+ if (phase === "pr_review") {
18
+ const canonical = normalized === "stalehead" ? "stale_head" : normalized;
19
+ if (!prReviewStatuses.includes(canonical)) {
20
+ throw new Error(`pr_review status must be one of ${prReviewStatuses.join(", ")}.`);
21
+ }
22
+ return canonical;
23
+ }
16
24
  if (phase === "architect") {
17
25
  const canonical = normalized === "needsrevision" ? "needs_revision" : normalized;
18
26
  if (canonical !== "pass" && canonical !== "needs_revision" && canonical !== "blocked") {
@@ -0,0 +1,18 @@
1
+ import type { RunOnceDispatchPacket } from "./session.types.js";
2
+ /** Runs git in the review's repository: resolves with stdout, rejects when git fails. */
3
+ export type ReviewDiffBaseGit = (args: readonly string[]) => Promise<string>;
4
+ /**
5
+ * The commit a Forge PR review diffs against: the merge base of the dispatched base and the head, the
6
+ * same `base...head` diff the pull request shows. The provider's base (GitHub's `base.sha`) is the base
7
+ * branch tip at the pull request's last sync, which is not an ancestor of the head once the base moves
8
+ * on and the branch has not merged it; a Docker sandbox imports only the head's ancestry, so that tip
9
+ * is not there, but the merge base always is. Resolved with the bridge's own git, fetching the base by
10
+ * its SHA when the checkout lacks it and falling back to the base branch on origin when the base commit
11
+ * is gone. Null when the dispatch is not a review or no base can be found: the dispatch is then unchanged.
12
+ */
13
+ export declare function resolveReviewDiffBase(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "prReview" | "pullRequest">, git: ReviewDiffBaseGit): Promise<string | null>;
14
+ /**
15
+ * The dispatch with its review base set to the diff base, keeping the base tip it replaced, so the prompt,
16
+ * the completion tool's anchor check and the recorded review all use one commit that is in the worktree.
17
+ */
18
+ export declare function withReviewDiffBase(dispatch: RunOnceDispatchPacket, diffBase: string | null): RunOnceDispatchPacket;
@@ -0,0 +1,45 @@
1
+ import { prReviewDispatchHeadSha } from "./pr-review-placement.js";
2
+ const fullObjectId = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u;
3
+ /**
4
+ * The commit a Forge PR review diffs against: the merge base of the dispatched base and the head, the
5
+ * same `base...head` diff the pull request shows. The provider's base (GitHub's `base.sha`) is the base
6
+ * branch tip at the pull request's last sync, which is not an ancestor of the head once the base moves
7
+ * on and the branch has not merged it; a Docker sandbox imports only the head's ancestry, so that tip
8
+ * is not there, but the merge base always is. Resolved with the bridge's own git, fetching the base by
9
+ * its SHA when the checkout lacks it and falling back to the base branch on origin when the base commit
10
+ * is gone. Null when the dispatch is not a review or no base can be found: the dispatch is then unchanged.
11
+ */
12
+ export async function resolveReviewDiffBase(dispatch, git) {
13
+ const headSha = prReviewDispatchHeadSha(dispatch);
14
+ const baseSha = (dispatch.prReview?.baseSha ?? "").trim().toLowerCase();
15
+ // Both reach git as arguments (fetch, merge-base): only a full object id may, never a ref or an option.
16
+ if (!headSha || !fullObjectId.test(headSha) || !fullObjectId.test(baseSha)) {
17
+ return null;
18
+ }
19
+ const commit = async (rev) => {
20
+ const sha = (await git(["rev-parse", "--verify", "--quiet", `${rev}^{commit}`]).catch(() => "")).trim().toLowerCase();
21
+ return fullObjectId.test(sha) ? sha : null;
22
+ };
23
+ let base = await commit(baseSha);
24
+ if (!base) {
25
+ await git(["fetch", "--no-tags", "--no-write-fetch-head", "origin", baseSha]).catch(() => undefined);
26
+ const baseBranch = (dispatch.prReview?.baseBranch || dispatch.cycleRun.baseBranch || "").trim();
27
+ base = await commit(baseSha) ?? (baseBranch ? await commit(`refs/remotes/origin/${baseBranch}`) : null);
28
+ }
29
+ if (!base) {
30
+ return null;
31
+ }
32
+ const mergeBase = (await git(["merge-base", base, headSha]).catch(() => "")).trim().toLowerCase();
33
+ return fullObjectId.test(mergeBase) ? mergeBase : null;
34
+ }
35
+ /**
36
+ * The dispatch with its review base set to the diff base, keeping the base tip it replaced, so the prompt,
37
+ * the completion tool's anchor check and the recorded review all use one commit that is in the worktree.
38
+ */
39
+ export function withReviewDiffBase(dispatch, diffBase) {
40
+ const prReview = dispatch.prReview;
41
+ if (!diffBase || !prReview || prReview.baseSha.trim().toLowerCase() === diffBase) {
42
+ return dispatch;
43
+ }
44
+ return { ...dispatch, prReview: { ...prReview, baseSha: diffBase, baseTipSha: prReview.baseTipSha || prReview.baseSha } };
45
+ }
@@ -0,0 +1,50 @@
1
+ import { type RunnerDispatchEvent, type RunOnceDispatchPacket, type RunOnceResultPacket } from "./session.types.js";
2
+ /**
3
+ * Where a Forge PR review may run. A review reads pull request code an author controls, and the only
4
+ * operating-system isolation this bridge enforces is its Docker sandbox: a container with no git
5
+ * credential, no remote and no host home directory. On a plain host the provider runs as the
6
+ * bridge's user, beside that user's git credentials and provider sign-in, and the review guardrails
7
+ * (credential-free git environment, tool deny rules, command shims, the post-run ref and remote-head
8
+ * checks) are defence in depth, not a boundary. So a review placed on the host is refused before any
9
+ * provider starts unless the runner's owner opted in with `allowUnsandboxedPrReview: true` in
10
+ * bridge.json, accepting that risk.
11
+ */
12
+ export declare const prReviewUnsandboxedHostCode = "pr_review.unsandboxed_host";
13
+ /**
14
+ * A review placed in this bridge's Docker sandbox for a project whose sandbox contract it cannot read or build:
15
+ * refused before any provider starts, and never retried on this runner (a capacity wait would only expire).
16
+ */
17
+ export declare const prReviewSandboxUnavailableCode = "pr_review.sandbox_unavailable";
18
+ /** The execution facility a runner advertises when its owner opted in to host-placed reviews. */
19
+ export declare const prReviewUnsandboxedHostFacility = "pr_review_unsandboxed_host";
20
+ /** The warning a host-placed review carries when the runner's owner opted in. */
21
+ export declare const prReviewUnsandboxedHostWarningEvent = "pr_review_unsandboxed_host_warning";
22
+ /** A dispatch for the review-only pr_review session, by role, lane or cycle kind. */
23
+ export declare function isPrReviewDispatch(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun">): boolean;
24
+ /** The pull request head a review dispatch reads, lowercased, or null for any other dispatch. */
25
+ export declare function prReviewDispatchHeadSha(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "prReview" | "pullRequest">): string | null;
26
+ /** Why this bridge refuses the dispatch, or null: a review placed outside Docker without the opt-in. */
27
+ export declare function prReviewPlacementRefusal(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "sandbox">, allowUnsandboxedPrReview: boolean | undefined): string | null;
28
+ /** The warning for a review that runs on the host because the runner's owner opted in, or null. */
29
+ export declare function prReviewUnsandboxedHostWarning(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "sandbox">, allowUnsandboxedPrReview: boolean | undefined): string | null;
30
+ /** The terminal failure for a refused review (see {@link prReviewPlacementRefusal}), or null. */
31
+ export declare function prReviewPlacementRefusalResult(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "sandbox">, allowUnsandboxedPrReview: boolean | undefined): RunOnceResultPacket | null;
32
+ /**
33
+ * Set by the server-local runner on a run-once whose Forge PR review it admitted on its host (in its container
34
+ * sandbox, or because the runner opted in to host reviews). Nothing else sets it.
35
+ */
36
+ export declare const prReviewHostAdmittedEnv = "FORGE_PR_REVIEW_HOST_ADMITTED";
37
+ /**
38
+ * forge-bridge run-once (which the server-local runner launches): a Forge PR review placed outside Docker runs
39
+ * only when the server-local runner admitted it on this host; any other is refused before a provider starts.
40
+ */
41
+ export declare function runOnceWithReviewPlacement(dispatch: RunOnceDispatchPacket, run: (dispatch: RunOnceDispatchPacket) => Promise<RunOnceResultPacket>, env?: NodeJS.ProcessEnv): Promise<RunOnceResultPacket>;
42
+ /** The execution facilities that tell Forge this runner's owner opted in to host-placed reviews. */
43
+ export declare function prReviewExecutionFacilities(allowUnsandboxedPrReview: boolean | undefined): readonly string[];
44
+ /**
45
+ * Runs the dispatch; a review that runs on the host by the owner's opt-in is logged, announced as a
46
+ * session event and reported in the result summary as a warning.
47
+ */
48
+ export declare function runWithUnsandboxedReviewWarning(dispatch: Pick<RunOnceDispatchPacket, "execution" | "cycleRun" | "sandbox">, allowUnsandboxedPrReview: boolean | undefined, sink: {
49
+ emit(event: RunnerDispatchEvent): Promise<void>;
50
+ }, log: (message: string) => void, run: () => Promise<RunOnceResultPacket>): Promise<RunOnceResultPacket>;