deft-bridge 0.3.0 → 0.3.1

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 (2) hide show
  1. package/dist/bridge.js +150 -93
  2. package/package.json +2 -2
package/dist/bridge.js CHANGED
@@ -1824,17 +1824,17 @@ function gone(child) {
1824
1824
  }
1825
1825
  function terminateChild(child, graceMs = TERMINATE_GRACE_MS) {
1826
1826
  if (gone(child)) return Promise.resolve();
1827
- return new Promise((resolve18) => {
1827
+ return new Promise((resolve19) => {
1828
1828
  let timer;
1829
1829
  const onExit = () => {
1830
1830
  clearTimeout(timer);
1831
- resolve18();
1831
+ resolve19();
1832
1832
  };
1833
1833
  child.once("exit", onExit);
1834
1834
  timer = setTimeout(() => {
1835
1835
  child.off("exit", onExit);
1836
1836
  if (!gone(child)) child.kill("SIGKILL");
1837
- resolve18();
1837
+ resolve19();
1838
1838
  }, graceMs);
1839
1839
  child.kill("SIGTERM");
1840
1840
  });
@@ -2808,13 +2808,13 @@ function untilAborted(promise, signal) {
2808
2808
  });
2809
2809
  return Promise.reject(new ToolCancelledError());
2810
2810
  }
2811
- return new Promise((resolve18, reject) => {
2811
+ return new Promise((resolve19, reject) => {
2812
2812
  const onAbort = () => reject(new ToolCancelledError());
2813
2813
  signal.addEventListener("abort", onAbort, { once: true });
2814
2814
  promise.then(
2815
2815
  (value) => {
2816
2816
  signal.removeEventListener("abort", onAbort);
2817
- resolve18(value);
2817
+ resolve19(value);
2818
2818
  },
2819
2819
  (error) => {
2820
2820
  signal.removeEventListener("abort", onAbort);
@@ -3562,7 +3562,7 @@ var BRIDGE_VERSION;
3562
3562
  var init_version = __esm({
3563
3563
  "packages/core/src/version.ts"() {
3564
3564
  "use strict";
3565
- BRIDGE_VERSION = "0.3.0";
3565
+ BRIDGE_VERSION = "0.3.1";
3566
3566
  }
3567
3567
  });
3568
3568
 
@@ -4986,8 +4986,8 @@ var init_rpc_client = __esm({
4986
4986
  const commandWithId = { ...command, id };
4987
4987
  const line = JSON.stringify(commandWithId) + "\n";
4988
4988
  const timeoutMs = options.timeoutMs ?? (UNTIMED_COMMANDS.has(command.type) ? 0 : this.requestTimeoutMs);
4989
- return new Promise((resolve18, reject) => {
4990
- const entry = { resolve: resolve18, reject };
4989
+ return new Promise((resolve19, reject) => {
4990
+ const entry = { resolve: resolve19, reject };
4991
4991
  this.pending.set(id, entry);
4992
4992
  if (timeoutMs > 0) {
4993
4993
  entry.timer = setTimeout(() => {
@@ -5642,8 +5642,8 @@ var init_client3 = __esm({
5642
5642
  let usage;
5643
5643
  let settle2;
5644
5644
  let fail2;
5645
- const settled = new Promise((resolve18, reject) => {
5646
- settle2 = resolve18;
5645
+ const settled = new Promise((resolve19, reject) => {
5646
+ settle2 = resolve19;
5647
5647
  fail2 = reject;
5648
5648
  });
5649
5649
  const cleanupEvents = client.onEvent((event) => {
@@ -7575,20 +7575,20 @@ var init_session = __esm({
7575
7575
  waiting = [];
7576
7576
  ended = false;
7577
7577
  push(item) {
7578
- const resolve18 = this.waiting.shift();
7579
- if (resolve18) resolve18({ value: item, done: false });
7578
+ const resolve19 = this.waiting.shift();
7579
+ if (resolve19) resolve19({ value: item, done: false });
7580
7580
  else this.queue.push(item);
7581
7581
  }
7582
7582
  end() {
7583
7583
  this.ended = true;
7584
- for (const resolve18 of this.waiting.splice(0)) resolve18({ value: void 0, done: true });
7584
+ for (const resolve19 of this.waiting.splice(0)) resolve19({ value: void 0, done: true });
7585
7585
  }
7586
7586
  [Symbol.asyncIterator]() {
7587
7587
  return {
7588
7588
  next: () => {
7589
7589
  if (this.queue.length) return Promise.resolve({ value: this.queue.shift(), done: false });
7590
7590
  if (this.ended) return Promise.resolve({ value: void 0, done: true });
7591
- return new Promise((resolve18) => this.waiting.push(resolve18));
7591
+ return new Promise((resolve19) => this.waiting.push(resolve19));
7592
7592
  }
7593
7593
  };
7594
7594
  }
@@ -9692,7 +9692,7 @@ var init_transport = __esm({
9692
9692
  }
9693
9693
  const id = this.nextId++;
9694
9694
  const key2 = rpcKey(id);
9695
- return new Promise((resolve18, reject) => {
9695
+ return new Promise((resolve19, reject) => {
9696
9696
  const timer = timeoutMs > 0 ? setTimeout(() => {
9697
9697
  this.pending.delete(key2);
9698
9698
  reject(
@@ -9700,7 +9700,7 @@ var init_transport = __esm({
9700
9700
  );
9701
9701
  }, timeoutMs) : void 0;
9702
9702
  this.pending.set(key2, {
9703
- resolve: (val) => resolve18(val),
9703
+ resolve: (val) => resolve19(val),
9704
9704
  reject,
9705
9705
  ...timer ? { timer } : {}
9706
9706
  });
@@ -11114,8 +11114,8 @@ var init_config2 = __esm({
11114
11114
  {
11115
11115
  id: "read-only",
11116
11116
  name: "Read-only",
11117
- description: "Inspect files without modifying the workspace",
11118
- approvalPolicy: "on-request",
11117
+ description: "Ask before editing files or running untrusted commands; read-only sandbox",
11118
+ approvalPolicy: "untrusted",
11119
11119
  sandboxMode: "read-only"
11120
11120
  },
11121
11121
  {
@@ -11624,8 +11624,8 @@ var init_session2 = __esm({
11624
11624
  this.settleTurnSinks(prev, { stopReason: "cancelled", usage: prev.usage });
11625
11625
  }
11626
11626
  let resolveTurnId;
11627
- const turnIdReady = new Promise((resolve18) => {
11628
- resolveTurnId = (id) => resolve18(id || void 0);
11627
+ const turnIdReady = new Promise((resolve19) => {
11628
+ resolveTurnId = (id) => resolve19(id || void 0);
11629
11629
  });
11630
11630
  const state = {
11631
11631
  resolveTurnId,
@@ -14411,7 +14411,7 @@ var init_front = __esm({
14411
14411
  try {
14412
14412
  const out$ = await this.source.execute(close, ctx);
14413
14413
  await new Promise(
14414
- (resolve18) => out$.subscribe({ error: () => resolve18(), complete: () => resolve18() })
14414
+ (resolve19) => out$.subscribe({ error: () => resolve19(), complete: () => resolve19() })
14415
14415
  );
14416
14416
  if (!outcome || !("result" in outcome))
14417
14417
  this.runtimeLogger?.warn("Ideal: closing a session of an ended connection failed", {
@@ -14814,8 +14814,8 @@ var init_GrokProcessTransport = __esm({
14814
14814
  method,
14815
14815
  params
14816
14816
  };
14817
- return new Promise((resolve18, reject) => {
14818
- this.addPending(id, method, resolve18, reject);
14817
+ return new Promise((resolve19, reject) => {
14818
+ this.addPending(id, method, resolve19, reject);
14819
14819
  this.writeMessage(request);
14820
14820
  });
14821
14821
  }
@@ -14834,15 +14834,15 @@ var init_GrokProcessTransport = __esm({
14834
14834
  method,
14835
14835
  params
14836
14836
  };
14837
- const promise = new Promise((resolve18, reject) => {
14838
- this.addPending(id, method, resolve18, reject);
14837
+ const promise = new Promise((resolve19, reject) => {
14838
+ this.addPending(id, method, resolve19, reject);
14839
14839
  });
14840
14840
  this.writeMessage(request);
14841
14841
  return { id, promise };
14842
14842
  }
14843
14843
  /** Wait for the reply to `id`, for as long as `method` may take. */
14844
- addPending(id, method, resolve18, reject) {
14845
- const entry = { resolve: resolve18, reject, method };
14844
+ addPending(id, method, resolve19, reject) {
14845
+ const entry = { resolve: resolve19, reject, method };
14846
14846
  this.pendingRequests.set(id, entry);
14847
14847
  const timeoutMs = UNTIMED_METHODS.has(method) ? 0 : this.config.requestTimeoutMs ?? GROK_REQUEST_TIMEOUT_MS;
14848
14848
  if (timeoutMs > 0) {
@@ -15424,7 +15424,7 @@ var init_client7 = __esm({
15424
15424
  const key2 = this.upstreamSessionKey(ctx);
15425
15425
  const worker = this.worker(key2);
15426
15426
  let release;
15427
- const done = new Promise((resolve18) => release = resolve18);
15427
+ const done = new Promise((resolve19) => release = resolve19);
15428
15428
  let closed = false;
15429
15429
  let inner;
15430
15430
  const end = () => {
@@ -16789,7 +16789,7 @@ var init_sessions3 = __esm({
16789
16789
  if (!session) return Promise.reject(new Error(`Unknown session ${id}`));
16790
16790
  if (ctx.turn?.phase === "finished")
16791
16791
  return Promise.reject(new TurnCancelled("the execution ended before its turn came"));
16792
- return new Promise((resolve18, reject) => {
16792
+ return new Promise((resolve19, reject) => {
16793
16793
  const state = lifecycle(`turn ${ctx.requestId}`, turnTable, "queued", this.options);
16794
16794
  const turn = {
16795
16795
  ctx,
@@ -16797,7 +16797,7 @@ var init_sessions3 = __esm({
16797
16797
  start: () => {
16798
16798
  state.send("start");
16799
16799
  session.running.add(turn);
16800
- resolve18();
16800
+ resolve19();
16801
16801
  },
16802
16802
  stop: (reason) => {
16803
16803
  if (state.state === "queued") {
@@ -17000,7 +17000,7 @@ var init_interactions = __esm({
17000
17000
  open(request) {
17001
17001
  const correlationId = randomUUID11();
17002
17002
  let settle2;
17003
- const reply = new Promise((resolve18) => settle2 = resolve18);
17003
+ const reply = new Promise((resolve19) => settle2 = resolve19);
17004
17004
  if (this.closed) {
17005
17005
  settle2({ error: { ...INTERACTION_ERRORS.disconnected } });
17006
17006
  return { correlationId, reply };
@@ -17100,7 +17100,7 @@ function bridgeMeta3(meta) {
17100
17100
  async function within(work, ms) {
17101
17101
  let timer;
17102
17102
  const timedOut = new Promise(
17103
- (resolve18) => timer = setTimeout(() => resolve18(false), ms)
17103
+ (resolve19) => timer = setTimeout(() => resolve19(false), ms)
17104
17104
  );
17105
17105
  try {
17106
17106
  return await Promise.race([work.then(() => true), timedOut]);
@@ -17243,7 +17243,7 @@ var init_nodes = __esm({
17243
17243
  if (!answered)
17244
17244
  for (const execution of executions)
17245
17245
  execution.abort(new TurnCancelled("connection closed"));
17246
- await new Promise((resolve18) => setTimeout(resolve18, 0));
17246
+ await new Promise((resolve19) => setTimeout(resolve19, 0));
17247
17247
  await port.close().catch(
17248
17248
  (error) => front.logger?.debug("Closing an ACP connection failed", { error: errorText(error) })
17249
17249
  );
@@ -17344,7 +17344,7 @@ var init_nodes = __esm({
17344
17344
  ctx.turn.onCancel((reason) => execution.abort(reason));
17345
17345
  let replied;
17346
17346
  let settle2;
17347
- const done = new Promise((resolve18) => settle2 = resolve18);
17347
+ const done = new Promise((resolve19) => settle2 = resolve19);
17348
17348
  ctx.reply = (reply) => {
17349
17349
  if (replied) return false;
17350
17350
  replied = reply;
@@ -17361,7 +17361,7 @@ var init_nodes = __esm({
17361
17361
  const connection = this.connections.get(port);
17362
17362
  const running = connection?.running;
17363
17363
  let ran;
17364
- const executed = new Promise((resolve18) => ran = resolve18);
17364
+ const executed = new Promise((resolve19) => ran = resolve19);
17365
17365
  running?.add(executed);
17366
17366
  connection?.executions.add(execution);
17367
17367
  const finish = () => {
@@ -17942,11 +17942,11 @@ var init_proxy = __esm({
17942
17942
  this.phase = "open";
17943
17943
  this.finished = this.source.execute(this.entry, this.ctx).then(
17944
17944
  (out$) => new Promise(
17945
- (resolve18, reject) => out$.subscribe({
17945
+ (resolve19, reject) => out$.subscribe({
17946
17946
  error: reject,
17947
17947
  // Ended by the graph, not by end() or abort() (a node completed early): what is
17948
17948
  // sent after this would wait for nothing, so it ends as a failure does.
17949
- complete: () => this.phase === "ended" ? resolve18() : reject(new Error("The agent stream\u2019s execution ended early"))
17949
+ complete: () => this.phase === "ended" ? resolve19() : reject(new Error("The agent stream\u2019s execution ended early"))
17950
17950
  })
17951
17951
  )
17952
17952
  ).catch((error) => this.failed(error));
@@ -18472,7 +18472,7 @@ var init_mcp3 = __esm({
18472
18472
  }
18473
18473
  async request(source, front, port, interactions, call, signal) {
18474
18474
  let settle2;
18475
- const done = new Promise((resolve18) => settle2 = resolve18);
18475
+ const done = new Promise((resolve19) => settle2 = resolve19);
18476
18476
  let replied = false;
18477
18477
  const ctx = {
18478
18478
  requestId: randomUUID14(),
@@ -18841,7 +18841,7 @@ var init_pi2 = __esm({
18841
18841
  ctx.turn.onCancel((reason) => execution.abort(reason));
18842
18842
  let replied = false;
18843
18843
  let settle2;
18844
- const done = new Promise((resolve18) => settle2 = resolve18);
18844
+ const done = new Promise((resolve19) => settle2 = resolve19);
18845
18845
  ctx.reply = (reply) => {
18846
18846
  if (replied) return false;
18847
18847
  replied = true;
@@ -22222,7 +22222,7 @@ var init_rpc2 = __esm({
22222
22222
  this.name = options.name ?? "peer";
22223
22223
  this.clock = options.clock ?? systemClock;
22224
22224
  this.writer = channel.writable.getWriter();
22225
- this.closed = new Promise((resolve18) => this.resolveClosed = resolve18);
22225
+ this.closed = new Promise((resolve19) => this.resolveClosed = resolve19);
22226
22226
  this.writer.closed.catch(() => {
22227
22227
  if (this.current === "draining") this.finish({ reason: "remote-ended" });
22228
22228
  });
@@ -22306,8 +22306,8 @@ var init_rpc2 = __esm({
22306
22306
  return Promise.reject(new LocalError("aborted", `${this.name}: ${method} aborted before it was sent`, { method, cause: options.signal.reason }));
22307
22307
  }
22308
22308
  const id = this.nextId++;
22309
- return new Promise((resolve18, reject) => {
22310
- const pending = { method, resolve: resolve18, reject, cleanups: [] };
22309
+ return new Promise((resolve19, reject) => {
22310
+ const pending = { method, resolve: resolve19, reject, cleanups: [] };
22311
22311
  this.pending.set(id, pending);
22312
22312
  const timeoutMs = options.timeoutMs ?? this.options.timeoutMs;
22313
22313
  if (timeoutMs !== void 0 && timeoutMs > 0 && Number.isFinite(timeoutMs)) {
@@ -23060,7 +23060,7 @@ async function decide(policy, request, signal) {
23060
23060
  try {
23061
23061
  const decision = await Promise.race([
23062
23062
  Promise.resolve(policy(request, signal)),
23063
- new Promise((resolve18) => signal.addEventListener("abort", () => resolve18("cancelled"), { once: true }))
23063
+ new Promise((resolve19) => signal.addEventListener("abort", () => resolve19("cancelled"), { once: true }))
23064
23064
  ]);
23065
23065
  return signal.aborted ? { outcome: "cancelled" } : resolveDecision(decision, request.options);
23066
23066
  } catch {
@@ -23936,8 +23936,8 @@ var init_turn = __esm({
23936
23936
  if (!Number.isInteger(history) || history < 0) throw new RangeError(`history must be 'all', 'none' or a whole number >= 0, not ${history}`);
23937
23937
  this.keep = history;
23938
23938
  }
23939
- this.done = new Promise((resolve18, reject) => {
23940
- this.resolveDone = resolve18;
23939
+ this.done = new Promise((resolve19, reject) => {
23940
+ this.resolveDone = resolve19;
23941
23941
  this.rejectDone = reject;
23942
23942
  });
23943
23943
  this.done.catch(() => {
@@ -23987,7 +23987,7 @@ var init_turn = __esm({
23987
23987
  return;
23988
23988
  }
23989
23989
  this.trim();
23990
- await new Promise((resolve18) => this.waiters.add(resolve18));
23990
+ await new Promise((resolve19) => this.waiters.add(resolve19));
23991
23991
  }
23992
23992
  } finally {
23993
23993
  this.cursors.delete(ref);
@@ -24083,11 +24083,11 @@ var init_turn = __esm({
24083
24083
  if (!this.observer || this.observerEnded || this.finished) return;
24084
24084
  const target = this.total;
24085
24085
  if (this.dispatched >= target) return;
24086
- await new Promise((resolve18) => {
24086
+ await new Promise((resolve19) => {
24087
24087
  const done = () => {
24088
24088
  clearTimeout(timer);
24089
24089
  this.progress.delete(check2);
24090
- resolve18();
24090
+ resolve19();
24091
24091
  };
24092
24092
  const check2 = () => {
24093
24093
  if (this.dispatched >= target || this.finished || this.observerEnded) done();
@@ -27492,8 +27492,8 @@ async function spawnProcess(command, options = {}) {
27492
27492
  stdio: ["pipe", "pipe", "pipe"],
27493
27493
  windowsVerbatimArguments: true
27494
27494
  });
27495
- await new Promise((resolve18, reject) => {
27496
- child.once("spawn", resolve18);
27495
+ await new Promise((resolve19, reject) => {
27496
+ child.once("spawn", resolve19);
27497
27497
  child.once("error", (error) => {
27498
27498
  const hint = error.code === "ENOENT" ? notFoundHint(command, options.cwd, windows) : error.code === "EACCES" ? `"${command}" is not executable.` : error.message;
27499
27499
  reject(new SpawnError(command, error.code, hint, { cause: error }));
@@ -27516,16 +27516,16 @@ async function spawnProcess(command, options = {}) {
27516
27516
  };
27517
27517
  child.stdin.on("error", () => {
27518
27518
  });
27519
- const exited = new Promise((resolve18) => {
27519
+ const exited = new Promise((resolve19) => {
27520
27520
  if (child.exitCode !== null || child.signalCode !== null) {
27521
- resolve18({ code: child.exitCode, signal: child.signalCode });
27521
+ resolve19({ code: child.exitCode, signal: child.signalCode });
27522
27522
  } else {
27523
- child.once("exit", (code, signal) => resolve18({ code, signal }));
27523
+ child.once("exit", (code, signal) => resolve19({ code, signal }));
27524
27524
  }
27525
27525
  });
27526
- const stdoutEnded = new Promise((resolve18) => {
27527
- if (child.stdout.readableEnded) resolve18();
27528
- else child.stdout.once("close", () => resolve18());
27526
+ const stdoutEnded = new Promise((resolve19) => {
27527
+ if (child.stdout.readableEnded) resolve19();
27528
+ else child.stdout.once("close", () => resolve19());
27529
27529
  });
27530
27530
  const ended = Promise.all([exited, stdoutEnded]).then(([info]) => info);
27531
27531
  const pid = child.pid;
@@ -27548,10 +27548,10 @@ async function spawnProcess(command, options = {}) {
27548
27548
  }
27549
27549
  };
27550
27550
  const treeKill = windows && pid !== void 0;
27551
- const killTree = (force) => new Promise((resolve18) => {
27551
+ const killTree = (force) => new Promise((resolve19) => {
27552
27552
  const fallback = () => {
27553
27553
  if (force) signalGroup("SIGKILL");
27554
- resolve18();
27554
+ resolve19();
27555
27555
  };
27556
27556
  const [file, killArgs] = taskkillCommand(pid, force, env3);
27557
27557
  let killer;
@@ -27561,7 +27561,7 @@ async function spawnProcess(command, options = {}) {
27561
27561
  return fallback();
27562
27562
  }
27563
27563
  killer.once("error", fallback);
27564
- killer.once("exit", (code) => code === 0 ? resolve18() : fallback());
27564
+ killer.once("exit", (code) => code === 0 ? resolve19() : fallback());
27565
27565
  });
27566
27566
  const killNow = () => {
27567
27567
  if (treeKill) void killTree(true);
@@ -27588,7 +27588,7 @@ async function spawnProcess(command, options = {}) {
27588
27588
  const grace = graceMs ?? options.killGraceMs ?? 2e3;
27589
27589
  const deadline = Date.now() + grace;
27590
27590
  while (groupAlive() && Date.now() < deadline) {
27591
- await new Promise((resolve18) => setTimeout(resolve18, 25));
27591
+ await new Promise((resolve19) => setTimeout(resolve19, 25));
27592
27592
  }
27593
27593
  if (groupAlive()) {
27594
27594
  if (treeKill) await killTree(true);
@@ -27616,12 +27616,12 @@ async function spawnProcess(command, options = {}) {
27616
27616
  }
27617
27617
  function webWritable(stream) {
27618
27618
  return new WritableStream({
27619
- write: (chunk) => new Promise((resolve18, reject) => {
27620
- stream.write(chunk, (error) => error ? reject(error) : resolve18());
27619
+ write: (chunk) => new Promise((resolve19, reject) => {
27620
+ stream.write(chunk, (error) => error ? reject(error) : resolve19());
27621
27621
  }),
27622
- close: () => new Promise((resolve18) => {
27623
- if (stream.writableEnded) resolve18();
27624
- else stream.end(() => resolve18());
27622
+ close: () => new Promise((resolve19) => {
27623
+ if (stream.writableEnded) resolve19();
27624
+ else stream.end(() => resolve19());
27625
27625
  }),
27626
27626
  abort: (reason) => {
27627
27627
  stream.destroy(reason instanceof Error ? reason : void 0);
@@ -27986,9 +27986,10 @@ function sessionPolicy(requested, ceiling) {
27986
27986
  function skipsPermissions(mode) {
27987
27987
  return SKIPPING.has(mode.toLowerCase());
27988
27988
  }
27989
- function checkSessionMode(mode, ceiling, configuredMode) {
27989
+ function checkSessionMode(mode, ceiling, configuredMode, agent) {
27990
27990
  if (mode === void 0 || ceiling === "allow" || mode === configuredMode) return;
27991
- if (skipsPermissions(mode)) {
27991
+ const codexDefault = mode.toLowerCase() === "default" && (configuredMode?.toLowerCase() === "read-only" || agent?.args?.some((a) => a === "codex-app-server" || a === "--backend=codex-app-server") === true);
27992
+ if (skipsPermissions(mode) || codexDefault) {
27992
27993
  throw new Error(
27993
27994
  `Mode "${mode}" is refused: in it the agent approves its own permission requests, which this server's configured ceiling ([mcp] defaultPermission = "${ceiling}") does not allow. Leave mode unset or choose a mode that asks first. Only the user can allow it, in bridge.toml.`
27994
27995
  );
@@ -28005,6 +28006,11 @@ function checkHostEnv(env3, ceiling, allowed = []) {
28005
28006
  `Environment variable${refused.length > 1 ? "s" : ""} ${refused.map((n) => `"${n}"`).join(", ")} refused: under this server's configured ceiling ([mcp] defaultPermission = "${ceiling}") a host may set only ${patterns.join(", ")}, since other variables can change what the agent trusts or runs. Only the user can allow more, with [mcp] hostEnv in bridge.toml.`
28006
28007
  );
28007
28008
  }
28009
+ function insertBridgeAgents(catalog) {
28010
+ const index = catalog.layers.findIndex((layer) => layer.source === "built-in");
28011
+ catalog.layers.splice(index >= 0 ? index + 1 : catalog.layers.length, 0, BRIDGE_AGENTS);
28012
+ return catalog;
28013
+ }
28008
28014
  function agentsOf(catalog) {
28009
28015
  const out = {};
28010
28016
  for (const agent of listAgents(catalog)) {
@@ -28039,13 +28045,10 @@ function defaultCatalog(cwd = process.cwd(), options = {}) {
28039
28045
  const index = catalog.layers.findIndex((layer) => layer.source === folderFile);
28040
28046
  if (index >= 0) catalog.layers.splice(index, 1);
28041
28047
  }
28042
- catalog.layers.push(BRIDGE_AGENTS);
28043
- return catalog;
28048
+ return insertBridgeAgents(catalog);
28044
28049
  }
28045
28050
  function builtinAgents() {
28046
- const catalog = builtinCatalog();
28047
- catalog.layers.push(BRIDGE_AGENTS);
28048
- return agentsOf(catalog);
28051
+ return agentsOf(insertBridgeAgents(builtinCatalog()));
28049
28052
  }
28050
28053
  function parseMcpConfig(tomlText, source, catalog = defaultCatalog()) {
28051
28054
  const raw = parseToml4(tomlText);
@@ -28158,9 +28161,9 @@ var init_config4 = __esm({
28158
28161
  PermissionPolicySchema = z4.enum(["ask", "user", "allow", "deny"]);
28159
28162
  STRICTNESS = { allow: 0, ask: 1, user: 1, deny: 2 };
28160
28163
  PERMISSION_SKIPPING_MODES = {
28161
- // claude-agent-acp: default (asks) and plan are fine.
28164
+ // claude-sdk and claude-agent-acp: default (asks) and plan are fine.
28162
28165
  claude: ["acceptEdits", "auto", "bypassPermissions", "dontAsk"],
28163
- // codex-acp: read-only asks. Older versions named them auto and full-access.
28166
+ // codex-app-server (read-only asks; default, auto and full-access skip workspace approvals) and codex-acp.
28164
28167
  codex: ["workspace-write", "agent", "agent-full-access", "auto", "full-access"],
28165
28168
  // Gemini CLI's approval modes (not seen in a recorded trace).
28166
28169
  gemini: ["autoEdit", "auto_edit", "yolo"],
@@ -28214,9 +28217,43 @@ var init_config4 = __esm({
28214
28217
  BRIDGE_AGENTS = {
28215
28218
  source: "bridge (built-in)",
28216
28219
  agents: {
28220
+ claude: {
28221
+ command: "bridge",
28222
+ args: ["--backend", "claude-sdk", "--transport", "stdio"],
28223
+ env: { BRIDGE_TRANSPORT: "stdio" },
28224
+ mode: "default",
28225
+ description: "Claude Code through Bridge's Claude Agent SDK backend",
28226
+ install: "Install deft-bridge (npm install -g deft-bridge) and Claude Code",
28227
+ quirks: {
28228
+ // Subspace's built-in claude quirks describe claude-agent-acp; Bridge's
28229
+ // claude-sdk backend starts in default (ask) mode and sends no _auth/status_update.
28230
+ "starts-in-auto-mode": { enabled: false },
28231
+ "account-in-auth-status": { enabled: false }
28232
+ }
28233
+ },
28234
+ codex: {
28235
+ command: "bridge",
28236
+ args: ["--backend", "codex-app-server", "--transport", "stdio"],
28237
+ env: { BRIDGE_TRANSPORT: "stdio" },
28238
+ mode: "read-only",
28239
+ description: "Codex through Bridge's native Codex App Server backend",
28240
+ install: "Install deft-bridge and @openai/codex (npm install -g @openai/codex deft-bridge)",
28241
+ quirks: {
28242
+ // Subspace's built-in codex quirks describe @agentclientprotocol/codex-acp.
28243
+ // In codex-app-server, "default" uses workspace-write + on-request (which writes
28244
+ // workspace files without asking), so sessions switch to "read-only" (read-only
28245
+ // sandbox + untrusted approvals, asking before writes and untrusted commands).
28246
+ "starts-in-agent-mode": { enabled: false },
28247
+ "refused-turn-ends-cancelled": { enabled: false },
28248
+ "mcp-calls-cancelled-in-read-only": { enabled: false },
28249
+ "reject-option-named-cancel": { enabled: false },
28250
+ "account-in-auth-status": { enabled: false }
28251
+ }
28252
+ },
28217
28253
  bridge: {
28218
28254
  command: "bridge",
28219
- args: [],
28255
+ args: ["--transport", "stdio"],
28256
+ env: { BRIDGE_TRANSPORT: "stdio" },
28220
28257
  description: "Bridge itself as an ACP agent, using the backend in bridge.toml"
28221
28258
  }
28222
28259
  }
@@ -28230,7 +28267,7 @@ var SERVER_VERSION;
28230
28267
  var init_version2 = __esm({
28231
28268
  "packages/mcp-front/src/version.ts"() {
28232
28269
  "use strict";
28233
- SERVER_VERSION = "0.3.0";
28270
+ SERVER_VERSION = "0.3.1";
28234
28271
  }
28235
28272
  });
28236
28273
 
@@ -28616,6 +28653,13 @@ var init_session_manager = __esm({
28616
28653
  * the person. Without it, agents are told there is no elicitation.
28617
28654
  */
28618
28655
  userElicitationHandler;
28656
+ /**
28657
+ * Path to the running `bridge` CLI script (set by `bridge mcp`). When set,
28658
+ * agents whose `command` is `"bridge"` spawn this script under
28659
+ * `process.execPath`, so `npx` and repo checkouts need no global `bridge` on
28660
+ * `PATH` and always run the same Bridge build.
28661
+ */
28662
+ bridgeEntry;
28619
28663
  closing = /* @__PURE__ */ new Map();
28620
28664
  /** Starts still in progress (git and agent startup), so shutdown can wait for them. */
28621
28665
  starting = /* @__PURE__ */ new Set();
@@ -28648,10 +28692,18 @@ var init_session_manager = __esm({
28648
28692
  throw startCancelled();
28649
28693
  }
28650
28694
  let agentProcess;
28695
+ const isBridgeCmd = options.agent.command === "bridge";
28696
+ const useSelf = isBridgeCmd && Boolean(this.bridgeEntry);
28697
+ const spawnCmd = useSelf ? process.execPath : options.agent.command;
28698
+ const spawnArgs = useSelf ? [this.bridgeEntry, ...options.agent.args] : options.agent.args;
28651
28699
  try {
28652
- agentProcess = await spawnProcess(options.agent.command, {
28653
- args: options.agent.args,
28654
- env: { ...options.agent.env, ...options.env ?? {} },
28700
+ agentProcess = await spawnProcess(spawnCmd, {
28701
+ args: spawnArgs,
28702
+ env: {
28703
+ ...isBridgeCmd ? { BRIDGE_TRANSPORT: "stdio" } : {},
28704
+ ...options.agent.env,
28705
+ ...options.env ?? {}
28706
+ },
28655
28707
  cwd
28656
28708
  });
28657
28709
  } catch (err) {
@@ -29497,7 +29549,7 @@ function createServer2(config, manager = new SessionManager2(), options = {}) {
29497
29549
  ),
29498
29550
  base: z5.string().optional().describe("With worktree: the commit, branch, or tag to start from (default HEAD)."),
29499
29551
  mode: z5.string().optional().describe(
29500
- `ACP session mode to switch to, if the agent offers it (for example Claude's "default" ask mode). Overrides the agent's configured mode. Usually leave it unset: the built-in presets start in a mode that asks before acting (Codex "read-only", Claude "default"), and the agent can still edit files and run commands once you approve its permission request.` + (config.defaultPermission === "allow" ? "" : ` Modes in which the agent approves its own permission requests (for example Claude's "acceptEdits", "auto" or "bypassPermissions", Codex's "workspace-write", "agent" or "agent-full-access") are refused, because the server's permission ceiling is "${ceiling}".`)
29552
+ `ACP session mode to switch to, if the agent offers it (for example Claude's "default" ask mode or Codex's "read-only" ask mode). Overrides the agent's configured mode. Usually leave it unset: the built-in presets start in a mode that asks before acting (Codex "read-only", Claude "default"), and the agent can still edit files and run commands once you approve its permission request.` + (config.defaultPermission === "allow" ? "" : ` Modes in which the agent approves its own permission requests (for example Claude's "acceptEdits", "auto" or "bypassPermissions", Codex's "default", "auto", "full-access", "workspace-write", "agent" or "agent-full-access") are refused, because the server's permission ceiling is "${ceiling}".`)
29501
29553
  )
29502
29554
  }
29503
29555
  },
@@ -29509,7 +29561,7 @@ function createServer2(config, manager = new SessionManager2(), options = {}) {
29509
29561
  );
29510
29562
  }
29511
29563
  const policy = sessionPolicy(permission, config.defaultPermission);
29512
- checkSessionMode(mode, config.defaultPermission, definition.mode);
29564
+ checkSessionMode(mode, config.defaultPermission, definition.mode, definition);
29513
29565
  checkHostEnv(env3, config.defaultPermission, config.hostEnv);
29514
29566
  const servers = mcpServersFor(config.servers, agent);
29515
29567
  const session = await manager.startSession({
@@ -29757,7 +29809,7 @@ function createServer2(config, manager = new SessionManager2(), options = {}) {
29757
29809
  };
29758
29810
  let handlers;
29759
29811
  let closedResolve;
29760
- const closed = new Promise((resolve18) => closedResolve = resolve18);
29812
+ const closed = new Promise((resolve19) => closedResolve = resolve19);
29761
29813
  const abort = new AbortController();
29762
29814
  const previousClose = server.server.onclose;
29763
29815
  let state = "open";
@@ -29936,7 +29988,7 @@ function readGraph(path2) {
29936
29988
  );
29937
29989
  }
29938
29990
  }
29939
- async function runMcpServer(args) {
29991
+ async function runMcpServer(args, options = {}) {
29940
29992
  const { help, configPath, graphPath } = parseMcpArgs(args);
29941
29993
  if (help) {
29942
29994
  process.stderr.write(MCP_USAGE);
@@ -29944,6 +29996,7 @@ async function runMcpServer(args) {
29944
29996
  }
29945
29997
  const config = loadMcpConfig(configPath);
29946
29998
  const manager = new SessionManager2();
29999
+ if (options.bridgeEntry) manager.bridgeEntry = options.bridgeEntry;
29947
30000
  const server = createServer2(config, manager, graphPath ? { graph: readGraph(graphPath) } : {});
29948
30001
  let stopping = false;
29949
30002
  const shutdown = async () => {
@@ -30018,6 +30071,8 @@ var init_src8 = __esm({
30018
30071
  });
30019
30072
 
30020
30073
  // packages/cli/src/cli-main.ts
30074
+ import { statSync as statSync2 } from "node:fs";
30075
+ import { resolve as resolve18 } from "node:path";
30021
30076
  import { pathToFileURL as pathToFileURL3 } from "node:url";
30022
30077
 
30023
30078
  // packages/cli/src/bridge-server.ts
@@ -31923,9 +31978,9 @@ var HttpFront = class {
31923
31978
  );
31924
31979
  const server = http.createServer((req, res) => void this.handle(req, res));
31925
31980
  this.server = server;
31926
- await new Promise((resolve18, reject) => {
31981
+ await new Promise((resolve19, reject) => {
31927
31982
  server.once("error", reject);
31928
- server.listen(this.options.port ?? 6809, this.host, () => resolve18());
31983
+ server.listen(this.options.port ?? 6809, this.host, () => resolve19());
31929
31984
  });
31930
31985
  }
31931
31986
  /** Idempotent: a second call waits for the first. */
@@ -31937,14 +31992,14 @@ var HttpFront = class {
31937
31992
  for (const connection of [...this.connections.values()]) this.end(connection);
31938
31993
  const server = this.server;
31939
31994
  if (!server) return;
31940
- await new Promise((resolve18) => {
31995
+ await new Promise((resolve19) => {
31941
31996
  const grace = setTimeout(
31942
31997
  () => server.closeAllConnections(),
31943
31998
  this.options.stopGraceMs ?? 2e3
31944
31999
  );
31945
32000
  server.close(() => {
31946
32001
  clearTimeout(grace);
31947
- resolve18();
32002
+ resolve19();
31948
32003
  });
31949
32004
  server.closeIdleConnections();
31950
32005
  });
@@ -32298,7 +32353,7 @@ function piPort(channel) {
32298
32353
  const writer = channel.writable.getWriter();
32299
32354
  const abort = new AbortController();
32300
32355
  let resolveClosed;
32301
- const closed = new Promise((resolve18) => resolveClosed = resolve18);
32356
+ const closed = new Promise((resolve19) => resolveClosed = resolve19);
32302
32357
  const write = (message) => writer.write(message).catch(() => {
32303
32358
  });
32304
32359
  let counter = 0;
@@ -32516,7 +32571,7 @@ function processConnector(options = {}) {
32516
32571
  addLine(partial);
32517
32572
  partial = "";
32518
32573
  });
32519
- const ended = new Promise((resolve18) => child.once("close", () => resolve18()));
32574
+ const ended = new Promise((resolve19) => child.once("close", () => resolve19()));
32520
32575
  const channel = ndjson({
32521
32576
  readable: Readable.toWeb(child.stdout),
32522
32577
  writable: Writable2.toWeb(child.stdin)
@@ -32539,7 +32594,7 @@ function processConnector(options = {}) {
32539
32594
  let timer;
32540
32595
  await Promise.race([
32541
32596
  ended,
32542
- new Promise((resolve18) => timer = setTimeout(resolve18, EXIT_WAIT_MS))
32597
+ new Promise((resolve19) => timer = setTimeout(resolve19, EXIT_WAIT_MS))
32543
32598
  ]);
32544
32599
  clearTimeout(timer);
32545
32600
  }
@@ -33006,8 +33061,8 @@ var BridgeServer = class {
33006
33061
  const bounded = async (step, work) => {
33007
33062
  if (!work) return;
33008
33063
  let timer;
33009
- const timedOut = new Promise((resolve18) => {
33010
- timer = setTimeout(() => resolve18("timeout"), capMs);
33064
+ const timedOut = new Promise((resolve19) => {
33065
+ timer = setTimeout(() => resolve19("timeout"), capMs);
33011
33066
  });
33012
33067
  try {
33013
33068
  if (await Promise.race([work, timedOut]) === "timeout") {
@@ -33415,8 +33470,10 @@ function isMcpCommand(argv = process.argv) {
33415
33470
  async function main(argv = process.argv) {
33416
33471
  if (isMcpCommand(argv)) {
33417
33472
  const { runMcpServer: runMcpServer2 } = await Promise.resolve().then(() => (init_src8(), src_exports));
33473
+ const resolvedEntry = argv[1] ? resolve18(argv[1]) : void 0;
33474
+ const bridgeEntry = resolvedEntry && statSync2(resolvedEntry, { throwIfNoEntry: false })?.isFile() ? resolvedEntry : void 0;
33418
33475
  try {
33419
- await runMcpServer2(argv.slice(3));
33476
+ await runMcpServer2(argv.slice(3), bridgeEntry ? { bridgeEntry } : void 0);
33420
33477
  } catch (err) {
33421
33478
  process.stderr.write(`bridge mcp: ${err instanceof Error ? err.message : String(err)}
33422
33479
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deft-bridge",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Bridge: an ACP agent server, and (bridge mcp) an MCP server that drives ACP agents",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -59,7 +59,7 @@
59
59
  },
60
60
  "devDependencies": {
61
61
  "esbuild": "0.28.2",
62
- "@bridge/cli": "0.3.0"
62
+ "@bridge/cli": "0.3.1"
63
63
  },
64
64
  "scripts": {
65
65
  "bundle": "node scripts/bundle.mjs",