cdpm-mcp 0.1.9 → 0.1.12
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 +131 -94
- package/README.ko.md +326 -324
- package/README.md +249 -247
- package/dist/agent-setup.js +23 -23
- package/dist/cdp/client.js +13 -9
- package/dist/cdp/downloads.js +4 -1
- package/dist/cdp/sessions.js +45 -24
- package/dist/cdp/targets.js +12 -1
- package/dist/chrome/bubbles.js +14 -14
- package/dist/chrome/launcher.js +3 -0
- package/dist/claude-md-setup.js +22 -22
- package/dist/cli.js +6 -4
- package/dist/page/actions.js +248 -143
- package/dist/page/keys.js +1 -1
- package/dist/page/snapshot.js +11 -5
- package/dist/proxy-forwarder.js +17 -11
- package/dist/registry/lock.js +47 -4
- package/dist/registry/messages.js +28 -13
- package/dist/registry/store.js +19 -7
- package/dist/service.js +5 -5
- package/dist/taskbar/dock.js +31 -31
- package/dist/taskbar/icon-gdi.js +158 -158
- package/dist/taskbar/watcher.js +4 -0
- package/dist/tools/register.js +105 -73
- package/package.json +65 -65
package/dist/agent-setup.js
CHANGED
|
@@ -41,29 +41,29 @@ export function registeredNames(configFile = process.env.CLAUDE_CONFIG_DIR ? pat
|
|
|
41
41
|
}
|
|
42
42
|
export function agentFile(names) {
|
|
43
43
|
const tools = [...names.flatMap((n) => AGENT_TOOLS.map((t) => `mcp__${n}__${t}`)), 'Write'];
|
|
44
|
-
return `---
|
|
45
|
-
name: cdpm-browser
|
|
46
|
-
description: Subagent that owns one CDPM browser slot and navigates, reads, clicks and types in it. When several CDPM slots get different jobs, start one per slot, all in a single message.
|
|
47
|
-
tools: ${tools.join(', ')}
|
|
48
|
-
omitClaudeMd: true
|
|
49
|
-
---
|
|
50
|
-
${MARK}
|
|
51
|
-
You own one CDPM browser slot. The main agent talks to the user, launches slots, hands out work and merges results; everything on this slot's screen is yours.
|
|
52
|
-
Instructions from the main agent are short (slot number, your agent name, the task). Work out the rest from these rules and act right away.
|
|
53
|
-
- Report back in the language the main agent/user uses. In the report, name the slot and the tab you worked in (e.g. "slot 1, tab 3 [t7]"), not just the slot.
|
|
54
|
-
- Pass your slot number and agent name to every CDPM tool. Never touch other slots.
|
|
55
|
-
- If assigned a specific tab, pass that tab to every tool and leave other tabs alone. If told to use a new tab, open one with browser_tab_new and use its ID. If your work depends on another tab's owner finishing first, wait for their signal with slot_inbox(wait); when your own work is done, notify whoever is waiting with slot_send immediately.
|
|
56
|
-
- 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).
|
|
57
|
-
- Fill multiple fields on the same page with a single browser_fill.
|
|
58
|
-
- Do your own navigation (the main agent only launches the slot). If the start page is already open from launch, start there without navigating again (check first with browser_snapshot interactive=true).
|
|
59
|
-
- Keep waiting to a minimum; never use fixed-time sleeps. For jobs that take minutes (e.g. bulk collection), check progress briefly now and then and return results as soon as it finishes. To wait for a button to enable, use browser_wait enabled. For pages that load data in the background (search results, lists), click and then use browser_wait response (URL fragment) to get the response JSON directly instead of reading the screen.
|
|
60
|
-
- When the user must log in, verify identity, solve a CAPTCHA, etc. on any site, never ask them to tell you when done. Leave the screen alone (no reload or re-navigation: it wipes their input) and detect completion with browser_wait url (URL change) / gone (login form text disappears) / text (text shown only after login), then continue.
|
|
61
|
-
- When working with other agents, signal in real time: as soon as your part is done, notify them with slot_send(slot=their slot, to=their name); when waiting on them, don't keep refreshing the screen, use slot_inbox(slot=your slot, wait=120-600) (returns as soon as a message arrives). Act on signals immediately.
|
|
62
|
-
- If the user pauses the slot, actions are rejected with a pause notice. Then stop acting and wait with slot_inbox(slot=your slot, wait=600); on the resume message, re-read the screen with browser_snapshot and continue. Never resume on your own.
|
|
63
|
-
- To see another slot's screen, use read-only tools (browser_snapshot, browser_text) on it directly (no actions).
|
|
64
|
-
- When a dialog appears, normally read it and accept/dismiss it yourself with browser_dialog. Only if it confirms something irreversible outside your task (payment, deletion, etc.), leave it and report to the main agent.
|
|
65
|
-
- If the header warns about a Chrome permission bubble (browser UI, not in snapshots), the page may be waiting on it: answer it with browser_permission when your task needs it (e.g. a work site reaching a local app). Don't allow camera, microphone or location the user didn't ask for; report to the main agent instead.
|
|
66
|
-
- Return only your own requested part of the output (report, HTML fragment, table, etc.), briefly. If asked for a file, write it to that path.
|
|
44
|
+
return `---
|
|
45
|
+
name: cdpm-browser
|
|
46
|
+
description: Subagent that owns one CDPM browser slot and navigates, reads, clicks and types in it. When several CDPM slots get different jobs, start one per slot, all in a single message.
|
|
47
|
+
tools: ${tools.join(', ')}
|
|
48
|
+
omitClaudeMd: true
|
|
49
|
+
---
|
|
50
|
+
${MARK}
|
|
51
|
+
You own one CDPM browser slot. The main agent talks to the user, launches slots, hands out work and merges results; everything on this slot's screen is yours.
|
|
52
|
+
Instructions from the main agent are short (slot number, your agent name, the task). Work out the rest from these rules and act right away.
|
|
53
|
+
- Report back in the language the main agent/user uses. In the report, name the slot and the tab you worked in (e.g. "slot 1, tab 3 [t7]"), not just the slot.
|
|
54
|
+
- Pass your slot number and agent name to every CDPM tool. Never touch other slots.
|
|
55
|
+
- If assigned a specific tab, pass that tab to every tool and leave other tabs alone. If told to use a new tab, open one with browser_tab_new and use its ID. If your work depends on another tab's owner finishing first, wait for their signal with slot_inbox(wait); when your own work is done, notify whoever is waiting with slot_send immediately.
|
|
56
|
+
- 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).
|
|
57
|
+
- Fill multiple fields on the same page with a single browser_fill.
|
|
58
|
+
- Do your own navigation (the main agent only launches the slot). If the start page is already open from launch, start there without navigating again (check first with browser_snapshot interactive=true).
|
|
59
|
+
- Keep waiting to a minimum; never use fixed-time sleeps. For jobs that take minutes (e.g. bulk collection), check progress briefly now and then and return results as soon as it finishes. To wait for a button to enable, use browser_wait enabled. For pages that load data in the background (search results, lists), click and then use browser_wait response (URL fragment) to get the response JSON directly instead of reading the screen.
|
|
60
|
+
- When the user must log in, verify identity, solve a CAPTCHA, etc. on any site, never ask them to tell you when done. Leave the screen alone (no reload or re-navigation: it wipes their input) and detect completion with browser_wait url (URL change) / gone (login form text disappears) / text (text shown only after login), then continue.
|
|
61
|
+
- When working with other agents, signal in real time: as soon as your part is done, notify them with slot_send(slot=their slot, to=their name); when waiting on them, don't keep refreshing the screen, use slot_inbox(slot=your slot, wait=120-600) (returns as soon as a message arrives). Act on signals immediately.
|
|
62
|
+
- If the user pauses the slot, actions are rejected with a pause notice. Then stop acting and wait with slot_inbox(slot=your slot, wait=600); on the resume message, re-read the screen with browser_snapshot and continue. Never resume on your own.
|
|
63
|
+
- To see another slot's screen, use read-only tools (browser_snapshot, browser_text) on it directly (no actions).
|
|
64
|
+
- When a dialog appears, normally read it and accept/dismiss it yourself with browser_dialog. Only if it confirms something irreversible outside your task (payment, deletion, etc.), leave it and report to the main agent.
|
|
65
|
+
- If the header warns about a Chrome permission bubble (browser UI, not in snapshots), the page may be waiting on it: answer it with browser_permission when your task needs it (e.g. a work site reaching a local app). Don't allow camera, microphone or location the user didn't ask for; report to the main agent instead.
|
|
66
|
+
- Return only your own requested part of the output (report, HTML fragment, table, etc.), briefly. If asked for a file, write it to that path.
|
|
67
67
|
`;
|
|
68
68
|
}
|
|
69
69
|
/** 설치(또는 최신으로 갱신). 사용자가 직접 만든 같은 이름의 파일은 건드리지 않는다. */
|
package/dist/cdp/client.js
CHANGED
|
@@ -65,21 +65,25 @@ export class CdpConnection {
|
|
|
65
65
|
}
|
|
66
66
|
onClosed(handler) {
|
|
67
67
|
this.closedHandlers.add(handler);
|
|
68
|
+
return () => this.closedHandlers.delete(handler);
|
|
68
69
|
}
|
|
69
|
-
/** 조건에 맞는 이벤트를 기다린다. 시간 안에 안
|
|
70
|
+
/** 조건에 맞는 이벤트를 기다린다. 시간 안에 안 오거나 연결이 닫히면 null. */
|
|
70
71
|
waitFor(event, predicate = () => true, timeoutMs = 30_000) {
|
|
72
|
+
if (this.closed)
|
|
73
|
+
return Promise.resolve(null);
|
|
71
74
|
return new Promise((resolve) => {
|
|
72
|
-
const
|
|
73
|
-
if (!predicate(p))
|
|
74
|
-
return;
|
|
75
|
+
const done = (v) => {
|
|
75
76
|
clearTimeout(timer);
|
|
76
77
|
off();
|
|
77
|
-
|
|
78
|
+
offClosed();
|
|
79
|
+
resolve(v);
|
|
80
|
+
};
|
|
81
|
+
const off = this.on(event, (p) => {
|
|
82
|
+
if (predicate(p))
|
|
83
|
+
done(p);
|
|
78
84
|
});
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
resolve(null);
|
|
82
|
-
}, timeoutMs);
|
|
85
|
+
const offClosed = this.onClosed(() => done(null));
|
|
86
|
+
const timer = setTimeout(() => done(null), timeoutMs);
|
|
83
87
|
});
|
|
84
88
|
}
|
|
85
89
|
close() {
|
package/dist/cdp/downloads.js
CHANGED
|
@@ -28,7 +28,10 @@ export async function ensureDownloadTracking(slot) {
|
|
|
28
28
|
if (p.filePath)
|
|
29
29
|
d.filePath = p.filePath;
|
|
30
30
|
});
|
|
31
|
-
conn.onClosed(() =>
|
|
31
|
+
conn.onClosed(() => {
|
|
32
|
+
if (tracking.get(slot) === conn)
|
|
33
|
+
tracking.delete(slot);
|
|
34
|
+
});
|
|
32
35
|
await conn.send('Browser.setDownloadBehavior', { behavior: 'default', eventsEnabled: true }, 5000);
|
|
33
36
|
}
|
|
34
37
|
catch {
|
package/dist/cdp/sessions.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { CdpmError } from '../errors.js';
|
|
4
|
-
import { pidAlive } from '../util.js';
|
|
5
4
|
import { portOf } from '../slots.js';
|
|
6
5
|
import { paths } from '../paths.js';
|
|
7
|
-
import { withFileLock } from '../registry/lock.js';
|
|
6
|
+
import { removeIfOwnerDead, withFileLock } from '../registry/lock.js';
|
|
8
7
|
import { CdpConnection, CdpTimeoutError } from './client.js';
|
|
9
8
|
import { NetworkRecorder } from './network.js';
|
|
10
9
|
import { listFrameTargets, listPages, probe } from './targets.js';
|
|
@@ -133,13 +132,23 @@ export class PageSession {
|
|
|
133
132
|
}
|
|
134
133
|
return w;
|
|
135
134
|
}
|
|
136
|
-
/**
|
|
137
|
-
|
|
135
|
+
/**
|
|
136
|
+
* 실행 공간이 사라졌다는 오류면 다시 만들어 한 번 더 시도한다.
|
|
137
|
+
* once: 두 번 실행되면 안 되는 코드(사용자 스크립트). 실행 공간 ID가 이미 없어 시작도 못 한 경우만 다시 하고,
|
|
138
|
+
* 실행 도중 페이지가 바뀐 경우("Execution context was destroyed")는 다시 돌리지 않는다 (POST·제출이 두 번 일어나므로).
|
|
139
|
+
*/
|
|
140
|
+
async inWorld(frameId, fn, once = false) {
|
|
141
|
+
let started = false;
|
|
138
142
|
try {
|
|
139
|
-
|
|
143
|
+
const contextId = await this.world(frameId);
|
|
144
|
+
started = true;
|
|
145
|
+
return await fn(contextId);
|
|
140
146
|
}
|
|
141
147
|
catch (e) {
|
|
142
|
-
|
|
148
|
+
const msg = e.message;
|
|
149
|
+
if (once && started && !/Cannot find context with specified id/i.test(msg))
|
|
150
|
+
throw e;
|
|
151
|
+
if (!/context|Cannot find|not found/i.test(msg))
|
|
143
152
|
throw e;
|
|
144
153
|
this.worlds.delete(frameId ?? this.mainFrameId ?? '');
|
|
145
154
|
if (!frameId)
|
|
@@ -154,7 +163,7 @@ export class PageSession {
|
|
|
154
163
|
if (r.exceptionDetails)
|
|
155
164
|
return { type: 'exception', exception: r.exceptionDetails.exception?.description ?? r.exceptionDetails.text };
|
|
156
165
|
return r.result;
|
|
157
|
-
});
|
|
166
|
+
}, opts.once);
|
|
158
167
|
}
|
|
159
168
|
setSnapshot(agent, refs, cache) {
|
|
160
169
|
this.refMaps.set(agent, refs);
|
|
@@ -379,17 +388,34 @@ export function hasLiveBrowserConnection(slot) {
|
|
|
379
388
|
const c = browserConns.get(slot);
|
|
380
389
|
return !!c && !c.closed;
|
|
381
390
|
}
|
|
391
|
+
const browserConnecting = new Map();
|
|
392
|
+
/** 슬롯 브라우저 연결. 동시에 처음 불려도 연결은 하나만 만든다 (덮어써진 연결이 새거나, 닫힐 때 새 연결 기록을 지우지 않게). */
|
|
382
393
|
export async function browserConnection(slot) {
|
|
383
394
|
const cached = browserConns.get(slot);
|
|
384
395
|
if (cached && !cached.closed)
|
|
385
396
|
return cached;
|
|
386
|
-
const
|
|
387
|
-
if (
|
|
388
|
-
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
397
|
+
const pending = browserConnecting.get(slot);
|
|
398
|
+
if (pending)
|
|
399
|
+
return pending;
|
|
400
|
+
const p = (async () => {
|
|
401
|
+
const probed = await probe(slot);
|
|
402
|
+
if (probed.state !== 'chrome')
|
|
403
|
+
throw new CdpmError(`Chrome is not running on slot ${slot} (port ${portOf(slot)}).`);
|
|
404
|
+
const conn = await CdpConnection.connect(probed.version.webSocketDebuggerUrl);
|
|
405
|
+
conn.onClosed(() => {
|
|
406
|
+
if (browserConns.get(slot) === conn)
|
|
407
|
+
browserConns.delete(slot);
|
|
408
|
+
});
|
|
409
|
+
browserConns.set(slot, conn);
|
|
410
|
+
return conn;
|
|
411
|
+
})();
|
|
412
|
+
browserConnecting.set(slot, p);
|
|
413
|
+
try {
|
|
414
|
+
return await p;
|
|
415
|
+
}
|
|
416
|
+
finally {
|
|
417
|
+
browserConnecting.delete(slot);
|
|
418
|
+
}
|
|
393
419
|
}
|
|
394
420
|
/** 탭 연결을 얻는다. 같은 탭에 동시에 요청이 와도 연결은 하나만 만든다. */
|
|
395
421
|
export async function pageSession(slot, targetId, wsUrl) {
|
|
@@ -412,7 +438,10 @@ export async function pageSession(slot, targetId, wsUrl) {
|
|
|
412
438
|
throw new CdpmError('Tab not found (it may have been closed).');
|
|
413
439
|
const conn = await CdpConnection.connect(url);
|
|
414
440
|
const session = new PageSession(slot, targetId, conn);
|
|
415
|
-
conn.onClosed(() =>
|
|
441
|
+
conn.onClosed(() => {
|
|
442
|
+
if (pageSessions.get(key) === session)
|
|
443
|
+
pageSessions.delete(key);
|
|
444
|
+
});
|
|
416
445
|
pageSessions.set(key, session);
|
|
417
446
|
// Page.enable: dialog·로딩 이벤트용. 이미 떠 있는 dialog도 이때 알려준다.
|
|
418
447
|
// Runtime.enable(봇 탐지 흔적)과 Emulation.*(사용자 환경 변경)은 쓰지 않는다.
|
|
@@ -500,15 +529,7 @@ function cleanStaleTabLocks() {
|
|
|
500
529
|
for (const n of names) {
|
|
501
530
|
if (!n.endsWith('.lock'))
|
|
502
531
|
continue;
|
|
503
|
-
|
|
504
|
-
try {
|
|
505
|
-
const pid = Number(fs.readFileSync(file, 'utf8'));
|
|
506
|
-
if (pid > 0 && !pidAlive(pid))
|
|
507
|
-
fs.unlinkSync(file);
|
|
508
|
-
}
|
|
509
|
-
catch {
|
|
510
|
-
// 그 사이 풀렸으면 무시
|
|
511
|
-
}
|
|
532
|
+
removeIfOwnerDead(path.join(dir, n));
|
|
512
533
|
}
|
|
513
534
|
}
|
|
514
535
|
/** 프로세스를 끝내기 전에 모든 CDP 연결을 닫는다. */
|
package/dist/cdp/targets.js
CHANGED
|
@@ -29,9 +29,20 @@ export async function listPages(slot, timeoutMs = 10_000) {
|
|
|
29
29
|
const res = await fetch(`http://127.0.0.1:${portOf(slot)}/json/list`, { signal: AbortSignal.timeout(timeoutMs) });
|
|
30
30
|
const all = (await res.json());
|
|
31
31
|
return all
|
|
32
|
-
.filter((t) => t.type === 'page' && !t.url.startsWith('devtools://'))
|
|
32
|
+
.filter((t) => t.type === 'page' && !t.url.startsWith('devtools://') && !isPrintPreview(t))
|
|
33
33
|
.map((t) => ({ ...t, title: decodeEntities(t.title) }));
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* 인쇄 미리보기는 탭이 아닌데 page 대상(chrome://print/)으로 잡힌다. 어느 탭 것인지 알려 주지 않지만
|
|
37
|
+
* 제목이 그 탭 제목과 같다. 떠 있는 동안 그 탭은 입력 명령에 답하지 않는다 (페이지 스크립트가 print()에서 멈춤).
|
|
38
|
+
*/
|
|
39
|
+
function isPrintPreview(t) {
|
|
40
|
+
return t.type === 'page' && t.url.startsWith('chrome://print');
|
|
41
|
+
}
|
|
42
|
+
export async function listPrintPreviews(slot, timeoutMs = 3000) {
|
|
43
|
+
const res = await fetch(`http://127.0.0.1:${portOf(slot)}/json/list`, { signal: AbortSignal.timeout(timeoutMs) });
|
|
44
|
+
return (await res.json()).filter(isPrintPreview).map((t) => ({ ...t, title: decodeEntities(t.title) }));
|
|
45
|
+
}
|
|
35
46
|
/** 다른 사이트 iframe(별도 프로세스) 대상들. 대상 ID는 그 iframe의 프레임 ID와 같다. */
|
|
36
47
|
export async function listFrameTargets(slot, timeoutMs = 10_000) {
|
|
37
48
|
const res = await fetch(`http://127.0.0.1:${portOf(slot)}/json/list`, { signal: AbortSignal.timeout(timeoutMs) });
|
package/dist/chrome/bubbles.js
CHANGED
|
@@ -40,20 +40,20 @@ export function permissionBubbles(slot, hosts) {
|
|
|
40
40
|
return [];
|
|
41
41
|
}
|
|
42
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
|
|
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
57
|
`;
|
|
58
58
|
const ENCODED = Buffer.from(UIA_SCRIPT, 'utf16le').toString('base64');
|
|
59
59
|
function runUia(b, press) {
|
package/dist/chrome/launcher.js
CHANGED
|
@@ -24,6 +24,9 @@ export function chromeArgs(slot, opts = {}) {
|
|
|
24
24
|
* Chrome은 살아 있도록 부모 없는 프로세스로 띄운다 (orphan.ts).
|
|
25
25
|
*/
|
|
26
26
|
export async function launchChrome(slot, opts = {}) {
|
|
27
|
+
// 시작 주소는 Chrome 실행 인자 끝에 붙는다. '-'로 시작하면 주소가 아니라 Chrome 옵션으로 읽힌다.
|
|
28
|
+
if (opts.url && /^\s*-/.test(opts.url))
|
|
29
|
+
throw new CdpmError(`Not a URL: ${opts.url.slice(0, 80)}`);
|
|
27
30
|
const chrome = findChrome();
|
|
28
31
|
fs.mkdirSync(paths.profile(slot), { recursive: true });
|
|
29
32
|
const extra = opts.proxy ? await proxyArgs(slot, opts.proxy) : [];
|
package/dist/claude-md-setup.js
CHANGED
|
@@ -6,28 +6,28 @@ import os from 'node:os';
|
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
const START = '<!-- CDPM:START (cdpm setup이 관리하는 부분) -->';
|
|
8
8
|
const END = '<!-- CDPM:END -->';
|
|
9
|
-
export const CDPM_RULES = `${START}
|
|
10
|
-
## CDPM (Chrome slot MCP) rules
|
|
11
|
-
|
|
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).
|
|
9
|
+
export const CDPM_RULES = `${START}
|
|
10
|
+
## CDPM (Chrome slot MCP) rules
|
|
11
|
+
|
|
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).
|
|
31
31
|
${END}`;
|
|
32
32
|
export function claudeMdPath() {
|
|
33
33
|
const dir = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude');
|
package/dist/cli.js
CHANGED
|
@@ -50,8 +50,9 @@ async function closeSlot(slot) {
|
|
|
50
50
|
async function closeSlotLocked(slot) {
|
|
51
51
|
const { probe } = await lazy.targets();
|
|
52
52
|
const { browserConnection } = await lazy.sessions();
|
|
53
|
-
const { forgetSlot } = await lazy.service();
|
|
54
|
-
|
|
53
|
+
const { forgetSlot, probeSure } = await lazy.service();
|
|
54
|
+
// 바빠서 늦게 답하는 Chrome을 꺼진 것으로 보고 기록을 지우지 않게 (늦으면 8초까지 다시 묻는다)
|
|
55
|
+
if ((await probeSure(slot)).state !== 'chrome') {
|
|
55
56
|
await forgetSlot(slot);
|
|
56
57
|
console.log(`${slot}번: 이미 꺼져 있어요.`);
|
|
57
58
|
return;
|
|
@@ -122,8 +123,9 @@ async function main(argv) {
|
|
|
122
123
|
const [slot] = slotsFrom(rest.slice(0, 1));
|
|
123
124
|
if (slot === undefined)
|
|
124
125
|
throw new CdpmError('슬롯을 적어 주세요. 예: cdpm purge 3');
|
|
125
|
-
|
|
126
|
-
|
|
126
|
+
// 바빠서 늦게 답하는 Chrome도 떠 있는 것이다 (늦으면 8초까지 다시 묻고, 그래도 늦으면 지우지 않고 멈춘다)
|
|
127
|
+
const { probeSure } = await lazy.service();
|
|
128
|
+
if ((await probeSure(slot)).state === 'chrome')
|
|
127
129
|
throw new CdpmError(`${slot}번 Chrome이 떠 있어요. 먼저 cdpm close ${slot}으로 종료하세요.`);
|
|
128
130
|
fs.rmSync(paths.profile(slot), { recursive: true, force: true });
|
|
129
131
|
console.log(`${slot}번 프로필을 삭제했어요: ${paths.profile(slot)}`);
|