deictic 0.4.0 → 0.6.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 +19 -8
- package/dist/cli.js +34 -28
- package/dist/cli.js.map +1 -1
- package/dist/shared/board.js +8 -19
- package/dist/shared/board.js.map +1 -1
- package/dist/shared/clean.js +105 -0
- package/dist/shared/clean.js.map +1 -0
- package/dist/shared/endpoints.js +35 -9
- package/dist/shared/endpoints.js.map +1 -1
- package/dist/shared/find.js +3 -2
- package/dist/shared/find.js.map +1 -1
- package/dist/shared/frame.js +4 -18
- package/dist/shared/frame.js.map +1 -1
- package/dist/shared/index.d.ts +8 -4
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index7.d.ts +2 -0
- package/dist/shared/index7.d.ts.map +1 -1
- package/dist/shared/init.js +17 -24
- package/dist/shared/init.js.map +1 -1
- package/dist/shared/local.js +2 -1
- package/dist/shared/local.js.map +1 -1
- package/dist/shared/packages.js +9 -2
- package/dist/shared/packages.js.map +1 -1
- package/dist/shared/recording.js +4 -27
- package/dist/shared/recording.js.map +1 -1
- package/dist/shared/src.js.map +1 -1
- package/dist/shared/task.js +43 -10
- package/dist/shared/task.js.map +1 -1
- package/dist/shared/tasks.js +109 -115
- package/dist/shared/tasks.js.map +1 -1
- package/dist/shared/transcribe.js +1 -128
- package/dist/shared/transcribe2.js +119 -0
- package/dist/shared/transcribe2.js.map +1 -0
- package/dist/shared/vb.js +2 -3
- package/dist/shared/vb.js.map +1 -1
- package/dist/shared/voice2.js +4 -17
- package/dist/shared/voice2.js.map +1 -1
- package/dist/shared/watch.js +56 -39
- package/dist/shared/watch.js.map +1 -1
- package/dist/tailwind/index.js +6 -2
- package/dist/tailwind/index.js.map +1 -1
- package/dist/tasks/client.d.ts.map +1 -1
- package/dist/tasks/client.js +4 -5
- package/dist/tasks/client.js.map +1 -1
- package/dist/tasks/index.js +1 -1
- package/package.json +2 -1
- package/skills/deictic/SKILL.md +5 -3
- package/skills/deictic/references/tasks.md +6 -5
- package/src/cli/board.ts +7 -13
- package/src/cli/clean.ts +104 -0
- package/src/cli/find.ts +3 -1
- package/src/cli/frame.ts +3 -13
- package/src/cli/init.ts +16 -20
- package/src/cli/recording.ts +15 -21
- package/src/cli/task.ts +49 -10
- package/src/cli/transcribe.ts +13 -16
- package/src/cli/vb.ts +0 -2
- package/src/cli/voice.ts +3 -12
- package/src/cli/watch.ts +58 -29
- package/src/cli.ts +130 -31
- package/src/index.ts +8 -4
- package/src/plugins/tailwind/index.ts +6 -2
- package/src/plugins/tasks/client.ts +4 -5
- package/src/plugins/tasks/index.ts +113 -124
- package/src/plugins/tasks/local.ts +2 -1
- package/src/tools/endpoints.ts +18 -7
- package/src/tools/packages.ts +3 -0
- package/src/tools/source.ts +25 -5
- package/dist/shared/transcribe.js.map +0 -1
package/src/cli.ts
CHANGED
|
@@ -1,37 +1,136 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* The `deictic` command. `init` sets a project up, for the person; the rest are for
|
|
4
|
-
* as the skill says: the board, a watch, a task, and what a task carries. Each
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* The `deictic` command. `init` sets a project up and `clean` deletes what it kept, for the person; the rest are for
|
|
4
|
+
* the agent that works the tasks, as the skill says: the board, a watch, a task, and what a task carries. Each is
|
|
5
|
+
* declared here, its arguments and options with what they do, which is all `--help` needs; what it runs is in `cli/`,
|
|
6
|
+
* imported only when it's run, so `deictic task` doesn't load the parser `init` edits configs with. Run in the
|
|
7
|
+
* project, where its board and `.deictic/` are: `npx deictic <command>`.
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
-
init: () => import('./cli/init.ts'),
|
|
10
|
-
vb: () => import('./cli/vb.ts'),
|
|
11
|
-
watch: () => import('./cli/watch.ts'),
|
|
12
|
-
task: () => import('./cli/task.ts'),
|
|
13
|
-
recording: () => import('./cli/recording.ts'),
|
|
14
|
-
frame: () => import('./cli/frame.ts'),
|
|
15
|
-
voice: () => import('./cli/voice.ts'),
|
|
16
|
-
transcribe: () => import('./cli/transcribe.ts'),
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
type Name = keyof typeof COMMANDS;
|
|
20
|
-
const isName = (name: string | undefined): name is Name => name !== undefined && Object.hasOwn(COMMANDS, name);
|
|
21
|
-
|
|
22
|
-
async function help(): Promise<string> {
|
|
23
|
-
const lines = await Promise.all(Object.values(COMMANDS).map(async (load) => ` ${(await load()).usage}`));
|
|
24
|
-
return `Usage: deictic <command>\n\nSetting up:\n${lines[0]}\n\nFor the agent that works the tasks (the skill):\n${lines.slice(1).join('\n')}\n`;
|
|
25
|
-
}
|
|
9
|
+
import { Argument, Command } from 'commander';
|
|
26
10
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
11
|
+
/** A repeatable option's values, in order. */
|
|
12
|
+
const all = (value: string, previous: string[] | undefined) => [...(previous ?? []), value];
|
|
13
|
+
const RECORDING = 'a task (68), a replay URL, a recording ID or a JSON file';
|
|
14
|
+
const CLIP = 'a task, a replay URL, a recording ID, an audio file or a clip ID';
|
|
15
|
+
|
|
16
|
+
const program = new Command('deictic')
|
|
17
|
+
.usage('<command> [options]')
|
|
18
|
+
.enablePositionalOptions()
|
|
19
|
+
.helpOption('-h, --help', 'says what a command takes')
|
|
20
|
+
.showHelpAfterError('(add --help for what it takes)')
|
|
21
|
+
.addHelpText('after', '\nRun in the project. deictic help <command>, or <command> --help, says what it takes.');
|
|
22
|
+
|
|
23
|
+
program.commandsGroup('Setting up and cleaning up:');
|
|
24
|
+
// Here, not under a heading of its own, which a lone `help` would get.
|
|
25
|
+
program.helpCommand('help [command]', 'says what a command takes');
|
|
26
|
+
|
|
27
|
+
program
|
|
28
|
+
.command('init')
|
|
29
|
+
.description('sets deictic up in this project')
|
|
30
|
+
.option('--dry-run', 'says what it would do, and does none of it')
|
|
31
|
+
.option('--no-install', "doesn't install: says the command instead")
|
|
32
|
+
.option('--skill', 'adds the agent skill without asking')
|
|
33
|
+
.option('--no-skill', "doesn't add the agent skill: says the command instead")
|
|
34
|
+
.action(async (options) => (await import('./cli/init.ts')).run(options));
|
|
35
|
+
|
|
36
|
+
program
|
|
37
|
+
.command('clean')
|
|
38
|
+
.description('deletes what deictic kept, after saying what and how big and asking')
|
|
39
|
+
.addArgument(
|
|
40
|
+
new Argument('[parts...]', 'what to delete: shots, recordings and voice clips by default').choices([
|
|
41
|
+
'screenshots',
|
|
42
|
+
'recordings',
|
|
43
|
+
'voice',
|
|
44
|
+
'history',
|
|
45
|
+
'board',
|
|
46
|
+
'all',
|
|
47
|
+
'transcribe',
|
|
48
|
+
]),
|
|
49
|
+
)
|
|
50
|
+
.option('-y, --yes', "deletes without asking: with no terminal to ask on, it doesn't delete without it")
|
|
51
|
+
.addHelpText(
|
|
52
|
+
'after',
|
|
53
|
+
'\nhistory (undo) and board (the local board, its tasks) only with the dev server stopped. all is everything in' +
|
|
54
|
+
"\nthe project's .deictic/; transcribe is the transcription model, outside it, which every project shares.",
|
|
55
|
+
)
|
|
56
|
+
.action(async (parts: string[], options) => (await import('./cli/clean.ts')).run(parts, options));
|
|
57
|
+
|
|
58
|
+
program.commandsGroup('For the agent that works the tasks (the skill):');
|
|
59
|
+
|
|
60
|
+
program
|
|
61
|
+
.command('vb')
|
|
62
|
+
.description('the board on the dev server: deictic vb whoami, deictic vb tasks claim 68 --lease 30m')
|
|
63
|
+
.argument('[args...]', 'anything vb takes')
|
|
64
|
+
// All of it is vb's, --help too.
|
|
65
|
+
.helpOption(false)
|
|
66
|
+
.allowUnknownOption()
|
|
67
|
+
.passThroughOptions()
|
|
68
|
+
.action(async (args: string[]) => (await import('./cli/vb.ts')).run(args));
|
|
69
|
+
|
|
70
|
+
program
|
|
71
|
+
.command('watch')
|
|
72
|
+
.description('a line per new task, reply and cancellation')
|
|
73
|
+
.argument('[channel]', 'the channel', 'deictic')
|
|
74
|
+
.option('--idle <time>', 'ends once the channel has had nothing for this long: 30m, 45s, 1h', '20m')
|
|
75
|
+
.option('--once', 'ends at the first thing to act on')
|
|
76
|
+
.option('--label <key=value>', 'only tasks with this label (repeatable)', all)
|
|
77
|
+
.action(async (channel: string, options) => (await import('./cli/watch.ts')).run(channel, options));
|
|
78
|
+
|
|
79
|
+
program
|
|
80
|
+
.command('task')
|
|
81
|
+
.description('a task briefly: what was asked, by whom, who holds it, what is attached')
|
|
82
|
+
.argument('<id>', 'the task: 68 or #68')
|
|
83
|
+
.option('--out <dir>', 'downloads what is attached here')
|
|
84
|
+
.action(async (id: string, options) => (await import('./cli/task.ts')).run(id, options));
|
|
85
|
+
|
|
86
|
+
program
|
|
87
|
+
.command('recording')
|
|
88
|
+
.description('a recording as a timeline, or the part of it asked for')
|
|
89
|
+
.argument('<recording>', RECORDING)
|
|
90
|
+
.option('--nth <n>', "a task's nth recording", '1')
|
|
91
|
+
.option('--only <kinds>', 'these kinds of line: console, request, page, click, input, scroll, resize, marks, voice (repeatable)', all)
|
|
92
|
+
.option('--problems', 'errors, warnings and requests that failed')
|
|
93
|
+
.option('--from <seconds>', 'from this far in')
|
|
94
|
+
.option('--to <seconds>', 'to this far in')
|
|
95
|
+
.option('--around <seconds>', 'the 3 seconds either side of this')
|
|
96
|
+
.option('--grep <text>', 'lines with this in them, in any case')
|
|
97
|
+
.option('--full', "all of each line: where it was logged from, a request's headers and bodies")
|
|
98
|
+
.option('--json', 'as JSON')
|
|
99
|
+
.action(async (ref: string, options) => (await import('./cli/recording.ts')).run(ref, options));
|
|
100
|
+
|
|
101
|
+
program
|
|
102
|
+
.command('frame')
|
|
103
|
+
.description('PNGs of a recording, as the replay draws it, marks and all (needs the dev server)')
|
|
104
|
+
.argument('<recording>', RECORDING)
|
|
105
|
+
.option('--nth <n>', "a task's nth recording", '1')
|
|
106
|
+
.option('--at <seconds>', 'a frame this far in (repeatable); by default after each change to the marks, and the end', all)
|
|
107
|
+
.option('--every <seconds>', 'a frame this often')
|
|
108
|
+
.option('--out <dir>', 'where the PNGs go, a temporary folder by default')
|
|
109
|
+
.option('--base <url>', "the dev server, where it's not the recorded page's origin")
|
|
110
|
+
.action(async (ref: string, options) => (await import('./cli/frame.ts')).run(ref, options));
|
|
111
|
+
|
|
112
|
+
program
|
|
113
|
+
.command('voice')
|
|
114
|
+
.description("when speech happens in voice clips, in the recording's time")
|
|
115
|
+
.argument('<clip>', CLIP)
|
|
116
|
+
.option('--noise <dB>', 'what counts as silence; lower hears quieter speech', '-35')
|
|
117
|
+
.option('--gap <seconds>', 'the shortest silence between stretches of speech', '0.4')
|
|
118
|
+
.option('--wav <dir>', 'also writes each clip here as 16 kHz WAV')
|
|
119
|
+
.option('--json', 'as JSON')
|
|
120
|
+
.action(async (ref: string, options) => (await import('./cli/voice.ts')).run(ref, options));
|
|
121
|
+
|
|
122
|
+
program
|
|
123
|
+
.command('transcribe')
|
|
124
|
+
.description('what was said in voice clips, on this machine, with when')
|
|
125
|
+
.argument('[clip]', CLIP)
|
|
126
|
+
.option('--setup', 'installs it, outside the project: ask the person first')
|
|
127
|
+
.option('--model <size>', 'tiny, base, small, large-v3-turbo, or a model ID', 'base')
|
|
128
|
+
.option('--language <code>', 'the language spoken (en), rather than guessed')
|
|
129
|
+
.option('--json', 'as JSON')
|
|
130
|
+
.action(async (ref: string | undefined, options) => (await import('./cli/transcribe.ts')).run(ref, options));
|
|
131
|
+
|
|
132
|
+
if (process.argv.length <= 2) {
|
|
133
|
+
program.outputHelp();
|
|
35
134
|
process.exit(0);
|
|
36
135
|
}
|
|
37
|
-
await
|
|
136
|
+
await program.parseAsync();
|
package/src/index.ts
CHANGED
|
@@ -131,10 +131,14 @@ export interface ServerPlugin<Model = unknown, Op = unknown, Record = unknown, A
|
|
|
131
131
|
setup?(context: ServerContext): Maybe<Api>;
|
|
132
132
|
/** Routes of its own, by their first segment under `/__deictic/plugins/<name>/`. */
|
|
133
133
|
routes?: { [route: string]: Route };
|
|
134
|
-
/**
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
/**
|
|
135
|
+
* The model its panel shows for an element. Without it, the panel gets none. `source` is a `Refusal` where the
|
|
136
|
+
* element isn't to be found in its file (it doesn't parse, or the page runs other code than it has): throw it where
|
|
137
|
+
* the plugin needs the source, or go on without it, as a task does.
|
|
138
|
+
*/
|
|
139
|
+
read?(source: Source | Refusal, target: Target): Maybe<Model>;
|
|
140
|
+
/** Text edits for deictic to write, which it refuses without the source, or a change the plugin made itself. */
|
|
141
|
+
apply?(source: Source | Refusal, target: Target, op: Op): Maybe<TextEdit[] | Done<Record>>;
|
|
138
142
|
/**
|
|
139
143
|
* Takes back a change `apply` made itself, or throws a `Refusal` saying why it can't any more. It may
|
|
140
144
|
* answer what the next redo needs, where that differs (what it put back has a new ID).
|
|
@@ -103,14 +103,18 @@ export function tailwind(options: TailwindOptions = {}) {
|
|
|
103
103
|
},
|
|
104
104
|
css: async (request, context) => Response.json({ css: (await catalog(context))?.css(await asked(request)) ?? '' }),
|
|
105
105
|
},
|
|
106
|
-
read(
|
|
106
|
+
read(source) {
|
|
107
|
+
if (source instanceof Refusal) throw source;
|
|
108
|
+
const { code, element, program } = source;
|
|
107
109
|
const spot = spotOf(element, code, helpers);
|
|
108
110
|
if (spot.kind === 'fixed') return { editable: false, source: spot.source };
|
|
109
111
|
if (spot.kind === 'missing') return { editable: true, classes: '' };
|
|
110
112
|
const others = spot.others?.flatMap((argument) => extrasOf(argument, code, program)).map(({ spot: _, ...extra }) => extra);
|
|
111
113
|
return { editable: true, classes: code.slice(spot.start, spot.end), ...(others === undefined ? {} : { others }) };
|
|
112
114
|
},
|
|
113
|
-
apply(
|
|
115
|
+
apply(source, _target, { classes, at }) {
|
|
116
|
+
if (source instanceof Refusal) throw source;
|
|
117
|
+
const { file, code, element, program } = source;
|
|
114
118
|
const list = classes.trim().split(/\s+/).filter(Boolean).join(' ');
|
|
115
119
|
const spot = spotOf(element, code, helpers);
|
|
116
120
|
if (spot.kind === 'fixed') throw new Refusal('this class list is built at runtime: edit it in the editor');
|
|
@@ -276,8 +276,8 @@ const OUTLINE = '#12b358';
|
|
|
276
276
|
const ROOM = 3;
|
|
277
277
|
|
|
278
278
|
/**
|
|
279
|
-
* A shot's PNG with the element outlined in it: dashes around its box,
|
|
280
|
-
*
|
|
279
|
+
* A shot's PNG with the element outlined in it: dashes around its box, with nothing between them, as the overlay
|
|
280
|
+
* draws it. The shot may have more pixels than its size in CSS ones, which the box is in.
|
|
281
281
|
*/
|
|
282
282
|
async function outlined(png: Blob | string, { box, size }: Pick<Shot, 'box' | 'size'>): Promise<Blob> {
|
|
283
283
|
const url = typeof png === 'string' ? png : URL.createObjectURL(png);
|
|
@@ -291,9 +291,6 @@ async function outlined(png: Blob | string, { box, size }: Pick<Shot, 'box' | 's
|
|
|
291
291
|
ctx.drawImage(image, 0, 0);
|
|
292
292
|
const k = image.naturalWidth / size.width;
|
|
293
293
|
const rect = [(box.x - ROOM) * k, (box.y - ROOM) * k, (box.width + 2 * ROOM) * k, (box.height + 2 * ROOM) * k] as const;
|
|
294
|
-
ctx.lineWidth = 4 * k;
|
|
295
|
-
ctx.strokeStyle = '#fff';
|
|
296
|
-
ctx.strokeRect(...rect);
|
|
297
294
|
ctx.lineWidth = 2 * k;
|
|
298
295
|
ctx.strokeStyle = OUTLINE;
|
|
299
296
|
ctx.setLineDash([6 * k, 4 * k]);
|
|
@@ -866,6 +863,8 @@ export default defineClientPlugin<Model, Change>({
|
|
|
866
863
|
announce(model, op, context.target);
|
|
867
864
|
text.value = '';
|
|
868
865
|
reset();
|
|
866
|
+
const dropped = model.tasks.at(-1)?.dropped;
|
|
867
|
+
if (dropped !== undefined) problem.textContent = `Sent without ${dropped}: it wasn't kept any more`;
|
|
869
868
|
} catch {
|
|
870
869
|
// The panel's status says why; what was typed and drawn stays, to send again.
|
|
871
870
|
}
|
|
@@ -2,8 +2,7 @@
|
|
|
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)
|
|
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
|
|
5
|
+
* it is in the shot) and the chain of source it rendered through, out to the files that use its component. Its HTML as it rendered is a file attached, `element.html`, for whoever
|
|
7
6
|
* 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
|
|
8
7
|
* from there; deictic only adds them.
|
|
9
8
|
*
|
|
@@ -81,6 +80,8 @@ export interface Task {
|
|
|
81
80
|
open: boolean;
|
|
82
81
|
/** Its page on the board, when there's one to link to. */
|
|
83
82
|
link?: string;
|
|
83
|
+
/** What was attached to it but not kept by the time it was sent, so it went without: `a screenshot`. */
|
|
84
|
+
dropped?: string;
|
|
84
85
|
/**
|
|
85
86
|
* Where it was added, where that isn't the element's place: for one of `tasks`, where the element was before
|
|
86
87
|
* it moved; for one of `elsewhere`, the element it's about.
|
|
@@ -213,6 +214,8 @@ const AT = 'deictic.at';
|
|
|
213
214
|
const FILE = 'deictic.file';
|
|
214
215
|
/** What parts what was typed from the rest of a task's text. */
|
|
215
216
|
const REST = '\n---\n';
|
|
217
|
+
/** A file for the board, as the plugins that keep them read it. */
|
|
218
|
+
type Upload = { data: Uint8Array<ArrayBuffer>; name: string; type: string };
|
|
216
219
|
const OPEN = new Set(['waiting', 'ready', 'blocked']);
|
|
217
220
|
|
|
218
221
|
export function tasks(options: TasksOptions = {}) {
|
|
@@ -309,30 +312,45 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
309
312
|
// Kept from `setup`, to `use` another plugin when an op asks for it.
|
|
310
313
|
let context: ServerContext | undefined;
|
|
311
314
|
let project = options.project;
|
|
312
|
-
/**
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
315
|
+
/**
|
|
316
|
+
* The op with only the screenshots, recordings and voice clips still kept, their files, and what's left out: a file
|
|
317
|
+
* goes once newer ones pass its plugin's `keep`, or `deictic clean` takes it, and that's no reason to lose the task.
|
|
318
|
+
*/
|
|
319
|
+
const keptOf = (op: Op) => {
|
|
320
|
+
const clipOf = (id: string): ReturnType<Clips['read']> => context?.use('voice')?.read(id);
|
|
321
|
+
// In the op's order, each kind's: the Nth PNG is `deictic.screenshot.N`'s, the Nth recording `deictic.recording.N`'s.
|
|
322
|
+
const files: Upload[] = [];
|
|
323
|
+
const dropped: Kind[] = [];
|
|
324
|
+
const take = (file: Upload | undefined, missing: Kind) => {
|
|
325
|
+
if (file === undefined) dropped.push(missing);
|
|
326
|
+
else files.push(file);
|
|
327
|
+
return file !== undefined;
|
|
328
|
+
};
|
|
329
|
+
const screenshots = (op.screenshots ?? []).filter(({ id }) => take(context?.use('screenshots')?.read(id), 'screenshot'));
|
|
330
|
+
const recordings = (op.recordings ?? []).flatMap((recording) => {
|
|
331
|
+
const found: ReturnType<Recordings['read']> = context?.use('recordings')?.read(recording.id);
|
|
332
|
+
if (!take(found, 'recording')) return [];
|
|
333
|
+
if (recording.voice === undefined) return [recording];
|
|
334
|
+
const clipped = (id: string) => take(clipOf(id), 'voice clip');
|
|
335
|
+
return [{ ...recording, voice: recording.voice.filter(clipped) }];
|
|
336
|
+
});
|
|
337
|
+
const voice = (op.voice ?? []).filter(({ id }) => take(clipOf(id), 'voice note'));
|
|
338
|
+
// Last, and files, not the task's words: there to look into, and most tasks are done without them. What was
|
|
339
|
+
// pointed at is in the element's HTML, and a file of its own only where that isn't attached.
|
|
340
|
+
const html = typeof op.html === 'string' && op.html !== '' ? op.html : undefined;
|
|
341
|
+
if (html !== undefined) files.push({ data: new TextEncoder().encode(html.slice(0, HTML)), name: 'element.html', type: 'text/html' });
|
|
342
|
+
else if (op.pointed !== undefined)
|
|
343
|
+
files.push({ data: new TextEncoder().encode(op.pointed.html.slice(0, HTML)), name: 'pointed.html', type: 'text/html' });
|
|
344
|
+
const kept: Op = {
|
|
345
|
+
...op,
|
|
346
|
+
...(op.screenshots === undefined ? {} : { screenshots }),
|
|
347
|
+
...(op.recordings === undefined ? {} : { recordings }),
|
|
348
|
+
...(op.voice === undefined ? {} : { voice }),
|
|
349
|
+
};
|
|
350
|
+
return { op: kept, files, dropped };
|
|
351
|
+
};
|
|
352
|
+
/** The files uploaded to the board, or nothing when there are none. */
|
|
353
|
+
const upload = async (files: Upload[]): Promise<string[] | undefined> => {
|
|
336
354
|
if (files.length === 0) return undefined;
|
|
337
355
|
const team = await boardOf();
|
|
338
356
|
return Promise.all(files.map(async (file) => (await team.upload(file)).id));
|
|
@@ -365,9 +383,8 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
365
383
|
team.tasks.list({ channel, state: 'claimed' }),
|
|
366
384
|
]);
|
|
367
385
|
const listed = new Set(inFile.tasks.map(({ message }) => message.id));
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
const once = source.code.split(line).length === 2;
|
|
386
|
+
// Nothing to tell a moved task by where the file has no such element.
|
|
387
|
+
const line = source instanceof Refusal ? undefined : onceIn(source);
|
|
371
388
|
const tasks: Task[] = [];
|
|
372
389
|
const elsewhere: (Task & { at: Place })[] = [];
|
|
373
390
|
const about = [...here.tasks.filter((t) => !listed.has(t.message.id)), ...inFile.tasks];
|
|
@@ -381,6 +398,8 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
381
398
|
const by = actors.get(actorOf(message) ?? '')?.name;
|
|
382
399
|
const text = message.text.split(REST, 1)[0]!;
|
|
383
400
|
const to = taskLink(page, message.id);
|
|
401
|
+
const missing = Object.entries(message.labels).flatMap(([key, value]) => (/^deictic\.dropped\.\d+$/.test(key) ? [value] : []));
|
|
402
|
+
const dropped = missing.length === 0 ? undefined : listOf(missing);
|
|
384
403
|
const task = {
|
|
385
404
|
id: message.id,
|
|
386
405
|
title: text.split('\n', 1)[0]!,
|
|
@@ -389,10 +408,11 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
389
408
|
...(by === undefined ? {} : { by }),
|
|
390
409
|
open: OPEN.has(state),
|
|
391
410
|
...(to === undefined ? {} : { link: to }),
|
|
411
|
+
...(dropped === undefined ? {} : { dropped }),
|
|
392
412
|
};
|
|
393
413
|
const at = placeIn(message.labels);
|
|
394
414
|
if (at === undefined || message.labels[AT] === atOf(target)) tasks.push(task);
|
|
395
|
-
else if (
|
|
415
|
+
else if (line !== undefined && at.tag === target.tag && message.labels['deictic.line'] === line) tasks.push({ ...task, at });
|
|
396
416
|
else elsewhere.push({ ...task, at });
|
|
397
417
|
}
|
|
398
418
|
// An agent at work on a task is here too, though its watch may be over until the task is (`deictic watch --once`).
|
|
@@ -425,23 +445,26 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
425
445
|
if ('edit' in op) {
|
|
426
446
|
return asked(async () => {
|
|
427
447
|
const before = (await openTask(await boardOf(), op.edit, 'edit')).text;
|
|
428
|
-
// What follows the words (what's attached, what was pointed at) stays
|
|
448
|
+
// What follows the words in a task added before they were labels (what's attached, what was pointed at) stays.
|
|
429
449
|
const rest = before.includes(REST) ? before.slice(before.indexOf(REST)) : '';
|
|
430
450
|
const after = clip(op.text.trim(), 10_000 - rest.length) + rest;
|
|
431
451
|
await rewrite(op.edit, before, after);
|
|
432
452
|
return { done: { kind: 'edited' as const, id: op.edit, before, after } };
|
|
433
453
|
});
|
|
434
454
|
}
|
|
455
|
+
const { op: kept, files, dropped } = keptOf(op);
|
|
456
|
+
const verb = dropped.length === 1 ? "isn't" : "aren't";
|
|
457
|
+
if (wordsOf(kept) === '') throw new Refusal(`${listOf(dropped)} ${verb} kept any more: attach again, or say what should change`);
|
|
435
458
|
const labels = {
|
|
436
459
|
...options.labels,
|
|
437
460
|
...(project === undefined ? {} : { 'deictic.project': clip(project, LABEL) }),
|
|
438
|
-
...labelsOf(source, target,
|
|
461
|
+
...labelsOf(source, target, kept),
|
|
462
|
+
...attachedLabels(kept, dropped),
|
|
439
463
|
};
|
|
440
464
|
return asked(async () => {
|
|
441
|
-
const attachments = await
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
};
|
|
465
|
+
const attachments = await upload(files);
|
|
466
|
+
const text = clip(wordsOf(kept), 10_000);
|
|
467
|
+
return { done: await create({ channel, text, labels, ...(attachments === undefined ? {} : { attachments }) }) };
|
|
445
468
|
});
|
|
446
469
|
},
|
|
447
470
|
undo: (record) =>
|
|
@@ -489,72 +512,50 @@ async function localPage(team: TaskBoard, channel: string): Promise<string | und
|
|
|
489
512
|
return `${url.origin}${url.pathname.slice(0, -'/api/board'.length)}/c/${channel.split('/').map(encodeURIComponent).join('/')}`;
|
|
490
513
|
}
|
|
491
514
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
/** What was marked on the page: how many marks, and what the notes say. */
|
|
496
|
-
function annotated({ count, notes }: Marks, shots: number, recordings: number): string {
|
|
497
|
-
const where = [
|
|
498
|
-
...(shots === 0 ? [] : [shots === 1 ? 'the screenshot' : 'the screenshots']),
|
|
499
|
-
...(recordings === 0 ? [] : [recordings === 1 ? 'the recording' : 'the recordings']),
|
|
500
|
-
];
|
|
501
|
-
const drawn = where.length === 0 ? '' : `, drawn in ${where.join(' and ')}`;
|
|
502
|
-
return `${plural(count, 'mark')} on the page${drawn}${said(notes)}`;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/** How long each recording ran, and where it plays back, while the dev server keeps it. */
|
|
506
|
-
function recordingsOf(recordings: NonNullable<Op['recordings']>): string[] {
|
|
507
|
-
return recordings.map(({ duration, replay, voice }, i) => {
|
|
508
|
-
const name = recordings.length === 1 ? 'A recording' : `Recording ${i + 1}`;
|
|
509
|
-
const spoken = voice === undefined || voice.length === 0 ? '' : `, with the voice (${voice.map((id) => `voice-${id}`).join(', ')})`;
|
|
510
|
-
return `${name}, ${clock(duration)} long, attached as rrweb events${spoken}; it replays at ${replay}`;
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
/** How long each voice note runs, and the attachment it's in. */
|
|
515
|
-
function voicesOf(voice: NonNullable<Op['voice']>): string[] {
|
|
516
|
-
return voice.map(({ id, duration }, i) => {
|
|
517
|
-
const name = voice.length === 1 ? 'A voice note' : `Voice note ${i + 1}`;
|
|
518
|
-
return `${name}, ${clock(duration)} long, attached as voice-${id}`;
|
|
519
|
-
});
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
const clock = (ms: number) => {
|
|
523
|
-
const s = Math.round(ms / 1000);
|
|
524
|
-
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`;
|
|
525
|
-
};
|
|
515
|
+
/** What may be left out of a task as no longer kept, as `deictic.dropped.N` names it. */
|
|
516
|
+
type Kind = 'screenshot' | 'recording' | 'voice clip' | 'voice note';
|
|
526
517
|
|
|
527
518
|
/**
|
|
528
|
-
* What
|
|
529
|
-
*
|
|
530
|
-
* on it
|
|
519
|
+
* What the attached files don't say, as labels numbered from 1, so each value is short and none is read out of the
|
|
520
|
+
* text. `deictic.screenshot.N` is the Nth PNG attached: its `.position` and `.size` where the element is in it (CSS
|
|
521
|
+
* pixels from its top left), `.note.M` a note drawn on it. `deictic.recording.N.replay` is where the Nth recording
|
|
522
|
+
* plays back; `deictic.note.M` a note drawn on the page; `deictic.dropped.N` what wasn't kept any more;
|
|
523
|
+
* `deictic.pointed` the path to what was pointed at inside the element. A note past a label is cut.
|
|
531
524
|
*/
|
|
532
|
-
function
|
|
533
|
-
const
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
return has.length === 0 ? [] : [`The screenshot has ${has.join(' and ')}`];
|
|
541
|
-
}
|
|
542
|
-
return shots.map(({ box, marks, outlined }, i) => {
|
|
543
|
-
const drawn = marks === undefined || marks.count === 0 ? '' : `, with ${plural(marks.count, 'mark')} drawn on it${said(marks.notes)}`;
|
|
525
|
+
function attachedLabels(op: Op, dropped: Kind[]): Record<string, string> {
|
|
526
|
+
const labels: Record<string, string> = {};
|
|
527
|
+
// A board takes no control characters in a label: a note's lines go on one.
|
|
528
|
+
const set = (key: string, value: string) => {
|
|
529
|
+
labels[`deictic.${key}`] = clip(value.replace(/\p{Cc}+/gu, ' '), LABEL);
|
|
530
|
+
};
|
|
531
|
+
for (const [i, { box, marks }] of (op.screenshots ?? []).entries()) {
|
|
532
|
+
const n = `screenshot.${i + 1}`;
|
|
544
533
|
const [x, y, width, height] = boxOf(box);
|
|
545
|
-
|
|
546
|
-
|
|
534
|
+
set(`${n}.position`, `${x},${y}`);
|
|
535
|
+
set(`${n}.size`, `${width}x${height}`);
|
|
536
|
+
for (const [j, note] of (marks?.notes ?? []).entries()) set(`${n}.note.${j + 1}`, note);
|
|
537
|
+
}
|
|
538
|
+
for (const [j, note] of (op.annotations?.notes ?? []).entries()) set(`note.${j + 1}`, note);
|
|
539
|
+
// Not cut: half a URL leads nowhere.
|
|
540
|
+
for (const [i, { replay }] of (op.recordings ?? []).entries()) if (replay.length <= LABEL) set(`recording.${i + 1}.replay`, replay);
|
|
541
|
+
for (const [i, kind] of dropped.entries()) set(`dropped.${i + 1}`, kind);
|
|
542
|
+
if (op.pointed !== undefined) set('pointed', op.pointed.path);
|
|
543
|
+
return labels;
|
|
547
544
|
}
|
|
548
545
|
|
|
549
546
|
/**
|
|
550
|
-
* `
|
|
551
|
-
* it: the components that use it, where the page knows them, or the files around
|
|
547
|
+
* `deictic.source`, `Field (src/Field.tsx:20) ← Panel`: what the element rendered through, out from its own place
|
|
548
|
+
* (`deictic.at`), as the page said it: the components that use it, where the page knows them, or the files around
|
|
549
|
+
* it. As many as a label holds, the farthest left out first.
|
|
552
550
|
*/
|
|
553
|
-
function
|
|
554
|
-
|
|
555
|
-
|
|
551
|
+
function sourceOf(chain: NonNullable<Op['chain']>): Record<string, string> {
|
|
552
|
+
let places = chain.slice(0, CHAIN).map(String);
|
|
553
|
+
while (places.length > 1 && places.join(THROUGH).length > LABEL) places = places.slice(0, -1);
|
|
554
|
+
return places.length === 0 ? {} : { 'deictic.source': clip(places.join(THROUGH), LABEL) };
|
|
556
555
|
}
|
|
557
556
|
|
|
557
|
+
const THROUGH = ' ← ';
|
|
558
|
+
|
|
558
559
|
/** How many places a chain names after the element's own: the first few say which use of a component it is. */
|
|
559
560
|
const CHAIN = 3;
|
|
560
561
|
|
|
@@ -580,29 +581,23 @@ function nameOf(root: string): string | undefined {
|
|
|
580
581
|
/**
|
|
581
582
|
* The facts about the element, as labels: short values a script reads without parsing the text, and a watch
|
|
582
583
|
* filters by. `deictic.line` is the opening tag's first line as the task saw it, to tell later that it moved.
|
|
583
|
-
* `deictic.url` is the page's whole URL, where a label holds it
|
|
584
|
+
* `deictic.url` is the page's whole URL, where a label holds it; `deictic.page` is its path.
|
|
584
585
|
*/
|
|
585
|
-
function labelsOf(
|
|
586
|
-
const [shot] = op.screenshots ?? [];
|
|
586
|
+
function labelsOf(source: Source | Refusal, target: Target, op: Op): Record<string, string> {
|
|
587
587
|
return {
|
|
588
588
|
[AT]: atOf(target),
|
|
589
589
|
[FILE]: clip(target.loc.file, LABEL),
|
|
590
590
|
'deictic.tag': target.tag,
|
|
591
|
-
|
|
591
|
+
// Not where the file has no such element: the task is the page's, and goes without.
|
|
592
|
+
...(source instanceof Refusal ? {} : { 'deictic.line': clip(lineOf(source), LABEL) }),
|
|
592
593
|
'deictic.page': clip(new URL(op.page).pathname, LABEL),
|
|
593
594
|
...(op.page.length <= LABEL ? { 'deictic.url': op.page } : {}),
|
|
594
595
|
'deictic.viewport': `${op.viewport.width}x${op.viewport.height}`,
|
|
595
596
|
'deictic.count': String(op.count),
|
|
596
|
-
...(op.
|
|
597
|
+
...sourceOf(op.chain ?? []),
|
|
597
598
|
};
|
|
598
599
|
}
|
|
599
600
|
|
|
600
|
-
/** Where the element is in the one shot, from its top left, and how big: `87,387` and `138x32`, as the viewport is written. */
|
|
601
|
-
function placeOf(box: Box): Record<string, string> {
|
|
602
|
-
const [x, y, width, height] = boxOf(box);
|
|
603
|
-
return { 'deictic.position': `${x},${y}`, 'deictic.size': `${width}x${height}` };
|
|
604
|
-
}
|
|
605
|
-
|
|
606
601
|
/**
|
|
607
602
|
* The actors these IDs name, by ID. An actor's ID isn't read for its name (each board writes them its own way), so
|
|
608
603
|
* the board is asked who they are, and only when there's one to ask about.
|
|
@@ -631,6 +626,12 @@ const atOf = ({ loc }: Target) => `${loc.file}:${loc.line}:${loc.column}`;
|
|
|
631
626
|
/** The opening tag's first line, as written. */
|
|
632
627
|
const lineOf = ({ code, element }: Pick<Source, 'code' | 'element'>) => code.slice(element.start, element.end).split('\n', 1)[0]!.trim();
|
|
633
628
|
|
|
629
|
+
/** The element's line as a label has it, where the file has it once: a line it has twice says nothing of which element a task was about. */
|
|
630
|
+
function onceIn(source: Source): string | undefined {
|
|
631
|
+
const line = lineOf(source);
|
|
632
|
+
return source.code.split(line).length === 2 ? clip(line, LABEL) : undefined;
|
|
633
|
+
}
|
|
634
|
+
|
|
634
635
|
/** Where a task says its element is, from its labels. */
|
|
635
636
|
function placeIn(labels: Record<string, string>): Place | undefined {
|
|
636
637
|
const [, line, column] = /:(\d+):(\d+)$/.exec(labels[AT] ?? '') ?? [];
|
|
@@ -638,25 +639,6 @@ function placeIn(labels: Record<string, string>): Place | undefined {
|
|
|
638
639
|
return { line: Number(line), column: Number(column), tag: labels['deictic.tag'] ?? '' };
|
|
639
640
|
}
|
|
640
641
|
|
|
641
|
-
/**
|
|
642
|
-
* The task's text: what was typed, and after a `---` only what no label holds: what's attached and drawn, the
|
|
643
|
-
* source it rendered through, what was pointed at inside it, and a URL too long for a label.
|
|
644
|
-
* A board holds 10,000 characters.
|
|
645
|
-
*/
|
|
646
|
-
function textOf(op: Op, target: Target): string {
|
|
647
|
-
const more = [
|
|
648
|
-
...(op.page.length <= LABEL ? [] : [op.page]),
|
|
649
|
-
...shotsOf(op.screenshots ?? []),
|
|
650
|
-
...recordingsOf(op.recordings ?? []),
|
|
651
|
-
...voicesOf(op.voice ?? []),
|
|
652
|
-
...(op.annotations === undefined ? [] : [annotated(op.annotations, op.screenshots?.length ?? 0, op.recordings?.length ?? 0)]),
|
|
653
|
-
...chainOf(target, op.chain ?? []),
|
|
654
|
-
...(op.pointed === undefined ? [] : [`Pointed at, inside it: \`${op.pointed.path}\``, fence(op.pointed.html, 'html')]),
|
|
655
|
-
];
|
|
656
|
-
const tail = more.length === 0 ? '' : REST + more.join('\n');
|
|
657
|
-
return clip(wordsOf(op), 10_000 - tail.length) + tail;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
642
|
/** The task's words: what was typed, or where nothing was, a line that sends the reader to what's attached. */
|
|
661
643
|
const wordsOf = (op: Op) => (op.text.trim() === '' ? (shown(op) ?? '') : op.text.trim());
|
|
662
644
|
|
|
@@ -669,10 +651,17 @@ function shown(op: Op): string | undefined {
|
|
|
669
651
|
...named(op.recordings?.length, 'recording'),
|
|
670
652
|
...named(op.voice?.length, 'voice note'),
|
|
671
653
|
];
|
|
672
|
-
return attached.length === 0 ? undefined : `See ${
|
|
654
|
+
return attached.length === 0 ? undefined : `See ${conjunction(attached)}`;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/** `a screenshot and 2 voice notes`, of `deictic.dropped.N`'s values. */
|
|
658
|
+
function listOf(kinds: string[]): string {
|
|
659
|
+
return conjunction(
|
|
660
|
+
[...Map.groupBy(kinds, (kind) => kind)].map(([kind, all]) => (all.length === 1 ? `a ${kind}` : `${all.length} ${kind}s`)),
|
|
661
|
+
);
|
|
673
662
|
}
|
|
674
663
|
|
|
675
|
-
const
|
|
664
|
+
const conjunction = (things: string[]) => new Intl.ListFormat('en', { type: 'conjunction' }).format(things);
|
|
676
665
|
|
|
677
666
|
const clip = (text: string, max: number) => (text.length <= max ? text : `${text.slice(0, max - 1)}…`);
|
|
678
667
|
|
|
@@ -128,7 +128,8 @@ export function runningAt(file: string): Running | undefined {
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
/** Whether the process is running. */
|
|
132
|
+
export function alive(pid: number): boolean {
|
|
132
133
|
try {
|
|
133
134
|
process.kill(pid, 0);
|
|
134
135
|
return true;
|