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.
Files changed (111) hide show
  1. package/API.md +156 -31
  2. package/README.md +6 -4
  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/bun.js +1 -1
  9. package/dist/client/index.d.ts +7 -6
  10. package/dist/client/index.d.ts.map +1 -1
  11. package/dist/client/index.js +1077 -236
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/index.d.ts +2 -2
  14. package/dist/next.js +1 -1
  15. package/dist/recommended/index.d.ts +2 -2
  16. package/dist/recordings/client.d.ts.map +1 -1
  17. package/dist/recordings/client.js +89 -154
  18. package/dist/recordings/client.js.map +1 -1
  19. package/dist/screenshots/client.d.ts.map +1 -1
  20. package/dist/shared/annotations.js +3 -4
  21. package/dist/shared/annotations.js.map +1 -1
  22. package/dist/shared/board.js +1 -1
  23. package/dist/shared/client.js +45 -2
  24. package/dist/shared/client.js.map +1 -1
  25. package/dist/shared/component.js +62 -0
  26. package/dist/shared/component.js.map +1 -0
  27. package/dist/shared/dom.js +79 -0
  28. package/dist/shared/dom.js.map +1 -0
  29. package/dist/shared/drawer.js +217 -0
  30. package/dist/shared/drawer.js.map +1 -0
  31. package/dist/shared/endpoints.js +26 -6
  32. package/dist/shared/endpoints.js.map +1 -1
  33. package/dist/shared/index.d.ts +150 -9
  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 +123 -26
  38. package/dist/shared/index7.d.ts.map +1 -1
  39. package/dist/shared/index9.d.ts +1 -1
  40. package/dist/shared/integration.d.ts +1 -1
  41. package/dist/shared/integration.js +59 -5
  42. package/dist/shared/integration.js.map +1 -1
  43. package/dist/shared/package.js +23 -0
  44. package/dist/shared/package.js.map +1 -0
  45. package/dist/shared/packages.js +14 -23
  46. package/dist/shared/packages.js.map +1 -1
  47. package/dist/shared/playwright.js +11 -3
  48. package/dist/shared/playwright.js.map +1 -1
  49. package/dist/shared/recording.js +31 -3
  50. package/dist/shared/recording.js.map +1 -1
  51. package/dist/shared/src.js.map +1 -1
  52. package/dist/shared/task.js +55 -31
  53. package/dist/shared/task.js.map +1 -1
  54. package/dist/shared/tasks.js +279 -61
  55. package/dist/shared/tasks.js.map +1 -1
  56. package/dist/shared/vb.js +1 -1
  57. package/dist/shared/voice2.js +6 -4
  58. package/dist/shared/voice2.js.map +1 -1
  59. package/dist/shared/watch.js +15 -14
  60. package/dist/shared/watch.js.map +1 -1
  61. package/dist/tailwind/index.js +7 -2
  62. package/dist/tailwind/index.js.map +1 -1
  63. package/dist/tasks/client.d.ts +2 -2
  64. package/dist/tasks/client.d.ts.map +1 -1
  65. package/dist/tasks/client.js +1870 -741
  66. package/dist/tasks/client.js.map +1 -1
  67. package/dist/tasks/index.d.ts +2 -2
  68. package/dist/voice/client.d.ts.map +1 -1
  69. package/dist/voice/client.js +154 -57
  70. package/dist/voice/client.js.map +1 -1
  71. package/dist/webpack.js +1 -1
  72. package/package.json +2 -1
  73. package/skills/deictic/SKILL.md +22 -28
  74. package/src/cli/recording.ts +34 -3
  75. package/src/cli/task.ts +78 -33
  76. package/src/cli/voice.ts +9 -4
  77. package/src/cli/watch.ts +16 -13
  78. package/src/client/away.ts +3 -1
  79. package/src/client/component.ts +98 -0
  80. package/src/client/dom.ts +70 -0
  81. package/src/client/drawer.ts +258 -0
  82. package/src/client/index.ts +290 -165
  83. package/src/client/lightbox.ts +8 -8
  84. package/src/client/lighting.ts +279 -0
  85. package/src/client/style.ts +263 -44
  86. package/src/client/tools.ts +279 -0
  87. package/src/client/tooltip.ts +25 -5
  88. package/src/client/tray.ts +48 -0
  89. package/src/index.ts +148 -8
  90. package/src/plugins/annotations/client.ts +103 -129
  91. package/src/plugins/annotations/draw.ts +68 -72
  92. package/src/plugins/annotations/index.ts +12 -19
  93. package/src/plugins/recordings/client.ts +96 -168
  94. package/src/plugins/screenshots/client.ts +53 -2
  95. package/src/plugins/screenshots/playwright.ts +8 -3
  96. package/src/plugins/tailwind/index.ts +3 -2
  97. package/src/plugins/tasks/client.ts +229 -748
  98. package/src/plugins/tasks/composer.ts +797 -0
  99. package/src/plugins/tasks/drawer.ts +516 -0
  100. package/src/plugins/tasks/index.ts +436 -80
  101. package/src/plugins/tasks/pins.ts +280 -0
  102. package/src/plugins/tasks/store.ts +132 -0
  103. package/src/plugins/tasks/which.ts +34 -0
  104. package/src/plugins/voice/client.ts +96 -5
  105. package/src/tools/endpoints.ts +31 -5
  106. package/src/tools/packages.ts +12 -4
  107. package/src/tools/plugins.ts +18 -4
  108. package/src/tools/problems.ts +60 -0
  109. package/skills/deictic/references/recordings.md +0 -13
  110. package/skills/deictic/references/tasks.md +0 -22
  111. package/skills/deictic/references/watch.md +0 -17
@@ -1,5 +1,6 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import { join, relative } from "node:path";
3
+ import { i as version, t as bugs } from "./package.js";
3
4
  import { r as definePlugin, t as Refusal } from "./src.js";
4
5
  import { r as localBoard } from "./local.js";
5
6
  import { n as watchersOf } from "./watchers.js";
@@ -18,8 +19,19 @@ import { n as watchersOf } from "./watchers.js";
18
19
  * place is no longer the element's is still its own where the tag and the line it saw (`deictic.line`) are
19
20
  * the element's, and that line is in the file once: the element has moved, as lines above it changed.
20
21
  */
22
+ /** How many of the latest finished tasks the drawer lists: what an agent said as it ended one is there to read. */
23
+ const OVER = 10;
24
+ /** How many tasks a page is asked about at most: past that it has more pins than anyone reads. */
25
+ const PINNED = 500;
21
26
  const AT = "deictic.at";
27
+ /** A problem's key, on the task that tells of it: one task per problem while it's open. */
28
+ const PROBLEM = "deictic.problem";
22
29
  const FILE = "deictic.file";
30
+ /** `x,y`: the spot in the element a task is about, in CSS pixels from the element's top left. */
31
+ const POINT = "deictic.point";
32
+ /** Which of several elements from one place it's about: `deictic.nth` from 1, `deictic.text` its text. */
33
+ const NTH = "deictic.nth";
34
+ const TEXT = "deictic.text";
23
35
  /** What parts what was typed from the rest of a task's text. */
24
36
  const REST = "\n---\n";
25
37
  const OPEN = /* @__PURE__ */ new Set([
@@ -65,9 +77,11 @@ function tasks(options = {}) {
65
77
  * One of this channel's tasks about an element, while it's still open: the page names it by ID, so
66
78
  * nothing else on the board is its to change, nor a task someone has taken up.
67
79
  */
80
+ /** One of deictic's: it has a place, or the page it's about where no element was attached. */
81
+ const ours = (message) => message.labels[AT] !== void 0 || message.labels["deictic.page"] !== void 0 || message.labels[PROBLEM] !== void 0;
68
82
  const openTask = async (team, id, verb) => {
69
83
  const { message } = await team.thread(id);
70
- 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`);
84
+ 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`);
71
85
  const { task } = message;
72
86
  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`);
73
87
  return message;
@@ -98,6 +112,139 @@ function tasks(options = {}) {
98
112
  id: task.id
99
113
  };
100
114
  };
115
+ /** A board's task as the panel lists it: its words, its state, who has it, and its page there. */
116
+ const taskOf = (message, actors, page) => {
117
+ const state = message.task?.state ?? "ready";
118
+ const by = actors.get(message.task?.claim?.actor ?? "")?.name;
119
+ const text = message.text.split(REST, 1)[0];
120
+ const to = taskLink(page, message.id);
121
+ const missing = Object.entries(message.labels).flatMap(([key, value]) => /^deictic\.dropped\.\d+$/.test(key) ? [value] : []);
122
+ const dropped = missing.length === 0 ? void 0 : listOf(missing);
123
+ const [, x, y] = /^(-?\d+),(-?\d+)$/.exec(message.labels[POINT] ?? "") ?? [];
124
+ const point = x === void 0 || y === void 0 ? void 0 : {
125
+ x: Number(x),
126
+ y: Number(y)
127
+ };
128
+ const nth = Number(message.labels[NTH]);
129
+ const said = message.labels[TEXT];
130
+ const which = Number.isInteger(nth) && nth > 0 ? {
131
+ nth,
132
+ ...said === void 0 ? {} : { text: said }
133
+ } : void 0;
134
+ return {
135
+ id: message.id,
136
+ title: text.split("\n", 1)[0],
137
+ text,
138
+ state,
139
+ ...by === void 0 ? {} : { by },
140
+ open: OPEN.has(state),
141
+ ...to === void 0 ? {} : { link: to },
142
+ ...dropped === void 0 ? {} : { dropped },
143
+ ...point === void 0 ? {} : { point },
144
+ ...which === void 0 ? {} : { which }
145
+ };
146
+ };
147
+ const listedOf = ({ message, replies, last }, actors, page) => {
148
+ const { task, labels } = message;
149
+ const said = task?.blocked?.reason ?? task?.result ?? task?.reason ?? void 0;
150
+ const problem = labels[`${PROBLEM}.kind`];
151
+ return {
152
+ ...taskOf(message, actors, page),
153
+ ...labels[AT] === void 0 ? {} : { place: labels[AT] },
154
+ ...labels["deictic.tag"] === void 0 ? {} : { tag: labels["deictic.tag"] },
155
+ ...labels["deictic.page"] === void 0 ? {} : { page: labels["deictic.page"] },
156
+ replies,
157
+ ...last === null ? {} : { last: last.id },
158
+ ...said === void 0 || said === "" ? {} : { said: clip(said, 2e3) },
159
+ ...problem === "setup" || problem === "bug" ? { problem } : {}
160
+ };
161
+ };
162
+ /**
163
+ * 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
164
+ * than `PINNED`, then the `OVER` that last ended, the latest first.
165
+ */
166
+ const listed = async () => {
167
+ const team = await boardOf();
168
+ const open = [];
169
+ for (let after; open.length < PINNED;) {
170
+ const { tasks, cursor } = await team.tasks.list({
171
+ channel,
172
+ ...after === void 0 ? {} : { after }
173
+ });
174
+ open.push(...tasks);
175
+ if (tasks.length === 0 || cursor === after) break;
176
+ after = cursor;
177
+ }
178
+ const ended = await Promise.all(["completed", "failed"].map((state) => team.threads({
179
+ channel,
180
+ label: { "board.task": state },
181
+ limit: OVER
182
+ })));
183
+ const when = ({ message, last }) => (last ?? message).createdAt;
184
+ const over = ended.flatMap(({ threads }) => threads).sort((a, b) => when(b).localeCompare(when(a))).slice(0, OVER);
185
+ const about = [...open, ...over].filter(({ message }) => ours(message));
186
+ const [actors, page] = await Promise.all([actorsOf(team, about.flatMap(({ message }) => message.task?.claim?.actor ?? [])), linkOf()]);
187
+ return about.map((summary) => listedOf(summary, actors, page));
188
+ };
189
+ const replyOf = (message) => ({
190
+ id: message.id,
191
+ by: message.author?.name ?? message.by.actor,
192
+ kind: message.author?.kind ?? "unknown",
193
+ text: message.text,
194
+ at: message.createdAt,
195
+ files: filesOf(message)
196
+ });
197
+ /** A task of ours with its thread, the newest replies a board answers at once. */
198
+ const threadOf = async (id) => {
199
+ const team = await boardOf();
200
+ const { message, replies } = await team.thread(id);
201
+ 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`);
202
+ const said = replies.filter((reply) => !reply.deleted);
203
+ const [actors, page] = await Promise.all([actorsOf(team, message.task?.claim ? [message.task.claim.actor] : []), linkOf()]);
204
+ return {
205
+ task: listedOf({
206
+ message,
207
+ replies: said.length,
208
+ last: said.at(-1) ?? null
209
+ }, actors, page),
210
+ files: filesOf(message),
211
+ replies: said.map(replyOf)
212
+ };
213
+ };
214
+ /** The task a route's request names, as its last segment, and what it sent. */
215
+ const named = async (req) => {
216
+ const id = decodeURIComponent(new URL(req.url).pathname.split("/").at(-1) ?? "");
217
+ const sent = req.method === "POST" ? await req.json().catch(() => ({})) : {};
218
+ const body = typeof sent === "object" && sent !== null ? sent : {};
219
+ return {
220
+ id,
221
+ text: typeof body.text === "string" ? body.text : "",
222
+ body
223
+ };
224
+ };
225
+ /**
226
+ * A file of a task's, `file/<task>/<file>`: one attached to the task or to a reply in its thread, and to nothing
227
+ * 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
228
+ * lightbox's dark colours, so an element's HTML is read there, never run, on the dev server's origin.
229
+ */
230
+ const fileOf = async (req) => {
231
+ const [task = "", file = ""] = (new URL(req.url).pathname.split("/file/")[1] ?? "").split("/").map(decodeURIComponent);
232
+ const team = await boardOf();
233
+ const { message, replies } = await team.thread(task);
234
+ 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`);
235
+ const found = [message, ...replies].flatMap((m) => m.attachments).find((a) => a.id === file);
236
+ if (found === void 0) throw new Refusal(`task ${task} has no file ${file}: reload the page for what it has`);
237
+ const res = await team.download(found.id);
238
+ const media = /^(image|audio|video)\//.test(found.type);
239
+ const body = media ? res.body : textPage(found.name, await res.text());
240
+ return new Response(body, { headers: {
241
+ "content-type": media ? found.type : "text/html; charset=utf-8",
242
+ "content-disposition": `inline; filename="${found.name.replaceAll("\"", "")}"`,
243
+ "x-content-type-options": "nosniff",
244
+ "content-security-policy": "sandbox; default-src 'none'; style-src 'unsafe-inline'; img-src 'self' blob:; media-src 'self' blob:",
245
+ "cache-control": "private, max-age=86400, immutable"
246
+ } });
247
+ };
101
248
  let context;
102
249
  let project = options.project;
103
250
  /**
@@ -136,6 +283,14 @@ function tasks(options = {}) {
136
283
  name: "pointed.html",
137
284
  type: "text/html"
138
285
  });
286
+ for (const [i, other] of (op.also ?? []).entries()) {
287
+ if (typeof other.html !== "string" || other.html === "") continue;
288
+ files.push({
289
+ data: new TextEncoder().encode(other.html.slice(0, HTML)),
290
+ name: `element.${i + 2}.html`,
291
+ type: "text/html"
292
+ });
293
+ }
139
294
  return {
140
295
  op: {
141
296
  ...op,
@@ -165,6 +320,54 @@ function tasks(options = {}) {
165
320
  project ??= nameOf(given.root);
166
321
  boardOf().catch(() => {});
167
322
  },
323
+ routes: {
324
+ page: async () => {
325
+ const [tasks, link] = await Promise.all([asked(listed), linkOf()]);
326
+ return Response.json({
327
+ channel,
328
+ ...link === void 0 ? {} : { link },
329
+ tasks
330
+ });
331
+ },
332
+ thread: async (req) => Response.json(await asked(async () => threadOf((await named(req)).id))),
333
+ file: (req) => asked(() => fileOf(req)),
334
+ reply: (req) => asked(async () => {
335
+ const { id, text, body } = await named(req);
336
+ const answer = {
337
+ text,
338
+ ...Array.isArray(body.screenshots) ? { screenshots: body.screenshots } : {},
339
+ ...Array.isArray(body.recordings) ? { recordings: body.recordings } : {},
340
+ ...Array.isArray(body.voice) ? { voice: body.voice } : {},
341
+ ...body.annotations === void 0 ? {} : { annotations: body.annotations }
342
+ };
343
+ if (wordsOf(answer) === "") throw new Refusal("say something first");
344
+ await threadOf(id);
345
+ const { op: kept, files, dropped } = keptOf(answer);
346
+ const verb = dropped.length === 1 ? "isn't" : "aren't";
347
+ if (wordsOf(kept) === "") throw new Refusal(`${listOf(dropped)} ${verb} kept any more: attach again, or say something`);
348
+ const labels = attachedLabels(kept, dropped);
349
+ const attachments = await upload(files);
350
+ await (await boardOf()).reply(id, {
351
+ text: clip(wordsOf(kept), 1e4),
352
+ ...Object.keys(labels).length === 0 ? {} : { labels },
353
+ ...attachments === void 0 ? {} : { attachments }
354
+ });
355
+ return Response.json(await threadOf(id));
356
+ }),
357
+ edit: (req) => asked(async () => {
358
+ const { id, text } = await named(req);
359
+ if (text.trim() === "") throw new Refusal("say what should change first");
360
+ const before = (await openTask(await boardOf(), id, "edit")).text;
361
+ const rest = before.includes(REST) ? before.slice(before.indexOf(REST)) : "";
362
+ await rewrite(id, before, clip(text.trim(), 1e4 - rest.length) + rest);
363
+ return Response.json(await threadOf(id));
364
+ }),
365
+ remove: (req) => asked(async () => {
366
+ const { id } = await named(req);
367
+ await cancel(id, "deleted in deictic");
368
+ return Response.json({});
369
+ })
370
+ },
168
371
  read: (source, target) => asked(async () => {
169
372
  const team = await boardOf();
170
373
  const labelled = (label) => team.tasks.list({
@@ -184,39 +387,19 @@ function tasks(options = {}) {
184
387
  const listed = new Set(inFile.tasks.map(({ message }) => message.id));
185
388
  const line = source instanceof Refusal ? void 0 : onceIn(source);
186
389
  const tasks = [];
187
- const elsewhere = [];
188
390
  const about = [...here.tasks.filter((t) => !listed.has(t.message.id)), ...inFile.tasks];
189
391
  const actorOf = ({ task }) => task?.claim?.actor;
190
392
  const claims = held.tasks.flatMap(({ message }) => message.task?.claim ?? []);
191
393
  const actors = await actorsOf(team, [...about.flatMap(({ message }) => actorOf(message) ?? []), ...claims.map((c) => c.actor)]);
192
394
  for (const { message } of about) {
193
- const state = message.task?.state ?? "ready";
194
- if (state === "canceled") continue;
195
- const by = actors.get(actorOf(message) ?? "")?.name;
196
- const text = message.text.split(REST, 1)[0];
197
- const to = taskLink(page, message.id);
198
- const missing = Object.entries(message.labels).flatMap(([key, value]) => /^deictic\.dropped\.\d+$/.test(key) ? [value] : []);
199
- const dropped = missing.length === 0 ? void 0 : listOf(missing);
200
- const task = {
201
- id: message.id,
202
- title: text.split("\n", 1)[0],
203
- text,
204
- state,
205
- ...by === void 0 ? {} : { by },
206
- open: OPEN.has(state),
207
- ...to === void 0 ? {} : { link: to },
208
- ...dropped === void 0 ? {} : { dropped }
209
- };
395
+ if (message.task?.state === "canceled") continue;
396
+ const task = taskOf(message, actors, page);
210
397
  const at = placeIn(message.labels);
211
398
  if (at === void 0 || message.labels[AT] === atOf(target)) tasks.push(task);
212
399
  else if (line !== void 0 && at.tag === target.tag && message.labels["deictic.line"] === line) tasks.push({
213
400
  ...task,
214
401
  at
215
402
  });
216
- else elsewhere.push({
217
- ...task,
218
- at
219
- });
220
403
  }
221
404
  const working = agentsOf(actors, claims);
222
405
  const watching = [.../* @__PURE__ */ new Set([...watchersOf(root ?? process.cwd(), channel), ...working])].sort();
@@ -225,37 +408,11 @@ function tasks(options = {}) {
225
408
  channel,
226
409
  ...page === void 0 ? {} : { link: page },
227
410
  ...watching.length > 0 || ours ? { watching } : {},
228
- tasks,
229
- elsewhere: elsewhere.sort((a, b) => a.at.line === b.at.line ? a.at.column - b.at.column : a.at.line - b.at.line)
411
+ tasks
230
412
  };
231
413
  }),
232
414
  apply: (source, target, op) => {
233
- if ("remove" in op) return asked(async () => {
234
- const message = await cancel(op.remove, "deleted in deictic");
235
- const labels = Object.fromEntries(Object.entries(message.labels).filter(([key]) => !key.startsWith("board.")));
236
- const attachments = message.attachments.map((a) => a.id);
237
- return { done: {
238
- kind: "removed",
239
- channel,
240
- id: op.remove,
241
- text: message.text,
242
- labels,
243
- ...attachments.length === 0 ? {} : { attachments }
244
- } };
245
- });
246
- if (op.text.trim() === "" && ("edit" in op || shown(op) === void 0)) throw new Refusal("say what should change first");
247
- if ("edit" in op) return asked(async () => {
248
- const before = (await openTask(await boardOf(), op.edit, "edit")).text;
249
- const rest = before.includes(REST) ? before.slice(before.indexOf(REST)) : "";
250
- const after = clip(op.text.trim(), 1e4 - rest.length) + rest;
251
- await rewrite(op.edit, before, after);
252
- return { done: {
253
- kind: "edited",
254
- id: op.edit,
255
- before,
256
- after
257
- } };
258
- });
415
+ if (op.text.trim() === "" && shown(op) === void 0) throw new Refusal("say what should change first");
259
416
  const { op: kept, files, dropped } = keptOf(op);
260
417
  const verb = dropped.length === 1 ? "isn't" : "aren't";
261
418
  if (wordsOf(kept) === "") throw new Refusal(`${listOf(dropped)} ${verb} kept any more: attach again, or say what should change`);
@@ -303,15 +460,41 @@ function tasks(options = {}) {
303
460
  await cancel(record.id, "deleted in deictic");
304
461
  return record;
305
462
  }),
306
- describe: (op, before) => {
307
- const named = (id) => `task "${clip(before.tasks.find((t) => t.id === id)?.title ?? `#${id}`, 60)}"`;
308
- if ("remove" in op) return `delete ${named(op.remove)}`;
309
- if ("edit" in op) return `edit ${named(op.edit)}`;
310
- return `task "${clip(wordsOf(op).split("\n", 1)[0], 60)}"`;
463
+ describe: (op) => `task "${clip(wordsOf(op).split("\n", 1)[0], 60)}"`,
464
+ problem: async (problem) => {
465
+ if (options.problems === false) return;
466
+ const key = clip(problem.key, LABEL);
467
+ if ((await (await boardOf()).tasks.list({
468
+ channel,
469
+ label: { [PROBLEM]: key },
470
+ limit: 1
471
+ })).tasks.length > 0) return;
472
+ await create({
473
+ channel,
474
+ text: clip(problemText(problem), 1e4),
475
+ labels: {
476
+ ...options.labels,
477
+ ...project === void 0 ? {} : { "deictic.project": clip(project, LABEL) },
478
+ [PROBLEM]: key,
479
+ [`${PROBLEM}.kind`]: problem.kind,
480
+ ...problem.plugin === void 0 ? {} : { [`${PROBLEM}.plugin`]: clip(problem.plugin, LABEL) },
481
+ "deictic.version": version
482
+ }
483
+ });
311
484
  }
312
485
  });
313
486
  }
314
487
  /**
488
+ * A problem as a task says it: what went wrong and what to do, and after the `---` its details, which `deictic task`
489
+ * prints and the drawer leaves out.
490
+ */
491
+ function problemText({ kind, message, details, plugin }) {
492
+ const whose = plugin === void 0 ? "deictic" : `deictic's ${plugin} plugin`;
493
+ const todo = kind === "setup" ? `Reported by ${whose}, about the project's setup: fix it as it says, then restart the dev server and check it's gone.` : `A bug in ${whose} (${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 ${bugs.url}), and complete the task.`;
494
+ const more = details === void 0 ? "" : `${REST}\`\`\`\n${details}\n\`\`\``;
495
+ return `${message[0].toUpperCase()}${message.slice(1)}\n\n${todo}${more}`;
496
+ }
497
+ /**
315
498
  * The channel's page on a board `vb serve` runs on this machine, which serves its pages beside its API:
316
499
  * `/api/board` there, `/c/<channel>` beside it. Nothing for any other board.
317
500
  */
@@ -325,9 +508,35 @@ async function localPage(team, channel) {
325
508
  return `${url.origin}${url.pathname.slice(0, -10)}/c/${channel.split("/").map(encodeURIComponent).join("/")}`;
326
509
  }
327
510
  /**
511
+ * 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
512
+ * browser's own text page is black on nothing and the lightbox is dark under it.
513
+ */
514
+ function textPage(name, text) {
515
+ const escape = (raw) => raw.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
516
+ 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)}`;
517
+ }
518
+ /**
519
+ * A message's files, as the drawer shows them: each recording with where it replays, which its
520
+ * `deictic.recording.N.replay` label says, the Nth being the Nth recording attached.
521
+ */
522
+ function filesOf({ attachments, labels }) {
523
+ const recordings = attachments.filter((a) => a.name.startsWith("recording-"));
524
+ return attachments.map(({ id, name, type, size }) => {
525
+ const n = recordings.findIndex((r) => r.id === id);
526
+ const replay = n === -1 ? void 0 : labels[`deictic.recording.${n + 1}.replay`];
527
+ return {
528
+ id,
529
+ name,
530
+ type,
531
+ size,
532
+ ...replay === void 0 ? {} : { replay }
533
+ };
534
+ });
535
+ }
536
+ /**
328
537
  * What the attached files don't say, as labels numbered from 1, so each value is short and none is read out of the
329
538
  * text. `deictic.screenshot.N` is the Nth PNG attached: its `.position` and `.size` where the element is in it (CSS
330
- * pixels from its top left), `.note.M` a note drawn on it. `deictic.recording.N.replay` is where the Nth recording
539
+ * 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
331
540
  * plays back; `deictic.note.M` a note drawn on the page; `deictic.dropped.N` what wasn't kept any more;
332
541
  * `deictic.pointed` the path to what was pointed at inside the element. A note past a label is cut.
333
542
  */
@@ -338,12 +547,14 @@ function attachedLabels(op, dropped) {
338
547
  };
339
548
  for (const [i, { box, marks }] of (op.screenshots ?? []).entries()) {
340
549
  const n = `screenshot.${i + 1}`;
550
+ for (const [j, note] of (marks?.notes ?? []).entries()) set(`${n}.note.${j + 1}`, note);
551
+ if (box === void 0) continue;
341
552
  const [x, y, width, height] = boxOf(box);
342
553
  set(`${n}.position`, `${x},${y}`);
343
554
  set(`${n}.size`, `${width}x${height}`);
344
- for (const [j, note] of (marks?.notes ?? []).entries()) set(`${n}.note.${j + 1}`, note);
345
555
  }
346
556
  for (const [j, note] of (op.annotations?.notes ?? []).entries()) set(`note.${j + 1}`, note);
557
+ for (const [i, { at, tag }] of (op.also ?? []).entries()) set(`also.${i + 1}`, `${at} <${tag}>`);
347
558
  for (const [i, { replay }] of (op.recordings ?? []).entries()) if (replay.length <= LABEL) set(`recording.${i + 1}.replay`, replay);
348
559
  for (const [i, kind] of dropped.entries()) set(`dropped.${i + 1}`, kind);
349
560
  if (op.pointed !== void 0) set("pointed", op.pointed.path);
@@ -388,15 +599,22 @@ function nameOf(root) {
388
599
  * `deictic.url` is the page's whole URL, where a label holds it; `deictic.page` is its path.
389
600
  */
390
601
  function labelsOf(source, target, op) {
602
+ const page = {
603
+ "deictic.page": clip(new URL(op.page).pathname, LABEL),
604
+ ...op.page.length <= LABEL ? { "deictic.url": op.page } : {},
605
+ "deictic.viewport": `${op.viewport.width}x${op.viewport.height}`
606
+ };
607
+ if (op.detached === true) return page;
391
608
  return {
392
609
  [AT]: atOf(target),
393
610
  [FILE]: clip(target.loc.file, LABEL),
394
611
  "deictic.tag": target.tag,
395
612
  ...source instanceof Refusal ? {} : { "deictic.line": clip(lineOf(source), LABEL) },
396
- "deictic.page": clip(new URL(op.page).pathname, LABEL),
397
- ...op.page.length <= LABEL ? { "deictic.url": op.page } : {},
398
- "deictic.viewport": `${op.viewport.width}x${op.viewport.height}`,
613
+ ...page,
399
614
  "deictic.count": String(op.count),
615
+ ...op.point === void 0 ? {} : { [POINT]: `${Math.round(op.point.x)},${Math.round(op.point.y)}` },
616
+ ...op.which === void 0 ? {} : { [NTH]: String(op.which.nth) },
617
+ ...op.which?.text === void 0 ? {} : { [TEXT]: clip(op.which.text, LABEL) },
400
618
  ...sourceOf(op.chain ?? [])
401
619
  };
402
620
  }