deictic 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +303 -0
- package/README.md +56 -127
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +117 -7
- package/dist/client/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/logs/client.d.ts +4 -0
- package/dist/logs/client.d.ts.map +1 -0
- package/dist/logs/client.js +16 -0
- package/dist/logs/client.js.map +1 -0
- package/dist/logs/index.d.ts +18 -0
- package/dist/logs/index.d.ts.map +1 -0
- package/dist/logs/index.js +21 -0
- package/dist/logs/index.js.map +1 -0
- package/dist/network/client.d.ts +4 -0
- package/dist/network/client.d.ts.map +1 -0
- package/dist/network/client.js +29 -0
- package/dist/network/client.js.map +1 -0
- package/dist/network/index.d.ts +2 -0
- package/dist/network/index.js +39 -0
- package/dist/network/index.js.map +1 -0
- package/dist/recommended/index.d.ts +13 -3
- package/dist/recommended/index.d.ts.map +1 -1
- package/dist/recommended/index.js +8 -1
- package/dist/recommended/index.js.map +1 -1
- package/dist/recordings/client.d.ts +1 -1
- package/dist/recordings/client.d.ts.map +1 -1
- package/dist/recordings/client.js +175 -46
- package/dist/recordings/client.js.map +1 -1
- package/dist/recordings/index.d.ts +2 -2
- package/dist/screenshots/client.d.ts +6 -0
- package/dist/screenshots/client.d.ts.map +1 -1
- package/dist/screenshots/client.js +34 -2
- package/dist/screenshots/client.js.map +1 -1
- package/dist/screenshots/dom.d.ts.map +1 -1
- package/dist/screenshots/dom.js +1 -28
- package/dist/screenshots/dom.js.map +1 -1
- package/dist/screenshots/index.js.map +1 -1
- package/dist/screenshots/rrweb.d.ts +1 -1
- package/dist/screenshots/rrweb.js +5 -1
- package/dist/screenshots/rrweb.js.map +1 -1
- package/dist/shared/index.d.ts +14 -2
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index2.d.ts +2 -0
- package/dist/shared/index2.d.ts.map +1 -1
- package/dist/shared/index3.d.ts +29 -3
- package/dist/shared/index3.d.ts.map +1 -1
- package/dist/shared/index4.d.ts +52 -172
- package/dist/shared/index4.d.ts.map +1 -1
- package/dist/shared/index5.d.ts +208 -58
- package/dist/shared/index5.d.ts.map +1 -1
- package/dist/shared/index6.d.ts +70 -0
- package/dist/shared/index6.d.ts.map +1 -0
- package/dist/shared/marks.js +6 -1
- package/dist/shared/marks.js.map +1 -1
- package/dist/shared/mask.js +107 -0
- package/dist/shared/mask.js.map +1 -0
- package/dist/shared/playwright.js +19 -4
- package/dist/shared/playwright.js.map +1 -1
- package/dist/shared/recordings.js +219 -28
- package/dist/shared/recordings.js.map +1 -1
- package/dist/shared/tasks.js +145 -34
- package/dist/shared/tasks.js.map +1 -1
- package/dist/tailwind/client.d.ts +1 -1
- package/dist/tailwind/index.d.ts +1 -1
- package/dist/tasks/client.d.ts +1 -1
- package/dist/tasks/client.d.ts.map +1 -1
- package/dist/tasks/client.js +271 -56
- package/dist/tasks/client.js.map +1 -1
- package/dist/tasks/index.d.ts +2 -2
- package/dist/voice/client.d.ts.map +1 -1
- package/dist/voice/client.js +35 -14
- package/dist/voice/client.js.map +1 -1
- package/dist/voice/index.d.ts +6 -1
- package/dist/voice/index.d.ts.map +1 -1
- package/dist/voice/index.js +12 -2
- package/dist/voice/index.js.map +1 -1
- package/package.json +41 -2
- package/skills/deictic/SKILL.md +20 -14
- package/skills/deictic/references/install.md +18 -11
- package/skills/deictic/references/recordings.md +29 -0
- package/skills/deictic/references/tasks.md +49 -21
- package/skills/deictic/references/watch.md +38 -11
- package/skills/deictic/scripts/lib.mjs +69 -3
- package/skills/deictic/scripts/recording.mjs +84 -4
- package/skills/deictic/scripts/task.mjs +36 -7
- package/skills/deictic/scripts/vb.mjs +12 -0
- package/skills/deictic/scripts/watch.mjs +74 -10
- package/src/client/away.ts +105 -0
- package/src/client/index.ts +40 -9
- package/src/client/style.ts +1 -0
- package/src/index.ts +14 -2
- package/src/plugins/logs/client.ts +18 -0
- package/src/plugins/logs/index.ts +55 -0
- package/src/plugins/network/client.ts +30 -0
- package/src/plugins/network/index.ts +69 -0
- package/src/plugins/network/mask.ts +133 -0
- package/src/plugins/recommended/index.ts +14 -1
- package/src/plugins/recordings/client.ts +219 -40
- package/src/plugins/recordings/index.ts +108 -23
- package/src/plugins/recordings/marks.ts +6 -0
- package/src/plugins/recordings/replay.ts +127 -4
- package/src/plugins/screenshots/client.ts +35 -0
- package/src/plugins/screenshots/dom.ts +1 -32
- package/src/plugins/screenshots/index.ts +2 -0
- package/src/plugins/screenshots/playwright.ts +15 -4
- package/src/plugins/screenshots/rrweb.ts +2 -1
- package/src/plugins/tasks/client.ts +273 -41
- package/src/plugins/tasks/index.ts +155 -39
- package/src/plugins/tasks/watchers.ts +36 -0
- package/src/plugins/voice/client.ts +33 -11
- package/src/plugins/voice/index.ts +21 -4
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
* `deictic/tasks`: open its tab on an element to add a task about it to a Vercel Board
|
|
3
3
|
* (`@vercel/board`). The task says what to change, in the words typed, and where: the element's file,
|
|
4
4
|
* line and tag, the page and the project, all as labels beside the short facts (viewport, how many, where
|
|
5
|
-
* it is in the shot)
|
|
5
|
+
* it is in the shot), and after the words what a label can't hold: the chain of source it rendered through, from
|
|
6
|
+
* its own line out to the files that use its component. Its HTML as it rendered is a file attached, `element.html`, for whoever
|
|
7
|
+
* wants more than the task says: a task stays short. Whatever works the board's tasks (a person, or an agent of theirs claiming them) takes it
|
|
6
8
|
* from there; deictic only adds them.
|
|
7
9
|
*
|
|
8
10
|
* Adding one is a change like any other: undo cancels the task, while no one has claimed it, and redo
|
|
9
|
-
* adds it again, as a new task. Each task carries `deictic.at=<file:line:column
|
|
10
|
-
* lists the ones about the element clicked,
|
|
11
|
+
* adds it again, as a new task. Each task carries `deictic.at=<file:line:column>` and `deictic.file`, so
|
|
12
|
+
* the panel lists the ones about the element clicked, and after them the rest of its file's. One whose
|
|
13
|
+
* place is no longer the element's is still its own where the tag and the line it saw (`deictic.line`) are
|
|
14
|
+
* the element's, and that line is in the file once: the element has moved, as lines above it changed.
|
|
11
15
|
*/
|
|
12
16
|
import { readFileSync } from 'node:fs';
|
|
13
17
|
import { join, relative } from 'node:path';
|
|
@@ -21,11 +25,12 @@ import type { Box } from '#src/plugins/screenshots/index.ts';
|
|
|
21
25
|
import type { Clips } from '#src/plugins/voice/index.ts';
|
|
22
26
|
|
|
23
27
|
import { type LocalBoard, localBoard } from './local.ts';
|
|
28
|
+
import { watchersOf } from './watchers.ts';
|
|
24
29
|
|
|
25
30
|
export { local, type LocalBoard, type LocalOptions } from './local.ts';
|
|
26
31
|
|
|
27
32
|
/** What the plugin uses of a board: `board()` from `@vercel/board` is one. */
|
|
28
|
-
export type TaskBoard = Pick<Board, 'tasks' | 'thread' | 'discovery' | 'upload' | 'edit'>;
|
|
33
|
+
export type TaskBoard = Pick<Board, 'tasks' | 'thread' | 'discovery' | 'upload' | 'edit' | 'actors'>;
|
|
29
34
|
|
|
30
35
|
export interface TasksOptions {
|
|
31
36
|
/**
|
|
@@ -52,6 +57,13 @@ export interface TasksOptions {
|
|
|
52
57
|
* deictic can't know.
|
|
53
58
|
*/
|
|
54
59
|
link?: (channel: string, task?: string) => string | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Whether a task has the element's HTML as it rendered attached, as `element.html`, masked as a screenshot is
|
|
62
|
+
* (the screenshots plugin's masking, where it's loaded): what was on the page, for whoever can't open it as the
|
|
63
|
+
* person did. True by default: the Task tab has a box for it, ticked, to untick for a task that should go
|
|
64
|
+
* without. `false` takes the box away, where a page shows what the board shouldn't hold.
|
|
65
|
+
*/
|
|
66
|
+
html?: boolean;
|
|
55
67
|
/** What opens its tab directly, beside deictic's own shortcut, which opens any: none by default. */
|
|
56
68
|
shortcut?: Shortcut;
|
|
57
69
|
}
|
|
@@ -67,14 +79,35 @@ export interface Task {
|
|
|
67
79
|
open: boolean;
|
|
68
80
|
/** Its page on the board, when there's one to link to. */
|
|
69
81
|
link?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Where it was added, where that isn't the element's place: for one of `tasks`, where the element was before
|
|
84
|
+
* it moved; for one of `elsewhere`, the element it's about.
|
|
85
|
+
*/
|
|
86
|
+
at?: Place;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** A place in the element's file: a line and a column, from 1, and the tag there as the task saw it. */
|
|
90
|
+
export interface Place {
|
|
91
|
+
line: number;
|
|
92
|
+
column: number;
|
|
93
|
+
tag: string;
|
|
70
94
|
}
|
|
71
95
|
|
|
72
96
|
export interface Model {
|
|
73
97
|
channel: string;
|
|
74
98
|
/** The channel's page, when there's one to link to. */
|
|
75
99
|
link?: string;
|
|
76
|
-
/** Tasks about this element, oldest first, canceled ones left out. */
|
|
100
|
+
/** Tasks about this element, oldest first, canceled ones left out: also those added before it moved. */
|
|
77
101
|
tasks: Task[];
|
|
102
|
+
/** Tasks about the file's other elements, by line, canceled ones left out: each with its `at`. */
|
|
103
|
+
elsewhere: Task[];
|
|
104
|
+
/**
|
|
105
|
+
* Who watches the channel, by name (`claude`): the agents whose watch (the skill's `watch.mjs`) is running in
|
|
106
|
+
* this project, as a board can't say, and those holding a claim on one of the channel's tasks, which it can.
|
|
107
|
+
* Empty where none is and the board is this machine's own;
|
|
108
|
+
* left out where none is and the board is another, which an agent may watch from elsewhere.
|
|
109
|
+
*/
|
|
110
|
+
watching?: string[];
|
|
78
111
|
}
|
|
79
112
|
|
|
80
113
|
/**
|
|
@@ -96,11 +129,19 @@ export interface Op {
|
|
|
96
129
|
pointed?: { path: string; html: string };
|
|
97
130
|
/** How many elements on the page come from the same place in the source. */
|
|
98
131
|
count: number;
|
|
132
|
+
/**
|
|
133
|
+
* The source it rendered through, after its own place, nearest first, each a `file:line`: where the file
|
|
134
|
+
* before it is used. A shared component's line says nothing of which use of it this is, and these do.
|
|
135
|
+
*/
|
|
136
|
+
chain?: string[];
|
|
137
|
+
/** The element's HTML as it rendered, to attach: cut short, and masked where the screenshots plugin is loaded. */
|
|
138
|
+
html?: string;
|
|
99
139
|
/**
|
|
100
140
|
* Shots the screenshots plugin took of it, to attach, where that plugin is loaded: each with where the
|
|
101
|
-
* element is in it,
|
|
141
|
+
* element is in it, whether it's `outlined` there (dashes drawn around it, in the PNG), and the marks drawn
|
|
142
|
+
* on it in the panel, where there are any.
|
|
102
143
|
*/
|
|
103
|
-
screenshots?: { id: string; box: Box; marks?: Marks }[];
|
|
144
|
+
screenshots?: { id: string; box: Box; outlined?: boolean; marks?: Marks }[];
|
|
104
145
|
/**
|
|
105
146
|
* Recordings the recordings plugin made, to attach, where that plugin is loaded: how long each ran,
|
|
106
147
|
* where it plays back, and the voice plugin's clips of the mic in it, attached too.
|
|
@@ -165,6 +206,7 @@ export interface Removed extends Added {
|
|
|
165
206
|
export type Kept = Added | Edited | Removed;
|
|
166
207
|
|
|
167
208
|
const AT = 'deictic.at';
|
|
209
|
+
const FILE = 'deictic.file';
|
|
168
210
|
/** What parts what was typed from the rest of a task's text. */
|
|
169
211
|
const REST = '\n---\n';
|
|
170
212
|
const OPEN = new Set(['waiting', 'ready', 'blocked']);
|
|
@@ -263,7 +305,7 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
263
305
|
// Kept from `setup`, to `use` another plugin when an op asks for it.
|
|
264
306
|
let context: ServerContext | undefined;
|
|
265
307
|
let project = options.project;
|
|
266
|
-
/** The screenshots and
|
|
308
|
+
/** The screenshots, recordings and the element's HTML to attach, uploaded to the board, or nothing when there are none. */
|
|
267
309
|
const attach = async (op: Op): Promise<string[] | undefined> => {
|
|
268
310
|
// All read first, so one no longer kept uploads none.
|
|
269
311
|
const files = [
|
|
@@ -282,6 +324,10 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
282
324
|
if (clip === undefined) throw new Refusal(`voice clip ${id} isn't kept any more: record it again`);
|
|
283
325
|
return clip;
|
|
284
326
|
}),
|
|
327
|
+
// Last, and a file, not the task's words: it's there to look into, and most tasks are done without it.
|
|
328
|
+
...(typeof op.html !== 'string' || op.html === ''
|
|
329
|
+
? []
|
|
330
|
+
: [{ data: new TextEncoder().encode(op.html.slice(0, HTML)), name: 'element.html', type: 'text/html' }]),
|
|
285
331
|
];
|
|
286
332
|
if (files.length === 0) return undefined;
|
|
287
333
|
const team = await boardOf();
|
|
@@ -291,6 +337,8 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
291
337
|
return definePlugin<Model, Change, Kept>({
|
|
292
338
|
name: 'tasks',
|
|
293
339
|
client: 'deictic/tasks/client',
|
|
340
|
+
// Only where it's turned off: the page half sends the HTML unless told not to.
|
|
341
|
+
...(options.html === false ? { clientOptions: { html: false } } : {}),
|
|
294
342
|
shortcut: options.shortcut,
|
|
295
343
|
setup: (given) => {
|
|
296
344
|
context = given;
|
|
@@ -300,30 +348,56 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
300
348
|
// Not waited for: a failure is the first request's to tell.
|
|
301
349
|
void boardOf().catch(() => {});
|
|
302
350
|
},
|
|
303
|
-
read: (
|
|
351
|
+
read: (source, target) =>
|
|
304
352
|
asked(async () => {
|
|
305
|
-
const
|
|
306
|
-
|
|
353
|
+
const team = await boardOf();
|
|
354
|
+
const labelled = (label: Record<string, string>) => team.tasks.list({ channel, label, state: 'all' });
|
|
355
|
+
// By place too: a task added before there was a `deictic.file` has none, and is still its element's.
|
|
356
|
+
const [here, inFile, page, held] = await Promise.all([
|
|
357
|
+
labelled({ [AT]: atOf(target) }),
|
|
358
|
+
labelled({ [FILE]: clip(target.loc.file, LABEL) }),
|
|
307
359
|
linkOf(),
|
|
360
|
+
team.tasks.list({ channel, state: 'claimed' }),
|
|
308
361
|
]);
|
|
362
|
+
const listed = new Set(inFile.tasks.map(({ message }) => message.id));
|
|
363
|
+
const line = lineOf(source);
|
|
364
|
+
// A line the file has twice says nothing of which element a task was about.
|
|
365
|
+
const once = source.code.split(line).length === 2;
|
|
366
|
+
const tasks: Task[] = [];
|
|
367
|
+
const elsewhere: (Task & { at: Place })[] = [];
|
|
368
|
+
for (const { message } of [...here.tasks.filter((t) => !listed.has(t.message.id)), ...inFile.tasks]) {
|
|
369
|
+
const state = message.task?.state ?? 'ready';
|
|
370
|
+
if (state === 'canceled') continue;
|
|
371
|
+
const text = message.text.split(REST, 1)[0]!;
|
|
372
|
+
const to = taskLink(page, message.id);
|
|
373
|
+
const task = {
|
|
374
|
+
id: message.id,
|
|
375
|
+
title: text.split('\n', 1)[0]!,
|
|
376
|
+
text,
|
|
377
|
+
state,
|
|
378
|
+
open: OPEN.has(state),
|
|
379
|
+
...(to === undefined ? {} : { link: to }),
|
|
380
|
+
};
|
|
381
|
+
const at = placeIn(message.labels);
|
|
382
|
+
if (at === undefined || message.labels[AT] === atOf(target)) tasks.push(task);
|
|
383
|
+
else if (once && at.tag === target.tag && message.labels['deictic.line'] === clip(line, LABEL)) tasks.push({ ...task, at });
|
|
384
|
+
else elsewhere.push({ ...task, at });
|
|
385
|
+
}
|
|
386
|
+
// An agent at work on a task is here too, though its watch may be over until the task is (`watch.mjs --once`).
|
|
387
|
+
const working = await agentsOf(
|
|
388
|
+
team,
|
|
389
|
+
held.tasks.flatMap(({ message }) => message.task?.claim ?? []),
|
|
390
|
+
);
|
|
391
|
+
const watching = [...new Set([...watchersOf(root ?? process.cwd(), channel), ...working])].sort();
|
|
392
|
+
// A board of this machine's own is watched from here or not at all.
|
|
393
|
+
const ours = own !== undefined || (options.board === undefined && process.env.BOARD_URL === undefined);
|
|
309
394
|
return {
|
|
310
395
|
channel,
|
|
311
396
|
...(page === undefined ? {} : { link: page }),
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
const to = taskLink(page, message.id);
|
|
317
|
-
return {
|
|
318
|
-
id: message.id,
|
|
319
|
-
title: text.split('\n', 1)[0]!,
|
|
320
|
-
text,
|
|
321
|
-
state,
|
|
322
|
-
open: OPEN.has(state),
|
|
323
|
-
...(to === undefined ? {} : { link: to }),
|
|
324
|
-
};
|
|
325
|
-
})
|
|
326
|
-
.filter((t) => t.state !== 'canceled'),
|
|
397
|
+
...(watching.length > 0 || ours ? { watching } : {}),
|
|
398
|
+
tasks,
|
|
399
|
+
// The board's order (oldest first) among those of one place.
|
|
400
|
+
elsewhere: elsewhere.sort((a, b) => (a.at.line === b.at.line ? a.at.column - b.at.column : a.at.line - b.at.line)),
|
|
327
401
|
};
|
|
328
402
|
}),
|
|
329
403
|
apply: (source, target, op) => {
|
|
@@ -357,7 +431,7 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
357
431
|
return asked(async () => {
|
|
358
432
|
const attachments = await attach(op);
|
|
359
433
|
return {
|
|
360
|
-
done: await create({ channel, text: textOf(op), labels, ...(attachments === undefined ? {} : { attachments }) }),
|
|
434
|
+
done: await create({ channel, text: textOf(op, target), labels, ...(attachments === undefined ? {} : { attachments }) }),
|
|
361
435
|
};
|
|
362
436
|
});
|
|
363
437
|
},
|
|
@@ -442,27 +516,42 @@ const clock = (ms: number) => {
|
|
|
442
516
|
};
|
|
443
517
|
|
|
444
518
|
/**
|
|
445
|
-
* What
|
|
446
|
-
* shot's place is the `deictic.position` and `deictic.size` labels, so a shot with
|
|
519
|
+
* What's drawn on each shot (the element's outline, the person's marks), and with several, where the element is
|
|
520
|
+
* in each. One shot's place is the `deictic.position` and `deictic.size` labels, so a shot with nothing drawn
|
|
521
|
+
* on it has no line.
|
|
447
522
|
*/
|
|
448
523
|
function shotsOf(shots: NonNullable<Op['screenshots']>): string[] {
|
|
449
524
|
const [only] = shots;
|
|
450
525
|
if (shots.length === 1 && only !== undefined) {
|
|
451
|
-
const { marks } = only;
|
|
452
|
-
|
|
453
|
-
? []
|
|
454
|
-
|
|
526
|
+
const { marks, outlined } = only;
|
|
527
|
+
const has = [
|
|
528
|
+
...(outlined === true ? ['the element outlined in dashes'] : []),
|
|
529
|
+
...(marks === undefined || marks.count === 0 ? [] : [`${plural(marks.count, 'mark')} drawn on it${said(marks.notes)}`]),
|
|
530
|
+
];
|
|
531
|
+
return has.length === 0 ? [] : [`The screenshot has ${has.join(' and ')}`];
|
|
455
532
|
}
|
|
456
|
-
return shots.map(({ box, marks }, i) => {
|
|
533
|
+
return shots.map(({ box, marks, outlined }, i) => {
|
|
457
534
|
const drawn = marks === undefined || marks.count === 0 ? '' : `, with ${plural(marks.count, 'mark')} drawn on it${said(marks.notes)}`;
|
|
458
535
|
const [x, y, width, height] = boxOf(box);
|
|
459
|
-
return `In screenshot ${i + 1} at x ${x}, y ${y}, ${width}×${height}${drawn}`;
|
|
536
|
+
return `In screenshot ${i + 1} at x ${x}, y ${y}, ${width}×${height}${outlined === true ? ', outlined in dashes' : ''}${drawn}`;
|
|
460
537
|
});
|
|
461
538
|
}
|
|
462
539
|
|
|
540
|
+
/** `Source: src/ui/label.tsx:6 ← src/Field.tsx:20 ← src/Panel.tsx:880`: from the element's line out, as the page said it. */
|
|
541
|
+
function chainOf({ loc }: Target, chain: NonNullable<Op['chain']>): string[] {
|
|
542
|
+
const places = chain.slice(0, CHAIN).map((place) => clip(String(place), LABEL));
|
|
543
|
+
return places.length === 0 ? [] : [`Source: ${[`${loc.file}:${loc.line}`, ...places].join(' ← ')}`];
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/** How many places a chain names after the element's own: the first few say which use of a component it is. */
|
|
547
|
+
const CHAIN = 5;
|
|
548
|
+
|
|
463
549
|
/** A box as `x,y,width,height`, in whole CSS pixels from the shot's top left. */
|
|
464
550
|
const boxOf = ({ x, y, width, height }: Box) => [x, y, width, height].map(Math.round);
|
|
465
551
|
|
|
552
|
+
/** What `element.html` holds of an element at most, in characters: a table's rows, not a whole page. */
|
|
553
|
+
const HTML = 100_000;
|
|
554
|
+
|
|
466
555
|
/** A label's value: a board holds 256 characters. */
|
|
467
556
|
const LABEL = 256;
|
|
468
557
|
|
|
@@ -485,8 +574,9 @@ function labelsOf({ code, element }: Source, target: Target, op: Op): Record<str
|
|
|
485
574
|
const [shot] = op.screenshots ?? [];
|
|
486
575
|
return {
|
|
487
576
|
[AT]: atOf(target),
|
|
577
|
+
[FILE]: clip(target.loc.file, LABEL),
|
|
488
578
|
'deictic.tag': target.tag,
|
|
489
|
-
'deictic.line': clip(code
|
|
579
|
+
'deictic.line': clip(lineOf({ code, element }), LABEL),
|
|
490
580
|
'deictic.page': clip(new URL(op.page).pathname, LABEL),
|
|
491
581
|
...(op.page.length <= LABEL ? { 'deictic.url': op.page } : {}),
|
|
492
582
|
'deictic.viewport': `${op.viewport.width}x${op.viewport.height}`,
|
|
@@ -501,19 +591,45 @@ function placeOf(box: Box): Record<string, string> {
|
|
|
501
591
|
return { 'deictic.position': `${x},${y}`, 'deictic.size': `${width}x${height}` };
|
|
502
592
|
}
|
|
503
593
|
|
|
594
|
+
/**
|
|
595
|
+
* The agents holding these claims, by name, while their leases run. An actor's ID isn't read for it (each board
|
|
596
|
+
* writes them its own way), so the board is asked who they are, and only when a claim is held. A person holding
|
|
597
|
+
* one is left out: they needn't be told they're there. (Whatever else holds one works tasks: an agent, a workflow.)
|
|
598
|
+
*/
|
|
599
|
+
async function agentsOf(team: TaskBoard, claims: { actor: string; until: string }[]): Promise<string[]> {
|
|
600
|
+
const holders = new Set(claims.filter((claim) => Date.parse(claim.until) > Date.now()).map((claim) => claim.actor));
|
|
601
|
+
if (holders.size === 0) return [];
|
|
602
|
+
// By ID, which a board from 0.54 answers without listing everyone; an older one lists them all, so they're picked out here too.
|
|
603
|
+
return (await team.actors({ id: [...holders] }))
|
|
604
|
+
.filter((actor) => holders.has(actor.id) && actor.kind !== 'person')
|
|
605
|
+
.map((actor) => actor.name);
|
|
606
|
+
}
|
|
607
|
+
|
|
504
608
|
const atOf = ({ loc }: Target) => `${loc.file}:${loc.line}:${loc.column}`;
|
|
505
609
|
|
|
610
|
+
/** The opening tag's first line, as written. */
|
|
611
|
+
const lineOf = ({ code, element }: Pick<Source, 'code' | 'element'>) => code.slice(element.start, element.end).split('\n', 1)[0]!.trim();
|
|
612
|
+
|
|
613
|
+
/** Where a task says its element is, from its labels. */
|
|
614
|
+
function placeIn(labels: Record<string, string>): Place | undefined {
|
|
615
|
+
const [, line, column] = /:(\d+):(\d+)$/.exec(labels[AT] ?? '') ?? [];
|
|
616
|
+
if (line === undefined || column === undefined) return undefined;
|
|
617
|
+
return { line: Number(line), column: Number(column), tag: labels['deictic.tag'] ?? '' };
|
|
618
|
+
}
|
|
619
|
+
|
|
506
620
|
/**
|
|
507
|
-
* The task's text: what was typed, and after a `---` only what no label holds: what's attached and drawn,
|
|
508
|
-
* was pointed at inside
|
|
621
|
+
* The task's text: what was typed, and after a `---` only what no label holds: what's attached and drawn, the
|
|
622
|
+
* source it rendered through, what was pointed at inside it, and a URL too long for a label.
|
|
623
|
+
* A board holds 10,000 characters.
|
|
509
624
|
*/
|
|
510
|
-
function textOf(op: Op): string {
|
|
625
|
+
function textOf(op: Op, target: Target): string {
|
|
511
626
|
const more = [
|
|
512
627
|
...(op.page.length <= LABEL ? [] : [op.page]),
|
|
513
628
|
...shotsOf(op.screenshots ?? []),
|
|
514
629
|
...recordingsOf(op.recordings ?? []),
|
|
515
630
|
...voicesOf(op.voice ?? []),
|
|
516
631
|
...(op.annotations === undefined ? [] : [annotated(op.annotations, op.screenshots?.length ?? 0, op.recordings?.length ?? 0)]),
|
|
632
|
+
...chainOf(target, op.chain ?? []),
|
|
517
633
|
...(op.pointed === undefined ? [] : [`Pointed at, inside it: \`${op.pointed.path}\``, fence(op.pointed.html, 'html')]),
|
|
518
634
|
];
|
|
519
635
|
const tail = more.length === 0 ? '' : REST + more.join('\n');
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who watches the channel for tasks. A board can't say (it knows who claimed a task, not who's listening), so a
|
|
3
|
+
* watch says it itself: the skill's `watch.mjs` keeps a file under `.deictic/watchers` while it runs, written
|
|
4
|
+
* again every 20 seconds, and the Task tab shows the names, so a person knows whether a task they add is taken up.
|
|
5
|
+
* (An agent holding a claim is one more, which the board does say: `agentsOf`, in `index.ts`.)
|
|
6
|
+
*/
|
|
7
|
+
import { readdirSync, readFileSync, rmSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
|
|
10
|
+
import { keptIn } from '#src/tools/kept.ts';
|
|
11
|
+
|
|
12
|
+
/** How old a watch's last word may be: three of its beats, as one killed says nothing more. */
|
|
13
|
+
const FRESH = 60_000;
|
|
14
|
+
|
|
15
|
+
/** The names watching `channel` from this project now, each once, in order. */
|
|
16
|
+
export function watchersOf(root: string, channel: string, now = Date.now()): string[] {
|
|
17
|
+
const dir = keptIn(root, 'watchers');
|
|
18
|
+
let files: string[];
|
|
19
|
+
try {
|
|
20
|
+
files = readdirSync(dir);
|
|
21
|
+
} catch {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
const names = new Set<string>();
|
|
25
|
+
for (const file of files) {
|
|
26
|
+
const path = join(dir, file);
|
|
27
|
+
try {
|
|
28
|
+
const { name, channel: of, at } = JSON.parse(readFileSync(path, 'utf8')) as { name?: unknown; channel?: unknown; at?: unknown };
|
|
29
|
+
if (typeof at !== 'number' || now - at > FRESH) rmSync(path, { force: true });
|
|
30
|
+
else if (of === channel && typeof name === 'string') names.add(name);
|
|
31
|
+
} catch {
|
|
32
|
+
// Half written: whole by the next read.
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return [...names].sort();
|
|
36
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The voice plugin's page half: `start()` asks for the mic (the browser asks the user the first time) and
|
|
3
|
-
* records it with `MediaRecorder
|
|
4
|
-
*
|
|
3
|
+
* records it with `MediaRecorder`, sending what's spoken each second: the take's start to the `add` route,
|
|
4
|
+
* the rest to `more/<id>`. So a take the page leaves in the middle of (a recording that goes on to another
|
|
5
|
+
* page) is kept up to there. `stop` sends the last of it and lets the mic go, so the browser's recording
|
|
6
|
+
* light goes out between takes.
|
|
5
7
|
*/
|
|
6
8
|
import { defineClientPlugin } from '#src/index.ts';
|
|
7
9
|
|
|
@@ -9,6 +11,8 @@ import type { Clip, Voice } from './index.ts';
|
|
|
9
11
|
|
|
10
12
|
/** What the browser can record, best first: Opus in WebM where it can (Chrome, Firefox), else MP4 (Safari). */
|
|
11
13
|
const TYPES = ['audio/webm;codecs=opus', 'audio/webm', 'audio/ogg;codecs=opus', 'audio/mp4'];
|
|
14
|
+
/** How often what's spoken is sent, in milliseconds: what a page load can lose of a take. */
|
|
15
|
+
const EVERY = 1000;
|
|
12
16
|
|
|
13
17
|
export default defineClientPlugin<never, never, Voice>({
|
|
14
18
|
name: 'voice',
|
|
@@ -21,10 +25,30 @@ export default defineClientPlugin<never, never, Voice>({
|
|
|
21
25
|
});
|
|
22
26
|
const mimeType = TYPES.find((t) => MediaRecorder.isTypeSupported(t));
|
|
23
27
|
const recorder = new MediaRecorder(stream, mimeType === undefined ? {} : { mimeType });
|
|
24
|
-
const
|
|
25
|
-
|
|
28
|
+
const typeOf = () => (recorder.mimeType || mimeType || 'audio/webm').split(';')[0]!;
|
|
29
|
+
// The clip, once its start is kept, and where it is, where what keeps it says (a `standalone` build's does).
|
|
30
|
+
let id: string | undefined;
|
|
31
|
+
let url: string | undefined;
|
|
32
|
+
// One request at a time, in the order spoken: the audio is its pieces end to end. The first problem ends the sending.
|
|
33
|
+
let sent: Promise<void> = Promise.resolve();
|
|
34
|
+
const send = (body: Blob | undefined, last = false) => {
|
|
35
|
+
sent = sent.then(async () => {
|
|
36
|
+
if (id === undefined && body === undefined) throw new Error('voice: the clip is empty: speak for a moment longer');
|
|
37
|
+
const route = id === undefined ? 'add' : `more/${id}${last ? '?last' : ''}`;
|
|
38
|
+
const res = await request(route, { method: 'POST', headers: { 'content-type': typeOf() }, ...(body ? { body } : {}) });
|
|
39
|
+
const answer = (await res.json()) as { id?: string; url?: string; problem?: string };
|
|
40
|
+
if (answer.id === undefined) throw new Error(`voice: ${answer.problem ?? res.statusText}`);
|
|
41
|
+
id = answer.id;
|
|
42
|
+
url = answer.url ?? url;
|
|
43
|
+
});
|
|
44
|
+
return sent;
|
|
45
|
+
};
|
|
46
|
+
recorder.addEventListener('dataavailable', (e) => {
|
|
47
|
+
// Heard only at `stop`, with the rest: a problem here is that one's.
|
|
48
|
+
if (e.data.size > 0) send(new Blob([e.data], { type: typeOf() })).catch(() => {});
|
|
49
|
+
});
|
|
26
50
|
const started = Date.now();
|
|
27
|
-
recorder.start();
|
|
51
|
+
recorder.start(EVERY);
|
|
28
52
|
const release = () => {
|
|
29
53
|
for (const track of stream.getTracks()) track.stop();
|
|
30
54
|
};
|
|
@@ -38,6 +62,7 @@ export default defineClientPlugin<never, never, Voice>({
|
|
|
38
62
|
return {
|
|
39
63
|
started,
|
|
40
64
|
stream,
|
|
65
|
+
soFar: () => (id === undefined ? undefined : { id, duration: Date.now() - started }),
|
|
41
66
|
cancel: () => {
|
|
42
67
|
void ended().then(release);
|
|
43
68
|
},
|
|
@@ -45,12 +70,9 @@ export default defineClientPlugin<never, never, Voice>({
|
|
|
45
70
|
await ended();
|
|
46
71
|
release();
|
|
47
72
|
const duration = Date.now() - started;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const { id, url, problem } = (await res.json()) as { id?: string; url?: string; problem?: string };
|
|
52
|
-
if (id === undefined) throw new Error(`voice: ${problem ?? res.statusText}`);
|
|
53
|
-
return { id, url: url ?? `${base}__deictic/plugins/voice/clip/${id}`, duration, type };
|
|
73
|
+
// The last piece came as it stopped. This says it's over, to what names the clip's place only then.
|
|
74
|
+
await send(undefined, true);
|
|
75
|
+
return { id: id!, url: url ?? `${base}__deictic/plugins/voice/clip/${id}`, duration, type: typeOf() };
|
|
54
76
|
},
|
|
55
77
|
};
|
|
56
78
|
},
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `deictic/voice`: records the mic, for other plugins to attach (tasks does) or play along with
|
|
3
3
|
* something (a recording does). No tab of its own. The page half asks for the mic the first time, records
|
|
4
|
-
* with `MediaRecorder` and sends each take to the `add` route
|
|
4
|
+
* with `MediaRecorder` and sends each take as it's spoken, its start to the `add` route and the rest to
|
|
5
|
+
* `more/<id>`, so one a page load cuts short is kept up to there; the server half keeps the latest `keep`
|
|
5
6
|
* clips under `.deictic/voice` and serves them at `clip/<id>`.
|
|
6
7
|
*/
|
|
7
|
-
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
8
|
+
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
8
9
|
import { join, resolve } from 'node:path';
|
|
9
10
|
|
|
10
11
|
import { definePlugin } from '#src/index.ts';
|
|
@@ -18,12 +19,17 @@ export interface Clip {
|
|
|
18
19
|
type: string;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
/** A take going on: `stop` ends it and
|
|
22
|
+
/** A take going on: `stop` ends it and answers its clip, `cancel` ends it with none (what was sent of it goes as the oldest clips do). */
|
|
22
23
|
export interface Take {
|
|
23
24
|
/** When it started, as `Date.now()`. */
|
|
24
25
|
started: number;
|
|
25
26
|
/** The mic, while it's recorded: to show it's heard (`liveWaveform` from `deictic/client`). */
|
|
26
27
|
stream: MediaStream;
|
|
28
|
+
/**
|
|
29
|
+
* What's kept of it by now, as the clip it would be if it ended here, or nothing before its first second is:
|
|
30
|
+
* for a page that's going, with no time left to `stop` it.
|
|
31
|
+
*/
|
|
32
|
+
soFar(): Pick<Clip, 'id' | 'duration'> | undefined;
|
|
27
33
|
stop(): Promise<Clip>;
|
|
28
34
|
cancel(): void;
|
|
29
35
|
}
|
|
@@ -91,7 +97,7 @@ export function voice(options: VoiceOptions = {}) {
|
|
|
91
97
|
return { read };
|
|
92
98
|
},
|
|
93
99
|
routes: {
|
|
94
|
-
// A take the page
|
|
100
|
+
// A take the page is recording, as the audio type its `MediaRecorder` makes: its start, the rest to `more`.
|
|
95
101
|
add: async (req) => {
|
|
96
102
|
const type = (req.headers.get('content-type') ?? '').split(';')[0]!.trim();
|
|
97
103
|
const ext = Object.keys(TYPES).find((e) => TYPES[e] === type);
|
|
@@ -101,6 +107,17 @@ export function voice(options: VoiceOptions = {}) {
|
|
|
101
107
|
if (body.byteLength > MAX) return Response.json({ problem: `a clip may weigh ${MAX / 1024 / 1024} MB at most` }, { status: 413 });
|
|
102
108
|
return Response.json({ id: keepClip(body, ext) });
|
|
103
109
|
},
|
|
110
|
+
// `more/<id>`: the take goes on, and this is the next of its audio. With `?last`, and maybe nothing, it's over.
|
|
111
|
+
more: async (req) => {
|
|
112
|
+
const id = new URL(req.url).pathname.split('/').at(-1) ?? '';
|
|
113
|
+
const file = fileOf(id);
|
|
114
|
+
if (file === undefined) return Response.json({ problem: `clip ${id} isn't kept any more: record it again` }, { status: 404 });
|
|
115
|
+
const body = new Uint8Array(await req.arrayBuffer());
|
|
116
|
+
if (statSync(join(dir, file)).size + body.byteLength > MAX)
|
|
117
|
+
return Response.json({ problem: `a clip may weigh ${MAX / 1024 / 1024} MB at most` }, { status: 413 });
|
|
118
|
+
appendFileSync(join(dir, file), body);
|
|
119
|
+
return Response.json({ id });
|
|
120
|
+
},
|
|
104
121
|
// `clip/<id>`: the audio, to play back.
|
|
105
122
|
clip: (req) => {
|
|
106
123
|
const found = read(new URL(req.url).pathname.split('/').at(-1) ?? '');
|