@bridge_gpt/mcp-server 0.2.71 → 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 +55 -17
- package/build/agent-launchers/claude-executor-adapter.js +22 -3
- package/build/agent-notes.js +171 -95
- package/build/agents.generated.js +7 -7
- package/build/bridge-permissions.js +31 -0
- package/build/bridge-worktree-inspection.js +237 -0
- package/build/check-evidence.js +6 -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/claude-review-workflow.js +1 -1
- package/build/cli-help.js +6 -0
- package/build/codex-auto-recovery.js +126 -0
- package/build/codex-launcher-pin.js +33 -2
- package/build/codex-skill-adapter.js +5 -1
- package/build/command-host.js +33 -0
- package/build/commands.generated.js +7 -6
- package/build/conductor/bridge-api-client.js +1352 -50
- 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 +187 -28
- 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 +213 -13
- 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 +281 -10
- package/build/conductor/gate-settings-review.js +525 -5
- 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 +6 -53
- package/build/conductor/launch-plan.js +318 -121
- 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/prerequisite-inputs.js +1213 -0
- package/build/conductor/readiness-assessment.js +93 -0
- package/build/conductor/readiness-cli.js +30 -9
- package/build/conductor/readiness-prerequisites.js +77 -5
- package/build/conductor/readiness-sections.js +146 -126
- package/build/conductor/readiness.js +21 -3
- package/build/conductor/recovery-cli.js +236 -15
- package/build/conductor/recovery-operations.js +34 -4
- package/build/conductor/repair-contract.js +33 -0
- package/build/conductor/tools.js +36 -4
- package/build/conductor/wait-run-attention.js +115 -0
- package/build/conductor/wait-run-cli.js +300 -21
- package/build/conductor/worker-database-doctor-inspector.js +34 -2
- package/build/conductor/worker-setup-tally.js +27 -0
- package/build/credential-store.js +96 -21
- package/build/dependency-install-declarations.js +212 -0
- package/build/docs.generated.js +4 -4
- package/build/doctor.js +91 -8
- package/build/drive-epic-help.js +23 -4
- package/build/drive-epic.js +1841 -340
- 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 +2184 -52
- package/build/epic-launch-context.js +607 -0
- package/build/epic-launch-profile.js +1 -1
- 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/cli.js +2 -0
- package/build/executor/completion-contract.js +24 -1
- 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 +119 -17
- package/build/executor/epic-server-context.js +141 -0
- package/build/executor/gate-qualification-job.js +127 -26
- package/build/executor/harness-coverage.js +19 -0
- package/build/executor/http-client.js +87 -6
- package/build/executor/index.js +2 -1
- package/build/executor/install-preflight.js +1 -1
- package/build/executor/job-runner.js +659 -87
- package/build/executor/likely-tests.js +94 -97
- package/build/executor/observation.js +8 -0
- package/build/executor/pre-pr-checks.js +363 -0
- package/build/executor/prompt-spec.js +127 -5
- package/build/executor/reconcile-overlap-job.js +5 -3
- package/build/executor/required-verification.js +28 -0
- package/build/executor/required-work-diagnostics.js +32 -0
- package/build/executor/required-work-ledger.js +955 -39
- package/build/executor/results.js +100 -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/terminal-mutation.js +8 -0
- package/build/executor/test-clock.js +3 -0
- package/build/executor/verification-hints.js +179 -0
- package/build/executor/worker-command.js +126 -5
- package/build/executor/worker-database-config.js +281 -0
- package/build/executor/worker-database-target.js +16 -12
- package/build/executor/worker-database.js +575 -116
- package/build/executor/worker-finalization.js +71 -10
- package/build/executor/worker-guard-hook.js +10 -2
- package/build/executor/worker-resources.js +25 -3
- package/build/executor/worker-verification-guidance.js +55 -5
- package/build/executor/worktree-inspection.js +42 -0
- package/build/executor/worktree.js +20 -1
- package/build/executor-launch.js +54 -2
- package/build/generated-assets-catalog.js +2 -2
- package/build/github-sign-in.js +1 -1
- package/build/index.js +1111 -381
- package/build/init.js +29 -14
- 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 +1383 -188
- package/build/install-bridge-conductor-setup.js +637 -92
- package/build/install-bridge-conductor.js +3163 -740
- package/build/install-bridge.js +601 -128
- package/build/install-maintenance.js +127 -0
- package/build/install-reexec.js +1 -1
- package/build/launcher-config-inspection.js +162 -1
- package/build/local-cleanup.js +59 -0
- 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-install-state.js +68 -2
- 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 +236 -111
- 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-discovery.js +97 -4
- package/build/plan-execution-ledger.js +248 -9
- 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 +23 -7
- package/build/plane/preflight.js +50 -10
- package/build/plane/shutdown.js +19 -0
- package/build/plane/terminal-run-cleanup.js +23 -5
- package/build/plane/terminal-run-status.js +4 -0
- package/build/printed-remedy-commands.js +229 -15
- package/build/readiness-check.js +1 -1
- package/build/readiness-prerequisites.generated.js +311 -4
- package/build/readme.generated.js +1 -1
- package/build/repository-state-paths.js +38 -0
- package/build/repository-toolchains.js +50 -8
- package/build/run-unit-tests-launcher.js +8 -1
- package/build/setup-change-policy.js +32 -0
- package/build/setup-epic.js +1192 -198
- package/build/setup-progress.js +44 -0
- package/build/setup-question.js +180 -0
- package/build/start-tickets.js +4 -0
- package/build/test-command-detection.js +32 -88
- package/build/test-support/notes-fs.js +40 -0
- package/build/third-party-mcp-targets.js +30 -0
- package/build/ticket-delivery-enrollment.js +30 -8
- package/build/ticket-delivery-run-scope.js +128 -0
- package/build/upgrade-cli.js +85 -2
- package/build/v2-readiness-requirements.js +28 -1
- 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-INSTALL.md +9 -1
- package/docs/EPIC-IMPLEMENTER.md +5 -0
- package/docs/epic-implementer/getting-started.md +42 -15
- package/docs/epic-implementer/self-hosting.md +14 -1
- package/package.json +2 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sanitizeHarnessCoverage } from "../executor/harness-coverage.js";
|
|
1
2
|
import { monotonicNow, elapsedMs } from "./precheck-timings.js";
|
|
2
3
|
/**
|
|
3
4
|
* Combined, strictly read-only epic-implementer doctor report (BAPI-395, BAPI-418).
|
|
@@ -85,7 +86,7 @@ export const DENY_ENFORCEMENT_SKIP_REMEDIATION = "run `epic-implementer doctor`
|
|
|
85
86
|
/** Explicit display value for an unset `BRIDGE_MCP_PROFILE`. */
|
|
86
87
|
export const MCP_PROFILE_UNSET = "(unset)";
|
|
87
88
|
/** BAPI-1461: the printed setup command, used in stored-token remedies. */
|
|
88
|
-
const PRINTED_SETUP_COMMAND = `npx -y ${MCP_PACKAGE_NAME} install
|
|
89
|
+
const PRINTED_SETUP_COMMAND = `npx -y ${MCP_PACKAGE_NAME} install epic-implementer`;
|
|
89
90
|
/** BAPI-1461: the fix for a stored token GitHub rejected. */
|
|
90
91
|
export const STORED_MERGE_TOKEN_REJECTED_REMEDIATION = `replace the stored merge token: run \`${PRINTED_SETUP_COMMAND}\` and accept the offer to ` +
|
|
91
92
|
`replace it, or remove it with \`${PRINTED_SETUP_COMMAND} --remove-merge-token\`.`;
|
|
@@ -162,6 +163,48 @@ export const WORKER_DATABASE_DOCTOR_OWNER = "host operator";
|
|
|
162
163
|
export const WORKER_DATABASE_DOCTOR_TIMEOUT_MS = 20_000;
|
|
163
164
|
/** Maximum validated names listed per inventory group; the rest are counted. */
|
|
164
165
|
export const WORKER_DATABASE_DOCTOR_NAME_LIMIT = 20;
|
|
166
|
+
const MIGRATION_CAUSE_LABELS = {
|
|
167
|
+
multiple_heads: "Multiple heads",
|
|
168
|
+
revision_missing: "Missing revision",
|
|
169
|
+
ssl_refused: "SSL refused",
|
|
170
|
+
connection_refused: "Connection refused",
|
|
171
|
+
permission_denied: "Permission denied",
|
|
172
|
+
timeout: "Timed out",
|
|
173
|
+
other: "Other failure",
|
|
174
|
+
};
|
|
175
|
+
/** Most owner roles ever displayed. */
|
|
176
|
+
export const WORKER_DATABASE_DOCTOR_OWNER_ROLE_LIMIT = 5;
|
|
177
|
+
const OWNER_ROLE_PATTERN = /^[A-Za-z_][A-Za-z0-9_$-]{0,62}$/;
|
|
178
|
+
/** True only for a whole-string valid PostgreSQL role name; nothing is trimmed into validity. */
|
|
179
|
+
export function isDisplayableOwnerRole(value) {
|
|
180
|
+
return typeof value === "string" && OWNER_ROLE_PATTERN.test(value);
|
|
181
|
+
}
|
|
182
|
+
/** Revalidate, deduplicate, sort (byte order), and cap an untrusted owner list. */
|
|
183
|
+
export function sanitizeOwnerRoles(value) {
|
|
184
|
+
if (!Array.isArray(value))
|
|
185
|
+
return [];
|
|
186
|
+
const roles = new Set();
|
|
187
|
+
for (const entry of value)
|
|
188
|
+
if (isDisplayableOwnerRole(entry))
|
|
189
|
+
roles.add(entry);
|
|
190
|
+
return [...roles]
|
|
191
|
+
.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0))
|
|
192
|
+
.slice(0, WORKER_DATABASE_DOCTOR_OWNER_ROLE_LIMIT);
|
|
193
|
+
}
|
|
194
|
+
/** Exact owner total when it is a safe integer no smaller than the displayed list; otherwise the list length. */
|
|
195
|
+
export function sanitizeOwnerRoleTotal(value, displayed) {
|
|
196
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= displayed ? value : displayed;
|
|
197
|
+
}
|
|
198
|
+
/** `postgres, ci_owner (+1 more)` — validated roles only. */
|
|
199
|
+
export function formatOwnerRoles(roles, total) {
|
|
200
|
+
const more = total - roles.length;
|
|
201
|
+
return roles.join(", ") + (more > 0 ? ` (+${more} more)` : "");
|
|
202
|
+
}
|
|
203
|
+
function safeMigrationCause(value) {
|
|
204
|
+
return typeof value === "string" && Object.prototype.hasOwnProperty.call(MIGRATION_CAUSE_LABELS, value)
|
|
205
|
+
? value
|
|
206
|
+
: undefined;
|
|
207
|
+
}
|
|
165
208
|
const ROW_STATES = new Set(["healthy", "unsafe", "unknown"]);
|
|
166
209
|
const RETAIN_REASONS = new Set([
|
|
167
210
|
"owner_alive",
|
|
@@ -218,49 +261,107 @@ function makeRow(id, label, state, detail) {
|
|
|
218
261
|
...(state === "healthy" ? {} : { runbook: WORKER_DATABASE_DOCTOR_RUNBOOK_SECTION }),
|
|
219
262
|
};
|
|
220
263
|
}
|
|
221
|
-
|
|
264
|
+
/** The configured role, for technical details; a generic phrase when doctor was not told one. */
|
|
265
|
+
function configuredRole(config) {
|
|
266
|
+
// No declaration passed at all (the launch advisory, which still inspects the
|
|
267
|
+
// Bridge seed): keep the wording it always had. The inspector uses the same seed.
|
|
268
|
+
if (config === undefined)
|
|
269
|
+
return "bridge_epic_worker";
|
|
270
|
+
return config.status === "configured" && config.workerRole ? config.workerRole : "the worker role";
|
|
271
|
+
}
|
|
272
|
+
/** An informational row for a check that does not apply. Nothing was probed. */
|
|
273
|
+
function notConfiguredRow(id, label) {
|
|
274
|
+
return {
|
|
275
|
+
...makeRow(id, label, "healthy", "Not configured — no worker database is expected for this project"),
|
|
276
|
+
not_configured: true,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
/** A row for a declaration that could not be read. Warning treatment; nothing was probed. */
|
|
280
|
+
function unreadableConfigRow(id, label) {
|
|
281
|
+
return makeRow(id, label, "unknown", "Couldn't check — the worker database setting could not be read");
|
|
282
|
+
}
|
|
283
|
+
const NOT_CONFIGURED_LABELS = [
|
|
284
|
+
["worker-db-role", "worker role"],
|
|
285
|
+
["worker-db-boundary", "protected-database boundary"],
|
|
286
|
+
["worker-db-alembic", "operator-checkout Alembic"],
|
|
287
|
+
["worker-db-leftovers", "worker databases"],
|
|
288
|
+
["worker-db-unverifiable", "unverifiable worker databases"],
|
|
289
|
+
["worker-db-harness", "conductor_harness databases"],
|
|
290
|
+
];
|
|
291
|
+
/** True when the declaration says a disposable database is expected and was read. */
|
|
292
|
+
function isDisposableConfig(config) {
|
|
293
|
+
return config?.status === "configured" && config.mode === "disposable_postgres";
|
|
294
|
+
}
|
|
295
|
+
function roleRow(role, config) {
|
|
296
|
+
if (config?.status === "unreadable")
|
|
297
|
+
return unreadableConfigRow("worker-db-role", "worker role");
|
|
298
|
+
if (config !== undefined && !isDisposableConfig(config))
|
|
299
|
+
return notConfiguredRow("worker-db-role", "worker role");
|
|
300
|
+
const name = configuredRole(config);
|
|
222
301
|
const r = (role ?? {});
|
|
223
302
|
let state = safeState(r.state);
|
|
224
303
|
const category = safeCategory(r.category);
|
|
225
304
|
let detail;
|
|
226
305
|
if (state === "healthy") {
|
|
227
|
-
detail =
|
|
306
|
+
detail = `${name} exists with the expected attributes and no elevating memberships`;
|
|
228
307
|
}
|
|
229
308
|
else if (state === "unsafe") {
|
|
230
309
|
detail =
|
|
231
310
|
category === "role_missing"
|
|
232
|
-
?
|
|
233
|
-
:
|
|
311
|
+
? `${name} does not exist`
|
|
312
|
+
: `${name} attributes or memberships differ from the expected least-privilege set`;
|
|
234
313
|
}
|
|
235
314
|
else if (category === "role_missing") {
|
|
236
315
|
// A definitive "missing" answer is actionable, not unknown.
|
|
237
316
|
state = "unsafe";
|
|
238
|
-
detail =
|
|
317
|
+
detail = `${name} does not exist`;
|
|
239
318
|
}
|
|
240
319
|
else {
|
|
241
320
|
detail = `unknown — ${describeUnavailableCategory(category)}`;
|
|
242
321
|
}
|
|
243
322
|
return makeRow("worker-db-role", "worker role", state, detail);
|
|
244
323
|
}
|
|
245
|
-
function boundaryRow(boundary) {
|
|
324
|
+
function boundaryRow(boundary, config) {
|
|
325
|
+
const label = config === undefined ? "bridgeapi boundary" : "protected-database boundary";
|
|
326
|
+
if (config?.status === "unreadable")
|
|
327
|
+
return unreadableConfigRow("worker-db-boundary", label);
|
|
328
|
+
if (config !== undefined && !isDisposableConfig(config))
|
|
329
|
+
return notConfiguredRow("worker-db-boundary", label);
|
|
246
330
|
const b = (boundary ?? {});
|
|
247
331
|
const state = safeState(b.state);
|
|
248
332
|
const category = safeCategory(b.category);
|
|
333
|
+
if (config === undefined) {
|
|
334
|
+
// No declaration passed (the launch advisory still inspects the Bridge seed): the wording it always had.
|
|
335
|
+
const legacy = state === "healthy"
|
|
336
|
+
? "bridge_epic_worker is refused on bridgeapi"
|
|
337
|
+
: state === "unsafe"
|
|
338
|
+
? "UNSAFE — bridge_epic_worker can connect to bridgeapi"
|
|
339
|
+
: `unknown — ${category === "boundary_unknown" ? "the bridgeapi refusal could not be confirmed" : describeUnavailableCategory(category)}`;
|
|
340
|
+
return makeRow("worker-db-boundary", label, state, legacy);
|
|
341
|
+
}
|
|
342
|
+
const name = configuredRole(config);
|
|
343
|
+
const protectedNames = config.protectedDatabases.length > 0 ? config.protectedDatabases.join(", ") : "the protected databases";
|
|
249
344
|
const detail = state === "healthy"
|
|
250
|
-
?
|
|
345
|
+
? `${name} is refused on ${protectedNames}`
|
|
251
346
|
: state === "unsafe"
|
|
252
|
-
?
|
|
253
|
-
: `unknown — ${category === "boundary_unknown" ? "the
|
|
254
|
-
return makeRow("worker-db-boundary",
|
|
347
|
+
? `UNSAFE — ${name} can connect to a protected database (${protectedNames})`
|
|
348
|
+
: `unknown — ${category === "boundary_unknown" ? "the protected-database refusal could not be confirmed" : describeUnavailableCategory(category)}`;
|
|
349
|
+
return makeRow("worker-db-boundary", label, state, detail);
|
|
255
350
|
}
|
|
256
351
|
function alembicRow(alembic) {
|
|
257
|
-
const
|
|
352
|
+
const a = (alembic ?? {});
|
|
353
|
+
const state = safeState(a.state);
|
|
354
|
+
// A cause is meaningful only on an unsafe result; it is dropped everywhere else.
|
|
355
|
+
const cause = state === "unsafe" ? safeMigrationCause(a.cause) : undefined;
|
|
258
356
|
const detail = state === "healthy"
|
|
259
|
-
? "the operator checkout
|
|
357
|
+
? "the operator checkout has one migration head and renders base:head offline " +
|
|
358
|
+
"(no live database connection, object permission, or worker-branch check)"
|
|
260
359
|
: state === "unsafe"
|
|
261
|
-
?
|
|
262
|
-
|
|
263
|
-
|
|
360
|
+
? cause
|
|
361
|
+
? `the operator checkout's offline migration check failed: ${MIGRATION_CAUSE_LABELS[cause]} (cause: ${cause})`
|
|
362
|
+
: "the operator checkout's migration launcher is missing"
|
|
363
|
+
: "unknown — the operator checkout's offline migration check is not declared or could not be completed";
|
|
364
|
+
return { ...makeRow("worker-db-alembic", "operator-checkout Alembic", state, detail), ...(cause ? { cause } : {}) };
|
|
264
365
|
}
|
|
265
366
|
function safeNameList(value, redacted) {
|
|
266
367
|
if (!Array.isArray(value))
|
|
@@ -284,7 +385,7 @@ function sanitizeInventory(inventory) {
|
|
|
284
385
|
!Array.isArray(value.leftovers) ||
|
|
285
386
|
!Array.isArray(value.unverifiable) ||
|
|
286
387
|
typeof value.harnessCount !== "number" ||
|
|
287
|
-
!Number.
|
|
388
|
+
!Number.isSafeInteger(value.harnessCount) ||
|
|
288
389
|
value.harnessCount < 0) {
|
|
289
390
|
return { state: "unknown" };
|
|
290
391
|
}
|
|
@@ -303,15 +404,37 @@ function sanitizeInventory(inventory) {
|
|
|
303
404
|
: "unrecognized";
|
|
304
405
|
unverifiable.push({ name: e.name, reason });
|
|
305
406
|
}
|
|
407
|
+
const harnessOwners = sanitizeOwnerRoles(value.harnessOwners);
|
|
306
408
|
return {
|
|
307
409
|
state: "known",
|
|
308
410
|
active,
|
|
309
411
|
leftovers,
|
|
310
412
|
unverifiable,
|
|
311
413
|
harness_count: value.harnessCount,
|
|
414
|
+
...(sanitizeHarnessCoverage(value.harnessCoverage, value.harnessCount)
|
|
415
|
+
? { harness_coverage: sanitizeHarnessCoverage(value.harnessCoverage, value.harnessCount) } : {}),
|
|
416
|
+
harness_owners: harnessOwners,
|
|
417
|
+
harness_owner_total: sanitizeOwnerRoleTotal(value.harnessOwnerCount, harnessOwners.length),
|
|
312
418
|
redacted_count: redacted.count,
|
|
313
419
|
};
|
|
314
420
|
}
|
|
421
|
+
function harnessRow(inventory) {
|
|
422
|
+
const healthy = inventory.harness_count === 0;
|
|
423
|
+
const owners = healthy ? [] : inventory.harness_owners;
|
|
424
|
+
const coverage = inventory.harness_coverage;
|
|
425
|
+
const coverageClause = coverage?.activity === "known"
|
|
426
|
+
? `; ${coverage.covered} in use or CI-owned; ${coverage.uncovered} uncovered; activity known ` +
|
|
427
|
+
`(overlapping categories: ${coverage.inUse} in use, ${coverage.ciOwned} CI-owned)`
|
|
428
|
+
: "; activity unknown";
|
|
429
|
+
const ownerClause = owners.length > 0
|
|
430
|
+
? `; owners shown: ${formatOwnerRoles(owners, inventory.harness_owner_total)} — ` +
|
|
431
|
+
"drop as the owning role, not the CI role (see the harness reaper and owner-role guidance in the runbook)"
|
|
432
|
+
: "";
|
|
433
|
+
const row = makeRow("worker-db-harness", "conductor_harness databases", healthy ? "healthy" : "unsafe", `${inventory.harness_count} present (owned by the Python harness reaper; the executor never cleans them)` +
|
|
434
|
+
coverageClause + ownerClause);
|
|
435
|
+
return { ...row, ...(coverage ? { harness_coverage: coverage } : {}),
|
|
436
|
+
...(owners.length > 0 ? { owner_roles: owners, owner_role_total: inventory.harness_owner_total } : {}) };
|
|
437
|
+
}
|
|
315
438
|
function inventoryRows(inventory) {
|
|
316
439
|
if (inventory.state === "unknown") {
|
|
317
440
|
const detail = "unknown — the database inventory could not be read";
|
|
@@ -329,11 +452,26 @@ function inventoryRows(inventory) {
|
|
|
329
452
|
"(dead executor on this host; the next executor start sweeps them)"),
|
|
330
453
|
makeRow("worker-db-unverifiable", "unverifiable worker databases", unverifiableCount === 0 ? "healthy" : "unsafe", `${unverifiableCount} with unreadable, malformed, foreign-host, or unknown ownership ` +
|
|
331
454
|
"(left in place; review manually)"),
|
|
332
|
-
|
|
455
|
+
harnessRow(inventory),
|
|
333
456
|
];
|
|
334
457
|
}
|
|
335
458
|
/** Project a (possibly hostile or malformed) inspection into the sanitized advisory section. */
|
|
336
|
-
export function buildWorkerDatabaseDoctorSection(inspection) {
|
|
459
|
+
export function buildWorkerDatabaseDoctorSection(inspection, config) {
|
|
460
|
+
// BAPI-1598: a declaration that says no database is expected, or that could not
|
|
461
|
+
// be read, never reaches an inspection — every row says so and nothing is probed.
|
|
462
|
+
if (config !== undefined && !isDisposableConfig(config)) {
|
|
463
|
+
const unreadable = config.status === "unreadable";
|
|
464
|
+
return {
|
|
465
|
+
advisory: true,
|
|
466
|
+
owner: WORKER_DATABASE_DOCTOR_OWNER,
|
|
467
|
+
runbook: WORKER_DATABASE_DOCTOR_RUNBOOK_SECTION,
|
|
468
|
+
rows: NOT_CONFIGURED_LABELS.map(([id, label]) => ({
|
|
469
|
+
...(unreadable ? unreadableConfigRow(id, label) : notConfiguredRow(id, label)),
|
|
470
|
+
duration_ms: 0,
|
|
471
|
+
})),
|
|
472
|
+
inventory: { state: "unknown" },
|
|
473
|
+
};
|
|
474
|
+
}
|
|
337
475
|
const insp = (inspection ?? {});
|
|
338
476
|
const inventory = inspection ? sanitizeInventory(insp.inventory) : { state: "unknown" };
|
|
339
477
|
return {
|
|
@@ -341,8 +479,8 @@ export function buildWorkerDatabaseDoctorSection(inspection) {
|
|
|
341
479
|
owner: WORKER_DATABASE_DOCTOR_OWNER,
|
|
342
480
|
runbook: WORKER_DATABASE_DOCTOR_RUNBOOK_SECTION,
|
|
343
481
|
rows: [
|
|
344
|
-
roleRow(insp.role),
|
|
345
|
-
boundaryRow(insp.boundary),
|
|
482
|
+
roleRow(insp.role, config),
|
|
483
|
+
boundaryRow(insp.boundary, config),
|
|
346
484
|
alembicRow(insp.alembic),
|
|
347
485
|
...inventoryRows(inventory),
|
|
348
486
|
].map((row) => ({ ...row, duration_ms: inspection?.timings?.[row.id] ?? elapsedMs(monotonicNow()) })),
|
|
@@ -358,10 +496,14 @@ export function buildWorkerDatabaseDoctorSection(inspection) {
|
|
|
358
496
|
* `timeout`/`error` classification — never the thrown value — so a caller can
|
|
359
497
|
* say that the inspection failed without echoing exception text.
|
|
360
498
|
*/
|
|
361
|
-
export async function collectWorkerDatabaseDoctorSection(inspect, timeoutMs = WORKER_DATABASE_DOCTOR_TIMEOUT_MS, onFailure) {
|
|
499
|
+
export async function collectWorkerDatabaseDoctorSection(inspect, timeoutMs = WORKER_DATABASE_DOCTOR_TIMEOUT_MS, onFailure, config) {
|
|
500
|
+
// BAPI-1598: nothing to inspect when no database is expected or the setting is unreadable.
|
|
501
|
+
if (config !== undefined && !isDisposableConfig(config)) {
|
|
502
|
+
return buildWorkerDatabaseDoctorSection(null, config);
|
|
503
|
+
}
|
|
362
504
|
const started = monotonicNow();
|
|
363
505
|
const failedSection = () => {
|
|
364
|
-
const section = buildWorkerDatabaseDoctorSection(null);
|
|
506
|
+
const section = buildWorkerDatabaseDoctorSection(null, config);
|
|
365
507
|
return { ...section, rows: section.rows.map((row) => ({ ...row, duration_ms: elapsedMs(started) })) };
|
|
366
508
|
};
|
|
367
509
|
let timer;
|
|
@@ -370,10 +512,10 @@ export async function collectWorkerDatabaseDoctorSection(inspect, timeoutMs = WO
|
|
|
370
512
|
timer = setTimeout(() => resolve(null), timeoutMs);
|
|
371
513
|
timer.unref?.();
|
|
372
514
|
});
|
|
373
|
-
const inspection = await Promise.race([Promise.resolve().then(inspect), timeout]);
|
|
515
|
+
const inspection = await Promise.race([Promise.resolve().then(() => inspect(config)), timeout]);
|
|
374
516
|
if (inspection === null)
|
|
375
517
|
onFailure?.("timeout");
|
|
376
|
-
return inspection === null ? failedSection() : buildWorkerDatabaseDoctorSection(inspection);
|
|
518
|
+
return inspection === null ? failedSection() : buildWorkerDatabaseDoctorSection(inspection, config);
|
|
377
519
|
}
|
|
378
520
|
catch {
|
|
379
521
|
onFailure?.("error");
|
|
@@ -406,6 +548,10 @@ export function formatWorkerDatabaseDoctorSection(section) {
|
|
|
406
548
|
lines.push("──────────────────────────────────────");
|
|
407
549
|
for (const row of section.rows) {
|
|
408
550
|
const state = safeState(row.state);
|
|
551
|
+
if (row.not_configured === true) {
|
|
552
|
+
lines.push(`${row.label.padEnd(30)} [INFO] ${row.detail}`);
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
409
555
|
lines.push(`${row.label.padEnd(30)} ${WORKER_DB_STATE_TAG[state]} ${state} — ${row.detail}`);
|
|
410
556
|
if (state !== "healthy") {
|
|
411
557
|
lines.push(` → ${WORKER_DATABASE_DOCTOR_OWNER}: see ${WORKER_DATABASE_DOCTOR_RUNBOOK_SECTION}`);
|
|
@@ -430,7 +576,8 @@ export function formatWorkerDatabaseDoctorSection(section) {
|
|
|
430
576
|
* therefore resolve credentials themselves (CLAUDE.md "Shell-Spawned Credential
|
|
431
577
|
* Resolution"): the four BAPI-872 recovery verbs, the six run-addressed repair
|
|
432
578
|
* verbs (BAPI-1154's three and BAPI-1176's three), and BAPI-1300's parked-child
|
|
433
|
-
* continuation pair
|
|
579
|
+
* continuation pair, BAPI-1557's `prerequisite-inputs`, and BAPI-1642's driver-supervision
|
|
580
|
+
* commands. `.mcp.json` env is invisible to
|
|
434
581
|
* them — only `BAPI_API_KEY` in the parent env and the user-scoped credential
|
|
435
582
|
* store count.
|
|
436
583
|
*/
|
|
@@ -450,6 +597,13 @@ export const CREDENTIALED_RECOVERY_COMMANDS = [
|
|
|
450
597
|
"continuation-receipt",
|
|
451
598
|
// BAPI-1469: the read-only bounded wait on a run's state.
|
|
452
599
|
"wait-run",
|
|
600
|
+
// BAPI-1557: reads stored tickets and writes private local scanner inputs.
|
|
601
|
+
"prerequisite-inputs",
|
|
602
|
+
// BAPI-1642: driver supervision. The Stop-hook guard itself resolves nothing;
|
|
603
|
+
// its detached lapse FYI goes through `escalate`.
|
|
604
|
+
"driver-register",
|
|
605
|
+
"driver-release",
|
|
606
|
+
"declare-blocked",
|
|
453
607
|
];
|
|
454
608
|
/** Remediation for recovery/repair verbs that cannot resolve Bridge credentials. */
|
|
455
609
|
export const REPAIR_CREDENTIAL_REMEDIATION = "export BAPI_API_KEY in the shell that runs `conductor`, or store a credential for this " +
|
|
@@ -1131,8 +1285,12 @@ export async function buildConductorDoctorReport(deps = {}) {
|
|
|
1131
1285
|
const command_drift = deps.inspectCommandDrift
|
|
1132
1286
|
? await inspectCommandDriftSafe(deps.inspectCommandDrift)
|
|
1133
1287
|
: undefined;
|
|
1288
|
+
let workerDatabaseConfig;
|
|
1289
|
+
if (deps.inspectWorkerDatabase && deps.readWorkerDatabaseConfig) {
|
|
1290
|
+
workerDatabaseConfig = await deps.readWorkerDatabaseConfig().catch(() => ({ status: "unreadable" }));
|
|
1291
|
+
}
|
|
1134
1292
|
const worker_database = deps.inspectWorkerDatabase
|
|
1135
|
-
? await collectWorkerDatabaseDoctorSection(deps.inspectWorkerDatabase, deps.workerDatabaseTimeoutMs ?? WORKER_DATABASE_DOCTOR_TIMEOUT_MS)
|
|
1293
|
+
? await collectWorkerDatabaseDoctorSection(deps.inspectWorkerDatabase, deps.workerDatabaseTimeoutMs ?? WORKER_DATABASE_DOCTOR_TIMEOUT_MS, undefined, workerDatabaseConfig)
|
|
1136
1294
|
: undefined;
|
|
1137
1295
|
return {
|
|
1138
1296
|
ledger,
|
|
@@ -1449,7 +1607,8 @@ export const CONDUCTOR_LEDGER_REMEDIATION = "run `epic-implementer doctor` for t
|
|
|
1449
1607
|
"owner-only permissions; the ledger is local observability and never blocks a run.";
|
|
1450
1608
|
/** Remediation for degraded or missing managed git hooks. */
|
|
1451
1609
|
export const CONDUCTOR_GIT_HOOKS_REMEDIATION = "run `epic-implementer install-git-hooks` from a persistent install to install the managed post-commit and " +
|
|
1452
|
-
"reference-transaction hooks;
|
|
1610
|
+
"reference-transaction hooks; use `epic-implementer uninstall-git-hooks` for consented removal. " +
|
|
1611
|
+
"They are local, opportunistic, and bypassable, and never gate engine admission.";
|
|
1453
1612
|
/** Remediation for a Claude login this host cannot confirm. */
|
|
1454
1613
|
export const CONDUCTOR_CLAUDE_LOGIN_REMEDIATION = "run `claude login` on the host that will run conductor workers; Bridge stores no Anthropic " +
|
|
1455
1614
|
"credential and can only advise here.";
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one rendering of every command the driver guard prints or recognizes
|
|
3
|
+
* (BAPI-1642): the registered waiter, the `declare-blocked` template, and the
|
|
4
|
+
* `driver-release` exits.
|
|
5
|
+
*
|
|
6
|
+
* The launcher prefix is the same value the project permission rules are
|
|
7
|
+
* written for ({@link resolvePermissionLauncher}): `npx -y @bridge_gpt/mcp-server`
|
|
8
|
+
* by default, or a validated `BAPI_MCP_CLI`. The prefix stays unquoted so the
|
|
9
|
+
* printed command matches those exact-prefix rules; every argument value is
|
|
10
|
+
* single-quoted.
|
|
11
|
+
*
|
|
12
|
+
* RECOGNITION. The Stop hook compares a running task's `command` with the
|
|
13
|
+
* registered waiter byte for byte (`waiter_verified`). Investigation 4 found that
|
|
14
|
+
* Claude Code 2.1.312 reports the command exactly as the agent ran it, quotes
|
|
15
|
+
* included. {@link parseWaiterInvocation} is a deliberately small tokenizer for
|
|
16
|
+
* the near-miss case (`waiter_unrecognized`): plain words and single- or
|
|
17
|
+
* double-quoted words only. Anything with shell operators, substitutions, or
|
|
18
|
+
* escapes is not parsed, never guessed at.
|
|
19
|
+
*/
|
|
20
|
+
import { resolvePermissionLauncher } from "../bridge-permissions.js";
|
|
21
|
+
/** The `--max-minutes` every registered waiter uses. */
|
|
22
|
+
export const DRIVER_WAITER_MAX_MINUTES = 20;
|
|
23
|
+
/** Quote one argument value for a POSIX shell. Values here never contain `'`. */
|
|
24
|
+
export function shellQuote(value) {
|
|
25
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The launcher prefix, or `null` when `BAPI_MCP_CLI` is set but unusable (a
|
|
29
|
+
* quote, a shell operator, or a credential-like value). A null launcher means no
|
|
30
|
+
* waiter can be printed, so registration refuses to arm.
|
|
31
|
+
*/
|
|
32
|
+
export function resolveDriverLauncher(env) {
|
|
33
|
+
const resolved = resolvePermissionLauncher(env);
|
|
34
|
+
return resolved.ok ? resolved.prefix : null;
|
|
35
|
+
}
|
|
36
|
+
/** The exact registered waiter command. */
|
|
37
|
+
export function renderWaiterCommand(launcher, epicRunId, generation) {
|
|
38
|
+
return `${launcher} epic-implementer wait-run --epic-run-id ${shellQuote(epicRunId)} --watch ` +
|
|
39
|
+
`--max-minutes ${DRIVER_WAITER_MAX_MINUTES} --driver-generation ${shellQuote(generation)} --json`;
|
|
40
|
+
}
|
|
41
|
+
/** The unregistered watch waiter, for a host or session with no registration. */
|
|
42
|
+
export function renderPlainWaiterCommand(launcher, epicRunId) {
|
|
43
|
+
return `${launcher} epic-implementer wait-run --epic-run-id ${shellQuote(epicRunId)} --watch ` +
|
|
44
|
+
`--max-minutes ${DRIVER_WAITER_MAX_MINUTES} --json`;
|
|
45
|
+
}
|
|
46
|
+
/** The `declare-blocked` template the block message names; `<…>` are the driver's inputs. */
|
|
47
|
+
export function renderDeclareBlockedTemplate(launcher, epicRunId) {
|
|
48
|
+
return `${launcher} epic-implementer declare-blocked --epic-run-id ${shellQuote(epicRunId)} ` +
|
|
49
|
+
"--ticket-key <TICKET> --entry <1|2|3|4|5|wedge> --requirement '<what is needed>' " +
|
|
50
|
+
"--evidence '<current evidence>' --tried '<verbs already run>'";
|
|
51
|
+
}
|
|
52
|
+
/** One `driver-release` exit. `--reason` comes first so permission rules can tell them apart. */
|
|
53
|
+
export function renderReleaseCommand(launcher, reason, epicRunId) {
|
|
54
|
+
return `${launcher} epic-implementer driver-release --reason ${reason} --epic-run-id ${shellQuote(epicRunId)}`;
|
|
55
|
+
}
|
|
56
|
+
/** A `wait-run` result token (change mode `v1:`, attention mode `a1:`). */
|
|
57
|
+
const WAITER_SINCE_TOKEN = /^(?:v1|a1):[0-9a-f]{16}$/;
|
|
58
|
+
/**
|
|
59
|
+
* True when `command` is the registered waiter exactly, or exactly the
|
|
60
|
+
* registered waiter followed by ` --since '<token>'` with a valid token. The
|
|
61
|
+
* prompt passes the previous result's token on every re-arm, so this is the one
|
|
62
|
+
* structured variant the exact match accepts; nothing else is loosened.
|
|
63
|
+
*/
|
|
64
|
+
export function isRegisteredWaiterCommand(command, waiterCommand) {
|
|
65
|
+
if (command === waiterCommand)
|
|
66
|
+
return true;
|
|
67
|
+
const prefix = `${waiterCommand} --since `;
|
|
68
|
+
if (!command.startsWith(prefix))
|
|
69
|
+
return false;
|
|
70
|
+
const rest = command.slice(prefix.length);
|
|
71
|
+
const token = rest.startsWith("'") && rest.endsWith("'") && rest.length > 2 ? rest.slice(1, -1) : rest;
|
|
72
|
+
return WAITER_SINCE_TOKEN.test(token);
|
|
73
|
+
}
|
|
74
|
+
/** At most this many characters of a task command are parsed. */
|
|
75
|
+
const MAX_PARSED_COMMAND_CHARS = 1000;
|
|
76
|
+
/** A word that needs no quoting and carries no shell meaning. */
|
|
77
|
+
const PLAIN_WORD = /^[A-Za-z0-9_@%+=:,./-]+$/;
|
|
78
|
+
/**
|
|
79
|
+
* Split a command into words, accepting only plain words and whole single- or
|
|
80
|
+
* double-quoted words with no escapes, expansions or operators inside. Returns
|
|
81
|
+
* `null` for anything else.
|
|
82
|
+
*/
|
|
83
|
+
export function tokenizeSimpleCommand(command) {
|
|
84
|
+
if (command.length === 0 || command.length > MAX_PARSED_COMMAND_CHARS)
|
|
85
|
+
return null;
|
|
86
|
+
const words = [];
|
|
87
|
+
for (const raw of command.trim().split(/[ \t]+/)) {
|
|
88
|
+
if (raw.length === 0)
|
|
89
|
+
continue;
|
|
90
|
+
if (raw.length >= 2 && raw.startsWith("'") && raw.endsWith("'")) {
|
|
91
|
+
const inner = raw.slice(1, -1);
|
|
92
|
+
if (inner.includes("'"))
|
|
93
|
+
return null;
|
|
94
|
+
words.push(inner);
|
|
95
|
+
}
|
|
96
|
+
else if (raw.length >= 2 && raw.startsWith("\"") && raw.endsWith("\"")) {
|
|
97
|
+
const inner = raw.slice(1, -1);
|
|
98
|
+
if (/["$`\\]/.test(inner))
|
|
99
|
+
return null;
|
|
100
|
+
words.push(inner);
|
|
101
|
+
}
|
|
102
|
+
else if (PLAIN_WORD.test(raw)) {
|
|
103
|
+
words.push(raw);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return words.length > 0 ? words : null;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Parse a task command as a `wait-run` invocation and return the run id and
|
|
113
|
+
* generation it names, or `null` when it is not a parseable `epic-implementer
|
|
114
|
+
* wait-run` call carrying both `--epic-run-id` and `--driver-generation`.
|
|
115
|
+
*/
|
|
116
|
+
export function parseWaiterInvocation(command) {
|
|
117
|
+
const words = tokenizeSimpleCommand(command);
|
|
118
|
+
if (!words)
|
|
119
|
+
return null;
|
|
120
|
+
const at = words.indexOf("epic-implementer");
|
|
121
|
+
if (at < 0 || words[at + 1] !== "wait-run")
|
|
122
|
+
return null;
|
|
123
|
+
let epicRunId;
|
|
124
|
+
let generation;
|
|
125
|
+
for (let i = at + 2; i < words.length; i += 1) {
|
|
126
|
+
const word = words[i];
|
|
127
|
+
const [name, inline] = word.includes("=") ? [word.slice(0, word.indexOf("=")), word.slice(word.indexOf("=") + 1)] : [word, undefined];
|
|
128
|
+
if (name !== "--epic-run-id" && name !== "--driver-generation")
|
|
129
|
+
continue;
|
|
130
|
+
const value = inline ?? words[i + 1];
|
|
131
|
+
if (inline === undefined)
|
|
132
|
+
i += 1;
|
|
133
|
+
if (value === undefined)
|
|
134
|
+
return null;
|
|
135
|
+
if (name === "--epic-run-id")
|
|
136
|
+
epicRunId = value;
|
|
137
|
+
else
|
|
138
|
+
generation = value;
|
|
139
|
+
}
|
|
140
|
+
return epicRunId !== undefined && generation !== undefined ? { epicRunId, generation } : null;
|
|
141
|
+
}
|