@broberg/lens-daemon 0.1.59 → 0.1.60

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@broberg/lens-daemon",
3
- "version": "0.1.59",
3
+ "version": "0.1.60",
4
4
  "description": "The Lens module of the cardmem daemon (flows, critic, coverage, capture sessions, the /lens/* routes and the cardmem-lens MCP) as a package. The daemon mounts createLensRouter(deps) + createLensMcpRouter(deps). Bun runtime.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -15,8 +15,8 @@
15
15
  "sharp": "^0.35.5",
16
16
  "turndown": "^7.2.4",
17
17
  "zod": "^3.23.8",
18
- "@broberg/lens-engine": "0.14.1",
19
- "@broberg/lens-svg": "0.1.1"
18
+ "@broberg/lens-svg": "0.1.1",
19
+ "@broberg/lens-engine": "0.14.1"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@happy-dom/global-registrator": "^20.10.6",
package/src/flow.ts CHANGED
@@ -38,7 +38,7 @@ import { fillSecret, getVaultWriter, type VaultReceipt, type VaultTarget } from
38
38
  import { storagePayload, type StorageSeed } from './seed-storage.ts';
39
39
  import { passwordInUrl, type FilledPassword, type PasswordInUrlFinding } from './password-in-url.ts';
40
40
  import { assertTestMailbox, cleanupMail, fillFromMail, httpMailSource, type MailFrom, type MailSource } from './mail-fill.ts';
41
- import { fillFromOwner, OWNER_KINDS, OWNER_WAIT_MAX_MS, type OwnerFrom, type OwnerKind } from './owner-fill.ts';
41
+ import { approveNumberWithOwner, fillFromOwner, MS_NUMBER_SELECTOR, OWNER_KINDS, OWNER_WAIT_MAX_MS, type OwnerFrom, type OwnerKind } from './owner-fill.ts';
42
42
  import {
43
43
  EDIT_EVENTS,
44
44
  waitForListening,
@@ -120,6 +120,8 @@ export type FlowStep =
120
120
  // Wait until the page URL contains this substring — the redirect-back assertion
121
121
  // so a manuscript knows it left the 3rd party and is back on our origin.
122
122
  | { type: 'waitForUrl'; url: string; label?: string; timeout?: number }
123
+ /** F010.16 — read Microsoft's number-matching number and let the owner approve it in ARS. */
124
+ | { type: 'ownerNumber'; question: string; selector?: string; label?: string; timeout?: number }
123
125
  // F082.x (lens-gap) — DOM inspector: dump a frame's iframes/inputs/clickables
124
126
  // (names, ids, roles, iframe titles, testids, text) so an author can discover
125
127
  // the exact anchors on a 3rd-party page (Stripe's accordion + PCI iframes)
@@ -532,6 +534,8 @@ export const STEP_TYPES = new Set([
532
534
  'expectRequest',
533
535
  // F009.139 — follow a window the page opened
534
536
  'waitForPopup', 'waitForPopupClose',
537
+ // F010.16 — Microsoft number matching through ARS
538
+ 'ownerNumber',
535
539
  ]);
536
540
 
537
541
  /** Validate + normalise an untrusted flow (HTTP/MCP boundary). Throws on the
@@ -789,6 +793,7 @@ export const STEP_FIELDS: Record<string, string[]> = {
789
793
  clickSelector: ['selector', 'frame', 'at'],
790
794
  waitForBuild: ['sha'],
791
795
  waitForUrl: ['url'],
796
+ ownerNumber: ['question', 'selector'],
792
797
  inspect: ['frame', 'html', 'testid'],
793
798
  assert: ['js'],
794
799
  screenshot: [],
@@ -915,6 +920,11 @@ function validateAndNormalizeSteps(steps: unknown[], depth = 0, inParallel = fal
915
920
  throw new Error('autocomplete step requires pickText (string) or pickIndex (number)');
916
921
  }
917
922
  }
923
+ if (s.type === 'ownerNumber') {
924
+ const o = s as { question?: unknown; selector?: unknown };
925
+ if (typeof o.question !== 'string' || !o.question.trim()) throw new Error('ownerNumber step requires a "question" the owner sees in ARS');
926
+ if (o.selector !== undefined && (typeof o.selector !== 'string' || !o.selector.trim())) throw new Error('ownerNumber step: "selector" must be a CSS selector string');
927
+ }
918
928
  if (s.type === 'capture' && (s as { to?: unknown }).to !== undefined) {
919
929
  // F010.15 — to vault: a target, and never a variable that would hold the value.
920
930
  const c = s as { to?: unknown; vault?: unknown; as?: unknown; from?: unknown };
@@ -1315,7 +1325,7 @@ export const MANUSCRIPT_VERBS = [
1315
1325
  'expectText', 'expectVisible', 'expectEditable', 'expectAbsent', 'expectTopmost',
1316
1326
  'fillSelector', 'clickSelector',
1317
1327
  'inspect', 'assert', 'screenshot', 'capture',
1318
- 'waitForPopup', 'waitForPopupClose',
1328
+ 'waitForPopup', 'waitForPopupClose', 'approve',
1319
1329
  ] as const;
1320
1330
 
1321
1331
  function parseManuscriptStep(s: string): FlowStep {
@@ -1469,6 +1479,12 @@ function parseManuscriptStep(s: string): FlowStep {
1469
1479
  const match = m[1] === '~' ? 'contains' : m[1] === '==' ? 'equals' : 'not-equals';
1470
1480
  return { type: 'expectText', testid: testid(), text, match };
1471
1481
  }
1482
+ case 'approve': {
1483
+ // F010.16 — "approve number [css] from owner \"<question>\"" ([css] optional).
1484
+ const m = s.match(/^approve\s+number(?:\s+\[([^\]]+)\])?\s+from\s+owner\s+"([^"]+)"\s*$/i);
1485
+ if (!m) throw new Error(`approve step "${s}" needs: approve number [css] from owner "<question>"`);
1486
+ return { type: 'ownerNumber', question: m[2]!, ...(m[1] ? { selector: m[1].trim() } : {}) };
1487
+ }
1472
1488
  case 'waitforurl':
1473
1489
  return { type: 'waitForUrl', url: s.replace(/^waitForUrl\s+/i, '').trim() };
1474
1490
  case 'fillselector': {
@@ -1726,6 +1742,7 @@ function describe(step: FlowStep): string {
1726
1742
  case 'clickSelector': return `clickSelector ${step.selector}${step.at ? ` @ ${step.at}` : ''}`;
1727
1743
  case 'uploadSelector': return `upload ${Array.isArray(step.path) ? `${step.path.length} files` : (step.path.startsWith('data:') ? 'data:…' : step.path)} → ${step.selector}`;
1728
1744
  case 'waitForUrl': return `waitForUrl ${step.url}`;
1745
+ case 'ownerNumber': return 'approve number from owner';
1729
1746
  case 'inspect': return step.html ? `inspect html${step.testid ? ` [${step.testid}]` : ''}` : step.frame ? 'inspect @frame' : 'inspect';
1730
1747
  case 'drag': return `drag ${step.testid} ${step.by ? `by ${step.by.x},${step.by.y}` : `→ ${step.toTestid}`}`;
1731
1748
  case 'uploadFile': return `upload ${Array.isArray(step.path) ? `${step.path.length} files` : (step.path.startsWith('data:') ? 'data:…' : step.path)} → ${step.testid}`;
@@ -2661,6 +2678,16 @@ async function execStep(page: Page, step: FlowStep, base: string, vars: Record<s
2661
2678
  await resolveLocator(page, b.selector, b.frame).first().setInputFiles(files, { timeout: stepTimeout(step) });
2662
2679
  return null;
2663
2680
  }
2681
+ case 'ownerNumber': {
2682
+ const selector = step.selector ?? MS_NUMBER_SELECTOR;
2683
+ const loc = page.locator(selector).first();
2684
+ await approveNumberWithOwner(async () => {
2685
+ // Not visible in time = no number: the caller fails the step naming the selector.
2686
+ const shown = await loc.waitFor({ state: 'visible', timeout: stepTimeout(step) }).then(() => true, () => false);
2687
+ return shown ? ((await loc.textContent({ timeout: 1000 })) ?? '').trim() : null;
2688
+ }, selector, step.question, step.timeout);
2689
+ return null;
2690
+ }
2664
2691
  case 'waitForUrl': {
2665
2692
  const want = subst(step.url, vars);
2666
2693
  await page.waitForURL((u) => u.toString().includes(want), { timeout: stepTimeout(step) });
package/src/mcp.ts CHANGED
@@ -416,7 +416,7 @@ export const TOOLS = [
416
416
  {
417
417
  name: 'lens_run_manuscript',
418
418
  description:
419
- `Compile a human-readable markdown manuscript (fmc-automation style: "# flow: name", "base: <url>", then one "- <verb> …" per line) into a flow and run it E2E. VERBS (${MANUSCRIPT_VERBS.length}, this is the complete list): ${MANUSCRIPT_VERBS.join(' / ')}. Shapes: "- goto /x" · "- fill [testid] = value" · a PASSWORD without plaintext: "- fill [testid] from file <path>" (absolute, or relative to local_path) or "- fill [testid] from env <NAME>" (F009.121 — password inputs only; the value never appears in the run, the report or a screenshot) · "- click [testid]" · "- press Enter" (global) or "- press Enter [testid]" (on a focused element) · "- expectText [testid] ~ text" · "- drag [source] -> [target]" or "- drag [node] by 120,-40" (a canvas offset; both move in 10 mousemoves so React Flow / d3-drag nodes really move — "steps N" to change, F009.123) · "- upload [input-testid] = <fixture>" · an input with NO testid, also inside an open shadow root: "- uploadSelector <css> = <fixture>[, <fixture>]" (F009.136; fixtures repo-relative to local_path or data:) · a CODE FROM MAIL: "- fill [testid] from mail to jam@jams.party subject ~ Jam match /\\b\\d{6}\\b/" (F009.137 — waits ≤60 s for a mail received after the step started, read through mail-mcp; only the test mailbox webhouse.developer@gmail.com / jam@jams.party; the mail is deleted after the run, report carries mail {consumed, cleaned}; the code never appears in the report) · a VALUE ONLY THE OWNER HAS (an npm/authenticator code, a password): "- fill [testid] from owner \"<question>\"" (add "as password" or "as text"; default code) — asked in ARS through buddy's «ars ask», the owner types it there and nowhere else; declined / expired fail the step by that word; the value never appears in the report (F010.6) · a VALUE THE PAGE SHOWS THAT MUST GO STRAIGHT TO THE VAULT (a new API key a console shows once): "- capture [testid] to vault <project>/<name> as <ENV_VAR>" — the daemon reads it and stores it in cardmem's vault with its own key; the report carries only {secret_id, name, preview}, and every later inspect redacts it (F010.15; flow JSON: {type:"capture", testid, to:"vault", vault:{project, name, env_var_name?}}) · the BUILT SCREEN'S HTML after the click path: "- inspect html [testid]" (or "- inspect html" for the whole body) — the step detail is that outerHTML, for cardmem_check_mockup_fidelity's built_html (F009.138) · a WINDOW THE PAGE OPENS (window.open / target=_blank — an OAuth dialog like «Continue with Facebook/Google»): "- waitForPopup" takes it over (also one opened by the click just before), "- in opened: <step>" acts in it, "- waitForPopupClose" waits for it to close; steps without the prefix stay in the opener (F009.139) · "- assert: <js>" · "- screenshot label" · frame-aware "- fillSelector <css> = <value> @frame <iframe>" and "- clickSelector <css> @frame <iframe>" · "- waitForUrl <substring>". TWO BROWSERS AT ONCE (F009.122): prefix a step with "in <name>:" — "- in b: goto /" · "- in b: expectText [note] == Hej" — and it runs in its own browser (own cookies + storage), open alongside the default one for the rest of the run; steps without the prefix run in the default browser. Click modifiers: "- click [testid] via enter" (F255.1, for Angular/MDC buttons a mouse click does not activate) and "- click [testid] @ 50%,28%" (F255.4, aim at a point inside a canvas/3D surface). A field that already HOLDS a value may no longer render an input — a combobox typically swaps to its selected state, so "fill" times out there while "press ArrowDown" / "press Enter" still drive it (fd-sundhed, 2026-08-21). The authoring shortcut — write prose, not JSON.`,
419
+ `Compile a human-readable markdown manuscript (fmc-automation style: "# flow: name", "base: <url>", then one "- <verb> …" per line) into a flow and run it E2E. VERBS (${MANUSCRIPT_VERBS.length}, this is the complete list): ${MANUSCRIPT_VERBS.join(' / ')}. Shapes: "- goto /x" · "- fill [testid] = value" · a PASSWORD without plaintext: "- fill [testid] from file <path>" (absolute, or relative to local_path) or "- fill [testid] from env <NAME>" (F009.121 — password inputs only; the value never appears in the run, the report or a screenshot) · "- click [testid]" · "- press Enter" (global) or "- press Enter [testid]" (on a focused element) · "- expectText [testid] ~ text" · "- drag [source] -> [target]" or "- drag [node] by 120,-40" (a canvas offset; both move in 10 mousemoves so React Flow / d3-drag nodes really move — "steps N" to change, F009.123) · "- upload [input-testid] = <fixture>" · an input with NO testid, also inside an open shadow root: "- uploadSelector <css> = <fixture>[, <fixture>]" (F009.136; fixtures repo-relative to local_path or data:) · a CODE FROM MAIL: "- fill [testid] from mail to jam@jams.party subject ~ Jam match /\\b\\d{6}\\b/" (F009.137 — waits ≤60 s for a mail received after the step started, read through mail-mcp; only the test mailbox webhouse.developer@gmail.com / jam@jams.party; the mail is deleted after the run, report carries mail {consumed, cleaned}; the code never appears in the report) · a VALUE ONLY THE OWNER HAS (an npm/authenticator code, a password): "- fill [testid] from owner \"<question>\"" (add "as password" or "as text"; default code) — asked in ARS through buddy's «ars ask», the owner types it there and nowhere else; declined / expired fail the step by that word; the value never appears in the report (F010.6) · MICROSOFT NUMBER MATCHING (the sign-in page shows a number and the phone asks for it): "- approve number [css] from owner \"<question>\"" ([css] optional — default Microsoft's number display) reads the number and shows it big in ARS; the owner types it in Authenticator and presses Færdig; nothing is typed into the page (F010.16; flow JSON {type:"ownerNumber", question, selector?}) · a VALUE THE PAGE SHOWS THAT MUST GO STRAIGHT TO THE VAULT (a new API key a console shows once): "- capture [testid] to vault <project>/<name> as <ENV_VAR>" — the daemon reads it and stores it in cardmem's vault with its own key; the report carries only {secret_id, name, preview}, and every later inspect redacts it (F010.15; flow JSON: {type:"capture", testid, to:"vault", vault:{project, name, env_var_name?}}) · the BUILT SCREEN'S HTML after the click path: "- inspect html [testid]" (or "- inspect html" for the whole body) — the step detail is that outerHTML, for cardmem_check_mockup_fidelity's built_html (F009.138) · a WINDOW THE PAGE OPENS (window.open / target=_blank — an OAuth dialog like «Continue with Facebook/Google»): "- waitForPopup" takes it over (also one opened by the click just before), "- in opened: <step>" acts in it, "- waitForPopupClose" waits for it to close; steps without the prefix stay in the opener (F009.139) · "- assert: <js>" · "- screenshot label" · frame-aware "- fillSelector <css> = <value> @frame <iframe>" and "- clickSelector <css> @frame <iframe>" · "- waitForUrl <substring>". TWO BROWSERS AT ONCE (F009.122): prefix a step with "in <name>:" — "- in b: goto /" · "- in b: expectText [note] == Hej" — and it runs in its own browser (own cookies + storage), open alongside the default one for the rest of the run; steps without the prefix run in the default browser. Click modifiers: "- click [testid] via enter" (F255.1, for Angular/MDC buttons a mouse click does not activate) and "- click [testid] @ 50%,28%" (F255.4, aim at a point inside a canvas/3D surface). A field that already HOLDS a value may no longer render an input — a combobox typically swaps to its selected state, so "fill" times out there while "press ArrowDown" / "press Enter" still drive it (fd-sundhed, 2026-08-21). The authoring shortcut — write prose, not JSON.`,
420
420
  inputSchema: {
421
421
  type: 'object',
422
422
  required: ['project', 'manuscript'],
package/src/owner-fill.ts CHANGED
@@ -36,7 +36,7 @@ export type OwnerAnswer =
36
36
  | { status: 'expired' }
37
37
  | { status: 'error'; reason: string };
38
38
 
39
- export type OwnerAsker = (q: { kind: OwnerKind; question: string; timeout: number }) => Promise<OwnerAnswer>;
39
+ export type OwnerAsker = (q: { kind: OwnerKind | 'number'; question: string; timeout: number; number?: string }) => Promise<OwnerAnswer>;
40
40
 
41
41
  // One config value. buddy gives `ars` one fixed path on every edge, ~/.buddy/bin/ars
42
42
  // (buddy #44209: measured on m1 and cb-2). launchd's PATH is NOT searched — it is
@@ -45,10 +45,10 @@ export function arsBinary(): string {
45
45
  return process.env.LENS_ARS_BIN || join(homedir(), '.buddy', 'bin', 'ars');
46
46
  }
47
47
 
48
- const spawnAsker: OwnerAsker = ({ kind, question, timeout }) =>
48
+ const spawnAsker: OwnerAsker = ({ kind, question, timeout, number }) =>
49
49
  new Promise((resolve) => {
50
50
  const bin = arsBinary();
51
- const child = spawn(bin, ['ask', '--kind', kind, '--question', question, '--requester', 'lens'], {
51
+ const child = spawn(bin, ['ask', '--kind', kind, ...(number ? ['--number', number] : []), '--question', question, '--requester', 'lens'], {
52
52
  // The BID ticket names the asker from this, so the owner sees «session lens».
53
53
  env: { ...process.env, BUDDY_SESSION_NAME: 'lens' },
54
54
  stdio: ['ignore', 'pipe', 'pipe'],
@@ -101,3 +101,21 @@ export async function fillFromOwner(loc: Locator, of: OwnerFrom, fillTimeout: nu
101
101
  }
102
102
  }
103
103
 
104
+
105
+ // F010.16 — Microsoft number matching: the sign-in page shows a number and the
106
+ // owner's Authenticator asks him to type it. Lens reads the number off the page and
107
+ // ARS shows it big («Tast dette tal i Microsoft Authenticator»); he presses Færdig.
108
+ // Nothing is typed into the page — the approval happens on the phone.
109
+ export const MS_NUMBER_SELECTOR = '#idRemoteNGC_DisplaySign, #displaySign, [data-testid=displaySign]';
110
+
111
+ export async function approveNumberWithOwner(readNumber: () => Promise<string | null>, selector: string, question: string, timeout?: number): Promise<{ number: string }> {
112
+ const raw = await readNumber();
113
+ const number = raw?.match(/\d{1,3}/)?.[0];
114
+ if (!number) throw new Error(`approve number: no 1–3 digit number in ${selector} — nothing asked`);
115
+ const res = await asker({ kind: 'number', number, question, timeout: timeout ?? OWNER_WAIT_MS });
116
+ if (res.status === 'declined') throw new Error(`approve number: declined — the owner said no to «${question}»`);
117
+ if (res.status === 'expired') throw new Error(`approve number: expired — no answer to «${question}» in time`);
118
+ if (res.status === 'error') throw new Error(`approve number: ARS failed — ${res.reason}`);
119
+ if (res.answer !== 'done') throw new Error(`approve number: ARS answered «${res.answer.slice(0, 20)}», not done`);
120
+ return { number };
121
+ }