deictic 0.3.1 → 0.4.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 (165) hide show
  1. package/API.md +26 -17
  2. package/README.md +6 -26
  3. package/dist/annotations/client.d.ts +1 -1
  4. package/dist/annotations/client.js +1 -1
  5. package/dist/annotations/index.d.ts +2 -101
  6. package/dist/annotations/index.js +1 -22
  7. package/dist/astro.d.ts +1 -1
  8. package/dist/astro.js +1 -1
  9. package/dist/cli.d.ts +1 -0
  10. package/dist/cli.js +37 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/index.js +1 -10
  13. package/dist/logs/client.d.ts +1 -1
  14. package/dist/logs/client.js +1 -1
  15. package/dist/logs/index.d.ts +2 -18
  16. package/dist/logs/index.js +1 -21
  17. package/dist/network/client.d.ts +1 -1
  18. package/dist/network/client.js +1 -1
  19. package/dist/network/index.d.ts +1 -1
  20. package/dist/network/index.js +1 -37
  21. package/dist/recommended/index.d.ts +7 -7
  22. package/dist/recommended/index.js +1 -26
  23. package/dist/recordings/client.d.ts +1 -1
  24. package/dist/recordings/client.js +1 -1
  25. package/dist/recordings/index.d.ts +1 -1
  26. package/dist/screenshots/client.d.ts +1 -1
  27. package/dist/screenshots/client.js +1 -108
  28. package/dist/screenshots/dom.d.ts +1 -1
  29. package/dist/screenshots/dom.js +1 -1
  30. package/dist/screenshots/index.d.ts +1 -1
  31. package/dist/screenshots/index.js +1 -103
  32. package/dist/screenshots/rrweb.d.ts +1 -1
  33. package/dist/screenshots/rrweb.js +1 -1
  34. package/dist/shared/annotations.js +22 -0
  35. package/dist/shared/annotations.js.map +1 -0
  36. package/dist/shared/board.js +190 -0
  37. package/dist/shared/board.js.map +1 -0
  38. package/dist/shared/client.js +108 -0
  39. package/dist/shared/endpoints.js +4 -1
  40. package/dist/shared/endpoints.js.map +1 -1
  41. package/dist/shared/find.js +156 -0
  42. package/dist/shared/find.js.map +1 -0
  43. package/dist/shared/frame.js +75 -0
  44. package/dist/shared/frame.js.map +1 -0
  45. package/dist/shared/index.d.ts +5 -0
  46. package/dist/shared/index.d.ts.map +1 -1
  47. package/dist/shared/index2.d.ts +85 -88
  48. package/dist/shared/index2.d.ts.map +1 -1
  49. package/dist/shared/index3.d.ts +83 -89
  50. package/dist/shared/index3.d.ts.map +1 -1
  51. package/dist/shared/index4.d.ts +98 -50
  52. package/dist/shared/index4.d.ts.map +1 -1
  53. package/dist/shared/index5.d.ts +13 -219
  54. package/dist/shared/index5.d.ts.map +1 -1
  55. package/dist/shared/index6.d.ts +55 -61
  56. package/dist/shared/index6.d.ts.map +1 -1
  57. package/dist/shared/index7.d.ts +224 -0
  58. package/dist/shared/index7.d.ts.map +1 -0
  59. package/dist/shared/index8.d.ts +52 -0
  60. package/dist/shared/index8.d.ts.map +1 -0
  61. package/dist/shared/index9.d.ts +70 -0
  62. package/dist/shared/index9.d.ts.map +1 -0
  63. package/dist/shared/init.js +472 -0
  64. package/dist/shared/init.js.map +1 -0
  65. package/dist/shared/local.js +165 -0
  66. package/dist/shared/local.js.map +1 -0
  67. package/dist/shared/logs.js +22 -0
  68. package/dist/shared/logs.js.map +1 -0
  69. package/dist/shared/network.js +39 -0
  70. package/dist/shared/network.js.map +1 -0
  71. package/dist/shared/packages.js +125 -0
  72. package/dist/shared/packages.js.map +1 -0
  73. package/dist/shared/recommended.js +26 -0
  74. package/dist/shared/recommended.js.map +1 -0
  75. package/dist/shared/recording.js +316 -0
  76. package/dist/shared/recording.js.map +1 -0
  77. package/dist/shared/recordings.js +2 -1
  78. package/dist/shared/recordings.js.map +1 -1
  79. package/dist/shared/screenshots.js +108 -0
  80. package/dist/shared/screenshots.js.map +1 -0
  81. package/dist/shared/src.js +10 -0
  82. package/dist/shared/src.js.map +1 -0
  83. package/dist/shared/task.js +108 -0
  84. package/dist/shared/task.js.map +1 -0
  85. package/dist/shared/tasks.js +7 -180
  86. package/dist/shared/tasks.js.map +1 -1
  87. package/dist/shared/transcribe.js +128 -0
  88. package/dist/shared/transcribe.js.map +1 -0
  89. package/dist/shared/vb.js +13 -0
  90. package/dist/shared/vb.js.map +1 -0
  91. package/dist/shared/vite.d.ts +16 -0
  92. package/dist/shared/vite.d.ts.map +1 -0
  93. package/dist/shared/vite.js +61 -0
  94. package/dist/shared/vite.js.map +1 -0
  95. package/dist/shared/voice.js +84 -0
  96. package/dist/{voice/index.js.map → shared/voice.js.map} +1 -1
  97. package/dist/shared/voice2.js +90 -0
  98. package/dist/shared/voice2.js.map +1 -0
  99. package/dist/shared/watch.js +209 -0
  100. package/dist/shared/watch.js.map +1 -0
  101. package/dist/shared/watchers.js +62 -0
  102. package/dist/shared/watchers.js.map +1 -0
  103. package/dist/tailwind/client.d.ts +1 -1
  104. package/dist/tailwind/client.js +1 -1
  105. package/dist/tailwind/index.d.ts +1 -1
  106. package/dist/tailwind/index.js +1 -1
  107. package/dist/tasks/client.d.ts +1 -1
  108. package/dist/tasks/client.js +1 -1
  109. package/dist/tasks/index.d.ts +1 -1
  110. package/dist/tasks/index.js +3 -1
  111. package/dist/vite.d.ts +2 -15
  112. package/dist/vite.js +2 -60
  113. package/dist/voice/client.d.ts +1 -1
  114. package/dist/voice/client.js +1 -1
  115. package/dist/voice/index.d.ts +2 -52
  116. package/dist/voice/index.js +1 -84
  117. package/package.json +6 -9
  118. package/skills/deictic/SKILL.md +27 -42
  119. package/skills/deictic/references/recordings.md +9 -108
  120. package/skills/deictic/references/tasks.md +21 -112
  121. package/skills/deictic/references/watch.md +13 -68
  122. package/src/cli/board.ts +204 -0
  123. package/src/cli/bun.ts +133 -0
  124. package/src/cli/edit.ts +56 -0
  125. package/src/cli/find.ts +147 -0
  126. package/src/cli/frame.ts +90 -0
  127. package/src/cli/init.ts +388 -0
  128. package/src/cli/recording.ts +383 -0
  129. package/src/cli/task.ts +126 -0
  130. package/src/cli/transcribe.ts +129 -0
  131. package/src/cli/vb.ts +11 -0
  132. package/src/cli/voice.ts +59 -0
  133. package/src/cli/watch.ts +221 -0
  134. package/src/cli.ts +37 -0
  135. package/src/index.ts +5 -0
  136. package/src/plugins/logs/index.ts +1 -0
  137. package/src/plugins/network/index.ts +1 -0
  138. package/src/plugins/recordings/index.ts +1 -0
  139. package/src/plugins/screenshots/index.ts +5 -1
  140. package/src/plugins/tasks/index.ts +3 -2
  141. package/src/plugins/tasks/local.ts +19 -6
  142. package/src/plugins/tasks/watchers.ts +41 -6
  143. package/src/tools/endpoints.ts +3 -0
  144. package/src/tools/packages.ts +107 -0
  145. package/dist/annotations/index.d.ts.map +0 -1
  146. package/dist/annotations/index.js.map +0 -1
  147. package/dist/index.js.map +0 -1
  148. package/dist/logs/index.d.ts.map +0 -1
  149. package/dist/logs/index.js.map +0 -1
  150. package/dist/network/index.js.map +0 -1
  151. package/dist/recommended/index.js.map +0 -1
  152. package/dist/screenshots/index.js.map +0 -1
  153. package/dist/vite.d.ts.map +0 -1
  154. package/dist/vite.js.map +0 -1
  155. package/dist/voice/index.d.ts.map +0 -1
  156. package/skills/deictic/references/install.md +0 -103
  157. package/skills/deictic/scripts/frame.mjs +0 -62
  158. package/skills/deictic/scripts/lib.mjs +0 -283
  159. package/skills/deictic/scripts/recording.mjs +0 -266
  160. package/skills/deictic/scripts/task.mjs +0 -120
  161. package/skills/deictic/scripts/transcribe.mjs +0 -93
  162. package/skills/deictic/scripts/vb.mjs +0 -12
  163. package/skills/deictic/scripts/voice.mjs +0 -50
  164. package/skills/deictic/scripts/watch.mjs +0 -152
  165. /package/dist/{screenshots → shared}/client.js.map +0 -0
@@ -1,266 +0,0 @@
1
- #!/usr/bin/env node
2
- // A recording as a timeline: the page, each click and field typed in (with the element's place in the source),
3
- // scrolls, resizes, each change to the marks (what was drawn, where, and the notes' text), the voice clips,
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
12
- import { clock, fail, loadRecording, parseArgs } from './lib.mjs';
13
-
14
- const { options, rest } = parseArgs(process.argv.slice(2), ['json', 'problems', 'full']);
15
- const { kept, id, replay, task } = await loadRecording(rest[0], Number(options.nth?.[0] ?? 1));
16
- const { events } = kept;
17
- if (!Array.isArray(events) || events.length === 0) fail(`Recording ${id} has no events.`);
18
- const t0 = events[0].timestamp;
19
-
20
- // The page's nodes by rrweb's IDs, from the full snapshot and each mutation: enough to name an element.
21
- const nodes = new Map();
22
- const add = (node, parent) => {
23
- nodes.set(node.id, { ...node, parent, childNodes: undefined, kids: (node.childNodes ?? []).map((c) => c.id) });
24
- for (const c of node.childNodes ?? []) add(c, node.id);
25
- };
26
- const textOf = (nid, max = 60) => {
27
- let out = '';
28
- const walk = (n) => {
29
- const node = nodes.get(n);
30
- if (node === undefined || out.length > max) return;
31
- if (node.type === 3) out += node.textContent ?? '';
32
- for (const k of node.kids ?? []) walk(k);
33
- };
34
- walk(nid);
35
- const text = out.replace(/\s+/g, ' ').trim();
36
- return text.length > max ? `${text.slice(0, max)}…` : text;
37
- };
38
- /** `<button> "Save" at src/App.tsx:9:7`: the element, its text, and the nearest place deictic marked. */
39
- const describe = (nid) => {
40
- const node = nodes.get(nid);
41
- if (node === undefined) return `node ${nid}`;
42
- if (node.type === 0) return 'the page';
43
- let at;
44
- for (let n = node; n !== undefined && at === undefined; n = nodes.get(n.parent)) at = n.attributes?.['data-deictic'];
45
- const tag = node.tagName ? `<${node.tagName}>` : 'text';
46
- const text = textOf(nid);
47
- return `${tag}${text ? ` "${text}"` : ''}${at ? ` at ${at}` : ''}`;
48
- };
49
-
50
- // The marks, as data where the recording has it, else read off the SVG.
51
- const boundsOf = (points) => {
52
- const xs = points.map((p) => p.x);
53
- const ys = points.map((p) => p.y);
54
- return `(${Math.round(Math.min(...xs))},${Math.round(Math.min(...ys))})–(${Math.round(Math.max(...xs))},${Math.round(Math.max(...ys))})`;
55
- };
56
- const shapeOf = ({ shape }) => {
57
- switch (shape.kind) {
58
- case 'box':
59
- return `box ${boundsOf([shape, { x: shape.x + shape.width, y: shape.y + shape.height }])}`;
60
- case 'arrow':
61
- return `arrow from (${Math.round(shape.from.x)},${Math.round(shape.from.y)}) to (${Math.round(shape.to.x)},${Math.round(shape.to.y)})`;
62
- case 'pen':
63
- return `pen stroke over ${boundsOf(shape.points)}`;
64
- case 'note':
65
- return `note at (${Math.round(shape.at.x)},${Math.round(shape.at.y)}): ${JSON.stringify(shape.text)}`;
66
- default:
67
- return shape.kind;
68
- }
69
- };
70
- const pairs = (s) => [...s.matchAll(/(-?[\d.]+)[ ,](-?[\d.]+)/g)].map((m) => ({ x: Number(m[1]), y: Number(m[2]) }));
71
- const shapesInSvg = (svg) => {
72
- const out = [];
73
- const unescape = (t) => t.replaceAll('&lt;', '<').replaceAll('&gt;', '>').replaceAll('&quot;', '"').replaceAll('&amp;', '&');
74
- for (const m of svg.matchAll(/<(rect|path|polyline|text)\b([^>]*)>(?:(.*?)<\/text>)?/g)) {
75
- const [, tag, attrs, inner] = m;
76
- const num = (name) => Number(attrs.match(new RegExp(`\\b${name}="(-?[\\d.]+)"`))?.[1]);
77
- if (tag === 'rect' && attrs.includes('fill="none"'))
78
- out.push({ shape: { kind: 'box', x: num('x'), y: num('y'), width: num('width'), height: num('height') } });
79
- if (tag === 'path') {
80
- const [from, to] = pairs(attrs.match(/d="([^"]*)"/)[1]);
81
- out.push({ shape: { kind: 'arrow', from, to } });
82
- }
83
- if (tag === 'polyline') out.push({ shape: { kind: 'pen', points: pairs(attrs.match(/points="([^"]*)"/)[1]) } });
84
- if (tag === 'text') {
85
- const lines = [...inner.matchAll(/<tspan[^>]*>(.*?)<\/tspan>/g)].map((l) => unescape(l[1]));
86
- const at = pairs(
87
- inner
88
- .match(/x="(-?[\d.]+)" y="(-?[\d.]+)"/)
89
- ?.slice(1)
90
- .join(',') ?? '0,0',
91
- )[0];
92
- out.push({ shape: { kind: 'note', at, text: lines.join('\n') } });
93
- }
94
- }
95
- return out;
96
- };
97
-
98
- const timeline = [];
99
- const at = (e) => e.timestamp - t0;
100
- const push = (t, kind, text, extra = {}) => timeline.push({ t, at: clock(t), kind, text, ...extra });
101
- let marks = [];
102
- let scroll;
103
- let typing;
104
- const flushScroll = () => {
105
- if (scroll) push(scroll.t, 'scroll', `${describe(scroll.id)} to (${scroll.x},${scroll.y})`);
106
- scroll = undefined;
107
- };
108
- const flushTyping = () => {
109
- if (typing) push(typing.t, 'input', `${describe(typing.id)}: ${typing.value}`);
110
- typing = undefined;
111
- };
112
-
113
- for (const e of events) {
114
- const t = at(e);
115
- if (e.type === 4) push(t, 'page', `${e.data.href} at ${e.data.width}×${e.data.height}`);
116
- if (e.type === 2) {
117
- nodes.clear();
118
- add(e.data.node, undefined);
119
- }
120
- if (e.type === 5 && e.data.tag === 'deictic.annotations') {
121
- const now = e.data.payload.annotations ?? shapesInSvg(e.data.payload.svg ?? '');
122
- const key = (a) => a.id ?? JSON.stringify(a.shape);
123
- const before = new Set(marks.map(key));
124
- const after = new Set(now.map(key));
125
- const added = now.filter((a) => !before.has(key(a)));
126
- const removed = marks.filter((a) => !after.has(key(a)));
127
- if (added.length > 0 || removed.length > 0) {
128
- push(t, 'marks', [...added.map((a) => `+ ${shapeOf(a)}`), ...removed.map((a) => `− ${shapeOf(a)}`)].join('; '), {
129
- marks: now.map((a) => a.shape),
130
- });
131
- }
132
- marks = now;
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
- }
166
- if (e.type === 5 && e.data.tag === 'deictic.end') push(t, 'end', 'recording stopped');
167
- if (e.type !== 3) continue;
168
- const d = e.data;
169
- if (d.source === 0) {
170
- for (const a of d.adds ?? []) add(a.node, a.parentId);
171
- for (const a of d.attributes ?? []) {
172
- const node = nodes.get(a.id);
173
- if (node) node.attributes = { ...node.attributes, ...a.attributes };
174
- }
175
- for (const x of d.texts ?? []) {
176
- const node = nodes.get(x.id);
177
- if (node) node.textContent = x.value;
178
- }
179
- }
180
- if (d.source === 2 && [2, 3, 4].includes(d.type)) {
181
- flushScroll();
182
- flushTyping();
183
- const what = { 2: 'click', 3: 'right-click', 4: 'double-click' }[d.type];
184
- // A click a key made (Enter on a button) has no position.
185
- const where = d.x === 0 && d.y === 0 ? ' by keyboard' : ` at (${Math.round(d.x)},${Math.round(d.y)}) in the viewport`;
186
- push(t, what, `${describe(d.id)}${where}`, { node: d.id });
187
- }
188
- if (d.source === 3) {
189
- if (scroll && scroll.id !== d.id) flushScroll();
190
- scroll = { t: scroll?.t ?? t, id: d.id, x: Math.round(d.x), y: Math.round(d.y) };
191
- }
192
- if (d.source === 4) push(t, 'resize', `viewport ${d.width}×${d.height}`);
193
- if (d.source === 5) {
194
- if (typing && typing.id !== d.id) flushTyping();
195
- typing = {
196
- t: typing?.t ?? t,
197
- id: d.id,
198
- value: d.isChecked !== undefined && d.text === undefined ? String(d.isChecked) : JSON.stringify(d.text),
199
- };
200
- }
201
- }
202
- flushScroll();
203
- flushTyping();
204
- for (const c of kept.voice ?? []) push(c.at, 'voice', `clip ${c.id}, ${clock(c.duration)} long, until ${clock(c.at + c.duration)}`);
205
- timeline.sort((a, b) => a.t - b.t);
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
-
231
- const head = {
232
- id,
233
- page: kept.page,
234
- viewport: kept.viewport,
235
- colorScheme: kept.colorScheme ?? 'light',
236
- startedAt: new Date(kept.startedAt ?? t0).toISOString(),
237
- duration: kept.duration,
238
- replay,
239
- task: task?.id,
240
- };
241
- if (options.json) {
242
- console.log(JSON.stringify({ ...head, lines: timeline.length, timeline: shown }, null, 2));
243
- } else {
244
- console.log(`Recording ${id}${task ? ` on task #${task.id}` : ''}: ${clock(kept.duration)} of ${kept.page}`);
245
- console.log(`viewport ${kept.viewport.width}×${kept.viewport.height}, ${head.colorScheme}, started ${head.startedAt}`);
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`);
248
- console.log();
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.');
266
- }
@@ -1,120 +0,0 @@
1
- #!/usr/bin/env node
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, the replies, and the other open tasks about the same page.
4
- // Usage: task.mjs <id> [--out dir]
5
- // --out downloads the attachments there.
6
- import { existsSync, mkdirSync, readFileSync } from 'node:fs';
7
- import { dirname, join, resolve } from 'node:path';
8
- import { fileURLToPath } from 'node:url';
9
-
10
- import { deicticDirs, fail, parseArgs, vb } from './lib.mjs';
11
-
12
- const vbScript = join(dirname(fileURLToPath(import.meta.url)), 'vb.mjs');
13
-
14
- const { options, rest } = parseArgs(process.argv.slice(2));
15
- if (rest[0] === undefined) fail('Name a task: task.mjs 68');
16
- const { message: root, replies } = vb(['read', rest[0].replace(/^#/, '')], { json: true });
17
- const [asked = '', where = ''] = root.text.split(/\n---\n/);
18
- const at = root.labels['deictic.at'];
19
- const here = dirname(fileURLToPath(import.meta.url));
20
-
21
- // Who asked, said as that: the line's state is beside it, and a board's record names no one for a task's end.
22
- console.log(`#${root.id} ${root.task?.state ?? 'not a task'}, asked by ${root.author?.handle ?? root.by.actor}, ${root.createdAt}`);
23
- // An actor by the profile its ID ends in (`…+claude`), or the ID of one that writes as itself.
24
- const nameOf = (actor) => (actor.includes('+') ? actor.slice(actor.lastIndexOf('+') + 1) : actor);
25
- const claim = root.task?.claim;
26
- if (claim) console.log(`Claimed by ${nameOf(claim.actor)} until ${claim.until}`);
27
- if (root.task?.result) console.log(`Result: ${root.task.result}`);
28
- if (root.task?.reason) console.log(`Reason: ${root.task.reason}`);
29
- console.log(`\nAsked:\n${asked.trim()}\n`);
30
- // The part inside the element that was pointed at, where nothing marked it: what the person means.
31
- const pointed = where.match(/\nPointed at, inside it: `([^`]*)`\n`{3,}\w*\n([\s\S]*?)\n`{3,}/);
32
- // Where, from the labels: the place, the page, and the viewport to look at it in.
33
- const facts = [
34
- ['deictic.project', (v) => `Project ${v}`],
35
- ['deictic.at', (v) => `${v} <${root.labels['deictic.tag'] ?? '?'}>`],
36
- ['deictic.url', (v) => v],
37
- ['deictic.viewport', (v) => `Viewport ${v}`],
38
- ['deictic.count', (v) => (v === '1' ? undefined : `${v} elements on the page come from that line`)],
39
- ['deictic.position', (v) => `In the screenshot at x,y ${v}, ${root.labels['deictic.size'] ?? '?'} (CSS pixels from its top left)`],
40
- ];
41
- for (const [key, say] of facts) {
42
- const line = root.labels[key] === undefined ? undefined : say(root.labels[key]);
43
- if (line !== undefined) console.log(line);
44
- }
45
- // What no label holds: what's attached and drawn on it.
46
- const told = (pointed ? where.slice(0, pointed.index) : where).trim();
47
- if (told !== '') console.log(told);
48
- if (pointed) console.log(`\nPointed at, inside it: ${pointed[1]}\n ${pointed[2]}`);
49
-
50
- // The place as the task saw it, against the file now: the element's opening tag may have moved or changed.
51
- if (at !== undefined) {
52
- const [file, line] = [at.replace(/:\d+:\d+$/, ''), Number(at.split(':').at(-2))];
53
- // Marks are from the dev server's root: here, above, or a folder with a .deictic/ of its own.
54
- const roots = [process.cwd(), ...deicticDirs().map(dirname)];
55
- const path = roots.map((r) => resolve(r, file)).find((p) => existsSync(p));
56
- if (path === undefined) {
57
- console.log(`\n${file} isn't under ${roots.join(' or ')}: find the dev server's root.`);
58
- } else {
59
- const lines = readFileSync(path, 'utf8').split('\n');
60
- // The tag's first line may follow other code on its line: `const App = () => <h1>`.
61
- const first = root.labels['deictic.line'];
62
- const now = lines[line - 1]?.trim();
63
- if (first === undefined || now?.includes(first.slice(0, 40))) {
64
- console.log(`\nFile: ${path}:${line}, as the task saw it.`);
65
- } else {
66
- const moved = lines.findIndex((l) => l.includes(first.slice(0, 40)));
67
- console.log(
68
- moved >= 0
69
- ? `\nFile: moved to ${path}:${moved + 1} (the task says line ${line}).`
70
- : `\nFile: ${path}:${line} no longer reads as the task saw it; it was:\n ${first}`,
71
- );
72
- }
73
- }
74
- }
75
-
76
- if (root.attachments.length > 0) console.log('\nAttached:');
77
- const out = options.out?.[0] && resolve(options.out[0]);
78
- if (out) mkdirSync(out, { recursive: true });
79
- for (const a of root.attachments) {
80
- const kb = `${Math.round(a.size / 1024)} KB`;
81
- if (out) vb(['download', a.id, join(out, a.name)]);
82
- const saved = out ? ` → ${join(out, a.name)}` : '';
83
- if (a.name.startsWith('recording-')) {
84
- console.log(` ${a.name} (${kb})${saved}`);
85
- console.log(` timeline: node ${join(here, 'recording.mjs')} ${root.id}`);
86
- console.log(` frames: node ${join(here, 'frame.mjs')} ${root.id}`);
87
- } else if (a.name.startsWith('voice-')) {
88
- console.log(` ${a.name} (${kb}), a voice clip${saved}`);
89
- console.log(` speech: node ${join(here, 'voice.mjs')} ${root.id}`);
90
- } else if (a.name === 'element.html') {
91
- console.log(
92
- ` ${a.name} (${kb}), the element's HTML as it rendered, if you need it${saved || `: node ${vbScript} download ${a.id} ${a.name}`}`,
93
- );
94
- } else {
95
- // To a file's path: the CLI writes what it's given, and refuses a folder.
96
- console.log(` ${a.name} (${a.type}, ${kb})${saved || `: node ${vbScript} download ${a.id} ${a.name}`}`);
97
- }
98
- }
99
- if (replies.length > 0) console.log('\nReplies:');
100
- for (const r of replies) console.log(` ${r.author?.handle ?? r.by.actor}: ${r.text}`);
101
-
102
- // The other open tasks about the same page, of the same project: left a minute apart, they're often one change.
103
- const page = root.labels['deictic.page'];
104
- if (page !== undefined) {
105
- const project = root.labels['deictic.project'];
106
- const labels = [`deictic.page=${page}`, ...(project === undefined ? [] : [`deictic.project=${project}`])];
107
- const { tasks } = vb(['tasks', root.channel, ...labels.flatMap((l) => ['--label', l])], { json: true });
108
- const others = tasks.map((t) => t.message).filter((m) => m.id !== root.id);
109
- if (others.length > 0) {
110
- const count = `${others.length} other open task${others.length === 1 ? '' : 's'}`;
111
- console.log(`\n${count} on ${page}: read them before you start, they may be one change.`);
112
- for (const m of others) {
113
- const title = m.text
114
- .split(/\n---\n/)[0]
115
- .split('\n')[0]
116
- .slice(0, 100);
117
- console.log(` #${m.id} ${m.task?.state ?? ''}, ${m.labels['deictic.at'] ?? '?'}: ${title}`);
118
- }
119
- }
120
- }
@@ -1,93 +0,0 @@
1
- #!/usr/bin/env node
2
- // What was said in voice clips, with when: Whisper on this machine, through transformers.js. For a recording, the
3
- // times are the recording's, to line up with its timeline. Nothing leaves the machine once the model is downloaded.
4
- //
5
- // Usage: transcribe.mjs <task | replay URL | recording ID | file | clip ID> [--model base] [--language en] [--json]
6
- // transcribe.mjs --setup [--model base] installs it: ask the person first
7
- //
8
- // Setup puts @huggingface/transformers and the model in ~/.cache/deictic/transcribe (DEICTIC_CACHE moves it),
9
- // outside the project. Models: tiny (~40 MB), base (~77 MB, the default), small (~250 MB), large-v3-turbo
10
- // (~800 MB), or any ONNX Whisper on Hugging Face by its ID. Needs ffmpeg on the PATH.
11
- import { spawnSync } from 'node:child_process';
12
- import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
13
- import { createRequire } from 'node:module';
14
- import { homedir } from 'node:os';
15
- import { join } from 'node:path';
16
- import { pathToFileURL } from 'node:url';
17
-
18
- import { clock, fail, ffmpeg, parseArgs, voiceClips } from './lib.mjs';
19
-
20
- // Pinned, so a setup installs what the script was written against; move it on deliberately.
21
- const TRANSFORMERS = '@huggingface/transformers@4.3.2';
22
- const MODELS = { tiny: 'whisper-tiny', base: 'whisper-base', small: 'whisper-small', 'large-v3-turbo': 'whisper-large-v3-turbo' };
23
-
24
- const { options, rest } = parseArgs(process.argv.slice(2), ['setup', 'json']);
25
- const size = options.model?.[0] ?? 'base';
26
- const model = size.includes('/')
27
- ? size
28
- : `onnx-community/${MODELS[size] ?? fail(`--model is one of ${Object.keys(MODELS).join(', ')}, or a model ID`)}`;
29
- const dir = join(process.env.DEICTIC_CACHE ?? join(homedir(), '.cache', 'deictic'), 'transcribe');
30
- const models = join(dir, 'models');
31
- const installed = existsSync(join(dir, 'node_modules', '@huggingface', 'transformers', 'package.json'));
32
- const downloaded = existsSync(join(models, ...model.split('/')));
33
-
34
- if (options.setup) {
35
- mkdirSync(dir, { recursive: true });
36
- if (!existsSync(join(dir, 'package.json'))) writeFileSync(join(dir, 'package.json'), '{ "private": true }\n');
37
- if (!installed) {
38
- console.log(`Installing ${TRANSFORMERS} in ${dir}…`);
39
- const windows = process.platform === 'win32';
40
- const args = ['install', '--prefix', dir, '--no-audit', '--no-fund', '--save-exact', TRANSFORMERS];
41
- const run = spawnSync(windows ? `npm ${args.map((a) => `"${a}"`).join(' ')}` : 'npm', windows ? [] : args, {
42
- stdio: 'inherit',
43
- shell: windows,
44
- });
45
- if (run.status !== 0) fail(`npm install failed (${run.error?.message ?? `exit ${run.status}`}).`);
46
- }
47
- } else if (!installed || !downloaded) {
48
- fail(
49
- `Local transcription isn't set up${installed ? ` with the ${size} model` : ''}. Ask the person first: it downloads ` +
50
- `${installed ? '' : `${TRANSFORMERS} (with ONNX Runtime, ~470 MB) and `}Whisper ${size} into ${dir}, outside ` +
51
- `the project; after that, audio is transcribed on this machine. On yes: node ${process.argv[1]} --setup` +
52
- (size === 'base' ? '' : ` --model ${size}`),
53
- );
54
- }
55
-
56
- const transformers = await import(pathToFileURL(createRequire(join(dir, 'package.json')).resolve('@huggingface/transformers')).href);
57
- transformers.env.cacheDir = models;
58
- // Only setup downloads; a transcription uses what's here.
59
- transformers.env.allowRemoteModels = Boolean(options.setup);
60
- if (options.setup) console.log(`Downloading ${model} (quantized) into ${models}…`);
61
- const asr = await transformers.pipeline('automatic-speech-recognition', model, { dtype: 'q8' });
62
- if (options.setup) {
63
- console.log(`Ready: node ${process.argv[1]} <task>${size === 'base' ? '' : ` --model ${size}`}`);
64
- if (rest[0] === undefined) process.exit(0);
65
- }
66
-
67
- const results = [];
68
- for (const c of await voiceClips(rest[0])) {
69
- // Whisper takes 16 kHz mono samples; ffmpeg decodes the clip (webm, ogg or mp4) to them.
70
- const raw = ffmpeg(['-loglevel', 'error', '-i', c.file, '-f', 'f32le', '-ac', '1', '-ar', '16000', '-'], 'buffer').stdout;
71
- const audio = new Float32Array(raw.buffer.slice(raw.byteOffset, raw.byteOffset + raw.byteLength - (raw.byteLength % 4)));
72
- const out = await asr(audio, {
73
- return_timestamps: true,
74
- chunk_length_s: 30,
75
- stride_length_s: 5,
76
- ...(options.language ? { language: options.language[0] } : {}),
77
- });
78
- const said = (out.chunks ?? [{ timestamp: [0, audio.length / 16000], text: out.text }]).map(({ timestamp: [from, to], text }) => ({
79
- from: c.at + from * 1000,
80
- to: c.at + (to ?? audio.length / 16000) * 1000,
81
- text: text.trim(),
82
- }));
83
- results.push({ ...c, text: out.text.trim(), said });
84
- }
85
-
86
- if (options.json) {
87
- console.log(JSON.stringify(results, null, 2));
88
- } else {
89
- for (const r of results) {
90
- console.log(`clip ${r.id} (${r.recording ? `in recording ${r.recording}, from ${clock(r.at)}` : 'a voice note'}):`);
91
- for (const s of r.said) console.log(` ${clock(s.from).padStart(6)} – ${clock(s.to).padStart(6)} ${s.text}`);
92
- }
93
- }
@@ -1,12 +0,0 @@
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,50 +0,0 @@
1
- #!/usr/bin/env node
2
- // When something was said: the stretches of speech in voice clips, found by ffmpeg's silence detection. For a
3
- // recording, in the recording's time, to line up with its timeline; for a task, each voice note on it too.
4
- // Usage: voice.mjs <task | replay URL | recording ID | file | clip ID> [--noise -35] [--gap 0.4] [--wav dir] [--json]
5
- // --wav writes each clip as 16 kHz mono WAV, what speech-to-text tools take. Needs ffmpeg on the PATH.
6
- import { mkdirSync } from 'node:fs';
7
- import { join, resolve } from 'node:path';
8
-
9
- import { clock, ffmpeg, parseArgs, voiceClips } from './lib.mjs';
10
-
11
- const { options, rest } = parseArgs(process.argv.slice(2), ['json']);
12
- const noise = Number(options.noise?.[0] ?? -35);
13
- const gap = Number(options.gap?.[0] ?? 0.4);
14
- const clips = await voiceClips(rest[0]);
15
-
16
- const results = [];
17
- for (const c of clips) {
18
- // ffmpeg reports silence; speech is what's between. MediaRecorder's webm has no duration, so it's measured.
19
- const run = ffmpeg(['-i', c.file, '-af', `silencedetect=noise=${noise}dB:d=${gap}`, '-f', 'null', '-']);
20
- const log = run.stderr;
21
- const starts = [...log.matchAll(/silence_start: (-?[\d.]+)/g)].map((m) => Number(m[1]) * 1000);
22
- const ends = [...log.matchAll(/silence_end: (-?[\d.]+)/g)].map((m) => Number(m[1]) * 1000);
23
- const times = [...log.matchAll(/time=(\d+):(\d+):([\d.]+)/g)].at(-1);
24
- const length = times ? (Number(times[1]) * 3600 + Number(times[2]) * 60 + Number(times[3])) * 1000 : Math.max(0, ...ends);
25
- const speech = [];
26
- let from = 0;
27
- for (let i = 0; i < starts.length; i++) {
28
- if (starts[i] - from > 150) speech.push([from, starts[i]]);
29
- from = ends[i] ?? length;
30
- }
31
- if (length - from > 150) speech.push([from, length]);
32
- if (options.wav) {
33
- const dir = resolve(options.wav[0]);
34
- mkdirSync(dir, { recursive: true });
35
- ffmpeg(['-y', '-loglevel', 'error', '-i', c.file, '-ar', '16000', '-ac', '1', '-sample_fmt', 's16', join(dir, `${c.id}.wav`)]);
36
- }
37
- results.push({ ...c, length, speech: speech.map(([a, b]) => ({ from: c.at + a, to: c.at + b })) });
38
- }
39
-
40
- if (options.json) {
41
- console.log(JSON.stringify(results, null, 2));
42
- } else {
43
- for (const r of results) {
44
- const where = r.recording ? `in recording ${r.recording}, from ${clock(r.at)}` : 'a voice note';
45
- console.log(`clip ${r.id} (${where}), ${clock(r.length)} long: ${r.file}`);
46
- if (r.speech.length === 0) console.log(' no speech found: try a lower --noise, like -45');
47
- for (const s of r.speech) console.log(` ${clock(s.from).padStart(6)} – ${clock(s.to).padStart(6)} speech`);
48
- if (options.wav) console.log(` wav: ${join(resolve(options.wav[0]), `${r.id}.wav`)}`);
49
- }
50
- }