cdpm-mcp 0.1.3 → 0.1.5
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 +12 -0
- package/README.ko.md +2 -0
- package/README.md +2 -0
- package/dist/agent-setup.js +16 -14
- 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/finder.js +2 -2
- package/dist/chrome/launcher.js +19 -21
- package/dist/chrome/proxy.js +16 -28
- package/dist/claude-md-setup.js +19 -16
- package/dist/cli.js +1 -1
- package/dist/orphan.js +49 -0
- 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/tools/format.js +12 -12
- package/dist/tools/read.js +10 -10
- package/dist/tools/register.js +301 -298
- package/dist/util.js +5 -5
- package/package.json +1 -1
package/dist/page/snapshot.js
CHANGED
|
@@ -44,7 +44,7 @@ export function formatAxTree(nodes, opts = {}) {
|
|
|
44
44
|
const sub = node.backendDOMNodeId !== undefined ? ctx.frames?.get(node.backendDOMNodeId) : undefined;
|
|
45
45
|
const head = `${pad(depth)}- iframe${name ? ` ${quote(name)}` : ''}`;
|
|
46
46
|
if (sub === 'unsupported')
|
|
47
|
-
return [`${head} (
|
|
47
|
+
return [`${head} (unreadable)`];
|
|
48
48
|
if (!sub)
|
|
49
49
|
return [head];
|
|
50
50
|
// 같은 프로세스 iframe은 요소 ID 공간이 같고, 다른 사이트 iframe은 자기 공간을 쓴다
|
package/dist/pause.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// 다시 시작하면 그 슬롯의 모든 에이전트에게 메시지를 보내 slot_inbox로 기다리던 에이전트를 바로 깨운다.
|
|
5
5
|
import { sendMessage } from './registry/messages.js';
|
|
6
6
|
import { readRegistry, updateRegistry } from './registry/store.js';
|
|
7
|
-
import { ago,
|
|
7
|
+
import { ago, nowIso } from './util.js';
|
|
8
8
|
export function pausedInfo(slot) {
|
|
9
9
|
return readRegistry().slots[String(slot)]?.paused;
|
|
10
10
|
}
|
|
@@ -23,10 +23,9 @@ export function pausedRefusal(slot) {
|
|
|
23
23
|
const p = pausedInfo(slot);
|
|
24
24
|
if (!p)
|
|
25
25
|
return undefined;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
'스스로 다시 시작(slot_resume)하지 마세요: 사용자가 정해요.';
|
|
26
|
+
return `[paused] ${p.agent} paused slot ${slot} (${ago(p.at)}). The user may be operating it, so don't act on this slot. ` +
|
|
27
|
+
`Wait with slot_inbox(slot=${slot}, wait=600); a message arrives on resume. The page may have changed, so re-read with browser_snapshot and continue. ` +
|
|
28
|
+
"Don't resume it yourself (slot_resume): the user decides.";
|
|
30
29
|
}
|
|
31
30
|
/** 슬롯들을 멈춘다. 꺼진 슬롯은 건너뛴다. 결과 안내 줄들을 돌려준다. */
|
|
32
31
|
export async function pauseSlots(slots, by) {
|
|
@@ -41,11 +40,11 @@ export async function pauseSlots(slots, by) {
|
|
|
41
40
|
const out = [];
|
|
42
41
|
for (const slot of slots) {
|
|
43
42
|
if (!done.includes(slot)) {
|
|
44
|
-
out.push(
|
|
43
|
+
out.push(`Slot ${slot} is not running.`);
|
|
45
44
|
continue;
|
|
46
45
|
}
|
|
47
|
-
await sendMessage(slot, by, `[
|
|
48
|
-
out.push(
|
|
46
|
+
await sendMessage(slot, by, `[paused] The user paused slot ${slot}. Don't act; wait with slot_inbox(slot=${slot}, wait=600).`, null);
|
|
47
|
+
out.push(`Paused slot ${slot}. All actions on it are now refused, and waiting agents stop at once.`);
|
|
49
48
|
}
|
|
50
49
|
return out;
|
|
51
50
|
}
|
|
@@ -60,11 +59,11 @@ export async function resumeSlots(slots, by) {
|
|
|
60
59
|
const out = [];
|
|
61
60
|
for (const slot of slots) {
|
|
62
61
|
if (!was.includes(slot)) {
|
|
63
|
-
out.push(
|
|
62
|
+
out.push(`Slot ${slot} is not paused.`);
|
|
64
63
|
continue;
|
|
65
64
|
}
|
|
66
|
-
await sendMessage(slot, by, `[
|
|
67
|
-
out.push(
|
|
65
|
+
await sendMessage(slot, by, `[resumed] The user resumed slot ${slot}. The page may have changed while paused; re-read with browser_snapshot and continue your task.`, null);
|
|
66
|
+
out.push(`Resumed slot ${slot}. Waiting agents were notified.`);
|
|
68
67
|
}
|
|
69
68
|
return out;
|
|
70
69
|
}
|
package/dist/proxy-forwarder.js
CHANGED
|
@@ -19,7 +19,7 @@ function tunnel(host, port) {
|
|
|
19
19
|
const s = connectUpstream();
|
|
20
20
|
const fail = (e) => { s.destroy(); reject(e); };
|
|
21
21
|
s.once('error', fail);
|
|
22
|
-
s.setTimeout(20_000, () => fail(new Error('
|
|
22
|
+
s.setTimeout(20_000, () => fail(new Error('Proxy not responding')));
|
|
23
23
|
const ready = () => { s.setTimeout(0); s.removeListener('error', fail); resolve(s); };
|
|
24
24
|
s.once(up.scheme === 'https' ? 'secureConnect' : 'connect', () => {
|
|
25
25
|
if (up.scheme === 'socks5')
|
|
@@ -35,7 +35,7 @@ function tunnel(host, port) {
|
|
|
35
35
|
s.pause(); // 다 읽은 뒤 멈춰 둬야, 이어서 온 데이터가 읽는 쪽이 붙기 전에 버려지지 않는다
|
|
36
36
|
const status = /^HTTP\/1\.[01] (\d{3})/.exec(buf.toString('latin1'))?.[1];
|
|
37
37
|
if (status !== '200')
|
|
38
|
-
return fail(new Error(
|
|
38
|
+
return fail(new Error(`Proxy refused the connection (HTTP ${status ?? '?'})`));
|
|
39
39
|
const rest = buf.subarray(end + 4);
|
|
40
40
|
if (rest.length)
|
|
41
41
|
s.unshift(rest);
|
|
@@ -59,7 +59,7 @@ function readBytes(s, n) {
|
|
|
59
59
|
s.unshift(buf.subarray(n));
|
|
60
60
|
resolve(buf.subarray(0, n));
|
|
61
61
|
};
|
|
62
|
-
const onClose = () => reject(new Error('
|
|
62
|
+
const onClose = () => reject(new Error('Proxy closed the connection'));
|
|
63
63
|
s.on('data', onData);
|
|
64
64
|
s.once('close', onClose);
|
|
65
65
|
s.resume(); // 앞에서 멈춰 둔 소켓은 data 리스너만으로는 다시 흐르지 않는다
|
|
@@ -73,10 +73,10 @@ async function socks5(s, host, port) {
|
|
|
73
73
|
s.write(Buffer.concat([Buffer.from([1, u.length]), u, Buffer.from([p.length]), p]));
|
|
74
74
|
const [, ok] = await readBytes(s, 2);
|
|
75
75
|
if (ok !== 0)
|
|
76
|
-
throw new Error('socks5
|
|
76
|
+
throw new Error('socks5 proxy rejected the username/password');
|
|
77
77
|
}
|
|
78
78
|
else if (method !== 0)
|
|
79
|
-
throw new Error('socks5
|
|
79
|
+
throw new Error('socks5 proxy rejected the auth method');
|
|
80
80
|
// 주소 이름을 그대로 넘겨 DNS도 프록시 쪽에서 풀게 한다 (이 PC의 DNS로 새지 않게)
|
|
81
81
|
const h = host.replace(/^\[|\]$/g, '');
|
|
82
82
|
const ipType = net.isIP(h);
|
|
@@ -86,7 +86,7 @@ async function socks5(s, host, port) {
|
|
|
86
86
|
s.write(Buffer.concat([Buffer.from([5, 1, 0]), addr, Buffer.from([port >> 8, port & 255])]));
|
|
87
87
|
const head = await readBytes(s, 4);
|
|
88
88
|
if (head[1] !== 0)
|
|
89
|
-
throw new Error(`socks5
|
|
89
|
+
throw new Error(`socks5 proxy refused the connection (code ${head[1]})`);
|
|
90
90
|
const len = head[3] === 1 ? 4 : head[3] === 4 ? 16 : (await readBytes(s, 1))[0];
|
|
91
91
|
await readBytes(s, len + 2);
|
|
92
92
|
}
|
|
@@ -114,7 +114,7 @@ const server = http.createServer((req, res) => {
|
|
|
114
114
|
const headers = { ...req.headers };
|
|
115
115
|
delete headers['proxy-connection'];
|
|
116
116
|
const done = (e) => { if (!res.headersSent)
|
|
117
|
-
res.writeHead(502, { 'content-type': 'text/plain; charset=utf-8' }); res.end(`CDPM
|
|
117
|
+
res.writeHead(502, { 'content-type': 'text/plain; charset=utf-8' }); res.end(`CDPM proxy forwarder error: ${e.message}`); };
|
|
118
118
|
if (up.scheme === 'socks5') {
|
|
119
119
|
const port = Number(target.port || 80);
|
|
120
120
|
tunnel(target.hostname, port).then((sock) => {
|
|
@@ -147,7 +147,7 @@ server.on('connect', (req, client, head) => {
|
|
|
147
147
|
remote.pipe(client);
|
|
148
148
|
client.pipe(remote);
|
|
149
149
|
}, (e) => {
|
|
150
|
-
client.end(`HTTP/1.1 502 Bad Gateway\r\ncontent-type: text/plain; charset=utf-8\r\n\r\nCDPM
|
|
150
|
+
client.end(`HTTP/1.1 502 Bad Gateway\r\ncontent-type: text/plain; charset=utf-8\r\n\r\nCDPM proxy forwarder error: ${e.message}`);
|
|
151
151
|
});
|
|
152
152
|
});
|
|
153
153
|
/** 그 슬롯 포트에 떠 있는 Chrome의 고유 주소 (Chrome마다 다름). 응답이 없으면 undefined. */
|
package/dist/registry/lock.js
CHANGED
|
@@ -13,11 +13,11 @@ export class LockTimeoutError extends Error {
|
|
|
13
13
|
* (느린 프로세스의 잠금을 뺏어 기록이 깨지는 일이 없게).
|
|
14
14
|
*/
|
|
15
15
|
export async function withLock(fn, timeoutMs = 10_000) {
|
|
16
|
-
return withFileLock(paths.lock(), fn, timeoutMs, '
|
|
16
|
+
return withFileLock(paths.lock(), fn, timeoutMs, 'Could not acquire the store lock (another process is holding it).');
|
|
17
17
|
}
|
|
18
18
|
/** 슬롯 켜기·끄기를 여러 Claude 세션 사이에서 하나씩 (동시에 켜면 Chrome이 두 번 떠서 하나가 실패함). */
|
|
19
19
|
export function withSlotLock(slot, fn) {
|
|
20
|
-
return withFileLock(paths.slotLock(slot), fn, 90_000,
|
|
20
|
+
return withFileLock(paths.slotLock(slot), fn, 90_000, `Another Claude session is launching or closing slot ${slot}. Try again shortly.`);
|
|
21
21
|
}
|
|
22
22
|
/** 같은 방식의 잠금을 원하는 파일로 (예: 탭 하나를 여러 Claude 세션이 동시에 조작하지 않게). */
|
|
23
23
|
export async function withFileLock(lockPath, fn, timeoutMs, timeoutMessage) {
|
package/dist/service.js
CHANGED
|
@@ -9,8 +9,8 @@ import { newSlotRecord, readRegistry, updateRegistry } from './registry/store.js
|
|
|
9
9
|
import { MAX_SLOT, portOf } from './slots.js';
|
|
10
10
|
import { applyDock, DOCK_SUPPORTED } from './taskbar/dock.js';
|
|
11
11
|
import { applyTaskbar } from './taskbar/watcher.js';
|
|
12
|
-
import { ago,
|
|
13
|
-
export const EXTERNAL = '(
|
|
12
|
+
import { ago, nowIso, pidAlive, secondsSince, sleep } from './util.js';
|
|
13
|
+
export const EXTERNAL = '(external)';
|
|
14
14
|
/** 이 프로세스가 직접 만든 탭 → 만든 에이전트. 기록부에 처음 올릴 때 openedBy로 쓴다. */
|
|
15
15
|
const createdBy = new Map();
|
|
16
16
|
const createdAt = new Map();
|
|
@@ -27,8 +27,8 @@ export function markCreated(targetId, agent) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
export const notRunningMessage = (slot) =>
|
|
31
|
-
|
|
30
|
+
export const notRunningMessage = (slot) => `Chrome on slot ${slot} is off. CDPM starts Chrome only when the user asks. ` +
|
|
31
|
+
`Ask the user whether to start it; if yes, use browser_launch.`;
|
|
32
32
|
/** 떠 있는 슬롯에 붙는다 (기록·작업표시줄 맞춤). 꺼져 있으면 켜지 않고 오류. */
|
|
33
33
|
/** 포트 확인. 늦게 답하면(바쁜 Chrome) 길게 한 번 더 묻는다. */
|
|
34
34
|
async function probeSure(slot) {
|
|
@@ -36,7 +36,7 @@ async function probeSure(slot) {
|
|
|
36
36
|
if (p.state === 'slow')
|
|
37
37
|
p = await probe(slot, 8000);
|
|
38
38
|
if (p.state === 'slow') {
|
|
39
|
-
throw new CdpmError(
|
|
39
|
+
throw new CdpmError(`Slot ${slot} port (${portOf(slot)}) has not responded for over 8s. Chrome may be very busy or hung. Retry shortly.`);
|
|
40
40
|
}
|
|
41
41
|
return p;
|
|
42
42
|
}
|
|
@@ -60,7 +60,7 @@ export async function attachSlot(slot) {
|
|
|
60
60
|
pid = await browserPid(slot);
|
|
61
61
|
if (!pid || !pidAlive(pid)) {
|
|
62
62
|
await forgetSlot(slot);
|
|
63
|
-
throw new CdpmError(
|
|
63
|
+
throw new CdpmError(`Slot ${slot} port (${portOf(slot)}) is connected to a Chrome on another machine (SSH tunnel, etc.). Close that connection or use another slot.`);
|
|
64
64
|
}
|
|
65
65
|
await updateRegistry((r) => {
|
|
66
66
|
const s = (r.slots[String(slot)] ??= newSlotRecord(EXTERNAL, nowIso()));
|
|
@@ -72,7 +72,7 @@ export async function attachSlot(slot) {
|
|
|
72
72
|
void applyDock(slot, pid); // macOS만
|
|
73
73
|
}
|
|
74
74
|
function portBusy(slot, detail) {
|
|
75
|
-
return new CdpmError(
|
|
75
|
+
return new CdpmError(`Slot ${slot} port ${portOf(slot)} is used by a non-Chrome program (${detail}). Close it or use another slot.`);
|
|
76
76
|
}
|
|
77
77
|
/** 사용자가 켜라고 했을 때만 부른다. 이미 떠 있으면 붙기만 한다. */
|
|
78
78
|
export function launchSlot(slot, agent, opts = {}) {
|
|
@@ -174,7 +174,7 @@ export async function syncTabs(slot) {
|
|
|
174
174
|
const opener = openers.get(p.id);
|
|
175
175
|
if (!openedBy && opener) {
|
|
176
176
|
const by = s.tabs[opener]?.last?.agent;
|
|
177
|
-
openedBy = by ? `${by} (
|
|
177
|
+
openedBy = by ? `${by} (via page)` : `page in ${s.tabs[opener]?.id ?? 'another tab'}`;
|
|
178
178
|
}
|
|
179
179
|
const seq = s.nextTabSeq++;
|
|
180
180
|
s.tabs[p.id] = { id: `t${seq}`, seq, seenAt: nowIso(), openedBy: openedBy ?? EXTERNAL };
|
|
@@ -208,13 +208,13 @@ export function pickTab(tabs, tabArg, kind, preferred) {
|
|
|
208
208
|
const found = byId ?? byNo;
|
|
209
209
|
if (found)
|
|
210
210
|
return { tab: found };
|
|
211
|
-
const list = tabs.map((t) => `${t.no}
|
|
212
|
-
return { error:
|
|
211
|
+
const list = tabs.map((t) => `${t.no} [${t.id}]`).join(', ');
|
|
212
|
+
return { error: `No such tab: "${s}". Open tabs: ${list || 'none'}` };
|
|
213
213
|
}
|
|
214
214
|
if (tabs.length === 1)
|
|
215
215
|
return { tab: tabs[0] };
|
|
216
216
|
if (tabs.length === 0)
|
|
217
|
-
return { error: '
|
|
217
|
+
return { error: 'No open tabs.' };
|
|
218
218
|
// 이 에이전트가 마지막으로 쓴(또는 새로 연) 탭이 있으면 보기·조작 모두 그 탭
|
|
219
219
|
const mine = tabs.find((t) => t.targetId === preferred);
|
|
220
220
|
if (mine)
|
|
@@ -222,7 +222,7 @@ export function pickTab(tabs, tabArg, kind, preferred) {
|
|
|
222
222
|
// 보기 도구: 앞에 보이는 탭 → 첫 탭. 조작 도구: 쓴 적 있는 탭이 없으면 지정을 요구한다.
|
|
223
223
|
if (kind === 'view')
|
|
224
224
|
return { tab: tabs.find((t) => t.active) ?? tabs[0] };
|
|
225
|
-
return { error:
|
|
225
|
+
return { error: `There are ${tabs.length} tabs and this agent has not used any yet. Set tab to a number or ID (e.g. "${tabs[0].id}").` };
|
|
226
226
|
}
|
|
227
227
|
/** 다른 에이전트가 최근(2분 안)에 조작한 탭을 조작할 때 붙일 경고 (막지는 않음). */
|
|
228
228
|
export function ownershipWarnings(tab, agent) {
|
|
@@ -230,7 +230,7 @@ export function ownershipWarnings(tab, agent) {
|
|
|
230
230
|
if (!last || last.agent === agent || secondsSince(last.at) > 120)
|
|
231
231
|
return [];
|
|
232
232
|
const when = ago(last.at);
|
|
233
|
-
return [
|
|
233
|
+
return [`Tab [${tab.id}] was used by ${last.agent} ${when} (${last.action}). If sharing it, tell them via slot_send.`];
|
|
234
234
|
}
|
|
235
235
|
/** 행동 기록. 기록부 잠금에 실패해도 도구 동작은 성공으로 두고 false를 돌려준다. */
|
|
236
236
|
export async function recordAction(slot, targetId, agent, action, summary, anon = false, title) {
|
package/dist/slots.js
CHANGED
|
@@ -23,7 +23,7 @@ export function isValidSlot(slot) {
|
|
|
23
23
|
}
|
|
24
24
|
export function assertSlot(slot) {
|
|
25
25
|
if (!isValidSlot(slot)) {
|
|
26
|
-
throw new CdpmError(
|
|
26
|
+
throw new CdpmError(`Slot must be ${MIN_SLOT}-${MAX_SLOT} (got: ${String(slot)})`);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
/**
|
package/dist/tools/format.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import { portOf } from '../slots.js';
|
|
2
2
|
import { ago, displayWidth, padEnd, shortUrl, truncate } from '../util.js';
|
|
3
3
|
export function tabLines(tabs, markTargetId, withSummary = false) {
|
|
4
|
-
const titles = tabs.map((t) => truncate(t.title || '(
|
|
4
|
+
const titles = tabs.map((t) => truncate(t.title || '(untitled)', 34));
|
|
5
5
|
const urls = tabs.map((t) => shortUrl(t.url, 34));
|
|
6
6
|
const tw = Math.max(0, ...titles.map(displayWidth));
|
|
7
7
|
const uw = Math.max(0, ...urls.map(displayWidth));
|
|
8
8
|
const lines = [];
|
|
9
9
|
tabs.forEach((t, i) => {
|
|
10
10
|
const mark = t.targetId === markTargetId ? '>' : ' ';
|
|
11
|
-
const last = t.rec.last ? `
|
|
12
|
-
const active = t.active ? '
|
|
13
|
-
lines.push(`${mark} ${t.no}. [${t.id}]${active} ${padEnd(titles[i], tw)} ${padEnd(urls[i], uw)}
|
|
11
|
+
const last = t.rec.last ? ` last: ${t.rec.last.agent} ${t.rec.last.action} (${ago(t.rec.last.at)})` : '';
|
|
12
|
+
const active = t.active ? ' ·front' : '';
|
|
13
|
+
lines.push(`${mark} ${t.no}. [${t.id}]${active} ${padEnd(titles[i], tw)} ${padEnd(urls[i], uw)} opened by: ${t.rec.openedBy}${last}`);
|
|
14
14
|
if (withSummary && t.rec.summary) {
|
|
15
|
-
lines.push(`
|
|
15
|
+
lines.push(` summary: ${t.rec.summary.agent} — ${t.rec.summary.text} (${ago(t.rec.summary.at)})`);
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
return lines;
|
|
19
19
|
}
|
|
20
20
|
export function formatHeader(h) {
|
|
21
21
|
const exec = h.tabs.find((t) => t.targetId === h.executedTargetId);
|
|
22
|
-
const lines = [`[${h.slot}
|
|
22
|
+
const lines = [`[Slot ${h.slot}] ${h.tabs.length} tab(s)${exec ? ` · ran on tab ${exec.no} [${exec.id}]` : ''}`];
|
|
23
23
|
lines.push(...tabLines(h.tabs, h.executedTargetId));
|
|
24
24
|
for (const t of h.tabs) {
|
|
25
25
|
const d = h.dialogs?.get(t.targetId);
|
|
26
26
|
if (d)
|
|
27
|
-
lines.push(`[
|
|
27
|
+
lines.push(`[warning] dialog open (${d.type}) on tab ${t.no} [${t.id}]: "${truncate(d.message, 80)}" — read it and handle it yourself with browser_dialog (ask the user only for confirmations of unrequested payment/deletion etc.)`);
|
|
28
28
|
}
|
|
29
29
|
for (const w of h.warnings ?? [])
|
|
30
|
-
lines.push(`[
|
|
30
|
+
lines.push(`[warning] ${w}`);
|
|
31
31
|
if (h.messages?.length) {
|
|
32
|
-
lines.push(
|
|
32
|
+
lines.push(`${h.messages.length} new message(s) (marked read here; won't appear again in slot_inbox)`);
|
|
33
33
|
lines.push(...formatMessages(h.messages).map((l) => ` ${l}`));
|
|
34
34
|
}
|
|
35
35
|
return lines.join('\n');
|
|
@@ -38,10 +38,10 @@ export function formatMessages(msgs) {
|
|
|
38
38
|
return msgs.map((m) => `${m.from}${m.to ? ` → ${m.to}` : ''} (${ago(m.at)}): ${m.text}`);
|
|
39
39
|
}
|
|
40
40
|
export function formatSlotStatus(slot, rec, tabs) {
|
|
41
|
-
const mode = rec.headless ? ' ·
|
|
42
|
-
const lines = [`[${slot}
|
|
41
|
+
const mode = rec.headless ? ' · headless' : '';
|
|
42
|
+
const lines = [`[Slot ${slot}] port ${portOf(slot)}${mode} · ${tabs ? `${tabs.length}` : '?'} tab(s) · launched by: ${rec.launchedBy ?? '(external)'} (${ago(rec.launchedAt)})`];
|
|
43
43
|
if (rec.summary)
|
|
44
|
-
lines.push(`
|
|
44
|
+
lines.push(` summary: ${rec.summary.agent} — ${rec.summary.text} (${ago(rec.summary.at)})`);
|
|
45
45
|
if (tabs)
|
|
46
46
|
lines.push(...tabLines(tabs, undefined, true).map((l) => ` ${l}`));
|
|
47
47
|
return lines.join('\n');
|
package/dist/tools/read.js
CHANGED
|
@@ -4,13 +4,13 @@ const MAX_REMOVED_SHOWN = 15;
|
|
|
4
4
|
function footer(p, total) {
|
|
5
5
|
if (p.pages <= 1)
|
|
6
6
|
return '';
|
|
7
|
-
return `\n— 1/${p.pages}
|
|
7
|
+
return `\n— page 1/${p.pages} (${total.toLocaleString()} chars total) · continue: browser_snapshot page=2`;
|
|
8
8
|
}
|
|
9
9
|
/** 스냅샷 1쪽 (browser_snapshot과 같은 모양). */
|
|
10
10
|
async function snapshotPage1(s, agent) {
|
|
11
11
|
const { text } = await takeSnapshot(s, agent);
|
|
12
12
|
if (!text)
|
|
13
|
-
return '(
|
|
13
|
+
return '(no readable elements)';
|
|
14
14
|
const p = paginate(text, 1);
|
|
15
15
|
return p.body + footer(p, text.length);
|
|
16
16
|
}
|
|
@@ -24,9 +24,9 @@ async function changes(s, agent) {
|
|
|
24
24
|
const samePage = prev && prev.url.split('#')[0] === url.split('#')[0];
|
|
25
25
|
if (!prev || !samePage) {
|
|
26
26
|
if (!text)
|
|
27
|
-
return '(
|
|
27
|
+
return '(no readable elements)';
|
|
28
28
|
const p = paginate(text, 1);
|
|
29
|
-
return `(${prev ? '
|
|
29
|
+
return `(${prev ? 'page changed' : 'no previous snapshot to compare'}; showing full page)\n${p.body}${footer(p, text.length)}`;
|
|
30
30
|
}
|
|
31
31
|
const count = (lines) => {
|
|
32
32
|
const m = new Map();
|
|
@@ -54,16 +54,16 @@ async function changes(s, agent) {
|
|
|
54
54
|
removed.push(l);
|
|
55
55
|
}
|
|
56
56
|
if (!added.length && !removed.length)
|
|
57
|
-
return '(
|
|
58
|
-
const out = [
|
|
57
|
+
return '(no changes)';
|
|
58
|
+
const out = [`Changes since last snapshot: ${added.length} added · ${removed.length} removed`];
|
|
59
59
|
if (added.length) {
|
|
60
60
|
const p = paginate(added.map((l) => `+ ${l.trimStart()}`).join('\n'), 1);
|
|
61
|
-
out.push(p.body + (p.pages > 1 ? `\n—
|
|
61
|
+
out.push(p.body + (p.pages > 1 ? `\n— too many new lines; partial (full: browser_snapshot)` : ''));
|
|
62
62
|
}
|
|
63
63
|
if (removed.length) {
|
|
64
64
|
out.push(...removed.slice(0, MAX_REMOVED_SHOWN).map((l) => `- ${l.trimStart()}`));
|
|
65
65
|
if (removed.length > MAX_REMOVED_SHOWN)
|
|
66
|
-
out.push(`- …
|
|
66
|
+
out.push(`- … ${removed.length - MAX_REMOVED_SHOWN} more`);
|
|
67
67
|
}
|
|
68
68
|
return out.join('\n');
|
|
69
69
|
}
|
|
@@ -73,9 +73,9 @@ export async function readAfter(s, agent, mode) {
|
|
|
73
73
|
return '';
|
|
74
74
|
try {
|
|
75
75
|
const body = mode === 'text' ? await act.extractText(s, agent, undefined, 1) : mode === 'snapshot' ? await snapshotPage1(s, agent) : await changes(s, agent);
|
|
76
|
-
return `\n\n[
|
|
76
|
+
return `\n\n[page: ${mode}]\n${body}`;
|
|
77
77
|
}
|
|
78
78
|
catch (e) {
|
|
79
|
-
return `\n\n[
|
|
79
|
+
return `\n\n[page read failed: ${e.message}]`;
|
|
80
80
|
}
|
|
81
81
|
}
|