deictic 0.1.0 → 0.3.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 (166) hide show
  1. package/API.md +303 -0
  2. package/README.md +56 -104
  3. package/dist/annotations/index.d.ts +1 -1
  4. package/dist/astro.d.ts +1 -1
  5. package/dist/bun.d.ts +1 -1
  6. package/dist/bun.js +2 -2
  7. package/dist/client/index.d.ts +4 -2
  8. package/dist/client/index.d.ts.map +1 -1
  9. package/dist/client/index.js +130 -16
  10. package/dist/client/index.js.map +1 -1
  11. package/dist/index.d.ts +21 -218
  12. package/dist/index.js.map +1 -1
  13. package/dist/loader.js +1 -1
  14. package/dist/logs/client.d.ts +4 -0
  15. package/dist/logs/client.d.ts.map +1 -0
  16. package/dist/logs/client.js +16 -0
  17. package/dist/logs/client.js.map +1 -0
  18. package/dist/logs/index.d.ts +18 -0
  19. package/dist/logs/index.d.ts.map +1 -0
  20. package/dist/logs/index.js +21 -0
  21. package/dist/logs/index.js.map +1 -0
  22. package/dist/network/client.d.ts +4 -0
  23. package/dist/network/client.d.ts.map +1 -0
  24. package/dist/network/client.js +29 -0
  25. package/dist/network/client.js.map +1 -0
  26. package/dist/network/index.d.ts +2 -0
  27. package/dist/network/index.js +39 -0
  28. package/dist/network/index.js.map +1 -0
  29. package/dist/next.d.ts +1 -1
  30. package/dist/next.js +2 -2
  31. package/dist/recommended/index.d.ts +15 -5
  32. package/dist/recommended/index.d.ts.map +1 -1
  33. package/dist/recommended/index.js +10 -3
  34. package/dist/recommended/index.js.map +1 -1
  35. package/dist/recordings/client.d.ts +1 -1
  36. package/dist/recordings/client.d.ts.map +1 -1
  37. package/dist/recordings/client.js +177 -48
  38. package/dist/recordings/client.js.map +1 -1
  39. package/dist/recordings/index.d.ts +2 -2
  40. package/dist/recordings/index.js +3 -3
  41. package/dist/screenshots/client.d.ts +7 -1
  42. package/dist/screenshots/client.d.ts.map +1 -1
  43. package/dist/screenshots/client.js +36 -4
  44. package/dist/screenshots/client.js.map +1 -1
  45. package/dist/screenshots/dom.d.ts +1 -1
  46. package/dist/screenshots/dom.d.ts.map +1 -1
  47. package/dist/screenshots/dom.js +1 -28
  48. package/dist/screenshots/dom.js.map +1 -1
  49. package/dist/screenshots/index.d.ts +1 -1
  50. package/dist/screenshots/index.js +2 -2
  51. package/dist/screenshots/index.js.map +1 -1
  52. package/dist/screenshots/rrweb.d.ts +2 -2
  53. package/dist/screenshots/rrweb.js +5 -1
  54. package/dist/screenshots/rrweb.js.map +1 -1
  55. package/dist/{endpoints.js → shared/endpoints.js} +1 -1
  56. package/dist/shared/endpoints.js.map +1 -0
  57. package/dist/shared/index.d.ts +238 -0
  58. package/dist/shared/index.d.ts.map +1 -0
  59. package/dist/{index3.d.ts → shared/index2.d.ts} +3 -1
  60. package/dist/shared/index2.d.ts.map +1 -0
  61. package/dist/shared/index3.d.ts +112 -0
  62. package/dist/shared/index3.d.ts.map +1 -0
  63. package/dist/shared/index4.d.ts +64 -0
  64. package/dist/shared/index4.d.ts.map +1 -0
  65. package/dist/shared/index5.d.ts +220 -0
  66. package/dist/shared/index5.d.ts.map +1 -0
  67. package/dist/{index5.d.ts → shared/index6.d.ts} +2 -2
  68. package/dist/shared/index6.d.ts.map +1 -0
  69. package/dist/{integration.d.ts → shared/integration.d.ts} +4 -3
  70. package/dist/shared/integration.d.ts.map +1 -0
  71. package/dist/{integration.js → shared/integration.js} +5 -3
  72. package/dist/shared/integration.js.map +1 -0
  73. package/dist/{kept.js → shared/kept.js} +2 -2
  74. package/dist/shared/kept.js.map +1 -0
  75. package/dist/{marks.js → shared/marks.js} +6 -1
  76. package/dist/shared/marks.js.map +1 -0
  77. package/dist/shared/mask.js +107 -0
  78. package/dist/shared/mask.js.map +1 -0
  79. package/dist/{playwright.js → shared/playwright.js} +19 -4
  80. package/dist/shared/playwright.js.map +1 -0
  81. package/dist/shared/recordings.js +437 -0
  82. package/dist/shared/recordings.js.map +1 -0
  83. package/dist/shared/shortcut.js.map +1 -0
  84. package/dist/shared/tasks.js +632 -0
  85. package/dist/shared/tasks.js.map +1 -0
  86. package/dist/shared/waveform.js.map +1 -0
  87. package/dist/tailwind/client.d.ts +1 -1
  88. package/dist/tailwind/index.d.ts +1 -1
  89. package/dist/tasks/client.d.ts +1 -1
  90. package/dist/tasks/client.d.ts.map +1 -1
  91. package/dist/tasks/client.js +272 -57
  92. package/dist/tasks/client.js.map +1 -1
  93. package/dist/tasks/index.d.ts +2 -159
  94. package/dist/tasks/index.js +1 -348
  95. package/dist/vite.d.ts +11 -12
  96. package/dist/vite.d.ts.map +1 -1
  97. package/dist/vite.js +21 -4
  98. package/dist/vite.js.map +1 -1
  99. package/dist/voice/client.d.ts.map +1 -1
  100. package/dist/voice/client.js +36 -15
  101. package/dist/voice/client.js.map +1 -1
  102. package/dist/voice/index.d.ts +6 -1
  103. package/dist/voice/index.d.ts.map +1 -1
  104. package/dist/voice/index.js +13 -3
  105. package/dist/voice/index.js.map +1 -1
  106. package/dist/webpack.d.ts +1 -1
  107. package/dist/webpack.js +2 -2
  108. package/package.json +41 -2
  109. package/skills/deictic/SKILL.md +20 -14
  110. package/skills/deictic/references/install.md +32 -10
  111. package/skills/deictic/references/recordings.md +29 -0
  112. package/skills/deictic/references/tasks.md +49 -21
  113. package/skills/deictic/references/watch.md +38 -11
  114. package/skills/deictic/scripts/lib.mjs +88 -4
  115. package/skills/deictic/scripts/recording.mjs +84 -4
  116. package/skills/deictic/scripts/task.mjs +36 -7
  117. package/skills/deictic/scripts/vb.mjs +12 -0
  118. package/skills/deictic/scripts/watch.mjs +74 -10
  119. package/src/client/away.ts +105 -0
  120. package/src/client/index.ts +60 -16
  121. package/src/client/style.ts +1 -0
  122. package/src/index.ts +21 -2
  123. package/src/plugins/logs/client.ts +18 -0
  124. package/src/plugins/logs/index.ts +55 -0
  125. package/src/plugins/network/client.ts +30 -0
  126. package/src/plugins/network/index.ts +69 -0
  127. package/src/plugins/network/mask.ts +133 -0
  128. package/src/plugins/recommended/index.ts +14 -1
  129. package/src/plugins/recordings/client.ts +220 -40
  130. package/src/plugins/recordings/index.ts +111 -25
  131. package/src/plugins/recordings/marks.ts +6 -0
  132. package/src/plugins/recordings/replay.ts +159 -10
  133. package/src/plugins/screenshots/client.ts +38 -2
  134. package/src/plugins/screenshots/dom.ts +1 -32
  135. package/src/plugins/screenshots/index.ts +2 -0
  136. package/src/plugins/screenshots/playwright.ts +15 -4
  137. package/src/plugins/screenshots/rrweb.ts +2 -1
  138. package/src/plugins/tasks/client.ts +273 -41
  139. package/src/plugins/tasks/index.ts +207 -47
  140. package/src/plugins/tasks/local.ts +170 -0
  141. package/src/plugins/tasks/watchers.ts +36 -0
  142. package/src/plugins/voice/client.ts +33 -10
  143. package/src/plugins/voice/index.ts +21 -4
  144. package/src/tools/integration.ts +5 -3
  145. package/src/tools/kept.ts +2 -2
  146. package/src/vite.ts +23 -4
  147. package/dist/endpoints.js.map +0 -1
  148. package/dist/index.d.ts.map +0 -1
  149. package/dist/index2.d.ts +0 -23
  150. package/dist/index3.d.ts.map +0 -1
  151. package/dist/index4.d.ts +0 -74
  152. package/dist/index4.d.ts.map +0 -1
  153. package/dist/index5.d.ts.map +0 -1
  154. package/dist/integration.d.ts.map +0 -1
  155. package/dist/integration.js.map +0 -1
  156. package/dist/kept.js.map +0 -1
  157. package/dist/marks.js.map +0 -1
  158. package/dist/playwright.js.map +0 -1
  159. package/dist/recordings.js +0 -235
  160. package/dist/recordings.js.map +0 -1
  161. package/dist/shortcut.js.map +0 -1
  162. package/dist/tasks/index.d.ts.map +0 -1
  163. package/dist/tasks/index.js.map +0 -1
  164. package/dist/waveform.js.map +0 -1
  165. /package/dist/{shortcut.js → shared/shortcut.js} +0 -0
  166. /package/dist/{waveform.js → shared/waveform.js} +0 -0
@@ -2,15 +2,19 @@
2
2
  * `deictic/tasks`: open its tab on an element to add a task about it to a Vercel Board
3
3
  * (`@vercel/board`). The task says what to change, in the words typed, and where: the element's file,
4
4
  * line and tag, the page and the project, all as labels beside the short facts (viewport, how many, where
5
- * it is in the shot). Whatever works the board's tasks (a person, or an agent of theirs claiming them) takes it
5
+ * it is in the shot), and after the words what a label can't hold: the chain of source it rendered through, from
6
+ * its own line out to the files that use its component. Its HTML as it rendered is a file attached, `element.html`, for whoever
7
+ * 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
6
8
  * from there; deictic only adds them.
7
9
  *
8
10
  * Adding one is a change like any other: undo cancels the task, while no one has claimed it, and redo
9
- * adds it again, as a new task. Each task carries `deictic.at=<file:line:column>`, so the panel
10
- * lists the ones about the element clicked, until its line moves.
11
+ * adds it again, as a new task. Each task carries `deictic.at=<file:line:column>` and `deictic.file`, so
12
+ * the panel lists the ones about the element clicked, and after them the rest of its file's. One whose
13
+ * place is no longer the element's is still its own where the tag and the line it saw (`deictic.line`) are
14
+ * the element's, and that line is in the file once: the element has moved, as lines above it changed.
11
15
  */
12
16
  import { readFileSync } from 'node:fs';
13
- import { join } from 'node:path';
17
+ import { join, relative } from 'node:path';
14
18
 
15
19
  import type { Board } from '@vercel/board';
16
20
 
@@ -20,15 +24,23 @@ import type { Recordings } from '#src/plugins/recordings/index.ts';
20
24
  import type { Box } from '#src/plugins/screenshots/index.ts';
21
25
  import type { Clips } from '#src/plugins/voice/index.ts';
22
26
 
27
+ import { type LocalBoard, localBoard } from './local.ts';
28
+ import { watchersOf } from './watchers.ts';
29
+
30
+ export { local, type LocalBoard, type LocalOptions } from './local.ts';
31
+
23
32
  /** What the plugin uses of a board: `board()` from `@vercel/board` is one. */
24
- export type TaskBoard = Pick<Board, 'tasks' | 'thread' | 'discovery' | 'upload' | 'edit'>;
33
+ export type TaskBoard = Pick<Board, 'tasks' | 'thread' | 'discovery' | 'upload' | 'edit' | 'actors'>;
25
34
 
26
35
  export interface TasksOptions {
27
36
  /**
28
- * The board, as `@vercel/board`'s `board()` answers it: by default the one `BOARD_URL` names (`npx vb serve`
29
- * runs one on this machine), or your team's default board, through `vercel login`.
37
+ * The board, as `@vercel/board`'s `board()` answers it. By default the one `BOARD_URL` names, and with none,
38
+ * one of the project's own on this machine: `vb serve`, started with the dev server and stopped with it, at
39
+ * `http://127.0.0.1:4100/api/board` (or the port `.deictic/board.json` says, where that one's taken), its log
40
+ * in `.deictic/board`. For your team's board, through `vercel login`, pass `board()`. `local()`, from here, is
41
+ * that board of the project's own whatever `BOARD_URL` says, with its port, its folder and the rest as options.
30
42
  */
31
- board?: TaskBoard;
43
+ board?: TaskBoard | LocalBoard;
32
44
  /** The channel tasks go to: `deictic` by default. */
33
45
  channel?: string;
34
46
  /**
@@ -45,6 +57,13 @@ export interface TasksOptions {
45
57
  * deictic can't know.
46
58
  */
47
59
  link?: (channel: string, task?: string) => string | undefined;
60
+ /**
61
+ * Whether a task has the element's HTML as it rendered attached, as `element.html`, masked as a screenshot is
62
+ * (the screenshots plugin's masking, where it's loaded): what was on the page, for whoever can't open it as the
63
+ * person did. True by default: the Task tab has a box for it, ticked, to untick for a task that should go
64
+ * without. `false` takes the box away, where a page shows what the board shouldn't hold.
65
+ */
66
+ html?: boolean;
48
67
  /** What opens its tab directly, beside deictic's own shortcut, which opens any: none by default. */
49
68
  shortcut?: Shortcut;
50
69
  }
@@ -60,14 +79,35 @@ export interface Task {
60
79
  open: boolean;
61
80
  /** Its page on the board, when there's one to link to. */
62
81
  link?: string;
82
+ /**
83
+ * Where it was added, where that isn't the element's place: for one of `tasks`, where the element was before
84
+ * it moved; for one of `elsewhere`, the element it's about.
85
+ */
86
+ at?: Place;
87
+ }
88
+
89
+ /** A place in the element's file: a line and a column, from 1, and the tag there as the task saw it. */
90
+ export interface Place {
91
+ line: number;
92
+ column: number;
93
+ tag: string;
63
94
  }
64
95
 
65
96
  export interface Model {
66
97
  channel: string;
67
98
  /** The channel's page, when there's one to link to. */
68
99
  link?: string;
69
- /** Tasks about this element, oldest first, canceled ones left out. */
100
+ /** Tasks about this element, oldest first, canceled ones left out: also those added before it moved. */
70
101
  tasks: Task[];
102
+ /** Tasks about the file's other elements, by line, canceled ones left out: each with its `at`. */
103
+ elsewhere: Task[];
104
+ /**
105
+ * Who watches the channel, by name (`claude`): the agents whose watch (the skill's `watch.mjs`) is running in
106
+ * this project, as a board can't say, and those holding a claim on one of the channel's tasks, which it can.
107
+ * Empty where none is and the board is this machine's own;
108
+ * left out where none is and the board is another, which an agent may watch from elsewhere.
109
+ */
110
+ watching?: string[];
71
111
  }
72
112
 
73
113
  /**
@@ -89,11 +129,19 @@ export interface Op {
89
129
  pointed?: { path: string; html: string };
90
130
  /** How many elements on the page come from the same place in the source. */
91
131
  count: number;
132
+ /**
133
+ * The source it rendered through, after its own place, nearest first, each a `file:line`: where the file
134
+ * before it is used. A shared component's line says nothing of which use of it this is, and these do.
135
+ */
136
+ chain?: string[];
137
+ /** The element's HTML as it rendered, to attach: cut short, and masked where the screenshots plugin is loaded. */
138
+ html?: string;
92
139
  /**
93
140
  * Shots the screenshots plugin took of it, to attach, where that plugin is loaded: each with where the
94
- * element is in it, and the marks drawn on it in the panel, where there are any.
141
+ * element is in it, whether it's `outlined` there (dashes drawn around it, in the PNG), and the marks drawn
142
+ * on it in the panel, where there are any.
95
143
  */
96
- screenshots?: { id: string; box: Box; marks?: Marks }[];
144
+ screenshots?: { id: string; box: Box; outlined?: boolean; marks?: Marks }[];
97
145
  /**
98
146
  * Recordings the recordings plugin made, to attach, where that plugin is loaded: how long each ran,
99
147
  * where it plays back, and the voice plugin's clips of the mic in it, attached too.
@@ -158,6 +206,7 @@ export interface Removed extends Added {
158
206
  export type Kept = Added | Edited | Removed;
159
207
 
160
208
  const AT = 'deictic.at';
209
+ const FILE = 'deictic.file';
161
210
  /** What parts what was typed from the rest of a task's text. */
162
211
  const REST = '\n---\n';
163
212
  const OPEN = new Set(['waiting', 'ready', 'blocked']);
@@ -165,12 +214,45 @@ const OPEN = new Set(['waiting', 'ready', 'blocked']);
165
214
  export function tasks(options: TasksOptions = {}) {
166
215
  const channel = options.channel ?? 'deictic';
167
216
  let team: Promise<TaskBoard> | undefined;
168
- // Loaded when first used, so a project that doesn't add this plugin needn't install the SDK.
169
- const boardOf = () => (team ??= options.board ? Promise.resolve(options.board) : import('@vercel/board').then((m) => m.board()));
217
+ let root: string | undefined;
218
+ const own = options.board !== undefined && 'local' in options.board ? options.board.local : undefined;
219
+ const found = async (): Promise<TaskBoard> => {
220
+ if (options.board !== undefined && !('local' in options.board)) return options.board;
221
+ // Loaded when first used, so a project that doesn't add this plugin needn't install the SDK.
222
+ const { board } = await import('@vercel/board');
223
+ if (own === undefined && process.env.BOARD_URL !== undefined) return board();
224
+
225
+ const base = root ?? process.cwd();
226
+ const { url, fresh, dir } = await localBoard(base, own);
227
+ if (fresh) {
228
+ const kept = relative(base, dir).replaceAll('\\', '/');
229
+ console.log(`deictic/tasks: tasks go to a board on this machine, ${url.replace(/\/api\/board$/, '/')} (kept in ${kept})`);
230
+ }
231
+ // `board()` takes a URL from the environment only, as it's called: so it's set for the call, and what the
232
+ // environment said is left as it was.
233
+ const before = process.env.BOARD_URL;
234
+ process.env.BOARD_URL = url;
235
+ try {
236
+ return board();
237
+ } finally {
238
+ if (before === undefined) delete process.env.BOARD_URL;
239
+ else process.env.BOARD_URL = before;
240
+ }
241
+ };
242
+ // Asked again after a failure: a board that didn't start may the next time.
243
+ const boardOf = () =>
244
+ (team ??= found().catch((e: unknown) => {
245
+ team = undefined;
246
+ throw e;
247
+ }));
170
248
  let link: Promise<string | undefined> | undefined;
171
249
  // Asked once, unless asking failed: no link is no reason to keep the panel from showing the tasks.
172
250
  const linkOf = () =>
173
- (link ??= (options.link ? Promise.resolve(options.link(channel)) : boardOf().then((b) => localPage(b, channel))).catch(() => {
251
+ (link ??= (
252
+ options.link
253
+ ? Promise.resolve(options.link(channel))
254
+ : boardOf().then((b) => (own?.inspect === false ? undefined : localPage(b, channel)))
255
+ ).catch(() => {
174
256
  link = undefined;
175
257
  return undefined;
176
258
  }));
@@ -223,7 +305,7 @@ export function tasks(options: TasksOptions = {}) {
223
305
  // Kept from `setup`, to `use` another plugin when an op asks for it.
224
306
  let context: ServerContext | undefined;
225
307
  let project = options.project;
226
- /** The screenshots and recordings to attach, uploaded to the board, or nothing when there are none. */
308
+ /** The screenshots, recordings and the element's HTML to attach, uploaded to the board, or nothing when there are none. */
227
309
  const attach = async (op: Op): Promise<string[] | undefined> => {
228
310
  // All read first, so one no longer kept uploads none.
229
311
  const files = [
@@ -242,6 +324,10 @@ export function tasks(options: TasksOptions = {}) {
242
324
  if (clip === undefined) throw new Refusal(`voice clip ${id} isn't kept any more: record it again`);
243
325
  return clip;
244
326
  }),
327
+ // Last, and a file, not the task's words: it's there to look into, and most tasks are done without it.
328
+ ...(typeof op.html !== 'string' || op.html === ''
329
+ ? []
330
+ : [{ data: new TextEncoder().encode(op.html.slice(0, HTML)), name: 'element.html', type: 'text/html' }]),
245
331
  ];
246
332
  if (files.length === 0) return undefined;
247
333
  const team = await boardOf();
@@ -251,35 +337,67 @@ export function tasks(options: TasksOptions = {}) {
251
337
  return definePlugin<Model, Change, Kept>({
252
338
  name: 'tasks',
253
339
  client: 'deictic/tasks/client',
340
+ // Only where it's turned off: the page half sends the HTML unless told not to.
341
+ ...(options.html === false ? { clientOptions: { html: false } } : {}),
254
342
  shortcut: options.shortcut,
255
343
  setup: (given) => {
256
344
  context = given;
345
+ root = given.root;
257
346
  project ??= nameOf(given.root);
347
+ // Started with the dev server, not at the first task, so whoever works the tasks can watch from the start.
348
+ // Not waited for: a failure is the first request's to tell.
349
+ void boardOf().catch(() => {});
258
350
  },
259
- read: (_source, target) =>
351
+ read: (source, target) =>
260
352
  asked(async () => {
261
- const [{ tasks: found }, page] = await Promise.all([
262
- (await boardOf()).tasks.list({ channel, label: { [AT]: atOf(target) }, state: 'all' }),
353
+ const team = await boardOf();
354
+ const labelled = (label: Record<string, string>) => team.tasks.list({ channel, label, state: 'all' });
355
+ // By place too: a task added before there was a `deictic.file` has none, and is still its element's.
356
+ const [here, inFile, page, held] = await Promise.all([
357
+ labelled({ [AT]: atOf(target) }),
358
+ labelled({ [FILE]: clip(target.loc.file, LABEL) }),
263
359
  linkOf(),
360
+ team.tasks.list({ channel, state: 'claimed' }),
264
361
  ]);
362
+ const listed = new Set(inFile.tasks.map(({ message }) => message.id));
363
+ const line = lineOf(source);
364
+ // A line the file has twice says nothing of which element a task was about.
365
+ const once = source.code.split(line).length === 2;
366
+ const tasks: Task[] = [];
367
+ const elsewhere: (Task & { at: Place })[] = [];
368
+ for (const { message } of [...here.tasks.filter((t) => !listed.has(t.message.id)), ...inFile.tasks]) {
369
+ const state = message.task?.state ?? 'ready';
370
+ if (state === 'canceled') continue;
371
+ const text = message.text.split(REST, 1)[0]!;
372
+ const to = taskLink(page, message.id);
373
+ const task = {
374
+ id: message.id,
375
+ title: text.split('\n', 1)[0]!,
376
+ text,
377
+ state,
378
+ open: OPEN.has(state),
379
+ ...(to === undefined ? {} : { link: to }),
380
+ };
381
+ const at = placeIn(message.labels);
382
+ if (at === undefined || message.labels[AT] === atOf(target)) tasks.push(task);
383
+ else if (once && at.tag === target.tag && message.labels['deictic.line'] === clip(line, LABEL)) tasks.push({ ...task, at });
384
+ else elsewhere.push({ ...task, at });
385
+ }
386
+ // An agent at work on a task is here too, though its watch may be over until the task is (`watch.mjs --once`).
387
+ const working = await agentsOf(
388
+ team,
389
+ held.tasks.flatMap(({ message }) => message.task?.claim ?? []),
390
+ );
391
+ const watching = [...new Set([...watchersOf(root ?? process.cwd(), channel), ...working])].sort();
392
+ // A board of this machine's own is watched from here or not at all.
393
+ const ours = own !== undefined || (options.board === undefined && process.env.BOARD_URL === undefined);
265
394
  return {
266
395
  channel,
267
396
  ...(page === undefined ? {} : { link: page }),
268
- tasks: found
269
- .map(({ message }) => {
270
- const text = message.text.split(REST, 1)[0]!;
271
- const state = message.task?.state ?? 'ready';
272
- const to = taskLink(page, message.id);
273
- return {
274
- id: message.id,
275
- title: text.split('\n', 1)[0]!,
276
- text,
277
- state,
278
- open: OPEN.has(state),
279
- ...(to === undefined ? {} : { link: to }),
280
- };
281
- })
282
- .filter((t) => t.state !== 'canceled'),
397
+ ...(watching.length > 0 || ours ? { watching } : {}),
398
+ tasks,
399
+ // The board's order (oldest first) among those of one place.
400
+ elsewhere: elsewhere.sort((a, b) => (a.at.line === b.at.line ? a.at.column - b.at.column : a.at.line - b.at.line)),
283
401
  };
284
402
  }),
285
403
  apply: (source, target, op) => {
@@ -313,7 +431,7 @@ export function tasks(options: TasksOptions = {}) {
313
431
  return asked(async () => {
314
432
  const attachments = await attach(op);
315
433
  return {
316
- done: await create({ channel, text: textOf(op), labels, ...(attachments === undefined ? {} : { attachments }) }),
434
+ done: await create({ channel, text: textOf(op, target), labels, ...(attachments === undefined ? {} : { attachments }) }),
317
435
  };
318
436
  });
319
437
  },
@@ -398,27 +516,42 @@ const clock = (ms: number) => {
398
516
  };
399
517
 
400
518
  /**
401
- * What was drawn on each shot, and with several, where the element is in each: nothing marks it there. One
402
- * shot's place is the `deictic.position` and `deictic.size` labels, so a shot with no marks has no line.
519
+ * What's drawn on each shot (the element's outline, the person's marks), and with several, where the element is
520
+ * in each. One shot's place is the `deictic.position` and `deictic.size` labels, so a shot with nothing drawn
521
+ * on it has no line.
403
522
  */
404
523
  function shotsOf(shots: NonNullable<Op['screenshots']>): string[] {
405
524
  const [only] = shots;
406
525
  if (shots.length === 1 && only !== undefined) {
407
- const { marks } = only;
408
- return marks === undefined || marks.count === 0
409
- ? []
410
- : [`The screenshot has ${plural(marks.count, 'mark')} drawn on it${said(marks.notes)}`];
526
+ const { marks, outlined } = only;
527
+ const has = [
528
+ ...(outlined === true ? ['the element outlined in dashes'] : []),
529
+ ...(marks === undefined || marks.count === 0 ? [] : [`${plural(marks.count, 'mark')} drawn on it${said(marks.notes)}`]),
530
+ ];
531
+ return has.length === 0 ? [] : [`The screenshot has ${has.join(' and ')}`];
411
532
  }
412
- return shots.map(({ box, marks }, i) => {
533
+ return shots.map(({ box, marks, outlined }, i) => {
413
534
  const drawn = marks === undefined || marks.count === 0 ? '' : `, with ${plural(marks.count, 'mark')} drawn on it${said(marks.notes)}`;
414
535
  const [x, y, width, height] = boxOf(box);
415
- return `In screenshot ${i + 1} at x ${x}, y ${y}, ${width}×${height}${drawn}`;
536
+ return `In screenshot ${i + 1} at x ${x}, y ${y}, ${width}×${height}${outlined === true ? ', outlined in dashes' : ''}${drawn}`;
416
537
  });
417
538
  }
418
539
 
540
+ /** `Source: src/ui/label.tsx:6 ← src/Field.tsx:20 ← src/Panel.tsx:880`: from the element's line out, as the page said it. */
541
+ function chainOf({ loc }: Target, chain: NonNullable<Op['chain']>): string[] {
542
+ const places = chain.slice(0, CHAIN).map((place) => clip(String(place), LABEL));
543
+ return places.length === 0 ? [] : [`Source: ${[`${loc.file}:${loc.line}`, ...places].join(' ← ')}`];
544
+ }
545
+
546
+ /** How many places a chain names after the element's own: the first few say which use of a component it is. */
547
+ const CHAIN = 5;
548
+
419
549
  /** A box as `x,y,width,height`, in whole CSS pixels from the shot's top left. */
420
550
  const boxOf = ({ x, y, width, height }: Box) => [x, y, width, height].map(Math.round);
421
551
 
552
+ /** What `element.html` holds of an element at most, in characters: a table's rows, not a whole page. */
553
+ const HTML = 100_000;
554
+
422
555
  /** A label's value: a board holds 256 characters. */
423
556
  const LABEL = 256;
424
557
 
@@ -441,8 +574,9 @@ function labelsOf({ code, element }: Source, target: Target, op: Op): Record<str
441
574
  const [shot] = op.screenshots ?? [];
442
575
  return {
443
576
  [AT]: atOf(target),
577
+ [FILE]: clip(target.loc.file, LABEL),
444
578
  'deictic.tag': target.tag,
445
- 'deictic.line': clip(code.slice(element.start, element.end).split('\n', 1)[0]!.trim(), LABEL),
579
+ 'deictic.line': clip(lineOf({ code, element }), LABEL),
446
580
  'deictic.page': clip(new URL(op.page).pathname, LABEL),
447
581
  ...(op.page.length <= LABEL ? { 'deictic.url': op.page } : {}),
448
582
  'deictic.viewport': `${op.viewport.width}x${op.viewport.height}`,
@@ -457,19 +591,45 @@ function placeOf(box: Box): Record<string, string> {
457
591
  return { 'deictic.position': `${x},${y}`, 'deictic.size': `${width}x${height}` };
458
592
  }
459
593
 
594
+ /**
595
+ * The agents holding these claims, by name, while their leases run. An actor's ID isn't read for it (each board
596
+ * writes them its own way), so the board is asked who they are, and only when a claim is held. A person holding
597
+ * one is left out: they needn't be told they're there. (Whatever else holds one works tasks: an agent, a workflow.)
598
+ */
599
+ async function agentsOf(team: TaskBoard, claims: { actor: string; until: string }[]): Promise<string[]> {
600
+ const holders = new Set(claims.filter((claim) => Date.parse(claim.until) > Date.now()).map((claim) => claim.actor));
601
+ if (holders.size === 0) return [];
602
+ // By ID, which a board from 0.54 answers without listing everyone; an older one lists them all, so they're picked out here too.
603
+ return (await team.actors({ id: [...holders] }))
604
+ .filter((actor) => holders.has(actor.id) && actor.kind !== 'person')
605
+ .map((actor) => actor.name);
606
+ }
607
+
460
608
  const atOf = ({ loc }: Target) => `${loc.file}:${loc.line}:${loc.column}`;
461
609
 
610
+ /** The opening tag's first line, as written. */
611
+ const lineOf = ({ code, element }: Pick<Source, 'code' | 'element'>) => code.slice(element.start, element.end).split('\n', 1)[0]!.trim();
612
+
613
+ /** Where a task says its element is, from its labels. */
614
+ function placeIn(labels: Record<string, string>): Place | undefined {
615
+ const [, line, column] = /:(\d+):(\d+)$/.exec(labels[AT] ?? '') ?? [];
616
+ if (line === undefined || column === undefined) return undefined;
617
+ return { line: Number(line), column: Number(column), tag: labels['deictic.tag'] ?? '' };
618
+ }
619
+
462
620
  /**
463
- * The task's text: what was typed, and after a `---` only what no label holds: what's attached and drawn, what
464
- * was pointed at inside the element, and a URL too long for one. A board holds 10,000 characters.
621
+ * The task's text: what was typed, and after a `---` only what no label holds: what's attached and drawn, the
622
+ * source it rendered through, what was pointed at inside it, and a URL too long for a label.
623
+ * A board holds 10,000 characters.
465
624
  */
466
- function textOf(op: Op): string {
625
+ function textOf(op: Op, target: Target): string {
467
626
  const more = [
468
627
  ...(op.page.length <= LABEL ? [] : [op.page]),
469
628
  ...shotsOf(op.screenshots ?? []),
470
629
  ...recordingsOf(op.recordings ?? []),
471
630
  ...voicesOf(op.voice ?? []),
472
631
  ...(op.annotations === undefined ? [] : [annotated(op.annotations, op.screenshots?.length ?? 0, op.recordings?.length ?? 0)]),
632
+ ...chainOf(target, op.chain ?? []),
473
633
  ...(op.pointed === undefined ? [] : [`Pointed at, inside it: \`${op.pointed.path}\``, fence(op.pointed.html, 'html')]),
474
634
  ];
475
635
  const tail = more.length === 0 ? '' : REST + more.join('\n');
@@ -504,7 +664,7 @@ async function asked<T>(ask: () => Promise<T>): Promise<T> {
504
664
  const { code, message, hint } = e as { code?: unknown; message?: string; hint?: string };
505
665
  if (typeof code === 'string') throw new Refusal(`the board says: ${message}${hint === undefined ? '' : ` (${hint})`}`, { cause: e });
506
666
  throw new Refusal(
507
- `can't reach the board (${message ?? String(e)}): run \`npx vb serve\` and set BOARD_URL for the dev server, or \`vercel login\``,
667
+ `can't reach the board (${message ?? String(e)}): restart the dev server, which starts its own, or check the BOARD_URL or \`board\` it was given`,
508
668
  { cause: e },
509
669
  );
510
670
  }
@@ -0,0 +1,170 @@
1
+ /**
2
+ * The board tasks go to when nothing names one: `vb serve`, `@vercel/board`'s own, started with the dev server
3
+ * and stopped with it, its log in `.deictic/board`. So Alt-click adds a task with nothing else to run, and
4
+ * whoever works the tasks reaches the same board at the URL `.deictic/board.json` holds.
5
+ */
6
+ import { type ChildProcess, spawn } from 'node:child_process';
7
+ import { readFileSync, writeFileSync } from 'node:fs';
8
+ import { createRequire } from 'node:module';
9
+ import { createServer } from 'node:net';
10
+ import { dirname, join, resolve } from 'node:path';
11
+
12
+ import { keptIn } from '#src/tools/kept.ts';
13
+
14
+ /** `vb serve`'s own default, so `http://127.0.0.1:4100/api/board` is the board wherever it's free. */
15
+ const PORT = 4100;
16
+ /** How long a board may take to answer after it's started, or to be gone after it's stopped. */
17
+ const PATIENCE = 20_000;
18
+
19
+ export interface LocalOptions {
20
+ /**
21
+ * The port it listens on, on 127.0.0.1. By default 4100, or a free one where that's taken. One named here is
22
+ * the only one tried: taken, the board doesn't start.
23
+ */
24
+ port?: number;
25
+ /** Where its log is kept, from the project's root: `.deictic/board` by default. */
26
+ dir?: string;
27
+ /** `false` for no pages of the board's own (its inspector): the panel then links its tasks nowhere. */
28
+ inspect?: boolean;
29
+ /** More arguments for `vb serve`, as it takes them: `['--tailscale', 'box.tailnet.ts.net']`. */
30
+ args?: string[];
31
+ }
32
+
33
+ /** What `local()` answers, for the tasks plugin's `board` option. */
34
+ export interface LocalBoard {
35
+ local: LocalOptions;
36
+ }
37
+
38
+ /**
39
+ * The project's own board on this machine, as the tasks plugin's `board`: what it uses anyway with no
40
+ * `BOARD_URL`, here whatever the environment says, and with options.
41
+ */
42
+ export const local = (options: LocalOptions = {}): LocalBoard => ({ local: options });
43
+
44
+ /** What `.deictic/board.json` holds: the board the dev server started, for whoever works its tasks. */
45
+ export interface Running {
46
+ url: string;
47
+ pid: number;
48
+ /** The options it was started with, as one string to compare: other ones need another board. */
49
+ as: string;
50
+ }
51
+
52
+ export interface Local {
53
+ url: string;
54
+ /** Whether this call started it, rather than found it running. */
55
+ fresh: boolean;
56
+ /** Where its log is. */
57
+ dir: string;
58
+ /** Stops the board, where this call started it: one found running is left to what started it. */
59
+ stop: () => void;
60
+ }
61
+
62
+ /**
63
+ * The project's own board, started unless it's running: a dev server that restarts in its process (Vite, when
64
+ * its config changes) asks again, and so does a second dev server of the same project, and two boards mustn't
65
+ * write one log. One running with other options is stopped first, for the same reason.
66
+ */
67
+ export async function localBoard(root: string, options: LocalOptions = {}): Promise<Local> {
68
+ const file = keptIn(root, 'board.json');
69
+ const dir = options.dir === undefined ? keptIn(root, 'board') : resolve(root, options.dir);
70
+ const flags = [...(options.inspect === false ? ['--no-inspect'] : []), ...(options.args ?? [])];
71
+ const as = JSON.stringify([options.port ?? null, dir, flags]);
72
+
73
+ const running = read(file);
74
+ if (running !== undefined && alive(running.pid) && (await answers(running.url))) {
75
+ if (running.as === as) return { url: running.url, fresh: false, dir, stop: () => {} };
76
+ process.kill(running.pid);
77
+ await gone(running.url);
78
+ }
79
+
80
+ const port = options.port ?? (await free(PORT));
81
+ const url = `http://127.0.0.1:${port}/api/board`;
82
+ const child = spawn(process.execPath, [cli(), 'serve', '--port', String(port), '--no-open', '--dir', dir, ...flags], {
83
+ stdio: ['ignore', 'ignore', 'pipe'],
84
+ });
85
+ let said = '';
86
+ child.stderr.on('data', (chunk: Buffer) => (said += chunk.toString()));
87
+ const stop = () => void child.kill();
88
+ process.once('exit', stop);
89
+
90
+ try {
91
+ await started(child, url);
92
+ } catch (e) {
93
+ stop();
94
+ const fix = options.port === undefined ? 'set BOARD_URL to a board of your own' : `is port ${port} taken? name another, or none`;
95
+ throw new Error(`the board didn't start (${said.trim() || (e as Error).message}): ${fix}`, { cause: e });
96
+ }
97
+ writeFileSync(file, `${JSON.stringify({ url, pid: child.pid, as }, null, 2)}\n`);
98
+ // The board ends with this process, and mustn't be what keeps it from ending.
99
+ child.unref();
100
+ (child.stderr as { unref?: () => void }).unref?.();
101
+ return { url, fresh: true, dir, stop };
102
+ }
103
+
104
+ /** `vb`'s script in the project's `@vercel/board`, run with this process's own runtime: no shim, no shell. */
105
+ function cli(): string {
106
+ return join(dirname(createRequire(import.meta.url).resolve('@vercel/board/package.json')), 'dist', 'cli.mjs');
107
+ }
108
+
109
+ function read(file: string): Running | undefined {
110
+ try {
111
+ const { url, pid, as } = JSON.parse(readFileSync(file, 'utf8')) as Partial<Running>;
112
+ return typeof url === 'string' && typeof pid === 'number' ? { url, pid, as: as ?? '' } : undefined;
113
+ } catch {
114
+ return undefined;
115
+ }
116
+ }
117
+
118
+ function alive(pid: number): boolean {
119
+ try {
120
+ process.kill(pid, 0);
121
+ return true;
122
+ } catch {
123
+ return false;
124
+ }
125
+ }
126
+
127
+ /** Whether a board answers there: its discovery, which names its own URL. */
128
+ async function answers(url: string): Promise<boolean> {
129
+ try {
130
+ const res = await fetch(url, { signal: AbortSignal.timeout(2000) });
131
+ return res.ok && ((await res.json()) as { url?: unknown }).url === url;
132
+ } catch {
133
+ return false;
134
+ }
135
+ }
136
+
137
+ /** `wanted` where nothing listens on it (another project's board may), or else a port the system picks. */
138
+ async function free(wanted: number): Promise<number> {
139
+ const listen = (port: number) =>
140
+ new Promise<number>((done, failed) => {
141
+ const server = createServer();
142
+ server.once('error', failed);
143
+ server.listen(port, '127.0.0.1', () => {
144
+ const { port: got } = server.address() as { port: number };
145
+ server.close(() => done(got));
146
+ });
147
+ });
148
+ return listen(wanted).catch(() => listen(0));
149
+ }
150
+
151
+ const nap = () => new Promise((wake) => setTimeout(wake, 100));
152
+
153
+ /** Waits for the board to answer, or for its process to end without having. */
154
+ async function started(child: ChildProcess, url: string): Promise<void> {
155
+ let ended: string | undefined;
156
+ child.once('error', (e) => (ended = e.message));
157
+ child.once('exit', (code) => (ended ??= `exit ${code}`));
158
+ for (const until = Date.now() + PATIENCE; Date.now() < until; await nap()) {
159
+ if (ended !== undefined) throw new Error(ended);
160
+ if (await answers(url)) return;
161
+ }
162
+ throw new Error(`no answer at ${url} after ${PATIENCE / 1000}s`);
163
+ }
164
+
165
+ /** Waits for a stopped board to let go of its port and its log. */
166
+ async function gone(url: string): Promise<void> {
167
+ for (const until = Date.now() + PATIENCE; Date.now() < until; await nap()) if (!(await answers(url))) return;
168
+
169
+ throw new Error(`the board at ${url} is still running: stop it, then restart the dev server`);
170
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Who watches the channel for tasks. A board can't say (it knows who claimed a task, not who's listening), so a
3
+ * watch says it itself: the skill's `watch.mjs` keeps a file under `.deictic/watchers` while it runs, written
4
+ * again every 20 seconds, and the Task tab shows the names, so a person knows whether a task they add is taken up.
5
+ * (An agent holding a claim is one more, which the board does say: `agentsOf`, in `index.ts`.)
6
+ */
7
+ import { readdirSync, readFileSync, rmSync } from 'node:fs';
8
+ import { join } from 'node:path';
9
+
10
+ import { keptIn } from '#src/tools/kept.ts';
11
+
12
+ /** How old a watch's last word may be: three of its beats, as one killed says nothing more. */
13
+ const FRESH = 60_000;
14
+
15
+ /** The names watching `channel` from this project now, each once, in order. */
16
+ export function watchersOf(root: string, channel: string, now = Date.now()): string[] {
17
+ const dir = keptIn(root, 'watchers');
18
+ let files: string[];
19
+ try {
20
+ files = readdirSync(dir);
21
+ } catch {
22
+ return [];
23
+ }
24
+ const names = new Set<string>();
25
+ for (const file of files) {
26
+ const path = join(dir, file);
27
+ try {
28
+ const { name, channel: of, at } = JSON.parse(readFileSync(path, 'utf8')) as { name?: unknown; channel?: unknown; at?: unknown };
29
+ if (typeof at !== 'number' || now - at > FRESH) rmSync(path, { force: true });
30
+ else if (of === channel && typeof name === 'string') names.add(name);
31
+ } catch {
32
+ // Half written: whole by the next read.
33
+ }
34
+ }
35
+ return [...names].sort();
36
+ }