@abide/bridge 0.6.2 → 0.7.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # @abide/bridge
2
2
 
3
+ ## 0.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - eb51ccb: the pairing question leaves no unresponsive app in front once answered, draws a site with no icon as an app, and names Claude Code's Agent tool ([`65e13db`](https://github.com/briancray/abide/commit/65e13db8a3a2a7b4258e3578747f15b5c78aa5a0))
8
+
9
+ ## 0.7.0
10
+
11
+ ### Minor Changes
12
+
13
+ - f929fa5: one headline at every level — "<app> (<site>) is requesting access to Claude Code." — with what it asks for first in the body — 44.42 ([`3b6b3f5`](https://github.com/briancray/abide/commit/3b6b3f54ae9e6cb47eedc877c662461606e89727))
14
+ - f929fa5: the question's buttons are laid out as each desktop lays its own — Allow the default, Don't Allow on Escape ([`498200a`](https://github.com/briancray/abide/commit/498200a9d30faa9c1fc57a3b96bfb2d4621edf64))
15
+ - f929fa5: the question names what a link asks of this machine by what it lets the site do, and every MCP tool on one line counted per server — 44.65, 44.92 ([`73be13a`](https://github.com/briancray/abide/commit/73be13ab61845b0026946cdf2cb0c409be004fd7))
16
+ - f929fa5: every level of the question says what it requests the same way, offers Only Site Tools wherever it asks for anything of this machine, and remembers which was granted — 44.62, 44.86, 44.88 ([`7803bbe`](https://github.com/briancray/abide/commit/7803bbe849dc7450d9e11e95a9707c2cf7b9c2ae))
17
+ - f929fa5: Allow first, Only Site Tools beside it, Don't Allow last; each button answers by what it says — 44.86 ([`b92e292`](https://github.com/briancray/abide/commit/b92e292e8e9d0245768caad361c41b94099a3728))
18
+ - f929fa5: Allow is the question's default — blue, pressed by Return — and Escape is Don't Allow ([`cc2d66a`](https://github.com/briancray/abide/commit/cc2d66a38499b779f90daa5a42798a2b8cdb49e3))
19
+ - 7e887bb: The bridge runs Claude Code in auto mode, and asks the page about anything auto mode would ask you: `provider.claudeCode` yields each prompt as a `permission` event, and `provider.claudeCode.permit(id, allow)` answers it. A granted tool is no longer approved just for being granted. `abide-bridge --full` (and `abide-bridge install --full`) gives a site everything your Claude Code has, and the native app's own bridge always runs that way.
20
+ - fac557b: `abide-bridge install` run from a checkout of the bridge — `bun packages/bridge/bin/abideBridge.ts install` — makes every pairing link open with that checkout's handler and run its bridge, whatever release the link names, so an edit there is what the next link runs.
21
+ - af74604: A site can ask a visitor's Claude Code for full access: `provider.claudeCode.bridgeCommand({ full: true })` and `provider.claudeCode.bridge({ full: true })` carry `--full` in the command and ask for it in the link, and `ABIDE_BRIDGE_FULL` does the same for `pairing()`. Opening such a link names no tool: it says the site is requesting full access, and offers Allow, Only Site Tools or Don't Allow. Allow is now kept for the site and the person its code was minted for, with no separate Always Allow, and an ask for full access is kept as it was answered; `abide-bridge forget` undoes it. The question is a macOS alert with a bold headline, and no longer names the bridge release, which the handler's log keeps.
22
+ - 8d12435: A native app built with `abide bundle` now pairs its window with Claude Code on the same machine. Nothing needs to be installed, no link needs clicking and no code is spent (RULEBOOK 44.77). `provider.claudeCode` runs turns there, inside the app's process, and pages see an ordinary paired `BridgeStatus`. The window's turns get every tool the site asks for, both built-in tools and MCP tools whose server is in the visitor's Claude Code user scope. `missing` lists only MCP tools whose server it doesn't find (RULEBOOK 44.78). Only the window counts as local. It proves this with a cookie minted at each launch, never by its user agent (RULEBOOK 44.79).
23
+
24
+ The native app runs with the `PATH` the visitor's login shell sets, so it finds `claude` even when opened from the Finder (RULEBOOK 44.80). The window and the menu bar extra's panel now hand links of other schemes, such as `abide-bridge:` and `mailto:`, to macOS instead of failing them (RULEBOOK 38.174).
25
+
26
+ `@abide/abide` now depends on `@abide/bridge`. The bridge's turn handling is now one module, `@abide/bridge/serveTurns`, shared by `abide-bridge` and the native app.
27
+ - 9d74469: The question a pairing link asks is each desktop's own, by the asking app: on macOS a native `NSAlert` the bridge shows itself, in front, with the site's `/icon.png` as its icon; on Windows a dialog with a bold headline, the icon and labelled buttons in place of Yes/No/Cancel; on Linux zenity or kdialog titled by the app, with its icon. The headline names the app beside its site — `CRM (crm.example)` — which `/__abide/bridge`'s holder answer now carries as `name`.
28
+ - 6531d98: An app can say why it asks to pair: `provider.claudeCode.bridgeCommand({ note })` and `provider.claudeCode.bridge({ note })`, or `ABIDE_BRIDGE_NOTE` for `pairing()`, keep a note with the pairing's code, and the question a pairing link asks shows it under its headline as the app's own words — `From CRM: …`, one line of at most 200 characters. The rest of the question stays the bridge's.
29
+
3
30
  ## 0.6.2
4
31
 
5
32
  ### Patch Changes
@@ -1,18 +1,22 @@
1
1
  #!/usr/bin/env bun
2
- // `abide-bridge <site> <code> [--claude <path>] [--env NAME=VALUE]... [-- <claude options>]` — the command
3
- // an abide site shows you to connect your Claude Code to its assistant. `--claude <path>` names the
4
- // executable where `claude` is not on PATH; each `--env` sets a variable Claude Code runs with; whatever
5
- // follows `--` is passed to Claude Code as you wrote it, and is how you give a site what reaches this
6
- // machine — `-- --tools WebSearch,WebFetch` for the built-in tools it asks for.
2
+ // `abide-bridge <site> <code> [--full] [--claude <path>] [--env NAME=VALUE]... [-- <claude options>]` — the
3
+ // command an abide site shows you to connect your Claude Code to its assistant. `--claude <path>` names
4
+ // the executable where `claude` is not on PATH; each `--env` sets a variable Claude Code runs with;
5
+ // whatever follows `--` is passed to Claude Code as you wrote it, and is how you give a site what
6
+ // reaches this machine — `-- --tools WebSearch,WebFetch` for the built-in tools it asks for — and
7
+ // `--full` gives it everything your Claude Code has.
7
8
  //
8
9
  // `abide-bridge install` takes the same options and builds and registers, on macOS, Linux or Windows,
9
10
  // what opens the pairing link a site shows beside its command, so a click pairs instead of a terminal —
10
11
  // every link it opens runs with the `--env` and the `--` options given here (44.44); `abide-bridge
11
12
  // uninstall` takes it away. `abide-bridge forget [<site>]` stops always allowing a site, or every site.
13
+ // Run from a checkout — `bun packages/bridge/bin/abideBridge.ts install` — every link opens with the
14
+ // checkout's handler and runs its bridge, whatever release the link names (44.89).
12
15
 
13
16
  import { allowedIn, forget } from '../src/allowedSites.ts'
14
17
  import { bridge } from '../src/bridge.ts'
15
18
  import {
19
+ checkoutOf,
16
20
  handlerDirectory,
17
21
  install,
18
22
  installDirectory,
@@ -20,19 +24,21 @@ import {
20
24
  } from '../src/install.ts'
21
25
 
22
26
  const USAGE =
23
- 'usage: abide-bridge <site> <code> [--claude <path>] [--env NAME=VALUE]... [-- <claude options>]\n abide-bridge install [--claude <path>] [--env NAME=VALUE]... [-- <claude options>]\n abide-bridge uninstall\n abide-bridge forget [<site>]'
27
+ 'usage: abide-bridge <site> <code> [--full] [--claude <path>] [--env NAME=VALUE]... [-- <claude options>]\n abide-bridge install [--full] [--claude <path>] [--env NAME=VALUE]... [-- <claude options>]\n abide-bridge uninstall\n abide-bridge forget [<site>]'
24
28
 
25
29
  const all = process.argv.slice(2)
26
30
  const split = all.indexOf('--')
27
31
  const args = split === -1 ? all : all.slice(0, split)
28
32
  const claudeArgs = split === -1 ? [] : all.slice(split + 1)
29
33
  let claude: string | undefined
34
+ let full = false
30
35
  const env: Record<string, string> = {}
31
36
  const positional: string[] = []
32
37
  let malformed = false
33
38
  for (let index = 0; index < args.length; index++) {
34
39
  const arg = args[index] as string
35
40
  if (arg === '--claude') claude = args[++index]
41
+ else if (arg === '--full') full = true
36
42
  else if (arg === '--env') {
37
43
  const assignment = /^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s.exec(
38
44
  args[++index] ?? '',
@@ -79,16 +85,23 @@ try {
79
85
  : `--claude ${claude} is no executable here. Name the path to Claude Code, and run this again.`,
80
86
  )
81
87
  if (site === 'install') {
88
+ const checkout = checkoutOf(import.meta.dir)
82
89
  const app = await install({
83
90
  bun: process.execPath,
84
91
  claude: found,
85
92
  path: Bun.env.PATH ?? '',
86
93
  claudeArgs,
94
+ full,
87
95
  env,
96
+ ...(checkout === undefined ? {} : { checkout }),
88
97
  })
89
98
  console.error(
90
99
  `Installed ${app}. A site's pairing link now opens here, and asks you before it pairs. \`abide-bridge uninstall\` removes it.`,
91
100
  )
101
+ if (checkout !== undefined)
102
+ console.error(
103
+ `Every link runs the bridge in ${checkout}, whatever release it names, and your edits there are what the next link runs. Run install from a release to stop.`,
104
+ )
92
105
  } else {
93
106
  // Claude Code is started with this process's environment.
94
107
  Object.assign(process.env, env)
@@ -96,6 +109,7 @@ try {
96
109
  site,
97
110
  code: code as string,
98
111
  claudeArgs,
112
+ full,
99
113
  claude: found,
100
114
  })
101
115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abide/bridge",
3
- "version": "0.6.2",
3
+ "version": "0.7.1",
4
4
  "type": "module",
5
5
  "description": "Connects the Claude Code on your machine to the assistant on an abide site",
6
6
  "license": "MIT",
@@ -18,6 +18,11 @@
18
18
  "access": "public",
19
19
  "provenance": true
20
20
  },
21
+ "exports": {
22
+ "./serveTurns": "./src/serveTurns.ts",
23
+ "./grant": "./src/grant.ts",
24
+ "./package.json": "./package.json"
25
+ },
21
26
  "bin": {
22
27
  "abide-bridge": "./bin/abideBridge.ts"
23
28
  },
@@ -1,11 +1,20 @@
1
1
  // THE SITES A VISITOR ALWAYS ALLOWS (44.62), kept beside the handler install wrote so uninstall takes
2
2
  // them too. ONE PER SITE AND HOLDER: a link pairs unasked only where its code was minted for the same
3
- // holder `/__abide/bridge` named when the visitor chose to always allow it — a code an attacker minted
4
- // is minted for the attacker, and is asked about.
3
+ // holder `/__abide/bridge` named when the visitor allowed it — a code an attacker minted is minted for
4
+ // the attacker, and is asked about. A visitor who allowed a site full access, or only its own tools
5
+ // (44.86), is not asked again: it runs as they allowed it, whatever it asks for.
5
6
  import { siteOf } from './pairingLink.ts'
6
7
 
7
- /** A site paired unasked, for one holder, while a link asks for none but `tools`. */
8
- export type AllowedSite = { site: string; holder: string; tools: string[] }
8
+ /**
9
+ * A site paired unasked, for one holder, while a link asks for none but `tools` — or whatever it asks
10
+ * for, where the visitor `granted` it full access or only its own tools.
11
+ */
12
+ export type AllowedSite = {
13
+ site: string
14
+ holder: string
15
+ tools: string[]
16
+ granted?: 'full' | 'siteTools'
17
+ }
9
18
 
10
19
  /** The file the sites `directory`'s handler always allows are kept in. */
11
20
  export function allowedIn(directory: string): string {
@@ -18,28 +27,38 @@ export async function allowedSites(file: string): Promise<AllowedSite[]> {
18
27
  return (await kept.exists()) ? ((await kept.json()) as AllowedSite[]) : []
19
28
  }
20
29
 
21
- /** Whether `sites` let a link for `site`, minted for `holder` and asking for `tools`, pair unasked. 44.62. */
22
- export function allowsUnasked(
30
+ /**
31
+ * The site `sites` let a link for `site`, minted for `holder`, pair unasked as, or `undefined` where
32
+ * they do not: it asks for a tool beyond those allowed, or for full access, and was granted neither
33
+ * full access nor only its own tools. 44.62.
34
+ */
35
+ export function allowedAs(
23
36
  sites: readonly AllowedSite[],
24
37
  site: string,
25
38
  holder: string,
26
- tools: readonly string[],
27
- ): boolean {
39
+ asked: { tools: readonly string[]; full: boolean },
40
+ ): AllowedSite | undefined {
28
41
  for (const allowed of sites)
29
42
  if (allowed.site === site && allowed.holder === holder) {
30
- for (const tool of tools)
31
- if (!allowed.tools.includes(tool)) return false
32
- return true
43
+ if (allowed.granted !== undefined) return allowed
44
+ if (asked.full) return undefined
45
+ for (const tool of asked.tools)
46
+ if (!allowed.tools.includes(tool)) return undefined
47
+ return allowed
33
48
  }
34
- return false
49
+ return undefined
35
50
  }
36
51
 
37
- /** Keeps `site` always allowed for `holder`, with `tools` beside the ones allowed before. */
52
+ /**
53
+ * Keeps `site` always allowed for `holder`, with `tools` beside the ones allowed before, and — where
54
+ * the visitor answered so — `granted` full access or only its own tools.
55
+ */
38
56
  export async function allowAlways(
39
57
  file: string,
40
58
  site: string,
41
59
  holder: string,
42
60
  tools: readonly string[],
61
+ granted?: 'full' | 'siteTools',
43
62
  ): Promise<void> {
44
63
  const sites = await allowedSites(file)
45
64
  let entry = sites.find(
@@ -51,6 +70,7 @@ export async function allowAlways(
51
70
  }
52
71
  for (const tool of tools)
53
72
  if (!entry.tools.includes(tool)) entry.tools.push(tool)
73
+ if (granted !== undefined) entry.granted = granted
54
74
  await Bun.write(file, JSON.stringify(sites, null, 4))
55
75
  }
56
76
 
package/src/bridge.ts CHANGED
@@ -7,21 +7,17 @@
7
7
  // inside the page's own request, as the person at the page. No credential of theirs reaches this
8
8
  // machine, and none of this machine's reaches the site.
9
9
 
10
- import type { ProviderEvent } from '@abide/abide/server'
11
-
12
10
  import { BRIDGE_PATH } from './BRIDGE_PATH.ts'
13
- import { claudeTurn, type TurnRequest } from './claudeTurn.ts'
14
11
  import { grantFor, withheldNotices } from './grant.ts'
15
12
  import { HEARTBEAT_MILLISECONDS } from './HEARTBEAT_MILLISECONDS.ts'
16
13
  import { siteOf } from './pairingLink.ts'
17
14
  import { readLines } from './readLines.ts'
18
15
  import { RESUME_MILLISECONDS } from './RESUME_MILLISECONDS.ts'
16
+ import { serveTurns, type TurnFrame, type TurnReport } from './serveTurns.ts'
19
17
  import { siteTls } from './siteTls.ts'
20
18
 
21
19
  // How long reports gather before they are posted, so a streamed reply is not a post per token.
22
20
  const BATCH_MILLISECONDS = 15
23
- // 44.24 — how long a relayed MCP request waits for the site's reply.
24
- const REPLY_MILLISECONDS = 120_000
25
21
  // 44.25 — the first wait before redialing a dropped stream, doubled per failed dial up to the last.
26
22
  const FIRST_REDIAL_MILLISECONDS = 250
27
23
  const LAST_REDIAL_MILLISECONDS = 8_000
@@ -30,51 +26,10 @@ export const SILENCE_MILLISECONDS = 3 * HEARTBEAT_MILLISECONDS
30
26
 
31
27
  type SiteFrame =
32
28
  | { type: 'paired'; token: string; tools?: string[] }
33
- | ({ type: 'turn' } & TurnRequest)
34
- | {
35
- type: 'reply'
36
- turn: string
37
- id: number
38
- reply: Record<string, unknown>
39
- }
40
- | { type: 'cancel'; turn: string }
29
+ | TurnFrame
41
30
  | { type: 'bye' }
42
31
 
43
- type Report =
44
- | { type: 'event'; turn: string; event: ProviderEvent }
45
- | {
46
- type: 'mcp'
47
- turn: string
48
- id: number
49
- method: string
50
- params: unknown
51
- }
52
- | { type: 'end'; turn: string }
53
- | { type: 'fail'; turn: string; message: string }
54
- | { type: 'missing'; tools: string[] }
55
-
56
- /** A relayed MCP request the site has yet to reply to. */
57
- type Waiting = {
58
- turn: string
59
- method: string
60
- answer: (reply: Record<string, unknown>) => void
61
- deadline: ReturnType<typeof setTimeout>
62
- }
63
-
64
- /** 44.46 — the abort reason of a turn the site missed part of, which it reports failed with. */
65
- class MissedTurn extends Error {}
66
-
67
- /** What Claude Code is answered where the site never replied: a failed call, or a JSON-RPC error. */
68
- function unanswered(method: string, message: string): Record<string, unknown> {
69
- return method === 'tools/call'
70
- ? {
71
- result: {
72
- content: [{ type: 'text', text: message }],
73
- isError: true,
74
- },
75
- }
76
- : { error: { code: -32603, message } }
77
- }
32
+ type Report = TurnReport | { type: 'missing'; tools: string[] }
78
33
 
79
34
  /** Pairs with `site` by `code`, and serves its turns until the site or the stream ends it. */
80
35
  export async function bridge(options: {
@@ -82,6 +37,8 @@ export async function bridge(options: {
82
37
  code: string
83
38
  claude?: string
84
39
  claudeArgs?: string[]
40
+ /** Everything `claude` has is the site's to use, prompts asked of its page. 44.82. */
41
+ full?: boolean
85
42
  say?: (line: string) => void
86
43
  replyMilliseconds?: number
87
44
  silenceMilliseconds?: number
@@ -92,7 +49,7 @@ export async function bridge(options: {
92
49
  // sentence naming the site by its host. The detail goes to Claude Code, in the failure it is answered.
93
50
  const host = new URL(site).host
94
51
  const say = options.say ?? ((line: string) => console.error(line))
95
- const replyMilliseconds = options.replyMilliseconds ?? REPLY_MILLISECONDS
52
+ const full = options.full ?? false
96
53
  const silenceMilliseconds =
97
54
  options.silenceMilliseconds ?? SILENCE_MILLISECONDS
98
55
  // What cuts the stream being read, where it went silent.
@@ -111,14 +68,6 @@ export async function bridge(options: {
111
68
  )
112
69
 
113
70
  let token = ''
114
- const waiting = new Map<number, Waiting>()
115
- const answer = (id: number, reply: Record<string, unknown>): void => {
116
- const waiter = waiting.get(id)
117
- if (waiter === undefined) return
118
- waiting.delete(id)
119
- clearTimeout(waiter.deadline)
120
- waiter.answer(reply)
121
- }
122
71
  const outbox: Report[] = []
123
72
  let flushing: Promise<void> = Promise.resolve()
124
73
  let scheduled = false
@@ -165,13 +114,10 @@ export async function bridge(options: {
165
114
  // A lost `missing` is said again by the next look, rather than taken as said.
166
115
  if (item.type === 'missing') reported = undefined
167
116
  else
168
- turns
169
- .get(item.turn)
170
- ?.abort(
171
- new MissedTurn(
172
- `The site missed part of this turn, so it was ended: ${failure}`,
173
- ),
174
- )
117
+ core.miss(
118
+ item.turn,
119
+ `The site missed part of this turn, so it was ended: ${failure}`,
120
+ )
175
121
  }
176
122
  // One post at a time, in order: a turn's `end` never overtakes its last event.
177
123
  const report = (item: Report): void => {
@@ -199,6 +145,7 @@ export async function bridge(options: {
199
145
  const { grant } = await grantFor(
200
146
  pairingAsked,
201
147
  options.claudeArgs ?? [],
148
+ full,
202
149
  sayOnce,
203
150
  )
204
151
  const missing = [...grant.ungranted, ...grant.unserved]
@@ -209,114 +156,27 @@ export async function bridge(options: {
209
156
  report({ type: 'missing', tools: missing })
210
157
  }
211
158
 
212
- const turns = new Map<string, AbortController>()
159
+ const core = serveTurns({
160
+ site,
161
+ claude: options.claude ?? 'claude',
162
+ claudeArgs: options.claudeArgs ?? [],
163
+ full,
164
+ report,
165
+ say: sayOnce,
166
+ beforeTurn: reportMissing,
167
+ ...(options.replyMilliseconds === undefined
168
+ ? {}
169
+ : { replyMilliseconds: options.replyMilliseconds }),
170
+ })
213
171
  // 44.30 — A SIGNAL ENDS THE RUNS WITH THE BRIDGE: exiting on one skips every `finally`, so a run
214
172
  // still going would outlive it, orphaned.
215
173
  const signals = { SIGHUP: 129, SIGINT: 130, SIGTERM: 143 } as const
216
174
  const stopped = (signal: keyof typeof signals): void => {
217
- for (const controller of turns.values()) controller.abort()
175
+ core.cancelAll()
218
176
  process.exit(signals[signal])
219
177
  }
220
178
  for (const signal of Object.keys(signals) as (keyof typeof signals)[])
221
179
  process.on(signal, stopped)
222
- let asked = 0
223
- const secret = crypto.randomUUID()
224
- const shim = Bun.serve({
225
- hostname: '127.0.0.1',
226
- port: 0,
227
- // A tool call takes as long as its handler does: the reply deadline (44.24) bounds the wait,
228
- // where bun's own idle timeout would cut every call past 10 seconds.
229
- idleTimeout: 0,
230
- async fetch(request) {
231
- const [, given, turn] = new URL(request.url).pathname.split('/')
232
- if (given !== secret || turn === undefined || !turns.has(turn))
233
- return new Response(null, { status: 404 })
234
- if (request.method !== 'POST')
235
- return new Response(null, {
236
- status: 405,
237
- headers: { allow: 'POST' },
238
- })
239
- const message = (await request.json()) as {
240
- id?: number | string
241
- method: string
242
- params?: unknown
243
- }
244
- // A notification is acknowledged here; there is nothing for the site to answer.
245
- if (message.id === undefined)
246
- return new Response(null, { status: 202 })
247
- const id = ++asked
248
- const method = message.method
249
- const reply = new Promise<Record<string, unknown>>((done) => {
250
- waiting.set(id, {
251
- turn,
252
- method,
253
- answer: done,
254
- // 44.24 — a reply lost on the way is a failure Claude Code is told of.
255
- deadline: setTimeout(
256
- () =>
257
- answer(
258
- id,
259
- unanswered(
260
- method,
261
- `${site} sent no reply within ${replyMilliseconds} ms.`,
262
- ),
263
- ),
264
- replyMilliseconds,
265
- ),
266
- })
267
- })
268
- report({
269
- type: 'mcp',
270
- turn,
271
- id,
272
- method: message.method,
273
- params: message.params,
274
- })
275
- return Response.json({
276
- jsonrpc: '2.0',
277
- id: message.id,
278
- ...(await reply),
279
- })
280
- },
281
- })
282
-
283
- const run = async (turn: TurnRequest): Promise<void> => {
284
- const controller = new AbortController()
285
- turns.set(turn.id, controller)
286
- await reportMissing()
287
- // A cancel or a signal aborts with no reason of its own, and ends the turn as asked.
288
- const missed = (): string | undefined =>
289
- controller.signal.reason instanceof MissedTurn
290
- ? controller.signal.reason.message
291
- : undefined
292
- try {
293
- await claudeTurn(turn, {
294
- claude: options.claude ?? 'claude',
295
- claudeArgs: options.claudeArgs ?? [],
296
- mcpUrl: `http://127.0.0.1:${shim.port}/${secret}/${turn.id}`,
297
- signal: controller.signal,
298
- report: (event) =>
299
- report({ type: 'event', turn: turn.id, event }),
300
- say: sayOnce,
301
- })
302
- const message = missed()
303
- if (message === undefined) report({ type: 'end', turn: turn.id })
304
- else report({ type: 'fail', turn: turn.id, message })
305
- } catch (thrown) {
306
- report({
307
- type: 'fail',
308
- turn: turn.id,
309
- message:
310
- missed() ??
311
- (thrown instanceof Error ? thrown.message : String(thrown)),
312
- })
313
- } finally {
314
- turns.delete(turn.id)
315
- for (const [id, waiter] of waiting)
316
- if (waiter.turn === turn.id)
317
- answer(id, unanswered(waiter.method, 'The turn ended.'))
318
- }
319
- }
320
180
 
321
181
  // 44.25 — THE STREAM REDIALED BY ITS TOKEN, each wait twice the last, until the site refuses it or
322
182
  // stops holding the pairing.
@@ -374,18 +234,15 @@ export async function bridge(options: {
374
234
  token = frame.token
375
235
  pairingAsked = frame.tools ?? []
376
236
  say(
377
- `Connected to ${host}. Close the page to disconnect.`,
237
+ full
238
+ ? `Connected to ${host}, which can use everything your Claude Code can. Close the page to disconnect.`
239
+ : `Connected to ${host}. Close the page to disconnect.`,
378
240
  )
379
241
  void reportMissing()
380
- } else if (frame.type === 'turn') void run(frame)
381
- else if (frame.type === 'reply')
382
- answer(frame.id, frame.reply)
383
- else if (frame.type === 'cancel')
384
- turns.get(frame.turn)?.abort()
385
- else if (frame.type === 'bye') {
242
+ } else if (frame.type === 'bye') {
386
243
  bye = true
387
244
  break
388
- }
245
+ } else core.take(frame)
389
246
  }
390
247
  } catch {
391
248
  // A stream cut mid-read is a drop like one that ended.
@@ -400,10 +257,10 @@ export async function bridge(options: {
400
257
  } finally {
401
258
  for (const signal of Object.keys(signals) as (keyof typeof signals)[])
402
259
  process.off(signal, stopped)
403
- for (const controller of turns.values()) controller.abort()
260
+ core.cancelAll()
404
261
  await flushing
405
262
  await flush()
406
- shim.stop(true)
263
+ core.stop()
407
264
  say(`Disconnected from ${host}.`)
408
265
  }
409
266
  }
package/src/claudeTurn.ts CHANGED
@@ -6,7 +6,11 @@
6
6
  // a site's is laid on as its flag where it only shapes the answer, and its `tools` are a request the
7
7
  // visitor's own `--tools` narrows (`grant.ts`). What reaches this machine — a user's settings, a
8
8
  // project's CLAUDE.md, the files around it, its shell, the web from its network, its MCP servers — is
9
- // the visitor's to give, on the bridge's command line, and nothing the site sends can.
9
+ // the visitor's to give, on the bridge's command line, and nothing the site sends can. A bridge run
10
+ // `--full` (44.82) is given all of it, as `claude` run in an empty directory is.
11
+ //
12
+ // A TOOL OF THIS MACHINE IS APPROVED AS AUTO MODE DECIDES, and what it would ask is asked of the page
13
+ // (44.81): the site's own tools alone are approved without asking.
10
14
 
11
15
  import { mkdtemp, rm } from 'node:fs/promises' // bun has no temporary directory or recursive remove of its own
12
16
  import { tmpdir } from 'node:os' // bun exposes no temporary directory of its own
@@ -16,6 +20,7 @@ import type { ClaudeCodeConfig, ProviderEvent } from '@abide/abide/server'
16
20
  import {
17
21
  type Grant,
18
22
  grantFor,
23
+ PERMISSION_SERVER,
19
24
  SERVER_NAME,
20
25
  takeFlag,
21
26
  withheldNotices,
@@ -25,6 +30,8 @@ import { readLines } from './readLines.ts'
25
30
  // Every tool of that server, as `--allowedTools` names them.
26
31
  const SERVER_TOOLS = `mcp__${SERVER_NAME}`
27
32
  const TOOL_PREFIX = `${SERVER_TOOLS}__`
33
+ /** The tool each permission prompt is asked of, as `--permission-prompt-tool` names it. 44.81. */
34
+ const PERMISSION_TOOL = `mcp__${PERMISSION_SERVER}__ask`
28
35
 
29
36
  /** What the site asks of one turn: its one message, as Messages API blocks. */
30
37
  export type TurnRequest = {
@@ -111,33 +118,40 @@ function siteFlags(config: Omit<ClaudeCodeConfig, 'tools'>): string[] {
111
118
  }
112
119
 
113
120
  /**
114
- * Every flag but the protocol's: the site's, then the visitor's — so theirs wins where both set one —
115
- * then the tools the site asked for and the visitor granted (44.29), and no setting source where the
116
- * visitor named none.
121
+ * Every flag but the protocol's: the site's, then auto mode, then the visitor's — so theirs wins where
122
+ * two set one — and of a bridge not run `--full`, the tools the site asked for and the visitor granted
123
+ * (44.29) and no setting source where the visitor named none. The site's own tools are approved
124
+ * without asking, beside whatever the visitor's `--allowedTools` approves.
117
125
  * Beside them, what the site was given of this machine (`grantFor`).
118
126
  */
119
127
  async function launchFlags(
120
128
  config: ClaudeCodeConfig,
121
129
  visitor: string[],
130
+ full: boolean,
122
131
  ): Promise<{ flags: string[]; grant: Grant }> {
123
132
  const { tools: asked, ...options } = config
124
- // 44.15 — the visitor's servers reach a turn only as the tools it was given are of them.
125
- const { grant, args } = await grantFor(asked ?? [], visitor)
126
- const allowed = takeFlag(args, ['--allowedTools', '--allowed-tools'])
127
- const sources = takeFlag(args, ['--setting-sources']) ?? []
133
+ const { grant, args } = await grantFor(asked ?? [], visitor, full)
134
+ // 44.82 — the visitor's options as they gave them, and Claude Code's own settings and servers.
135
+ const given = full ? [...visitor] : args
136
+ const allowed = takeFlag(given, ['--allowedTools', '--allowed-tools'])
137
+ const sources = full ? [] : takeFlag(given, ['--setting-sources'])
128
138
  const flags = [
129
139
  ...siteFlags(options),
130
- ...args,
131
- '--tools',
132
- grant.builtIn.join(','),
133
- // The site's own tools are always approved; one of this machine's is approved as granted,
134
- // unless the visitor said which calls of it are.
140
+ '--permission-mode',
141
+ 'auto',
142
+ ...given,
135
143
  '--allowedTools',
136
144
  SERVER_TOOLS,
137
- ...(allowed ?? [...grant.builtIn, ...grant.mcp]),
138
- '--setting-sources',
139
- sources.join(','),
145
+ ...(allowed ?? []),
140
146
  ]
147
+ if (!full)
148
+ flags.push(
149
+ '--tools',
150
+ grant.builtIn.join(','),
151
+ '--setting-sources',
152
+ (sources ?? []).join(','),
153
+ '--strict-mcp-config',
154
+ )
141
155
  return { flags, grant }
142
156
  }
143
157
 
@@ -173,22 +187,35 @@ export async function claudeTurn(
173
187
  options: {
174
188
  claude: string
175
189
  claudeArgs: string[]
190
+ /** Everything `claude` has is given, as by the native app's own bridge. 44.78, 44.82. */
191
+ full: boolean
192
+ /** The site's MCP server; the permission server is `${mcpUrl}/permission`. */
176
193
  mcpUrl: string
177
194
  signal: AbortSignal
178
195
  report: (event: ProviderEvent) => void
179
196
  say: (line: string) => void
180
197
  },
181
198
  ): Promise<void> {
182
- const { flags, grant } = await launchFlags(turn.config, options.claudeArgs)
183
- for (const notice of withheldNotices(grant)) options.say(notice)
199
+ const { flags, grant } = await launchFlags(
200
+ turn.config,
201
+ options.claudeArgs,
202
+ options.full,
203
+ )
204
+ if (!options.full)
205
+ for (const notice of withheldNotices(grant)) options.say(notice)
184
206
  const directory = await mkdtemp(`${tmpdir()}/abide-bridge-`)
185
207
  const config = `${directory}/mcp.json`
186
208
  await Bun.write(
187
209
  config,
188
210
  JSON.stringify({
189
211
  mcpServers: {
190
- ...grant.servers,
212
+ // 44.82 — a full bridge's Claude Code reads the visitor's servers where `claude` would.
213
+ ...(options.full ? {} : grant.servers),
191
214
  [SERVER_NAME]: { type: 'http', url: options.mcpUrl },
215
+ [PERMISSION_SERVER]: {
216
+ type: 'http',
217
+ url: `${options.mcpUrl}/permission`,
218
+ },
192
219
  },
193
220
  }),
194
221
  )
@@ -205,7 +232,8 @@ export async function claudeTurn(
205
232
  '--verbose',
206
233
  '--include-partial-messages',
207
234
  '--no-session-persistence',
208
- '--strict-mcp-config',
235
+ '--permission-prompt-tool',
236
+ PERMISSION_TOOL,
209
237
  '--mcp-config',
210
238
  config,
211
239
  '--max-turns',