@abide/bridge 0.6.1 → 0.7.0

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.
@@ -0,0 +1,144 @@
1
+ // THE QUESTION AS macOS's OWN ALERT, over the Objective-C runtime through `bun:ffi`: an `NSAlert` this
2
+ // process shows itself, so it comes to the front, carries the asking app's icon, and answers which
3
+ // button was pressed. abide drives AppKit the same way (`packages/abide/src/server/appKit.ts`), and
4
+ // exports none of it; the handler is bundled into one file, so this is the few calls an alert needs.
5
+ //
6
+ // LOADED WHEN ASKED, never at import: the handler runs on Linux and Windows too, where neither library
7
+ // is there to open.
8
+
9
+ import { CFunction, dlopen, FFIType } from 'bun:ffi'
10
+
11
+ type Id = number | null
12
+
13
+ /** The first button's answer from `runModal`; each button after it answers one more. */
14
+ const FIRST_BUTTON = 1000
15
+ // NSApplicationActivationPolicyAccessory: in front of the browser, with no Dock icon of its own.
16
+ const ACCESSORY = 1
17
+ // NSAlertStyleWarning: the alert's own icon, with nothing laid over it.
18
+ const WARNING = 0
19
+
20
+ const ENCODER = new TextEncoder()
21
+ function text(value: string): Uint8Array {
22
+ return ENCODER.encode(`${value}\0`)
23
+ }
24
+
25
+ /**
26
+ * Shows `headline` in bold over `body`, with `icon` where it is an image macOS reads, and `buttons` —
27
+ * the first the default, pressed by Return, and the last pressed by Escape. Answers the index of the
28
+ * button pressed.
29
+ */
30
+ export function macAlert(
31
+ headline: string,
32
+ body: string,
33
+ icon: Uint8Array | undefined,
34
+ buttons: readonly string[],
35
+ ): number {
36
+ const runtime = dlopen('/usr/lib/libobjc.A.dylib', {
37
+ objc_getClass: { args: [FFIType.cstring], returns: FFIType.ptr },
38
+ sel_registerName: { args: [FFIType.cstring], returns: FFIType.ptr },
39
+ objc_msgSend: { args: [], returns: FFIType.void },
40
+ })
41
+ // Loaded for the classes it registers, which `objc_getClass` then finds by name.
42
+ dlopen('/System/Library/Frameworks/AppKit.framework/AppKit', {
43
+ NSApplicationMain: { args: [], returns: FFIType.i32 },
44
+ })
45
+ const messenger = (
46
+ runtime.symbols.objc_msgSend as unknown as { ptr: number }
47
+ ).ptr
48
+ const senders = new Map<string, ReturnType<typeof CFunction>>()
49
+ function sendTyped(
50
+ receiver: Id,
51
+ name: string,
52
+ args: FFIType[],
53
+ returns: FFIType,
54
+ ...values: (Id | number | Uint8Array | boolean)[]
55
+ ): unknown {
56
+ const key = `${args.join(',')}>${returns}`
57
+ let sender = senders.get(key)
58
+ if (sender === undefined) {
59
+ sender = CFunction({
60
+ ptr: messenger as never,
61
+ args: [FFIType.ptr, FFIType.ptr, ...args],
62
+ returns,
63
+ })
64
+ senders.set(key, sender)
65
+ }
66
+ return sender(
67
+ receiver,
68
+ runtime.symbols.sel_registerName(text(name)),
69
+ ...values,
70
+ )
71
+ }
72
+ const send = (receiver: Id, name: string, ...values: Id[]): Id =>
73
+ sendTyped(
74
+ receiver,
75
+ name,
76
+ values.map(() => FFIType.ptr),
77
+ FFIType.ptr,
78
+ ...values,
79
+ ) as Id
80
+ const classNamed = (name: string): Id =>
81
+ runtime.symbols.objc_getClass(text(name)) as Id
82
+ const string = (value: string): Id =>
83
+ sendTyped(
84
+ classNamed('NSString'),
85
+ 'stringWithUTF8String:',
86
+ [FFIType.ptr],
87
+ FFIType.ptr,
88
+ text(value),
89
+ ) as Id
90
+
91
+ try {
92
+ const application = send(
93
+ classNamed('NSApplication'),
94
+ 'sharedApplication',
95
+ )
96
+ sendTyped(
97
+ application,
98
+ 'setActivationPolicy:',
99
+ [FFIType.i64],
100
+ FFIType.bool,
101
+ ACCESSORY,
102
+ )
103
+ send(application, 'finishLaunching')
104
+ sendTyped(
105
+ application,
106
+ 'activateIgnoringOtherApps:',
107
+ [FFIType.bool],
108
+ FFIType.void,
109
+ true,
110
+ )
111
+ const alert = send(send(classNamed('NSAlert'), 'alloc'), 'init')
112
+ sendTyped(alert, 'setAlertStyle:', [FFIType.u64], FFIType.void, WARNING)
113
+ send(alert, 'setMessageText:', string(headline))
114
+ send(alert, 'setInformativeText:', string(body))
115
+ if (icon !== undefined && icon.length > 0) {
116
+ const data = sendTyped(
117
+ classNamed('NSData'),
118
+ 'dataWithBytes:length:',
119
+ [FFIType.ptr, FFIType.u64],
120
+ FFIType.ptr,
121
+ icon,
122
+ icon.length,
123
+ ) as Id
124
+ const image = send(
125
+ send(classNamed('NSImage'), 'alloc'),
126
+ 'initWithData:',
127
+ data,
128
+ )
129
+ // An icon macOS cannot read leaves the alert its own.
130
+ if (image !== null && image !== 0) send(alert, 'setIcon:', image)
131
+ }
132
+ // Laid out as AppKit lays any alert: the first button added is the default, and where each
133
+ // goes is AppKit's. Escape, which it gives only a button titled Cancel, is the last's.
134
+ let last: Id = null
135
+ for (const button of buttons)
136
+ last = send(alert, 'addButtonWithTitle:', string(button))
137
+ send(last, 'setKeyEquivalent:', string('\u001b'))
138
+ const pressed = sendTyped(alert, 'runModal', [], FFIType.i64) as
139
+ number | bigint
140
+ return Number(pressed) - FIRST_BUTTON
141
+ } finally {
142
+ runtime.close()
143
+ }
144
+ }
package/src/opened.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  // WHAT RUNS WHEN A PAIRING LINK IS OPENED: the handler `abide-bridge install` bundles beside the app it
2
- // registers, started with the link. It asks the visitor first (44.42) — unless they always allow the
2
+ // registers, started with the link — or, installed from a checkout (44.89), the checkout's own, which
3
+ // then runs the checkout's bridge whatever release the link names. It asks the visitor first (44.42) — unless they always allow the
3
4
  // site for whoever the link's code was minted for (44.62) — then runs the release of the bridge the
4
5
  // link names, as the command a site shows would — so a site is answered by the bridge that speaks its
5
6
  // relay, while what asks is the one the visitor installed.
@@ -13,15 +14,16 @@ import { appendFile } from 'node:fs/promises' // bun has no append of its own
13
14
 
14
15
  import {
15
16
  allowAlways,
17
+ allowedAs,
16
18
  allowedIn,
17
19
  allowedSites,
18
- allowsUnasked,
19
20
  } from './allowedSites.ts'
20
- import { BRIDGE_PATH } from './bridge.ts'
21
- import { type Answer, ask, notify } from './desktop.ts'
21
+ import { BRIDGE_PATH } from './BRIDGE_PATH.ts'
22
+ import { type Answer, ask, notify, type Question } from './desktop.ts'
22
23
  import { grantFor, serversNamed } from './grant.ts'
23
24
  import { type Pairing, pairingOf } from './pairingLink.ts'
24
25
  import { readLines } from './readLines.ts'
26
+ import { requestedLines } from './requestedLines.ts'
25
27
  import { siteTls } from './siteTls.ts'
26
28
 
27
29
  /**
@@ -33,33 +35,98 @@ export type HandlerSettings = {
33
35
  claude: string
34
36
  path: string
35
37
  claudeArgs: string[]
38
+ /** `abide-bridge install --full`: every link's bridge is run `--full` (44.82). An older install's settings hold none. */
39
+ full: boolean
40
+ /** The bridge package install was run from, where it is a checkout rather than a release (44.89). */
41
+ checkout?: string
36
42
  env: Record<string, string>
37
43
  }
38
44
 
45
+ /** A site as the visitor reads it: what a link names, without its scheme. */
46
+ function shownSite(site: string): string {
47
+ return site.slice(site.indexOf('://') + 3)
48
+ }
49
+
50
+ /** Whether the visitor's options leave Claude Code in auto mode (44.81). */
51
+ function inAutoMode(claudeArgs: readonly string[]): boolean {
52
+ for (const arg of claudeArgs)
53
+ if (
54
+ arg.startsWith('--permission-mode') ||
55
+ arg.startsWith('--dangerously-skip-permissions')
56
+ )
57
+ return false
58
+ return true
59
+ }
60
+
61
+ /**
62
+ * Whether the question for `pairing` offers the site's own tools alone: where it asks for anything of
63
+ * this machine's, and install did not already give every site everything. 44.86.
64
+ */
65
+ export function offersSiteTools(
66
+ pairing: Pairing,
67
+ settings: HandlerSettings,
68
+ ): boolean {
69
+ return settings.full !== true && (pairing.full || pairing.tools.length > 0)
70
+ }
71
+
39
72
  /**
40
- * What the visitor is asked before `pairing` runs, naming each MCP tool it asks for of a server their
41
- * Claude Code is not configured with, `unserved` (44.65).
73
+ * What the visitor is asked before `pairing` runs (44.42), by the app `asker` names beside its site
74
+ * where the site names one, with its `note` as its own words (44.91): a site asking for full access is named as asking for it, and none of its tools
75
+ * (44.85); else each tool it asks for, and each MCP tool of a server their Claude Code is not
76
+ * configured with, `unserved` (44.65). Its icon is the caller's to lay on.
42
77
  */
43
78
  export function question(
44
79
  pairing: Pairing,
45
80
  settings: HandlerSettings,
46
81
  unserved: readonly string[] = [],
47
- ): string {
48
- const tools =
49
- pairing.tools.length === 0
50
- ? 'It gets none of this computer’s tools.'
51
- : `It also asks for these tools of this computer’s: ${pairing.tools.join(', ')}.`
52
- const missing =
53
- unserved.length === 0
54
- ? ''
55
- : `\n\nYour Claude Code has no ${serversNamed(unserved)} MCP server, so it can’t give ${unserved.join(', ')}. Add it with \`claude mcp add --scope user\` before you ask.`
82
+ {
83
+ name,
84
+ note,
85
+ }: { name?: string | undefined; note?: string | undefined } = {},
86
+ ): Question {
87
+ const site = shownSite(pairing.site)
88
+ // The name is the site's to choose, so the site it is served from is always beside it.
89
+ const asker = name === undefined ? site : `${name} (${site})`
90
+ const owner = name ?? site
91
+ const auto = inAutoMode(settings.claudeArgs)
92
+ ? 'Claude Code will run with permissions in auto mode: it will do safe steps on its own and ask you before anything risky.'
93
+ : ''
94
+ // One headline at every level, and what is asked for read in the body, each level alike.
95
+ const headline = `${asker} is requesting access to Claude Code.`
96
+ // 44.92 — what it asks of this machine, as what that lets it do, never a list of tool names.
97
+ const said = [
98
+ settings.full === true
99
+ ? 'Requested from this computer: full access, which you gave every site when you installed the bridge.'
100
+ : pairing.full
101
+ ? 'Requested from this computer: full access to everything Claude Code can do.'
102
+ : pairing.tools.length === 0
103
+ ? 'Requested from this computer: nothing. It uses only its own tools.'
104
+ : `Requested from this computer:\n• ${requestedLines(pairing.tools).join('\n• ')}`,
105
+ ]
106
+ // The site's own tools are approved without asking (44.81), so auto mode is said only of this machine's.
107
+ if (settings.full === true || pairing.full || pairing.tools.length > 0)
108
+ said.push(auto)
109
+ if (unserved.length > 0 && !pairing.full && settings.full !== true)
110
+ said.push(
111
+ `You don’t have a ${serversNamed(unserved)} MCP server, so its tools won’t work. Add it with \`claude mcp add --scope user\` first.`,
112
+ )
113
+ if (offersSiteTools(pairing, settings))
114
+ said.push(
115
+ 'Only Site Tools is the safest option but may limit full functionality.',
116
+ )
117
+ // 44.91 — the app's own words, said to be its own, ahead of what the bridge says.
118
+ if (note !== undefined) said.unshift(`From ${owner}: ${note}`)
56
119
  // A variable's value is only named, never shown: it is as likely a token as a host.
57
- const names = Object.keys(settings.env)
58
- const kept =
59
- settings.claudeArgs.length === 0 && names.length === 0
60
- ? ''
61
- : `\n\nIt also gets what you gave install for every site: ${[...settings.claudeArgs, ...names].join(' ')}.`
62
- return `${pairing.site} wants to use your Claude Code as its assistant, with its own tools, on your Claude account.\n\n${tools}${missing}${kept}\n\nIt runs @abide/bridge ${pairing.version}. Allow it only if you just asked to pair on that site.`
120
+ const kept = [...settings.claudeArgs, ...Object.keys(settings.env)]
121
+ if (kept.length > 0)
122
+ said.push(
123
+ `It also gets what you gave install for every site: ${kept.join(' ')}.`,
124
+ )
125
+ let body = ''
126
+ for (const paragraph of said)
127
+ if (paragraph.trim() !== '')
128
+ body += `${body === '' ? '' : '\n\n'}${paragraph.trim()}`
129
+ return { title: owner, headline, body, icon: undefined }
63
130
  }
64
131
 
65
132
  /**
@@ -73,12 +140,14 @@ export function bridgeArguments(
73
140
  const claudeArgs = claudeArgsOf(pairing, settings)
74
141
  return [
75
142
  settings.bun,
76
- 'x',
77
- `@abide/bridge@${pairing.version}`,
143
+ ...(settings.checkout === undefined
144
+ ? ['x', `@abide/bridge@${pairing.version}`]
145
+ : [`${settings.checkout}/bin/abideBridge.ts`]),
78
146
  pairing.site,
79
147
  pairing.code,
80
148
  '--claude',
81
149
  settings.claude,
150
+ ...(settings.full === true || pairing.full ? ['--full'] : []),
82
151
  ...(claudeArgs.length === 0 ? [] : ['--', ...claudeArgs]),
83
152
  ]
84
153
  }
@@ -115,22 +184,91 @@ function directoryOf(file: string): string {
115
184
  )
116
185
  }
117
186
 
187
+ /** The longest app name the question shows; a longer one is cut, so it cannot push the site out of view. */
188
+ const LONGEST_NAME = 60
189
+ /** The longest note the question shows: a sentence on why, never a page that buries the question. 44.91. */
190
+ const LONGEST_NOTE = 200
191
+
192
+ /**
193
+ * What a site wrote, as one line a reader sees: each control character a space, each run of spaces one,
194
+ * and cut at `longest` with an ellipsis where it ran past — or `undefined` where nothing is left.
195
+ */
196
+ function oneLine(written: unknown, longest: number): string | undefined {
197
+ if (typeof written !== 'string') return undefined
198
+ const line = written
199
+ .replace(/\p{Cc}/gu, ' ')
200
+ .replace(/\s+/g, ' ')
201
+ .trim()
202
+ if (line === '') return undefined
203
+ return line.length > longest ? `${line.slice(0, longest - 1)}…` : line
204
+ }
205
+
206
+ const NO_ASKER = { holder: undefined, name: undefined, note: undefined }
207
+
118
208
  /**
119
- * Who `pairing`'s code was minted for, as `/__abide/bridge` names them (44.63), or `undefined` where the
120
- * site names no one — a release before it did, or a code it did not mint.
209
+ * Who `pairing`'s code was minted for, as `/__abide/bridge` names them (44.63), the app's name and the
210
+ * note the code was minted with (44.91), or `undefined` for each the site names none of — a release
211
+ * before it did, or a code it did not mint.
121
212
  */
122
- export async function holderOf(pairing: Pairing): Promise<string | undefined> {
213
+ export async function askerOf(
214
+ pairing: Pick<Pairing, 'site' | 'code'>,
215
+ ): Promise<{
216
+ holder: string | undefined
217
+ name: string | undefined
218
+ note: string | undefined
219
+ }> {
123
220
  try {
124
221
  const answer = await fetch(
125
222
  `${pairing.site}${BRIDGE_PATH}?holder=${encodeURIComponent(pairing.code)}`,
126
223
  { tls: siteTls(), signal: AbortSignal.timeout(10_000) },
127
224
  )
128
225
  if (!answer.ok) {
226
+ await answer.body?.cancel()
227
+ return NO_ASKER
228
+ }
229
+ const { holder, name, note } = (await answer.json()) as {
230
+ holder?: unknown
231
+ name?: unknown
232
+ note?: unknown
233
+ }
234
+ return {
235
+ holder:
236
+ typeof holder === 'string' && holder !== ''
237
+ ? holder
238
+ : undefined,
239
+ name: oneLine(name, LONGEST_NAME),
240
+ note: oneLine(note, LONGEST_NOTE),
241
+ }
242
+ } catch {
243
+ return NO_ASKER
244
+ }
245
+ }
246
+
247
+ /** The largest icon the question shows: an app icon is a few hundred kilobytes at most. */
248
+ const LARGEST_ICON = 1024 * 1024
249
+ const PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]
250
+
251
+ /**
252
+ * The icon `site` publishes at `/icon.png`, abide's app icon (45.15), or `undefined` where
253
+ * it publishes none, it is no PNG, or it is larger than any app icon — the question waits on it, so it
254
+ * is given three seconds.
255
+ */
256
+ export async function iconOf(site: string): Promise<Uint8Array | undefined> {
257
+ try {
258
+ const answer = await fetch(`${site}/icon.png`, {
259
+ tls: siteTls(),
260
+ signal: AbortSignal.timeout(3_000),
261
+ })
262
+ const declared = Number(answer.headers.get('content-length') ?? 0)
263
+ if (!answer.ok || declared > LARGEST_ICON) {
129
264
  await answer.body?.cancel()
130
265
  return undefined
131
266
  }
132
- const { holder } = (await answer.json()) as { holder?: unknown }
133
- return typeof holder === 'string' && holder !== '' ? holder : undefined
267
+ const bytes = await answer.bytes()
268
+ if (bytes.length > LARGEST_ICON) return undefined
269
+ for (let at = 0; at < PNG_SIGNATURE.length; at++)
270
+ if (bytes[at] !== PNG_SIGNATURE[at]) return undefined
271
+ return bytes
134
272
  } catch {
135
273
  return undefined
136
274
  }
@@ -145,46 +283,79 @@ export async function unservedOf(
145
283
  const { grant } = await grantFor(
146
284
  pairing.tools,
147
285
  claudeArgsOf(pairing, settings),
286
+ settings.full === true,
148
287
  () => {},
149
288
  )
150
289
  return grant.unserved
151
290
  }
152
291
 
292
+ /** `pairing` with only the site's own tools: none of this machine's, and not full. 44.86. */
293
+ function siteToolsOnly(pairing: Pairing): Pairing {
294
+ return { ...pairing, tools: [], full: false }
295
+ }
296
+
153
297
  /**
154
- * Whether `pairing` may pair: unasked where the visitor always allows its site for the holder its code
155
- * was minted for and it asks for no tool beyond those allowed then (44.62), else as `askVisitor`
156
- * answers — offering to always allow only where the site named a holder — keeping an always in
157
- * `allowedFile`.
298
+ * `pairing` as the visitor allows it, or `undefined` where they do not: unasked where they allowed its
299
+ * site before for the holder its code was minted for, as they allowed it then (44.62), else as
300
+ * `askVisitor` answers — offering the site's own tools alone where it asks for anything of this
301
+ * machine's (44.86) — keeping what they allowed in `allowedFile` where the site named a holder (44.88).
158
302
  */
159
303
  export async function consented(
160
304
  pairing: Pairing,
161
305
  settings: HandlerSettings,
162
306
  allowedFile: string,
163
- askVisitor: (question: string, offerAlways: boolean) => Promise<Answer>,
307
+ askVisitor: (
308
+ question: Question,
309
+ offerSiteTools: boolean,
310
+ ) => Promise<Answer>,
164
311
  say: (line: string) => void,
165
- ): Promise<boolean> {
166
- // None waits on another, and the holder is a round trip to the site.
167
- const [holder, allowed, unserved] = await Promise.all([
168
- holderOf(pairing),
312
+ ): Promise<Pairing | undefined> {
313
+ // None waits on another, and the asker and the icon are each a round trip to the site.
314
+ const [asker, icon, allowed, unserved] = await Promise.all([
315
+ askerOf(pairing),
316
+ iconOf(pairing.site),
169
317
  allowedSites(allowedFile),
170
318
  unservedOf(pairing, settings),
171
319
  ])
172
- if (
173
- holder !== undefined &&
174
- allowsUnasked(allowed, pairing.site, holder, pairing.tools)
175
- ) {
320
+ // An install run `--full` gives full access to every link, so a link's ask for it is moot.
321
+ const asksFull = pairing.full && settings.full !== true
322
+ const { holder } = asker
323
+ const before =
324
+ holder === undefined
325
+ ? undefined
326
+ : allowedAs(allowed, pairing.site, holder, {
327
+ tools: pairing.tools,
328
+ full: asksFull,
329
+ })
330
+ if (before !== undefined) {
176
331
  say(
177
- `Pairing with ${new URL(pairing.site).host}, which you always allow.`,
332
+ `Pairing with ${asker.name ?? shownSite(pairing.site)}, which you always allow.`,
178
333
  )
179
- return true
334
+ return before.granted === 'siteTools' ? siteToolsOnly(pairing) : pairing
180
335
  }
181
336
  const answer = await askVisitor(
182
- question(pairing, settings, unserved),
183
- holder !== undefined,
337
+ {
338
+ ...question(pairing, settings, unserved, asker),
339
+ icon,
340
+ },
341
+ offersSiteTools(pairing, settings),
184
342
  )
185
- if (answer === 'always' && holder !== undefined)
186
- await allowAlways(allowedFile, pairing.site, holder, pairing.tools)
187
- return answer !== 'deny'
343
+ if (answer === 'deny') return undefined
344
+ const allowedAsAnswered =
345
+ answer === 'siteTools' ? siteToolsOnly(pairing) : pairing
346
+ if (holder !== undefined)
347
+ await allowAlways(
348
+ allowedFile,
349
+ pairing.site,
350
+ holder,
351
+ allowedAsAnswered.tools,
352
+ answer === 'siteTools'
353
+ ? 'siteTools'
354
+ : asksFull
355
+ ? 'full'
356
+ : undefined,
357
+ )
358
+ return allowedAsAnswered
188
359
  }
189
360
 
190
361
  /**
@@ -213,18 +384,25 @@ function notifier(): { show(line: string): void; settled(): Promise<void> } {
213
384
  }
214
385
  }
215
386
 
216
- /** Opens `link`: asks the visitor, then runs the bridge until it ends. Answers the exit code. */
217
- async function open(link: string): Promise<number> {
387
+ /**
388
+ * Opens `link` with the settings and the allowed sites kept in `directory`: asks the visitor, then runs
389
+ * the bridge until it ends. Answers the exit code.
390
+ */
391
+ export async function open(link: string, directory: string): Promise<number> {
218
392
  const notifications = notifier()
219
- const log = `${import.meta.dir}/../bridge.log`
393
+ const log = `${directory}/../bridge.log`
220
394
  let logged = Promise.resolve()
221
- function say(line: string): void {
395
+ /** Writes `line` to the log alone. */
396
+ function record(line: string): void {
222
397
  console.error(line)
223
398
  logged = logged.then(() =>
224
399
  appendFile(log, `${new Date().toISOString()} ${line}\n`).catch(
225
400
  () => {},
226
401
  ),
227
402
  )
403
+ }
404
+ function say(line: string): void {
405
+ record(line)
228
406
  notifications.show(line)
229
407
  }
230
408
  async function settled(code: number): Promise<number> {
@@ -233,7 +411,7 @@ async function open(link: string): Promise<number> {
233
411
  return code
234
412
  }
235
413
  try {
236
- return settled(await pairWith(link, say))
414
+ return settled(await pairWith(link, directory, say, record))
237
415
  } catch (thrown) {
238
416
  // The applet discards this process's output, so a throw is only seen if it is said.
239
417
  say(
@@ -245,7 +423,9 @@ async function open(link: string): Promise<number> {
245
423
 
246
424
  async function pairWith(
247
425
  link: string,
426
+ directory: string,
248
427
  say: (line: string) => void,
428
+ record: (line: string) => void,
249
429
  ): Promise<number> {
250
430
  const pairing = pairingOf(link)
251
431
  if (pairing === undefined) {
@@ -253,19 +433,18 @@ async function pairWith(
253
433
  return 1
254
434
  }
255
435
  const settings = (await Bun.file(
256
- `${import.meta.dir}/settings.json`,
436
+ `${directory}/settings.json`,
257
437
  ).json()) as HandlerSettings
258
- if (
259
- !(await consented(
260
- pairing,
261
- settings,
262
- allowedIn(import.meta.dir),
263
- ask,
264
- say,
265
- ))
438
+ record(`${pairing.site} asks for @abide/bridge ${pairing.version}.`)
439
+ const allowed = await consented(
440
+ pairing,
441
+ settings,
442
+ allowedIn(directory),
443
+ ask,
444
+ say,
266
445
  )
267
- return 0
268
- const running = Bun.spawn(bridgeArguments(pairing, settings), {
446
+ if (allowed === undefined) return 0
447
+ const running = Bun.spawn(bridgeArguments(allowed, settings), {
269
448
  stdout: 'ignore',
270
449
  stderr: 'pipe',
271
450
  // The visitor's own `--env` last, so a `PATH` they gave install wins over the one it found.
@@ -280,4 +459,5 @@ async function pairWith(
280
459
  return running.exited
281
460
  }
282
461
 
283
- if (import.meta.main) process.exit(await open(process.argv[2] ?? ''))
462
+ if (import.meta.main)
463
+ process.exit(await open(process.argv[2] ?? '', import.meta.dir))
@@ -1,10 +1,9 @@
1
1
  // A PAIRING AS A LINK: what a site shows beside its command (44.40), opened by the handler
2
2
  // `abide-bridge install` registers. It carries what the command does — the site, the code, the bridge
3
- // release that speaks the site's relay and the tools of this machine it asks for — and nothing more,
4
- // and the handler asks the visitor before it runs one (44.42).
3
+ // release that speaks the site's relay, the tools of this machine it asks for and whether it asks for
4
+ // all of them (44.85) — and nothing more, and the handler asks the visitor before it runs one (44.42).
5
5
 
6
- // abide's `BRIDGE_SCHEME`, spelled out for `BRIDGE_PATH`'s reason — a test holds the two equal.
7
- export const PAIRING_SCHEME = 'abide-bridge'
6
+ import { PAIRING_SCHEME } from './PAIRING_SCHEME.ts'
8
7
 
9
8
  /** One pairing a link asks for. */
10
9
  export type Pairing = {
@@ -12,6 +11,8 @@ export type Pairing = {
12
11
  code: string
13
12
  version: string
14
13
  tools: string[]
14
+ /** The site asks for everything the visitor's Claude Code has, as `--full` gives it. 44.85. */
15
+ full: boolean
15
16
  }
16
17
 
17
18
  // A release on npm, never a range, a tag or a path: the version is laid into `bun x`'s package spec.
@@ -39,6 +40,7 @@ export function pairingOf(link: string): Pairing | undefined {
39
40
  const site = url.searchParams.get('site') ?? ''
40
41
  const code = url.searchParams.get('code') ?? ''
41
42
  const version = url.searchParams.get('version') ?? ''
43
+ const full = url.searchParams.get('full')
42
44
  const tools = (url.searchParams.get('tools') ?? '')
43
45
  .split(',')
44
46
  .filter((tool) => tool !== '')
@@ -58,7 +60,8 @@ export function pairingOf(link: string): Pairing | undefined {
58
60
  siteUrl.search !== '' ||
59
61
  siteUrl.hash !== '' ||
60
62
  !CODE.test(code) ||
61
- !RELEASE.test(version)
63
+ !RELEASE.test(version) ||
64
+ (full !== null && full !== '1')
62
65
  )
63
66
  return undefined
64
67
  for (const tool of tools) if (!TOOL.test(tool)) return undefined
@@ -67,6 +70,7 @@ export function pairingOf(link: string): Pairing | undefined {
67
70
  code,
68
71
  version,
69
72
  tools,
73
+ full: full === '1',
70
74
  }
71
75
  }
72
76