@yanzc/claude-pro 0.9.5 → 0.9.6
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 +3 -8
- package/package.json +1 -1
- package/src/browser/session.js +11 -9
- package/src/commands.js +0 -102
- package/src/ui/repl.js +2 -2
package/README.md
CHANGED
|
@@ -262,18 +262,13 @@ claude-pro config set CLAUDE_PRO_GATEWAY_URL https://gw.predix.icu
|
|
|
262
262
|
} }
|
|
263
263
|
```
|
|
264
264
|
|
|
265
|
-
##
|
|
265
|
+
## 浏览器
|
|
266
266
|
|
|
267
267
|
`Browser` 工具操作你自己的 Edge/Chrome(带着你的登录状态),也可以用 claude-pro 自己的浏览器(`browser: "own"`)。先在 Edge 的 `edge://inspect/#remote-debugging`(Chrome 是 `chrome://inspect/#remote-debugging`)里打开允许远程调试。浏览器对每个新连接都会弹窗问“是否允许远程调试”(没有“始终允许”),所以连接由一个后台小进程(`src/browser/broker.js`)替所有 claude-pro 会话保持:每个浏览器实例只需点一次“允许”,claude-pro 重启、新开会话都沿用这个连接,不再弹窗。最后一个用它的会话退出 10 分钟后,后台进程才断开连接并退出;之后再用浏览器会重新问一次。
|
|
268
268
|
|
|
269
|
-
|
|
269
|
+
**指定标签页**:在消息里写网址或标题里的字(例如“操作 YouTube 那个标签页”),模型在当前连着的浏览器里按标题和网址找到它。标签页 ID 是 `t` 加浏览器内部 ID 的前几位,只要标签页没关就不变:重新连接或 claude-pro 重启后,同一个 ID 还是同一个标签页,所以也可以直接在消息里写“用 t3f9a”。标签页关了,ID 就失效并报错,不会落到别的标签页上。
|
|
270
270
|
|
|
271
|
-
-
|
|
272
|
-
- 输入框里插入 `[Browser tab t3f9a in Microsoft Edge: "(1) 收件箱 | …"]`,接着写要它做什么就行,模型不用再列出标签页查找、匹配。
|
|
273
|
-
|
|
274
|
-
标签页 ID 是 `t` 加浏览器内部 ID 的前几位,只要标签页没关就不变:重新连接或 claude-pro 重启后,同一个 ID 还是同一个标签页,所以也可以直接在消息里写“用 t3f9a”。标签页关了,ID 就失效并报错,不会落到别的标签页上。
|
|
275
|
-
|
|
276
|
-
选过的浏览器实例会记住:claude-pro 重启后,模型下一次用浏览器时自动连回这个实例,对话里的标签页 ID 仍然有效。没选过时,自动选第一个开了远程调试的浏览器(按 Edge、Chrome、Brave、Chromium 的常用数据目录,再到用独立数据目录运行的实例);要固定默认,`/config set CLAUDE_PRO_BROWSER edge`。查找浏览器实例要读取正在运行的浏览器进程(Windows 上约 1–3 秒),已经连着浏览器时直接 `/tabs` 不用再找。
|
|
271
|
+
用过的浏览器实例会记住:claude-pro 重启后,模型下一次用浏览器时自动连回这个实例,对话里的标签页 ID 仍然有效。没用过时,自动选第一个开了远程调试的浏览器(按 Edge、Chrome、Brave、Chromium 的常用数据目录,再到用独立数据目录运行的实例);要固定默认,`/config set CLAUDE_PRO_BROWSER edge`。
|
|
277
272
|
|
|
278
273
|
## 非交互模式
|
|
279
274
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yanzc/claude-pro",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.6",
|
|
4
4
|
"description": "claude-pro: a command line coding agent for the codex-gateway. Full access with no permission prompts; file edits are checkpointed and can be rewound.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
package/src/browser/session.js
CHANGED
|
@@ -154,8 +154,8 @@ const howToTurnOn = (b) => `${b.label} does not allow remote debugging now. The
|
|
|
154
154
|
//
|
|
155
155
|
// A browser started with a profile directory of its own (--user-data-dir: an app that opens its window in Edge, a
|
|
156
156
|
// second profile kept apart) is another instance, with its own tabs and its own DevToolsActivePort in that
|
|
157
|
-
// directory, which the usual places do not have:
|
|
158
|
-
//
|
|
157
|
+
// directory, which the usual places do not have: looking in those only missed the Edge the user's mail was open
|
|
158
|
+
// in. The running browsers' command lines say where each one keeps its profile.
|
|
159
159
|
|
|
160
160
|
const samePath = (a, b) => {
|
|
161
161
|
const x = path.resolve(String(a));
|
|
@@ -229,7 +229,7 @@ function shortDir(dir) {
|
|
|
229
229
|
return dir;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
// An instance found at `dir`, for
|
|
232
|
+
// An instance found at `dir`, for the Browser tool: {name, label, dir, url, port, isDefault, own?}.
|
|
233
233
|
function instance(kind, dir, url) {
|
|
234
234
|
if (kind === 'own' || samePath(dir, OWN.dir)) return { ...OWN, dir: OWN.dir, url, port: portOf(url), own: true };
|
|
235
235
|
const base = knownBrowsers().find((b) => b.name === kind) || { name: kind || 'chrome', label: 'Chromium browser', inspect: 'chrome://inspect/#remote-debugging' };
|
|
@@ -258,7 +258,7 @@ export async function browserInstances() {
|
|
|
258
258
|
return found.filter(Boolean);
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
// The instance the session used last (
|
|
261
|
+
// The instance the session used last (the one before a restart, too), when it is still there and
|
|
262
262
|
// the call asks for no browser in particular or for one of its kind (`w`, the call's own browser field: the user's
|
|
263
263
|
// pick wins over the configured default): its tab ids are the ones the conversation knows.
|
|
264
264
|
async function preferredTarget(preferred, w) {
|
|
@@ -287,7 +287,7 @@ export async function resolveBrowser(spec, env, signal, preferred = null) {
|
|
|
287
287
|
// not in its usual profile: one running on a profile directory of its own
|
|
288
288
|
const others = (await browserInstances()).filter((i) => i.name === w);
|
|
289
289
|
if (others.length === 1) return others[0];
|
|
290
|
-
if (others.length > 1) throw new BrowserError(`${known.label} allows remote debugging in ${others.length} profile directories: ${others.map((i) => i.dir).join('; ')}. Pass the one meant as browser (the user
|
|
290
|
+
if (others.length > 1) throw new BrowserError(`${known.label} allows remote debugging in ${others.length} profile directories: ${others.map((i) => i.dir).join('; ')}. Pass the one meant as browser (ask the user which one)`);
|
|
291
291
|
throw new BrowserError(howToTurnOn(known));
|
|
292
292
|
}
|
|
293
293
|
if (/[\\/]/.test(wanted) && fs.existsSync(wanted) && fs.statSync(wanted).isDirectory()) {
|
|
@@ -406,7 +406,7 @@ class BrowserSession {
|
|
|
406
406
|
return next;
|
|
407
407
|
}
|
|
408
408
|
|
|
409
|
-
// `spec`: what the call asked for (see resolveBrowser), or an instance from browserInstances
|
|
409
|
+
// `spec`: what the call asked for (see resolveBrowser), or an instance from browserInstances. The user's
|
|
410
410
|
// browsers are reached through the broker (broker.js), whose connection outlives this process: the user allows
|
|
411
411
|
// it once, not again at every restart and in every session. Another browser asked for is found and connected to
|
|
412
412
|
// before the one there is let go: a request for one that is not there (chrome, when only Edge allows it) cost
|
|
@@ -465,8 +465,8 @@ class BrowserSession {
|
|
|
465
465
|
// A tab's id is "t" and the start of its own id in the browser (its targetId, which it keeps while it is open),
|
|
466
466
|
// 4 hex digits or as many more as it takes to tell it from the other open tabs. Numbers given in the order of a
|
|
467
467
|
// connection (t1, t2...) started again at every reconnect and restart of claude-pro, so that an id in the
|
|
468
|
-
// conversation
|
|
469
|
-
//
|
|
468
|
+
// conversation could then be another tab, the one the agent would click in or close. These ids mean the same tab
|
|
469
|
+
// in every connection and every session (see tab).
|
|
470
470
|
relabel() {
|
|
471
471
|
const hexTabs = [...this.tabs.values()].filter((t) => t.hex);
|
|
472
472
|
for (const tab of hexTabs) {
|
|
@@ -857,7 +857,9 @@ class BrowserSession {
|
|
|
857
857
|
}
|
|
858
858
|
|
|
859
859
|
async evaluate(tab, script, ref) {
|
|
860
|
-
|
|
860
|
+
// a function is called; one that calls itself already ((() => {…})()) is an expression, not called again
|
|
861
|
+
const iife = /^\s*\(/.test(script) && /\)\s*\(\s*\)\s*;?\s*$/.test(script);
|
|
862
|
+
const isFn = !iife && /^\s*(async\s+)?(function\b|\([^)]*\)\s*=>|[\w$]+\s*=>)/.test(script);
|
|
861
863
|
let r;
|
|
862
864
|
if (ref) {
|
|
863
865
|
const objectId = await this.objectId(tab, refId(ref), ref);
|
package/src/commands.js
CHANGED
|
@@ -20,7 +20,6 @@ import { activePromptName, listPromptProfiles, loadActivePrompt, promptDirectory
|
|
|
20
20
|
import { cleanName, machineName } from './peers.js';
|
|
21
21
|
import { rewind, promptAt } from './checkpoints.js';
|
|
22
22
|
import { canRestart, runSelfCheck } from './restart.js';
|
|
23
|
-
import { browserSession, browserInstances, sameBrowser, safeUrl } from './browser/session.js';
|
|
24
23
|
|
|
25
24
|
const EFFORTS = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
|
|
26
25
|
const isGpt = (modelId) => /^gpt-/i.test(modelId);
|
|
@@ -760,107 +759,6 @@ export function buildCommands(app) {
|
|
|
760
759
|
},
|
|
761
760
|
});
|
|
762
761
|
|
|
763
|
-
// The tab the Browser tool is to work in, picked by the user instead of looked for by the model: the tabs of the
|
|
764
|
-
// browser with their ids, from the same connection the tool uses (so the ids are the tool's), and the one picked is
|
|
765
|
-
// selected there and named in the message being written. Its id stays that tab's after a reconnect or a restart
|
|
766
|
-
// (BrowserSession.relabel), so the agent goes straight to it. Several browser instances may allow remote debugging
|
|
767
|
-
// (Edge also on a profile directory of its own, as an app's window has): the user picks one first, and the
|
|
768
|
-
// session goes back to it after a restart (BrowserSession.preferred).
|
|
769
|
-
add({
|
|
770
|
-
name: 'tabs',
|
|
771
|
-
aliases: ['tab'],
|
|
772
|
-
argHint: '[edge|chrome|brave|chromium|own|words of a profile directory]',
|
|
773
|
-
description: 'Pick a tab of your browser for the Browser tool: it is selected, and its id goes into your message',
|
|
774
|
-
async run(args) {
|
|
775
|
-
// the agent's own browser calls go to the selected tab: not changed under it while it works
|
|
776
|
-
if (app.isTurnRunning()) { out(c.dim('The agent is working and may be using the browser: /tabs once the turn is done (or Esc).')); return; }
|
|
777
|
-
if (app.runtime.tasks.running().length) { out(c.dim('Background agents are running and may be using the browser: /tabs once they are done (/tasks).')); return; }
|
|
778
|
-
const s = browserSession;
|
|
779
|
-
// Esc cancels while it waits: the browser may ask the user to allow the connection first
|
|
780
|
-
const busy = async (status, fn) => {
|
|
781
|
-
app.busy = true;
|
|
782
|
-
app.status = status;
|
|
783
|
-
app.turnStart = Date.now();
|
|
784
|
-
app.controller = new AbortController();
|
|
785
|
-
try { return await s.run(app.controller.signal, fn); } finally {
|
|
786
|
-
app.busy = false;
|
|
787
|
-
app.status = null;
|
|
788
|
-
app.controller = null;
|
|
789
|
-
app.screen.schedule();
|
|
790
|
-
}
|
|
791
|
-
};
|
|
792
|
-
const failed = (e, what) => out(e?.name === 'AbortError' ? c.dim('Cancelled.') : c.red(`${what}: ${e.message}`));
|
|
793
|
-
// The instance to connect to: the one matching `ask` (a kind, or words of its profile directory), or the user's
|
|
794
|
-
// pick when several are there. null: none, or the user closed the list.
|
|
795
|
-
const chooseBrowser = async (ask) => {
|
|
796
|
-
let all;
|
|
797
|
-
try { all = await busy('Looking for browsers', () => browserInstances()); } catch (e) { failed(e, 'Cannot list the browsers'); return null; }
|
|
798
|
-
const q = ask.toLowerCase();
|
|
799
|
-
const list = q ? all.filter((i) => i.name === q || `${i.label} ${i.dir}`.toLowerCase().includes(q)) : all;
|
|
800
|
-
if (!list.length) {
|
|
801
|
-
out(c.red(`${q ? `No browser matching "${ask}" allows` : 'No browser allows'} remote debugging now. Turn it on in yours at edge://inspect/#remote-debugging (Chrome: chrome://inspect/#remote-debugging) and allow it for this browser instance.`));
|
|
802
|
-
return null;
|
|
803
|
-
}
|
|
804
|
-
if (list.length === 1) return list[0];
|
|
805
|
-
const connected = list.find((i) => s.connected && sameBrowser(i, s.browser));
|
|
806
|
-
const key = await app.showDialog(new SelectDialog({
|
|
807
|
-
title: 'Which browser?',
|
|
808
|
-
question: 'These allow remote debugging now; each asks once per connection to allow it.',
|
|
809
|
-
options: list.map((i) => ({ value: i.dir || i.url, label: `${i.label}${i === connected ? c.dim(' (connected)') : ''}`, description: `${i.dir}${i.port ? ` · port ${i.port}` : ''}` })),
|
|
810
|
-
selected: Math.max(0, list.indexOf(connected)),
|
|
811
|
-
}));
|
|
812
|
-
return key ? list.find((i) => (i.dir || i.url) === key) : null;
|
|
813
|
-
};
|
|
814
|
-
try {
|
|
815
|
-
const ask = args.trim();
|
|
816
|
-
let target = null;
|
|
817
|
-
if (ask || !s.connected) {
|
|
818
|
-
target = await chooseBrowser(ask);
|
|
819
|
-
if (!target) return;
|
|
820
|
-
}
|
|
821
|
-
for (;;) {
|
|
822
|
-
if (target) {
|
|
823
|
-
const connecting = target;
|
|
824
|
-
target = null;
|
|
825
|
-
try {
|
|
826
|
-
await busy('Connecting to the browser', () => s.connect(connecting, app.runtime.config.env, (b) => {
|
|
827
|
-
app.status = `Allow the connection in ${b.label} ("Allow remote debugging?" → Allow) · Esc cancels`;
|
|
828
|
-
app.screen.schedule();
|
|
829
|
-
}));
|
|
830
|
-
} catch (e) { failed(e, 'Cannot use the browser'); return; }
|
|
831
|
-
}
|
|
832
|
-
const browser = s.browser;
|
|
833
|
-
const tabs = [...s.tabs.values()];
|
|
834
|
-
if (!browser) { out(c.dim('The connection to the browser was lost.')); return; }
|
|
835
|
-
const title = (t, n) => truncate(String(t.title || '(no title)').replace(/\s+/g, ' '), n);
|
|
836
|
-
const chosen = await app.showDialog(new SelectDialog({
|
|
837
|
-
title: `Tabs in ${browser.label}`,
|
|
838
|
-
question: 'The Browser tool works in the tab you pick, and its id goes into your message.',
|
|
839
|
-
options: [
|
|
840
|
-
...tabs.map((t) => ({ value: t.targetId, label: `${padEnd(t.id, 8)} ${title(t, 70)}${t === s.current ? c.dim(' (selected)') : ''}`, description: safeUrl(t.url || '') })),
|
|
841
|
-
{ value: '__browser__', label: c.dim('Another browser or profile…') },
|
|
842
|
-
],
|
|
843
|
-
selected: Math.max(0, tabs.indexOf(s.current)),
|
|
844
|
-
}));
|
|
845
|
-
if (!chosen) return;
|
|
846
|
-
if (chosen === '__browser__') {
|
|
847
|
-
target = await chooseBrowser('');
|
|
848
|
-
if (!target) return;
|
|
849
|
-
continue;
|
|
850
|
-
}
|
|
851
|
-
const tab = s.tabs.get(chosen);
|
|
852
|
-
if (!tab) { out(c.red('That tab was closed meanwhile.')); return; }
|
|
853
|
-
try { await busy('Selecting the tab', () => s.select(tab)); } catch (e) { failed(e, `Could not select ${tab.id}`); return; }
|
|
854
|
-
app.editor.insert(`[Browser tab ${tab.id} in ${browser.label}: ${JSON.stringify(title(tab, 60))}] `);
|
|
855
|
-
out(c.dim(`${tab.id} is the Browser tool's tab now, and its id is in your message.`));
|
|
856
|
-
return;
|
|
857
|
-
}
|
|
858
|
-
} finally {
|
|
859
|
-
app.sendWhatWaited(); // what was typed while it connected
|
|
860
|
-
}
|
|
861
|
-
},
|
|
862
|
-
});
|
|
863
|
-
|
|
864
762
|
add({
|
|
865
763
|
name: 'tui',
|
|
866
764
|
argHint: '[fullscreen | default]',
|
package/src/ui/repl.js
CHANGED
|
@@ -1057,8 +1057,8 @@ export class App {
|
|
|
1057
1057
|
changedDirectory: Boolean(request.cwd),
|
|
1058
1058
|
// where the agent's shell is (a `cd` in Bash moves it): the next process goes on there, not at the project's root
|
|
1059
1059
|
agentCwd: request.cwd ? null : this.agent.cwd,
|
|
1060
|
-
// the browser instance in use (
|
|
1061
|
-
//
|
|
1060
|
+
// the browser instance in use (it may be any of several): the next process connects to it again, where the
|
|
1061
|
+
// tab ids in the conversation are still its tabs'
|
|
1062
1062
|
browser: browserSession.preferred || null,
|
|
1063
1063
|
sessionId: this.store.id,
|
|
1064
1064
|
sessionFile: moved?.file || this.store.file,
|