@bridge_gpt/mcp-server 0.2.71 → 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.
- package/README.md +55 -17
- package/build/agent-launchers/claude-executor-adapter.js +22 -3
- package/build/agent-notes.js +171 -95
- package/build/agents.generated.js +7 -7
- package/build/bridge-permissions.js +31 -0
- package/build/bridge-worktree-inspection.js +237 -0
- package/build/check-evidence.js +6 -0
- package/build/ci-system-detection.js +50 -0
- package/build/ci-trigger-adapters.js +631 -0
- package/build/ci-trigger-install.js +106 -0
- package/build/claude-review-workflow.js +1 -1
- package/build/cli-help.js +6 -0
- package/build/codex-auto-recovery.js +126 -0
- package/build/codex-launcher-pin.js +33 -2
- package/build/codex-skill-adapter.js +5 -1
- package/build/command-host.js +33 -0
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +1352 -50
- package/build/conductor/bring-up-facts.js +18 -5
- package/build/conductor/command-drift-production.js +42 -17
- package/build/conductor/command-drift.js +47 -0
- package/build/conductor/declare-blocked.js +554 -0
- package/build/conductor/doctor.js +187 -28
- package/build/conductor/driver-commands.js +141 -0
- package/build/conductor/driver-guard.js +277 -0
- package/build/conductor/driver-lapse.js +321 -0
- package/build/conductor/driver-register.js +176 -0
- package/build/conductor/driver-release.js +174 -0
- package/build/conductor/driver-session-state.js +315 -0
- package/build/conductor/epic-branch-ci-inspection.js +222 -29
- package/build/conductor/epic-implementer-cli.js +213 -13
- package/build/conductor/epic-server-database.js +162 -0
- package/build/conductor/epic-server-guidance.js +278 -0
- package/build/conductor/epic-server-journal.js +239 -0
- package/build/conductor/epic-server-processes.js +324 -0
- package/build/conductor/epic-server-recipe.js +397 -0
- package/build/conductor/epic-server-runtime.js +1207 -0
- package/build/conductor/epic-server-sfcc.js +107 -0
- package/build/conductor/epic-server-state.js +427 -0
- package/build/conductor/epic-server.js +594 -0
- package/build/conductor/gate-discovery.js +281 -10
- package/build/conductor/gate-settings-review.js +525 -5
- package/build/conductor/git-hooks-uninstall.js +112 -0
- package/build/conductor/git-hooks.js +81 -15
- package/build/conductor/guided-repair.js +10 -1
- package/build/conductor/install-doctor.js +2 -4
- package/build/conductor/launch-need-probes.js +6 -53
- package/build/conductor/launch-plan.js +318 -121
- package/build/conductor/local-merge.js +12 -1
- package/build/conductor/merge-execution-contract.js +1 -1
- package/build/conductor/merged-child-check.js +2 -1
- package/build/conductor/prerequisite-inputs.js +1213 -0
- package/build/conductor/readiness-assessment.js +93 -0
- package/build/conductor/readiness-cli.js +30 -9
- package/build/conductor/readiness-prerequisites.js +77 -5
- package/build/conductor/readiness-sections.js +146 -126
- package/build/conductor/readiness.js +21 -3
- package/build/conductor/recovery-cli.js +236 -15
- package/build/conductor/recovery-operations.js +34 -4
- package/build/conductor/repair-contract.js +33 -0
- package/build/conductor/tools.js +36 -4
- package/build/conductor/wait-run-attention.js +115 -0
- package/build/conductor/wait-run-cli.js +300 -21
- package/build/conductor/worker-database-doctor-inspector.js +34 -2
- package/build/conductor/worker-setup-tally.js +27 -0
- package/build/credential-store.js +96 -21
- package/build/dependency-install-declarations.js +212 -0
- package/build/docs.generated.js +4 -4
- package/build/doctor.js +91 -8
- package/build/drive-epic-help.js +23 -4
- package/build/drive-epic.js +1841 -340
- package/build/engine-paths.js +20 -0
- package/build/epic-branch-ci-summary.js +140 -0
- package/build/epic-capability-statement.js +107 -0
- package/build/epic-ci-workflow-drift.js +30 -15
- package/build/epic-ci-workflow-install.js +110 -42
- package/build/epic-ci-workflow-v2.js +274 -0
- package/build/epic-ci-workflow.js +38 -12
- package/build/epic-implementer-bin.js +2184 -52
- package/build/epic-launch-context.js +607 -0
- package/build/epic-launch-profile.js +1 -1
- package/build/epic-server-record.js +273 -0
- package/build/epic-shared/bridge-client.js +11 -3
- package/build/escalation-reachability.js +43 -0
- package/build/executor/ci-fix-test-runs.js +334 -0
- package/build/executor/cli.js +2 -0
- package/build/executor/completion-contract.js +24 -1
- package/build/executor/credentials.js +1 -1
- package/build/executor/delivery-observations.js +113 -0
- package/build/executor/delivery-outcome.js +30 -0
- package/build/executor/dependency-refresh-runner.js +132 -0
- package/build/executor/dependency-refresh.js +530 -0
- package/build/executor/deps.js +4 -0
- package/build/executor/env.js +119 -17
- package/build/executor/epic-server-context.js +141 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/harness-coverage.js +19 -0
- package/build/executor/http-client.js +87 -6
- package/build/executor/index.js +2 -1
- package/build/executor/install-preflight.js +1 -1
- package/build/executor/job-runner.js +659 -87
- package/build/executor/likely-tests.js +94 -97
- package/build/executor/observation.js +8 -0
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +127 -5
- package/build/executor/reconcile-overlap-job.js +5 -3
- package/build/executor/required-verification.js +28 -0
- package/build/executor/required-work-diagnostics.js +32 -0
- package/build/executor/required-work-ledger.js +955 -39
- package/build/executor/results.js +100 -0
- package/build/executor/service-discovery.js +42 -0
- package/build/executor/service-lifecycle.js +109 -2
- package/build/executor/service-uninstall.js +205 -0
- package/build/executor/service-unit.js +5 -3
- package/build/executor/terminal-mutation.js +8 -0
- package/build/executor/test-clock.js +3 -0
- package/build/executor/verification-hints.js +179 -0
- package/build/executor/worker-command.js +126 -5
- package/build/executor/worker-database-config.js +281 -0
- package/build/executor/worker-database-target.js +16 -12
- package/build/executor/worker-database.js +575 -116
- package/build/executor/worker-finalization.js +71 -10
- package/build/executor/worker-guard-hook.js +10 -2
- package/build/executor/worker-resources.js +25 -3
- package/build/executor/worker-verification-guidance.js +55 -5
- package/build/executor/worktree-inspection.js +42 -0
- package/build/executor/worktree.js +20 -1
- package/build/executor-launch.js +54 -2
- package/build/generated-assets-catalog.js +2 -2
- package/build/github-sign-in.js +1 -1
- package/build/index.js +1111 -381
- package/build/init.js +29 -14
- package/build/install-bridge-conductor-answers.js +465 -0
- package/build/install-bridge-conductor-apply.js +259 -0
- package/build/install-bridge-conductor-assessment.js +895 -0
- package/build/install-bridge-conductor-compact.js +161 -0
- package/build/install-bridge-conductor-contracts.js +63 -0
- package/build/install-bridge-conductor-gate.js +1383 -188
- package/build/install-bridge-conductor-setup.js +637 -92
- package/build/install-bridge-conductor.js +3163 -740
- package/build/install-bridge.js +601 -128
- package/build/install-maintenance.js +127 -0
- package/build/install-reexec.js +1 -1
- package/build/launcher-config-inspection.js +162 -1
- package/build/local-cleanup.js +59 -0
- package/build/mcp-grant-candidates.js +767 -0
- package/build/mcp-grant-doctor.js +63 -0
- package/build/mcp-grant.js +288 -0
- package/build/mcp-host-targets.js +8 -0
- package/build/mcp-identity.js +23 -0
- package/build/mcp-install-state.js +68 -2
- package/build/mcp-invoke.js +126 -13
- package/build/mcp-presets.js +107 -0
- package/build/mcp-provisioning.js +134 -2
- package/build/mcp-registration-doctor.js +31 -2
- package/build/mcp-server-invocation.js +6 -1
- package/build/merge-workflow-install.js +236 -111
- package/build/package-script-semantics.js +10 -0
- package/build/pipeline-utils.js +1 -1
- package/build/pipelines.generated.js +6 -6
- package/build/plan-discovery.js +97 -4
- package/build/plan-execution-ledger.js +248 -9
- package/build/plan-generation-io.js +262 -0
- package/build/plan-generation.js +424 -0
- package/build/plane/build-freshness.js +6 -1
- package/build/plane/cli.js +75 -9
- package/build/plane/plane-freshness.js +23 -7
- package/build/plane/preflight.js +50 -10
- package/build/plane/shutdown.js +19 -0
- package/build/plane/terminal-run-cleanup.js +23 -5
- package/build/plane/terminal-run-status.js +4 -0
- package/build/printed-remedy-commands.js +229 -15
- package/build/readiness-check.js +1 -1
- package/build/readiness-prerequisites.generated.js +311 -4
- package/build/readme.generated.js +1 -1
- package/build/repository-state-paths.js +38 -0
- package/build/repository-toolchains.js +50 -8
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-change-policy.js +32 -0
- package/build/setup-epic.js +1192 -198
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +180 -0
- package/build/start-tickets.js +4 -0
- package/build/test-command-detection.js +32 -88
- package/build/test-support/notes-fs.js +40 -0
- package/build/third-party-mcp-targets.js +30 -0
- package/build/ticket-delivery-enrollment.js +30 -8
- package/build/ticket-delivery-run-scope.js +128 -0
- package/build/upgrade-cli.js +85 -2
- package/build/v2-readiness-requirements.js +28 -1
- package/build/version.generated.js +3 -3
- package/build/worker-guard-hook-bin.js +2 -2
- package/build/worktrees.js +105 -0
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
- package/docs/EPIC-IMPLEMENTER.md +5 -0
- package/docs/epic-implementer/getting-started.md +42 -15
- package/docs/epic-implementer/self-hosting.md +14 -1
- package/package.json +2 -2
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one contained reader of `.bridge/verification-hints.json` (BAPI-1551).
|
|
3
|
+
*
|
|
4
|
+
* Version 1 is `{version:1, pins?:[{paths:[...], tests:[...]}], always?:[...]}`.
|
|
5
|
+
* `pins` maps changed paths to tests (BAPI-1479). `always` (BAPI-1551) lists at
|
|
6
|
+
* most {@link MAX_ALWAYS_ENTRIES} repository-relative test files or directories
|
|
7
|
+
* (a trailing `/` marks a directory) that a worker runs before every push,
|
|
8
|
+
* whatever it changed. `pins` may be omitted when `always` is present.
|
|
9
|
+
*
|
|
10
|
+
* Both likely-tests discovery and the executor's worker prompt read the file
|
|
11
|
+
* through {@link readVerificationHints}, so the two always agree on which
|
|
12
|
+
* `always` entries were admitted. An entry is admitted only when it exists as the
|
|
13
|
+
* kind it claims, checked through the same contained no-follow walk that reads
|
|
14
|
+
* the hints file itself. A missing, wrong-kind, or invalid entry is skipped and
|
|
15
|
+
* reported as `skipped`. A missing or malformed file is fail-open: no required
|
|
16
|
+
* references, and the caller keeps its existing discovery notes.
|
|
17
|
+
*
|
|
18
|
+
* References are data only, never commands.
|
|
19
|
+
*/
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
import { constants } from "node:fs";
|
|
22
|
+
import { lstat, open } from "node:fs/promises";
|
|
23
|
+
export const VERIFICATION_HINTS_PATH = ".bridge/verification-hints.json";
|
|
24
|
+
export const MAX_ALWAYS_ENTRIES = 32;
|
|
25
|
+
export const TEST_REFERENCE_MAX_LENGTH = 512;
|
|
26
|
+
export const MAX_OPTIONAL_JSON_BYTES = 256 * 1024;
|
|
27
|
+
export function object(value) {
|
|
28
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
29
|
+
? value : undefined;
|
|
30
|
+
}
|
|
31
|
+
export function validTestReference(value) {
|
|
32
|
+
return typeof value === "string" && value.trim().length > 0 &&
|
|
33
|
+
value.length <= TEST_REFERENCE_MAX_LENGTH && !/[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(value);
|
|
34
|
+
}
|
|
35
|
+
export function validRepoPath(value, directory = false) {
|
|
36
|
+
const candidate = directory && value.endsWith("/") ? value.slice(0, -1) : value;
|
|
37
|
+
return !!candidate && !path.isAbsolute(candidate) && !/[:\\\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(candidate) &&
|
|
38
|
+
candidate.split("/").every(p => p !== "" && p !== "." && p !== "..");
|
|
39
|
+
}
|
|
40
|
+
/** A test reference; a file-shaped one must be a safe path (a trailing `/` names a directory). */
|
|
41
|
+
export function validReference(value) {
|
|
42
|
+
if (!validTestReference(value))
|
|
43
|
+
return false;
|
|
44
|
+
const file = value.split("::")[0];
|
|
45
|
+
const fileShaped = value.includes("/") || /\.(?:py|[cm]?[jt]sx?)(?:::|$)/.test(value) || value.includes("::");
|
|
46
|
+
return !fileShaped || validRepoPath(file, !value.includes("::") && file.endsWith("/"));
|
|
47
|
+
}
|
|
48
|
+
function validAlwaysEntry(value) {
|
|
49
|
+
return validTestReference(value) && !value.includes("::") && validRepoPath(value, true);
|
|
50
|
+
}
|
|
51
|
+
/** Parse a hints document, or `undefined` when it is not a version-1 document. */
|
|
52
|
+
export function parseVerificationHints(value) {
|
|
53
|
+
const doc = object(value);
|
|
54
|
+
if (!doc || doc.version !== 1)
|
|
55
|
+
return undefined;
|
|
56
|
+
const hasPins = Object.prototype.hasOwnProperty.call(doc, "pins");
|
|
57
|
+
const hasAlways = Object.prototype.hasOwnProperty.call(doc, "always");
|
|
58
|
+
if (hasPins ? !Array.isArray(doc.pins) : !hasAlways)
|
|
59
|
+
return undefined;
|
|
60
|
+
if (hasAlways && !Array.isArray(doc.always))
|
|
61
|
+
return undefined;
|
|
62
|
+
const pins = [];
|
|
63
|
+
let skipped = false;
|
|
64
|
+
for (const entry of doc.pins ?? []) {
|
|
65
|
+
const pin = object(entry);
|
|
66
|
+
if (!pin || !Array.isArray(pin.paths) || !Array.isArray(pin.tests)) {
|
|
67
|
+
skipped = true;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const paths = pin.paths.filter((p) => typeof p === "string" && validRepoPath(p, true));
|
|
71
|
+
const tests = pin.tests.filter(validReference);
|
|
72
|
+
if (paths.length !== pin.paths.length || tests.length !== pin.tests.length)
|
|
73
|
+
skipped = true;
|
|
74
|
+
if (paths.length && tests.length)
|
|
75
|
+
pins.push({ paths, tests });
|
|
76
|
+
else
|
|
77
|
+
skipped = true;
|
|
78
|
+
}
|
|
79
|
+
const always = [];
|
|
80
|
+
const declared = doc.always ?? [];
|
|
81
|
+
for (let index = 0; index < declared.length; index++) {
|
|
82
|
+
const entry = declared[index];
|
|
83
|
+
if (index >= MAX_ALWAYS_ENTRIES || !validAlwaysEntry(entry)) {
|
|
84
|
+
skipped = true;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (!always.includes(entry))
|
|
88
|
+
always.push(entry);
|
|
89
|
+
}
|
|
90
|
+
return { pins, always, skipped };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Walk `relative` under `root` without following a link: every component is
|
|
94
|
+
* `lstat`ed, a symlink anywhere refuses, and every ancestor must be a directory.
|
|
95
|
+
* Returns the final component's kind.
|
|
96
|
+
*/
|
|
97
|
+
export async function containedKind(root, relative) {
|
|
98
|
+
if (!validRepoPath(relative))
|
|
99
|
+
throw new Error("invalid_path");
|
|
100
|
+
let current = root;
|
|
101
|
+
let kind = "other";
|
|
102
|
+
const parts = relative.split("/");
|
|
103
|
+
for (let index = 0; index < parts.length; index++) {
|
|
104
|
+
current = path.join(current, parts[index]);
|
|
105
|
+
const info = await lstat(current);
|
|
106
|
+
if (info.isSymbolicLink())
|
|
107
|
+
throw new Error("symlink");
|
|
108
|
+
const last = index === parts.length - 1;
|
|
109
|
+
if (!last && !info.isDirectory())
|
|
110
|
+
throw new Error("ancestor");
|
|
111
|
+
if (last)
|
|
112
|
+
kind = info.isDirectory() ? "directory" : info.isFile() ? "file" : "other";
|
|
113
|
+
}
|
|
114
|
+
if (kind === "other")
|
|
115
|
+
throw new Error("not_regular");
|
|
116
|
+
return kind;
|
|
117
|
+
}
|
|
118
|
+
/** No-follow and fstat protect the final component; lstat every ancestor first.
|
|
119
|
+
* Reads at most limit+1 bytes even if a file grows between stat and read.
|
|
120
|
+
*/
|
|
121
|
+
export async function containedText(root, relative, limit) {
|
|
122
|
+
if (!validRepoPath(relative))
|
|
123
|
+
throw new Error("invalid_path");
|
|
124
|
+
let current = root;
|
|
125
|
+
for (const part of relative.split("/")) {
|
|
126
|
+
current = path.join(current, part);
|
|
127
|
+
const info = await lstat(current);
|
|
128
|
+
if (info.isSymbolicLink())
|
|
129
|
+
throw new Error("symlink");
|
|
130
|
+
if (current !== path.join(root, relative) && !info.isDirectory())
|
|
131
|
+
throw new Error("ancestor");
|
|
132
|
+
}
|
|
133
|
+
const handle = await open(current, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
134
|
+
try {
|
|
135
|
+
const info = await handle.stat();
|
|
136
|
+
if (!info.isFile())
|
|
137
|
+
throw new Error("not_regular");
|
|
138
|
+
if (info.size > limit)
|
|
139
|
+
throw new Error("bound");
|
|
140
|
+
const buffer = Buffer.alloc(limit + 1);
|
|
141
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
142
|
+
if (bytesRead > limit)
|
|
143
|
+
throw new Error("bound");
|
|
144
|
+
return buffer.subarray(0, bytesRead).toString("utf8");
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
await handle.close();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/** Read and admit the hints file under `root`. Never throws. */
|
|
151
|
+
export async function readVerificationHints(root, options = {}) {
|
|
152
|
+
const read = options.readText ?? containedText;
|
|
153
|
+
const kindOf = options.kindOf ?? containedKind;
|
|
154
|
+
let parsed;
|
|
155
|
+
try {
|
|
156
|
+
parsed = parseVerificationHints(JSON.parse(await read(root, VERIFICATION_HINTS_PATH, MAX_OPTIONAL_JSON_BYTES)));
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
return error.code === "ENOENT" ? { status: "missing" } : { status: "malformed" };
|
|
160
|
+
}
|
|
161
|
+
if (!parsed)
|
|
162
|
+
return { status: "malformed" };
|
|
163
|
+
const required = [];
|
|
164
|
+
let skipped = parsed.skipped;
|
|
165
|
+
for (const entry of parsed.always) {
|
|
166
|
+
const directory = entry.endsWith("/");
|
|
167
|
+
try {
|
|
168
|
+
const kind = await kindOf(root, directory ? entry.slice(0, -1) : entry);
|
|
169
|
+
if (kind === (directory ? "directory" : "file"))
|
|
170
|
+
required.push(entry);
|
|
171
|
+
else
|
|
172
|
+
skipped = true;
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
skipped = true;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return { status: "ok", pins: parsed.pins, required, skipped };
|
|
179
|
+
}
|
|
@@ -23,6 +23,8 @@ import { isRemainingWork, validateCorrectionIntent } from "./correction-dispatch
|
|
|
23
23
|
import { readRequiredVerification } from "./completion-supervision.js";
|
|
24
24
|
import { isValidExecutorEpicRunId } from "./claim-scope.js";
|
|
25
25
|
import path from "node:path";
|
|
26
|
+
import { isSafeRepoRelativePath } from "../dependency-install-declarations.js";
|
|
27
|
+
import { PRE_PR_BUDGET_SECONDS } from "./pre-pr-checks.js";
|
|
26
28
|
/**
|
|
27
29
|
* BAPI-1296: `ci_fix` is the one recovery job with a FOCUSED prompt route. It
|
|
28
30
|
* renders its server-authored `payload.prompt_spec` (the dispatched failing and
|
|
@@ -92,6 +94,34 @@ export function resolveExecutorPrompt(job, trusted) {
|
|
|
92
94
|
}
|
|
93
95
|
return resolveExecutorPromptLegacy(job, trusted);
|
|
94
96
|
}
|
|
97
|
+
/** The exact obligation token the server sends for a timed-out implement job. It is compared, never rewritten. */
|
|
98
|
+
const INTERRUPTED_WORK_OBLIGATION = "finish_interrupted_work_verify_and_open_pr_if_absent";
|
|
99
|
+
/** The text `render_remaining_obligation` emits for carried tasks, in singular and plural form. */
|
|
100
|
+
const CARRIED_TASK_OBLIGATION_TEXT = "unfinished background task";
|
|
101
|
+
/**
|
|
102
|
+
* Plain-language explanation of the interrupted-work obligation. It sits after the
|
|
103
|
+
* unchanged retained-branch header and before any operator context. It adds no
|
|
104
|
+
* payload field, job kind, or admission rule.
|
|
105
|
+
*/
|
|
106
|
+
const INTERRUPTED_WORK_BLOCK = "Interrupted work: a time limit ended the earlier session before it finished. " +
|
|
107
|
+
"Read `get_ticket_delivery_readiness` and `get_phase_context` first. Finish the plan steps that are still " +
|
|
108
|
+
"unrecorded or genuinely stale, inside targeted verification scope. Record each remaining step with " +
|
|
109
|
+
"`record_phase_result`. Open a pull request with `create_pull_request` only if none exists.\n" +
|
|
110
|
+
"Keep valid evidence: use readiness to tell an unresolved CI deferral from stale local evidence. Keep valid " +
|
|
111
|
+
"records and existing `remote_ci` deferrals while their command-to-check mapping and selection condition " +
|
|
112
|
+
"still hold. Refresh a deferral when its mapping or condition changed. Run the step locally when coverage " +
|
|
113
|
+
"can no longer be shown. Waiting for CI never needs a local rerun, and CI closure is never reported as a " +
|
|
114
|
+
"locally executed pass.\n" +
|
|
115
|
+
"\"Do not invoke a full implementation or planning workflow\" means do not restart `/implement-ticket` or " +
|
|
116
|
+
"`/plan-ticket`. It does not stop you from running and recording the remaining plan steps.";
|
|
117
|
+
/** Explains tasks carried over from a session that has already ended. */
|
|
118
|
+
const CARRIED_BACKGROUND_TASK_BLOCK = "Carried background tasks: the obligation names unfinished background tasks. They belonged to an earlier " +
|
|
119
|
+
"session that has ended, so they cannot be resumed or waited on. Do not try to monitor them. Do any " +
|
|
120
|
+
"outstanding replacement work in the foreground and record its result with `record_phase_result`. " +
|
|
121
|
+
"In your final report, name each earlier task ID you can see as obsolete and superseded, either by its " +
|
|
122
|
+
"foreground replacement or by a replacement record that is already valid. Never invent a task ID or add a " +
|
|
123
|
+
"report field; if you only have a count, say so. Do not call a real verification failure obsolete just " +
|
|
124
|
+
"because its task is obsolete, and do not repeat replacement work that is already recorded as valid.";
|
|
95
125
|
function resolveExecutorPromptLegacy(job, trusted) {
|
|
96
126
|
const payload = job.payload && typeof job.payload === "object"
|
|
97
127
|
? job.payload
|
|
@@ -113,14 +143,19 @@ function resolveExecutorPromptLegacy(job, trusted) {
|
|
|
113
143
|
const header = `Continue the retained branch ${branch}. Complete only the ${kind} obligation: ${obligation}. ` +
|
|
114
144
|
"Preserve completed work and existing limits. Do not invoke a full implementation or planning workflow.";
|
|
115
145
|
const operatorContext = renderOperatorNoteBlock(payload);
|
|
116
|
-
|
|
146
|
+
// The server joins carried obligations with "; " (render_remaining_obligation).
|
|
147
|
+
const obligations = obligation.split("; ");
|
|
148
|
+
const interruptedWork = obligations.includes(INTERRUPTED_WORK_OBLIGATION);
|
|
149
|
+
const explanatoryBlocks = (interruptedWork ? "\n\n" + INTERRUPTED_WORK_BLOCK : "") +
|
|
150
|
+
(obligation.includes(CARRIED_TASK_OBLIGATION_TEXT) ? "\n\n" + CARRIED_BACKGROUND_TASK_BLOCK : "");
|
|
151
|
+
const prGuidance = payload.pr_attached !== true || interruptedWork
|
|
117
152
|
? "\n\nIf no pull request exists for this branch, open it with the `create_pull_request` MCP tool; `gh` is unavailable. Do not quote workflow slash commands in PR text."
|
|
118
153
|
: "";
|
|
119
154
|
const pushing = job.job_type !== "reconcile_overlap" && kind !== "overlap_reconciliation";
|
|
120
155
|
const guidance = pushing ? renderWorkerPushAndCommitGuidance(job.job_type === "rebase") +
|
|
121
|
-
"\n\n" + renderWorkerTestInvocationGuidance() +
|
|
156
|
+
"\n\n" + renderWorkerTestInvocationGuidance(payload.verification_handoff_enabled === true) +
|
|
122
157
|
(trusted ? "\n\n" + renderWorkerVerificationGuidance(trusted.comparisonSha) : "") : "";
|
|
123
|
-
const focusedHeader = `${header}${operatorContext}${prGuidance}${guidance}`;
|
|
158
|
+
const focusedHeader = `${header}${explanatoryBlocks}${operatorContext}${prGuidance}${guidance}`;
|
|
124
159
|
if (kind === "approved_spec_delta") {
|
|
125
160
|
const delta = intent.approved_delta;
|
|
126
161
|
return { ok: true, prompt: `${focusedHeader}\nApproved files: ${delta.file_boundary.join(", ")}\n` +
|
|
@@ -251,6 +286,14 @@ const RECOGNIZED_DATABASE_CATEGORIES = new Set([
|
|
|
251
286
|
"bridgeapi_reachable", "boundary_unknown", "alembic_missing", "create_failed",
|
|
252
287
|
"migration_failed", "timeout", "cancelled",
|
|
253
288
|
]);
|
|
289
|
+
/**
|
|
290
|
+
* The closed migration causes the section may name. Mirrors
|
|
291
|
+
* `WorkerDatabaseMigrationCause`; the annotation makes the compiler reject a
|
|
292
|
+
* member the type does not have. Anything else is omitted from the line.
|
|
293
|
+
*/
|
|
294
|
+
const RECOGNIZED_DATABASE_CAUSES = new Set([
|
|
295
|
+
"multiple_heads", "revision_missing", "ssl_refused", "connection_refused", "permission_denied", "timeout", "other",
|
|
296
|
+
]);
|
|
254
297
|
/**
|
|
255
298
|
* Mirrors the server renderer's admission rules
|
|
256
299
|
* (`render_reproduction_section` in `prompt_specs.py`): the first 64 entries,
|
|
@@ -264,6 +307,19 @@ const REPRODUCE_SOURCES = new Set(["check_hint", "test_command", "none"]);
|
|
|
264
307
|
const REPRODUCE_SOURCE_NONE = "none";
|
|
265
308
|
/** Python `str.strip()` whitespace, which differs from JavaScript's `trim()`. */
|
|
266
309
|
const PYTHON_BLANK = /^[\t\n\v\f\r\x1c-\x1f \x85\xa0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000]*$/;
|
|
310
|
+
/** BAPI-1551: the fixed stale-dependency wording, keyed by closed reason. */
|
|
311
|
+
const STALE_DEPENDENCY_TEXT = {
|
|
312
|
+
install_failed: "install failed",
|
|
313
|
+
lockfile_unreadable: "lockfile could not be read",
|
|
314
|
+
no_budget: "not enough job time to refresh",
|
|
315
|
+
copy_uncertain: "background copy still running or completion unknown",
|
|
316
|
+
shared_inode: "dependency files have shared inodes",
|
|
317
|
+
marker_uncleared: "refresh marker could not be cleared",
|
|
318
|
+
};
|
|
319
|
+
/** BAPI-1598: the line added when the worker has no database and CI provides one. */
|
|
320
|
+
const CI_DATABASE_DELEGATED_LINE = "- No worker database is available. Database-backed checks are delegated to CI's required checks at the pushed head.";
|
|
321
|
+
/** BAPI-1551: the line added when CI has no database and this worker has one. */
|
|
322
|
+
export const CI_DATABASE_NONE_LINE = "- CI runs without a database. Reproduce database-touching failures with the database variables unset.";
|
|
267
323
|
/** Same text transforms as the server's `_reproduction_text`, for the first argv item. */
|
|
268
324
|
function reproductionText(value, maxChars) {
|
|
269
325
|
if (typeof value !== "string")
|
|
@@ -348,10 +404,19 @@ function unrunnableCheckPositions(o) {
|
|
|
348
404
|
*/
|
|
349
405
|
export function renderLocalEnvironmentLimits(options) {
|
|
350
406
|
const lines = [];
|
|
351
|
-
|
|
407
|
+
const databaseExpected = options.workerDatabaseMode === undefined || options.workerDatabaseMode === "disposable_postgres";
|
|
408
|
+
if (!options.databaseAvailable && options.ciDatabase === "provided") {
|
|
409
|
+
// CI provides the database. This only says where the checks run; it does not
|
|
410
|
+
// mark any verification as completed.
|
|
411
|
+
lines.push(CI_DATABASE_DELEGATED_LINE);
|
|
412
|
+
}
|
|
413
|
+
else if (!options.databaseAvailable && databaseExpected) {
|
|
352
414
|
const category = options.databaseUnavailableCategory;
|
|
415
|
+
const cause = options.databaseUnavailableCause;
|
|
416
|
+
const causeText = category === "migration_failed" && typeof cause === "string" &&
|
|
417
|
+
RECOGNIZED_DATABASE_CAUSES.has(cause) ? `, cause: ${cause}` : "";
|
|
353
418
|
const reason = category !== undefined && RECOGNIZED_DATABASE_CATEGORIES.has(category)
|
|
354
|
-
? ` (reason: ${category})` : "";
|
|
419
|
+
? ` (reason: ${category}${causeText})` : "";
|
|
355
420
|
lines.push(`- No disposable database was provisioned for this worker${reason}, so database-backed ` +
|
|
356
421
|
"verification cannot run locally. CI at the pushed head is the verifier.");
|
|
357
422
|
}
|
|
@@ -360,6 +425,14 @@ export function renderLocalEnvironmentLimits(options) {
|
|
|
360
425
|
"the program its command starts with is not runnable on this machine. Do not attempt that " +
|
|
361
426
|
"command. CI at the pushed head is the verifier.");
|
|
362
427
|
}
|
|
428
|
+
if (options.ciDatabase === "none" && options.databaseAvailable)
|
|
429
|
+
lines.push(CI_DATABASE_NONE_LINE);
|
|
430
|
+
for (const stale of options.staleDependencyCwds ?? []) {
|
|
431
|
+
const text = STALE_DEPENDENCY_TEXT[stale.reason];
|
|
432
|
+
if (text === undefined || !isSafeRepoRelativePath(stale.cwd, { allowRoot: true }))
|
|
433
|
+
continue;
|
|
434
|
+
lines.push(`- dependencies for ${stale.cwd} may be stale: ${text}`);
|
|
435
|
+
}
|
|
363
436
|
if (lines.length === 0)
|
|
364
437
|
return "";
|
|
365
438
|
return [
|
|
@@ -369,3 +442,51 @@ export function renderLocalEnvironmentLimits(options) {
|
|
|
369
442
|
"This section is informational. It adds no completion obligation, evidence rule, or exit.",
|
|
370
443
|
].join("\n");
|
|
371
444
|
}
|
|
445
|
+
// ---------------------------------------------------------------------------
|
|
446
|
+
// REQUIRED BEFORE PUSH (BAPI-1551)
|
|
447
|
+
// ---------------------------------------------------------------------------
|
|
448
|
+
/** The heading of the section naming the repository's always-run guard tests. */
|
|
449
|
+
export const REQUIRED_BEFORE_PUSH_HEADING = "## REQUIRED BEFORE PUSH ##";
|
|
450
|
+
/**
|
|
451
|
+
* Render the `REQUIRED BEFORE PUSH` section from the ADMITTED `always` entries of
|
|
452
|
+
* `.bridge/verification-hints.json`, or `""` when there are none. The entries are
|
|
453
|
+
* test references, never shell text; the worker maps them through the
|
|
454
|
+
* repository's declared runner.
|
|
455
|
+
*/
|
|
456
|
+
export function renderRequiredBeforePush(references) {
|
|
457
|
+
if (references.length === 0)
|
|
458
|
+
return "";
|
|
459
|
+
return [
|
|
460
|
+
REQUIRED_BEFORE_PUSH_HEADING,
|
|
461
|
+
"This repository declares always-run guard tests: run these before you push, whatever you changed, " +
|
|
462
|
+
"through the repository's declared test runner. They are test references, not shell commands.",
|
|
463
|
+
...references.map((reference) => `- ${reference}`),
|
|
464
|
+
].join("\n");
|
|
465
|
+
}
|
|
466
|
+
// ---------------------------------------------------------------------------
|
|
467
|
+
// PRE-PR CHECKS (BAPI-1582)
|
|
468
|
+
// ---------------------------------------------------------------------------
|
|
469
|
+
/** The heading of the section naming the repository's owner-confirmed pre-PR commands. */
|
|
470
|
+
export const PRE_PR_CHECKS_HEADING = "## PRE-PR CHECKS ##";
|
|
471
|
+
/**
|
|
472
|
+
* Render the `PRE-PR CHECKS` section from the ADMITTED gate-profile commands, or
|
|
473
|
+
* `""` when there are none. Each command is one JSON line carrying its argv as
|
|
474
|
+
* data: it is never joined into a shell command line.
|
|
475
|
+
*/
|
|
476
|
+
export function renderPrePrChecks(checks) {
|
|
477
|
+
if (checks.length === 0)
|
|
478
|
+
return "";
|
|
479
|
+
return [
|
|
480
|
+
PRE_PR_CHECKS_HEADING,
|
|
481
|
+
"This repository's owner confirmed these commands as local reproductions of its CI checks. " +
|
|
482
|
+
"Run them in the pre-PR step, after the targeted verification and likely-tests references, " +
|
|
483
|
+
"before you call create_pull_request.",
|
|
484
|
+
`- One shared budget of ${PRE_PR_BUDGET_SECONDS} seconds covers the whole pre-PR step for this attempt. ` +
|
|
485
|
+
"When it runs out, skip the rest and record each as skipped with reason budget.",
|
|
486
|
+
"- Run each command from the worktree root, exactly as its argv list, with no shell: no pipes, " +
|
|
487
|
+
"no redirects, no added words. Cap it at its own timeout_seconds or the remaining budget, whichever is less.",
|
|
488
|
+
"- This step never blocks the pull request. A failed, timed-out, or skipped command is disclosed " +
|
|
489
|
+
"in .conductor/pre-pr-checks.json and the handoff, and the PR still opens.",
|
|
490
|
+
...checks.map((check) => `- ${JSON.stringify({ check: check.check, argv: check.argv, timeout_seconds: check.timeoutSeconds })}`),
|
|
491
|
+
].join("\n");
|
|
492
|
+
}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The job payload's `worker_database` declaration, parsed at the executor's
|
|
3
|
+
* consuming boundary (BAPI-1598).
|
|
4
|
+
*
|
|
5
|
+
* The server validates the same declaration when an admin writes it; this parser
|
|
6
|
+
* re-checks it because the executor must never provision, migrate, or protect a
|
|
7
|
+
* database on the strength of a payload it has not validated itself. It mirrors
|
|
8
|
+
* the server's closed-object, identifier, command, credential-pattern,
|
|
9
|
+
* URL-destination, and `worker_env` overlap rules.
|
|
10
|
+
*
|
|
11
|
+
* Only a valid explicit `disposable_postgres` declaration can enable
|
|
12
|
+
* provisioning. A missing, `null`, `none`, unknown-mode, or malformed value
|
|
13
|
+
* disables it, and never falls back to a Bridge default. A VALID `none`
|
|
14
|
+
* declaration that lists protected databases still carries its configuration, so
|
|
15
|
+
* the environment builder can keep the sentinel in place.
|
|
16
|
+
*
|
|
17
|
+
* Diagnostics are closed reason tokens and field paths only. No value, argv item,
|
|
18
|
+
* URL, or object key from the payload is ever returned or logged.
|
|
19
|
+
*/
|
|
20
|
+
import { isWorkerEnvNameReserved } from "./env.js";
|
|
21
|
+
import { POSTGRES_IDENTIFIER_MAX_LENGTH } from "./worker-database-target.js";
|
|
22
|
+
export const WORKER_DATABASE_MODES = ["none", "disposable_postgres"];
|
|
23
|
+
/** The only database URL name a declaration may use that `worker_env` may not. */
|
|
24
|
+
export const WORKER_DATABASE_URL_EXCEPTION_NAME = "DATABASE_URL";
|
|
25
|
+
/** Bounds mirrored from the server contract (per-command timeout, argv shape). */
|
|
26
|
+
export const WORKER_DATABASE_MIGRATE_TIMEOUT_MIN_SECONDS = 1;
|
|
27
|
+
export const WORKER_DATABASE_MIGRATE_TIMEOUT_MAX_SECONDS = 1800;
|
|
28
|
+
const MAX_ARGV_ITEMS = 32;
|
|
29
|
+
const MAX_ARG_CHARS = 1024;
|
|
30
|
+
const MAX_LIST_ITEMS = 16;
|
|
31
|
+
const IDENTIFIER_PATTERN = new RegExp(`^[A-Za-z_][A-Za-z0-9_$]{0,${POSTGRES_IDENTIFIER_MAX_LENGTH - 1}}$`);
|
|
32
|
+
const ENV_NAME_PATTERN = /^[A-Z_][A-Z0-9_]{0,63}$/;
|
|
33
|
+
const SECRET_NAME_FRAGMENTS = ["TOKEN", "SECRET", "PASSWORD", "API_KEY"];
|
|
34
|
+
/** URL user information, `password=` assignments, and `--password` flags. Pattern-based only. */
|
|
35
|
+
const CREDENTIAL_PATTERNS = [
|
|
36
|
+
/[a-z][a-z0-9+.-]*:\/\/[^\s/?#]*@/i,
|
|
37
|
+
/password\s*=/i,
|
|
38
|
+
/--password/i,
|
|
39
|
+
];
|
|
40
|
+
/** True for a name that is safe to use as a PostgreSQL role or database identifier. */
|
|
41
|
+
export function isWorkerDatabaseIdentifier(value) {
|
|
42
|
+
return parseIdentifier(value) !== undefined;
|
|
43
|
+
}
|
|
44
|
+
const fail = (reason) => ({ fail: reason });
|
|
45
|
+
const isFail = (value) => typeof value === "object" && value !== null && "fail" in value;
|
|
46
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
47
|
+
function hasCredentialPattern(value, depth = 0) {
|
|
48
|
+
if (depth > 6)
|
|
49
|
+
return true;
|
|
50
|
+
if (typeof value === "string")
|
|
51
|
+
return CREDENTIAL_PATTERNS.some((pattern) => pattern.test(value));
|
|
52
|
+
if (Array.isArray(value))
|
|
53
|
+
return value.some((item) => hasCredentialPattern(item, depth + 1));
|
|
54
|
+
if (isRecord(value))
|
|
55
|
+
return Object.values(value).some((item) => hasCredentialPattern(item, depth + 1));
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
function parseIdentifier(value) {
|
|
59
|
+
return typeof value === "string" && IDENTIFIER_PATTERN.test(value) ? value : undefined;
|
|
60
|
+
}
|
|
61
|
+
function parseIdentifierList(value) {
|
|
62
|
+
if (!Array.isArray(value) || value.length > MAX_LIST_ITEMS)
|
|
63
|
+
return undefined;
|
|
64
|
+
const out = [];
|
|
65
|
+
for (const item of value) {
|
|
66
|
+
const id = parseIdentifier(item);
|
|
67
|
+
if (id === undefined || out.includes(id))
|
|
68
|
+
return undefined;
|
|
69
|
+
out.push(id);
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
/** True when `name` is a legal database URL destination (the `DATABASE_URL` exception applies). */
|
|
74
|
+
export function isWorkerDatabaseUrlDestinationAllowed(name) {
|
|
75
|
+
if (typeof name !== "string" || !ENV_NAME_PATTERN.test(name))
|
|
76
|
+
return false;
|
|
77
|
+
if (name !== WORKER_DATABASE_URL_EXCEPTION_NAME && !name.endsWith("_URL"))
|
|
78
|
+
return false;
|
|
79
|
+
if (name !== WORKER_DATABASE_URL_EXCEPTION_NAME && isWorkerEnvNameReserved(name))
|
|
80
|
+
return false;
|
|
81
|
+
const upper = name.toUpperCase();
|
|
82
|
+
return !SECRET_NAME_FRAGMENTS.some((fragment) => upper.includes(fragment));
|
|
83
|
+
}
|
|
84
|
+
function parseEnvNames(value) {
|
|
85
|
+
if (!Array.isArray(value) || value.length > MAX_LIST_ITEMS)
|
|
86
|
+
return undefined;
|
|
87
|
+
const out = [];
|
|
88
|
+
for (const item of value) {
|
|
89
|
+
if (!isWorkerDatabaseUrlDestinationAllowed(item) || out.includes(item))
|
|
90
|
+
return undefined;
|
|
91
|
+
out.push(item);
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
export function parseAlembicArgv(argv) {
|
|
96
|
+
if (argv.length === 3 && argv[0].length > 0 && argv[1] === "upgrade" && argv[2] === "head") {
|
|
97
|
+
return { launcher: argv[0], configArgs: [] };
|
|
98
|
+
}
|
|
99
|
+
if (argv.length === 5 &&
|
|
100
|
+
argv[0].length > 0 &&
|
|
101
|
+
(argv[1] === "-c" || argv[1] === "--config") &&
|
|
102
|
+
argv[2].length > 0 &&
|
|
103
|
+
argv[3] === "upgrade" &&
|
|
104
|
+
argv[4] === "head") {
|
|
105
|
+
return { launcher: argv[0], configArgs: [argv[1], argv[2]] };
|
|
106
|
+
}
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
function parseMigrateCommand(value) {
|
|
110
|
+
if (!isRecord(value))
|
|
111
|
+
return fail("invalid_migrate_command");
|
|
112
|
+
for (const key of Object.keys(value)) {
|
|
113
|
+
if (key !== "argv" && key !== "timeout_seconds" && key !== "head_check")
|
|
114
|
+
return fail("unknown_field");
|
|
115
|
+
}
|
|
116
|
+
const { argv, timeout_seconds: timeout, head_check: headCheck } = value;
|
|
117
|
+
if (!Array.isArray(argv) || argv.length === 0 || argv.length > MAX_ARGV_ITEMS)
|
|
118
|
+
return fail("invalid_migrate_command");
|
|
119
|
+
for (const arg of argv) {
|
|
120
|
+
if (typeof arg !== "string" || arg.length === 0 || arg.length > MAX_ARG_CHARS || arg.includes("\u0000")) {
|
|
121
|
+
return fail("invalid_migrate_command");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (typeof timeout !== "number" ||
|
|
125
|
+
!Number.isInteger(timeout) ||
|
|
126
|
+
timeout < WORKER_DATABASE_MIGRATE_TIMEOUT_MIN_SECONDS ||
|
|
127
|
+
timeout > WORKER_DATABASE_MIGRATE_TIMEOUT_MAX_SECONDS) {
|
|
128
|
+
return fail("invalid_migrate_command");
|
|
129
|
+
}
|
|
130
|
+
if (headCheck !== undefined && headCheck !== null && headCheck !== "alembic" && headCheck !== "none") {
|
|
131
|
+
return fail("invalid_migrate_command");
|
|
132
|
+
}
|
|
133
|
+
const check = headCheck === "alembic" ? "alembic" : "none";
|
|
134
|
+
if (check === "alembic" && parseAlembicArgv(argv) === undefined)
|
|
135
|
+
return fail("invalid_alembic_argv");
|
|
136
|
+
return { argv: [...argv], timeoutSeconds: timeout, headCheck: check };
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Parse a payload's `worker_database` value. `workerEnvNames` are the names the
|
|
140
|
+
* payload's own `worker_env` declares; a URL alias that also appears there is
|
|
141
|
+
* malformed, so a repository variable can never name the protected destination.
|
|
142
|
+
* Never throws and never logs.
|
|
143
|
+
*/
|
|
144
|
+
export function parseWorkerDatabasePayload(raw, workerEnvNames = []) {
|
|
145
|
+
if (raw === undefined || raw === null)
|
|
146
|
+
return { classification: "absent" };
|
|
147
|
+
if (!isRecord(raw))
|
|
148
|
+
return { classification: "malformed", reason: "not_an_object" };
|
|
149
|
+
for (const key of Object.keys(raw)) {
|
|
150
|
+
if (!["mode", "worker_role", "protected_databases", "env_names", "migrate_command"].includes(key)) {
|
|
151
|
+
return { classification: "malformed", reason: "unknown_field" };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (hasCredentialPattern(raw))
|
|
155
|
+
return { classification: "malformed", reason: "credential_like_value" };
|
|
156
|
+
const modeRaw = raw.mode ?? "none";
|
|
157
|
+
if (typeof modeRaw !== "string")
|
|
158
|
+
return { classification: "malformed", reason: "invalid_mode" };
|
|
159
|
+
if (modeRaw !== "none" && modeRaw !== "disposable_postgres")
|
|
160
|
+
return { classification: "disabled" };
|
|
161
|
+
const mode = modeRaw;
|
|
162
|
+
// Every field that is supplied is validated, whatever the mode.
|
|
163
|
+
let workerRole;
|
|
164
|
+
if (raw.worker_role !== undefined && raw.worker_role !== null) {
|
|
165
|
+
workerRole = parseIdentifier(raw.worker_role);
|
|
166
|
+
if (workerRole === undefined)
|
|
167
|
+
return { classification: "malformed", reason: "invalid_worker_role" };
|
|
168
|
+
}
|
|
169
|
+
let protectedDatabases = [];
|
|
170
|
+
if (raw.protected_databases !== undefined && raw.protected_databases !== null) {
|
|
171
|
+
const parsed = parseIdentifierList(raw.protected_databases);
|
|
172
|
+
if (parsed === undefined)
|
|
173
|
+
return { classification: "malformed", reason: "invalid_protected_databases" };
|
|
174
|
+
protectedDatabases = parsed;
|
|
175
|
+
}
|
|
176
|
+
let envNames = [];
|
|
177
|
+
if (raw.env_names !== undefined && raw.env_names !== null) {
|
|
178
|
+
const parsed = parseEnvNames(raw.env_names);
|
|
179
|
+
if (parsed === undefined)
|
|
180
|
+
return { classification: "malformed", reason: "invalid_env_names" };
|
|
181
|
+
envNames = parsed;
|
|
182
|
+
}
|
|
183
|
+
if (envNames.some((name) => workerEnvNames.includes(name))) {
|
|
184
|
+
return { classification: "malformed", reason: "worker_env_overlap" };
|
|
185
|
+
}
|
|
186
|
+
let migrateCommand;
|
|
187
|
+
if (raw.migrate_command !== undefined && raw.migrate_command !== null) {
|
|
188
|
+
const parsed = parseMigrateCommand(raw.migrate_command);
|
|
189
|
+
if (isFail(parsed))
|
|
190
|
+
return { classification: "malformed", reason: parsed.fail };
|
|
191
|
+
migrateCommand = parsed;
|
|
192
|
+
}
|
|
193
|
+
const config = {
|
|
194
|
+
mode,
|
|
195
|
+
...(workerRole !== undefined ? { workerRole } : {}),
|
|
196
|
+
protectedDatabases,
|
|
197
|
+
envNames,
|
|
198
|
+
...(migrateCommand !== undefined ? { migrateCommand } : {}),
|
|
199
|
+
};
|
|
200
|
+
if (mode === "none")
|
|
201
|
+
return { classification: "disabled", config };
|
|
202
|
+
if (workerRole === undefined || envNames.length === 0 || migrateCommand === undefined) {
|
|
203
|
+
return { classification: "malformed", reason: "missing_required_field" };
|
|
204
|
+
}
|
|
205
|
+
return { classification: "enabled", config: { ...config, workerRole, migrateCommand } };
|
|
206
|
+
}
|
|
207
|
+
/** The `worker_env` entry names of a payload value, for the overlap check. Never reads values. */
|
|
208
|
+
export function workerEnvNamesOf(workerEnv) {
|
|
209
|
+
if (!Array.isArray(workerEnv))
|
|
210
|
+
return [];
|
|
211
|
+
const names = [];
|
|
212
|
+
for (const entry of workerEnv) {
|
|
213
|
+
if (isRecord(entry) && typeof entry.name === "string")
|
|
214
|
+
names.push(entry.name);
|
|
215
|
+
}
|
|
216
|
+
return names;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* The `{ workerDatabase }` option a job payload implies: the parse of an OWN
|
|
220
|
+
* `worker_database` key, or an absent classification. Overlap is checked against
|
|
221
|
+
* the payload's own `worker_env`.
|
|
222
|
+
*/
|
|
223
|
+
export function payloadWorkerDatabaseParse(payload) {
|
|
224
|
+
if (!isRecord(payload) || !Object.prototype.hasOwnProperty.call(payload, "worker_database")) {
|
|
225
|
+
return { classification: "absent" };
|
|
226
|
+
}
|
|
227
|
+
return parseWorkerDatabasePayload(payload.worker_database, workerEnvNamesOf(payload.worker_env));
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* The `{ workerDatabaseConfig }` option a payload implies: present only for a
|
|
231
|
+
* valid declaration (enabled, or `none` carrying its config). Anything else adds
|
|
232
|
+
* nothing, so an unconfigured job's environment gets no database placeholder.
|
|
233
|
+
*/
|
|
234
|
+
export function payloadWorkerDatabaseConfigOption(payload) {
|
|
235
|
+
const parsed = payloadWorkerDatabaseParse(payload);
|
|
236
|
+
return (parsed.classification === "enabled" || parsed.classification === "disabled") && parsed.config
|
|
237
|
+
? { workerDatabaseConfig: parsed.config }
|
|
238
|
+
: {};
|
|
239
|
+
}
|
|
240
|
+
/** The safe job metadata a dispatch records: mode and live profile revision only. */
|
|
241
|
+
export function payloadWorkerDatabaseMetadata(payload) {
|
|
242
|
+
const parsed = payloadWorkerDatabaseParse(payload);
|
|
243
|
+
const mode = parsed.classification === "enabled"
|
|
244
|
+
? "disposable_postgres"
|
|
245
|
+
: parsed.classification === "malformed"
|
|
246
|
+
? "malformed"
|
|
247
|
+
: parsed.classification === "disabled"
|
|
248
|
+
? "none"
|
|
249
|
+
: "absent";
|
|
250
|
+
const revision = isRecord(payload) ? payload.execution_profile_revision : undefined;
|
|
251
|
+
return {
|
|
252
|
+
worker_database_mode: mode,
|
|
253
|
+
...(typeof revision === "number" && Number.isSafeInteger(revision) && revision >= 0
|
|
254
|
+
? { execution_profile_revision: revision }
|
|
255
|
+
: {}),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
const SAFE_JOB_ID_FOR_LOG = /^[A-Za-z0-9_-]{1,64}$/;
|
|
259
|
+
/** The ONE bounded advisory line for a malformed payload declaration. Closed reason token only. */
|
|
260
|
+
export function formatWorkerDatabaseMalformedLine(jobId, reason) {
|
|
261
|
+
const id = SAFE_JOB_ID_FOR_LOG.test(String(jobId)) ? String(jobId) : "unknown";
|
|
262
|
+
return (`[executor] job ${id}: worker_database declaration is malformed (reason: ${reason}); ` +
|
|
263
|
+
"no worker database was provisioned and no default was applied");
|
|
264
|
+
}
|
|
265
|
+
/** The bounded job-log line recording a dispatch's effective database mode and live profile revision. */
|
|
266
|
+
export function formatWorkerDatabaseModeLine(jobId, metadata) {
|
|
267
|
+
const id = SAFE_JOB_ID_FOR_LOG.test(String(jobId)) ? String(jobId) : "unknown";
|
|
268
|
+
const revision = metadata.execution_profile_revision;
|
|
269
|
+
return (`[executor] job ${id}: worker database mode=${metadata.worker_database_mode}` +
|
|
270
|
+
(revision !== undefined ? ` profile_revision=${revision}` : ""));
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* The bounded job-log line for a worker with no database whose CI capability makes
|
|
274
|
+
* a database hand-off wrong or unfounded. `delegated`: CI provides the database, so
|
|
275
|
+
* its required checks at the pushed head verify. `unknown_ci`: CI's capability is
|
|
276
|
+
* unknown, which is not confirmed absence. Neither records a gap. Closed tokens only.
|
|
277
|
+
*/
|
|
278
|
+
export function formatWorkerDatabaseSkippedObservationLine(jobId, reason) {
|
|
279
|
+
const id = SAFE_JOB_ID_FOR_LOG.test(String(jobId)) ? String(jobId) : "unknown";
|
|
280
|
+
return `[executor] job ${id}: no database verification hand-off recorded (reason: ${reason})`;
|
|
281
|
+
}
|