@kurvball/rehearse 1.12.2 → 1.13.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.
- package/README.md +1 -0
- package/dist/commands/drive.js +16 -7
- package/dist/commands/index.js +2 -0
- package/dist/commands/record.d.ts +2 -0
- package/dist/commands/record.js +146 -0
- package/dist/drive/browser.d.ts +12 -1
- package/dist/drive/browser.js +64 -5
- package/dist/drive/daemon.js +91 -90
- package/dist/drive/grammar.d.ts +1 -0
- package/dist/drive/grammar.js +3 -1
- package/dist/drive/index.d.ts +9 -5
- package/dist/drive/index.js +9 -5
- package/dist/drive/log.d.ts +19 -0
- package/dist/drive/log.js +75 -0
- package/dist/drive/names.d.ts +2 -0
- package/dist/drive/names.js +4 -0
- package/dist/drive/open.d.ts +25 -0
- package/dist/drive/open.js +95 -0
- package/dist/drive/secrets.d.ts +3 -0
- package/dist/drive/secrets.js +31 -21
- package/dist/drive/state.d.ts +2 -0
- package/dist/drive/state.js +11 -0
- package/dist/drive/walk.d.ts +39 -0
- package/dist/drive/walk.js +112 -0
- package/dist/drive/watcher.d.ts +28 -0
- package/dist/drive/watcher.js +255 -0
- package/dist/kinds/flow/kind.js +2 -2
- package/dist/manifest/index.d.ts +1 -1
- package/dist/manifest/index.js +1 -1
- package/dist/manifest/types.d.ts +1 -0
- package/dist/record/flow.d.ts +38 -0
- package/dist/record/flow.js +88 -0
- package/dist/record/index.d.ts +6 -0
- package/dist/record/index.js +5 -0
- package/dist/record/keys.d.ts +24 -0
- package/dist/record/keys.js +92 -0
- package/dist/record/page.d.ts +47 -0
- package/dist/record/page.js +188 -0
- package/dist/record/person.d.ts +22 -0
- package/dist/record/person.js +286 -0
- package/dist/record/taking.d.ts +39 -0
- package/dist/record/taking.js +214 -0
- package/dist/record/walked.d.ts +10 -0
- package/dist/record/walked.js +59 -0
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +1 -0
- package/llms.txt +3 -2
- package/package.json +1 -1
- package/schema/v1/flow.schema.json +4 -0
- package/schema/v1/record.schema.json +64 -0
- package/schema/v1/samples/record.json +20 -0
- package/skill/rehearse/SKILL.md +14 -1
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
export const SECRETS = 'rehearse.secrets';
|
|
2
|
+
export function watchForSecrets({ key, autocomplete }) {
|
|
3
|
+
if (Symbol.for(key) in window)
|
|
4
|
+
return;
|
|
5
|
+
const PLAIN_TYPES = new Set(['text', 'email', 'search', 'url', 'tel', 'number']);
|
|
6
|
+
const AUTOCOMPLETE = new Set(autocomplete);
|
|
7
|
+
const SAYS_SECRET = /pass|secret|token|pwd/i;
|
|
8
|
+
const SECRET_WORDS = new Set([
|
|
9
|
+
'otp',
|
|
10
|
+
'totp',
|
|
11
|
+
'pin',
|
|
12
|
+
'pincode',
|
|
13
|
+
'nip',
|
|
14
|
+
'key',
|
|
15
|
+
'apikey',
|
|
16
|
+
'cvv',
|
|
17
|
+
'cvv2',
|
|
18
|
+
'cvc',
|
|
19
|
+
'ssn',
|
|
20
|
+
'iban',
|
|
21
|
+
'securitycode',
|
|
22
|
+
]);
|
|
23
|
+
const SECRET_PHRASES = [
|
|
24
|
+
'security code',
|
|
25
|
+
'verification code',
|
|
26
|
+
'authentication code',
|
|
27
|
+
'recovery code',
|
|
28
|
+
'card number',
|
|
29
|
+
];
|
|
30
|
+
const secret = new WeakSet();
|
|
31
|
+
const secretIdentities = new Set();
|
|
32
|
+
const watched = new WeakSet();
|
|
33
|
+
const keys = new WeakMap();
|
|
34
|
+
const byKey = new Map();
|
|
35
|
+
const listeners = [];
|
|
36
|
+
const thisDocument = Math.random().toString(36).slice(2, 10);
|
|
37
|
+
let lastKey = 0;
|
|
38
|
+
const keyOf = (el) => {
|
|
39
|
+
const known = keys.get(el);
|
|
40
|
+
if (known)
|
|
41
|
+
return known;
|
|
42
|
+
lastKey += 1;
|
|
43
|
+
const made = `${thisDocument}:${lastKey}`;
|
|
44
|
+
keys.set(el, made);
|
|
45
|
+
byKey.set(made, el);
|
|
46
|
+
return made;
|
|
47
|
+
};
|
|
48
|
+
const tidy = (s) => (s ?? '').replace(/\s+/g, ' ').trim();
|
|
49
|
+
const textOfIds = (el, attribute) => {
|
|
50
|
+
const ids = (el.getAttribute(attribute) ?? '').split(/\s+/).filter(Boolean);
|
|
51
|
+
const root = el.getRootNode();
|
|
52
|
+
return ids.map((id) => root.getElementById?.(id)?.textContent ?? '').join(' ');
|
|
53
|
+
};
|
|
54
|
+
const labelsOf = (el) => {
|
|
55
|
+
const labels = el.labels;
|
|
56
|
+
return labels ? [...labels].map((l) => l.textContent ?? '').join(' ') : '';
|
|
57
|
+
};
|
|
58
|
+
const nameOf = (el) => tidy(el.computedName ||
|
|
59
|
+
el.getAttribute('aria-label') ||
|
|
60
|
+
textOfIds(el, 'aria-labelledby') ||
|
|
61
|
+
labelsOf(el) ||
|
|
62
|
+
el.getAttribute('placeholder') ||
|
|
63
|
+
el.getAttribute('title'));
|
|
64
|
+
const identitiesOf = (el) => [
|
|
65
|
+
el.getAttribute('name') && `name:${el.getAttribute('name')}`,
|
|
66
|
+
el.id && `id:${el.id}`,
|
|
67
|
+
nameOf(el) && `label:${nameOf(el).toLowerCase()}`,
|
|
68
|
+
].filter((i) => Boolean(i));
|
|
69
|
+
const wordsIn = (said) => said
|
|
70
|
+
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
|
71
|
+
.toLowerCase()
|
|
72
|
+
.split(/[^a-z0-9]+/)
|
|
73
|
+
.filter(Boolean);
|
|
74
|
+
const saysSecret = (el) => {
|
|
75
|
+
const said = [
|
|
76
|
+
el.getAttribute('name'),
|
|
77
|
+
el.id,
|
|
78
|
+
el.getAttribute('aria-label'),
|
|
79
|
+
textOfIds(el, 'aria-labelledby'),
|
|
80
|
+
el.getAttribute('placeholder'),
|
|
81
|
+
el.getAttribute('title'),
|
|
82
|
+
labelsOf(el),
|
|
83
|
+
el.computedName,
|
|
84
|
+
]
|
|
85
|
+
.filter(Boolean)
|
|
86
|
+
.join(' ');
|
|
87
|
+
const words = wordsIn(said);
|
|
88
|
+
const phrase = words.join(' ');
|
|
89
|
+
return (SAYS_SECRET.test(said) ||
|
|
90
|
+
words.some((w) => SECRET_WORDS.has(w)) ||
|
|
91
|
+
SECRET_PHRASES.some((p) => phrase.includes(p)));
|
|
92
|
+
};
|
|
93
|
+
const takesText = (el) => el.tagName === 'TEXTAREA' ||
|
|
94
|
+
el.tagName === 'INPUT' ||
|
|
95
|
+
el.isContentEditable === true ||
|
|
96
|
+
['textbox', 'searchbox', 'combobox', 'spinbutton'].includes(el.getAttribute('role') ?? '');
|
|
97
|
+
const masked = (el) => {
|
|
98
|
+
const view = el.ownerDocument.defaultView;
|
|
99
|
+
if (!view)
|
|
100
|
+
return false;
|
|
101
|
+
const style = view.getComputedStyle(el);
|
|
102
|
+
const security = style.getPropertyValue('-webkit-text-security');
|
|
103
|
+
return (Boolean(security) && security !== 'none') || /text-security/i.test(style.fontFamily);
|
|
104
|
+
};
|
|
105
|
+
const looksSecret = (el) => (el.tagName === 'INPUT' && el.type === 'password') ||
|
|
106
|
+
(el.getAttribute('autocomplete') ?? '')
|
|
107
|
+
.toLowerCase()
|
|
108
|
+
.split(/\s+/)
|
|
109
|
+
.some((t) => AUTOCOMPLETE.has(t)) ||
|
|
110
|
+
(takesText(el) &&
|
|
111
|
+
(masked(el) || saysSecret(el) || identitiesOf(el).some((i) => secretIdentities.has(i))));
|
|
112
|
+
const mark = (el) => {
|
|
113
|
+
if (secret.has(el) || !looksSecret(el))
|
|
114
|
+
return;
|
|
115
|
+
secret.add(el);
|
|
116
|
+
const identities = identitiesOf(el);
|
|
117
|
+
for (const i of identities)
|
|
118
|
+
secretIdentities.add(i);
|
|
119
|
+
const became = { key: keyOf(el), identities };
|
|
120
|
+
for (const listener of listeners)
|
|
121
|
+
listener(became);
|
|
122
|
+
};
|
|
123
|
+
const markForGood = (el) => {
|
|
124
|
+
if (!(el.tagName === 'INPUT' && el.type === 'password'))
|
|
125
|
+
for (const i of identitiesOf(el))
|
|
126
|
+
secretIdentities.add(i);
|
|
127
|
+
mark(el);
|
|
128
|
+
};
|
|
129
|
+
const scan = (root) => {
|
|
130
|
+
if (root instanceof Element) {
|
|
131
|
+
mark(root);
|
|
132
|
+
if (root.shadowRoot)
|
|
133
|
+
watch(root.shadowRoot);
|
|
134
|
+
}
|
|
135
|
+
for (const el of root.querySelectorAll('*')) {
|
|
136
|
+
mark(el);
|
|
137
|
+
if (el.shadowRoot)
|
|
138
|
+
watch(el.shadowRoot);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
let recheckWaiting = false;
|
|
142
|
+
const recheckAll = () => {
|
|
143
|
+
recheckWaiting = false;
|
|
144
|
+
for (const el of byKey.values())
|
|
145
|
+
mark(el);
|
|
146
|
+
};
|
|
147
|
+
const recheckSoon = () => {
|
|
148
|
+
if (recheckWaiting)
|
|
149
|
+
return;
|
|
150
|
+
recheckWaiting = true;
|
|
151
|
+
queueMicrotask(recheckAll);
|
|
152
|
+
};
|
|
153
|
+
const watch = (root) => {
|
|
154
|
+
if (watched.has(root))
|
|
155
|
+
return;
|
|
156
|
+
watched.add(root);
|
|
157
|
+
new MutationObserver((records) => {
|
|
158
|
+
recheckSoon();
|
|
159
|
+
for (const r of records) {
|
|
160
|
+
if (r.type === 'attributes' && r.target instanceof Element) {
|
|
161
|
+
if (r.attributeName === 'type' && r.oldValue?.toLowerCase() === 'password')
|
|
162
|
+
markForGood(r.target);
|
|
163
|
+
else
|
|
164
|
+
mark(r.target);
|
|
165
|
+
}
|
|
166
|
+
for (const added of r.addedNodes)
|
|
167
|
+
if (added instanceof Element)
|
|
168
|
+
scan(added);
|
|
169
|
+
}
|
|
170
|
+
}).observe(root, {
|
|
171
|
+
subtree: true,
|
|
172
|
+
childList: true,
|
|
173
|
+
characterData: true,
|
|
174
|
+
attributes: true,
|
|
175
|
+
attributeOldValue: true,
|
|
176
|
+
attributeFilter: [
|
|
177
|
+
'type',
|
|
178
|
+
'autocomplete',
|
|
179
|
+
'name',
|
|
180
|
+
'id',
|
|
181
|
+
'aria-label',
|
|
182
|
+
'aria-labelledby',
|
|
183
|
+
'placeholder',
|
|
184
|
+
'title',
|
|
185
|
+
'class',
|
|
186
|
+
'style',
|
|
187
|
+
],
|
|
188
|
+
});
|
|
189
|
+
scan(root);
|
|
190
|
+
};
|
|
191
|
+
const isSecret = (el) => {
|
|
192
|
+
mark(el);
|
|
193
|
+
return secret.has(el);
|
|
194
|
+
};
|
|
195
|
+
const isPlain = (el) => ((el.tagName === 'INPUT' && PLAIN_TYPES.has(el.type)) ||
|
|
196
|
+
el.tagName === 'TEXTAREA') &&
|
|
197
|
+
!isSecret(el);
|
|
198
|
+
const lookAt = (el) => ({
|
|
199
|
+
key: keyOf(el),
|
|
200
|
+
typed: isSecret(el) ? 'password' : isPlain(el) || el.tagName === 'SELECT' ? 'shown' : 'unseen',
|
|
201
|
+
identities: identitiesOf(el),
|
|
202
|
+
choice: el.tagName === 'SELECT',
|
|
203
|
+
});
|
|
204
|
+
const nothing = { key: null, typed: 'unseen', identities: [], choice: false };
|
|
205
|
+
const focused = () => {
|
|
206
|
+
let el = document.activeElement;
|
|
207
|
+
while (el?.shadowRoot?.activeElement)
|
|
208
|
+
el = el.shadowRoot.activeElement;
|
|
209
|
+
if (!el || el === document.body || el === document.documentElement)
|
|
210
|
+
return nothing;
|
|
211
|
+
if (el.tagName === 'IFRAME' || el.tagName === 'FRAME') {
|
|
212
|
+
try {
|
|
213
|
+
const inner = el.contentWindow;
|
|
214
|
+
return inner?.[Symbol.for(key)]?.focused() ?? nothing;
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
return nothing;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return lookAt(el);
|
|
221
|
+
};
|
|
222
|
+
const recheck = (wanted) => wanted.flatMap((k) => {
|
|
223
|
+
const el = byKey.get(k);
|
|
224
|
+
return el && isSecret(el) ? [{ key: k, identities: identitiesOf(el) }] : [];
|
|
225
|
+
});
|
|
226
|
+
const watchPath = (event) => {
|
|
227
|
+
for (const node of event.composedPath())
|
|
228
|
+
if (node instanceof ShadowRoot)
|
|
229
|
+
watch(node);
|
|
230
|
+
};
|
|
231
|
+
for (const type of ['pointerdown', 'focusin', 'keydown'])
|
|
232
|
+
window.addEventListener(type, watchPath, true);
|
|
233
|
+
for (const type of ['focusout', 'load', 'transitionend', 'animationend'])
|
|
234
|
+
window.addEventListener(type, recheckSoon, true);
|
|
235
|
+
window.addEventListener('pagehide', recheckAll, true);
|
|
236
|
+
watch(document);
|
|
237
|
+
Object.defineProperty(window, Symbol.for(key), {
|
|
238
|
+
value: {
|
|
239
|
+
isSecret,
|
|
240
|
+
isPlain,
|
|
241
|
+
keyOf,
|
|
242
|
+
identitiesOf,
|
|
243
|
+
lookAt,
|
|
244
|
+
focused,
|
|
245
|
+
recheck,
|
|
246
|
+
secretValueOf: (wanted) => {
|
|
247
|
+
const el = byKey.get(wanted);
|
|
248
|
+
return el && isSecret(el) && 'value' in el && typeof el.value === 'string' && el.value
|
|
249
|
+
? el.value
|
|
250
|
+
: null;
|
|
251
|
+
},
|
|
252
|
+
onSecret: (listener) => listeners.push(listener),
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
}
|
package/dist/kinds/flow/kind.js
CHANGED
|
@@ -229,7 +229,7 @@ async function throughBrowser(s, ctx, browser, url) {
|
|
|
229
229
|
if (!ok)
|
|
230
230
|
break;
|
|
231
231
|
const n = i + 2;
|
|
232
|
-
const filled = step.with === undefined
|
|
232
|
+
const filled = step.with === undefined || step.literal
|
|
233
233
|
? step
|
|
234
234
|
: { ...step, with: fill(step.with, { token: person ? (ctx.tokens[person] ?? '') : '' }) };
|
|
235
235
|
const did = await act(page, stepCommand(filled));
|
|
@@ -296,7 +296,7 @@ async function upAgainWhereTheWorldStarts(ctx, running) {
|
|
|
296
296
|
const cantBeBroughtUpAfresh = (service, afterAnotherFlow) => `${service} can't be brought up afresh (it needs a down command, and an up that hands over to a daemon), so this flow started ${afterAnotherFlow ? 'where the last one left the app' : 'with the app as it found it'}.`;
|
|
297
297
|
registerRunner({
|
|
298
298
|
kind: 'flow',
|
|
299
|
-
version: 'flow/
|
|
299
|
+
version: 'flow/5',
|
|
300
300
|
services: (s) => (s.service ? [s.service] : []),
|
|
301
301
|
async run(scenarios, asGiven) {
|
|
302
302
|
let ctx = asGiven;
|
package/dist/manifest/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { fill, fillEnv } from './fill.ts';
|
|
1
|
+
export { fill, fillEnv, placeholdersIn } from './fill.ts';
|
|
2
2
|
export { STARTER, STARTER_BLOCKS, STARTER_HEAD } from './init.ts';
|
|
3
3
|
export { findManifest, hashOf, INERT_BY_DEFAULT, loadManifest, MANIFEST_FILE, manifestFrom } from './load.ts';
|
|
4
4
|
export { KIND_BLOCK, KINDS, type Kind, type Manifest, type PathEntry, type Person, type Real, type Service, type Standin, type World, } from './types.ts';
|
package/dist/manifest/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { fill, fillEnv } from './fill.js';
|
|
1
|
+
export { fill, fillEnv, placeholdersIn } from './fill.js';
|
|
2
2
|
export { STARTER, STARTER_BLOCKS, STARTER_HEAD } from './init.js';
|
|
3
3
|
export { findManifest, hashOf, INERT_BY_DEFAULT, loadManifest, MANIFEST_FILE, manifestFrom } from './load.js';
|
|
4
4
|
export { KIND_BLOCK, KINDS, } from './types.js';
|
package/dist/manifest/types.d.ts
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Step } from '../drive/index.ts';
|
|
2
|
+
export declare const PASSWORD = "<password>";
|
|
3
|
+
export declare const PASSWORD_NOTE = "Rehearse never records what is typed in a password field, or in one that may hold a secret: write what this flow types there in place of <password>.";
|
|
4
|
+
export declare const UNSEEN = "<not recorded>";
|
|
5
|
+
export declare const UNSEEN_NOTE = "Rehearse keeps typed text only for plain fields it can see, and this was typed elsewhere, such as into a closed shadow root, an editor that isn't a native field, or with nothing focused: write what the flow types in place of <not recorded>.";
|
|
6
|
+
export declare const NOT_PLAIN_NOTE = "Rehearse keeps typed text only for plain fields it can see, and this field isn't one: write what the flow types in place of <not recorded>.";
|
|
7
|
+
export declare const NAME_HELD_NOTE = "This step\u2019s name held a secret value, so Rehearse wrote \u2039secret\u203A in its place: the step won\u2019t match until you edit the name.";
|
|
8
|
+
export declare const NAME_UNCHECKED_NOTE = "Rehearse couldn\u2019t check this step\u2019s name for secret values: check it before you commit the flow.";
|
|
9
|
+
export declare const PENDING_NOTE = "The drive stopped before Rehearse checked this text again, so it didn't keep it: write what the flow types in place of <not recorded>.";
|
|
10
|
+
export declare const TRIMMED_NOTE = "The start path held a token, so Rehearse left out its query and fragment: put back what the flow needs, without the token.";
|
|
11
|
+
export declare const DRIVER_NOTE = "Rehearse can\u2019t see the field a service\u2019s own driver types into, so it didn\u2019t record the text: write what the flow types in place of <not recorded>.";
|
|
12
|
+
export declare const TOKEN_NOTE = "The text held a person\u2019s token that the flow can\u2019t fill in here, so Rehearse didn\u2019t record it: write what the flow types in place of <not recorded>.";
|
|
13
|
+
export declare const MOST_STEPS = 60;
|
|
14
|
+
export interface FlowHead {
|
|
15
|
+
name: string;
|
|
16
|
+
service: string | null;
|
|
17
|
+
piece: string | null;
|
|
18
|
+
start: string | null;
|
|
19
|
+
world: string | null;
|
|
20
|
+
person: string | null;
|
|
21
|
+
}
|
|
22
|
+
export interface Taken {
|
|
23
|
+
step: Step;
|
|
24
|
+
note: string | null;
|
|
25
|
+
fillsIn?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface Warning {
|
|
28
|
+
line: number | null;
|
|
29
|
+
step: number | null;
|
|
30
|
+
says: string;
|
|
31
|
+
}
|
|
32
|
+
export interface Written {
|
|
33
|
+
text: string;
|
|
34
|
+
steps: Step[];
|
|
35
|
+
warnings: Warning[];
|
|
36
|
+
}
|
|
37
|
+
export declare function nameFromFile(file: string): string;
|
|
38
|
+
export declare function flowOf(head: FlowHead, taken: readonly Taken[], notes: readonly string[]): Written | null;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { stringify } from 'yaml';
|
|
3
|
+
import { placeholdersIn, readYaml } from '../manifest/index.js';
|
|
4
|
+
import { validate } from '../schema.js';
|
|
5
|
+
export const PASSWORD = '<password>';
|
|
6
|
+
export const PASSWORD_NOTE = `Rehearse never records what is typed in a password field, or in one that may hold a secret: write what this flow types there in place of ${PASSWORD}.`;
|
|
7
|
+
export const UNSEEN = '<not recorded>';
|
|
8
|
+
export const UNSEEN_NOTE = `Rehearse keeps typed text only for plain fields it can see, and this was typed elsewhere, such as into a closed shadow root, an editor that isn't a native field, or with nothing focused: write what the flow types in place of ${UNSEEN}.`;
|
|
9
|
+
export const NOT_PLAIN_NOTE = `Rehearse keeps typed text only for plain fields it can see, and this field isn't one: write what the flow types in place of ${UNSEEN}.`;
|
|
10
|
+
export const NAME_HELD_NOTE = 'This step’s name held a secret value, so Rehearse wrote ‹secret› in its place: the step won’t match until you edit the name.';
|
|
11
|
+
export const NAME_UNCHECKED_NOTE = 'Rehearse couldn’t check this step’s name for secret values: check it before you commit the flow.';
|
|
12
|
+
export const PENDING_NOTE = `The drive stopped before Rehearse checked this text again, so it didn't keep it: write what the flow types in place of ${UNSEEN}.`;
|
|
13
|
+
export const TRIMMED_NOTE = 'The start path held a token, so Rehearse left out its query and fragment: put back what the flow needs, without the token.';
|
|
14
|
+
export const DRIVER_NOTE = `Rehearse can’t see the field a service’s own driver types into, so it didn’t record the text: write what the flow types in place of ${UNSEEN}.`;
|
|
15
|
+
export const TOKEN_NOTE = `The text held a person’s token that the flow can’t fill in here, so Rehearse didn’t record it: write what the flow types in place of ${UNSEEN}.`;
|
|
16
|
+
export const MOST_STEPS = 60;
|
|
17
|
+
const MOST_WORDS = 120;
|
|
18
|
+
export function nameFromFile(file) {
|
|
19
|
+
const words = path
|
|
20
|
+
.basename(file)
|
|
21
|
+
.replace(/(\.flow)?\.ya?ml$/i, '')
|
|
22
|
+
.replace(/[-_.\s]+/g, ' ')
|
|
23
|
+
.trim();
|
|
24
|
+
const name = words ? `${words[0].toUpperCase()}${words.slice(1)}` : 'A recorded flow';
|
|
25
|
+
return name.slice(0, MOST_WORDS).trim();
|
|
26
|
+
}
|
|
27
|
+
const wordsOf = (step) => step.click ?? step.fill ?? step.snapshot ?? '';
|
|
28
|
+
const fits = (t) => wordsOf(t.step).length <= MOST_WORDS;
|
|
29
|
+
const typesSomething = (t) => t.step.type !== '';
|
|
30
|
+
function ordered({ step, fillsIn }) {
|
|
31
|
+
const { role, with: text, literal: _given, ...verb } = step;
|
|
32
|
+
const literal = text !== undefined && !fillsIn && placeholdersIn(text).length > 0;
|
|
33
|
+
return {
|
|
34
|
+
...verb,
|
|
35
|
+
...(role !== undefined && { role }),
|
|
36
|
+
...(text !== undefined && { with: text }),
|
|
37
|
+
...(literal && { literal: true }),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export function flowOf(head, taken, notes) {
|
|
41
|
+
const typing = taken.filter(typesSomething);
|
|
42
|
+
const fitting = typing.filter(fits);
|
|
43
|
+
const kept = fitting.slice(0, MOST_STEPS);
|
|
44
|
+
if (kept.length === 0)
|
|
45
|
+
return null;
|
|
46
|
+
const steps = kept.map(ordered);
|
|
47
|
+
const flow = {
|
|
48
|
+
name: head.name,
|
|
49
|
+
...(head.piece ? { piece: head.piece } : head.service ? { service: head.service } : {}),
|
|
50
|
+
...(head.start && { start: head.start }),
|
|
51
|
+
...(head.world && { world: head.world }),
|
|
52
|
+
...(head.person && { person: head.person }),
|
|
53
|
+
steps,
|
|
54
|
+
};
|
|
55
|
+
const invalid = validate('flow', flow);
|
|
56
|
+
if (invalid.length)
|
|
57
|
+
throw new Error(`Rehearse wrote a flow it can’t read: ${invalid[0].says}`);
|
|
58
|
+
const text = stringify(flow, { lineWidth: 0 });
|
|
59
|
+
const read = readYaml(text, 'flow.yaml');
|
|
60
|
+
const tooLong = typing.length - fitting.length;
|
|
61
|
+
const over = fitting.length - kept.length;
|
|
62
|
+
return {
|
|
63
|
+
text,
|
|
64
|
+
steps,
|
|
65
|
+
warnings: [
|
|
66
|
+
...kept.flatMap((t, i) => t.note ? [{ line: read.lineOf(['steps', String(i)]) ?? null, step: i + 1, says: t.note }] : []),
|
|
67
|
+
...notes.map((says) => ({ line: null, step: null, says })),
|
|
68
|
+
...(tooLong
|
|
69
|
+
? [
|
|
70
|
+
{
|
|
71
|
+
line: null,
|
|
72
|
+
step: null,
|
|
73
|
+
says: `${tooLong === 1 ? 'A step was' : `${tooLong} steps were`} left out: a flow names things in up to ${MOST_WORDS} characters, and ${tooLong === 1 ? 'its name is' : 'their names are'} longer.`,
|
|
74
|
+
},
|
|
75
|
+
]
|
|
76
|
+
: []),
|
|
77
|
+
...(over
|
|
78
|
+
? [
|
|
79
|
+
{
|
|
80
|
+
line: null,
|
|
81
|
+
step: null,
|
|
82
|
+
says: `A flow takes up to ${MOST_STEPS} steps, so the ${over === 1 ? 'last step was' : `last ${over} steps were`} left out: record the rest as a flow of its own.`,
|
|
83
|
+
},
|
|
84
|
+
]
|
|
85
|
+
: []),
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { flowOf, MOST_STEPS, nameFromFile, PASSWORD, type FlowHead, type Taken, type Warning, type Written, } from './flow.ts';
|
|
2
|
+
export { keyOf, type KeySeen, type KeyTaken } from './keys.ts';
|
|
3
|
+
export type { Seen } from './page.ts';
|
|
4
|
+
export { interruptsUntilWritten, recordAPerson, type Interrupts, type Watched, type Watching, } from './person.ts';
|
|
5
|
+
export { Taking, type Picker, type PickerBefore } from './taking.ts';
|
|
6
|
+
export { fromTheWalk, type FromTheWalk } from './walked.ts';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface KeySeen {
|
|
2
|
+
key: string;
|
|
3
|
+
code: string;
|
|
4
|
+
control: boolean;
|
|
5
|
+
alt: boolean;
|
|
6
|
+
shift: boolean;
|
|
7
|
+
meta: boolean;
|
|
8
|
+
inField: boolean;
|
|
9
|
+
multiline: boolean;
|
|
10
|
+
choosing: boolean;
|
|
11
|
+
}
|
|
12
|
+
export type KeyTaken = {
|
|
13
|
+
as: 'key';
|
|
14
|
+
key: string;
|
|
15
|
+
} | {
|
|
16
|
+
as: 'text';
|
|
17
|
+
text: string;
|
|
18
|
+
} | {
|
|
19
|
+
as: 'nothing';
|
|
20
|
+
} | {
|
|
21
|
+
as: 'unknown';
|
|
22
|
+
key: string;
|
|
23
|
+
};
|
|
24
|
+
export declare function keyOf(k: KeySeen): KeyTaken;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { isKey } from '../drive/index.js';
|
|
2
|
+
const NAMED = {
|
|
3
|
+
Enter: 'Enter',
|
|
4
|
+
Escape: 'Escape',
|
|
5
|
+
Tab: 'Tab',
|
|
6
|
+
Backspace: 'Backspace',
|
|
7
|
+
Delete: 'Delete',
|
|
8
|
+
' ': 'Space',
|
|
9
|
+
ArrowUp: 'ArrowUp',
|
|
10
|
+
ArrowDown: 'ArrowDown',
|
|
11
|
+
ArrowLeft: 'ArrowLeft',
|
|
12
|
+
ArrowRight: 'ArrowRight',
|
|
13
|
+
Home: 'Home',
|
|
14
|
+
End: 'End',
|
|
15
|
+
PageUp: 'PageUp',
|
|
16
|
+
PageDown: 'PageDown',
|
|
17
|
+
...Object.fromEntries(Array.from({ length: 12 }, (_, i) => [`F${i + 1}`, `F${i + 1}`])),
|
|
18
|
+
};
|
|
19
|
+
const PUNCTUATION_BY_CODE = {
|
|
20
|
+
Comma: ',',
|
|
21
|
+
Period: '.',
|
|
22
|
+
Slash: '/',
|
|
23
|
+
Semicolon: ';',
|
|
24
|
+
Quote: "'",
|
|
25
|
+
Backquote: '`',
|
|
26
|
+
BracketLeft: '[',
|
|
27
|
+
BracketRight: ']',
|
|
28
|
+
Backslash: '\\',
|
|
29
|
+
Equal: '=',
|
|
30
|
+
Minus: '-',
|
|
31
|
+
};
|
|
32
|
+
const ONLY_A_MODIFIER = new Set([
|
|
33
|
+
'Shift',
|
|
34
|
+
'Control',
|
|
35
|
+
'Alt',
|
|
36
|
+
'AltGraph',
|
|
37
|
+
'Meta',
|
|
38
|
+
'CapsLock',
|
|
39
|
+
'NumLock',
|
|
40
|
+
'ScrollLock',
|
|
41
|
+
'Fn',
|
|
42
|
+
'FnLock',
|
|
43
|
+
'Hyper',
|
|
44
|
+
'Super',
|
|
45
|
+
'Symbol',
|
|
46
|
+
'SymbolLock',
|
|
47
|
+
'Dead',
|
|
48
|
+
'Compose',
|
|
49
|
+
'Process',
|
|
50
|
+
'Unidentified',
|
|
51
|
+
]);
|
|
52
|
+
const MOVES_THE_CARET = new Set(['Backspace', 'Delete', 'ArrowLeft', 'ArrowRight', 'Home', 'End']);
|
|
53
|
+
const EDITS_THE_TEXT = /^[acvxyz]$/;
|
|
54
|
+
const LEAVES_A_CHOICE = new Set(['Tab', 'Escape']);
|
|
55
|
+
function baseOf(k) {
|
|
56
|
+
const named = NAMED[k.key];
|
|
57
|
+
if (named)
|
|
58
|
+
return named;
|
|
59
|
+
const letter = /^Key([A-Z])$/.exec(k.code)?.[1]?.toLowerCase();
|
|
60
|
+
const digit = /^Digit(\d)$/.exec(k.code)?.[1];
|
|
61
|
+
const mark = PUNCTUATION_BY_CODE[k.code];
|
|
62
|
+
return letter ?? digit ?? mark ?? (k.key.length === 1 ? k.key.toLowerCase() : null);
|
|
63
|
+
}
|
|
64
|
+
const madeByAlt = (k) => k.alt && !k.meta && k.key.length === 1 && k.key.toLowerCase() !== (baseOf({ ...k, key: '' }) ?? '');
|
|
65
|
+
export function keyOf(k) {
|
|
66
|
+
if (ONLY_A_MODIFIER.has(k.key))
|
|
67
|
+
return { as: 'nothing' };
|
|
68
|
+
const composed = madeByAlt(k);
|
|
69
|
+
const chord = (k.control || k.alt || k.meta) && !composed;
|
|
70
|
+
const printable = k.key.length === 1 && !chord;
|
|
71
|
+
if (k.choosing && !chord && !LEAVES_A_CHOICE.has(k.key))
|
|
72
|
+
return { as: 'nothing' };
|
|
73
|
+
if (k.inField) {
|
|
74
|
+
if (printable || (!k.control && !k.meta && !NAMED[k.key]))
|
|
75
|
+
return { as: 'nothing' };
|
|
76
|
+
if (!chord && MOVES_THE_CARET.has(k.key))
|
|
77
|
+
return { as: 'nothing' };
|
|
78
|
+
if (k.multiline && k.key === 'Enter' && !chord)
|
|
79
|
+
return { as: 'nothing' };
|
|
80
|
+
if ((k.control || k.meta) && !k.alt && EDITS_THE_TEXT.test(baseOf(k) ?? ''))
|
|
81
|
+
return { as: 'nothing' };
|
|
82
|
+
}
|
|
83
|
+
else if (printable && k.key !== ' ')
|
|
84
|
+
return { as: 'text', text: k.key };
|
|
85
|
+
const base = baseOf(k);
|
|
86
|
+
const name = [k.control && 'Control', k.alt && 'Alt', k.shift && 'Shift', k.meta && 'Meta', base]
|
|
87
|
+
.filter(Boolean)
|
|
88
|
+
.join('+');
|
|
89
|
+
if (base && isKey(name))
|
|
90
|
+
return { as: 'key', key: name };
|
|
91
|
+
return k.inField ? { as: 'nothing' } : { as: 'unknown', key: name || k.key };
|
|
92
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { BecameSecret } from '../drive/index.ts';
|
|
2
|
+
import type { KeySeen } from './keys.ts';
|
|
3
|
+
export declare const BINDING = "__rehearseRecorded";
|
|
4
|
+
export declare const SHOWS_ITS_ACCESSIBILITY_TREE = "--enable-blink-features=ComputedAccessibilityInfo";
|
|
5
|
+
export type Seen = {
|
|
6
|
+
kind: 'click';
|
|
7
|
+
role: string;
|
|
8
|
+
name: string;
|
|
9
|
+
nameNote?: string;
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'text';
|
|
12
|
+
field: string;
|
|
13
|
+
role: string;
|
|
14
|
+
name: string;
|
|
15
|
+
nameNote?: string;
|
|
16
|
+
identities: string[];
|
|
17
|
+
plain: boolean;
|
|
18
|
+
secret: boolean;
|
|
19
|
+
value: string | null;
|
|
20
|
+
long?: boolean;
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'choice';
|
|
23
|
+
field: string;
|
|
24
|
+
role: string;
|
|
25
|
+
name: string;
|
|
26
|
+
nameNote?: string;
|
|
27
|
+
identities: string[];
|
|
28
|
+
secret: boolean;
|
|
29
|
+
value: string;
|
|
30
|
+
repeated: boolean;
|
|
31
|
+
several: boolean;
|
|
32
|
+
} | ({
|
|
33
|
+
kind: 'secret';
|
|
34
|
+
} & BecameSecret) | {
|
|
35
|
+
kind: 'unseen';
|
|
36
|
+
} | {
|
|
37
|
+
kind: 'frame';
|
|
38
|
+
name: string;
|
|
39
|
+
nameNote?: string;
|
|
40
|
+
} | ({
|
|
41
|
+
kind: 'key';
|
|
42
|
+
} & KeySeen);
|
|
43
|
+
export interface Listening {
|
|
44
|
+
binding: string;
|
|
45
|
+
secrets: string;
|
|
46
|
+
}
|
|
47
|
+
export declare function listenAsThePersonActs({ binding, secrets: secretsKey }: Listening): void;
|