@abide/bridge 0.8.1 → 0.8.3

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,17 @@
1
1
  # @abide/bridge
2
2
 
3
+ ## 0.8.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 86c7508: a prompt's input rides on its waiter, and two shallow spellings go ([`bae558a`](https://github.com/briancray/abide/commit/bae558ae539697e88e575a3d1a51b4cc197a2b5b))
8
+
9
+ ## 0.8.2
10
+
11
+ ### Patch Changes
12
+
13
+ - d8fef91: one withoutScheme; SITE_OPTIONS keyed by ClaudeCodeConfig; bridge() drops options nothing passes ([`4725199`](https://github.com/briancray/abide/commit/4725199666442d61d52758aec21615491d6a37c1))
14
+
3
15
  ## 0.8.1
4
16
 
5
17
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abide/bridge",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
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",
@@ -3,7 +3,7 @@
3
3
  // holder `/__abide/bridge` named when the visitor allowed it — a code an attacker minted is minted for
4
4
  // the attacker, and is asked about. A visitor who allowed a site full access, or only its own tools
5
5
  // (44.86), is not asked again: it runs as they allowed it, whatever it asks for.
6
- import { siteOf } from './pairingLink.ts'
6
+ import { siteOf, withoutScheme } from './pairingLink.ts'
7
7
 
8
8
  /**
9
9
  * A site paired unasked, for one holder, while a link asks for none but `tools` — or whatever it asks
@@ -97,7 +97,3 @@ export async function forget(file: string, site?: string): Promise<number> {
97
97
  await Bun.write(file, JSON.stringify(kept, null, 4))
98
98
  return sites.length - kept.length
99
99
  }
100
-
101
- function withoutScheme(site: string): string {
102
- return site.slice(site.indexOf('://') + 3)
103
- }
package/src/bridge.ts CHANGED
@@ -35,11 +35,10 @@ type Report = TurnReport | { type: 'missing'; tools: string[] }
35
35
  export async function bridge(options: {
36
36
  site: string
37
37
  code: string
38
- claude?: string
38
+ claude: string
39
39
  claudeArgs?: string[]
40
40
  /** Everything `claude` has is the site's to use, prompts asked of its page. 44.82. */
41
41
  full?: boolean
42
- say?: (line: string) => void
43
42
  replyMilliseconds?: number
44
43
  silenceMilliseconds?: number
45
44
  }): Promise<void> {
@@ -48,7 +47,7 @@ export async function bridge(options: {
48
47
  // WHAT IS SAID IS READ AS A NOTIFICATION, where a link opened the bridge (`opened.ts`): one short
49
48
  // sentence naming the site by its host. The detail goes to Claude Code, in the failure it is answered.
50
49
  const host = new URL(site).host
51
- const say = options.say ?? ((line: string) => console.error(line))
50
+ const say = (line: string): void => console.error(line)
52
51
  const full = options.full ?? false
53
52
  const silenceMilliseconds =
54
53
  options.silenceMilliseconds ?? SILENCE_MILLISECONDS
@@ -159,7 +158,7 @@ export async function bridge(options: {
159
158
 
160
159
  const core = serveTurns({
161
160
  site,
162
- claude: options.claude ?? 'claude',
161
+ claude: options.claude,
163
162
  claudeArgs: () => options.claudeArgs ?? [],
164
163
  full,
165
164
  report,
package/src/claudeTurn.ts CHANGED
@@ -78,16 +78,20 @@ type CodeLine = {
78
78
  }
79
79
 
80
80
  // 44.16 — the options a site may set: each only shapes the answer, and reaches nothing of this machine.
81
- const SITE_OPTIONS = new Set([
82
- 'model',
83
- 'fallbackModel',
84
- 'systemPrompt',
85
- 'appendSystemPrompt',
86
- 'effort',
87
- 'maxBudgetUsd',
88
- 'betas',
89
- 'disallowedTools',
90
- ])
81
+ // Keyed by `ClaudeCodeConfig`'s own keys, so a key added on abide's side is a compile error here
82
+ // until it is decided whether a site may set it.
83
+ const SITE_OPTIONS = new Set(
84
+ Object.keys({
85
+ model: true,
86
+ fallbackModel: true,
87
+ systemPrompt: true,
88
+ appendSystemPrompt: true,
89
+ effort: true,
90
+ maxBudgetUsd: true,
91
+ betas: true,
92
+ disallowedTools: true,
93
+ } satisfies Record<keyof Omit<ClaudeCodeConfig, 'tools'>, true>),
94
+ )
91
95
 
92
96
  /** Claude Code's flag for an option named in camelCase: `fallbackModel` is `--fallback-model`. */
93
97
  function flagOf(option: string): string {
package/src/desktop.ts CHANGED
@@ -121,17 +121,6 @@ async function ran(
121
121
  }
122
122
  }
123
123
 
124
- /** Runs one AppleScript with `argv` as its `argv`. */
125
- function appleScript(
126
- lines: string[],
127
- ...argv: string[]
128
- ): ReturnType<typeof ran> {
129
- const script: string[] = ['-e', 'on run argv']
130
- for (const line of lines) script.push('-e', line)
131
- script.push('-e', 'end run')
132
- return ran(['osascript', ...script, ...argv])
133
- }
134
-
135
124
  /** Writes `icon` where a dialog can read it as a file, answering where, or `undefined` for none. */
136
125
  async function iconFile(
137
126
  icon: Uint8Array | undefined,
@@ -263,10 +252,16 @@ export async function ask(
263
252
  /** Shows `line` as a notification, where this desktop has a way to. */
264
253
  export async function notify(line: string): Promise<void> {
265
254
  if (process.platform === 'darwin')
266
- await appleScript(
267
- [`display notification (item 1 of argv) with title "${TITLE}"`],
255
+ await ran([
256
+ 'osascript',
257
+ '-e',
258
+ 'on run argv',
259
+ '-e',
260
+ `display notification (item 1 of argv) with title "${TITLE}"`,
261
+ '-e',
262
+ 'end run',
268
263
  line,
269
- )
264
+ ])
270
265
  else if (process.platform === 'linux' && Bun.which('notify-send') !== null)
271
266
  await ran(['notify-send', TITLE, line])
272
267
  }
package/src/opened.ts CHANGED
@@ -21,7 +21,7 @@ import {
21
21
  import { BRIDGE_PATH } from './BRIDGE_PATH.ts'
22
22
  import { type Answer, ask, notify, type Question } from './desktop.ts'
23
23
  import { grantFor, serversNamed } from './grant.ts'
24
- import { type Pairing, pairingOf } from './pairingLink.ts'
24
+ import { type Pairing, pairingOf, withoutScheme } from './pairingLink.ts'
25
25
  import { readLines } from './readLines.ts'
26
26
  import { requestedLines } from './requestedLines.ts'
27
27
  import { siteTls } from './siteTls.ts'
@@ -35,18 +35,13 @@ export type HandlerSettings = {
35
35
  claude: string
36
36
  path: string
37
37
  claudeArgs: string[]
38
- /** `abide-bridge install --full`: every link's bridge is run `--full` (44.82). An older install's settings hold none. */
38
+ /** `abide-bridge install --full`: every link's bridge is run `--full` (44.82). */
39
39
  full: boolean
40
40
  /** The bridge package install was run from, where it is a checkout rather than a release (44.89). */
41
41
  checkout?: string
42
42
  env: Record<string, string>
43
43
  }
44
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
45
  /** Whether the visitor's options leave Claude Code in auto mode (44.81). */
51
46
  function inAutoMode(claudeArgs: readonly string[]): boolean {
52
47
  for (const arg of claudeArgs)
@@ -66,7 +61,7 @@ export function offersSiteTools(
66
61
  pairing: Pairing,
67
62
  settings: HandlerSettings,
68
63
  ): boolean {
69
- return settings.full !== true && (pairing.full || pairing.tools.length > 0)
64
+ return !settings.full && (pairing.full || pairing.tools.length > 0)
70
65
  }
71
66
 
72
67
  /**
@@ -84,7 +79,7 @@ export function question(
84
79
  note,
85
80
  }: { name?: string | undefined; note?: string | undefined } = {},
86
81
  ): Question {
87
- const site = shownSite(pairing.site)
82
+ const site = withoutScheme(pairing.site)
88
83
  // The name is the site's to choose, so the site it is served from is always beside it.
89
84
  const asker = name === undefined ? site : `${name} (${site})`
90
85
  const owner = name ?? site
@@ -95,7 +90,7 @@ export function question(
95
90
  const headline = `${asker} is requesting access to Claude Code.`
96
91
  // 44.92 — what it asks of this machine, as what that lets it do, never a list of tool names.
97
92
  const said = [
98
- settings.full === true
93
+ settings.full
99
94
  ? 'Requested from this computer: full access, which you gave every site when you installed the bridge.'
100
95
  : pairing.full
101
96
  ? 'Requested from this computer: full access to everything Claude Code can do.'
@@ -104,9 +99,9 @@ export function question(
104
99
  : `Requested from this computer:\n• ${requestedLines(pairing.tools).join('\n• ')}`,
105
100
  ]
106
101
  // 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)
102
+ if (settings.full || pairing.full || pairing.tools.length > 0)
108
103
  said.push(auto)
109
- if (unserved.length > 0 && !pairing.full && settings.full !== true)
104
+ if (unserved.length > 0 && !pairing.full && !settings.full)
110
105
  said.push(
111
106
  `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
107
  )
@@ -147,7 +142,7 @@ export function bridgeArguments(
147
142
  pairing.code,
148
143
  '--claude',
149
144
  settings.claude,
150
- ...(settings.full === true || pairing.full ? ['--full'] : []),
145
+ ...(settings.full || pairing.full ? ['--full'] : []),
151
146
  ...(claudeArgs.length === 0 ? [] : ['--', ...claudeArgs]),
152
147
  ]
153
148
  }
@@ -283,7 +278,7 @@ export async function unservedOf(
283
278
  const { grant } = await grantFor(
284
279
  pairing.tools,
285
280
  claudeArgsOf(pairing, settings),
286
- settings.full === true,
281
+ settings.full,
287
282
  () => {},
288
283
  )
289
284
  return grant.unserved
@@ -318,7 +313,7 @@ export async function consented(
318
313
  unservedOf(pairing, settings),
319
314
  ])
320
315
  // 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
316
+ const asksFull = pairing.full && !settings.full
322
317
  const { holder } = asker
323
318
  const before =
324
319
  holder === undefined
@@ -329,7 +324,7 @@ export async function consented(
329
324
  })
330
325
  if (before !== undefined) {
331
326
  say(
332
- `Pairing with ${asker.name ?? shownSite(pairing.site)}, which you always allow.`,
327
+ `Pairing with ${asker.name ?? withoutScheme(pairing.site)}, which you always allow.`,
333
328
  )
334
329
  return before.granted === 'siteTools' ? siteToolsOnly(pairing) : pairing
335
330
  }
@@ -78,3 +78,8 @@ export function pairingOf(link: string): Pairing | undefined {
78
78
  export function siteOf(url: URL): string {
79
79
  return `${url.origin}${url.pathname}`.replace(/\/+$/, '')
80
80
  }
81
+
82
+ /** A site as a person reads it: `siteOf`'s, with no scheme. */
83
+ export function withoutScheme(site: string): string {
84
+ return site.slice(site.indexOf('://') + 3)
85
+ }
package/src/serveTurns.ts CHANGED
@@ -56,6 +56,8 @@ type Waiting = {
56
56
  method: string
57
57
  answer: (reply: Record<string, unknown>) => void
58
58
  deadline: ReturnType<typeof setTimeout>
59
+ /** A prompt's input, handed back as Claude Code's `updatedInput` where the page allows it. */
60
+ input: unknown
59
61
  }
60
62
 
61
63
  /** 44.46 — the abort reason of a turn the site missed part of, which it reports failed with. */
@@ -153,13 +155,10 @@ export function serveTurns(options: {
153
155
  const { site, report } = options
154
156
  const replyMilliseconds = options.replyMilliseconds ?? REPLY_MILLISECONDS
155
157
  const waiting = new Map<number, Waiting>()
156
- // Each prompt's input, handed back as Claude Code's `updatedInput` where the page allows it.
157
- const inputs = new Map<number, unknown>()
158
158
  const answer = (id: number, reply: Record<string, unknown>): void => {
159
159
  const waiter = waiting.get(id)
160
160
  if (waiter === undefined) return
161
161
  waiting.delete(id)
162
- inputs.delete(id)
163
162
  clearTimeout(waiter.deadline)
164
163
  waiter.answer(reply)
165
164
  }
@@ -210,11 +209,18 @@ export function serveTurns(options: {
210
209
  })
211
210
  const id = ++asked
212
211
  const method = prompted ? 'permission' : message.method
212
+ const { tool_name, input } = (
213
+ prompted
214
+ ? ((message.params as { arguments?: unknown })?.arguments ??
215
+ {})
216
+ : {}
217
+ ) as { tool_name?: string; input?: unknown }
213
218
  const reply = new Promise<Record<string, unknown>>((done) => {
214
219
  waiting.set(id, {
215
220
  turn,
216
221
  method,
217
222
  answer: done,
223
+ input,
218
224
  // 44.24 — a reply lost on the way is a failure Claude Code is told of.
219
225
  deadline: setTimeout(
220
226
  () =>
@@ -229,11 +235,7 @@ export function serveTurns(options: {
229
235
  ),
230
236
  })
231
237
  })
232
- if (prompted) {
233
- const { tool_name, input } = ((
234
- message.params as { arguments?: unknown }
235
- )?.arguments ?? {}) as { tool_name?: string; input?: unknown }
236
- inputs.set(id, input)
238
+ if (prompted)
237
239
  report({
238
240
  type: 'permission',
239
241
  turn,
@@ -241,7 +243,7 @@ export function serveTurns(options: {
241
243
  name: tool_name ?? '',
242
244
  input,
243
245
  })
244
- } else
246
+ else
245
247
  report({
246
248
  type: 'mcp',
247
249
  turn,
@@ -367,7 +369,7 @@ export function serveTurns(options: {
367
369
  frame.id,
368
370
  decided(
369
371
  frame.allow,
370
- inputs.get(frame.id),
372
+ waiter.input,
371
373
  'The person at the page said no.',
372
374
  ),
373
375
  )