@bridge_gpt/mcp-server 0.2.70 → 0.2.72

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 (134) hide show
  1. package/README.md +55 -17
  2. package/build/agent-launchers/claude-executor-adapter.js +29 -4
  3. package/build/agent-notes.js +171 -95
  4. package/build/agent-registry.js +5 -5
  5. package/build/agents.generated.js +12 -2
  6. package/build/bounded-wait.js +9 -1
  7. package/build/bridge-permissions.js +17 -5
  8. package/build/bridge-worktree-inspection.js +237 -0
  9. package/build/check-evidence.js +6 -0
  10. package/build/claude-review-workflow.js +1 -1
  11. package/build/cli-help.js +6 -0
  12. package/build/codex-auto-recovery.js +126 -0
  13. package/build/codex-skill-adapter.js +2 -0
  14. package/build/commands.generated.js +5 -5
  15. package/build/conductor/bridge-api-client.js +776 -23
  16. package/build/conductor/command-drift-production.js +7 -2
  17. package/build/conductor/doctor.js +93 -13
  18. package/build/conductor/epic-implementer-cli.js +55 -2
  19. package/build/conductor/gate-discovery.js +659 -19
  20. package/build/conductor/gate-settings-review.js +751 -0
  21. package/build/conductor/git-hooks-uninstall.js +112 -0
  22. package/build/conductor/git-hooks.js +81 -15
  23. package/build/conductor/guided-repair.js +10 -1
  24. package/build/conductor/install-doctor.js +2 -4
  25. package/build/conductor/launch-need-probes.js +16 -11
  26. package/build/conductor/launch-plan.js +185 -0
  27. package/build/conductor/local-merge.js +12 -1
  28. package/build/conductor/merge-execution-contract.js +1 -1
  29. package/build/conductor/merged-child-check.js +2 -1
  30. package/build/conductor/precheck-timings.js +14 -0
  31. package/build/conductor/prerequisite-inputs.js +379 -0
  32. package/build/conductor/preview-observations.js +10 -0
  33. package/build/conductor/readiness-assessment.js +78 -0
  34. package/build/conductor/readiness-cli.js +10 -0
  35. package/build/conductor/readiness-prerequisites.js +53 -0
  36. package/build/conductor/readiness-sections.js +25 -9
  37. package/build/conductor/readiness.js +20 -2
  38. package/build/conductor/recovery-cli.js +281 -14
  39. package/build/conductor/recovery-operations.js +78 -5
  40. package/build/conductor/repair-contract.js +33 -0
  41. package/build/conductor/tools.js +34 -3
  42. package/build/conductor/wait-run-attention.js +115 -0
  43. package/build/conductor/wait-run-cli.js +96 -3
  44. package/build/conductor/worker-database-doctor-inspector.js +1 -0
  45. package/build/credential-store.js +25 -20
  46. package/build/dependency-install-declarations.js +157 -0
  47. package/build/docs.generated.js +4 -4
  48. package/build/doctor.js +37 -5
  49. package/build/drive-epic-help.js +2 -2
  50. package/build/drive-epic.js +240 -56
  51. package/build/epic-ci-workflow-drift.js +71 -23
  52. package/build/epic-ci-workflow-install.js +83 -26
  53. package/build/epic-ci-workflow-v1.js +132 -0
  54. package/build/epic-ci-workflow.js +174 -13
  55. package/build/epic-implementer-bin.js +119 -44
  56. package/build/epic-launch-profile.js +1 -1
  57. package/build/executor/ci-rerun-job.js +220 -14
  58. package/build/executor/cli.js +2 -0
  59. package/build/executor/completion-contract.js +16 -0
  60. package/build/executor/credentials.js +1 -1
  61. package/build/executor/delivery-observations.js +113 -0
  62. package/build/executor/delivery-outcome.js +30 -0
  63. package/build/executor/dependency-refresh-runner.js +132 -0
  64. package/build/executor/dependency-refresh.js +530 -0
  65. package/build/executor/deps.js +4 -0
  66. package/build/executor/env.js +274 -5
  67. package/build/executor/gate-qualification-job.js +20 -5
  68. package/build/executor/harness-coverage.js +19 -0
  69. package/build/executor/http-client.js +35 -1
  70. package/build/executor/index.js +2 -1
  71. package/build/executor/install-preflight.js +1 -1
  72. package/build/executor/job-runner.js +355 -36
  73. package/build/executor/likely-tests.js +100 -98
  74. package/build/executor/preflight.js +5 -0
  75. package/build/executor/process-containment.js +18 -0
  76. package/build/executor/prompt-spec.js +84 -15
  77. package/build/executor/reconcile-overlap-job.js +6 -1
  78. package/build/executor/required-verification.js +28 -0
  79. package/build/executor/required-work-diagnostics.js +30 -0
  80. package/build/executor/required-work-ledger.js +19 -1
  81. package/build/executor/results.js +42 -0
  82. package/build/executor/service-discovery.js +42 -0
  83. package/build/executor/service-lifecycle.js +109 -2
  84. package/build/executor/service-uninstall.js +205 -0
  85. package/build/executor/service-unit.js +5 -3
  86. package/build/executor/test-clock.js +3 -0
  87. package/build/executor/verification-hints.js +179 -0
  88. package/build/executor/worker-command.js +188 -1
  89. package/build/executor/worker-database.js +299 -40
  90. package/build/executor/worker-finalization.js +65 -10
  91. package/build/executor/worker-guard-hook.js +10 -2
  92. package/build/executor/worker-resources.js +12 -1
  93. package/build/executor/worker-verification-guidance.js +64 -0
  94. package/build/executor/worktree-inspection.js +42 -0
  95. package/build/github-sign-in.js +1 -1
  96. package/build/index.js +767 -310
  97. package/build/init.js +3 -3
  98. package/build/install-bridge-conductor-gate.js +416 -41
  99. package/build/install-bridge-conductor-setup.js +135 -32
  100. package/build/install-bridge-conductor.js +769 -353
  101. package/build/install-bridge.js +419 -124
  102. package/build/install-maintenance.js +104 -0
  103. package/build/install-reexec.js +1 -1
  104. package/build/local-cleanup.js +59 -0
  105. package/build/mcp-install-state.js +68 -2
  106. package/build/merge-workflow-install.js +22 -2
  107. package/build/package-script-semantics.js +10 -0
  108. package/build/pipeline-utils.js +1 -1
  109. package/build/pipelines.generated.js +6 -6
  110. package/build/plan-execution-ledger.js +171 -10
  111. package/build/plane/plane-freshness.js +12 -9
  112. package/build/plane/preflight.js +19 -0
  113. package/build/plane/terminal-run-cleanup.js +5 -1
  114. package/build/plane/terminal-run-status.js +4 -0
  115. package/build/printed-remedy-commands.js +31 -4
  116. package/build/readiness-check.js +1 -78
  117. package/build/readiness-prerequisites.generated.js +199 -0
  118. package/build/readme.generated.js +1 -1
  119. package/build/repository-toolchains.js +623 -0
  120. package/build/setup-change-policy.js +32 -0
  121. package/build/setup-epic.js +26 -9
  122. package/build/setup-question.js +62 -0
  123. package/build/start-tickets.js +4 -0
  124. package/build/test-command-detection.js +61 -80
  125. package/build/test-support/notes-fs.js +40 -0
  126. package/build/ticket-delivery-artifacts.js +7 -0
  127. package/build/ticket-delivery-enrollment.js +80 -4
  128. package/build/ticket-delivery-run-scope.js +128 -0
  129. package/build/version.generated.js +3 -3
  130. package/build/worker-guard-hook-bin.js +2 -2
  131. package/build/worktrees.js +105 -0
  132. package/docs/EPIC-IMPLEMENTER.md +43 -0
  133. package/docs/epic-implementer/getting-started.md +95 -14
  134. package/package.json +2 -2
@@ -75,6 +75,69 @@ import { INDEX_SCOPE_ENV_VAR, validateOptionalIndexScope } from "../index-scope-
75
75
  import { delimiter as PLATFORM_PATH_DELIMITER } from "node:path";
76
76
  import { EPIC_IMPLEMENTER_ENV_PREFIX, EPIC_IMPLEMENTER_NODE_PATH_ENV, LEGACY_EPIC_IMPLEMENTER_ENV_PREFIX, LEGACY_EPIC_IMPLEMENTER_NODE_PATH_ENV, } from "../epic-implementer-env.js";
77
77
  import { buildWorkerDatabaseEnv } from "./worker-database-target.js";
78
+ import { admitDependencyInstallDeclarations, normalizeCiDatabase, } from "../dependency-install-declarations.js";
79
+ /** Entry rules for a declared worker variable (BAPI-1520), rechecked by the executor. */
80
+ const MAX_WORKER_ENV_ENTRIES = 32;
81
+ const MAX_WORKER_ENV_VALUE_BYTES = 1024;
82
+ const WORKER_ENV_NAME_PATTERN = /^[A-Z_][A-Z0-9_]{0,63}$/;
83
+ /**
84
+ * Names a declared worker variable may never use. A SORTED COPY of
85
+ * `WORKER_ENV_RESERVED_NAMES_SORTED` in `api/library/epic_implementer/gate_profile.py`
86
+ * (the authority): `tests/fixtures/executor/worker_env_reserved_names.json` is held
87
+ * to that authority by a Python test and to this export by `env.test.ts`. The
88
+ * executor owns its own copy because it may import only an allowlisted set of
89
+ * conductor modules.
90
+ */
91
+ const WORKER_ENV_RESERVED_NAMES = [
92
+ "BASH_ENV",
93
+ "BRIDGE_SKIP_PREPUSH",
94
+ "CI",
95
+ LEGACY_EPIC_IMPLEMENTER_NODE_PATH_ENV,
96
+ "DATABASE_URL",
97
+ "EPIC_IMPLEMENTER_NODE_PATH",
98
+ "GH_TOKEN",
99
+ "GITHUB_MERGE_TOKEN",
100
+ "GITHUB_TOKEN",
101
+ "HOME",
102
+ "LANG",
103
+ "LC_ALL",
104
+ "LD_PRELOAD",
105
+ "LOGNAME",
106
+ "MAX_MCP_OUTPUT_TOKENS",
107
+ "NODE_OPTIONS",
108
+ "NO_COLOR",
109
+ "OPENAI_API_KEY",
110
+ "PATH",
111
+ "PGDATABASE",
112
+ "PGHOST",
113
+ "PGPASSFILE",
114
+ "PGPASSWORD",
115
+ "PGPORT",
116
+ "PGSERVICE",
117
+ "PGUSER",
118
+ "POSTGRES_DATABASE",
119
+ "POSTGRES_DB",
120
+ "POSTGRES_HOST",
121
+ "POSTGRES_PASSWORD",
122
+ "POSTGRES_PORT",
123
+ "POSTGRES_USER",
124
+ "SHELL",
125
+ "TEMP",
126
+ "TERM",
127
+ "TMP",
128
+ "TMPDIR",
129
+ "USER",
130
+ "XDG_CONFIG_HOME",
131
+ ];
132
+ /** Reserved name prefixes; a sorted copy of `WORKER_ENV_RESERVED_PREFIXES_SORTED`. */
133
+ const WORKER_ENV_RESERVED_PREFIXES = [
134
+ "ANTHROPIC_",
135
+ "BAPI_",
136
+ "BRIDGE_",
137
+ "CLAUDE_",
138
+ "DYLD_",
139
+ "GIT_CONFIG_",
140
+ ];
78
141
  /** Non-secret operational keys forwarded to the worker when present. */
79
142
  const ALLOWED_ENV_KEYS = [
80
143
  "PATH",
@@ -121,7 +184,7 @@ export const WORKER_SENTINEL_DATABASE_ENV_KEYS = [
121
184
  "PGDATABASE",
122
185
  ];
123
186
  /**
124
- * CI's non-secret test values, injected into EVERY worker environment (BAPI-1479).
187
+ * Four non-secret BGPT_* compatibility values for legacy payloads without worker_env.
125
188
  *
126
189
  * These are the exact literals the Python lane of
127
190
  * `.github/workflows/epic-implementer-ci.yml` sets. They are throwaway CI values,
@@ -141,10 +204,184 @@ export const CI_WORKER_ENV_CONSTANTS = Object.freeze({
141
204
  BGPT_DEMO_SECRET: "test-demo-secret",
142
205
  BGPT_SESSION_SECRET: "test-session-secret",
143
206
  BGPT_INVITE_SECRET: "test-invite-secret",
144
- ENVIRONMENT: "LOCAL",
145
207
  });
208
+ /**
209
+ * BAPI-1521 — the ONE reserved-name policy for repository-declared worker
210
+ * variables. The exact names and prefixes are the sorted copies of
211
+ * `WORKER_ENV_RESERVED_NAMES_SORTED` / `WORKER_ENV_RESERVED_PREFIXES_SORTED` in
212
+ * `api/library/epic_implementer/gate_profile.py` (the authority; a drift test
213
+ * compares them). Every caller that applies a declaration depends on this export
214
+ * rather than keeping its own list.
215
+ *
216
+ * The executor-owned keys this builder sets or denies (`EXPLICIT_DENY_KEYS`, the
217
+ * allowlisted process names, the database keys `buildWorkerDatabaseEnv` emits)
218
+ * are all covered by those names and prefixes; {@link isWorkerEnvNameReserved}
219
+ * additionally checks `EXPLICIT_DENY_KEYS` and `ALLOWED_ENV_KEYS` so a future
220
+ * executor-owned key cannot be overwritten before the Python list catches up.
221
+ */
222
+ export const WORKER_ENV_RESERVED_POLICY = Object.freeze({
223
+ names: WORKER_ENV_RESERVED_NAMES,
224
+ prefixes: WORKER_ENV_RESERVED_PREFIXES,
225
+ });
226
+ /** True when a declared worker variable may not use `name`. */
227
+ export function isWorkerEnvNameReserved(name) {
228
+ return (WORKER_ENV_RESERVED_POLICY.names.includes(name) ||
229
+ WORKER_ENV_RESERVED_POLICY.prefixes.some((prefix) => name.startsWith(prefix)) ||
230
+ EXPLICIT_DENY_KEYS.includes(name) ||
231
+ ALLOWED_ENV_KEYS.includes(name));
232
+ }
233
+ /**
234
+ * The `{ workerEnv }` option a job payload implies: present exactly when the
235
+ * payload OWNS a `worker_env` key (whatever its value), empty otherwise. Spread it
236
+ * into an options object so absence stays absence. Never reads the value.
237
+ */
238
+ export function payloadWorkerEnvOption(payload) {
239
+ if (typeof payload !== "object" || payload === null || Array.isArray(payload))
240
+ return {};
241
+ if (!Object.prototype.hasOwnProperty.call(payload, "worker_env"))
242
+ return {};
243
+ return { workerEnv: payload.worker_env };
244
+ }
245
+ /** Printed in place of a name that is not a safely printable variable name. */
246
+ const WORKER_ENV_UNPRINTABLE_NAME_LABEL = "(unprintable name)";
247
+ const LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
248
+ function logWorkerEnvSkip(name, reason) {
249
+ const label = typeof name === "string" && WORKER_ENV_NAME_PATTERN.test(name)
250
+ ? name
251
+ : WORKER_ENV_UNPRINTABLE_NAME_LABEL;
252
+ console.error(`executor: skipped declared worker variable ${label}: ${reason}`);
253
+ }
254
+ /**
255
+ * Validate a payload `worker_env` declaration against the server's entry rules
256
+ * (BAPI-1520) and return the entries safe to assign. Never throws: an invalid or
257
+ * over-bound entry is skipped with a closed reason and a sanitized name, and the
258
+ * rest of the list still applies. The first occurrence of a name wins.
259
+ *
260
+ * `taken` holds keys the executor already owns in the environment under
261
+ * construction; a declaration naming one is skipped as reserved.
262
+ */
263
+ export function validateWorkerEnvDeclarations(raw, taken = new Set()) {
264
+ if (!Array.isArray(raw)) {
265
+ // Field name only: never the received value.
266
+ console.error("executor: worker_env is present but is not a list; applying no declarations");
267
+ return [];
268
+ }
269
+ const accepted = [];
270
+ const seen = new Set();
271
+ for (let index = 0; index < raw.length; index++) {
272
+ if (index >= MAX_WORKER_ENV_ENTRIES) {
273
+ logWorkerEnvSkip(undefined, "worker_env_over_bound");
274
+ break;
275
+ }
276
+ const item = raw[index];
277
+ if (typeof item !== "object" || item === null || Array.isArray(item)) {
278
+ logWorkerEnvSkip(undefined, "worker_env_invalid_entry");
279
+ continue;
280
+ }
281
+ const entry = item;
282
+ const name = entry.name;
283
+ if (typeof name !== "string" || !WORKER_ENV_NAME_PATTERN.test(name)) {
284
+ logWorkerEnvSkip(name, "worker_env_invalid_name");
285
+ continue;
286
+ }
287
+ const value = entry.value;
288
+ if (typeof value !== "string" || LONE_SURROGATE.test(value) || /[\u0000\r\n]/.test(value)) {
289
+ logWorkerEnvSkip(name, "worker_env_invalid_value");
290
+ continue;
291
+ }
292
+ if (Buffer.byteLength(value, "utf8") > MAX_WORKER_ENV_VALUE_BYTES) {
293
+ logWorkerEnvSkip(name, "worker_env_over_bound");
294
+ continue;
295
+ }
296
+ const flag = entry.committed_literal;
297
+ if (flag !== undefined && typeof flag !== "boolean") {
298
+ logWorkerEnvSkip(name, "worker_env_invalid_entry");
299
+ continue;
300
+ }
301
+ if (isWorkerEnvNameReserved(name) || taken.has(name)) {
302
+ logWorkerEnvSkip(name, "worker_env_reserved_name");
303
+ continue;
304
+ }
305
+ if (isSecretLookingWorkerEnvName(name) && flag !== true) {
306
+ logWorkerEnvSkip(name, "worker_env_secret_name");
307
+ continue;
308
+ }
309
+ if (seen.has(name)) {
310
+ logWorkerEnvSkip(name, "worker_env_duplicate");
311
+ continue;
312
+ }
313
+ seen.add(name);
314
+ accepted.push({ name, value });
315
+ }
316
+ return accepted;
317
+ }
318
+ /**
319
+ * BAPI-1551 — the environment a declared dependency install runs with: the
320
+ * sentinel worker environment plus the payload's declared worker variables. It
321
+ * carries no credential and never the operator's database. Built here so the
322
+ * job runner never constructs a worker environment itself.
323
+ */
324
+ export function buildDependencyInstallEnv(parentEnv, payload) {
325
+ return buildExecutorBaseWorkerEnv(parentEnv, { ...payloadWorkerEnvOption(payload), legacyNotice: false });
326
+ }
327
+ /**
328
+ * BAPI-1551 — the `{ dependencyInstall }` option a job payload implies: present
329
+ * exactly when the payload OWNS a `dependency_install` key. Never reads the value.
330
+ */
331
+ export function payloadDependencyInstallOption(payload) {
332
+ if (typeof payload !== "object" || payload === null || Array.isArray(payload))
333
+ return {};
334
+ if (!Object.prototype.hasOwnProperty.call(payload, "dependency_install"))
335
+ return {};
336
+ return { dependencyInstall: payload.dependency_install };
337
+ }
338
+ /** BAPI-1551 — the `{ ciDatabase }` option, present exactly when the payload owns `ci_database`. */
339
+ export function payloadCiDatabaseOption(payload) {
340
+ if (typeof payload !== "object" || payload === null || Array.isArray(payload))
341
+ return {};
342
+ if (!Object.prototype.hasOwnProperty.call(payload, "ci_database"))
343
+ return {};
344
+ return { ciDatabase: payload.ci_database };
345
+ }
346
+ /** BAPI-1551 — the payload's `ci_database`, with anything other than the three values (or absence) read as `unknown`. */
347
+ export function payloadCiDatabase(payload) {
348
+ return normalizeCiDatabase(payloadCiDatabaseOption(payload).ciDatabase);
349
+ }
350
+ /**
351
+ * BAPI-1551 — validate a payload `dependency_install` declaration against the
352
+ * server's entry rules and return the entries safe to run. Never throws: an
353
+ * invalid entry is skipped with a closed reason, logged with its `cwd` only when
354
+ * that `cwd` passed the path rules, and never with an argv item.
355
+ */
356
+ export function validateDependencyInstallDeclarations(raw, errorLog = (message) => console.error(message)) {
357
+ let admitted;
358
+ try {
359
+ admitted = admitDependencyInstallDeclarations(raw);
360
+ }
361
+ catch {
362
+ admitted = { entries: [], skipped: [], notAList: true };
363
+ }
364
+ const log = (message) => { try {
365
+ errorLog(message);
366
+ }
367
+ catch { /* sink */ } };
368
+ if (admitted.notAList) {
369
+ log("executor: dependency_install is present but is not a list; running no dependency refresh");
370
+ return [];
371
+ }
372
+ for (const skip of admitted.skipped) {
373
+ const where = skip.cwd !== undefined ? ` for ${skip.cwd}` : "";
374
+ log(`executor: skipped declared dependency refresh${where}: ${skip.reason}`);
375
+ }
376
+ return admitted.entries;
377
+ }
146
378
  /** Substrings that mark a key as secret-bearing (case-insensitive). */
147
379
  const SECRET_NAME_FRAGMENTS = ["TOKEN", "SECRET", "PASSWORD", "API_KEY"];
380
+ /** True when `name` looks secret, so a declaration of it needs `committed_literal: true`. */
381
+ function isSecretLookingWorkerEnvName(name) {
382
+ const upper = name.toUpperCase();
383
+ return SECRET_NAME_FRAGMENTS.some((fragment) => upper.includes(fragment));
384
+ }
148
385
  /**
149
386
  * Explicit deny-list of known secret / MCP / conductor keys.
150
387
  *
@@ -166,6 +403,11 @@ export const EXPLICIT_DENY_KEYS = [
166
403
  // launched the executor must never reach a worker: whoever chose the tag
167
404
  // could make an unrelated process look job-owned to the cleanup sweep.
168
405
  "BRIDGE_EXECUTOR_JOB_TAG",
406
+ // BAPI-1544: the claimed executor job's ID. Like the ownership tag it is
407
+ // injected AFTER this builder and the agent adapter have run (`job-runner.ts`,
408
+ // from the claimed job row), so an ambient value, a job payload, or an adapter
409
+ // can never choose which job a worker registers its delivery binding against.
410
+ "BRIDGE_EXECUTOR_JOB_ID",
169
411
  EPIC_IMPLEMENTER_NODE_PATH_ENV,
170
412
  // BAPI-1190: the legacy spelling stays denied so a stale ambient value from an
171
413
  // older package can never reach a worker during a version-skew window.
@@ -318,6 +560,10 @@ export function isExecutorEnvKeyAllowed(key) {
318
560
  return false;
319
561
  return true;
320
562
  }
563
+ /** True when the options object owns a `workerEnv` property (value irrelevant). */
564
+ export function hasWorkerEnvOption(options) {
565
+ return options !== undefined && Object.prototype.hasOwnProperty.call(options, "workerEnv");
566
+ }
321
567
  export function buildExecutorBaseWorkerEnv(parentEnv, options = {}) {
322
568
  const env = {};
323
569
  for (const key of ALLOWED_ENV_KEYS) {
@@ -345,8 +591,17 @@ export function buildExecutorBaseWorkerEnv(parentEnv, options = {}) {
345
591
  Object.assign(env, buildWorkerDatabaseEnv(options.workerDatabase));
346
592
  }
347
593
  // BAPI-1479 — CI's throwaway test values, from constants and never from
348
- // `parentEnv`, for every job type and every adapter.
349
- Object.assign(env, CI_WORKER_ENV_CONSTANTS);
594
+ // `parentEnv`, for every job type and every adapter. BAPI-1521: only when the
595
+ // payload did not carry a `worker_env` declaration at all. A present declaration
596
+ // — even an empty or malformed one — replaces the constants, so a repository
597
+ // that cleared its variables gets none, not the legacy defaults.
598
+ const workerEnvPresent = hasWorkerEnvOption(options);
599
+ if (!workerEnvPresent) {
600
+ if (options.legacyNotice !== false) {
601
+ console.error("executor: payload carries no worker_env; applying legacy compatibility constants");
602
+ }
603
+ Object.assign(env, CI_WORKER_ENV_CONSTANTS);
604
+ }
350
605
  // BAPI-1479 — the own-build launcher directory goes FIRST on PATH, from the
351
606
  // explicit option only. The inherited PATH follows it unchanged; an empty or
352
607
  // absent inherited PATH adds no empty component (an empty component means
@@ -392,12 +647,25 @@ export function buildExecutorBaseWorkerEnv(parentEnv, options = {}) {
392
647
  if (Array.isArray(options.declaredTouchedFiles)) {
393
648
  env[DECLARED_TOUCHED_FILES_ENV] = JSON.stringify(normalizeDeclaredTouchedFiles(options.declaredTouchedFiles));
394
649
  }
650
+ // BAPI-1521 — repository-declared variables go in LAST among the base keys and
651
+ // can never overwrite a key the executor already owns in `env`.
652
+ if (workerEnvPresent) {
653
+ const taken = new Set(Object.keys(env));
654
+ for (const { name, value } of validateWorkerEnvDeclarations(options.workerEnv, taken)) {
655
+ env[name] = value;
656
+ }
657
+ }
395
658
  // Nothing agent-specific is added here, and deliberately nothing secret. An
396
659
  // adapter that needs to forward an operator-owned credential declares it as a
397
660
  // passthrough and copies it onto the object this function returns; see
398
661
  // `buildClaudeWorkerEnv`. Keeping the base free of every credential is what
399
662
  // makes "which secrets can reach a worker?" answerable per adapter instead of
400
663
  // per call site.
664
+ // Loopback worker PostgreSQL has SSL disabled. Apply the compatibility default
665
+ // AFTER validating declarations so ENVIRONMENT remains repository-overridable
666
+ // and an ambient host value can never choose the worker's SSL policy. Alembic
667
+ // uses this same builder, including for empty or legacy declarations.
668
+ env.ENVIRONMENT ??= "LOCAL";
401
669
  return env;
402
670
  }
403
671
  /**
@@ -417,5 +685,6 @@ export function buildExecutorBaseWorkerEnv(parentEnv, options = {}) {
417
685
  * capability probes are not filtered.
418
686
  */
419
687
  export function buildHeadlessAgentEnv(parentEnv) {
420
- return buildExecutorBaseWorkerEnv(parentEnv);
688
+ // BAPI-1521: not a job, so no legacy notice either; it keeps the constants silently.
689
+ return buildExecutorBaseWorkerEnv(parentEnv, { legacyNotice: false });
421
690
  }
@@ -219,7 +219,15 @@ export function parseGateQualificationPayload(job) {
219
219
  return refuse(MESSAGES.contract);
220
220
  return {
221
221
  ok: true,
222
- payload: { repoName: envelope.repo_name, revision: envelope.revision, commands, digest },
222
+ payload: {
223
+ repoName: envelope.repo_name,
224
+ revision: envelope.revision,
225
+ commands,
226
+ digest,
227
+ workerEnvOption: Object.prototype.hasOwnProperty.call(envelope, "worker_env")
228
+ ? { workerEnv: envelope.worker_env }
229
+ : {},
230
+ },
223
231
  };
224
232
  }
225
233
  // ---------------------------------------------------------------------------
@@ -386,6 +394,10 @@ export async function runGateQualificationJob(job, input, deps) {
386
394
  }, OWNERSHIP_POLL_MS);
387
395
  };
388
396
  watchOwnership();
397
+ // BAPI-1521 — the effective environment is built here, AFTER the envelope was
398
+ // verified and BEFORE any command runs, from the sealed declaration. The
399
+ // injected dependencies are never mutated.
400
+ const commandEnv = deps.commandEnv ?? buildGateQualificationEnv(deps.baseEnv ?? {}, payload.workerEnvOption);
389
401
  const commands = payload.commands.map((command) => ({
390
402
  identity: command.identity,
391
403
  position: command.position,
@@ -398,7 +410,7 @@ export async function runGateQualificationJob(job, input, deps) {
398
410
  const run = await runRequiredVerificationCommands({
399
411
  commands,
400
412
  worktreePath: dir,
401
- env: deps.commandEnv,
413
+ env: commandEnv,
402
414
  launch: deps.launch,
403
415
  now: deps.now,
404
416
  deadlineAtMs,
@@ -449,9 +461,12 @@ export async function runGateQualificationJob(job, input, deps) {
449
461
  * The explicit command environment: the executor's worker base environment
450
462
  * (allowlisted keys, parent credentials stripped, sentinel database values,
451
463
  * `BRIDGE_SKIP_PREPUSH=1`) plus `CI=1`, so test tooling runs non-interactively.
464
+ * BAPI-1521: the sealed declaration's `worker_env` is passed with its presence
465
+ * intact — absent keeps the compatibility constants, present replaces them.
452
466
  */
453
- export function buildGateQualificationEnv(parentEnv) {
454
- return { ...buildExecutorBaseWorkerEnv(parentEnv), CI: "1" };
467
+ export function buildGateQualificationEnv(parentEnv, workerEnvOption = {}) {
468
+ // BAPI-1521: `CI=1` is applied last, so a declaration can never turn it off.
469
+ return { ...buildExecutorBaseWorkerEnv(parentEnv, workerEnvOption), CI: "1" };
455
470
  }
456
471
  /**
457
472
  * Production dependencies built from the executor's own boundary.
@@ -480,7 +495,7 @@ export function createProductionGateQualificationDeps(input) {
480
495
  deps,
481
496
  ...(input.registerLive ? { registerLive: input.registerLive } : {}),
482
497
  }),
483
- commandEnv: buildGateQualificationEnv(deps.env),
498
+ baseEnv: deps.env,
484
499
  repoRoot: deps.cwd,
485
500
  fallbackBaseBranch: options.baseBranch,
486
501
  makeTempDir,
@@ -0,0 +1,19 @@
1
+ /** Validate at each projection boundary; legacy/malformed evidence grants nothing. */
2
+ export function sanitizeHarnessCoverage(value, total) {
3
+ if (typeof value !== "object" || value === null)
4
+ return undefined;
5
+ const c = value;
6
+ const count = (n) => typeof n === "number" && Number.isSafeInteger(n) && n >= 0;
7
+ if (!count(c.total) || (total !== undefined && c.total !== total) || !count(c.ciOwned) || c.ciOwned > c.total)
8
+ return undefined;
9
+ if (c.activity === "unknown") {
10
+ return c.inUse === null && c.covered === null && c.uncovered === null
11
+ ? { total: c.total, activity: "unknown", inUse: null, ciOwned: c.ciOwned, covered: null, uncovered: null }
12
+ : undefined;
13
+ }
14
+ if (c.activity !== "known" || !count(c.inUse) || !count(c.covered) || !count(c.uncovered) ||
15
+ c.inUse > c.total || c.covered + c.uncovered !== c.total ||
16
+ c.covered < Math.max(c.inUse, c.ciOwned) || c.covered > Math.min(c.total, c.inUse + c.ciOwned))
17
+ return undefined;
18
+ return { total: c.total, activity: "known", inUse: c.inUse, ciOwned: c.ciOwned, covered: c.covered, uncovered: c.uncovered };
19
+ }
@@ -8,7 +8,7 @@
8
8
  * logged and never included in any error string.
9
9
  */
10
10
  import { RECONCILER_LIVENESS_VALUES } from "./types.js";
11
- import { EXECUTOR_REPORTABLE_END_CAUSE_VALUES, } from "./completion-contract.js";
11
+ import { EXECUTOR_REPORTABLE_END_CAUSE_VALUES, MAX_VERIFICATION_OBSERVATIONS, } from "./completion-contract.js";
12
12
  import { readEpicRunCompletionState, } from "../conductor/bridge-api-client.js";
13
13
  /** BAPI-1258 — the server's stable `error_code` for refused capacity evidence. */
14
14
  export const UNSUPPORTED_TERMINAL_CAPACITY_ERROR_CODE = "UNSUPPORTED_TERMINAL_CAPACITY";
@@ -128,6 +128,33 @@ export function envelopeForClaim(job, envelope) {
128
128
  const { end_cause: _omitted, ...rest } = envelope;
129
129
  return rest;
130
130
  }
131
+ /**
132
+ * BAPI-1563 — normalize a claim's `delivery_observations_capability`. Only the
133
+ * exact `{protocol_version: 1}` is admitted; absent, null, or anything else (an
134
+ * older server, a future protocol) reads as no capability.
135
+ */
136
+ export function normalizeDeliveryObservationsCapability(value) {
137
+ if (value === null || typeof value !== "object" || Array.isArray(value))
138
+ return null;
139
+ return value.protocol_version === 1 ? { protocol_version: 1 } : null;
140
+ }
141
+ /**
142
+ * BAPI-1563 — the observation fields of a terminal report, present ONLY when the
143
+ * claim advertised the capability. Without it both are omitted, so an older
144
+ * server's strict schema never sees an unknown key. This governs serialization
145
+ * and nothing else: no permission or success decision is derived from it, and a
146
+ * rejection is never parsed or resent.
147
+ */
148
+ function deliveryObservationFields(job, report) {
149
+ if (normalizeDeliveryObservationsCapability(job.delivery_observations_capability) === null)
150
+ return {};
151
+ return {
152
+ ...(report.observed_pr !== undefined ? { observed_pr: report.observed_pr } : {}),
153
+ ...(report.verification_observations !== undefined && report.verification_observations.length > 0
154
+ ? { verification_observations: report.verification_observations.slice(0, MAX_VERIFICATION_OBSERVATIONS) }
155
+ : {}),
156
+ };
157
+ }
131
158
  /** Bound a server-provided diagnostic snippet included in error strings. */
132
159
  function boundedDetail(text) {
133
160
  const trimmed = (text ?? "").trim();
@@ -347,6 +374,11 @@ export function createExecutorHttpClient(config) {
347
374
  // BAPI-1421 (F4): only recognized executor-reportable end causes are
348
375
  // kept; an older server's absent key becomes an empty list.
349
376
  job.end_cause_capability = normalizeEndCauseCapability(job.end_cause_capability);
377
+ // BAPI-1563: the observation capability is normalized in place only when
378
+ // the server sent the key, so an older server's claim keeps its shape.
379
+ if ("delivery_observations_capability" in job) {
380
+ job.delivery_observations_capability = normalizeDeliveryObservationsCapability(job.delivery_observations_capability);
381
+ }
350
382
  job.prior_attempt_head_sha = normalizePriorAttemptHeadSha(job.prior_attempt_head_sha, () => (config.warn ?? ((message) => console.error(message)))(`executor: ignoring malformed prior attempt head in the claim for job ${String(job.id)}; ` +
351
383
  `treating it as a first dispatch.`));
352
384
  return { kind: "claimed", job, reconcilerLiveness };
@@ -504,6 +536,7 @@ export function createExecutorHttpClient(config) {
504
536
  last_commit_sha: completion.last_commit_sha,
505
537
  telemetry: completion.telemetry,
506
538
  ...completionContractFields(job, completion),
539
+ ...deliveryObservationFields(job, completion),
507
540
  };
508
541
  return mutate(`/${job.id}/complete`, body, true, job.repo_name);
509
542
  },
@@ -521,6 +554,7 @@ export function createExecutorHttpClient(config) {
521
554
  last_commit_sha: failure.last_commit_sha,
522
555
  telemetry: failure.telemetry,
523
556
  ...completionContractFields(job, failure),
557
+ ...deliveryObservationFields(job, failure),
524
558
  };
525
559
  if (failure.capacity_evidence === undefined) {
526
560
  return mutate(`/${job.id}/fail`, body, false, job.repo_name);
@@ -17,7 +17,7 @@ export { runExecutor } from "./runner.js";
17
17
  // imports the generator still cannot start a persistent daemon.
18
18
  export { runExecutorInstallServiceCli, getExecutorInstallServiceUsage, buildExecutorServiceArtifact, writeExecutorServiceArtifact, inspectExecutorServiceArtifact, executorLaunchdDirForHome, executorSystemdDirForHome, executorIdFromLaunchdFilename, executorIdFromSystemdFilename,
19
19
  // Programmatic, lifecycle-free plan/write seam (BAPI-779) — how
20
- // `install conductor` reaches the generator without shelling out to the CLI.
20
+ // `install epic-implementer` reaches the generator without shelling out to the CLI.
21
21
  planExecutorServiceInstall, writeExecutorServicePlan, resolvePackagedExecutorInvocation,
22
22
  // Durable-host credential declaration contract (BAPI-1137, R-4). doctor needs
23
23
  // the shared inspector and the postcondition helper so its diagnostic and the
@@ -25,6 +25,7 @@ planExecutorServiceInstall, writeExecutorServicePlan, resolvePackagedExecutorInv
25
25
  // and the argument-contract predicate keeps the contract locally auditable
26
26
  // rather than discoverable only by reading the renderer.
27
27
  inspectExecutorServiceCredentialDeclaration, assertExecutorServiceCredentialPostcondition, checkExecutorServiceArgumentContract, isAllowedExecutorServiceUnitEnvKey, executorLaunchdLogPathsForId, EXECUTOR_SERVICE_BASE_URL_ENV, EXECUTOR_SERVICE_PATH_ENV, EXECUTOR_SERVICE_UNIT_ENV_ALLOWLIST, EXECUTOR_SERVICE_UNIT_FILE_MODE, } from "./service-unit.js";
28
+ export { discoverExecutorServiceUnits } from "./service-discovery.js";
28
29
  // Consented lifecycle (BAPI-779, R-1). Deliberately a SEPARATE module from the
29
30
  // generator above: importing the writer never grants the ability to start a
30
31
  // persistent daemon.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Executor installation preflight for `install conductor` (BAPI-779).
2
+ * Executor installation preflight for `install epic-implementer` (BAPI-779).
3
3
  *
4
4
  * This is the gate that runs BEFORE the installer writes a service unit or
5
5
  * starts anything: it answers "can this host actually run a conductor executor?"