@bridge_gpt/mcp-server 0.2.70 → 0.2.72
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 +55 -17
- package/build/agent-launchers/claude-executor-adapter.js +29 -4
- package/build/agent-notes.js +171 -95
- package/build/agent-registry.js +5 -5
- package/build/agents.generated.js +12 -2
- package/build/bounded-wait.js +9 -1
- package/build/bridge-permissions.js +17 -5
- package/build/bridge-worktree-inspection.js +237 -0
- package/build/check-evidence.js +6 -0
- package/build/claude-review-workflow.js +1 -1
- package/build/cli-help.js +6 -0
- package/build/codex-auto-recovery.js +126 -0
- package/build/codex-skill-adapter.js +2 -0
- package/build/commands.generated.js +5 -5
- package/build/conductor/bridge-api-client.js +776 -23
- package/build/conductor/command-drift-production.js +7 -2
- package/build/conductor/doctor.js +93 -13
- package/build/conductor/epic-implementer-cli.js +55 -2
- package/build/conductor/gate-discovery.js +659 -19
- package/build/conductor/gate-settings-review.js +751 -0
- package/build/conductor/git-hooks-uninstall.js +112 -0
- package/build/conductor/git-hooks.js +81 -15
- package/build/conductor/guided-repair.js +10 -1
- package/build/conductor/install-doctor.js +2 -4
- package/build/conductor/launch-need-probes.js +16 -11
- package/build/conductor/launch-plan.js +185 -0
- package/build/conductor/local-merge.js +12 -1
- package/build/conductor/merge-execution-contract.js +1 -1
- package/build/conductor/merged-child-check.js +2 -1
- package/build/conductor/precheck-timings.js +14 -0
- package/build/conductor/prerequisite-inputs.js +379 -0
- package/build/conductor/preview-observations.js +10 -0
- package/build/conductor/readiness-assessment.js +78 -0
- package/build/conductor/readiness-cli.js +10 -0
- package/build/conductor/readiness-prerequisites.js +53 -0
- package/build/conductor/readiness-sections.js +25 -9
- package/build/conductor/readiness.js +20 -2
- package/build/conductor/recovery-cli.js +281 -14
- package/build/conductor/recovery-operations.js +78 -5
- package/build/conductor/repair-contract.js +33 -0
- package/build/conductor/tools.js +34 -3
- package/build/conductor/wait-run-attention.js +115 -0
- package/build/conductor/wait-run-cli.js +96 -3
- package/build/conductor/worker-database-doctor-inspector.js +1 -0
- package/build/credential-store.js +25 -20
- package/build/dependency-install-declarations.js +157 -0
- package/build/docs.generated.js +4 -4
- package/build/doctor.js +37 -5
- package/build/drive-epic-help.js +2 -2
- package/build/drive-epic.js +240 -56
- package/build/epic-ci-workflow-drift.js +71 -23
- package/build/epic-ci-workflow-install.js +83 -26
- package/build/epic-ci-workflow-v1.js +132 -0
- package/build/epic-ci-workflow.js +174 -13
- package/build/epic-implementer-bin.js +119 -44
- package/build/epic-launch-profile.js +1 -1
- package/build/executor/ci-rerun-job.js +220 -14
- package/build/executor/cli.js +2 -0
- package/build/executor/completion-contract.js +16 -0
- package/build/executor/credentials.js +1 -1
- package/build/executor/delivery-observations.js +113 -0
- package/build/executor/delivery-outcome.js +30 -0
- package/build/executor/dependency-refresh-runner.js +132 -0
- package/build/executor/dependency-refresh.js +530 -0
- package/build/executor/deps.js +4 -0
- package/build/executor/env.js +274 -5
- package/build/executor/gate-qualification-job.js +20 -5
- package/build/executor/harness-coverage.js +19 -0
- package/build/executor/http-client.js +35 -1
- package/build/executor/index.js +2 -1
- package/build/executor/install-preflight.js +1 -1
- package/build/executor/job-runner.js +355 -36
- package/build/executor/likely-tests.js +100 -98
- package/build/executor/preflight.js +5 -0
- package/build/executor/process-containment.js +18 -0
- package/build/executor/prompt-spec.js +84 -15
- package/build/executor/reconcile-overlap-job.js +6 -1
- package/build/executor/required-verification.js +28 -0
- package/build/executor/required-work-diagnostics.js +30 -0
- package/build/executor/required-work-ledger.js +19 -1
- package/build/executor/results.js +42 -0
- package/build/executor/service-discovery.js +42 -0
- package/build/executor/service-lifecycle.js +109 -2
- package/build/executor/service-uninstall.js +205 -0
- package/build/executor/service-unit.js +5 -3
- package/build/executor/test-clock.js +3 -0
- package/build/executor/verification-hints.js +179 -0
- package/build/executor/worker-command.js +188 -1
- package/build/executor/worker-database.js +299 -40
- package/build/executor/worker-finalization.js +65 -10
- package/build/executor/worker-guard-hook.js +10 -2
- package/build/executor/worker-resources.js +12 -1
- package/build/executor/worker-verification-guidance.js +64 -0
- package/build/executor/worktree-inspection.js +42 -0
- package/build/github-sign-in.js +1 -1
- package/build/index.js +767 -310
- package/build/init.js +3 -3
- package/build/install-bridge-conductor-gate.js +416 -41
- package/build/install-bridge-conductor-setup.js +135 -32
- package/build/install-bridge-conductor.js +769 -353
- package/build/install-bridge.js +419 -124
- package/build/install-maintenance.js +104 -0
- package/build/install-reexec.js +1 -1
- package/build/local-cleanup.js +59 -0
- package/build/mcp-install-state.js +68 -2
- package/build/merge-workflow-install.js +22 -2
- package/build/package-script-semantics.js +10 -0
- package/build/pipeline-utils.js +1 -1
- package/build/pipelines.generated.js +6 -6
- package/build/plan-execution-ledger.js +171 -10
- package/build/plane/plane-freshness.js +12 -9
- package/build/plane/preflight.js +19 -0
- package/build/plane/terminal-run-cleanup.js +5 -1
- package/build/plane/terminal-run-status.js +4 -0
- package/build/printed-remedy-commands.js +31 -4
- package/build/readiness-check.js +1 -78
- package/build/readiness-prerequisites.generated.js +199 -0
- package/build/readme.generated.js +1 -1
- package/build/repository-toolchains.js +623 -0
- package/build/setup-change-policy.js +32 -0
- package/build/setup-epic.js +26 -9
- package/build/setup-question.js +62 -0
- package/build/start-tickets.js +4 -0
- package/build/test-command-detection.js +61 -80
- package/build/test-support/notes-fs.js +40 -0
- package/build/ticket-delivery-artifacts.js +7 -0
- package/build/ticket-delivery-enrollment.js +80 -4
- package/build/ticket-delivery-run-scope.js +128 -0
- package/build/version.generated.js +3 -3
- package/build/worker-guard-hook-bin.js +2 -2
- package/build/worktrees.js +105 -0
- package/docs/EPIC-IMPLEMENTER.md +43 -0
- package/docs/epic-implementer/getting-started.md +95 -14
- package/package.json +2 -2
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `epic-implementer prerequisite-inputs` — write the private scanner input files
|
|
3
|
+
* for a `/drive-epic-run` prerequisite scan (BAPI-1557).
|
|
4
|
+
*
|
|
5
|
+
* WHAT IT DOES. The driver passes the epic key and its validated, ordered child
|
|
6
|
+
* keys. For each child the command reads the stored epic and child descriptions
|
|
7
|
+
* through the shared Bridge API client and writes one deterministic file,
|
|
8
|
+
* `~/.local/state/bapi-conductor-runs/<EPIC>/prerequisite-input-<CHILD>.txt`,
|
|
9
|
+
* that holds the epic description (for context) and that one child's description.
|
|
10
|
+
* A scanner agent then reads only its own file.
|
|
11
|
+
*
|
|
12
|
+
* WHAT IT IS NOT. It changes nothing on the server and decides nothing: it does
|
|
13
|
+
* not derive run membership, skip decisions, or order. It reads stored tickets
|
|
14
|
+
* (a read-only route) and writes local files only inside a private directory.
|
|
15
|
+
*
|
|
16
|
+
* PRIVACY. Descriptions and raw upstream content never reach stdout, stderr,
|
|
17
|
+
* logs, argv, or error text. A per-child failure reports only a closed reason.
|
|
18
|
+
* Access comes only from the shared resolver, never from this module.
|
|
19
|
+
*
|
|
20
|
+
* EXIT CODES. Per-child failures (including all children failing) exit 0 with a
|
|
21
|
+
* closed reason per child. Exit 1 with one bounded stderr line is reserved for an
|
|
22
|
+
* invalid call, an access failure, an epic-read failure, or a run directory that
|
|
23
|
+
* cannot be made private.
|
|
24
|
+
*/
|
|
25
|
+
import { randomBytes } from "node:crypto";
|
|
26
|
+
import { constants as fsConstants } from "node:fs";
|
|
27
|
+
import { lstat, mkdir, open, rename, unlink, chmod } from "node:fs/promises";
|
|
28
|
+
import os from "node:os";
|
|
29
|
+
import path from "node:path";
|
|
30
|
+
import { ConductorBridgeApiError, fetchStoredTicket, resolveConductorBridgeApiAccess, } from "./bridge-api-client.js";
|
|
31
|
+
import { ConductorValidationError } from "./errors.js";
|
|
32
|
+
import { writeJsonDocument } from "./json-output.js";
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// Constants
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
/** Ticket-key shape every key argument must match. */
|
|
37
|
+
export const PREREQUISITE_INPUT_KEY_PATTERN = /^[A-Z][A-Z0-9_]{0,19}-[0-9]+$/;
|
|
38
|
+
/** A line longer than this many Unicode code points is wrapped at a space or tab. */
|
|
39
|
+
export const PREREQUISITE_INPUT_WRAP_LIMIT = 1000;
|
|
40
|
+
/** A completed input larger than this many UTF-8 bytes is refused. */
|
|
41
|
+
export const PREREQUISITE_INPUT_MAX_BYTES = 98_304;
|
|
42
|
+
/** Fixed run-state root, relative to the home directory. */
|
|
43
|
+
const RUN_STATE_SEGMENTS = [".local", "state", "bapi-conductor-runs"];
|
|
44
|
+
const MAX_ERROR_CHARS = 200;
|
|
45
|
+
const UNEXPECTED_FAILURE_MESSAGE = "prerequisite-inputs failed unexpectedly; no scanner input was reported.";
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// Usage and argument parsing
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
export function getPrerequisiteInputsUsage() {
|
|
50
|
+
return [
|
|
51
|
+
"Usage: epic-implementer prerequisite-inputs --epic-key <KEY> --child <KEY> [--child <KEY> ...] [--json]",
|
|
52
|
+
"",
|
|
53
|
+
"Reads stored ticket descriptions and writes one private local scanner input file per",
|
|
54
|
+
"child under ~/.local/state/bapi-conductor-runs/<EPIC>/. Changes nothing on the server.",
|
|
55
|
+
"",
|
|
56
|
+
"Options:",
|
|
57
|
+
" --epic-key <KEY> The epic whose description gives context (required)",
|
|
58
|
+
" --child <KEY> A child ticket, repeated, in the order to report (at least one)",
|
|
59
|
+
" --json Print one JSON document",
|
|
60
|
+
"",
|
|
61
|
+
"Each child prints its written path, or the reason `input over size cap` or",
|
|
62
|
+
"`input rewrite failed`. Per-child failures exit 0. Invalid calls, access failures,",
|
|
63
|
+
"an unreadable epic, or a directory that cannot be made private exit 1 with one line",
|
|
64
|
+
"on stderr. Descriptions never appear in output.",
|
|
65
|
+
"",
|
|
66
|
+
"Example:",
|
|
67
|
+
" epic-implementer prerequisite-inputs --epic-key EPIC-1 --child EPIC-2 --child EPIC-3",
|
|
68
|
+
].join("\n");
|
|
69
|
+
}
|
|
70
|
+
/** Parse flags. Every message is fixed text: argv content is never echoed. */
|
|
71
|
+
export function parsePrerequisiteInputsArgs(argv) {
|
|
72
|
+
let epicKey;
|
|
73
|
+
const children = [];
|
|
74
|
+
let json = false;
|
|
75
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
76
|
+
const token = argv[i];
|
|
77
|
+
if (token === "-h" || token === "--help") {
|
|
78
|
+
return { help: true, epicKey: "", children: [], json: false };
|
|
79
|
+
}
|
|
80
|
+
if (token === "--json") {
|
|
81
|
+
json = true;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (token !== "--epic-key" && token !== "--child") {
|
|
85
|
+
throw new ConductorValidationError('Unknown or malformed prerequisite-inputs argument. Run "epic-implementer prerequisite-inputs --help" for usage.');
|
|
86
|
+
}
|
|
87
|
+
const value = argv[i + 1];
|
|
88
|
+
if (value === undefined || value.startsWith("--")) {
|
|
89
|
+
throw new ConductorValidationError(`Flag "${token}" requires a value.`);
|
|
90
|
+
}
|
|
91
|
+
i += 1;
|
|
92
|
+
if (!PREREQUISITE_INPUT_KEY_PATTERN.test(value)) {
|
|
93
|
+
throw new ConductorValidationError(`Flag "${token}" requires a valid ticket key.`);
|
|
94
|
+
}
|
|
95
|
+
if (token === "--epic-key") {
|
|
96
|
+
if (epicKey !== undefined) {
|
|
97
|
+
throw new ConductorValidationError('Flag "--epic-key" may be given only once.');
|
|
98
|
+
}
|
|
99
|
+
epicKey = value;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
if (children.includes(value)) {
|
|
103
|
+
throw new ConductorValidationError('Flag "--child" may not repeat a ticket key.');
|
|
104
|
+
}
|
|
105
|
+
children.push(value);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (epicKey === undefined) {
|
|
109
|
+
throw new ConductorValidationError('Flag "--epic-key" is required.');
|
|
110
|
+
}
|
|
111
|
+
if (children.length === 0) {
|
|
112
|
+
throw new ConductorValidationError('At least one "--child" is required.');
|
|
113
|
+
}
|
|
114
|
+
return { help: false, epicKey, children, json };
|
|
115
|
+
}
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
// Content
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
/**
|
|
120
|
+
* Wrap long lines, and change nothing else.
|
|
121
|
+
*
|
|
122
|
+
* Counting Unicode code points, a line longer than the limit has the last ASCII
|
|
123
|
+
* space or tab at or before the limit replaced by LF, and the remainder is
|
|
124
|
+
* handled the same way. Position zero is never a break, and a token with no
|
|
125
|
+
* eligible space or tab at or before the limit stays whole on its own line, with
|
|
126
|
+
* wrapping resuming at the first space or tab after it. Existing newlines (and the CR in a CRLF),
|
|
127
|
+
* multibyte whitespace, and every other character pass through untouched: no
|
|
128
|
+
* trimming, normalization, summarizing, or truncation.
|
|
129
|
+
*/
|
|
130
|
+
export function wrapDescription(text, limit = PREREQUISITE_INPUT_WRAP_LIMIT) {
|
|
131
|
+
return text
|
|
132
|
+
.split("\n")
|
|
133
|
+
.map((line) => wrapLine(line, limit))
|
|
134
|
+
.join("\n");
|
|
135
|
+
}
|
|
136
|
+
function wrapLine(line, limit) {
|
|
137
|
+
let rest = Array.from(line);
|
|
138
|
+
if (rest.length <= limit)
|
|
139
|
+
return line;
|
|
140
|
+
const out = [];
|
|
141
|
+
while (rest.length > limit) {
|
|
142
|
+
let breakAt = -1;
|
|
143
|
+
for (let i = Math.min(limit, rest.length - 1); i >= 1; i -= 1) {
|
|
144
|
+
if (rest[i] === " " || rest[i] === "\t") {
|
|
145
|
+
breakAt = i;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (breakAt < 0) {
|
|
150
|
+
// An unbreakable run longer than the limit stays whole on its own line;
|
|
151
|
+
// wrapping resumes at the first ASCII space or tab after it.
|
|
152
|
+
for (let i = limit + 1; i < rest.length; i += 1) {
|
|
153
|
+
if (rest[i] === " " || rest[i] === "\t") {
|
|
154
|
+
breakAt = i;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (breakAt < 0)
|
|
160
|
+
break;
|
|
161
|
+
out.push(rest.slice(0, breakAt).join(""));
|
|
162
|
+
rest = rest.slice(breakAt + 1);
|
|
163
|
+
}
|
|
164
|
+
out.push(rest.join(""));
|
|
165
|
+
return out.join("\n");
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The exact file layout: `Epic: <EPIC>\n` + epic segment + `\n\nChild: <CHILD>\n` +
|
|
169
|
+
* child segment + `\n`, each segment the wrapped description.
|
|
170
|
+
*/
|
|
171
|
+
export function formatPrerequisiteInput(epicKey, epicDescription, childKey, childDescription) {
|
|
172
|
+
return (`Epic: ${epicKey}\n` +
|
|
173
|
+
wrapDescription(epicDescription) +
|
|
174
|
+
`\n\nChild: ${childKey}\n` +
|
|
175
|
+
wrapDescription(childDescription) +
|
|
176
|
+
"\n");
|
|
177
|
+
}
|
|
178
|
+
/** The one stdout document for a result list. */
|
|
179
|
+
export function formatPrerequisiteInputResults(results, json) {
|
|
180
|
+
if (json)
|
|
181
|
+
return JSON.stringify({ results });
|
|
182
|
+
return results
|
|
183
|
+
.map((r) => ("path" in r ? `${r.child}: ${r.path}` : `${r.child}: ${r.reason}`))
|
|
184
|
+
.join("\n");
|
|
185
|
+
}
|
|
186
|
+
// ---------------------------------------------------------------------------
|
|
187
|
+
// Filesystem
|
|
188
|
+
// ---------------------------------------------------------------------------
|
|
189
|
+
function defaultFs() {
|
|
190
|
+
return {
|
|
191
|
+
mkdir: async (dir, mode) => {
|
|
192
|
+
await mkdir(dir, { recursive: true, mode });
|
|
193
|
+
},
|
|
194
|
+
lstat: (p) => lstat(p),
|
|
195
|
+
chmod: (p, mode) => chmod(p, mode),
|
|
196
|
+
openExclusive: async (p, mode) => {
|
|
197
|
+
// O_NOFOLLOW is absent on Windows; the exclusive create still refuses an
|
|
198
|
+
// existing name there.
|
|
199
|
+
const flags = fsConstants.O_WRONLY | fsConstants.O_CREAT | fsConstants.O_EXCL | (fsConstants.O_NOFOLLOW ?? 0);
|
|
200
|
+
const handle = await open(p, flags, mode);
|
|
201
|
+
return {
|
|
202
|
+
stat: () => handle.stat(),
|
|
203
|
+
chmod: (m) => handle.chmod(m),
|
|
204
|
+
writeFile: (data, encoding) => handle.writeFile(data, encoding),
|
|
205
|
+
sync: () => handle.sync(),
|
|
206
|
+
close: () => handle.close(),
|
|
207
|
+
};
|
|
208
|
+
},
|
|
209
|
+
rename: (from, to) => rename(from, to),
|
|
210
|
+
unlink: (p) => unlink(p),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
class PrivateDirectoryError extends Error {
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Create the run directory at mode 0700 and prove it is a real directory (not a
|
|
217
|
+
* symlink) owned by the current user whose mode is exactly 0700.
|
|
218
|
+
*/
|
|
219
|
+
async function ensurePrivateRunDirectory(fs, dir, uid, isWindows) {
|
|
220
|
+
try {
|
|
221
|
+
await fs.mkdir(dir, 0o700);
|
|
222
|
+
let info = await fs.lstat(dir);
|
|
223
|
+
if (info.isSymbolicLink() || !info.isDirectory())
|
|
224
|
+
throw new PrivateDirectoryError();
|
|
225
|
+
if (isWindows)
|
|
226
|
+
return;
|
|
227
|
+
if (uid === undefined || info.uid !== uid)
|
|
228
|
+
throw new PrivateDirectoryError();
|
|
229
|
+
if ((info.mode & 0o777) !== 0o700) {
|
|
230
|
+
await fs.chmod(dir, 0o700);
|
|
231
|
+
info = await fs.lstat(dir);
|
|
232
|
+
if (info.isSymbolicLink() || !info.isDirectory() || info.uid !== uid) {
|
|
233
|
+
throw new PrivateDirectoryError();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if ((info.mode & 0o777) !== 0o700)
|
|
237
|
+
throw new PrivateDirectoryError();
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
throw new PrivateDirectoryError();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Write `content` to `target` through an exclusively created, mode-0600 temporary
|
|
245
|
+
* file in the same verified directory, then rename it over the target. The rename
|
|
246
|
+
* replaces a symlinked target rather than writing through it.
|
|
247
|
+
*/
|
|
248
|
+
async function writePrivateFileAtomically(fs, dir, targetName, content, uid, isWindows, suffix) {
|
|
249
|
+
const target = path.join(dir, targetName);
|
|
250
|
+
const temp = path.join(dir, `.${targetName}.${suffix}.tmp`);
|
|
251
|
+
let created = false;
|
|
252
|
+
// A target that is already a symlink is refused outright: it is never followed,
|
|
253
|
+
// never replaced, and never reported as a success. A missing target is fine.
|
|
254
|
+
let existing;
|
|
255
|
+
try {
|
|
256
|
+
existing = await fs.lstat(target);
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
// No readable target entry: nothing to refuse. A genuine access problem
|
|
260
|
+
// surfaces from the exclusive create or the rename below.
|
|
261
|
+
existing = undefined;
|
|
262
|
+
}
|
|
263
|
+
if (existing?.isSymbolicLink())
|
|
264
|
+
throw new Error("target is a symlink");
|
|
265
|
+
try {
|
|
266
|
+
const handle = await fs.openExclusive(temp, 0o600);
|
|
267
|
+
created = true;
|
|
268
|
+
try {
|
|
269
|
+
if (!isWindows)
|
|
270
|
+
await handle.chmod(0o600);
|
|
271
|
+
const info = await handle.stat();
|
|
272
|
+
if (!info.isFile())
|
|
273
|
+
throw new Error("not a regular file");
|
|
274
|
+
if (!isWindows && (uid === undefined || info.uid !== uid || (info.mode & 0o777) !== 0o600)) {
|
|
275
|
+
throw new Error("unverified temporary file");
|
|
276
|
+
}
|
|
277
|
+
await handle.writeFile(content, "utf8");
|
|
278
|
+
await handle.sync();
|
|
279
|
+
}
|
|
280
|
+
finally {
|
|
281
|
+
await handle.close();
|
|
282
|
+
}
|
|
283
|
+
await fs.rename(temp, target);
|
|
284
|
+
created = false;
|
|
285
|
+
return target;
|
|
286
|
+
}
|
|
287
|
+
finally {
|
|
288
|
+
if (created) {
|
|
289
|
+
try {
|
|
290
|
+
await fs.unlink(temp);
|
|
291
|
+
}
|
|
292
|
+
catch {
|
|
293
|
+
// best effort; the name is unique and holds no secret beyond the input
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
// ---------------------------------------------------------------------------
|
|
299
|
+
// Command
|
|
300
|
+
// ---------------------------------------------------------------------------
|
|
301
|
+
function boundedLine(text) {
|
|
302
|
+
// eslint-disable-next-line no-control-regex
|
|
303
|
+
const single = text.replace(/[\u0000-\u001f\u007f-\u009f]+/g, " ").trim();
|
|
304
|
+
return single.length > MAX_ERROR_CHARS ? `${single.slice(0, MAX_ERROR_CHARS - 1)}…` : single;
|
|
305
|
+
}
|
|
306
|
+
/** Run `prerequisite-inputs`; returns the process exit code. */
|
|
307
|
+
export async function runPrerequisiteInputsCommand(argv, deps = {}) {
|
|
308
|
+
const writeStdout = deps.writeStdout ?? ((text) => writeJsonDocument(text));
|
|
309
|
+
const writeStderr = deps.writeStderr ?? ((line) => console.error(line));
|
|
310
|
+
const fail = (message) => {
|
|
311
|
+
writeStderr(`Error: ${boundedLine(message)}`);
|
|
312
|
+
return 1;
|
|
313
|
+
};
|
|
314
|
+
try {
|
|
315
|
+
let parsed;
|
|
316
|
+
try {
|
|
317
|
+
parsed = parsePrerequisiteInputsArgs(argv);
|
|
318
|
+
}
|
|
319
|
+
catch (err) {
|
|
320
|
+
return fail(err instanceof ConductorValidationError ? err.message : UNEXPECTED_FAILURE_MESSAGE);
|
|
321
|
+
}
|
|
322
|
+
if (parsed.help) {
|
|
323
|
+
if (await writeStdout(getPrerequisiteInputsUsage()))
|
|
324
|
+
return 0;
|
|
325
|
+
return fail("prerequisite-inputs: the help text could not be written to stdout.");
|
|
326
|
+
}
|
|
327
|
+
const resolveAccess = deps.resolveAccess ?? (() => resolveConductorBridgeApiAccess());
|
|
328
|
+
const accessResult = await resolveAccess();
|
|
329
|
+
if (!accessResult.ok) {
|
|
330
|
+
// The shared resolver's messages are fixed, secret-free text.
|
|
331
|
+
return fail(`prerequisite-inputs: ${accessResult.error}`);
|
|
332
|
+
}
|
|
333
|
+
const access = accessResult.access;
|
|
334
|
+
const fetchTicket = deps.fetchTicket ?? fetchStoredTicket;
|
|
335
|
+
// Read the epic once. Failing here is a whole-command failure.
|
|
336
|
+
let epic;
|
|
337
|
+
try {
|
|
338
|
+
epic = await fetchTicket(access, parsed.epicKey);
|
|
339
|
+
}
|
|
340
|
+
catch (err) {
|
|
341
|
+
const detail = err instanceof ConductorBridgeApiError ? ` (${err.message})` : "";
|
|
342
|
+
return fail(`prerequisite-inputs: the epic ticket could not be read${detail}.`);
|
|
343
|
+
}
|
|
344
|
+
const fs = deps.fs ?? defaultFs();
|
|
345
|
+
const isWindows = process.platform === "win32";
|
|
346
|
+
const uid = deps.getuid ? deps.getuid() : typeof process.getuid === "function" ? process.getuid() : undefined;
|
|
347
|
+
const home = (deps.homedir ?? os.homedir)();
|
|
348
|
+
const runDir = path.join(home, ...RUN_STATE_SEGMENTS, parsed.epicKey);
|
|
349
|
+
try {
|
|
350
|
+
await ensurePrivateRunDirectory(fs, runDir, uid, isWindows);
|
|
351
|
+
}
|
|
352
|
+
catch {
|
|
353
|
+
return fail("prerequisite-inputs: the run directory could not be made private.");
|
|
354
|
+
}
|
|
355
|
+
const suffixOf = deps.randomSuffix ?? (() => randomBytes(8).toString("hex"));
|
|
356
|
+
const results = [];
|
|
357
|
+
for (const child of parsed.children) {
|
|
358
|
+
try {
|
|
359
|
+
const ticket = await fetchTicket(access, child);
|
|
360
|
+
const content = formatPrerequisiteInput(parsed.epicKey, epic.description, child, ticket.description);
|
|
361
|
+
if (Buffer.byteLength(content, "utf8") > PREREQUISITE_INPUT_MAX_BYTES) {
|
|
362
|
+
results.push({ child, reason: "input over size cap" });
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
const written = await writePrivateFileAtomically(fs, runDir, `prerequisite-input-${child}.txt`, content, uid, isWindows, suffixOf());
|
|
366
|
+
results.push({ child, path: written });
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
results.push({ child, reason: "input rewrite failed" });
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
if (await writeStdout(formatPrerequisiteInputResults(results, parsed.json)))
|
|
373
|
+
return 0;
|
|
374
|
+
return fail("prerequisite-inputs: the result could not be written to stdout.");
|
|
375
|
+
}
|
|
376
|
+
catch {
|
|
377
|
+
return fail(UNEXPECTED_FAILURE_MESSAGE);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function previewObservationScopeMatches(observed, access, epic) {
|
|
2
|
+
try {
|
|
3
|
+
const normalize = (url) => new URL(url).href.replace(/\/+$/, "");
|
|
4
|
+
return normalize(observed.endpoint) === normalize(access.baseUrl) &&
|
|
5
|
+
observed.repository === access.repoName && observed.epic === epic;
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** Explicit advisory evidence. This module performs no I/O or authorization. */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { READINESS_ASSESSMENT_V1 as C } from '../readiness-prerequisites.generated.js';
|
|
4
|
+
export function assessmentBlockingEffect(app, state, impact) {
|
|
5
|
+
if (impact !== 'mandatory' || app === 'policy_inapplicable')
|
|
6
|
+
return 'none';
|
|
7
|
+
if (app === 'unknown' || ['pending', 'unreadable', 'unverified', 'unknown'].includes(state))
|
|
8
|
+
return 'unresolved';
|
|
9
|
+
return state === 'confirmed' ? 'none' : 'blocker';
|
|
10
|
+
}
|
|
11
|
+
const remedy = z.strictObject({ reference: z.enum(C.remedies), audience: z.enum(C.audiences) }).refine(r => (r.reference !== 'self_host' || r.audience === 'self_host_operator') &&
|
|
12
|
+
(r.audience !== 'bridge_support' || ['none', 'retry', 'support'].includes(r.reference)));
|
|
13
|
+
const context = z.strictObject({
|
|
14
|
+
kind: z.enum(['repository_preview', 'selected_run']),
|
|
15
|
+
repo_name: z.string().min(1).max(128).regex(/^[A-Za-z0-9_.:/-]+$/),
|
|
16
|
+
epic_run_id: z.string().min(1).max(128).regex(/^[A-Za-z0-9_.:-]+$/).nullable(),
|
|
17
|
+
stage: z.enum(['pre_create', 'first_approval', 'approved_run', 'auto_merge', 'unknown']),
|
|
18
|
+
policy_read_status: z.enum(['confirmed', 'missing', 'malformed', 'unreadable']),
|
|
19
|
+
observed_at: z.string().max(40).regex(/^\d{4}-\d{2}-\d{2}T[0-9:.+Z-]+$/),
|
|
20
|
+
}).refine(c => (c.kind === 'selected_run') === (c.epic_run_id !== null));
|
|
21
|
+
const exemptionBases = C.exemption_bases_by_id;
|
|
22
|
+
const record = z.strictObject({
|
|
23
|
+
id: z.string().min(1).max(128), scope: z.enum(C.scopes),
|
|
24
|
+
applicability: z.enum(C.applicability), basis: z.enum(C.basis),
|
|
25
|
+
observed_state: z.enum(C.states), impact: z.enum(C.impacts),
|
|
26
|
+
blocking_effect: z.enum(C.blocking_effects), inspected_sha: z.string().regex(/^[0-9a-f]{40}$/).nullable(),
|
|
27
|
+
reason: z.enum(C.reasons), remedy,
|
|
28
|
+
}).refine(r => C.coverage.some(c => c.id === r.id && c.scope === r.scope)
|
|
29
|
+
&& (r.applicability !== 'unknown' || r.basis === 'policy_unreadable')
|
|
30
|
+
&& (r.applicability !== 'applicable' || r.basis === 'required')
|
|
31
|
+
&& (r.applicability !== 'policy_inapplicable' || exemptionBases[r.id]?.includes(r.basis) === true)
|
|
32
|
+
&& r.blocking_effect === assessmentBlockingEffect(r.applicability, r.observed_state, r.impact)
|
|
33
|
+
&& (!['indexed_commit', 'default_branch'].includes(r.scope) || r.inspected_sha !== null || !['confirmed', 'absent', 'deficient'].includes(r.observed_state)));
|
|
34
|
+
export const readinessAssessmentSchema = z.strictObject({ version: z.literal(1), context, records: z.array(record) }).refine(a => {
|
|
35
|
+
const identities = a.records.map(r => `${r.scope}:${r.id}`);
|
|
36
|
+
return identities.length === C.coverage.length && new Set(identities).size === identities.length
|
|
37
|
+
&& C.coverage.every(c => identities.includes(`${c.scope}:${c.id}`))
|
|
38
|
+
&& a.records.every(r => r.impact === (r.id === 'server.parse-progress' ? 'advisory' : 'mandatory'));
|
|
39
|
+
});
|
|
40
|
+
export function parseAssessmentNegotiation(body) {
|
|
41
|
+
if (!Object.hasOwn(body, 'assessment'))
|
|
42
|
+
return { status: 'unsupported' };
|
|
43
|
+
const result = readinessAssessmentSchema.safeParse(body.assessment);
|
|
44
|
+
return result.success ? { status: 'available', assessment: result.data } : { status: 'unavailable' };
|
|
45
|
+
}
|
|
46
|
+
export function composeReadinessAssessment(negotiation, local = []) {
|
|
47
|
+
if (negotiation.status === 'available') {
|
|
48
|
+
const parsed = readinessAssessmentSchema.safeParse(negotiation.assessment);
|
|
49
|
+
negotiation = parsed.success ? { status: 'available', assessment: parsed.data } : { status: 'unavailable' };
|
|
50
|
+
}
|
|
51
|
+
// Local observations live in a separate namespace. They cannot replace even
|
|
52
|
+
// one server record, its applicability, or its mandatory impact.
|
|
53
|
+
const facts = new Map(local.map(f => [f.id, Object.freeze({ ...f,
|
|
54
|
+
impact: f.id === 'local.executor-installation' ? 'optional' : f.impact })]));
|
|
55
|
+
return Object.freeze({ negotiation: negotiation.status,
|
|
56
|
+
context: negotiation.status === 'available' ? negotiation.assessment.context : null,
|
|
57
|
+
records: negotiation.status === 'available' ? negotiation.assessment.records : [],
|
|
58
|
+
local: [...facts.values()] });
|
|
59
|
+
}
|
|
60
|
+
export function assessmentGroups(assessment) {
|
|
61
|
+
const blockers = assessment.records.filter(r => r.blocking_effect === 'blocker');
|
|
62
|
+
const unresolved = assessment.records.filter(r => r.blocking_effect === 'unresolved');
|
|
63
|
+
const localBlockers = assessment.local.filter(f => f.impact === 'mandatory' && ['absent', 'deficient'].includes(f.observed_state));
|
|
64
|
+
const localUnresolved = assessment.local.filter(f => f.impact === 'mandatory' && !['confirmed', 'absent', 'deficient'].includes(f.observed_state));
|
|
65
|
+
return { blockers, unresolved, localBlockers, localUnresolved };
|
|
66
|
+
}
|
|
67
|
+
export function deriveAdvisoryVerdict(assessment) {
|
|
68
|
+
const g = assessmentGroups(assessment);
|
|
69
|
+
if (g.blockers.length || g.localBlockers.length)
|
|
70
|
+
return 'Not ready';
|
|
71
|
+
if (assessment.negotiation !== 'available' || g.unresolved.length || g.localUnresolved.length)
|
|
72
|
+
return 'Readiness not confirmed';
|
|
73
|
+
return 'Ready';
|
|
74
|
+
}
|
|
75
|
+
export function assessmentContextLabel(assessment) {
|
|
76
|
+
const c = assessment.context;
|
|
77
|
+
return c ? `${c.kind === 'selected_run' ? `selected run ${c.epic_run_id}` : 'repository preview'} (${c.repo_name}; ${c.stage})` : 'assessment context unavailable';
|
|
78
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { composeReadinessAssessment, deriveAdvisoryVerdict } from './readiness-assessment.js';
|
|
2
|
+
import { localReadinessFacts } from './readiness.js';
|
|
1
3
|
/**
|
|
2
4
|
* The `epic-implementer readiness` command surface (BAPI-1055, AC-6).
|
|
3
5
|
*
|
|
@@ -183,6 +185,8 @@ async function collectProductionReport(repoRoot, env, baseUrl, epicRunId) {
|
|
|
183
185
|
});
|
|
184
186
|
}
|
|
185
187
|
const access = accessResult.ok ? accessResult.access : null;
|
|
188
|
+
// Legacy rows retain their confirmed repository default. Version-1
|
|
189
|
+
// applicability is carried independently by the negotiated assessment.
|
|
186
190
|
const reviewPolicySource = await resolveReadinessReviewPolicySource(access);
|
|
187
191
|
return collectConductorReadinessGate({
|
|
188
192
|
// Never guessed: an unresolved identity is reported as such rather than
|
|
@@ -197,6 +201,7 @@ async function collectProductionReport(repoRoot, env, baseUrl, epicRunId) {
|
|
|
197
201
|
// `verdict_protocol` whenever that cannot be established. This is a
|
|
198
202
|
// prospective assessment, not a prediction or authorization of any run.
|
|
199
203
|
reviewPolicySource,
|
|
204
|
+
assessmentVersion: 1,
|
|
200
205
|
// BAPI-1465: an explicit run id also scopes the effective-review-mode row.
|
|
201
206
|
...(epicRunId !== undefined ? { epicRunId } : {}),
|
|
202
207
|
readWorkflowFile: () => fsReadFile(claudeReviewWorkflowPath(repoRoot), "utf-8"),
|
|
@@ -255,6 +260,11 @@ export async function runConductorReadinessCommand(argv, deps = {}) {
|
|
|
255
260
|
const collect = deps.collect ??
|
|
256
261
|
((repoRoot) => collectProductionReport(repoRoot, env, parsed.baseUrl, parsed.epicRunId));
|
|
257
262
|
const report = await collect(cwd);
|
|
263
|
+
report.assessmentNegotiation ??= { status: 'unavailable' };
|
|
264
|
+
if (report.assessmentNegotiation.status === 'available') {
|
|
265
|
+
report.assessment = report.assessmentNegotiation.assessment;
|
|
266
|
+
report.advisoryVerdict = deriveAdvisoryVerdict(composeReadinessAssessment(report.assessmentNegotiation, localReadinessFacts(report.checks)));
|
|
267
|
+
}
|
|
258
268
|
// Fixed, sanitized, and stderr-only: never a credential, exception, header,
|
|
259
269
|
// body, subprocess output, or absolute path. It fires on a COLLECTION gap,
|
|
260
270
|
// not on a failed prerequisite — a report that says "a source is missing"
|
|
@@ -39,3 +39,56 @@ export function formatReadinessPrerequisites(items, options = {}) {
|
|
|
39
39
|
const state = { met: 'Met', not_met: 'Not met', unknown: "Couldn't check", not_applicable: 'Not applicable' };
|
|
40
40
|
return [verdict, ...selected.flatMap(p => [` ${p.label}: ${state[p.check_status]}`, ...(p.fix && ['not_met', 'unknown'].includes(p.check_status) ? [` ${p.fix}`] : [])])];
|
|
41
41
|
}
|
|
42
|
+
/** The explicit assessment path never derives policy from legacy text. */
|
|
43
|
+
export { composeReadinessAssessment, deriveAdvisoryVerdict } from './readiness-assessment.js';
|
|
44
|
+
import { assessmentGroups, assessmentContextLabel, deriveAdvisoryVerdict as advisoryVerdict } from './readiness-assessment.js';
|
|
45
|
+
import { assessmentRemedyQuestion } from '../printed-remedy-commands.js';
|
|
46
|
+
import { renderSetupQuestion } from '../setup-question.js';
|
|
47
|
+
export function formatReadinessAssessment(assessment, options = {}) {
|
|
48
|
+
const lines = [`Assessment: ${assessmentContextLabel(assessment)} (advisory only)`];
|
|
49
|
+
if (assessment.negotiation !== 'available')
|
|
50
|
+
lines.push(assessment.negotiation === 'unsupported'
|
|
51
|
+
? 'Version-1 assessment unsupported. Upgrade the Bridge backend or contact Bridge support; mandatory coverage remains unconfirmed.'
|
|
52
|
+
: 'Assessment unavailable. Retry readiness or contact Bridge support; mandatory coverage remains unconfirmed.');
|
|
53
|
+
const g = assessmentGroups(assessment);
|
|
54
|
+
const label = (id) => READINESS_PREREQUISITE_BY_ID.get(id)?.label ?? { 'server.canonical-index': 'Canonical index validity', 'server.parse-progress': 'Parse progress' }[id] ?? id;
|
|
55
|
+
const render = (record) => {
|
|
56
|
+
const evidence = `${label(record.id)} [${record.scope}${record.inspected_sha ? ` @ ${record.inspected_sha}` : '; revision unknown'}]: ${record.applicability === 'policy_inapplicable' ? `policy-inapplicable (${record.basis})` : `${record.observed_state}; ${record.applicability} (${record.basis})`}`;
|
|
57
|
+
lines.push(` ${evidence}`);
|
|
58
|
+
if (!options.initial && record.blocking_effect !== 'none')
|
|
59
|
+
lines.push(renderSetupQuestion(assessmentRemedyQuestion(record.remedy, [evidence])));
|
|
60
|
+
};
|
|
61
|
+
if (options.initial) {
|
|
62
|
+
lines.push('Current observations; setup work is in progress.');
|
|
63
|
+
assessment.records.forEach(render);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
if (g.blockers.length || g.localBlockers.length) {
|
|
67
|
+
lines.push('Mandatory blockers');
|
|
68
|
+
g.blockers.forEach(render);
|
|
69
|
+
g.localBlockers.forEach(f => lines.push(` ${f.id}: ${f.observed_state}. Sign in or resolve this local fact, or defer and leave it unresolved; then rerun setup.`));
|
|
70
|
+
}
|
|
71
|
+
if (g.unresolved.length || g.localUnresolved.length) {
|
|
72
|
+
lines.push('Unresolved mandatory evidence');
|
|
73
|
+
g.unresolved.forEach(render);
|
|
74
|
+
g.localUnresolved.forEach(f => lines.push(` ${f.id}: ${f.observed_state}. Retry this local observation, or defer and keep readiness unconfirmed.`));
|
|
75
|
+
}
|
|
76
|
+
const rest = assessment.records.filter(r => r.blocking_effect === 'none' && (options.all || r.applicability === 'policy_inapplicable' || r.id === 'server.parse-progress'));
|
|
77
|
+
if (rest.length) {
|
|
78
|
+
lines.push('Evidence and diagnostic progress');
|
|
79
|
+
rest.forEach(render);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const indexed = assessment.records.find(r => r.scope === 'indexed_commit')?.inspected_sha;
|
|
83
|
+
const current = assessment.records.find(r => r.scope === 'default_branch')?.inspected_sha;
|
|
84
|
+
lines.push(indexed && current ? (indexed === current ? `Workflow observations share revision ${indexed}.` : `Workflow revision mismatch: indexed ${indexed}; default branch ${current}.`) : 'Workflow revision comparison is unknown.');
|
|
85
|
+
const diagnostics = assessment.local.filter(f => f.impact === 'advisory');
|
|
86
|
+
if (diagnostics.length)
|
|
87
|
+
lines.push('Local maintenance observations (not server proof)', ...diagnostics.map(f => ` ${f.id}: ${f.observed_state}`));
|
|
88
|
+
const optional = assessment.local.filter(f => f.impact === 'optional');
|
|
89
|
+
if (!options.initial && optional.length)
|
|
90
|
+
lines.push('Optional capability', ...optional.map(f => ` ${f.id}: ${f.observed_state}. Install a persistent executor for background work, or defer it. Launch still checks its required executor capability independently.`));
|
|
91
|
+
if (!options.initial)
|
|
92
|
+
lines.push(`${advisoryVerdict(assessment)} — ${assessmentContextLabel(assessment)}; advisory only.`);
|
|
93
|
+
return lines;
|
|
94
|
+
}
|