@jeffawe/understudy 0.5.0 → 0.5.1

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/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  What changed in each release of `@jeffawe/understudy`. Newest first.
4
4
 
5
+ ## 0.5.1 — 2026-12-01
6
+
7
+ ### Fixed
8
+ - A session takes a step just as recall shows it, with `nth`, `n` and
9
+ `placeholder`, not only `hints.nth` and `valueRef`. A check added to a flow
10
+ can use `hints.nth` too, and suggested waits keep it.
11
+
12
+ ### Changed
13
+ - Requires `@modelcontextprotocol/sdk` 1.32.2 or later, which clears the
14
+ security advisories on earlier versions.
15
+ - `dom-accessibility-api` is no longer installed with the package. Only the
16
+ build uses it.
17
+
5
18
  ## 0.5.0 — 2026-12-01
6
19
 
7
20
  **Upgrade every machine that shares a database.** The flows index changes so a
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Understudy
1
+ # understudy
2
2
 
3
- ![Understudy — record a flow once, replay it as a test](https://understudy.jeffawe.dev/og.png)
3
+ ![understudy — record a flow once, replay it as a test](https://understudy.jeffawe.dev/og.png)
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/@jeffawe/understudy)](https://www.npmjs.com/package/@jeffawe/understudy)
6
6
 
package/dist/entry/mcp.js CHANGED
@@ -478,7 +478,7 @@ server.registerTool('understudy_session', {
478
478
  description: [
479
479
  'Explore an app in a browser Understudy drives, and keep what worked as a flow.',
480
480
  'do: start {app, url} or {app, flow, upTo} (runs a saved flow first; to repair one, it stops where it fails), step {step}, look {within?}, save {name, keep?}, close.',
481
- 'A step is a stored step, e.g. {"action":"click","role":"button","name":"Next"}; a password is valueRef "SECRET.password".',
481
+ 'A step is as in recall, e.g. {"action":"click","role":"button","name":"Next"}; a password is valueRef "SECRET.password".',
482
482
  'step returns what changed; look, the page\'s controls (no field values). save proves the kept steps in a fresh browser, up to a commit. A commit step needs allowPurchases.',
483
483
  ].join(' '),
484
484
  inputSchema: {
@@ -270,7 +270,7 @@ const ADDABLE = {
270
270
  human: ['untilText', 'untilUrl', 'untilResponse'],
271
271
  // A check of what the page shows — how a flow should end. Addressed by
272
272
  // role + name, which is a look, not a click.
273
- assert: ['assert', 'timeoutMs'],
273
+ assert: ['assert', 'timeoutMs', 'nth'],
274
274
  wait_response: ['method', 'status', 'field', 'equals', 'above', 'urlRegex', 'urlFlags', 'timeoutMs'],
275
275
  wait_url: ['timeoutMs'],
276
276
  wait_text: ['timeoutMs'],
@@ -303,6 +303,9 @@ export function checkAdditions(flow, adds) {
303
303
  if (ms !== undefined && (!Number.isInteger(ms) || ms < 1000 || ms > 600_000)) {
304
304
  problems.push(`${at}.step.hints.timeoutMs must be a whole number of ms from 1000 to 600000`);
305
305
  }
306
+ const nth = hints?.nth;
307
+ if (nth !== undefined && !(Number.isInteger(nth) && nth >= -1))
308
+ problems.push(`${at}.step.hints.nth must be a whole number: 0 is the first match, -1 the last`);
306
309
  const needsValue = !isAssert || kind === 'text' || kind === 'contains';
307
310
  if (needsValue && (typeof value !== 'string' || !value.trim())) {
308
311
  problems.push(`${at}.step.value is required: ${action === 'human' ? 'what the person does' : action === 'wait_response' ? 'the address' : isAssert ? 'the text to expect' : 'what to wait for'}`);
@@ -50,7 +50,9 @@ const SESSION_ACTIONS = new Set([
50
50
  'wait_url', 'wait_text', 'wait_response', 'assert',
51
51
  ]);
52
52
  /** Step fields an agent may set — the stored step shape, minus what Understudy fills in. */
53
- const STEP_FIELDS = new Set(['action', 'role', 'name', 'exact', 'value', 'valueRef', 'css', 'testId', 'testIdAttr', 'frameHint', 'hints']);
53
+ const STEP_FIELDS = new Set(['action', 'role', 'name', 'exact', 'value', 'valueRef', 'css', 'testId', 'testIdAttr', 'frameHint', 'nth', 'hints']);
54
+ /** What recall adds or renames, taken so a recalled step can be sent as it is: `n`, its number, is dropped; `placeholder` is its word for valueRef. */
55
+ const FROM_RECALL = new Set(['n', 'placeholder']);
54
56
  const sessions = new Map();
55
57
  function touch(s) {
56
58
  if (s.timer)
@@ -176,13 +178,13 @@ export async function startSession(opts) {
176
178
  /** Check a step the agent sent; return the problems, or the step. */
177
179
  function readStep(raw) {
178
180
  const problems = [];
179
- const extra = Object.keys(raw).filter((k) => !STEP_FIELDS.has(k));
181
+ const extra = Object.keys(raw).filter((k) => !STEP_FIELDS.has(k) && !FROM_RECALL.has(k));
180
182
  if (extra.length)
181
183
  problems.push(`a step can't have ${extra.join(', ')} (it can have ${[...STEP_FIELDS].join(', ')})`);
182
184
  const action = raw.action;
183
185
  if (!SESSION_ACTIONS.has(action))
184
186
  problems.push(`action must be one of ${[...SESSION_ACTIONS].join(', ')}`);
185
- for (const k of ['role', 'name', 'value', 'valueRef', 'css', 'testId', 'testIdAttr', 'frameHint']) {
187
+ for (const k of ['role', 'name', 'value', 'valueRef', 'placeholder', 'css', 'testId', 'testIdAttr', 'frameHint']) {
186
188
  if (raw[k] !== undefined && typeof raw[k] !== 'string')
187
189
  problems.push(`${k} must be a string`);
188
190
  }
@@ -190,7 +192,24 @@ function readStep(raw) {
190
192
  problems.push('hints must be an object');
191
193
  if (action === 'goto' && typeof raw.value !== 'string')
192
194
  problems.push('a goto needs value: the address');
193
- return problems.length ? { problems } : { step: raw, problems };
195
+ if (raw.placeholder !== undefined && raw.valueRef !== undefined && raw.placeholder !== raw.valueRef)
196
+ problems.push('placeholder and valueRef differ — send one');
197
+ // Recall shows `nth` beside the other fields; a stored step keeps it in hints. Either is taken.
198
+ const { n: _number, placeholder, nth: beside, ...rest } = raw;
199
+ const inHints = raw.hints?.nth;
200
+ const nth = beside ?? inHints;
201
+ if (nth !== undefined && !(Number.isInteger(nth) && nth >= -1))
202
+ problems.push('nth must be a whole number: 0 is the first match, -1 the last');
203
+ if (beside !== undefined && inHints !== undefined && beside !== inHints)
204
+ problems.push('nth and hints.nth differ — send one');
205
+ if (problems.length)
206
+ return { problems };
207
+ const read = {
208
+ ...rest,
209
+ ...(placeholder !== undefined ? { valueRef: placeholder } : {}),
210
+ ...(nth !== undefined ? { hints: { ...rest.hints, nth } } : {}),
211
+ };
212
+ return { step: read, problems };
194
213
  }
195
214
  export async function step(id, raw) {
196
215
  const s = get(id);
@@ -312,7 +331,7 @@ export async function saveSession(id, opts) {
312
331
  const suggestions = suggest(s.tried, picked, first.action !== 'goto' ? 1 : 0, out.proven?.result.steps ?? [], (await timeoutFor(s.app)) ?? 10_000);
313
332
  return { recording, out, ...(suggestions ? { suggestions } : {}) };
314
333
  }
315
- const keyOf = (s) => [s.action, s.role ?? '', s.name ?? '', s.testId ?? '', s.css ?? ''].join('\u0000');
334
+ const keyOf = (s) => [s.action, s.role ?? '', s.name ?? '', s.testId ?? '', s.css ?? '', s.hints?.nth ?? ''].join('\u0000');
316
335
  const NOT_READY = /not enabled|not visible|not stable|timeout|matched no elements/i;
317
336
  /**
318
337
  * Pure: what the session's own record says the saved flow may need. Exported
@@ -330,7 +349,10 @@ export function suggest(tried, kept, offset, proof, timeoutMs) {
330
349
  const check = (t, assert, ms, why) => {
331
350
  if (!t.step.role || !t.step.name || waits.some((w) => w.before === at(t)))
332
351
  return;
333
- waits.push({ before: at(t), step: { action: 'assert', role: t.step.role, name: t.step.name, hints: { assert, timeoutMs: Math.min(600_000, ms) } }, why });
352
+ // The check must look at the same element the step uses, not another with its name.
353
+ const nth = t.step.hints?.nth;
354
+ const hints = { assert, timeoutMs: Math.min(600_000, ms), ...(nth !== undefined ? { nth } : {}) };
355
+ waits.push({ before: at(t), step: { action: 'assert', role: t.step.role, name: t.step.name, hints }, why });
334
356
  };
335
357
  for (const t of kept) {
336
358
  if (t.fromFlow || !['click', 'fill', 'select', 'check', 'uncheck', 'press'].includes(t.step.action))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeffawe/understudy",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "End-to-end tests for your own web apps: record a flow once, and Understudy remembers it, replays it, notices when the app changes, and runs goals you describe in words — on its own or as an MCP server for AI agents.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -53,8 +53,7 @@
53
53
  "extension:package": "npm run extension:build && node scripts/package-extension.mjs"
54
54
  },
55
55
  "dependencies": {
56
- "@modelcontextprotocol/sdk": "^1.30.0",
57
- "dom-accessibility-api": "^0.7.1",
56
+ "@modelcontextprotocol/sdk": "^1.32.2",
58
57
  "dotenv": "^17.2.3",
59
58
  "mongodb": "^7.9.0",
60
59
  "pixelmatch": "^7.2.0",
@@ -66,6 +65,7 @@
66
65
  "devDependencies": {
67
66
  "@types/node": "^22.18.9",
68
67
  "@types/pngjs": "^6.0.5",
68
+ "dom-accessibility-api": "^0.7.1",
69
69
  "tsx": "^4.20.6"
70
70
  }
71
71
  }