@bridge_gpt/mcp-server 0.2.71 → 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.
Files changed (116) hide show
  1. package/README.md +55 -17
  2. package/build/agent-launchers/claude-executor-adapter.js +19 -3
  3. package/build/agent-notes.js +171 -95
  4. package/build/agents.generated.js +4 -4
  5. package/build/bridge-permissions.js +4 -0
  6. package/build/bridge-worktree-inspection.js +237 -0
  7. package/build/check-evidence.js +6 -0
  8. package/build/claude-review-workflow.js +1 -1
  9. package/build/cli-help.js +6 -0
  10. package/build/codex-auto-recovery.js +126 -0
  11. package/build/codex-skill-adapter.js +2 -0
  12. package/build/commands.generated.js +5 -5
  13. package/build/conductor/bridge-api-client.js +518 -23
  14. package/build/conductor/doctor.js +84 -10
  15. package/build/conductor/epic-implementer-cli.js +51 -2
  16. package/build/conductor/gate-discovery.js +136 -10
  17. package/build/conductor/gate-settings-review.js +305 -5
  18. package/build/conductor/git-hooks-uninstall.js +112 -0
  19. package/build/conductor/git-hooks.js +81 -15
  20. package/build/conductor/guided-repair.js +10 -1
  21. package/build/conductor/install-doctor.js +2 -4
  22. package/build/conductor/launch-plan.js +42 -2
  23. package/build/conductor/local-merge.js +12 -1
  24. package/build/conductor/merge-execution-contract.js +1 -1
  25. package/build/conductor/merged-child-check.js +2 -1
  26. package/build/conductor/prerequisite-inputs.js +379 -0
  27. package/build/conductor/readiness-assessment.js +78 -0
  28. package/build/conductor/readiness-cli.js +10 -0
  29. package/build/conductor/readiness-prerequisites.js +53 -0
  30. package/build/conductor/readiness-sections.js +21 -8
  31. package/build/conductor/readiness.js +20 -2
  32. package/build/conductor/recovery-cli.js +223 -13
  33. package/build/conductor/recovery-operations.js +34 -4
  34. package/build/conductor/repair-contract.js +33 -0
  35. package/build/conductor/tools.js +34 -3
  36. package/build/conductor/wait-run-attention.js +115 -0
  37. package/build/conductor/wait-run-cli.js +96 -3
  38. package/build/conductor/worker-database-doctor-inspector.js +1 -0
  39. package/build/credential-store.js +25 -20
  40. package/build/dependency-install-declarations.js +157 -0
  41. package/build/docs.generated.js +4 -4
  42. package/build/doctor.js +37 -5
  43. package/build/drive-epic-help.js +2 -2
  44. package/build/drive-epic.js +52 -11
  45. package/build/epic-implementer-bin.js +118 -43
  46. package/build/epic-launch-profile.js +1 -1
  47. package/build/executor/cli.js +2 -0
  48. package/build/executor/completion-contract.js +16 -0
  49. package/build/executor/credentials.js +1 -1
  50. package/build/executor/delivery-observations.js +113 -0
  51. package/build/executor/delivery-outcome.js +30 -0
  52. package/build/executor/dependency-refresh-runner.js +132 -0
  53. package/build/executor/dependency-refresh.js +530 -0
  54. package/build/executor/deps.js +4 -0
  55. package/build/executor/env.js +67 -2
  56. package/build/executor/harness-coverage.js +19 -0
  57. package/build/executor/http-client.js +35 -1
  58. package/build/executor/index.js +2 -1
  59. package/build/executor/install-preflight.js +1 -1
  60. package/build/executor/job-runner.js +246 -28
  61. package/build/executor/likely-tests.js +94 -97
  62. package/build/executor/prompt-spec.js +13 -3
  63. package/build/executor/required-verification.js +28 -0
  64. package/build/executor/required-work-diagnostics.js +30 -0
  65. package/build/executor/required-work-ledger.js +19 -1
  66. package/build/executor/results.js +42 -0
  67. package/build/executor/service-discovery.js +42 -0
  68. package/build/executor/service-lifecycle.js +109 -2
  69. package/build/executor/service-uninstall.js +205 -0
  70. package/build/executor/service-unit.js +5 -3
  71. package/build/executor/test-clock.js +3 -0
  72. package/build/executor/verification-hints.js +179 -0
  73. package/build/executor/worker-command.js +54 -2
  74. package/build/executor/worker-database.js +271 -31
  75. package/build/executor/worker-finalization.js +65 -10
  76. package/build/executor/worker-guard-hook.js +10 -2
  77. package/build/executor/worker-verification-guidance.js +37 -2
  78. package/build/executor/worktree-inspection.js +42 -0
  79. package/build/github-sign-in.js +1 -1
  80. package/build/index.js +679 -278
  81. package/build/init.js +3 -3
  82. package/build/install-bridge-conductor-gate.js +236 -42
  83. package/build/install-bridge-conductor-setup.js +115 -26
  84. package/build/install-bridge-conductor.js +448 -350
  85. package/build/install-bridge.js +418 -123
  86. package/build/install-maintenance.js +104 -0
  87. package/build/install-reexec.js +1 -1
  88. package/build/local-cleanup.js +59 -0
  89. package/build/mcp-install-state.js +68 -2
  90. package/build/merge-workflow-install.js +2 -2
  91. package/build/package-script-semantics.js +10 -0
  92. package/build/pipeline-utils.js +1 -1
  93. package/build/pipelines.generated.js +5 -5
  94. package/build/plan-execution-ledger.js +148 -2
  95. package/build/plane/plane-freshness.js +6 -7
  96. package/build/plane/terminal-run-cleanup.js +5 -1
  97. package/build/plane/terminal-run-status.js +4 -0
  98. package/build/printed-remedy-commands.js +24 -4
  99. package/build/readiness-check.js +1 -78
  100. package/build/readiness-prerequisites.generated.js +199 -0
  101. package/build/readme.generated.js +1 -1
  102. package/build/repository-toolchains.js +50 -8
  103. package/build/setup-change-policy.js +32 -0
  104. package/build/setup-epic.js +2 -2
  105. package/build/setup-question.js +62 -0
  106. package/build/start-tickets.js +4 -0
  107. package/build/test-command-detection.js +32 -88
  108. package/build/test-support/notes-fs.js +40 -0
  109. package/build/ticket-delivery-enrollment.js +21 -8
  110. package/build/ticket-delivery-run-scope.js +128 -0
  111. package/build/version.generated.js +3 -3
  112. package/build/worker-guard-hook-bin.js +2 -2
  113. package/build/worktrees.js +105 -0
  114. package/docs/EPIC-IMPLEMENTER.md +5 -0
  115. package/docs/epic-implementer/getting-started.md +40 -15
  116. package/package.json +1 -1
@@ -4,7 +4,7 @@
4
4
  * WHY THIS MODULE EXISTS SEPARATELY. `service-unit.ts` carries an invariant
5
5
  * titled "Never manages service lifecycle": it renders and writes a unit file
6
6
  * and runs no `launchctl` / `systemctl`. R-1 (2026-08-14) deliberately amends
7
- * the *product* rule — `install conductor` may now start the service the
7
+ * the *product* rule — `install epic-implementer` may now start the service the
8
8
  * generator just wrote — while keeping the *module* rule intact. So lifecycle
9
9
  * lives here, behind its own entry points, and the generator stays lifecycle
10
10
  * free. A caller that only wants a unit written physically cannot start a
@@ -211,6 +211,113 @@ export function formatExecutorServiceStartFailure(result) {
211
211
  : `exit code ${result.exitCode}`;
212
212
  return `service start did not complete: '${result.failedStage}' failed (${detail}).`;
213
213
  }
214
+ /**
215
+ * Build the destructive half of an uninstall. This is pure: callers still
216
+ * obtain consent and verify state before passing the plan to the runner.
217
+ * Linux reload is deliberately absent; it belongs after deleting the unit.
218
+ */
219
+ export function buildExecutorServiceStopPlan(target) {
220
+ if (typeof target.serviceIdentifier !== "string" || target.serviceIdentifier.length === 0) {
221
+ return { ok: false, error: "the service identifier is missing, so no unit can be stopped." };
222
+ }
223
+ if (/[/\\\x00-\x1f\x7f]/.test(target.serviceIdentifier) || target.serviceIdentifier.startsWith("-") ||
224
+ (target.platform === "linux" && !/^[A-Za-z0-9][A-Za-z0-9:_.-]*\.service$/.test(target.serviceIdentifier))) {
225
+ return { ok: false, error: "the service identifier is not a literal user-service target." };
226
+ }
227
+ if (target.platform === "darwin") {
228
+ if (typeof target.uid !== "number" || !Number.isInteger(target.uid) || target.uid < 0) {
229
+ return { ok: false, error: "a numeric uid is required for the launchd domain target." };
230
+ }
231
+ const commands = [{
232
+ stage: "launchctl bootout",
233
+ executable: "launchctl",
234
+ args: ["bootout", `gui/${target.uid}/${target.serviceIdentifier}`],
235
+ }];
236
+ return { ok: true, plan: { platform: "darwin", serviceManager: "launchd", commands, manualCommand: commands.map(renderCommand).join(" && ") } };
237
+ }
238
+ if (target.platform === "linux") {
239
+ const commands = [{
240
+ stage: "systemctl --user disable --now",
241
+ executable: "systemctl",
242
+ args: ["--user", "disable", "--now", target.serviceIdentifier],
243
+ }];
244
+ return { ok: true, plan: { platform: "linux", serviceManager: "systemd-user", commands, manualCommand: commands.map(renderCommand).join(" && ") } };
245
+ }
246
+ return { ok: false, error: "consented service removal is supported on darwin and linux only." };
247
+ }
248
+ /** Execute every planned stop command at most once and stop at the first failure. */
249
+ export async function stopExecutorService(plan, run) {
250
+ let commandsRun = 0;
251
+ for (const command of plan.commands) {
252
+ commandsRun++;
253
+ try {
254
+ const result = await run(command.executable, command.args);
255
+ const exitCode = typeof result?.exitCode === "number" ? result.exitCode : 1;
256
+ if (exitCode !== 0)
257
+ return { ok: false, manualCommand: plan.manualCommand, failedStage: command.stage, exitCode, reason: "nonzero-exit", commandsRun };
258
+ }
259
+ catch {
260
+ return { ok: false, manualCommand: plan.manualCommand, failedStage: command.stage, exitCode: null, reason: "runner-refused", commandsRun };
261
+ }
262
+ }
263
+ return { ok: true, manualCommand: plan.manualCommand, commandsRun };
264
+ }
265
+ /** Linux only: run after the unit file was deleted or found absent. */
266
+ export async function reloadExecutorServiceManager(platform, run) {
267
+ if (platform !== "linux")
268
+ return { ok: true, manualCommand: "", commandsRun: 0 };
269
+ const command = { stage: "systemctl --user daemon-reload", executable: "systemctl", args: ["--user", "daemon-reload"] };
270
+ return stopExecutorService({ platform, serviceManager: "systemd-user", commands: [command], manualCommand: renderCommand(command) }, run);
271
+ }
272
+ export function formatExecutorServiceStopFailure(result) {
273
+ const detail = result.reason === "runner-refused" ? "the command could not be run on this host" : `exit code ${result.exitCode}`;
274
+ return `service stop did not complete: '${result.failedStage}' failed (${detail}).`;
275
+ }
276
+ /** Strict uninstall observation; ordinary diagnostic compatibility stays intact. */
277
+ export async function inspectExecutorServiceForUninstall(target, run) {
278
+ const unknown = { state: "unknown", disabled: false, definitionAbsent: false };
279
+ const probe = buildExecutorServiceStateProbe(target);
280
+ if (!probe)
281
+ return unknown;
282
+ try {
283
+ if (target.platform === "darwin") {
284
+ const result = await run(probe.executable, probe.args);
285
+ if (result.exitCode === 0)
286
+ return { state: "active", disabled: false, definitionAbsent: false };
287
+ // Permission/session errors must never be mistaken for an unloaded job.
288
+ const expected = `Could not find service "${target.serviceIdentifier}" in domain for user gui: ${target.uid}`;
289
+ const lines = [result.stdout ?? "", result.stderr ?? ""].join("\n").split(/\r?\n/).map(line => line.trim()).filter(Boolean);
290
+ // Real launchctl on macOS 26 prefixes the exact absence line with
291
+ // `Bad request.`. Keep target/domain matching strict, including exit 113.
292
+ if (result.exitCode === 113 && lines.filter(line => line === expected).length === 1 && lines.every(line => line === expected || line === "Bad request."))
293
+ return { state: "absent", disabled: true, definitionAbsent: true };
294
+ return unknown;
295
+ }
296
+ const result = await run("systemctl", ["--user", "show", target.serviceIdentifier, "--property=LoadState,ActiveState,UnitFileState"]);
297
+ if (result.exitCode !== 0)
298
+ return unknown;
299
+ const values = new Map((result.stdout ?? "").trim().split(/\r?\n/).map(line => {
300
+ const at = line.indexOf("=");
301
+ return [line.slice(0, at), line.slice(at + 1)];
302
+ }));
303
+ const load = values.get("LoadState"), active = values.get("ActiveState"), enabled = values.get("UnitFileState");
304
+ if (load === "not-found" && active === "inactive")
305
+ return { state: "absent", disabled: true, definitionAbsent: true };
306
+ if (load !== "loaded")
307
+ return unknown;
308
+ const disabled = enabled === "disabled" || enabled === "static" || enabled === "masked";
309
+ if (active === "active")
310
+ return { state: "active", disabled, definitionAbsent: false };
311
+ if (active === "inactive" || active === "failed")
312
+ return { state: "stopped", disabled, definitionAbsent: false };
313
+ if (["activating", "deactivating", "reloading"].includes(active ?? ""))
314
+ return { state: "transitional", disabled, definitionAbsent: false };
315
+ return unknown;
316
+ }
317
+ catch {
318
+ return unknown;
319
+ }
320
+ }
214
321
  /**
215
322
  * Build the strictly read-only state probe for a target.
216
323
  *
@@ -370,7 +477,7 @@ export async function inspectExecutorServiceDurability(target, run) {
370
477
  // durability the probe did not establish.
371
478
  //
372
479
  // A ZERO exit is NOT `configured`. It says the gui/<uid> domain exists at
373
- // this instant — which it does whenever an operator runs `install conductor`
480
+ // this instant — which it does whenever an operator runs `install epic-implementer`
374
481
  // or `doctor` from their own logged-in session — and a LaunchAgent in that
375
482
  // domain is tied to the login, not to the machine being powered on. Calling
376
483
  // it `configured` would let a renderer that means "survives logout" assert
@@ -0,0 +1,205 @@
1
+ /** Consented local removal of one home-scoped executor service. */
2
+ import { lstat, readFile, unlink } from "node:fs/promises";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { confirmLocalCleanup, runLocalCommand } from "../local-cleanup.js";
6
+ import { forgetInstalledExecutorServiceUnit } from "../mcp-install-state.js";
7
+ import { posixShellQuote, xmlEscape } from "../platform-escaping.js";
8
+ import { MCP_PACKAGE_NAME } from "../mcp-identity.js";
9
+ import { discoverExecutorServiceUnits } from "./service-discovery.js";
10
+ import { buildExecutorServiceStopPlan, stopExecutorService, reloadExecutorServiceManager, inspectExecutorServiceForUninstall } from "./service-lifecycle.js";
11
+ import { executorLaunchdPlistPathForId, executorSystemdUnitPathForId, executorLaunchdLabelForId, executorSystemdUnitNameForId, executorLaunchdLogPathsForId, inspectExecutorServiceArtifact, validateExecutorId } from "./service-unit.js";
12
+ import { parseExecutorWorktreeLock } from "./worktree-lock.js";
13
+ import { parseGitWorktreePorcelain } from "./worktree-inspection.js";
14
+ export function getExecutorUninstallServiceUsage() {
15
+ return "Usage: mcp-server executor uninstall-service [--executor-id <id>] [--dry-run]\nWithout an id, list filesystem-discovered units. Removal requires interactive consent; logs are retained.\n -h, --help Show help.";
16
+ }
17
+ /** A matching live worker lock is positive job evidence. Unknown remains disclosed. */
18
+ async function localActivity(cwd, executorId) {
19
+ const list = await runLocalCommand("git", ["worktree", "list", "--porcelain"], cwd);
20
+ if (list.exitCode !== 0)
21
+ return "unknown";
22
+ for (const wt of parseGitWorktreePorcelain(list.stdout)) {
23
+ try {
24
+ const raw = await readFile(path.join(wt.path, ".conductor", "worker.lock"), "utf8");
25
+ const owner = parseExecutorWorktreeLock(raw);
26
+ if (!owner)
27
+ continue;
28
+ if (owner.executorId !== executorId)
29
+ continue;
30
+ try {
31
+ process.kill(owner.ownerPid, 0);
32
+ return "active";
33
+ }
34
+ catch (error) {
35
+ if (error.code !== "ESRCH")
36
+ return "unknown";
37
+ }
38
+ }
39
+ catch (error) {
40
+ if (error.code !== "ENOENT")
41
+ return "unknown";
42
+ }
43
+ }
44
+ // Other repositories may be served by this home-scoped unit.
45
+ return "unknown";
46
+ }
47
+ export async function runExecutorUninstallServiceCli(argv, overrides = {}) {
48
+ const deps = { platform: process.platform, homeDir: os.homedir(), cwd: process.cwd(), uid: process.getuid?.() ?? null,
49
+ isTTY: Boolean(process.stdin.isTTY && process.stdout.isTTY), log: text => process.stderr.write(text + "\n"), prompt: confirmLocalCleanup,
50
+ run: runLocalCommand, lstat, readFile, unlink, discover: discoverExecutorServiceUnits, forget: forgetInstalledExecutorServiceUnit, activity: localActivity, ...overrides };
51
+ let id, dryRun = false;
52
+ for (let i = 0; i < argv.length; i++) {
53
+ if (argv[i] === "--help" || argv[i] === "-h") {
54
+ deps.log(getExecutorUninstallServiceUsage());
55
+ return 0;
56
+ }
57
+ if (argv[i] === "--dry-run")
58
+ dryRun = true;
59
+ else if (argv[i] === "--executor-id" && !id && argv[i + 1] && !argv[i + 1].startsWith("--"))
60
+ id = argv[++i];
61
+ else {
62
+ deps.log("Invalid uninstall-service arguments.\n" + getExecutorUninstallServiceUsage());
63
+ return 1;
64
+ }
65
+ }
66
+ if (deps.platform !== "darwin" && deps.platform !== "linux") {
67
+ deps.log("Service removal supports darwin and linux only.");
68
+ return 1;
69
+ }
70
+ const platform = deps.platform;
71
+ if (!id) {
72
+ const found = await deps.discover(platform, deps.homeDir);
73
+ if (!found.ok) {
74
+ deps.log("Executor service directory unavailable; no absence is established.");
75
+ return 0;
76
+ }
77
+ for (const unit of found.units)
78
+ deps.log(`${unit.executorId}: ${unit.path}`);
79
+ if (!found.units.length)
80
+ deps.log("No executor service unit files found.");
81
+ return 0;
82
+ }
83
+ try {
84
+ validateExecutorId(id, platform);
85
+ }
86
+ catch {
87
+ deps.log("Invalid executor id.");
88
+ return 1;
89
+ }
90
+ const unitPath = platform === "darwin" ? executorLaunchdPlistPathForId(id, deps.homeDir) : executorSystemdUnitPathForId(id, deps.homeDir);
91
+ const identifier = platform === "darwin" ? executorLaunchdLabelForId(id) : executorSystemdUnitNameForId(id);
92
+ const target = { platform, unitPath, serviceIdentifier: identifier, uid: deps.uid };
93
+ const built = buildExecutorServiceStopPlan(target);
94
+ if (!built.ok) {
95
+ deps.log(built.error);
96
+ return 1;
97
+ }
98
+ const snapshot = async () => {
99
+ try {
100
+ const stat = await deps.lstat(unitPath);
101
+ if (!stat.isFile() || stat.isSymbolicLink())
102
+ throw new Error("unsafe");
103
+ const bytes = await deps.readFile(unitPath);
104
+ if (bytes.length > 1024 * 1024)
105
+ throw new Error("oversize");
106
+ const text = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
107
+ const inspection = inspectExecutorServiceArtifact(platform === "darwin" ? "launchd-plist" : "systemd-service", text);
108
+ if (!inspection.ok || inspection.executorId !== id || text.includes("\0"))
109
+ throw new Error("identity");
110
+ if (platform === "darwin") {
111
+ const labels = [...text.matchAll(/<key>Label<\/key>\s*<string>([^<]*)<\/string>/g)];
112
+ if (labels.length !== 1 || labels[0][1] !== xmlEscape(identifier))
113
+ throw new Error("label");
114
+ }
115
+ return { stat, bytes };
116
+ }
117
+ catch (error) {
118
+ if (error.code === "ENOENT")
119
+ return null;
120
+ throw error;
121
+ }
122
+ };
123
+ try {
124
+ const before = await snapshot();
125
+ const unchanged = async () => {
126
+ const now = await snapshot();
127
+ return before === null ? now === null : now !== null && now.stat.ino === before.stat.ino && now.stat.dev === before.stat.dev && now.stat.mode === before.stat.mode && now.bytes.equals(before.bytes);
128
+ };
129
+ const activity = await deps.activity(deps.cwd, id);
130
+ deps.log(`Executor: ${id}\nUnit: ${unitPath}\nPhases: stop/unload, verify stopped, delete definition, reload (Linux), verify removal, forget current-repository locator.\nService removal is home-scoped; locator cleanup is limited to the current repository.\nLocal job activity: ${activity}. Live service state has not yet been probed.\nStopping may interrupt jobs and does not certify termination of every child process. Finish or stop work through the existing executor/plane workflow first.`);
131
+ if (platform === "darwin") {
132
+ const logs = executorLaunchdLogPathsForId(id, deps.homeDir);
133
+ deps.log(`Retained logs for manual review:\n${logs.stdout}\n${logs.stderr}`);
134
+ }
135
+ else
136
+ deps.log("Linux logs are retained in the user journald journal.");
137
+ if (dryRun) {
138
+ deps.log("dry run — nothing was removed");
139
+ return 0;
140
+ }
141
+ if (activity === "active") {
142
+ deps.log("Retained: active worker evidence. Finish the job before retrying.");
143
+ return 0;
144
+ }
145
+ if (!deps.isTTY || !await deps.prompt(`Remove executor service ${id}?`)) {
146
+ deps.log("declined — nothing was removed");
147
+ return 0;
148
+ }
149
+ if (await deps.activity(deps.cwd, id) === "active" || !await unchanged()) {
150
+ deps.log("Retained: activity or definition changed after consent.");
151
+ return 0;
152
+ }
153
+ const initial = await inspectExecutorServiceForUninstall(target, deps.run);
154
+ if (initial.state === "unknown" || initial.state === "transitional") {
155
+ deps.log("Failed: service state unavailable; unit and locator retained.");
156
+ return 1;
157
+ }
158
+ if (initial.state !== "absent") {
159
+ const stopped = await stopExecutorService(built.plan, deps.run);
160
+ if (!stopped.ok) {
161
+ const raced = await inspectExecutorServiceForUninstall(target, deps.run);
162
+ if (raced.state !== "absent") {
163
+ deps.log(`Failed: ${stopped.failedStage}; unit and locator retained. Manual recovery: ${stopped.manualCommand}`);
164
+ return 1;
165
+ }
166
+ }
167
+ }
168
+ const stopped = await inspectExecutorServiceForUninstall(target, deps.run);
169
+ if (!(platform === "darwin" ? stopped.state === "absent" : (stopped.state === "stopped" || stopped.state === "absent") && stopped.disabled)) {
170
+ deps.log("Failed: stop verification; unit and locator retained.");
171
+ return 1;
172
+ }
173
+ if (!await unchanged()) {
174
+ deps.log("Failed: definition changed; retained.");
175
+ return 1;
176
+ }
177
+ if (before) {
178
+ await deps.unlink(unitPath);
179
+ deps.log(`Completed: deleted ${unitPath}`);
180
+ }
181
+ const reload = await reloadExecutorServiceManager(platform, deps.run);
182
+ const final = reload.ok ? await inspectExecutorServiceForUninstall(target, deps.run) : null;
183
+ if (!final || final.state !== "absent" || !final.definitionAbsent) {
184
+ deps.log("Failed: final service verification; locator retained.");
185
+ return 1;
186
+ }
187
+ const root = await deps.run("git", ["rev-parse", "--show-toplevel"], deps.cwd);
188
+ if (root.exitCode === 0) {
189
+ const forgotten = await deps.forget(root.stdout.trim(), unitPath, deps.homeDir);
190
+ if (!forgotten.ok) {
191
+ deps.log(`Failed: current-repository locator retained (${forgotten.reason}). Retry: npx -y ${MCP_PACKAGE_NAME} executor uninstall-service --executor-id ${posixShellQuote(id)}`);
192
+ return 1;
193
+ }
194
+ deps.log(`Completed: locator ${forgotten.outcome}.`);
195
+ }
196
+ else
197
+ deps.log("Current directory is outside a repository; no locator cleanup attempted.");
198
+ deps.log(before ? "Completed: executor service removed; logs retained." : "nothing to remove — service already absent; stale locator reconciled and logs retained.");
199
+ return 0;
200
+ }
201
+ catch {
202
+ deps.log("Failed: unsafe or unavailable service definition; retained remaining resources.");
203
+ return 1;
204
+ }
205
+ }
@@ -52,7 +52,7 @@
52
52
  * longer forbidden to Bridge outright: consented, one-shot start and
53
53
  * read-only state inspection now live in a SEPARATE module,
54
54
  * {@link ../executor/service-lifecycle.js `executor/service-lifecycle.ts`},
55
- * which `install conductor` drives behind its own independent consent. The
55
+ * which `install epic-implementer` drives behind its own independent consent. The
56
56
  * split is the point — a caller that wants a unit written cannot
57
57
  * accidentally start a persistent daemon, because the two capabilities are
58
58
  * in different modules with different entry points.
@@ -935,7 +935,7 @@ export function getExecutorInstallServiceUsage() {
935
935
  "The FILE-GENERATION LEG of durable-host mode. It writes one unit and stops there.",
936
936
  "For the supported composed bring-up — planning, consented write, consented start,",
937
937
  "read-only local inspection, and bounded server-observed readiness — run",
938
- "`install conductor` instead. Use this command when you deliberately manage the",
938
+ "`install epic-implementer` instead. Use this command when you deliberately manage the",
939
939
  "service lifecycle yourself.",
940
940
  "",
941
941
  "Generates ONE long-running user-domain service unit for ONE stable executor id:",
@@ -978,7 +978,7 @@ export function getExecutorInstallServiceUsage() {
978
978
  "host's output is readable after the fact; a systemd --user unit logs to journald.",
979
979
  "",
980
980
  "This command writes a file and nothing else. Starting, stopping, enabling, and",
981
- "removing the service stay operator-managed via launchctl / systemctl --user /",
981
+ "removing the service use separately consented executor uninstall-service, or launchctl / systemctl --user /",
982
982
  "Task Scheduler. A written unit is NOT readiness, and neither is a started one:",
983
983
  "only a server-observed executor claim, after a start you perform separately, makes",
984
984
  "this host ready to do work.",
@@ -1400,6 +1400,7 @@ function formatPostWriteGuidance(artifact, executorId) {
1400
1400
  ` launchctl bootstrap gui/$(id -u) ${posixShellQuote(artifact.path)}`,
1401
1401
  ` launchctl print gui/$(id -u)/${label} # status`,
1402
1402
  ` launchctl bootout gui/$(id -u)/${label} # stop + unload`,
1403
+ ` npx -y ${MCP_SERVER_PACKAGE_NAME} executor uninstall-service --executor-id ${posixShellQuote(executorId)} # consented removal`,
1403
1404
  "",
1404
1405
  "Starting it is still not readiness: this host is ready only once the Bridge",
1405
1406
  "server observes an executor claim from it.",
@@ -1411,6 +1412,7 @@ function formatPostWriteGuidance(artifact, executorId) {
1411
1412
  " systemctl --user daemon-reload",
1412
1413
  ` systemctl --user enable --now ${unit}`,
1413
1414
  ` systemctl --user status ${unit}`,
1415
+ ` npx -y ${MCP_SERVER_PACKAGE_NAME} executor uninstall-service --executor-id ${posixShellQuote(executorId)} # consented removal`,
1414
1416
  "",
1415
1417
  "On a headless host, also run `loginctl enable-linger $USER` so the user service",
1416
1418
  "keeps running without an active login session.",
@@ -144,6 +144,9 @@ export function makeFakeExecutorDeps(clock, overrides = {}) {
144
144
  throw Object.assign(new Error("ENOENT"), { code: "ENOENT" });
145
145
  },
146
146
  writeFile: async () => { },
147
+ // BAPI-1551: no hints file. The real reader's filesystem I/O would resolve
148
+ // outside the virtual clock's microtask flush and strand the spawn.
149
+ readVerificationHints: async () => ({ status: "missing" }),
147
150
  // The exclude writer publishes through a temporary file plus rename.
148
151
  rename: async () => { },
149
152
  mkdir: async () => undefined,
@@ -0,0 +1,179 @@
1
+ /**
2
+ * The one contained reader of `.bridge/verification-hints.json` (BAPI-1551).
3
+ *
4
+ * Version 1 is `{version:1, pins?:[{paths:[...], tests:[...]}], always?:[...]}`.
5
+ * `pins` maps changed paths to tests (BAPI-1479). `always` (BAPI-1551) lists at
6
+ * most {@link MAX_ALWAYS_ENTRIES} repository-relative test files or directories
7
+ * (a trailing `/` marks a directory) that a worker runs before every push,
8
+ * whatever it changed. `pins` may be omitted when `always` is present.
9
+ *
10
+ * Both likely-tests discovery and the executor's worker prompt read the file
11
+ * through {@link readVerificationHints}, so the two always agree on which
12
+ * `always` entries were admitted. An entry is admitted only when it exists as the
13
+ * kind it claims, checked through the same contained no-follow walk that reads
14
+ * the hints file itself. A missing, wrong-kind, or invalid entry is skipped and
15
+ * reported as `skipped`. A missing or malformed file is fail-open: no required
16
+ * references, and the caller keeps its existing discovery notes.
17
+ *
18
+ * References are data only, never commands.
19
+ */
20
+ import path from "node:path";
21
+ import { constants } from "node:fs";
22
+ import { lstat, open } from "node:fs/promises";
23
+ export const VERIFICATION_HINTS_PATH = ".bridge/verification-hints.json";
24
+ export const MAX_ALWAYS_ENTRIES = 32;
25
+ export const TEST_REFERENCE_MAX_LENGTH = 512;
26
+ export const MAX_OPTIONAL_JSON_BYTES = 256 * 1024;
27
+ export function object(value) {
28
+ return value !== null && typeof value === "object" && !Array.isArray(value)
29
+ ? value : undefined;
30
+ }
31
+ export function validTestReference(value) {
32
+ return typeof value === "string" && value.trim().length > 0 &&
33
+ value.length <= TEST_REFERENCE_MAX_LENGTH && !/[\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(value);
34
+ }
35
+ export function validRepoPath(value, directory = false) {
36
+ const candidate = directory && value.endsWith("/") ? value.slice(0, -1) : value;
37
+ return !!candidate && !path.isAbsolute(candidate) && !/[:\\\x00-\x1f\x7f-\x9f\u2028\u2029]/.test(candidate) &&
38
+ candidate.split("/").every(p => p !== "" && p !== "." && p !== "..");
39
+ }
40
+ /** A test reference; a file-shaped one must be a safe path (a trailing `/` names a directory). */
41
+ export function validReference(value) {
42
+ if (!validTestReference(value))
43
+ return false;
44
+ const file = value.split("::")[0];
45
+ const fileShaped = value.includes("/") || /\.(?:py|[cm]?[jt]sx?)(?:::|$)/.test(value) || value.includes("::");
46
+ return !fileShaped || validRepoPath(file, !value.includes("::") && file.endsWith("/"));
47
+ }
48
+ function validAlwaysEntry(value) {
49
+ return validTestReference(value) && !value.includes("::") && validRepoPath(value, true);
50
+ }
51
+ /** Parse a hints document, or `undefined` when it is not a version-1 document. */
52
+ export function parseVerificationHints(value) {
53
+ const doc = object(value);
54
+ if (!doc || doc.version !== 1)
55
+ return undefined;
56
+ const hasPins = Object.prototype.hasOwnProperty.call(doc, "pins");
57
+ const hasAlways = Object.prototype.hasOwnProperty.call(doc, "always");
58
+ if (hasPins ? !Array.isArray(doc.pins) : !hasAlways)
59
+ return undefined;
60
+ if (hasAlways && !Array.isArray(doc.always))
61
+ return undefined;
62
+ const pins = [];
63
+ let skipped = false;
64
+ for (const entry of doc.pins ?? []) {
65
+ const pin = object(entry);
66
+ if (!pin || !Array.isArray(pin.paths) || !Array.isArray(pin.tests)) {
67
+ skipped = true;
68
+ continue;
69
+ }
70
+ const paths = pin.paths.filter((p) => typeof p === "string" && validRepoPath(p, true));
71
+ const tests = pin.tests.filter(validReference);
72
+ if (paths.length !== pin.paths.length || tests.length !== pin.tests.length)
73
+ skipped = true;
74
+ if (paths.length && tests.length)
75
+ pins.push({ paths, tests });
76
+ else
77
+ skipped = true;
78
+ }
79
+ const always = [];
80
+ const declared = doc.always ?? [];
81
+ for (let index = 0; index < declared.length; index++) {
82
+ const entry = declared[index];
83
+ if (index >= MAX_ALWAYS_ENTRIES || !validAlwaysEntry(entry)) {
84
+ skipped = true;
85
+ continue;
86
+ }
87
+ if (!always.includes(entry))
88
+ always.push(entry);
89
+ }
90
+ return { pins, always, skipped };
91
+ }
92
+ /**
93
+ * Walk `relative` under `root` without following a link: every component is
94
+ * `lstat`ed, a symlink anywhere refuses, and every ancestor must be a directory.
95
+ * Returns the final component's kind.
96
+ */
97
+ export async function containedKind(root, relative) {
98
+ if (!validRepoPath(relative))
99
+ throw new Error("invalid_path");
100
+ let current = root;
101
+ let kind = "other";
102
+ const parts = relative.split("/");
103
+ for (let index = 0; index < parts.length; index++) {
104
+ current = path.join(current, parts[index]);
105
+ const info = await lstat(current);
106
+ if (info.isSymbolicLink())
107
+ throw new Error("symlink");
108
+ const last = index === parts.length - 1;
109
+ if (!last && !info.isDirectory())
110
+ throw new Error("ancestor");
111
+ if (last)
112
+ kind = info.isDirectory() ? "directory" : info.isFile() ? "file" : "other";
113
+ }
114
+ if (kind === "other")
115
+ throw new Error("not_regular");
116
+ return kind;
117
+ }
118
+ /** No-follow and fstat protect the final component; lstat every ancestor first.
119
+ * Reads at most limit+1 bytes even if a file grows between stat and read.
120
+ */
121
+ export async function containedText(root, relative, limit) {
122
+ if (!validRepoPath(relative))
123
+ throw new Error("invalid_path");
124
+ let current = root;
125
+ for (const part of relative.split("/")) {
126
+ current = path.join(current, part);
127
+ const info = await lstat(current);
128
+ if (info.isSymbolicLink())
129
+ throw new Error("symlink");
130
+ if (current !== path.join(root, relative) && !info.isDirectory())
131
+ throw new Error("ancestor");
132
+ }
133
+ const handle = await open(current, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
134
+ try {
135
+ const info = await handle.stat();
136
+ if (!info.isFile())
137
+ throw new Error("not_regular");
138
+ if (info.size > limit)
139
+ throw new Error("bound");
140
+ const buffer = Buffer.alloc(limit + 1);
141
+ const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
142
+ if (bytesRead > limit)
143
+ throw new Error("bound");
144
+ return buffer.subarray(0, bytesRead).toString("utf8");
145
+ }
146
+ finally {
147
+ await handle.close();
148
+ }
149
+ }
150
+ /** Read and admit the hints file under `root`. Never throws. */
151
+ export async function readVerificationHints(root, options = {}) {
152
+ const read = options.readText ?? containedText;
153
+ const kindOf = options.kindOf ?? containedKind;
154
+ let parsed;
155
+ try {
156
+ parsed = parseVerificationHints(JSON.parse(await read(root, VERIFICATION_HINTS_PATH, MAX_OPTIONAL_JSON_BYTES)));
157
+ }
158
+ catch (error) {
159
+ return error.code === "ENOENT" ? { status: "missing" } : { status: "malformed" };
160
+ }
161
+ if (!parsed)
162
+ return { status: "malformed" };
163
+ const required = [];
164
+ let skipped = parsed.skipped;
165
+ for (const entry of parsed.always) {
166
+ const directory = entry.endsWith("/");
167
+ try {
168
+ const kind = await kindOf(root, directory ? entry.slice(0, -1) : entry);
169
+ if (kind === (directory ? "directory" : "file"))
170
+ required.push(entry);
171
+ else
172
+ skipped = true;
173
+ }
174
+ catch {
175
+ skipped = true;
176
+ }
177
+ }
178
+ return { status: "ok", pins: parsed.pins, required, skipped };
179
+ }