@jeffawe/understudy 0.3.0 → 0.5.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 (42) hide show
  1. package/CHANGELOG.md +127 -0
  2. package/README.md +69 -160
  3. package/REASONER.md +76 -86
  4. package/dist/adapters/recorder/script.d.ts +25 -2
  5. package/dist/adapters/recorder/script.js +126 -31
  6. package/dist/core/outline.d.ts +43 -0
  7. package/dist/core/outline.js +121 -0
  8. package/dist/core/recording.d.ts +19 -1
  9. package/dist/core/recording.js +38 -2
  10. package/dist/core/replay.d.ts +62 -1
  11. package/dist/core/replay.js +162 -106
  12. package/dist/entry/cli.js +185 -30
  13. package/dist/entry/mcp.d.ts +2 -0
  14. package/dist/entry/mcp.js +128 -23
  15. package/dist/flows/destructive.js +1 -1
  16. package/dist/flows/distill.js +11 -6
  17. package/dist/flows/emit.d.ts +7 -0
  18. package/dist/flows/emit.js +26 -10
  19. package/dist/flows/execute.d.ts +12 -0
  20. package/dist/flows/execute.js +23 -16
  21. package/dist/flows/runs.d.ts +2 -0
  22. package/dist/flows/runs.js +7 -3
  23. package/dist/flows/save.d.ts +5 -2
  24. package/dist/flows/save.js +38 -23
  25. package/dist/flows/session.d.ts +176 -0
  26. package/dist/flows/session.js +383 -0
  27. package/dist/flows/variants.d.ts +81 -0
  28. package/dist/flows/variants.js +139 -0
  29. package/dist/memory/calibrate.d.ts +114 -0
  30. package/dist/memory/calibrate.js +260 -0
  31. package/dist/memory/pages.d.ts +34 -0
  32. package/dist/memory/pages.js +60 -0
  33. package/dist/memory/recall.d.ts +87 -25
  34. package/dist/memory/recall.js +242 -45
  35. package/dist/plan/planner.d.ts +11 -1
  36. package/dist/plan/planner.js +36 -19
  37. package/dist/store/app-settings.d.ts +26 -0
  38. package/dist/store/app-settings.js +49 -0
  39. package/dist/store/db.js +8 -1
  40. package/dist/store/reembed.js +18 -7
  41. package/dist/store/types.d.ts +50 -0
  42. package/package.json +3 -2
@@ -13,20 +13,31 @@ export async function reembed() {
13
13
  if (!cfg)
14
14
  throw new Error('no embedding model configured — set EMBED_KEY (Voyage), or EMBED_URL and EMBED_MODEL for another model');
15
15
  const c = await collections();
16
- // Record the new model first, so ensureSchema accepts it and resizes the indexes.
16
+ const flows = c.flows;
17
+ const notes = c.notes;
18
+ // Embed everything BEFORE changing anything: if the model fails (wrong
19
+ // name, not pulled, out of quota), the database is left as it was — still
20
+ // recorded as the old model, with the old model's vectors.
21
+ const [flowVectors, noteVectors] = [await vectorsFor(flows), await vectorsFor(notes)];
22
+ // Record the new model, so ensureSchema accepts it and resizes the indexes.
17
23
  await c.meta.replaceOne({ _id: 'embedder' }, { model: cfg.model, dims: cfg.dims, setAt: new Date() }, { upsert: true });
18
24
  await ensureSchema();
19
25
  return {
20
- flows: await reembedCollection(c.flows),
21
- notes: await reembedCollection(c.notes),
26
+ flows: await write(flows, flowVectors),
27
+ notes: await write(notes, noteVectors),
22
28
  model: cfg.model,
23
29
  };
24
30
  }
25
- async function reembedCollection(coll) {
31
+ async function vectorsFor(coll) {
26
32
  const docs = await coll.find({}, { projection: { searchText: 1 } }).toArray();
27
33
  if (!docs.length)
28
- return 0;
34
+ return [];
29
35
  const vectors = await embed(docs.map((d) => d.searchText), 'document');
30
- await coll.bulkWrite(docs.map((d, i) => ({ updateOne: { filter: { _id: d._id }, update: { $set: { embedding: vectors[i] } } } })));
31
- return docs.length;
36
+ return docs.map((d, i) => ({ _id: d._id, embedding: vectors[i] }));
37
+ }
38
+ async function write(coll, vectors) {
39
+ if (!vectors.length)
40
+ return 0;
41
+ await coll.bulkWrite(vectors.map((v) => ({ updateOne: { filter: { _id: v._id }, update: { $set: { embedding: v.embedding } } } })));
42
+ return vectors.length;
32
43
  }
@@ -10,6 +10,7 @@
10
10
  *
11
11
  * Steps live inside their flow, because you never want one without the other.
12
12
  */
13
+ import type { Control } from '../core/outline.js';
13
14
  import type { ObjectId } from 'mongodb';
14
15
  import type { RawEvent } from '../core/recording.js';
15
16
  export type Precondition = 'authenticated' | 'not authenticated';
@@ -33,12 +34,52 @@ export interface App {
33
34
  * value moves to the user's env file. See memory/placeholders.ts.
34
35
  */
35
36
  placeholders?: PlaceholderKind[];
37
+ /** How long one step may wait, in ms — overrides UNDERSTUDY_TIMEOUT_MS. See store/app-settings.ts. */
38
+ timeoutMs?: number;
39
+ /**
40
+ * Goals to fit recall's known/unknown cutoffs from (`understudy calibrate`).
41
+ * Kept so `reembed` can re-fit them for a new model without asking again.
42
+ */
43
+ calibrationGoals?: CalibrationGoals;
44
+ /** The cutoffs fitted from them, for one embedding model. Ignored when the model changes. */
45
+ cutoffs?: FittedCutoffs;
36
46
  createdAt: Date;
37
47
  }
48
+ /** Goals labelled with the flow that does them; `unknown` ones the app doesn't have. */
49
+ export interface CalibrationGoals {
50
+ known: {
51
+ flow: string;
52
+ goal: string;
53
+ }[];
54
+ unknown: string[];
55
+ }
56
+ /** recall's rule for "known": top ≥ strong, or top ≥ good and ≥ margin ahead of the next flow. */
57
+ export interface Cutoffs {
58
+ strong: number;
59
+ good: number;
60
+ margin: number;
61
+ }
62
+ export interface FittedCutoffs extends Cutoffs {
63
+ model: string;
64
+ dims: number;
65
+ fittedAt: Date;
66
+ /** How many goals it was fitted on, and how many the cutoffs put on the right side. */
67
+ goals: {
68
+ known: number;
69
+ unknown: number;
70
+ };
71
+ correct: number;
72
+ }
38
73
  export interface Flow {
39
74
  _id?: ObjectId;
40
75
  app: string;
41
76
  slug: string;
77
+ /**
78
+ * Set on a copy of a flow made for one version of the app — a branch, a
79
+ * preview deploy — so testing it never replaces the main flow. Absent on the
80
+ * main flow, never null. See flows/variants.ts.
81
+ */
82
+ variant?: string;
42
83
  title: string;
43
84
  /** What the flow is FOR, phrased the way someone would ask for it. */
44
85
  intent: string;
@@ -124,6 +165,9 @@ export interface Page {
124
165
  name: string;
125
166
  };
126
167
  }[];
168
+ /** Its controls when last seen — roles, names, states, options; never field values. */
169
+ outline?: Control[];
170
+ outlineAt?: Date;
127
171
  firstSeen: Date;
128
172
  lastSeen: Date;
129
173
  }
@@ -198,6 +242,8 @@ export interface Run {
198
242
  * attributed: an agent reached the goal by other means and reported it.
199
243
  */
200
244
  mode: 'run' | 'replay' | 'attributed';
245
+ /** Run with this variant's flows, where it has them. Its history is its own. */
246
+ variant?: string;
201
247
  /**
202
248
  * The run stopped, as asked, before this step — the flow's commit — rather
203
249
  * than doing it. Its path is partial, so it is never drift history.
@@ -258,6 +304,10 @@ export interface Run {
258
304
  }>;
259
305
  dryRun?: boolean;
260
306
  allowPurchases?: boolean;
307
+ /** Run up to the first commit step, check its control, and stop there. */
308
+ stopBeforeCommit?: boolean;
309
+ /** Run the app at this address instead of the one the flows were saved on. */
310
+ baseUrl?: string;
261
311
  };
262
312
  startedAt: Date;
263
313
  endedAt?: Date;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeffawe/understudy",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
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",
@@ -33,7 +33,8 @@
33
33
  "dist",
34
34
  "extension",
35
35
  "build/extension/firefox",
36
- "REASONER.md"
36
+ "REASONER.md",
37
+ "CHANGELOG.md"
37
38
  ],
38
39
  "publishConfig": {
39
40
  "access": "public"