cdpm-mcp 0.1.4 → 0.1.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/CHANGELOG.md +18 -0
- package/README.ko.md +276 -273
- package/README.md +199 -196
- package/dist/agent-setup.js +18 -15
- package/dist/auto-setup.js +1 -1
- package/dist/cdp/client.js +7 -7
- package/dist/cdp/downloads.js +4 -4
- package/dist/cdp/sessions.js +7 -7
- package/dist/cdp/targets.js +1 -1
- package/dist/chrome/bubbles.js +108 -0
- package/dist/chrome/finder.js +2 -2
- package/dist/chrome/launcher.js +5 -5
- package/dist/chrome/proxy.js +4 -4
- package/dist/claude-md-setup.js +20 -16
- package/dist/cli.js +1 -1
- package/dist/orphan.js +3 -3
- package/dist/page/actions.js +105 -105
- package/dist/page/snapshot.js +1 -1
- package/dist/pause.js +10 -11
- package/dist/proxy-forwarder.js +8 -8
- package/dist/registry/lock.js +2 -2
- package/dist/service.js +13 -13
- package/dist/slots.js +1 -1
- package/dist/statusline.js +27 -11
- package/dist/taskbar/win32.js +29 -0
- package/dist/tools/format.js +12 -12
- package/dist/tools/read.js +10 -10
- package/dist/tools/register.js +362 -298
- package/dist/util.js +5 -5
- package/package.json +64 -64
package/dist/cdp/client.js
CHANGED
|
@@ -22,7 +22,7 @@ export class CdpConnection {
|
|
|
22
22
|
const ws = new WebSocket(url);
|
|
23
23
|
const timer = setTimeout(() => {
|
|
24
24
|
ws.close();
|
|
25
|
-
reject(new CdpmError(`CDP
|
|
25
|
+
reject(new CdpmError(`CDP connect timed out: ${url}`));
|
|
26
26
|
}, timeoutMs);
|
|
27
27
|
ws.addEventListener('open', () => {
|
|
28
28
|
clearTimeout(timer);
|
|
@@ -30,19 +30,19 @@ export class CdpConnection {
|
|
|
30
30
|
}, { once: true });
|
|
31
31
|
ws.addEventListener('error', () => {
|
|
32
32
|
clearTimeout(timer);
|
|
33
|
-
reject(new CdpmError(`CDP
|
|
33
|
+
reject(new CdpmError(`CDP connect failed: ${url}`));
|
|
34
34
|
}, { once: true });
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
send(method, params = {}, timeoutMs = 30_000, sessionId) {
|
|
38
38
|
if (this.closed)
|
|
39
|
-
return Promise.reject(new CdpmError(`CDP
|
|
39
|
+
return Promise.reject(new CdpmError(`CDP connection closed (${method}).`));
|
|
40
40
|
const id = this.nextId++;
|
|
41
41
|
return new Promise((resolve, reject) => {
|
|
42
42
|
const timer = setTimeout(() => {
|
|
43
43
|
this.pending.delete(id);
|
|
44
|
-
reject(new CdpTimeoutError(`Chrome
|
|
45
|
-
'
|
|
44
|
+
reject(new CdpTimeoutError(`Chrome did not respond for ${Math.round(timeoutMs / 1000)}s (${method}). ` +
|
|
45
|
+
'The page may be heavy, the network slow, or a dialog open. Retry shortly or check with browser_tabs.'));
|
|
46
46
|
}, timeoutMs);
|
|
47
47
|
this.pending.set(id, { resolve, reject, timer, method });
|
|
48
48
|
this.ws.send(JSON.stringify({ id, method, params, ...(sessionId ? { sessionId } : {}) }));
|
|
@@ -106,7 +106,7 @@ export class CdpConnection {
|
|
|
106
106
|
this.pending.delete(msg.id);
|
|
107
107
|
clearTimeout(p.timer);
|
|
108
108
|
if (msg.error)
|
|
109
|
-
p.reject(new CdpmError(`${p.method}
|
|
109
|
+
p.reject(new CdpmError(`${p.method} failed: ${msg.error.message}`));
|
|
110
110
|
else
|
|
111
111
|
p.resolve(msg.result);
|
|
112
112
|
return;
|
|
@@ -139,7 +139,7 @@ export class CdpConnection {
|
|
|
139
139
|
this.closed = true;
|
|
140
140
|
for (const [, p] of this.pending) {
|
|
141
141
|
clearTimeout(p.timer);
|
|
142
|
-
p.reject(new CdpmError(`CDP
|
|
142
|
+
p.reject(new CdpmError(`CDP connection closed (${p.method}). The tab or Chrome may have closed.`));
|
|
143
143
|
}
|
|
144
144
|
this.pending.clear();
|
|
145
145
|
for (const h of this.closedHandlers)
|
package/dist/cdp/downloads.js
CHANGED
|
@@ -52,17 +52,17 @@ export async function waitDownload(slot, timeoutSec, stop) {
|
|
|
52
52
|
if (d && d.state !== 'inProgress') {
|
|
53
53
|
d.reported = true;
|
|
54
54
|
if (d.state === 'canceled')
|
|
55
|
-
return
|
|
55
|
+
return `Download canceled: ${d.file}`;
|
|
56
56
|
const size = d.totalBytes || d.receivedBytes;
|
|
57
|
-
return
|
|
57
|
+
return `Download finished: ${d.filePath ?? d.file}${size ? ` (${(size / 1024).toFixed(1)}KB)` : ''}`;
|
|
58
58
|
}
|
|
59
59
|
const why = stop?.();
|
|
60
60
|
if (why)
|
|
61
61
|
return why;
|
|
62
62
|
if (Date.now() > until) {
|
|
63
63
|
if (d)
|
|
64
|
-
return
|
|
65
|
-
throw new Error('
|
|
64
|
+
return `Download not finished after ${timeoutSec}s: ${d.file} (${d.receivedBytes}/${d.totalBytes || '?'} bytes). Call again to keep waiting.`;
|
|
65
|
+
throw new Error('No download in progress or recently started. Call this after clicking the download button.');
|
|
66
66
|
}
|
|
67
67
|
await new Promise((r) => setTimeout(r, 100));
|
|
68
68
|
}
|
package/dist/cdp/sessions.js
CHANGED
|
@@ -78,7 +78,7 @@ export class PageSession {
|
|
|
78
78
|
* 잠금을 잡은 프로세스가 죽으면 바로 풀린다. 다른 세션의 조작이 2분 넘게 끝나지 않으면 기다리지 않고 알린다.
|
|
79
79
|
*/
|
|
80
80
|
exclusive(fn) {
|
|
81
|
-
const locked = () => withFileLock(paths.tabLock(this.slot, this.targetId), fn, TAB_LOCK_WAIT_MS, '
|
|
81
|
+
const locked = () => withFileLock(paths.tabLock(this.slot, this.targetId), fn, TAB_LOCK_WAIT_MS, 'Another Claude session has been using this tab for over 2 min. Ask it via slot_send or use your own tab (browser_tab_new).');
|
|
82
82
|
const run = this.chain.then(locked, locked);
|
|
83
83
|
this.chain = run.then(() => undefined, () => undefined);
|
|
84
84
|
return run;
|
|
@@ -288,11 +288,11 @@ export class PageSession {
|
|
|
288
288
|
/** 붙을 때 탭이 아직 답하지 않음 (알림창이 떠 있거나 무거운 작업 중). 응답이 오면 자동으로 풀린다. */
|
|
289
289
|
markUnresponsive() {
|
|
290
290
|
this.pendingEnable = true;
|
|
291
|
-
this.dialog ??= { type: '
|
|
291
|
+
this.dialog ??= { type: 'unresponsive', message: 'Tab not responding yet (dialog open or busy)', at: new Date().toISOString() };
|
|
292
292
|
}
|
|
293
293
|
/** 붙을 때 보낸 Page.enable이 나중에라도 끝나면: 탭이 다시 움직인다는 신호 */
|
|
294
294
|
enabledLater() {
|
|
295
|
-
if (this.dialog?.type === '
|
|
295
|
+
if (this.dialog?.type === 'unresponsive')
|
|
296
296
|
this.dialog = undefined;
|
|
297
297
|
if (this.pendingEnable) {
|
|
298
298
|
this.pendingEnable = false;
|
|
@@ -301,8 +301,8 @@ export class PageSession {
|
|
|
301
301
|
}
|
|
302
302
|
assertNoDialog() {
|
|
303
303
|
if (this.dialog) {
|
|
304
|
-
throw new CdpmError(
|
|
305
|
-
'
|
|
304
|
+
throw new CdpmError(`A ${this.dialog.type} dialog is open on this tab: "${this.dialog.message}"\n` +
|
|
305
|
+
'Read it and handle it yourself with browser_dialog (accept: true = OK, false = cancel). Ask the user only if it confirms something irreversible they did not request (payment, deletion, etc.).');
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
308
|
}
|
|
@@ -385,7 +385,7 @@ export async function browserConnection(slot) {
|
|
|
385
385
|
return cached;
|
|
386
386
|
const p = await probe(slot);
|
|
387
387
|
if (p.state !== 'chrome')
|
|
388
|
-
throw new CdpmError(
|
|
388
|
+
throw new CdpmError(`Chrome is not running on slot ${slot} (port ${portOf(slot)}).`);
|
|
389
389
|
const conn = await CdpConnection.connect(p.version.webSocketDebuggerUrl);
|
|
390
390
|
conn.onClosed(() => browserConns.delete(slot));
|
|
391
391
|
browserConns.set(slot, conn);
|
|
@@ -409,7 +409,7 @@ export async function pageSession(slot, targetId, wsUrl) {
|
|
|
409
409
|
url = t?.webSocketDebuggerUrl;
|
|
410
410
|
}
|
|
411
411
|
if (!url)
|
|
412
|
-
throw new CdpmError('
|
|
412
|
+
throw new CdpmError('Tab not found (it may have been closed).');
|
|
413
413
|
const conn = await CdpConnection.connect(url);
|
|
414
414
|
const session = new PageSession(slot, targetId, conn);
|
|
415
415
|
conn.onClosed(() => pageSessions.delete(key));
|
package/dist/cdp/targets.js
CHANGED
|
@@ -21,7 +21,7 @@ export async function probe(slot, timeoutMs = 1500) {
|
|
|
21
21
|
return { state: 'other', detail: `HTTP ${res.status}` };
|
|
22
22
|
}
|
|
23
23
|
catch {
|
|
24
|
-
return { state: 'other', detail: `HTTP ${res.status} (JSON
|
|
24
|
+
return { state: 'other', detail: `HTTP ${res.status} (not JSON)` };
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
/** 탭(page) 목록. Chrome이 돌려주는 순서 그대로 (첫 번째가 가장 최근 활성 탭). */
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Windows 전용: Chrome이 띄운 권한 요청 말풍선("○○에서 다음 권한을 요청합니다" 등)을 찾고 버튼을 누른다.
|
|
2
|
+
// 말풍선은 페이지가 아니라 브라우저 화면이라 CDP(스냅샷·스크린샷·클릭)로는 보이지도 눌리지도 않고,
|
|
3
|
+
// 이미 뜬 말풍선은 CDP로 권한을 줘도 닫히지 않는다 (실측). 그래서
|
|
4
|
+
// - 찾기: Chrome 본 창에 딸린 작은 창 중 제목에 탭의 사이트 주소가 들어간 것 (EnumWindows, 1ms 미만).
|
|
5
|
+
// 번역·비밀번호 저장 말풍선은 제목에 주소가 없어서 걸러지고, Chrome 표시 언어와도 상관없다.
|
|
6
|
+
// - 버튼 읽기·누르기: Windows UI Automation (PowerShell, 말풍선이 있을 때만 부른다).
|
|
7
|
+
// 창이 최소화돼 있거나 다른 창에 가려져 있어도 읽고 누를 수 있다 (실측).
|
|
8
|
+
import { execFile } from 'node:child_process';
|
|
9
|
+
import { readRegistry } from '../registry/store.js';
|
|
10
|
+
import { win32 } from '../taskbar/win32.js';
|
|
11
|
+
/** 탭 주소들에서 말풍선 제목과 맞춰 볼 호스트 이름을 뽑는다. */
|
|
12
|
+
export function hostsOf(urls) {
|
|
13
|
+
const hosts = new Set();
|
|
14
|
+
for (const u of urls) {
|
|
15
|
+
try {
|
|
16
|
+
const h = new URL(u).hostname;
|
|
17
|
+
if (h)
|
|
18
|
+
hosts.add(h);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// about:blank 등
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return [...hosts];
|
|
25
|
+
}
|
|
26
|
+
/** 슬롯 Chrome에 떠 있는 권한 요청 말풍선. Windows가 아니거나 창 모드가 아니면 늘 빈 목록. */
|
|
27
|
+
export function permissionBubbles(slot, hosts) {
|
|
28
|
+
const w = win32();
|
|
29
|
+
if (!w || !hosts.length)
|
|
30
|
+
return [];
|
|
31
|
+
const pid = readRegistry().slots[String(slot)]?.pid;
|
|
32
|
+
if (!pid)
|
|
33
|
+
return [];
|
|
34
|
+
try {
|
|
35
|
+
return w.ownedWindowsOf(pid)
|
|
36
|
+
.filter((x) => (x.visible || x.ownerMinimized) && hosts.some((h) => x.title.includes(h)))
|
|
37
|
+
.map((x) => ({ key: x.key, title: x.title, hwnd: x.hwnd }));
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const UIA_SCRIPT = `
|
|
44
|
+
$OutputEncoding = [Console]::OutputEncoding = [Text.Encoding]::UTF8
|
|
45
|
+
Add-Type -AssemblyName UIAutomationClient, UIAutomationTypes
|
|
46
|
+
$A = [Windows.Automation.AutomationElement]
|
|
47
|
+
$e = $A::FromHandle([IntPtr][long]$env:CDPM_BUBBLE_HWND)
|
|
48
|
+
$type = { param($t) New-Object Windows.Automation.PropertyCondition($A::ControlTypeProperty, $t) }
|
|
49
|
+
$btns = @($e.FindAll('Descendants', (& $type ([Windows.Automation.ControlType]::Button))))
|
|
50
|
+
$texts = @($e.FindAll('Descendants', (& $type ([Windows.Automation.ControlType]::Text))) | ForEach-Object { $_.Current.Name } | Where-Object { $_ })
|
|
51
|
+
$pressed = $null
|
|
52
|
+
if ($env:CDPM_BUBBLE_PRESS) {
|
|
53
|
+
$b = $btns | Where-Object { $_.Current.Name -eq $env:CDPM_BUBBLE_PRESS } | Select-Object -First 1
|
|
54
|
+
if ($b) { $b.GetCurrentPattern([Windows.Automation.InvokePattern]::Pattern).Invoke(); $pressed = $true } else { $pressed = $false }
|
|
55
|
+
}
|
|
56
|
+
@{ texts = @($texts); buttons = @($btns | ForEach-Object { $_.Current.Name } | Where-Object { $_ }); pressed = $pressed } | ConvertTo-Json -Compress
|
|
57
|
+
`;
|
|
58
|
+
const ENCODED = Buffer.from(UIA_SCRIPT, 'utf16le').toString('base64');
|
|
59
|
+
function runUia(b, press) {
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
execFile('powershell.exe', ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-EncodedCommand', ENCODED], {
|
|
62
|
+
env: { ...process.env, CDPM_BUBBLE_HWND: b.key, CDPM_BUBBLE_PRESS: press ?? '' },
|
|
63
|
+
timeout: 15_000, windowsHide: true, encoding: 'utf8',
|
|
64
|
+
}, (err, stdout) => {
|
|
65
|
+
if (err)
|
|
66
|
+
return reject(err);
|
|
67
|
+
try {
|
|
68
|
+
const j = JSON.parse(stdout.trim().split('\n').pop() ?? '');
|
|
69
|
+
const arr = (v) => (Array.isArray(v) ? v : v ? [v] : []).map(String);
|
|
70
|
+
resolve({ texts: arr(j.texts), buttons: arr(j.buttons), pressed: typeof j.pressed === 'boolean' ? j.pressed : null });
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
reject(e);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/** 같은 말풍선을 매번 다시 읽지 않게 (말풍선 하나에 PowerShell 한 번, 약 0.6초). */
|
|
79
|
+
const details = new Map();
|
|
80
|
+
export async function bubbleDetail(b) {
|
|
81
|
+
const k = `${b.key}|${b.title}`;
|
|
82
|
+
const hit = details.get(k);
|
|
83
|
+
if (hit)
|
|
84
|
+
return hit;
|
|
85
|
+
try {
|
|
86
|
+
const d = await runUia(b);
|
|
87
|
+
if (details.size > 50)
|
|
88
|
+
details.clear();
|
|
89
|
+
details.set(k, { texts: d.texts, buttons: d.buttons });
|
|
90
|
+
return details.get(k);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** 말풍선의 버튼을 이름 그대로 누른다. 없는 이름이면 false. */
|
|
97
|
+
export async function pressBubble(b, button) {
|
|
98
|
+
const r = await runUia(b, button);
|
|
99
|
+
details.delete(`${b.key}|${b.title}`);
|
|
100
|
+
return r.pressed === true;
|
|
101
|
+
}
|
|
102
|
+
/** 머리말·기다리기에 쓰는 한 줄 안내. */
|
|
103
|
+
export function bubbleLine(b, d) {
|
|
104
|
+
const what = d?.texts.filter((t) => t !== b.title).join(' / ');
|
|
105
|
+
const buttons = d?.buttons.length ? ` Buttons: ${d.buttons.join(', ')}.` : '';
|
|
106
|
+
return `Chrome permission bubble open: "${b.title}"${what ? ` (${what})` : ''}.${buttons} ` +
|
|
107
|
+
'It is browser UI (not in snapshot/screenshot; page tools can\'t click it) and the page may be stuck until it is answered. Press a button with browser_permission.';
|
|
108
|
+
}
|
package/dist/chrome/finder.js
CHANGED
|
@@ -41,9 +41,9 @@ export function findChromeWith(deps) {
|
|
|
41
41
|
const found = candidates.find((p) => deps.exists(p));
|
|
42
42
|
if (found)
|
|
43
43
|
return found;
|
|
44
|
-
throw new CdpmError('Chrome
|
|
44
|
+
throw new CdpmError('Chrome not found. Searched:\n' +
|
|
45
45
|
candidates.map((c) => ` - ${c}`).join('\n') +
|
|
46
|
-
`\
|
|
46
|
+
`\nSet it manually in ${paths.config()}: {"chromePath": "<full path to Chrome executable>"}`);
|
|
47
47
|
}
|
|
48
48
|
function regQuery(key) {
|
|
49
49
|
try {
|
package/dist/chrome/launcher.js
CHANGED
|
@@ -32,7 +32,7 @@ export async function launchChrome(slot, opts = {}) {
|
|
|
32
32
|
({ pid } = await spawnOrphan(chrome, [...chromeArgs(slot, opts), ...extra, opts.url || 'about:blank'], { hide: false }));
|
|
33
33
|
}
|
|
34
34
|
catch (e) {
|
|
35
|
-
throw new CdpmError(`
|
|
35
|
+
throw new CdpmError(`Failed to launch Chrome: ${e.message}`);
|
|
36
36
|
}
|
|
37
37
|
const deadline = Date.now() + READY_TIMEOUT_MS;
|
|
38
38
|
while (Date.now() < deadline) {
|
|
@@ -40,11 +40,11 @@ export async function launchChrome(slot, opts = {}) {
|
|
|
40
40
|
if (p.state === 'chrome')
|
|
41
41
|
return { pid, version: p.version };
|
|
42
42
|
if (!pidAlive(pid)) {
|
|
43
|
-
throw new CdpmError(
|
|
44
|
-
|
|
43
|
+
throw new CdpmError(`Slot ${slot} Chrome exited right after launch. ` +
|
|
44
|
+
`If a Chrome using the same profile (${paths.profile(slot)}) is already running without a debugging port, the new one hands its window over and exits. Close that window and launch again.`);
|
|
45
45
|
}
|
|
46
46
|
await sleep(100);
|
|
47
47
|
}
|
|
48
|
-
throw new CdpmError(
|
|
49
|
-
|
|
48
|
+
throw new CdpmError(`Slot ${slot} Chrome started, but CDP port ${portOf(slot)} did not open within ${READY_TIMEOUT_MS / 1000}s. ` +
|
|
49
|
+
`A Chrome using the same profile (${paths.profile(slot)}) may already be running without a debugging port. Close it and try again.`);
|
|
50
50
|
}
|
package/dist/chrome/proxy.js
CHANGED
|
@@ -12,13 +12,13 @@ const SCHEMES = { http: 'http', https: 'https', socks: 'socks5', socks5: 'socks5
|
|
|
12
12
|
*/
|
|
13
13
|
export function parseProxy(input) {
|
|
14
14
|
let s = input.trim();
|
|
15
|
-
const bad = () => new CdpmError(
|
|
15
|
+
const bad = () => new CdpmError(`Unrecognized proxy: "${maskProxyText(input)}". Examples: 1.2.3.4:8080, http://user:pass@1.2.3.4:8080, socks5://1.2.3.4:1080, 1.2.3.4:8080:user:pass`);
|
|
16
16
|
let scheme = 'http';
|
|
17
17
|
const m = /^([a-z0-9]+):\/\//i.exec(s);
|
|
18
18
|
if (m) {
|
|
19
19
|
const sc = SCHEMES[m[1].toLowerCase()];
|
|
20
20
|
if (!sc)
|
|
21
|
-
throw new CdpmError(
|
|
21
|
+
throw new CdpmError(`Unsupported proxy scheme: ${m[1]} (use http, https, socks5 or socks4)`);
|
|
22
22
|
scheme = sc;
|
|
23
23
|
s = s.slice(m[0].length);
|
|
24
24
|
}
|
|
@@ -60,7 +60,7 @@ export function parseProxy(input) {
|
|
|
60
60
|
user = dec(user);
|
|
61
61
|
pass = dec(pass);
|
|
62
62
|
if (user && scheme === 'socks4')
|
|
63
|
-
throw new CdpmError('socks4
|
|
63
|
+
throw new CdpmError('socks4 proxies do not support username/password. Use socks5 or http.');
|
|
64
64
|
return { scheme, host: hp[1], port, ...(user ? { user, pass: pass ?? '' } : {}) };
|
|
65
65
|
}
|
|
66
66
|
/** 결과에 보여 줄 때: 비밀번호는 가린다. */
|
|
@@ -92,6 +92,6 @@ async function startForwarder(slot, p) {
|
|
|
92
92
|
return Number(/LISTEN (\d+)/.exec(line ?? '')?.[1]);
|
|
93
93
|
}
|
|
94
94
|
catch (e) {
|
|
95
|
-
throw new CdpmError(
|
|
95
|
+
throw new CdpmError(`Failed to start proxy forwarder: ${e.message}`);
|
|
96
96
|
}
|
|
97
97
|
}
|
package/dist/claude-md-setup.js
CHANGED
|
@@ -7,23 +7,27 @@ import path from 'node:path';
|
|
|
7
7
|
const START = '<!-- CDPM:START (cdpm setup이 관리하는 부분) -->';
|
|
8
8
|
const END = '<!-- CDPM:END -->';
|
|
9
9
|
export const CDPM_RULES = `${START}
|
|
10
|
-
## CDPM (Chrome
|
|
10
|
+
## CDPM (Chrome slot MCP) rules
|
|
11
11
|
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
12
|
+
- Reply to the user in the user's language.
|
|
13
|
+
- When telling the user about slot work, always name the tab too, not just the slot: e.g. "working in slot 1, tab 3 [t7]".
|
|
14
|
+
- Roles (always, for any job using multiple slots or tabs, on any site):
|
|
15
|
+
- Main: talks to the user, launches/closes slots, hands work to subagents, merges and reports results. Never navigates, reads or acts on slot screens itself.
|
|
16
|
+
- Subagent (cdpm-browser): everything on its one slot: navigation, reading, typing, clicking, detecting login completion, its own part of the output, and signaling other subagents when needed.
|
|
17
|
+
- A simple job on a single slot can be done by the main agent directly.
|
|
18
|
+
- Windowed (visible) vs headless is the user's call: headless: true only if the user says "headless", "hidden", "no window"; false for "show the window", "headful" (in any language). If unspecified, don't guess; ask first (once for multiple slots).
|
|
19
|
+
- When several CDPM slots get different jobs (e.g. "open 5, one for Naver, one for YouTube...", "log in on slot 1 and open another site on slot 2"), the main agent does not do them itself.
|
|
20
|
+
1. Launch all slots with one browser_launch (slots or count). If start pages are known, open them at launch with url/urls. The main agent stops there; subagents do all navigation, reading and actions from the start.
|
|
21
|
+
2. In one message, call the Agent tool once per slot to start all subagents together, each with run_in_background: true (don't wait for one to finish). Use subagent_type "cdpm-browser" (CDPM-only, starts fast).
|
|
22
|
+
- Keep instructions to 1-3 lines: slot number, agent name (e.g. "naver"), task. cdpm-browser already knows CDPM usage and rules; don't repeat them (long instructions only add delay).
|
|
23
|
+
- At most 20 subagents run at once. With more than 20 slots, start 20 first and the rest as they finish (raise via env CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS).
|
|
24
|
+
3. Each subagent writes and returns its own part of the output (report, HTML fragment, table, etc.); the main agent only merges.
|
|
25
|
+
- If tabs within one slot get different jobs (e.g. "slot 1 first tab logs in, second tab does X on another site"), assign one subagent per tab just like slots (the main agent doesn't switch tabs doing them in turn). Each uses only its assigned tab number or opens its own with browser_tab_new, with a distinct agent name per tab (e.g. "slot1-tab1"). Same slot, so the one-agent-one-slot rule doesn't apply; actions queue per tab and run concurrently. If a tab's job depends on another finishing first (e.g. needs login), the dependent owner waits with slot_inbox(wait) and the other notifies with slot_send as soon as done (login carries over to other tabs since they share the profile).
|
|
26
|
+
- One agent acts on one slot only (CDPM rejects actions on another slot; viewing other slots is fine).
|
|
27
|
+
- When the user must log in, verify identity, solve a CAPTCHA, etc. on any site, never ask them to say when done. Start the subagents first and have each detect completion with browser_wait url/gone/text without touching the screen (no reload), then continue.
|
|
28
|
+
- Waits that may take minutes (bulk collection/processing, waiting for user login, etc.) are not done by the main agent: hand them to a background subagent (run_in_background: true), tell the user the current status right away and keep talking. While the main agent blocks on browser_wait or a long foreground shell command, it can't answer the user.
|
|
29
|
+
- Keep waiting minimal. When subagents collaborate (e.g. exchanging emails), each notifies the other with slot_send as soon as its part is done and waits with slot_inbox wait (no repeated screen refreshes). Never instruct subagents to use long fixed waits.
|
|
30
|
+
- When you need the screen, add read to the action tool to get it in one call (text for content, snapshot when you need things to click, changes to see only what changed).
|
|
27
31
|
${END}`;
|
|
28
32
|
export function claudeMdPath() {
|
|
29
33
|
const dir = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude');
|
package/dist/cli.js
CHANGED
package/dist/orphan.js
CHANGED
|
@@ -36,14 +36,14 @@ export function spawnOrphan(cmd, args, opts = {}) {
|
|
|
36
36
|
});
|
|
37
37
|
let out = '';
|
|
38
38
|
bridge.stdout.on('data', (d) => (out += String(d)));
|
|
39
|
-
bridge.on('error', (e) => reject(new CdpmError(
|
|
39
|
+
bridge.on('error', (e) => reject(new CdpmError(`Failed to start: ${e.message}`)));
|
|
40
40
|
bridge.on('exit', () => {
|
|
41
41
|
const pid = Number(/PID (\d+)/.exec(out)?.[1]);
|
|
42
42
|
const line = /LINE (.*)/.exec(out)?.[1];
|
|
43
43
|
if (pid && (!opts.waitLine || line))
|
|
44
44
|
return resolve({ pid, line });
|
|
45
|
-
const why = /ERR (.*)/.exec(out)?.[1] ?? (/EXIT (.*)/.exec(out) ?
|
|
46
|
-
reject(new CdpmError(
|
|
45
|
+
const why = /ERR (.*)/.exec(out)?.[1] ?? (/EXIT (.*)/.exec(out) ? `exited immediately (code ${/EXIT (.*)/.exec(out)[1]})` : /TIMEOUT/.test(out) ? 'no ready signal' : out.trim());
|
|
46
|
+
reject(new CdpmError(`Failed to start: ${why}`));
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
49
|
}
|