@bridge_gpt/mcp-server 0.2.72 → 0.2.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/build/agent-launchers/claude-executor-adapter.js +3 -0
- package/build/agents.generated.js +6 -6
- package/build/bridge-permissions.js +27 -0
- package/build/ci-system-detection.js +50 -0
- package/build/ci-trigger-adapters.js +631 -0
- package/build/ci-trigger-install.js +106 -0
- package/build/codex-launcher-pin.js +33 -2
- package/build/codex-skill-adapter.js +3 -1
- package/build/command-host.js +33 -0
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +842 -35
- package/build/conductor/bring-up-facts.js +18 -5
- package/build/conductor/command-drift-production.js +42 -17
- package/build/conductor/command-drift.js +47 -0
- package/build/conductor/declare-blocked.js +554 -0
- package/build/conductor/doctor.js +106 -21
- package/build/conductor/driver-commands.js +141 -0
- package/build/conductor/driver-guard.js +277 -0
- package/build/conductor/driver-lapse.js +321 -0
- package/build/conductor/driver-register.js +176 -0
- package/build/conductor/driver-release.js +174 -0
- package/build/conductor/driver-session-state.js +315 -0
- package/build/conductor/epic-branch-ci-inspection.js +222 -29
- package/build/conductor/epic-implementer-cli.js +166 -15
- package/build/conductor/epic-server-database.js +162 -0
- package/build/conductor/epic-server-guidance.js +278 -0
- package/build/conductor/epic-server-journal.js +239 -0
- package/build/conductor/epic-server-processes.js +324 -0
- package/build/conductor/epic-server-recipe.js +397 -0
- package/build/conductor/epic-server-runtime.js +1207 -0
- package/build/conductor/epic-server-sfcc.js +107 -0
- package/build/conductor/epic-server-state.js +427 -0
- package/build/conductor/epic-server.js +594 -0
- package/build/conductor/gate-discovery.js +150 -5
- package/build/conductor/gate-settings-review.js +224 -4
- package/build/conductor/launch-need-probes.js +6 -53
- package/build/conductor/launch-plan.js +313 -156
- package/build/conductor/prerequisite-inputs.js +879 -45
- package/build/conductor/readiness-assessment.js +16 -1
- package/build/conductor/readiness-cli.js +20 -9
- package/build/conductor/readiness-prerequisites.js +28 -9
- package/build/conductor/readiness-sections.js +133 -126
- package/build/conductor/readiness.js +1 -1
- package/build/conductor/recovery-cli.js +13 -2
- package/build/conductor/tools.js +6 -5
- package/build/conductor/wait-run-attention.js +2 -2
- package/build/conductor/wait-run-cli.js +208 -22
- package/build/conductor/worker-database-doctor-inspector.js +33 -2
- package/build/conductor/worker-setup-tally.js +27 -0
- package/build/credential-store.js +71 -1
- package/build/dependency-install-declarations.js +55 -0
- package/build/docs.generated.js +2 -2
- package/build/doctor.js +54 -3
- package/build/drive-epic-help.js +21 -2
- package/build/drive-epic.js +1811 -351
- package/build/engine-paths.js +20 -0
- package/build/epic-branch-ci-summary.js +140 -0
- package/build/epic-capability-statement.js +107 -0
- package/build/epic-ci-workflow-drift.js +30 -15
- package/build/epic-ci-workflow-install.js +110 -42
- package/build/epic-ci-workflow-v2.js +274 -0
- package/build/epic-ci-workflow.js +38 -12
- package/build/epic-implementer-bin.js +2101 -44
- package/build/epic-launch-context.js +607 -0
- package/build/epic-server-record.js +273 -0
- package/build/epic-shared/bridge-client.js +11 -3
- package/build/escalation-reachability.js +43 -0
- package/build/executor/ci-fix-test-runs.js +334 -0
- package/build/executor/completion-contract.js +8 -1
- package/build/executor/env.js +59 -22
- package/build/executor/epic-server-context.js +141 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/http-client.js +52 -5
- package/build/executor/job-runner.js +423 -69
- package/build/executor/observation.js +8 -0
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +114 -2
- package/build/executor/reconcile-overlap-job.js +5 -3
- package/build/executor/required-work-diagnostics.js +4 -2
- package/build/executor/required-work-ledger.js +936 -38
- package/build/executor/results.js +58 -0
- package/build/executor/terminal-mutation.js +8 -0
- package/build/executor/worker-command.js +72 -3
- package/build/executor/worker-database-config.js +281 -0
- package/build/executor/worker-database-target.js +16 -12
- package/build/executor/worker-database.js +320 -101
- package/build/executor/worker-finalization.js +7 -1
- package/build/executor/worker-resources.js +25 -3
- package/build/executor/worker-verification-guidance.js +18 -3
- package/build/executor/worktree.js +20 -1
- package/build/executor-launch.js +54 -2
- package/build/generated-assets-catalog.js +2 -2
- package/build/index.js +664 -335
- package/build/init.js +26 -11
- package/build/install-bridge-conductor-answers.js +465 -0
- package/build/install-bridge-conductor-apply.js +259 -0
- package/build/install-bridge-conductor-assessment.js +895 -0
- package/build/install-bridge-conductor-compact.js +161 -0
- package/build/install-bridge-conductor-contracts.js +63 -0
- package/build/install-bridge-conductor-gate.js +1197 -196
- package/build/install-bridge-conductor-setup.js +535 -79
- package/build/install-bridge-conductor.js +2885 -560
- package/build/install-bridge.js +199 -21
- package/build/install-maintenance.js +26 -3
- package/build/launcher-config-inspection.js +162 -1
- package/build/mcp-grant-candidates.js +767 -0
- package/build/mcp-grant-doctor.js +63 -0
- package/build/mcp-grant.js +288 -0
- package/build/mcp-host-targets.js +8 -0
- package/build/mcp-identity.js +23 -0
- package/build/mcp-invoke.js +126 -13
- package/build/mcp-presets.js +107 -0
- package/build/mcp-provisioning.js +134 -2
- package/build/mcp-registration-doctor.js +31 -2
- package/build/mcp-server-invocation.js +6 -1
- package/build/merge-workflow-install.js +234 -109
- package/build/pipelines.generated.js +5 -5
- package/build/plan-discovery.js +97 -4
- package/build/plan-execution-ledger.js +100 -7
- package/build/plan-generation-io.js +262 -0
- package/build/plan-generation.js +424 -0
- package/build/plane/build-freshness.js +6 -1
- package/build/plane/cli.js +75 -9
- package/build/plane/plane-freshness.js +17 -0
- package/build/plane/preflight.js +50 -10
- package/build/plane/shutdown.js +19 -0
- package/build/plane/terminal-run-cleanup.js +18 -4
- package/build/printed-remedy-commands.js +206 -12
- package/build/readiness-check.js +77 -0
- package/build/readiness-prerequisites.generated.js +122 -14
- package/build/readme.generated.js +1 -1
- package/build/repository-state-paths.js +38 -0
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-epic.js +1190 -196
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +122 -4
- package/build/third-party-mcp-targets.js +30 -0
- package/build/ticket-delivery-enrollment.js +9 -0
- package/build/upgrade-cli.js +85 -2
- package/build/v2-readiness-requirements.js +28 -1
- package/build/version.generated.js +3 -3
- package/docs/EPIC-IMPLEMENTER-INSTALL.md +9 -1
- package/docs/epic-implementer/getting-started.md +3 -1
- package/docs/epic-implementer/self-hosting.md +14 -1
- package/package.json +2 -2
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `epic-implementer declare-blocked` — the `/drive-epic-run` blocker check
|
|
3
|
+
* (BAPI-1642).
|
|
4
|
+
*
|
|
5
|
+
* declare-blocked --epic-run-id <id> --ticket-key <K> [--ticket-key <K> ...]
|
|
6
|
+
* --entry 1|2|3|4|5|wedge --requirement <text> [--evidence <text>]
|
|
7
|
+
* [--tried <verbs>] [--alternatives <text>] [--fixer-outcome <text>] [--json]
|
|
8
|
+
*
|
|
9
|
+
* ADVISORY ONLY. It never refuses without a next step and never releases the
|
|
10
|
+
* session; the Stop-hook guard never reads its receipts. Each named ticket is
|
|
11
|
+
* classified on its own, against `explain_run`'s guided action:
|
|
12
|
+
*
|
|
13
|
+
* not a blocker yet an `eligible` command, or a `conditional` one whose
|
|
14
|
+
* prerequisite is not the one being declared missing, that
|
|
15
|
+
* the driver has not tried with the same input. Prints the
|
|
16
|
+
* command to run. A wedge missing any of its four evidence
|
|
17
|
+
* items also lands here, naming what is missing.
|
|
18
|
+
* accepted otherwise: one escalation per ticket through the existing
|
|
19
|
+
* route (entries 1-5 -> stop_destructive, stop_outside_sandbox,
|
|
20
|
+
* stop_credential, stop_budget_spend, correctness_threat;
|
|
21
|
+
* wedge -> wedge, an FYI and not a sixth stop category).
|
|
22
|
+
* scope unknown an unreadable explanation, an escalate 422, or a
|
|
23
|
+
* truncated `blocks`. Never an acceptance by default.
|
|
24
|
+
* escalation failed the class, a closed reason, and the exact retry command.
|
|
25
|
+
*
|
|
26
|
+
* COVERAGE is the server's: the union of each response's `blocks` (its
|
|
27
|
+
* transitive dependents over the approved plan) plus the accepted tickets. It is
|
|
28
|
+
* never recomputed here. When non-terminal tickets remain outside it, supervision
|
|
29
|
+
* continues for them; when none do, the run is "run-wide blocked", a reporting
|
|
30
|
+
* class only: the driver keeps its normal waiter and every sanctioned action
|
|
31
|
+
* stays available.
|
|
32
|
+
*
|
|
33
|
+
* RECORDS. One closed-valued tally line and one 0600 receipt per ticket under
|
|
34
|
+
* `<KEY>/`. The bounded `--requirement`/`--evidence` summaries go only to the
|
|
35
|
+
* receipt and the escalation's `action_needed`, never to a log line.
|
|
36
|
+
*
|
|
37
|
+
* EXIT CODES. 0 for every completed advisory outcome, including "not a blocker
|
|
38
|
+
* yet"; 1 only when processing was incomplete or an escalation failed. No exit
|
|
39
|
+
* code stops, parks, or pauses the run.
|
|
40
|
+
*/
|
|
41
|
+
import { ConductorBridgeApiError, escalateTicket, fetchExplainRun, resolveConductorBridgeApiAccess, } from "./bridge-api-client.js";
|
|
42
|
+
import { BRIDGE_DEFAULT_LAUNCHER } from "../bridge-permissions.js";
|
|
43
|
+
import { redactSecretString } from "./redaction.js";
|
|
44
|
+
import { renderPlainWaiterCommand, resolveDriverLauncher, shellQuote } from "./driver-commands.js";
|
|
45
|
+
import { deliveryStatusToken } from "./driver-lapse.js";
|
|
46
|
+
import { DRIVER_KEY_PATTERN, DRIVER_RUN_REF_PATTERN, DRIVER_SESSION_ID_PATTERN, DRIVER_STATE_VERSION, appendDriverTallyLine, blockerReceiptPath, currentPointerPath, formatDriverTallyLine, parseCurrentPointer, parseRegistration, readDriverJson, registrationPath, resolveDriverStateRoots, writeDriverJsonAtomic, } from "./driver-session-state.js";
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// Constants
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
export const DECLARE_BLOCKED_ENTRIES = ["1", "2", "3", "4", "5", "wedge"];
|
|
51
|
+
/** Stop-list entry -> the escalate route's cause. */
|
|
52
|
+
export const DECLARE_BLOCKED_CAUSES = {
|
|
53
|
+
"1": "stop_destructive",
|
|
54
|
+
"2": "stop_outside_sandbox",
|
|
55
|
+
"3": "stop_credential",
|
|
56
|
+
"4": "stop_budget_spend",
|
|
57
|
+
"5": "correctness_threat",
|
|
58
|
+
wedge: "wedge",
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* The closed "same prerequisite" mapping: for a declared entry, the guided
|
|
62
|
+
* verbs whose `conditional` prerequisite IS what that entry declares missing,
|
|
63
|
+
* so prescribing them would ask the driver for the very thing it lacks.
|
|
64
|
+
* Entry 4 (authorized spending exhausted): `grant-continuation` extends a
|
|
65
|
+
* spent allowance, which is exactly the budget authority entry 4 says is gone.
|
|
66
|
+
* No other combination is established by server policy, so none is listed;
|
|
67
|
+
* an unlisted conditional verb is prescribed, never accepted by default.
|
|
68
|
+
*/
|
|
69
|
+
export const CONDITIONAL_PREREQUISITE_VERBS = {
|
|
70
|
+
"4": new Set(["grant-continuation"]),
|
|
71
|
+
};
|
|
72
|
+
/** `ActionEligibility` (`api/models/explain_run.py`). A command exists only for the first two. */
|
|
73
|
+
const COMMAND_ELIGIBILITIES = new Set(["eligible", "conditional"]);
|
|
74
|
+
const ALL_ELIGIBILITIES = new Set([
|
|
75
|
+
"eligible", "conditional", "no_safe_action", "unavailable", "not_applicable",
|
|
76
|
+
]);
|
|
77
|
+
const TERMINAL_TICKET_STATUSES = new Set(["done", "abandoned"]);
|
|
78
|
+
export const DECLARE_BLOCKED_LIMITS = {
|
|
79
|
+
requirement: 200,
|
|
80
|
+
evidence: 400,
|
|
81
|
+
tried: 200,
|
|
82
|
+
alternatives: 300,
|
|
83
|
+
fixerOutcome: 300,
|
|
84
|
+
tickets: 20,
|
|
85
|
+
};
|
|
86
|
+
const ACTION_NEEDED_MAX_CHARS = 300;
|
|
87
|
+
export class DeclareBlockedUsageError extends Error {
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Bound and screen one factual summary. Control characters, over-long text,
|
|
91
|
+
* and anything the shared redactor would change (a credential shape) are
|
|
92
|
+
* refused, and the rejected text is never echoed.
|
|
93
|
+
*/
|
|
94
|
+
export function screenSummary(flag, value, max) {
|
|
95
|
+
const trimmed = value.trim();
|
|
96
|
+
if (trimmed.length > max)
|
|
97
|
+
throw new DeclareBlockedUsageError(`Flag "${flag}" is longer than ${max} characters.`);
|
|
98
|
+
// eslint-disable-next-line no-control-regex
|
|
99
|
+
if (/[\u0000-\u001f\u007f-\u009f]/.test(trimmed)) {
|
|
100
|
+
throw new DeclareBlockedUsageError(`Flag "${flag}" must be one line of plain text.`);
|
|
101
|
+
}
|
|
102
|
+
if (redactSecretString(trimmed) !== trimmed) {
|
|
103
|
+
throw new DeclareBlockedUsageError(`Flag "${flag}" looks like it contains a credential; describe it instead.`);
|
|
104
|
+
}
|
|
105
|
+
return trimmed;
|
|
106
|
+
}
|
|
107
|
+
export function getDeclareBlockedUsage() {
|
|
108
|
+
return [
|
|
109
|
+
"Usage: epic-implementer declare-blocked --epic-run-id <id> --ticket-key <K> [--ticket-key <K> ...]",
|
|
110
|
+
" --entry 1|2|3|4|5|wedge --requirement <text> [--evidence <text>] [--tried <verbs>]",
|
|
111
|
+
" [--alternatives <text>] [--fixer-outcome <text>] [--json]",
|
|
112
|
+
"",
|
|
113
|
+
"Check a blocker against the /drive-epic-run criteria. Advisory: it always prints a next step,",
|
|
114
|
+
"never releases supervision, and never stops, parks, or pauses the run. Each ticket gets one of:",
|
|
115
|
+
" not a blocker yet: run <command> a guided verb is still available",
|
|
116
|
+
" accepted for <keys>, escalated escalated through the existing route; supervision continues",
|
|
117
|
+
" run-wide blocked, escalated nothing can progress; keep the normal waiter running",
|
|
118
|
+
" scope unknown supervision continues",
|
|
119
|
+
"--entry wedge needs --evidence, --tried, --alternatives and --fixer-outcome.",
|
|
120
|
+
].join("\n");
|
|
121
|
+
}
|
|
122
|
+
const VALUE_FLAGS = new Set([
|
|
123
|
+
"--epic-run-id", "--ticket-key", "--entry", "--requirement", "--evidence", "--tried",
|
|
124
|
+
"--alternatives", "--fixer-outcome",
|
|
125
|
+
]);
|
|
126
|
+
export function parseDeclareBlockedArgs(argv) {
|
|
127
|
+
const values = new Map();
|
|
128
|
+
const tickets = [];
|
|
129
|
+
let json = false;
|
|
130
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
131
|
+
const token = argv[i];
|
|
132
|
+
if (token === "--help" || token === "-h")
|
|
133
|
+
return { help: true };
|
|
134
|
+
if (token === "--json") {
|
|
135
|
+
json = true;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const eq = token.indexOf("=");
|
|
139
|
+
const name = eq >= 0 ? token.slice(0, eq) : token;
|
|
140
|
+
if (!VALUE_FLAGS.has(name)) {
|
|
141
|
+
throw new DeclareBlockedUsageError('Unknown declare-blocked option. Run "epic-implementer declare-blocked --help".');
|
|
142
|
+
}
|
|
143
|
+
const value = eq >= 0 ? token.slice(eq + 1) : argv[++i];
|
|
144
|
+
if (value === undefined)
|
|
145
|
+
throw new DeclareBlockedUsageError(`Flag "${name}" requires a value.`);
|
|
146
|
+
if (name === "--ticket-key")
|
|
147
|
+
tickets.push(value.trim());
|
|
148
|
+
else if (values.has(name))
|
|
149
|
+
throw new DeclareBlockedUsageError(`Flag "${name}" may be given once.`);
|
|
150
|
+
else
|
|
151
|
+
values.set(name, value);
|
|
152
|
+
}
|
|
153
|
+
const epicRunId = values.get("--epic-run-id")?.trim() ?? "";
|
|
154
|
+
if (!DRIVER_RUN_REF_PATTERN.test(epicRunId)) {
|
|
155
|
+
throw new DeclareBlockedUsageError('Flag "--epic-run-id" is required and must be a run id or epic key.');
|
|
156
|
+
}
|
|
157
|
+
if (tickets.length === 0 || tickets.length > DECLARE_BLOCKED_LIMITS.tickets ||
|
|
158
|
+
tickets.some((key) => !DRIVER_KEY_PATTERN.test(key))) {
|
|
159
|
+
throw new DeclareBlockedUsageError(`Give 1 to ${DECLARE_BLOCKED_LIMITS.tickets} --ticket-key values, each a ticket key such as PROJ-12.`);
|
|
160
|
+
}
|
|
161
|
+
const entry = values.get("--entry")?.trim();
|
|
162
|
+
if (!entry || !DECLARE_BLOCKED_ENTRIES.includes(entry)) {
|
|
163
|
+
throw new DeclareBlockedUsageError('Flag "--entry" must be 1, 2, 3, 4, 5, or wedge.');
|
|
164
|
+
}
|
|
165
|
+
const requirement = screenSummary("--requirement", values.get("--requirement") ?? "", DECLARE_BLOCKED_LIMITS.requirement);
|
|
166
|
+
if (requirement.length === 0) {
|
|
167
|
+
throw new DeclareBlockedUsageError('Flag "--requirement" is required: say what is needed to unblock.');
|
|
168
|
+
}
|
|
169
|
+
const alternatives = screenSummary("--alternatives", values.get("--alternatives") ?? "", DECLARE_BLOCKED_LIMITS.alternatives);
|
|
170
|
+
const fixerOutcome = screenSummary("--fixer-outcome", values.get("--fixer-outcome") ?? "", DECLARE_BLOCKED_LIMITS.fixerOutcome);
|
|
171
|
+
if (entry !== "wedge" && (alternatives || fixerOutcome)) {
|
|
172
|
+
throw new DeclareBlockedUsageError('Flags "--alternatives" and "--fixer-outcome" apply only to --entry wedge.');
|
|
173
|
+
}
|
|
174
|
+
const triedText = screenSummary("--tried", values.get("--tried") ?? "", DECLARE_BLOCKED_LIMITS.tried);
|
|
175
|
+
return {
|
|
176
|
+
epicRunId,
|
|
177
|
+
ticketKeys: [...new Set(tickets)],
|
|
178
|
+
entry: entry,
|
|
179
|
+
requirement,
|
|
180
|
+
evidence: screenSummary("--evidence", values.get("--evidence") ?? "", DECLARE_BLOCKED_LIMITS.evidence),
|
|
181
|
+
tried: triedText.split(/[\s,]+/).map((verb) => verb.trim()).filter((verb) => verb.length > 0),
|
|
182
|
+
triedText,
|
|
183
|
+
alternatives,
|
|
184
|
+
fixerOutcome,
|
|
185
|
+
json,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/** The wedge's four evidence items, named when missing. */
|
|
189
|
+
export function missingWedgeEvidence(args) {
|
|
190
|
+
const missing = [];
|
|
191
|
+
if (!args.evidence)
|
|
192
|
+
missing.push("current failure evidence (--evidence)");
|
|
193
|
+
if (args.tried.length === 0)
|
|
194
|
+
missing.push("the attempts made and their outcomes (--tried)");
|
|
195
|
+
if (!args.alternatives)
|
|
196
|
+
missing.push("why the remaining guided alternatives cannot work (--alternatives)");
|
|
197
|
+
if (!args.fixerOutcome)
|
|
198
|
+
missing.push("a bounded unblocker or fixer outcome, or proof they cannot run (--fixer-outcome)");
|
|
199
|
+
return missing;
|
|
200
|
+
}
|
|
201
|
+
function parseNextAction(value) {
|
|
202
|
+
if (value === null)
|
|
203
|
+
return null;
|
|
204
|
+
if (value === undefined || typeof value !== "object" || Array.isArray(value))
|
|
205
|
+
return "malformed";
|
|
206
|
+
const v = value;
|
|
207
|
+
if (typeof v.eligibility !== "string")
|
|
208
|
+
return "malformed";
|
|
209
|
+
return {
|
|
210
|
+
eligibility: v.eligibility,
|
|
211
|
+
verb: typeof v.verb === "string" && v.verb.length > 0 ? v.verb : null,
|
|
212
|
+
command: typeof v.command === "string" && v.command.length > 0 ? v.command : null,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Classify one ticket's guided action. `lastGuidedCommand` is the full command
|
|
217
|
+
* this ticket's previous receipt recorded: a `--tried` verb counts as exhausted
|
|
218
|
+
* only when that exact command (every binding included) is what is guided now.
|
|
219
|
+
*/
|
|
220
|
+
export function classifyTicket(nextAction, entry, tried, lastGuidedCommand) {
|
|
221
|
+
const action = parseNextAction(nextAction);
|
|
222
|
+
if (action === "malformed")
|
|
223
|
+
return { kind: "scope_unknown", reason: "next_action_unreadable" };
|
|
224
|
+
if (action === null)
|
|
225
|
+
return { kind: "accept", guidedCommand: null };
|
|
226
|
+
if (!ALL_ELIGIBILITIES.has(action.eligibility))
|
|
227
|
+
return { kind: "scope_unknown", reason: "eligibility_unknown" };
|
|
228
|
+
if (!COMMAND_ELIGIBILITIES.has(action.eligibility) || !action.command || !action.verb) {
|
|
229
|
+
return { kind: "accept", guidedCommand: null };
|
|
230
|
+
}
|
|
231
|
+
if (action.eligibility === "conditional" && CONDITIONAL_PREREQUISITE_VERBS[entry]?.has(action.verb)) {
|
|
232
|
+
return { kind: "accept", guidedCommand: action.command };
|
|
233
|
+
}
|
|
234
|
+
const exhausted = tried.includes(action.verb) && lastGuidedCommand === action.command;
|
|
235
|
+
return exhausted
|
|
236
|
+
? { kind: "accept", guidedCommand: action.command }
|
|
237
|
+
: { kind: "not_a_blocker_yet", command: action.command, missing: [] };
|
|
238
|
+
}
|
|
239
|
+
/** Compose `action_needed` within the route's 300 characters, trimming evidence first. */
|
|
240
|
+
export function composeActionNeeded(args) {
|
|
241
|
+
const cause = DECLARE_BLOCKED_CAUSES[args.entry];
|
|
242
|
+
const fit = (text, room) => room <= 1 ? "" : text.length <= room ? text : `${text.slice(0, room - 1)}…`;
|
|
243
|
+
const head = `declare-blocked entry ${args.entry} (${cause}): needs ${args.requirement}.`;
|
|
244
|
+
const tried = args.triedText ? ` Tried: ${args.triedText}.` : "";
|
|
245
|
+
let text = fit(head, ACTION_NEEDED_MAX_CHARS);
|
|
246
|
+
const triedPart = fit(tried, ACTION_NEEDED_MAX_CHARS - text.length);
|
|
247
|
+
const evidenceRoom = ACTION_NEEDED_MAX_CHARS - text.length - triedPart.length - " Evidence: .".length;
|
|
248
|
+
if (args.evidence && evidenceRoom > 10)
|
|
249
|
+
text += ` Evidence: ${fit(args.evidence, evidenceRoom)}.`;
|
|
250
|
+
return (text + triedPart).slice(0, ACTION_NEEDED_MAX_CHARS);
|
|
251
|
+
}
|
|
252
|
+
/** The exact command that retries one ticket's declaration. */
|
|
253
|
+
export function renderRetryCommand(launcher, args, ticket) {
|
|
254
|
+
const parts = [
|
|
255
|
+
`${launcher} epic-implementer declare-blocked`,
|
|
256
|
+
`--epic-run-id ${shellQuote(args.epicRunId)}`,
|
|
257
|
+
`--ticket-key ${shellQuote(ticket)}`,
|
|
258
|
+
`--entry ${args.entry}`,
|
|
259
|
+
`--requirement ${shellQuote(args.requirement)}`,
|
|
260
|
+
];
|
|
261
|
+
if (args.evidence)
|
|
262
|
+
parts.push(`--evidence ${shellQuote(args.evidence)}`);
|
|
263
|
+
if (args.triedText)
|
|
264
|
+
parts.push(`--tried ${shellQuote(args.triedText)}`);
|
|
265
|
+
if (args.alternatives)
|
|
266
|
+
parts.push(`--alternatives ${shellQuote(args.alternatives)}`);
|
|
267
|
+
if (args.fixerOutcome)
|
|
268
|
+
parts.push(`--fixer-outcome ${shellQuote(args.fixerOutcome)}`);
|
|
269
|
+
return parts.join(" ");
|
|
270
|
+
}
|
|
271
|
+
function escalationFailureReason(error) {
|
|
272
|
+
if (error instanceof ConductorBridgeApiError) {
|
|
273
|
+
if (error.status === 404)
|
|
274
|
+
return "ticket_not_in_run";
|
|
275
|
+
if (error.status === 401 || error.status === 403)
|
|
276
|
+
return "not_authorized";
|
|
277
|
+
if (error.kind === "timeout")
|
|
278
|
+
return "timeout";
|
|
279
|
+
if (error.kind === "network")
|
|
280
|
+
return "network";
|
|
281
|
+
if (error.status !== undefined && error.status >= 500)
|
|
282
|
+
return "server_error";
|
|
283
|
+
}
|
|
284
|
+
return "escalate_failed";
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Coverage from server facts only: the accepted tickets plus every response's
|
|
288
|
+
* `blocks`. Any truncated `blocks`, unknown outcome, or unknown ticket status
|
|
289
|
+
* makes the scope unknown.
|
|
290
|
+
*/
|
|
291
|
+
export function summarizeCoverage(outcomes, ticketStatuses) {
|
|
292
|
+
const accepted = outcomes.filter((o) => o.class === "accepted");
|
|
293
|
+
if (accepted.length === 0)
|
|
294
|
+
return { class: "none_accepted" };
|
|
295
|
+
const keys = accepted.map((o) => o.ticket);
|
|
296
|
+
if (!ticketStatuses || outcomes.some((o) => o.class === "scope_unknown") ||
|
|
297
|
+
accepted.some((o) => o.response.blocks.truncated)) {
|
|
298
|
+
return { class: "scope_unknown", accepted: keys };
|
|
299
|
+
}
|
|
300
|
+
const covered = new Set(keys);
|
|
301
|
+
for (const o of accepted)
|
|
302
|
+
for (const key of o.response.blocks.tickets)
|
|
303
|
+
covered.add(key);
|
|
304
|
+
let progressing = 0;
|
|
305
|
+
for (const [key, status] of ticketStatuses) {
|
|
306
|
+
if (!TERMINAL_TICKET_STATUSES.has(status) && !covered.has(key))
|
|
307
|
+
progressing += 1;
|
|
308
|
+
}
|
|
309
|
+
return progressing === 0 ? { class: "run_wide", accepted: keys } : { class: "scoped", accepted: keys, progressing };
|
|
310
|
+
}
|
|
311
|
+
async function readLastGuidedCommand(roots, epicKey, ticket) {
|
|
312
|
+
const read = await readDriverJson(blockerReceiptPath(roots, epicKey, ticket)).catch(() => ({ state: "failed" }));
|
|
313
|
+
if (read.state !== "ok" || read.value === null || typeof read.value !== "object")
|
|
314
|
+
return null;
|
|
315
|
+
const command = read.value.guided_command;
|
|
316
|
+
return typeof command === "string" ? command : null;
|
|
317
|
+
}
|
|
318
|
+
/** The waiter to keep: this session's registered one, else the plain watch waiter. */
|
|
319
|
+
async function waiterFor(roots, env, launcher, epicRunId, epicKey) {
|
|
320
|
+
const sessionId = env.CLAUDE_CODE_SESSION_ID?.trim() ?? "";
|
|
321
|
+
if (DRIVER_SESSION_ID_PATTERN.test(sessionId)) {
|
|
322
|
+
const read = await readDriverJson(registrationPath(roots, sessionId)).catch(() => null);
|
|
323
|
+
const registration = read?.state === "ok" ? parseRegistration(read.value) : null;
|
|
324
|
+
if (registration && registration.epic_key === epicKey) {
|
|
325
|
+
const pointer = await readDriverJson(currentPointerPath(roots, epicKey)).catch(() => null);
|
|
326
|
+
const current = pointer?.state === "ok" ? parseCurrentPointer(pointer.value) : null;
|
|
327
|
+
if (current?.generation === registration.generation)
|
|
328
|
+
return registration.waiter_command;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return renderPlainWaiterCommand(launcher, epicRunId);
|
|
332
|
+
}
|
|
333
|
+
/** Run `declare-blocked`. Never throws; returns the exit code. */
|
|
334
|
+
export async function runDeclareBlockedCommand(argv, deps = {}) {
|
|
335
|
+
const env = deps.env ?? process.env;
|
|
336
|
+
const now = deps.now ?? (() => new Date());
|
|
337
|
+
const out = deps.writeStdout ?? ((text) => console.log(text));
|
|
338
|
+
const err = deps.writeStderr ?? ((line) => console.error(line));
|
|
339
|
+
let parsed;
|
|
340
|
+
try {
|
|
341
|
+
parsed = parseDeclareBlockedArgs(argv);
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
err(`Error: ${error instanceof DeclareBlockedUsageError ? error.message : "declare-blocked arguments are invalid."}`);
|
|
345
|
+
return 1;
|
|
346
|
+
}
|
|
347
|
+
if ("help" in parsed) {
|
|
348
|
+
out(getDeclareBlockedUsage());
|
|
349
|
+
return 0;
|
|
350
|
+
}
|
|
351
|
+
const args = parsed;
|
|
352
|
+
const launcher = resolveDriverLauncher(env) ?? BRIDGE_DEFAULT_LAUNCHER;
|
|
353
|
+
const scopeUnknownAll = (reason) => {
|
|
354
|
+
const lines = args.ticketKeys.map((ticket) => `${ticket}: scope unknown (${reason}); supervision continues.`);
|
|
355
|
+
if (args.json)
|
|
356
|
+
out(JSON.stringify({ outcomes: args.ticketKeys.map((ticket) => ({ ticket, class: "scope_unknown", reason })),
|
|
357
|
+
summary: { class: "scope_unknown" } }));
|
|
358
|
+
else
|
|
359
|
+
out([...lines, "Nothing was escalated. Keep the waiter running and supervising every other ticket."].join("\n"));
|
|
360
|
+
return 1;
|
|
361
|
+
};
|
|
362
|
+
let access;
|
|
363
|
+
try {
|
|
364
|
+
access = await (deps.resolveAccess ?? (async () => {
|
|
365
|
+
const resolved = await resolveConductorBridgeApiAccess({ followEpicLaunchProfile: true });
|
|
366
|
+
return resolved.ok ? resolved.access : null;
|
|
367
|
+
}))();
|
|
368
|
+
}
|
|
369
|
+
catch {
|
|
370
|
+
access = null;
|
|
371
|
+
}
|
|
372
|
+
if (!access)
|
|
373
|
+
return scopeUnknownAll("credentials_unavailable");
|
|
374
|
+
const fetchExplain = deps.fetchExplain ?? ((a, id, key) => fetchExplainRun(a, id, key));
|
|
375
|
+
let explain;
|
|
376
|
+
try {
|
|
377
|
+
explain = await fetchExplain(access, args.epicRunId);
|
|
378
|
+
}
|
|
379
|
+
catch {
|
|
380
|
+
return scopeUnknownAll("explain_unreadable");
|
|
381
|
+
}
|
|
382
|
+
const runPayload = explain;
|
|
383
|
+
const run = runPayload?.run;
|
|
384
|
+
const epicKey = run?.epic_key;
|
|
385
|
+
const epicRunId = run?.epic_run_id;
|
|
386
|
+
if (!run || typeof epicKey !== "string" || !DRIVER_KEY_PATTERN.test(epicKey) ||
|
|
387
|
+
typeof epicRunId !== "string" || !Array.isArray(runPayload?.tickets)) {
|
|
388
|
+
return scopeUnknownAll("explain_unreadable");
|
|
389
|
+
}
|
|
390
|
+
const tickets = new Map();
|
|
391
|
+
const statuses = new Map();
|
|
392
|
+
let statusesKnown = true;
|
|
393
|
+
for (const t of runPayload.tickets) {
|
|
394
|
+
if (t === null || typeof t !== "object") {
|
|
395
|
+
statusesKnown = false;
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
const ticket = t;
|
|
399
|
+
if (typeof ticket.ticket_key !== "string") {
|
|
400
|
+
statusesKnown = false;
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
tickets.set(ticket.ticket_key, ticket);
|
|
404
|
+
if (typeof ticket.ticket_status === "string")
|
|
405
|
+
statuses.set(ticket.ticket_key, ticket.ticket_status);
|
|
406
|
+
else
|
|
407
|
+
statusesKnown = false;
|
|
408
|
+
}
|
|
409
|
+
const roots = resolveDriverStateRoots(deps.homeDir);
|
|
410
|
+
const outcomes = [];
|
|
411
|
+
const guided = new Map();
|
|
412
|
+
for (const ticket of args.ticketKeys) {
|
|
413
|
+
try {
|
|
414
|
+
const entryTicket = tickets.get(ticket);
|
|
415
|
+
if (!entryTicket) {
|
|
416
|
+
outcomes.push({ ticket, class: "scope_unknown", reason: "ticket_not_in_run" });
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
if (args.entry === "wedge") {
|
|
420
|
+
const missing = missingWedgeEvidence(args);
|
|
421
|
+
if (missing.length > 0) {
|
|
422
|
+
outcomes.push({ ticket, class: "not_a_blocker_yet", command: null, missing });
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
let nextAction = entryTicket.next_action;
|
|
427
|
+
if (!("next_action" in entryTicket)) {
|
|
428
|
+
try {
|
|
429
|
+
const one = await fetchExplain(access, epicRunId, ticket);
|
|
430
|
+
nextAction = one?.ticket && "next_action" in one.ticket ? one.ticket.next_action : undefined;
|
|
431
|
+
}
|
|
432
|
+
catch {
|
|
433
|
+
nextAction = undefined;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
const classification = classifyTicket(nextAction, args.entry, args.tried, await readLastGuidedCommand(roots, epicKey, ticket));
|
|
437
|
+
if (classification.kind === "scope_unknown") {
|
|
438
|
+
outcomes.push({ ticket, class: "scope_unknown", reason: classification.reason });
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
if (classification.kind === "not_a_blocker_yet") {
|
|
442
|
+
guided.set(ticket, classification.command);
|
|
443
|
+
outcomes.push({ ticket, class: "not_a_blocker_yet", command: classification.command, missing: [] });
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
guided.set(ticket, classification.guidedCommand);
|
|
447
|
+
try {
|
|
448
|
+
const response = await (deps.escalate ?? escalateTicket)(access, {
|
|
449
|
+
epicRunId, ticketKey: ticket, cause: DECLARE_BLOCKED_CAUSES[args.entry], actionNeeded: composeActionNeeded(args),
|
|
450
|
+
});
|
|
451
|
+
outcomes.push({ ticket, class: "accepted", response });
|
|
452
|
+
}
|
|
453
|
+
catch (error) {
|
|
454
|
+
if (error instanceof ConductorBridgeApiError && error.status === 422) {
|
|
455
|
+
outcomes.push({ ticket, class: "scope_unknown", reason: "escalate_422" });
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
outcomes.push({ ticket, class: "escalation_failed", reason: escalationFailureReason(error),
|
|
459
|
+
retry: renderRetryCommand(launcher, args, ticket) });
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
catch {
|
|
464
|
+
outcomes.push({ ticket, class: "scope_unknown", reason: "processing_failed" });
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
// Records: one receipt and one closed-valued tally line per ticket. A failed
|
|
468
|
+
// write is reported, never fatal to the advice already computed.
|
|
469
|
+
let recordsFailed = false;
|
|
470
|
+
for (const outcome of outcomes) {
|
|
471
|
+
const accepted = outcome.class === "accepted" ? outcome.response : null;
|
|
472
|
+
const receipt = {
|
|
473
|
+
version: DRIVER_STATE_VERSION,
|
|
474
|
+
ticket_key: outcome.ticket,
|
|
475
|
+
class: outcome.class,
|
|
476
|
+
entry: args.entry,
|
|
477
|
+
guided_command: guided.get(outcome.ticket) ?? null,
|
|
478
|
+
notification_id: accepted?.notification_id ?? null,
|
|
479
|
+
delivery_status: accepted?.delivery_status ?? null,
|
|
480
|
+
requirement: args.requirement,
|
|
481
|
+
evidence: args.evidence,
|
|
482
|
+
tried: args.triedText,
|
|
483
|
+
at: now().toISOString(),
|
|
484
|
+
};
|
|
485
|
+
const fields = { ticket: outcome.ticket, class: outcome.class, entry: args.entry };
|
|
486
|
+
if (accepted) {
|
|
487
|
+
fields.notification_id = accepted.notification_id;
|
|
488
|
+
fields.delivery_status = deliveryStatusToken(accepted.delivery_status);
|
|
489
|
+
}
|
|
490
|
+
if (outcome.class === "scope_unknown" || outcome.class === "escalation_failed")
|
|
491
|
+
fields.reason = outcome.reason;
|
|
492
|
+
try {
|
|
493
|
+
await writeDriverJsonAtomic(blockerReceiptPath(roots, epicKey, outcome.ticket), receipt);
|
|
494
|
+
await appendDriverTallyLine(roots, epicKey, formatDriverTallyLine("declare-blocked", fields, now()));
|
|
495
|
+
}
|
|
496
|
+
catch {
|
|
497
|
+
recordsFailed = true;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
const summary = summarizeCoverage(outcomes, statusesKnown ? statuses : null);
|
|
501
|
+
const waiter = await waiterFor(roots, env, launcher, epicRunId, epicKey).catch(() => "");
|
|
502
|
+
const lines = [];
|
|
503
|
+
for (const o of outcomes) {
|
|
504
|
+
if (o.class === "not_a_blocker_yet") {
|
|
505
|
+
lines.push(o.command
|
|
506
|
+
? `${o.ticket}: not a blocker yet: run ${o.command}`
|
|
507
|
+
: `${o.ticket}: not a blocker yet: a wedge needs ${o.missing.join("; ")}. Gather it, then declare again.`);
|
|
508
|
+
}
|
|
509
|
+
else if (o.class === "accepted") {
|
|
510
|
+
lines.push(`${o.ticket}: accepted, escalated (${DECLARE_BLOCKED_CAUSES[args.entry]}; notification ` +
|
|
511
|
+
`${o.response.notification_id}; delivery ${o.response.delivery_status}; ${o.response.blocker_enforcement}).`);
|
|
512
|
+
}
|
|
513
|
+
else if (o.class === "scope_unknown") {
|
|
514
|
+
lines.push(`${o.ticket}: scope unknown (${o.reason}); supervision continues.`);
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
lines.push(`${o.ticket}: escalation failed (${o.reason}); not escalated. Retry: ${o.retry}`);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
if (summary.class === "scoped") {
|
|
521
|
+
lines.push(`accepted for ${summary.accepted.join(", ")}, escalated; supervision continues: ` +
|
|
522
|
+
`${summary.progressing} ticket${summary.progressing === 1 ? "" : "s"} can still progress.`);
|
|
523
|
+
}
|
|
524
|
+
else if (summary.class === "run_wide") {
|
|
525
|
+
lines.push(`run-wide blocked, escalated; keep watching with the normal waiter: ${waiter}`);
|
|
526
|
+
}
|
|
527
|
+
else if (summary.class === "scope_unknown") {
|
|
528
|
+
lines.push(`accepted for ${summary.accepted.join(", ")}, escalated; scope unknown; supervision continues.`);
|
|
529
|
+
}
|
|
530
|
+
if (args.entry === "wedge" && summary.class !== "none_accepted") {
|
|
531
|
+
lines.push("A wedge is an FYI for the named tickets, not a stop and not a release.");
|
|
532
|
+
}
|
|
533
|
+
lines.push("This check never releases supervision. Keep the waiter running" + (waiter ? `: ${waiter}` : "."));
|
|
534
|
+
if (recordsFailed)
|
|
535
|
+
lines.push("Warning: a receipt or tally line could not be written.");
|
|
536
|
+
if (args.json) {
|
|
537
|
+
out(JSON.stringify({
|
|
538
|
+
epic_key: epicKey,
|
|
539
|
+
outcomes: outcomes.map((o) => o.class === "accepted"
|
|
540
|
+
? { ticket: o.ticket, class: o.class, notification_id: o.response.notification_id,
|
|
541
|
+
delivery_status: o.response.delivery_status, blocks: o.response.blocks,
|
|
542
|
+
blocker_enforcement: o.response.blocker_enforcement }
|
|
543
|
+
: o),
|
|
544
|
+
summary,
|
|
545
|
+
waiter_command: waiter || null,
|
|
546
|
+
}));
|
|
547
|
+
}
|
|
548
|
+
else {
|
|
549
|
+
out(lines.join("\n"));
|
|
550
|
+
}
|
|
551
|
+
const incomplete = outcomes.some((o) => o.class === "escalation_failed" ||
|
|
552
|
+
(o.class === "scope_unknown" && o.reason === "processing_failed"));
|
|
553
|
+
return incomplete ? 1 : 0;
|
|
554
|
+
}
|