@bridge_gpt/mcp-server 0.2.72 → 0.2.73

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 (146) hide show
  1. package/README.md +5 -5
  2. package/build/agent-launchers/claude-executor-adapter.js +3 -0
  3. package/build/agents.generated.js +6 -6
  4. package/build/bridge-permissions.js +27 -0
  5. package/build/ci-system-detection.js +50 -0
  6. package/build/ci-trigger-adapters.js +631 -0
  7. package/build/ci-trigger-install.js +106 -0
  8. package/build/codex-launcher-pin.js +33 -2
  9. package/build/codex-skill-adapter.js +3 -1
  10. package/build/command-host.js +33 -0
  11. package/build/commands.generated.js +7 -6
  12. package/build/conductor/bridge-api-client.js +842 -35
  13. package/build/conductor/bring-up-facts.js +18 -5
  14. package/build/conductor/command-drift-production.js +42 -17
  15. package/build/conductor/command-drift.js +47 -0
  16. package/build/conductor/declare-blocked.js +554 -0
  17. package/build/conductor/doctor.js +106 -21
  18. package/build/conductor/driver-commands.js +141 -0
  19. package/build/conductor/driver-guard.js +277 -0
  20. package/build/conductor/driver-lapse.js +321 -0
  21. package/build/conductor/driver-register.js +176 -0
  22. package/build/conductor/driver-release.js +174 -0
  23. package/build/conductor/driver-session-state.js +315 -0
  24. package/build/conductor/epic-branch-ci-inspection.js +222 -29
  25. package/build/conductor/epic-implementer-cli.js +166 -15
  26. package/build/conductor/epic-server-database.js +162 -0
  27. package/build/conductor/epic-server-guidance.js +278 -0
  28. package/build/conductor/epic-server-journal.js +239 -0
  29. package/build/conductor/epic-server-processes.js +324 -0
  30. package/build/conductor/epic-server-recipe.js +397 -0
  31. package/build/conductor/epic-server-runtime.js +1207 -0
  32. package/build/conductor/epic-server-sfcc.js +107 -0
  33. package/build/conductor/epic-server-state.js +427 -0
  34. package/build/conductor/epic-server.js +594 -0
  35. package/build/conductor/gate-discovery.js +150 -5
  36. package/build/conductor/gate-settings-review.js +224 -4
  37. package/build/conductor/launch-need-probes.js +6 -53
  38. package/build/conductor/launch-plan.js +313 -156
  39. package/build/conductor/prerequisite-inputs.js +879 -45
  40. package/build/conductor/readiness-assessment.js +16 -1
  41. package/build/conductor/readiness-cli.js +20 -9
  42. package/build/conductor/readiness-prerequisites.js +28 -9
  43. package/build/conductor/readiness-sections.js +133 -126
  44. package/build/conductor/readiness.js +1 -1
  45. package/build/conductor/recovery-cli.js +13 -2
  46. package/build/conductor/tools.js +6 -5
  47. package/build/conductor/wait-run-attention.js +2 -2
  48. package/build/conductor/wait-run-cli.js +208 -22
  49. package/build/conductor/worker-database-doctor-inspector.js +33 -2
  50. package/build/conductor/worker-setup-tally.js +27 -0
  51. package/build/credential-store.js +71 -1
  52. package/build/dependency-install-declarations.js +55 -0
  53. package/build/docs.generated.js +2 -2
  54. package/build/doctor.js +54 -3
  55. package/build/drive-epic-help.js +21 -2
  56. package/build/drive-epic.js +1811 -351
  57. package/build/engine-paths.js +20 -0
  58. package/build/epic-branch-ci-summary.js +140 -0
  59. package/build/epic-capability-statement.js +107 -0
  60. package/build/epic-ci-workflow-drift.js +30 -15
  61. package/build/epic-ci-workflow-install.js +110 -42
  62. package/build/epic-ci-workflow-v2.js +274 -0
  63. package/build/epic-ci-workflow.js +38 -12
  64. package/build/epic-implementer-bin.js +2101 -44
  65. package/build/epic-launch-context.js +607 -0
  66. package/build/epic-server-record.js +273 -0
  67. package/build/epic-shared/bridge-client.js +11 -3
  68. package/build/escalation-reachability.js +43 -0
  69. package/build/executor/ci-fix-test-runs.js +334 -0
  70. package/build/executor/completion-contract.js +8 -1
  71. package/build/executor/env.js +59 -22
  72. package/build/executor/epic-server-context.js +141 -0
  73. package/build/executor/gate-qualification-job.js +127 -26
  74. package/build/executor/http-client.js +52 -5
  75. package/build/executor/job-runner.js +423 -69
  76. package/build/executor/observation.js +8 -0
  77. package/build/executor/pre-pr-checks.js +363 -0
  78. package/build/executor/prompt-spec.js +114 -2
  79. package/build/executor/reconcile-overlap-job.js +5 -3
  80. package/build/executor/required-work-diagnostics.js +4 -2
  81. package/build/executor/required-work-ledger.js +936 -38
  82. package/build/executor/results.js +58 -0
  83. package/build/executor/terminal-mutation.js +8 -0
  84. package/build/executor/worker-command.js +72 -3
  85. package/build/executor/worker-database-config.js +281 -0
  86. package/build/executor/worker-database-target.js +16 -12
  87. package/build/executor/worker-database.js +320 -101
  88. package/build/executor/worker-finalization.js +7 -1
  89. package/build/executor/worker-resources.js +25 -3
  90. package/build/executor/worker-verification-guidance.js +18 -3
  91. package/build/executor/worktree.js +20 -1
  92. package/build/executor-launch.js +54 -2
  93. package/build/generated-assets-catalog.js +2 -2
  94. package/build/index.js +664 -335
  95. package/build/init.js +26 -11
  96. package/build/install-bridge-conductor-answers.js +465 -0
  97. package/build/install-bridge-conductor-apply.js +259 -0
  98. package/build/install-bridge-conductor-assessment.js +895 -0
  99. package/build/install-bridge-conductor-compact.js +161 -0
  100. package/build/install-bridge-conductor-contracts.js +63 -0
  101. package/build/install-bridge-conductor-gate.js +1197 -196
  102. package/build/install-bridge-conductor-setup.js +535 -79
  103. package/build/install-bridge-conductor.js +2885 -560
  104. package/build/install-bridge.js +199 -21
  105. package/build/install-maintenance.js +26 -3
  106. package/build/launcher-config-inspection.js +162 -1
  107. package/build/mcp-grant-candidates.js +767 -0
  108. package/build/mcp-grant-doctor.js +63 -0
  109. package/build/mcp-grant.js +288 -0
  110. package/build/mcp-host-targets.js +8 -0
  111. package/build/mcp-identity.js +23 -0
  112. package/build/mcp-invoke.js +126 -13
  113. package/build/mcp-presets.js +107 -0
  114. package/build/mcp-provisioning.js +134 -2
  115. package/build/mcp-registration-doctor.js +31 -2
  116. package/build/mcp-server-invocation.js +6 -1
  117. package/build/merge-workflow-install.js +234 -109
  118. package/build/pipelines.generated.js +5 -5
  119. package/build/plan-discovery.js +97 -4
  120. package/build/plan-execution-ledger.js +100 -7
  121. package/build/plan-generation-io.js +262 -0
  122. package/build/plan-generation.js +424 -0
  123. package/build/plane/build-freshness.js +6 -1
  124. package/build/plane/cli.js +75 -9
  125. package/build/plane/plane-freshness.js +17 -0
  126. package/build/plane/preflight.js +50 -10
  127. package/build/plane/shutdown.js +19 -0
  128. package/build/plane/terminal-run-cleanup.js +18 -4
  129. package/build/printed-remedy-commands.js +206 -12
  130. package/build/readiness-check.js +77 -0
  131. package/build/readiness-prerequisites.generated.js +122 -14
  132. package/build/readme.generated.js +1 -1
  133. package/build/repository-state-paths.js +38 -0
  134. package/build/run-unit-tests-launcher.js +8 -1
  135. package/build/setup-epic.js +1190 -196
  136. package/build/setup-progress.js +44 -0
  137. package/build/setup-question.js +122 -4
  138. package/build/third-party-mcp-targets.js +30 -0
  139. package/build/ticket-delivery-enrollment.js +9 -0
  140. package/build/upgrade-cli.js +85 -2
  141. package/build/v2-readiness-requirements.js +28 -1
  142. package/build/version.generated.js +3 -3
  143. package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
  144. package/docs/epic-implementer/getting-started.md +3 -1
  145. package/docs/epic-implementer/self-hosting.md +14 -1
  146. package/package.json +2 -2
@@ -681,6 +681,7 @@ export function createObservationState(deps, options) {
681
681
  let exitCode;
682
682
  let attemptStartSha;
683
683
  let attemptEndSha;
684
+ let workerDatabaseProvisioned = false;
684
685
  /**
685
686
  * BAPI-828/BAPI-898: the MOST SEVERE qualifying advisory observed so far wins,
686
687
  * ranked by {@link rateLimitSeverity}. An advisory at equal or lower severity —
@@ -847,6 +848,9 @@ export function createObservationState(deps, options) {
847
848
  }
848
849
  publication = { ...publication, to_sha: fact.to_sha };
849
850
  },
851
+ recordWorkerDatabaseProvisioned() {
852
+ workerDatabaseProvisioned = true;
853
+ },
850
854
  snapshot() {
851
855
  const residue = { ...git };
852
856
  if (publication) {
@@ -870,6 +874,10 @@ export function createObservationState(deps, options) {
870
874
  residue.attempt_start_sha = attemptStartSha;
871
875
  if (attemptEndSha !== undefined)
872
876
  residue.attempt_end_sha = attemptEndSha;
877
+ // BAPI-1609: absent until a database was really provisioned, so a job
878
+ // without one serializes exactly as before.
879
+ if (workerDatabaseProvisioned)
880
+ residue.worker_resources = { database: "provisioned" };
873
881
  return residue;
874
882
  },
875
883
  terminalCapacity() {
@@ -0,0 +1,363 @@
1
+ /**
2
+ * BAPI-1582 — pre-PR checks for an `implement` worker.
3
+ *
4
+ * Two contracts live here:
5
+ *
6
+ * 1. **Declarations.** The server stamps `pre_pr_checks` on an implement payload:
7
+ * every owner-confirmed gate-profile reproduction hint as
8
+ * `{check, argv, timeout_seconds}`, sorted by check name. The executor
9
+ * re-validates each entry before rendering it into the worker prompt. An
10
+ * invalid entry is skipped with a closed reason and its position; an argv item
11
+ * is never logged or rendered from a rejected entry.
12
+ *
13
+ * 2. **Evidence.** The worker writes `<worktree>/.conductor/pre-pr-checks.json`
14
+ * before it calls `create_pull_request`. After exit the executor reads it with
15
+ * a bounded, no-follow read, trusts it only when its `tested_head` equals the
16
+ * observed final head, and attaches a bounded summary to the completion result
17
+ * as telemetry. It is never gate evidence, never a ledger record, and a
18
+ * missing, stale, or malformed record attaches nothing and fails nothing.
19
+ */
20
+ import path from "node:path";
21
+ /** The shared budget, in seconds, for the whole pre-PR step of one implement attempt. */
22
+ export const PRE_PR_BUDGET_SECONDS = 600;
23
+ /** Declaration bounds (mirror the gate profile's reproduction-hint rules). */
24
+ export const PRE_PR_MAX_DECLARATIONS = 32;
25
+ export const PRE_PR_CHECK_NAME_MAX_CHARS = 200;
26
+ export const PRE_PR_ARGV_MAX_ITEMS = 32;
27
+ export const PRE_PR_ARG_MAX_CHARS = 1024;
28
+ export const PRE_PR_TIMEOUT_MIN_SECONDS = 1;
29
+ export const PRE_PR_TIMEOUT_MAX_SECONDS = 1800;
30
+ /** The evidence record's location under the worktree. */
31
+ export const PRE_PR_EVIDENCE_RELATIVE_PATH = path.join(".conductor", "pre-pr-checks.json");
32
+ /** Largest evidence file the executor reads. */
33
+ export const PRE_PR_EVIDENCE_MAX_BYTES = 64_000;
34
+ /** The completion-result key the bounded summary rides on. */
35
+ export const PRE_PR_SUMMARY_KEY = "pre_pr_checks_summary";
36
+ const CONTROL_CHAR_RE = /[\x00-\x1f\x7f]/;
37
+ const DECLARATION_KEYS = new Set(["check", "argv", "timeout_seconds"]);
38
+ function isPlainRecord(value) {
39
+ return value !== null && typeof value === "object" && !Array.isArray(value);
40
+ }
41
+ function rejectDeclaration(raw) {
42
+ if (!isPlainRecord(raw))
43
+ return "not_an_object";
44
+ for (const key of Object.keys(raw))
45
+ if (!DECLARATION_KEYS.has(key))
46
+ return "unexpected_key";
47
+ const check = raw.check;
48
+ if (typeof check !== "string")
49
+ return "check_invalid";
50
+ const name = check.trim();
51
+ if (!name || name.length > PRE_PR_CHECK_NAME_MAX_CHARS || CONTROL_CHAR_RE.test(name))
52
+ return "check_invalid";
53
+ const argv = raw.argv;
54
+ if (!Array.isArray(argv))
55
+ return "argv_not_a_list";
56
+ if (argv.length < 1 || argv.length > PRE_PR_ARGV_MAX_ITEMS)
57
+ return "argv_count_invalid";
58
+ for (const item of argv) {
59
+ if (typeof item !== "string" || !item.trim() || item.length > PRE_PR_ARG_MAX_CHARS || item.includes("\x00")) {
60
+ return "argv_item_invalid";
61
+ }
62
+ }
63
+ const timeout = raw.timeout_seconds;
64
+ if (typeof timeout !== "number" || !Number.isInteger(timeout) ||
65
+ timeout < PRE_PR_TIMEOUT_MIN_SECONDS || timeout > PRE_PR_TIMEOUT_MAX_SECONDS) {
66
+ return "timeout_invalid";
67
+ }
68
+ return { check: name, argv: [...argv], timeoutSeconds: timeout };
69
+ }
70
+ /**
71
+ * Validate a payload `pre_pr_checks` value. Never throws. Entries keep their
72
+ * supplied (server-sorted) order; a duplicate check name or an entry past
73
+ * {@link PRE_PR_MAX_DECLARATIONS} is skipped, never silently merged.
74
+ */
75
+ export function admitPrePrChecks(raw) {
76
+ if (!Array.isArray(raw))
77
+ return { entries: [], skipped: [], notAList: true };
78
+ const entries = [];
79
+ const skipped = [];
80
+ const seen = new Set();
81
+ raw.forEach((item, position) => {
82
+ if (position >= PRE_PR_MAX_DECLARATIONS) {
83
+ skipped.push({ position, reason: "too_many_declarations" });
84
+ return;
85
+ }
86
+ const verdict = rejectDeclaration(item);
87
+ if (typeof verdict === "string") {
88
+ skipped.push({ position, reason: verdict });
89
+ return;
90
+ }
91
+ if (seen.has(verdict.check)) {
92
+ skipped.push({ position, reason: "duplicate_check" });
93
+ return;
94
+ }
95
+ seen.add(verdict.check);
96
+ entries.push(verdict);
97
+ });
98
+ return { entries, skipped, notAList: false };
99
+ }
100
+ /**
101
+ * The admitted entries for a payload option, logging each skip by position and
102
+ * closed reason only. Absent (`undefined`) admits nothing and logs nothing.
103
+ */
104
+ export function validatePrePrCheckDeclarations(option, errorLog = (message) => console.error(message)) {
105
+ if (!Object.prototype.hasOwnProperty.call(option, "prePrChecks"))
106
+ return [];
107
+ const log = (message) => { try {
108
+ errorLog(message);
109
+ }
110
+ catch { /* sink */ } };
111
+ let admitted;
112
+ try {
113
+ admitted = admitPrePrChecks(option.prePrChecks);
114
+ }
115
+ catch {
116
+ admitted = { entries: [], skipped: [], notAList: true };
117
+ }
118
+ if (admitted.notAList) {
119
+ log("executor: pre_pr_checks is present but is not a list; rendering no pre-PR checks");
120
+ return [];
121
+ }
122
+ for (const skip of admitted.skipped) {
123
+ log(`executor: skipped pre_pr_checks entry ${skip.position}: ${skip.reason}`);
124
+ }
125
+ return admitted.entries;
126
+ }
127
+ // ---------------------------------------------------------------------------
128
+ // Evidence record
129
+ // ---------------------------------------------------------------------------
130
+ export const PRE_PR_SOURCES = ["required", "likely_tests", "gate_profile"];
131
+ export const PRE_PR_RUN_OUTCOMES = ["passed", "failed", "timed_out"];
132
+ export const PRE_PR_SKIP_REASONS = ["budget", "unmappable", "not_executable", "unavailable"];
133
+ /** Evidence bounds. */
134
+ export const PRE_PR_EVIDENCE_MAX_SELECTED = 256;
135
+ export const PRE_PR_EVIDENCE_MAX_RUNS = 512;
136
+ export const PRE_PR_EVIDENCE_MAX_SKIPPED = 256;
137
+ export const PRE_PR_EVIDENCE_NAME_MAX_CHARS = 500;
138
+ /** Largest duration accepted for one run or the whole step (a day; anything more is malformed). */
139
+ const PRE_PR_MAX_SECONDS = 86_400;
140
+ /** Names listed in the summary's not-passed and unverified lists. */
141
+ export const PRE_PR_SUMMARY_MAX_NAMES = 16;
142
+ const SHA_RE = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
143
+ function validName(value) {
144
+ return typeof value === "string" && value.trim().length > 0 &&
145
+ value.length <= PRE_PR_EVIDENCE_NAME_MAX_CHARS && !CONTROL_CHAR_RE.test(value);
146
+ }
147
+ function validSeconds(value) {
148
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= PRE_PR_MAX_SECONDS;
149
+ }
150
+ function validSha(value) {
151
+ return typeof value === "string" && SHA_RE.test(value);
152
+ }
153
+ function oneOf(values, value) {
154
+ return typeof value === "string" && values.includes(value);
155
+ }
156
+ function exactKeys(value, keys) {
157
+ const present = Object.keys(value);
158
+ return present.length === keys.length && keys.every((key) => Object.prototype.hasOwnProperty.call(value, key));
159
+ }
160
+ /**
161
+ * Validate a parsed evidence record. Returns the record (with only its declared
162
+ * fields) or `null`. Never throws. Unknown keys, unknown vocabulary, an invalid
163
+ * SHA, a negative or non-finite duration, or an array over its bound all reject
164
+ * the whole record — nothing from it is trusted partially.
165
+ */
166
+ export function validatePrePrEvidence(raw) {
167
+ if (!isPlainRecord(raw))
168
+ return null;
169
+ if (!exactKeys(raw, ["version", "tested_head", "budget_seconds", "elapsed_seconds", "selected", "run", "skipped"])) {
170
+ return null;
171
+ }
172
+ if (raw.version !== 1 || !validSha(raw.tested_head))
173
+ return null;
174
+ if (raw.budget_seconds !== PRE_PR_BUDGET_SECONDS || !validSeconds(raw.elapsed_seconds))
175
+ return null;
176
+ const { selected, run, skipped } = raw;
177
+ if (!Array.isArray(selected) || selected.length > PRE_PR_EVIDENCE_MAX_SELECTED)
178
+ return null;
179
+ if (!Array.isArray(run) || run.length > PRE_PR_EVIDENCE_MAX_RUNS)
180
+ return null;
181
+ if (!Array.isArray(skipped) || skipped.length > PRE_PR_EVIDENCE_MAX_SKIPPED)
182
+ return null;
183
+ const out = {
184
+ version: 1,
185
+ tested_head: raw.tested_head,
186
+ budget_seconds: PRE_PR_BUDGET_SECONDS,
187
+ elapsed_seconds: raw.elapsed_seconds,
188
+ selected: [],
189
+ run: [],
190
+ skipped: [],
191
+ };
192
+ for (const entry of selected) {
193
+ if (!isPlainRecord(entry) || !exactKeys(entry, ["name", "source"]))
194
+ return null;
195
+ if (!validName(entry.name) || !oneOf(PRE_PR_SOURCES, entry.source))
196
+ return null;
197
+ out.selected.push({ name: entry.name, source: entry.source });
198
+ }
199
+ for (const entry of run) {
200
+ if (!isPlainRecord(entry) || !exactKeys(entry, ["name", "source", "head_sha", "outcome", "seconds"]))
201
+ return null;
202
+ if (!validName(entry.name) || !oneOf(PRE_PR_SOURCES, entry.source) || !validSha(entry.head_sha) ||
203
+ !oneOf(PRE_PR_RUN_OUTCOMES, entry.outcome) || !validSeconds(entry.seconds)) {
204
+ return null;
205
+ }
206
+ out.run.push({
207
+ name: entry.name, source: entry.source, head_sha: entry.head_sha,
208
+ outcome: entry.outcome, seconds: entry.seconds,
209
+ });
210
+ }
211
+ for (const entry of skipped) {
212
+ if (!isPlainRecord(entry) || !exactKeys(entry, ["name", "source", "reason"]))
213
+ return null;
214
+ if (!validName(entry.name) || !oneOf(PRE_PR_SOURCES, entry.source) || !oneOf(PRE_PR_SKIP_REASONS, entry.reason)) {
215
+ return null;
216
+ }
217
+ out.skipped.push({ name: entry.name, source: entry.source, reason: entry.reason });
218
+ }
219
+ return out;
220
+ }
221
+ /**
222
+ * Summarize a validated record observed at `observedHead`. Returns `null` for a
223
+ * stale record (its `tested_head` is not the observed head).
224
+ */
225
+ export function summarizePrePrEvidence(evidence, observedHead) {
226
+ if (evidence.tested_head !== observedHead.trim().toLowerCase())
227
+ return null;
228
+ const atHead = { passed: 0, failed: 0, timed_out: 0 };
229
+ const latestAtHead = new Map();
230
+ let historical = 0;
231
+ for (const run of evidence.run) {
232
+ if (run.head_sha === evidence.tested_head) {
233
+ atHead[run.outcome] += 1;
234
+ latestAtHead.set(run.name, run.outcome);
235
+ }
236
+ else {
237
+ historical += 1;
238
+ }
239
+ }
240
+ const skipped = { budget: 0, unmappable: 0, not_executable: 0, unavailable: 0 };
241
+ const skippedNames = new Set();
242
+ for (const skip of evidence.skipped) {
243
+ skipped[skip.reason] += 1;
244
+ skippedNames.add(skip.name);
245
+ }
246
+ const notPassed = [];
247
+ const unverified = [];
248
+ const seen = new Set();
249
+ for (const { name } of evidence.selected) {
250
+ if (seen.has(name))
251
+ continue;
252
+ seen.add(name);
253
+ const outcome = latestAtHead.get(name);
254
+ if (outcome === undefined) {
255
+ if (!skippedNames.has(name))
256
+ unverified.push(name);
257
+ }
258
+ else if (outcome !== "passed") {
259
+ notPassed.push(name);
260
+ }
261
+ }
262
+ return {
263
+ version: 1,
264
+ tested_head: evidence.tested_head,
265
+ budget_seconds: evidence.budget_seconds,
266
+ elapsed_seconds: evidence.elapsed_seconds,
267
+ selected_count: evidence.selected.length,
268
+ at_tested_head: atHead,
269
+ historical_run_count: historical,
270
+ skipped,
271
+ not_passed_at_tested_head: notPassed.slice(0, PRE_PR_SUMMARY_MAX_NAMES),
272
+ unverified_at_tested_head: unverified.slice(0, PRE_PR_SUMMARY_MAX_NAMES),
273
+ unverified_at_tested_head_count: unverified.length,
274
+ };
275
+ }
276
+ /**
277
+ * Read `<worktree>/.conductor/pre-pr-checks.json` with a bounded, no-follow read.
278
+ * Never throws; `code` is a fixed, secret-free token.
279
+ */
280
+ export async function readPrePrEvidenceArtifact(worktreePath, deps) {
281
+ const conductorDir = path.join(worktreePath, ".conductor");
282
+ const artifactPath = path.join(worktreePath, PRE_PR_EVIDENCE_RELATIVE_PATH);
283
+ if (deps.lstatPath) {
284
+ try {
285
+ const dirMeta = await deps.lstatPath(conductorDir);
286
+ if (dirMeta === null)
287
+ return { status: "missing", code: "artifact_absent" };
288
+ if (dirMeta.isSymbolicLink || !dirMeta.isDirectory)
289
+ return { status: "invalid", code: "artifact_dir_unsafe" };
290
+ const meta = await deps.lstatPath(artifactPath);
291
+ if (meta === null)
292
+ return { status: "missing", code: "artifact_absent" };
293
+ if (meta.isDirectory || meta.isSymbolicLink)
294
+ return { status: "invalid", code: "artifact_not_regular_file" };
295
+ }
296
+ catch {
297
+ return { status: "invalid", code: "artifact_unreadable" };
298
+ }
299
+ }
300
+ let raw;
301
+ try {
302
+ raw = await deps.readFile(artifactPath);
303
+ }
304
+ catch (err) {
305
+ const code = err && typeof err === "object" ? err.code : undefined;
306
+ return code === "ENOENT"
307
+ ? { status: "missing", code: "artifact_absent" }
308
+ : { status: "invalid", code: "artifact_unreadable" };
309
+ }
310
+ if (typeof raw !== "string")
311
+ return { status: "invalid", code: "artifact_unreadable" };
312
+ if (Buffer.byteLength(raw, "utf8") > PRE_PR_EVIDENCE_MAX_BYTES)
313
+ return { status: "invalid", code: "artifact_oversized" };
314
+ let parsed;
315
+ try {
316
+ parsed = JSON.parse(raw);
317
+ }
318
+ catch {
319
+ return { status: "invalid", code: "artifact_not_json" };
320
+ }
321
+ const evidence = validatePrePrEvidence(parsed);
322
+ return evidence === null ? { status: "invalid", code: "artifact_invalid" } : { status: "ok", evidence };
323
+ }
324
+ const CONTENT_FAILURE_CODES = new Set(["artifact_oversized", "artifact_not_json", "artifact_invalid"]);
325
+ /**
326
+ * Attach the bounded summary to `result` when a valid, current-head record
327
+ * exists and the augmented result still fits `maxResultBytes`. Otherwise
328
+ * `result` is returned unchanged. Never throws.
329
+ */
330
+ export async function withPrePrChecksSummary(result, options) {
331
+ const log = (message) => { try {
332
+ options.errorLog?.(message);
333
+ }
334
+ catch { /* sink */ } };
335
+ try {
336
+ if (typeof options.observedHead !== "string" || !SHA_RE.test(options.observedHead.trim().toLowerCase())) {
337
+ return result;
338
+ }
339
+ const read = await readPrePrEvidenceArtifact(options.worktreePath, options.deps);
340
+ if (read.status !== "ok") {
341
+ // An absent or unreadable record is ordinary (no pre-PR step, full scope,
342
+ // or a filesystem shape the worker never wrote): stay quiet. Only a record
343
+ // the worker wrote with bad content is worth a line.
344
+ if (CONTENT_FAILURE_CODES.has(read.code))
345
+ log(`executor: pre-PR checks record invalid (${read.code}); no summary attached`);
346
+ return result;
347
+ }
348
+ const summary = summarizePrePrEvidence(read.evidence, options.observedHead);
349
+ if (summary === null) {
350
+ log("executor: pre-PR checks record is stale (tested_head is not the final head); no summary attached");
351
+ return result;
352
+ }
353
+ const augmented = { ...result, [PRE_PR_SUMMARY_KEY]: summary };
354
+ if (Buffer.byteLength(JSON.stringify(augmented), "utf8") > options.maxResultBytes) {
355
+ log("executor: pre-PR checks summary would exceed the result budget; not attached");
356
+ return result;
357
+ }
358
+ return augmented;
359
+ }
360
+ catch {
361
+ return result;
362
+ }
363
+ }
@@ -21,6 +21,96 @@ import { renderPreexistingAtBaseGuidance, renderWorkerVerificationGuidance, rend
21
21
  import { CiFixContext, ExecutorNamedError } from "./job-errors.js";
22
22
  import { EPIC_WORKAROUNDS_DIR, epicWorkaroundRecordPath } from "../epic-workarounds-path.js";
23
23
  import { WORKER_BACKGROUND_WORK_RULE } from "./required-work-diagnostics.js";
24
+ import { validateEpicCapabilityStatement } from "../epic-capability-statement.js";
25
+ import { epicServerAcquireCommandSeconds } from "./epic-server-context.js";
26
+ import { EPIC_SERVER_DEFAULT_TIMING } from "../conductor/epic-server-recipe.js";
27
+ import { buildSfccWorkerPolicyText } from "../conductor/epic-server-sfcc.js";
28
+ /**
29
+ * BAPI-1546: the epic-server turn paragraph, a SEPARATE builder so the
30
+ * workaround contract ({@link buildEpicWorkaroundWorkerInstruction}) stays
31
+ * byte-identical. Appended beside it only when the repository opted in:
32
+ * `disabled` returns null and the caller appends nothing.
33
+ *
34
+ * - local, live: acquire a bounded turn through the own-build launcher, with
35
+ * the running helper's own turn wait (from its proven recipe) and the longest
36
+ * the command can take (that wait plus the rebuild budget), run the
37
+ * check against the printed address with the printed login file, release with
38
+ * the printed lease, and bind the served SHA and generation in the evidence.
39
+ * A lost lease discards the observation. The spawn env raises the harness
40
+ * command ceiling to that same number (`withEpicServerEnv`).
41
+ * - local, unavailable: one bounded acquire attempt; its output is the
42
+ * `no_live_server` observation under the hand-off rules.
43
+ * - SFCC: own-branch uploads onto the shared active version, one fresh upload
44
+ * before the single retry, upload intervals, and the evidence label.
45
+ *
46
+ * Single-line and free of `;`, quotes, and apostrophes, like the paragraph it
47
+ * follows. A missing server is a hand-off; a check that ran and failed is a real
48
+ * failure.
49
+ */
50
+ export function buildEpicServerWorkerInstruction(context, ticketKey) {
51
+ if (context.kind === "disabled")
52
+ return null;
53
+ if (context.kind === "sfcc") {
54
+ const sfcc = buildSfccWorkerPolicyText(context.origin);
55
+ return /[;'"\r\n]/.test(sfcc) ? null : sfcc;
56
+ }
57
+ const ticket = ticketKey && /^[A-Z][A-Z0-9_]{0,19}-\d{1,9}$/.test(ticketKey) ? ticketKey : "<TICKET>";
58
+ const wait = context.kind === "local_live" ? context.turnWaitSeconds : EPIC_SERVER_DEFAULT_TIMING.acquire_wait_seconds;
59
+ const acquire = "epic-implementer epic-server turn acquire --ticket " + ticket + " --head <your full head SHA> --wait " + wait +
60
+ " (it can take up to " + epicServerAcquireCommandSeconds(context) + " seconds before it prints, so run it in the foreground " +
61
+ "with a command timeout at least that long)";
62
+ const handoff = "If acquire prints outcome unavailable with cause no_live_server, rerun the same command once as the corrected " +
63
+ "invocation. If that also fails, record the step escalated with a hand-off whose cause is no_live_server, quoting " +
64
+ "the command, its output, and your head SHA, and naming the next human step. Nothing parks for this. A failed " +
65
+ "assertion or an application error from a check that did run is a real verification failure, never a hand-off.";
66
+ const turnRules = "On success it prints url, served_sha, generation, login_file, and lease. Run the check against that url only, " +
67
+ "sign in with the KEY=VALUE pairs in login_file, and never print, log, or commit them. Then run " +
68
+ "epic-implementer epic-server turn release --lease <the printed lease>. Write served_sha and generation into the " +
69
+ "step evidence. If release reports outcome lost, the turn expired or a newer generation fenced it: discard that " +
70
+ "observation, then acquire again and rerun, or record the hand-off below. Never record a lost observation as " +
71
+ "executed, and do not poll the lease in the background.";
72
+ let line;
73
+ if (context.kind === "local_live") {
74
+ line =
75
+ "Epic server: this run has one local epic server for e2e_tests and rendered_ui_review steps, shared by turns. " +
76
+ "Before each such check, take a bounded turn at your own head with " + acquire + " through the epic-implementer " +
77
+ "launcher on your PATH. " + turnRules + " " + handoff;
78
+ }
79
+ else {
80
+ line =
81
+ "Epic server: this run opted in to a local epic server, but it was not running when this worker started. For an " +
82
+ "e2e_tests or rendered_ui_review step, make one bounded attempt with " + acquire + " through the epic-implementer " +
83
+ "launcher on your PATH. If it is granted, follow the turn rules. " + turnRules + " Otherwise its output is the " +
84
+ "observation. " + handoff;
85
+ }
86
+ return /[;'"\r\n]/.test(line) ? null : line;
87
+ }
88
+ /**
89
+ * BAPI-1545: one advisory line telling an implement worker what the repository
90
+ * owner configured: the approved extra MCP servers, the epic-server mode, and
91
+ * the epic-server recipe state. Appended right after
92
+ * {@link buildEpicWorkaroundWorkerInstruction}, which stays byte-identical.
93
+ *
94
+ * The statement is revalidated here. Anything malformed returns `null`, and the
95
+ * caller then appends nothing, so the prompt is byte-identical to a repository
96
+ * with no statement. The line is SINGLE-LINE and free of `;`, quotes, and
97
+ * apostrophes, like the instruction it follows. It describes configuration, not
98
+ * runtime proof: a capability that fails at runtime still goes through the
99
+ * workaround and verification hand-off rules, never a claimed pass.
100
+ */
101
+ export function buildEpicCapabilityStatementWorkerInstruction(statement) {
102
+ const valid = validateEpicCapabilityStatement(statement);
103
+ if (valid === null)
104
+ return null;
105
+ const servers = valid.approved_servers.length > 0 ? valid.approved_servers.join(", ") : "none";
106
+ const line = "Capability statement from the repository owner setup, advisory configuration only and not proof " +
107
+ "that anything works at runtime: approved extra MCP servers are " + servers + ". The MCP grant is " +
108
+ valid.grant_state + ". The epic server mode is " + valid.epic_server_mode + " and its recipe is " +
109
+ valid.recipe + ". Treat anything listed as none, absent, unusable, or unknown as unavailable. If a " +
110
+ "check needs an unavailable or failing capability, follow the workaround and verification hand-off " +
111
+ "rules above and never report that check as passed.";
112
+ return /[;'"\r\n]/.test(line) ? null : line;
113
+ }
24
114
  /**
25
115
  * BAPI-1399 — the workaround contract for a PR-producing Epic Implementer worker.
26
116
  *
@@ -51,6 +141,12 @@ import { WORKER_BACKGROUND_WORK_RULE } from "./required-work-diagnostics.js";
51
141
  * failure. Review steps always run and are recorded executed. The server alone
52
142
  * decides whether a hand-off counts, from persisted run state.
53
143
  *
144
+ * BAPI-1609 adds `not_applicable` for a pre-PR step, review steps included, with
145
+ * genuinely nothing to verify (optional `rule_hint` and `target_path`). It is never
146
+ * admitted as a hand-off: the run carries it and the server labels the claim. The
147
+ * guidance also separates `no_database` (none provided or reachable) from a
148
+ * provided-but-broken database, and says a database nudge never rejects the record.
149
+ *
54
150
  * BAPI-1533 puts a test invocation rule ahead of that order: a selector that
55
151
  * collects zero tests is an invocation error (never a pass, never a missing
56
152
  * capability), every affected test-running step is rerun from the repository
@@ -107,6 +203,9 @@ export function buildEpicWorkaroundWorkerInstruction(ticketKey, handoffEnabled)
107
203
  "check before it produced any result, both on your first invocation and on the corrected rerun" + allowsClause +
108
204
  ", record the step escalated with a handoff object of exactly six fields. The cause is one of " +
109
205
  "no_live_server, no_database, toolchain_unavailable, credential_unavailable, or mcp_unavailable. " +
206
+ "no_database means no database was provided or reachable for the job. A database that was provided " +
207
+ "but is broken (a missing extension, a failed migration, a refused connection) is a verification " +
208
+ "failure, not that cause. " +
110
209
  "The criterion is the affected acceptance criterion. The observation names the command you first " +
111
210
  "ran and the missing capability it hit. The corrected_invocation names the corrected rerun and the " +
112
211
  "missing capability it hit. The observed_head_sha is the full head SHA both ran against, and it must " +
@@ -116,11 +215,24 @@ export function buildEpicWorkaroundWorkerInstruction(ticketKey, handoffEnabled)
116
215
  "A failed assertion, an " +
117
216
  "application error from a check that did run, and unfinished implementation or test authoring stay " +
118
217
  "blockers, and an unclear failure stays an ordinary escalation. Only those three step classes may be " +
119
- "handed off. Neither you nor the server turns an ordinary escalation into a hand-off, and you never " +
218
+ "handed off with a missing-capability cause. Neither you nor the server turns an ordinary escalation into a hand-off, and you never " +
120
219
  "invent a missing capability observation. Review steps (test_gap_review, " +
121
220
  "final_plan_review, and combined_review_test) always run, acknowledge the handed-off criterion from " +
122
221
  "that escalated record and the workaround record written in the same job, and are recorded executed, " +
123
- "never handed off. A hand-off counts only at the head it observed, so a new head needs a fresh " +
222
+ "never handed off with a capability cause. The one exception is not_applicable, described next. " +
223
+ "Nothing to verify: for any pre-PR step, review steps included, that has genuinely nothing to check " +
224
+ "for this ticket (a rendered-UI review when no rendered file changes, a named test target that does " +
225
+ "not exist and that no step creates, or zero tests collected after your corrected rerun), record it " +
226
+ "escalated with a handoff of the same six fields and cause not_applicable. You may add rule_hint " +
227
+ "(no_rendered_surface, target_absent, or zero_tests) and, with target_absent, target_path (the " +
228
+ "repository-relative path). Not applicable is never for unfinished implementation or a check you " +
229
+ "could not run, and a step that already failed keeps its plain escalation. Recording a step you cannot " +
230
+ "do, honestly, keeps the run moving: this run carries it to the integration pull request list instead " +
231
+ "of parking the ticket, and the server labels the claim afterwards. A not_applicable record never " +
232
+ "counts as a hand-off. If the reply advises that the executor provisioned a job database after you " +
233
+ "claimed no_database, the record is still accepted and need not be withdrawn. Check the database " +
234
+ "settings in your own environment and run the step if the database works. " +
235
+ "A hand-off counts only at the head it observed, so a new head needs a fresh " +
124
236
  "observation. A step that already failed at one head can be handed off only from a new head, " +
125
237
  "never at the head where it failed." +
126
238
  (handoffEnabled === true ? " " + renderPreexistingAtBaseGuidance(record) : ""));
@@ -52,6 +52,7 @@ import { classifyMergeTree } from "./merge-tree-classifier.js";
52
52
  import { RECONCILE_OVERLAP_PAYLOAD_SCHEMA_VERSION, } from "./reconcile-overlap-types.js";
53
53
  import { runRequiredVerificationCommands } from "./required-verification.js";
54
54
  import { validateWorkerFinalization } from "./worker-finalization.js";
55
+ import { payloadWorkerDatabaseConfigOption } from "./worker-database-config.js";
55
56
  export const RECONCILE_OVERLAP_JOB_TYPE = "reconcile_overlap";
56
57
  /** Result-envelope bounds, mirrored from the server's result model. */
57
58
  export const RECONCILE_EDITED_PATHS_MAX = 40;
@@ -256,9 +257,10 @@ export function validateReconcileOverlapPayload(job) {
256
257
  conflictReportPath,
257
258
  prompt,
258
259
  reconcileGeneration: generation,
259
- workerEnvOption: Object.prototype.hasOwnProperty.call(payload, "worker_env")
260
- ? { workerEnv: payload.worker_env }
261
- : {},
260
+ workerEnvOption: {
261
+ ...(Object.prototype.hasOwnProperty.call(payload, "worker_env") ? { workerEnv: payload.worker_env } : {}),
262
+ ...payloadWorkerDatabaseConfigOption(payload),
263
+ },
262
264
  },
263
265
  };
264
266
  }
@@ -25,6 +25,8 @@ export const COMPLETION_WINDOW_CLOSED_ON_LIVE_AGENT = "completion_window_closed_
25
25
  * rule about WHEN to report, not a demand to cancel productive background work:
26
26
  * the worker either waits for what it started or stops it, then reports. Shared
27
27
  * by the generic prompt assembly and the Claude held-stdin guidance, which
28
- * composes it at most once.
28
+ * composes it at most once. It is guidance only: it adds no diagnostic and no
29
+ * completion gate.
29
30
  */
30
- export const WORKER_BACKGROUND_WORK_RULE = "Do not post a final result while a sub-agent or background task you started is still running; wait for it or stop it.";
31
+ export const WORKER_BACKGROUND_WORK_RULE = "Before you write `.conductor/result.json`, post a final result, or end the turn, wait for or stop every " +
32
+ "background task and sub-agent you started in this session. Never end your job with your own task still running.";