@thegitai/cli 1.0.0-preview.60 → 1.0.0-preview.61

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/README.md CHANGED
@@ -222,7 +222,10 @@ start `ai` normally and ask about your current tab or a website task. It uses
222
222
  your existing Chrome profile, website sessions, and terminal login. Connection
223
223
  is automatic; no setup/start command, second sign-in, or manual tab attachment
224
224
  is required. Tabs used by the agent join a TheGitAI tab group in an existing
225
- window. The conversation stays in your terminal.
225
+ window. The conversation stays in your terminal. With more than one Chrome
226
+ profile connected, TheGitAI asks which one to use the first time it acts in
227
+ the browser, with the one you used last as the default, and keeps that profile
228
+ for the conversation, including after `/resume`.
226
229
 
227
230
  Default mode asks before using a website and can remember that site for the
228
231
  session. Bypass all permissions allows browser actions; Plan mode reads pages
@@ -5,6 +5,7 @@ import fs from 'node:fs';
5
5
  import net from 'node:net';
6
6
  import path from 'node:path';
7
7
  import { decodeFrames, encodeFrame, fragmentPayload, MAX_FRAME_BYTES } from '../src/browser/framing.js';
8
+ import { chromeProfileLabel } from '../src/browser/chrome-profiles.js';
8
9
  import { BROWSER_PROTOCOL_VERSION, browserRuntimeDir, sessionKeyFromRecordFile, sessionSocketPath, socketIsFile, } from '../src/browser/protocol.js';
9
10
  const SCAN_INTERVAL_MS = 1000;
10
11
  const NUL = String.fromCharCode(0);
@@ -12,7 +13,9 @@ const sessions = new Map();
12
13
  const runtimeDir = browserRuntimeDir(process.env);
13
14
  let extensionVersion = '';
14
15
  let extensionProfileId = '';
16
+ let extensionProfileLabel = '';
15
17
  let extensionPlatform = '';
18
+ let extensionLastFocusedAt = 0;
16
19
  function log(message) {
17
20
  process.stderr.write(`[thegitai-browser-host] ${message}\n`);
18
21
  }
@@ -44,7 +47,11 @@ process.stdin.on('end', () => {
44
47
  });
45
48
  function describeParentBrowser() {
46
49
  const cmdline = process.platform === 'win32' ? windowsParentCommandLine() : unixParentCommandLine();
47
- return describeFromCommandLine(cmdline);
50
+ const userDataArg = cmdline.find((part) => part.startsWith('--user-data-dir='));
51
+ return {
52
+ ...describeFromCommandLine(cmdline),
53
+ userDataDir: userDataArg ? userDataArg.slice('--user-data-dir='.length) : '',
54
+ };
48
55
  }
49
56
  function windowsParentCommandLine() {
50
57
  const PASS_THROUGH = /^(cmd|conhost|powershell|pwsh|node)\.exe$/i;
@@ -125,24 +132,36 @@ function identity() {
125
132
  return {
126
133
  key: browserKey(),
127
134
  browser: parent.browser,
128
- profile: parent.profile !== 'Default' || !extensionProfileId
129
- ? parent.profile
130
- : `profile ${extensionProfileId.slice(0, 6)}`,
135
+ profile: extensionProfileLabel ||
136
+ (parent.profile !== 'Default' || !extensionProfileId
137
+ ? parent.profile
138
+ : `profile ${extensionProfileId.slice(0, 6)}`),
131
139
  platform: extensionPlatform || process.platform,
132
140
  extensionVersion,
141
+ ...(extensionLastFocusedAt > 0 ? { lastFocusedAt: extensionLastFocusedAt } : {}),
133
142
  };
134
143
  }
135
144
  function handleExtensionFrame(frame) {
136
145
  if (frame?.t === 'hello') {
137
146
  extensionVersion = String(frame.extensionVersion ?? '');
138
147
  extensionProfileId = String(frame.profileId ?? '');
148
+ extensionProfileLabel = /^[0-9a-f-]{36}$/i.test(extensionProfileId)
149
+ ? chromeProfileLabel(extensionProfileId, parent.userDataDir)
150
+ : '';
139
151
  extensionPlatform = String(frame.platform ?? '');
152
+ extensionLastFocusedAt = Number(frame.lastFocusedAt) || 0;
140
153
  writeToExtension({ t: 'hello', protocol: BROWSER_PROTOCOL_VERSION });
141
154
  publishSessions();
142
155
  for (const link of sessions.values())
143
156
  sendHello(link);
144
157
  return;
145
158
  }
159
+ if (frame?.t === 'focus') {
160
+ extensionLastFocusedAt = Number(frame.at) || extensionLastFocusedAt;
161
+ for (const link of sessions.values())
162
+ sendHello(link);
163
+ return;
164
+ }
146
165
  if (frame?.t === 'res' || frame?.t === 'event') {
147
166
  const target = frame.session ? sessions.get(frame.session) : null;
148
167
  const { session: _routed, ...rest } = frame;
@@ -201,15 +201,21 @@ export function startBrowserBridge({ sessionKey, label, cwd, env = process.env,
201
201
  return true;
202
202
  },
203
203
  selectBrowser(key) {
204
- if (browsers.has(key))
205
- selected = key;
204
+ if (!browsers.has(key))
205
+ return false;
206
+ selected = key;
207
+ return true;
206
208
  },
207
209
  onEvent(listener) {
208
210
  listeners.add(listener);
209
211
  return () => listeners.delete(listener);
210
212
  },
211
213
  request(op, args = {}, options = {}) {
212
- const target = selected ? browsers.get(selected) : null;
214
+ const key = options.browser ?? selected;
215
+ const target = key ? browsers.get(key) : null;
216
+ if (!target && options.browser) {
217
+ return Promise.reject(new BrowserBridgeError('The Chrome profile chosen for this conversation is not connected.', 'chosen_profile_missing'));
218
+ }
213
219
  if (!target) {
214
220
  return Promise.reject(new BrowserBridgeError('No browser is connected to this session.', 'not_connected'));
215
221
  }
@@ -0,0 +1,73 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { EXTENSION_IDS } from './protocol.js';
4
+ export function chromeUserDataDirs(userDataDir = '') {
5
+ if (userDataDir)
6
+ return [userDataDir];
7
+ const home = process.env.HOME || process.env.USERPROFILE || '';
8
+ if (process.platform === 'win32') {
9
+ const local = process.env.LOCALAPPDATA || path.join(home, 'AppData', 'Local');
10
+ return [
11
+ ['Google', 'Chrome'],
12
+ ['Google', 'Chrome Beta'],
13
+ ['Chromium'],
14
+ ['BraveSoftware', 'Brave-Browser'],
15
+ ['Microsoft', 'Edge'],
16
+ ].map((parts) => path.join(local, ...parts, 'User Data'));
17
+ }
18
+ if (process.platform === 'darwin') {
19
+ const support = path.join(home, 'Library', 'Application Support');
20
+ return ['Google/Chrome', 'Google/Chrome Beta', 'Chromium', 'BraveSoftware/Brave-Browser', 'Microsoft Edge'].map((dir) => path.join(support, dir));
21
+ }
22
+ const config = process.env.XDG_CONFIG_HOME || path.join(home, '.config');
23
+ return [
24
+ ...['google-chrome', 'google-chrome-beta', 'google-chrome-unstable', 'chromium', 'BraveSoftware/Brave-Browser', 'microsoft-edge'].map((dir) => path.join(config, dir)),
25
+ path.join(home, 'snap', 'chromium', 'common', 'chromium'),
26
+ ];
27
+ }
28
+ const UUID_TAIL = '[0-9a-f]{0,8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}';
29
+ export function chromeProfileLabel(idOrPrefix, userDataDir = '') {
30
+ const wanted = String(idOrPrefix ?? '').toLowerCase();
31
+ if (!/^[0-9a-f]{6}/.test(wanted) || !/^[0-9a-f-]+$/.test(wanted))
32
+ return '';
33
+ const pattern = wanted.length >= 36 ? null : new RegExp(`${wanted}${UUID_TAIL.replace('{0,8}', `{${8 - Math.min(wanted.length, 8)}}`)}`);
34
+ for (const dataDir of chromeUserDataDirs(userDataDir)) {
35
+ let profiles;
36
+ try {
37
+ profiles = JSON.parse(fs.readFileSync(path.join(dataDir, 'Local State'), 'utf8'))?.profile?.info_cache ?? {};
38
+ }
39
+ catch {
40
+ continue;
41
+ }
42
+ for (const [profileDir, info] of Object.entries(profiles)) {
43
+ for (const extensionId of EXTENSION_IDS) {
44
+ const store = path.join(dataDir, profileDir, 'Local Extension Settings', extensionId);
45
+ let files;
46
+ try {
47
+ files = fs.readdirSync(store);
48
+ }
49
+ catch {
50
+ continue;
51
+ }
52
+ for (const file of files) {
53
+ if (!/\.(log|ldb)$/.test(file))
54
+ continue;
55
+ try {
56
+ const full = path.join(store, file);
57
+ if (fs.statSync(full).size > 8 * 1024 * 1024)
58
+ continue;
59
+ const text = fs.readFileSync(full).toString('latin1');
60
+ if (pattern ? !pattern.test(text) : !text.includes(wanted))
61
+ continue;
62
+ }
63
+ catch {
64
+ continue;
65
+ }
66
+ const name = String(info?.name ?? '').trim().slice(0, 60);
67
+ return name ? `${name} (${profileDir})` : profileDir;
68
+ }
69
+ }
70
+ }
71
+ }
72
+ return '';
73
+ }
@@ -256,6 +256,9 @@ export async function executeLocalToolCall(session, call) {
256
256
  grants: session.grants,
257
257
  requestPermission: session.requestPermission,
258
258
  requestSudoPassword: session.requestSudoPassword,
259
+ requestUserInput: session.requestUserInput
260
+ ? (request) => session.requestUserInput(request, session.turnAbortSignal)
261
+ : null,
259
262
  onStatus: session.onStatus,
260
263
  editJournal: session.clientState.editJournal,
261
264
  safety: session.clientState.safety,
@@ -2,8 +2,10 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { normalizeProjectRelativePath } from '../artifact-policy.js';
4
4
  import { BrowserBridgeError } from '../browser/bridge.js';
5
+ import { chromeProfileLabel } from '../browser/chrome-profiles.js';
5
6
  import { storeSessionImageBytes } from '../core/session-image-store.js';
6
7
  import { browserAvailability, drainBrowserEvents, ensureBrowserBridge, resyncBrowserBridge, } from '../browser/session-bridge.js';
8
+ import { getClientStateDir } from '../client-state.js';
7
9
  import { ensurePermission, originForUrl } from '../permissions.js';
8
10
  const READ_TIMEOUT_MS = 20000;
9
11
  const NAVIGATE_TIMEOUT_MS = 45000;
@@ -40,23 +42,202 @@ async function waitForBrowser(options, timeoutMs) {
40
42
  }
41
43
  return browserAvailability(options);
42
44
  }
43
- async function notConnected(context) {
45
+ async function notConnected(context, { allowUnchosen = false, tabId } = {}) {
44
46
  const options = { cwd: context.rootDir, env: context.env };
45
47
  const status = ensureBrowserBridge(options).status();
46
- if (status.connected)
47
- return { ok: true };
48
- if (status.everConnected)
49
- resyncBrowserBridge(options);
50
- const availability = await waitForBrowser(options, DISCOVERY_TIMEOUT_MS);
51
- if (availability.connected)
48
+ if (!status.connected) {
49
+ if (status.everConnected)
50
+ resyncBrowserBridge(options);
51
+ const availability = await waitForBrowser(options, DISCOVERY_TIMEOUT_MS);
52
+ if (!availability.connected) {
53
+ return {
54
+ ok: false,
55
+ connected: false,
56
+ browserErrorCode: 'not_connected',
57
+ error: `TheGitAI is not connected to a browser. ${availability.hint ?? ''}`.trim(),
58
+ failureCategory: 'external_service',
59
+ };
60
+ }
61
+ }
62
+ return allowUnchosen ? { ok: true } : profileChosen(context, Number(tabId));
63
+ }
64
+ const resolvedProfileNames = new Map();
65
+ function profileLabel(profile) {
66
+ const unnamed = /^profile ([0-9a-f]{6})$/.exec(profile);
67
+ if (!unnamed)
68
+ return profile;
69
+ if (!resolvedProfileNames.has(unnamed[1])) {
70
+ resolvedProfileNames.set(unnamed[1], chromeProfileLabel(unnamed[1]) || profile);
71
+ }
72
+ return resolvedProfileNames.get(unnamed[1]);
73
+ }
74
+ function describeBrowsers(availability) {
75
+ const latest = Math.max(0, ...availability.browsers.map((browser) => browser.lastFocusedAt ?? 0));
76
+ return [...availability.browsers]
77
+ .sort((a, b) => (b.lastFocusedAt ?? 0) - (a.lastFocusedAt ?? 0))
78
+ .map((browser) => ({
79
+ key: browser.key,
80
+ name: `${browser.browser} - ${profileLabel(browser.profile)}`,
81
+ extensionVersion: browser.extensionVersion,
82
+ ...(latest > 0 && browser.lastFocusedAt === latest ? { lastUsed: true } : {}),
83
+ }));
84
+ }
85
+ const BROWSER_CHOICES_FILE = 'browser-choices.json';
86
+ const BROWSER_CHOICES_KEPT = 200;
87
+ const sessionProfiles = new Map();
88
+ function readBrowserChoices(env) {
89
+ try {
90
+ const parsed = JSON.parse(fs.readFileSync(path.join(getClientStateDir(env), BROWSER_CHOICES_FILE), 'utf8'));
91
+ return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
92
+ }
93
+ catch {
94
+ return {};
95
+ }
96
+ }
97
+ function profileChoiceFor(context) {
98
+ const session = context.sessionId ?? '';
99
+ const remembered = sessionProfiles.get(session);
100
+ if (remembered)
101
+ return remembered;
102
+ const saved = session ? readBrowserChoices(context.env)[session] : undefined;
103
+ if (!saved?.key)
104
+ return null;
105
+ const choice = { key: String(saved.key), name: String(saved.name ?? saved.key), at: Number(saved.at) || 0 };
106
+ sessionProfiles.set(session, choice);
107
+ return choice;
108
+ }
109
+ function recordProfileChoice(context, browser) {
110
+ const session = context.sessionId ?? '';
111
+ const choice = { key: browser.key, name: browser.name, at: Date.now() };
112
+ sessionProfiles.set(session, choice);
113
+ if (!session)
114
+ return;
115
+ try {
116
+ const choices = readBrowserChoices(context.env);
117
+ choices[session] = choice;
118
+ const kept = Object.fromEntries(Object.entries(choices)
119
+ .sort(([, a], [, b]) => (b?.at ?? 0) - (a?.at ?? 0))
120
+ .slice(0, BROWSER_CHOICES_KEPT));
121
+ const dir = getClientStateDir(context.env);
122
+ fs.mkdirSync(dir, { recursive: true });
123
+ fs.writeFileSync(path.join(dir, BROWSER_CHOICES_FILE), JSON.stringify(kept), { mode: 0o600 });
124
+ }
125
+ catch {
126
+ }
127
+ }
128
+ async function askForProfile(context, listed, suggested) {
129
+ if (!context.requestUserInput)
130
+ return null;
131
+ const recommended = suggested ?? listed.find((browser) => browser.lastUsed) ?? listed[0];
132
+ const ordered = [recommended, ...listed.filter((browser) => browser.key !== recommended.key)];
133
+ const result = await context.requestUserInput({
134
+ questions: [
135
+ {
136
+ id: 'chrome_profile',
137
+ header: 'Chrome profile',
138
+ question: 'Which Chrome profile should TheGitAI use for this conversation?',
139
+ options: ordered.map((browser, index) => ({
140
+ id: `profile_${index}`,
141
+ label: browser.name,
142
+ description: browser.lastUsed ? 'The profile you used last' : 'Connected',
143
+ })),
144
+ multiSelect: false,
145
+ recommendedOptionId: 'profile_0',
146
+ },
147
+ ],
148
+ });
149
+ if (result?.status !== 'submitted')
150
+ return 'cancelled';
151
+ const answer = result.answers?.chrome_profile;
152
+ const option = /^profile_(\d+)$/.exec(answer?.selectedOptionIds?.[0] ?? '');
153
+ if (option && ordered[Number(option[1])])
154
+ return ordered[Number(option[1])];
155
+ const text = String(answer?.customText ?? '').trim();
156
+ return text ? { text } : 'cancelled';
157
+ }
158
+ async function useProfile(context, listed, suggested) {
159
+ const bridge = ensureBrowserBridge({ cwd: context.rootDir, env: context.env });
160
+ const choice = listed.length === 1 ? listed[0] : await askForProfile(context, listed, suggested);
161
+ if (choice === 'cancelled') {
162
+ return {
163
+ ok: false,
164
+ browserErrorCode: 'profile_question_cancelled',
165
+ error: 'The user closed the question about which Chrome profile to use, so nothing was done.',
166
+ failureCategory: 'user_declined',
167
+ browsers: listed,
168
+ };
169
+ }
170
+ if (choice && typeof choice === 'object' && 'text' in choice) {
171
+ return {
172
+ ok: false,
173
+ browserErrorCode: 'profile_answered_in_text',
174
+ error: `Asked which Chrome profile to use, the user answered in their own words instead of picking one: "${choice.text.slice(0, 300)}". Nothing was done.`,
175
+ failureCategory: 'user_declined',
176
+ browsers: listed,
177
+ };
178
+ }
179
+ const picked = choice ?? suggested;
180
+ if (!picked) {
181
+ return {
182
+ ok: false,
183
+ browserErrorCode: 'browser_not_chosen',
184
+ error: `${listed.length} Chrome profiles are connected and none has been chosen for this conversation.`,
185
+ failureCategory: 'invalid_argument',
186
+ browsers: listed,
187
+ };
188
+ }
189
+ recordProfileChoice(context, picked);
190
+ if (!bridge.selectBrowser(picked.key)) {
191
+ return {
192
+ ok: false,
193
+ browserErrorCode: 'chosen_profile_missing',
194
+ error: `The Chrome profile chosen for this conversation, ${picked.name}, is not connected.`,
195
+ failureCategory: 'external_service',
196
+ browsers: describeBrowsers(browserAvailability({ cwd: context.rootDir, env: context.env })),
197
+ };
198
+ }
199
+ return { ok: true };
200
+ }
201
+ async function profilesHoldingTab(context, listed, tabId) {
202
+ const bridge = ensureBrowserBridge({ cwd: context.rootDir, env: context.env });
203
+ const holders = await Promise.all(listed.map(async (browser) => {
204
+ try {
205
+ const result = await bridge.request('context', { includeAll: true }, { timeoutMs: READ_TIMEOUT_MS, browser: browser.key });
206
+ const tabs = Array.isArray(result?.tabs) ? result.tabs : [];
207
+ return tabs.some((tab) => Number(tab?.tabId) === tabId) ? browser : null;
208
+ }
209
+ catch {
210
+ return null;
211
+ }
212
+ }));
213
+ return holders.filter((browser) => browser !== null);
214
+ }
215
+ async function profileChosen(context, tabId = NaN) {
216
+ const options = { cwd: context.rootDir, env: context.env };
217
+ const listed = describeBrowsers(browserAvailability(options));
218
+ const choice = profileChoiceFor(context);
219
+ if (choice) {
220
+ if (ensureBrowserBridge(options).selectBrowser(choice.key))
221
+ return { ok: true };
222
+ return {
223
+ ok: false,
224
+ browserErrorCode: 'chosen_profile_missing',
225
+ error: `The Chrome profile chosen for this conversation, ${choice.name}, is not connected.`,
226
+ failureCategory: 'external_service',
227
+ browsers: listed,
228
+ };
229
+ }
230
+ if (!listed.length)
52
231
  return { ok: true };
53
- return {
54
- ok: false,
55
- connected: false,
56
- browserErrorCode: 'not_connected',
57
- error: `TheGitAI is not connected to a browser. ${availability.hint ?? ''}`.trim(),
58
- failureCategory: 'external_service',
59
- };
232
+ if (listed.length > 1 && Number.isInteger(tabId)) {
233
+ const holders = await profilesHoldingTab(context, listed, tabId);
234
+ if (holders.length === 1) {
235
+ ensureBrowserBridge(options).selectBrowser(holders[0].key);
236
+ recordProfileChoice(context, holders[0]);
237
+ return { ok: true };
238
+ }
239
+ }
240
+ return useProfile(context, listed);
60
241
  }
61
242
  function bridgeFailure(error) {
62
243
  const code = error instanceof BrowserBridgeError ? error.code : 'browser_error';
@@ -70,12 +251,15 @@ function bridgeFailure(error) {
70
251
  }
71
252
  async function call(context, op, args = {}, timeoutMs = READ_TIMEOUT_MS) {
72
253
  const bridge = ensureBrowserBridge({ cwd: context.rootDir, env: context.env });
73
- return bridge.request(op, args, { timeoutMs });
254
+ return bridge.request(op, args, { timeoutMs, browser: profileChoiceFor(context)?.key });
74
255
  }
75
256
  async function currentTab(context, tabId) {
76
257
  const result = await call(context, 'context', { includeAll: true });
77
258
  const tabs = Array.isArray(result?.tabs) ? result.tabs : [];
78
- return tabs.find((tab) => Number(tab.tabId) === tabId) ?? null;
259
+ const tab = tabs.find((entry) => Number(entry.tabId) === tabId);
260
+ if (!tab)
261
+ return null;
262
+ return { ...tab, url: String(tab.url ?? '').replace(/…+$/, '') };
79
263
  }
80
264
  async function ensureSiteAllowed(context, { url, tool, summary, }) {
81
265
  const origin = originForUrl(String(url ?? ''));
@@ -105,33 +289,80 @@ function attachEvents(result) {
105
289
  browserNotices: notable.map((entry) => String(entry.data?.message ?? `Browser ${entry.event}.`)),
106
290
  };
107
291
  }
108
- export async function browserGateway(context) {
109
- const guard = await notConnected(context);
292
+ export async function browserGateway(context, args = {}) {
293
+ const guard = await notConnected(context, { allowUnchosen: true });
110
294
  if (guard.ok === false)
111
295
  return guard;
112
- const availability = browserAvailability({ cwd: context.rootDir, env: context.env });
296
+ const options = { cwd: context.rootDir, env: context.env };
297
+ const requested = String(args.browser ?? '').trim();
298
+ const listed = describeBrowsers(browserAvailability(options));
299
+ if (requested) {
300
+ const wanted = requested.toLowerCase();
301
+ const partial = listed.filter((browser) => browser.name.toLowerCase().includes(wanted));
302
+ const match = listed.find((browser) => browser.key === requested) ??
303
+ listed.find((browser) => browser.name.toLowerCase() === wanted) ??
304
+ listed.find((browser) => browser.name.toLowerCase().endsWith(`(${wanted})`)) ??
305
+ (partial.length === 1 ? partial[0] : undefined);
306
+ if (!match) {
307
+ return {
308
+ ok: false,
309
+ error: partial.length > 1
310
+ ? `"${requested}" matches more than one connected browser. Use a key from browsers.`
311
+ : `No connected browser matches "${requested}". Use a key from browsers.`,
312
+ failureCategory: 'invalid_argument',
313
+ browsers: listed,
314
+ };
315
+ }
316
+ if (profileChoiceFor(context)?.key !== match.key) {
317
+ const chosen = await useProfile(context, listed, match);
318
+ if (chosen.ok === false)
319
+ return chosen;
320
+ }
321
+ }
322
+ else if (listed.length === 1 && !profileChoiceFor(context)) {
323
+ await useProfile(context, listed);
324
+ }
325
+ const availability = browserAvailability(options);
113
326
  const platform = availability.browsers[0]?.platform ?? process.platform;
327
+ const choice = profileChoiceFor(context);
328
+ const connectedChoice = choice && availability.browsers.some((browser) => browser.key === choice.key) ? choice : null;
114
329
  return {
115
330
  ok: true,
116
331
  connected: true,
117
- browsers: availability.browsers.map((browser) => ({
118
- key: browser.key,
119
- name: `${browser.browser} — ${browser.profile}`,
120
- extensionVersion: browser.extensionVersion,
121
- })),
122
- selected: availability.selected,
332
+ browsers: describeBrowsers(availability),
333
+ selected: connectedChoice?.key ?? null,
334
+ choiceNeeded: !connectedChoice,
123
335
  shortcutModifier: platform === 'darwin' ? 'cmd' : 'ctrl',
124
336
  platform,
125
337
  };
126
338
  }
127
339
  export async function browserTabs(context, args) {
128
- const guard = await notConnected(context);
340
+ const includeAll = args.include_all === true || args.includeAll === true;
341
+ const guard = await notConnected(context, { allowUnchosen: includeAll });
129
342
  if (guard.ok === false)
130
343
  return guard;
131
- try {
132
- const result = await call(context, 'context', {
133
- includeAll: args.include_all === true || args.includeAll === true,
344
+ const options = { cwd: context.rootDir, env: context.env };
345
+ const availability = browserAvailability(options);
346
+ if (includeAll && availability.browsers.length > 1) {
347
+ const bridge = ensureBrowserBridge(options);
348
+ const profiles = await Promise.all(describeBrowsers(availability).map(async (browser) => {
349
+ try {
350
+ const result = await bridge.request('context', { includeAll: true }, { timeoutMs: READ_TIMEOUT_MS, browser: browser.key });
351
+ return { ...browser, selected: browser.key === profileChoiceFor(context)?.key, ...result };
352
+ }
353
+ catch (error) {
354
+ return { ...browser, selected: browser.key === profileChoiceFor(context)?.key, error: String(error?.message ?? error) };
355
+ }
356
+ }));
357
+ const choice = profileChoiceFor(context);
358
+ return attachEvents({
359
+ ok: true,
360
+ choiceNeeded: !choice || !availability.browsers.some((browser) => browser.key === choice.key),
361
+ profiles,
134
362
  });
363
+ }
364
+ try {
365
+ const result = await call(context, 'context', { includeAll });
135
366
  return attachEvents({ ok: true, ...result });
136
367
  }
137
368
  catch (error) {
@@ -164,7 +395,7 @@ export async function browserTabNew(context, args = {}) {
164
395
  }
165
396
  }
166
397
  export async function browserTabClose(context, args) {
167
- const guard = await notConnected(context);
398
+ const guard = await notConnected(context, { tabId: args.tabId ?? args.tab_id });
168
399
  if (guard.ok === false)
169
400
  return guard;
170
401
  const tabId = Number(args.tabId ?? args.tab_id);
@@ -179,7 +410,7 @@ export async function browserTabClose(context, args) {
179
410
  }
180
411
  }
181
412
  export async function browserNavigate(context, args) {
182
- const guard = await notConnected(context);
413
+ const guard = await notConnected(context, { tabId: args.tabId ?? args.tab_id });
183
414
  if (guard.ok === false)
184
415
  return guard;
185
416
  const url = String(args.url ?? '').trim();
@@ -212,7 +443,7 @@ export async function browserNavigate(context, args) {
212
443
  }
213
444
  }
214
445
  async function gatedTabCall(context, { tool, op, args, summary, timeoutMs = READ_TIMEOUT_MS, }) {
215
- const guard = await notConnected(context);
446
+ const guard = await notConnected(context, { tabId: args.tabId ?? args.tab_id });
216
447
  if (guard.ok === false)
217
448
  return guard;
218
449
  const tabId = Number(args.tabId ?? args.tab_id);
@@ -472,7 +703,7 @@ export function browserResize(context, args) {
472
703
  });
473
704
  }
474
705
  export async function browserFileUpload(context, args) {
475
- const guard = await notConnected(context);
706
+ const guard = await notConnected(context, { tabId: args.tabId ?? args.tab_id });
476
707
  if (guard.ok === false)
477
708
  return guard;
478
709
  const ref = String(args.ref ?? '').trim();
@@ -593,7 +824,7 @@ const BATCH_TOOLS = {
593
824
  browser_downloads: browserDownloads,
594
825
  };
595
826
  export async function browserBatch(context, args) {
596
- const guard = await notConnected(context);
827
+ const guard = await notConnected(context, { tabId: (Array.isArray(args.actions) ? args.actions[0]?.input?.tabId : undefined) });
597
828
  if (guard.ok === false)
598
829
  return guard;
599
830
  const actions = Array.isArray(args.actions) ? args.actions : [];
@@ -44,7 +44,7 @@ export const TOOL_MAP = {
44
44
  shell_job_kill: shellJobKill,
45
45
  update_todos: updateTodos,
46
46
  analyze_image: (context, args) => readImageFile(context, args),
47
- browser: (context) => browserGateway(context),
47
+ browser: (context, args) => browserGateway(context, args),
48
48
  browser_tabs: browserTabs,
49
49
  browser_tab_new: (context, args) => browserTabNew(context, args),
50
50
  browser_tab_close: browserTabClose,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thegitai/cli",
3
- "version": "1.0.0-preview.60",
3
+ "version": "1.0.0-preview.61",
4
4
  "description": "TheGitAI is an agentic AI coding tool for your terminal. It reads and searches your repository, writes and edits files, runs your tests, and verifies the change before handing it back.",
5
5
  "keywords": [
6
6
  "agentic-ai",
@@ -45,11 +45,11 @@
45
45
  "@lydell/node-pty-linux-x64": "1.1.0",
46
46
  "@lydell/node-pty-win32-arm64": "1.1.0",
47
47
  "@lydell/node-pty-win32-x64": "1.1.0",
48
- "@thegitai/tui-darwin-arm64": "1.0.0-preview.60",
49
- "@thegitai/tui-darwin-x64": "1.0.0-preview.60",
50
- "@thegitai/tui-linux-arm64": "1.0.0-preview.60",
51
- "@thegitai/tui-linux-x64": "1.0.0-preview.60",
52
- "@thegitai/tui-win32-x64": "1.0.0-preview.60",
48
+ "@thegitai/tui-darwin-arm64": "1.0.0-preview.61",
49
+ "@thegitai/tui-darwin-x64": "1.0.0-preview.61",
50
+ "@thegitai/tui-linux-arm64": "1.0.0-preview.61",
51
+ "@thegitai/tui-linux-x64": "1.0.0-preview.61",
52
+ "@thegitai/tui-win32-x64": "1.0.0-preview.61",
53
53
  "@vscode/ripgrep": "1.18.0"
54
54
  },
55
55
  "repository": {