@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/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
21
  import { BRIDGE_PATH } from './BRIDGE_PATH.ts'
21
- import { type Answer, ask, notify } from './desktop.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,7 +1,7 @@
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
6
  import { PAIRING_SCHEME } from './PAIRING_SCHEME.ts'
7
7
 
@@ -11,6 +11,8 @@ export type Pairing = {
11
11
  code: string
12
12
  version: string
13
13
  tools: string[]
14
+ /** The site asks for everything the visitor's Claude Code has, as `--full` gives it. 44.85. */
15
+ full: boolean
14
16
  }
15
17
 
16
18
  // A release on npm, never a range, a tag or a path: the version is laid into `bun x`'s package spec.
@@ -38,6 +40,7 @@ export function pairingOf(link: string): Pairing | undefined {
38
40
  const site = url.searchParams.get('site') ?? ''
39
41
  const code = url.searchParams.get('code') ?? ''
40
42
  const version = url.searchParams.get('version') ?? ''
43
+ const full = url.searchParams.get('full')
41
44
  const tools = (url.searchParams.get('tools') ?? '')
42
45
  .split(',')
43
46
  .filter((tool) => tool !== '')
@@ -57,7 +60,8 @@ export function pairingOf(link: string): Pairing | undefined {
57
60
  siteUrl.search !== '' ||
58
61
  siteUrl.hash !== '' ||
59
62
  !CODE.test(code) ||
60
- !RELEASE.test(version)
63
+ !RELEASE.test(version) ||
64
+ (full !== null && full !== '1')
61
65
  )
62
66
  return undefined
63
67
  for (const tool of tools) if (!TOOL.test(tool)) return undefined
@@ -66,6 +70,7 @@ export function pairingOf(link: string): Pairing | undefined {
66
70
  code,
67
71
  version,
68
72
  tools,
73
+ full: full === '1',
69
74
  }
70
75
  }
71
76
 
@@ -0,0 +1,66 @@
1
+ // WHAT A LINK ASKS OF THIS MACHINE, AS A VISITOR READS IT (44.92): each built-in tool by what it lets
2
+ // the site do, several tools sharing one line, and every MCP tool on one line naming its server and how
3
+ // many of that server's tools it asks for — a site asking for many tools one by one is a few lines, and
4
+ // the count says how much it asked.
5
+
6
+ import { serverOf } from './grant.ts'
7
+
8
+ // The built-in tools by what they let a site do, in the order the lines are read: what reaches this
9
+ // machine furthest first. A tool that only keeps Claude Code's own notes is no line at all.
10
+ const CAPABILITIES: readonly { line: string; tools: readonly string[] }[] = [
11
+ { line: 'Run commands', tools: ['Bash', 'BashOutput', 'KillShell'] },
12
+ {
13
+ line: 'Change your files',
14
+ tools: ['Edit', 'Write', 'MultiEdit', 'NotebookEdit'],
15
+ },
16
+ {
17
+ line: 'Read and search your files',
18
+ tools: ['Read', 'Glob', 'Grep', 'LS'],
19
+ },
20
+ { line: 'Search the web', tools: ['WebSearch'] },
21
+ { line: 'Open web pages', tools: ['WebFetch'] },
22
+ { line: 'Start helper agents', tools: ['Agent', 'Task'] },
23
+ ]
24
+ const UNSHOWN = new Set(['TodoWrite', 'ExitPlanMode'])
25
+
26
+ /**
27
+ * The lines naming what `tools` ask of this machine: one per capability their built-in tools give, in
28
+ * `CAPABILITIES`' order, then any built-in it does not name by its own name, then one naming every MCP
29
+ * server with how many of its tools are asked for — `all tools` where a whole server is.
30
+ */
31
+ export function requestedLines(tools: readonly string[]): string[] {
32
+ const lines: string[] = []
33
+ for (const { line, tools: covered } of CAPABILITIES)
34
+ for (const tool of covered)
35
+ if (tools.includes(tool)) {
36
+ lines.push(line)
37
+ break
38
+ }
39
+ const servers = new Map<string, number | 'all'>()
40
+ for (const tool of tools) {
41
+ const server = serverOf(tool)
42
+ if (server === undefined) {
43
+ let named = UNSHOWN.has(tool)
44
+ for (const { tools: covered } of CAPABILITIES)
45
+ if (covered.includes(tool)) named = true
46
+ if (!named) lines.push(`Use ${tool}`)
47
+ continue
48
+ }
49
+ const counted = servers.get(server) ?? 0
50
+ servers.set(
51
+ server,
52
+ counted === 'all' || tool === `mcp__${server}`
53
+ ? 'all'
54
+ : counted + 1,
55
+ )
56
+ }
57
+ if (servers.size > 0) {
58
+ const named: string[] = []
59
+ for (const [server, count] of servers)
60
+ named.push(
61
+ `${server} (${count === 'all' ? 'all tools' : count === 1 ? '1 tool' : `${count} tools`})`,
62
+ )
63
+ lines.push(`MCP servers: ${named.join(', ')}`)
64
+ }
65
+ return lines
66
+ }