deictic 0.6.0 → 0.8.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 +156 -31
- package/README.md +6 -4
- package/dist/annotations/client.d.ts +1 -1
- package/dist/annotations/client.d.ts.map +1 -1
- package/dist/annotations/client.js +161 -176
- package/dist/annotations/client.js.map +1 -1
- package/dist/annotations/index.d.ts +2 -11
- package/dist/bun.js +1 -1
- package/dist/client/index.d.ts +7 -6
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1077 -236
- package/dist/client/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/next.js +1 -1
- package/dist/recommended/index.d.ts +2 -2
- package/dist/recordings/client.d.ts.map +1 -1
- package/dist/recordings/client.js +89 -154
- package/dist/recordings/client.js.map +1 -1
- package/dist/screenshots/client.d.ts.map +1 -1
- package/dist/shared/annotations.js +3 -4
- package/dist/shared/annotations.js.map +1 -1
- package/dist/shared/board.js +1 -1
- package/dist/shared/client.js +45 -2
- package/dist/shared/client.js.map +1 -1
- package/dist/shared/component.js +62 -0
- package/dist/shared/component.js.map +1 -0
- package/dist/shared/dom.js +79 -0
- package/dist/shared/dom.js.map +1 -0
- package/dist/shared/drawer.js +217 -0
- package/dist/shared/drawer.js.map +1 -0
- package/dist/shared/endpoints.js +26 -6
- package/dist/shared/endpoints.js.map +1 -1
- package/dist/shared/index.d.ts +150 -9
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index2.d.ts +9 -19
- package/dist/shared/index2.d.ts.map +1 -1
- package/dist/shared/index7.d.ts +123 -26
- package/dist/shared/index7.d.ts.map +1 -1
- package/dist/shared/index9.d.ts +1 -1
- package/dist/shared/integration.d.ts +1 -1
- package/dist/shared/integration.js +59 -5
- package/dist/shared/integration.js.map +1 -1
- package/dist/shared/package.js +23 -0
- package/dist/shared/package.js.map +1 -0
- package/dist/shared/packages.js +14 -23
- package/dist/shared/packages.js.map +1 -1
- package/dist/shared/playwright.js +11 -3
- package/dist/shared/playwright.js.map +1 -1
- package/dist/shared/recording.js +31 -3
- package/dist/shared/recording.js.map +1 -1
- package/dist/shared/src.js.map +1 -1
- package/dist/shared/task.js +55 -31
- package/dist/shared/task.js.map +1 -1
- package/dist/shared/tasks.js +279 -61
- package/dist/shared/tasks.js.map +1 -1
- package/dist/shared/vb.js +1 -1
- package/dist/shared/voice2.js +6 -4
- package/dist/shared/voice2.js.map +1 -1
- package/dist/shared/watch.js +15 -14
- package/dist/shared/watch.js.map +1 -1
- package/dist/tailwind/index.js +7 -2
- package/dist/tailwind/index.js.map +1 -1
- package/dist/tasks/client.d.ts +2 -2
- package/dist/tasks/client.d.ts.map +1 -1
- package/dist/tasks/client.js +1870 -741
- 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 +154 -57
- package/dist/voice/client.js.map +1 -1
- package/dist/webpack.js +1 -1
- package/package.json +2 -1
- package/skills/deictic/SKILL.md +22 -28
- package/src/cli/recording.ts +34 -3
- package/src/cli/task.ts +78 -33
- package/src/cli/voice.ts +9 -4
- package/src/cli/watch.ts +16 -13
- package/src/client/away.ts +3 -1
- package/src/client/component.ts +98 -0
- package/src/client/dom.ts +70 -0
- package/src/client/drawer.ts +258 -0
- package/src/client/index.ts +290 -165
- package/src/client/lightbox.ts +8 -8
- package/src/client/lighting.ts +279 -0
- package/src/client/style.ts +263 -44
- package/src/client/tools.ts +279 -0
- package/src/client/tooltip.ts +25 -5
- package/src/client/tray.ts +48 -0
- package/src/index.ts +148 -8
- package/src/plugins/annotations/client.ts +103 -129
- package/src/plugins/annotations/draw.ts +68 -72
- package/src/plugins/annotations/index.ts +12 -19
- package/src/plugins/recordings/client.ts +96 -168
- package/src/plugins/screenshots/client.ts +53 -2
- package/src/plugins/screenshots/playwright.ts +8 -3
- package/src/plugins/tailwind/index.ts +3 -2
- package/src/plugins/tasks/client.ts +229 -748
- package/src/plugins/tasks/composer.ts +797 -0
- package/src/plugins/tasks/drawer.ts +516 -0
- package/src/plugins/tasks/index.ts +436 -80
- package/src/plugins/tasks/pins.ts +280 -0
- package/src/plugins/tasks/store.ts +132 -0
- package/src/plugins/tasks/which.ts +34 -0
- package/src/plugins/voice/client.ts +96 -5
- package/src/tools/endpoints.ts +31 -5
- package/src/tools/packages.ts +12 -4
- package/src/tools/plugins.ts +18 -4
- package/src/tools/problems.ts +60 -0
- package/skills/deictic/references/recordings.md +0 -13
- package/skills/deictic/references/tasks.md +0 -22
- package/skills/deictic/references/watch.md +0 -17
|
@@ -17,7 +17,17 @@ import { join, relative } from 'node:path';
|
|
|
17
17
|
|
|
18
18
|
import type { Board } from '@vercel/board';
|
|
19
19
|
|
|
20
|
-
import
|
|
20
|
+
import manifest from '#package.json' with { type: 'json' };
|
|
21
|
+
import {
|
|
22
|
+
definePlugin,
|
|
23
|
+
type Point,
|
|
24
|
+
type Problem,
|
|
25
|
+
Refusal,
|
|
26
|
+
type ServerContext,
|
|
27
|
+
type Shortcut,
|
|
28
|
+
type Source,
|
|
29
|
+
type Target,
|
|
30
|
+
} from '#src/index.ts';
|
|
21
31
|
// For `use('screenshots')`'s type: the plugin may not be loaded, and nothing of it runs here.
|
|
22
32
|
import type { Recordings } from '#src/plugins/recordings/index.ts';
|
|
23
33
|
import type { Box } from '#src/plugins/screenshots/index.ts';
|
|
@@ -29,7 +39,7 @@ import { watchersOf } from './watchers.ts';
|
|
|
29
39
|
export { local, type LocalBoard, type LocalOptions } from './local.ts';
|
|
30
40
|
|
|
31
41
|
/** What the plugin uses of a board: `board()` from `@vercel/board` is one. */
|
|
32
|
-
export type TaskBoard = Pick<Board, 'tasks' | 'thread' | 'discovery' | 'upload' | 'edit' | 'actors'>;
|
|
42
|
+
export type TaskBoard = Pick<Board, 'tasks' | 'thread' | 'threads' | 'reply' | 'discovery' | 'upload' | 'download' | 'edit' | 'actors'>;
|
|
33
43
|
|
|
34
44
|
export interface TasksOptions {
|
|
35
45
|
/**
|
|
@@ -65,6 +75,12 @@ export interface TasksOptions {
|
|
|
65
75
|
html?: boolean;
|
|
66
76
|
/** What opens its tab directly, beside deictic's own shortcut, which opens any: none by default. */
|
|
67
77
|
shortcut?: Shortcut;
|
|
78
|
+
/**
|
|
79
|
+
* Whether deictic's own problems become tasks, for whoever works the board to fix: a package the project hasn't
|
|
80
|
+
* installed, a plugin that failed, a request that broke. One task per problem while it's open (`deictic.problem`
|
|
81
|
+
* is its key), about the project, not an element. True by default.
|
|
82
|
+
*/
|
|
83
|
+
problems?: boolean;
|
|
68
84
|
}
|
|
69
85
|
|
|
70
86
|
export interface Task {
|
|
@@ -82,13 +98,25 @@ export interface Task {
|
|
|
82
98
|
link?: string;
|
|
83
99
|
/** What was attached to it but not kept by the time it was sent, so it went without: `a screenshot`. */
|
|
84
100
|
dropped?: string;
|
|
101
|
+
/** The spot in the element it's about, where it's about one: CSS pixels from the element's top left. */
|
|
102
|
+
point?: Point;
|
|
103
|
+
/** Which of the elements from its place it's about, where the page had more than one. */
|
|
104
|
+
which?: Which;
|
|
85
105
|
/**
|
|
86
|
-
* Where it was added, where that isn't the element's place:
|
|
87
|
-
* it moved; for one of `elsewhere`, the element it's about.
|
|
106
|
+
* Where it was added, where that isn't the element's place: where the element was before it moved.
|
|
88
107
|
*/
|
|
89
108
|
at?: Place;
|
|
90
109
|
}
|
|
91
110
|
|
|
111
|
+
/**
|
|
112
|
+
* One of several elements from the same place in the source (a list's items): its place among them on the page, from 1,
|
|
113
|
+
* and its text where it has any, which still finds it once the list is in another order.
|
|
114
|
+
*/
|
|
115
|
+
export interface Which {
|
|
116
|
+
nth: number;
|
|
117
|
+
text?: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
92
120
|
/** A place in the element's file: a line and a column, from 1, and the tag there as the task saw it. */
|
|
93
121
|
export interface Place {
|
|
94
122
|
line: number;
|
|
@@ -96,14 +124,78 @@ export interface Place {
|
|
|
96
124
|
tag: string;
|
|
97
125
|
}
|
|
98
126
|
|
|
127
|
+
/** A task as the drawer lists it: with its place, where it has one, and how its thread stands. */
|
|
128
|
+
export interface Listed extends Task {
|
|
129
|
+
/** `file:line:column`, as the element's mark: none for a task about the page. */
|
|
130
|
+
place?: string;
|
|
131
|
+
/** The tag there, as the task saw it. */
|
|
132
|
+
tag?: string;
|
|
133
|
+
/** The page it was added on, as its path: `/pricing`. */
|
|
134
|
+
page?: string;
|
|
135
|
+
/** How many replies its thread has, and the newest's ID: what the page tells the unread by. */
|
|
136
|
+
replies: number;
|
|
137
|
+
last?: string;
|
|
138
|
+
/** What the board says of where it stands: why it's blocked, what it came to, why it failed. */
|
|
139
|
+
said?: string;
|
|
140
|
+
/** A problem of deictic's it tells of, not a person's ask: the project's setup to fix, or a bug of deictic's. */
|
|
141
|
+
problem?: Problem['kind'];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** A task with a place, as its mark has it: what the page pins to the element there. */
|
|
145
|
+
export type Placed = Listed & { place: string };
|
|
146
|
+
|
|
147
|
+
/** A file attached to a task or to a reply in its thread, as the board keeps it. */
|
|
148
|
+
export interface Attached {
|
|
149
|
+
/** The board's ID for it. */
|
|
150
|
+
id: string;
|
|
151
|
+
name: string;
|
|
152
|
+
/** Its MIME type: `image/png`, `audio/webm`, `application/json` for a recording, `text/html` for an element's HTML. */
|
|
153
|
+
type: string;
|
|
154
|
+
/** In bytes. */
|
|
155
|
+
size: number;
|
|
156
|
+
/**
|
|
157
|
+
* Where the page gets it: by default the plugin's `file/<task>/<id>` route, which serves an image or a sound as it
|
|
158
|
+
* is and anything else as text. A `standalone` server answers its own.
|
|
159
|
+
*/
|
|
160
|
+
url?: string;
|
|
161
|
+
/** Where a recording plays back, as the message says. */
|
|
162
|
+
replay?: string;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** A message in a task's thread, oldest first. */
|
|
166
|
+
export interface Reply {
|
|
167
|
+
id: string;
|
|
168
|
+
/** Who wrote it, by name. */
|
|
169
|
+
by: string;
|
|
170
|
+
/** `person`, or what else wrote it: an agent's `profile`, a deployment, a workflow. */
|
|
171
|
+
kind: string;
|
|
172
|
+
text: string;
|
|
173
|
+
/** When, as an ISO date. */
|
|
174
|
+
at: string;
|
|
175
|
+
/** What it has attached. */
|
|
176
|
+
files: Attached[];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** A task with its thread, as the drawer opens it. */
|
|
180
|
+
export interface Thread {
|
|
181
|
+
task: Listed;
|
|
182
|
+
/** What the task has attached: its shots, recordings, voice notes and elements' HTML. */
|
|
183
|
+
files: Attached[];
|
|
184
|
+
replies: Reply[];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* A reply, as the drawer's composer sends it to the `reply/<id>` route: its words, and what's attached, as a task
|
|
189
|
+
* attaches it. A reply with nothing typed says what's attached instead.
|
|
190
|
+
*/
|
|
191
|
+
export type Answer = Pick<Op, 'text' | 'screenshots' | 'recordings' | 'voice' | 'annotations'>;
|
|
192
|
+
|
|
99
193
|
export interface Model {
|
|
100
194
|
channel: string;
|
|
101
195
|
/** The channel's page, when there's one to link to. */
|
|
102
196
|
link?: string;
|
|
103
197
|
/** Tasks about this element, oldest first, canceled ones left out: also those added before it moved. */
|
|
104
198
|
tasks: Task[];
|
|
105
|
-
/** Tasks about the file's other elements, by line, canceled ones left out: each with its `at`. */
|
|
106
|
-
elsewhere: Task[];
|
|
107
199
|
/**
|
|
108
200
|
* Who watches the channel, by name (`claude`): the agents whose watch (`deictic watch`) is running in
|
|
109
201
|
* this project, as a board can't say, and those holding a claim on one of the channel's tasks, which it can.
|
|
@@ -113,18 +205,17 @@ export interface Model {
|
|
|
113
205
|
watching?: string[];
|
|
114
206
|
}
|
|
115
207
|
|
|
116
|
-
/**
|
|
117
|
-
* What the Task tab asks for: a new task (an `Op`), other words for one it lists (`edit` is its ID), or
|
|
118
|
-
* that one deleted (`remove` is its ID), which cancels it on the board.
|
|
119
|
-
*/
|
|
120
|
-
export type Change = Op | { edit: string; text: string } | { remove: string };
|
|
121
|
-
|
|
122
208
|
/** A new task: what the page knows and the source doesn't. */
|
|
123
209
|
export interface Op {
|
|
124
210
|
text: string;
|
|
125
211
|
/** The page's URL. */
|
|
126
212
|
page: string;
|
|
127
213
|
viewport: { width: number; height: number };
|
|
214
|
+
/**
|
|
215
|
+
* The spot it's about, where it was added on one (the tool panel's task tool) and not on the element as a whole:
|
|
216
|
+
* CSS pixels from the element's top left, and outside its box where the element is only the nearest to the spot.
|
|
217
|
+
*/
|
|
218
|
+
point?: Point;
|
|
128
219
|
/**
|
|
129
220
|
* What was under the pointer inside the element, where nothing marked it (a dependency's markup, or a
|
|
130
221
|
* shadow root's): its path from the element, and its HTML, cut short.
|
|
@@ -132,6 +223,18 @@ export interface Op {
|
|
|
132
223
|
pointed?: { path: string; html: string };
|
|
133
224
|
/** How many elements on the page come from the same place in the source. */
|
|
134
225
|
count: number;
|
|
226
|
+
/** Which of them it is, where there's more than one: what the page tells it from the others by. */
|
|
227
|
+
which?: Which;
|
|
228
|
+
/**
|
|
229
|
+
* The other elements it's about, after the one it's sent on, in the order they were attached: each one's place,
|
|
230
|
+
* its tag, and its HTML as it rendered, where that's attached.
|
|
231
|
+
*/
|
|
232
|
+
also?: { at: string; tag: string; html?: string }[];
|
|
233
|
+
/**
|
|
234
|
+
* No element is attached: it's about the page, and the element it's sent on is only where the popup was. It has
|
|
235
|
+
* no place then, so no element's tab lists it and nothing pins it.
|
|
236
|
+
*/
|
|
237
|
+
detached?: boolean;
|
|
135
238
|
/**
|
|
136
239
|
* The source it rendered through, after its own place, nearest first: where the one before it is used. With
|
|
137
240
|
* React in development, the components that wrote it, `Field (src/Field.tsx:20)` or a name alone; without, the
|
|
@@ -142,11 +245,12 @@ export interface Op {
|
|
|
142
245
|
/** The element's HTML as it rendered, to attach: cut short, and masked where the screenshots plugin is loaded. */
|
|
143
246
|
html?: string;
|
|
144
247
|
/**
|
|
145
|
-
* Shots the screenshots plugin took
|
|
146
|
-
*
|
|
147
|
-
*
|
|
248
|
+
* Shots the screenshots plugin took, to attach, where that plugin is loaded: each with where the element is in
|
|
249
|
+
* it (`box`, for one taken of the element; one taken of the window from the tool panel has none), whether
|
|
250
|
+
* it's `outlined` there (dashes drawn around it, or around the spot, in the PNG), and the marks drawn on it in
|
|
251
|
+
* the Task tab, where there are any.
|
|
148
252
|
*/
|
|
149
|
-
screenshots?: { id: string; box
|
|
253
|
+
screenshots?: { id: string; box?: Box; outlined?: boolean; marks?: Marks }[];
|
|
150
254
|
/**
|
|
151
255
|
* Recordings the recordings plugin made, to attach, where that plugin is loaded: how long each ran,
|
|
152
256
|
* where it plays back, and the voice plugin's clips of the mic in it, attached too.
|
|
@@ -174,6 +278,11 @@ export interface TaskAdded {
|
|
|
174
278
|
page: string;
|
|
175
279
|
/** How many of each were attached; `marks` counts those drawn on shots and on the page. */
|
|
176
280
|
attached: { screenshots: number; recordings: number; voice: number; marks: number };
|
|
281
|
+
/**
|
|
282
|
+
* Where each attached shot is, as it was sent (outlined, or as it was drawn on), for the page to show: the
|
|
283
|
+
* screenshots plugin's `shot` route, or what a `standalone` server answered.
|
|
284
|
+
*/
|
|
285
|
+
screenshots: string[];
|
|
177
286
|
}
|
|
178
287
|
|
|
179
288
|
/** Marks, as a task tells of them: how many, and what the notes among them say. */
|
|
@@ -191,7 +300,7 @@ export interface Added {
|
|
|
191
300
|
attachments?: string[];
|
|
192
301
|
}
|
|
193
302
|
|
|
194
|
-
/** A task's words changed: its message's whole text before and after. */
|
|
303
|
+
/** A task's words changed in the tab, as an earlier version let it: its message's whole text before and after. */
|
|
195
304
|
export interface Edited {
|
|
196
305
|
kind: 'edited';
|
|
197
306
|
id: string;
|
|
@@ -200,18 +309,37 @@ export interface Edited {
|
|
|
200
309
|
}
|
|
201
310
|
|
|
202
311
|
/**
|
|
203
|
-
* A task deleted in the
|
|
204
|
-
* an undo adds it again, as a new task whose ID the record then has.
|
|
312
|
+
* A task deleted in the tab, as an earlier version let it: canceled on the board, for good, as a board has it. So
|
|
313
|
+
* it's kept whole, and an undo adds it again, as a new task whose ID the record then has.
|
|
205
314
|
*/
|
|
206
315
|
export interface Removed extends Added {
|
|
207
316
|
kind: 'removed';
|
|
208
317
|
}
|
|
209
318
|
|
|
210
|
-
/**
|
|
319
|
+
/**
|
|
320
|
+
* What the history keeps of a change: a task added has no `kind`, as it had none before there were others. The others
|
|
321
|
+
* are no longer made (a task is changed in the drawer, by the plugin's routes), and still undone where a history has them.
|
|
322
|
+
*/
|
|
211
323
|
export type Kept = Added | Edited | Removed;
|
|
212
324
|
|
|
325
|
+
/** A task as a board lists it: its root message. */
|
|
326
|
+
type Message = Awaited<ReturnType<TaskBoard['thread']>>['message'];
|
|
327
|
+
/** A task's thread at a glance, as a board lists tasks. */
|
|
328
|
+
type Summary = Awaited<ReturnType<TaskBoard['tasks']['list']>>['tasks'][number];
|
|
329
|
+
/** How many of the latest finished tasks the drawer lists: what an agent said as it ended one is there to read. */
|
|
330
|
+
const OVER = 10;
|
|
331
|
+
|
|
332
|
+
/** How many tasks a page is asked about at most: past that it has more pins than anyone reads. */
|
|
333
|
+
const PINNED = 500;
|
|
213
334
|
const AT = 'deictic.at';
|
|
335
|
+
/** A problem's key, on the task that tells of it: one task per problem while it's open. */
|
|
336
|
+
const PROBLEM = 'deictic.problem';
|
|
214
337
|
const FILE = 'deictic.file';
|
|
338
|
+
/** `x,y`: the spot in the element a task is about, in CSS pixels from the element's top left. */
|
|
339
|
+
const POINT = 'deictic.point';
|
|
340
|
+
/** Which of several elements from one place it's about: `deictic.nth` from 1, `deictic.text` its text. */
|
|
341
|
+
const NTH = 'deictic.nth';
|
|
342
|
+
const TEXT = 'deictic.text';
|
|
215
343
|
/** What parts what was typed from the rest of a task's text. */
|
|
216
344
|
const REST = '\n---\n';
|
|
217
345
|
/** A file for the board, as the plugins that keep them read it. */
|
|
@@ -270,9 +398,12 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
270
398
|
* One of this channel's tasks about an element, while it's still open: the page names it by ID, so
|
|
271
399
|
* nothing else on the board is its to change, nor a task someone has taken up.
|
|
272
400
|
*/
|
|
401
|
+
/** One of deictic's: it has a place, or the page it's about where no element was attached. */
|
|
402
|
+
const ours = (message: Message) =>
|
|
403
|
+
message.labels[AT] !== undefined || message.labels['deictic.page'] !== undefined || message.labels[PROBLEM] !== undefined;
|
|
273
404
|
const openTask = async (team: TaskBoard, id: string, verb: string) => {
|
|
274
405
|
const { message } = await team.thread(id);
|
|
275
|
-
if (message.channel !== channel || message
|
|
406
|
+
if (message.channel !== channel || !ours(message))
|
|
276
407
|
throw new Refusal(`#${id} isn't a task of deictic's in #${channel}: reload the page for the ones that are`);
|
|
277
408
|
|
|
278
409
|
const { task } = message;
|
|
@@ -309,6 +440,141 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
309
440
|
return { ...record, id: task.id };
|
|
310
441
|
};
|
|
311
442
|
|
|
443
|
+
/** A board's task as the panel lists it: its words, its state, who has it, and its page there. */
|
|
444
|
+
const taskOf = (message: Message, actors: Awaited<ReturnType<typeof actorsOf>>, page: string | undefined): Task => {
|
|
445
|
+
const state = message.task?.state ?? 'ready';
|
|
446
|
+
const by = actors.get(message.task?.claim?.actor ?? '')?.name;
|
|
447
|
+
const text = message.text.split(REST, 1)[0]!;
|
|
448
|
+
const to = taskLink(page, message.id);
|
|
449
|
+
const missing = Object.entries(message.labels).flatMap(([key, value]) => (/^deictic\.dropped\.\d+$/.test(key) ? [value] : []));
|
|
450
|
+
const dropped = missing.length === 0 ? undefined : listOf(missing);
|
|
451
|
+
const [, x, y] = /^(-?\d+),(-?\d+)$/.exec(message.labels[POINT] ?? '') ?? [];
|
|
452
|
+
const point = x === undefined || y === undefined ? undefined : { x: Number(x), y: Number(y) };
|
|
453
|
+
const nth = Number(message.labels[NTH]);
|
|
454
|
+
const said = message.labels[TEXT];
|
|
455
|
+
const which = Number.isInteger(nth) && nth > 0 ? { nth, ...(said === undefined ? {} : { text: said }) } : undefined;
|
|
456
|
+
return {
|
|
457
|
+
id: message.id,
|
|
458
|
+
title: text.split('\n', 1)[0]!,
|
|
459
|
+
text,
|
|
460
|
+
state,
|
|
461
|
+
...(by === undefined ? {} : { by }),
|
|
462
|
+
open: OPEN.has(state),
|
|
463
|
+
...(to === undefined ? {} : { link: to }),
|
|
464
|
+
...(dropped === undefined ? {} : { dropped }),
|
|
465
|
+
...(point === undefined ? {} : { point }),
|
|
466
|
+
...(which === undefined ? {} : { which }),
|
|
467
|
+
};
|
|
468
|
+
};
|
|
469
|
+
const listedOf = (
|
|
470
|
+
{ message, replies, last }: Summary,
|
|
471
|
+
actors: Awaited<ReturnType<typeof actorsOf>>,
|
|
472
|
+
page: string | undefined,
|
|
473
|
+
): Listed => {
|
|
474
|
+
const { task, labels } = message;
|
|
475
|
+
const said = task?.blocked?.reason ?? task?.result ?? task?.reason ?? undefined;
|
|
476
|
+
const problem = labels[`${PROBLEM}.kind`];
|
|
477
|
+
return {
|
|
478
|
+
...taskOf(message, actors, page),
|
|
479
|
+
...(labels[AT] === undefined ? {} : { place: labels[AT] }),
|
|
480
|
+
...(labels['deictic.tag'] === undefined ? {} : { tag: labels['deictic.tag'] }),
|
|
481
|
+
...(labels['deictic.page'] === undefined ? {} : { page: labels['deictic.page'] }),
|
|
482
|
+
replies,
|
|
483
|
+
...(last === null ? {} : { last: last.id }),
|
|
484
|
+
...(said === undefined || said === '' ? {} : { said: clip(said, 2000) }),
|
|
485
|
+
...(problem === 'setup' || problem === 'bug' ? { problem } : {}),
|
|
486
|
+
};
|
|
487
|
+
};
|
|
488
|
+
/**
|
|
489
|
+
* The channel's tasks, for the page: those still to do, oldest first, a page of the board's at a time and no more
|
|
490
|
+
* than `PINNED`, then the `OVER` that last ended, the latest first.
|
|
491
|
+
*/
|
|
492
|
+
const listed = async (): Promise<Listed[]> => {
|
|
493
|
+
const team = await boardOf();
|
|
494
|
+
const open: Summary[] = [];
|
|
495
|
+
for (let after: string | undefined; open.length < PINNED;) {
|
|
496
|
+
const { tasks, cursor } = await team.tasks.list({ channel, ...(after === undefined ? {} : { after }) });
|
|
497
|
+
open.push(...tasks);
|
|
498
|
+
if (tasks.length === 0 || cursor === after) break;
|
|
499
|
+
after = cursor;
|
|
500
|
+
}
|
|
501
|
+
// By their latest activity, which is how a board answers threads: the newest of each end, then of both.
|
|
502
|
+
const ended = await Promise.all(
|
|
503
|
+
['completed', 'failed'].map((state) => team.threads({ channel, label: { 'board.task': state }, limit: OVER })),
|
|
504
|
+
);
|
|
505
|
+
const when = ({ message, last }: Summary) => (last ?? message).createdAt;
|
|
506
|
+
const over = ended
|
|
507
|
+
.flatMap(({ threads }) => threads)
|
|
508
|
+
.sort((a, b) => when(b).localeCompare(when(a)))
|
|
509
|
+
.slice(0, OVER);
|
|
510
|
+
const about = [...open, ...over].filter(({ message }) => ours(message));
|
|
511
|
+
const [actors, page] = await Promise.all([
|
|
512
|
+
actorsOf(
|
|
513
|
+
team,
|
|
514
|
+
about.flatMap(({ message }) => message.task?.claim?.actor ?? []),
|
|
515
|
+
),
|
|
516
|
+
linkOf(),
|
|
517
|
+
]);
|
|
518
|
+
return about.map((summary) => listedOf(summary, actors, page));
|
|
519
|
+
};
|
|
520
|
+
const replyOf = (message: Message): Reply => ({
|
|
521
|
+
id: message.id,
|
|
522
|
+
by: message.author?.name ?? message.by.actor,
|
|
523
|
+
kind: message.author?.kind ?? 'unknown',
|
|
524
|
+
text: message.text,
|
|
525
|
+
at: message.createdAt,
|
|
526
|
+
files: filesOf(message),
|
|
527
|
+
});
|
|
528
|
+
/** A task of ours with its thread, the newest replies a board answers at once. */
|
|
529
|
+
const threadOf = async (id: string): Promise<Thread> => {
|
|
530
|
+
const team = await boardOf();
|
|
531
|
+
const { message, replies } = await team.thread(id);
|
|
532
|
+
if (message.channel !== channel || !ours(message))
|
|
533
|
+
throw new Refusal(`#${id} isn't a task of deictic's in #${channel}: reload the page for the ones that are`);
|
|
534
|
+
const said = replies.filter((reply) => !reply.deleted);
|
|
535
|
+
const [actors, page] = await Promise.all([actorsOf(team, message.task?.claim ? [message.task.claim.actor] : []), linkOf()]);
|
|
536
|
+
return {
|
|
537
|
+
task: listedOf({ message, replies: said.length, last: said.at(-1) ?? null }, actors, page),
|
|
538
|
+
files: filesOf(message),
|
|
539
|
+
replies: said.map(replyOf),
|
|
540
|
+
};
|
|
541
|
+
};
|
|
542
|
+
/** The task a route's request names, as its last segment, and what it sent. */
|
|
543
|
+
const named = async (req: Request) => {
|
|
544
|
+
const id = decodeURIComponent(new URL(req.url).pathname.split('/').at(-1) ?? '');
|
|
545
|
+
const sent: unknown = req.method === 'POST' ? await req.json().catch(() => ({})) : {};
|
|
546
|
+
const body = (typeof sent === 'object' && sent !== null ? sent : {}) as Partial<Answer>;
|
|
547
|
+
return { id, text: typeof body.text === 'string' ? body.text : '', body };
|
|
548
|
+
};
|
|
549
|
+
/**
|
|
550
|
+
* A file of a task's, `file/<task>/<file>`: one attached to the task or to a reply in its thread, and to nothing
|
|
551
|
+
* else on the board. An image or a sound is served as it is; anything else as its text, escaped, in a page of the
|
|
552
|
+
* lightbox's dark colours, so an element's HTML is read there, never run, on the dev server's origin.
|
|
553
|
+
*/
|
|
554
|
+
const fileOf = async (req: Request): Promise<Response> => {
|
|
555
|
+
const [task = '', file = ''] = (new URL(req.url).pathname.split('/file/')[1] ?? '').split('/').map(decodeURIComponent);
|
|
556
|
+
const team = await boardOf();
|
|
557
|
+
const { message, replies } = await team.thread(task);
|
|
558
|
+
if (message.channel !== channel || !ours(message))
|
|
559
|
+
throw new Refusal(`#${task} isn't a task of deictic's in #${channel}: reload the page for the ones that are`);
|
|
560
|
+
const found = [message, ...replies].flatMap((m) => m.attachments).find((a) => a.id === file);
|
|
561
|
+
if (found === undefined) throw new Refusal(`task ${task} has no file ${file}: reload the page for what it has`);
|
|
562
|
+
const res = await team.download(found.id);
|
|
563
|
+
const media = /^(image|audio|video)\//.test(found.type);
|
|
564
|
+
const body = media ? res.body : textPage(found.name, await res.text());
|
|
565
|
+
return new Response(body, {
|
|
566
|
+
headers: {
|
|
567
|
+
'content-type': media ? found.type : 'text/html; charset=utf-8',
|
|
568
|
+
'content-disposition': `inline; filename="${found.name.replaceAll('"', '')}"`,
|
|
569
|
+
'x-content-type-options': 'nosniff',
|
|
570
|
+
// Its own style and nothing else: no script, no request anywhere.
|
|
571
|
+
'content-security-policy': "sandbox; default-src 'none'; style-src 'unsafe-inline'; img-src 'self' blob:; media-src 'self' blob:",
|
|
572
|
+
// A board's file never changes under its ID.
|
|
573
|
+
'cache-control': 'private, max-age=86400, immutable',
|
|
574
|
+
},
|
|
575
|
+
});
|
|
576
|
+
};
|
|
577
|
+
|
|
312
578
|
// Kept from `setup`, to `use` another plugin when an op asks for it.
|
|
313
579
|
let context: ServerContext | undefined;
|
|
314
580
|
let project = options.project;
|
|
@@ -316,7 +582,7 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
316
582
|
* The op with only the screenshots, recordings and voice clips still kept, their files, and what's left out: a file
|
|
317
583
|
* goes once newer ones pass its plugin's `keep`, or `deictic clean` takes it, and that's no reason to lose the task.
|
|
318
584
|
*/
|
|
319
|
-
const keptOf = (op:
|
|
585
|
+
const keptOf = <T extends Attaching>(op: T) => {
|
|
320
586
|
const clipOf = (id: string): ReturnType<Clips['read']> => context?.use('voice')?.read(id);
|
|
321
587
|
// In the op's order, each kind's: the Nth PNG is `deictic.screenshot.N`'s, the Nth recording `deictic.recording.N`'s.
|
|
322
588
|
const files: Upload[] = [];
|
|
@@ -341,7 +607,12 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
341
607
|
if (html !== undefined) files.push({ data: new TextEncoder().encode(html.slice(0, HTML)), name: 'element.html', type: 'text/html' });
|
|
342
608
|
else if (op.pointed !== undefined)
|
|
343
609
|
files.push({ data: new TextEncoder().encode(op.pointed.html.slice(0, HTML)), name: 'pointed.html', type: 'text/html' });
|
|
344
|
-
|
|
610
|
+
// The others': the Nth element's is `element.N.html`, the first being the one it's sent on.
|
|
611
|
+
for (const [i, other] of (op.also ?? []).entries()) {
|
|
612
|
+
if (typeof other.html !== 'string' || other.html === '') continue;
|
|
613
|
+
files.push({ data: new TextEncoder().encode(other.html.slice(0, HTML)), name: `element.${i + 2}.html`, type: 'text/html' });
|
|
614
|
+
}
|
|
615
|
+
const kept: T = {
|
|
345
616
|
...op,
|
|
346
617
|
...(op.screenshots === undefined ? {} : { screenshots }),
|
|
347
618
|
...(op.recordings === undefined ? {} : { recordings }),
|
|
@@ -356,7 +627,7 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
356
627
|
return Promise.all(files.map(async (file) => (await team.upload(file)).id));
|
|
357
628
|
};
|
|
358
629
|
|
|
359
|
-
return definePlugin<Model,
|
|
630
|
+
return definePlugin<Model, Op, Kept>({
|
|
360
631
|
name: 'tasks',
|
|
361
632
|
client: 'deictic/tasks/client',
|
|
362
633
|
packages: ['@vercel/board'],
|
|
@@ -371,6 +642,64 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
371
642
|
// Not waited for: a failure is the first request's to tell.
|
|
372
643
|
void boardOf().catch(() => {});
|
|
373
644
|
},
|
|
645
|
+
routes: {
|
|
646
|
+
// The channel's tasks, for the page: the drawer lists them, and those with a place are pinned where their
|
|
647
|
+
// elements are.
|
|
648
|
+
page: async () => {
|
|
649
|
+
const [tasks, link] = await Promise.all([asked(listed), linkOf()]);
|
|
650
|
+
return Response.json({ channel, ...(link === undefined ? {} : { link }), tasks });
|
|
651
|
+
},
|
|
652
|
+
// A task and its thread, `thread/<id>`: what the drawer opens.
|
|
653
|
+
thread: async (req) => Response.json(await asked(async () => threadOf((await named(req)).id))),
|
|
654
|
+
// What the drawer does to a task: a reply in its thread, other words for it, or its end, which cancels it
|
|
655
|
+
// on the board. Each answers the thread as it is after.
|
|
656
|
+
// What a task has attached, or a reply in its thread, for the drawer to show.
|
|
657
|
+
file: (req) => asked(() => fileOf(req)),
|
|
658
|
+
reply: (req) =>
|
|
659
|
+
asked(async () => {
|
|
660
|
+
const { id, text, body } = await named(req);
|
|
661
|
+
const answer: Answer = {
|
|
662
|
+
text,
|
|
663
|
+
...(Array.isArray(body.screenshots) ? { screenshots: body.screenshots } : {}),
|
|
664
|
+
...(Array.isArray(body.recordings) ? { recordings: body.recordings } : {}),
|
|
665
|
+
...(Array.isArray(body.voice) ? { voice: body.voice } : {}),
|
|
666
|
+
...(body.annotations === undefined ? {} : { annotations: body.annotations }),
|
|
667
|
+
};
|
|
668
|
+
if (wordsOf(answer) === '') throw new Refusal('say something first');
|
|
669
|
+
await threadOf(id);
|
|
670
|
+
const { op: kept, files, dropped } = keptOf(answer);
|
|
671
|
+
const verb = dropped.length === 1 ? "isn't" : "aren't";
|
|
672
|
+
if (wordsOf(kept) === '') throw new Refusal(`${listOf(dropped)} ${verb} kept any more: attach again, or say something`);
|
|
673
|
+
// What the files don't say, as a task has it: where each recording replays, the notes drawn.
|
|
674
|
+
const labels = attachedLabels(kept, dropped);
|
|
675
|
+
const attachments = await upload(files);
|
|
676
|
+
await (
|
|
677
|
+
await boardOf()
|
|
678
|
+
).reply(id, {
|
|
679
|
+
text: clip(wordsOf(kept), 10_000),
|
|
680
|
+
...(Object.keys(labels).length === 0 ? {} : { labels }),
|
|
681
|
+
...(attachments === undefined ? {} : { attachments }),
|
|
682
|
+
});
|
|
683
|
+
return Response.json(await threadOf(id));
|
|
684
|
+
}),
|
|
685
|
+
edit: (req) =>
|
|
686
|
+
asked(async () => {
|
|
687
|
+
const { id, text } = await named(req);
|
|
688
|
+
// A task's words are never changed to none.
|
|
689
|
+
if (text.trim() === '') throw new Refusal('say what should change first');
|
|
690
|
+
const before = (await openTask(await boardOf(), id, 'edit')).text;
|
|
691
|
+
// What follows the words in a task added before they were labels (what's attached, what was pointed at) stays.
|
|
692
|
+
const rest = before.includes(REST) ? before.slice(before.indexOf(REST)) : '';
|
|
693
|
+
await rewrite(id, before, clip(text.trim(), 10_000 - rest.length) + rest);
|
|
694
|
+
return Response.json(await threadOf(id));
|
|
695
|
+
}),
|
|
696
|
+
remove: (req) =>
|
|
697
|
+
asked(async () => {
|
|
698
|
+
const { id } = await named(req);
|
|
699
|
+
await cancel(id, 'deleted in deictic');
|
|
700
|
+
return Response.json({});
|
|
701
|
+
}),
|
|
702
|
+
},
|
|
374
703
|
read: (source, target) =>
|
|
375
704
|
asked(async () => {
|
|
376
705
|
const team = await boardOf();
|
|
@@ -386,34 +715,17 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
386
715
|
// Nothing to tell a moved task by where the file has no such element.
|
|
387
716
|
const line = source instanceof Refusal ? undefined : onceIn(source);
|
|
388
717
|
const tasks: Task[] = [];
|
|
389
|
-
const elsewhere: (Task & { at: Place })[] = [];
|
|
390
718
|
const about = [...here.tasks.filter((t) => !listed.has(t.message.id)), ...inFile.tasks];
|
|
391
719
|
// Who has each, and who holds any claim on the channel: asked of the board at once.
|
|
392
720
|
const actorOf = ({ task }: (typeof about)[number]['message']) => task?.claim?.actor;
|
|
393
721
|
const claims = held.tasks.flatMap(({ message }) => message.task?.claim ?? []);
|
|
394
722
|
const actors = await actorsOf(team, [...about.flatMap(({ message }) => actorOf(message) ?? []), ...claims.map((c) => c.actor)]);
|
|
395
723
|
for (const { message } of about) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
const by = actors.get(actorOf(message) ?? '')?.name;
|
|
399
|
-
const text = message.text.split(REST, 1)[0]!;
|
|
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);
|
|
403
|
-
const task = {
|
|
404
|
-
id: message.id,
|
|
405
|
-
title: text.split('\n', 1)[0]!,
|
|
406
|
-
text,
|
|
407
|
-
state,
|
|
408
|
-
...(by === undefined ? {} : { by }),
|
|
409
|
-
open: OPEN.has(state),
|
|
410
|
-
...(to === undefined ? {} : { link: to }),
|
|
411
|
-
...(dropped === undefined ? {} : { dropped }),
|
|
412
|
-
};
|
|
724
|
+
if (message.task?.state === 'canceled') continue;
|
|
725
|
+
const task = taskOf(message, actors, page);
|
|
413
726
|
const at = placeIn(message.labels);
|
|
414
727
|
if (at === undefined || message.labels[AT] === atOf(target)) tasks.push(task);
|
|
415
728
|
else if (line !== undefined && at.tag === target.tag && message.labels['deictic.line'] === line) tasks.push({ ...task, at });
|
|
416
|
-
else elsewhere.push({ ...task, at });
|
|
417
729
|
}
|
|
418
730
|
// An agent at work on a task is here too, though its watch may be over until the task is (`deictic watch --once`).
|
|
419
731
|
const working = agentsOf(actors, claims);
|
|
@@ -425,33 +737,11 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
425
737
|
...(page === undefined ? {} : { link: page }),
|
|
426
738
|
...(watching.length > 0 || ours ? { watching } : {}),
|
|
427
739
|
tasks,
|
|
428
|
-
// The board's order (oldest first) among those of one place.
|
|
429
|
-
elsewhere: elsewhere.sort((a, b) => (a.at.line === b.at.line ? a.at.column - b.at.column : a.at.line - b.at.line)),
|
|
430
740
|
};
|
|
431
741
|
}),
|
|
432
742
|
apply: (source, target, op) => {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
const message = await cancel(op.remove, 'deleted in deictic');
|
|
436
|
-
// The board's own labels (`board.task`) are its to set on the task an undo adds.
|
|
437
|
-
const labels = Object.fromEntries(Object.entries(message.labels).filter(([key]) => !key.startsWith('board.')));
|
|
438
|
-
const attachments = message.attachments.map((a) => a.id);
|
|
439
|
-
const kept = { channel, id: op.remove, text: message.text, labels, ...(attachments.length === 0 ? {} : { attachments }) };
|
|
440
|
-
return { done: { kind: 'removed' as const, ...kept } };
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
// A new task may go without words where something attached says it; a task's words are never changed to none.
|
|
444
|
-
if (op.text.trim() === '' && ('edit' in op || shown(op) === undefined)) throw new Refusal('say what should change first');
|
|
445
|
-
if ('edit' in op) {
|
|
446
|
-
return asked(async () => {
|
|
447
|
-
const before = (await openTask(await boardOf(), op.edit, 'edit')).text;
|
|
448
|
-
// What follows the words in a task added before they were labels (what's attached, what was pointed at) stays.
|
|
449
|
-
const rest = before.includes(REST) ? before.slice(before.indexOf(REST)) : '';
|
|
450
|
-
const after = clip(op.text.trim(), 10_000 - rest.length) + rest;
|
|
451
|
-
await rewrite(op.edit, before, after);
|
|
452
|
-
return { done: { kind: 'edited' as const, id: op.edit, before, after } };
|
|
453
|
-
});
|
|
454
|
-
}
|
|
743
|
+
// A task may go without words where something attached says it.
|
|
744
|
+
if (op.text.trim() === '' && shown(op) === undefined) throw new Refusal('say what should change first');
|
|
455
745
|
const { op: kept, files, dropped } = keptOf(op);
|
|
456
746
|
const verb = dropped.length === 1 ? "isn't" : "aren't";
|
|
457
747
|
if (wordsOf(kept) === '') throw new Refusal(`${listOf(dropped)} ${verb} kept any more: attach again, or say what should change`);
|
|
@@ -493,15 +783,43 @@ export function tasks(options: TasksOptions = {}) {
|
|
|
493
783
|
await cancel(record.id, 'deleted in deictic');
|
|
494
784
|
return record;
|
|
495
785
|
}),
|
|
496
|
-
describe: (op
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
if (
|
|
500
|
-
|
|
786
|
+
describe: (op) => `task "${clip(wordsOf(op).split('\n', 1)[0]!, 60)}"`,
|
|
787
|
+
// A task, unless one is open for it already: a dev server started again finds the same problem again.
|
|
788
|
+
problem: async (problem) => {
|
|
789
|
+
if (options.problems === false) return;
|
|
790
|
+
const key = clip(problem.key, LABEL);
|
|
791
|
+
const team = await boardOf();
|
|
792
|
+
if ((await team.tasks.list({ channel, label: { [PROBLEM]: key }, limit: 1 })).tasks.length > 0) return;
|
|
793
|
+
await create({
|
|
794
|
+
channel,
|
|
795
|
+
text: clip(problemText(problem), 10_000),
|
|
796
|
+
labels: {
|
|
797
|
+
...options.labels,
|
|
798
|
+
...(project === undefined ? {} : { 'deictic.project': clip(project, LABEL) }),
|
|
799
|
+
[PROBLEM]: key,
|
|
800
|
+
[`${PROBLEM}.kind`]: problem.kind,
|
|
801
|
+
...(problem.plugin === undefined ? {} : { [`${PROBLEM}.plugin`]: clip(problem.plugin, LABEL) }),
|
|
802
|
+
'deictic.version': manifest.version,
|
|
803
|
+
},
|
|
804
|
+
});
|
|
501
805
|
},
|
|
502
806
|
});
|
|
503
807
|
}
|
|
504
808
|
|
|
809
|
+
/**
|
|
810
|
+
* A problem as a task says it: what went wrong and what to do, and after the `---` its details, which `deictic task`
|
|
811
|
+
* prints and the drawer leaves out.
|
|
812
|
+
*/
|
|
813
|
+
function problemText({ kind, message, details, plugin }: Problem): string {
|
|
814
|
+
const whose = plugin === undefined ? 'deictic' : `deictic's ${plugin} plugin`;
|
|
815
|
+
const todo =
|
|
816
|
+
kind === 'setup'
|
|
817
|
+
? `Reported by ${whose}, about the project's setup: fix it as it says, then restart the dev server and check it's gone.`
|
|
818
|
+
: `A bug in ${whose} (${manifest.version}), not in this project: don't change it where it's installed. Tell the person, with the details, so they can report it (deictic's own at ${manifest.bugs.url}), and complete the task.`;
|
|
819
|
+
const more = details === undefined ? '' : `${REST}\`\`\`\n${details}\n\`\`\``;
|
|
820
|
+
return `${message[0]!.toUpperCase()}${message.slice(1)}\n\n${todo}${more}`;
|
|
821
|
+
}
|
|
822
|
+
|
|
505
823
|
/**
|
|
506
824
|
* The channel's page on a board `vb serve` runs on this machine, which serves its pages beside its API:
|
|
507
825
|
* `/api/board` there, `/c/<channel>` beside it. Nothing for any other board.
|
|
@@ -512,17 +830,44 @@ async function localPage(team: TaskBoard, channel: string): Promise<string | und
|
|
|
512
830
|
return `${url.origin}${url.pathname.slice(0, -'/api/board'.length)}/c/${channel.split('/').map(encodeURIComponent).join('/')}`;
|
|
513
831
|
}
|
|
514
832
|
|
|
833
|
+
/**
|
|
834
|
+
* A file's text as a page to read it in: escaped, so nothing in it runs or loads, in the lightbox's colours, as the
|
|
835
|
+
* browser's own text page is black on nothing and the lightbox is dark under it.
|
|
836
|
+
*/
|
|
837
|
+
function textPage(name: string, text: string): string {
|
|
838
|
+
const escape = (raw: string) => raw.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>');
|
|
839
|
+
const style =
|
|
840
|
+
':root{color-scheme:dark}body{margin:0;padding:16px;font:12px/1.5 ui-monospace,monospace;color:#e4e4e7;background:#18181b;white-space:pre-wrap;overflow-wrap:anywhere}';
|
|
841
|
+
return `<!doctype html><meta charset="utf-8"><title>${escape(name)}</title><style>${style}</style><body>${escape(text)}`;
|
|
842
|
+
}
|
|
843
|
+
|
|
515
844
|
/** What may be left out of a task as no longer kept, as `deictic.dropped.N` names it. */
|
|
516
845
|
type Kind = 'screenshot' | 'recording' | 'voice clip' | 'voice note';
|
|
517
846
|
|
|
847
|
+
/** What a task or a reply attaches: files, and what the labels say of them. */
|
|
848
|
+
type Attaching = Partial<Pick<Op, 'screenshots' | 'recordings' | 'voice' | 'annotations' | 'html' | 'pointed' | 'also'>>;
|
|
849
|
+
|
|
850
|
+
/**
|
|
851
|
+
* A message's files, as the drawer shows them: each recording with where it replays, which its
|
|
852
|
+
* `deictic.recording.N.replay` label says, the Nth being the Nth recording attached.
|
|
853
|
+
*/
|
|
854
|
+
function filesOf({ attachments, labels }: Message): Attached[] {
|
|
855
|
+
const recordings = attachments.filter((a) => a.name.startsWith('recording-'));
|
|
856
|
+
return attachments.map(({ id, name, type, size }) => {
|
|
857
|
+
const n = recordings.findIndex((r) => r.id === id);
|
|
858
|
+
const replay = n === -1 ? undefined : labels[`deictic.recording.${n + 1}.replay`];
|
|
859
|
+
return { id, name, type, size, ...(replay === undefined ? {} : { replay }) };
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
|
|
518
863
|
/**
|
|
519
864
|
* 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
865
|
* 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
|
|
866
|
+
* pixels from its top left), for one taken of the element, `.note.M` a note drawn on it. `deictic.recording.N.replay` is where the Nth recording
|
|
522
867
|
* plays back; `deictic.note.M` a note drawn on the page; `deictic.dropped.N` what wasn't kept any more;
|
|
523
868
|
* `deictic.pointed` the path to what was pointed at inside the element. A note past a label is cut.
|
|
524
869
|
*/
|
|
525
|
-
function attachedLabels(op:
|
|
870
|
+
function attachedLabels(op: Attaching, dropped: Kind[]): Record<string, string> {
|
|
526
871
|
const labels: Record<string, string> = {};
|
|
527
872
|
// A board takes no control characters in a label: a note's lines go on one.
|
|
528
873
|
const set = (key: string, value: string) => {
|
|
@@ -530,12 +875,15 @@ function attachedLabels(op: Op, dropped: Kind[]): Record<string, string> {
|
|
|
530
875
|
};
|
|
531
876
|
for (const [i, { box, marks }] of (op.screenshots ?? []).entries()) {
|
|
532
877
|
const n = `screenshot.${i + 1}`;
|
|
878
|
+
for (const [j, note] of (marks?.notes ?? []).entries()) set(`${n}.note.${j + 1}`, note);
|
|
879
|
+
// One of the window, from the tool panel, says nothing of the element: it may not be in it.
|
|
880
|
+
if (box === undefined) continue;
|
|
533
881
|
const [x, y, width, height] = boxOf(box);
|
|
534
882
|
set(`${n}.position`, `${x},${y}`);
|
|
535
883
|
set(`${n}.size`, `${width}x${height}`);
|
|
536
|
-
for (const [j, note] of (marks?.notes ?? []).entries()) set(`${n}.note.${j + 1}`, note);
|
|
537
884
|
}
|
|
538
885
|
for (const [j, note] of (op.annotations?.notes ?? []).entries()) set(`note.${j + 1}`, note);
|
|
886
|
+
for (const [i, { at, tag }] of (op.also ?? []).entries()) set(`also.${i + 1}`, `${at} <${tag}>`);
|
|
539
887
|
// Not cut: half a URL leads nowhere.
|
|
540
888
|
for (const [i, { replay }] of (op.recordings ?? []).entries()) if (replay.length <= LABEL) set(`recording.${i + 1}.replay`, replay);
|
|
541
889
|
for (const [i, kind] of dropped.entries()) set(`dropped.${i + 1}`, kind);
|
|
@@ -584,16 +932,24 @@ function nameOf(root: string): string | undefined {
|
|
|
584
932
|
* `deictic.url` is the page's whole URL, where a label holds it; `deictic.page` is its path.
|
|
585
933
|
*/
|
|
586
934
|
function labelsOf(source: Source | Refusal, target: Target, op: Op): Record<string, string> {
|
|
935
|
+
const page = {
|
|
936
|
+
'deictic.page': clip(new URL(op.page).pathname, LABEL),
|
|
937
|
+
...(op.page.length <= LABEL ? { 'deictic.url': op.page } : {}),
|
|
938
|
+
'deictic.viewport': `${op.viewport.width}x${op.viewport.height}`,
|
|
939
|
+
};
|
|
940
|
+
// With no element attached it's the page's alone: nothing of the one the popup happened to be on.
|
|
941
|
+
if (op.detached === true) return page;
|
|
587
942
|
return {
|
|
588
943
|
[AT]: atOf(target),
|
|
589
944
|
[FILE]: clip(target.loc.file, LABEL),
|
|
590
945
|
'deictic.tag': target.tag,
|
|
591
946
|
// Not where the file has no such element: the task is the page's, and goes without.
|
|
592
947
|
...(source instanceof Refusal ? {} : { 'deictic.line': clip(lineOf(source), LABEL) }),
|
|
593
|
-
|
|
594
|
-
...(op.page.length <= LABEL ? { 'deictic.url': op.page } : {}),
|
|
595
|
-
'deictic.viewport': `${op.viewport.width}x${op.viewport.height}`,
|
|
948
|
+
...page,
|
|
596
949
|
'deictic.count': String(op.count),
|
|
950
|
+
...(op.point === undefined ? {} : { [POINT]: `${Math.round(op.point.x)},${Math.round(op.point.y)}` }),
|
|
951
|
+
...(op.which === undefined ? {} : { [NTH]: String(op.which.nth) }),
|
|
952
|
+
...(op.which?.text === undefined ? {} : { [TEXT]: clip(op.which.text, LABEL) }),
|
|
597
953
|
...sourceOf(op.chain ?? []),
|
|
598
954
|
};
|
|
599
955
|
}
|
|
@@ -640,10 +996,10 @@ function placeIn(labels: Record<string, string>): Place | undefined {
|
|
|
640
996
|
}
|
|
641
997
|
|
|
642
998
|
/** The task's words: what was typed, or where nothing was, a line that sends the reader to what's attached. */
|
|
643
|
-
const wordsOf = (op: Op) => (op.text.trim() === '' ? (shown(op) ?? '') : op.text.trim());
|
|
999
|
+
const wordsOf = (op: Attaching & Pick<Op, 'text'>) => (op.text.trim() === '' ? (shown(op) ?? '') : op.text.trim());
|
|
644
1000
|
|
|
645
1001
|
/** `See the recording and the voice note`: what stands for the words of a task sent with none, where something is attached. */
|
|
646
|
-
function shown(op:
|
|
1002
|
+
function shown(op: Attaching): string | undefined {
|
|
647
1003
|
const named = (count: number | undefined, word: string) =>
|
|
648
1004
|
count === undefined || count === 0 ? [] : [`the ${word}${count === 1 ? '' : 's'}`];
|
|
649
1005
|
const attached = [
|