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.
- package/API.md +26 -17
- package/README.md +6 -26
- package/dist/annotations/client.d.ts +1 -1
- package/dist/annotations/client.js +1 -1
- package/dist/annotations/index.d.ts +2 -101
- package/dist/annotations/index.js +1 -22
- package/dist/astro.d.ts +1 -1
- package/dist/astro.js +1 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +37 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.js +1 -10
- package/dist/logs/client.d.ts +1 -1
- package/dist/logs/client.js +1 -1
- package/dist/logs/index.d.ts +2 -18
- package/dist/logs/index.js +1 -21
- package/dist/network/client.d.ts +1 -1
- package/dist/network/client.js +1 -1
- package/dist/network/index.d.ts +1 -1
- package/dist/network/index.js +1 -37
- package/dist/recommended/index.d.ts +7 -7
- package/dist/recommended/index.js +1 -26
- package/dist/recordings/client.d.ts +1 -1
- package/dist/recordings/client.js +1 -1
- package/dist/recordings/index.d.ts +1 -1
- package/dist/screenshots/client.d.ts +1 -1
- package/dist/screenshots/client.js +1 -108
- package/dist/screenshots/dom.d.ts +1 -1
- package/dist/screenshots/dom.js +1 -1
- package/dist/screenshots/index.d.ts +1 -1
- package/dist/screenshots/index.js +1 -103
- package/dist/screenshots/rrweb.d.ts +1 -1
- package/dist/screenshots/rrweb.js +1 -1
- package/dist/shared/annotations.js +22 -0
- package/dist/shared/annotations.js.map +1 -0
- package/dist/shared/board.js +190 -0
- package/dist/shared/board.js.map +1 -0
- package/dist/shared/client.js +108 -0
- package/dist/shared/endpoints.js +4 -1
- package/dist/shared/endpoints.js.map +1 -1
- package/dist/shared/find.js +156 -0
- package/dist/shared/find.js.map +1 -0
- package/dist/shared/frame.js +75 -0
- package/dist/shared/frame.js.map +1 -0
- package/dist/shared/index.d.ts +5 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index2.d.ts +85 -88
- package/dist/shared/index2.d.ts.map +1 -1
- package/dist/shared/index3.d.ts +83 -89
- package/dist/shared/index3.d.ts.map +1 -1
- package/dist/shared/index4.d.ts +98 -50
- package/dist/shared/index4.d.ts.map +1 -1
- package/dist/shared/index5.d.ts +13 -219
- package/dist/shared/index5.d.ts.map +1 -1
- package/dist/shared/index6.d.ts +55 -61
- package/dist/shared/index6.d.ts.map +1 -1
- package/dist/shared/index7.d.ts +224 -0
- package/dist/shared/index7.d.ts.map +1 -0
- package/dist/shared/index8.d.ts +52 -0
- package/dist/shared/index8.d.ts.map +1 -0
- package/dist/shared/index9.d.ts +70 -0
- package/dist/shared/index9.d.ts.map +1 -0
- package/dist/shared/init.js +472 -0
- package/dist/shared/init.js.map +1 -0
- package/dist/shared/local.js +165 -0
- package/dist/shared/local.js.map +1 -0
- package/dist/shared/logs.js +22 -0
- package/dist/shared/logs.js.map +1 -0
- package/dist/shared/network.js +39 -0
- package/dist/shared/network.js.map +1 -0
- package/dist/shared/packages.js +125 -0
- package/dist/shared/packages.js.map +1 -0
- package/dist/shared/recommended.js +26 -0
- package/dist/shared/recommended.js.map +1 -0
- package/dist/shared/recording.js +316 -0
- package/dist/shared/recording.js.map +1 -0
- package/dist/shared/recordings.js +2 -1
- package/dist/shared/recordings.js.map +1 -1
- package/dist/shared/screenshots.js +108 -0
- package/dist/shared/screenshots.js.map +1 -0
- package/dist/shared/src.js +10 -0
- package/dist/shared/src.js.map +1 -0
- package/dist/shared/task.js +108 -0
- package/dist/shared/task.js.map +1 -0
- package/dist/shared/tasks.js +7 -180
- package/dist/shared/tasks.js.map +1 -1
- package/dist/shared/transcribe.js +128 -0
- package/dist/shared/transcribe.js.map +1 -0
- package/dist/shared/vb.js +13 -0
- package/dist/shared/vb.js.map +1 -0
- package/dist/shared/vite.d.ts +16 -0
- package/dist/shared/vite.d.ts.map +1 -0
- package/dist/shared/vite.js +61 -0
- package/dist/shared/vite.js.map +1 -0
- package/dist/shared/voice.js +84 -0
- package/dist/{voice/index.js.map → shared/voice.js.map} +1 -1
- package/dist/shared/voice2.js +90 -0
- package/dist/shared/voice2.js.map +1 -0
- package/dist/shared/watch.js +209 -0
- package/dist/shared/watch.js.map +1 -0
- package/dist/shared/watchers.js +62 -0
- package/dist/shared/watchers.js.map +1 -0
- package/dist/tailwind/client.d.ts +1 -1
- package/dist/tailwind/client.js +1 -1
- package/dist/tailwind/index.d.ts +1 -1
- package/dist/tailwind/index.js +1 -1
- package/dist/tasks/client.d.ts +1 -1
- package/dist/tasks/client.js +1 -1
- package/dist/tasks/index.d.ts +1 -1
- package/dist/tasks/index.js +3 -1
- package/dist/vite.d.ts +2 -15
- package/dist/vite.js +2 -60
- package/dist/voice/client.d.ts +1 -1
- package/dist/voice/client.js +1 -1
- package/dist/voice/index.d.ts +2 -52
- package/dist/voice/index.js +1 -84
- package/package.json +6 -9
- package/skills/deictic/SKILL.md +27 -42
- package/skills/deictic/references/recordings.md +9 -108
- package/skills/deictic/references/tasks.md +21 -112
- package/skills/deictic/references/watch.md +13 -68
- package/src/cli/board.ts +204 -0
- package/src/cli/bun.ts +133 -0
- package/src/cli/edit.ts +56 -0
- package/src/cli/find.ts +147 -0
- package/src/cli/frame.ts +90 -0
- package/src/cli/init.ts +388 -0
- package/src/cli/recording.ts +383 -0
- package/src/cli/task.ts +126 -0
- package/src/cli/transcribe.ts +129 -0
- package/src/cli/vb.ts +11 -0
- package/src/cli/voice.ts +59 -0
- package/src/cli/watch.ts +221 -0
- package/src/cli.ts +37 -0
- package/src/index.ts +5 -0
- package/src/plugins/logs/index.ts +1 -0
- package/src/plugins/network/index.ts +1 -0
- package/src/plugins/recordings/index.ts +1 -0
- package/src/plugins/screenshots/index.ts +5 -1
- package/src/plugins/tasks/index.ts +3 -2
- package/src/plugins/tasks/local.ts +19 -6
- package/src/plugins/tasks/watchers.ts +41 -6
- package/src/tools/endpoints.ts +3 -0
- package/src/tools/packages.ts +107 -0
- package/dist/annotations/index.d.ts.map +0 -1
- package/dist/annotations/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logs/index.d.ts.map +0 -1
- package/dist/logs/index.js.map +0 -1
- package/dist/network/index.js.map +0 -1
- package/dist/recommended/index.js.map +0 -1
- package/dist/screenshots/index.js.map +0 -1
- package/dist/vite.d.ts.map +0 -1
- package/dist/vite.js.map +0 -1
- package/dist/voice/index.d.ts.map +0 -1
- package/skills/deictic/references/install.md +0 -103
- package/skills/deictic/scripts/frame.mjs +0 -62
- package/skills/deictic/scripts/lib.mjs +0 -283
- package/skills/deictic/scripts/recording.mjs +0 -266
- package/skills/deictic/scripts/task.mjs +0 -120
- package/skills/deictic/scripts/transcribe.mjs +0 -93
- package/skills/deictic/scripts/vb.mjs +0 -12
- package/skills/deictic/scripts/voice.mjs +0 -50
- package/skills/deictic/scripts/watch.mjs +0 -152
- /package/dist/{screenshots → shared}/client.js.map +0 -0
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `deictic recording`: a recording as a timeline: the page, each click and field typed in (with the element's place
|
|
3
|
+
* in the source), scrolls, resizes, each change to the marks (what was drawn, where, and the notes' text), the voice
|
|
4
|
+
* clips, the page's console and its requests where the project records them, and the end. Or the part of it asked
|
|
5
|
+
* for: `--only`, `--problems`, `--from`, `--to`, `--around`, `--grep`, and `--full` for all of each line.
|
|
6
|
+
*/
|
|
7
|
+
import type { Shape } from '#src/plugins/annotations/index.ts';
|
|
8
|
+
|
|
9
|
+
import { clock, fail, ME, parseArgs } from './board.ts';
|
|
10
|
+
import { loadRecording } from './find.ts';
|
|
11
|
+
|
|
12
|
+
export const usage = `recording <task | replay URL | recording ID | file> [--nth 2] [--json] a recording as a timeline
|
|
13
|
+
--only console,request these kinds of line (also page, click, input, scroll, resize, marks, voice)
|
|
14
|
+
--problems errors, warnings and requests that failed
|
|
15
|
+
--from 10 --to 15 a stretch, in seconds; --around 12 is the 3 seconds either side
|
|
16
|
+
--grep text lines with this in them, in any case
|
|
17
|
+
--full all of each line: where it was logged from, a request's headers and bodies`;
|
|
18
|
+
|
|
19
|
+
/** A node of rrweb's snapshot. */
|
|
20
|
+
interface SnapNode {
|
|
21
|
+
id: number;
|
|
22
|
+
type: number;
|
|
23
|
+
tagName?: string;
|
|
24
|
+
textContent?: string;
|
|
25
|
+
attributes?: Record<string, string>;
|
|
26
|
+
childNodes?: SnapNode[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface Known extends Omit<SnapNode, 'childNodes'> {
|
|
30
|
+
parent: number | undefined;
|
|
31
|
+
kids: number[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A request rrweb's network plugin kept. */
|
|
35
|
+
interface Request {
|
|
36
|
+
name: string;
|
|
37
|
+
method?: string;
|
|
38
|
+
initiatorType?: string;
|
|
39
|
+
status?: number;
|
|
40
|
+
duration?: number;
|
|
41
|
+
requestHeaders?: Record<string, string>;
|
|
42
|
+
responseHeaders?: Record<string, string>;
|
|
43
|
+
requestBody?: string;
|
|
44
|
+
responseBody?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** What rrweb's events carry that the timeline reads: each kind has some of it. */
|
|
48
|
+
interface Data {
|
|
49
|
+
href?: string;
|
|
50
|
+
width?: number;
|
|
51
|
+
height?: number;
|
|
52
|
+
node?: SnapNode;
|
|
53
|
+
tag?: string;
|
|
54
|
+
plugin?: string;
|
|
55
|
+
payload?: {
|
|
56
|
+
annotations?: Annotation[];
|
|
57
|
+
svg?: string;
|
|
58
|
+
href?: string;
|
|
59
|
+
level?: string;
|
|
60
|
+
payload?: string[];
|
|
61
|
+
trace?: string[];
|
|
62
|
+
requests?: Request[];
|
|
63
|
+
isInitial?: boolean;
|
|
64
|
+
};
|
|
65
|
+
source?: number;
|
|
66
|
+
type?: number;
|
|
67
|
+
id?: number;
|
|
68
|
+
x?: number;
|
|
69
|
+
y?: number;
|
|
70
|
+
adds?: { node: SnapNode; parentId: number }[];
|
|
71
|
+
attributes?: { id: number; attributes: Record<string, string> }[];
|
|
72
|
+
texts?: { id: number; value: string }[];
|
|
73
|
+
isChecked?: boolean;
|
|
74
|
+
text?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
interface Event {
|
|
78
|
+
type: number;
|
|
79
|
+
timestamp: number;
|
|
80
|
+
data: Data;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface Annotation {
|
|
84
|
+
id?: string;
|
|
85
|
+
shape: Shape;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
interface Line {
|
|
89
|
+
t: number;
|
|
90
|
+
at: string;
|
|
91
|
+
kind: string;
|
|
92
|
+
text: string;
|
|
93
|
+
problem?: boolean;
|
|
94
|
+
trace?: string[];
|
|
95
|
+
request?: Request;
|
|
96
|
+
before?: string;
|
|
97
|
+
marks?: Shape[];
|
|
98
|
+
node?: number;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
type Point = { x: number; y: number };
|
|
102
|
+
|
|
103
|
+
const round = Math.round;
|
|
104
|
+
|
|
105
|
+
/** The marks, as data where the recording has it. */
|
|
106
|
+
function shapeOf({ shape }: Annotation): string {
|
|
107
|
+
const bounds = (points: Point[]) => {
|
|
108
|
+
const xs = points.map((p) => p.x);
|
|
109
|
+
const ys = points.map((p) => p.y);
|
|
110
|
+
return `(${round(Math.min(...xs))},${round(Math.min(...ys))})–(${round(Math.max(...xs))},${round(Math.max(...ys))})`;
|
|
111
|
+
};
|
|
112
|
+
if (shape.kind === 'box') return `box ${bounds([shape, { x: shape.x + shape.width, y: shape.y + shape.height }])}`;
|
|
113
|
+
if (shape.kind === 'arrow')
|
|
114
|
+
return `arrow from (${round(shape.from.x)},${round(shape.from.y)}) to (${round(shape.to.x)},${round(shape.to.y)})`;
|
|
115
|
+
if (shape.kind === 'pen') return `pen stroke over ${bounds(shape.points)}`;
|
|
116
|
+
return `note at (${round(shape.at.x)},${round(shape.at.y)}): ${JSON.stringify(shape.text)}`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const pairs = (s: string): Point[] => [...s.matchAll(/(-?[\d.]+)[ ,](-?[\d.]+)/g)].map((m) => ({ x: Number(m[1]), y: Number(m[2]) }));
|
|
120
|
+
|
|
121
|
+
/** The marks read off the SVG, for a recording older than the marks as data. */
|
|
122
|
+
function shapesInSvg(svg: string): Annotation[] {
|
|
123
|
+
const out: Annotation[] = [];
|
|
124
|
+
const unescape = (t: string) => t.replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll('&', '&');
|
|
125
|
+
for (const [, tag, attrs = '', inner = ''] of svg.matchAll(/<(rect|path|polyline|text)\b([^>]*)>(?:(.*?)<\/text>)?/g)) {
|
|
126
|
+
const num = (name: string) => Number(new RegExp(`\\b${name}="(-?[\\d.]+)"`).exec(attrs)?.[1]);
|
|
127
|
+
if (tag === 'rect' && attrs.includes('fill="none"'))
|
|
128
|
+
out.push({ shape: { kind: 'box', x: num('x'), y: num('y'), width: num('width'), height: num('height') } });
|
|
129
|
+
if (tag === 'path') {
|
|
130
|
+
const [from, to] = pairs(/d="([^"]*)"/.exec(attrs)?.[1] ?? '');
|
|
131
|
+
if (from !== undefined && to !== undefined) out.push({ shape: { kind: 'arrow', from, to } });
|
|
132
|
+
}
|
|
133
|
+
if (tag === 'polyline') out.push({ shape: { kind: 'pen', points: pairs(/points="([^"]*)"/.exec(attrs)?.[1] ?? '') } });
|
|
134
|
+
if (tag === 'text') {
|
|
135
|
+
const lines = [...inner.matchAll(/<tspan[^>]*>(.*?)<\/tspan>/g)].map((l) => unescape(l[1] ?? ''));
|
|
136
|
+
const xy = /x="(-?[\d.]+)" y="(-?[\d.]+)"/.exec(inner);
|
|
137
|
+
out.push({ shape: { kind: 'note', at: { x: Number(xy?.[1] ?? 0), y: Number(xy?.[2] ?? 0) }, text: lines.join('\n') } });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** The page's nodes by rrweb's IDs, from the full snapshot and each mutation: enough to name an element. */
|
|
144
|
+
class Nodes {
|
|
145
|
+
#nodes = new Map<number, Known>();
|
|
146
|
+
|
|
147
|
+
clear(): void {
|
|
148
|
+
this.#nodes.clear();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
add(node: SnapNode, parent: number | undefined): void {
|
|
152
|
+
const { childNodes = [], ...rest } = node;
|
|
153
|
+
this.#nodes.set(node.id, { ...rest, parent, kids: childNodes.map((c) => c.id) });
|
|
154
|
+
for (const c of childNodes) this.add(c, node.id);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
get(id: number): Known | undefined {
|
|
158
|
+
return this.#nodes.get(id);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
text(id: number, max = 60): string {
|
|
162
|
+
let out = '';
|
|
163
|
+
const walk = (n: number) => {
|
|
164
|
+
const node = this.#nodes.get(n);
|
|
165
|
+
if (node === undefined || out.length > max) return;
|
|
166
|
+
if (node.type === 3) out += node.textContent ?? '';
|
|
167
|
+
for (const k of node.kids) walk(k);
|
|
168
|
+
};
|
|
169
|
+
walk(id);
|
|
170
|
+
const text = out.replace(/\s+/g, ' ').trim();
|
|
171
|
+
return text.length > max ? `${text.slice(0, max)}…` : text;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** `<button> "Save" at src/App.tsx:9:7`: the element, its text, and the nearest place deictic marked. */
|
|
175
|
+
describe(id: number | undefined): string {
|
|
176
|
+
const node = id === undefined ? undefined : this.#nodes.get(id);
|
|
177
|
+
if (id === undefined || node === undefined) return `node ${id}`;
|
|
178
|
+
if (node.type === 0) return 'the page';
|
|
179
|
+
let at: string | undefined;
|
|
180
|
+
for (
|
|
181
|
+
let n: Known | undefined = node;
|
|
182
|
+
n !== undefined && at === undefined;
|
|
183
|
+
n = n.parent === undefined ? undefined : this.#nodes.get(n.parent)
|
|
184
|
+
)
|
|
185
|
+
at = n.attributes?.['data-deictic'];
|
|
186
|
+
const tag = node.tagName === undefined ? 'text' : `<${node.tagName}>`;
|
|
187
|
+
const text = this.text(id);
|
|
188
|
+
return `${tag}${text ? ` "${text}"` : ''}${at === undefined ? '' : ` at ${at}`}`;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** The page's console's arguments, each as JSON: a string without its quotes. */
|
|
193
|
+
const plain = (arg: string) => {
|
|
194
|
+
try {
|
|
195
|
+
const value: unknown = JSON.parse(arg);
|
|
196
|
+
return typeof value === 'string' ? value : arg;
|
|
197
|
+
} catch {
|
|
198
|
+
return arg;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/** Every line of the recording, in time. */
|
|
203
|
+
function timelineOf(events: Event[], voice: { id: string; at: number; duration: number }[]): Line[] {
|
|
204
|
+
const t0 = events[0]!.timestamp;
|
|
205
|
+
const timeline: Line[] = [];
|
|
206
|
+
const nodes = new Nodes();
|
|
207
|
+
const push = (t: number, kind: string, text: string, extra: Partial<Line> = {}) =>
|
|
208
|
+
timeline.push({ t, at: clock(t), kind, text, ...extra });
|
|
209
|
+
let marks: Annotation[] = [];
|
|
210
|
+
let scroll: { t: number; id: number | undefined; x: number; y: number } | undefined;
|
|
211
|
+
let typing: { t: number; id: number | undefined; value: string } | undefined;
|
|
212
|
+
const flushScroll = () => {
|
|
213
|
+
if (scroll) push(scroll.t, 'scroll', `${nodes.describe(scroll.id)} to (${scroll.x},${scroll.y})`);
|
|
214
|
+
scroll = undefined;
|
|
215
|
+
};
|
|
216
|
+
const flushTyping = () => {
|
|
217
|
+
if (typing) push(typing.t, 'input', `${nodes.describe(typing.id)}: ${typing.value}`);
|
|
218
|
+
typing = undefined;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
for (const e of events) {
|
|
222
|
+
const t = e.timestamp - t0;
|
|
223
|
+
const d = e.data;
|
|
224
|
+
const payload = d.payload ?? {};
|
|
225
|
+
if (e.type === 4) push(t, 'page', `${d.href} at ${d.width}×${d.height}`);
|
|
226
|
+
if (e.type === 2 && d.node !== undefined) {
|
|
227
|
+
nodes.clear();
|
|
228
|
+
nodes.add(d.node, undefined);
|
|
229
|
+
}
|
|
230
|
+
if (e.type === 5 && d.tag === 'deictic.annotations') {
|
|
231
|
+
const now = payload.annotations ?? shapesInSvg(payload.svg ?? '');
|
|
232
|
+
const key = (a: Annotation) => a.id ?? JSON.stringify(a.shape);
|
|
233
|
+
const before = new Set(marks.map(key));
|
|
234
|
+
const after = new Set(now.map(key));
|
|
235
|
+
const added = now.filter((a) => !before.has(key(a)));
|
|
236
|
+
const removed = marks.filter((a) => !after.has(key(a)));
|
|
237
|
+
if (added.length > 0 || removed.length > 0) {
|
|
238
|
+
const text = [...added.map((a) => `+ ${shapeOf(a)}`), ...removed.map((a) => `− ${shapeOf(a)}`)].join('; ');
|
|
239
|
+
push(t, 'marks', text, { marks: now.map((a) => a.shape) });
|
|
240
|
+
}
|
|
241
|
+
marks = now;
|
|
242
|
+
}
|
|
243
|
+
// The address changed with no load: a route of the app's.
|
|
244
|
+
if (e.type === 5 && d.tag === 'deictic.page') push(t, 'page', `${payload.href} (a route change, no load)`);
|
|
245
|
+
// The page's console, and errors nothing caught (rrweb's console plugin), and where it was logged from, which goes
|
|
246
|
+
// under a warning or an error.
|
|
247
|
+
if (e.type === 6 && d.plugin === 'rrweb/console@1') {
|
|
248
|
+
const level = payload.level ?? 'log';
|
|
249
|
+
push(t, `console.${level}`, (payload.payload ?? []).map(plain).join(' '), {
|
|
250
|
+
trace: payload.trace ?? [],
|
|
251
|
+
...(['error', 'assert', 'warn'].includes(level) ? { problem: true } : {}),
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
// The page's requests (rrweb's network plugin), masked as they were kept: each as it ended. One the browser
|
|
255
|
+
// reported of itself has no method; headers and bodies, where kept, are in `--json`.
|
|
256
|
+
if (e.type === 6 && d.plugin === 'rrweb/network@1') {
|
|
257
|
+
for (const r of payload.requests ?? []) {
|
|
258
|
+
const took = r.duration !== undefined && Number.isFinite(r.duration) ? ` in ${round(r.duration)} ms` : '';
|
|
259
|
+
const status = r.status === undefined || r.status === 0 ? 'no status (failed, blocked, or another origin’s)' : r.status;
|
|
260
|
+
push(t, 'request', `${r.method ?? r.initiatorType ?? ''} ${r.name} → ${status}${took}`.trim(), {
|
|
261
|
+
request: r,
|
|
262
|
+
...((r.status ?? 0) >= 400 ? { problem: true } : {}),
|
|
263
|
+
...(payload.isInitial === true ? { before: 'made as the page loaded, before this moment' } : {}),
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (e.type === 5 && d.tag === 'deictic.end') push(t, 'end', 'recording stopped');
|
|
268
|
+
if (e.type !== 3) continue;
|
|
269
|
+
if (d.source === 0) {
|
|
270
|
+
for (const a of d.adds ?? []) nodes.add(a.node, a.parentId);
|
|
271
|
+
for (const a of d.attributes ?? []) {
|
|
272
|
+
const node = nodes.get(a.id);
|
|
273
|
+
if (node) node.attributes = { ...node.attributes, ...a.attributes };
|
|
274
|
+
}
|
|
275
|
+
for (const x of d.texts ?? []) {
|
|
276
|
+
const node = nodes.get(x.id);
|
|
277
|
+
if (node) node.textContent = x.value;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (d.source === 2 && (d.type === 2 || d.type === 3 || d.type === 4)) {
|
|
281
|
+
flushScroll();
|
|
282
|
+
flushTyping();
|
|
283
|
+
const what = { 2: 'click', 3: 'right-click', 4: 'double-click' }[d.type];
|
|
284
|
+
// A click a key made (Enter on a button) has no position.
|
|
285
|
+
const where = d.x === 0 && d.y === 0 ? ' by keyboard' : ` at (${round(d.x ?? 0)},${round(d.y ?? 0)}) in the viewport`;
|
|
286
|
+
push(t, what, `${nodes.describe(d.id)}${where}`, { node: d.id });
|
|
287
|
+
}
|
|
288
|
+
if (d.source === 3) {
|
|
289
|
+
if (scroll && scroll.id !== d.id) flushScroll();
|
|
290
|
+
scroll = { t: scroll?.t ?? t, id: d.id, x: round(d.x ?? 0), y: round(d.y ?? 0) };
|
|
291
|
+
}
|
|
292
|
+
if (d.source === 4) push(t, 'resize', `viewport ${d.width}×${d.height}`);
|
|
293
|
+
if (d.source === 5) {
|
|
294
|
+
if (typing && typing.id !== d.id) flushTyping();
|
|
295
|
+
const value = d.isChecked !== undefined && d.text === undefined ? String(d.isChecked) : JSON.stringify(d.text);
|
|
296
|
+
typing = { t: typing?.t ?? t, id: d.id, value };
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
flushScroll();
|
|
300
|
+
flushTyping();
|
|
301
|
+
for (const c of voice) push(c.at, 'voice', `clip ${c.id}, ${clock(c.duration)} long, until ${clock(c.at + c.duration)}`);
|
|
302
|
+
return timeline.sort((a, b) => a.t - b.t);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export async function run(args: string[]): Promise<void> {
|
|
306
|
+
const { values, positionals } = parseArgs(args, {
|
|
307
|
+
nth: { type: 'string', default: '1' },
|
|
308
|
+
json: { type: 'boolean' },
|
|
309
|
+
only: { type: 'string', multiple: true },
|
|
310
|
+
problems: { type: 'boolean' },
|
|
311
|
+
from: { type: 'string' },
|
|
312
|
+
to: { type: 'string' },
|
|
313
|
+
around: { type: 'string' },
|
|
314
|
+
grep: { type: 'string' },
|
|
315
|
+
full: { type: 'boolean' },
|
|
316
|
+
});
|
|
317
|
+
const { kept, id, replay, task } = await loadRecording(positionals[0], Number(values.nth));
|
|
318
|
+
const events = kept.events as Event[];
|
|
319
|
+
if (!Array.isArray(events) || events.length === 0) fail(`Recording ${id} has no events.`);
|
|
320
|
+
const timeline = timelineOf(events, kept.voice ?? []);
|
|
321
|
+
|
|
322
|
+
// The part asked for. Seconds, as the replay's `?t=` and `frame --at` take them.
|
|
323
|
+
const seconds = (name: 'from' | 'to' | 'around') => {
|
|
324
|
+
const given = values[name];
|
|
325
|
+
if (given === undefined) return undefined;
|
|
326
|
+
const value = Number(given);
|
|
327
|
+
if (!Number.isFinite(value)) fail(`--${name} takes seconds from the recording's start, as 12 or 4.5: not ${given}`);
|
|
328
|
+
return value * 1000;
|
|
329
|
+
};
|
|
330
|
+
const around = seconds('around');
|
|
331
|
+
const from = seconds('from') ?? (around === undefined ? undefined : around - 3000);
|
|
332
|
+
const to = seconds('to') ?? (around === undefined ? undefined : around + 3000);
|
|
333
|
+
const only = (values.only ?? []).flatMap((list) => list.split(',')).filter(Boolean);
|
|
334
|
+
const grep = values.grep?.toLowerCase();
|
|
335
|
+
// `console` is every level's lines, `click` a right or a double one too.
|
|
336
|
+
const isKind = (kind: string, asked: string) => kind === asked || kind.startsWith(`${asked}.`) || kind.endsWith(`-${asked}`);
|
|
337
|
+
const shown = timeline.filter(
|
|
338
|
+
(e) =>
|
|
339
|
+
(only.length === 0 || only.some((asked) => isKind(e.kind, asked))) &&
|
|
340
|
+
(values.problems !== true || e.problem === true) &&
|
|
341
|
+
(from === undefined || e.t >= from) &&
|
|
342
|
+
(to === undefined || e.t <= to) &&
|
|
343
|
+
(grep === undefined || `${e.kind} ${e.text}`.toLowerCase().includes(grep)),
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
const colorScheme = kept.colorScheme ?? 'light';
|
|
347
|
+
const startedAt = new Date(kept.startedAt ?? events[0]!.timestamp).toISOString();
|
|
348
|
+
if (values.json) {
|
|
349
|
+
const head = { id, page: kept.page, viewport: kept.viewport, colorScheme, startedAt, duration: kept.duration, replay, task: task?.id };
|
|
350
|
+
console.log(JSON.stringify({ ...head, lines: timeline.length, timeline: shown }, null, 2));
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
console.log(`Recording ${id}${task ? ` on task #${task.id}` : ''}: ${clock(kept.duration)} of ${kept.page}`);
|
|
354
|
+
console.log(`viewport ${kept.viewport.width}×${kept.viewport.height}, ${colorScheme}, started ${startedAt}`);
|
|
355
|
+
if (replay !== undefined) console.log(`replays at ${replay} (add ?t=<seconds> to open it paused there)`);
|
|
356
|
+
if (shown.length < timeline.length) console.log(`${shown.length} of its ${timeline.length} lines, as asked`);
|
|
357
|
+
console.log();
|
|
358
|
+
const under = (line: string) => console.log(`${' '.repeat(22)}${line}`);
|
|
359
|
+
for (const e of shown) {
|
|
360
|
+
console.log(`${e.at.padStart(6)} ${e.kind.padEnd(13)} ${e.text}`);
|
|
361
|
+
// Where a warning or an error came from, its nearest few places: all of them, and every line's, with `--full`.
|
|
362
|
+
if (e.trace && (values.full === true || e.problem === true))
|
|
363
|
+
for (const line of values.full ? e.trace : e.trace.slice(0, 5)) under(`at ${line}`);
|
|
364
|
+
if (values.full !== true || e.request === undefined) continue;
|
|
365
|
+
const r = e.request;
|
|
366
|
+
if (e.before !== undefined) under(e.before);
|
|
367
|
+
for (const [title, held] of [
|
|
368
|
+
['request headers', r.requestHeaders],
|
|
369
|
+
['response headers', r.responseHeaders],
|
|
370
|
+
] as const)
|
|
371
|
+
for (const [name, value] of Object.entries(held ?? {})) under(`${title} ${name}: ${value}`);
|
|
372
|
+
if (r.requestBody !== undefined) under(`request body ${r.requestBody}`);
|
|
373
|
+
if (r.responseBody !== undefined) under(`response body ${r.responseBody}`);
|
|
374
|
+
}
|
|
375
|
+
if (shown.length === 0) console.log(timeline.length === 0 ? 'Nothing in it.' : 'No line of it is what was asked for.');
|
|
376
|
+
// Where something went wrong, how to get to it: what led up to it, and what the page looked like.
|
|
377
|
+
const problems = timeline.filter((e) => e.problem === true).length;
|
|
378
|
+
if (problems === 0 || shown.length < timeline.length) return;
|
|
379
|
+
const ref = task?.id ?? id;
|
|
380
|
+
console.log(
|
|
381
|
+
`\n${problems} problem${problems === 1 ? '' : 's'}: --problems lists them, --around <seconds> shows what led to one, and ${ME} frame ${ref} --at <seconds> the page then.`,
|
|
382
|
+
);
|
|
383
|
+
}
|
package/src/cli/task.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `deictic task`: a task, briefly: what was asked, where (and whether that place has moved in the source since), the
|
|
3
|
+
* page, what's attached with the command to look at each, the replies, and the other open tasks about the same page.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync } from 'node:fs';
|
|
6
|
+
import { dirname, join, resolve } from 'node:path';
|
|
7
|
+
|
|
8
|
+
import { deicticDirs, download, fail, ME, type Message, parseArgs, read, vbJson } from './board.ts';
|
|
9
|
+
|
|
10
|
+
export const usage = 'task <id> [--out dir] a task briefly; --out downloads what is attached';
|
|
11
|
+
|
|
12
|
+
/** An actor by the profile its ID ends in (`…+claude`), or the ID of one that writes as itself. */
|
|
13
|
+
const nameOf = (actor: string) => (actor.includes('+') ? actor.slice(actor.lastIndexOf('+') + 1) : actor);
|
|
14
|
+
|
|
15
|
+
export function run(args: string[]): void {
|
|
16
|
+
const { values, positionals } = parseArgs(args, { out: { type: 'string' } });
|
|
17
|
+
if (positionals[0] === undefined) fail(`Name a task: ${ME} task 68`);
|
|
18
|
+
const { message: root, replies } = read(positionals[0]);
|
|
19
|
+
const [asked = '', where = ''] = root.text.split(/\n---\n/);
|
|
20
|
+
const label = (key: string) => root.labels[key];
|
|
21
|
+
const at = label('deictic.at');
|
|
22
|
+
|
|
23
|
+
// 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.
|
|
24
|
+
console.log(`#${root.id} ${root.task?.state ?? 'not a task'}, asked by ${root.author?.handle ?? root.by.actor}, ${root.createdAt}`);
|
|
25
|
+
const claim = root.task?.claim;
|
|
26
|
+
if (claim) console.log(`Claimed by ${nameOf(claim.actor)} until ${claim.until}`);
|
|
27
|
+
if (root.task?.result !== undefined) console.log(`Result: ${root.task.result}`);
|
|
28
|
+
if (root.task?.reason !== undefined) 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 = /\nPointed at, inside it: `([^`]*)`\n`{3,}\w*\n([\s\S]*?)\n`{3,}/.exec(where);
|
|
32
|
+
// Where, from the labels: the place, the page, and the viewport to look at it in.
|
|
33
|
+
const facts: [string, (v: string) => string | undefined][] = [
|
|
34
|
+
['deictic.project', (v) => `Project ${v}`],
|
|
35
|
+
['deictic.at', (v) => `${v} <${label('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}, ${label('deictic.size') ?? '?'} (CSS pixels from its top left)`],
|
|
40
|
+
];
|
|
41
|
+
for (const [key, say] of facts) {
|
|
42
|
+
const value = label(key);
|
|
43
|
+
const line = value === undefined ? undefined : say(value);
|
|
44
|
+
if (line !== undefined) console.log(line);
|
|
45
|
+
}
|
|
46
|
+
// What no label holds: what's attached and drawn on it.
|
|
47
|
+
const told = (pointed ? where.slice(0, pointed.index) : where).trim();
|
|
48
|
+
if (told !== '') console.log(told);
|
|
49
|
+
if (pointed) console.log(`\nPointed at, inside it: ${pointed[1]}\n ${pointed[2]}`);
|
|
50
|
+
|
|
51
|
+
if (at !== undefined) placeOf(at, label('deictic.line'));
|
|
52
|
+
attachments(root, values.out === undefined ? undefined : resolve(values.out));
|
|
53
|
+
|
|
54
|
+
if (replies.length > 0) console.log('\nReplies:');
|
|
55
|
+
for (const r of replies) console.log(` ${r.author?.handle ?? r.by.actor}: ${r.text}`);
|
|
56
|
+
others(root);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The place as the task saw it, against the file now: the element's opening tag may have moved or changed. */
|
|
60
|
+
function placeOf(at: string, first: string | undefined): void {
|
|
61
|
+
const file = at.replace(/:\d+:\d+$/, '');
|
|
62
|
+
const line = Number(at.split(':').at(-2));
|
|
63
|
+
// Marks are from the dev server's root: here, above, or a folder with a .deictic/ of its own.
|
|
64
|
+
const roots = [process.cwd(), ...deicticDirs().map(dirname)];
|
|
65
|
+
const path = roots.map((r) => resolve(r, file)).find((p) => existsSync(p));
|
|
66
|
+
if (path === undefined) {
|
|
67
|
+
console.log(`\n${file} isn't under ${roots.join(' or ')}: find the dev server's root.`);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const lines = readFileSync(path, 'utf8').split('\n');
|
|
71
|
+
// The tag's first line may follow other code on its line: `const App = () => <h1>`.
|
|
72
|
+
const now = lines[line - 1]?.trim();
|
|
73
|
+
if (first === undefined || now?.includes(first.slice(0, 40))) {
|
|
74
|
+
console.log(`\nFile: ${path}:${line}, as the task saw it.`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const moved = lines.findIndex((l) => l.includes(first.slice(0, 40)));
|
|
78
|
+
console.log(
|
|
79
|
+
moved >= 0
|
|
80
|
+
? `\nFile: moved to ${path}:${moved + 1} (the task says line ${line}).`
|
|
81
|
+
: `\nFile: ${path}:${line} no longer reads as the task saw it; it was:\n ${first}`,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** What's attached, with the command to look at each, downloaded to `out` where it's given. */
|
|
86
|
+
function attachments(root: Message, out: string | undefined): void {
|
|
87
|
+
if (root.attachments.length > 0) console.log('\nAttached:');
|
|
88
|
+
if (out !== undefined) mkdirSync(out, { recursive: true });
|
|
89
|
+
for (const a of root.attachments) {
|
|
90
|
+
const kb = `${Math.round(a.size / 1024)} KB`;
|
|
91
|
+
if (out !== undefined) download(a, join(out, a.name));
|
|
92
|
+
const saved = out === undefined ? '' : ` → ${join(out, a.name)}`;
|
|
93
|
+
// To a file's path: the CLI writes what it's given, and refuses a folder.
|
|
94
|
+
const get = saved || `: ${ME} vb download ${a.id} ${a.name}`;
|
|
95
|
+
if (a.name.startsWith('recording-')) {
|
|
96
|
+
console.log(` ${a.name} (${kb})${saved}`);
|
|
97
|
+
console.log(` timeline: ${ME} recording ${root.id}`);
|
|
98
|
+
console.log(` frames: ${ME} frame ${root.id}`);
|
|
99
|
+
} else if (a.name.startsWith('voice-')) {
|
|
100
|
+
console.log(` ${a.name} (${kb}), a voice clip${saved}`);
|
|
101
|
+
console.log(` speech: ${ME} voice ${root.id}`);
|
|
102
|
+
} else if (a.name === 'element.html') {
|
|
103
|
+
console.log(` ${a.name} (${kb}), the element's HTML as it rendered, if you need it${get}`);
|
|
104
|
+
} else {
|
|
105
|
+
console.log(` ${a.name} (${a.type}, ${kb})${get}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The other open tasks about the same page, of the same project: left a minute apart, they're often one change. */
|
|
111
|
+
function others(root: Message): void {
|
|
112
|
+
const page = root.labels['deictic.page'];
|
|
113
|
+
if (page === undefined) return;
|
|
114
|
+
const project = root.labels['deictic.project'];
|
|
115
|
+
const labels = [`deictic.page=${page}`, ...(project === undefined ? [] : [`deictic.project=${project}`])];
|
|
116
|
+
const { tasks } = vbJson<{ tasks: { message: Message }[] }>(['tasks', root.channel, ...labels.flatMap((l) => ['--label', l])]);
|
|
117
|
+
const rest = tasks.map((t) => t.message).filter((m) => m.id !== root.id);
|
|
118
|
+
if (rest.length === 0) return;
|
|
119
|
+
console.log(
|
|
120
|
+
`\n${rest.length} other open task${rest.length === 1 ? '' : 's'} on ${page}: read them before you start, they may be one change.`,
|
|
121
|
+
);
|
|
122
|
+
for (const m of rest) {
|
|
123
|
+
const title = (m.text.split(/\n---\n/)[0] ?? '').split('\n')[0]?.slice(0, 100);
|
|
124
|
+
console.log(` #${m.id} ${m.task?.state ?? ''}, ${m.labels['deictic.at'] ?? '?'}: ${title}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `deictic transcribe`: what was said in voice clips, with when: Whisper on this machine, through transformers.js.
|
|
3
|
+
* For a recording, the times are the recording's, to line up with its timeline. Nothing leaves the machine once the
|
|
4
|
+
* model is downloaded.
|
|
5
|
+
*
|
|
6
|
+
* `--setup` puts @huggingface/transformers and the model in ~/.cache/deictic/transcribe (DEICTIC_CACHE moves it),
|
|
7
|
+
* outside the project; an agent asks the person first. Models: tiny (~40 MB), base (~77 MB, the default), small
|
|
8
|
+
* (~250 MB), large-v3-turbo (~800 MB), or any ONNX Whisper on Hugging Face by its ID. Needs ffmpeg on the PATH.
|
|
9
|
+
*/
|
|
10
|
+
import { spawnSync } from 'node:child_process';
|
|
11
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
12
|
+
import { createRequire } from 'node:module';
|
|
13
|
+
import { homedir } from 'node:os';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { pathToFileURL } from 'node:url';
|
|
16
|
+
|
|
17
|
+
import { clock, fail, ME, parseArgs } from './board.ts';
|
|
18
|
+
import { ffmpeg, voiceClips } from './find.ts';
|
|
19
|
+
|
|
20
|
+
export const usage = `transcribe <task | replay URL | recording ID | file | clip ID> [--model base] [--language en] [--json] what was said
|
|
21
|
+
transcribe --setup [--model base] installs it, outside the project: ask the person first`;
|
|
22
|
+
|
|
23
|
+
// Pinned, so a setup installs what this was written against; move it on deliberately.
|
|
24
|
+
const TRANSFORMERS = '@huggingface/transformers@4.3.2';
|
|
25
|
+
const MODELS: Record<string, string> = {
|
|
26
|
+
tiny: 'whisper-tiny',
|
|
27
|
+
base: 'whisper-base',
|
|
28
|
+
small: 'whisper-small',
|
|
29
|
+
'large-v3-turbo': 'whisper-large-v3-turbo',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** What of transformers.js this uses: its type isn't the project's, as it's installed outside it. */
|
|
33
|
+
interface Transformers {
|
|
34
|
+
env: { cacheDir: string; allowRemoteModels: boolean };
|
|
35
|
+
pipeline(
|
|
36
|
+
task: 'automatic-speech-recognition',
|
|
37
|
+
model: string,
|
|
38
|
+
options: { dtype: string },
|
|
39
|
+
): Promise<
|
|
40
|
+
(
|
|
41
|
+
audio: Float32Array,
|
|
42
|
+
options: Record<string, unknown>,
|
|
43
|
+
) => Promise<{ text: string; chunks?: { timestamp: [number, number | null]; text: string }[] }>
|
|
44
|
+
>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function run(args: string[]): Promise<void> {
|
|
48
|
+
const { values, positionals } = parseArgs(args, {
|
|
49
|
+
setup: { type: 'boolean' },
|
|
50
|
+
json: { type: 'boolean' },
|
|
51
|
+
model: { type: 'string', default: 'base' },
|
|
52
|
+
language: { type: 'string' },
|
|
53
|
+
});
|
|
54
|
+
const size = values.model;
|
|
55
|
+
const named = MODELS[size];
|
|
56
|
+
if (!size.includes('/') && named === undefined) fail(`--model is one of ${Object.keys(MODELS).join(', ')}, or a model ID`);
|
|
57
|
+
const model = named === undefined ? size : `onnx-community/${named}`;
|
|
58
|
+
const dir = join(process.env.DEICTIC_CACHE ?? join(homedir(), '.cache', 'deictic'), 'transcribe');
|
|
59
|
+
const models = join(dir, 'models');
|
|
60
|
+
const installed = existsSync(join(dir, 'node_modules', '@huggingface', 'transformers', 'package.json'));
|
|
61
|
+
const downloaded = existsSync(join(models, ...model.split('/')));
|
|
62
|
+
const again = `${ME} transcribe`;
|
|
63
|
+
const sized = size === 'base' ? '' : ` --model ${size}`;
|
|
64
|
+
|
|
65
|
+
if (values.setup) {
|
|
66
|
+
mkdirSync(dir, { recursive: true });
|
|
67
|
+
if (!existsSync(join(dir, 'package.json'))) writeFileSync(join(dir, 'package.json'), '{ "private": true }\n');
|
|
68
|
+
if (!installed) {
|
|
69
|
+
console.log(`Installing ${TRANSFORMERS} in ${dir}…`);
|
|
70
|
+
const windows = process.platform === 'win32';
|
|
71
|
+
const npm = ['install', '--prefix', dir, '--no-audit', '--no-fund', '--save-exact', TRANSFORMERS];
|
|
72
|
+
const run = spawnSync(windows ? `npm ${npm.map((a) => `"${a}"`).join(' ')}` : 'npm', windows ? [] : npm, {
|
|
73
|
+
stdio: 'inherit',
|
|
74
|
+
shell: windows,
|
|
75
|
+
});
|
|
76
|
+
if (run.status !== 0) fail(`npm install failed (${run.error?.message ?? `exit ${run.status}`}).`);
|
|
77
|
+
}
|
|
78
|
+
} else if (!installed || !downloaded) {
|
|
79
|
+
fail(
|
|
80
|
+
`Local transcription isn't set up${installed ? ` with the ${size} model` : ''}. Ask the person first: it downloads ` +
|
|
81
|
+
`${installed ? '' : `${TRANSFORMERS} (with ONNX Runtime, ~470 MB) and `}Whisper ${size} into ${dir}, outside ` +
|
|
82
|
+
`the project; after that, audio is transcribed on this machine. On yes: ${again} --setup${sized} (--model small ` +
|
|
83
|
+
`hears better, ~250 MB more). On no, don't ask again this session: work from ${ME} voice's times.`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const entry = createRequire(join(dir, 'package.json')).resolve('@huggingface/transformers');
|
|
88
|
+
const transformers = (await import(pathToFileURL(entry).href)) as Transformers;
|
|
89
|
+
transformers.env.cacheDir = models;
|
|
90
|
+
// Only setup downloads; a transcription uses what's here.
|
|
91
|
+
transformers.env.allowRemoteModels = values.setup === true;
|
|
92
|
+
if (values.setup) console.log(`Downloading ${model} (quantized) into ${models}…`);
|
|
93
|
+
const asr = await transformers.pipeline('automatic-speech-recognition', model, { dtype: 'q8' });
|
|
94
|
+
if (values.setup) {
|
|
95
|
+
console.log(`Ready: ${again} <task>${sized}`);
|
|
96
|
+
if (positionals[0] === undefined) return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const results = [];
|
|
100
|
+
for (const c of await voiceClips(positionals[0])) {
|
|
101
|
+
// Whisper takes 16 kHz mono samples; ffmpeg decodes the clip (webm, ogg or mp4) to them.
|
|
102
|
+
const raw = ffmpeg(['-loglevel', 'error', '-i', c.file, '-f', 'f32le', '-ac', '1', '-ar', '16000', '-']).stdout;
|
|
103
|
+
const audio = new Float32Array(raw.buffer.slice(raw.byteOffset, raw.byteOffset + raw.byteLength - (raw.byteLength % 4)));
|
|
104
|
+
const seconds = audio.length / 16000;
|
|
105
|
+
const out = await asr(audio, {
|
|
106
|
+
return_timestamps: true,
|
|
107
|
+
chunk_length_s: 30,
|
|
108
|
+
stride_length_s: 5,
|
|
109
|
+
...(values.language === undefined ? {} : { language: values.language }),
|
|
110
|
+
});
|
|
111
|
+
const said = (out.chunks ?? [{ timestamp: [0, seconds] as [number, number], text: out.text }]).map(
|
|
112
|
+
({ timestamp: [from, to], text }) => ({
|
|
113
|
+
from: c.at + from * 1000,
|
|
114
|
+
to: c.at + (to ?? seconds) * 1000,
|
|
115
|
+
text: text.trim(),
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
118
|
+
results.push({ ...c, text: out.text.trim(), said });
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (values.json) {
|
|
122
|
+
console.log(JSON.stringify(results, null, 2));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
for (const r of results) {
|
|
126
|
+
console.log(`clip ${r.id} (${r.recording === undefined ? 'a voice note' : `in recording ${r.recording}, from ${clock(r.at)}`}):`);
|
|
127
|
+
for (const s of r.said) console.log(` ${clock(s.from).padStart(6)} – ${clock(s.to).padStart(6)} ${s.text}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
package/src/cli/vb.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `deictic vb`: the board's CLI as the other commands run it, the project's own `@vercel/board`, which needn't be on
|
|
3
|
+
* the PATH, on the board the dev server uses (`BOARD_URL`, or with none, the one `.deictic/board.json` names).
|
|
4
|
+
*/
|
|
5
|
+
import { vbHere } from './board.ts';
|
|
6
|
+
|
|
7
|
+
export const usage = 'vb <anything vb takes> the board on the dev server: vb whoami, vb tasks claim 68 --lease 30m';
|
|
8
|
+
|
|
9
|
+
export function run(args: string[]): void {
|
|
10
|
+
process.exit(vbHere(args));
|
|
11
|
+
}
|