typeclaw 0.47.2 → 0.48.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.
Files changed (105) hide show
  1. package/package.json +1 -1
  2. package/src/agent/index.ts +1 -2
  3. package/src/agent/loop-guard.ts +71 -41
  4. package/src/agent/plugin-tools.ts +167 -50
  5. package/src/agent/system-prompt.ts +1 -1
  6. package/src/agent/turn-runner.ts +12 -2
  7. package/src/bundled-plugins/agent-browser/index.ts +0 -38
  8. package/src/bundled-plugins/agent-browser/skills/agent-browser/SKILL.md +1 -1
  9. package/src/bundled-plugins/guard/policies/non-workspace-write.ts +16 -1
  10. package/src/bundled-plugins/memory/append-tool.ts +75 -2
  11. package/src/bundled-plugins/memory/frontmatter.ts +13 -2
  12. package/src/bundled-plugins/memory/load-memory.ts +1 -1
  13. package/src/bundled-plugins/memory/memory-logger.ts +5 -1
  14. package/src/bundled-plugins/memory/secret-detector.ts +7 -0
  15. package/src/bundled-plugins/memory/vector/hybrid.ts +3 -1
  16. package/src/bundled-plugins/memory/vector/passages.ts +5 -1
  17. package/src/bundled-plugins/security/index.ts +148 -98
  18. package/src/bundled-plugins/security/policies/private-surface-read.ts +43 -28
  19. package/src/channels/adapters/discord-bot-edit.ts +3 -5
  20. package/src/channels/adapters/discord-bot-reactions.ts +4 -6
  21. package/src/channels/adapters/discord-bot-slash-commands.ts +3 -1
  22. package/src/channels/adapters/discord-bot.ts +20 -23
  23. package/src/channels/adapters/discord-edit.ts +3 -5
  24. package/src/channels/adapters/discord-reactions.ts +4 -6
  25. package/src/channels/adapters/discord.ts +1 -1
  26. package/src/channels/adapters/github/decoy-reviewer.ts +2 -1
  27. package/src/channels/adapters/github/history.ts +2 -1
  28. package/src/channels/adapters/github/inbound.ts +4 -11
  29. package/src/channels/adapters/github/index.ts +6 -9
  30. package/src/channels/adapters/github/outbound.ts +3 -6
  31. package/src/channels/adapters/github/reactions.ts +3 -2
  32. package/src/channels/adapters/github/reconcile-cooldown-store.ts +4 -6
  33. package/src/channels/adapters/github/reconcile-open-prs.ts +5 -4
  34. package/src/channels/adapters/github/recover-failed-deliveries.ts +2 -5
  35. package/src/channels/adapters/github/review-state.ts +3 -2
  36. package/src/channels/adapters/github/review-thread-resolver.ts +3 -2
  37. package/src/channels/adapters/github/webhook-register.ts +5 -8
  38. package/src/channels/adapters/instagram-channel-resolver.ts +3 -5
  39. package/src/channels/adapters/instagram.ts +1 -1
  40. package/src/channels/adapters/kakaotalk-author-resolver.ts +2 -5
  41. package/src/channels/adapters/kakaotalk-channel-resolver.ts +3 -5
  42. package/src/channels/adapters/kakaotalk-fetch-attachment.ts +2 -1
  43. package/src/channels/adapters/kakaotalk-membership.ts +2 -5
  44. package/src/channels/adapters/kakaotalk-typing.ts +1 -1
  45. package/src/channels/adapters/kakaotalk.ts +1 -1
  46. package/src/channels/adapters/line-channel-resolver.ts +3 -5
  47. package/src/channels/adapters/line.ts +1 -1
  48. package/src/channels/adapters/slack-bot-edit.ts +1 -1
  49. package/src/channels/adapters/slack-bot-reactions.ts +4 -6
  50. package/src/channels/adapters/slack-bot.ts +8 -8
  51. package/src/channels/adapters/slack-edit.ts +3 -5
  52. package/src/channels/adapters/slack-reactions.ts +4 -6
  53. package/src/channels/adapters/slack.ts +1 -1
  54. package/src/channels/adapters/teams-edit.ts +2 -5
  55. package/src/channels/adapters/teams.ts +1 -1
  56. package/src/channels/adapters/telegram-bot-edit.ts +4 -7
  57. package/src/channels/adapters/telegram-bot.ts +1 -1
  58. package/src/channels/adapters/webex-bot.ts +1 -1
  59. package/src/channels/adapters/webex-edit.ts +3 -5
  60. package/src/channels/adapters/webex.ts +1 -1
  61. package/src/channels/github-review-claim.ts +89 -4
  62. package/src/channels/github-token-bridge.ts +2 -1
  63. package/src/channels/manager.ts +478 -64
  64. package/src/channels/membership-cache.ts +2 -5
  65. package/src/channels/persistence.ts +3 -6
  66. package/src/channels/reloadable.ts +23 -6
  67. package/src/channels/router.ts +134 -56
  68. package/src/channels/tunnel-bridge.ts +2 -1
  69. package/src/channels/types.ts +6 -3
  70. package/src/cli/hostd.ts +56 -28
  71. package/src/config/config.ts +10 -0
  72. package/src/config/providers.ts +179 -0
  73. package/src/dependencies/bin-resolver.ts +88 -0
  74. package/src/dependencies/bins.ts +227 -0
  75. package/src/dependencies/index.ts +17 -0
  76. package/src/doctor/checks.ts +2 -0
  77. package/src/doctor/operational-incidents.ts +32 -0
  78. package/src/hostd/credential-rotation-apply.ts +94 -0
  79. package/src/init/models-dev.ts +17 -3
  80. package/src/init/validate-api-key.ts +26 -4
  81. package/src/operations/classify-tool-outcome.ts +151 -0
  82. package/src/operations/incidents.ts +274 -0
  83. package/src/operations/index.ts +3 -0
  84. package/src/operations/remediations.ts +41 -0
  85. package/src/reload/client.ts +8 -2
  86. package/src/reload/docker-exec-client.ts +10 -2
  87. package/src/reload/index.ts +1 -1
  88. package/src/reload/recover.ts +5 -3
  89. package/src/reload/registry.ts +5 -5
  90. package/src/reload/types.ts +9 -1
  91. package/src/run/index.ts +5 -0
  92. package/src/sandbox/dependency-bins.ts +125 -0
  93. package/src/sandbox/errors.ts +32 -0
  94. package/src/sandbox/hidden-paths.ts +4 -1
  95. package/src/sandbox/index.ts +8 -0
  96. package/src/sandbox/policy.ts +1 -1
  97. package/src/sandbox/privileged-runtime.ts +88 -7
  98. package/src/sandbox/runtime-private.ts +4 -0
  99. package/src/sandbox/writable-zones.ts +4 -4
  100. package/src/server/index.ts +7 -5
  101. package/src/shared/protocol.ts +6 -1
  102. package/typeclaw.schema.json +35 -5
  103. package/src/bundled-plugins/agent-browser/shim-install.ts +0 -179
  104. package/src/bundled-plugins/agent-browser/shim.ts +0 -108
  105. /package/src/channels/{adapters/describe-error.ts → describe-error.ts} +0 -0
@@ -2,6 +2,11 @@ export type ReloadResultPayload =
2
2
  | { scope: string; ok: true; summary: string; details?: unknown }
3
3
  | { scope: string; ok: false; reason: string }
4
4
 
5
+ // Structurally mirrors ReloadCause in src/reload/types.ts. Kept as its own
6
+ // declaration so the wire protocol stays free of subsystem imports, the same
7
+ // way ReloadResultPayload mirrors ReloadResult.
8
+ export type ReloadCausePayload = { kind: 'credential-rotation'; adapter: string }
9
+
5
10
  export type PromptDelivery = 'queue' | 'steer' | 'interrupt'
6
11
 
7
12
  export type DoctorRequestId = string
@@ -171,7 +176,7 @@ export type InspectServerMessage =
171
176
 
172
177
  export type ClientMessage =
173
178
  | { type: 'prompt'; text: string; delivery?: PromptDelivery }
174
- | { type: 'reload'; scope?: string }
179
+ | { type: 'reload'; scope?: string; cause?: ReloadCausePayload }
175
180
  | { type: 'restart' }
176
181
  | { type: 'abort' }
177
182
  | { type: 'queue_cancel'; messageId: string }
@@ -64,7 +64,13 @@
64
64
  "moonshot/kimi-k2.7-code",
65
65
  "moonshot/kimi-k2.6",
66
66
  "moonshot/kimi-k2.5",
67
- "moonshot-coding/kimi-for-coding"
67
+ "moonshot-coding/kimi-for-coding",
68
+ "opengateway/openai/gpt-5.4-nano",
69
+ "opengateway/openai/gpt-5.5",
70
+ "opengateway/anthropic/claude-sonnet-5",
71
+ "opengateway/anthropic/claude-opus-4-8",
72
+ "opengateway/moonshotai/kimi-k2.6",
73
+ "opengateway/minimax/MiniMax-M3"
68
74
  ]
69
75
  },
70
76
  {
@@ -120,7 +126,13 @@
120
126
  "moonshot/kimi-k2.7-code",
121
127
  "moonshot/kimi-k2.6",
122
128
  "moonshot/kimi-k2.5",
123
- "moonshot-coding/kimi-for-coding"
129
+ "moonshot-coding/kimi-for-coding",
130
+ "opengateway/openai/gpt-5.4-nano",
131
+ "opengateway/openai/gpt-5.5",
132
+ "opengateway/anthropic/claude-sonnet-5",
133
+ "opengateway/anthropic/claude-opus-4-8",
134
+ "opengateway/moonshotai/kimi-k2.6",
135
+ "opengateway/minimax/MiniMax-M3"
124
136
  ]
125
137
  },
126
138
  {
@@ -177,7 +189,13 @@
177
189
  "moonshot/kimi-k2.7-code",
178
190
  "moonshot/kimi-k2.6",
179
191
  "moonshot/kimi-k2.5",
180
- "moonshot-coding/kimi-for-coding"
192
+ "moonshot-coding/kimi-for-coding",
193
+ "opengateway/openai/gpt-5.4-nano",
194
+ "opengateway/openai/gpt-5.5",
195
+ "opengateway/anthropic/claude-sonnet-5",
196
+ "opengateway/anthropic/claude-opus-4-8",
197
+ "opengateway/moonshotai/kimi-k2.6",
198
+ "opengateway/minimax/MiniMax-M3"
181
199
  ]
182
200
  },
183
201
  {
@@ -232,7 +250,13 @@
232
250
  "moonshot/kimi-k2.7-code",
233
251
  "moonshot/kimi-k2.6",
234
252
  "moonshot/kimi-k2.5",
235
- "moonshot-coding/kimi-for-coding"
253
+ "moonshot-coding/kimi-for-coding",
254
+ "opengateway/openai/gpt-5.4-nano",
255
+ "opengateway/openai/gpt-5.5",
256
+ "opengateway/anthropic/claude-sonnet-5",
257
+ "opengateway/anthropic/claude-opus-4-8",
258
+ "opengateway/moonshotai/kimi-k2.6",
259
+ "opengateway/minimax/MiniMax-M3"
236
260
  ]
237
261
  },
238
262
  {
@@ -288,7 +312,13 @@
288
312
  "moonshot/kimi-k2.7-code",
289
313
  "moonshot/kimi-k2.6",
290
314
  "moonshot/kimi-k2.5",
291
- "moonshot-coding/kimi-for-coding"
315
+ "moonshot-coding/kimi-for-coding",
316
+ "opengateway/openai/gpt-5.4-nano",
317
+ "opengateway/openai/gpt-5.5",
318
+ "opengateway/anthropic/claude-sonnet-5",
319
+ "opengateway/anthropic/claude-opus-4-8",
320
+ "opengateway/moonshotai/kimi-k2.6",
321
+ "opengateway/minimax/MiniMax-M3"
292
322
  ]
293
323
  },
294
324
  {
@@ -1,179 +0,0 @@
1
- import {
2
- lstatSync,
3
- readFileSync,
4
- readlinkSync,
5
- renameSync,
6
- statSync,
7
- symlinkSync,
8
- unlinkSync,
9
- writeFileSync,
10
- } from 'node:fs'
11
- import { dirname, join, resolve as resolvePath } from 'node:path'
12
-
13
- import { REAL_BIN_ENV } from './shim'
14
-
15
- const DEFAULT_GLOBAL_BIN_PATH = '/usr/local/bin/agent-browser'
16
- const DEFAULT_LOCAL_BIN_PATH = '/agent/node_modules/.bin/agent-browser'
17
- const STASH_ROOT = '/usr/local/lib/typeclaw-agent-browser'
18
- const SHIM_MARKER = '# typeclaw-agent-browser-shim'
19
- const IMAGE_WRAPPER_MARKER = '# typeclaw-agent-browser-image-wrapper'
20
- const LOCAL_ALIAS_MARKER = '# typeclaw-agent-browser-local-alias'
21
-
22
- export type InstallShimOptions = {
23
- binPath?: string
24
- stashDir?: string
25
- shimEntry?: string
26
- delegateTarget?: string
27
- fs?: ShimFs
28
- }
29
-
30
- export type ShimFs = {
31
- lstat: (path: string) => { isSymbolicLink: () => boolean } | null
32
- // statExists follows symlinks: a broken symlink (link entry exists, target
33
- // does not) returns false. This is the discriminator we need to skip
34
- // installation when the host bind-mount surfaces dangling node_modules/.bin
35
- // entries inside the container — see installShim's upstream guard.
36
- statExists: (path: string) => boolean
37
- readlink: (path: string) => string
38
- readFile: (path: string) => string
39
- rename: (from: string, to: string) => void
40
- symlink: (target: string, path: string) => void
41
- writeFile: (path: string, data: string, mode: number) => void
42
- unlink: (path: string) => void
43
- mkdirp: (path: string) => void
44
- }
45
-
46
- export type InstallShimResult =
47
- | { kind: 'installed'; realBin: string; binPath: string; stashTarget: string }
48
- | { kind: 'delegated'; binPath: string; delegateTarget: string }
49
- | { kind: 'already-installed'; binPath: string }
50
- | { kind: 'no-upstream'; binPath: string }
51
-
52
- export function installShim(opts: InstallShimOptions = {}): InstallShimResult {
53
- const binPath = opts.binPath ?? DEFAULT_GLOBAL_BIN_PATH
54
- const shimEntry = opts.shimEntry ?? defaultShimEntry()
55
- const fs = opts.fs ?? defaultFs()
56
- const stashDir = opts.stashDir ?? defaultStashDir(binPath)
57
- const stashTarget = join(stashDir, 'agent-browser-real')
58
-
59
- const stat = fs.lstat(binPath)
60
- if (stat === null) return { kind: 'no-upstream', binPath }
61
-
62
- const wrapperKind = getWrapperKind(binPath, fs)
63
- if (wrapperKind === 'image' || wrapperKind === 'local-alias') {
64
- return { kind: 'already-installed', binPath }
65
- }
66
- if (wrapperKind === 'runtime' && opts.delegateTarget === undefined) {
67
- if (fs.statExists(stashTarget)) return { kind: 'already-installed', binPath }
68
- // The stash this wrapper points at is gone (STASH_ROOT lives outside the
69
- // bind-mount), so executing it would ENOENT. Nothing here is worth
70
- // preserving; drop it and report no-upstream.
71
- fs.unlink(binPath)
72
- return { kind: 'no-upstream', binPath }
73
- }
74
-
75
- // Bind-mounted node_modules/.bin entries can be dangling symlinks inside
76
- // the container (host ran bun install; the container image did not). lstat
77
- // alone passes for those. Follow the link with statExists before mutating
78
- // anything — otherwise we'd stash a broken symlink and write a wrapper
79
- // pointing at a target that never resolves.
80
- if (!fs.statExists(binPath)) return { kind: 'no-upstream', binPath }
81
- if (opts.delegateTarget !== undefined) {
82
- fs.unlink(binPath)
83
- fs.writeFile(binPath, renderDelegatingWrapper(opts.delegateTarget), 0o755)
84
- return { kind: 'delegated', binPath, delegateTarget: opts.delegateTarget }
85
- }
86
-
87
- const realBin = resolveCurrentTarget(binPath, stat, fs)
88
- fs.mkdirp(stashDir)
89
- if (stat.isSymbolicLink()) {
90
- fs.unlink(binPath)
91
- if (fs.lstat(stashTarget) !== null) fs.unlink(stashTarget)
92
- fs.symlink(realBin, stashTarget)
93
- } else {
94
- if (fs.lstat(stashTarget) !== null) fs.unlink(stashTarget)
95
- fs.rename(binPath, stashTarget)
96
- }
97
-
98
- fs.writeFile(binPath, renderWrapper(shimEntry, stashTarget), 0o755)
99
- return { kind: 'installed', realBin, binPath, stashTarget }
100
- }
101
-
102
- export const KNOWN_BIN_PATHS = {
103
- global: DEFAULT_GLOBAL_BIN_PATH,
104
- local: DEFAULT_LOCAL_BIN_PATH,
105
- } as const
106
-
107
- function defaultStashDir(binPath: string): string {
108
- // Per-binPath subdirectory under the image-owned stash root. Lives outside
109
- // every bind-mounted agent folder so a host-side `bun install` cannot
110
- // touch it; the wrapper at the bind-mounted location can be clobbered by
111
- // host-side installs but the stash and image-level real binary stay safe.
112
- const slug = binPath.replace(/[^A-Za-z0-9]+/g, '-').replace(/^-+|-+$/g, '')
113
- return join(STASH_ROOT, slug)
114
- }
115
-
116
- function getWrapperKind(binPath: string, fs: ShimFs): 'image' | 'local-alias' | 'runtime' | null {
117
- try {
118
- const contents = fs.readFile(binPath)
119
- if (contents.includes(IMAGE_WRAPPER_MARKER)) return 'image'
120
- if (contents.includes(LOCAL_ALIAS_MARKER)) return 'local-alias'
121
- return contents.includes(SHIM_MARKER) ? 'runtime' : null
122
- } catch {
123
- return null
124
- }
125
- }
126
-
127
- function resolveCurrentTarget(binPath: string, stat: { isSymbolicLink: () => boolean }, fs: ShimFs): string {
128
- if (!stat.isSymbolicLink()) return binPath
129
- const target = fs.readlink(binPath)
130
- return resolvePath(dirname(binPath), target)
131
- }
132
-
133
- function renderWrapper(shimEntry: string, stashTarget: string): string {
134
- return `#!/bin/sh
135
- ${SHIM_MARKER}
136
- export ${REAL_BIN_ENV}="\${${REAL_BIN_ENV}:-${stashTarget}}"
137
- exec bun run ${shimEntry} "$@"
138
- `
139
- }
140
-
141
- function renderDelegatingWrapper(delegateTarget: string): string {
142
- return `#!/bin/sh
143
- ${LOCAL_ALIAS_MARKER}
144
- exec "${delegateTarget}" "$@"
145
- `
146
- }
147
-
148
- function defaultShimEntry(): string {
149
- return resolvePath(import.meta.dir, 'shim.ts')
150
- }
151
-
152
- function defaultFs(): ShimFs {
153
- return {
154
- lstat: (path) => {
155
- try {
156
- return lstatSync(path)
157
- } catch {
158
- return null
159
- }
160
- },
161
- statExists: (path) => {
162
- try {
163
- statSync(path)
164
- return true
165
- } catch {
166
- return false
167
- }
168
- },
169
- readlink: readlinkSync,
170
- readFile: (path) => readFileSync(path, 'utf-8'),
171
- rename: renameSync,
172
- symlink: symlinkSync,
173
- writeFile: (path, data, mode) => writeFileSync(path, data, { mode }),
174
- unlink: unlinkSync,
175
- mkdirp: (path) => {
176
- Bun.spawnSync(['mkdir', '-p', path])
177
- },
178
- }
179
- }
@@ -1,108 +0,0 @@
1
- // PATH-shadow shim installed at the global bin path that `bun install -g
2
- // agent-browser` previously occupied. Replaces the plugin's old prompt-nudge +
3
- // bash-regex `tool.before` block, which was leaky (missed shell variations,
4
- // bypassed by `typeclaw shell`, by spawned subprocesses, by the user typing
5
- // it directly). Now ANY in-container `agent-browser` caller routes through
6
- // here and gets the anti-fingerprint User-Agent default before execing the
7
- // real upstream binary unchanged.
8
-
9
- import { existsSync } from 'node:fs'
10
-
11
- export const REAL_BIN_ENV = 'TYPECLAW_AGENT_BROWSER_REAL_BIN'
12
-
13
- // Recent desktop Chrome on Linux x86_64. The shim runs inside the TypeClaw
14
- // container (always Linux), so a macOS or Windows UA would mismatch the TCP
15
- // fingerprint, Accept-Language, and JS-side platform — itself a bot signal on
16
- // stricter sites (Cloudflare, Akamai, PerimeterX). `X11; Linux x86_64` is
17
- // also correct on linux/arm64 hosts: Chrome on Linux does not expose ARM in
18
- // the UA string at all (verified against current Chrome 131 releases).
19
- // The upstream binary defaults to a UA that includes "HeadlessChrome" /
20
- // a stale Chromium build, which is widely fingerprinted as a bot and
21
- // silently triggers CAPTCHAs, 403s, blank pages, and A/B-test misrouting.
22
- // Bump on Chrome major releases — same hygiene as the curl-impersonate pin
23
- // in src/init/dockerfile.ts.
24
- export const DEFAULT_USER_AGENT =
25
- 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
26
-
27
- export const USER_AGENT_ENV = 'AGENT_BROWSER_USER_AGENT'
28
-
29
- export function hasUserAgentFlag(argv: readonly string[]): boolean {
30
- // Matches both `--user-agent <val>` and `--user-agent=<val>`. The upstream
31
- // CLI does not document a short alias for --user-agent today (verified via
32
- // `agent-browser --help`), so we only check the long form.
33
- for (const arg of argv) {
34
- if (arg === '--user-agent' || arg.startsWith('--user-agent=')) return true
35
- }
36
- return false
37
- }
38
-
39
- export function injectUserAgentEnv(
40
- argv: readonly string[],
41
- env: Record<string, string | undefined>,
42
- defaultUa: string = DEFAULT_USER_AGENT,
43
- ): void {
44
- // Upstream's precedence is CLI flag > env > default. We only inject the
45
- // env when BOTH layers above it are absent so:
46
- // - explicit `--user-agent foo` wins (mobile testing, intentional bot UA)
47
- // - operator-set AGENT_BROWSER_USER_AGENT wins (per-shell override)
48
- // - default UA fills the otherwise-empty slot
49
- // `set device "iPhone 14"` is unaffected: it sets UA via CDP at runtime,
50
- // not through this env var, so our injection doesn't fight device emulation.
51
- if (env[USER_AGENT_ENV] !== undefined && env[USER_AGENT_ENV] !== '') return
52
- if (hasUserAgentFlag(argv)) return
53
- env[USER_AGENT_ENV] = defaultUa
54
- }
55
-
56
- export function resolveRealAgentBrowserBin(): string {
57
- // Set by the installer when it moves the upstream symlink aside. Honored
58
- // first so unit tests can point at a stub without touching the filesystem.
59
- const fromEnv = process.env[REAL_BIN_ENV]
60
- if (fromEnv && fromEnv.length > 0) return fromEnv
61
-
62
- // Fallback: `bun install -g agent-browser` ships per-platform native bins
63
- // under this stable path inside the bun image. The installer should have
64
- // stashed a copy/symlink, but if the shim runs before the plugin's
65
- // installer ever did (e.g. first agent boot), we can still find the real
66
- // bin and the next plugin boot will install the shim properly.
67
- const arch = process.arch === 'arm64' ? 'arm64' : process.arch === 'x64' ? 'x64' : null
68
- const platform = process.platform === 'linux' ? 'linux' : process.platform === 'darwin' ? 'darwin' : null
69
- if (arch !== null && platform !== null) {
70
- const native = `/root/.bun/install/global/node_modules/agent-browser/bin/agent-browser-${platform}-${arch}`
71
- if (existsSync(native)) return native
72
- }
73
-
74
- throw new Error(
75
- `${REAL_BIN_ENV} is not set and no fallback agent-browser binary was found. ` +
76
- `The shim cannot resolve the real upstream binary; refusing to exec to avoid an infinite loop.`,
77
- )
78
- }
79
-
80
- export type ShimOptions = {
81
- argv?: readonly string[]
82
- realBin?: string
83
- spawn?: (cmd: string[]) => { exited: Promise<number> }
84
- env?: Record<string, string | undefined>
85
- }
86
-
87
- export async function runShim(opts: ShimOptions = {}): Promise<number> {
88
- const argv = opts.argv ?? process.argv.slice(2)
89
- const realBin = opts.realBin ?? resolveRealAgentBrowserBin()
90
- const spawn = opts.spawn ?? defaultSpawn
91
- const env = opts.env ?? process.env
92
-
93
- injectUserAgentEnv(argv, env)
94
- return await spawn([realBin, ...argv]).exited
95
- }
96
-
97
- function defaultSpawn(cmd: string[]): { exited: Promise<number> } {
98
- // Inherit stdio so the upstream binary's TUI/spinner/colors work. The
99
- // shim is meant to be invisible; intercepting stdio would make e.g.
100
- // `agent-browser open` look broken to the caller.
101
- const proc = Bun.spawn(cmd, { stdio: ['inherit', 'inherit', 'inherit'] })
102
- return { exited: proc.exited }
103
- }
104
-
105
- if (import.meta.main) {
106
- const code = await runShim()
107
- process.exit(code)
108
- }