@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.
- package/README.md +5 -5
- package/build/agent-launchers/claude-executor-adapter.js +3 -0
- package/build/agents.generated.js +6 -6
- package/build/bridge-permissions.js +27 -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/codex-launcher-pin.js +33 -2
- package/build/codex-skill-adapter.js +3 -1
- package/build/command-host.js +33 -0
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +842 -35
- 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 +106 -21
- 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 +166 -15
- 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 +150 -5
- package/build/conductor/gate-settings-review.js +224 -4
- package/build/conductor/launch-need-probes.js +6 -53
- package/build/conductor/launch-plan.js +313 -156
- package/build/conductor/prerequisite-inputs.js +879 -45
- package/build/conductor/readiness-assessment.js +16 -1
- package/build/conductor/readiness-cli.js +20 -9
- package/build/conductor/readiness-prerequisites.js +28 -9
- package/build/conductor/readiness-sections.js +133 -126
- package/build/conductor/readiness.js +1 -1
- package/build/conductor/recovery-cli.js +13 -2
- package/build/conductor/tools.js +6 -5
- package/build/conductor/wait-run-attention.js +2 -2
- package/build/conductor/wait-run-cli.js +208 -22
- package/build/conductor/worker-database-doctor-inspector.js +33 -2
- package/build/conductor/worker-setup-tally.js +27 -0
- package/build/credential-store.js +71 -1
- package/build/dependency-install-declarations.js +55 -0
- package/build/docs.generated.js +2 -2
- package/build/doctor.js +54 -3
- package/build/drive-epic-help.js +21 -2
- package/build/drive-epic.js +1811 -351
- 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 +2101 -44
- package/build/epic-launch-context.js +607 -0
- 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/completion-contract.js +8 -1
- package/build/executor/env.js +59 -22
- package/build/executor/epic-server-context.js +141 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/http-client.js +52 -5
- package/build/executor/job-runner.js +423 -69
- package/build/executor/observation.js +8 -0
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +114 -2
- package/build/executor/reconcile-overlap-job.js +5 -3
- package/build/executor/required-work-diagnostics.js +4 -2
- package/build/executor/required-work-ledger.js +936 -38
- package/build/executor/results.js +58 -0
- package/build/executor/terminal-mutation.js +8 -0
- package/build/executor/worker-command.js +72 -3
- package/build/executor/worker-database-config.js +281 -0
- package/build/executor/worker-database-target.js +16 -12
- package/build/executor/worker-database.js +320 -101
- package/build/executor/worker-finalization.js +7 -1
- package/build/executor/worker-resources.js +25 -3
- package/build/executor/worker-verification-guidance.js +18 -3
- package/build/executor/worktree.js +20 -1
- package/build/executor-launch.js +54 -2
- package/build/generated-assets-catalog.js +2 -2
- package/build/index.js +664 -335
- package/build/init.js +26 -11
- 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 +1197 -196
- package/build/install-bridge-conductor-setup.js +535 -79
- package/build/install-bridge-conductor.js +2885 -560
- package/build/install-bridge.js +199 -21
- package/build/install-maintenance.js +26 -3
- package/build/launcher-config-inspection.js +162 -1
- 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-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 +234 -109
- package/build/pipelines.generated.js +5 -5
- package/build/plan-discovery.js +97 -4
- package/build/plan-execution-ledger.js +100 -7
- 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 +17 -0
- package/build/plane/preflight.js +50 -10
- package/build/plane/shutdown.js +19 -0
- package/build/plane/terminal-run-cleanup.js +18 -4
- package/build/printed-remedy-commands.js +206 -12
- package/build/readiness-check.js +77 -0
- package/build/readiness-prerequisites.generated.js +122 -14
- package/build/readme.generated.js +1 -1
- package/build/repository-state-paths.js +38 -0
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-epic.js +1190 -196
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +122 -4
- package/build/third-party-mcp-targets.js +30 -0
- package/build/ticket-delivery-enrollment.js +9 -0
- package/build/upgrade-cli.js +85 -2
- package/build/v2-readiness-requirements.js +28 -1
- package/build/version.generated.js +3 -3
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
- package/docs/epic-implementer/getting-started.md +3 -1
- package/docs/epic-implementer/self-hosting.md +14 -1
- package/package.json +2 -2
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* delegated to T3b — this ticket only reads the human-readable critique.
|
|
8
8
|
*/
|
|
9
9
|
import path from "node:path";
|
|
10
|
+
import { CI_FIX_TEST_RUNS_PATH, parseCiFixTestRuns, } from "./ci-fix-test-runs.js";
|
|
10
11
|
/** Smoke evidence byte cap (mirrors server `SMOKE_EVIDENCE_MAX_BYTES`). */
|
|
11
12
|
export const SMOKE_EVIDENCE_MAX_BYTES = 8_000;
|
|
12
13
|
/** Whole-envelope byte cap (mirrors server `RESULT_JSONB_MAX_BYTES`). */
|
|
@@ -316,3 +317,60 @@ export async function readCiFixResultArtifact(worktreePath, requiredChecks, deps
|
|
|
316
317
|
const covered = requiredChecks.every((name) => Object.prototype.hasOwnProperty.call(validatedClaims, name));
|
|
317
318
|
return { status: covered ? "complete" : "partial", fields };
|
|
318
319
|
}
|
|
320
|
+
/** BAPI-1582 — the bounded, no-follow pre-PR evidence reader lives with its contract. */
|
|
321
|
+
export { readPrePrEvidenceArtifact } from "./pre-pr-checks.js";
|
|
322
|
+
/**
|
|
323
|
+
* Read `<worktree>/.conductor/ci-fix-test-runs.json` with the same contained,
|
|
324
|
+
* no-follow, bounded read as {@link readCiFixResultArtifact}, capped at
|
|
325
|
+
* {@link RESULT_JSONB_MAX_BYTES}, and validate it against the dispatched logical
|
|
326
|
+
* job. An oversized, unparseable, malformed, or other-job file is never partly
|
|
327
|
+
* trusted. Never throws; `code` is a fixed, secret-free token.
|
|
328
|
+
*/
|
|
329
|
+
export async function readCiFixTestRunsArtifact(worktreePath, expected, deps) {
|
|
330
|
+
if (!expected)
|
|
331
|
+
return { status: "invalid", code: "logical_job_unavailable" };
|
|
332
|
+
const directory = path.join(worktreePath, ".conductor");
|
|
333
|
+
const artifactPath = path.join(worktreePath, CI_FIX_TEST_RUNS_PATH);
|
|
334
|
+
if (deps.lstatPath) {
|
|
335
|
+
try {
|
|
336
|
+
const dirMeta = await deps.lstatPath(directory);
|
|
337
|
+
if (dirMeta === null)
|
|
338
|
+
return { status: "missing", code: "artifact_absent" };
|
|
339
|
+
if (!dirMeta.isDirectory || dirMeta.isSymbolicLink) {
|
|
340
|
+
return { status: "invalid", code: "artifact_directory_unsafe" };
|
|
341
|
+
}
|
|
342
|
+
const meta = await deps.lstatPath(artifactPath);
|
|
343
|
+
if (meta === null)
|
|
344
|
+
return { status: "missing", code: "artifact_absent" };
|
|
345
|
+
if (meta.isDirectory || meta.isSymbolicLink) {
|
|
346
|
+
return { status: "invalid", code: "artifact_not_regular_file" };
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
catch {
|
|
350
|
+
return { status: "invalid", code: "artifact_unreadable" };
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
let raw;
|
|
354
|
+
try {
|
|
355
|
+
raw = await deps.readFile(artifactPath);
|
|
356
|
+
}
|
|
357
|
+
catch (err) {
|
|
358
|
+
const code = err && typeof err === "object" ? err.code : undefined;
|
|
359
|
+
return code === "ENOENT"
|
|
360
|
+
? { status: "missing", code: "artifact_absent" }
|
|
361
|
+
: { status: "invalid", code: "artifact_unreadable" };
|
|
362
|
+
}
|
|
363
|
+
if (typeof raw !== "string")
|
|
364
|
+
return { status: "invalid", code: "artifact_unreadable" };
|
|
365
|
+
if (byteLength(raw) > RESULT_JSONB_MAX_BYTES)
|
|
366
|
+
return { status: "invalid", code: "artifact_oversized" };
|
|
367
|
+
let parsed;
|
|
368
|
+
try {
|
|
369
|
+
parsed = JSON.parse(raw);
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
372
|
+
return { status: "invalid", code: "artifact_not_json" };
|
|
373
|
+
}
|
|
374
|
+
const evidence = parseCiFixTestRuns(parsed, expected);
|
|
375
|
+
return evidence ? { status: "valid", evidence } : { status: "invalid", code: "artifact_invalid" };
|
|
376
|
+
}
|
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
* window has not elapsed; then abandon.
|
|
8
8
|
* - `invalid_job_result` → (complete only) terminal non-success; the server has
|
|
9
9
|
* already failed the job, so DO NOT then call `/fail`.
|
|
10
|
+
* - completion-evidence refusal (BAPI-1590, marked) → one send, no retry, not
|
|
11
|
+
* abandoned; the job is still running, so the runner may
|
|
12
|
+
* send its `/fail`.
|
|
10
13
|
*
|
|
11
14
|
* Retry diagnostics are bounded and never include raw result envelopes, secrets,
|
|
12
15
|
* or unbounded stdout/stderr.
|
|
@@ -31,6 +34,11 @@ export async function sendTerminalMutationWithRetry(params) {
|
|
|
31
34
|
// a lost/stale claim) and never invokes `send()` a second time.
|
|
32
35
|
return { outcome: "auth_fatal", httpStatus: mapped.authHttpStatus ?? 401 };
|
|
33
36
|
}
|
|
37
|
+
// BAPI-1590: ordered BEFORE the stale-claim branch on purpose.
|
|
38
|
+
if (mapped.completionEvidenceRefused === true) {
|
|
39
|
+
params.log?.(`${params.kind}: server refused success on the completion evidence`);
|
|
40
|
+
return { outcome: "completion_evidence_refused", completionEvidenceRefused: true };
|
|
41
|
+
}
|
|
34
42
|
if (outcome === "stale_claim") {
|
|
35
43
|
ownership.abandoned = true;
|
|
36
44
|
ownership.abandonReason = "stale_claim";
|
|
@@ -24,6 +24,7 @@ import { readRequiredVerification } from "./completion-supervision.js";
|
|
|
24
24
|
import { isValidExecutorEpicRunId } from "./claim-scope.js";
|
|
25
25
|
import path from "node:path";
|
|
26
26
|
import { isSafeRepoRelativePath } from "../dependency-install-declarations.js";
|
|
27
|
+
import { PRE_PR_BUDGET_SECONDS } from "./pre-pr-checks.js";
|
|
27
28
|
/**
|
|
28
29
|
* BAPI-1296: `ci_fix` is the one recovery job with a FOCUSED prompt route. It
|
|
29
30
|
* renders its server-authored `payload.prompt_spec` (the dispatched failing and
|
|
@@ -93,6 +94,34 @@ export function resolveExecutorPrompt(job, trusted) {
|
|
|
93
94
|
}
|
|
94
95
|
return resolveExecutorPromptLegacy(job, trusted);
|
|
95
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.";
|
|
96
125
|
function resolveExecutorPromptLegacy(job, trusted) {
|
|
97
126
|
const payload = job.payload && typeof job.payload === "object"
|
|
98
127
|
? job.payload
|
|
@@ -114,14 +143,19 @@ function resolveExecutorPromptLegacy(job, trusted) {
|
|
|
114
143
|
const header = `Continue the retained branch ${branch}. Complete only the ${kind} obligation: ${obligation}. ` +
|
|
115
144
|
"Preserve completed work and existing limits. Do not invoke a full implementation or planning workflow.";
|
|
116
145
|
const operatorContext = renderOperatorNoteBlock(payload);
|
|
117
|
-
|
|
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
|
|
118
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."
|
|
119
153
|
: "";
|
|
120
154
|
const pushing = job.job_type !== "reconcile_overlap" && kind !== "overlap_reconciliation";
|
|
121
155
|
const guidance = pushing ? renderWorkerPushAndCommitGuidance(job.job_type === "rebase") +
|
|
122
156
|
"\n\n" + renderWorkerTestInvocationGuidance(payload.verification_handoff_enabled === true) +
|
|
123
157
|
(trusted ? "\n\n" + renderWorkerVerificationGuidance(trusted.comparisonSha) : "") : "";
|
|
124
|
-
const focusedHeader = `${header}${operatorContext}${prGuidance}${guidance}`;
|
|
158
|
+
const focusedHeader = `${header}${explanatoryBlocks}${operatorContext}${prGuidance}${guidance}`;
|
|
125
159
|
if (kind === "approved_spec_delta") {
|
|
126
160
|
const delta = intent.approved_delta;
|
|
127
161
|
return { ok: true, prompt: `${focusedHeader}\nApproved files: ${delta.file_boundary.join(", ")}\n` +
|
|
@@ -282,6 +316,8 @@ const STALE_DEPENDENCY_TEXT = {
|
|
|
282
316
|
shared_inode: "dependency files have shared inodes",
|
|
283
317
|
marker_uncleared: "refresh marker could not be cleared",
|
|
284
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.";
|
|
285
321
|
/** BAPI-1551: the line added when CI has no database and this worker has one. */
|
|
286
322
|
export const CI_DATABASE_NONE_LINE = "- CI runs without a database. Reproduce database-touching failures with the database variables unset.";
|
|
287
323
|
/** Same text transforms as the server's `_reproduction_text`, for the first argv item. */
|
|
@@ -368,7 +404,13 @@ function unrunnableCheckPositions(o) {
|
|
|
368
404
|
*/
|
|
369
405
|
export function renderLocalEnvironmentLimits(options) {
|
|
370
406
|
const lines = [];
|
|
371
|
-
|
|
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) {
|
|
372
414
|
const category = options.databaseUnavailableCategory;
|
|
373
415
|
const cause = options.databaseUnavailableCause;
|
|
374
416
|
const causeText = category === "migration_failed" && typeof cause === "string" &&
|
|
@@ -421,3 +463,30 @@ export function renderRequiredBeforePush(references) {
|
|
|
421
463
|
...references.map((reference) => `- ${reference}`),
|
|
422
464
|
].join("\n");
|
|
423
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
|
+
}
|
|
@@ -10,9 +10,11 @@
|
|
|
10
10
|
*
|
|
11
11
|
* A worker database is created per job by the executor, migrated with the job's
|
|
12
12
|
* own branch, and dropped when the job ends. Workers connect to it as the
|
|
13
|
-
*
|
|
14
|
-
* `LOGIN CREATEDB` and nothing else and is refused on
|
|
15
|
-
*
|
|
13
|
+
* configured loopback role, which holds
|
|
14
|
+
* `LOGIN CREATEDB` and nothing else and is refused on every protected database
|
|
15
|
+
* (Architecture Miss 28). The role, protected databases, and URL aliases come
|
|
16
|
+
* from the project's `worker_database` declaration (BAPI-1598), never from a
|
|
17
|
+
* constant here. The one-time role setup lives in
|
|
16
18
|
* `docs/claude/runbooks/local-db-safety.md`.
|
|
17
19
|
*/
|
|
18
20
|
/**
|
|
@@ -23,8 +25,6 @@
|
|
|
23
25
|
* reach a live worker's database.
|
|
24
26
|
*/
|
|
25
27
|
export const WORKER_DATABASE_PREFIX = "bridge_worker_job_";
|
|
26
|
-
/** The dedicated loopback role a worker connects as. The executor never creates it. */
|
|
27
|
-
export const WORKER_DATABASE_ROLE = "bridge_epic_worker";
|
|
28
28
|
/** Loopback host the worker role connects to — never a hostname a resolver could redirect. */
|
|
29
29
|
export const WORKER_DATABASE_HOST = "127.0.0.1";
|
|
30
30
|
/** The local PostgreSQL port. A string because it lands in an environment. */
|
|
@@ -65,27 +65,31 @@ export function validateWorkerDatabaseName(name) {
|
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* The environment keys that point a worker at its job database, in the shape
|
|
68
|
-
* CI's database-backed lanes use: the per-job name in
|
|
69
|
-
* `POSTGRES_DATABASE`/`POSTGRES_DB`/`PGDATABASE` trio, the loopback host,
|
|
70
|
-
* and role, an empty-but-PRESENT `POSTGRES_PASSWORD` (`db/utils.py`
|
|
68
|
+
* CI's database-backed lanes use: the per-job name in each configured URL alias
|
|
69
|
+
* and the `POSTGRES_DATABASE`/`POSTGRES_DB`/`PGDATABASE` trio, the loopback host,
|
|
70
|
+
* port, and role, an empty-but-PRESENT `POSTGRES_PASSWORD` (`db/utils.py`
|
|
71
71
|
* `resolve_db_params()` requires the key to exist), and the `PG*` mirrors.
|
|
72
72
|
*
|
|
73
73
|
* Validates the name first, so no environment is ever produced for a name that
|
|
74
74
|
* is not a worker database.
|
|
75
75
|
*/
|
|
76
|
-
export function buildWorkerDatabaseEnv(target) {
|
|
76
|
+
export function buildWorkerDatabaseEnv(target, options) {
|
|
77
77
|
const name = validateWorkerDatabaseName(target.name);
|
|
78
|
+
const url = `postgresql://${options.role}@${WORKER_DATABASE_HOST}:${WORKER_DATABASE_PORT}/${name}`;
|
|
79
|
+
const env = {};
|
|
80
|
+
for (const alias of options.envNames)
|
|
81
|
+
env[alias] = url;
|
|
78
82
|
return {
|
|
79
|
-
|
|
83
|
+
...env,
|
|
80
84
|
POSTGRES_DATABASE: name,
|
|
81
85
|
POSTGRES_DB: name,
|
|
82
86
|
PGDATABASE: name,
|
|
83
87
|
POSTGRES_HOST: WORKER_DATABASE_HOST,
|
|
84
88
|
POSTGRES_PORT: WORKER_DATABASE_PORT,
|
|
85
|
-
POSTGRES_USER:
|
|
89
|
+
POSTGRES_USER: options.role,
|
|
86
90
|
POSTGRES_PASSWORD: "",
|
|
87
91
|
PGHOST: WORKER_DATABASE_HOST,
|
|
88
92
|
PGPORT: WORKER_DATABASE_PORT,
|
|
89
|
-
PGUSER:
|
|
93
|
+
PGUSER: options.role,
|
|
90
94
|
};
|
|
91
95
|
}
|