deictic 0.1.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.
Files changed (166) hide show
  1. package/API.md +303 -0
  2. package/README.md +56 -104
  3. package/dist/annotations/index.d.ts +1 -1
  4. package/dist/astro.d.ts +1 -1
  5. package/dist/bun.d.ts +1 -1
  6. package/dist/bun.js +2 -2
  7. package/dist/client/index.d.ts +4 -2
  8. package/dist/client/index.d.ts.map +1 -1
  9. package/dist/client/index.js +130 -16
  10. package/dist/client/index.js.map +1 -1
  11. package/dist/index.d.ts +21 -218
  12. package/dist/index.js.map +1 -1
  13. package/dist/loader.js +1 -1
  14. package/dist/logs/client.d.ts +4 -0
  15. package/dist/logs/client.d.ts.map +1 -0
  16. package/dist/logs/client.js +16 -0
  17. package/dist/logs/client.js.map +1 -0
  18. package/dist/logs/index.d.ts +18 -0
  19. package/dist/logs/index.d.ts.map +1 -0
  20. package/dist/logs/index.js +21 -0
  21. package/dist/logs/index.js.map +1 -0
  22. package/dist/network/client.d.ts +4 -0
  23. package/dist/network/client.d.ts.map +1 -0
  24. package/dist/network/client.js +29 -0
  25. package/dist/network/client.js.map +1 -0
  26. package/dist/network/index.d.ts +2 -0
  27. package/dist/network/index.js +39 -0
  28. package/dist/network/index.js.map +1 -0
  29. package/dist/next.d.ts +1 -1
  30. package/dist/next.js +2 -2
  31. package/dist/recommended/index.d.ts +15 -5
  32. package/dist/recommended/index.d.ts.map +1 -1
  33. package/dist/recommended/index.js +10 -3
  34. package/dist/recommended/index.js.map +1 -1
  35. package/dist/recordings/client.d.ts +1 -1
  36. package/dist/recordings/client.d.ts.map +1 -1
  37. package/dist/recordings/client.js +177 -48
  38. package/dist/recordings/client.js.map +1 -1
  39. package/dist/recordings/index.d.ts +2 -2
  40. package/dist/recordings/index.js +3 -3
  41. package/dist/screenshots/client.d.ts +7 -1
  42. package/dist/screenshots/client.d.ts.map +1 -1
  43. package/dist/screenshots/client.js +36 -4
  44. package/dist/screenshots/client.js.map +1 -1
  45. package/dist/screenshots/dom.d.ts +1 -1
  46. package/dist/screenshots/dom.d.ts.map +1 -1
  47. package/dist/screenshots/dom.js +1 -28
  48. package/dist/screenshots/dom.js.map +1 -1
  49. package/dist/screenshots/index.d.ts +1 -1
  50. package/dist/screenshots/index.js +2 -2
  51. package/dist/screenshots/index.js.map +1 -1
  52. package/dist/screenshots/rrweb.d.ts +2 -2
  53. package/dist/screenshots/rrweb.js +5 -1
  54. package/dist/screenshots/rrweb.js.map +1 -1
  55. package/dist/{endpoints.js → shared/endpoints.js} +1 -1
  56. package/dist/shared/endpoints.js.map +1 -0
  57. package/dist/shared/index.d.ts +238 -0
  58. package/dist/shared/index.d.ts.map +1 -0
  59. package/dist/{index3.d.ts → shared/index2.d.ts} +3 -1
  60. package/dist/shared/index2.d.ts.map +1 -0
  61. package/dist/shared/index3.d.ts +112 -0
  62. package/dist/shared/index3.d.ts.map +1 -0
  63. package/dist/shared/index4.d.ts +64 -0
  64. package/dist/shared/index4.d.ts.map +1 -0
  65. package/dist/shared/index5.d.ts +220 -0
  66. package/dist/shared/index5.d.ts.map +1 -0
  67. package/dist/{index5.d.ts → shared/index6.d.ts} +2 -2
  68. package/dist/shared/index6.d.ts.map +1 -0
  69. package/dist/{integration.d.ts → shared/integration.d.ts} +4 -3
  70. package/dist/shared/integration.d.ts.map +1 -0
  71. package/dist/{integration.js → shared/integration.js} +5 -3
  72. package/dist/shared/integration.js.map +1 -0
  73. package/dist/{kept.js → shared/kept.js} +2 -2
  74. package/dist/shared/kept.js.map +1 -0
  75. package/dist/{marks.js → shared/marks.js} +6 -1
  76. package/dist/shared/marks.js.map +1 -0
  77. package/dist/shared/mask.js +107 -0
  78. package/dist/shared/mask.js.map +1 -0
  79. package/dist/{playwright.js → shared/playwright.js} +19 -4
  80. package/dist/shared/playwright.js.map +1 -0
  81. package/dist/shared/recordings.js +437 -0
  82. package/dist/shared/recordings.js.map +1 -0
  83. package/dist/shared/shortcut.js.map +1 -0
  84. package/dist/shared/tasks.js +632 -0
  85. package/dist/shared/tasks.js.map +1 -0
  86. package/dist/shared/waveform.js.map +1 -0
  87. package/dist/tailwind/client.d.ts +1 -1
  88. package/dist/tailwind/index.d.ts +1 -1
  89. package/dist/tasks/client.d.ts +1 -1
  90. package/dist/tasks/client.d.ts.map +1 -1
  91. package/dist/tasks/client.js +272 -57
  92. package/dist/tasks/client.js.map +1 -1
  93. package/dist/tasks/index.d.ts +2 -159
  94. package/dist/tasks/index.js +1 -348
  95. package/dist/vite.d.ts +11 -12
  96. package/dist/vite.d.ts.map +1 -1
  97. package/dist/vite.js +21 -4
  98. package/dist/vite.js.map +1 -1
  99. package/dist/voice/client.d.ts.map +1 -1
  100. package/dist/voice/client.js +36 -15
  101. package/dist/voice/client.js.map +1 -1
  102. package/dist/voice/index.d.ts +6 -1
  103. package/dist/voice/index.d.ts.map +1 -1
  104. package/dist/voice/index.js +13 -3
  105. package/dist/voice/index.js.map +1 -1
  106. package/dist/webpack.d.ts +1 -1
  107. package/dist/webpack.js +2 -2
  108. package/package.json +41 -2
  109. package/skills/deictic/SKILL.md +20 -14
  110. package/skills/deictic/references/install.md +32 -10
  111. package/skills/deictic/references/recordings.md +29 -0
  112. package/skills/deictic/references/tasks.md +49 -21
  113. package/skills/deictic/references/watch.md +38 -11
  114. package/skills/deictic/scripts/lib.mjs +88 -4
  115. package/skills/deictic/scripts/recording.mjs +84 -4
  116. package/skills/deictic/scripts/task.mjs +36 -7
  117. package/skills/deictic/scripts/vb.mjs +12 -0
  118. package/skills/deictic/scripts/watch.mjs +74 -10
  119. package/src/client/away.ts +105 -0
  120. package/src/client/index.ts +60 -16
  121. package/src/client/style.ts +1 -0
  122. package/src/index.ts +21 -2
  123. package/src/plugins/logs/client.ts +18 -0
  124. package/src/plugins/logs/index.ts +55 -0
  125. package/src/plugins/network/client.ts +30 -0
  126. package/src/plugins/network/index.ts +69 -0
  127. package/src/plugins/network/mask.ts +133 -0
  128. package/src/plugins/recommended/index.ts +14 -1
  129. package/src/plugins/recordings/client.ts +220 -40
  130. package/src/plugins/recordings/index.ts +111 -25
  131. package/src/plugins/recordings/marks.ts +6 -0
  132. package/src/plugins/recordings/replay.ts +159 -10
  133. package/src/plugins/screenshots/client.ts +38 -2
  134. package/src/plugins/screenshots/dom.ts +1 -32
  135. package/src/plugins/screenshots/index.ts +2 -0
  136. package/src/plugins/screenshots/playwright.ts +15 -4
  137. package/src/plugins/screenshots/rrweb.ts +2 -1
  138. package/src/plugins/tasks/client.ts +273 -41
  139. package/src/plugins/tasks/index.ts +207 -47
  140. package/src/plugins/tasks/local.ts +170 -0
  141. package/src/plugins/tasks/watchers.ts +36 -0
  142. package/src/plugins/voice/client.ts +33 -10
  143. package/src/plugins/voice/index.ts +21 -4
  144. package/src/tools/integration.ts +5 -3
  145. package/src/tools/kept.ts +2 -2
  146. package/src/vite.ts +23 -4
  147. package/dist/endpoints.js.map +0 -1
  148. package/dist/index.d.ts.map +0 -1
  149. package/dist/index2.d.ts +0 -23
  150. package/dist/index3.d.ts.map +0 -1
  151. package/dist/index4.d.ts +0 -74
  152. package/dist/index4.d.ts.map +0 -1
  153. package/dist/index5.d.ts.map +0 -1
  154. package/dist/integration.d.ts.map +0 -1
  155. package/dist/integration.js.map +0 -1
  156. package/dist/kept.js.map +0 -1
  157. package/dist/marks.js.map +0 -1
  158. package/dist/playwright.js.map +0 -1
  159. package/dist/recordings.js +0 -235
  160. package/dist/recordings.js.map +0 -1
  161. package/dist/shortcut.js.map +0 -1
  162. package/dist/tasks/index.d.ts.map +0 -1
  163. package/dist/tasks/index.js.map +0 -1
  164. package/dist/waveform.js.map +0 -1
  165. /package/dist/{shortcut.js → shared/shortcut.js} +0 -0
  166. /package/dist/{waveform.js → shared/waveform.js} +0 -0
@@ -1,7 +1,7 @@
1
1
  // What the scripts share: the board's CLI, the project's `.deictic/` folders, and finding a recording or a
2
2
  // voice clip by a task's ID, a recording's ID, a replay URL or a path. Node 20 or Bun; no dependencies.
3
3
  import { spawnSync } from 'node:child_process';
4
- import { existsSync, mkdtempSync, readdirSync, readFileSync } from 'node:fs';
4
+ import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
5
5
  import { tmpdir } from 'node:os';
6
6
  import { delimiter, dirname, join, resolve } from 'node:path';
7
7
  import { pathToFileURL } from 'node:url';
@@ -55,12 +55,90 @@ export function deicticDirs() {
55
55
  }
56
56
 
57
57
  /**
58
- * How to run the board's CLI: `vb` from the project's dependencies or the PATH, with the environment's board,
59
- * as `spawn`'s command, arguments and options.
58
+ * The board's URL: `BOARD_URL`, or with none, the board the dev server started for the project, which
59
+ * `.deictic/board.json` names. Nothing where there's neither: `vb` then finds the team's board.
60
+ */
61
+ export function boardUrl() {
62
+ if (process.env.BOARD_URL) return process.env.BOARD_URL;
63
+ for (const dir of deicticDirs()) {
64
+ try {
65
+ const { url } = JSON.parse(readFileSync(join(dir, 'board.json'), 'utf8'));
66
+ if (typeof url === 'string') return url;
67
+ } catch {
68
+ // No board of this project's own: the next one's, or the team's.
69
+ }
70
+ }
71
+ return undefined;
72
+ }
73
+
74
+ /** How often a watch says it's still there, and so how soon the page knows of one that was killed (three missed). */
75
+ const BEAT = 20_000;
76
+
77
+ /**
78
+ * Tells the project's dev server that `name` watches `channel`, which a board can't say: a file under
79
+ * `.deictic/watchers`, written again every `BEAT`, that the Task tab reads. In the `.deictic/` whose board this
80
+ * is, or in each one near here where the board is the environment's. Answers what takes it back.
81
+ */
82
+ export function watching(channel, name) {
83
+ const url = boardUrl();
84
+ const dirs = deicticDirs();
85
+ const boardIn = (dir) => {
86
+ try {
87
+ return JSON.parse(readFileSync(join(dir, 'board.json'), 'utf8')).url;
88
+ } catch {
89
+ return undefined;
90
+ }
91
+ };
92
+ const own = dirs.filter((dir) => boardIn(dir) === url);
93
+ const files = (own.length > 0 ? own : dirs).map((dir) => join(dir, 'watchers', `${process.pid}.json`));
94
+ const beat = () => {
95
+ for (const file of files) {
96
+ try {
97
+ mkdirSync(dirname(file), { recursive: true });
98
+ writeFileSync(file, `${JSON.stringify({ name, channel, pid: process.pid, at: Date.now() })}\n`);
99
+ } catch {
100
+ // A folder that can't be written to: the watch goes on, unseen.
101
+ }
102
+ }
103
+ };
104
+ beat();
105
+ const timer = setInterval(beat, BEAT);
106
+ return () => {
107
+ clearInterval(timer);
108
+ for (const file of files) rmSync(file, { force: true });
109
+ };
110
+ }
111
+
112
+ /** `30m`, `45s`, `1h` or a bare number of seconds, as milliseconds. */
113
+ export function duration(text) {
114
+ const [, n, unit = 's'] = /^(\d+(?:\.\d+)?)([smh])?$/.exec(text) ?? [];
115
+ if (n === undefined) fail(`"${text}" isn't a duration: 30m, 45s, 1h, or seconds as a number.`);
116
+ return Number(n) * { s: 1000, m: 60_000, h: 3_600_000 }[unit];
117
+ }
118
+
119
+ /** The project's own `@vercel/board` CLI, as a script: from here, above, or beside a `.deictic/` near here. */
120
+ function vbScript() {
121
+ for (const dir of new Set([...upFrom(), ...deicticDirs().map(dirname)])) {
122
+ const pkg = join(dir, 'node_modules', '@vercel', 'board', 'package.json');
123
+ if (!existsSync(pkg)) continue;
124
+ const { bin } = JSON.parse(readFileSync(pkg, 'utf8'));
125
+ const entry = typeof bin === 'string' ? bin : bin?.vb;
126
+ if (typeof entry === 'string') return join(dirname(pkg), entry);
127
+ }
128
+ return undefined;
129
+ }
130
+
131
+ /**
132
+ * How to run the board's CLI, with the environment's board or the project's own, as `spawn`'s command,
133
+ * arguments and options: the project's `@vercel/board`, run by this runtime, so it needn't be on the PATH and
134
+ * no shell reads the arguments; with none installed, `vb` from the PATH.
60
135
  */
61
136
  export function vbCommand(args) {
62
137
  const bins = [...upFrom()].map((d) => join(d, 'node_modules', '.bin'));
63
- const env = { ...process.env, PATH: [...bins, process.env.PATH].join(delimiter) };
138
+ const url = boardUrl();
139
+ const env = { ...process.env, ...(url === undefined ? {} : { BOARD_URL: url }), PATH: [...bins, process.env.PATH].join(delimiter) };
140
+ const script = vbScript();
141
+ if (script !== undefined) return [process.execPath, [script, ...args], { env }];
64
142
  // npm's shims on Windows are .cmd files, which only a shell runs; the arguments here are IDs and names.
65
143
  if (process.platform === 'win32') return [`vb ${args.map((a) => `"${a}"`).join(' ')}`, [], { env, shell: true }];
66
144
  return ['vb', args, { env }];
@@ -79,6 +157,12 @@ export function vb(args, { json = false } = {}) {
79
157
  return json ? JSON.parse(run.stdout) : run.stdout;
80
158
  }
81
159
 
160
+ /**
161
+ * Who the CLI writes as: `{ actor, handle, profile }`. `profile` is the name `BOARD_PROFILE` (or `--as`) gave, and
162
+ * `null` without one: then what's written is the person's own, as the board sees it.
163
+ */
164
+ export const whoami = () => vb(['whoami'], { json: true });
165
+
82
166
  /** A task's root message, by its ID (`68` or `#68`). */
83
167
  export const task = (id) => vb(['read', String(id).replace(/^#/, '')], { json: true }).message;
84
168
 
@@ -1,10 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
  // A recording as a timeline: the page, each click and field typed in (with the element's place in the source),
3
3
  // scrolls, resizes, each change to the marks (what was drawn, where, and the notes' text), the voice clips,
4
- // and the end. Usage: recording.mjs <task | replay URL | recording ID | file> [--nth 2] [--json]
4
+ // the page's console and its requests where the project records them, and the end.
5
+ // Usage: recording.mjs <task | replay URL | recording ID | file> [--nth 2] [--json]
6
+ // And to ask for a part of it, in any mix:
7
+ // --only console,request these kinds of line (`console` is every level; also page, click, input, scroll, resize, marks, voice)
8
+ // --problems errors, warnings and requests that failed
9
+ // --from 10 --to 15 a stretch, in seconds; --around 12 is the 3 seconds either side
10
+ // --grep text lines with this in them, in any case
11
+ // --full all of each line: where it was logged from, a request's headers and bodies
5
12
  import { clock, fail, loadRecording, parseArgs } from './lib.mjs';
6
13
 
7
- const { options, rest } = parseArgs(process.argv.slice(2), ['json']);
14
+ const { options, rest } = parseArgs(process.argv.slice(2), ['json', 'problems', 'full']);
8
15
  const { kept, id, replay, task } = await loadRecording(rest[0], Number(options.nth?.[0] ?? 1));
9
16
  const { events } = kept;
10
17
  if (!Array.isArray(events) || events.length === 0) fail(`Recording ${id} has no events.`);
@@ -124,6 +131,38 @@ for (const e of events) {
124
131
  }
125
132
  marks = now;
126
133
  }
134
+ // The address changed with no load: a route of the app's.
135
+ if (e.type === 5 && e.data.tag === 'deictic.page') push(t, 'page', `${e.data.payload.href} (a route change, no load)`);
136
+ // The page's console, and errors nothing caught (rrweb's console plugin): each argument as JSON, a string in
137
+ // quotes, and where it was logged from, which goes under a warning or an error.
138
+ if (e.type === 6 && e.data.plugin === 'rrweb/console@1') {
139
+ const { level, payload, trace } = e.data.payload;
140
+ const plain = (arg) => {
141
+ try {
142
+ const value = JSON.parse(arg);
143
+ return typeof value === 'string' ? value : arg;
144
+ } catch {
145
+ return arg;
146
+ }
147
+ };
148
+ push(t, `console.${level}`, (payload ?? []).map(plain).join(' '), {
149
+ trace: trace ?? [],
150
+ ...(['error', 'assert', 'warn'].includes(level) ? { problem: true } : {}),
151
+ });
152
+ }
153
+ // The page's requests (rrweb's network plugin), masked as they were kept: each as it ended. One the browser
154
+ // reported of itself has no method; headers and bodies, where kept, are in `--json`.
155
+ if (e.type === 6 && e.data.plugin === 'rrweb/network@1') {
156
+ for (const r of e.data.payload.requests ?? []) {
157
+ const took = Number.isFinite(r.duration) ? ` in ${Math.round(r.duration)} ms` : '';
158
+ const status = r.status ? r.status : 'no status (failed, blocked, or another origin’s)';
159
+ push(t, 'request', `${r.method ?? r.initiatorType ?? ''} ${r.name} → ${status}${took}`.trim(), {
160
+ request: r,
161
+ ...(r.status >= 400 ? { problem: true } : {}),
162
+ ...(e.data.payload.isInitial ? { before: 'made as the page loaded, before this moment' } : {}),
163
+ });
164
+ }
165
+ }
127
166
  if (e.type === 5 && e.data.tag === 'deictic.end') push(t, 'end', 'recording stopped');
128
167
  if (e.type !== 3) continue;
129
168
  const d = e.data;
@@ -165,6 +204,30 @@ flushTyping();
165
204
  for (const c of kept.voice ?? []) push(c.at, 'voice', `clip ${c.id}, ${clock(c.duration)} long, until ${clock(c.at + c.duration)}`);
166
205
  timeline.sort((a, b) => a.t - b.t);
167
206
 
207
+ // The part asked for. Seconds, as the replay's `?t=` and `frame.mjs --at` take them.
208
+ const seconds = (name) => {
209
+ const given = options[name]?.[0];
210
+ if (given === undefined) return undefined;
211
+ const value = Number(given);
212
+ if (!Number.isFinite(value)) fail(`--${name} takes seconds from the recording's start, as 12 or 4.5: not ${given}`);
213
+ return value * 1000;
214
+ };
215
+ const around = seconds('around');
216
+ const from = seconds('from') ?? (around === undefined ? undefined : around - 3000);
217
+ const to = seconds('to') ?? (around === undefined ? undefined : around + 3000);
218
+ const only = (options.only ?? []).flatMap((list) => String(list).split(',')).filter(Boolean);
219
+ const grep = options.grep?.[0]?.toLowerCase();
220
+ // `console` is every level's lines, `click` a right or a double one too.
221
+ const isKind = (kind, asked) => kind === asked || kind.startsWith(`${asked}.`) || kind.endsWith(`-${asked}`);
222
+ const shown = timeline.filter(
223
+ (e) =>
224
+ (only.length === 0 || only.some((asked) => isKind(e.kind, asked))) &&
225
+ (!options.problems || e.problem === true) &&
226
+ (from === undefined || e.t >= from) &&
227
+ (to === undefined || e.t <= to) &&
228
+ (grep === undefined || `${e.kind} ${e.text}`.toLowerCase().includes(grep)),
229
+ );
230
+
168
231
  const head = {
169
232
  id,
170
233
  page: kept.page,
@@ -176,11 +239,28 @@ const head = {
176
239
  task: task?.id,
177
240
  };
178
241
  if (options.json) {
179
- console.log(JSON.stringify({ ...head, timeline }, null, 2));
242
+ console.log(JSON.stringify({ ...head, lines: timeline.length, timeline: shown }, null, 2));
180
243
  } else {
181
244
  console.log(`Recording ${id}${task ? ` on task #${task.id}` : ''}: ${clock(kept.duration)} of ${kept.page}`);
182
245
  console.log(`viewport ${kept.viewport.width}×${kept.viewport.height}, ${head.colorScheme}, started ${head.startedAt}`);
183
246
  if (replay) console.log(`replays at ${replay} (add ?t=<seconds> to open it paused there)`);
247
+ if (shown.length < timeline.length) console.log(`${shown.length} of its ${timeline.length} lines, as asked`);
184
248
  console.log();
185
- for (const e of timeline) console.log(`${e.at.padStart(6)} ${e.kind.padEnd(12)} ${e.text}`);
249
+ const under = (line) => console.log(`${' '.repeat(22)}${line}`);
250
+ for (const e of shown) {
251
+ console.log(`${e.at.padStart(6)} ${e.kind.padEnd(13)} ${e.text}`);
252
+ // Where a warning or an error came from, its nearest few places: all of them, and every line's, with `--full`.
253
+ if (e.trace && (options.full || e.problem)) for (const line of options.full ? e.trace : e.trace.slice(0, 5)) under(`at ${line}`);
254
+ if (!options.full || !e.request) continue;
255
+ const r = e.request;
256
+ if (e.before) under(e.before);
257
+ for (const [title, held] of [
258
+ ['request headers', r.requestHeaders],
259
+ ['response headers', r.responseHeaders],
260
+ ])
261
+ for (const [name, value] of Object.entries(held ?? {})) under(`${title} ${name}: ${value}`);
262
+ if (r.requestBody) under(`request body ${r.requestBody}`);
263
+ if (r.responseBody) under(`response body ${r.responseBody}`);
264
+ }
265
+ if (shown.length === 0) console.log(timeline.length === 0 ? 'Nothing in it.' : 'No line of it is what was asked for.');
186
266
  }
@@ -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 replies. Usage: task.mjs <id> [--out dir]
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?.startsWith(first.slice(0, 40))) {
53
- console.log(`\nSource: ${path}:${line}, as the task saw it.`);
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.trim().startsWith(first.slice(0, 40)));
59
+ const moved = lines.findIndex((l) => l.includes(first.slice(0, 40)));
56
60
  console.log(
57
61
  moved >= 0
58
- ? `\nSource: moved to ${path}:${moved + 1} (the task says line ${line}).`
59
- : `\nSource: ${path}:${line} no longer reads as the task saw it; it was:\n ${first}`,
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
- console.log(` ${a.name} (${a.type}, ${kb})${saved || `: vb download ${a.id} <dir>`}`);
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); it runs until stopped, and says so if the board goes away.
5
- // Usage: watch.mjs [channel, default deictic] [--label k=v ...]
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 { 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
- say(`watching ${channel} on ${process.env.BOARD_URL ?? 'the default board'}`);
19
- for (const line of ready ? ready.split('\n') : []) if (/^#\d+/.test(line)) say(`ready: ${line}`);
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
- const tail = spawn(command, argv, { ...spawnOptions, stdio: ['ignore', 'pipe', 'inherit'] });
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') say(`new task #${p.id}: ${roots.get(p.thread) ?? ''}. Read it: vb read ${p.id}`);
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
- say(`reply on #${p.re} by ${by}: ${first(p.text ?? '')}`);
107
+ event(`reply on #${p.re} by ${by}: ${first(p.text ?? '')}`);
45
108
  }
46
- if (e.type === 'task.canceled') say(`task #${p.id} canceled: ${p.reason ?? ''}. Stop work on it.`);
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
+ }