deictic 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/API.md +71 -17
  2. package/README.md +1 -1
  3. package/dist/annotations/client.js +1 -1
  4. package/dist/cli.js +1 -1
  5. package/dist/cli.js.map +1 -1
  6. package/dist/client/index.d.ts +13 -13
  7. package/dist/client/index.d.ts.map +1 -1
  8. package/dist/client/index.js +11 -7
  9. package/dist/client/index.js.map +1 -1
  10. package/dist/react/client.d.ts +19 -0
  11. package/dist/react/client.d.ts.map +1 -0
  12. package/dist/react/client.js +504 -0
  13. package/dist/react/client.js.map +1 -0
  14. package/dist/react/index.d.ts +2 -0
  15. package/dist/react/index.js +1 -0
  16. package/dist/recommended/index.d.ts +15 -7
  17. package/dist/recommended/index.d.ts.map +1 -1
  18. package/dist/recommended/index.js +1 -1
  19. package/dist/recordings/client.d.ts.map +1 -1
  20. package/dist/recordings/client.js +48 -5
  21. package/dist/recordings/client.js.map +1 -1
  22. package/dist/screenshots/client.d.ts +9 -1
  23. package/dist/screenshots/client.d.ts.map +1 -1
  24. package/dist/screenshots/rrweb.d.ts +0 -6
  25. package/dist/screenshots/rrweb.d.ts.map +1 -1
  26. package/dist/screenshots/rrweb.js +46 -12
  27. package/dist/screenshots/rrweb.js.map +1 -1
  28. package/dist/shared/board.js +1 -1
  29. package/dist/shared/client.js +44 -2
  30. package/dist/shared/client.js.map +1 -1
  31. package/dist/shared/dom.js +7 -1
  32. package/dist/shared/dom.js.map +1 -1
  33. package/dist/shared/drawer.js +1 -1
  34. package/dist/shared/endpoints.js +1 -1
  35. package/dist/shared/index.d.ts +6 -0
  36. package/dist/shared/index.d.ts.map +1 -1
  37. package/dist/shared/index10.d.ts +70 -0
  38. package/dist/shared/index10.d.ts.map +1 -0
  39. package/dist/shared/index3.d.ts +11 -0
  40. package/dist/shared/index3.d.ts.map +1 -1
  41. package/dist/shared/index7.d.ts +92 -312
  42. package/dist/shared/index7.d.ts.map +1 -1
  43. package/dist/shared/index8.d.ts +324 -47
  44. package/dist/shared/index8.d.ts.map +1 -1
  45. package/dist/shared/index9.d.ts +45 -63
  46. package/dist/shared/index9.d.ts.map +1 -1
  47. package/dist/shared/init.js +15 -11
  48. package/dist/shared/init.js.map +1 -1
  49. package/dist/shared/marks.js +7 -1
  50. package/dist/shared/marks.js.map +1 -1
  51. package/dist/shared/package.js +3 -1
  52. package/dist/shared/packages.js +1 -1
  53. package/dist/shared/playwright.js +39 -1
  54. package/dist/shared/playwright.js.map +1 -1
  55. package/dist/shared/react.js +25 -0
  56. package/dist/shared/react.js.map +1 -0
  57. package/dist/shared/recommended.js +6 -3
  58. package/dist/shared/recommended.js.map +1 -1
  59. package/dist/shared/recording.js +80 -3
  60. package/dist/shared/recording.js.map +1 -1
  61. package/dist/shared/recordings.js +30 -2
  62. package/dist/shared/recordings.js.map +1 -1
  63. package/dist/shared/screenshots.js.map +1 -1
  64. package/dist/shared/src.js.map +1 -1
  65. package/dist/shared/task.js +1 -0
  66. package/dist/shared/task.js.map +1 -1
  67. package/dist/shared/tasks.js +11 -0
  68. package/dist/shared/tasks.js.map +1 -1
  69. package/dist/tailwind/client.d.ts +1 -1
  70. package/dist/tailwind/index.d.ts +1 -1
  71. package/dist/tasks/client.d.ts +1 -1
  72. package/dist/tasks/client.js +45 -19
  73. package/dist/tasks/client.js.map +1 -1
  74. package/dist/tasks/index.d.ts +1 -1
  75. package/dist/voice/client.d.ts +1 -1
  76. package/dist/voice/client.js +1 -1
  77. package/dist/voice/index.d.ts +1 -1
  78. package/package.json +25 -1
  79. package/src/cli/bun.ts +2 -2
  80. package/src/cli/init.ts +14 -9
  81. package/src/cli/recording.ts +90 -4
  82. package/src/cli/task.ts +4 -0
  83. package/src/cli.ts +13 -6
  84. package/src/client/dom.ts +14 -0
  85. package/src/client/index.ts +21 -14
  86. package/src/index.ts +6 -0
  87. package/src/plugins/react/client.ts +162 -0
  88. package/src/plugins/react/index.ts +130 -0
  89. package/src/plugins/react/renders.ts +219 -0
  90. package/src/plugins/react/serialize.ts +139 -0
  91. package/src/plugins/react/timeline.ts +143 -0
  92. package/src/plugins/recommended/index.ts +17 -5
  93. package/src/plugins/recordings/client.ts +64 -4
  94. package/src/plugins/recordings/marks.ts +7 -0
  95. package/src/plugins/recordings/replay.ts +30 -2
  96. package/src/plugins/screenshots/client.ts +42 -2
  97. package/src/plugins/screenshots/index.ts +11 -0
  98. package/src/plugins/screenshots/playwright.ts +65 -1
  99. package/src/plugins/screenshots/rrweb.ts +55 -28
  100. package/src/plugins/screenshots/states.ts +26 -0
  101. package/src/plugins/tasks/client.ts +41 -6
  102. package/src/plugins/tasks/composer.ts +24 -7
  103. package/src/plugins/tasks/index.ts +16 -2
@@ -1,2 +1,2 @@
1
- import { C as local, S as LocalOptions, _ as TasksOptions, a as Kept, b as tasks, c as Model, d as Placed, f as Removed, g as TaskBoard, h as TaskAdded, i as Edited, l as Op, m as Task, n as Answer, o as Listed, p as Reply, r as Attached, s as Marks, t as Added, u as Place, v as Thread, x as LocalBoard, y as Which } from "../shared/index7.js";
1
+ import { C as local, S as LocalOptions, _ as TasksOptions, a as Kept, b as tasks, c as Model, d as Placed, f as Removed, g as TaskBoard, h as TaskAdded, i as Edited, l as Op, m as Task, n as Answer, o as Listed, p as Reply, r as Attached, s as Marks, t as Added, u as Place, v as Thread, x as LocalBoard, y as Which } from "../shared/index8.js";
2
2
  export { Added, Answer, Attached, Edited, Kept, Listed, type LocalBoard, type LocalOptions, Marks, Model, Op, Place, Placed, Removed, Reply, Task, TaskAdded, TaskBoard, TasksOptions, Thread, Which, tasks as default, tasks, local };
@@ -1,4 +1,4 @@
1
- import { i as Voice } from "../shared/index8.js";
1
+ import { i as Voice } from "../shared/index9.js";
2
2
  declare const _default: import("deictic").ClientPlugin<never, never, Voice>;
3
3
  export { _default as default };
4
4
  //# sourceMappingURL=client.d.ts.map
@@ -1,4 +1,4 @@
1
- import { u as toolButton } from "../shared/dom.js";
1
+ import { f as toolButton } from "../shared/dom.js";
2
2
  import { n as playMark, r as trayed } from "../shared/drawer.js";
3
3
  import { n as liveWaveform } from "../shared/waveform.js";
4
4
  import { n as defineClientPlugin } from "../shared/src.js";
@@ -1,2 +1,2 @@
1
- import { a as VoiceOptions, i as Voice, n as Clips, o as voice, r as Take, t as Clip } from "../shared/index8.js";
1
+ import { a as VoiceOptions, i as Voice, n as Clips, o as voice, r as Take, t as Clip } from "../shared/index9.js";
2
2
  export { Clip, Clips, Take, Voice, VoiceOptions, voice as default, voice };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deictic",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "description": "Point at an element in your running app and leave a task about it for your agent.",
5
5
  "keywords": [
6
6
  "annotations",
@@ -204,6 +204,20 @@
204
204
  "default": "./dist/network/client.js"
205
205
  }
206
206
  },
207
+ "./react": {
208
+ "deictic@dev": "./src/plugins/react/index.ts",
209
+ "default": {
210
+ "types": "./dist/react/index.d.ts",
211
+ "default": "./dist/react/index.js"
212
+ }
213
+ },
214
+ "./react/client": {
215
+ "deictic@dev": "./src/plugins/react/client.ts",
216
+ "default": {
217
+ "types": "./dist/react/client.d.ts",
218
+ "default": "./dist/react/client.js"
219
+ }
220
+ },
207
221
  "./recommended": {
208
222
  "deictic@dev": "./src/plugins/recommended/index.ts",
209
223
  "default": {
@@ -267,11 +281,13 @@
267
281
  "@rrweb/rrweb-plugin-network-record": "2.2.2",
268
282
  "@rspack/core": "2.3.3",
269
283
  "@types/bun": "^1.4.5",
284
+ "@types/react": "^19.3.0",
270
285
  "@vercel/board": "^0.54.0",
271
286
  "@vitejs/plugin-react": "^6.3.0",
272
287
  "astro": "^7.4.13",
273
288
  "babel-loader": "^10.1.1",
274
289
  "babel-plugin-react-compiler": "^1.0.0",
290
+ "bippy": "0.7.3",
275
291
  "launch-editor": "2.14.2",
276
292
  "modern-screenshot": "^4.7.0",
277
293
  "next": "^16.4.6",
@@ -296,10 +312,12 @@
296
312
  "@rspack/core": ">=1",
297
313
  "@vercel/board": ">=0.53.0",
298
314
  "astro": ">=5",
315
+ "bippy": "^0.7.3",
299
316
  "launch-editor": "^2.9.0",
300
317
  "modern-screenshot": "^4.7.0",
301
318
  "next": ">=16",
302
319
  "playwright-core": "^1.50.0",
320
+ "react": ">=18",
303
321
  "rrweb": "^2.2.2",
304
322
  "rrweb-player": "^2.2.2",
305
323
  "rrweb-snapshot": "^2.2.2",
@@ -322,6 +340,9 @@
322
340
  "astro": {
323
341
  "optional": true
324
342
  },
343
+ "bippy": {
344
+ "optional": true
345
+ },
325
346
  "launch-editor": {
326
347
  "optional": true
327
348
  },
@@ -334,6 +355,9 @@
334
355
  "playwright-core": {
335
356
  "optional": true
336
357
  },
358
+ "react": {
359
+ "optional": true
360
+ },
337
361
  "rrweb": {
338
362
  "optional": true
339
363
  },
package/src/cli/bun.ts CHANGED
@@ -16,11 +16,11 @@ import { addFirst, addImports, eolOf } from './edit.ts';
16
16
  export const MODULE = 'deictic.plugin.ts';
17
17
 
18
18
  export const PLUGIN = `import { deictic } from 'deictic/bun';
19
- import { recommended } from 'deictic/recommended';
19
+ import { deicticRecommended } from 'deictic/recommended';
20
20
 
21
21
  // One module for both: bunfig.toml names it as the dev server's bundler plugin, and the server spreads its routes,
22
22
  // deictic's endpoints, into its own.
23
- export default deictic({ plugins: recommended() });
23
+ export default deictic({ plugins: deicticRecommended() });
24
24
  `;
25
25
 
26
26
  const SOURCE = /\.[cm]?[jt]sx?$/;
package/src/cli/init.ts CHANGED
@@ -12,9 +12,9 @@ import { createInterface } from 'node:readline/promises';
12
12
  import MagicString from 'magic-string';
13
13
  import { type Expression, type ObjectExpression, parseSync, type Program } from 'oxc-parser';
14
14
 
15
- import { recommended } from '#src/plugins/recommended/index.ts';
15
+ import { deicticRecommended } from '#src/plugins/recommended/index.ts';
16
16
 
17
- import { installCommand, packageManager, readJson, runnerOf } from '#src/tools/packages.ts';
17
+ import { installCommand, installed, packageManager, readJson, runnerOf } from '#src/tools/packages.ts';
18
18
 
19
19
  import { fail } from './board.ts';
20
20
  import { addToBunfig, addToServer, BY_HAND, MODULE, PLUGIN, serverOf } from './bun.ts';
@@ -37,7 +37,7 @@ interface Setup {
37
37
  }
38
38
 
39
39
  const extensions = (base: string) => ['ts', 'mts', 'js', 'mjs', 'cts', 'cjs'].map((e) => `${base}.${e}`);
40
- const PLUGINS = '{ plugins: recommended() }';
40
+ const PLUGINS = '{ plugins: deicticRecommended() }';
41
41
 
42
42
  const SETUPS: Record<Exclude<Bundler, 'bun'>, Setup> = {
43
43
  next: {
@@ -109,9 +109,14 @@ export function bundlerOf(root: string): Bundler | undefined {
109
109
  return undefined;
110
110
  }
111
111
 
112
- /** What the recommended setup imports, for the bundler: launch-editor opens files under webpack, which has no launcher. */
113
- export function packagesFor(bundler: Bundler | undefined): string[] {
114
- const plugins = recommended().flatMap((p) => p.packages ?? []);
112
+ /**
113
+ * What the recommended setup imports, for the bundler and the project: launch-editor opens files under webpack, which
114
+ * has no launcher, and React's state is read only where it has React.
115
+ */
116
+ export function packagesFor(bundler: Bundler | undefined, root: string): string[] {
117
+ // Named in package.json and not installed yet, in a fresh checkout, or installed from a workspace's.
118
+ const react = dependenciesOf(root).has('react') || installed(root, 'react');
119
+ const plugins = deicticRecommended({ react: react ? {} : false }).flatMap((p) => p.packages ?? []);
115
120
  return ['deictic', ...plugins, ...(bundler === 'webpack' || bundler === 'rspack' ? ['launch-editor'] : [])];
116
121
  }
117
122
 
@@ -197,7 +202,7 @@ export function addToConfig(bundler: Exclude<Bundler, 'bun'>, file: string, code
197
202
  }
198
203
 
199
204
  const lines: [string, string][] = [
200
- ['{ recommended }', 'deictic/recommended'],
205
+ ['{ deicticRecommended }', 'deictic/recommended'],
201
206
  [`{ ${setup.name} }`, setup.from],
202
207
  ];
203
208
  addImports(out, program, code, lines, exported.commonjs);
@@ -259,7 +264,7 @@ export async function init(options: InitOptions): Promise<void> {
259
264
  const bundler = bundlerOf(root);
260
265
  const has = dependenciesOf(root);
261
266
 
262
- const wanted = packagesFor(bundler).filter((p) => !has.has(p));
267
+ const wanted = packagesFor(bundler, root).filter((p) => !has.has(p));
263
268
  const command = installCommand(manager, wanted, root);
264
269
  if (wanted.length === 0) {
265
270
  log('deictic: its packages are installed');
@@ -298,7 +303,7 @@ function configure(root: string, bundler: Bundler | undefined, dryRun: boolean,
298
303
  }
299
304
  const setup = SETUPS[bundler];
300
305
  const file = setup.files.map((f) => join(root, f)).find((f) => existsSync(f));
301
- const imports = `import { recommended } from 'deictic/recommended';\nimport { ${setup.name} } from '${setup.from}';`;
306
+ const imports = `import { deicticRecommended } from 'deictic/recommended';\nimport { ${setup.name} } from '${setup.from}';`;
302
307
  if (file === undefined) {
303
308
  log(`deictic: no ${setup.files[0]} here: add deictic to your ${bundler} config:\n\n${imports}\n${setup.snippet}\n`);
304
309
  return;
@@ -1,12 +1,19 @@
1
1
  /**
2
2
  * `deictic recording`: a recording as a timeline: the page, each click and field typed in (with the element's place
3
3
  * in the source), scrolls, resizes, each change to the marks (what was drawn, where, and the notes' text), the voice
4
- * clips, the page's console and its requests where the project records them, and the end. Or the part of it asked
5
- * for: `--only`, `--problems`, `--from`, `--to`, `--around`, `--grep`, and `--full` for all of each line.
4
+ * clips, the page's console and its requests where the project records them, React's commits where the recording had
5
+ * them on, and the end. Or the part of it asked
6
+ * for: `--only`, `--problems`, `--from`, `--to`, `--around`, `--grep`, `--all`, and `--full` for all of each line.
7
+ *
8
+ * Asked for nothing, it's what the person did and what went wrong: the page's requests, its console's lines and
9
+ * React's commits, which a dev server makes hundreds of, are left out where they're not a problem, and counted at
10
+ * the end with what lists them. An agent asks for them where the task needs them. `--json` has every line.
6
11
  */
7
12
  import { relative } from 'node:path';
8
13
 
9
14
  import type { Shape } from '#src/plugins/annotations/index.ts';
15
+ import type { Commit } from '#src/plugins/react/index.ts';
16
+ import { REACT } from '#src/plugins/recordings/marks.ts';
10
17
 
11
18
  import { clock, fail, ME } from './board.ts';
12
19
  import { loadRecording } from './find.ts';
@@ -56,7 +63,7 @@ interface Data {
56
63
  trace?: string[];
57
64
  requests?: Request[];
58
65
  isInitial?: boolean;
59
- };
66
+ } & Partial<Commit> & { on?: boolean };
60
67
  source?: number;
61
68
  type?: number;
62
69
  id?: number;
@@ -91,6 +98,57 @@ interface Line {
91
98
  before?: string;
92
99
  marks?: Shape[];
93
100
  node?: number;
101
+ /** A React commit entry's components, one line each: under it with `--full`. */
102
+ details?: string[];
103
+ }
104
+
105
+ /**
106
+ * The kinds left out of a timeline asked for nothing in particular, where a line of them isn't a problem: a dev
107
+ * server's page makes hundreds of requests (its modules, its hot updates), logs what its tools do, and commits
108
+ * React each frame it animates. Counted, with what lists them.
109
+ */
110
+ const QUIET = [
111
+ { kind: 'request', noun: 'request' },
112
+ { kind: 'console', noun: 'console line' },
113
+ { kind: 'react', noun: 'React line' },
114
+ ];
115
+
116
+ /** A commit past this took longer than a frame: a problem, as it's what makes a page stutter. */
117
+ const FRAME = 16;
118
+
119
+ const ms = (n: number) => `${n < 10 ? n.toFixed(1) : round(n)}ms`;
120
+
121
+ /** A React commit entry, as a line: how long, why it ran, and what rendered, the slowest first. */
122
+ function commitLine(c: Partial<Commit>): Pick<Line, 'text' | 'details' | 'problem'> {
123
+ const components = c.components ?? [];
124
+ const many = (c.commits ?? 1) > 1;
125
+ const head = [
126
+ c.priority,
127
+ many ? `${c.commits} commits${c.over === undefined ? '' : ` over ${(c.over / 1000).toFixed(1)}s`}` : undefined,
128
+ c.slowest === undefined ? undefined : `slowest ${ms(c.slowest)}`,
129
+ ]
130
+ .filter(Boolean)
131
+ .join(', ');
132
+ // One slow commit is what makes a page stutter, not many quick ones.
133
+ const slow = c.slowest ?? c.ms;
134
+ const named = components.map(
135
+ (r) => `${r.name}${(r.count ?? 1) > 1 ? ` ×${r.count}` : ''}${r.selfMs === undefined ? '' : ` ${ms(r.selfMs)}`} (${r.why})`,
136
+ );
137
+ const rest = c.more === undefined ? '' : named.length === 0 ? `${c.more} components` : `, and ${c.more} more`;
138
+ return {
139
+ text: `${c.ms === undefined ? 'commit' : ms(c.ms)}${head === '' ? '' : ` (${head})`}: ${named.join(', ')}${rest}`,
140
+ details: components.map((r) =>
141
+ [
142
+ `${r.name}${(r.count ?? 1) > 1 ? ` ×${r.count}` : ''}`,
143
+ r.at,
144
+ r.ms === undefined ? undefined : `${ms(r.ms)} with what it rendered`,
145
+ r.why,
146
+ ]
147
+ .filter(Boolean)
148
+ .join(' · '),
149
+ ),
150
+ ...(slow !== undefined && slow > FRAME ? { problem: true } : {}),
151
+ };
94
152
  }
95
153
 
96
154
  type Point = { x: number; y: number };
@@ -261,6 +319,10 @@ function timelineOf(events: Event[], voice: { id: string; at: number; duration:
261
319
  });
262
320
  }
263
321
  }
322
+ if (e.type === 5 && d.tag === REACT) {
323
+ if (payload.on !== undefined) push(t, 'react', payload.on ? 'commits recorded from here' : 'commits no longer recorded');
324
+ else push(t, 'react', '', commitLine(payload));
325
+ }
264
326
  if (e.type === 5 && d.tag === 'deictic.end') push(t, 'end', 'recording stopped');
265
327
  if (e.type !== 3) continue;
266
328
  if (d.source === 0) {
@@ -328,6 +390,7 @@ function shortener(page: string): (text: string) => string {
328
390
  export interface Options {
329
391
  nth: string;
330
392
  json?: boolean;
393
+ all?: boolean;
331
394
  only?: string[];
332
395
  problems?: boolean;
333
396
  from?: string;
@@ -358,6 +421,19 @@ export async function run(named: string, values: Options): Promise<void> {
358
421
  const grep = values.grep?.toLowerCase();
359
422
  // `console` is every level's lines, `click` a right or a double one too.
360
423
  const isKind = (kind: string, asked: string) => kind === asked || kind.startsWith(`${asked}.`) || kind.endsWith(`-${asked}`);
424
+ // Asked for nothing in particular: what the person did and what went wrong, the rest counted. A slice of time, a
425
+ // word or kinds asked for are every line of it.
426
+ const whole = values.all === true || only.length > 0 || from !== undefined || to !== undefined || grep !== undefined;
427
+ const left = new Map<string, { count: number; noun: string }>();
428
+ const listed = (e: Line) => {
429
+ if (whole || e.problem === true) return true;
430
+ const quiet = QUIET.find((q) => isKind(e.kind, q.kind));
431
+ if (quiet === undefined) return true;
432
+ const held = left.get(quiet.kind) ?? { count: 0, noun: quiet.noun };
433
+ held.count++;
434
+ left.set(quiet.kind, held);
435
+ return false;
436
+ };
361
437
  const shown = timeline.filter(
362
438
  (e) =>
363
439
  (only.length === 0 || only.some((asked) => isKind(e.kind, asked))) &&
@@ -366,6 +442,8 @@ export async function run(named: string, values: Options): Promise<void> {
366
442
  (to === undefined || e.t <= to) &&
367
443
  (grep === undefined || `${e.kind} ${e.text}`.toLowerCase().includes(grep)),
368
444
  );
445
+ // Not in `--json`, which is for a script, and has every line it was asked for.
446
+ const listing = values.json === true ? shown : shown.filter(listed);
369
447
 
370
448
  const colorScheme = kept.colorScheme ?? 'light';
371
449
  const startedAt = new Date(kept.startedAt ?? events[0]!.timestamp).toISOString();
@@ -378,14 +456,17 @@ export async function run(named: string, values: Options): Promise<void> {
378
456
  console.log(`viewport ${kept.viewport.width}×${kept.viewport.height}, ${colorScheme}, started ${startedAt}`);
379
457
  if (replay !== undefined) console.log(`replays at ${replay} (add ?t=<seconds> to open it paused there)`);
380
458
  if (shown.length < timeline.length) console.log(`${shown.length} of its ${timeline.length} lines, as asked`);
459
+ else if (listing.length < shown.length)
460
+ console.log(`${listing.length} of its ${timeline.length} lines: what the person did, and what went wrong`);
381
461
  console.log();
382
462
  const short = shortener(kept.page);
383
463
  const under = (line: string) => console.log(`${' '.repeat(22)}${short(line)}`);
384
- for (const e of shown) {
464
+ for (const e of listing) {
385
465
  console.log(`${e.at.padStart(6)} ${e.kind.padEnd(13)} ${short(e.text)}`);
386
466
  // Where a warning or an error came from, its nearest few places: all of them, and every line's, with `--full`.
387
467
  if (e.trace && (values.full === true || e.problem === true))
388
468
  for (const line of values.full ? e.trace : e.trace.slice(0, 5)) under(`at ${line}`);
469
+ if (values.full === true) for (const line of e.details ?? []) under(line);
389
470
  if (values.full !== true || e.request === undefined) continue;
390
471
  const r = e.request;
391
472
  if (e.before !== undefined) under(e.before);
@@ -398,6 +479,11 @@ export async function run(named: string, values: Options): Promise<void> {
398
479
  if (r.responseBody !== undefined) under(`response body ${r.responseBody}`);
399
480
  }
400
481
  if (shown.length === 0) console.log(timeline.length === 0 ? 'Nothing in it.' : 'No line of it is what was asked for.');
482
+ if (left.size > 0) {
483
+ const counted = [...left.entries()].map(([kind, { count, noun }]) => `${count} ${noun}${count === 1 ? '' : 's'} (--only ${kind})`);
484
+ console.log(`
485
+ Not listed: ${counted.join(', ')}; --all lists every line, --around <seconds> every line of a moment.`);
486
+ }
401
487
  // Where something went wrong, how to get to it: what led up to it, and what the page looked like.
402
488
  const problems = timeline.filter((e) => e.problem === true).length;
403
489
  if (problems === 0 || shown.length < timeline.length) return;
package/src/cli/task.ts CHANGED
@@ -183,6 +183,10 @@ function attachments(message: Message, out: string | undefined, indent: string,
183
183
  if (task === undefined) console.log(`${indent} ${ME} voice ${/^voice-(.+)\.\w+$/.exec(a.name)?.[1] ?? a.id} (speech)`);
184
184
  } else if (a.name === 'element.html') {
185
185
  console.log(`${indent}${a.name} (${kb}), the element's HTML as it rendered, if you need it${saved}`);
186
+ } else if (/^react(\.\d+)?\.json$/.test(a.name)) {
187
+ console.log(
188
+ `${indent}${a.name} (${kb}), the props, state and hooks of the components that wrote it, as React's DevTools has them, if the change depends on them${saved}`,
189
+ );
186
190
  } else {
187
191
  console.log(`${indent}${a.name} (${kb})${saved}`);
188
192
  }
package/src/cli.ts CHANGED
@@ -85,16 +85,23 @@ program
85
85
 
86
86
  program
87
87
  .command('recording')
88
- .description('a recording as a timeline, or the part of it asked for')
88
+ .description(
89
+ "a recording as a timeline: what the person did and what went wrong, with a count of the page's other requests, console lines and React commits; or the part of it asked for",
90
+ )
89
91
  .argument('<recording>', RECORDING)
90
92
  .option('--nth <n>', "a task's nth recording", '1')
91
- .option('--only <kinds>', 'these kinds of line: console, request, page, click, input, scroll, resize, marks, voice (repeatable)', all)
92
- .option('--problems', 'errors, warnings and requests that failed')
93
+ .option(
94
+ '--only <kinds>',
95
+ 'these kinds of line: console, request, react, page, click, input, scroll, resize, marks, voice (repeatable)',
96
+ all,
97
+ )
98
+ .option('--all', 'every line: every request, console line and React commit too')
99
+ .option('--problems', 'errors, warnings, requests that failed and React commits slower than a frame')
93
100
  .option('--from <seconds>', 'from this far in')
94
101
  .option('--to <seconds>', 'to this far in')
95
- .option('--around <seconds>', 'the 3 seconds either side of this')
96
- .option('--grep <text>', 'lines with this in them, in any case')
97
- .option('--full', "all of each line: where it was logged from, a request's headers and bodies")
102
+ .option('--around <seconds>', 'every line of the 3 seconds either side of this')
103
+ .option('--grep <text>', 'lines with this in them, in any case, of every line')
104
+ .option('--full', "all of each line: where it was logged from, a request's headers and bodies, a React commit's components")
98
105
  .option('--json', 'as JSON')
99
106
  .action(async (ref: string, options) => (await import('./cli/recording.ts')).run(ref, options));
100
107
 
package/src/client/dom.ts CHANGED
@@ -68,3 +68,17 @@ export function controlFor(within: ParentNode, e: KeyboardEvent, loose = false):
68
68
 
69
69
  /** The key held with a letter for a command, as the platform has it, by the name `aria-keyshortcuts` gives it. */
70
70
  export const MOD = typeof navigator !== 'undefined' && /Mac|iP(?:hone|ad)/.test(navigator.platform) ? 'Meta' : 'Control';
71
+
72
+ /**
73
+ * What the page hears on `window` as the popup opens over it on an element (its `detail` a `PopupOpened`) and as
74
+ * it closes: for a page that moves on its own to hold still meanwhile, as deictic's site does. Not for one pinned.
75
+ */
76
+ export const POPUP_OPENED = 'deictic:open';
77
+ export const POPUP_CLOSED = 'deictic:close';
78
+
79
+ export interface PopupOpened {
80
+ /** The element it's open on. */
81
+ element: Element;
82
+ /** The plugin whose tab it opened at. */
83
+ tab: string;
84
+ }
@@ -24,7 +24,7 @@ import { gestureOf, type Shortcut } from '#src/shortcut.ts';
24
24
 
25
25
  import { dropAway, keepAway, keptAway } from './away.ts';
26
26
  import { named, tell } from './component.ts';
27
- import { ATTRIBUTE, div, nameOf, reduced, sameAs, targetOf } from './dom.ts';
27
+ import { ATTRIBUTE, div, nameOf, POPUP_CLOSED, POPUP_OPENED, type PopupOpened, reduced, sameAs, targetOf } from './dom.ts';
28
28
  import { drawerIn } from './drawer.ts';
29
29
  import { openLightbox } from './lightbox.ts';
30
30
  import { CLEAR, type Lighting, spotlight, spotOf } from './lighting.ts';
@@ -98,19 +98,8 @@ interface Started {
98
98
 
99
99
  let started: Started | undefined;
100
100
 
101
- /**
102
- * What the page hears on `window` as the popup opens over it on an element (its `detail` a `PopupOpened`) and as
103
- * it closes: for a page that moves on its own to hold still meanwhile, as deictic's site does. Not for one pinned.
104
- */
105
- export const POPUP_OPENED = 'deictic:open';
106
- export const POPUP_CLOSED = 'deictic:close';
107
-
108
- export interface PopupOpened {
109
- /** The element it's open on. */
110
- element: Element;
111
- /** The plugin whose tab it opened at. */
112
- tab: string;
113
- }
101
+ // The events the page hears as the popup opens and closes: kept beside the mark, where a plugin's page half reads them.
102
+ export { POPUP_CLOSED, POPUP_OPENED, type PopupOpened } from './dom.ts';
114
103
 
115
104
  /**
116
105
  * Opens the popup over the page on `element`, as deictic's own shortcut does: at `tab` (a plugin's name), or at the
@@ -430,6 +419,24 @@ export function start({ base, shortcut: own, plugins: given, server }: StartOpti
430
419
  );
431
420
  let press = {};
432
421
  let opened: object | undefined;
422
+ // The page as it is under the press, for whoever keeps it (`pressed`): before the page's own handlers, which may
423
+ // close what was open, and before the popup takes the pointer and the focus.
424
+ window.addEventListener(
425
+ 'pointerdown',
426
+ (e) => {
427
+ if (e.composedPath().includes(host) || pressedBy(e) === undefined) return;
428
+ const hit = hitAt(e.clientX, e.clientY);
429
+ if (hit === undefined) return;
430
+ for (const { plugin } of given) {
431
+ try {
432
+ plugin.pressed?.(contextOf(plugin.name), hit.el);
433
+ } catch (e) {
434
+ report(failed(plugin.name, 'keep what the page showed as it was pressed', e));
435
+ }
436
+ }
437
+ },
438
+ true,
439
+ );
433
440
  // Alt-click on a link would otherwise download it, and on a field focus it.
434
441
  window.addEventListener(
435
442
  'mousedown',
package/src/index.ts CHANGED
@@ -401,6 +401,12 @@ export interface ClientPlugin<Model = unknown, Op = unknown, Api = unknown> {
401
401
  * plugin pins each task where its element is. Answers what takes it away.
402
402
  */
403
403
  pointing?(context: ClientContext): () => void;
404
+ /**
405
+ * A shortcut's press on a marked element, before the page hears it and before the popup opens: the page as the
406
+ * person saw it, a tooltip still open under the pointer, a menu still focused. Called as the press goes down, so
407
+ * it must be quick; the screenshots plugin keeps what a shot needs here, and renders it later.
408
+ */
409
+ pressed?(context: ClientContext, element: Element): void;
404
410
  /** Draws into `panel`, inside deictic's shadow root. Returns what to undo on the page when the panel closes. */
405
411
  mount?: (panel: HTMLElement, context: PanelContext<Model, Op>) => (() => void) | void;
406
412
  }
@@ -0,0 +1,162 @@
1
+ /**
2
+ * The react plugin's page half: what React's DevTools would show of the components that wrote an element, read off
3
+ * its fibers with bippy (an optional peer, imported as a task first asks for it), for a task to attach.
4
+ */
5
+ import type * as Main from 'bippy';
6
+ import type * as Source from 'bippy/source';
7
+
8
+ import { componentOf, fiberOf, type Owner, ownerOf } from '#src/client/component.ts';
9
+ import { defineClientPlugin } from '#src/index.ts';
10
+
11
+ import type { Commit, Component, Hook, ReactOptions, Snapshot } from './index.ts';
12
+ import { countRenders, type Fiber } from './renders.ts';
13
+ import { serialize } from './serialize.ts';
14
+ import { timeline } from './timeline.ts';
15
+
16
+ /** What a task asks of the plugin, and a recording. */
17
+ export interface Inspector {
18
+ /** The snapshot of the element's components, as the JSON a task attaches: `undefined` where React didn't render it in development. */
19
+ snapshot(el: Element): Promise<string | undefined>;
20
+ /**
21
+ * React's commits from now, an entry a frame (`emit` hears each), until what's answered stops it: for a recording.
22
+ * `undefined` where renders aren't counted (`renders: false`, or no DevTools hook on the page).
23
+ */
24
+ commits?: (emit: (commit: Commit) => void) => () => void;
25
+ }
26
+
27
+ declare module 'deictic' {
28
+ interface ClientApis {
29
+ react: Inspector;
30
+ }
31
+ }
32
+
33
+ /** How long hook names may take: their source, and its map, are fetched from the dev server. */
34
+ const NAMES_WAIT = 3000;
35
+ /** What's attached at most, in characters: a page's values may be its whole store. */
36
+ const MOST = 200_000;
37
+
38
+ /** Hooks whose values are functions to run, which say nothing of what the component shows. */
39
+ const SILENT = new Set(['Effect', 'LayoutEffect', 'InsertionEffect', 'ImperativeHandle', 'EffectEvent']);
40
+
41
+ type Bippy = typeof Main & typeof Source;
42
+
43
+ let loading: Promise<Bippy> | undefined;
44
+
45
+ /**
46
+ * bippy, with a renderer to inspect hooks through. React hands its renderer to DevTools' hook as it loads, which
47
+ * React Refresh (Vite's, Next's) installs first in development; where nothing did, the page's React is asked for its
48
+ * dispatcher, which is all hook inspection needs of one.
49
+ */
50
+ const bippy = (): Promise<Bippy> =>
51
+ (loading ??= (async () => {
52
+ const [main, source] = await Promise.all([import('bippy'), import('bippy/source')]).catch((e: unknown) => {
53
+ loading = undefined;
54
+ throw new Error('react needs bippy: add it to your devDependencies', { cause: e });
55
+ });
56
+ if (main.getRDTHook().renderers.size === 0 && main._renderers.size === 0) {
57
+ const React = (await import('react')) as unknown as Record<string, unknown>;
58
+ const internals = (React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE ??
59
+ (React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as { ReactCurrentDispatcher?: unknown } | undefined)
60
+ ?.ReactCurrentDispatcher) as { H: unknown } | { current: unknown } | undefined;
61
+ if (internals !== undefined) main._renderers.add({ currentDispatcherRef: internals } as never);
62
+ }
63
+ return { ...main, ...source };
64
+ })());
65
+
66
+ const parentOf = (el: Element): Element | undefined => {
67
+ if (el.parentElement !== null) return el.parentElement;
68
+ const root = el.getRootNode();
69
+ return root instanceof ShadowRoot ? root.host : undefined;
70
+ };
71
+
72
+ /** `src/Plan.tsx:12`: where the nearest element around `el` that `owner` wrote is, which is in its JSX. */
73
+ function placeOf(el: Element, owner: Owner): string | undefined {
74
+ for (let at: Element | undefined = el; at !== undefined; at = parentOf(at)) {
75
+ const by = ownerOf(fiberOf(at));
76
+ // A component's fiber is one of two, by turns: an element may name either.
77
+ if (by === undefined || (by !== owner && by !== owner.alternate)) continue;
78
+ const mark = at.getAttribute('data-deictic');
79
+ if (mark !== null) return mark.replace(/:\d+$/, '');
80
+ }
81
+ return undefined;
82
+ }
83
+
84
+ export default defineClientPlugin<never, never, Inspector>({
85
+ name: 'react',
86
+ setup: ({ options }) => {
87
+ const { components = 4, mask = [], names = true, renders = true } = (options ?? {}) as ReactOptions;
88
+ // From now, before any task: what rendered before the page started deictic goes uncounted.
89
+ const counted = renders ? countRenders() : undefined;
90
+ const value = (of: unknown) => serialize(of, mask);
91
+
92
+ /** A hook as DevTools lists it: its kind (`State`, or a custom hook's name less `use`), what the code calls it, its value. */
93
+ const hookOf = (node: Source.HooksNode, named: Map<string, string>): Hook | undefined => {
94
+ if (SILENT.has(node.name)) return undefined;
95
+ const { fileName, lineNumber, columnNumber } = node.hookSource ?? {};
96
+ const as = fileName ? named.get(`${fileName}:${lineNumber ?? 0}:${columnNumber ?? 0}`) : undefined;
97
+ const inner = node.subHooks.flatMap((sub) => hookOf(sub, named) ?? []);
98
+ const read = node.subHooks.length > 0 && node.value === undefined ? undefined : value(node.value);
99
+ return {
100
+ hook: node.name,
101
+ ...(as === undefined ? {} : { as }),
102
+ ...(read === undefined ? {} : { value: read }),
103
+ ...(inner.length === 0 ? {} : { hooks: inner }),
104
+ };
105
+ };
106
+
107
+ return {
108
+ ...(counted === undefined ? {} : { commits: (emit: (commit: Commit) => void) => timeline(counted.subscribe, emit) }),
109
+ snapshot: async (el) => {
110
+ const wrote = ownerOf(fiberOf(el));
111
+ if (wrote === undefined) return undefined;
112
+ const b = await bippy();
113
+ const found: Component[] = [];
114
+ for (let owner: Owner | undefined = wrote; owner !== undefined && found.length < components; owner = ownerOf(owner)) {
115
+ const name = componentOf(owner) ?? 'Anonymous';
116
+ // A server component: it has a name and no fiber, so no props or state the page holds.
117
+ if (typeof owner.name === 'string') {
118
+ found.push({ name, server: true });
119
+ continue;
120
+ }
121
+ const fiber = b.getLatestFiber(owner as never) as unknown as Owner & {
122
+ memoizedProps?: unknown;
123
+ memoizedState?: unknown;
124
+ stateNode?: { state?: unknown } | null;
125
+ };
126
+ const at = placeOf(el, owner);
127
+ const component: Component = { name, ...(at === undefined ? {} : { at }) };
128
+ const props = value(fiber.memoizedProps);
129
+ if (props !== undefined) component.props = props;
130
+ const rendered = counted?.read(fiber as unknown as Fiber);
131
+ if (rendered !== undefined) component.renders = rendered;
132
+ // A class's state is its instance's; a function's is its hooks.
133
+ if (fiber.stateNode !== null && typeof fiber.stateNode === 'object' && 'state' in fiber.stateNode) {
134
+ const state = value(fiber.stateNode.state);
135
+ if (state !== undefined) component.state = state;
136
+ } else {
137
+ try {
138
+ const tree = b.getFiberHooks(fiber as never);
139
+ let named = new Map<string, string>();
140
+ if (names && tree.length > 0) {
141
+ // Read off the source, which may not answer: the hooks go unnamed then.
142
+ named = await b.parseHookNames(tree, undefined, { timeoutMs: NAMES_WAIT }).catch(() => new Map());
143
+ }
144
+ const hooks = tree.flatMap((node) => hookOf(node, named) ?? []);
145
+ if (hooks.length > 0) component.hooks = hooks;
146
+ } catch (e) {
147
+ component.problem = `its hooks couldn't be read: ${e instanceof Error ? e.message : String(e)}`;
148
+ }
149
+ }
150
+ found.push(component);
151
+ }
152
+ if (found.length === 0) return undefined;
153
+ const snapshot: Snapshot = { components: found };
154
+ const json = JSON.stringify(snapshot, null, 2);
155
+ if (json.length <= MOST) return json;
156
+ // Too much: the nearest component's alone, the one that wrote the element.
157
+ const less = JSON.stringify({ components: found.slice(0, 1) } satisfies Snapshot, null, 2);
158
+ return less.length <= MOST ? less : `${less.slice(0, MOST)}\n… cut short`;
159
+ },
160
+ };
161
+ },
162
+ });