deictic 0.5.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 +15 -8
- package/dist/shared/endpoints.js +34 -8
- package/dist/shared/endpoints.js.map +1 -1
- package/dist/shared/find.js +2 -1
- package/dist/shared/find.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 +12 -10
- package/dist/shared/init.js.map +1 -1
- package/dist/shared/packages.js +1 -1
- package/dist/shared/src.js.map +1 -1
- package/dist/shared/task.js +36 -0
- package/dist/shared/task.js.map +1 -1
- package/dist/shared/tasks.js +108 -114
- package/dist/shared/tasks.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/package.json +1 -1
- package/skills/deictic/references/tasks.md +6 -5
- package/src/cli/find.ts +3 -1
- package/src/cli/init.ts +13 -11
- package/src/cli/task.ts +43 -1
- 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/tools/endpoints.ts +18 -7
- package/src/tools/source.ts +25 -5
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
# Reading a task
|
|
2
2
|
|
|
3
|
-
`npx deictic task 68` prints what was asked, where, the page and viewport, what's attached with the
|
|
4
|
-
each, and whether the line still reads as the task saw it.
|
|
3
|
+
`npx deictic task 68` prints what was asked, where, the page and viewport, the notes drawn, what's attached with the
|
|
4
|
+
command to read each, and whether the line still reads as the task saw it.
|
|
5
5
|
|
|
6
|
-
- **`Source:`** is the chain the element rendered through, from its
|
|
6
|
+
- **`Source:`** (the `deictic.source` label, after its own place) is the chain the element rendered through, from its
|
|
7
|
+
own line out:
|
|
7
8
|
`src/ui/label.tsx:6 ← ParticipantsField (src/ParticipantsField.tsx:20) ← WorkflowPanel`. When the first is a shared
|
|
8
9
|
component (`ui/label.tsx`), the change is usually at the next one. A name alone is a component to find by name.
|
|
9
|
-
- **`Pointed at, inside it:`** is markup inside the element that no line marks (a dependency's): what they mean.
|
|
10
|
-
it by its classes.
|
|
10
|
+
- **`Pointed at, inside it:`** is markup inside the element that no line marks (a dependency's): what they mean. Its
|
|
11
|
+
HTML is in the file named beside it. Find it by its classes.
|
|
11
12
|
- **The element is one place**: what they mean may be its parent, a sibling, or every element the line renders. The
|
|
12
13
|
words and the marks decide.
|
|
13
14
|
- **`element.html`** is the element as it rendered. Read it only when the task and the screenshot don't settle which
|
package/src/cli/find.ts
CHANGED
|
@@ -48,7 +48,9 @@ export async function loadRecording(ref: string | undefined, nth = 1): Promise<F
|
|
|
48
48
|
const file = files[nth - 1];
|
|
49
49
|
if (file === undefined) fail(`Task #${root.id} has ${files.length} recording(s), not a ${nth}th.`);
|
|
50
50
|
const id = file.name.slice('recording-'.length, -'.json'.length);
|
|
51
|
-
|
|
51
|
+
// Its `deictic.recording.N.replay` label, or in the text of a task added before that was a label.
|
|
52
|
+
const where = (text: string) => new RegExp(`https?://\\S+/replay/${id}`).exec(text)?.[0];
|
|
53
|
+
const replay = Object.values(root.labels).map(where).find(Boolean) ?? where(root.text);
|
|
52
54
|
return { kept: parsed(fetched(root, file.name)), id, replay, task: root };
|
|
53
55
|
}
|
|
54
56
|
if (/^https?:/.test(ref)) {
|
package/src/cli/init.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { installCommand, packageManager, readJson, runnerOf } from '#src/tools/p
|
|
|
18
18
|
|
|
19
19
|
import { fail } from './board.ts';
|
|
20
20
|
import { addToBunfig, addToServer, BY_HAND, MODULE, PLUGIN, serverOf } from './bun.ts';
|
|
21
|
-
import { addFirst, addImports
|
|
21
|
+
import { addFirst, addImports } from './edit.ts';
|
|
22
22
|
|
|
23
23
|
export type Bundler = 'next' | 'astro' | 'vite' | 'rspack' | 'webpack' | 'bun';
|
|
24
24
|
|
|
@@ -62,7 +62,7 @@ const SETUPS: Record<Exclude<Bundler, 'bun'>, Setup> = {
|
|
|
62
62
|
name: 'deictic',
|
|
63
63
|
list: 'plugins',
|
|
64
64
|
value: `deictic(${PLUGINS})`,
|
|
65
|
-
snippet: `export default defineConfig({ plugins: [
|
|
65
|
+
snippet: `export default defineConfig({ plugins: [deictic(${PLUGINS}), react()] });`,
|
|
66
66
|
},
|
|
67
67
|
rspack: {
|
|
68
68
|
files: extensions('rspack.config'),
|
|
@@ -177,7 +177,7 @@ function exportedOf(program: Program): { value: Expression; commonjs: boolean }
|
|
|
177
177
|
|
|
178
178
|
/**
|
|
179
179
|
* The config with deictic added, or nothing where it can't tell where: deictic's import beside the config's, and its
|
|
180
|
-
* plugin
|
|
180
|
+
* plugin first in the list (`plugins`, `integrations`), as its marks count lines and columns in the code it's given, or the config wrapped (Next's). Written in the config's quotes,
|
|
181
181
|
* semicolons and line endings.
|
|
182
182
|
*/
|
|
183
183
|
export function addToConfig(bundler: Exclude<Bundler, 'bun'>, file: string, code: string): string | undefined {
|
|
@@ -186,7 +186,6 @@ export function addToConfig(bundler: Exclude<Bundler, 'bun'>, file: string, code
|
|
|
186
186
|
if (errors.length > 0) return undefined;
|
|
187
187
|
const exported = exportedOf(program);
|
|
188
188
|
if (exported === undefined) return undefined;
|
|
189
|
-
const eol = eolOf(code);
|
|
190
189
|
const out = new MagicString(code);
|
|
191
190
|
|
|
192
191
|
if (setup.wrap) {
|
|
@@ -194,7 +193,7 @@ export function addToConfig(bundler: Exclude<Bundler, 'bun'>, file: string, code
|
|
|
194
193
|
out.appendRight(exported.value.end, `, ${setup.value})`);
|
|
195
194
|
} else {
|
|
196
195
|
const object = objectOf(exported.value, program);
|
|
197
|
-
if (object === undefined || !addTo(out, code, object, setup.list!, setup.value
|
|
196
|
+
if (object === undefined || !addTo(out, code, object, setup.list!, setup.value)) return undefined;
|
|
198
197
|
}
|
|
199
198
|
|
|
200
199
|
const lines: [string, string][] = [
|
|
@@ -205,8 +204,12 @@ export function addToConfig(bundler: Exclude<Bundler, 'bun'>, file: string, code
|
|
|
205
204
|
return out.toString();
|
|
206
205
|
}
|
|
207
206
|
|
|
208
|
-
/**
|
|
209
|
-
|
|
207
|
+
/**
|
|
208
|
+
* Adds `value` first in the object's array `list`, or the list with it, as the object is laid out. False where `list`
|
|
209
|
+
* isn't an array. First, since a plugin before deictic's that changes a module (both `pre` under Vite) leaves the
|
|
210
|
+
* page's marks pointing at its code, not the file.
|
|
211
|
+
*/
|
|
212
|
+
function addTo(out: MagicString, code: string, object: ObjectExpression, list: string, value: string): boolean {
|
|
210
213
|
const property = object.properties.find(
|
|
211
214
|
(p) =>
|
|
212
215
|
p.type === 'Property' &&
|
|
@@ -218,13 +221,12 @@ function addTo(out: MagicString, code: string, object: ObjectExpression, list: s
|
|
|
218
221
|
let array = property.value;
|
|
219
222
|
while (array.type === 'TSAsExpression' || array.type === 'TSSatisfiesExpression') array = array.expression;
|
|
220
223
|
if (array.type !== 'ArrayExpression') return false;
|
|
221
|
-
const
|
|
222
|
-
if (
|
|
224
|
+
const first = array.elements.find((e) => e !== null);
|
|
225
|
+
if (first == null) {
|
|
223
226
|
out.appendLeft(array.start + 1, value);
|
|
224
227
|
return true;
|
|
225
228
|
}
|
|
226
|
-
|
|
227
|
-
out.appendLeft(last.end, multiline ? `,${eol}${indentAt(code, last.start)}${value}` : `, ${value}`);
|
|
229
|
+
addFirst(out, code, array.start, first, value);
|
|
228
230
|
return true;
|
|
229
231
|
}
|
|
230
232
|
addFirst(out, code, object.start, object.properties[0], `${list}: [${value}]`);
|
package/src/cli/task.ts
CHANGED
|
@@ -30,9 +30,12 @@ export function run(id: string, values: { out?: string }): void {
|
|
|
30
30
|
const facts: [string, (v: string) => string | undefined][] = [
|
|
31
31
|
['deictic.project', (v) => `Project ${v}`],
|
|
32
32
|
['deictic.at', (v) => `${v} <${label('deictic.tag') ?? '?'}>`],
|
|
33
|
+
// From its own line out: before the label, tasks said it in their text, which is printed below as it is.
|
|
34
|
+
['deictic.source', (v) => `Source: ${at?.replace(/:\d+$/, '') ?? '?'} ← ${v}`],
|
|
33
35
|
['deictic.url', (v) => v],
|
|
34
36
|
['deictic.viewport', (v) => `Viewport ${v}`],
|
|
35
37
|
['deictic.count', (v) => (v === '1' ? undefined : `${v} elements on the page come from that line`)],
|
|
38
|
+
// A task added before shots were numbered had its one shot's place here.
|
|
36
39
|
['deictic.position', (v) => `In the screenshot at x,y ${v}, ${label('deictic.size') ?? '?'} (CSS pixels from its top left)`],
|
|
37
40
|
];
|
|
38
41
|
for (const [key, say] of facts) {
|
|
@@ -40,10 +43,16 @@ export function run(id: string, values: { out?: string }): void {
|
|
|
40
43
|
const line = value === undefined ? undefined : say(value);
|
|
41
44
|
if (line !== undefined) console.log(line);
|
|
42
45
|
}
|
|
43
|
-
|
|
46
|
+
for (const line of drawn(root)) console.log(line);
|
|
47
|
+
// A task added before these were labels says them after its words.
|
|
44
48
|
const told = (pointed ? where.slice(0, pointed.index) : where).trim();
|
|
45
49
|
if (told !== '') console.log(told);
|
|
46
50
|
if (pointed) console.log(`\nPointed at, inside it: ${pointed[1]}\n ${pointed[2]}`);
|
|
51
|
+
const path = label('deictic.pointed');
|
|
52
|
+
if (path !== undefined) {
|
|
53
|
+
const file = root.attachments.some((a) => a.name === 'pointed.html') ? 'pointed.html' : 'element.html';
|
|
54
|
+
console.log(`\nPointed at, inside it: ${path} (its HTML is in ${file})`);
|
|
55
|
+
}
|
|
47
56
|
|
|
48
57
|
if (at !== undefined) placeOf(at, label('deictic.line'));
|
|
49
58
|
attachments(root, values.out === undefined ? undefined : resolve(values.out));
|
|
@@ -53,6 +62,39 @@ export function run(id: string, values: { out?: string }): void {
|
|
|
53
62
|
others(root);
|
|
54
63
|
}
|
|
55
64
|
|
|
65
|
+
/**
|
|
66
|
+
* What the attached files don't say, from the numbered labels: where the element is in each shot and the notes on it, the
|
|
67
|
+
* notes drawn on the page, where each recording replays, and what wasn't kept any more.
|
|
68
|
+
*/
|
|
69
|
+
function drawn({ labels, attachments }: Message): string[] {
|
|
70
|
+
const numbered = (prefix: string) => {
|
|
71
|
+
const out: string[] = [];
|
|
72
|
+
for (let n = 1; labels[`${prefix}.${n}`] !== undefined; n++) out.push(labels[`${prefix}.${n}`]!);
|
|
73
|
+
return out;
|
|
74
|
+
};
|
|
75
|
+
const notes = (prefix: string) => numbered(`${prefix}.note`).map((note) => JSON.stringify(note));
|
|
76
|
+
const lines: string[] = [];
|
|
77
|
+
// `deictic.screenshot.N` is the Nth PNG attached, `deictic.recording.N` the Nth recording.
|
|
78
|
+
for (const [i, { name }] of attachments.filter((a) => a.type === 'image/png').entries()) {
|
|
79
|
+
const shot = `deictic.screenshot.${i + 1}`;
|
|
80
|
+
const position = labels[`${shot}.position`];
|
|
81
|
+
if (position === undefined) continue;
|
|
82
|
+
const said = notes(shot);
|
|
83
|
+
lines.push(
|
|
84
|
+
`${name}: the element at x,y ${position}, ${labels[`${shot}.size`] ?? '?'} (CSS pixels from its top left)${said.length === 0 ? '' : `; notes drawn on it: ${said.join(', ')}`}`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
const onPage = notes('deictic');
|
|
88
|
+
if (onPage.length > 0) lines.push(`Notes drawn on the page: ${onPage.join(', ')}`);
|
|
89
|
+
for (const [i, { name }] of attachments.filter((a) => a.name.startsWith('recording-')).entries()) {
|
|
90
|
+
const replay = labels[`deictic.recording.${i + 1}.replay`];
|
|
91
|
+
if (replay !== undefined) lines.push(`${name} replays at ${replay}`);
|
|
92
|
+
}
|
|
93
|
+
const dropped = numbered('deictic.dropped');
|
|
94
|
+
if (dropped.length > 0) lines.push(`Not attached, as it wasn't kept any more: ${dropped.join(', ')}`);
|
|
95
|
+
return lines;
|
|
96
|
+
}
|
|
97
|
+
|
|
56
98
|
/** The place as the task saw it, against the file now: the element's opening tag may have moved or changed. */
|
|
57
99
|
function placeOf(at: string, first: string | undefined): void {
|
|
58
100
|
const file = at.replace(/:\d+:\d+$/, '');
|
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
|
|