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
@@ -8,9 +8,10 @@
8
8
  * Everything drawn sits in one shadow root, so neither the page's styles nor ours cross over. A
9
9
  * panel's undo and redo are its tab's on its element: the latest change that plugin made there.
10
10
  */
11
- import type { ClientContext, ClientPlugin, LightboxItem, PanelContext, Resumed, Target } from '#src/index.ts';
11
+ import type { ClientContext, ClientPlugin, LightboxItem, PanelContext, Resumed, Standalone, Target } from '#src/index.ts';
12
12
  import { gestureOf, type Shortcut } from '#src/shortcut.ts';
13
13
 
14
+ import { dropAway, keepAway, keptAway } from './away.ts';
14
15
  import { openLightbox } from './lightbox.ts';
15
16
  import { STYLE } from './style.ts';
16
17
  import { tooltips } from './tooltip.ts';
@@ -25,8 +26,13 @@ export interface StartOptions {
25
26
  shortcut?: Required<Shortcut>;
26
27
  /** Each plugin with a half in the page, and its own shortcut as the bundler's plugin checked it, where it has one. */
27
28
  plugins: { plugin: ClientPlugin; shortcut?: Required<Shortcut>; options?: unknown }[];
29
+ /** What answers the requests where there's no dev server to: a `standalone` build's. */
30
+ server?: Standalone;
28
31
  }
29
32
 
33
+ /** A request to the endpoints, by its URL: to the dev server, or to what stands in for it. */
34
+ type Send = (url: string, init?: RequestInit) => Promise<Response>;
35
+
30
36
  type Mount = (panel: HTMLElement, context: PanelContext<unknown, unknown>) => (() => void) | void;
31
37
 
32
38
  /** A plugin with a panel: a tab in the popup. */
@@ -78,6 +84,7 @@ const nameOf = (el: Element) => `${el.localName}${[...el.classList].map((c) => `
78
84
  /** What the overlay keeps once started, for `popupIn` to show the popup with. */
79
85
  interface Started {
80
86
  base: string;
87
+ send: Send;
81
88
  contextOf: (name: string) => ClientContext;
82
89
  tabs: Tab[];
83
90
  /** Opens the popup over the page on an element, at a tab or the one used last: `openPopup`. */
@@ -121,7 +128,7 @@ export function popupIn(container: Element, { tab: name, element }: { tab?: stri
121
128
  if (started === undefined) throw new Error('deictic: the overlay has not started, so there is no popup to show');
122
129
  const target = targetOf(element);
123
130
  if (target === undefined) throw new Error(`deictic: ${nameOf(element)} has no ${ATTRIBUTE} mark to open the popup on`);
124
- const { base, contextOf, tabs } = started;
131
+ const { base, send, contextOf, tabs } = started;
125
132
  // A tab shown here isn't one a person chose: the popup over the page keeps opening at theirs.
126
133
  const remember = () => {};
127
134
  const tab = tabs.find((t) => t.plugin.name === name) ?? tabs[0];
@@ -136,6 +143,7 @@ export function popupIn(container: Element, { tab: name, element }: { tab?: stri
136
143
  const open = (at: Tab, resumed?: Resumed) => {
137
144
  panel = openPanel({
138
145
  base,
146
+ send,
139
147
  root,
140
148
  contextOf,
141
149
  tabs,
@@ -180,7 +188,7 @@ export function lightboxIn(container: Element, items: LightboxItem[], { at }: {
180
188
  }
181
189
 
182
190
  /** Starts the overlay, once per page: the client module runs again when a module importing it is replaced. */
183
- export function start({ base, shortcut: own, plugins: given }: StartOptions): void {
191
+ export function start({ base, shortcut: own, plugins: given, server }: StartOptions): void {
184
192
  const page = globalThis as { [STARTED]?: true };
185
193
  if (page[STARTED] === true) return;
186
194
  page[STARTED] = true;
@@ -204,13 +212,15 @@ export function start({ base, shortcut: own, plugins: given }: StartOptions): vo
204
212
  // Each plugin's API, set up before any panel opens. `use` reads it when asked, so a setup may keep
205
213
  // `use` for later, not call it: the plugin it asks for may not be set up yet.
206
214
  const apis = new Map<string, unknown>();
215
+ const send: Send =
216
+ server === undefined ? (url, init) => fetch(url, init) : async (url, init) => server(new Request(new URL(url, location.href), init));
207
217
  const optionsOf = new Map(given.map(({ plugin, options }) => [plugin.name, options]));
208
218
  const contextOf = (name: string): ClientContext => ({
209
219
  base,
210
220
  root,
211
221
  options: optionsOf.get(name),
212
222
  use: (other) => apis.get(other) as never,
213
- request: (route, init) => fetch(`${base}__deictic/plugins/${name}/${route}`, init),
223
+ request: (route, init) => send(`${base}__deictic/plugins/${name}/${route}`, init),
214
224
  open: (plugin, element) => openAt(plugin, element),
215
225
  lightbox: (items, options) => openLightbox(root, items, options),
216
226
  });
@@ -226,6 +236,7 @@ export function start({ base, shortcut: own, plugins: given }: StartOptions): vo
226
236
  const tabs: Tab[] = given.flatMap(({ plugin }) => (plugin.mount === undefined ? [] : [{ plugin, mount: plugin.mount }]));
227
237
  started = {
228
238
  base,
239
+ send,
229
240
  contextOf,
230
241
  tabs,
231
242
  // Not over a popup holding something unsaved: the press that asked shook its button (`openPanel`).
@@ -362,6 +373,7 @@ export function start({ base, shortcut: own, plugins: given }: StartOptions): vo
362
373
  panel?.close();
363
374
  panel = openPanel({
364
375
  base,
376
+ send,
365
377
  root,
366
378
  contextOf,
367
379
  tabs,
@@ -373,15 +385,32 @@ export function start({ base, shortcut: own, plugins: given }: StartOptions): vo
373
385
  onClose: () => (panel = undefined),
374
386
  ...(resumed === undefined ? {} : { resumed }),
375
387
  reopen: (again, element, kept) => {
376
- const found = element.isConnected ? element : sameAs(element)[0];
377
- const at = found === undefined ? undefined : targetOf(found);
378
- // Gone from the page while away: there's nothing to come back to.
379
- if (found === undefined || at === undefined)
380
- return console.warn('deictic: the element is no longer on the page, so the popup stays closed');
381
- openTab(again, found, at, kept, pointed?.isConnected === true && found === element ? pointed : undefined);
388
+ // Rendered again while away, or gone from the page, which moved on: the popup comes back all the same, on
389
+ // the element as it was left, since what it kept (a recording) is about it wherever the page is now.
390
+ const found = element.isConnected ? element : (sameAs(element)[0] ?? element);
391
+ openTab(again, found, targetOf(found) ?? target, kept, pointed?.isConnected === true && found === element ? pointed : undefined);
382
392
  },
383
393
  });
384
394
  };
395
+ // What the page before this left a panel for (`away`), where that carries on here: the popup comes back when
396
+ // it's done, on the element where this page has it, and on a stand-in for it where it doesn't.
397
+ void keptAway().then((away) => {
398
+ if (away === undefined) return;
399
+ const tab = tabs.find((t) => t.plugin.name === away.tab);
400
+ const task = tab?.plugin.resume?.(contextOf(away.tab));
401
+ if (tab === undefined || task === undefined) return dropAway();
402
+ const back = (resumed: Resumed) => {
403
+ dropAway();
404
+ const { loc, tag } = away.target;
405
+ const absent = document.createElement(tag);
406
+ absent.setAttribute(ATTRIBUTE, `${loc.file}:${loc.line}:${loc.column}`);
407
+ openTab(tab, sameAs(absent).find((el) => el.localName === tag) ?? absent, away.target, resumed);
408
+ };
409
+ task.then(
410
+ (result) => back({ state: away.state, result }),
411
+ (e: unknown) => back({ state: away.state, problem: messageOf(e) }),
412
+ );
413
+ });
385
414
  function openAt(name: string, given: Element): boolean {
386
415
  const tab = tabs.find((t) => t.plugin.name === name);
387
416
  const el = given.isConnected ? given : (sameAs(given)[0] ?? undefined);
@@ -395,6 +424,7 @@ export function start({ base, shortcut: own, plugins: given }: StartOptions): vo
395
424
 
396
425
  interface PanelOptions {
397
426
  base: string;
427
+ send: Send;
398
428
  root: ShadowRoot;
399
429
  contextOf: (name: string) => ClientContext;
400
430
  tabs: Tab[];
@@ -418,6 +448,7 @@ interface PanelOptions {
418
448
 
419
449
  function openPanel({
420
450
  base,
451
+ send,
421
452
  root,
422
453
  contextOf,
423
454
  tabs,
@@ -452,7 +483,7 @@ function openPanel({
452
483
  where.href = `${base}__deictic/open?${new URLSearchParams(at)}`;
453
484
  where.addEventListener('click', (e) => {
454
485
  e.preventDefault();
455
- void fetch(where.href);
486
+ void send(where.href);
456
487
  });
457
488
  // Off until the tab's history is read: there's nothing to take back on most elements.
458
489
  const undo = iconButton(UNDO, 'Undo', 'Nothing to undo');
@@ -469,6 +500,9 @@ function openPanel({
469
500
  close.classList.add('close');
470
501
  head.append(...buttons.map((b) => b.el), close);
471
502
  bar.append(where, undo, redo);
503
+ // Back from `away` on a page that doesn't have the element: said, as nothing on it is outlined.
504
+ if (!element.isConnected)
505
+ where.after(Object.assign(document.createElement('span'), { className: 'absent', textContent: 'not on this page' }));
472
506
  const body = div('body');
473
507
  body.setAttribute('role', 'tabpanel');
474
508
  const status = div('status');
@@ -487,7 +521,7 @@ function openPanel({
487
521
  status.classList.toggle('problem', problem);
488
522
  };
489
523
  const post = async <T>(route: string, body?: unknown): Promise<T> => {
490
- const res = await fetch(`${base}__deictic/${route}`, {
524
+ const res = await send(`${base}__deictic/${route}`, {
491
525
  method: 'POST',
492
526
  headers: { 'content-type': 'application/json' },
493
527
  body: JSON.stringify(body ?? {}),
@@ -521,7 +555,7 @@ function openPanel({
521
555
  const ask = ++asked;
522
556
  let history: { done: { label: string }[]; undone: { label: string }[] };
523
557
  try {
524
- const res = await fetch(`${base}__deictic/history?${new URLSearchParams({ plugin: current.plugin.name, ...at })}`);
558
+ const res = await send(`${base}__deictic/history?${new URLSearchParams({ plugin: current.plugin.name, ...at })}`);
525
559
  if (!res.ok || ask !== asked) return;
526
560
  history = (await res.json()) as typeof history;
527
561
  } catch {
@@ -603,9 +637,15 @@ function openPanel({
603
637
  away: (state, task) => {
604
638
  const tab = current;
605
639
  done(true);
640
+ // For the tab's next page too, should this one go before the task is done. Not one a page pinned: that's the page's own.
641
+ if (!pinned) keepAway({ tab: tab.plugin.name, target, state });
642
+ const back = (resumed: Resumed) => {
643
+ if (!pinned) dropAway();
644
+ reopen(tab, element, resumed);
645
+ };
606
646
  void task().then(
607
- (result) => reopen(tab, element, { state, result }),
608
- (e: unknown) => reopen(tab, element, { state, problem: messageOf(e) }),
647
+ (result) => back({ state, result }),
648
+ (e: unknown) => back({ state, problem: messageOf(e) }),
609
649
  );
610
650
  },
611
651
  element,
@@ -702,7 +742,11 @@ function keepInView(panel: HTMLElement, body: HTMLElement, handle: HTMLElement,
702
742
  let timer: ReturnType<typeof setTimeout> | undefined;
703
743
  // Where the element was last seen: one gone from the page leaves the popup where it was.
704
744
  let r = element.getBoundingClientRect();
705
- let moved: { left: number; top: number } | undefined;
745
+ // An element that's not on the page (back from `away`, on another) has no place to be beside: as if dragged to the
746
+ // middle, toward the top.
747
+ let moved: { left: number; top: number } | undefined = element.isConnected
748
+ ? undefined
749
+ : { left: (document.documentElement.clientWidth - panel.offsetWidth) / 2, top: document.documentElement.clientHeight / 5 };
706
750
  const fit = () => {
707
751
  cancelAnimationFrame(frame);
708
752
  clearTimeout(timer);
@@ -105,6 +105,7 @@ export const STYLE = `
105
105
  .bar .where svg { flex: none; }
106
106
  .bar .where:hover, .bar .where:focus-visible { color: var(--deictic-fg); }
107
107
  .bar .where:hover span { text-decoration: underline; }
108
+ .bar .absent { flex: none; margin-right: 6px; font-size: 12px; color: var(--deictic-muted); }
108
109
  .lightbox {
109
110
  position: fixed;
110
111
  inset: 0;
package/src/index.ts CHANGED
@@ -59,6 +59,13 @@ export interface Source {
59
59
  read(file: string): string;
60
60
  }
61
61
 
62
+ /**
63
+ * What answers the overlay's requests in a page with no dev server behind it (`deictic/vite`'s `standalone`): the
64
+ * default export of a module of the page's. A request is one the endpoints would get, under `<base>__deictic/`;
65
+ * the answer is theirs too (`{ model }`, `{ model, change }`, `{ problem }` with a status that isn't ok).
66
+ */
67
+ export type Standalone = (request: Request) => Response | Promise<Response>;
68
+
62
69
  /** An op a plugin won't make. The message says why and what to do instead; the panel shows it. */
63
70
  export class Refusal extends Error {
64
71
  override name = 'Refusal';
@@ -184,7 +191,11 @@ export interface LightboxOptions {
184
191
  }
185
192
 
186
193
  export interface PanelContext<Model, Op> extends ClientContext {
187
- /** The element clicked: the one the source marked, under the pointer or around what is. */
194
+ /**
195
+ * The element clicked: the one the source marked, under the pointer or around what is. Back from `away`
196
+ * it may be off the page (`isConnected` is false), where the page moved on without it: the element as it
197
+ * was left, or after a page load an empty one of its tag and mark. `elements` is then empty.
198
+ */
188
199
  element: Element;
189
200
  /**
190
201
  * What was under the pointer, where it isn't `element` but inside it: markup nothing marked, as a
@@ -208,7 +219,9 @@ export interface PanelContext<Model, Op> extends ClientContext {
208
219
  * Leaves the popup to do something on the page, then comes back: closes it, runs `task` (a recording, a
209
220
  * pick of another element), and opens it again at this tab on this element. The next mount gets
210
221
  * `resumed`: the `state` kept now (what was typed, what's attached), and what `task` answered, or why
211
- * it failed. The state stays in the page, as it is: no need for JSON.
222
+ * it failed. The state stays in the page, as it is: no need for JSON. It's also kept for the tab's next
223
+ * page, as a structured clone, where it can be one: after a page load, the plugin's `resume` says whether
224
+ * the task carries on, and the popup comes back there.
212
225
  */
213
226
  away: <T>(state: unknown, task: () => Promise<T>) => void;
214
227
  /** Set when this mount is the panel coming back from `away`. */
@@ -233,6 +246,12 @@ export interface ClientPlugin<Model = unknown, Op = unknown, Api = unknown> {
233
246
  * plugin's API to the others in the page, at once: one that needs time keeps its promises inside it.
234
247
  */
235
248
  setup?(context: ClientContext): Api;
249
+ /**
250
+ * Asked as a page starts where the page before it left this plugin's panel `away`: the task it left for,
251
+ * where that carries on in this page (a recording does), or nothing where it ended with the page. When it's
252
+ * done the popup opens at this tab with `resumed`, on the element where this page has it and without where not.
253
+ */
254
+ resume?(context: ClientContext): Promise<unknown> | undefined;
236
255
  /** Draws into `panel`, inside deictic's shadow root. Returns what to undo on the page when the panel closes. */
237
256
  mount?: (panel: HTMLElement, context: PanelContext<Model, Op>) => (() => void) | void;
238
257
  }
@@ -0,0 +1,18 @@
1
+ /** The logs plugin's page half: rrweb's console plugin, imported as a recording first asks for it. */
2
+ import { defineClientPlugin } from '#src/index.ts';
3
+ import type { Recorded } from '#src/plugins/recordings/index.ts';
4
+
5
+ import type { Level } from './index.ts';
6
+
7
+ export default defineClientPlugin<never, never, Recorded>({
8
+ name: 'logs',
9
+ setup: ({ options }) => ({
10
+ plugin: async () => {
11
+ const { getRecordConsolePlugin } = await import('@rrweb/rrweb-plugin-console-record').catch((e: unknown) => {
12
+ throw new Error('logs needs @rrweb/rrweb-plugin-console-record: add it to your devDependencies', { cause: e });
13
+ });
14
+ const { levels } = (options ?? {}) as { levels?: Level[] };
15
+ return getRecordConsolePlugin(levels === undefined ? {} : { level: levels });
16
+ },
17
+ }),
18
+ });
@@ -0,0 +1,55 @@
1
+ /**
2
+ * `deictic/logs`: what the page logs while it's recorded, and the errors nothing caught, in the recording, each at
3
+ * its moment. No tab, and nothing of its own: it hands the recordings plugin rrweb's console plugin
4
+ * (`@rrweb/rrweb-plugin-console-record`, an optional peer), whose events are rrweb's (`rrweb/console@1`).
5
+ *
6
+ * A wrapped console names the wrapper, not the caller, as each line's source in the browser's tools. rrweb wraps it
7
+ * as a recording starts and puts it back as it stops, so it's the page's own the rest of the time. Leave the plugin
8
+ * out and it never is.
9
+ */
10
+ import { definePlugin } from '#src/index.ts';
11
+ import type { Recorded } from '#src/plugins/recordings/index.ts';
12
+
13
+ /** What of the console is kept: its methods, by name. */
14
+ export type Level =
15
+ | 'assert'
16
+ | 'count'
17
+ | 'countReset'
18
+ | 'debug'
19
+ | 'dir'
20
+ | 'dirxml'
21
+ | 'error'
22
+ | 'group'
23
+ | 'groupCollapsed'
24
+ | 'info'
25
+ | 'log'
26
+ | 'table'
27
+ | 'time'
28
+ | 'timeEnd'
29
+ | 'timeLog'
30
+ | 'trace'
31
+ | 'warn';
32
+
33
+ export interface LogsOptions {
34
+ /**
35
+ * The console's methods kept, `['warn', 'error']` for the least: every one that says something by default. Errors
36
+ * nothing caught, and rejections nothing handled, come with `error`.
37
+ */
38
+ levels?: Level[];
39
+ }
40
+
41
+ declare module 'deictic' {
42
+ interface ClientApis {
43
+ logs: Recorded;
44
+ }
45
+ }
46
+
47
+ export function logs(options: LogsOptions = {}) {
48
+ return definePlugin<never, never>({
49
+ name: 'logs',
50
+ client: 'deictic/logs/client',
51
+ clientOptions: { levels: options.levels },
52
+ });
53
+ }
54
+
55
+ export default logs;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The network plugin's page half: rrweb's network plugin, imported as a recording first asks for it, with every
3
+ * request masked before rrweb has it.
4
+ */
5
+ import { defineClientPlugin } from '#src/index.ts';
6
+ import type { Recorded } from '#src/plugins/recordings/index.ts';
7
+
8
+ import type { Resolved } from './index.ts';
9
+ import { maskRequest } from './mask.ts';
10
+
11
+ export default defineClientPlugin<never, never, Recorded>({
12
+ name: 'network',
13
+ setup: ({ options }) => ({
14
+ plugin: async ({ sinceLoad }) => {
15
+ const { getRecordNetworkPlugin } = await import('@rrweb/rrweb-plugin-network-record').catch((e: unknown) => {
16
+ throw new Error('network needs @rrweb/rrweb-plugin-network-record: add it to your devDependencies', { cause: e });
17
+ });
18
+ const { initiators, headers, body, mask, ignore } = options as Resolved;
19
+ type Options = NonNullable<Parameters<typeof getRecordNetworkPlugin>[0]>;
20
+ return getRecordNetworkPlugin({
21
+ initiatorTypes: initiators as NonNullable<Options['initiatorTypes']>,
22
+ recordHeaders: headers,
23
+ recordBody: body,
24
+ // What the page asked for as it loaded, where the recording was going by then: before, it's not the recording's.
25
+ recordInitialRequests: sinceLoad,
26
+ transformRequestFn: (request) => maskRequest(request, { mask, ignore }),
27
+ });
28
+ },
29
+ }),
30
+ });
@@ -0,0 +1,69 @@
1
+ /**
2
+ * `deictic/network`: the requests the page makes while it's recorded, in the recording, each as it ends. No tab,
3
+ * and nothing of its own: it hands the recordings plugin rrweb's network plugin
4
+ * (`@rrweb/rrweb-plugin-network-record`, an optional peer), whose events are rrweb's (`rrweb/network@1`).
5
+ *
6
+ * By default a request is its URL, its status and its timing, which the browser reports of itself
7
+ * (`PerformanceObserver`): nothing of the page's is wrapped, and no method is known. `headers` and `body` add those
8
+ * and the method, for which rrweb wraps `fetch` and `XMLHttpRequest` while a recording is going, and only then.
9
+ *
10
+ * Everything kept is masked first (`mask.ts`): a secret in a URL's query, a header or a body's field is blanked by
11
+ * its name, and deictic's own requests are left out.
12
+ */
13
+ import { definePlugin } from '#src/index.ts';
14
+ import type { Recorded } from '#src/plugins/recordings/index.ts';
15
+
16
+ export { MASKED, maskBody, maskHeaders, maskRequest, maskUrl, sensitive } from './mask.ts';
17
+
18
+ export interface NetworkOptions {
19
+ /**
20
+ * What made the requests kept, as the browser names it (a resource's `initiatorType`): `['fetch',
21
+ * 'xmlhttprequest']` by default, the page's own calls. `'img'`, `'script'`, `'css'` and the like add what it loads.
22
+ */
23
+ initiators?: string[];
24
+ /** Keeps each request's and response's headers, the secret ones blanked (`Authorization`, `Cookie`, …): not by default. */
25
+ headers?: boolean;
26
+ /**
27
+ * Keeps each request's and response's body, cut at 10,000 characters, secrets blanked by name where it's JSON or a
28
+ * form's fields: not by default. `true` is JSON, text and forms; a list names the content types, by a part of each.
29
+ */
30
+ body?: boolean | string[];
31
+ /** More names whose values are blanked, in a query, a header or a body: a part of the name, in any case (`['email']`). */
32
+ mask?: string[];
33
+ /** Requests left out whole: a part of the URL (`['/analytics', 'sentry.io']`). */
34
+ ignore?: string[];
35
+ }
36
+
37
+ /** The options as the page half gets them. */
38
+ export interface Resolved {
39
+ initiators: string[];
40
+ headers: boolean;
41
+ body: false | string[];
42
+ mask: string[];
43
+ ignore: string[];
44
+ }
45
+
46
+ declare module 'deictic' {
47
+ interface ClientApis {
48
+ network: Recorded;
49
+ }
50
+ }
51
+
52
+ /** The bodies kept with `body: true`: what reads as text. */
53
+ const TEXT = ['application/json', '+json', 'text/', 'application/x-www-form-urlencoded', 'application/xml'];
54
+
55
+ export function network(options: NetworkOptions = {}) {
56
+ return definePlugin<never, never>({
57
+ name: 'network',
58
+ client: 'deictic/network/client',
59
+ clientOptions: {
60
+ initiators: options.initiators ?? ['fetch', 'xmlhttprequest'],
61
+ headers: options.headers ?? false,
62
+ body: options.body === true ? TEXT : (options.body ?? false),
63
+ mask: options.mask ?? [],
64
+ ignore: options.ignore ?? [],
65
+ } satisfies Resolved,
66
+ });
67
+ }
68
+
69
+ export default network;
@@ -0,0 +1,133 @@
1
+ /**
2
+ * What a request is kept as: with what it carries that's a secret blanked, wherever a name says so. The
3
+ * names are all there is to go by, so a secret under a name that says nothing (a token in a path, a password in
4
+ * prose) isn't found: bodies and headers are kept only where asked for, and `ignore` leaves a request out whole.
5
+ */
6
+
7
+ /** A request as rrweb's network plugin has it: all this reads of one, and changes. */
8
+ export interface Request {
9
+ name: string;
10
+ requestHeaders?: Record<string, string>;
11
+ responseHeaders?: Record<string, string>;
12
+ requestBody?: string | null;
13
+ responseBody?: string | null;
14
+ }
15
+
16
+ export interface Masking {
17
+ /** More names whose values are blanked, as these are: a part of the name, in any case. */
18
+ mask: string[];
19
+ /** Requests left out: a part of the URL. */
20
+ ignore: string[];
21
+ }
22
+
23
+ /** What a blanked value reads as. */
24
+ export const MASKED = '***';
25
+ /** What's kept of a body at most, in characters. */
26
+ const BODY = 10_000;
27
+
28
+ /** A name with one of these in it holds a secret, in any case: `access_token`, `X-Api-Key`, `Set-Cookie`. */
29
+ const PARTS = [
30
+ 'token',
31
+ 'secret',
32
+ 'passw',
33
+ 'pwd',
34
+ 'auth',
35
+ 'cookie',
36
+ 'session',
37
+ 'credential',
38
+ 'signature',
39
+ 'apikey',
40
+ 'api-key',
41
+ 'api_key',
42
+ 'jwt',
43
+ 'otp',
44
+ 'cvv',
45
+ 'cvc',
46
+ 'ssn',
47
+ 'cardnumber',
48
+ 'card_number',
49
+ ];
50
+ /** And these whole names, too short to look for inside others: `code` is OAuth's, on its way back. */
51
+ const NAMES = new Set(['key', 'pass', 'code', 'pin', 'sig', 'sid']);
52
+ /** deictic's own requests: a recording sends itself as it goes, which would be a request to record each second. */
53
+ const OURS = '/__deictic/';
54
+
55
+ export const sensitive = (name: string, more: readonly string[] = []): boolean => {
56
+ const lower = name.toLowerCase();
57
+ return NAMES.has(lower) || PARTS.some((part) => lower.includes(part)) || more.some((part) => lower.includes(part.toLowerCase()));
58
+ };
59
+
60
+ function maskParams(params: URLSearchParams, more: readonly string[]): boolean {
61
+ let changed = false;
62
+ for (const name of new Set(params.keys())) {
63
+ if (!sensitive(name, more)) continue;
64
+ params.set(name, MASKED);
65
+ changed = true;
66
+ }
67
+ return changed;
68
+ }
69
+
70
+ /** The URL without a name and password before its host, and with its secrets blanked: the query's, and a fragment's that reads as one. */
71
+ export function maskUrl(url: string, more: readonly string[] = []): string {
72
+ let parsed: URL;
73
+ try {
74
+ parsed = new URL(url);
75
+ } catch {
76
+ // Not one this can read: kept as it is, as there's no telling its parts.
77
+ return url;
78
+ }
79
+ let changed = parsed.username !== '' || parsed.password !== '';
80
+ parsed.username = parsed.password = '';
81
+ if (maskParams(parsed.searchParams, more)) changed = true;
82
+ if (parsed.hash.includes('=')) {
83
+ const fragment = new URLSearchParams(parsed.hash.slice(1));
84
+ if (maskParams(fragment, more)) {
85
+ parsed.hash = fragment.toString();
86
+ changed = true;
87
+ }
88
+ }
89
+ // As it was written where nothing changed: a parsed URL spells some things its own way.
90
+ return changed ? parsed.href.replaceAll(encodeURIComponent(MASKED), MASKED) : url;
91
+ }
92
+
93
+ export function maskHeaders(headers: Record<string, string>, more: readonly string[] = []): Record<string, string> {
94
+ return Object.fromEntries(Object.entries(headers).map(([name, value]) => [name, sensitive(name, more) ? MASKED : value]));
95
+ }
96
+
97
+ function maskJson(value: unknown, more: readonly string[]): unknown {
98
+ if (Array.isArray(value)) return value.map((item) => maskJson(item, more));
99
+ if (typeof value !== 'object' || value === null) return value;
100
+ return Object.fromEntries(Object.entries(value).map(([name, inner]) => [name, sensitive(name, more) ? MASKED : maskJson(inner, more)]));
101
+ }
102
+
103
+ /** A body with its secrets blanked where it's JSON or a form's fields, cut where it's long: other text has no names to go by. */
104
+ export function maskBody(body: string, more: readonly string[] = []): string {
105
+ const cut = (text: string) => (text.length > BODY ? `${text.slice(0, BODY)}… (${text.length} characters)` : text);
106
+ const text = body.trim();
107
+ if (text.startsWith('{') || text.startsWith('[')) {
108
+ try {
109
+ return cut(JSON.stringify(maskJson(JSON.parse(text), more)));
110
+ } catch {
111
+ // Not JSON after all.
112
+ }
113
+ }
114
+ // A form's fields: `name=value&…`, with nothing a sentence would have.
115
+ if (/^[^\s=&]+=[^\s&]*(&[^\s=&]+=[^\s&]*)*$/.test(text)) {
116
+ const fields = new URLSearchParams(text);
117
+ if (maskParams(fields, more)) return cut(fields.toString().replaceAll(encodeURIComponent(MASKED), MASKED));
118
+ }
119
+ return cut(body);
120
+ }
121
+
122
+ /** The request as it's kept, or nothing for one left out. */
123
+ export function maskRequest<R extends Request>(request: R, { mask, ignore }: Masking): R | undefined {
124
+ if (request.name.includes(OURS) || ignore.some((part) => request.name.includes(part))) return undefined;
125
+ return {
126
+ ...request,
127
+ name: maskUrl(request.name, mask),
128
+ ...(request.requestHeaders ? { requestHeaders: maskHeaders(request.requestHeaders, mask) } : {}),
129
+ ...(request.responseHeaders ? { responseHeaders: maskHeaders(request.responseHeaders, mask) } : {}),
130
+ ...(typeof request.requestBody === 'string' ? { requestBody: maskBody(request.requestBody, mask) } : {}),
131
+ ...(typeof request.responseBody === 'string' ? { responseBody: maskBody(request.responseBody, mask) } : {}),
132
+ };
133
+ }
@@ -1,12 +1,15 @@
1
1
  /**
2
2
  * `deictic/recommended`: the plugins for describing a change rather than making it. Alt-click an element, say what
3
3
  * should change, attach a screenshot to draw on, a screen recording or your voice, and it goes to a Vercel Board.
4
+ * A recording has the page's console and its requests in it too.
4
5
  *
5
6
  * Only the server halves, as every factory is: each names its page half, which the integration imports. A plugin
6
7
  * outside the preset (Tailwind, your own) goes beside it: `plugins: [...recommended(), tailwind()]`.
7
8
  */
8
9
  import type { ServerPlugin } from '#src/index.ts';
9
10
  import { annotations, type AnnotationsOptions } from '#src/plugins/annotations/index.ts';
11
+ import { logs, type LogsOptions } from '#src/plugins/logs/index.ts';
12
+ import { network, type NetworkOptions } from '#src/plugins/network/index.ts';
10
13
  import { recordings, type RecordingsOptions } from '#src/plugins/recordings/index.ts';
11
14
  import { screenshots, type ScreenshotsOptions } from '#src/plugins/screenshots/index.ts';
12
15
  import { tasks, type TasksOptions } from '#src/plugins/tasks/index.ts';
@@ -19,9 +22,16 @@ export interface RecommendedOptions {
19
22
  annotations?: AnnotationsOptions | false;
20
23
  recordings?: RecordingsOptions | false;
21
24
  voice?: VoiceOptions | false;
25
+ /** The console's lines in a recording. */
26
+ logs?: LogsOptions | false;
27
+ /** The page's requests in a recording, masked. */
28
+ network?: NetworkOptions | false;
22
29
  }
23
30
 
24
- /** Tasks, screenshots, annotations, recordings and voice, in that order: the order of their tabs. */
31
+ /**
32
+ * Tasks, screenshots, annotations, recordings and voice, in that order, the order of their tabs, then what a
33
+ * recording has besides the page: logs and network.
34
+ */
25
35
  export function recommended(options: RecommendedOptions = {}): ServerPlugin[] {
26
36
  const plugins: ServerPlugin[] = [];
27
37
  if (options.tasks !== false) plugins.push(tasks(options.tasks));
@@ -29,6 +39,9 @@ export function recommended(options: RecommendedOptions = {}): ServerPlugin[] {
29
39
  if (options.annotations !== false) plugins.push(annotations(options.annotations));
30
40
  if (options.recordings !== false) plugins.push(recordings(options.recordings));
31
41
  if (options.voice !== false) plugins.push(voice(options.voice));
42
+ // Nothing without recordings to be in.
43
+ if (options.recordings !== false && options.logs !== false) plugins.push(logs(options.logs));
44
+ if (options.recordings !== false && options.network !== false) plugins.push(network(options.network));
32
45
  return plugins;
33
46
  }
34
47