@bridge_gpt/mcp-server 0.2.69 → 0.2.71
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 +140 -292
- package/build/agent-launchers/claude-executor-adapter.js +27 -5
- package/build/agent-registry.js +5 -5
- package/build/agents.generated.js +15 -5
- package/build/artifact-diff.js +110 -0
- package/build/bin-entrypoint.js +36 -0
- package/build/bounded-wait.js +9 -1
- package/build/bridge-permissions.js +36 -9
- package/build/claude-review-workflow-drift.js +3 -3
- package/build/codex-bridge-profile.js +1 -1
- package/build/commands.generated.js +6 -6
- package/build/conductor/bridge-api-client.js +858 -21
- package/build/conductor/bring-up-facts.js +9 -9
- package/build/conductor/command-drift-production.js +7 -2
- package/build/conductor/doctor.js +472 -18
- package/build/conductor/epic-child-continuation.js +54 -3
- package/build/conductor/epic-implementer-cli.js +136 -34
- package/build/conductor/epic-runtime.js +2 -2
- package/build/conductor/epic-state.js +1 -1
- package/build/conductor/gate-discovery.js +524 -10
- package/build/conductor/gate-settings-review.js +451 -0
- package/build/conductor/hook-runtime-qualification.js +1 -1
- package/build/conductor/install-doctor.js +4 -2
- package/build/conductor/launch-need-probes.js +342 -0
- package/build/conductor/launch-plan.js +145 -0
- package/build/conductor/local-merge.js +241 -56
- package/build/conductor/merge-credential.js +172 -0
- package/build/conductor/merge-execution-eligibility.js +1 -1
- package/build/conductor/merged-child-check.js +95 -0
- package/build/conductor/plan-trim.js +30 -0
- package/build/conductor/pr-ci-producer.js +1 -1
- package/build/conductor/precheck-timings.js +14 -0
- package/build/conductor/preview-observations.js +10 -0
- package/build/conductor/readiness-cli.js +11 -6
- package/build/conductor/readiness-prerequisites.js +41 -0
- package/build/conductor/readiness-sections.js +348 -55
- package/build/conductor/readiness.js +99 -87
- package/build/conductor/recovery-cli.js +665 -23
- package/build/conductor/recovery-operations.js +350 -8
- package/build/conductor/repair-contract.js +47 -2
- package/build/conductor/repository-workflow-remedy.js +8 -6
- package/build/conductor/stored-merge-credential.js +76 -0
- package/build/conductor/stored-merge-token-probe.js +28 -0
- package/build/conductor/temporary-plan.js +50 -0
- package/build/conductor/wait-run-cli.js +759 -0
- package/build/conductor/worker-database-doctor-inspector.js +49 -0
- package/build/conductor-bin.js +2 -2
- package/build/conductor-claude-hook-bin.js +2 -2
- package/build/conductor-claude-hook-removed-stub-bin.js +2 -5
- package/build/conductor-removed-stub-bin.js +2 -5
- package/build/credential-store.js +356 -13
- package/build/docs.generated.js +26 -13
- package/build/doctor.js +94 -32
- package/build/drive-epic-help.js +212 -0
- package/build/drive-epic.js +1989 -379
- package/build/epic-ci-workflow-drift.js +125 -0
- package/build/epic-ci-workflow-install.js +240 -0
- package/build/epic-ci-workflow-v1.js +132 -0
- package/build/epic-ci-workflow.js +318 -0
- package/build/epic-contract-context.js +326 -0
- package/build/epic-implementer-bin.js +58 -42
- package/build/epic-implementer-claude-hook-bin.js +2 -2
- package/build/escalation-reachability.js +134 -0
- package/build/executor/ci-rerun-job.js +220 -14
- package/build/executor/cleanup-report.js +99 -0
- package/build/executor/cli.js +12 -1
- package/build/executor/completion-contract.js +66 -11
- package/build/executor/completion-supervision.js +99 -0
- package/build/executor/delivery-outcome.js +179 -0
- package/build/executor/deps.js +3 -0
- package/build/executor/env.js +276 -1
- package/build/executor/failure-reason-codes.js +126 -0
- package/build/executor/gate-qualification-job.js +20 -5
- package/build/executor/heartbeat.js +38 -0
- package/build/executor/http-client.js +72 -0
- package/build/executor/integration-job.js +298 -5
- package/build/executor/job-errors.js +36 -6
- package/build/executor/job-runner.js +830 -45
- package/build/executor/likely-tests.js +42 -3
- package/build/executor/merge-job.js +145 -2
- package/build/executor/observation.js +73 -4
- package/build/executor/permissions.js +193 -97
- package/build/executor/preflight.js +19 -3
- package/build/executor/process-containment.js +46 -2
- package/build/executor/prompt-spec.js +113 -9
- package/build/executor/rebase-finalization.js +38 -3
- package/build/executor/reconcile-overlap-job.js +41 -8
- package/build/executor/required-work-ledger.js +236 -81
- package/build/executor/resume-pre-spawn.js +38 -1
- package/build/executor/runner.js +91 -3
- package/build/executor/test-clock.js +8 -0
- package/build/executor/types.js +37 -2
- package/build/executor/worker-cli-launcher.js +259 -0
- package/build/executor/worker-command.js +177 -5
- package/build/executor/worker-database-target.js +91 -0
- package/build/executor/worker-database.js +927 -0
- package/build/executor/worker-finalization.js +106 -0
- package/build/executor/worker-guard-hook.js +203 -0
- package/build/executor/worker-resources.js +58 -0
- package/build/executor/worker-verification-guidance.js +44 -2
- package/build/executor/worktree.js +303 -15
- package/build/executor-launch.js +11 -1
- package/build/generated-assets-doctor.js +9 -1
- package/build/generated-assets-health.js +13 -4
- package/build/generated-assets-legacy.js +39 -0
- package/build/generated-assets-paths.js +12 -1
- package/build/generated-assets-repair.js +4 -1
- package/build/generated-assets-test-support.js +12 -0
- package/build/github-remote.js +33 -0
- package/build/github-sign-in.js +62 -0
- package/build/index.js +1133 -546
- package/build/init.js +39 -1
- package/build/install-bridge-conductor-gate.js +270 -11
- package/build/install-bridge-conductor-setup.js +427 -0
- package/build/install-bridge-conductor.js +1545 -268
- package/build/install-bridge.js +376 -60
- package/build/mcp-install-state.js +8 -2
- package/build/merge-pull-request.js +6 -0
- package/build/merge-workflow-install.js +782 -344
- package/build/phase-result-artifacts.js +75 -20
- package/build/pipeline-orchestrator.js +247 -4
- package/build/pipelines.generated.js +35 -35
- package/build/plan-discovery.js +15 -2
- package/build/plan-execution-ledger.js +321 -17
- package/build/plan-phase-routing.js +48 -13
- package/build/plane/cli.js +105 -51
- package/build/plane/defaults.js +3 -0
- package/build/plane/plane-freshness.js +298 -0
- package/build/plane/preflight.js +19 -0
- package/build/plane/schema-compatibility.js +137 -0
- package/build/plane/shutdown-deps.js +38 -0
- package/build/plane/shutdown.js +83 -8
- package/build/plane/terminal-run-cleanup.js +303 -0
- package/build/printed-remedy-commands.js +33 -4
- package/build/readiness-check.js +6 -2
- package/build/readiness-prerequisites.generated.js +532 -0
- package/build/readme.generated.js +1 -1
- package/build/repository-toolchains.js +581 -0
- package/build/setup-epic.js +421 -34
- package/build/shared-resources.generated.js +5 -0
- package/build/start-tickets.js +28 -15
- package/build/test-command-detection.js +284 -0
- package/build/test-command-validation.js +73 -0
- package/build/testing-config-client.js +150 -0
- package/build/ticket-delivery-artifacts.js +265 -0
- package/build/ticket-delivery-enrollment.js +369 -0
- package/build/ticket-delivery.js +205 -0
- package/build/ticket-review-summary.js +14 -0
- package/build/upgrade-cli.js +13 -0
- package/build/v2-readiness-requirements.js +552 -0
- package/build/version.generated.js +3 -3
- package/build/worker-guard-hook-bin.js +2 -2
- package/build/worktree-core.js +22 -7
- package/docs/BRIDGE-DIRECTORY-README.md +48 -0
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +12 -867
- package/docs/EPIC-IMPLEMENTER.md +142 -63
- package/docs/epic-implementer/getting-started.md +187 -0
- package/docs/epic-implementer/self-hosting.md +133 -0
- package/package.json +4 -4
- package/pipelines/idea-to-ticket.json +1 -1
- package/pipelines/implement-ticket.json +8 -8
- package/pipelines/review-ticket.json +2 -2
- package/design-assets/favicon/favicon-32x32.png +0 -0
- package/design-assets/just-logo-rough-draft.png +0 -0
|
@@ -27,6 +27,13 @@
|
|
|
27
27
|
import { createHash } from "node:crypto";
|
|
28
28
|
/** The capability string declared on `POST /claim` and required by covered jobs. */
|
|
29
29
|
export const COMPLETION_EVIDENCE_CAPABILITY = "completion_evidence.v1";
|
|
30
|
+
/**
|
|
31
|
+
* BAPI-1504 — declared on `POST /claim` by an executor that persists ownership
|
|
32
|
+
* BEFORE spawning a covered worker and can deliver `POST /{id}/cleanup-report`.
|
|
33
|
+
* A job stamped with it makes a `null` stored ownership reliable evidence that no
|
|
34
|
+
* owned worker was spawned. Mirrors the server's `CLEANUP_REPORT_CAPABILITY`.
|
|
35
|
+
*/
|
|
36
|
+
export const CLEANUP_REPORT_CAPABILITY = "cleanup_report.v1";
|
|
30
37
|
export const COMPLETION_CONTRACT_VERSION = 1;
|
|
31
38
|
/**
|
|
32
39
|
* BAPI-1302 (D4c) — the envelope version that carries executor-run check facts
|
|
@@ -40,12 +47,13 @@ export const COMPLETION_CONTRACT_VERSION_V2 = 2;
|
|
|
40
47
|
* without the runner never claims one.
|
|
41
48
|
*/
|
|
42
49
|
export const REQUIRED_VERIFICATION_CAPABILITY = "required_verification.v1";
|
|
50
|
+
export const REQUIRED_VERIFICATION_CI_DEFERRAL_CAPABILITY = "required_verification.ci_deferral.v2";
|
|
43
51
|
export const COMPLETION_CONTRACT_MARKER_VALUES = ["completion_evidence.v1", "legacy"];
|
|
44
52
|
export const COVERED_JOB_TYPES = ["implement", "resume", "remediate", "ci_fix"];
|
|
45
53
|
/**
|
|
46
|
-
* The measured
|
|
47
|
-
*
|
|
48
|
-
*
|
|
54
|
+
* The measured baseline (BAPI-1292 probe): Claude Code 2.1.282 on macOS arm64.
|
|
55
|
+
* It is a reference value, not the acceptance rule. `runtimeMatchesSupported`
|
|
56
|
+
* accepts this identity and any newer CLI version on a supported platform.
|
|
49
57
|
*/
|
|
50
58
|
export const SUPPORTED_COMPLETION_RUNTIME = {
|
|
51
59
|
adapter: "claude",
|
|
@@ -122,6 +130,7 @@ export const EXECUTION_VALUES = ["complete", "incomplete", "unknown"];
|
|
|
122
130
|
*/
|
|
123
131
|
export const VERIFICATION_VALUES = [
|
|
124
132
|
"not_declared",
|
|
133
|
+
"awaiting_ci",
|
|
125
134
|
"passed",
|
|
126
135
|
"failed",
|
|
127
136
|
"unavailable",
|
|
@@ -162,15 +171,53 @@ export const TASK_STATE_VALUES = [
|
|
|
162
171
|
"failed",
|
|
163
172
|
"stopped",
|
|
164
173
|
"withdrawn",
|
|
174
|
+
"failed_to_start",
|
|
165
175
|
"replaced",
|
|
166
176
|
"unknown",
|
|
167
177
|
"conflict",
|
|
168
178
|
];
|
|
169
|
-
/**
|
|
179
|
+
/**
|
|
180
|
+
* The states that resolve EXECUTION of a REQUIRED task. Resolving execution is
|
|
181
|
+
* not the same as succeeding or verifying: `withdrawn` (the worker stopped its
|
|
182
|
+
* own helper) and `failed_to_start` (a background command failed inside the
|
|
183
|
+
* startup window) only say the work is no longer running. `failed`, a
|
|
184
|
+
* CLI-teardown `stopped`, a verdict-time `unknown`, and `conflict` stay
|
|
185
|
+
* unresolved when required. Declared verification depends only on verification
|
|
186
|
+
* facts, never on this set.
|
|
187
|
+
*/
|
|
170
188
|
export const TASK_RESOLVING_STATES = new Set([
|
|
171
189
|
"succeeded",
|
|
172
190
|
"replaced",
|
|
191
|
+
"withdrawn",
|
|
192
|
+
"failed_to_start",
|
|
173
193
|
]);
|
|
194
|
+
/**
|
|
195
|
+
* BAPI-1455 — the command kinds whose own terminal result can be DELIVERED to
|
|
196
|
+
* the worker. Delegates and monitors are not commands and never qualify.
|
|
197
|
+
*/
|
|
198
|
+
export const DELIVERY_RESOLVABLE_KINDS = new Set(["bash_task", "bash_bg", "subagent_bash"]);
|
|
199
|
+
/**
|
|
200
|
+
* BAPI-1455 — the terminal states a delivered command result resolves. `pending`,
|
|
201
|
+
* `unknown`, and `conflict` are never resolved by delivery.
|
|
202
|
+
*/
|
|
203
|
+
export const DELIVERY_RESOLVABLE_STATES = new Set(["failed", "stopped"]);
|
|
204
|
+
/**
|
|
205
|
+
* The one rule for "this required task no longer blocks execution". A task is
|
|
206
|
+
* resolved when its state is in {@link TASK_RESOLVING_STATES}, or when it is a
|
|
207
|
+
* command that ended `failed` or `stopped` AND the worker received that
|
|
208
|
+
* command's own terminal result (`result_delivered === true`, exactly).
|
|
209
|
+
*
|
|
210
|
+
* Resolving is not succeeding: a delivered failure keeps its real state, is not
|
|
211
|
+
* completed work, and proves no verification. Mirror of `task_is_resolved` in
|
|
212
|
+
* Python; every resolution check in this module goes through it.
|
|
213
|
+
*/
|
|
214
|
+
export function isTaskResolved(task) {
|
|
215
|
+
if (TASK_RESOLVING_STATES.has(task.state))
|
|
216
|
+
return true;
|
|
217
|
+
return (task.result_delivered === true &&
|
|
218
|
+
DELIVERY_RESOLVABLE_KINDS.has(task.kind) &&
|
|
219
|
+
DELIVERY_RESOLVABLE_STATES.has(task.state));
|
|
220
|
+
}
|
|
174
221
|
export const DENIAL_OPERATION_VALUES = [
|
|
175
222
|
"push",
|
|
176
223
|
"pr_create",
|
|
@@ -186,6 +233,7 @@ export const MISSING_CAPABILITY_VALUES = [
|
|
|
186
233
|
"focused_ci_repair",
|
|
187
234
|
"repaired_head_convergence",
|
|
188
235
|
"continuation",
|
|
236
|
+
"cleanup_report",
|
|
189
237
|
];
|
|
190
238
|
/** BAPI-1302 — where a job's declaration came from. Neither `absent` nor `declared_empty` is a pass. */
|
|
191
239
|
export const DECLARATION_PROVENANCE_VALUES = ["declared", "declared_empty", "absent", "refused"];
|
|
@@ -295,7 +343,7 @@ export function runtimeMatchesSupported(runtime) {
|
|
|
295
343
|
cliVersionAtLeast(version, minimum));
|
|
296
344
|
}
|
|
297
345
|
export function unresolvedRequiredTasks(envelope) {
|
|
298
|
-
return envelope.tasks.filter((t) => t.required && !
|
|
346
|
+
return envelope.tasks.filter((t) => t.required && !isTaskResolved(t));
|
|
299
347
|
}
|
|
300
348
|
const FULL_SHA_RE = /^[0-9a-f]{40}$/;
|
|
301
349
|
/**
|
|
@@ -312,7 +360,7 @@ export function verificationVerdictFromFacts(facts, declaredCount) {
|
|
|
312
360
|
if (facts.provenance !== "declared")
|
|
313
361
|
return "incomplete";
|
|
314
362
|
const expected = declaredCount ?? facts.commands.length;
|
|
315
|
-
if (expected === 0 || facts.commands.length !== expected)
|
|
363
|
+
if ((expected === 0 && !facts.deferred_obligation_identities?.length) || facts.commands.length !== expected)
|
|
316
364
|
return "incomplete";
|
|
317
365
|
if (facts.artifact !== "stable" || facts.tested_head_sha === null || !FULL_SHA_RE.test(facts.tested_head_sha)) {
|
|
318
366
|
return "incomplete";
|
|
@@ -321,12 +369,15 @@ export function verificationVerdictFromFacts(facts, declaredCount) {
|
|
|
321
369
|
return "incomplete";
|
|
322
370
|
if (facts.commands.some((c) => c.outcome === "exited_nonzero"))
|
|
323
371
|
return "failed";
|
|
324
|
-
return "passed";
|
|
372
|
+
return facts.deferred_obligation_identities?.length ? "awaiting_ci" : "passed";
|
|
325
373
|
}
|
|
326
374
|
/**
|
|
327
375
|
* Closed reason the envelope cannot support a covered success, or null.
|
|
328
376
|
* Mirrors the server's `success_refusal_reason` clause for clause, so the
|
|
329
377
|
* executor never sends `/complete` for an envelope the server would refuse.
|
|
378
|
+
*
|
|
379
|
+
* A delivered command result (BAPI-1455) only resolves its task's execution.
|
|
380
|
+
* Verification, finalization, cleanup, and denials still decide on their own.
|
|
330
381
|
*/
|
|
331
382
|
export function successRefusalReason(envelope) {
|
|
332
383
|
if (envelope.evidence !== "sufficient")
|
|
@@ -335,7 +386,7 @@ export function successRefusalReason(envelope) {
|
|
|
335
386
|
return "execution_not_complete";
|
|
336
387
|
if (unresolvedRequiredTasks(envelope).length > 0)
|
|
337
388
|
return "required_task_unresolved";
|
|
338
|
-
if (envelope.verification !== "passed" && envelope.verification !== "not_declared") {
|
|
389
|
+
if (envelope.verification !== "passed" && envelope.verification !== "not_declared" && envelope.verification !== "awaiting_ci") {
|
|
339
390
|
return "verification_not_acceptable";
|
|
340
391
|
}
|
|
341
392
|
if (envelope.finalization !== "ok" && envelope.finalization !== "not_required") {
|
|
@@ -365,7 +416,7 @@ export function deriveCompletionCause(envelope) {
|
|
|
365
416
|
if (blocking.length > 0 && envelope.evidence === "sufficient" && blocking.some((d) => d.result_after_denial)) {
|
|
366
417
|
return "permission_stop";
|
|
367
418
|
}
|
|
368
|
-
const unresolved = envelope.tasks.some((t) => t.required && !
|
|
419
|
+
const unresolved = envelope.tasks.some((t) => t.required && !isTaskResolved(t));
|
|
369
420
|
const requiredWorkIncomplete = blocking.length > 0 ||
|
|
370
421
|
envelope.evidence !== "sufficient" ||
|
|
371
422
|
envelope.execution !== "complete" ||
|
|
@@ -417,7 +468,7 @@ export function isNotLaunchedEnvelope(envelope) {
|
|
|
417
468
|
*/
|
|
418
469
|
export function buildNotLaunchedEnvelope(input) {
|
|
419
470
|
return {
|
|
420
|
-
evidence_version: input.verificationFacts ? COMPLETION_CONTRACT_VERSION_V2 : COMPLETION_CONTRACT_VERSION,
|
|
471
|
+
evidence_version: input.verificationFacts?.deferred_obligation_identities !== undefined ? 3 : input.verificationFacts ? COMPLETION_CONTRACT_VERSION_V2 : COMPLETION_CONTRACT_VERSION,
|
|
421
472
|
runtime: { ...input.runtime },
|
|
422
473
|
binding: { ...input.binding },
|
|
423
474
|
session_id: null,
|
|
@@ -466,7 +517,7 @@ export function boundEnvelope(envelope) {
|
|
|
466
517
|
};
|
|
467
518
|
let next = markOversize({
|
|
468
519
|
...envelope,
|
|
469
|
-
tasks: envelope.tasks.filter((t) => t.required && !
|
|
520
|
+
tasks: envelope.tasks.filter((t) => t.required && !isTaskResolved(t)),
|
|
470
521
|
});
|
|
471
522
|
if (size(next) <= MAX_SERIALIZED_BYTES)
|
|
472
523
|
return next;
|
|
@@ -479,3 +530,7 @@ export function boundEnvelope(envelope) {
|
|
|
479
530
|
// Last resort: identities cannot fit. Keep the count-free verdict only.
|
|
480
531
|
return markOversize({ ...next, tasks: next.tasks.slice(0, 8), denials: next.denials.slice(0, 8) });
|
|
481
532
|
}
|
|
533
|
+
/** Whether a stored requirement list names the cleanup-report capability (BAPI-1504). */
|
|
534
|
+
export function claimRequiresCleanupReport(requiredCapabilities) {
|
|
535
|
+
return Array.isArray(requiredCapabilities) && requiredCapabilities.includes(CLEANUP_REPORT_CAPABILITY);
|
|
536
|
+
}
|
|
@@ -133,6 +133,8 @@ export function readRequiredVerification(payload) {
|
|
|
133
133
|
return { kind: "refused", reason: "not_an_object", provenance: null, digest: null };
|
|
134
134
|
}
|
|
135
135
|
const d = raw;
|
|
136
|
+
if (d.schema_version === 2)
|
|
137
|
+
return readPolicyDeclaration(d);
|
|
136
138
|
const digest = typeof d.digest === "string" && DIGEST_RE.test(d.digest) ? d.digest : null;
|
|
137
139
|
const provenance = d.provenance === "declared" || d.provenance === "declared_empty" || d.provenance === "absent" || d.provenance === "refused"
|
|
138
140
|
? d.provenance
|
|
@@ -200,6 +202,103 @@ export function readDeclaredChecks(payload) {
|
|
|
200
202
|
const read = readRequiredVerification(payload);
|
|
201
203
|
return read.kind === "ok" ? read.declaration.checks : [];
|
|
202
204
|
}
|
|
205
|
+
export function renderApprovedVerificationGuidance(payload) {
|
|
206
|
+
const read = readRequiredVerification(payload);
|
|
207
|
+
if (read.kind !== "ok" || read.declaration.policyVersion !== 2)
|
|
208
|
+
return "";
|
|
209
|
+
const raw = payload[REQUIRED_VERIFICATION_PAYLOAD_KEY];
|
|
210
|
+
return "APPROVED EPIC VERIFICATION POLICY v2. Use targeted checks for this focused job. " +
|
|
211
|
+
"Run mandatory local checks and focused repair tests. Defer only the explicitly approved CI obligations, even when runnable locally. " +
|
|
212
|
+
"Do not rerun their full suites during repair or renewal. Missing coverage stays local. " +
|
|
213
|
+
"Preserve all phase-owned records; focused tests do not prove a suite. Actual local failures remain verification_failures. " +
|
|
214
|
+
"Use the sealed delivery-plan joins from get_phase_context for remote_ci records, naming all covering checks. " +
|
|
215
|
+
"Invalidate stale local proof with invalidatedBy stale_verification_head. Do one renewal pass on the final pushed artifact and one confirming readiness read. " +
|
|
216
|
+
"Deferred obligations remain awaiting_ci, never locally passed.\n" +
|
|
217
|
+
"Mandatory local commands: " + JSON.stringify(read.declaration.checks) + "\nApproved obligations: " + JSON.stringify(raw.obligations);
|
|
218
|
+
}
|
|
219
|
+
/** The v2 approval is validated whole before selecting local commands. */
|
|
220
|
+
function readPolicyDeclaration(d) {
|
|
221
|
+
const refuse = () => ({ kind: "refused", reason: "malformed_command", digest: null, provenance: null });
|
|
222
|
+
const exact = (v, keys) => Object.keys(v).sort().join("|") === keys.sort().join("|");
|
|
223
|
+
const text = (v) => typeof v === "string" && v.length > 0 && v.length <= 200 && v.trim() === v;
|
|
224
|
+
if (!exact(d, ["schema_version", "provenance", "plan_version", "plan_hash", "commands", "digest", "policy_revision", "execution_scope", "ticket_key", "obligations"]) ||
|
|
225
|
+
!isInt(d.plan_version) || d.plan_version < 0 || typeof d.plan_hash !== "string" || !DIGEST_RE.test(d.plan_hash) ||
|
|
226
|
+
!text(d.policy_revision) || d.execution_scope !== "epic_targeted" || typeof d.ticket_key !== "string" || !/^[A-Z][A-Z0-9_]{0,19}-\d+$/.test(d.ticket_key) ||
|
|
227
|
+
typeof d.digest !== "string" || !DIGEST_RE.test(d.digest) || computeDeclarationDigest(d) !== d.digest ||
|
|
228
|
+
!Array.isArray(d.commands) || d.commands.length > 16 || !Array.isArray(d.obligations) || d.obligations.length > 1024 ||
|
|
229
|
+
!["declared", "declared_empty", "absent"].includes(String(d.provenance)) || (d.provenance === "declared") !== (d.obligations.length > 0))
|
|
230
|
+
return refuse();
|
|
231
|
+
const checks = [];
|
|
232
|
+
const argvKeys = new Set();
|
|
233
|
+
for (let i = 0; i < d.commands.length; i++) {
|
|
234
|
+
const command = validCommand(d.commands[i], i);
|
|
235
|
+
if (typeof command === "string")
|
|
236
|
+
return refuse();
|
|
237
|
+
const argvKey = JSON.stringify(command.argv);
|
|
238
|
+
if (argvKeys.has(argvKey))
|
|
239
|
+
return refuse();
|
|
240
|
+
argvKeys.add(argvKey);
|
|
241
|
+
checks.push(command);
|
|
242
|
+
}
|
|
243
|
+
const byIdentity = new Map(checks.map(c => [c.identity, c]));
|
|
244
|
+
const seen = new Set(), associated = new Set(), local = new Set(), joins = new Set();
|
|
245
|
+
const deferred = [];
|
|
246
|
+
for (const raw of d.obligations) {
|
|
247
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
248
|
+
return refuse();
|
|
249
|
+
const o = raw;
|
|
250
|
+
if (!exact(o, ["identity", "command_identity", "source", "source_identity", "approval_reference", "classification", "local_reason", "covering_checks", "delivery_plan_digest", "delivery_step_ids"]) ||
|
|
251
|
+
!["plan", "profile", "inspection"].includes(String(o.source)) || !text(o.source_identity) ||
|
|
252
|
+
!["mandatory_local", "ci_deferred"].includes(String(o.classification)) ||
|
|
253
|
+
!Array.isArray(o.covering_checks) || o.covering_checks.length > 64 || !o.covering_checks.every(text) ||
|
|
254
|
+
new Set(o.covering_checks).size !== o.covering_checks.length || [...o.covering_checks].sort().join("|") !== o.covering_checks.join("|") ||
|
|
255
|
+
!Array.isArray(o.delivery_step_ids) || o.delivery_step_ids.length > 256 || !o.delivery_step_ids.every(s => isInt(s) && s > 0) ||
|
|
256
|
+
new Set(o.delivery_step_ids).size !== o.delivery_step_ids.length ||
|
|
257
|
+
JSON.stringify([...o.delivery_step_ids].sort((a, b) => Number(a) - Number(b))) !== JSON.stringify(o.delivery_step_ids) ||
|
|
258
|
+
(o.delivery_plan_digest !== null && !text(o.delivery_plan_digest)) ||
|
|
259
|
+
(o.delivery_step_ids.length > 0) !== text(o.delivery_plan_digest) ||
|
|
260
|
+
o.approval_reference !== `${d.plan_hash}:${d.policy_revision}`)
|
|
261
|
+
return refuse();
|
|
262
|
+
const identity = `ob-${sha256Hex(`${d.ticket_key}:${o.source}:${o.source_identity}`).slice(0, 32)}`;
|
|
263
|
+
if (o.identity !== identity || seen.has(identity))
|
|
264
|
+
return refuse();
|
|
265
|
+
seen.add(identity);
|
|
266
|
+
for (const step of o.delivery_step_ids) {
|
|
267
|
+
const join = `${o.delivery_plan_digest}:${step}`;
|
|
268
|
+
if (joins.has(join))
|
|
269
|
+
return refuse();
|
|
270
|
+
joins.add(join);
|
|
271
|
+
}
|
|
272
|
+
if (o.source === "inspection") {
|
|
273
|
+
if (o.command_identity !== null || o.classification !== "mandatory_local" || o.local_reason !== "non_ci_inspection")
|
|
274
|
+
return refuse();
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
const c = typeof o.command_identity === "string" ? byIdentity.get(o.command_identity) : undefined;
|
|
278
|
+
const sourcePosition = /^cmd-(\d+)-[a-f0-9]{16}$/.exec(o.source_identity);
|
|
279
|
+
if (!c || !sourcePosition || declaredCommandIdentity(Number(sourcePosition[1]), { name: c.name, argv: c.argv, timeout_seconds: c.timeoutSeconds }) !== o.source_identity)
|
|
280
|
+
return refuse();
|
|
281
|
+
associated.add(c.identity);
|
|
282
|
+
}
|
|
283
|
+
if (o.classification === "ci_deferred") {
|
|
284
|
+
if (o.source !== "plan" || o.local_reason !== null || o.covering_checks.length === 0)
|
|
285
|
+
return refuse();
|
|
286
|
+
deferred.push(identity);
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
if (o.covering_checks.length !== 0 || !["coverage_not_established", "explicitly_approved_local", "stamped_local_gate", "non_ci_inspection"].includes(String(o.local_reason)) ||
|
|
290
|
+
(o.source === "profile" && o.local_reason !== "stamped_local_gate"))
|
|
291
|
+
return refuse();
|
|
292
|
+
if (typeof o.command_identity === "string")
|
|
293
|
+
local.add(o.command_identity);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (associated.size !== checks.length)
|
|
297
|
+
return refuse();
|
|
298
|
+
return { kind: "ok", declaration: { provenance: d.provenance, digest: d.digest,
|
|
299
|
+
planVersion: d.plan_version, planHash: d.plan_hash, checks: checks.filter(c => local.has(c.identity)), policyVersion: 2, deferredIdentities: deferred,
|
|
300
|
+
obligations: structuredClone(d.obligations) } };
|
|
301
|
+
}
|
|
203
302
|
export function finalizationObligations(branch, baseBranch) {
|
|
204
303
|
return {
|
|
205
304
|
push: { remote: "origin", ref: `refs/heads/${branch}` },
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BAPI-1426 — the server-confirmed ticket delivery outcome an outer worker reads
|
|
3
|
+
* before it finalizes.
|
|
4
|
+
*
|
|
5
|
+
* A managed ticket (one with an active delivery binding on the server) may end
|
|
6
|
+
* an attempt on purpose without a pull request: its required work is blocked, a
|
|
7
|
+
* required check failed, or its evidence is missing or stale. The worker then
|
|
8
|
+
* pushes a checkpoint and stops. Finalization must not report that as an
|
|
9
|
+
* accidental missing-PR failure, and must never report it as success either.
|
|
10
|
+
*
|
|
11
|
+
* Only the SERVER can say a ticket is managed and what its outcome is. This
|
|
12
|
+
* module makes two bounded, read-only GETs through the executor's own fetch
|
|
13
|
+
* boundary and the shared repo-scoped credential resolver:
|
|
14
|
+
*
|
|
15
|
+
* 1. `GET /ticket-delivery/executions/recover` — is there an active attempt for
|
|
16
|
+
* this ticket and branch? A 404 means "not managed" (legacy behavior).
|
|
17
|
+
* 2. `GET /ticket-delivery/executions/{attempt_id}/readiness?boundary=publish`
|
|
18
|
+
* — the server's current decision for that attempt.
|
|
19
|
+
*
|
|
20
|
+
* It never throws. Any failure is reported as `unavailable`, which finalization
|
|
21
|
+
* treats as "no server confirmation" and so falls through to its existing
|
|
22
|
+
* checks unchanged. An outage is never turned into a failed check. Nothing from
|
|
23
|
+
* the response is kept beyond closed tokens, a full SHA, an identifier, integer
|
|
24
|
+
* step ids, and a PR number; free text from evidence never reaches a message.
|
|
25
|
+
*/
|
|
26
|
+
import { buildConductorVcsUrl, resolveConductorBridgeApiAccess, } from "../conductor/bridge-api-client.js";
|
|
27
|
+
/** Server readiness outcomes (mirror of `ticket_delivery_readiness.py`). */
|
|
28
|
+
export const DELIVERY_OUTCOMES = [
|
|
29
|
+
"blocked",
|
|
30
|
+
"verification_failed",
|
|
31
|
+
"evidence_missing_or_stale",
|
|
32
|
+
"awaiting_post_pr",
|
|
33
|
+
"complete",
|
|
34
|
+
];
|
|
35
|
+
/** Default bound for each of the two reads. */
|
|
36
|
+
export const DELIVERY_OUTCOME_READ_TIMEOUT_MS = 15_000;
|
|
37
|
+
const FULL_SHA_RE = /^[0-9a-f]{40}$/;
|
|
38
|
+
const ATTEMPT_ID_RE = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
39
|
+
const TOKEN_RE = /^[a-z][a-z0-9_]{0,63}$/;
|
|
40
|
+
const MAX_BLOCKERS = 16;
|
|
41
|
+
const UNAVAILABLE_UNKNOWN = { bound: "unknown", unavailable: true };
|
|
42
|
+
const UNAVAILABLE_BOUND = { bound: true, unavailable: true };
|
|
43
|
+
/** One bounded GET. Never throws; never reads the body of a failed response. */
|
|
44
|
+
async function boundedGet(url, headers, deps) {
|
|
45
|
+
const timeoutMs = Math.max(1, deps.timeoutMs ?? DELIVERY_OUTCOME_READ_TIMEOUT_MS);
|
|
46
|
+
const setTimer = deps.setTimer ?? ((cb, ms) => setTimeout(cb, ms));
|
|
47
|
+
const clearTimer = (deps.clearTimer ?? ((h) => clearTimeout(h)));
|
|
48
|
+
let handle;
|
|
49
|
+
const timeout = new Promise((resolve) => {
|
|
50
|
+
handle = setTimer(() => resolve({ kind: "failed" }), timeoutMs);
|
|
51
|
+
});
|
|
52
|
+
const read = (async () => {
|
|
53
|
+
try {
|
|
54
|
+
const res = await deps.fetch(url, { method: "GET", headers });
|
|
55
|
+
if (res.status === 404)
|
|
56
|
+
return { kind: "not_found" };
|
|
57
|
+
if (res.status < 200 || res.status >= 300)
|
|
58
|
+
return { kind: "failed" };
|
|
59
|
+
const text = await res.text();
|
|
60
|
+
return { kind: "ok", body: JSON.parse(text) };
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return { kind: "failed" };
|
|
64
|
+
}
|
|
65
|
+
})();
|
|
66
|
+
try {
|
|
67
|
+
return await Promise.race([read, timeout]);
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
if (handle !== undefined)
|
|
71
|
+
clearTimer(handle);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function asRecord(value) {
|
|
75
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
76
|
+
? value
|
|
77
|
+
: null;
|
|
78
|
+
}
|
|
79
|
+
/** Reduce the server's blocker list to closed kind tokens and integer step ids. */
|
|
80
|
+
export function summarizeDeliveryBlockers(value) {
|
|
81
|
+
if (!Array.isArray(value))
|
|
82
|
+
return [];
|
|
83
|
+
const out = [];
|
|
84
|
+
for (const entry of value) {
|
|
85
|
+
if (out.length >= MAX_BLOCKERS)
|
|
86
|
+
break;
|
|
87
|
+
const rec = asRecord(entry);
|
|
88
|
+
if (!rec)
|
|
89
|
+
continue;
|
|
90
|
+
const kind = typeof rec.kind === "string" && TOKEN_RE.test(rec.kind) ? rec.kind : "unrecognized";
|
|
91
|
+
const step = rec.step_id;
|
|
92
|
+
out.push(typeof step === "number" && Number.isInteger(step) && step >= 0 && step <= 1_000_000
|
|
93
|
+
? { kind, step_id: step }
|
|
94
|
+
: { kind });
|
|
95
|
+
}
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
function isDeliveryOutcomeToken(value) {
|
|
99
|
+
return typeof value === "string" && DELIVERY_OUTCOMES.includes(value);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* BAPI-1473: does this server decision show a renewed attempt at `headSha` whose
|
|
103
|
+
* only outstanding work is `remote_ci` deferrals? Requires a bound, available
|
|
104
|
+
* `awaiting_post_pr` decision, the server's remote-CI-only flag, and an OBSERVED
|
|
105
|
+
* head equal to `headSha` (never the preserved fallback). Anything else is false.
|
|
106
|
+
*/
|
|
107
|
+
export function deliveryRenewedWithRemoteCiDeferrals(outcome, headSha) {
|
|
108
|
+
if (!outcome || outcome.bound !== true || outcome.unavailable === true)
|
|
109
|
+
return false;
|
|
110
|
+
if (outcome.outcome !== "awaiting_post_pr" || outcome.postPrRemoteCiOnly !== true)
|
|
111
|
+
return false;
|
|
112
|
+
const head = headSha.trim().toLowerCase();
|
|
113
|
+
return FULL_SHA_RE.test(head) && outcome.observedHeadSha === head;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Read the server-confirmed delivery outcome for `job` on `branch`. Never throws.
|
|
117
|
+
* Returns `{ bound: false }` when the job has no ticket or branch, or when the
|
|
118
|
+
* server reports no active attempt (404).
|
|
119
|
+
*/
|
|
120
|
+
export async function fetchServerDeliveryOutcome(job, branch, deps) {
|
|
121
|
+
try {
|
|
122
|
+
const ticket = typeof job.ticket_key === "string" ? job.ticket_key.trim() : "";
|
|
123
|
+
const sourceBranch = typeof branch === "string" ? branch.trim() : "";
|
|
124
|
+
if (!ticket || !sourceBranch || !job.repo_name)
|
|
125
|
+
return { bound: false };
|
|
126
|
+
const resolve = deps.resolveAccess ??
|
|
127
|
+
((repoName) => resolveConductorBridgeApiAccess({ ...(deps.accessDeps ?? {}), repoName }));
|
|
128
|
+
const access = await resolve(job.repo_name);
|
|
129
|
+
if (!access.ok)
|
|
130
|
+
return UNAVAILABLE_UNKNOWN;
|
|
131
|
+
const headers = { "X-API-Key": access.access.apiKey };
|
|
132
|
+
const recoverUrl = new URL(buildConductorVcsUrl(access.access.baseUrl, "/ticket-delivery/executions/recover"));
|
|
133
|
+
recoverUrl.searchParams.set("repo_name", job.repo_name);
|
|
134
|
+
recoverUrl.searchParams.set("ticket_number", ticket);
|
|
135
|
+
recoverUrl.searchParams.set("source_branch", sourceBranch);
|
|
136
|
+
const recovered = await boundedGet(recoverUrl.toString(), headers, deps);
|
|
137
|
+
if (recovered.kind === "not_found")
|
|
138
|
+
return { bound: false };
|
|
139
|
+
if (recovered.kind !== "ok")
|
|
140
|
+
return UNAVAILABLE_UNKNOWN;
|
|
141
|
+
const binding = asRecord(asRecord(recovered.body)?.binding);
|
|
142
|
+
const attemptId = binding?.attempt_id;
|
|
143
|
+
if (typeof attemptId !== "string" || !ATTEMPT_ID_RE.test(attemptId))
|
|
144
|
+
return UNAVAILABLE_BOUND;
|
|
145
|
+
const readinessUrl = new URL(buildConductorVcsUrl(access.access.baseUrl, `/ticket-delivery/executions/${encodeURIComponent(attemptId)}/readiness`));
|
|
146
|
+
readinessUrl.searchParams.set("repo_name", job.repo_name);
|
|
147
|
+
readinessUrl.searchParams.set("boundary", "publish");
|
|
148
|
+
const read = await boundedGet(readinessUrl.toString(), headers, deps);
|
|
149
|
+
if (read.kind !== "ok")
|
|
150
|
+
return UNAVAILABLE_BOUND;
|
|
151
|
+
const body = asRecord(read.body);
|
|
152
|
+
const readiness = asRecord(body?.readiness);
|
|
153
|
+
if (!readiness || !isDeliveryOutcomeToken(readiness.outcome))
|
|
154
|
+
return UNAVAILABLE_BOUND;
|
|
155
|
+
// `preserved_head_sha` is the observed head when the server observed one, but
|
|
156
|
+
// falls back to the binding's stored head otherwise, so it is NOT proof that
|
|
157
|
+
// the decision applies to the current head. `observed_head_sha` is.
|
|
158
|
+
const rawHead = typeof readiness.preserved_head_sha === "string" ? readiness.preserved_head_sha.trim().toLowerCase() : "";
|
|
159
|
+
const snapshot = asRecord(readiness.snapshot);
|
|
160
|
+
const rawObserved = typeof snapshot?.observed_head_sha === "string" ? snapshot.observed_head_sha.trim().toLowerCase() : "";
|
|
161
|
+
const freshBinding = asRecord(body?.binding) ?? binding;
|
|
162
|
+
const rawPr = freshBinding?.pr_number;
|
|
163
|
+
return {
|
|
164
|
+
bound: true,
|
|
165
|
+
attemptId,
|
|
166
|
+
outcome: readiness.outcome,
|
|
167
|
+
preservedHeadSha: FULL_SHA_RE.test(rawHead) ? rawHead : null,
|
|
168
|
+
blockers: summarizeDeliveryBlockers(readiness.blockers),
|
|
169
|
+
prNumber: typeof rawPr === "number" && Number.isInteger(rawPr) && rawPr > 0 ? rawPr : null,
|
|
170
|
+
// Additive (BAPI-1473): present only when the server supplied a usable value,
|
|
171
|
+
// so a response without them parses exactly as it did before.
|
|
172
|
+
...(FULL_SHA_RE.test(rawObserved) ? { observedHeadSha: rawObserved } : {}),
|
|
173
|
+
...(readiness.post_pr_remote_ci_only === true ? { postPrRemoteCiOnly: true } : {}),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return UNAVAILABLE_UNKNOWN;
|
|
178
|
+
}
|
|
179
|
+
}
|
package/build/executor/deps.js
CHANGED
|
@@ -230,5 +230,8 @@ export function createDefaultExecutorDeps() {
|
|
|
230
230
|
argv1: process.argv[1],
|
|
231
231
|
fileExists: existsSync,
|
|
232
232
|
}),
|
|
233
|
+
// BAPI-1479: `workerResources` is deliberately NOT built here. Integration
|
|
234
|
+
// tests spread these real deps, and a real provisioning seam would reach the
|
|
235
|
+
// host PostgreSQL from them. The executor CLI attaches it (`cli.ts`).
|
|
233
236
|
};
|
|
234
237
|
}
|