@broberg/lens-daemon 0.1.58 → 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 +1 -1
- package/src/flow.ts +40 -3
- package/src/mcp.ts +1 -1
- package/src/owner-fill.ts +21 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@broberg/lens-daemon",
|
|
3
|
-
"version": "0.1.
|
|
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",
|
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
|
|
@@ -610,7 +614,17 @@ export function parseFlow(input: unknown): Flow {
|
|
|
610
614
|
}
|
|
611
615
|
let browsers: Record<string, { auth: AuthConfig }> | undefined;
|
|
612
616
|
if (f.browsers !== undefined) {
|
|
613
|
-
|
|
617
|
+
// F009.142 — an MCP client whose tool list predates the field sends it as a JSON
|
|
618
|
+
// string; read it like coerceAuth reads auth, never drop it (a dropped login would
|
|
619
|
+
// run both browsers as one user and still report green).
|
|
620
|
+
let b = f.browsers as unknown;
|
|
621
|
+
if (typeof b === 'string') {
|
|
622
|
+
try {
|
|
623
|
+
b = JSON.parse(b);
|
|
624
|
+
} catch {
|
|
625
|
+
throw new Error('flow.browsers was a string but not valid JSON — pass {<name>: {auth: {...}}}');
|
|
626
|
+
}
|
|
627
|
+
}
|
|
614
628
|
if (!b || typeof b !== 'object' || Array.isArray(b)) throw new Error('flow.browsers must be {<name>: {auth: {...}}}');
|
|
615
629
|
browsers = {};
|
|
616
630
|
for (const [name, v] of Object.entries(b as Record<string, unknown>)) {
|
|
@@ -779,6 +793,7 @@ export const STEP_FIELDS: Record<string, string[]> = {
|
|
|
779
793
|
clickSelector: ['selector', 'frame', 'at'],
|
|
780
794
|
waitForBuild: ['sha'],
|
|
781
795
|
waitForUrl: ['url'],
|
|
796
|
+
ownerNumber: ['question', 'selector'],
|
|
782
797
|
inspect: ['frame', 'html', 'testid'],
|
|
783
798
|
assert: ['js'],
|
|
784
799
|
screenshot: [],
|
|
@@ -905,6 +920,11 @@ function validateAndNormalizeSteps(steps: unknown[], depth = 0, inParallel = fal
|
|
|
905
920
|
throw new Error('autocomplete step requires pickText (string) or pickIndex (number)');
|
|
906
921
|
}
|
|
907
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
|
+
}
|
|
908
928
|
if (s.type === 'capture' && (s as { to?: unknown }).to !== undefined) {
|
|
909
929
|
// F010.15 — to vault: a target, and never a variable that would hold the value.
|
|
910
930
|
const c = s as { to?: unknown; vault?: unknown; as?: unknown; from?: unknown };
|
|
@@ -1305,7 +1325,7 @@ export const MANUSCRIPT_VERBS = [
|
|
|
1305
1325
|
'expectText', 'expectVisible', 'expectEditable', 'expectAbsent', 'expectTopmost',
|
|
1306
1326
|
'fillSelector', 'clickSelector',
|
|
1307
1327
|
'inspect', 'assert', 'screenshot', 'capture',
|
|
1308
|
-
'waitForPopup', 'waitForPopupClose',
|
|
1328
|
+
'waitForPopup', 'waitForPopupClose', 'approve',
|
|
1309
1329
|
] as const;
|
|
1310
1330
|
|
|
1311
1331
|
function parseManuscriptStep(s: string): FlowStep {
|
|
@@ -1459,6 +1479,12 @@ function parseManuscriptStep(s: string): FlowStep {
|
|
|
1459
1479
|
const match = m[1] === '~' ? 'contains' : m[1] === '==' ? 'equals' : 'not-equals';
|
|
1460
1480
|
return { type: 'expectText', testid: testid(), text, match };
|
|
1461
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
|
+
}
|
|
1462
1488
|
case 'waitforurl':
|
|
1463
1489
|
return { type: 'waitForUrl', url: s.replace(/^waitForUrl\s+/i, '').trim() };
|
|
1464
1490
|
case 'fillselector': {
|
|
@@ -1716,6 +1742,7 @@ function describe(step: FlowStep): string {
|
|
|
1716
1742
|
case 'clickSelector': return `clickSelector ${step.selector}${step.at ? ` @ ${step.at}` : ''}`;
|
|
1717
1743
|
case 'uploadSelector': return `upload ${Array.isArray(step.path) ? `${step.path.length} files` : (step.path.startsWith('data:') ? 'data:…' : step.path)} → ${step.selector}`;
|
|
1718
1744
|
case 'waitForUrl': return `waitForUrl ${step.url}`;
|
|
1745
|
+
case 'ownerNumber': return 'approve number from owner';
|
|
1719
1746
|
case 'inspect': return step.html ? `inspect html${step.testid ? ` [${step.testid}]` : ''}` : step.frame ? 'inspect @frame' : 'inspect';
|
|
1720
1747
|
case 'drag': return `drag ${step.testid} ${step.by ? `by ${step.by.x},${step.by.y}` : `→ ${step.toTestid}`}`;
|
|
1721
1748
|
case 'uploadFile': return `upload ${Array.isArray(step.path) ? `${step.path.length} files` : (step.path.startsWith('data:') ? 'data:…' : step.path)} → ${step.testid}`;
|
|
@@ -2651,6 +2678,16 @@ async function execStep(page: Page, step: FlowStep, base: string, vars: Record<s
|
|
|
2651
2678
|
await resolveLocator(page, b.selector, b.frame).first().setInputFiles(files, { timeout: stepTimeout(step) });
|
|
2652
2679
|
return null;
|
|
2653
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
|
+
}
|
|
2654
2691
|
case 'waitForUrl': {
|
|
2655
2692
|
const want = subst(step.url, vars);
|
|
2656
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
|
+
}
|