@bridge_gpt/mcp-server 0.2.75 → 0.2.77
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 +8 -6
- package/build/agents.generated.js +5 -5
- package/build/cli-dispatch.js +333 -0
- package/build/codex-auto-recovery.js +25 -7
- package/build/commands.generated.js +8 -8
- package/build/conductor/bridge-api-client.js +193 -13
- package/build/conductor/declare-blocked.js +146 -7
- package/build/conductor/driver-pass.js +8 -0
- package/build/conductor/driver-register.js +8 -2
- package/build/conductor/epic-implementer-cli.js +15 -10
- package/build/conductor/epic-server-journal.js +52 -22
- package/build/conductor/epic-server-recipe.js +15 -5
- package/build/conductor/epic-server-runtime.js +163 -45
- package/build/conductor/epic-server.js +13 -6
- package/build/conductor/install-doctor.js +30 -2
- package/build/conductor/launch-plan.js +28 -7
- package/build/conductor/local-merge.js +55 -13
- package/build/conductor/pr-ci-producer.js +12 -3
- package/build/conductor/readiness-prerequisites.js +89 -2
- package/build/conductor/readiness-sections.js +46 -13
- package/build/conductor/readiness.js +3 -40
- package/build/conductor/recovery-cli.js +14 -12
- package/build/conductor/repository-workflow-remedy.js +147 -7
- package/build/conductor/ui-readiness.js +224 -0
- package/build/conductor/wait-run-attention.js +9 -4
- package/build/conductor/wait-run-cli.js +9 -2
- package/build/docs.generated.js +67 -4
- package/build/doctor.js +97 -1
- package/build/drive-epic.js +625 -33
- package/build/engine-paths.js +10 -0
- package/build/epic-coherence-input-cli.js +105 -10
- package/build/epic-coherence-input.js +877 -4
- package/build/epic-coherence-input.test-fixtures.js +117 -0
- package/build/epic-implementer-bin.js +947 -120
- package/build/epic-implementer-env.js +2 -2
- package/build/epic-launch-context.js +8 -1
- package/build/epic-shared/cut-protocol.js +55 -3
- package/build/executor/completion-contract.js +14 -1
- package/build/executor/failure-reason-codes.js +2 -0
- package/build/executor/guarded-fast-forward-push.js +25 -2
- package/build/executor/integration-job.js +56 -2
- package/build/executor/job-runner.js +87 -28
- package/build/executor/likely-tests.js +78 -6
- package/build/executor/merge-job.js +45 -1
- package/build/executor/permissions.js +187 -2
- package/build/executor/provider-checks.js +101 -5
- package/build/executor/rebase-finalization.js +29 -27
- package/build/executor/reconcile-overlap-job.js +70 -17
- package/build/executor/rename-aside.js +265 -0
- package/build/executor/required-work-ledger.js +89 -6
- package/build/executor/resume-pre-spawn.js +32 -8
- package/build/executor/runner.js +26 -4
- package/build/executor/types.js +121 -0
- package/build/executor/worktree.js +39 -2
- package/build/index.js +2500 -495
- package/build/init.js +16 -0
- package/build/install-bridge-conductor-answers.js +4 -0
- package/build/install-bridge-conductor-apply.js +10 -0
- package/build/install-bridge-conductor-assessment.js +84 -0
- package/build/install-bridge-conductor-contracts.js +9 -1
- package/build/install-bridge-conductor-setup.js +103 -3
- package/build/install-bridge-conductor.js +440 -812
- package/build/install-bridge.js +4 -11
- package/build/language-catalog.generated.js +2649 -0
- package/build/mcp-host-config.js +54 -37
- package/build/phase-context-git-probe.js +16 -0
- package/build/pipelines.generated.js +47 -19
- package/build/plan-execution-ledger.js +35 -0
- package/build/plan-generation.js +34 -0
- package/build/plane/build-freshness.js +6 -0
- package/build/plane/cli.js +12 -5
- package/build/plane/plane-freshness.js +43 -26
- package/build/printed-remedy-commands.js +17 -0
- package/build/readiness-prerequisites.generated.js +28 -0
- package/build/readme.generated.js +1 -1
- package/build/run-unit-tests-launcher.js +3 -1
- package/build/secret-redaction.js +3 -0
- package/build/server.js +7946 -0
- package/build/setup-epic.js +41 -8
- package/build/start-tickets-prereqs.js +3 -6
- package/build/test-support/console-guard.js +30 -0
- package/build/test-support/create-preview-world.js +232 -0
- package/build/test-support/module-imports.js +155 -0
- package/build/test-support/server-client.js +96 -0
- package/build/test-support/stdio-server.js +146 -0
- package/build/ticket-delivery.js +65 -0
- package/build/v2-readiness-requirements.js +39 -5
- package/build/version.generated.js +3 -3
- package/build/worktree-core.js +51 -7
- package/docs/EPIC-IMPLEMENTER.md +150 -2
- package/docs/epic-implementer/getting-started.md +5 -1
- package/package.json +3 -3
- package/pipelines/implement-ticket.json +2 -2
- package/pipelines/learn-repository.json +19 -1
|
@@ -913,22 +913,110 @@ export async function fetchEffectiveSupervisorConfig(access, epicKey, fetchImpl
|
|
|
913
913
|
const parsed = await fetchConductorJsonWithTimeout(url, conductorGetHeaders(access), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl);
|
|
914
914
|
return parsed;
|
|
915
915
|
}
|
|
916
|
+
/** Server bounds on the `required_checks` query value (BAPI-1527). */
|
|
917
|
+
export const POLL_CI_CHECKS_MAX_REQUIRED_NAMES = 64;
|
|
918
|
+
export const POLL_CI_CHECKS_MAX_REQUIRED_NAME_LENGTH = 200;
|
|
919
|
+
/** The fixed unresolved-cache reason the poll route returns without the fallback. */
|
|
920
|
+
const CI_CHECKS_UNRESOLVED_REASON = "CI checks not yet resolved";
|
|
921
|
+
/** True when `requiredChecks` satisfies the route's array, string, and size contract. */
|
|
922
|
+
function isValidRequiredChecksList(requiredChecks) {
|
|
923
|
+
return (Array.isArray(requiredChecks) &&
|
|
924
|
+
requiredChecks.length <= POLL_CI_CHECKS_MAX_REQUIRED_NAMES &&
|
|
925
|
+
requiredChecks.every((name) => typeof name === "string" && name.length <= POLL_CI_CHECKS_MAX_REQUIRED_NAME_LENGTH));
|
|
926
|
+
}
|
|
916
927
|
/**
|
|
917
928
|
* Poll CI checks for a commit through the existing `/poll-ci-checks` endpoint.
|
|
918
929
|
* Validates `commitRef` with {@link normalizeSha} and rejects BEFORE issuing the
|
|
919
930
|
* request when it is not a valid SHA. Returns the endpoint response verbatim —
|
|
920
931
|
* the client never invents `pr_number`/`head_sha` fields.
|
|
921
|
-
|
|
922
|
-
|
|
932
|
+
*
|
|
933
|
+
* BAPI-1527: the optional trailing `requiredChecks` opts into the route's
|
|
934
|
+
* read-only fallback for a repository whose CI check configuration was never
|
|
935
|
+
* resolved. It is encoded as a JSON array in `required_checks`; an explicit `[]`
|
|
936
|
+
* is sent as `[]`, never omitted. A value that breaks the route's bounds throws
|
|
937
|
+
* `invalid-input` before any request. When the route reports a transient polling
|
|
938
|
+
* failure for an opted-in call, this throws a fixed-text `server` error so the
|
|
939
|
+
* caller keeps its retryable `ci_poll_*` handling; a configuration-unavailable
|
|
940
|
+
* response is returned for {@link classifyCiPollAvailability} to read.
|
|
941
|
+
*/
|
|
942
|
+
export async function pollCiChecksForCommit(access, commitRef, fetchImpl = globalThis.fetch, requiredChecks) {
|
|
923
943
|
const sha = normalizeSha(commitRef);
|
|
924
944
|
if (sha === null) {
|
|
925
945
|
throw new ConductorBridgeApiError("invalid-input");
|
|
926
946
|
}
|
|
927
|
-
|
|
947
|
+
if (requiredChecks !== undefined && !isValidRequiredChecksList(requiredChecks)) {
|
|
948
|
+
throw new ConductorBridgeApiError("invalid-input");
|
|
949
|
+
}
|
|
950
|
+
const params = {
|
|
928
951
|
repo_name: access.repoName,
|
|
929
952
|
commit_ref: sha,
|
|
930
|
-
}
|
|
931
|
-
|
|
953
|
+
};
|
|
954
|
+
if (requiredChecks !== undefined) {
|
|
955
|
+
params.required_checks = JSON.stringify(requiredChecks);
|
|
956
|
+
}
|
|
957
|
+
const url = buildConductorJiraUrl(access.baseUrl, "/poll-ci-checks", params);
|
|
958
|
+
const response = await fetchConductorJsonWithTimeout(url, conductorGetHeaders(access), CONDUCTOR_FETCH_TIMEOUT_MS, fetchImpl);
|
|
959
|
+
if (requiredChecks !== undefined && readUnavailabilityKind(response) === "transient") {
|
|
960
|
+
// Fixed text only: no upstream reason or body is carried forward.
|
|
961
|
+
throw new CiPollTransientUnavailableError();
|
|
962
|
+
}
|
|
963
|
+
return response;
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* BAPI-1527: the route answered an opted-in poll with `unavailability_kind:
|
|
967
|
+
* "transient"` (an exception while it polled the provider). It is an ordinary
|
|
968
|
+
* `server` error to every caller, so readers that stop on a thrown poll keep
|
|
969
|
+
* doing so. The local merge wait alone tells it apart from a real 5xx or network
|
|
970
|
+
* failure: before the opt-in, the same exception came back as a plain
|
|
971
|
+
* not-green envelope and the wait kept polling, so it still does (decision A,
|
|
972
|
+
* never an earlier park).
|
|
973
|
+
*/
|
|
974
|
+
export class CiPollTransientUnavailableError extends ConductorBridgeApiError {
|
|
975
|
+
constructor() {
|
|
976
|
+
super("server");
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
/** The `unavailability_kind` of a poll envelope, or `undefined` when absent or unknown. */
|
|
980
|
+
function readUnavailabilityKind(response) {
|
|
981
|
+
if (response === null || typeof response !== "object")
|
|
982
|
+
return undefined;
|
|
983
|
+
const kind = response.unavailability_kind;
|
|
984
|
+
return kind === "configuration" || kind === "transient" ? kind : undefined;
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Classify a poll response's availability. `configuration_unavailable` means the
|
|
988
|
+
* required-check configuration or provider access could not be read — the
|
|
989
|
+
* route's fixed `unavailability_kind: "configuration"` or its legacy fixed
|
|
990
|
+
* unresolved-cache reason. It is evidence of a missing capability, never of a
|
|
991
|
+
* failed check, so a `detail: null` body must not be read as red CI.
|
|
992
|
+
*/
|
|
993
|
+
export function classifyCiPollAvailability(response) {
|
|
994
|
+
if (response === null || typeof response !== "object")
|
|
995
|
+
return "unavailable_other";
|
|
996
|
+
const obj = response;
|
|
997
|
+
if (obj.available === true)
|
|
998
|
+
return "available";
|
|
999
|
+
if (obj.available !== false)
|
|
1000
|
+
return "unavailable_other";
|
|
1001
|
+
if (readUnavailabilityKind(obj) === "configuration" || obj.reason === CI_CHECKS_UNRESOLVED_REASON) {
|
|
1002
|
+
return "configuration_unavailable";
|
|
1003
|
+
}
|
|
1004
|
+
return "unavailable_other";
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* True when a successful poll came from the route's required-checks fallback and
|
|
1008
|
+
* observed no check at all. Distinguishes "nothing reported yet" from red CI.
|
|
1009
|
+
*/
|
|
1010
|
+
export function isFallbackWithNoObservedChecks(response) {
|
|
1011
|
+
if (response === null || typeof response !== "object")
|
|
1012
|
+
return false;
|
|
1013
|
+
const detail = response.detail;
|
|
1014
|
+
if (detail === null || typeof detail !== "object")
|
|
1015
|
+
return false;
|
|
1016
|
+
const d = detail;
|
|
1017
|
+
return (d.evaluation_source === "required_checks_fallback" &&
|
|
1018
|
+
Array.isArray(d.checks) &&
|
|
1019
|
+
d.checks.length === 0);
|
|
932
1020
|
}
|
|
933
1021
|
// ---------------------------------------------------------------------------
|
|
934
1022
|
// Conductor BAPI-440: PR review status GET client
|
|
@@ -1658,7 +1746,7 @@ export async function createEpicRunWithDisposition(access, request, fetchImpl =
|
|
|
1658
1746
|
// `ConductorMutationOutcomeUnknownError`; the caller re-reads, never re-sends.
|
|
1659
1747
|
let response;
|
|
1660
1748
|
try {
|
|
1661
|
-
response = await fetchConductorJsonWithMethodStatusAndTimeout("POST", url, conductorPostHeaders(access), JSON.stringify(body),
|
|
1749
|
+
response = await fetchConductorJsonWithMethodStatusAndTimeout("POST", url, conductorPostHeaders(access), JSON.stringify(body), CONDUCTOR_READINESS_FETCH_TIMEOUT_MS, fetchImpl);
|
|
1662
1750
|
}
|
|
1663
1751
|
catch (err) {
|
|
1664
1752
|
rethrowMutationFailure("create", err);
|
|
@@ -3896,6 +3984,45 @@ const RETIRED_ROW_TEXT_MAX = 400;
|
|
|
3896
3984
|
function isBoundedServerText(value) {
|
|
3897
3985
|
return typeof value === 'string' && value.length <= RETIRED_ROW_TEXT_MAX && !/[\u0000-\u001f\u007f]/.test(value);
|
|
3898
3986
|
}
|
|
3987
|
+
const FINDING_NAME_MAX = 100;
|
|
3988
|
+
const FINDING_NAMES_MAX = 20;
|
|
3989
|
+
/**
|
|
3990
|
+
* BAPI-1747 — validate optional findings. Unusable findings are dropped on their own;
|
|
3991
|
+
* they never cost the row or the list. Names must be short, printable, and plain.
|
|
3992
|
+
*/
|
|
3993
|
+
function parseReadinessFindings(raw) {
|
|
3994
|
+
if (!Array.isArray(raw))
|
|
3995
|
+
return undefined;
|
|
3996
|
+
const out = [];
|
|
3997
|
+
for (const item of raw.slice(0, 50)) {
|
|
3998
|
+
if (typeof item !== 'object' || item === null || Array.isArray(item))
|
|
3999
|
+
continue;
|
|
4000
|
+
const f = item;
|
|
4001
|
+
if (typeof f.reason !== 'string' || !/^[a-z_]{1,40}$/.test(f.reason))
|
|
4002
|
+
continue;
|
|
4003
|
+
if (f.status !== 'not_met' && f.status !== 'unknown')
|
|
4004
|
+
continue;
|
|
4005
|
+
const names = Array.isArray(f.names) ? f.names : [];
|
|
4006
|
+
if (names.length > FINDING_NAMES_MAX || !names.every(n => typeof n === 'string' && n.length > 0 && n.length <= FINDING_NAME_MAX && /^[A-Za-z0-9 _./:()[\]@#+-]+$/.test(n)))
|
|
4007
|
+
continue;
|
|
4008
|
+
const finding = { reason: f.reason, status: f.status, names: names };
|
|
4009
|
+
if (typeof f.count === 'number' && Number.isInteger(f.count) && f.count >= 0)
|
|
4010
|
+
finding.count = f.count;
|
|
4011
|
+
out.push(finding);
|
|
4012
|
+
}
|
|
4013
|
+
return out.length ? out : undefined;
|
|
4014
|
+
}
|
|
4015
|
+
const PREREQUISITE_ROW_KEYS = 'check_status,fix,id,impact,label,scope';
|
|
4016
|
+
/** The six original keys, with an optional `findings` key (BAPI-1747). */
|
|
4017
|
+
function hasPrerequisiteRowKeys(r) {
|
|
4018
|
+
const keys = Object.keys(r).filter(k => k !== 'findings').sort().join(',');
|
|
4019
|
+
return keys === PREREQUISITE_ROW_KEYS;
|
|
4020
|
+
}
|
|
4021
|
+
function withFindings(r) {
|
|
4022
|
+
const { findings, ...row } = r;
|
|
4023
|
+
const parsed = parseReadinessFindings(findings);
|
|
4024
|
+
return (parsed ? { ...row, findings: parsed } : row);
|
|
4025
|
+
}
|
|
3899
4026
|
export function parseReadinessPrerequisites(raw) {
|
|
3900
4027
|
if (!Array.isArray(raw))
|
|
3901
4028
|
return undefined;
|
|
@@ -3905,27 +4032,54 @@ export function parseReadinessPrerequisites(raw) {
|
|
|
3905
4032
|
if (typeof item !== 'object' || item === null || Array.isArray(item))
|
|
3906
4033
|
return undefined;
|
|
3907
4034
|
const r = item;
|
|
3908
|
-
|
|
3909
|
-
|
|
4035
|
+
// BAPI-1602 retired rows, and BAPI-1747 rows a NEWER server sends that this build
|
|
4036
|
+
// does not know: kept with the server's own bounded text and rendered after the
|
|
4037
|
+
// catalog rows, never dropped, so one new row cannot hide the whole list.
|
|
4038
|
+
if (typeof r.id === 'string' && !READINESS_PREREQUISITE_BY_ID.has(r.id)) {
|
|
4039
|
+
if (seen.has(r.id) || !/^[a-z][a-z0-9_.-]{0,99}$/.test(r.id) || !hasPrerequisiteRowKeys(r) ||
|
|
3910
4040
|
!isBoundedServerText(r.label) || !isBoundedServerText(r.fix) || !['customer', 'self_host'].includes(String(r.scope)) ||
|
|
3911
4041
|
!['met', 'not_met', 'unknown', 'not_applicable'].includes(String(r.check_status)) || !['blocking', 'warning', 'info'].includes(String(r.impact)) ||
|
|
3912
|
-
(r.check_status === 'unknown' && r.impact === 'blocking'))
|
|
3913
|
-
|
|
4042
|
+
(r.check_status === 'unknown' && r.impact === 'blocking')) {
|
|
4043
|
+
if (RETIRED_READINESS_PREREQUISITE_IDS.has(r.id))
|
|
4044
|
+
return undefined;
|
|
4045
|
+
continue;
|
|
4046
|
+
}
|
|
3914
4047
|
seen.add(r.id);
|
|
3915
|
-
result.push(r);
|
|
4048
|
+
result.push(withFindings(r));
|
|
3916
4049
|
continue;
|
|
3917
4050
|
}
|
|
3918
4051
|
const d = typeof r.id === 'string' ? READINESS_PREREQUISITE_BY_ID.get(r.id) : undefined;
|
|
3919
|
-
if (!d || seen.has(d.id) ||
|
|
4052
|
+
if (!d || seen.has(d.id) || !hasPrerequisiteRowKeys(r) || r.label !== d.label || r.scope !== d.scope ||
|
|
3920
4053
|
!['met', 'not_met', 'unknown', 'not_applicable'].includes(String(r.check_status)) || !['blocking', 'warning', 'info'].includes(String(r.impact)) ||
|
|
3921
4054
|
typeof r.fix !== 'string' || !(Object.values(READINESS_PREREQUISITE_FIXES).includes(r.fix) || PREVIOUS_SERVER_READINESS_FIXES.includes(r.fix)) ||
|
|
3922
4055
|
(r.check_status === 'unknown' && r.impact === 'blocking'))
|
|
3923
4056
|
return undefined;
|
|
3924
4057
|
seen.add(d.id);
|
|
3925
|
-
result.push(r);
|
|
4058
|
+
result.push(withFindings(r));
|
|
3926
4059
|
}
|
|
3927
4060
|
return result;
|
|
3928
4061
|
}
|
|
4062
|
+
/** BAPI-1526 — the four forecast outcomes the server may report. */
|
|
4063
|
+
export const MERGE_FORECAST_OUTCOMES = [
|
|
4064
|
+
"auto_merge_kept",
|
|
4065
|
+
"merge_approval_required",
|
|
4066
|
+
"not_requested",
|
|
4067
|
+
"unknown",
|
|
4068
|
+
];
|
|
4069
|
+
/** BAPI-1526 — the closed first-approval stamp reason tokens (`gate_profile.py`). */
|
|
4070
|
+
export const MERGE_FORECAST_REASON_IDS = [
|
|
4071
|
+
"local_gate_verification_disabled",
|
|
4072
|
+
"local_gate_direct_to_base",
|
|
4073
|
+
"none_profile_requires_merge_approval",
|
|
4074
|
+
"operator_no_ci_gate_override",
|
|
4075
|
+
"operator_ci_key_kept",
|
|
4076
|
+
"plan_node_required_checks_gate_the_run",
|
|
4077
|
+
"repository_policy_auto_merge_kept_without_ci",
|
|
4078
|
+
"epic_branch_ci_declined",
|
|
4079
|
+
"epic_branch_auto_merge_kept",
|
|
4080
|
+
"no_automated_check",
|
|
4081
|
+
"watched_checks_only",
|
|
4082
|
+
];
|
|
3929
4083
|
export const ESCALATION_CHANNELS = ["webhook", "email", "none", "unknown"];
|
|
3930
4084
|
export const WEBHOOK_LAST_DELIVERIES = ["failed", "handed_off", "queued", "unknown"];
|
|
3931
4085
|
/** BAPI-1452 — the three supported merge execution modes, as the server reports them. */
|
|
@@ -4316,6 +4470,32 @@ export function parseConductorReadinessResponse(body) {
|
|
|
4316
4470
|
})(),
|
|
4317
4471
|
...parseLaunchMergeFacts(root),
|
|
4318
4472
|
...parseEscalationObservations(root),
|
|
4473
|
+
...(() => {
|
|
4474
|
+
const forecast = parseMergeForecast(root.merge_forecast);
|
|
4475
|
+
return forecast === undefined ? {} : { merge_forecast: forecast };
|
|
4476
|
+
})(),
|
|
4477
|
+
};
|
|
4478
|
+
}
|
|
4479
|
+
/**
|
|
4480
|
+
* BAPI-1526 — parse the optional advisory forecast. Absent, `null`, or malformed
|
|
4481
|
+
* (an unknown outcome, a non-array, an unknown reason, or too many reasons) is
|
|
4482
|
+
* `undefined`, never an error: losing the readiness read over an advisory field
|
|
4483
|
+
* would be the wrong trade.
|
|
4484
|
+
*/
|
|
4485
|
+
export function parseMergeForecast(value) {
|
|
4486
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
4487
|
+
return undefined;
|
|
4488
|
+
const o = value;
|
|
4489
|
+
if (!MERGE_FORECAST_OUTCOMES.includes(o.outcome))
|
|
4490
|
+
return undefined;
|
|
4491
|
+
const raw = o.reason_ids === undefined ? [] : o.reason_ids;
|
|
4492
|
+
if (!Array.isArray(raw) || raw.length > MERGE_FORECAST_REASON_IDS.length)
|
|
4493
|
+
return undefined;
|
|
4494
|
+
if (!raw.every((r) => MERGE_FORECAST_REASON_IDS.includes(r)))
|
|
4495
|
+
return undefined;
|
|
4496
|
+
return {
|
|
4497
|
+
outcome: o.outcome,
|
|
4498
|
+
reason_ids: [...raw],
|
|
4319
4499
|
};
|
|
4320
4500
|
}
|
|
4321
4501
|
/**
|
|
@@ -117,6 +117,10 @@ export function getDeclareBlockedUsage() {
|
|
|
117
117
|
" run-wide blocked, escalated nothing can progress; keep the normal waiter running",
|
|
118
118
|
" scope unknown supervision continues",
|
|
119
119
|
"--entry wedge needs --evidence, --tried, --alternatives and --fixer-outcome.",
|
|
120
|
+
`Limits: --requirement ${DECLARE_BLOCKED_LIMITS.requirement}, --evidence ${DECLARE_BLOCKED_LIMITS.evidence}, ` +
|
|
121
|
+
`--tried ${DECLARE_BLOCKED_LIMITS.tried}, --alternatives ${DECLARE_BLOCKED_LIMITS.alternatives}, ` +
|
|
122
|
+
`--fixer-outcome ${DECLARE_BLOCKED_LIMITS.fixerOutcome} characters each; ` +
|
|
123
|
+
`at most ${DECLARE_BLOCKED_LIMITS.tickets} --ticket-key arguments.`,
|
|
120
124
|
].join("\n");
|
|
121
125
|
}
|
|
122
126
|
const VALUE_FLAGS = new Set([
|
|
@@ -330,6 +334,118 @@ async function waiterFor(roots, env, launcher, epicRunId, epicKey) {
|
|
|
330
334
|
}
|
|
331
335
|
return renderPlainWaiterCommand(launcher, epicRunId);
|
|
332
336
|
}
|
|
337
|
+
// ---------------------------------------------------------------------------
|
|
338
|
+
// BAPI-1781 — bounded delivery re-read
|
|
339
|
+
// ---------------------------------------------------------------------------
|
|
340
|
+
/** The whole re-read phase's budget, request timeouts and pauses included. */
|
|
341
|
+
export const DELIVERY_REREAD_BUDGET_MS = 5_000;
|
|
342
|
+
/** The short pause between re-read rounds. */
|
|
343
|
+
export const DELIVERY_REREAD_INTERVAL_MS = 500;
|
|
344
|
+
/** Printed when the stored status is still `queued` after the bounded re-read. */
|
|
345
|
+
export const DELIVERY_QUEUED_TEXT = "queued, not yet handed off";
|
|
346
|
+
/** Printed when the escalation was accepted but no re-read succeeded. */
|
|
347
|
+
export const DELIVERY_UNVERIFIED_TEXT = "accepted, but delivery could not be verified";
|
|
348
|
+
/**
|
|
349
|
+
* A stored status that will not change by waiting a few seconds. `queued` is
|
|
350
|
+
* the normal first answer (the sweep runs every 60 seconds) and `unknown...`
|
|
351
|
+
* may still settle, so both keep polling; every other status is conclusive.
|
|
352
|
+
*/
|
|
353
|
+
export function isConclusiveDeliveryStatus(status) {
|
|
354
|
+
return status !== "queued" && !status.startsWith("unknown");
|
|
355
|
+
}
|
|
356
|
+
/** A fetch that also aborts when `deadline` aborts (Node 18 has no AbortSignal.any). */
|
|
357
|
+
function deadlineBoundFetch(deadline) {
|
|
358
|
+
const base = globalThis.fetch;
|
|
359
|
+
return (url, init) => {
|
|
360
|
+
const combined = new AbortController();
|
|
361
|
+
const abort = () => combined.abort();
|
|
362
|
+
if (init.signal.aborted || deadline.aborted)
|
|
363
|
+
combined.abort();
|
|
364
|
+
init.signal.addEventListener("abort", abort, { once: true });
|
|
365
|
+
deadline.addEventListener("abort", abort, { once: true });
|
|
366
|
+
return base(url, { ...init, signal: combined.signal }).finally(() => {
|
|
367
|
+
init.signal.removeEventListener("abort", abort);
|
|
368
|
+
deadline.removeEventListener("abort", abort);
|
|
369
|
+
});
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
/** Run one call, bounded by `ms`; resolves `null` when the bound runs out or the call fails. */
|
|
373
|
+
async function boundedCall(ms, call) {
|
|
374
|
+
const controller = new AbortController();
|
|
375
|
+
let timer;
|
|
376
|
+
const expired = new Promise((resolve) => {
|
|
377
|
+
timer = setTimeout(() => { controller.abort(); resolve(null); }, Math.max(0, ms));
|
|
378
|
+
});
|
|
379
|
+
try {
|
|
380
|
+
return await Promise.race([call(controller.signal).catch(() => null), expired]);
|
|
381
|
+
}
|
|
382
|
+
finally {
|
|
383
|
+
if (timer !== undefined)
|
|
384
|
+
clearTimeout(timer);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Re-read each accepted escalation's delivery status from storage within ONE
|
|
389
|
+
* bounded budget. The only mechanism is replaying the identical accepted
|
|
390
|
+
* request: the server resolves the same notification identity (`created=False`)
|
|
391
|
+
* and reports `_delivery_status` from the stored row. A response for a different
|
|
392
|
+
* notification is ignored. The last valid stored status is kept; a later
|
|
393
|
+
* timeout never replaces it. Nothing here triggers the notification sweep.
|
|
394
|
+
*/
|
|
395
|
+
export async function rereadDeliveryStatuses(access, accepted, deps) {
|
|
396
|
+
const clock = deps.monotonicNow ?? (() => performance.now());
|
|
397
|
+
const sleep = deps.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
398
|
+
const budget = deps.rereadBudgetMs ?? DELIVERY_REREAD_BUDGET_MS;
|
|
399
|
+
const interval = deps.rereadIntervalMs ?? DELIVERY_REREAD_INTERVAL_MS;
|
|
400
|
+
const reread = deps.reread ?? (deps.escalate
|
|
401
|
+
? (a, r) => deps.escalate(a, r)
|
|
402
|
+
: (a, r, signal) => escalateTicket(a, r, deadlineBoundFetch(signal)));
|
|
403
|
+
const results = accepted.map(({ response }) => isConclusiveDeliveryStatus(response.delivery_status)
|
|
404
|
+
? { status: response.delivery_status, source: "response" }
|
|
405
|
+
: { status: response.delivery_status, source: "unverified" });
|
|
406
|
+
const pending = () => results
|
|
407
|
+
.map((r, i) => (r.source === "response" || (r.source === "storage" && isConclusiveDeliveryStatus(r.status)) ? -1 : i))
|
|
408
|
+
.filter((i) => i >= 0);
|
|
409
|
+
const deadline = clock() + budget;
|
|
410
|
+
while (pending().length > 0) {
|
|
411
|
+
for (const i of pending()) {
|
|
412
|
+
const remaining = deadline - clock();
|
|
413
|
+
if (remaining <= 0)
|
|
414
|
+
return results;
|
|
415
|
+
const { request, response } = accepted[i];
|
|
416
|
+
const replay = { ...request };
|
|
417
|
+
const answer = await boundedCall(remaining, (signal) => reread(access, replay, signal));
|
|
418
|
+
if (answer && answer.notification_id === response.notification_id &&
|
|
419
|
+
typeof answer.delivery_status === "string" && answer.delivery_status !== "") {
|
|
420
|
+
results[i] = { status: answer.delivery_status, source: "storage" };
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
if (pending().length === 0)
|
|
424
|
+
break;
|
|
425
|
+
const remaining = deadline - clock();
|
|
426
|
+
if (remaining <= 0)
|
|
427
|
+
break;
|
|
428
|
+
await sleep(Math.min(interval, remaining));
|
|
429
|
+
}
|
|
430
|
+
return results;
|
|
431
|
+
}
|
|
432
|
+
/** The operator-facing delivery phrase for one accepted escalation. */
|
|
433
|
+
export function renderDeliveryOutcome(delivery, statusCommand) {
|
|
434
|
+
if (delivery.source === "unverified") {
|
|
435
|
+
return `${DELIVERY_UNVERIFIED_TEXT}; check it with ${statusCommand}`;
|
|
436
|
+
}
|
|
437
|
+
if (delivery.status === "queued") {
|
|
438
|
+
return `delivery ${DELIVERY_QUEUED_TEXT}; check later with ${statusCommand} or the explain_run MCP tool`;
|
|
439
|
+
}
|
|
440
|
+
if (!isConclusiveDeliveryStatus(delivery.status)) {
|
|
441
|
+
return `delivery ${delivery.status}; check later with ${statusCommand} or the explain_run MCP tool`;
|
|
442
|
+
}
|
|
443
|
+
return `delivery ${delivery.status}`;
|
|
444
|
+
}
|
|
445
|
+
/** The status-check command named in delivery output. */
|
|
446
|
+
export function deliveryStatusCommand(epicRunId) {
|
|
447
|
+
return `epic-implementer epic-status --epic-run-id ${epicRunId}`;
|
|
448
|
+
}
|
|
333
449
|
/** Run `declare-blocked`. Never throws; returns the exit code. */
|
|
334
450
|
export async function runDeclareBlockedCommand(argv, deps = {}) {
|
|
335
451
|
const env = deps.env ?? process.env;
|
|
@@ -445,10 +561,11 @@ export async function runDeclareBlockedCommand(argv, deps = {}) {
|
|
|
445
561
|
}
|
|
446
562
|
guided.set(ticket, classification.guidedCommand);
|
|
447
563
|
try {
|
|
448
|
-
const
|
|
564
|
+
const request = {
|
|
449
565
|
epicRunId, ticketKey: ticket, cause: DECLARE_BLOCKED_CAUSES[args.entry], actionNeeded: composeActionNeeded(args),
|
|
450
|
-
}
|
|
451
|
-
|
|
566
|
+
};
|
|
567
|
+
const response = await (deps.escalate ?? escalateTicket)(access, { ...request });
|
|
568
|
+
outcomes.push({ ticket, class: "accepted", response, request });
|
|
452
569
|
}
|
|
453
570
|
catch (error) {
|
|
454
571
|
if (error instanceof ConductorBridgeApiError && error.status === 422) {
|
|
@@ -464,6 +581,23 @@ export async function runDeclareBlockedCommand(argv, deps = {}) {
|
|
|
464
581
|
outcomes.push({ ticket, class: "scope_unknown", reason: "processing_failed" });
|
|
465
582
|
}
|
|
466
583
|
}
|
|
584
|
+
// BAPI-1781 — the real delivery outcome: one bounded re-read phase for every
|
|
585
|
+
// accepted escalation whose answer was not already conclusive. Advisory: a
|
|
586
|
+
// failure here never changes the class or the exit code.
|
|
587
|
+
const acceptedOutcomes = outcomes.filter((o) => o.class === "accepted");
|
|
588
|
+
try {
|
|
589
|
+
const readbacks = await rereadDeliveryStatuses(access, acceptedOutcomes.map((o) => ({
|
|
590
|
+
request: o.request ?? { epicRunId, ticketKey: o.ticket, cause: DECLARE_BLOCKED_CAUSES[args.entry],
|
|
591
|
+
actionNeeded: composeActionNeeded(args) },
|
|
592
|
+
response: o.response,
|
|
593
|
+
})), deps);
|
|
594
|
+
acceptedOutcomes.forEach((o, i) => { o.delivery = readbacks[i]; });
|
|
595
|
+
}
|
|
596
|
+
catch {
|
|
597
|
+
for (const o of acceptedOutcomes)
|
|
598
|
+
o.delivery ??= { status: o.response.delivery_status, source: "unverified" };
|
|
599
|
+
}
|
|
600
|
+
const deliveryOf = (o) => o.delivery ?? { status: o.response.delivery_status, source: "unverified" };
|
|
467
601
|
// Records: one receipt and one closed-valued tally line per ticket. A failed
|
|
468
602
|
// write is reported, never fatal to the advice already computed.
|
|
469
603
|
let recordsFailed = false;
|
|
@@ -476,7 +610,7 @@ export async function runDeclareBlockedCommand(argv, deps = {}) {
|
|
|
476
610
|
entry: args.entry,
|
|
477
611
|
guided_command: guided.get(outcome.ticket) ?? null,
|
|
478
612
|
notification_id: accepted?.notification_id ?? null,
|
|
479
|
-
delivery_status: accepted
|
|
613
|
+
delivery_status: outcome.class === "accepted" ? deliveryOf(outcome).status : null,
|
|
480
614
|
requirement: args.requirement,
|
|
481
615
|
evidence: args.evidence,
|
|
482
616
|
tried: args.triedText,
|
|
@@ -485,7 +619,8 @@ export async function runDeclareBlockedCommand(argv, deps = {}) {
|
|
|
485
619
|
const fields = { ticket: outcome.ticket, class: outcome.class, entry: args.entry };
|
|
486
620
|
if (accepted) {
|
|
487
621
|
fields.notification_id = accepted.notification_id;
|
|
488
|
-
fields.delivery_status = deliveryStatusToken(accepted.
|
|
622
|
+
fields.delivery_status = deliveryStatusToken(outcome.class === "accepted" ? deliveryOf(outcome).status
|
|
623
|
+
: accepted.delivery_status);
|
|
489
624
|
}
|
|
490
625
|
if (outcome.class === "scope_unknown" || outcome.class === "escalation_failed")
|
|
491
626
|
fields.reason = outcome.reason;
|
|
@@ -508,7 +643,8 @@ export async function runDeclareBlockedCommand(argv, deps = {}) {
|
|
|
508
643
|
}
|
|
509
644
|
else if (o.class === "accepted") {
|
|
510
645
|
lines.push(`${o.ticket}: accepted, escalated (${DECLARE_BLOCKED_CAUSES[args.entry]}; notification ` +
|
|
511
|
-
`${o.response.notification_id};
|
|
646
|
+
`${o.response.notification_id}; ${renderDeliveryOutcome(deliveryOf(o), deliveryStatusCommand(epicRunId))}; ` +
|
|
647
|
+
`${o.response.blocker_enforcement}).`);
|
|
512
648
|
}
|
|
513
649
|
else if (o.class === "scope_unknown") {
|
|
514
650
|
lines.push(`${o.ticket}: scope unknown (${o.reason}); supervision continues.`);
|
|
@@ -538,7 +674,10 @@ export async function runDeclareBlockedCommand(argv, deps = {}) {
|
|
|
538
674
|
epic_key: epicKey,
|
|
539
675
|
outcomes: outcomes.map((o) => o.class === "accepted"
|
|
540
676
|
? { ticket: o.ticket, class: o.class, notification_id: o.response.notification_id,
|
|
541
|
-
delivery_status: o.
|
|
677
|
+
delivery_status: deliveryOf(o).status, delivery_readback: deliveryOf(o).source,
|
|
678
|
+
...(deliveryOf(o).source === "unverified" || !isConclusiveDeliveryStatus(deliveryOf(o).status)
|
|
679
|
+
? { status_command: deliveryStatusCommand(epicRunId) } : {}),
|
|
680
|
+
blocks: o.response.blocks,
|
|
542
681
|
blocker_enforcement: o.response.blocker_enforcement }
|
|
543
682
|
: o),
|
|
544
683
|
summary,
|
|
@@ -182,8 +182,16 @@ function readJobs(block) {
|
|
|
182
182
|
* dropped. An accepted job keeps its own timestamp distinctions (missing, null, malformed,
|
|
183
183
|
* valid), so an unreadable `created_at` stays attributable to its ticket. State jobs need no
|
|
184
184
|
* heartbeat; that evidence belongs to explain's outstanding jobs.
|
|
185
|
+
*
|
|
186
|
+
* BAPI-1733: one other shape is readable. A block whose `state` is `"unknown"` and whose
|
|
187
|
+
* `empty_reason` is exactly `"no_jobs"` is the server's confirmation that both job sources read
|
|
188
|
+
* clean and the whole run has no jobs, so it reads as an empty map. Bare `unknown`, any other
|
|
189
|
+
* marker, and every other non-available block stay unreadable.
|
|
185
190
|
*/
|
|
186
191
|
export function readStateJobs(block) {
|
|
192
|
+
if (isRecord(block) && block.state === "unknown" && block.empty_reason === "no_jobs") {
|
|
193
|
+
return new Map();
|
|
194
|
+
}
|
|
187
195
|
if (!isRecord(block) || block.state !== "available" || !Array.isArray(block.jobs))
|
|
188
196
|
return "unreadable";
|
|
189
197
|
const byTicket = new Map();
|
|
@@ -19,10 +19,11 @@
|
|
|
19
19
|
* step (keep monitoring in the foreground) and never stops the run.
|
|
20
20
|
*/
|
|
21
21
|
import { randomBytes } from "node:crypto";
|
|
22
|
+
import { stat } from "node:fs/promises";
|
|
22
23
|
import { fetchEpicRunState, resolveConductorBridgeApiAccess, } from "./bridge-api-client.js";
|
|
23
24
|
import { renderReleaseCommand, renderWaiterCommand, resolveDriverLauncher, } from "./driver-commands.js";
|
|
24
25
|
import { transcribeLapseResult } from "./driver-lapse.js";
|
|
25
|
-
import { DRIVER_KEY_PATTERN, DRIVER_RUN_REF_PATTERN, DRIVER_SESSION_ID_PATTERN, DRIVER_STATE_VERSION, appendDriverTallyLine, createDriverJsonExclusive, currentPointerPath, formatDriverTallyLine, generationFilePath, generationLabel, parseRegistration, readDriverJson, registrationPath, resolveDriverStateRoots, writeDriverJsonAtomic, } from "./driver-session-state.js";
|
|
26
|
+
import { DRIVER_KEY_PATTERN, DRIVER_RUN_REF_PATTERN, DRIVER_SESSION_ID_PATTERN, DRIVER_STATE_VERSION, appendDriverTallyLine, createDriverJsonExclusive, currentPointerPath, formatDriverTallyLine, generationFilePath, generationLabel, parseRegistration, readDriverJson, registrationPath, resolveDriverStateRoots, tallyPath, writeDriverJsonAtomic, } from "./driver-session-state.js";
|
|
26
27
|
const TERMINAL_RUN_STATUSES = new Set(["done", "abandoned"]);
|
|
27
28
|
const NOT_ARMED_NEXT_STEP = "Keep monitoring in the foreground; do not end a turn while the run is active.";
|
|
28
29
|
export function getDriverRegisterUsage() {
|
|
@@ -148,7 +149,12 @@ export async function runDriverRegisterCommand(argv, deps = {}) {
|
|
|
148
149
|
registered_at: now().toISOString(),
|
|
149
150
|
};
|
|
150
151
|
await publishRegistration(roots, registration);
|
|
151
|
-
|
|
152
|
+
// BAPI-1782 — never CREATE the tally here: operation 8 writes its header first.
|
|
153
|
+
// Append the register line only to a tally that already exists; skip silently otherwise.
|
|
154
|
+
const tallyExists = await stat(tallyPath(roots, run.epic_key)).then((info) => info.isFile(), () => false);
|
|
155
|
+
if (tallyExists) {
|
|
156
|
+
await appendDriverTallyLine(roots, run.epic_key, formatDriverTallyLine("driver-guard", { event: "register", generation: generationLabel(generation) }, now())).catch(() => undefined);
|
|
157
|
+
}
|
|
152
158
|
if (parsed.json) {
|
|
153
159
|
out(JSON.stringify({
|
|
154
160
|
armed: true,
|
|
@@ -91,10 +91,11 @@ export function getConductorUsage() {
|
|
|
91
91
|
" likely-tests --base <sha> Local advisory test references for committed changes.",
|
|
92
92
|
" file-scope-guard Warn-only: compare the branch diff against the declared",
|
|
93
93
|
" touched-file set (always exits 0; never blocks a PR)",
|
|
94
|
-
" stop-run
|
|
95
|
-
" (the run record is preserved).
|
|
96
|
-
"
|
|
97
|
-
"
|
|
94
|
+
" stop-run Pause an epic run: block dispatch and cancel queued work",
|
|
95
|
+
" (the run record is preserved; it does NOT end the run).",
|
|
96
|
+
" Idempotent. To end a run, use abandon-run.",
|
|
97
|
+
" abandon-run End an active or stopped epic run in one step — TERMINAL",
|
|
98
|
+
" and IRREVERSIBLE. Idempotent on an already-abandoned run.",
|
|
98
99
|
" unpark Move a parked (needs_human) ticket back into its gate",
|
|
99
100
|
" machine. Retries internally on a concurrent change.",
|
|
100
101
|
" adopt-current-head-and-unpark",
|
|
@@ -131,7 +132,7 @@ export function getConductorUsage() {
|
|
|
131
132
|
" returns to evaluation with NO new wait, job, or repair allowance.",
|
|
132
133
|
" rerun-ci --epic-run-id <id> --ticket-key <key> --binding <token> [--json]",
|
|
133
134
|
" Ask CI to re-run a ticket's FAILED checks at its bound head (guided: copy",
|
|
134
|
-
" the command
|
|
135
|
+
" the command the `explain_run` MCP tool rendered). Charges NO allowance and never re-runs",
|
|
135
136
|
" claude-review. A re-run is not a verdict: after CI is green, use resume-ci.",
|
|
136
137
|
" regenerate-plan --epic-run-id <id> --ticket-key <key> --route test|implementation --reason <text> [--json]",
|
|
137
138
|
" Answer a child parked on a NAMED plan failure with ONE forced plan",
|
|
@@ -155,7 +156,7 @@ export function getConductorUsage() {
|
|
|
155
156
|
" epic-head commit: the PR leaves draft only when both holds are clear.",
|
|
156
157
|
" acknowledge-gaps --epic-run-id <id> --digest <CURRENT_DIGEST> --reason <text> [--json]",
|
|
157
158
|
" The OWNER's one acknowledgement of the run's carried-gap list, by its",
|
|
158
|
-
" current digest (from the PR report or
|
|
159
|
+
" current digest (from the PR report or the `explain_run` MCP tool). Never run by the",
|
|
159
160
|
" driver or a worker; it verifies, readies and merges nothing.",
|
|
160
161
|
" wait-run --epic-run-id <id> [--ticket-key <key>] [--since <token>] [--timeout <seconds>]",
|
|
161
162
|
" [--until change|attention] [--json] [--watch [--max-minutes <minutes>]]",
|
|
@@ -208,6 +209,7 @@ export function getConductorUsage() {
|
|
|
208
209
|
" [--evidence <text>] [--tried <verbs>] [--alternatives <text>] [--fixer-outcome <text>]",
|
|
209
210
|
" Advisory blocker check: not a blocker yet (run <command>), accepted and",
|
|
210
211
|
" escalated, run-wide blocked, or scope unknown. Never releases supervision.",
|
|
212
|
+
" Limits: epic-implementer declare-blocked --help",
|
|
211
213
|
"",
|
|
212
214
|
"supervise options:",
|
|
213
215
|
" --run-id <id> Run/session identifier to supervise (required)",
|
|
@@ -321,9 +323,12 @@ export function getConductorUsage() {
|
|
|
321
323
|
" --epic-run-id <id> Epic run identifier (required)",
|
|
322
324
|
" --json Print compact JSON result",
|
|
323
325
|
" --help Print this usage message",
|
|
324
|
-
" stop-run BLOCKS new dispatch and CANCELS queued work; the
|
|
325
|
-
" preserved and the run cannot resume on its own
|
|
326
|
-
"
|
|
326
|
+
" stop-run PAUSES a run: it BLOCKS new dispatch and CANCELS queued work; the",
|
|
327
|
+
" run record is preserved and the run cannot resume on its own. stop-run does",
|
|
328
|
+
" NOT end the run — a stopped run stays live (blocked) until it is abandoned.",
|
|
329
|
+
" abandon-run --epic-run-id <id> is the one-step way to END an active or",
|
|
330
|
+
" stopped run: the server applies the same stop fence (block dispatch, cancel",
|
|
331
|
+
" queued work) and then commits the TERMINAL, IRREVERSIBLE abandoned status;",
|
|
327
332
|
" once abandoned, the run can never resume or be reused. Both are idempotent —",
|
|
328
333
|
" repeating either is a safe no-op once the run is already stopped/abandoned.",
|
|
329
334
|
"",
|
|
@@ -359,7 +364,7 @@ export function getConductorUsage() {
|
|
|
359
364
|
" epic-implementer resume-ci --epic-run-id 3f9c2b7e-... --ticket-key PROJ-852",
|
|
360
365
|
" # CI failed on infrastructure: re-run it (never claude-review); then resume-ci once green:",
|
|
361
366
|
" epic-implementer rerun-ci --epic-run-id 3f9c2b7e-... --ticket-key PROJ-852 --binding <token>",
|
|
362
|
-
" # A child parked on a named plan failure (see
|
|
367
|
+
" # A child parked on a named plan failure (see the `explain_run` MCP tool, not a CLI verb, for the route and reason):",
|
|
363
368
|
" epic-implementer regenerate-plan --epic-run-id 3f9c2b7e-... --ticket-key PROJ-852 \\",
|
|
364
369
|
" --route implementation --reason \"The test plan named a target that is not indexed\"",
|
|
365
370
|
" # The owner accepted the risk of a step a worker could not verify (verification incomplete):",
|