deictic 0.3.0 → 0.4.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 (175) hide show
  1. package/API.md +31 -19
  2. package/README.md +6 -26
  3. package/dist/annotations/client.d.ts +1 -1
  4. package/dist/annotations/client.js +1 -1
  5. package/dist/annotations/index.d.ts +2 -101
  6. package/dist/annotations/index.js +1 -22
  7. package/dist/astro.d.ts +1 -1
  8. package/dist/astro.js +1 -1
  9. package/dist/cli.d.ts +1 -0
  10. package/dist/cli.js +37 -0
  11. package/dist/cli.js.map +1 -0
  12. package/dist/index.js +1 -10
  13. package/dist/logs/client.d.ts +1 -1
  14. package/dist/logs/client.js +1 -1
  15. package/dist/logs/index.d.ts +2 -18
  16. package/dist/logs/index.js +1 -21
  17. package/dist/network/client.d.ts +1 -1
  18. package/dist/network/client.js +1 -1
  19. package/dist/network/index.d.ts +1 -1
  20. package/dist/network/index.js +1 -37
  21. package/dist/recommended/index.d.ts +7 -7
  22. package/dist/recommended/index.js +1 -26
  23. package/dist/recordings/client.d.ts +1 -1
  24. package/dist/recordings/client.js +1 -1
  25. package/dist/recordings/index.d.ts +1 -1
  26. package/dist/screenshots/client.d.ts +1 -1
  27. package/dist/screenshots/client.js +1 -108
  28. package/dist/screenshots/dom.d.ts +1 -1
  29. package/dist/screenshots/dom.js +1 -1
  30. package/dist/screenshots/index.d.ts +1 -1
  31. package/dist/screenshots/index.js +1 -98
  32. package/dist/screenshots/rrweb.d.ts +2 -1
  33. package/dist/screenshots/rrweb.d.ts.map +1 -1
  34. package/dist/screenshots/rrweb.js +6 -2
  35. package/dist/screenshots/rrweb.js.map +1 -1
  36. package/dist/shared/annotations.js +22 -0
  37. package/dist/shared/annotations.js.map +1 -0
  38. package/dist/shared/board.js +190 -0
  39. package/dist/shared/board.js.map +1 -0
  40. package/dist/shared/client.js +108 -0
  41. package/dist/{screenshots → shared}/client.js.map +1 -1
  42. package/dist/shared/endpoints.js +4 -1
  43. package/dist/shared/endpoints.js.map +1 -1
  44. package/dist/shared/find.js +156 -0
  45. package/dist/shared/find.js.map +1 -0
  46. package/dist/shared/frame.js +75 -0
  47. package/dist/shared/frame.js.map +1 -0
  48. package/dist/shared/index.d.ts +5 -0
  49. package/dist/shared/index.d.ts.map +1 -1
  50. package/dist/shared/index2.d.ts +85 -84
  51. package/dist/shared/index2.d.ts.map +1 -1
  52. package/dist/shared/index3.d.ts +83 -89
  53. package/dist/shared/index3.d.ts.map +1 -1
  54. package/dist/shared/index4.d.ts +98 -50
  55. package/dist/shared/index4.d.ts.map +1 -1
  56. package/dist/shared/index5.d.ts +13 -215
  57. package/dist/shared/index5.d.ts.map +1 -1
  58. package/dist/shared/index6.d.ts +55 -61
  59. package/dist/shared/index6.d.ts.map +1 -1
  60. package/dist/shared/index7.d.ts +224 -0
  61. package/dist/shared/index7.d.ts.map +1 -0
  62. package/dist/shared/index8.d.ts +52 -0
  63. package/dist/shared/index8.d.ts.map +1 -0
  64. package/dist/shared/index9.d.ts +70 -0
  65. package/dist/shared/index9.d.ts.map +1 -0
  66. package/dist/shared/init.js +472 -0
  67. package/dist/shared/init.js.map +1 -0
  68. package/dist/shared/local.js +165 -0
  69. package/dist/shared/local.js.map +1 -0
  70. package/dist/shared/logs.js +22 -0
  71. package/dist/shared/logs.js.map +1 -0
  72. package/dist/shared/network.js +39 -0
  73. package/dist/shared/network.js.map +1 -0
  74. package/dist/shared/packages.js +125 -0
  75. package/dist/shared/packages.js.map +1 -0
  76. package/dist/shared/playwright.js +36 -9
  77. package/dist/shared/playwright.js.map +1 -1
  78. package/dist/shared/recommended.js +26 -0
  79. package/dist/shared/recommended.js.map +1 -0
  80. package/dist/shared/recording.js +316 -0
  81. package/dist/shared/recording.js.map +1 -0
  82. package/dist/shared/recordings.js +2 -1
  83. package/dist/shared/recordings.js.map +1 -1
  84. package/dist/shared/screenshots.js +108 -0
  85. package/dist/shared/screenshots.js.map +1 -0
  86. package/dist/shared/src.js +10 -0
  87. package/dist/shared/src.js.map +1 -0
  88. package/dist/shared/task.js +108 -0
  89. package/dist/shared/task.js.map +1 -0
  90. package/dist/shared/tasks.js +33 -191
  91. package/dist/shared/tasks.js.map +1 -1
  92. package/dist/shared/transcribe.js +128 -0
  93. package/dist/shared/transcribe.js.map +1 -0
  94. package/dist/shared/vb.js +13 -0
  95. package/dist/shared/vb.js.map +1 -0
  96. package/dist/shared/vite.d.ts +16 -0
  97. package/dist/shared/vite.d.ts.map +1 -0
  98. package/dist/shared/vite.js +61 -0
  99. package/dist/shared/vite.js.map +1 -0
  100. package/dist/shared/voice.js +84 -0
  101. package/dist/{voice/index.js.map → shared/voice.js.map} +1 -1
  102. package/dist/shared/voice2.js +90 -0
  103. package/dist/shared/voice2.js.map +1 -0
  104. package/dist/shared/watch.js +209 -0
  105. package/dist/shared/watch.js.map +1 -0
  106. package/dist/shared/watchers.js +62 -0
  107. package/dist/shared/watchers.js.map +1 -0
  108. package/dist/tailwind/client.d.ts +1 -1
  109. package/dist/tailwind/client.js +1 -1
  110. package/dist/tailwind/index.d.ts +1 -1
  111. package/dist/tailwind/index.js +1 -1
  112. package/dist/tasks/client.d.ts +1 -1
  113. package/dist/tasks/client.d.ts.map +1 -1
  114. package/dist/tasks/client.js +45 -8
  115. package/dist/tasks/client.js.map +1 -1
  116. package/dist/tasks/index.d.ts +1 -1
  117. package/dist/tasks/index.js +3 -1
  118. package/dist/vite.d.ts +2 -15
  119. package/dist/vite.js +2 -60
  120. package/dist/voice/client.d.ts +1 -1
  121. package/dist/voice/client.js +1 -1
  122. package/dist/voice/index.d.ts +2 -52
  123. package/dist/voice/index.js +1 -84
  124. package/package.json +6 -9
  125. package/skills/deictic/SKILL.md +27 -42
  126. package/skills/deictic/references/recordings.md +9 -108
  127. package/skills/deictic/references/tasks.md +21 -107
  128. package/skills/deictic/references/watch.md +13 -66
  129. package/src/cli/board.ts +204 -0
  130. package/src/cli/bun.ts +133 -0
  131. package/src/cli/edit.ts +56 -0
  132. package/src/cli/find.ts +147 -0
  133. package/src/cli/frame.ts +90 -0
  134. package/src/cli/init.ts +388 -0
  135. package/src/cli/recording.ts +383 -0
  136. package/src/cli/task.ts +126 -0
  137. package/src/cli/transcribe.ts +129 -0
  138. package/src/cli/vb.ts +11 -0
  139. package/src/cli/voice.ts +59 -0
  140. package/src/cli/watch.ts +221 -0
  141. package/src/cli.ts +37 -0
  142. package/src/index.ts +5 -0
  143. package/src/plugins/logs/index.ts +1 -0
  144. package/src/plugins/network/index.ts +1 -0
  145. package/src/plugins/recordings/index.ts +1 -0
  146. package/src/plugins/screenshots/client.ts +3 -2
  147. package/src/plugins/screenshots/index.ts +10 -3
  148. package/src/plugins/screenshots/playwright.ts +34 -7
  149. package/src/plugins/screenshots/rrweb.ts +5 -1
  150. package/src/plugins/tasks/client.ts +62 -7
  151. package/src/plugins/tasks/index.ts +41 -20
  152. package/src/plugins/tasks/local.ts +19 -6
  153. package/src/plugins/tasks/watchers.ts +41 -6
  154. package/src/tools/endpoints.ts +3 -0
  155. package/src/tools/packages.ts +107 -0
  156. package/dist/annotations/index.d.ts.map +0 -1
  157. package/dist/annotations/index.js.map +0 -1
  158. package/dist/index.js.map +0 -1
  159. package/dist/logs/index.d.ts.map +0 -1
  160. package/dist/logs/index.js.map +0 -1
  161. package/dist/network/index.js.map +0 -1
  162. package/dist/recommended/index.js.map +0 -1
  163. package/dist/screenshots/index.js.map +0 -1
  164. package/dist/vite.d.ts.map +0 -1
  165. package/dist/vite.js.map +0 -1
  166. package/dist/voice/index.d.ts.map +0 -1
  167. package/skills/deictic/references/install.md +0 -103
  168. package/skills/deictic/scripts/frame.mjs +0 -62
  169. package/skills/deictic/scripts/lib.mjs +0 -277
  170. package/skills/deictic/scripts/recording.mjs +0 -266
  171. package/skills/deictic/scripts/task.mjs +0 -113
  172. package/skills/deictic/scripts/transcribe.mjs +0 -93
  173. package/skills/deictic/scripts/vb.mjs +0 -12
  174. package/skills/deictic/scripts/voice.mjs +0 -50
  175. package/skills/deictic/scripts/watch.mjs +0 -115
@@ -1,108 +1 @@
1
- import { defineClientPlugin } from "../index.js";
2
- // src/plugins/screenshots/client.ts
3
- /**
4
- * The screenshots plugin's page half, around a renderer's capture: the renderer makes the shot (a PNG,
5
- * or what its server half makes one of), and this sends it to the plugin's `add` route and answers the
6
- * `Shot`. A renderer's page module default-exports `screenshotsClient(itsCapture)`.
7
- */
8
- /** Leaves out deictic's own UI: the overlay with its hover outline and any open panel. */
9
- const notOurs = (node) => !(node instanceof Element && node.localName === "deictic-overlay");
10
- /** The element's box, in CSS pixels from the viewport's top left, or from its own for a shot of it alone. */
11
- function boxOf(element, area) {
12
- const { x, y, width, height } = element.getBoundingClientRect();
13
- return area === "element" ? {
14
- x: 0,
15
- y: 0,
16
- width,
17
- height
18
- } : {
19
- x,
20
- y,
21
- width,
22
- height
23
- };
24
- }
25
- const BLANK = "#d4d4d8";
26
- const selector = (className, extra) => [`.${CSS.escape(className)}`, ...extra ? [extra] : []].join(", ");
27
- /**
28
- * Hides in a copy of the page's what rrweb would: blocked elements become a blank box their size (the copy keeps each
29
- * element's size as its styles), masked text keeps its spaces but shows `*`, and so do passwords' values,
30
- * or every field's.
31
- */
32
- function mask(copy, m) {
33
- if (!(copy instanceof Element)) return;
34
- const all = (sel) => [...copy.matches(sel) ? [copy] : [], ...copy.querySelectorAll(sel)];
35
- const stars = (text) => text.replace(/\S/g, "*");
36
- for (const el of all(selector(m.blockClass, m.blockSelector))) {
37
- el.replaceChildren();
38
- if (el instanceof HTMLElement || el instanceof SVGElement) el.style.background = BLANK;
39
- }
40
- for (const el of all(selector(m.maskTextClass, m.maskTextSelector))) {
41
- const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
42
- for (let text = walker.nextNode(); text !== null; text = walker.nextNode()) text.textContent = stars(text.textContent ?? "");
43
- }
44
- for (const field of all("input, textarea")) {
45
- if (!(field instanceof HTMLInputElement || field instanceof HTMLTextAreaElement)) continue;
46
- if (!m.maskAllInputs && !(field instanceof HTMLInputElement && field.type === "password")) continue;
47
- field.value = stars(field.value);
48
- field.setAttribute("value", field.value);
49
- if (field instanceof HTMLTextAreaElement) field.textContent = field.value;
50
- }
51
- }
52
- function screenshotsClient(capture) {
53
- return defineClientPlugin({
54
- name: "screenshots",
55
- setup: ({ base, request, options, use }) => {
56
- const { masking, renderer } = options;
57
- const overlay = (area) => {
58
- return use("annotations")?.svg(area);
59
- };
60
- const add = async (body, type, { box, size }) => {
61
- const res = await request("add", {
62
- method: "POST",
63
- headers: { "content-type": type },
64
- body
65
- });
66
- const { id, url, problem } = await res.json();
67
- if (id === void 0) throw new Error(`screenshots: ${problem ?? res.statusText}`);
68
- return {
69
- id,
70
- url: url ?? `${base}__deictic/plugins/screenshots/shot/${id}`,
71
- box,
72
- size
73
- };
74
- };
75
- return {
76
- capture: async (element, { area = "viewport" } = {}) => {
77
- const { body, type, box } = await capture(element, {
78
- area,
79
- masking,
80
- renderer,
81
- overlay
82
- });
83
- const { clientWidth, clientHeight } = document.documentElement;
84
- const size = area === "element" ? {
85
- width: box.width,
86
- height: box.height
87
- } : {
88
- width: clientWidth,
89
- height: clientHeight
90
- };
91
- return add(body, type, {
92
- box,
93
- size
94
- });
95
- },
96
- upload: (png, of) => add(png, "image/png", of),
97
- masked: (element) => {
98
- const copy = element.cloneNode(true);
99
- mask(copy, masking);
100
- return copy;
101
- }
102
- };
103
- }
104
- });
105
- }
106
- export { boxOf, mask, notOurs, screenshotsClient };
107
-
108
- //# sourceMappingURL=client.js.map
1
+ export { t as boxOf, n as mask, r as notOurs, i as screenshotsClient } from "../shared/client.js";
@@ -1,4 +1,4 @@
1
- import { r as Capture } from "../shared/index2.js";
1
+ import { r as Capture } from "../shared/index3.js";
2
2
  declare const _default: import("deictic").ClientPlugin<never, never, Capture>;
3
3
  export { _default as default };
4
4
  //# sourceMappingURL=dom.d.ts.map
@@ -1,4 +1,4 @@
1
- import { boxOf, mask, notOurs, screenshotsClient } from "./client.js";
1
+ import { i as screenshotsClient, n as mask, r as notOurs, t as boxOf } from "../shared/client.js";
2
2
  // src/plugins/screenshots/dom.ts
3
3
  /**
4
4
  * The `dom()` renderer's page half: draws the page in the page from its DOM with `modern-screenshot`
@@ -1,2 +1,2 @@
1
- import { a as Masking, c as Screenshots, d as dom, f as rrweb, i as CaptureOptions, l as ScreenshotsOptions, n as BrowserOptions, o as Renderer, p as screenshots, r as Capture, s as ResolvedMasking, t as Box, u as Shot } from "../shared/index2.js";
1
+ import { a as Masking, c as Screenshots, d as dom, f as rrweb, i as CaptureOptions, l as ScreenshotsOptions, n as BrowserOptions, o as Renderer, p as screenshots, r as Capture, s as ResolvedMasking, t as Box, u as Shot } from "../shared/index3.js";
2
2
  export { Box, BrowserOptions, Capture, CaptureOptions, Masking, Renderer, ResolvedMasking, Screenshots, ScreenshotsOptions, Shot, screenshots as default, screenshots, dom, rrweb };
@@ -1,98 +1 @@
1
- import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
2
- import { join, resolve } from "node:path";
3
- import { definePlugin } from "../index.js";
4
- import { t as keptIn } from "../shared/kept.js";
5
- // src/plugins/screenshots/index.ts
6
- /**
7
- * `deictic/screenshots`: a plugin with no panel, for others to build on. In the page,
8
- * `use('screenshots').capture(element)` takes what the viewport shows (or the element alone), with
9
- * nothing of deictic's in it, and says where the element is; on the server, `use('screenshots').read(id)`
10
- * hands the PNG to another plugin, which the tasks plugin attaches to a task.
11
- *
12
- * How a shot is made is its renderer's: `rrweb()` by default, which snapshots the page's DOM and renders it
13
- * in a browser beside the dev server, so text lays out as the page's does; or `dom()`, which draws the page
14
- * in the page itself, for a target with no server to render on. A renderer is a page module and, where it
15
- * renders elsewhere, a `render` here (`Renderer`): another may take pixels from screen sharing or devtools.
16
- *
17
- * Shots are kept under `.deictic/screenshots`, the latest `keep` of them, so they outlive a
18
- * restart of the dev server and stay out of git.
19
- */
20
- /** Draws the page in the page, from its DOM (`modern-screenshot`): no server needed, but text may lay out a little differently. */
21
- const dom = () => ({ client: "deictic/screenshots/dom" });
22
- /**
23
- * Snapshots the page's DOM in the page (`rrweb-snapshot`, masking as rrweb does) and renders it in a
24
- * browser beside the dev server (`playwright-core`), so text lays out as the page's does.
25
- */
26
- const rrweb = (options = {}) => ({
27
- client: "deictic/screenshots/rrweb",
28
- render: async (input) => (await import("../shared/playwright.js")).render(input, options)
29
- });
30
- const ID = /^[a-z0-9]+-[a-z0-9]+$/;
31
- /** What one PNG, or one snapshot to render, may weigh: a viewport at twice its pixels is a few MB. */
32
- const MAX = 20971520;
33
- function screenshots(options = {}) {
34
- const renderer = options.renderer ?? rrweb();
35
- const keep = options.keep ?? 100;
36
- let dir = "";
37
- let taken = 0;
38
- const pathOf = (id) => join(dir, `${id}.png`);
39
- const read = (id) => {
40
- if (!ID.test(id) || !existsSync(pathOf(id))) return void 0;
41
- return {
42
- data: new Uint8Array(readFileSync(pathOf(id))),
43
- name: `${id}.png`,
44
- type: "image/png"
45
- };
46
- };
47
- const keepShot = (data) => {
48
- const id = `${Date.now().toString(36).padStart(9, "0")}${(taken++ % 1296).toString(36).padStart(2, "0")}-${crypto.randomUUID().slice(0, 8)}`;
49
- mkdirSync(dir, { recursive: true });
50
- writeFileSync(pathOf(id), data);
51
- const kept = readdirSync(dir).filter((f) => f.endsWith(".png")).toSorted();
52
- for (const old of kept.slice(0, Math.max(0, kept.length - keep))) rmSync(join(dir, old));
53
- return id;
54
- };
55
- return definePlugin({
56
- name: "screenshots",
57
- client: renderer.client,
58
- clientOptions: {
59
- masking: {
60
- blockClass: options.blockClass ?? "rr-block",
61
- blockSelector: options.blockSelector,
62
- maskTextClass: options.maskTextClass ?? "rr-mask",
63
- maskTextSelector: options.maskTextSelector,
64
- maskAllInputs: options.maskAllInputs ?? false
65
- },
66
- renderer: renderer.clientOptions
67
- },
68
- setup: ({ root }) => {
69
- dir = options.dir === void 0 ? keptIn(root, "screenshots") : resolve(root, options.dir);
70
- return { read };
71
- },
72
- routes: {
73
- add: async (req) => {
74
- const type = req.headers.get("content-type") ?? "";
75
- const body = new Uint8Array(await req.arrayBuffer());
76
- if (body.byteLength > MAX) return Response.json({ problem: `a shot may weigh ${MAX / 1024 / 1024} MB at most` }, { status: 413 });
77
- if (type === "image/png") return Response.json({ id: keepShot(body) });
78
- if (renderer.render === void 0 || !type.startsWith("application/json")) return Response.json({ problem: "send the shot as image/png" }, { status: 415 });
79
- try {
80
- return Response.json({ id: keepShot(await renderer.render(JSON.parse(new TextDecoder().decode(body)))) });
81
- } catch (e) {
82
- return Response.json({ problem: e instanceof Error ? e.message : String(e) }, { status: 500 });
83
- }
84
- },
85
- shot: (req) => {
86
- const shot = read(new URL(req.url).pathname.split("/").at(-1) ?? "");
87
- if (shot === void 0) return new Response("no such shot, or not kept any more", { status: 404 });
88
- return new Response(shot.data, { headers: {
89
- "content-type": shot.type,
90
- "cache-control": "no-store"
91
- } });
92
- }
93
- }
94
- });
95
- }
96
- export { screenshots as default, screenshots, dom, rrweb };
97
-
98
- //# sourceMappingURL=index.js.map
1
+ export { r as default, r as screenshots, t as dom, n as rrweb } from "../shared/screenshots.js";
@@ -1,8 +1,9 @@
1
- import { r as Capture } from "../shared/index2.js";
1
+ import { r as Capture } from "../shared/index3.js";
2
2
  /**
3
3
  * The `rrweb()` renderer's page half: a snapshot of the page's DOM with `rrweb-snapshot` (imported on the
4
4
  * first shot), masked as rrweb masks, without deictic's overlay, sent with what the server's browser needs
5
5
  * to show it as the page does: the viewport and the window around it, where it's scrolled to, the pixel density, the page's URL.
6
+ * And which node of the snapshot the element is, so the server says where it is in what it drew.
6
7
  */
7
8
  declare const _default: import("deictic").ClientPlugin<never, never, Capture>;
8
9
  export { _default as default };
@@ -1 +1 @@
1
- {"version":3,"file":"rrweb.d.ts","names":["_$__index_ts0.Capture"],"sources":["../../src/plugins/screenshots/rrweb.ts"],"mappings":";;;;;;cAgBA,4B,2BAAAA"}
1
+ {"version":3,"file":"rrweb.d.ts","names":["_$__index_ts0.Capture"],"sources":["../../src/plugins/screenshots/rrweb.ts"],"mappings":";;;;;;;cAiBA,4B,2BAAAA"}
@@ -1,9 +1,10 @@
1
- import { boxOf, screenshotsClient } from "./client.js";
1
+ import { i as screenshotsClient, t as boxOf } from "../shared/client.js";
2
2
  // src/plugins/screenshots/rrweb.ts
3
3
  /**
4
4
  * The `rrweb()` renderer's page half: a snapshot of the page's DOM with `rrweb-snapshot` (imported on the
5
5
  * first shot), masked as rrweb masks, without deictic's overlay, sent with what the server's browser needs
6
6
  * to show it as the page does: the viewport and the window around it, where it's scrolled to, the pixel density, the page's URL.
7
+ * And which node of the snapshot the element is, so the server says where it is in what it drew.
7
8
  */
8
9
  /** The snapshot without deictic's overlay, which rrweb has no option to leave out. */
9
10
  function withoutOurs(node) {
@@ -15,10 +16,12 @@ function withoutOurs(node) {
15
16
  };
16
17
  }
17
18
  var rrweb_default = screenshotsClient(async (element, { area, masking, overlay }) => {
18
- const { snapshot } = await import("rrweb-snapshot").catch((e) => {
19
+ const { snapshot, createMirror } = await import("rrweb-snapshot").catch((e) => {
19
20
  throw new Error("the rrweb() renderer needs rrweb-snapshot: add it to your devDependencies", { cause: e });
20
21
  });
22
+ const mirror = createMirror();
21
23
  const taken = snapshot(document, {
24
+ mirror,
22
25
  inlineStylesheet: true,
23
26
  blockClass: masking.blockClass,
24
27
  blockSelector: masking.blockSelector ?? null,
@@ -39,6 +42,7 @@ var rrweb_default = screenshotsClient(async (element, { area, masking, overlay }
39
42
  });
40
43
  const body = {
41
44
  snapshot: withoutOurs(taken),
45
+ ...mirror.getId(element) === -1 ? {} : { element: mirror.getId(element) },
42
46
  url: location.href,
43
47
  viewport,
44
48
  window: {
@@ -1 +1 @@
1
- {"version":3,"file":"rrweb.js","names":[],"sources":["../../src/plugins/screenshots/rrweb.ts"],"sourcesContent":["/**\n * The `rrweb()` renderer's page half: a snapshot of the page's DOM with `rrweb-snapshot` (imported on the\n * first shot), masked as rrweb masks, without deictic's overlay, sent with what the server's browser needs\n * to show it as the page does: the viewport and the window around it, where it's scrolled to, the pixel density, the page's URL.\n */\n\nimport { boxOf, screenshotsClient } from './client.ts';\nimport type { Snapshot, SnapshotNode } from './playwright.ts';\n\n/** The snapshot without deictic's overlay, which rrweb has no option to leave out. */\nfunction withoutOurs(node: SnapshotNode): SnapshotNode {\n if (!('childNodes' in node)) return node;\n const childNodes = node.childNodes.filter((c: SnapshotNode) => !('tagName' in c && c.tagName === 'deictic-overlay')).map(withoutOurs);\n return { ...node, childNodes };\n}\n\nexport default screenshotsClient(async (element, { area, masking, overlay }) => {\n const { snapshot } = await import('rrweb-snapshot').catch((e: unknown) => {\n throw new Error('the rrweb() renderer needs rrweb-snapshot: add it to your devDependencies', { cause: e });\n });\n const taken = snapshot(document, {\n inlineStylesheet: true,\n blockClass: masking.blockClass,\n blockSelector: masking.blockSelector ?? null,\n maskTextClass: masking.maskTextClass,\n maskTextSelector: masking.maskTextSelector ?? null,\n maskAllInputs: masking.maskAllInputs,\n });\n if (taken === null) throw new Error('screenshots: rrweb took no snapshot of this page');\n const box = boxOf(element, area);\n const viewport = { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };\n // Over the viewport, which the server renders before cutting out an element's part.\n const marks = overlay({ x: 0, y: 0, ...viewport });\n const body: Snapshot = {\n snapshot: withoutOurs(taken),\n url: location.href,\n viewport,\n window: { width: innerWidth, height: innerHeight },\n ...(marks === undefined ? {} : { overlay: marks }),\n scroll: { x: scrollX, y: scrollY },\n scale: Math.min(devicePixelRatio, 2),\n // A shot of the element alone is the part of the viewport it fills.\n ...(area === 'element' ? { clip: element.getBoundingClientRect().toJSON() as Snapshot['clip'] } : {}),\n };\n return { body: JSON.stringify(body), type: 'application/json', box };\n});\n"],"mappings":";;;;;;;;AAUA,SAAS,YAAY,MAAkC;CACrD,IAAI,EAAE,gBAAgB,OAAO,OAAO;CACpC,MAAM,aAAa,KAAK,WAAW,QAAQ,MAAoB,EAAE,aAAa,KAAK,EAAE,YAAY,kBAAkB,CAAC,CAAC,IAAI,WAAW;CACpI,OAAO;EAAE,GAAG;EAAM;CAAW;AAC/B;AAEA,IAAA,gBAAe,kBAAkB,OAAO,SAAS,EAAE,MAAM,SAAS,cAAc;CAC9E,MAAM,EAAE,aAAa,MAAM,OAAO,iBAAiB,CAAC,OAAO,MAAe;EACxE,MAAM,IAAI,MAAM,6EAA6E,EAAE,OAAO,EAAE,CAAC;CAC3G,CAAC;CACD,MAAM,QAAQ,SAAS,UAAU;EAC/B,kBAAkB;EAClB,YAAY,QAAQ;EACpB,eAAe,QAAQ,iBAAiB;EACxC,eAAe,QAAQ;EACvB,kBAAkB,QAAQ,oBAAoB;EAC9C,eAAe,QAAQ;CACzB,CAAC;CACD,IAAI,UAAU,MAAM,MAAM,IAAI,MAAM,kDAAkD;CACtF,MAAM,MAAM,MAAM,SAAS,IAAI;CAC/B,MAAM,WAAW;EAAE,OAAO,SAAS,gBAAgB;EAAa,QAAQ,SAAS,gBAAgB;CAAa;CAE9G,MAAM,QAAQ,QAAQ;EAAE,GAAG;EAAG,GAAG;EAAG,GAAG;CAAS,CAAC;CACjD,MAAM,OAAiB;EACrB,UAAU,YAAY,KAAK;EAC3B,KAAK,SAAS;EACd;EACA,QAAQ;GAAE,OAAO;GAAY,QAAQ;EAAY;EACjD,GAAI,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,MAAM;EAChD,QAAQ;GAAE,GAAG;GAAS,GAAG;EAAQ;EACjC,OAAO,KAAK,IAAI,kBAAkB,CAAC;EAEnC,GAAI,SAAS,YAAY,EAAE,MAAM,QAAQ,sBAAsB,CAAC,CAAC,OAAO,EAAsB,IAAI,CAAC;CACrG;CACA,OAAO;EAAE,MAAM,KAAK,UAAU,IAAI;EAAG,MAAM;EAAoB;CAAI;AACrE,CAAC"}
1
+ {"version":3,"file":"rrweb.js","names":[],"sources":["../../src/plugins/screenshots/rrweb.ts"],"sourcesContent":["/**\n * The `rrweb()` renderer's page half: a snapshot of the page's DOM with `rrweb-snapshot` (imported on the\n * first shot), masked as rrweb masks, without deictic's overlay, sent with what the server's browser needs\n * to show it as the page does: the viewport and the window around it, where it's scrolled to, the pixel density, the page's URL.\n * And which node of the snapshot the element is, so the server says where it is in what it drew.\n */\n\nimport { boxOf, screenshotsClient } from './client.ts';\nimport type { Snapshot, SnapshotNode } from './playwright.ts';\n\n/** The snapshot without deictic's overlay, which rrweb has no option to leave out. */\nfunction withoutOurs(node: SnapshotNode): SnapshotNode {\n if (!('childNodes' in node)) return node;\n const childNodes = node.childNodes.filter((c: SnapshotNode) => !('tagName' in c && c.tagName === 'deictic-overlay')).map(withoutOurs);\n return { ...node, childNodes };\n}\n\nexport default screenshotsClient(async (element, { area, masking, overlay }) => {\n const { snapshot, createMirror } = await import('rrweb-snapshot').catch((e: unknown) => {\n throw new Error('the rrweb() renderer needs rrweb-snapshot: add it to your devDependencies', { cause: e });\n });\n const mirror = createMirror();\n const taken = snapshot(document, {\n mirror,\n inlineStylesheet: true,\n blockClass: masking.blockClass,\n blockSelector: masking.blockSelector ?? null,\n maskTextClass: masking.maskTextClass,\n maskTextSelector: masking.maskTextSelector ?? null,\n maskAllInputs: masking.maskAllInputs,\n });\n if (taken === null) throw new Error('screenshots: rrweb took no snapshot of this page');\n const box = boxOf(element, area);\n const viewport = { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };\n // Over the viewport, which the server renders before cutting out an element's part.\n const marks = overlay({ x: 0, y: 0, ...viewport });\n const body: Snapshot = {\n snapshot: withoutOurs(taken),\n ...(mirror.getId(element) === -1 ? {} : { element: mirror.getId(element) }),\n url: location.href,\n viewport,\n window: { width: innerWidth, height: innerHeight },\n ...(marks === undefined ? {} : { overlay: marks }),\n scroll: { x: scrollX, y: scrollY },\n scale: Math.min(devicePixelRatio, 2),\n // A shot of the element alone is the part of the viewport it fills.\n ...(area === 'element' ? { clip: element.getBoundingClientRect().toJSON() as Snapshot['clip'] } : {}),\n };\n return { body: JSON.stringify(body), type: 'application/json', box };\n});\n"],"mappings":";;;;;;;;;AAWA,SAAS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AM,QAAQ,sBAAsB,CAAC,CAAC,OAAO,EAAsB,IAAI,CAAC;CACrG;CACA,OAAO;EAAE,MAAM,KAAK,UAAU,IAAI;EAAG,MAAM;EAAoB;CAAI;AACrE,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { r as definePlugin } from "./src.js";
2
+ // src/plugins/annotations/index.ts
3
+ /**
4
+ * `deictic/annotations`: mark up the page itself. Its tab is annotate
5
+ * mode over the page: boxes, arrows, a pen and notes, drawn where the page is, so they stay with
6
+ * it as it scrolls. They're kept for the tab's session, per page, until cleared.
7
+ *
8
+ * They're data other plugins build on, through `use('annotations')` in the page: screenshots draw them
9
+ * over the page (`svg(area)`), tasks repeat their notes, and a recording can keep each change as it
10
+ * happens (`subscribe`). Nothing of it runs on the server.
11
+ */
12
+ function annotations(options = {}) {
13
+ return definePlugin({
14
+ name: "annotations",
15
+ client: "deictic/annotations/client",
16
+ shortcut: options.shortcut,
17
+ clientOptions: { color: options.color ?? "#ef4444" }
18
+ });
19
+ }
20
+ export { annotations as t };
21
+
22
+ //# sourceMappingURL=annotations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"annotations.js","names":[],"sources":["../../src/plugins/annotations/index.ts"],"sourcesContent":["/**\n * `deictic/annotations`: mark up the page itself. Its tab is annotate\n * mode over the page: boxes, arrows, a pen and notes, drawn where the page is, so they stay with\n * it as it scrolls. They're kept for the tab's session, per page, until cleared.\n *\n * They're data other plugins build on, through `use('annotations')` in the page: screenshots draw them\n * over the page (`svg(area)`), tasks repeat their notes, and a recording can keep each change as it\n * happens (`subscribe`). Nothing of it runs on the server.\n */\nimport { definePlugin, type Shortcut } from '#src/index.ts';\n\n/** A point in page coordinates: CSS pixels from the document's top left, so it stays put as the page scrolls. */\nexport interface Point {\n x: number;\n y: number;\n}\n\n/** A rectangle: in page coordinates for a shape, in viewport coordinates for an area to draw. */\nexport interface Area {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nexport type Shape =\n | ({ kind: 'box' } & Area)\n | { kind: 'arrow'; from: Point; to: Point }\n | { kind: 'pen'; points: Point[] }\n | { kind: 'note'; at: Point; text: string };\n\nexport interface Annotation {\n id: string;\n color: string;\n shape: Shape;\n /** When it was made, as `Date.now()`. */\n at: number;\n}\n\n/** A change, as `subscribe` hears it: what a recording keeps, to show the marks as they were made. */\nexport type AnnotationEvent = { type: 'add'; annotation: Annotation } | { type: 'remove'; id: string } | { type: 'clear' };\n\n/** The page's half, for other plugins' page halves. */\nexport interface Annotations {\n /** Every annotation on this page, oldest first. */\n list(): Annotation[];\n add(shape: Shape, color?: string): Annotation;\n remove(id: string): void;\n clear(): void;\n /** Hears every change from now on; answers what stops it. */\n subscribe(listener: (event: AnnotationEvent) => void): () => void;\n /**\n * The annotations over a part of the viewport, in viewport CSS pixels, as an SVG that size: what a\n * screenshot of that area draws over it. Nothing when there are none.\n */\n svg(area: Area): string | undefined;\n /**\n * Opens a picture (a screenshot, most often) over everything, with the toolbar, to draw on: answers the\n * marks, in the picture's CSS pixels, on Save, and nothing on Cancel, Esc or `signal`. It starts from\n * `marks`, to edit them again. They're the picture's alone, not the page's.\n */\n edit(picture: Picture, marks?: readonly Annotation[], options?: { signal?: AbortSignal }): Promise<Annotation[] | undefined>;\n /** The picture with the marks drawn over it, as a PNG at the picture's own resolution. */\n flatten(picture: Picture, marks: readonly Annotation[]): Promise<Blob>;\n /**\n * Annotate mode's tools, for another plugin's UI to show (a recording's toolbar): a pointer tool, picked\n * to start with, leaves the page usable; while a drawing tool is picked, the page is drawn on. What's\n * drawn is its own `marks`, not the page's: shown while it's open, kept by nothing, gone on `close`.\n */\n tools(): { element: HTMLElement; marks: MarkSet; close: () => void };\n}\n\n/** A set of marks on the page: the page's own, kept for the session, or a toolbar's, kept by nothing. */\nexport type MarkSet = Pick<Annotations, 'list' | 'add' | 'remove' | 'clear' | 'subscribe' | 'svg'>;\n\n/** An image to draw on: where it loads from (the page's origin, so a canvas may read it), and its size in CSS pixels, which marks on it are in. */\nexport interface Picture {\n url: string;\n width: number;\n height: number;\n}\n\ndeclare module 'deictic' {\n interface ClientApis {\n annotations: Annotations;\n }\n}\n\nexport interface AnnotationsOptions {\n /** What opens its tab directly, beside deictic's own shortcut, which opens any: none by default. */\n shortcut?: Shortcut;\n /** The colour marks are drawn in: a red that deictic's own green isn't. */\n color?: string;\n}\n\nexport function annotations(options: AnnotationsOptions = {}) {\n return definePlugin({\n name: 'annotations',\n client: 'deictic/annotations/client',\n shortcut: options.shortcut,\n clientOptions: { color: options.color ?? '#ef4444' },\n });\n}\n\nexport default annotations;\n"],"mappings":";;;;;;;;;;;AA+FA,SAAgB,YAAY,UAA8B,CAAC,GAAG;CAC5D,OAAO,aAAa;EAClB,MAAM;EACN,QAAQ;EACR,UAAU,QAAQ;EAClB,eAAe,EAAE,OAAO,QAAQ,SAAS,UAAU;CACrD,CAAC;AACH"}
@@ -0,0 +1,190 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { existsSync, readdirSync } from "node:fs";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { parseArgs as parseArgs$1 } from "node:util";
5
+ import { i as vbScript, r as runningAt } from "./local.js";
6
+ // src/cli/board.ts
7
+ /**
8
+ * What the agent's commands share: the board's CLI (`vb`, the project's `@vercel/board`) on the board the dev server
9
+ * uses, the project's `.deictic/` folders, and failing with what to do.
10
+ */
11
+ /** How the commands name each other in what they print, for an agent to run. */
12
+ const ME = "npx deictic";
13
+ function fail(message) {
14
+ console.error(message);
15
+ process.exit(1);
16
+ }
17
+ /** A command's options and arguments, or a failure saying what's wrong with them. */
18
+ function parseArgs(args, options) {
19
+ try {
20
+ return parseArgs$1({
21
+ args,
22
+ options,
23
+ allowPositionals: true,
24
+ allowNegative: true,
25
+ strict: true
26
+ });
27
+ } catch (e) {
28
+ return fail(e.message);
29
+ }
30
+ }
31
+ /** `1:02.5`, from milliseconds. */
32
+ function clock(ms) {
33
+ const s = Math.max(0, ms) / 1e3;
34
+ return `${Math.floor(s / 60)}:${(s % 60).toFixed(1).padStart(4, "0")}`;
35
+ }
36
+ /** `30m`, `45s`, `1h` or a bare number of seconds, as milliseconds. */
37
+ function duration(text) {
38
+ const [, n, unit = "s"] = /^(\d+(?:\.\d+)?)([smh])?$/.exec(text) ?? [];
39
+ if (n === void 0) fail(`"${text}" isn't a duration: 30m, 45s, 1h, or seconds as a number.`);
40
+ return Number(n) * {
41
+ s: 1e3,
42
+ m: 6e4,
43
+ h: 36e5
44
+ }[unit];
45
+ }
46
+ /** This directory and each above it. */
47
+ function* upFrom(dir = process.cwd()) {
48
+ for (let at = resolve(dir);; at = dirname(at)) {
49
+ yield at;
50
+ if (dirname(at) === at) return;
51
+ }
52
+ }
53
+ /** Every `.deictic/` near here: in this directory or above, or in a folder of it (a site/, an app/). */
54
+ function deicticDirs() {
55
+ const found = [...upFrom()].map((d) => join(d, ".deictic")).filter((p) => existsSync(p));
56
+ const walk = (dir, depth) => {
57
+ if (depth === 0) return;
58
+ for (const e of readdirSync(dir, { withFileTypes: true })) {
59
+ if (!e.isDirectory() || e.name === "node_modules" || e.name.startsWith(".") && e.name !== ".deictic") continue;
60
+ const path = join(dir, e.name);
61
+ if (e.name === ".deictic") found.push(path);
62
+ else walk(path, depth - 1);
63
+ }
64
+ };
65
+ walk(process.cwd(), 3);
66
+ return [...new Set(found)];
67
+ }
68
+ /** The board a `.deictic/` names: the one its dev server started. */
69
+ const boardIn = (dir) => runningAt(join(dir, "board.json"))?.url;
70
+ /**
71
+ * The board's URL: `BOARD_URL`, or with none, the board the dev server started for the project, which
72
+ * `.deictic/board.json` names. Nothing where there's neither: `vb` then finds the team's board.
73
+ */
74
+ function boardUrl() {
75
+ const given = process.env.BOARD_URL;
76
+ if (given !== void 0 && given !== "") return given;
77
+ return deicticDirs().map(boardIn).find((url) => url !== void 0);
78
+ }
79
+ /**
80
+ * The coding agents a shell of theirs says it is, by a variable each sets only there. Not one a person's terminal has
81
+ * too (Replit's `REPL_ID`, a `TERM_PROGRAM`): a person writes as themselves.
82
+ */
83
+ const AGENTS = [
84
+ ["claude", ["CLAUDECODE", "CLAUDE_CODE"]],
85
+ ["codex", ["CODEX_SANDBOX", "CODEX_THREAD_ID"]],
86
+ ["gemini", ["GEMINI_CLI"]],
87
+ ["cursor", ["CURSOR_AGENT"]],
88
+ ["copilot", ["COPILOT_AGENT", "COPILOT_CLI"]],
89
+ ["opencode", ["OPENCODE"]],
90
+ ["auggie", ["AUGMENT_AGENT"]],
91
+ ["goose", ["GOOSE_PROVIDER"]],
92
+ ["junie", ["JUNIE_DATA", "JUNIE_SHIM_PATH"]]
93
+ ];
94
+ /** A board's profile name: a letter, then up to 31 letters, digits and hyphens. */
95
+ const PROFILE = /^[A-Za-z][A-Za-z0-9-]{0,31}$/;
96
+ /**
97
+ * Who the board's CLI writes as: `BOARD_PROFILE` where it's set, or else the coding agent this runs in, so its claims,
98
+ * replies and results are its own, not the person's, without its setting anything on each command. By the variable
99
+ * its harness sets, then by `AI_AGENT` (`claude-code_2-1-330_agent` is `claude`). Nothing at a person's terminal.
100
+ */
101
+ function profileOf(env = process.env) {
102
+ if (env.BOARD_PROFILE !== void 0 && env.BOARD_PROFILE !== "") return env.BOARD_PROFILE;
103
+ const known = AGENTS.find(([, variables]) => variables.some((v) => env[v] !== void 0 && env[v] !== ""));
104
+ if (known !== void 0) return known[0];
105
+ const named = env.AI_AGENT?.toLowerCase();
106
+ if (named === void 0 || named === "") return void 0;
107
+ if (named.startsWith("github_copilot")) return "copilot";
108
+ const name = (named.split("_")[0] ?? "").replace(/-(code|cli|agent)$/, "");
109
+ return PROFILE.test(name) ? name : void 0;
110
+ }
111
+ /**
112
+ * How to run the board's CLI, as `spawn`'s command, arguments and options, on the environment's board or the
113
+ * project's own, as the agent running it (`profileOf`): the project's `@vercel/board`, run by this runtime, so it
114
+ * needn't be on the PATH and no shell reads the arguments; with none installed, `vb` from the PATH.
115
+ */
116
+ function vbCommand(args) {
117
+ const url = boardUrl();
118
+ const profile = profileOf();
119
+ const env = {
120
+ ...process.env,
121
+ ...url === void 0 ? {} : { BOARD_URL: url },
122
+ ...profile === void 0 ? {} : { BOARD_PROFILE: profile }
123
+ };
124
+ const script = vbScript();
125
+ if (script !== void 0) return [
126
+ process.execPath,
127
+ [script, ...args],
128
+ { env }
129
+ ];
130
+ if (process.platform === "win32") return [
131
+ `vb ${args.map((a) => `"${a}"`).join(" ")}`,
132
+ [],
133
+ {
134
+ env,
135
+ shell: true
136
+ }
137
+ ];
138
+ return [
139
+ "vb",
140
+ args,
141
+ { env }
142
+ ];
143
+ }
144
+ const unreachable = (message) => fail(`vb: ${message}. Install @vercel/board in the project (${ME} init), or put vb on the PATH.`);
145
+ /** Runs the board's CLI and answers what it printed. */
146
+ function vb(args) {
147
+ const [command, argv, options] = vbCommand(args);
148
+ const run = spawnSync(command, argv, {
149
+ ...options,
150
+ encoding: "utf8",
151
+ maxBuffer: 1 << 28
152
+ });
153
+ if (run.error) unreachable(run.error.message);
154
+ if (run.status !== 0) fail(`vb ${args.join(" ")}: ${run.stderr.trim() || `exit ${run.status}`}`);
155
+ return run.stdout;
156
+ }
157
+ /** The board's CLI's answer as JSON. */
158
+ const vbJson = (args) => JSON.parse(vb([...args, "--json"]));
159
+ /** Runs the board's CLI on this terminal, and answers its exit code. */
160
+ function vbHere(args) {
161
+ const [command, argv, options] = vbCommand(args);
162
+ const run = spawnSync(command, argv, {
163
+ ...options,
164
+ stdio: "inherit"
165
+ });
166
+ if (run.error) unreachable(run.error.message);
167
+ return run.status ?? 1;
168
+ }
169
+ /** Whether the board answers now, as whoever the CLI writes as: asked of one that may be starting again. */
170
+ function answers() {
171
+ const [command, argv, options] = vbCommand(["whoami", "--json"]);
172
+ return spawnSync(command, argv, {
173
+ ...options,
174
+ encoding: "utf8"
175
+ }).status === 0;
176
+ }
177
+ const whoami = () => vbJson(["whoami"]);
178
+ /** A task's root message and its replies, by its ID (`68` or `#68`). */
179
+ const read = (id) => vbJson(["read", id.replace(/^#/, "")]);
180
+ /** A task's root message. */
181
+ const task = (id) => read(id).message;
182
+ /** Writes an attachment to a file. */
183
+ const download = (attachment, path) => vb([
184
+ "download",
185
+ attachment.id,
186
+ path
187
+ ]);
188
+ export { whoami as _, clock as a, duration as c, read as d, task as f, vbJson as g, vbHere as h, boardUrl as i, fail as l, vbCommand as m, answers as n, deicticDirs as o, vb as p, boardIn as r, download as s, ME as t, parseArgs as u };
189
+
190
+ //# sourceMappingURL=board.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"board.js","names":["parse"],"sources":["../../src/cli/board.ts"],"sourcesContent":["/**\n * What the agent's commands share: the board's CLI (`vb`, the project's `@vercel/board`) on the board the dev server\n * uses, the project's `.deictic/` folders, and failing with what to do.\n */\nimport { spawnSync, type SpawnSyncOptions } from 'node:child_process';\nimport { existsSync, readdirSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\nimport { parseArgs as parse, type ParseArgsConfig } from 'node:util';\n\nimport { runningAt, vbScript } from '#src/plugins/tasks/local.ts';\n\n/** How the commands name each other in what they print, for an agent to run. */\nexport const ME = 'npx deictic';\n\nexport function fail(message: string): never {\n console.error(message);\n process.exit(1);\n}\n\n/** A command's options and arguments, or a failure saying what's wrong with them. */\nexport function parseArgs<T extends NonNullable<ParseArgsConfig['options']>>(args: string[], options: T) {\n try {\n return parse({ args, options, allowPositionals: true, allowNegative: true, strict: true });\n } catch (e) {\n return fail((e as Error).message);\n }\n}\n\n/** `1:02.5`, from milliseconds. */\nexport function clock(ms: number): string {\n const s = Math.max(0, ms) / 1000;\n return `${Math.floor(s / 60)}:${(s % 60).toFixed(1).padStart(4, '0')}`;\n}\n\n/** `30m`, `45s`, `1h` or a bare number of seconds, as milliseconds. */\nexport function duration(text: string): number {\n const [, n, unit = 's'] = /^(\\d+(?:\\.\\d+)?)([smh])?$/.exec(text) ?? [];\n if (n === undefined) fail(`\"${text}\" isn't a duration: 30m, 45s, 1h, or seconds as a number.`);\n return Number(n) * { s: 1000, m: 60_000, h: 3_600_000 }[unit as 's' | 'm' | 'h'];\n}\n\n/** This directory and each above it. */\nfunction* upFrom(dir = process.cwd()) {\n for (let at = resolve(dir); ; at = dirname(at)) {\n yield at;\n if (dirname(at) === at) return;\n }\n}\n\n/** Every `.deictic/` near here: in this directory or above, or in a folder of it (a site/, an app/). */\nexport function deicticDirs(): string[] {\n const found = [...upFrom()].map((d) => join(d, '.deictic')).filter((p) => existsSync(p));\n const walk = (dir: string, depth: number) => {\n if (depth === 0) return;\n for (const e of readdirSync(dir, { withFileTypes: true })) {\n if (!e.isDirectory() || e.name === 'node_modules' || (e.name.startsWith('.') && e.name !== '.deictic')) continue;\n const path = join(dir, e.name);\n if (e.name === '.deictic') found.push(path);\n else walk(path, depth - 1);\n }\n };\n walk(process.cwd(), 3);\n return [...new Set(found)];\n}\n\n/** The board a `.deictic/` names: the one its dev server started. */\nexport const boardIn = (dir: string) => runningAt(join(dir, 'board.json'))?.url;\n\n/**\n * The board's URL: `BOARD_URL`, or with none, the board the dev server started for the project, which\n * `.deictic/board.json` names. Nothing where there's neither: `vb` then finds the team's board.\n */\nexport function boardUrl(): string | undefined {\n const given = process.env.BOARD_URL;\n if (given !== undefined && given !== '') return given;\n return deicticDirs()\n .map(boardIn)\n .find((url) => url !== undefined);\n}\n\n/**\n * The coding agents a shell of theirs says it is, by a variable each sets only there. Not one a person's terminal has\n * too (Replit's `REPL_ID`, a `TERM_PROGRAM`): a person writes as themselves.\n */\nconst AGENTS: [name: string, variables: string[]][] = [\n ['claude', ['CLAUDECODE', 'CLAUDE_CODE']],\n ['codex', ['CODEX_SANDBOX', 'CODEX_THREAD_ID']],\n ['gemini', ['GEMINI_CLI']],\n ['cursor', ['CURSOR_AGENT']],\n ['copilot', ['COPILOT_AGENT', 'COPILOT_CLI']],\n ['opencode', ['OPENCODE']],\n ['auggie', ['AUGMENT_AGENT']],\n ['goose', ['GOOSE_PROVIDER']],\n ['junie', ['JUNIE_DATA', 'JUNIE_SHIM_PATH']],\n];\n\n/** A board's profile name: a letter, then up to 31 letters, digits and hyphens. */\nconst PROFILE = /^[A-Za-z][A-Za-z0-9-]{0,31}$/;\n\n/**\n * Who the board's CLI writes as: `BOARD_PROFILE` where it's set, or else the coding agent this runs in, so its claims,\n * replies and results are its own, not the person's, without its setting anything on each command. By the variable\n * its harness sets, then by `AI_AGENT` (`claude-code_2-1-330_agent` is `claude`). Nothing at a person's terminal.\n */\nexport function profileOf(env: NodeJS.ProcessEnv = process.env): string | undefined {\n if (env.BOARD_PROFILE !== undefined && env.BOARD_PROFILE !== '') return env.BOARD_PROFILE;\n const known = AGENTS.find(([, variables]) => variables.some((v) => env[v] !== undefined && env[v] !== ''));\n if (known !== undefined) return known[0];\n const named = env.AI_AGENT?.toLowerCase();\n if (named === undefined || named === '') return undefined;\n if (named.startsWith('github_copilot')) return 'copilot';\n // The agent's name, without its version, its kind or what it is (`-code`, `-cli`).\n const name = (named.split('_')[0] ?? '').replace(/-(code|cli|agent)$/, '');\n return PROFILE.test(name) ? name : undefined;\n}\n\n/**\n * How to run the board's CLI, as `spawn`'s command, arguments and options, on the environment's board or the\n * project's own, as the agent running it (`profileOf`): the project's `@vercel/board`, run by this runtime, so it\n * needn't be on the PATH and no shell reads the arguments; with none installed, `vb` from the PATH.\n */\nexport function vbCommand(args: string[]): [string, string[], SpawnSyncOptions] {\n const url = boardUrl();\n const profile = profileOf();\n const env = {\n ...process.env,\n ...(url === undefined ? {} : { BOARD_URL: url }),\n ...(profile === undefined ? {} : { BOARD_PROFILE: profile }),\n };\n const script = vbScript();\n if (script !== undefined) return [process.execPath, [script, ...args], { env }];\n // npm's shims on Windows are .cmd files, which only a shell runs; the arguments here are IDs and names.\n if (process.platform === 'win32') return [`vb ${args.map((a) => `\"${a}\"`).join(' ')}`, [], { env, shell: true }];\n return ['vb', args, { env }];\n}\n\nconst unreachable = (message: string) => fail(`vb: ${message}. Install @vercel/board in the project (${ME} init), or put vb on the PATH.`);\n\n/** Runs the board's CLI and answers what it printed. */\nexport function vb(args: string[]): string {\n const [command, argv, options] = vbCommand(args);\n const run = spawnSync(command, argv, { ...options, encoding: 'utf8', maxBuffer: 1 << 28 });\n if (run.error) unreachable(run.error.message);\n if (run.status !== 0) fail(`vb ${args.join(' ')}: ${run.stderr.trim() || `exit ${run.status}`}`);\n return run.stdout;\n}\n\n/** The board's CLI's answer as JSON. */\nexport const vbJson = <T>(args: string[]): T => JSON.parse(vb([...args, '--json'])) as T;\n\n/** Runs the board's CLI on this terminal, and answers its exit code. */\nexport function vbHere(args: string[]): number {\n const [command, argv, options] = vbCommand(args);\n const run = spawnSync(command, argv, { ...options, stdio: 'inherit' });\n if (run.error) unreachable(run.error.message);\n return run.status ?? 1;\n}\n\n/** Whether the board answers now, as whoever the CLI writes as: asked of one that may be starting again. */\nexport function answers(): boolean {\n const [command, argv, options] = vbCommand(['whoami', '--json']);\n return spawnSync(command, argv, { ...options, encoding: 'utf8' }).status === 0;\n}\n\n/**\n * Who the CLI writes as. `profile` is the name `BOARD_PROFILE` (or `--as`) gave, and `null` without one: then what's\n * written is the person's own, as the board sees it.\n */\nexport interface Me {\n actor: string;\n handle?: string;\n name?: string;\n profile: string | null;\n}\n\nexport const whoami = () => vbJson<Me>(['whoami']);\n\nexport interface Attachment {\n id: string;\n name: string;\n type: string;\n size: number;\n}\n\nexport interface Message {\n id: number;\n channel: string;\n text: string;\n labels: Record<string, string>;\n attachments: Attachment[];\n createdAt: string;\n by: { actor: string };\n author?: { handle?: string };\n task?: { state: string; claim?: { actor: string; until: string }; result?: string; reason?: string };\n}\n\n/** A task's root message and its replies, by its ID (`68` or `#68`). */\nexport const read = (id: string) => vbJson<{ message: Message; replies: Message[] }>(['read', id.replace(/^#/, '')]);\n\n/** A task's root message. */\nexport const task = (id: string) => read(id).message;\n\n/** Writes an attachment to a file. */\nexport const download = (attachment: Attachment, path: string) => vb(['download', attachment.id, path]);\n"],"mappings":";;;;;;;;;;;AAYA,MAAa,KAAK;AAElB,SAAgB,KAAK,SAAwB;CAC3C,QAAQ,MAAM,OAAO;C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