deictic 0.5.0 → 0.7.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.
Files changed (103) hide show
  1. package/API.md +150 -37
  2. package/README.md +4 -3
  3. package/dist/annotations/client.d.ts +1 -1
  4. package/dist/annotations/client.d.ts.map +1 -1
  5. package/dist/annotations/client.js +161 -176
  6. package/dist/annotations/client.js.map +1 -1
  7. package/dist/annotations/index.d.ts +2 -11
  8. package/dist/client/index.d.ts +7 -6
  9. package/dist/client/index.d.ts.map +1 -1
  10. package/dist/client/index.js +1007 -192
  11. package/dist/client/index.js.map +1 -1
  12. package/dist/index.d.ts +2 -2
  13. package/dist/recommended/index.d.ts +2 -2
  14. package/dist/recordings/client.d.ts.map +1 -1
  15. package/dist/recordings/client.js +82 -153
  16. package/dist/recordings/client.js.map +1 -1
  17. package/dist/screenshots/client.d.ts.map +1 -1
  18. package/dist/shared/annotations.js +3 -4
  19. package/dist/shared/annotations.js.map +1 -1
  20. package/dist/shared/board.js +1 -1
  21. package/dist/shared/client.js +45 -2
  22. package/dist/shared/client.js.map +1 -1
  23. package/dist/shared/component.js +62 -0
  24. package/dist/shared/component.js.map +1 -0
  25. package/dist/shared/dom.js +79 -0
  26. package/dist/shared/dom.js.map +1 -0
  27. package/dist/shared/drawer.js +217 -0
  28. package/dist/shared/drawer.js.map +1 -0
  29. package/dist/shared/endpoints.js +34 -8
  30. package/dist/shared/endpoints.js.map +1 -1
  31. package/dist/shared/find.js +2 -1
  32. package/dist/shared/find.js.map +1 -1
  33. package/dist/shared/index.d.ts +124 -11
  34. package/dist/shared/index.d.ts.map +1 -1
  35. package/dist/shared/index2.d.ts +9 -19
  36. package/dist/shared/index2.d.ts.map +1 -1
  37. package/dist/shared/index7.d.ts +105 -26
  38. package/dist/shared/index7.d.ts.map +1 -1
  39. package/dist/shared/index9.d.ts +1 -1
  40. package/dist/shared/init.js +12 -10
  41. package/dist/shared/init.js.map +1 -1
  42. package/dist/shared/integration.d.ts +1 -1
  43. package/dist/shared/packages.js +1 -1
  44. package/dist/shared/recording.js +31 -3
  45. package/dist/shared/recording.js.map +1 -1
  46. package/dist/shared/src.js.map +1 -1
  47. package/dist/shared/task.js +72 -21
  48. package/dist/shared/task.js.map +1 -1
  49. package/dist/shared/tasks.js +330 -166
  50. package/dist/shared/tasks.js.map +1 -1
  51. package/dist/shared/vb.js +1 -1
  52. package/dist/shared/voice2.js +6 -4
  53. package/dist/shared/voice2.js.map +1 -1
  54. package/dist/shared/watch.js +14 -14
  55. package/dist/shared/watch.js.map +1 -1
  56. package/dist/tailwind/index.js +6 -2
  57. package/dist/tailwind/index.js.map +1 -1
  58. package/dist/tasks/client.d.ts +2 -2
  59. package/dist/tasks/client.d.ts.map +1 -1
  60. package/dist/tasks/client.js +1829 -742
  61. package/dist/tasks/client.js.map +1 -1
  62. package/dist/tasks/index.d.ts +2 -2
  63. package/dist/voice/client.d.ts.map +1 -1
  64. package/dist/voice/client.js +154 -57
  65. package/dist/voice/client.js.map +1 -1
  66. package/package.json +1 -1
  67. package/skills/deictic/SKILL.md +22 -28
  68. package/src/cli/find.ts +3 -1
  69. package/src/cli/init.ts +13 -11
  70. package/src/cli/recording.ts +34 -3
  71. package/src/cli/task.ts +94 -23
  72. package/src/cli/voice.ts +9 -4
  73. package/src/cli/watch.ts +14 -13
  74. package/src/client/away.ts +3 -1
  75. package/src/client/component.ts +98 -0
  76. package/src/client/dom.ts +70 -0
  77. package/src/client/drawer.ts +258 -0
  78. package/src/client/index.ts +220 -128
  79. package/src/client/lightbox.ts +8 -8
  80. package/src/client/lighting.ts +279 -0
  81. package/src/client/style.ts +263 -44
  82. package/src/client/tools.ts +279 -0
  83. package/src/client/tooltip.ts +25 -5
  84. package/src/client/tray.ts +48 -0
  85. package/src/index.ts +121 -10
  86. package/src/plugins/annotations/client.ts +103 -129
  87. package/src/plugins/annotations/draw.ts +68 -72
  88. package/src/plugins/annotations/index.ts +12 -19
  89. package/src/plugins/recordings/client.ts +89 -167
  90. package/src/plugins/screenshots/client.ts +53 -2
  91. package/src/plugins/tailwind/index.ts +6 -2
  92. package/src/plugins/tasks/client.ts +219 -749
  93. package/src/plugins/tasks/composer.ts +797 -0
  94. package/src/plugins/tasks/drawer.ts +516 -0
  95. package/src/plugins/tasks/index.ts +459 -192
  96. package/src/plugins/tasks/pins.ts +275 -0
  97. package/src/plugins/tasks/store.ts +132 -0
  98. package/src/plugins/voice/client.ts +96 -5
  99. package/src/tools/endpoints.ts +18 -7
  100. package/src/tools/source.ts +25 -5
  101. package/skills/deictic/references/recordings.md +0 -13
  102. package/skills/deictic/references/tasks.md +0 -21
  103. package/skills/deictic/references/watch.md +0 -17
@@ -8,8 +8,7 @@ import { n as watchersOf } from "./watchers.js";
8
8
  * `deictic/tasks`: open its tab on an element to add a task about it to a Vercel Board
9
9
  * (`@vercel/board`). The task says what to change, in the words typed, and where: the element's file,
10
10
  * line and tag, the page and the project, all as labels beside the short facts (viewport, how many, where
11
- * it is in the shot), and after the words what a label can't hold: the chain of source it rendered through, from
12
- * its own line out to the files that use its component. Its HTML as it rendered is a file attached, `element.html`, for whoever
11
+ * 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
13
12
  * 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
14
13
  * from there; deictic only adds them.
15
14
  *
@@ -19,8 +18,14 @@ import { n as watchersOf } from "./watchers.js";
19
18
  * place is no longer the element's is still its own where the tag and the line it saw (`deictic.line`) are
20
19
  * the element's, and that line is in the file once: the element has moved, as lines above it changed.
21
20
  */
21
+ /** How many of the latest finished tasks the drawer lists: what an agent said as it ended one is there to read. */
22
+ const OVER = 10;
23
+ /** How many tasks a page is asked about at most: past that it has more pins than anyone reads. */
24
+ const PINNED = 500;
22
25
  const AT = "deictic.at";
23
26
  const FILE = "deictic.file";
27
+ /** `x,y`: the spot in the element a task is about, in CSS pixels from the element's top left. */
28
+ const POINT = "deictic.point";
24
29
  /** What parts what was typed from the rest of a task's text. */
25
30
  const REST = "\n---\n";
26
31
  const OPEN = /* @__PURE__ */ new Set([
@@ -66,9 +71,11 @@ function tasks(options = {}) {
66
71
  * One of this channel's tasks about an element, while it's still open: the page names it by ID, so
67
72
  * nothing else on the board is its to change, nor a task someone has taken up.
68
73
  */
74
+ /** One of deictic's: it has a place, or the page it's about where no element was attached. */
75
+ const ours = (message) => message.labels[AT] !== void 0 || message.labels["deictic.page"] !== void 0;
69
76
  const openTask = async (team, id, verb) => {
70
77
  const { message } = await team.thread(id);
71
- if (message.channel !== channel || message.labels[AT] === void 0) throw new Refusal(`#${id} isn't a task of deictic's in #${channel}: reload the page for the ones that are`);
78
+ if (message.channel !== channel || !ours(message)) throw new Refusal(`#${id} isn't a task of deictic's in #${channel}: reload the page for the ones that are`);
72
79
  const { task } = message;
73
80
  if (task !== void 0 && !OPEN.has(task.state)) throw new Refusal(`task ${id} is ${task.state}${task.claim ? ` by ${task.claim.actor}` : ""} now: ${verb} it on the board if you still mean to`);
74
81
  return message;
@@ -99,32 +106,189 @@ function tasks(options = {}) {
99
106
  id: task.id
100
107
  };
101
108
  };
109
+ /** A board's task as the panel lists it: its words, its state, who has it, and its page there. */
110
+ const taskOf = (message, actors, page) => {
111
+ const state = message.task?.state ?? "ready";
112
+ const by = actors.get(message.task?.claim?.actor ?? "")?.name;
113
+ const text = message.text.split(REST, 1)[0];
114
+ const to = taskLink(page, message.id);
115
+ const missing = Object.entries(message.labels).flatMap(([key, value]) => /^deictic\.dropped\.\d+$/.test(key) ? [value] : []);
116
+ const dropped = missing.length === 0 ? void 0 : listOf(missing);
117
+ const [, x, y] = /^(-?\d+),(-?\d+)$/.exec(message.labels[POINT] ?? "") ?? [];
118
+ const point = x === void 0 || y === void 0 ? void 0 : {
119
+ x: Number(x),
120
+ y: Number(y)
121
+ };
122
+ return {
123
+ id: message.id,
124
+ title: text.split("\n", 1)[0],
125
+ text,
126
+ state,
127
+ ...by === void 0 ? {} : { by },
128
+ open: OPEN.has(state),
129
+ ...to === void 0 ? {} : { link: to },
130
+ ...dropped === void 0 ? {} : { dropped },
131
+ ...point === void 0 ? {} : { point }
132
+ };
133
+ };
134
+ const listedOf = ({ message, replies, last }, actors, page) => {
135
+ const { task, labels } = message;
136
+ const said = task?.blocked?.reason ?? task?.result ?? task?.reason ?? void 0;
137
+ return {
138
+ ...taskOf(message, actors, page),
139
+ ...labels[AT] === void 0 ? {} : { place: labels[AT] },
140
+ ...labels["deictic.tag"] === void 0 ? {} : { tag: labels["deictic.tag"] },
141
+ ...labels["deictic.page"] === void 0 ? {} : { page: labels["deictic.page"] },
142
+ replies,
143
+ ...last === null ? {} : { last: last.id },
144
+ ...said === void 0 || said === "" ? {} : { said: clip(said, 2e3) }
145
+ };
146
+ };
147
+ /**
148
+ * 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
149
+ * than `PINNED`, then the `OVER` that last ended, the latest first.
150
+ */
151
+ const listed = async () => {
152
+ const team = await boardOf();
153
+ const open = [];
154
+ for (let after; open.length < PINNED;) {
155
+ const { tasks, cursor } = await team.tasks.list({
156
+ channel,
157
+ ...after === void 0 ? {} : { after }
158
+ });
159
+ open.push(...tasks);
160
+ if (tasks.length === 0 || cursor === after) break;
161
+ after = cursor;
162
+ }
163
+ const ended = await Promise.all(["completed", "failed"].map((state) => team.threads({
164
+ channel,
165
+ label: { "board.task": state },
166
+ limit: OVER
167
+ })));
168
+ const when = ({ message, last }) => (last ?? message).createdAt;
169
+ const over = ended.flatMap(({ threads }) => threads).sort((a, b) => when(b).localeCompare(when(a))).slice(0, OVER);
170
+ const about = [...open, ...over].filter(({ message }) => ours(message));
171
+ const [actors, page] = await Promise.all([actorsOf(team, about.flatMap(({ message }) => message.task?.claim?.actor ?? [])), linkOf()]);
172
+ return about.map((summary) => listedOf(summary, actors, page));
173
+ };
174
+ const replyOf = (message) => ({
175
+ id: message.id,
176
+ by: message.author?.name ?? message.by.actor,
177
+ kind: message.author?.kind ?? "unknown",
178
+ text: message.text,
179
+ at: message.createdAt,
180
+ files: filesOf(message)
181
+ });
182
+ /** A task of ours with its thread, the newest replies a board answers at once. */
183
+ const threadOf = async (id) => {
184
+ const team = await boardOf();
185
+ const { message, replies } = await team.thread(id);
186
+ if (message.channel !== channel || !ours(message)) throw new Refusal(`#${id} isn't a task of deictic's in #${channel}: reload the page for the ones that are`);
187
+ const said = replies.filter((reply) => !reply.deleted);
188
+ const [actors, page] = await Promise.all([actorsOf(team, message.task?.claim ? [message.task.claim.actor] : []), linkOf()]);
189
+ return {
190
+ task: listedOf({
191
+ message,
192
+ replies: said.length,
193
+ last: said.at(-1) ?? null
194
+ }, actors, page),
195
+ files: filesOf(message),
196
+ replies: said.map(replyOf)
197
+ };
198
+ };
199
+ /** The task a route's request names, as its last segment, and what it sent. */
200
+ const named = async (req) => {
201
+ const id = decodeURIComponent(new URL(req.url).pathname.split("/").at(-1) ?? "");
202
+ const sent = req.method === "POST" ? await req.json().catch(() => ({})) : {};
203
+ const body = typeof sent === "object" && sent !== null ? sent : {};
204
+ return {
205
+ id,
206
+ text: typeof body.text === "string" ? body.text : "",
207
+ body
208
+ };
209
+ };
210
+ /**
211
+ * A file of a task's, `file/<task>/<file>`: one attached to the task or to a reply in its thread, and to nothing
212
+ * 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
213
+ * lightbox's dark colours, so an element's HTML is read there, never run, on the dev server's origin.
214
+ */
215
+ const fileOf = async (req) => {
216
+ const [task = "", file = ""] = (new URL(req.url).pathname.split("/file/")[1] ?? "").split("/").map(decodeURIComponent);
217
+ const team = await boardOf();
218
+ const { message, replies } = await team.thread(task);
219
+ if (message.channel !== channel || !ours(message)) throw new Refusal(`#${task} isn't a task of deictic's in #${channel}: reload the page for the ones that are`);
220
+ const found = [message, ...replies].flatMap((m) => m.attachments).find((a) => a.id === file);
221
+ if (found === void 0) throw new Refusal(`task ${task} has no file ${file}: reload the page for what it has`);
222
+ const res = await team.download(found.id);
223
+ const media = /^(image|audio|video)\//.test(found.type);
224
+ const body = media ? res.body : textPage(found.name, await res.text());
225
+ return new Response(body, { headers: {
226
+ "content-type": media ? found.type : "text/html; charset=utf-8",
227
+ "content-disposition": `inline; filename="${found.name.replaceAll("\"", "")}"`,
228
+ "x-content-type-options": "nosniff",
229
+ "content-security-policy": "sandbox; default-src 'none'; style-src 'unsafe-inline'; img-src 'self' blob:; media-src 'self' blob:",
230
+ "cache-control": "private, max-age=86400, immutable"
231
+ } });
232
+ };
102
233
  let context;
103
234
  let project = options.project;
104
- /** The screenshots, recordings and the element's HTML to attach, uploaded to the board, or nothing when there are none. */
105
- const attach = async (op) => {
106
- const files = [
107
- ...(op.screenshots ?? []).map(({ id }) => {
108
- const shot = context?.use("screenshots")?.read(id);
109
- if (shot === void 0) throw new Refusal(`screenshot ${id} isn't kept any more: take it again`);
110
- return shot;
111
- }),
112
- ...(op.recordings ?? []).map(({ id }) => {
113
- const recording = context?.use("recordings")?.read(id);
114
- if (recording === void 0) throw new Refusal(`recording ${id} isn't kept any more: record it again`);
115
- return recording;
116
- }),
117
- ...[...(op.recordings ?? []).flatMap((r) => r.voice ?? []), ...(op.voice ?? []).map((v) => v.id)].map((id) => {
118
- const clip = context?.use("voice")?.read(id);
119
- if (clip === void 0) throw new Refusal(`voice clip ${id} isn't kept any more: record it again`);
120
- return clip;
121
- }),
122
- ...typeof op.html !== "string" || op.html === "" ? [] : [{
123
- data: new TextEncoder().encode(op.html.slice(0, HTML)),
124
- name: "element.html",
235
+ /**
236
+ * The op with only the screenshots, recordings and voice clips still kept, their files, and what's left out: a file
237
+ * goes once newer ones pass its plugin's `keep`, or `deictic clean` takes it, and that's no reason to lose the task.
238
+ */
239
+ const keptOf = (op) => {
240
+ const clipOf = (id) => context?.use("voice")?.read(id);
241
+ const files = [];
242
+ const dropped = [];
243
+ const take = (file, missing) => {
244
+ if (file === void 0) dropped.push(missing);
245
+ else files.push(file);
246
+ return file !== void 0;
247
+ };
248
+ const screenshots = (op.screenshots ?? []).filter(({ id }) => take(context?.use("screenshots")?.read(id), "screenshot"));
249
+ const recordings = (op.recordings ?? []).flatMap((recording) => {
250
+ const found = context?.use("recordings")?.read(recording.id);
251
+ if (!take(found, "recording")) return [];
252
+ if (recording.voice === void 0) return [recording];
253
+ const clipped = (id) => take(clipOf(id), "voice clip");
254
+ return [{
255
+ ...recording,
256
+ voice: recording.voice.filter(clipped)
257
+ }];
258
+ });
259
+ const voice = (op.voice ?? []).filter(({ id }) => take(clipOf(id), "voice note"));
260
+ const html = typeof op.html === "string" && op.html !== "" ? op.html : void 0;
261
+ if (html !== void 0) files.push({
262
+ data: new TextEncoder().encode(html.slice(0, HTML)),
263
+ name: "element.html",
264
+ type: "text/html"
265
+ });
266
+ else if (op.pointed !== void 0) files.push({
267
+ data: new TextEncoder().encode(op.pointed.html.slice(0, HTML)),
268
+ name: "pointed.html",
269
+ type: "text/html"
270
+ });
271
+ for (const [i, other] of (op.also ?? []).entries()) {
272
+ if (typeof other.html !== "string" || other.html === "") continue;
273
+ files.push({
274
+ data: new TextEncoder().encode(other.html.slice(0, HTML)),
275
+ name: `element.${i + 2}.html`,
125
276
  type: "text/html"
126
- }]
127
- ];
277
+ });
278
+ }
279
+ return {
280
+ op: {
281
+ ...op,
282
+ ...op.screenshots === void 0 ? {} : { screenshots },
283
+ ...op.recordings === void 0 ? {} : { recordings },
284
+ ...op.voice === void 0 ? {} : { voice }
285
+ },
286
+ files,
287
+ dropped
288
+ };
289
+ };
290
+ /** The files uploaded to the board, or nothing when there are none. */
291
+ const upload = async (files) => {
128
292
  if (files.length === 0) return void 0;
129
293
  const team = await boardOf();
130
294
  return Promise.all(files.map(async (file) => (await team.upload(file)).id));
@@ -141,6 +305,54 @@ function tasks(options = {}) {
141
305
  project ??= nameOf(given.root);
142
306
  boardOf().catch(() => {});
143
307
  },
308
+ routes: {
309
+ page: async () => {
310
+ const [tasks, link] = await Promise.all([asked(listed), linkOf()]);
311
+ return Response.json({
312
+ channel,
313
+ ...link === void 0 ? {} : { link },
314
+ tasks
315
+ });
316
+ },
317
+ thread: async (req) => Response.json(await asked(async () => threadOf((await named(req)).id))),
318
+ file: (req) => asked(() => fileOf(req)),
319
+ reply: (req) => asked(async () => {
320
+ const { id, text, body } = await named(req);
321
+ const answer = {
322
+ text,
323
+ ...Array.isArray(body.screenshots) ? { screenshots: body.screenshots } : {},
324
+ ...Array.isArray(body.recordings) ? { recordings: body.recordings } : {},
325
+ ...Array.isArray(body.voice) ? { voice: body.voice } : {},
326
+ ...body.annotations === void 0 ? {} : { annotations: body.annotations }
327
+ };
328
+ if (wordsOf(answer) === "") throw new Refusal("say something first");
329
+ await threadOf(id);
330
+ const { op: kept, files, dropped } = keptOf(answer);
331
+ const verb = dropped.length === 1 ? "isn't" : "aren't";
332
+ if (wordsOf(kept) === "") throw new Refusal(`${listOf(dropped)} ${verb} kept any more: attach again, or say something`);
333
+ const labels = attachedLabels(kept, dropped);
334
+ const attachments = await upload(files);
335
+ await (await boardOf()).reply(id, {
336
+ text: clip(wordsOf(kept), 1e4),
337
+ ...Object.keys(labels).length === 0 ? {} : { labels },
338
+ ...attachments === void 0 ? {} : { attachments }
339
+ });
340
+ return Response.json(await threadOf(id));
341
+ }),
342
+ edit: (req) => asked(async () => {
343
+ const { id, text } = await named(req);
344
+ if (text.trim() === "") throw new Refusal("say what should change first");
345
+ const before = (await openTask(await boardOf(), id, "edit")).text;
346
+ const rest = before.includes(REST) ? before.slice(before.indexOf(REST)) : "";
347
+ await rewrite(id, before, clip(text.trim(), 1e4 - rest.length) + rest);
348
+ return Response.json(await threadOf(id));
349
+ }),
350
+ remove: (req) => asked(async () => {
351
+ const { id } = await named(req);
352
+ await cancel(id, "deleted in deictic");
353
+ return Response.json({});
354
+ })
355
+ },
144
356
  read: (source, target) => asked(async () => {
145
357
  const team = await boardOf();
146
358
  const labelled = (label) => team.tasks.list({
@@ -158,36 +370,18 @@ function tasks(options = {}) {
158
370
  })
159
371
  ]);
160
372
  const listed = new Set(inFile.tasks.map(({ message }) => message.id));
161
- const line = lineOf(source);
162
- const once = source.code.split(line).length === 2;
373
+ const line = source instanceof Refusal ? void 0 : onceIn(source);
163
374
  const tasks = [];
164
- const elsewhere = [];
165
375
  const about = [...here.tasks.filter((t) => !listed.has(t.message.id)), ...inFile.tasks];
166
376
  const actorOf = ({ task }) => task?.claim?.actor;
167
377
  const claims = held.tasks.flatMap(({ message }) => message.task?.claim ?? []);
168
378
  const actors = await actorsOf(team, [...about.flatMap(({ message }) => actorOf(message) ?? []), ...claims.map((c) => c.actor)]);
169
379
  for (const { message } of about) {
170
- const state = message.task?.state ?? "ready";
171
- if (state === "canceled") continue;
172
- const by = actors.get(actorOf(message) ?? "")?.name;
173
- const text = message.text.split(REST, 1)[0];
174
- const to = taskLink(page, message.id);
175
- const task = {
176
- id: message.id,
177
- title: text.split("\n", 1)[0],
178
- text,
179
- state,
180
- ...by === void 0 ? {} : { by },
181
- open: OPEN.has(state),
182
- ...to === void 0 ? {} : { link: to }
183
- };
380
+ if (message.task?.state === "canceled") continue;
381
+ const task = taskOf(message, actors, page);
184
382
  const at = placeIn(message.labels);
185
383
  if (at === void 0 || message.labels[AT] === atOf(target)) tasks.push(task);
186
- else if (once && at.tag === target.tag && message.labels["deictic.line"] === clip(line, LABEL)) tasks.push({
187
- ...task,
188
- at
189
- });
190
- else elsewhere.push({
384
+ else if (line !== void 0 && at.tag === target.tag && message.labels["deictic.line"] === line) tasks.push({
191
385
  ...task,
192
386
  at
193
387
  });
@@ -199,47 +393,26 @@ function tasks(options = {}) {
199
393
  channel,
200
394
  ...page === void 0 ? {} : { link: page },
201
395
  ...watching.length > 0 || ours ? { watching } : {},
202
- tasks,
203
- elsewhere: elsewhere.sort((a, b) => a.at.line === b.at.line ? a.at.column - b.at.column : a.at.line - b.at.line)
396
+ tasks
204
397
  };
205
398
  }),
206
399
  apply: (source, target, op) => {
207
- if ("remove" in op) return asked(async () => {
208
- const message = await cancel(op.remove, "deleted in deictic");
209
- const labels = Object.fromEntries(Object.entries(message.labels).filter(([key]) => !key.startsWith("board.")));
210
- const attachments = message.attachments.map((a) => a.id);
211
- return { done: {
212
- kind: "removed",
213
- channel,
214
- id: op.remove,
215
- text: message.text,
216
- labels,
217
- ...attachments.length === 0 ? {} : { attachments }
218
- } };
219
- });
220
- if (op.text.trim() === "" && ("edit" in op || shown(op) === void 0)) throw new Refusal("say what should change first");
221
- if ("edit" in op) return asked(async () => {
222
- const before = (await openTask(await boardOf(), op.edit, "edit")).text;
223
- const rest = before.includes(REST) ? before.slice(before.indexOf(REST)) : "";
224
- const after = clip(op.text.trim(), 1e4 - rest.length) + rest;
225
- await rewrite(op.edit, before, after);
226
- return { done: {
227
- kind: "edited",
228
- id: op.edit,
229
- before,
230
- after
231
- } };
232
- });
400
+ if (op.text.trim() === "" && shown(op) === void 0) throw new Refusal("say what should change first");
401
+ const { op: kept, files, dropped } = keptOf(op);
402
+ const verb = dropped.length === 1 ? "isn't" : "aren't";
403
+ if (wordsOf(kept) === "") throw new Refusal(`${listOf(dropped)} ${verb} kept any more: attach again, or say what should change`);
233
404
  const labels = {
234
405
  ...options.labels,
235
406
  ...project === void 0 ? {} : { "deictic.project": clip(project, LABEL) },
236
- ...labelsOf(source, target, op)
407
+ ...labelsOf(source, target, kept),
408
+ ...attachedLabels(kept, dropped)
237
409
  };
238
410
  return asked(async () => {
239
- const attachments = await attach(op);
411
+ const attachments = await upload(files);
412
+ const text = clip(wordsOf(kept), 1e4);
240
413
  return { done: await create({
241
414
  channel,
242
- text: textOf(op, target),
415
+ text,
243
416
  labels,
244
417
  ...attachments === void 0 ? {} : { attachments }
245
418
  }) };
@@ -272,12 +445,7 @@ function tasks(options = {}) {
272
445
  await cancel(record.id, "deleted in deictic");
273
446
  return record;
274
447
  }),
275
- describe: (op, before) => {
276
- const named = (id) => `task "${clip(before.tasks.find((t) => t.id === id)?.title ?? `#${id}`, 60)}"`;
277
- if ("remove" in op) return `delete ${named(op.remove)}`;
278
- if ("edit" in op) return `edit ${named(op.edit)}`;
279
- return `task "${clip(wordsOf(op).split("\n", 1)[0], 60)}"`;
280
- }
448
+ describe: (op) => `task "${clip(wordsOf(op).split("\n", 1)[0], 60)}"`
281
449
  });
282
450
  }
283
451
  /**
@@ -293,58 +461,70 @@ async function localPage(team, channel) {
293
461
  ].includes(url.hostname) || !url.pathname.endsWith("/api/board")) return void 0;
294
462
  return `${url.origin}${url.pathname.slice(0, -10)}/c/${channel.split("/").map(encodeURIComponent).join("/")}`;
295
463
  }
296
- const plural = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
297
- const said = (notes) => notes.length === 0 ? "" : `; the notes say: ${notes.map((n) => JSON.stringify(n)).join(", ")}`;
298
- /** What was marked on the page: how many marks, and what the notes say. */
299
- function annotated({ count, notes }, shots, recordings) {
300
- const where = [...shots === 0 ? [] : [shots === 1 ? "the screenshot" : "the screenshots"], ...recordings === 0 ? [] : [recordings === 1 ? "the recording" : "the recordings"]];
301
- const drawn = where.length === 0 ? "" : `, drawn in ${where.join(" and ")}`;
302
- return `${plural(count, "mark")} on the page${drawn}${said(notes)}`;
303
- }
304
- /** How long each recording ran, and where it plays back, while the dev server keeps it. */
305
- function recordingsOf(recordings) {
306
- return recordings.map(({ duration, replay, voice }, i) => {
307
- const name = recordings.length === 1 ? "A recording" : `Recording ${i + 1}`;
308
- const spoken = voice === void 0 || voice.length === 0 ? "" : `, with the voice (${voice.map((id) => `voice-${id}`).join(", ")})`;
309
- return `${name}, ${clock(duration)} long, attached as rrweb events${spoken}; it replays at ${replay}`;
310
- });
464
+ /**
465
+ * 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
466
+ * browser's own text page is black on nothing and the lightbox is dark under it.
467
+ */
468
+ function textPage(name, text) {
469
+ const escape = (raw) => raw.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
470
+ return `<!doctype html><meta charset="utf-8"><title>${escape(name)}</title><style>: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}</style><body>${escape(text)}`;
311
471
  }
312
- /** How long each voice note runs, and the attachment it's in. */
313
- function voicesOf(voice) {
314
- return voice.map(({ id, duration }, i) => {
315
- return `${voice.length === 1 ? "A voice note" : `Voice note ${i + 1}`}, ${clock(duration)} long, attached as voice-${id}`;
472
+ /**
473
+ * A message's files, as the drawer shows them: each recording with where it replays, which its
474
+ * `deictic.recording.N.replay` label says, the Nth being the Nth recording attached.
475
+ */
476
+ function filesOf({ attachments, labels }) {
477
+ const recordings = attachments.filter((a) => a.name.startsWith("recording-"));
478
+ return attachments.map(({ id, name, type, size }) => {
479
+ const n = recordings.findIndex((r) => r.id === id);
480
+ const replay = n === -1 ? void 0 : labels[`deictic.recording.${n + 1}.replay`];
481
+ return {
482
+ id,
483
+ name,
484
+ type,
485
+ size,
486
+ ...replay === void 0 ? {} : { replay }
487
+ };
316
488
  });
317
489
  }
318
- const clock = (ms) => {
319
- const s = Math.round(ms / 1e3);
320
- return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
321
- };
322
490
  /**
323
- * What's drawn on each shot (the element's outline, the person's marks), and with several, where the element is
324
- * in each. One shot's place is the `deictic.position` and `deictic.size` labels, so a shot with nothing drawn
325
- * on it has no line.
491
+ * What the attached files don't say, as labels numbered from 1, so each value is short and none is read out of the
492
+ * text. `deictic.screenshot.N` is the Nth PNG attached: its `.position` and `.size` where the element is in it (CSS
493
+ * 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
494
+ * plays back; `deictic.note.M` a note drawn on the page; `deictic.dropped.N` what wasn't kept any more;
495
+ * `deictic.pointed` the path to what was pointed at inside the element. A note past a label is cut.
326
496
  */
327
- function shotsOf(shots) {
328
- const [only] = shots;
329
- if (shots.length === 1 && only !== void 0) {
330
- const { marks, outlined } = only;
331
- const has = [...outlined === true ? ["the element outlined in dashes"] : [], ...marks === void 0 || marks.count === 0 ? [] : [`${plural(marks.count, "mark")} drawn on it${said(marks.notes)}`]];
332
- return has.length === 0 ? [] : [`The screenshot has ${has.join(" and ")}`];
333
- }
334
- return shots.map(({ box, marks, outlined }, i) => {
335
- const drawn = marks === void 0 || marks.count === 0 ? "" : `, with ${plural(marks.count, "mark")} drawn on it${said(marks.notes)}`;
497
+ function attachedLabels(op, dropped) {
498
+ const labels = {};
499
+ const set = (key, value) => {
500
+ labels[`deictic.${key}`] = clip(value.replace(/\p{Cc}+/gu, " "), LABEL);
501
+ };
502
+ for (const [i, { box, marks }] of (op.screenshots ?? []).entries()) {
503
+ const n = `screenshot.${i + 1}`;
504
+ for (const [j, note] of (marks?.notes ?? []).entries()) set(`${n}.note.${j + 1}`, note);
505
+ if (box === void 0) continue;
336
506
  const [x, y, width, height] = boxOf(box);
337
- return `In screenshot ${i + 1} at x ${x}, y ${y}, ${width}×${height}${outlined === true ? ", outlined in dashes" : ""}${drawn}`;
338
- });
507
+ set(`${n}.position`, `${x},${y}`);
508
+ set(`${n}.size`, `${width}x${height}`);
509
+ }
510
+ for (const [j, note] of (op.annotations?.notes ?? []).entries()) set(`note.${j + 1}`, note);
511
+ for (const [i, { at, tag }] of (op.also ?? []).entries()) set(`also.${i + 1}`, `${at} <${tag}>`);
512
+ for (const [i, { replay }] of (op.recordings ?? []).entries()) if (replay.length <= LABEL) set(`recording.${i + 1}.replay`, replay);
513
+ for (const [i, kind] of dropped.entries()) set(`dropped.${i + 1}`, kind);
514
+ if (op.pointed !== void 0) set("pointed", op.pointed.path);
515
+ return labels;
339
516
  }
340
517
  /**
341
- * `Source: src/ui/label.tsx:6 ← Field (src/Field.tsx:20) ← Panel`: from the element's line out, as the page said
342
- * it: the components that use it, where the page knows them, or the files around it.
518
+ * `deictic.source`, `Field (src/Field.tsx:20) ← Panel`: what the element rendered through, out from its own place
519
+ * (`deictic.at`), as the page said it: the components that use it, where the page knows them, or the files around
520
+ * it. As many as a label holds, the farthest left out first.
343
521
  */
344
- function chainOf({ loc }, chain) {
345
- const places = chain.slice(0, CHAIN).map((place) => clip(String(place), LABEL));
346
- return places.length === 0 ? [] : [`Source: ${[`${loc.file}:${loc.line}`, ...places].join(" ← ")}`];
522
+ function sourceOf(chain) {
523
+ let places = chain.slice(0, CHAIN).map(String);
524
+ while (places.length > 1 && places.join(THROUGH).length > LABEL) places = places.slice(0, -1);
525
+ return places.length === 0 ? {} : { "deictic.source": clip(places.join(THROUGH), LABEL) };
347
526
  }
527
+ const THROUGH = " ← ";
348
528
  /** How many places a chain names after the element's own: the first few say which use of a component it is. */
349
529
  const CHAIN = 3;
350
530
  /** A box as `x,y,width,height`, in whole CSS pixels from the shot's top left. */
@@ -370,31 +550,24 @@ function nameOf(root) {
370
550
  /**
371
551
  * The facts about the element, as labels: short values a script reads without parsing the text, and a watch
372
552
  * filters by. `deictic.line` is the opening tag's first line as the task saw it, to tell later that it moved.
373
- * `deictic.url` is the page's whole URL, where a label holds it: `textOf` says a longer one.
553
+ * `deictic.url` is the page's whole URL, where a label holds it; `deictic.page` is its path.
374
554
  */
375
- function labelsOf({ code, element }, target, op) {
376
- const [shot] = op.screenshots ?? [];
555
+ function labelsOf(source, target, op) {
556
+ const page = {
557
+ "deictic.page": clip(new URL(op.page).pathname, LABEL),
558
+ ...op.page.length <= LABEL ? { "deictic.url": op.page } : {},
559
+ "deictic.viewport": `${op.viewport.width}x${op.viewport.height}`
560
+ };
561
+ if (op.detached === true) return page;
377
562
  return {
378
563
  [AT]: atOf(target),
379
564
  [FILE]: clip(target.loc.file, LABEL),
380
565
  "deictic.tag": target.tag,
381
- "deictic.line": clip(lineOf({
382
- code,
383
- element
384
- }), LABEL),
385
- "deictic.page": clip(new URL(op.page).pathname, LABEL),
386
- ...op.page.length <= LABEL ? { "deictic.url": op.page } : {},
387
- "deictic.viewport": `${op.viewport.width}x${op.viewport.height}`,
566
+ ...source instanceof Refusal ? {} : { "deictic.line": clip(lineOf(source), LABEL) },
567
+ ...page,
388
568
  "deictic.count": String(op.count),
389
- ...op.screenshots?.length === 1 && shot !== void 0 ? placeOf(shot.box) : {}
390
- };
391
- }
392
- /** Where the element is in the one shot, from its top left, and how big: `87,387` and `138x32`, as the viewport is written. */
393
- function placeOf(box) {
394
- const [x, y, width, height] = boxOf(box);
395
- return {
396
- "deictic.position": `${x},${y}`,
397
- "deictic.size": `${width}x${height}`
569
+ ...op.point === void 0 ? {} : { [POINT]: `${Math.round(op.point.x)},${Math.round(op.point.y)}` },
570
+ ...sourceOf(op.chain ?? [])
398
571
  };
399
572
  }
400
573
  /**
@@ -416,6 +589,11 @@ function agentsOf(actors, claims) {
416
589
  const atOf = ({ loc }) => `${loc.file}:${loc.line}:${loc.column}`;
417
590
  /** The opening tag's first line, as written. */
418
591
  const lineOf = ({ code, element }) => code.slice(element.start, element.end).split("\n", 1)[0].trim();
592
+ /** 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. */
593
+ function onceIn(source) {
594
+ const line = lineOf(source);
595
+ return source.code.split(line).length === 2 ? clip(line, LABEL) : void 0;
596
+ }
419
597
  /** Where a task says its element is, from its labels. */
420
598
  function placeIn(labels) {
421
599
  const [, line, column] = /:(\d+):(\d+)$/.exec(labels[AT] ?? "") ?? [];
@@ -426,24 +604,6 @@ function placeIn(labels) {
426
604
  tag: labels["deictic.tag"] ?? ""
427
605
  };
428
606
  }
429
- /**
430
- * The task's text: what was typed, and after a `---` only what no label holds: what's attached and drawn, the
431
- * source it rendered through, what was pointed at inside it, and a URL too long for a label.
432
- * A board holds 10,000 characters.
433
- */
434
- function textOf(op, target) {
435
- const more = [
436
- ...op.page.length <= LABEL ? [] : [op.page],
437
- ...shotsOf(op.screenshots ?? []),
438
- ...recordingsOf(op.recordings ?? []),
439
- ...voicesOf(op.voice ?? []),
440
- ...op.annotations === void 0 ? [] : [annotated(op.annotations, op.screenshots?.length ?? 0, op.recordings?.length ?? 0)],
441
- ...chainOf(target, op.chain ?? []),
442
- ...op.pointed === void 0 ? [] : [`Pointed at, inside it: \`${op.pointed.path}\``, fence(op.pointed.html, "html")]
443
- ];
444
- const tail = more.length === 0 ? "" : REST + more.join("\n");
445
- return clip(wordsOf(op), 1e4 - tail.length) + tail;
446
- }
447
607
  /** The task's words: what was typed, or where nothing was, a line that sends the reader to what's attached. */
448
608
  const wordsOf = (op) => op.text.trim() === "" ? shown(op) ?? "" : op.text.trim();
449
609
  /** `See the recording and the voice note`: what stands for the words of a task sent with none, where something is attached. */
@@ -454,9 +614,13 @@ function shown(op) {
454
614
  ...named(op.recordings?.length, "recording"),
455
615
  ...named(op.voice?.length, "voice note")
456
616
  ];
457
- return attached.length === 0 ? void 0 : `See ${new Intl.ListFormat("en", { type: "conjunction" }).format(attached)}`;
617
+ return attached.length === 0 ? void 0 : `See ${conjunction(attached)}`;
618
+ }
619
+ /** `a screenshot and 2 voice notes`, of `deictic.dropped.N`'s values. */
620
+ function listOf(kinds) {
621
+ return conjunction([...Map.groupBy(kinds, (kind) => kind)].map(([kind, all]) => all.length === 1 ? `a ${kind}` : `${all.length} ${kind}s`));
458
622
  }
459
- const fence = (text, lang) => `\`\`\`\`${lang}\n${clip(text, 1500)}\n\`\`\`\``;
623
+ const conjunction = (things) => new Intl.ListFormat("en", { type: "conjunction" }).format(things);
460
624
  const clip = (text, max) => text.length <= max ? text : `${text.slice(0, max - 1)}…`;
461
625
  /** The board's answer, or a `Refusal` saying what to do when there's no board to ask or it said no. */
462
626
  async function asked(ask) {