@jeffawe/understudy 0.0.0-stage → 0.2.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 (99) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +171 -2
  3. package/REASONER.md +67 -0
  4. package/build/extension/firefox/background.js +186 -0
  5. package/build/extension/firefox/icons/icon-128.png +0 -0
  6. package/build/extension/firefox/icons/icon-16.png +0 -0
  7. package/build/extension/firefox/icons/icon-32.png +0 -0
  8. package/build/extension/firefox/icons/icon-48.png +0 -0
  9. package/build/extension/firefox/manifest.json +54 -0
  10. package/build/extension/firefox/popup.html +52 -0
  11. package/build/extension/firefox/popup.js +106 -0
  12. package/build/extension/firefox/recorder.js +362 -0
  13. package/dist/adapters/recorder/accname-bundle.d.ts +12 -0
  14. package/dist/adapters/recorder/accname-bundle.js +12 -0
  15. package/dist/adapters/recorder/extension.d.ts +57 -0
  16. package/dist/adapters/recorder/extension.js +146 -0
  17. package/dist/adapters/recorder/injected.d.ts +21 -0
  18. package/dist/adapters/recorder/injected.js +352 -0
  19. package/dist/adapters/recorder/live.d.ts +105 -0
  20. package/dist/adapters/recorder/live.js +317 -0
  21. package/dist/adapters/recorder/script.d.ts +43 -0
  22. package/dist/adapters/recorder/script.js +530 -0
  23. package/dist/adapters/recorder/wire.d.ts +42 -0
  24. package/dist/adapters/recorder/wire.js +51 -0
  25. package/dist/core/auth-cache.d.ts +119 -0
  26. package/dist/core/auth-cache.js +216 -0
  27. package/dist/core/browser.d.ts +47 -0
  28. package/dist/core/browser.js +82 -0
  29. package/dist/core/distill.d.ts +118 -0
  30. package/dist/core/distill.js +197 -0
  31. package/dist/core/fingerprint.d.ts +15 -0
  32. package/dist/core/fingerprint.js +21 -0
  33. package/dist/core/recording-store.d.ts +34 -0
  34. package/dist/core/recording-store.js +64 -0
  35. package/dist/core/recording.d.ts +185 -0
  36. package/dist/core/recording.js +100 -0
  37. package/dist/core/replay.d.ts +307 -0
  38. package/dist/core/replay.js +804 -0
  39. package/dist/core/sig.d.ts +70 -0
  40. package/dist/core/sig.js +0 -0
  41. package/dist/core/trigger.d.ts +18 -0
  42. package/dist/core/trigger.js +35 -0
  43. package/dist/core/types.d.ts +28 -0
  44. package/dist/core/types.js +8 -0
  45. package/dist/core/visual.d.ts +80 -0
  46. package/dist/core/visual.js +111 -0
  47. package/dist/entry/cli.d.ts +9 -0
  48. package/dist/entry/cli.js +1008 -0
  49. package/dist/entry/mcp.d.ts +20 -0
  50. package/dist/entry/mcp.js +288 -0
  51. package/dist/flows/destructive.d.ts +19 -0
  52. package/dist/flows/destructive.js +48 -0
  53. package/dist/flows/distill.d.ts +28 -0
  54. package/dist/flows/distill.js +109 -0
  55. package/dist/flows/drift.d.ts +43 -0
  56. package/dist/flows/drift.js +116 -0
  57. package/dist/flows/emit.d.ts +23 -0
  58. package/dist/flows/emit.js +133 -0
  59. package/dist/flows/execute.d.ts +75 -0
  60. package/dist/flows/execute.js +133 -0
  61. package/dist/flows/findings.d.ts +38 -0
  62. package/dist/flows/findings.js +136 -0
  63. package/dist/flows/runs.d.ts +42 -0
  64. package/dist/flows/runs.js +93 -0
  65. package/dist/flows/save.d.ts +74 -0
  66. package/dist/flows/save.js +171 -0
  67. package/dist/memory/notes.d.ts +89 -0
  68. package/dist/memory/notes.js +163 -0
  69. package/dist/memory/placeholders.d.ts +41 -0
  70. package/dist/memory/placeholders.js +139 -0
  71. package/dist/memory/recall.d.ts +118 -0
  72. package/dist/memory/recall.js +147 -0
  73. package/dist/memory/vocabulary.d.ts +9 -0
  74. package/dist/memory/vocabulary.js +24 -0
  75. package/dist/plan/planner.d.ts +69 -0
  76. package/dist/plan/planner.js +211 -0
  77. package/dist/plan/seams.d.ts +58 -0
  78. package/dist/plan/seams.js +99 -0
  79. package/dist/store/db.d.ts +62 -0
  80. package/dist/store/db.js +183 -0
  81. package/dist/store/embed.d.ts +46 -0
  82. package/dist/store/embed.js +100 -0
  83. package/dist/store/reembed.d.ts +13 -0
  84. package/dist/store/reembed.js +32 -0
  85. package/dist/store/settings.d.ts +67 -0
  86. package/dist/store/settings.js +151 -0
  87. package/dist/store/types.d.ts +220 -0
  88. package/dist/store/types.js +14 -0
  89. package/extension/README.md +79 -0
  90. package/extension/background.js +186 -0
  91. package/extension/icons/icon-128.png +0 -0
  92. package/extension/icons/icon-16.png +0 -0
  93. package/extension/icons/icon-32.png +0 -0
  94. package/extension/icons/icon-48.png +0 -0
  95. package/extension/manifest.json +38 -0
  96. package/extension/popup.html +52 -0
  97. package/extension/popup.js +106 -0
  98. package/extension/recorder.js +362 -0
  99. package/package.json +68 -4
@@ -0,0 +1,352 @@
1
+ /**
2
+ * The in-page listener, as a STRING.
3
+ *
4
+ * It must not be authored as a TypeScript closure passed to addInitScript.
5
+ * tsx/esbuild rewrites function declarations to preserve their names via a
6
+ * `__name()` helper, and `addInitScript` serializes the function with
7
+ * `.toString()` — so the injected body references a helper that does not exist
8
+ * in the browser and dies with `ReferenceError: __name is not defined`.
9
+ *
10
+ * It fails SILENTLY: zero events captured, nothing logged, unless you happen to
11
+ * have attached a `pageerror` listener. Shipping it as a string sidesteps the
12
+ * compiler entirely.
13
+ *
14
+ * The script is deliberately dumb. It records WHAT happened and stamps WHICH
15
+ * element; it does not decide what any of it means. Role and accessible name
16
+ * are resolved on the Node side by Playwright's own engine — reimplementing
17
+ * the accessible-name algorithm here would be wrong in exactly the cases that
18
+ * matter (icon buttons, labelled inputs, aria-labelledby chains).
19
+ */
20
+ export const STAMP_ATTR = 'data-understudy-seq';
21
+ export const INJECTED_LISTENER = `
22
+ (() => {
23
+ if (window.__understudyInstalled) return;
24
+ window.__understudyInstalled = true;
25
+
26
+ var seq = 0;
27
+ var STAMP = '${STAMP_ATTR}';
28
+
29
+ // Best-effort name, used ONLY as a fallback when Playwright cannot resolve
30
+ // the element (a click that navigates can destroy it before we get there).
31
+ // Deliberately approximate — the authoritative answer comes from Node.
32
+ // The authoritative path: a spec-compliant accname implementation, running
33
+ // IN THE PAGE and SYNCHRONOUSLY at event time. This is the whole reason the
34
+ // bundle is injected — clicking often destroys the element clicked, so
35
+ // resolving later from Node loses the race. codegen gets correct names by
36
+ // doing exactly this with Playwright's own bundle.
37
+ function a11y() {
38
+ return window.__understudyA11y;
39
+ }
40
+
41
+ // PLAYWRIGHT IS THE GROUND TRUTH, NOT THE SPEC.
42
+ //
43
+ // These names are fed back to getByRole(role, {name}) at replay, so they must
44
+ // match what Playwright computes, not merely what the accname spec says.
45
+ // Measured on saucedemo, dom-accessibility-api and Playwright disagree in
46
+ // exactly two places — neither is wrong, they just draw the line differently:
47
+ //
48
+ // input[type=password] ARIA gives it NO implicit role, so getRole returns
49
+ // null. Playwright pragmatically calls it a textbox.
50
+ // placeholder-only name computeAccessibleName returns "". Playwright falls
51
+ // back to the placeholder, which is why it reports
52
+ // textbox "Username" where the library reports "".
53
+ //
54
+ // Without this shim every placeholder-labelled field in every recording would
55
+ // carry an empty name and be unaddressable on replay.
56
+ function accName(el) {
57
+ var lib = a11y();
58
+ if (!lib) return null;
59
+ try {
60
+ var n = lib.computeAccessibleName(el);
61
+ if (typeof n === 'string' && n.trim()) return n.trim();
62
+ } catch (e) { /* fall through */ }
63
+
64
+ var tag = (el.tagName || '').toLowerCase();
65
+ if (tag === 'input' || tag === 'textarea') {
66
+ var ph = el.getAttribute && el.getAttribute('placeholder');
67
+ if (ph && ph.trim()) return ph.trim();
68
+ }
69
+ return null;
70
+ }
71
+
72
+ function accRole(el) {
73
+ var lib = a11y();
74
+ if (!lib) return null;
75
+ try {
76
+ var r = lib.getRole(el);
77
+ if (r) return r;
78
+ } catch (e) { /* fall through */ }
79
+
80
+ var tag = (el.tagName || '').toLowerCase();
81
+ if (tag === 'input') {
82
+ var t = (el.getAttribute('type') || 'text').toLowerCase();
83
+ if (t === 'password') return 'textbox';
84
+ }
85
+ return null;
86
+ }
87
+
88
+ // Fallback only, for when the bundle failed to load. Kept because a weaker
89
+ // name still beats dropping the step.
90
+ function hintName(el) {
91
+ if (!el || !el.getAttribute) return '';
92
+ var tag = (el.tagName || '').toLowerCase();
93
+
94
+ // Follow the accessible-name priority order. This is an approximation of
95
+ // the W3C algorithm, not an implementation of it — but the shortcuts that
96
+ // seem harmless are exactly the ones that bite:
97
+ // . the 'name' ATTRIBUTE is not an accessible name. Using it recorded
98
+ // saucedemo's Login button as "login-button".
99
+ // . textContent of a <select> is every option concatenated, which
100
+ // produced "Name (A to Z)Name (Z to A)Price (low to high)…".
101
+ var labelledBy = el.getAttribute('aria-labelledby');
102
+ if (labelledBy) {
103
+ var parts = [];
104
+ labelledBy.split(/\\s+/).forEach(function (id) {
105
+ var ref = document.getElementById(id);
106
+ if (ref) parts.push((ref.textContent || '').trim());
107
+ });
108
+ var joined = parts.join(' ').trim();
109
+ if (joined) return joined;
110
+ }
111
+
112
+ var ariaLabel = el.getAttribute('aria-label');
113
+ if (ariaLabel && ariaLabel.trim()) return ariaLabel.trim();
114
+
115
+ if (el.labels && el.labels[0]) {
116
+ var lbl = (el.labels[0].textContent || '').trim();
117
+ if (lbl) return lbl;
118
+ }
119
+
120
+ if (tag === 'input' || tag === 'textarea' || tag === 'select') {
121
+ var ph = el.getAttribute('placeholder');
122
+ if (ph && ph.trim()) return ph.trim();
123
+ var ttl = el.getAttribute('title');
124
+ if (ttl && ttl.trim()) return ttl.trim();
125
+ // A <select>'s text is its options; a value is not a name.
126
+ if (tag === 'select') return '';
127
+ if ((el.getAttribute('type') || '') === 'submit') return el.value || '';
128
+ return '';
129
+ }
130
+
131
+ if (tag === 'img') return (el.getAttribute('alt') || '').trim();
132
+
133
+ var text = (el.textContent || '').replace(/\\s+/g, ' ').trim();
134
+ if (text) return text.slice(0, 80);
135
+
136
+ // An icon-only control: its name usually comes from a nested image.
137
+ var img = el.querySelector && el.querySelector('img[alt]');
138
+ if (img) return (img.getAttribute('alt') || '').trim();
139
+
140
+ return (el.getAttribute('title') || '').trim();
141
+ }
142
+
143
+ function hintRole(el) {
144
+ var explicit = el.getAttribute && el.getAttribute('role');
145
+ if (explicit) return explicit;
146
+ var tag = (el.tagName || '').toLowerCase();
147
+ if (tag === 'a') return el.hasAttribute('href') ? 'link' : 'generic';
148
+ if (tag === 'button') return 'button';
149
+ if (tag === 'select') return 'combobox';
150
+ if (tag === 'textarea') return 'textbox';
151
+ if (tag === 'input') {
152
+ var t = (el.getAttribute('type') || 'text').toLowerCase();
153
+ if (t === 'checkbox') return 'checkbox';
154
+ if (t === 'radio') return 'radio';
155
+ if (t === 'submit' || t === 'button') return 'button';
156
+ return 'textbox';
157
+ }
158
+ return tag || 'generic';
159
+ }
160
+
161
+ // A short CSS path, used when role+name can't address the element.
162
+ function cssPath(el) {
163
+ if (el.id) return '#' + CSS.escape(el.id);
164
+ var testId = el.getAttribute && (el.getAttribute('data-testid') || el.getAttribute('data-test'));
165
+ if (testId) return '[data-testid="' + testId + '"]';
166
+ var parts = [];
167
+ var node = el;
168
+ while (node && node.nodeType === 1 && parts.length < 4) {
169
+ var part = node.tagName.toLowerCase();
170
+ if (node.classList && node.classList.length) {
171
+ // Tailwind's variant/arbitrary-value classes (hover:bg-gray-200,
172
+ // text-[16px]) contain characters CSS reserves (: and [ ]). Joined
173
+ // raw, the resulting selector is not valid CSS and querySelectorAll
174
+ // throws — CSS.escape() is exactly what line 165 already uses for ids.
175
+ part += '.' + [].slice.call(node.classList).map(function (c) { return CSS.escape(c); }).join('.');
176
+ }
177
+ parts.unshift(part);
178
+ node = node.parentElement;
179
+ }
180
+ return parts.join(' > ');
181
+ }
182
+
183
+ function frameHint() {
184
+ try {
185
+ if (window.top === window) return undefined;
186
+ return (window.frameElement && (window.frameElement.id || window.frameElement.name)) || 'iframe';
187
+ } catch (e) {
188
+ return 'cross-origin-iframe';
189
+ }
190
+ }
191
+
192
+ // One element, ONE stamp. Reusing it lets a mousedown pre-resolution and the
193
+ // click that follows refer to the same element, which is what makes the
194
+ // pre-resolve cache hit.
195
+ function stampOf(el) {
196
+ var existing = el.getAttribute && el.getAttribute(STAMP);
197
+ if (existing !== null && existing !== undefined && existing !== '') return Number(existing);
198
+ var n = seq++;
199
+ try { el.setAttribute(STAMP, String(n)); } catch (e) { /* readonly node */ }
200
+ return n;
201
+ }
202
+
203
+ function emit(action, el, extra) {
204
+ if (!el || el.nodeType !== 1) return;
205
+ var n = stampOf(el);
206
+
207
+ var payload = {
208
+ seq: n,
209
+ action: action,
210
+ stamp: n,
211
+ url: location.href,
212
+ hintRole: accRole(el) || hintRole(el),
213
+ hintName: accName(el) || hintName(el),
214
+ // Records WHICH path produced the two fields above, so nothing
215
+ // downstream has to guess how much to trust them.
216
+ resolvedBy: a11y() ? 'accname' : 'heuristic',
217
+ css: cssPath(el),
218
+ testId: (el.getAttribute && (el.getAttribute('data-testid') || el.getAttribute('data-test'))) || undefined,
219
+ testIdAttr: (el.getAttribute && el.getAttribute('data-testid')) ? 'data-testid'
220
+ : (el.getAttribute && el.getAttribute('data-test')) ? 'data-test' : undefined,
221
+ inputType: (el.getAttribute && el.getAttribute('type')) || undefined,
222
+ frameHint: frameHint(),
223
+ };
224
+ if (extra) for (var k in extra) payload[k] = extra[k];
225
+
226
+ try { window.__understudyEmit(payload); } catch (e) { /* binding gone */ }
227
+ }
228
+
229
+ // TEXT INPUT IS DEFERRED, NOT IMMEDIATE.
230
+ //
231
+ // 'change' on a text field fires on BLUR, not on typing. Filling a login form
232
+ // therefore emits the username only when the password field takes focus, and
233
+ // emits the password NEVER — nothing blurs the last field before submit. The
234
+ // final field of every form would vanish from every recording, silently.
235
+ //
236
+ // So: track the latest value per element on 'input' (which does fire per
237
+ // keystroke), and flush it as one 'fill' when the field is done — on blur, or
238
+ // when any other action happens, or when recording ends. Flushing before the
239
+ // triggering action also keeps the order right: fill, then the click that
240
+ // submits it.
241
+ var pending = [];
242
+
243
+ function flushOne(el) {
244
+ for (var i = 0; i < pending.length; i++) {
245
+ if (pending[i].el !== el) continue;
246
+ var entry = pending.splice(i, 1)[0];
247
+ emit('fill', entry.el, { value: entry.value });
248
+ return;
249
+ }
250
+ }
251
+
252
+ function flushAll() {
253
+ while (pending.length) {
254
+ var entry = pending.shift();
255
+ emit('fill', entry.el, { value: entry.value });
256
+ }
257
+ }
258
+
259
+ // Called from Node before the recording is closed, so a field still focused
260
+ // when the browser shuts is not lost.
261
+ window.__understudyFlush = flushAll;
262
+
263
+ // Diagnostic hook: resolve any element exactly as the recorder would. Used to
264
+ // verify our role/name agree with Playwright's engine across a whole page,
265
+ // which is the only check that catches a systematic naming drift.
266
+ window.__understudyResolve = function (el) {
267
+ return { role: accRole(el) || hintRole(el), name: accName(el) || hintName(el) };
268
+ };
269
+
270
+ document.addEventListener('input', function (e) {
271
+ var el = (e.composedPath && e.composedPath()[0]) || e.target;
272
+ var tag = (el.tagName || '').toLowerCase();
273
+ if (tag !== 'input' && tag !== 'textarea') return;
274
+ var type = (el.getAttribute('type') || 'text').toLowerCase();
275
+ if (type === 'checkbox' || type === 'radio') return;
276
+ // A FILE INPUT'S VALUE IS A LIE. The browser masks it to 'C:\\fakepath\\name'
277
+ // so a page cannot learn where someone keeps their files. Deferring it here
278
+ // flushed it as an ordinary fill carrying that string: a step that cannot
279
+ // replay, with the file absent from the recording entirely, and nothing
280
+ // anywhere reporting either. The 'change' handler records it properly.
281
+ if (type === 'file') return;
282
+
283
+ for (var i = 0; i < pending.length; i++) {
284
+ if (pending[i].el === el) {
285
+ pending[i].value = el.value;
286
+ return;
287
+ }
288
+ }
289
+ pending.push({ el: el, value: el.value });
290
+ }, true);
291
+
292
+ document.addEventListener('blur', function (e) {
293
+ var el = (e.composedPath && e.composedPath()[0]) || e.target;
294
+ flushOne(el);
295
+ }, true);
296
+
297
+ // Capture phase, so we see the event before the app can stopPropagation it,
298
+ // and before an anchor's default navigation tears the element down.
299
+ document.addEventListener('click', function (e) {
300
+ flushAll();
301
+ var el = (e.composedPath && e.composedPath()[0]) || e.target;
302
+ var tag = (el.tagName || '').toLowerCase();
303
+ var type = (el.getAttribute && (el.getAttribute('type') || '')).toLowerCase();
304
+
305
+ // Checkboxes, radios, selects and text inputs report through 'change',
306
+ // which carries the resulting VALUE. Emitting both would double-count.
307
+ if (tag === 'select' || tag === 'textarea') return;
308
+ if (tag === 'input' && type !== 'submit' && type !== 'button') return;
309
+
310
+ emit('click', el);
311
+ }, true);
312
+
313
+ document.addEventListener('change', function (e) {
314
+ var el = (e.composedPath && e.composedPath()[0]) || e.target;
315
+ var tag = (el.tagName || '').toLowerCase();
316
+ var type = (el.getAttribute && (el.getAttribute('type') || 'text')).toLowerCase();
317
+
318
+ if (tag === 'select') {
319
+ var opt = el.options && el.options[el.selectedIndex];
320
+ emit('select', el, { value: el.value, label: opt ? opt.textContent : undefined });
321
+ return;
322
+ }
323
+ if (type === 'checkbox' || type === 'radio') {
324
+ emit(el.checked ? 'check' : 'uncheck', el);
325
+ return;
326
+ }
327
+ if (type === 'file') {
328
+ // The page reports THAT an upload happened and how many files it carried.
329
+ // It cannot report WHICH files: el.value is masked and File exposes only
330
+ // .name. Node resolves the real paths from the stamp over CDP, which is
331
+ // the only place they can be read at all.
332
+ var count = el.files ? el.files.length : 0;
333
+ if (!count) return; // clearing a file input is not an upload
334
+ emit('upload', el, { fileCount: count });
335
+ return;
336
+ }
337
+ // Text inputs are handled by the input+flush path above. Emitting here too
338
+ // would double-count every field that happens to blur.
339
+ }, true);
340
+
341
+ // Enter often submits without any click at all — a step that would otherwise
342
+ // vanish from the recording and make it unreplayable.
343
+ document.addEventListener('keydown', function (e) {
344
+ if (e.key !== 'Enter') return;
345
+ var el = (e.composedPath && e.composedPath()[0]) || e.target;
346
+ var tag = (el.tagName || '').toLowerCase();
347
+ if (tag !== 'input' && tag !== 'textarea') return;
348
+ flushAll();
349
+ emit('press', el, { value: 'Enter' });
350
+ }, true);
351
+ })();
352
+ `;
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Live recorder — a human drives a headed browser, we capture intent.
3
+ *
4
+ * This replaces `playwright codegen` rather than wrapping it. Codegen's only
5
+ * output is source code in one of five languages; it never exposes the
6
+ * structured actions it derives internally. We want the data, so we listen for
7
+ * it ourselves.
8
+ *
9
+ * DIVISION OF LABOUR:
10
+ * the injected script what happened, on which element, AND what that element
11
+ * is — role and accessible name, computed in-page and
12
+ * synchronously by a spec-compliant accname bundle
13
+ * Playwright fallback only, when that bundle failed to load
14
+ *
15
+ * Resolving from Node is a LAST RESORT because it loses a race it cannot win:
16
+ * clicking usually destroys the element clicked ("Add to cart" becomes
17
+ * "Remove"; a submit re-renders the page), and an async exposeBinding call
18
+ * cannot block the page's default action. codegen gets correct names precisely
19
+ * by computing them in-page at event time; this does the same.
20
+ */
21
+ import { type BrowserContext, type Page } from 'playwright';
22
+ import { type BrowserLease } from '../../core/browser.js';
23
+ import type { StorageState } from '../../core/auth-cache.js';
24
+ import { type RawRecording } from '../../core/recording.js';
25
+ export interface LiveRecordOptions {
26
+ appSlug: string;
27
+ startUrl: string;
28
+ /** Resolved automatically when omitted; recording is inherently interactive. */
29
+ headless?: boolean;
30
+ /** Stop after this long even if the window is still open. */
31
+ maxMinutes?: number;
32
+ /**
33
+ * Start the browser from a saved session instead of a cold one.
34
+ *
35
+ * Opaque here on purpose: the recorder does not read the session cache, it is
36
+ * handed a payload. Same reasoning as `lessonsFor` and `visualCheck` on
37
+ * ReplayOptions — capture stays ignorant of where things are stored.
38
+ */
39
+ storageState?: StorageState;
40
+ /**
41
+ * Hold capture until this resolves, so the operator can reach the starting
42
+ * point without recording how they got there.
43
+ *
44
+ * THE LISTENER IS GATED, NOT INJECTED LATE. `addInitScript` only runs on new
45
+ * documents, so a listener installed after the page has loaded never runs at
46
+ * all. Instead it is installed as usual and its events are discarded until
47
+ * this resolves — which also means there is no "did arming work?" failure
48
+ * mode, because nothing about the page setup changes.
49
+ */
50
+ armWhen?: (page: Page) => Promise<void>;
51
+ /**
52
+ * Drive the page programmatically instead of waiting for a human.
53
+ *
54
+ * Not a test hook — this is how an EXISTING Playwright script becomes a
55
+ * recording. A script's `.click()` dispatches the same DOM events a human
56
+ * click does, so the identical listener captures both. Provide this and the
57
+ * recorder stops when the callback returns rather than when a window closes.
58
+ */
59
+ drive?: (page: Page) => Promise<void>;
60
+ /**
61
+ * Called once, at the moment capture arms, with the browser that got there.
62
+ *
63
+ * This is the only point at which the session is worth saving: the operator
64
+ * has finished logging in, and nothing recorded has run yet — so it is
65
+ * exactly the state the recording claims to start from. Saving at the END
66
+ * would bank whatever the recorded steps did to the session, up to and
67
+ * including logging out of it.
68
+ */
69
+ onArmed?: (info: {
70
+ context: BrowserContext;
71
+ page: Page;
72
+ sig: string;
73
+ }) => Promise<{
74
+ sessionSaved?: boolean;
75
+ } | void>;
76
+ /**
77
+ * Record in a browser someone else owns, instead of launching one.
78
+ *
79
+ * The lease is never closed here — the owner closes it.
80
+ */
81
+ lease?: BrowserLease;
82
+ /**
83
+ * Walk a prelude AFTER the capture machinery is installed and BEFORE arming.
84
+ *
85
+ * THIS IS WHY IT LIVES HERE AND NOT IN THE CALLER. `addInitScript` only runs
86
+ * on new documents, so a listener installed after the prelude has navigated
87
+ * never runs on the page the operator is looking at — silently. Ordering the
88
+ * install before the prelude is the whole correctness argument, and a caller
89
+ * that had to remember it would eventually forget.
90
+ *
91
+ * The gate does the rest: capture is disarmed throughout, exactly as it is
92
+ * while a human drives to a starting point by hand. A prelude is just that
93
+ * journey, driven programmatically.
94
+ */
95
+ beforeArm?: (lease: BrowserLease) => Promise<void>;
96
+ /**
97
+ * The flow slugs `beforeArm` walked, recorded on the recording as its entry
98
+ * condition. Kept separate from the callback so what gets WRITTEN DOWN is a
99
+ * plain list, not something inferred from a function that already ran.
100
+ */
101
+ preludeSlugs?: string[];
102
+ origin?: string;
103
+ source?: RawRecording['source'];
104
+ }
105
+ export declare function recordLive(opts: LiveRecordOptions): Promise<RawRecording>;