@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.
- package/README.md +55 -17
- package/build/agent-launchers/claude-executor-adapter.js +29 -4
- package/build/agent-notes.js +171 -95
- package/build/agent-registry.js +5 -5
- package/build/agents.generated.js +12 -2
- package/build/bounded-wait.js +9 -1
- package/build/bridge-permissions.js +17 -5
- package/build/bridge-worktree-inspection.js +237 -0
- package/build/check-evidence.js +6 -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-skill-adapter.js +2 -0
- package/build/commands.generated.js +5 -5
- package/build/conductor/bridge-api-client.js +776 -23
- package/build/conductor/command-drift-production.js +7 -2
- package/build/conductor/doctor.js +93 -13
- package/build/conductor/epic-implementer-cli.js +55 -2
- package/build/conductor/gate-discovery.js +659 -19
- package/build/conductor/gate-settings-review.js +751 -0
- 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 +16 -11
- package/build/conductor/launch-plan.js +185 -0
- 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/precheck-timings.js +14 -0
- package/build/conductor/prerequisite-inputs.js +379 -0
- package/build/conductor/preview-observations.js +10 -0
- package/build/conductor/readiness-assessment.js +78 -0
- package/build/conductor/readiness-cli.js +10 -0
- package/build/conductor/readiness-prerequisites.js +53 -0
- package/build/conductor/readiness-sections.js +25 -9
- package/build/conductor/readiness.js +20 -2
- package/build/conductor/recovery-cli.js +281 -14
- package/build/conductor/recovery-operations.js +78 -5
- package/build/conductor/repair-contract.js +33 -0
- package/build/conductor/tools.js +34 -3
- package/build/conductor/wait-run-attention.js +115 -0
- package/build/conductor/wait-run-cli.js +96 -3
- package/build/conductor/worker-database-doctor-inspector.js +1 -0
- package/build/credential-store.js +25 -20
- package/build/dependency-install-declarations.js +157 -0
- package/build/docs.generated.js +4 -4
- package/build/doctor.js +37 -5
- package/build/drive-epic-help.js +2 -2
- package/build/drive-epic.js +240 -56
- package/build/epic-ci-workflow-drift.js +71 -23
- package/build/epic-ci-workflow-install.js +83 -26
- package/build/epic-ci-workflow-v1.js +132 -0
- package/build/epic-ci-workflow.js +174 -13
- package/build/epic-implementer-bin.js +119 -44
- package/build/epic-launch-profile.js +1 -1
- package/build/executor/ci-rerun-job.js +220 -14
- package/build/executor/cli.js +2 -0
- package/build/executor/completion-contract.js +16 -0
- 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 +274 -5
- package/build/executor/gate-qualification-job.js +20 -5
- package/build/executor/harness-coverage.js +19 -0
- package/build/executor/http-client.js +35 -1
- package/build/executor/index.js +2 -1
- package/build/executor/install-preflight.js +1 -1
- package/build/executor/job-runner.js +355 -36
- package/build/executor/likely-tests.js +100 -98
- package/build/executor/preflight.js +5 -0
- package/build/executor/process-containment.js +18 -0
- package/build/executor/prompt-spec.js +84 -15
- package/build/executor/reconcile-overlap-job.js +6 -1
- package/build/executor/required-verification.js +28 -0
- package/build/executor/required-work-diagnostics.js +30 -0
- package/build/executor/required-work-ledger.js +19 -1
- package/build/executor/results.js +42 -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/test-clock.js +3 -0
- package/build/executor/verification-hints.js +179 -0
- package/build/executor/worker-command.js +188 -1
- package/build/executor/worker-database.js +299 -40
- package/build/executor/worker-finalization.js +65 -10
- package/build/executor/worker-guard-hook.js +10 -2
- package/build/executor/worker-resources.js +12 -1
- package/build/executor/worker-verification-guidance.js +64 -0
- package/build/executor/worktree-inspection.js +42 -0
- package/build/github-sign-in.js +1 -1
- package/build/index.js +767 -310
- package/build/init.js +3 -3
- package/build/install-bridge-conductor-gate.js +416 -41
- package/build/install-bridge-conductor-setup.js +135 -32
- package/build/install-bridge-conductor.js +769 -353
- package/build/install-bridge.js +419 -124
- package/build/install-maintenance.js +104 -0
- package/build/install-reexec.js +1 -1
- package/build/local-cleanup.js +59 -0
- package/build/mcp-install-state.js +68 -2
- package/build/merge-workflow-install.js +22 -2
- 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-execution-ledger.js +171 -10
- package/build/plane/plane-freshness.js +12 -9
- package/build/plane/preflight.js +19 -0
- package/build/plane/terminal-run-cleanup.js +5 -1
- package/build/plane/terminal-run-status.js +4 -0
- package/build/printed-remedy-commands.js +31 -4
- package/build/readiness-check.js +1 -78
- package/build/readiness-prerequisites.generated.js +199 -0
- package/build/readme.generated.js +1 -1
- package/build/repository-toolchains.js +623 -0
- package/build/setup-change-policy.js +32 -0
- package/build/setup-epic.js +26 -9
- package/build/setup-question.js +62 -0
- package/build/start-tickets.js +4 -0
- package/build/test-command-detection.js +61 -80
- package/build/test-support/notes-fs.js +40 -0
- package/build/ticket-delivery-artifacts.js +7 -0
- package/build/ticket-delivery-enrollment.js +80 -4
- package/build/ticket-delivery-run-scope.js +128 -0
- 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.md +43 -0
- package/docs/epic-implementer/getting-started.md +95 -14
- 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
|
+
}
|
|
@@ -17,11 +17,13 @@
|
|
|
17
17
|
* distinct from the argv vocabulary is what stops a future flag rename in one
|
|
18
18
|
* agent's CLI from becoming an operator-visible policy break across all of them.
|
|
19
19
|
*/
|
|
20
|
-
import { renderWorkerVerificationGuidance, renderWorkerPushAndCommitGuidance } from "./worker-verification-guidance.js";
|
|
20
|
+
import { renderWorkerVerificationGuidance, renderWorkerPushAndCommitGuidance, renderWorkerTestInvocationGuidance } from "./worker-verification-guidance.js";
|
|
21
21
|
import { CiFixContext, ExecutorNamedError } from "./job-errors.js";
|
|
22
22
|
import { isRemainingWork, validateCorrectionIntent } from "./correction-dispatch.js";
|
|
23
23
|
import { readRequiredVerification } from "./completion-supervision.js";
|
|
24
24
|
import { isValidExecutorEpicRunId } from "./claim-scope.js";
|
|
25
|
+
import path from "node:path";
|
|
26
|
+
import { isSafeRepoRelativePath } from "../dependency-install-declarations.js";
|
|
25
27
|
/**
|
|
26
28
|
* BAPI-1296: `ci_fix` is the one recovery job with a FOCUSED prompt route. It
|
|
27
29
|
* renders its server-authored `payload.prompt_spec` (the dispatched failing and
|
|
@@ -117,6 +119,7 @@ function resolveExecutorPromptLegacy(job, trusted) {
|
|
|
117
119
|
: "";
|
|
118
120
|
const pushing = job.job_type !== "reconcile_overlap" && kind !== "overlap_reconciliation";
|
|
119
121
|
const guidance = pushing ? renderWorkerPushAndCommitGuidance(job.job_type === "rebase") +
|
|
122
|
+
"\n\n" + renderWorkerTestInvocationGuidance(payload.verification_handoff_enabled === true) +
|
|
120
123
|
(trusted ? "\n\n" + renderWorkerVerificationGuidance(trusted.comparisonSha) : "") : "";
|
|
121
124
|
const focusedHeader = `${header}${operatorContext}${prGuidance}${guidance}`;
|
|
122
125
|
if (kind === "approved_spec_delta") {
|
|
@@ -234,3 +237,187 @@ export function resolveWorkerPermissionPosture(payload) {
|
|
|
234
237
|
// than assembling a Claude-shaped command here. Re-adding a builder to this
|
|
235
238
|
// module would recreate the exact coupling the extraction removed: a generic
|
|
236
239
|
// job-policy module that only works for one CLI.
|
|
240
|
+
// ---------------------------------------------------------------------------
|
|
241
|
+
// LOCAL ENVIRONMENT LIMITS (BAPI-1522)
|
|
242
|
+
// ---------------------------------------------------------------------------
|
|
243
|
+
/** The heading of the final prompt section that names what cannot run locally. */
|
|
244
|
+
export const LOCAL_ENVIRONMENT_LIMITS_HEADING = "## LOCAL ENVIRONMENT LIMITS ##";
|
|
245
|
+
/**
|
|
246
|
+
* The closed database-unavailable categories the section may name. Mirrors
|
|
247
|
+
* `WorkerDatabaseUnavailableCategory`; the annotation makes the compiler reject
|
|
248
|
+
* a member the type does not have. Anything else is omitted from the line.
|
|
249
|
+
*/
|
|
250
|
+
const RECOGNIZED_DATABASE_CATEGORIES = new Set([
|
|
251
|
+
"client_missing", "postgres_unavailable", "role_missing", "role_misconfigured",
|
|
252
|
+
"bridgeapi_reachable", "boundary_unknown", "alembic_missing", "create_failed",
|
|
253
|
+
"migration_failed", "timeout", "cancelled",
|
|
254
|
+
]);
|
|
255
|
+
/**
|
|
256
|
+
* The closed migration causes the section may name. Mirrors
|
|
257
|
+
* `WorkerDatabaseMigrationCause`; the annotation makes the compiler reject a
|
|
258
|
+
* member the type does not have. Anything else is omitted from the line.
|
|
259
|
+
*/
|
|
260
|
+
const RECOGNIZED_DATABASE_CAUSES = new Set([
|
|
261
|
+
"multiple_heads", "revision_missing", "ssl_refused", "connection_refused", "permission_denied", "timeout", "other",
|
|
262
|
+
]);
|
|
263
|
+
/**
|
|
264
|
+
* Mirrors the server renderer's admission rules
|
|
265
|
+
* (`render_reproduction_section` in `prompt_specs.py`): the first 64 entries,
|
|
266
|
+
* the recognized sources, and a usable (non-blank) rendered check name.
|
|
267
|
+
*/
|
|
268
|
+
const REPRODUCE_MAX_ENTRIES = 64;
|
|
269
|
+
const REPRODUCE_MAX_CHECK_CHARS = 200;
|
|
270
|
+
const REPRODUCE_MAX_ARGV_ITEMS = 32;
|
|
271
|
+
const REPRODUCE_MAX_ARG_CHARS = 1024;
|
|
272
|
+
const REPRODUCE_SOURCES = new Set(["check_hint", "test_command", "none"]);
|
|
273
|
+
const REPRODUCE_SOURCE_NONE = "none";
|
|
274
|
+
/** Python `str.strip()` whitespace, which differs from JavaScript's `trim()`. */
|
|
275
|
+
const PYTHON_BLANK = /^[\t\n\v\f\r\x1c-\x1f \x85\xa0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000]*$/;
|
|
276
|
+
/** BAPI-1551: the fixed stale-dependency wording, keyed by closed reason. */
|
|
277
|
+
const STALE_DEPENDENCY_TEXT = {
|
|
278
|
+
install_failed: "install failed",
|
|
279
|
+
lockfile_unreadable: "lockfile could not be read",
|
|
280
|
+
no_budget: "not enough job time to refresh",
|
|
281
|
+
copy_uncertain: "background copy still running or completion unknown",
|
|
282
|
+
shared_inode: "dependency files have shared inodes",
|
|
283
|
+
marker_uncleared: "refresh marker could not be cleared",
|
|
284
|
+
};
|
|
285
|
+
/** BAPI-1551: the line added when CI has no database and this worker has one. */
|
|
286
|
+
export const CI_DATABASE_NONE_LINE = "- CI runs without a database. Reproduce database-touching failures with the database variables unset.";
|
|
287
|
+
/** Same text transforms as the server's `_reproduction_text`, for the first argv item. */
|
|
288
|
+
function reproductionText(value, maxChars) {
|
|
289
|
+
if (typeof value !== "string")
|
|
290
|
+
return "";
|
|
291
|
+
let text = Array.from(value, ch => {
|
|
292
|
+
const code = ch.codePointAt(0) ?? 0;
|
|
293
|
+
return code < 32 || code === 127 ? " " : ch;
|
|
294
|
+
}).slice(0, maxChars).join("").split('"""').join("' ' '");
|
|
295
|
+
while (text.includes("{{") || text.includes("}}")) {
|
|
296
|
+
text = text.split("{{").join("{ {").split("}}").join("} }");
|
|
297
|
+
}
|
|
298
|
+
return text;
|
|
299
|
+
}
|
|
300
|
+
/** The displayed first argv item of a usable argument array, or `null`. */
|
|
301
|
+
function displayedProgram(argv) {
|
|
302
|
+
if (!Array.isArray(argv) || argv.length === 0 || argv.length > REPRODUCE_MAX_ARGV_ITEMS)
|
|
303
|
+
return null;
|
|
304
|
+
for (const item of argv)
|
|
305
|
+
if (typeof item !== "string" || item.length === 0)
|
|
306
|
+
return null;
|
|
307
|
+
return reproductionText(argv[0], REPRODUCE_MAX_ARG_CHARS);
|
|
308
|
+
}
|
|
309
|
+
function isWithin(root, candidate) {
|
|
310
|
+
const relative = path.relative(root, candidate);
|
|
311
|
+
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
|
312
|
+
}
|
|
313
|
+
function programRunnable(program, o) {
|
|
314
|
+
try {
|
|
315
|
+
if (program.includes("/") || program.includes("\\")) {
|
|
316
|
+
const resolved = path.resolve(o.worktreePath, program);
|
|
317
|
+
if (!isWithin(o.worktreePath, resolved))
|
|
318
|
+
return false;
|
|
319
|
+
return o.isExecutable(resolved, { withinDirectory: o.worktreePath });
|
|
320
|
+
}
|
|
321
|
+
for (const dir of (o.workerPath ?? "").split(path.delimiter)) {
|
|
322
|
+
if (!dir)
|
|
323
|
+
continue;
|
|
324
|
+
if (o.isExecutable(path.resolve(o.worktreePath, dir, program)))
|
|
325
|
+
return true;
|
|
326
|
+
}
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
catch {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* The 1-based positions of displayed reproduction blocks whose program is not
|
|
335
|
+
* runnable. A position counts every admitted block, with or without a command.
|
|
336
|
+
*/
|
|
337
|
+
function unrunnableCheckPositions(o) {
|
|
338
|
+
const entries = Array.isArray(o.reproduceCommands) ? o.reproduceCommands.slice(0, REPRODUCE_MAX_ENTRIES) : [];
|
|
339
|
+
const missing = [];
|
|
340
|
+
let position = 0;
|
|
341
|
+
for (const entry of entries) {
|
|
342
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
343
|
+
continue;
|
|
344
|
+
const e = entry;
|
|
345
|
+
if (typeof e.source !== "string" || !REPRODUCE_SOURCES.has(e.source))
|
|
346
|
+
continue;
|
|
347
|
+
const check = reproductionText(e.check, REPRODUCE_MAX_CHECK_CHARS);
|
|
348
|
+
if (PYTHON_BLANK.test(check))
|
|
349
|
+
continue;
|
|
350
|
+
position += 1;
|
|
351
|
+
if (e.source === REPRODUCE_SOURCE_NONE)
|
|
352
|
+
continue;
|
|
353
|
+
const program = displayedProgram(e.argv);
|
|
354
|
+
if (program === null || program.trim().length === 0)
|
|
355
|
+
continue;
|
|
356
|
+
if (!programRunnable(program, o))
|
|
357
|
+
missing.push(position);
|
|
358
|
+
}
|
|
359
|
+
return missing;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Render the `LOCAL ENVIRONMENT LIMITS` section, or `""` when nothing is limited.
|
|
363
|
+
*
|
|
364
|
+
* Informational only: it adds no completion obligation, evidence rule, or exit.
|
|
365
|
+
* It names a missing program by its numbered Check position alone, never by check
|
|
366
|
+
* name, command text, executable name, or host path, and it never carries a
|
|
367
|
+
* credential, connection value, or internal diagnostic.
|
|
368
|
+
*/
|
|
369
|
+
export function renderLocalEnvironmentLimits(options) {
|
|
370
|
+
const lines = [];
|
|
371
|
+
if (!options.databaseAvailable) {
|
|
372
|
+
const category = options.databaseUnavailableCategory;
|
|
373
|
+
const cause = options.databaseUnavailableCause;
|
|
374
|
+
const causeText = category === "migration_failed" && typeof cause === "string" &&
|
|
375
|
+
RECOGNIZED_DATABASE_CAUSES.has(cause) ? `, cause: ${cause}` : "";
|
|
376
|
+
const reason = category !== undefined && RECOGNIZED_DATABASE_CATEGORIES.has(category)
|
|
377
|
+
? ` (reason: ${category}${causeText})` : "";
|
|
378
|
+
lines.push(`- No disposable database was provisioned for this worker${reason}, so database-backed ` +
|
|
379
|
+
"verification cannot run locally. CI at the pushed head is the verifier.");
|
|
380
|
+
}
|
|
381
|
+
for (const position of unrunnableCheckPositions(options)) {
|
|
382
|
+
lines.push(`- Check ${position} in HOW TO REPRODUCE LOCALLY (counting its \`Check:\` blocks in order): ` +
|
|
383
|
+
"the program its command starts with is not runnable on this machine. Do not attempt that " +
|
|
384
|
+
"command. CI at the pushed head is the verifier.");
|
|
385
|
+
}
|
|
386
|
+
if (options.ciDatabase === "none" && options.databaseAvailable)
|
|
387
|
+
lines.push(CI_DATABASE_NONE_LINE);
|
|
388
|
+
for (const stale of options.staleDependencyCwds ?? []) {
|
|
389
|
+
const text = STALE_DEPENDENCY_TEXT[stale.reason];
|
|
390
|
+
if (text === undefined || !isSafeRepoRelativePath(stale.cwd, { allowRoot: true }))
|
|
391
|
+
continue;
|
|
392
|
+
lines.push(`- dependencies for ${stale.cwd} may be stale: ${text}`);
|
|
393
|
+
}
|
|
394
|
+
if (lines.length === 0)
|
|
395
|
+
return "";
|
|
396
|
+
return [
|
|
397
|
+
LOCAL_ENVIRONMENT_LIMITS_HEADING,
|
|
398
|
+
...lines,
|
|
399
|
+
"Where the repository has no CI checks, its gate decides at merge.",
|
|
400
|
+
"This section is informational. It adds no completion obligation, evidence rule, or exit.",
|
|
401
|
+
].join("\n");
|
|
402
|
+
}
|
|
403
|
+
// ---------------------------------------------------------------------------
|
|
404
|
+
// REQUIRED BEFORE PUSH (BAPI-1551)
|
|
405
|
+
// ---------------------------------------------------------------------------
|
|
406
|
+
/** The heading of the section naming the repository's always-run guard tests. */
|
|
407
|
+
export const REQUIRED_BEFORE_PUSH_HEADING = "## REQUIRED BEFORE PUSH ##";
|
|
408
|
+
/**
|
|
409
|
+
* Render the `REQUIRED BEFORE PUSH` section from the ADMITTED `always` entries of
|
|
410
|
+
* `.bridge/verification-hints.json`, or `""` when there are none. The entries are
|
|
411
|
+
* test references, never shell text; the worker maps them through the
|
|
412
|
+
* repository's declared runner.
|
|
413
|
+
*/
|
|
414
|
+
export function renderRequiredBeforePush(references) {
|
|
415
|
+
if (references.length === 0)
|
|
416
|
+
return "";
|
|
417
|
+
return [
|
|
418
|
+
REQUIRED_BEFORE_PUSH_HEADING,
|
|
419
|
+
"This repository declares always-run guard tests: run these before you push, whatever you changed, " +
|
|
420
|
+
"through the repository's declared test runner. They are test references, not shell commands.",
|
|
421
|
+
...references.map((reference) => `- ${reference}`),
|
|
422
|
+
].join("\n");
|
|
423
|
+
}
|