deictic 0.2.0 → 0.3.0
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/API.md +303 -0
- package/README.md +56 -127
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +117 -7
- package/dist/client/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/logs/client.d.ts +4 -0
- package/dist/logs/client.d.ts.map +1 -0
- package/dist/logs/client.js +16 -0
- package/dist/logs/client.js.map +1 -0
- package/dist/logs/index.d.ts +18 -0
- package/dist/logs/index.d.ts.map +1 -0
- package/dist/logs/index.js +21 -0
- package/dist/logs/index.js.map +1 -0
- package/dist/network/client.d.ts +4 -0
- package/dist/network/client.d.ts.map +1 -0
- package/dist/network/client.js +29 -0
- package/dist/network/client.js.map +1 -0
- package/dist/network/index.d.ts +2 -0
- package/dist/network/index.js +39 -0
- package/dist/network/index.js.map +1 -0
- package/dist/recommended/index.d.ts +13 -3
- package/dist/recommended/index.d.ts.map +1 -1
- package/dist/recommended/index.js +8 -1
- package/dist/recommended/index.js.map +1 -1
- package/dist/recordings/client.d.ts +1 -1
- package/dist/recordings/client.d.ts.map +1 -1
- package/dist/recordings/client.js +175 -46
- package/dist/recordings/client.js.map +1 -1
- package/dist/recordings/index.d.ts +2 -2
- package/dist/screenshots/client.d.ts +6 -0
- package/dist/screenshots/client.d.ts.map +1 -1
- package/dist/screenshots/client.js +34 -2
- package/dist/screenshots/client.js.map +1 -1
- package/dist/screenshots/dom.d.ts.map +1 -1
- package/dist/screenshots/dom.js +1 -28
- package/dist/screenshots/dom.js.map +1 -1
- package/dist/screenshots/index.js.map +1 -1
- package/dist/screenshots/rrweb.d.ts +1 -1
- package/dist/screenshots/rrweb.js +5 -1
- package/dist/screenshots/rrweb.js.map +1 -1
- package/dist/shared/index.d.ts +14 -2
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index2.d.ts +2 -0
- package/dist/shared/index2.d.ts.map +1 -1
- package/dist/shared/index3.d.ts +29 -3
- package/dist/shared/index3.d.ts.map +1 -1
- package/dist/shared/index4.d.ts +52 -172
- package/dist/shared/index4.d.ts.map +1 -1
- package/dist/shared/index5.d.ts +208 -58
- package/dist/shared/index5.d.ts.map +1 -1
- package/dist/shared/index6.d.ts +70 -0
- package/dist/shared/index6.d.ts.map +1 -0
- package/dist/shared/marks.js +6 -1
- package/dist/shared/marks.js.map +1 -1
- package/dist/shared/mask.js +107 -0
- package/dist/shared/mask.js.map +1 -0
- package/dist/shared/playwright.js +19 -4
- package/dist/shared/playwright.js.map +1 -1
- package/dist/shared/recordings.js +219 -28
- package/dist/shared/recordings.js.map +1 -1
- package/dist/shared/tasks.js +145 -34
- package/dist/shared/tasks.js.map +1 -1
- package/dist/tailwind/client.d.ts +1 -1
- package/dist/tailwind/index.d.ts +1 -1
- package/dist/tasks/client.d.ts +1 -1
- package/dist/tasks/client.d.ts.map +1 -1
- package/dist/tasks/client.js +271 -56
- package/dist/tasks/client.js.map +1 -1
- package/dist/tasks/index.d.ts +2 -2
- package/dist/voice/client.d.ts.map +1 -1
- package/dist/voice/client.js +35 -14
- package/dist/voice/client.js.map +1 -1
- package/dist/voice/index.d.ts +6 -1
- package/dist/voice/index.d.ts.map +1 -1
- package/dist/voice/index.js +12 -2
- package/dist/voice/index.js.map +1 -1
- package/package.json +41 -2
- package/skills/deictic/SKILL.md +20 -14
- package/skills/deictic/references/install.md +18 -11
- package/skills/deictic/references/recordings.md +29 -0
- package/skills/deictic/references/tasks.md +49 -21
- package/skills/deictic/references/watch.md +38 -11
- package/skills/deictic/scripts/lib.mjs +69 -3
- package/skills/deictic/scripts/recording.mjs +84 -4
- package/skills/deictic/scripts/task.mjs +36 -7
- package/skills/deictic/scripts/vb.mjs +12 -0
- package/skills/deictic/scripts/watch.mjs +74 -10
- package/src/client/away.ts +105 -0
- package/src/client/index.ts +40 -9
- package/src/client/style.ts +1 -0
- package/src/index.ts +14 -2
- package/src/plugins/logs/client.ts +18 -0
- package/src/plugins/logs/index.ts +55 -0
- package/src/plugins/network/client.ts +30 -0
- package/src/plugins/network/index.ts +69 -0
- package/src/plugins/network/mask.ts +133 -0
- package/src/plugins/recommended/index.ts +14 -1
- package/src/plugins/recordings/client.ts +219 -40
- package/src/plugins/recordings/index.ts +108 -23
- package/src/plugins/recordings/marks.ts +6 -0
- package/src/plugins/recordings/replay.ts +127 -4
- package/src/plugins/screenshots/client.ts +35 -0
- package/src/plugins/screenshots/dom.ts +1 -32
- package/src/plugins/screenshots/index.ts +2 -0
- package/src/plugins/screenshots/playwright.ts +15 -4
- package/src/plugins/screenshots/rrweb.ts +2 -1
- package/src/plugins/tasks/client.ts +273 -41
- package/src/plugins/tasks/index.ts +155 -39
- package/src/plugins/tasks/watchers.ts +36 -0
- package/src/plugins/voice/client.ts +33 -11
- package/src/plugins/voice/index.ts +21 -4
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// A task, briefly: what was asked, where (and whether that place has moved in the source since), the page,
|
|
3
|
-
// what's attached with the command to look at each, and the
|
|
3
|
+
// what's attached with the command to look at each, the replies, and the other open tasks about the same page.
|
|
4
|
+
// Usage: task.mjs <id> [--out dir]
|
|
4
5
|
// --out downloads the attachments there.
|
|
5
6
|
import { existsSync, mkdirSync, readFileSync } from 'node:fs';
|
|
6
7
|
import { dirname, join, resolve } from 'node:path';
|
|
@@ -8,6 +9,8 @@ import { fileURLToPath } from 'node:url';
|
|
|
8
9
|
|
|
9
10
|
import { deicticDirs, fail, parseArgs, vb } from './lib.mjs';
|
|
10
11
|
|
|
12
|
+
const vbScript = join(dirname(fileURLToPath(import.meta.url)), 'vb.mjs');
|
|
13
|
+
|
|
11
14
|
const { options, rest } = parseArgs(process.argv.slice(2));
|
|
12
15
|
if (rest[0] === undefined) fail('Name a task: task.mjs 68');
|
|
13
16
|
const { message: root, replies } = vb(['read', rest[0].replace(/^#/, '')], { json: true });
|
|
@@ -47,16 +50,17 @@ if (at !== undefined) {
|
|
|
47
50
|
console.log(`\n${file} isn't under ${roots.join(' or ')}: find the dev server's root.`);
|
|
48
51
|
} else {
|
|
49
52
|
const lines = readFileSync(path, 'utf8').split('\n');
|
|
53
|
+
// The tag's first line may follow other code on its line: `const App = () => <h1>`.
|
|
50
54
|
const first = root.labels['deictic.line'];
|
|
51
55
|
const now = lines[line - 1]?.trim();
|
|
52
|
-
if (first === undefined || now?.
|
|
53
|
-
console.log(`\
|
|
56
|
+
if (first === undefined || now?.includes(first.slice(0, 40))) {
|
|
57
|
+
console.log(`\nFile: ${path}:${line}, as the task saw it.`);
|
|
54
58
|
} else {
|
|
55
|
-
const moved = lines.findIndex((l) => l.
|
|
59
|
+
const moved = lines.findIndex((l) => l.includes(first.slice(0, 40)));
|
|
56
60
|
console.log(
|
|
57
61
|
moved >= 0
|
|
58
|
-
? `\
|
|
59
|
-
: `\
|
|
62
|
+
? `\nFile: moved to ${path}:${moved + 1} (the task says line ${line}).`
|
|
63
|
+
: `\nFile: ${path}:${line} no longer reads as the task saw it; it was:\n ${first}`,
|
|
60
64
|
);
|
|
61
65
|
}
|
|
62
66
|
}
|
|
@@ -76,9 +80,34 @@ for (const a of root.attachments) {
|
|
|
76
80
|
} else if (a.name.startsWith('voice-')) {
|
|
77
81
|
console.log(` ${a.name} (${kb}), a voice clip${saved}`);
|
|
78
82
|
console.log(` speech: node ${join(here, 'voice.mjs')} ${root.id}`);
|
|
83
|
+
} else if (a.name === 'element.html') {
|
|
84
|
+
console.log(
|
|
85
|
+
` ${a.name} (${kb}), the element's HTML as it rendered, if you need it${saved || `: node ${vbScript} download ${a.id} ${a.name}`}`,
|
|
86
|
+
);
|
|
79
87
|
} else {
|
|
80
|
-
|
|
88
|
+
// To a file's path: the CLI writes what it's given, and refuses a folder.
|
|
89
|
+
console.log(` ${a.name} (${a.type}, ${kb})${saved || `: node ${vbScript} download ${a.id} ${a.name}`}`);
|
|
81
90
|
}
|
|
82
91
|
}
|
|
83
92
|
if (replies.length > 0) console.log('\nReplies:');
|
|
84
93
|
for (const r of replies) console.log(` ${r.author?.handle ?? r.by.actor}: ${r.text}`);
|
|
94
|
+
|
|
95
|
+
// The other open tasks about the same page, of the same project: left a minute apart, they're often one change.
|
|
96
|
+
const page = root.labels['deictic.page'];
|
|
97
|
+
if (page !== undefined) {
|
|
98
|
+
const project = root.labels['deictic.project'];
|
|
99
|
+
const labels = [`deictic.page=${page}`, ...(project === undefined ? [] : [`deictic.project=${project}`])];
|
|
100
|
+
const { tasks } = vb(['tasks', root.channel, ...labels.flatMap((l) => ['--label', l])], { json: true });
|
|
101
|
+
const others = tasks.map((t) => t.message).filter((m) => m.id !== root.id);
|
|
102
|
+
if (others.length > 0) {
|
|
103
|
+
const count = `${others.length} other open task${others.length === 1 ? '' : 's'}`;
|
|
104
|
+
console.log(`\n${count} on ${page}: read them before you start, they may be one change.`);
|
|
105
|
+
for (const m of others) {
|
|
106
|
+
const title = m.text
|
|
107
|
+
.split(/\n---\n/)[0]
|
|
108
|
+
.split('\n')[0]
|
|
109
|
+
.slice(0, 100);
|
|
110
|
+
console.log(` #${m.id} ${m.task?.state ?? ''}, ${m.labels['deictic.at'] ?? '?'}: ${title}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The board's CLI as the other scripts run it: the project's own `@vercel/board`, which needn't be on the PATH,
|
|
3
|
+
// on the board the dev server uses (`BOARD_URL`, or with none, the one `.deictic/board.json` names).
|
|
4
|
+
// Usage: vb.mjs <anything vb takes>, as in: vb.mjs whoami · vb.mjs tasks claim 68 --lease 30m
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
6
|
+
|
|
7
|
+
import { fail, vbCommand } from './lib.mjs';
|
|
8
|
+
|
|
9
|
+
const [command, argv, options] = vbCommand(process.argv.slice(2));
|
|
10
|
+
const run = spawnSync(command, argv, { ...options, stdio: 'inherit' });
|
|
11
|
+
if (run.error) fail(`vb: ${run.error.message}. Install @vercel/board in the project, or put vb on the PATH.`);
|
|
12
|
+
process.exit(run.status ?? 1);
|
|
@@ -1,27 +1,88 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Watches the board for deictic's tasks and prints one line per thing to act on: the tasks ready now as it
|
|
3
3
|
// starts, then each new task, a reply on one, and one canceled (undone in the page, say). Made for an agent's
|
|
4
|
-
// monitor (each line an event)
|
|
5
|
-
//
|
|
4
|
+
// monitor (each line an event). It says so if the board goes away, and ends by itself once nothing has happened
|
|
5
|
+
// on the channel for `--idle` (20m): a watch nobody feeds isn't started again, so no agent watches for ever.
|
|
6
|
+
// With `--once` it ends at the first thing to act on, for a harness that's woken only when a command exits.
|
|
7
|
+
// It ends, too, when the process that started it does: nobody reads its lines then.
|
|
8
|
+
// While it runs the project's Task tab shows who watches (`watching`, in lib.mjs). Replies the watcher wrote
|
|
9
|
+
// itself are left out where it has a name of its own (BOARD_PROFILE): with none it writes as the person.
|
|
10
|
+
// Usage: watch.mjs [channel, default deictic] [--idle 20m] [--once] [--label k=v ...]
|
|
11
|
+
// Exits 0 after `--once`'s event, 2 when idle, 1 when the board went away.
|
|
6
12
|
import { spawn } from 'node:child_process';
|
|
7
13
|
import { createInterface } from 'node:readline';
|
|
8
14
|
|
|
9
|
-
import { boardUrl, parseArgs, vb, vbCommand } from './lib.mjs';
|
|
15
|
+
import { boardUrl, duration, parseArgs, vb, vbCommand, watching, whoami } from './lib.mjs';
|
|
10
16
|
|
|
11
|
-
const { options, rest } = parseArgs(process.argv.slice(2));
|
|
17
|
+
const { options, rest } = parseArgs(process.argv.slice(2), ['once']);
|
|
12
18
|
const channel = rest[0] ?? 'deictic';
|
|
13
19
|
const labels = (options.label ?? []).flatMap((l) => ['--label', l]);
|
|
20
|
+
const idle = options.idle?.[0] ?? '20m';
|
|
14
21
|
const say = (line) => console.log(line.replace(/\s+/g, ' ').trim());
|
|
15
22
|
const first = (text) => (text.split('\n---')[0] ?? '').trim().slice(0, 160);
|
|
16
23
|
|
|
17
24
|
const ready = vb(['tasks', channel, '--state', 'ready', ...labels]).trim();
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
const me = whoami();
|
|
26
|
+
const unseen = watching(channel, me.profile ?? me.name ?? me.handle ?? me.actor);
|
|
27
|
+
let tail;
|
|
28
|
+
const end = (code) => {
|
|
29
|
+
unseen();
|
|
30
|
+
tail?.removeAllListeners('exit');
|
|
31
|
+
tail?.kill();
|
|
32
|
+
process.exit(code);
|
|
33
|
+
};
|
|
34
|
+
// Stopped by its monitor, where the system says so: the page isn't left thinking someone watches.
|
|
35
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) process.on(signal, () => end(0));
|
|
36
|
+
|
|
37
|
+
// Whoever started the watch reads its lines. With that gone (a session that ended and left the watch behind) no
|
|
38
|
+
// one does, and the page mustn't go on saying an agent watches. A dead parent shows as another parent's ID, except
|
|
39
|
+
// on Windows, where the ID stays and the system is asked whether it's still a process.
|
|
40
|
+
const parent = process.ppid;
|
|
41
|
+
const orphaned = () => {
|
|
42
|
+
if (process.ppid !== parent) return true;
|
|
43
|
+
try {
|
|
44
|
+
process.kill(parent, 0);
|
|
45
|
+
return false;
|
|
46
|
+
} catch (e) {
|
|
47
|
+
return e.code === 'ESRCH';
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
setInterval(() => orphaned() && end(0), 5000);
|
|
51
|
+
|
|
52
|
+
say(`watching ${channel} on ${boardUrl() ?? "the team's board"} as ${me.handle ?? me.actor}`);
|
|
53
|
+
// With no profile, the person's replies and the watcher's own are one actor's: none can be left out.
|
|
54
|
+
if (!me.profile) {
|
|
55
|
+
say(
|
|
56
|
+
`you write as ${me.handle ?? me.actor}, the person's own identity: set BOARD_PROFILE=<your name> (claude, codex) for every vb command, this watch too, and start it again`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
const waiting = (ready ? ready.split('\n') : []).filter((line) => /^#\d+/.test(line));
|
|
60
|
+
for (const line of waiting) say(`ready: ${line}`);
|
|
61
|
+
if (options.once && waiting.length > 0) end(0);
|
|
62
|
+
|
|
63
|
+
/** One thing to act on: all `--once` waits for. */
|
|
64
|
+
const event = (line) => {
|
|
65
|
+
say(line);
|
|
66
|
+
if (options.once) end(0);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// Anything on the channel puts the end off, the watcher's own claims and replies too: it's being worked.
|
|
70
|
+
let quiet;
|
|
71
|
+
const heard = () => {
|
|
72
|
+
clearTimeout(quiet);
|
|
73
|
+
quiet = setTimeout(() => {
|
|
74
|
+
say(
|
|
75
|
+
`idle: nothing on ${channel} in ${idle}, so the watch is over. Don't start it again by yourself: tell the person in a line that you've stopped watching, and watch again when they ask. Only if you're working a task now, start it once more when that's done.`,
|
|
76
|
+
);
|
|
77
|
+
end(2);
|
|
78
|
+
}, duration(idle));
|
|
79
|
+
};
|
|
80
|
+
heard();
|
|
20
81
|
|
|
21
82
|
// What the board says about each thread: its root's first line and where, to name it when a task is made.
|
|
22
83
|
const roots = new Map();
|
|
23
84
|
const [command, argv, spawnOptions] = vbCommand(['tail', channel, ...labels, '--json']);
|
|
24
|
-
|
|
85
|
+
tail = spawn(command, argv, { ...spawnOptions, stdio: ['ignore', 'pipe', 'inherit'] });
|
|
25
86
|
createInterface({ input: tail.stdout }).on('line', (line) => {
|
|
26
87
|
let e;
|
|
27
88
|
try {
|
|
@@ -29,6 +90,7 @@ createInterface({ input: tail.stdout }).on('line', (line) => {
|
|
|
29
90
|
} catch {
|
|
30
91
|
return;
|
|
31
92
|
}
|
|
93
|
+
heard();
|
|
32
94
|
const p = e.payload ?? {};
|
|
33
95
|
if (e.type === 'message.posted' && p.re === null) {
|
|
34
96
|
const at = p.labels?.['deictic.at'];
|
|
@@ -37,15 +99,17 @@ createInterface({ input: tail.stdout }).on('line', (line) => {
|
|
|
37
99
|
`"${first(p.text ?? '')}"${at ? ` at ${at}` : ''}${p.labels?.['deictic.page'] ? ` on ${p.labels['deictic.page']}` : ''}${p.labels?.['deictic.project'] ? ` in ${p.labels['deictic.project']}` : ''}`,
|
|
38
100
|
);
|
|
39
101
|
}
|
|
40
|
-
if (e.type === 'task.created')
|
|
102
|
+
if (e.type === 'task.created') event(`new task #${p.id}: ${roots.get(p.thread) ?? ''}. Read it: vb read ${p.id}`);
|
|
41
103
|
|
|
42
104
|
if (e.type === 'message.posted' && p.re !== null && p.re !== undefined) {
|
|
105
|
+
if (me.profile && p.by?.actor === me.actor) return;
|
|
43
106
|
const by = e.message?.author?.handle ?? p.by?.actor ?? 'someone';
|
|
44
|
-
|
|
107
|
+
event(`reply on #${p.re} by ${by}: ${first(p.text ?? '')}`);
|
|
45
108
|
}
|
|
46
|
-
if (e.type === 'task.canceled')
|
|
109
|
+
if (e.type === 'task.canceled') event(`task #${p.id} canceled: ${p.reason ?? ''}. Stop work on it.`);
|
|
47
110
|
});
|
|
48
111
|
tail.on('exit', (code) => {
|
|
49
112
|
say(`watch ended (vb tail exited ${code}): start it again`);
|
|
113
|
+
unseen();
|
|
50
114
|
process.exit(1);
|
|
51
115
|
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A panel's `away`, kept past a page load: the tab, the element's place and the state it left, for the
|
|
3
|
+
* next page to come back with when what it left for carries on there (a recording does).
|
|
4
|
+
*
|
|
5
|
+
* The state may hold what JSON can't (a drawn screenshot is a `Blob`), so it's in IndexedDB, which is the
|
|
6
|
+
* origin's: the tab's session storage holds the key, so each tab comes back to its own.
|
|
7
|
+
*/
|
|
8
|
+
import type { Target } from '#src/index.ts';
|
|
9
|
+
|
|
10
|
+
/** What the next page needs to come back: which tab, on what, with what. */
|
|
11
|
+
export interface Away {
|
|
12
|
+
tab: string;
|
|
13
|
+
target: Target;
|
|
14
|
+
state: unknown;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const KEY = 'deictic:away';
|
|
18
|
+
const STORE = 'away';
|
|
19
|
+
/** How long one nobody came back to is kept, in milliseconds: its tab was closed. */
|
|
20
|
+
const STALE = 24 * 60 * 60 * 1000;
|
|
21
|
+
|
|
22
|
+
/** One at a time, in the order asked: a `drop` right after a `keep` must not run before it. */
|
|
23
|
+
let last: Promise<unknown> = Promise.resolve();
|
|
24
|
+
|
|
25
|
+
function store<T>(mode: IDBTransactionMode, work: (store: IDBObjectStore) => IDBRequest<T>): Promise<T> {
|
|
26
|
+
const next = last
|
|
27
|
+
.catch(() => {})
|
|
28
|
+
.then(
|
|
29
|
+
() =>
|
|
30
|
+
new Promise<T>((done, fail) => {
|
|
31
|
+
const opening = indexedDB.open('deictic', 1);
|
|
32
|
+
opening.addEventListener('upgradeneeded', () => opening.result.createObjectStore(STORE));
|
|
33
|
+
opening.addEventListener('error', () => fail(opening.error));
|
|
34
|
+
opening.addEventListener('success', () => {
|
|
35
|
+
const db = opening.result;
|
|
36
|
+
const transaction = db.transaction(STORE, mode);
|
|
37
|
+
transaction.addEventListener('complete', () => db.close());
|
|
38
|
+
transaction.addEventListener('abort', () => db.close());
|
|
39
|
+
try {
|
|
40
|
+
const request = work(transaction.objectStore(STORE));
|
|
41
|
+
request.addEventListener('error', () => fail(request.error));
|
|
42
|
+
request.addEventListener('success', () => done(request.result));
|
|
43
|
+
} catch (e) {
|
|
44
|
+
// What can't be copied throws as it's put, here, where nothing would hear it.
|
|
45
|
+
fail(e);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
last = next;
|
|
51
|
+
return next;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const keyOf = (): string | undefined => {
|
|
55
|
+
try {
|
|
56
|
+
return sessionStorage.getItem(KEY) ?? undefined;
|
|
57
|
+
} catch {
|
|
58
|
+
// Storage can be off: nothing is kept past the page, then.
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** Keeps it for the tab's next page. A state that can't be copied (it holds a function, an element) isn't kept, and a page load loses it. */
|
|
64
|
+
export function keepAway(away: Away): void {
|
|
65
|
+
try {
|
|
66
|
+
const key = keyOf() ?? crypto.randomUUID();
|
|
67
|
+
sessionStorage.setItem(KEY, key);
|
|
68
|
+
void store('readwrite', (s) => {
|
|
69
|
+
// Those of tabs long closed go as a new one comes.
|
|
70
|
+
const walk = s.openCursor();
|
|
71
|
+
walk.addEventListener('success', () => {
|
|
72
|
+
const cursor = walk.result;
|
|
73
|
+
if (cursor === null) return;
|
|
74
|
+
if (Date.now() - (cursor.value as { at: number }).at > STALE) cursor.delete();
|
|
75
|
+
cursor.continue();
|
|
76
|
+
});
|
|
77
|
+
return s.put({ ...away, at: Date.now() }, key);
|
|
78
|
+
}).catch(() => {});
|
|
79
|
+
} catch {
|
|
80
|
+
// Not kept, then.
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** What the page before this left, if it left anything. */
|
|
85
|
+
export async function keptAway(): Promise<Away | undefined> {
|
|
86
|
+
const key = keyOf();
|
|
87
|
+
if (key === undefined) return undefined;
|
|
88
|
+
try {
|
|
89
|
+
return await store<Away | undefined>('readonly', (s) => s.get(key));
|
|
90
|
+
} catch {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** It's come back, or there's nothing to come back for. */
|
|
96
|
+
export function dropAway(): void {
|
|
97
|
+
const key = keyOf();
|
|
98
|
+
if (key === undefined) return;
|
|
99
|
+
try {
|
|
100
|
+
sessionStorage.removeItem(KEY);
|
|
101
|
+
} catch {
|
|
102
|
+
// It was readable, so this doesn't happen; and a stale one is dropped by the page that finds it.
|
|
103
|
+
}
|
|
104
|
+
void store('readwrite', (s) => s.delete(key)).catch(() => {});
|
|
105
|
+
}
|
package/src/client/index.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import type { ClientContext, ClientPlugin, LightboxItem, PanelContext, Resumed, Standalone, Target } from '#src/index.ts';
|
|
12
12
|
import { gestureOf, type Shortcut } from '#src/shortcut.ts';
|
|
13
13
|
|
|
14
|
+
import { dropAway, keepAway, keptAway } from './away.ts';
|
|
14
15
|
import { openLightbox } from './lightbox.ts';
|
|
15
16
|
import { STYLE } from './style.ts';
|
|
16
17
|
import { tooltips } from './tooltip.ts';
|
|
@@ -384,15 +385,32 @@ export function start({ base, shortcut: own, plugins: given, server }: StartOpti
|
|
|
384
385
|
onClose: () => (panel = undefined),
|
|
385
386
|
...(resumed === undefined ? {} : { resumed }),
|
|
386
387
|
reopen: (again, element, kept) => {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
return console.warn('deictic: the element is no longer on the page, so the popup stays closed');
|
|
392
|
-
openTab(again, found, at, kept, pointed?.isConnected === true && found === element ? pointed : undefined);
|
|
388
|
+
// Rendered again while away, or gone from the page, which moved on: the popup comes back all the same, on
|
|
389
|
+
// the element as it was left, since what it kept (a recording) is about it wherever the page is now.
|
|
390
|
+
const found = element.isConnected ? element : (sameAs(element)[0] ?? element);
|
|
391
|
+
openTab(again, found, targetOf(found) ?? target, kept, pointed?.isConnected === true && found === element ? pointed : undefined);
|
|
393
392
|
},
|
|
394
393
|
});
|
|
395
394
|
};
|
|
395
|
+
// What the page before this left a panel for (`away`), where that carries on here: the popup comes back when
|
|
396
|
+
// it's done, on the element where this page has it, and on a stand-in for it where it doesn't.
|
|
397
|
+
void keptAway().then((away) => {
|
|
398
|
+
if (away === undefined) return;
|
|
399
|
+
const tab = tabs.find((t) => t.plugin.name === away.tab);
|
|
400
|
+
const task = tab?.plugin.resume?.(contextOf(away.tab));
|
|
401
|
+
if (tab === undefined || task === undefined) return dropAway();
|
|
402
|
+
const back = (resumed: Resumed) => {
|
|
403
|
+
dropAway();
|
|
404
|
+
const { loc, tag } = away.target;
|
|
405
|
+
const absent = document.createElement(tag);
|
|
406
|
+
absent.setAttribute(ATTRIBUTE, `${loc.file}:${loc.line}:${loc.column}`);
|
|
407
|
+
openTab(tab, sameAs(absent).find((el) => el.localName === tag) ?? absent, away.target, resumed);
|
|
408
|
+
};
|
|
409
|
+
task.then(
|
|
410
|
+
(result) => back({ state: away.state, result }),
|
|
411
|
+
(e: unknown) => back({ state: away.state, problem: messageOf(e) }),
|
|
412
|
+
);
|
|
413
|
+
});
|
|
396
414
|
function openAt(name: string, given: Element): boolean {
|
|
397
415
|
const tab = tabs.find((t) => t.plugin.name === name);
|
|
398
416
|
const el = given.isConnected ? given : (sameAs(given)[0] ?? undefined);
|
|
@@ -482,6 +500,9 @@ function openPanel({
|
|
|
482
500
|
close.classList.add('close');
|
|
483
501
|
head.append(...buttons.map((b) => b.el), close);
|
|
484
502
|
bar.append(where, undo, redo);
|
|
503
|
+
// Back from `away` on a page that doesn't have the element: said, as nothing on it is outlined.
|
|
504
|
+
if (!element.isConnected)
|
|
505
|
+
where.after(Object.assign(document.createElement('span'), { className: 'absent', textContent: 'not on this page' }));
|
|
485
506
|
const body = div('body');
|
|
486
507
|
body.setAttribute('role', 'tabpanel');
|
|
487
508
|
const status = div('status');
|
|
@@ -616,9 +637,15 @@ function openPanel({
|
|
|
616
637
|
away: (state, task) => {
|
|
617
638
|
const tab = current;
|
|
618
639
|
done(true);
|
|
640
|
+
// For the tab's next page too, should this one go before the task is done. Not one a page pinned: that's the page's own.
|
|
641
|
+
if (!pinned) keepAway({ tab: tab.plugin.name, target, state });
|
|
642
|
+
const back = (resumed: Resumed) => {
|
|
643
|
+
if (!pinned) dropAway();
|
|
644
|
+
reopen(tab, element, resumed);
|
|
645
|
+
};
|
|
619
646
|
void task().then(
|
|
620
|
-
(result) =>
|
|
621
|
-
(e: unknown) =>
|
|
647
|
+
(result) => back({ state, result }),
|
|
648
|
+
(e: unknown) => back({ state, problem: messageOf(e) }),
|
|
622
649
|
);
|
|
623
650
|
},
|
|
624
651
|
element,
|
|
@@ -715,7 +742,11 @@ function keepInView(panel: HTMLElement, body: HTMLElement, handle: HTMLElement,
|
|
|
715
742
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
716
743
|
// Where the element was last seen: one gone from the page leaves the popup where it was.
|
|
717
744
|
let r = element.getBoundingClientRect();
|
|
718
|
-
|
|
745
|
+
// An element that's not on the page (back from `away`, on another) has no place to be beside: as if dragged to the
|
|
746
|
+
// middle, toward the top.
|
|
747
|
+
let moved: { left: number; top: number } | undefined = element.isConnected
|
|
748
|
+
? undefined
|
|
749
|
+
: { left: (document.documentElement.clientWidth - panel.offsetWidth) / 2, top: document.documentElement.clientHeight / 5 };
|
|
719
750
|
const fit = () => {
|
|
720
751
|
cancelAnimationFrame(frame);
|
|
721
752
|
clearTimeout(timer);
|
package/src/client/style.ts
CHANGED
|
@@ -105,6 +105,7 @@ export const STYLE = `
|
|
|
105
105
|
.bar .where svg { flex: none; }
|
|
106
106
|
.bar .where:hover, .bar .where:focus-visible { color: var(--deictic-fg); }
|
|
107
107
|
.bar .where:hover span { text-decoration: underline; }
|
|
108
|
+
.bar .absent { flex: none; margin-right: 6px; font-size: 12px; color: var(--deictic-muted); }
|
|
108
109
|
.lightbox {
|
|
109
110
|
position: fixed;
|
|
110
111
|
inset: 0;
|
package/src/index.ts
CHANGED
|
@@ -191,7 +191,11 @@ export interface LightboxOptions {
|
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
export interface PanelContext<Model, Op> extends ClientContext {
|
|
194
|
-
/**
|
|
194
|
+
/**
|
|
195
|
+
* The element clicked: the one the source marked, under the pointer or around what is. Back from `away`
|
|
196
|
+
* it may be off the page (`isConnected` is false), where the page moved on without it: the element as it
|
|
197
|
+
* was left, or after a page load an empty one of its tag and mark. `elements` is then empty.
|
|
198
|
+
*/
|
|
195
199
|
element: Element;
|
|
196
200
|
/**
|
|
197
201
|
* What was under the pointer, where it isn't `element` but inside it: markup nothing marked, as a
|
|
@@ -215,7 +219,9 @@ export interface PanelContext<Model, Op> extends ClientContext {
|
|
|
215
219
|
* Leaves the popup to do something on the page, then comes back: closes it, runs `task` (a recording, a
|
|
216
220
|
* pick of another element), and opens it again at this tab on this element. The next mount gets
|
|
217
221
|
* `resumed`: the `state` kept now (what was typed, what's attached), and what `task` answered, or why
|
|
218
|
-
* it failed. The state stays in the page, as it is: no need for JSON.
|
|
222
|
+
* it failed. The state stays in the page, as it is: no need for JSON. It's also kept for the tab's next
|
|
223
|
+
* page, as a structured clone, where it can be one: after a page load, the plugin's `resume` says whether
|
|
224
|
+
* the task carries on, and the popup comes back there.
|
|
219
225
|
*/
|
|
220
226
|
away: <T>(state: unknown, task: () => Promise<T>) => void;
|
|
221
227
|
/** Set when this mount is the panel coming back from `away`. */
|
|
@@ -240,6 +246,12 @@ export interface ClientPlugin<Model = unknown, Op = unknown, Api = unknown> {
|
|
|
240
246
|
* plugin's API to the others in the page, at once: one that needs time keeps its promises inside it.
|
|
241
247
|
*/
|
|
242
248
|
setup?(context: ClientContext): Api;
|
|
249
|
+
/**
|
|
250
|
+
* Asked as a page starts where the page before it left this plugin's panel `away`: the task it left for,
|
|
251
|
+
* where that carries on in this page (a recording does), or nothing where it ended with the page. When it's
|
|
252
|
+
* done the popup opens at this tab with `resumed`, on the element where this page has it and without where not.
|
|
253
|
+
*/
|
|
254
|
+
resume?(context: ClientContext): Promise<unknown> | undefined;
|
|
243
255
|
/** Draws into `panel`, inside deictic's shadow root. Returns what to undo on the page when the panel closes. */
|
|
244
256
|
mount?: (panel: HTMLElement, context: PanelContext<Model, Op>) => (() => void) | void;
|
|
245
257
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** The logs plugin's page half: rrweb's console plugin, imported as a recording first asks for it. */
|
|
2
|
+
import { defineClientPlugin } from '#src/index.ts';
|
|
3
|
+
import type { Recorded } from '#src/plugins/recordings/index.ts';
|
|
4
|
+
|
|
5
|
+
import type { Level } from './index.ts';
|
|
6
|
+
|
|
7
|
+
export default defineClientPlugin<never, never, Recorded>({
|
|
8
|
+
name: 'logs',
|
|
9
|
+
setup: ({ options }) => ({
|
|
10
|
+
plugin: async () => {
|
|
11
|
+
const { getRecordConsolePlugin } = await import('@rrweb/rrweb-plugin-console-record').catch((e: unknown) => {
|
|
12
|
+
throw new Error('logs needs @rrweb/rrweb-plugin-console-record: add it to your devDependencies', { cause: e });
|
|
13
|
+
});
|
|
14
|
+
const { levels } = (options ?? {}) as { levels?: Level[] };
|
|
15
|
+
return getRecordConsolePlugin(levels === undefined ? {} : { level: levels });
|
|
16
|
+
},
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `deictic/logs`: what the page logs while it's recorded, and the errors nothing caught, in the recording, each at
|
|
3
|
+
* its moment. No tab, and nothing of its own: it hands the recordings plugin rrweb's console plugin
|
|
4
|
+
* (`@rrweb/rrweb-plugin-console-record`, an optional peer), whose events are rrweb's (`rrweb/console@1`).
|
|
5
|
+
*
|
|
6
|
+
* A wrapped console names the wrapper, not the caller, as each line's source in the browser's tools. rrweb wraps it
|
|
7
|
+
* as a recording starts and puts it back as it stops, so it's the page's own the rest of the time. Leave the plugin
|
|
8
|
+
* out and it never is.
|
|
9
|
+
*/
|
|
10
|
+
import { definePlugin } from '#src/index.ts';
|
|
11
|
+
import type { Recorded } from '#src/plugins/recordings/index.ts';
|
|
12
|
+
|
|
13
|
+
/** What of the console is kept: its methods, by name. */
|
|
14
|
+
export type Level =
|
|
15
|
+
| 'assert'
|
|
16
|
+
| 'count'
|
|
17
|
+
| 'countReset'
|
|
18
|
+
| 'debug'
|
|
19
|
+
| 'dir'
|
|
20
|
+
| 'dirxml'
|
|
21
|
+
| 'error'
|
|
22
|
+
| 'group'
|
|
23
|
+
| 'groupCollapsed'
|
|
24
|
+
| 'info'
|
|
25
|
+
| 'log'
|
|
26
|
+
| 'table'
|
|
27
|
+
| 'time'
|
|
28
|
+
| 'timeEnd'
|
|
29
|
+
| 'timeLog'
|
|
30
|
+
| 'trace'
|
|
31
|
+
| 'warn';
|
|
32
|
+
|
|
33
|
+
export interface LogsOptions {
|
|
34
|
+
/**
|
|
35
|
+
* The console's methods kept, `['warn', 'error']` for the least: every one that says something by default. Errors
|
|
36
|
+
* nothing caught, and rejections nothing handled, come with `error`.
|
|
37
|
+
*/
|
|
38
|
+
levels?: Level[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
declare module 'deictic' {
|
|
42
|
+
interface ClientApis {
|
|
43
|
+
logs: Recorded;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function logs(options: LogsOptions = {}) {
|
|
48
|
+
return definePlugin<never, never>({
|
|
49
|
+
name: 'logs',
|
|
50
|
+
client: 'deictic/logs/client',
|
|
51
|
+
clientOptions: { levels: options.levels },
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default logs;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The network plugin's page half: rrweb's network plugin, imported as a recording first asks for it, with every
|
|
3
|
+
* request masked before rrweb has it.
|
|
4
|
+
*/
|
|
5
|
+
import { defineClientPlugin } from '#src/index.ts';
|
|
6
|
+
import type { Recorded } from '#src/plugins/recordings/index.ts';
|
|
7
|
+
|
|
8
|
+
import type { Resolved } from './index.ts';
|
|
9
|
+
import { maskRequest } from './mask.ts';
|
|
10
|
+
|
|
11
|
+
export default defineClientPlugin<never, never, Recorded>({
|
|
12
|
+
name: 'network',
|
|
13
|
+
setup: ({ options }) => ({
|
|
14
|
+
plugin: async ({ sinceLoad }) => {
|
|
15
|
+
const { getRecordNetworkPlugin } = await import('@rrweb/rrweb-plugin-network-record').catch((e: unknown) => {
|
|
16
|
+
throw new Error('network needs @rrweb/rrweb-plugin-network-record: add it to your devDependencies', { cause: e });
|
|
17
|
+
});
|
|
18
|
+
const { initiators, headers, body, mask, ignore } = options as Resolved;
|
|
19
|
+
type Options = NonNullable<Parameters<typeof getRecordNetworkPlugin>[0]>;
|
|
20
|
+
return getRecordNetworkPlugin({
|
|
21
|
+
initiatorTypes: initiators as NonNullable<Options['initiatorTypes']>,
|
|
22
|
+
recordHeaders: headers,
|
|
23
|
+
recordBody: body,
|
|
24
|
+
// What the page asked for as it loaded, where the recording was going by then: before, it's not the recording's.
|
|
25
|
+
recordInitialRequests: sinceLoad,
|
|
26
|
+
transformRequestFn: (request) => maskRequest(request, { mask, ignore }),
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `deictic/network`: the requests the page makes while it's recorded, in the recording, each as it ends. No tab,
|
|
3
|
+
* and nothing of its own: it hands the recordings plugin rrweb's network plugin
|
|
4
|
+
* (`@rrweb/rrweb-plugin-network-record`, an optional peer), whose events are rrweb's (`rrweb/network@1`).
|
|
5
|
+
*
|
|
6
|
+
* By default a request is its URL, its status and its timing, which the browser reports of itself
|
|
7
|
+
* (`PerformanceObserver`): nothing of the page's is wrapped, and no method is known. `headers` and `body` add those
|
|
8
|
+
* and the method, for which rrweb wraps `fetch` and `XMLHttpRequest` while a recording is going, and only then.
|
|
9
|
+
*
|
|
10
|
+
* Everything kept is masked first (`mask.ts`): a secret in a URL's query, a header or a body's field is blanked by
|
|
11
|
+
* its name, and deictic's own requests are left out.
|
|
12
|
+
*/
|
|
13
|
+
import { definePlugin } from '#src/index.ts';
|
|
14
|
+
import type { Recorded } from '#src/plugins/recordings/index.ts';
|
|
15
|
+
|
|
16
|
+
export { MASKED, maskBody, maskHeaders, maskRequest, maskUrl, sensitive } from './mask.ts';
|
|
17
|
+
|
|
18
|
+
export interface NetworkOptions {
|
|
19
|
+
/**
|
|
20
|
+
* What made the requests kept, as the browser names it (a resource's `initiatorType`): `['fetch',
|
|
21
|
+
* 'xmlhttprequest']` by default, the page's own calls. `'img'`, `'script'`, `'css'` and the like add what it loads.
|
|
22
|
+
*/
|
|
23
|
+
initiators?: string[];
|
|
24
|
+
/** Keeps each request's and response's headers, the secret ones blanked (`Authorization`, `Cookie`, …): not by default. */
|
|
25
|
+
headers?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Keeps each request's and response's body, cut at 10,000 characters, secrets blanked by name where it's JSON or a
|
|
28
|
+
* form's fields: not by default. `true` is JSON, text and forms; a list names the content types, by a part of each.
|
|
29
|
+
*/
|
|
30
|
+
body?: boolean | string[];
|
|
31
|
+
/** More names whose values are blanked, in a query, a header or a body: a part of the name, in any case (`['email']`). */
|
|
32
|
+
mask?: string[];
|
|
33
|
+
/** Requests left out whole: a part of the URL (`['/analytics', 'sentry.io']`). */
|
|
34
|
+
ignore?: string[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The options as the page half gets them. */
|
|
38
|
+
export interface Resolved {
|
|
39
|
+
initiators: string[];
|
|
40
|
+
headers: boolean;
|
|
41
|
+
body: false | string[];
|
|
42
|
+
mask: string[];
|
|
43
|
+
ignore: string[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare module 'deictic' {
|
|
47
|
+
interface ClientApis {
|
|
48
|
+
network: Recorded;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The bodies kept with `body: true`: what reads as text. */
|
|
53
|
+
const TEXT = ['application/json', '+json', 'text/', 'application/x-www-form-urlencoded', 'application/xml'];
|
|
54
|
+
|
|
55
|
+
export function network(options: NetworkOptions = {}) {
|
|
56
|
+
return definePlugin<never, never>({
|
|
57
|
+
name: 'network',
|
|
58
|
+
client: 'deictic/network/client',
|
|
59
|
+
clientOptions: {
|
|
60
|
+
initiators: options.initiators ?? ['fetch', 'xmlhttprequest'],
|
|
61
|
+
headers: options.headers ?? false,
|
|
62
|
+
body: options.body === true ? TEXT : (options.body ?? false),
|
|
63
|
+
mask: options.mask ?? [],
|
|
64
|
+
ignore: options.ignore ?? [],
|
|
65
|
+
} satisfies Resolved,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default network;
|