@abide/bridge 0.4.0 → 0.5.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @abide/bridge
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - efef999: `abide-bridge install` keeps `--env NAME=VALUE` and the Claude Code options after its `--`, and every pairing link it opens runs with them — naming them in the question it asks first (RULEBOOK 44.42, 44.44)
8
+
3
9
  ## 0.4.0
4
10
 
5
11
  ### Minor Changes
@@ -1,33 +1,48 @@
1
1
  #!/usr/bin/env bun
2
- // `abide-bridge <site> <code> [--claude <path>] [-- <claude options>]` — the command an abide site shows
3
- // you to connect your Claude Code to its assistant. `--claude <path>` names the executable where `claude`
4
- // is not on PATH; whatever follows `--` is passed to Claude Code as you wrote it, and is how you give a
5
- // site what reaches this machine — `-- --tools WebSearch,WebFetch` for the built-in tools it asks for.
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.
6
7
  //
7
- // `abide-bridge install [--claude <path>]` builds and registers, on macOS, the app that opens the pairing
8
- // link a site shows beside its command, so a click pairs instead of a terminal; `abide-bridge uninstall`
9
- // takes it away.
8
+ // `abide-bridge install` takes the same options and builds and registers, on macOS, the app that opens the
9
+ // pairing link a site shows beside its command, so a click pairs instead of a terminal — every link it
10
+ // opens runs with the `--env` and the `--` options given here (44.44); `abide-bridge uninstall` takes it
11
+ // away.
10
12
 
11
13
  import { bridge } from '../src/bridge.ts'
12
14
  import { install, installDirectory, uninstall } from '../src/install.ts'
13
15
 
16
+ const USAGE =
17
+ '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'
18
+
14
19
  const all = process.argv.slice(2)
15
20
  const split = all.indexOf('--')
16
21
  const args = split === -1 ? all : all.slice(0, split)
17
22
  const claudeArgs = split === -1 ? [] : all.slice(split + 1)
18
- const flag = args.indexOf('--claude')
19
- const claude = flag === -1 ? undefined : args[flag + 1]
20
- const [site, code] = args.filter(
21
- (_arg, index) => flag === -1 || (index !== flag && index !== flag + 1),
22
- )
23
+ let claude: string | undefined
24
+ const env: Record<string, string> = {}
25
+ const positional: string[] = []
26
+ let malformed = false
27
+ for (let index = 0; index < args.length; index++) {
28
+ const arg = args[index] as string
29
+ if (arg === '--claude') claude = args[++index]
30
+ else if (arg === '--env') {
31
+ const assignment = /^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s.exec(
32
+ args[++index] ?? '',
33
+ )
34
+ if (assignment === null) malformed = true
35
+ else env[assignment[1] as string] = assignment[2] as string
36
+ } else positional.push(arg)
37
+ }
38
+ const [site, code] = positional
23
39
 
24
40
  if (
41
+ malformed ||
25
42
  site === undefined ||
26
43
  (site !== 'uninstall' && site !== 'install' && code === undefined)
27
44
  ) {
28
- console.error(
29
- 'usage: abide-bridge <site> <code> [--claude <path>] [-- <claude options>]\n abide-bridge install [--claude <path>]\n abide-bridge uninstall',
30
- )
45
+ console.error(USAGE)
31
46
  process.exit(2)
32
47
  }
33
48
 
@@ -49,17 +64,22 @@ try {
49
64
  bun: process.execPath,
50
65
  claude: found,
51
66
  path: Bun.env.PATH ?? '',
67
+ claudeArgs,
68
+ env,
52
69
  })
53
70
  console.error(
54
71
  `Installed ${app}. A site's pairing link now opens here, and asks you before it pairs. \`abide-bridge uninstall\` removes it.`,
55
72
  )
56
- } else
73
+ } else {
74
+ // Claude Code is started with this process's environment.
75
+ Object.assign(process.env, env)
57
76
  await bridge({
58
77
  site,
59
78
  code: code as string,
60
79
  claudeArgs,
61
80
  claude: found,
62
81
  })
82
+ }
63
83
  }
64
84
  process.exit(0)
65
85
  } catch (thrown) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abide/bridge",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
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",
package/src/opened.ts CHANGED
@@ -11,27 +11,48 @@
11
11
  import { type Pairing, pairingOf } from './pairingLink.ts'
12
12
  import { readLines } from './readLines.ts'
13
13
 
14
- /** What install found, kept beside this file: `bun`, `claude`, and the `PATH` it was run on. */
15
- export type HandlerSettings = { bun: string; claude: string; path: string }
14
+ /**
15
+ * What install found, kept beside this file: `bun`, `claude`, and the `PATH` it was run on — and what
16
+ * the visitor gave it for every link (44.44): the Claude Code options after its `--` and each `--env`.
17
+ */
18
+ export type HandlerSettings = {
19
+ bun: string
20
+ claude: string
21
+ path: string
22
+ claudeArgs: string[]
23
+ env: Record<string, string>
24
+ }
16
25
 
17
26
  /**
18
27
  * What the visitor is asked before `pairing` runs. EVERY LINK IS ASKED (44.42): a code proves only
19
28
  * that the site minted it, never that this visitor's browser asked for it, so an answer kept for a
20
29
  * site would pair any page's link to whoever minted its code.
21
30
  */
22
- export function question(pairing: Pairing): string {
31
+ export function question(pairing: Pairing, settings: HandlerSettings): string {
23
32
  const tools =
24
33
  pairing.tools.length === 0
25
34
  ? 'It gets none of this Mac’s tools.'
26
35
  : `It also asks for these tools of this Mac’s: ${pairing.tools.join(', ')}.`
27
- return `${pairing.site} wants to use your Claude Code as its assistant, with its own tools, on your Claude account.\n\n${tools}\n\nIt runs @abide/bridge ${pairing.version}. Allow it only if you just asked to pair on that site.`
36
+ // A variable's value is only named, never shown: it is as likely a token as a host.
37
+ const names = Object.keys(settings.env)
38
+ const kept =
39
+ settings.claudeArgs.length === 0 && names.length === 0
40
+ ? ''
41
+ : `\n\nIt also gets what you gave install for every site: ${[...settings.claudeArgs, ...names].join(' ')}.`
42
+ return `${pairing.site} wants to use your Claude Code as its assistant, with its own tools, on your Claude account.\n\n${tools}${kept}\n\nIt runs @abide/bridge ${pairing.version}. Allow it only if you just asked to pair on that site.`
28
43
  }
29
44
 
30
- /** The bridge the link names, run as the command a site shows would run it. 44.32. */
45
+ /**
46
+ * The bridge the link names, run as the command a site shows would run it (44.32), with the options
47
+ * install kept ahead of the link's tools (44.44).
48
+ */
31
49
  export function bridgeArguments(
32
50
  pairing: Pairing,
33
51
  settings: HandlerSettings,
34
52
  ): string[] {
53
+ const claudeArgs = [...settings.claudeArgs]
54
+ if (pairing.tools.length > 0)
55
+ claudeArgs.push('--tools', pairing.tools.join(','))
35
56
  return [
36
57
  settings.bun,
37
58
  'x',
@@ -40,9 +61,7 @@ export function bridgeArguments(
40
61
  pairing.code,
41
62
  '--claude',
42
63
  settings.claude,
43
- ...(pairing.tools.length === 0
44
- ? []
45
- : ['--', '--tools', pairing.tools.join(',')]),
64
+ ...(claudeArgs.length === 0 ? [] : ['--', ...claudeArgs]),
46
65
  ]
47
66
  }
48
67
 
@@ -76,13 +95,16 @@ async function appleScript(
76
95
  }
77
96
 
78
97
  /** Asks the visitor about `pairing` in a dialog; closing it is a no. */
79
- async function allowed(pairing: Pairing): Promise<boolean> {
98
+ async function allowed(
99
+ pairing: Pairing,
100
+ settings: HandlerSettings,
101
+ ): Promise<boolean> {
80
102
  const pressed = await appleScript(
81
103
  [
82
104
  'display dialog (item 1 of argv) with title "abide bridge" buttons {"Don’t Allow", "Allow"} default button "Don’t Allow" cancel button "Don’t Allow" with icon caution',
83
105
  'button returned of result',
84
106
  ],
85
- question(pairing),
107
+ question(pairing, settings),
86
108
  )
87
109
  return pressed === 'Allow'
88
110
  }
@@ -134,11 +156,12 @@ async function open(link: string): Promise<number> {
134
156
  const settings = (await Bun.file(
135
157
  `${import.meta.dir}/settings.json`,
136
158
  ).json()) as HandlerSettings
137
- if (!(await allowed(pairing))) return 0
159
+ if (!(await allowed(pairing, settings))) return 0
138
160
  const running = Bun.spawn(bridgeArguments(pairing, settings), {
139
161
  stdout: 'ignore',
140
162
  stderr: 'pipe',
141
- env: { ...Bun.env, PATH: searchPath(settings) },
163
+ // The visitor's own `--env` last, so a `PATH` they gave install wins over the one it found.
164
+ env: { ...Bun.env, PATH: searchPath(settings), ...settings.env },
142
165
  })
143
166
  for await (const line of readLines(
144
167
  running.stderr as ReadableStream<Uint8Array>,