@bridge_gpt/mcp-server 0.2.74 → 0.2.75
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 +14 -7
- package/build/agent-launchers/prompt.js +9 -21
- package/build/agents.generated.js +2 -2
- package/build/authored-plan.js +542 -0
- package/build/bridge-permissions.js +8 -0
- package/build/commands.generated.js +5 -5
- package/build/conductor/bridge-api-client.js +666 -46
- package/build/conductor/epic-implementer-cli.js +337 -93
- package/build/conductor/gate-discovery.js +209 -9
- package/build/conductor/gate-settings-review.js +7 -11
- package/build/conductor/launch-plan.js +58 -12
- package/build/conductor/open-decision-phrases.js +50 -0
- package/build/conductor/prerequisite-inputs.js +181 -14
- package/build/connect-github-api.js +18 -0
- package/build/connect-github.js +35 -18
- package/build/docs.generated.js +2 -2
- package/build/drive-epic.js +387 -12
- package/build/epic-ci-workflow.js +3 -2
- package/build/epic-implementer-bin.js +152 -38
- package/build/epic-implementer-bundle-cli.js +61 -0
- package/build/epic-implementer-claude-hook-bin.js +1 -1
- package/build/epic-implementer-env.js +3 -4
- package/build/epic-integration-pr.js +5 -2
- package/build/executor/completion-contract.js +24 -1
- package/build/executor/gate-qualification-job.js +193 -23
- package/build/executor/gate-qualification-tests-ran.js +232 -0
- package/build/executor/job-runner.js +9 -722
- package/build/executor/job-type-wrappers.js +734 -0
- package/build/executor/preflight.js +6 -2
- package/build/executor/process-containment.js +8 -1
- package/build/executor/required-verification.js +28 -2
- package/build/executor/runner.js +4 -1
- package/build/executor/types.js +9 -0
- package/build/executor/worker-database.js +6 -1
- package/build/executor/worker-guard-hook.js +24 -2
- package/build/generated/ticket-status.js +20 -0
- package/build/index.js +391 -257
- package/build/install-bridge-conductor-answers.js +28 -1
- package/build/install-bridge-conductor-apply.js +11 -3
- package/build/install-bridge-conductor-assessment.js +114 -12
- package/build/install-bridge-conductor-compact.js +2 -0
- package/build/install-bridge-conductor-gate.js +257 -80
- package/build/install-bridge-conductor-setup.js +4 -4
- package/build/install-bridge-conductor-trial-report.js +170 -0
- package/build/install-bridge-conductor.js +303 -31
- package/build/pipelines.generated.js +7 -7
- package/build/plan-generation.js +17 -0
- package/build/printed-remedy-commands.js +54 -0
- package/build/readme.generated.js +1 -1
- package/build/repository-toolchains.js +11 -5
- package/build/scripts/saved-commands-config-field-driver.js +65 -0
- package/build/setup-epic.js +10 -1
- package/build/test-support/executor-source-files.js +1 -1
- package/build/v2-readiness-requirements.js +5 -1
- package/build/version.generated.js +3 -3
- package/build/worker-guard-hook-bin.js +2 -2
- package/docs/EPIC-IMPLEMENTER.md +4 -4
- package/docs/install/github-app.md +79 -92
- package/package.json +1 -1
- package/build/conductor/epic-reconcile.js +0 -603
- package/build/conductor/epic-runtime.js +0 -2020
- package/build/conductor/epic-state.js +0 -774
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BAPI-1706: save an epic's authored plan to the normal Bridge server.
|
|
3
|
+
*
|
|
4
|
+
* An authored plan is the folder `/define-tickets` or `/plan-epic` writes under
|
|
5
|
+
* `{docs_dir}/epic-plans/<slug>/`: the DAG (`epic-plan.dag.json`), the identity
|
|
6
|
+
* file (`epic-plan.meta.json`), and two optional side records — the eligibility
|
|
7
|
+
* advisory (`epic-implementer-eligibility.json`, or the legacy
|
|
8
|
+
* `conductor-eligibility.json`) and the gap-check record (`epic-coherence.json`).
|
|
9
|
+
*
|
|
10
|
+
* This module reads that folder as ONE complete snapshot and saves it with
|
|
11
|
+
* `saveAuthoredEpicPlan`. A side record that is genuinely absent (`ENOENT`) is
|
|
12
|
+
* saved as null; a present record that cannot be read or parsed fails the save,
|
|
13
|
+
* because silently dropping it would store a different plan than the author has.
|
|
14
|
+
* A save never inherits a side record from an earlier server version.
|
|
15
|
+
*
|
|
16
|
+
* It is reached three ways:
|
|
17
|
+
*
|
|
18
|
+
* - `epic-plan save --epic-key <KEY>` by hand or from the define-tickets hand-off;
|
|
19
|
+
* - `emit-epic-implementer-bundle finalize`, after the metadata is written;
|
|
20
|
+
* - `drive-epic`, which uploads a local-only plan with `if_absent` on a real launch.
|
|
21
|
+
*
|
|
22
|
+
* Access always comes from the general resolver — never an epic launch profile —
|
|
23
|
+
* so authored plans live on the account's normal Bridge server even when a run
|
|
24
|
+
* later executes on a local control plane.
|
|
25
|
+
*
|
|
26
|
+
* Nothing here prints a credential, a raw exception, a response body, or any
|
|
27
|
+
* value taken from inside the DAG. Failures carry a fixed reason token.
|
|
28
|
+
*/
|
|
29
|
+
import os from "node:os";
|
|
30
|
+
import path from "node:path";
|
|
31
|
+
import { chmod, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
32
|
+
import { getAuthoredEpicPlan, resolveConductorBridgeApiAccess, saveAuthoredEpicPlan, AuthoredEpicPlanSaveError, } from "./conductor/bridge-api-client.js";
|
|
33
|
+
import { hashPlan } from "./conductor/plan.js";
|
|
34
|
+
import { resolveDriverLauncher, shellQuote } from "./conductor/driver-commands.js";
|
|
35
|
+
import { EPIC_KEY_PATTERN } from "./drive-epic-key.js";
|
|
36
|
+
import { discoverEpicPlan } from "./plan-discovery.js";
|
|
37
|
+
import { validateEpicPlanSidecar } from "./setup-epic.js";
|
|
38
|
+
import { MCP_PACKAGE_NAME } from "./mcp-identity.js";
|
|
39
|
+
export const AUTHORED_PLAN_DAG_FILE = "epic-plan.dag.json";
|
|
40
|
+
export const AUTHORED_PLAN_META_FILE = "epic-plan.meta.json";
|
|
41
|
+
export const AUTHORED_PLAN_ELIGIBILITY_FILE = "epic-implementer-eligibility.json";
|
|
42
|
+
export const AUTHORED_PLAN_LEGACY_ELIGIBILITY_FILE = "conductor-eligibility.json";
|
|
43
|
+
export const AUTHORED_PLAN_COHERENCE_FILE = "epic-coherence.json";
|
|
44
|
+
function isEnoent(err) {
|
|
45
|
+
return typeof err === "object" && err !== null && err.code === "ENOENT";
|
|
46
|
+
}
|
|
47
|
+
function isPlainObject(value) {
|
|
48
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
49
|
+
}
|
|
50
|
+
/** Read an optional JSON-object file: only ENOENT is "absent". */
|
|
51
|
+
async function readOptionalRecord(fs, filePath) {
|
|
52
|
+
let raw;
|
|
53
|
+
try {
|
|
54
|
+
raw = await fs.readFile(filePath);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
return isEnoent(err) ? { kind: "absent" } : { kind: "invalid" };
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const parsed = JSON.parse(raw);
|
|
61
|
+
return isPlainObject(parsed) ? { kind: "present", value: parsed } : { kind: "invalid" };
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return { kind: "invalid" };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Read one authored plan folder as a complete snapshot.
|
|
69
|
+
*
|
|
70
|
+
* The metadata must name `epicKey`; the DAG must pass the same
|
|
71
|
+
* `validateEpicPlanSidecar` check `setup-epic` applies; the hash is `hashPlan()`.
|
|
72
|
+
* The eligibility record prefers the current file name and reads the legacy name
|
|
73
|
+
* only when the current one is confirmed absent.
|
|
74
|
+
*/
|
|
75
|
+
export async function readLocalAuthoredPlan(planDir, epicKey, fs) {
|
|
76
|
+
let metaRaw;
|
|
77
|
+
try {
|
|
78
|
+
metaRaw = await fs.readFile(path.join(planDir, AUTHORED_PLAN_META_FILE));
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return { ok: false, reason: "meta_unreadable" };
|
|
82
|
+
}
|
|
83
|
+
let meta;
|
|
84
|
+
try {
|
|
85
|
+
meta = JSON.parse(metaRaw);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return { ok: false, reason: "meta_invalid" };
|
|
89
|
+
}
|
|
90
|
+
if (!isPlainObject(meta) || typeof meta.epic_key !== "string")
|
|
91
|
+
return { ok: false, reason: "meta_invalid" };
|
|
92
|
+
if (meta.epic_key.trim() !== epicKey)
|
|
93
|
+
return { ok: false, reason: "meta_epic_mismatch" };
|
|
94
|
+
const dagPath = path.join(planDir, AUTHORED_PLAN_DAG_FILE);
|
|
95
|
+
let dagRaw;
|
|
96
|
+
try {
|
|
97
|
+
dagRaw = await fs.readFile(dagPath);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return { ok: false, reason: "dag_unreadable" };
|
|
101
|
+
}
|
|
102
|
+
let dagParsed;
|
|
103
|
+
try {
|
|
104
|
+
dagParsed = JSON.parse(dagRaw);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return { ok: false, reason: "dag_invalid" };
|
|
108
|
+
}
|
|
109
|
+
const validation = validateEpicPlanSidecar(dagParsed);
|
|
110
|
+
if (!validation.ok)
|
|
111
|
+
return { ok: false, reason: "dag_invalid" };
|
|
112
|
+
let eligibility = await readOptionalRecord(fs, path.join(planDir, AUTHORED_PLAN_ELIGIBILITY_FILE));
|
|
113
|
+
if (eligibility.kind === "absent") {
|
|
114
|
+
eligibility = await readOptionalRecord(fs, path.join(planDir, AUTHORED_PLAN_LEGACY_ELIGIBILITY_FILE));
|
|
115
|
+
}
|
|
116
|
+
if (eligibility.kind === "invalid")
|
|
117
|
+
return { ok: false, reason: "eligibility_invalid" };
|
|
118
|
+
const coherence = await readOptionalRecord(fs, path.join(planDir, AUTHORED_PLAN_COHERENCE_FILE));
|
|
119
|
+
if (coherence.kind === "invalid")
|
|
120
|
+
return { ok: false, reason: "coherence_invalid" };
|
|
121
|
+
return {
|
|
122
|
+
ok: true,
|
|
123
|
+
snapshot: {
|
|
124
|
+
epicKey,
|
|
125
|
+
planDir,
|
|
126
|
+
dagPath,
|
|
127
|
+
plan: validation.plan,
|
|
128
|
+
planHash: hashPlan(validation.plan),
|
|
129
|
+
eligibilityAdvisory: eligibility.kind === "present" ? eligibility.value : null,
|
|
130
|
+
gapCheckRecord: coherence.kind === "present" ? coherence.value : null,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/** The save request for one local snapshot. */
|
|
135
|
+
export function authoredPlanSaveRequest(snapshot, ifAbsent) {
|
|
136
|
+
return {
|
|
137
|
+
epicKey: snapshot.epicKey,
|
|
138
|
+
planBlob: snapshot.plan,
|
|
139
|
+
planHash: snapshot.planHash,
|
|
140
|
+
eligibilityAdvisory: snapshot.eligibilityAdvisory,
|
|
141
|
+
gapCheckRecord: snapshot.gapCheckRecord,
|
|
142
|
+
ifAbsent,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/** A save failure's fixed reason token. */
|
|
146
|
+
export function authoredPlanSaveFailureReason(err) {
|
|
147
|
+
return err instanceof AuthoredEpicPlanSaveError ? `server_${err.reason}` : "server_unknown";
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* A credential-free rendering of the server endpoint: scheme, host, port, and
|
|
151
|
+
* path only. Anything unparseable, or carrying user info, is not shown.
|
|
152
|
+
*/
|
|
153
|
+
export function displayBridgeEndpoint(baseUrl) {
|
|
154
|
+
try {
|
|
155
|
+
const url = new URL(baseUrl);
|
|
156
|
+
if (url.username || url.password)
|
|
157
|
+
return "(endpoint hidden)";
|
|
158
|
+
const pathname = url.pathname.replace(/\/+$/, "");
|
|
159
|
+
return `${url.protocol}//${url.host}${pathname}`;
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return "(endpoint hidden)";
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/** The exact retry command for a failed save. Operator-supplied values only. */
|
|
166
|
+
export function renderEpicPlanSaveCommand(env, args) {
|
|
167
|
+
const launcher = resolveDriverLauncher(env) ?? `npx -y ${MCP_PACKAGE_NAME}`;
|
|
168
|
+
return [
|
|
169
|
+
`${launcher} epic-plan save --epic-key ${shellQuote(args.epicKey)}`,
|
|
170
|
+
...(args.planDir !== undefined ? [`--plan-dir ${shellQuote(args.planDir)}`] : []),
|
|
171
|
+
...(args.repo !== undefined ? [`--repo ${shellQuote(args.repo)}`] : []),
|
|
172
|
+
].join(" ");
|
|
173
|
+
}
|
|
174
|
+
/** Save the folder at `planDir` for `epicKey`. Never throws. */
|
|
175
|
+
export async function saveLocalAuthoredPlan(deps, input) {
|
|
176
|
+
const retryCommand = renderEpicPlanSaveCommand(deps.env, {
|
|
177
|
+
epicKey: input.epicKey,
|
|
178
|
+
planDir: input.planDir,
|
|
179
|
+
...(input.repo !== undefined ? { repo: input.repo } : {}),
|
|
180
|
+
});
|
|
181
|
+
const fail = (reason) => ({
|
|
182
|
+
ok: false,
|
|
183
|
+
epicKey: input.epicKey,
|
|
184
|
+
reason,
|
|
185
|
+
planDir: input.planDir,
|
|
186
|
+
retryCommand,
|
|
187
|
+
});
|
|
188
|
+
if (!EPIC_KEY_PATTERN.test(input.epicKey))
|
|
189
|
+
return fail("invalid_epic_key");
|
|
190
|
+
try {
|
|
191
|
+
const local = await readLocalAuthoredPlan(input.planDir, input.epicKey, deps.fs);
|
|
192
|
+
if (!local.ok)
|
|
193
|
+
return fail(local.reason);
|
|
194
|
+
const access = await deps.resolveAccess(input.repo);
|
|
195
|
+
if (!access.ok)
|
|
196
|
+
return fail("access_unavailable");
|
|
197
|
+
let result;
|
|
198
|
+
try {
|
|
199
|
+
result = await deps.save(access.access, authoredPlanSaveRequest(local.snapshot, input.ifAbsent === true));
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
return fail(authoredPlanSaveFailureReason(err));
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
ok: true,
|
|
206
|
+
epicKey: input.epicKey,
|
|
207
|
+
planDir: input.planDir,
|
|
208
|
+
endpoint: displayBridgeEndpoint(access.access.baseUrl),
|
|
209
|
+
created: result.created,
|
|
210
|
+
result,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
return fail("server_unknown");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/** The general-resolver access every authored-plan caller uses. */
|
|
218
|
+
export function resolveAuthoredPlanAccess(repo, env) {
|
|
219
|
+
// `followEpicLaunchProfile` stays unset: authored plans live on the normal server.
|
|
220
|
+
// `env` lets drive-epic pass the environment captured BEFORE it adopted a launch
|
|
221
|
+
// target, so a local-plane launch still reads and saves on the normal server.
|
|
222
|
+
return resolveConductorBridgeApiAccess({
|
|
223
|
+
...(env !== undefined ? { env } : {}),
|
|
224
|
+
...(repo !== undefined ? { repoName: repo } : {}),
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
/** The real seams. */
|
|
228
|
+
export function createDefaultAuthoredPlanSaveDeps() {
|
|
229
|
+
return {
|
|
230
|
+
env: process.env,
|
|
231
|
+
fs: { readFile: (filePath) => readFile(filePath, "utf8") },
|
|
232
|
+
resolveAccess: resolveAuthoredPlanAccess,
|
|
233
|
+
save: (access, request) => saveAuthoredEpicPlan(access, request),
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
/** A short, human hash for terminal output; JSON always carries the full hash. */
|
|
237
|
+
export function shortPlanHash(hash) {
|
|
238
|
+
return hash.slice(0, 12);
|
|
239
|
+
}
|
|
240
|
+
/** One-line human summary of a successful save. */
|
|
241
|
+
export function renderAuthoredPlanSaved(outcome) {
|
|
242
|
+
const snap = outcome.result.snapshot;
|
|
243
|
+
const what = outcome.created ? "saved as a new version" : "already stored; the existing version was reused";
|
|
244
|
+
return (`${outcome.epicKey}: plan ${what} — authored version ${snap.authored_version}, ` +
|
|
245
|
+
`hash ${shortPlanHash(snap.plan_hash)}, server ${outcome.endpoint}.`);
|
|
246
|
+
}
|
|
247
|
+
/** The fixed not-saved warning, with the exact retry command. */
|
|
248
|
+
export function renderAuthoredPlanNotSaved(outcome) {
|
|
249
|
+
return [
|
|
250
|
+
`${outcome.epicKey}: the plan was NOT saved to the Bridge server (${outcome.reason}). ` +
|
|
251
|
+
"Local plan files are unchanged.",
|
|
252
|
+
`Retry: ${outcome.retryCommand}`,
|
|
253
|
+
];
|
|
254
|
+
}
|
|
255
|
+
// ---------------------------------------------------------------------------
|
|
256
|
+
// CLI: `epic-plan save --epic-key <KEY> [--plan-dir <dir>] [--repo <repo>] [--json]`
|
|
257
|
+
// ---------------------------------------------------------------------------
|
|
258
|
+
export function getEpicPlanUsage() {
|
|
259
|
+
return [
|
|
260
|
+
"Usage: epic-plan save --epic-key <KEY> [--plan-dir <dir>] [--repo <repo>] [--json]",
|
|
261
|
+
"",
|
|
262
|
+
"Save an epic's authored plan to the Bridge server so anyone with access to the",
|
|
263
|
+
"repository can run it with `drive-epic <KEY>`, with no local plan folder.",
|
|
264
|
+
"",
|
|
265
|
+
" --epic-key <KEY> The epic whose plan to save (must match epic-plan.meta.json).",
|
|
266
|
+
" --plan-dir <dir> The plan folder. Default: the folder under {docs_dir}/epic-plans",
|
|
267
|
+
" whose epic-plan.meta.json names <KEY>.",
|
|
268
|
+
" --repo <repo> Repository override. Default: BAPI_REPO_NAME or .bridge/config.",
|
|
269
|
+
" --json Print one JSON object.",
|
|
270
|
+
"",
|
|
271
|
+
"The DAG, the eligibility advisory, and the gap-check record are saved together.",
|
|
272
|
+
"Saving an unchanged plan again reuses the stored version. A changed plan becomes",
|
|
273
|
+
"a new version; earlier versions are kept, and a run already in progress keeps",
|
|
274
|
+
"the plan it was created with.",
|
|
275
|
+
].join("\n");
|
|
276
|
+
}
|
|
277
|
+
export function parseEpicPlanArgs(argv) {
|
|
278
|
+
if (argv.length === 0 || argv[0] === "--help" || argv[0] === "-h" || argv[0] === "help") {
|
|
279
|
+
return { status: "help" };
|
|
280
|
+
}
|
|
281
|
+
if (argv[0] !== "save")
|
|
282
|
+
return { status: "error", message: `epic-plan: unknown action '${argv[0]}'. Expected 'save'.` };
|
|
283
|
+
let epicKey;
|
|
284
|
+
let planDir;
|
|
285
|
+
let repo;
|
|
286
|
+
let json = false;
|
|
287
|
+
const valueOf = (flag, index) => {
|
|
288
|
+
const value = argv[index + 1];
|
|
289
|
+
if (value === undefined || value.startsWith("--") || value.trim() === "") {
|
|
290
|
+
return { error: `epic-plan save: ${flag} needs a value.` };
|
|
291
|
+
}
|
|
292
|
+
return value;
|
|
293
|
+
};
|
|
294
|
+
for (let i = 1; i < argv.length; i += 1) {
|
|
295
|
+
const arg = argv[i];
|
|
296
|
+
if (arg === "--help" || arg === "-h")
|
|
297
|
+
return { status: "help" };
|
|
298
|
+
if (arg === "--json") {
|
|
299
|
+
json = true;
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
if (arg === "--epic-key" || arg === "--plan-dir" || arg === "--repo") {
|
|
303
|
+
const value = valueOf(arg, i);
|
|
304
|
+
if (typeof value !== "string")
|
|
305
|
+
return { status: "error", message: value.error };
|
|
306
|
+
i += 1;
|
|
307
|
+
if (arg === "--epic-key")
|
|
308
|
+
epicKey = value.trim();
|
|
309
|
+
else if (arg === "--plan-dir")
|
|
310
|
+
planDir = value;
|
|
311
|
+
else
|
|
312
|
+
repo = value.trim();
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
return { status: "error", message: "epic-plan save: unknown argument." };
|
|
316
|
+
}
|
|
317
|
+
if (epicKey === undefined)
|
|
318
|
+
return { status: "error", message: "epic-plan save: --epic-key is required." };
|
|
319
|
+
if (!EPIC_KEY_PATTERN.test(epicKey)) {
|
|
320
|
+
return { status: "error", message: "epic-plan save: --epic-key must be a ticket key such as PROJ-123." };
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
status: "ok",
|
|
324
|
+
options: {
|
|
325
|
+
epicKey,
|
|
326
|
+
...(planDir !== undefined ? { planDir: path.resolve(planDir) } : {}),
|
|
327
|
+
...(repo !== undefined ? { repo } : {}),
|
|
328
|
+
json,
|
|
329
|
+
},
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
export async function createDefaultEpicPlanCliDeps() {
|
|
333
|
+
// Imported lazily so this module stays importable from `drive-epic` without a cycle.
|
|
334
|
+
const { resolveDriveEpicDocsDir } = await import("./drive-epic.js");
|
|
335
|
+
const { createDefaultRunExecutorLaunchDeps } = await import("./executor-launch.js");
|
|
336
|
+
return {
|
|
337
|
+
...createDefaultAuthoredPlanSaveDeps(),
|
|
338
|
+
resolveDocsDir: () => resolveDriveEpicDocsDir({
|
|
339
|
+
env: process.env,
|
|
340
|
+
gitTopLevel: async () => {
|
|
341
|
+
const top = await createDefaultRunExecutorLaunchDeps().execFile("git", ["rev-parse", "--show-toplevel"], {
|
|
342
|
+
cwd: process.cwd(),
|
|
343
|
+
});
|
|
344
|
+
return top.ok ? top.stdout.trim() : null;
|
|
345
|
+
},
|
|
346
|
+
}),
|
|
347
|
+
discoveryFs: {
|
|
348
|
+
readdir: (dirPath) => readdir(dirPath, { withFileTypes: true }),
|
|
349
|
+
readFile: (filePath) => readFile(filePath, "utf8"),
|
|
350
|
+
},
|
|
351
|
+
log: (message) => console.log(message),
|
|
352
|
+
errorLog: (message) => console.error(message),
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
/** Run `epic-plan`. Returns 0 on a saved (or already-stored) plan and 1 otherwise. Never throws. */
|
|
356
|
+
export async function runEpicPlanCli(argv, overrides = {}) {
|
|
357
|
+
const parsed = parseEpicPlanArgs(argv);
|
|
358
|
+
let deps;
|
|
359
|
+
try {
|
|
360
|
+
deps = { ...(await createDefaultEpicPlanCliDeps()), ...overrides };
|
|
361
|
+
}
|
|
362
|
+
catch {
|
|
363
|
+
process.stderr.write("epic-plan: could not start.\n");
|
|
364
|
+
return 1;
|
|
365
|
+
}
|
|
366
|
+
if (parsed.status === "help") {
|
|
367
|
+
deps.log(getEpicPlanUsage());
|
|
368
|
+
return 0;
|
|
369
|
+
}
|
|
370
|
+
if (parsed.status === "error") {
|
|
371
|
+
deps.errorLog(parsed.message);
|
|
372
|
+
deps.errorLog("");
|
|
373
|
+
deps.errorLog(getEpicPlanUsage());
|
|
374
|
+
return 1;
|
|
375
|
+
}
|
|
376
|
+
const { epicKey, repo, json } = parsed.options;
|
|
377
|
+
const report = (outcome) => {
|
|
378
|
+
if (outcome.ok) {
|
|
379
|
+
const snap = outcome.result.snapshot;
|
|
380
|
+
if (json) {
|
|
381
|
+
deps.log(JSON.stringify({
|
|
382
|
+
ok: true,
|
|
383
|
+
epic_key: outcome.epicKey,
|
|
384
|
+
created: outcome.created,
|
|
385
|
+
authored_version: snap.authored_version,
|
|
386
|
+
plan_hash: snap.plan_hash,
|
|
387
|
+
saved_by: snap.saved_by,
|
|
388
|
+
saved_at: snap.saved_at,
|
|
389
|
+
endpoint: outcome.endpoint,
|
|
390
|
+
}));
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
deps.log(renderAuthoredPlanSaved(outcome));
|
|
394
|
+
}
|
|
395
|
+
return 0;
|
|
396
|
+
}
|
|
397
|
+
for (const line of renderAuthoredPlanNotSaved(outcome))
|
|
398
|
+
deps.errorLog(line);
|
|
399
|
+
if (json) {
|
|
400
|
+
deps.log(JSON.stringify({ ok: false, epic_key: outcome.epicKey, reason: outcome.reason, retry_command: outcome.retryCommand }));
|
|
401
|
+
}
|
|
402
|
+
return 1;
|
|
403
|
+
};
|
|
404
|
+
const noDirFailure = (reason) => report({
|
|
405
|
+
ok: false,
|
|
406
|
+
epicKey,
|
|
407
|
+
reason,
|
|
408
|
+
retryCommand: renderEpicPlanSaveCommand(deps.env, { epicKey, ...(repo !== undefined ? { repo } : {}) }),
|
|
409
|
+
});
|
|
410
|
+
try {
|
|
411
|
+
let planDir = parsed.options.planDir;
|
|
412
|
+
if (planDir === undefined) {
|
|
413
|
+
const docs = await deps.resolveDocsDir();
|
|
414
|
+
if (!docs.ok)
|
|
415
|
+
return noDirFailure("docs_dir_unresolved");
|
|
416
|
+
const discovered = await discoverEpicPlan(epicKey, docs.docsDir, deps.discoveryFs);
|
|
417
|
+
if (discovered.status === "plan_not_found")
|
|
418
|
+
return noDirFailure("plan_not_found");
|
|
419
|
+
if (discovered.status === "plan_ambiguous")
|
|
420
|
+
return noDirFailure("plan_ambiguous");
|
|
421
|
+
// A plan `drive-epic` generated is not an authored plan. Name its folder to save it on purpose.
|
|
422
|
+
if (discovered.generated !== undefined)
|
|
423
|
+
return noDirFailure("generated_plan");
|
|
424
|
+
planDir = path.dirname(discovered.path);
|
|
425
|
+
}
|
|
426
|
+
return report(await saveLocalAuthoredPlan(deps, { epicKey, planDir, ...(repo !== undefined ? { repo } : {}) }));
|
|
427
|
+
}
|
|
428
|
+
catch {
|
|
429
|
+
return noDirFailure("server_unknown");
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* The one latest-read a launch or preview makes. Always the normal Bridge server
|
|
434
|
+
* (the general resolver), never the run's local control plane. Never throws.
|
|
435
|
+
*/
|
|
436
|
+
export async function lookupAuthoredPlanForLaunch(epicKey, repo, env) {
|
|
437
|
+
try {
|
|
438
|
+
const access = await resolveAuthoredPlanAccess(repo, env);
|
|
439
|
+
if (!access.ok)
|
|
440
|
+
return { lookup: { kind: "unknown", reason: "access_unavailable" }, endpoint: null };
|
|
441
|
+
return {
|
|
442
|
+
lookup: await getAuthoredEpicPlan(access.access, epicKey),
|
|
443
|
+
endpoint: displayBridgeEndpoint(access.access.baseUrl),
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
catch {
|
|
447
|
+
return { lookup: { kind: "unknown", reason: "network" }, endpoint: null };
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Write a server snapshot's DAG — and its eligibility advisory, under the exact
|
|
452
|
+
* name `readContainmentEligibilityAdvisory` reads — into a fresh owner-only
|
|
453
|
+
* folder outside `docs_dir`. Discovery never sees it. Real launches only: a
|
|
454
|
+
* preview serves the DAG from memory and writes nothing.
|
|
455
|
+
*/
|
|
456
|
+
export async function materializeAuthoredPlanSnapshot(snapshot) {
|
|
457
|
+
const dir = await mkdtemp(path.join(os.tmpdir(), "bapi-authored-plan-"));
|
|
458
|
+
const cleanup = async () => {
|
|
459
|
+
try {
|
|
460
|
+
await rm(dir, { recursive: true, force: true });
|
|
461
|
+
}
|
|
462
|
+
catch {
|
|
463
|
+
// A leftover private temp folder is harmless; never fail the launch on it.
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
try {
|
|
467
|
+
await chmod(dir, 0o700);
|
|
468
|
+
const planPath = path.join(dir, AUTHORED_PLAN_DAG_FILE);
|
|
469
|
+
await writeFile(planPath, JSON.stringify(snapshot.plan_blob, null, 2) + "\n", { encoding: "utf8", mode: 0o600 });
|
|
470
|
+
if (snapshot.eligibility_advisory !== null) {
|
|
471
|
+
await writeFile(path.join(dir, AUTHORED_PLAN_ELIGIBILITY_FILE), JSON.stringify(snapshot.eligibility_advisory, null, 2) + "\n", { encoding: "utf8", mode: 0o600 });
|
|
472
|
+
}
|
|
473
|
+
return { planPath, cleanup };
|
|
474
|
+
}
|
|
475
|
+
catch (err) {
|
|
476
|
+
await cleanup();
|
|
477
|
+
throw err;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
export function serverPlanProvenance(snapshot, endpoint) {
|
|
481
|
+
return {
|
|
482
|
+
source: "server",
|
|
483
|
+
plan_version: snapshot.authored_version,
|
|
484
|
+
plan_hash: snapshot.plan_hash,
|
|
485
|
+
saved_by: snapshot.saved_by,
|
|
486
|
+
saved_at: snapshot.saved_at,
|
|
487
|
+
endpoint,
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
export function nonServerPlanProvenance(source) {
|
|
491
|
+
return { source, plan_version: null, plan_hash: null, saved_by: null, saved_at: null, endpoint: null };
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Explain a run hash that differs from the authored hash, from what was actually
|
|
495
|
+
* observed: a trim of merged children (with the post-trim hash) and the server's
|
|
496
|
+
* reported count of added ordering edges. A difference those facts do not explain
|
|
497
|
+
* — including an older server that did not report the edge count — is `unknown`.
|
|
498
|
+
* Ordering is never inferred from hash inequality alone.
|
|
499
|
+
*/
|
|
500
|
+
export function explainRunPlanHash(input) {
|
|
501
|
+
if (input.runHash === input.authoredHash)
|
|
502
|
+
return [];
|
|
503
|
+
const reasons = [];
|
|
504
|
+
const expected = input.trimmedHash ?? input.authoredHash;
|
|
505
|
+
if (input.trimmedHash !== undefined && input.trimmedHash !== input.authoredHash) {
|
|
506
|
+
reasons.push("merged_children_trimmed");
|
|
507
|
+
}
|
|
508
|
+
if (input.runHash === expected)
|
|
509
|
+
return reasons.length > 0 ? reasons : ["unknown"];
|
|
510
|
+
if (input.orderingEdgesAdded !== undefined && input.orderingEdgesAdded > 0) {
|
|
511
|
+
reasons.push("ordering_edges_added");
|
|
512
|
+
return reasons;
|
|
513
|
+
}
|
|
514
|
+
return [...reasons, "unknown"];
|
|
515
|
+
}
|
|
516
|
+
/** The compact Plan summary line that leads human preview and launch output. */
|
|
517
|
+
export function renderPlanProvenanceLine(epicKey, provenance) {
|
|
518
|
+
if (provenance.source !== "server") {
|
|
519
|
+
return `${epicKey}: Plan — source ${provenance.source}.`;
|
|
520
|
+
}
|
|
521
|
+
return (`${epicKey}: Plan — source server, authored version ${provenance.plan_version ?? "unknown"}, ` +
|
|
522
|
+
`hash ${provenance.plan_hash !== null ? shortPlanHash(provenance.plan_hash) : "unknown"}, ` +
|
|
523
|
+
`saved by ${provenance.saved_by ?? "unknown"} at ${provenance.saved_at ?? "unknown"}, ` +
|
|
524
|
+
`server ${provenance.endpoint ?? "unknown"}.`);
|
|
525
|
+
}
|
|
526
|
+
/** The fixed text for a server lookup that could not be settled. */
|
|
527
|
+
export function authoredPlanUnknownRemedy(epicKey, repo) {
|
|
528
|
+
return ("No run was created; the stored plan could not be verified. The Bridge server did not give a " +
|
|
529
|
+
"definite answer about a stored plan for this epic, so no local or generated plan was used " +
|
|
530
|
+
`in its place. Check access and connectivity to the Bridge server, then re-run \`drive-epic ${epicKey}` +
|
|
531
|
+
`${repo !== undefined ? ` --repo ${repo}` : ""}\`. To run a local plan file instead, pass it with --plan-file.`);
|
|
532
|
+
}
|
|
533
|
+
/** The fixed text for a first-launch upload that did not complete. */
|
|
534
|
+
export function authoredPlanUploadFailedRemedy(retryCommand) {
|
|
535
|
+
return ("No run was created; the local plan could not be saved to the Bridge server, and a run must " +
|
|
536
|
+
`start from the stored plan. Save it, then launch again. Retry: ${retryCommand}`);
|
|
537
|
+
}
|
|
538
|
+
/** The one-line notice for a server without authored-plan routes. */
|
|
539
|
+
export const AUTHORED_PLAN_SERVER_TOO_OLD_NOTICE = "Notice: this Bridge server does not store epic plans yet; using the local plan files as before.";
|
|
540
|
+
/** The stop reason ids drive-epic reports. */
|
|
541
|
+
export const AUTHORED_PLAN_UNKNOWN_REASON_ID = "authored_plan_unknown";
|
|
542
|
+
export const AUTHORED_PLAN_UPLOAD_FAILED_REASON_ID = "authored_plan_upload_failed";
|
|
@@ -105,6 +105,9 @@ export const BRIDGE_SANCTIONED_VERB_SUBCOMMANDS = [
|
|
|
105
105
|
"resolve-handoff",
|
|
106
106
|
// BAPI-1532: answer a named plan failure with one forced regeneration.
|
|
107
107
|
"regenerate-plan",
|
|
108
|
+
// BAPI-1705: the open-decision council's reserve and settle verbs.
|
|
109
|
+
"reserve-council",
|
|
110
|
+
"record-decision",
|
|
108
111
|
];
|
|
109
112
|
/** The Bridge MCP tools the supervisor calls. */
|
|
110
113
|
export const BRIDGE_SUPERVISOR_MCP_TOOLS = [
|
|
@@ -116,6 +119,11 @@ export const BRIDGE_SUPERVISOR_MCP_TOOLS = [
|
|
|
116
119
|
"report_mcp_bug",
|
|
117
120
|
// BAPI-1399: the prerequisite scan reads the epic and its child tickets.
|
|
118
121
|
"get_ticket",
|
|
122
|
+
// BAPI-1705: the open-decision council and its Jira decision comment.
|
|
123
|
+
"request_council",
|
|
124
|
+
"get_council",
|
|
125
|
+
"get_comments",
|
|
126
|
+
"add_comment",
|
|
119
127
|
];
|
|
120
128
|
/** The private run-state directory the tally, patch, and context files live in. */
|
|
121
129
|
export const BRIDGE_RUN_STATE_DIR = "~/.local/state/bapi-conductor-runs";
|