@bridge_gpt/mcp-server 0.2.72 → 0.2.74
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 +15 -0
- package/build/agents.generated.js +6 -6
- package/build/bridge-config.js +7 -1
- package/build/bridge-permissions.js +30 -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/command-provisioning.js +4 -3
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +867 -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 +48 -1
- package/build/conductor/declare-blocked.js +554 -0
- package/build/conductor/declared-extras.js +335 -0
- package/build/conductor/doctor.js +108 -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-pass-output.js +104 -0
- package/build/conductor/driver-pass.js +571 -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 +281 -43
- package/build/conductor/epic-implementer-cli.js +199 -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-upload.js +1567 -0
- package/build/conductor/epic-server-sfcc.js +85 -0
- package/build/conductor/epic-server-state.js +427 -0
- package/build/conductor/epic-server.js +647 -0
- package/build/conductor/gate-discovery.js +196 -11
- package/build/conductor/gate-settings-review.js +261 -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-delivery.js +280 -0
- package/build/credential-launch-safety.js +142 -0
- package/build/credential-materialization.js +91 -16
- package/build/credential-references-node-deps.js +29 -0
- package/build/credential-references.js +1394 -0
- package/build/credential-references.test-fixtures.js +211 -0
- package/build/credential-scan-conventions.js +145 -0
- package/build/credential-scan.js +517 -0
- package/build/credential-store.js +121 -1
- package/build/credentials-cli.js +252 -3
- package/build/dependency-install-declarations.js +102 -1
- package/build/docs.generated.js +10 -3
- package/build/doctor.js +95 -3
- package/build/drive-epic-help.js +21 -2
- package/build/drive-epic.js +2095 -375
- package/build/engine-paths.js +20 -0
- package/build/epic-branch-ci-summary.js +157 -0
- package/build/epic-capability-statement.js +175 -0
- package/build/epic-ci-workflow-drift.js +77 -23
- package/build/epic-ci-workflow-install.js +137 -44
- package/build/epic-ci-workflow-v2.js +274 -0
- package/build/epic-ci-workflow-v3.js +273 -0
- package/build/epic-ci-workflow.js +165 -18
- package/build/epic-implementer-bin.js +2204 -56
- package/build/epic-launch-context.js +702 -0
- package/build/epic-server-record.js +288 -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/credential-delivery-step.js +168 -0
- package/build/executor/deps.js +3 -1
- package/build/executor/env.js +98 -23
- package/build/executor/epic-server-context.js +157 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/guarded-fast-forward-push.js +13 -8
- package/build/executor/http-client.js +52 -5
- package/build/executor/job-runner.js +577 -81
- package/build/executor/observation.js +8 -0
- package/build/executor/permissions.js +85 -3
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +149 -3
- 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 +58 -4
- package/build/generated-assets-catalog.js +2 -2
- package/build/git-exclude-lock.js +187 -0
- package/build/index.js +824 -366
- package/build/init.js +26 -11
- package/build/install-bridge-conductor-answers.js +528 -0
- package/build/install-bridge-conductor-apply.js +288 -0
- package/build/install-bridge-conductor-assessment.js +1222 -0
- package/build/install-bridge-conductor-compact.js +186 -0
- package/build/install-bridge-conductor-contracts.js +72 -0
- package/build/install-bridge-conductor-gate.js +1312 -198
- package/build/install-bridge-conductor-setup.js +577 -83
- package/build/install-bridge-conductor.js +3381 -544
- package/build/install-bridge.js +280 -25
- package/build/install-doctor.js +38 -8
- package/build/install-maintenance.js +26 -3
- package/build/install-sfcc-detection.js +120 -0
- package/build/install-sfcc-setup.js +185 -0
- package/build/launcher-config-inspection.js +162 -1
- package/build/mcp-grant-candidates.js +779 -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 +292 -15
- package/build/mcp-presets.js +107 -0
- package/build/mcp-provisioning.js +155 -6
- package/build/mcp-registration-doctor.js +31 -2
- package/build/mcp-server-invocation.js +19 -1
- package/build/merge-workflow-install.js +243 -110
- package/build/pipelines.generated.js +7 -6
- 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/status.js +8 -2
- package/build/plane/terminal-run-cleanup.js +18 -4
- package/build/printed-remedy-commands.js +211 -12
- package/build/project-root.js +40 -0
- 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 +41 -0
- package/build/repository-toolchains.js +6 -3
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-epic.js +1305 -210
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +122 -4
- package/build/sfcc/credentials.js +3 -2
- package/build/sfcc/hostname.js +98 -2
- package/build/sfcc/tool-wrapper.js +6 -95
- package/build/start-tickets.js +193 -29
- package/build/test-support/executor-source-files.js +200 -0
- package/build/testing-config-client.js +25 -2
- package/build/third-party-mcp-targets.js +63 -2
- 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/build/with-credentials.js +208 -0
- package/build/worktree-credential-delivery.js +340 -0
- 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
|
@@ -681,6 +681,7 @@ export function createObservationState(deps, options) {
|
|
|
681
681
|
let exitCode;
|
|
682
682
|
let attemptStartSha;
|
|
683
683
|
let attemptEndSha;
|
|
684
|
+
let workerDatabaseProvisioned = false;
|
|
684
685
|
/**
|
|
685
686
|
* BAPI-828/BAPI-898: the MOST SEVERE qualifying advisory observed so far wins,
|
|
686
687
|
* ranked by {@link rateLimitSeverity}. An advisory at equal or lower severity —
|
|
@@ -847,6 +848,9 @@ export function createObservationState(deps, options) {
|
|
|
847
848
|
}
|
|
848
849
|
publication = { ...publication, to_sha: fact.to_sha };
|
|
849
850
|
},
|
|
851
|
+
recordWorkerDatabaseProvisioned() {
|
|
852
|
+
workerDatabaseProvisioned = true;
|
|
853
|
+
},
|
|
850
854
|
snapshot() {
|
|
851
855
|
const residue = { ...git };
|
|
852
856
|
if (publication) {
|
|
@@ -870,6 +874,10 @@ export function createObservationState(deps, options) {
|
|
|
870
874
|
residue.attempt_start_sha = attemptStartSha;
|
|
871
875
|
if (attemptEndSha !== undefined)
|
|
872
876
|
residue.attempt_end_sha = attemptEndSha;
|
|
877
|
+
// BAPI-1609: absent until a database was really provisioned, so a job
|
|
878
|
+
// without one serializes exactly as before.
|
|
879
|
+
if (workerDatabaseProvisioned)
|
|
880
|
+
residue.worker_resources = { database: "provisioned" };
|
|
873
881
|
return residue;
|
|
874
882
|
},
|
|
875
883
|
terminalCapacity() {
|
|
@@ -37,7 +37,39 @@
|
|
|
37
37
|
*/
|
|
38
38
|
import { randomUUID } from "node:crypto";
|
|
39
39
|
import path from "node:path";
|
|
40
|
+
import { acquireExcludeLock } from "../git-exclude-lock.js";
|
|
40
41
|
import { mergeClaudeSettingsWithAutoMemoryDisabled, mergeClaudeSettingsWithCommandHook, provisionClaudeSettingsForWorktree, DEFAULT_PRE_TOOL_USE_MATCHER, } from "../claude-settings.js";
|
|
42
|
+
/**
|
|
43
|
+
* BAPI-1647: one exact `Read(<path>)` rule per distinct restricted source path,
|
|
44
|
+
* in first-seen order. A path with a control character, or that is not
|
|
45
|
+
* absolute, is skipped (child 1 already refuses both in the record).
|
|
46
|
+
*
|
|
47
|
+
* A POSIX absolute path also gets the `Read(/<path>)` form (two leading
|
|
48
|
+
* slashes): Claude Code's permission grammar reads a single leading `/` as
|
|
49
|
+
* relative to the settings file and `//` as the filesystem root, so the second
|
|
50
|
+
* form is the one that is certain to match the real file. The first form is the
|
|
51
|
+
* one the ticket and `doctor` name, and it matches this module's existing
|
|
52
|
+
* `Read(/etc/shadow)` convention.
|
|
53
|
+
*/
|
|
54
|
+
export function restrictedSourceDenyRules(paths) {
|
|
55
|
+
if (!paths || paths.length === 0)
|
|
56
|
+
return [];
|
|
57
|
+
const rules = [];
|
|
58
|
+
const seen = new Set();
|
|
59
|
+
for (const p of paths) {
|
|
60
|
+
if (typeof p !== "string" || p.length === 0 || /[\u0000-\u001f\u007f]/.test(p))
|
|
61
|
+
continue;
|
|
62
|
+
if (!path.posix.isAbsolute(p) && !path.win32.isAbsolute(p))
|
|
63
|
+
continue;
|
|
64
|
+
if (seen.has(p))
|
|
65
|
+
continue;
|
|
66
|
+
seen.add(p);
|
|
67
|
+
rules.push(`Read(${p})`);
|
|
68
|
+
if (path.posix.isAbsolute(p) && !p.startsWith("//"))
|
|
69
|
+
rules.push(`Read(/${p})`);
|
|
70
|
+
}
|
|
71
|
+
return rules;
|
|
72
|
+
}
|
|
41
73
|
/**
|
|
42
74
|
* The stable executor deny rules. Grammar mirrors the deny-enforcement probe's
|
|
43
75
|
* `Bash(<cmd>:<args-glob>)` / `Read(<path-glob>)` form. Covers: reads under
|
|
@@ -115,6 +147,9 @@ export function executorDenyRules(inputs) {
|
|
|
115
147
|
"Bash(docker:push*)",
|
|
116
148
|
"Bash(git push:*mcp-server/v*)",
|
|
117
149
|
"Bash(npm:publish*)",
|
|
150
|
+
// BAPI-1647 — restricted credential sources, appended after the stable list
|
|
151
|
+
// so a job with none gets exactly the list above.
|
|
152
|
+
...restrictedSourceDenyRules(inputs.restrictedSourcePaths),
|
|
118
153
|
];
|
|
119
154
|
}
|
|
120
155
|
/**
|
|
@@ -226,16 +261,46 @@ function asObject(value) {
|
|
|
226
261
|
* replaced.
|
|
227
262
|
*/
|
|
228
263
|
export function mergeExecutorDenySettings(existing, inputs) {
|
|
264
|
+
return mergeDenyRules(existing, executorDenyRules(inputs));
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Append `rules` to `permissions.deny`, keeping every existing setting and deny
|
|
268
|
+
* entry in place and adding only rules not already present (idempotent).
|
|
269
|
+
* Shared by the executor merge and BAPI-1647's restricted-read-only merge.
|
|
270
|
+
*/
|
|
271
|
+
export function mergeDenyRules(existing, rules) {
|
|
229
272
|
const permissions = { ...asObject(existing.permissions) };
|
|
230
273
|
const existingDeny = Array.isArray(permissions.deny) ? permissions.deny : [];
|
|
231
274
|
const merged = [...existingDeny];
|
|
232
|
-
for (const rule of
|
|
275
|
+
for (const rule of rules) {
|
|
233
276
|
if (!merged.includes(rule))
|
|
234
277
|
merged.push(rule);
|
|
235
278
|
}
|
|
236
279
|
permissions.deny = merged;
|
|
237
280
|
return { ...existing, permissions };
|
|
238
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* BAPI-1647: merge ONLY the restricted-source `Read(<path>)` rules into a
|
|
284
|
+
* worktree's `.claude/settings.local.json`, for `start-tickets` worktrees, which
|
|
285
|
+
* must not receive the executor's command restrictions. Uses the same
|
|
286
|
+
* malformed-safe write as the executor deny layer: a malformed file is never
|
|
287
|
+
* clobbered, unrelated settings and MCP trust entries are kept, and every
|
|
288
|
+
* failure is an advisory warning, never a stop.
|
|
289
|
+
*/
|
|
290
|
+
export async function provisionRestrictedReadDenyRules(worktreePath, restrictedSourcePaths, deps) {
|
|
291
|
+
const rules = restrictedSourceDenyRules(restrictedSourcePaths);
|
|
292
|
+
if (rules.length === 0)
|
|
293
|
+
return { ok: true };
|
|
294
|
+
try {
|
|
295
|
+
const result = await provisionClaudeSettingsForWorktree(worktreePath, (existing) => mergeDenyRules(existing, rules), deps);
|
|
296
|
+
if (result.ok)
|
|
297
|
+
return { ok: true };
|
|
298
|
+
return { ok: false, warning: "restricted credential read rules were not written: the worktree Claude settings could not be updated" };
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
return { ok: false, warning: "restricted credential read rules were not written: the worktree Claude settings could not be updated" };
|
|
302
|
+
}
|
|
303
|
+
}
|
|
239
304
|
/**
|
|
240
305
|
* The exact line appended to the worktree's `.git/info/exclude` so a worker's
|
|
241
306
|
* `git add -A` cannot commit the executor-owned settings file.
|
|
@@ -447,8 +512,15 @@ export async function resolveWorktreeSettingsExclude(worktreePath, deps) {
|
|
|
447
512
|
* the same `info/` directory and renamed into place; no lockfile is used, and
|
|
448
513
|
* nothing is published when no canonical line is missing. Competing executor
|
|
449
514
|
* writers add the same canonical entries, so fresh reads plus atomic publication
|
|
450
|
-
* prevent torn files and executor-created duplicates.
|
|
451
|
-
*
|
|
515
|
+
* prevent torn files and executor-created duplicates. Since BAPI-1647 the whole
|
|
516
|
+
* read-modify-write also runs inside the cross-process exclude lock
|
|
517
|
+
* (`git-exclude-lock.ts`), keyed on the canonical exclude path and shared with
|
|
518
|
+
* every other Bridge exclude writer, so concurrent launches in two worktrees of
|
|
519
|
+
* one repository cannot drop each other's lines. A fresh read alone did not
|
|
520
|
+
* prevent that lost update. The lock is best effort here: when it cannot be had,
|
|
521
|
+
* the publication proceeds exactly as before, so this function's outcome never
|
|
522
|
+
* changes because of it. It does not serialize against unrelated external
|
|
523
|
+
* editors.
|
|
452
524
|
*
|
|
453
525
|
* Warnings are bounded to a failure category plus the affected worktree path.
|
|
454
526
|
* They never carry `.git` contents, exception text, environment values, or
|
|
@@ -466,6 +538,9 @@ export async function provisionWorktreeSettingsExclude(worktreePath, deps) {
|
|
|
466
538
|
}
|
|
467
539
|
const { excludePath, infoDir } = resolved;
|
|
468
540
|
let tempPath;
|
|
541
|
+
// Only when the caller supplies its lock boundary: the executor's injected
|
|
542
|
+
// filesystem is the single I/O boundary its tests fake.
|
|
543
|
+
const lock = deps.excludeLock ? await acquireExcludeLock(excludePath, deps.excludeLock) : null;
|
|
469
544
|
try {
|
|
470
545
|
await deps.mkdir(infoDir, { recursive: true });
|
|
471
546
|
let existing = "";
|
|
@@ -510,6 +585,10 @@ export async function provisionWorktreeSettingsExclude(worktreePath, deps) {
|
|
|
510
585
|
warning: excludeWarning(worktreePath, "the exclude file could not be written"),
|
|
511
586
|
};
|
|
512
587
|
}
|
|
588
|
+
finally {
|
|
589
|
+
if (lock?.ok)
|
|
590
|
+
await lock.release();
|
|
591
|
+
}
|
|
513
592
|
}
|
|
514
593
|
/**
|
|
515
594
|
* Provision the executor deny layer into `<worktree>/.claude/settings.local.json`,
|
|
@@ -528,6 +607,9 @@ export async function provisionExecutorDenyLayer(worktreePath, options, deps) {
|
|
|
528
607
|
baseBranch: options.baseBranch,
|
|
529
608
|
worktreePath,
|
|
530
609
|
homedir: deps.homedir(),
|
|
610
|
+
...(options.restrictedSourcePaths && options.restrictedSourcePaths.length > 0
|
|
611
|
+
? { restrictedSourcePaths: options.restrictedSourcePaths }
|
|
612
|
+
: {}),
|
|
531
613
|
};
|
|
532
614
|
// BAPI-1397 (F7): the deny list the worktree will actually carry — the executor
|
|
533
615
|
// rules plus any operator-authored entries already in the file. Captured from
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BAPI-1582 — pre-PR checks for an `implement` worker.
|
|
3
|
+
*
|
|
4
|
+
* Two contracts live here:
|
|
5
|
+
*
|
|
6
|
+
* 1. **Declarations.** The server stamps `pre_pr_checks` on an implement payload:
|
|
7
|
+
* every owner-confirmed gate-profile reproduction hint as
|
|
8
|
+
* `{check, argv, timeout_seconds}`, sorted by check name. The executor
|
|
9
|
+
* re-validates each entry before rendering it into the worker prompt. An
|
|
10
|
+
* invalid entry is skipped with a closed reason and its position; an argv item
|
|
11
|
+
* is never logged or rendered from a rejected entry.
|
|
12
|
+
*
|
|
13
|
+
* 2. **Evidence.** The worker writes `<worktree>/.conductor/pre-pr-checks.json`
|
|
14
|
+
* before it calls `create_pull_request`. After exit the executor reads it with
|
|
15
|
+
* a bounded, no-follow read, trusts it only when its `tested_head` equals the
|
|
16
|
+
* observed final head, and attaches a bounded summary to the completion result
|
|
17
|
+
* as telemetry. It is never gate evidence, never a ledger record, and a
|
|
18
|
+
* missing, stale, or malformed record attaches nothing and fails nothing.
|
|
19
|
+
*/
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
/** The shared budget, in seconds, for the whole pre-PR step of one implement attempt. */
|
|
22
|
+
export const PRE_PR_BUDGET_SECONDS = 600;
|
|
23
|
+
/** Declaration bounds (mirror the gate profile's reproduction-hint rules). */
|
|
24
|
+
export const PRE_PR_MAX_DECLARATIONS = 32;
|
|
25
|
+
export const PRE_PR_CHECK_NAME_MAX_CHARS = 200;
|
|
26
|
+
export const PRE_PR_ARGV_MAX_ITEMS = 32;
|
|
27
|
+
export const PRE_PR_ARG_MAX_CHARS = 1024;
|
|
28
|
+
export const PRE_PR_TIMEOUT_MIN_SECONDS = 1;
|
|
29
|
+
export const PRE_PR_TIMEOUT_MAX_SECONDS = 1800;
|
|
30
|
+
/** The evidence record's location under the worktree. */
|
|
31
|
+
export const PRE_PR_EVIDENCE_RELATIVE_PATH = path.join(".conductor", "pre-pr-checks.json");
|
|
32
|
+
/** Largest evidence file the executor reads. */
|
|
33
|
+
export const PRE_PR_EVIDENCE_MAX_BYTES = 64_000;
|
|
34
|
+
/** The completion-result key the bounded summary rides on. */
|
|
35
|
+
export const PRE_PR_SUMMARY_KEY = "pre_pr_checks_summary";
|
|
36
|
+
const CONTROL_CHAR_RE = /[\x00-\x1f\x7f]/;
|
|
37
|
+
const DECLARATION_KEYS = new Set(["check", "argv", "timeout_seconds"]);
|
|
38
|
+
function isPlainRecord(value) {
|
|
39
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
40
|
+
}
|
|
41
|
+
function rejectDeclaration(raw) {
|
|
42
|
+
if (!isPlainRecord(raw))
|
|
43
|
+
return "not_an_object";
|
|
44
|
+
for (const key of Object.keys(raw))
|
|
45
|
+
if (!DECLARATION_KEYS.has(key))
|
|
46
|
+
return "unexpected_key";
|
|
47
|
+
const check = raw.check;
|
|
48
|
+
if (typeof check !== "string")
|
|
49
|
+
return "check_invalid";
|
|
50
|
+
const name = check.trim();
|
|
51
|
+
if (!name || name.length > PRE_PR_CHECK_NAME_MAX_CHARS || CONTROL_CHAR_RE.test(name))
|
|
52
|
+
return "check_invalid";
|
|
53
|
+
const argv = raw.argv;
|
|
54
|
+
if (!Array.isArray(argv))
|
|
55
|
+
return "argv_not_a_list";
|
|
56
|
+
if (argv.length < 1 || argv.length > PRE_PR_ARGV_MAX_ITEMS)
|
|
57
|
+
return "argv_count_invalid";
|
|
58
|
+
for (const item of argv) {
|
|
59
|
+
if (typeof item !== "string" || !item.trim() || item.length > PRE_PR_ARG_MAX_CHARS || item.includes("\x00")) {
|
|
60
|
+
return "argv_item_invalid";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const timeout = raw.timeout_seconds;
|
|
64
|
+
if (typeof timeout !== "number" || !Number.isInteger(timeout) ||
|
|
65
|
+
timeout < PRE_PR_TIMEOUT_MIN_SECONDS || timeout > PRE_PR_TIMEOUT_MAX_SECONDS) {
|
|
66
|
+
return "timeout_invalid";
|
|
67
|
+
}
|
|
68
|
+
return { check: name, argv: [...argv], timeoutSeconds: timeout };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Validate a payload `pre_pr_checks` value. Never throws. Entries keep their
|
|
72
|
+
* supplied (server-sorted) order; a duplicate check name or an entry past
|
|
73
|
+
* {@link PRE_PR_MAX_DECLARATIONS} is skipped, never silently merged.
|
|
74
|
+
*/
|
|
75
|
+
export function admitPrePrChecks(raw) {
|
|
76
|
+
if (!Array.isArray(raw))
|
|
77
|
+
return { entries: [], skipped: [], notAList: true };
|
|
78
|
+
const entries = [];
|
|
79
|
+
const skipped = [];
|
|
80
|
+
const seen = new Set();
|
|
81
|
+
raw.forEach((item, position) => {
|
|
82
|
+
if (position >= PRE_PR_MAX_DECLARATIONS) {
|
|
83
|
+
skipped.push({ position, reason: "too_many_declarations" });
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const verdict = rejectDeclaration(item);
|
|
87
|
+
if (typeof verdict === "string") {
|
|
88
|
+
skipped.push({ position, reason: verdict });
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (seen.has(verdict.check)) {
|
|
92
|
+
skipped.push({ position, reason: "duplicate_check" });
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
seen.add(verdict.check);
|
|
96
|
+
entries.push(verdict);
|
|
97
|
+
});
|
|
98
|
+
return { entries, skipped, notAList: false };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The admitted entries for a payload option, logging each skip by position and
|
|
102
|
+
* closed reason only. Absent (`undefined`) admits nothing and logs nothing.
|
|
103
|
+
*/
|
|
104
|
+
export function validatePrePrCheckDeclarations(option, errorLog = (message) => console.error(message)) {
|
|
105
|
+
if (!Object.prototype.hasOwnProperty.call(option, "prePrChecks"))
|
|
106
|
+
return [];
|
|
107
|
+
const log = (message) => { try {
|
|
108
|
+
errorLog(message);
|
|
109
|
+
}
|
|
110
|
+
catch { /* sink */ } };
|
|
111
|
+
let admitted;
|
|
112
|
+
try {
|
|
113
|
+
admitted = admitPrePrChecks(option.prePrChecks);
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
admitted = { entries: [], skipped: [], notAList: true };
|
|
117
|
+
}
|
|
118
|
+
if (admitted.notAList) {
|
|
119
|
+
log("executor: pre_pr_checks is present but is not a list; rendering no pre-PR checks");
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
for (const skip of admitted.skipped) {
|
|
123
|
+
log(`executor: skipped pre_pr_checks entry ${skip.position}: ${skip.reason}`);
|
|
124
|
+
}
|
|
125
|
+
return admitted.entries;
|
|
126
|
+
}
|
|
127
|
+
// ---------------------------------------------------------------------------
|
|
128
|
+
// Evidence record
|
|
129
|
+
// ---------------------------------------------------------------------------
|
|
130
|
+
export const PRE_PR_SOURCES = ["required", "likely_tests", "gate_profile"];
|
|
131
|
+
export const PRE_PR_RUN_OUTCOMES = ["passed", "failed", "timed_out"];
|
|
132
|
+
export const PRE_PR_SKIP_REASONS = ["budget", "unmappable", "not_executable", "unavailable"];
|
|
133
|
+
/** Evidence bounds. */
|
|
134
|
+
export const PRE_PR_EVIDENCE_MAX_SELECTED = 256;
|
|
135
|
+
export const PRE_PR_EVIDENCE_MAX_RUNS = 512;
|
|
136
|
+
export const PRE_PR_EVIDENCE_MAX_SKIPPED = 256;
|
|
137
|
+
export const PRE_PR_EVIDENCE_NAME_MAX_CHARS = 500;
|
|
138
|
+
/** Largest duration accepted for one run or the whole step (a day; anything more is malformed). */
|
|
139
|
+
const PRE_PR_MAX_SECONDS = 86_400;
|
|
140
|
+
/** Names listed in the summary's not-passed and unverified lists. */
|
|
141
|
+
export const PRE_PR_SUMMARY_MAX_NAMES = 16;
|
|
142
|
+
const SHA_RE = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
143
|
+
function validName(value) {
|
|
144
|
+
return typeof value === "string" && value.trim().length > 0 &&
|
|
145
|
+
value.length <= PRE_PR_EVIDENCE_NAME_MAX_CHARS && !CONTROL_CHAR_RE.test(value);
|
|
146
|
+
}
|
|
147
|
+
function validSeconds(value) {
|
|
148
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= PRE_PR_MAX_SECONDS;
|
|
149
|
+
}
|
|
150
|
+
function validSha(value) {
|
|
151
|
+
return typeof value === "string" && SHA_RE.test(value);
|
|
152
|
+
}
|
|
153
|
+
function oneOf(values, value) {
|
|
154
|
+
return typeof value === "string" && values.includes(value);
|
|
155
|
+
}
|
|
156
|
+
function exactKeys(value, keys) {
|
|
157
|
+
const present = Object.keys(value);
|
|
158
|
+
return present.length === keys.length && keys.every((key) => Object.prototype.hasOwnProperty.call(value, key));
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Validate a parsed evidence record. Returns the record (with only its declared
|
|
162
|
+
* fields) or `null`. Never throws. Unknown keys, unknown vocabulary, an invalid
|
|
163
|
+
* SHA, a negative or non-finite duration, or an array over its bound all reject
|
|
164
|
+
* the whole record — nothing from it is trusted partially.
|
|
165
|
+
*/
|
|
166
|
+
export function validatePrePrEvidence(raw) {
|
|
167
|
+
if (!isPlainRecord(raw))
|
|
168
|
+
return null;
|
|
169
|
+
if (!exactKeys(raw, ["version", "tested_head", "budget_seconds", "elapsed_seconds", "selected", "run", "skipped"])) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
if (raw.version !== 1 || !validSha(raw.tested_head))
|
|
173
|
+
return null;
|
|
174
|
+
if (raw.budget_seconds !== PRE_PR_BUDGET_SECONDS || !validSeconds(raw.elapsed_seconds))
|
|
175
|
+
return null;
|
|
176
|
+
const { selected, run, skipped } = raw;
|
|
177
|
+
if (!Array.isArray(selected) || selected.length > PRE_PR_EVIDENCE_MAX_SELECTED)
|
|
178
|
+
return null;
|
|
179
|
+
if (!Array.isArray(run) || run.length > PRE_PR_EVIDENCE_MAX_RUNS)
|
|
180
|
+
return null;
|
|
181
|
+
if (!Array.isArray(skipped) || skipped.length > PRE_PR_EVIDENCE_MAX_SKIPPED)
|
|
182
|
+
return null;
|
|
183
|
+
const out = {
|
|
184
|
+
version: 1,
|
|
185
|
+
tested_head: raw.tested_head,
|
|
186
|
+
budget_seconds: PRE_PR_BUDGET_SECONDS,
|
|
187
|
+
elapsed_seconds: raw.elapsed_seconds,
|
|
188
|
+
selected: [],
|
|
189
|
+
run: [],
|
|
190
|
+
skipped: [],
|
|
191
|
+
};
|
|
192
|
+
for (const entry of selected) {
|
|
193
|
+
if (!isPlainRecord(entry) || !exactKeys(entry, ["name", "source"]))
|
|
194
|
+
return null;
|
|
195
|
+
if (!validName(entry.name) || !oneOf(PRE_PR_SOURCES, entry.source))
|
|
196
|
+
return null;
|
|
197
|
+
out.selected.push({ name: entry.name, source: entry.source });
|
|
198
|
+
}
|
|
199
|
+
for (const entry of run) {
|
|
200
|
+
if (!isPlainRecord(entry) || !exactKeys(entry, ["name", "source", "head_sha", "outcome", "seconds"]))
|
|
201
|
+
return null;
|
|
202
|
+
if (!validName(entry.name) || !oneOf(PRE_PR_SOURCES, entry.source) || !validSha(entry.head_sha) ||
|
|
203
|
+
!oneOf(PRE_PR_RUN_OUTCOMES, entry.outcome) || !validSeconds(entry.seconds)) {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
out.run.push({
|
|
207
|
+
name: entry.name, source: entry.source, head_sha: entry.head_sha,
|
|
208
|
+
outcome: entry.outcome, seconds: entry.seconds,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
for (const entry of skipped) {
|
|
212
|
+
if (!isPlainRecord(entry) || !exactKeys(entry, ["name", "source", "reason"]))
|
|
213
|
+
return null;
|
|
214
|
+
if (!validName(entry.name) || !oneOf(PRE_PR_SOURCES, entry.source) || !oneOf(PRE_PR_SKIP_REASONS, entry.reason)) {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
out.skipped.push({ name: entry.name, source: entry.source, reason: entry.reason });
|
|
218
|
+
}
|
|
219
|
+
return out;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Summarize a validated record observed at `observedHead`. Returns `null` for a
|
|
223
|
+
* stale record (its `tested_head` is not the observed head).
|
|
224
|
+
*/
|
|
225
|
+
export function summarizePrePrEvidence(evidence, observedHead) {
|
|
226
|
+
if (evidence.tested_head !== observedHead.trim().toLowerCase())
|
|
227
|
+
return null;
|
|
228
|
+
const atHead = { passed: 0, failed: 0, timed_out: 0 };
|
|
229
|
+
const latestAtHead = new Map();
|
|
230
|
+
let historical = 0;
|
|
231
|
+
for (const run of evidence.run) {
|
|
232
|
+
if (run.head_sha === evidence.tested_head) {
|
|
233
|
+
atHead[run.outcome] += 1;
|
|
234
|
+
latestAtHead.set(run.name, run.outcome);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
historical += 1;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const skipped = { budget: 0, unmappable: 0, not_executable: 0, unavailable: 0 };
|
|
241
|
+
const skippedNames = new Set();
|
|
242
|
+
for (const skip of evidence.skipped) {
|
|
243
|
+
skipped[skip.reason] += 1;
|
|
244
|
+
skippedNames.add(skip.name);
|
|
245
|
+
}
|
|
246
|
+
const notPassed = [];
|
|
247
|
+
const unverified = [];
|
|
248
|
+
const seen = new Set();
|
|
249
|
+
for (const { name } of evidence.selected) {
|
|
250
|
+
if (seen.has(name))
|
|
251
|
+
continue;
|
|
252
|
+
seen.add(name);
|
|
253
|
+
const outcome = latestAtHead.get(name);
|
|
254
|
+
if (outcome === undefined) {
|
|
255
|
+
if (!skippedNames.has(name))
|
|
256
|
+
unverified.push(name);
|
|
257
|
+
}
|
|
258
|
+
else if (outcome !== "passed") {
|
|
259
|
+
notPassed.push(name);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
version: 1,
|
|
264
|
+
tested_head: evidence.tested_head,
|
|
265
|
+
budget_seconds: evidence.budget_seconds,
|
|
266
|
+
elapsed_seconds: evidence.elapsed_seconds,
|
|
267
|
+
selected_count: evidence.selected.length,
|
|
268
|
+
at_tested_head: atHead,
|
|
269
|
+
historical_run_count: historical,
|
|
270
|
+
skipped,
|
|
271
|
+
not_passed_at_tested_head: notPassed.slice(0, PRE_PR_SUMMARY_MAX_NAMES),
|
|
272
|
+
unverified_at_tested_head: unverified.slice(0, PRE_PR_SUMMARY_MAX_NAMES),
|
|
273
|
+
unverified_at_tested_head_count: unverified.length,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Read `<worktree>/.conductor/pre-pr-checks.json` with a bounded, no-follow read.
|
|
278
|
+
* Never throws; `code` is a fixed, secret-free token.
|
|
279
|
+
*/
|
|
280
|
+
export async function readPrePrEvidenceArtifact(worktreePath, deps) {
|
|
281
|
+
const conductorDir = path.join(worktreePath, ".conductor");
|
|
282
|
+
const artifactPath = path.join(worktreePath, PRE_PR_EVIDENCE_RELATIVE_PATH);
|
|
283
|
+
if (deps.lstatPath) {
|
|
284
|
+
try {
|
|
285
|
+
const dirMeta = await deps.lstatPath(conductorDir);
|
|
286
|
+
if (dirMeta === null)
|
|
287
|
+
return { status: "missing", code: "artifact_absent" };
|
|
288
|
+
if (dirMeta.isSymbolicLink || !dirMeta.isDirectory)
|
|
289
|
+
return { status: "invalid", code: "artifact_dir_unsafe" };
|
|
290
|
+
const meta = await deps.lstatPath(artifactPath);
|
|
291
|
+
if (meta === null)
|
|
292
|
+
return { status: "missing", code: "artifact_absent" };
|
|
293
|
+
if (meta.isDirectory || meta.isSymbolicLink)
|
|
294
|
+
return { status: "invalid", code: "artifact_not_regular_file" };
|
|
295
|
+
}
|
|
296
|
+
catch {
|
|
297
|
+
return { status: "invalid", code: "artifact_unreadable" };
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
let raw;
|
|
301
|
+
try {
|
|
302
|
+
raw = await deps.readFile(artifactPath);
|
|
303
|
+
}
|
|
304
|
+
catch (err) {
|
|
305
|
+
const code = err && typeof err === "object" ? err.code : undefined;
|
|
306
|
+
return code === "ENOENT"
|
|
307
|
+
? { status: "missing", code: "artifact_absent" }
|
|
308
|
+
: { status: "invalid", code: "artifact_unreadable" };
|
|
309
|
+
}
|
|
310
|
+
if (typeof raw !== "string")
|
|
311
|
+
return { status: "invalid", code: "artifact_unreadable" };
|
|
312
|
+
if (Buffer.byteLength(raw, "utf8") > PRE_PR_EVIDENCE_MAX_BYTES)
|
|
313
|
+
return { status: "invalid", code: "artifact_oversized" };
|
|
314
|
+
let parsed;
|
|
315
|
+
try {
|
|
316
|
+
parsed = JSON.parse(raw);
|
|
317
|
+
}
|
|
318
|
+
catch {
|
|
319
|
+
return { status: "invalid", code: "artifact_not_json" };
|
|
320
|
+
}
|
|
321
|
+
const evidence = validatePrePrEvidence(parsed);
|
|
322
|
+
return evidence === null ? { status: "invalid", code: "artifact_invalid" } : { status: "ok", evidence };
|
|
323
|
+
}
|
|
324
|
+
const CONTENT_FAILURE_CODES = new Set(["artifact_oversized", "artifact_not_json", "artifact_invalid"]);
|
|
325
|
+
/**
|
|
326
|
+
* Attach the bounded summary to `result` when a valid, current-head record
|
|
327
|
+
* exists and the augmented result still fits `maxResultBytes`. Otherwise
|
|
328
|
+
* `result` is returned unchanged. Never throws.
|
|
329
|
+
*/
|
|
330
|
+
export async function withPrePrChecksSummary(result, options) {
|
|
331
|
+
const log = (message) => { try {
|
|
332
|
+
options.errorLog?.(message);
|
|
333
|
+
}
|
|
334
|
+
catch { /* sink */ } };
|
|
335
|
+
try {
|
|
336
|
+
if (typeof options.observedHead !== "string" || !SHA_RE.test(options.observedHead.trim().toLowerCase())) {
|
|
337
|
+
return result;
|
|
338
|
+
}
|
|
339
|
+
const read = await readPrePrEvidenceArtifact(options.worktreePath, options.deps);
|
|
340
|
+
if (read.status !== "ok") {
|
|
341
|
+
// An absent or unreadable record is ordinary (no pre-PR step, full scope,
|
|
342
|
+
// or a filesystem shape the worker never wrote): stay quiet. Only a record
|
|
343
|
+
// the worker wrote with bad content is worth a line.
|
|
344
|
+
if (CONTENT_FAILURE_CODES.has(read.code))
|
|
345
|
+
log(`executor: pre-PR checks record invalid (${read.code}); no summary attached`);
|
|
346
|
+
return result;
|
|
347
|
+
}
|
|
348
|
+
const summary = summarizePrePrEvidence(read.evidence, options.observedHead);
|
|
349
|
+
if (summary === null) {
|
|
350
|
+
log("executor: pre-PR checks record is stale (tested_head is not the final head); no summary attached");
|
|
351
|
+
return result;
|
|
352
|
+
}
|
|
353
|
+
const augmented = { ...result, [PRE_PR_SUMMARY_KEY]: summary };
|
|
354
|
+
if (Buffer.byteLength(JSON.stringify(augmented), "utf8") > options.maxResultBytes) {
|
|
355
|
+
log("executor: pre-PR checks summary would exceed the result budget; not attached");
|
|
356
|
+
return result;
|
|
357
|
+
}
|
|
358
|
+
return augmented;
|
|
359
|
+
}
|
|
360
|
+
catch {
|
|
361
|
+
return result;
|
|
362
|
+
}
|
|
363
|
+
}
|