@broberg/lens-daemon 0.1.59 → 0.1.61
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-headers.ts +104 -0
- package/src/flow.ts +66 -5
- package/src/mcp.ts +3 -1
- package/src/owner-fill.ts +21 -3
- package/src/service.ts +5 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@broberg/lens-daemon",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.61",
|
|
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",
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// F010.17 — a flow sends a request header whose value lives in cardmem's vault, and
|
|
2
|
+
// ONLY to the hosts it names. beacon (F010.5) lets a Lens run past Cloudflare
|
|
3
|
+
// Turnstile on a customer domain with a secret header; the secret must never reach
|
|
4
|
+
// any other host the run touches (a CDN, Cloudflare itself, analytics).
|
|
5
|
+
import type { BrowserContext, Route } from 'playwright';
|
|
6
|
+
import { readSecret } from './secret-fill.ts';
|
|
7
|
+
|
|
8
|
+
export interface FlowHeader { name: string; from: { vault: string }; hosts: string[] }
|
|
9
|
+
export interface ResolvedHeader { name: string; value: string; hosts: Set<string> }
|
|
10
|
+
|
|
11
|
+
const HEADER_NAME = /^[A-Za-z0-9][A-Za-z0-9-]*$/;
|
|
12
|
+
// A bare hostname: no scheme, port, path or wildcard. A listed host is a promise
|
|
13
|
+
// about where the secret goes, so "*.x" or "x:443" is refused rather than guessed at.
|
|
14
|
+
const HOST = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/;
|
|
15
|
+
|
|
16
|
+
/** Refused when malformed, never dropped: a dropped header runs the flow without the
|
|
17
|
+
* pass and reports Turnstile as the site failing. */
|
|
18
|
+
export function parseFlowHeaders(input: unknown): FlowHeader[] {
|
|
19
|
+
let h = input;
|
|
20
|
+
if (typeof h === 'string') {
|
|
21
|
+
try {
|
|
22
|
+
h = JSON.parse(h);
|
|
23
|
+
} catch {
|
|
24
|
+
throw new Error('flow.headers was a string but not valid JSON — pass [{name, from: {vault}, hosts: [...]}]');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (!Array.isArray(h) || h.length === 0) throw new Error('flow.headers must be a non-empty array of {name, from: {vault: "<secret id>"}, hosts: ["<host>"]}');
|
|
28
|
+
const seen = new Set<string>();
|
|
29
|
+
return h.map((e, i) => {
|
|
30
|
+
const o = e as Record<string, unknown> | null;
|
|
31
|
+
if (!o || typeof o !== 'object' || Array.isArray(o) || Object.keys(o).some((k) => !['name', 'from', 'hosts'].includes(k))) {
|
|
32
|
+
throw new Error(`flow.headers[${i}] must be {name, from: {vault}, hosts} and nothing else`);
|
|
33
|
+
}
|
|
34
|
+
if (typeof o.name !== 'string' || !HEADER_NAME.test(o.name)) throw new Error(`flow.headers[${i}].name must be a header name (letters, digits, dash)`);
|
|
35
|
+
if (seen.has(o.name.toLowerCase())) throw new Error(`flow.headers: "${o.name}" is listed twice`);
|
|
36
|
+
seen.add(o.name.toLowerCase());
|
|
37
|
+
const f = o.from as Record<string, unknown> | null;
|
|
38
|
+
if (!f || typeof f !== 'object' || Array.isArray(f) || Object.keys(f).length !== 1 || typeof f.vault !== 'string' || !f.vault.trim()) {
|
|
39
|
+
throw new Error(`flow.headers[${i}].from must be {vault: "<secret id>"} — a header value only ever comes from the vault`);
|
|
40
|
+
}
|
|
41
|
+
if (!Array.isArray(o.hosts) || o.hosts.length === 0 || !o.hosts.every((x) => typeof x === 'string' && HOST.test(x))) {
|
|
42
|
+
throw new Error(`flow.headers[${i}].hosts must list exact hostnames (e.g. "beacon.broberg.ai") — no scheme, port, path or wildcard`);
|
|
43
|
+
}
|
|
44
|
+
return { name: o.name, from: { vault: f.vault.trim() }, hosts: o.hosts as string[] };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Read every value once, before the first step. The error names the secret id, never a value. */
|
|
49
|
+
export async function resolveFlowHeaders(headers: FlowHeader[]): Promise<ResolvedHeader[]> {
|
|
50
|
+
const out: ResolvedHeader[] = [];
|
|
51
|
+
for (const h of headers) {
|
|
52
|
+
let value: string;
|
|
53
|
+
try {
|
|
54
|
+
value = await readSecret({ vault: h.from.vault }, undefined);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
const why = err instanceof Error ? err.message.replace(/^fill valueFrom \{vault\}: /, '') : 'error';
|
|
57
|
+
throw new Error(`flow.headers ${h.name}: ${why}`);
|
|
58
|
+
}
|
|
59
|
+
out.push({ name: h.name, value, hosts: new Set(h.hosts) });
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The headers this request may carry: only those whose host list holds its EXACT hostname. */
|
|
65
|
+
export function headersFor(url: string, headers: ResolvedHeader[]): Record<string, string> {
|
|
66
|
+
let host: string;
|
|
67
|
+
try {
|
|
68
|
+
host = new URL(url).hostname;
|
|
69
|
+
} catch {
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
72
|
+
const out: Record<string, string> = {};
|
|
73
|
+
for (const h of headers) if (h.hosts.has(host)) out[h.name] = h.value;
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Install on a context. A matching request is fetched with redirects NOT followed and
|
|
79
|
+
* fulfilled with that answer: Playwright carries headers given to continue()/fetch()
|
|
80
|
+
* into every redirect, so a listed host answering 302 → elsewhere would hand the
|
|
81
|
+
* secret to that elsewhere. Unfollowed, the browser makes the redirected request
|
|
82
|
+
* itself, and it comes back through this handler and its host check.
|
|
83
|
+
*/
|
|
84
|
+
export async function installFlowHeaders(context: BrowserContext, headers: ResolvedHeader[]): Promise<void> {
|
|
85
|
+
if (headers.length === 0) return;
|
|
86
|
+
await context.route('**/*', async (route: Route) => {
|
|
87
|
+
const req = route.request();
|
|
88
|
+
const extra = headersFor(req.url(), headers);
|
|
89
|
+
if (Object.keys(extra).length === 0) return route.fallback();
|
|
90
|
+
const response = await route.fetch({ headers: { ...req.headers(), ...extra }, maxRedirects: 0 });
|
|
91
|
+
return route.fulfill({ response });
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Wrap a context preparation so the headers go on after it, in every context a run opens. */
|
|
96
|
+
export function withFlowHeaders(
|
|
97
|
+
prepare: ((context: BrowserContext) => Promise<void>) | undefined,
|
|
98
|
+
headers: () => ResolvedHeader[],
|
|
99
|
+
): ((context: BrowserContext) => Promise<void>) | undefined {
|
|
100
|
+
return async (context) => {
|
|
101
|
+
if (prepare) await prepare(context);
|
|
102
|
+
await installFlowHeaders(context, headers());
|
|
103
|
+
};
|
|
104
|
+
}
|
package/src/flow.ts
CHANGED
|
@@ -38,7 +38,8 @@ 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 {
|
|
41
|
+
import { parseFlowHeaders, resolveFlowHeaders, withFlowHeaders, type FlowHeader, type ResolvedHeader } from './flow-headers.ts';
|
|
42
|
+
import { approveNumberWithOwner, fillFromOwner, MS_NUMBER_SELECTOR, OWNER_KINDS, OWNER_WAIT_MAX_MS, type OwnerFrom, type OwnerKind } from './owner-fill.ts';
|
|
42
43
|
import {
|
|
43
44
|
EDIT_EVENTS,
|
|
44
45
|
waitForListening,
|
|
@@ -120,6 +121,8 @@ export type FlowStep =
|
|
|
120
121
|
// Wait until the page URL contains this substring — the redirect-back assertion
|
|
121
122
|
// so a manuscript knows it left the 3rd party and is back on our origin.
|
|
122
123
|
| { type: 'waitForUrl'; url: string; label?: string; timeout?: number }
|
|
124
|
+
/** F010.16 — read Microsoft's number-matching number and let the owner approve it in ARS. */
|
|
125
|
+
| { type: 'ownerNumber'; question: string; selector?: string; label?: string; timeout?: number }
|
|
123
126
|
// F082.x (lens-gap) — DOM inspector: dump a frame's iframes/inputs/clickables
|
|
124
127
|
// (names, ids, roles, iframe titles, testids, text) so an author can discover
|
|
125
128
|
// the exact anchors on a 3rd-party page (Stripe's accordion + PCI iframes)
|
|
@@ -218,6 +221,9 @@ export interface Flow {
|
|
|
218
221
|
/** F009.141 — a named browser («in <name>:») signs in as its OWN user. Without an
|
|
219
222
|
* entry it uses the run's auth, as before. */
|
|
220
223
|
browsers?: Record<string, { auth: AuthConfig }>;
|
|
224
|
+
/** F010.17 — request headers whose value is read from cardmem's vault, sent ONLY to
|
|
225
|
+
* requests whose hostname exactly equals one of `hosts` (every browser of the run). */
|
|
226
|
+
headers?: FlowHeader[];
|
|
221
227
|
steps: FlowStep[];
|
|
222
228
|
}
|
|
223
229
|
|
|
@@ -443,6 +449,8 @@ export interface FlowResult {
|
|
|
443
449
|
/** F009.131 — set when auth.persist was asked for: whether the renewed login was
|
|
444
450
|
* written back to statePath, and why not when it was not. Never a value. */
|
|
445
451
|
auth_persisted?: { ok: boolean; reason?: string };
|
|
452
|
+
/** F010.17 — the vault headers this run sent and the hosts they were limited to. Never a value. */
|
|
453
|
+
headers?: Array<{ name: string; hosts: string[] }>;
|
|
446
454
|
/** F010.1 — browsers the daemon reinstalled because their binary was missing. */
|
|
447
455
|
browser_repaired?: Array<{ engine: string; ms: number }>;
|
|
448
456
|
/** F010.7 — Chrome code-sign copies Lens removed after this run's browser closed. */
|
|
@@ -532,6 +540,8 @@ export const STEP_TYPES = new Set([
|
|
|
532
540
|
'expectRequest',
|
|
533
541
|
// F009.139 — follow a window the page opened
|
|
534
542
|
'waitForPopup', 'waitForPopupClose',
|
|
543
|
+
// F010.16 — Microsoft number matching through ARS
|
|
544
|
+
'ownerNumber',
|
|
535
545
|
]);
|
|
536
546
|
|
|
537
547
|
/** Validate + normalise an untrusted flow (HTTP/MCP boundary). Throws on the
|
|
@@ -634,6 +644,7 @@ export function parseFlow(input: unknown): Flow {
|
|
|
634
644
|
browsers[name] = { auth: e.auth as AuthConfig };
|
|
635
645
|
}
|
|
636
646
|
}
|
|
647
|
+
const headers = f.headers === undefined ? undefined : parseFlowHeaders(f.headers);
|
|
637
648
|
if (!extension && usesPopup(f.steps as FlowStep[])) {
|
|
638
649
|
throw new Error('openPopup / in:"popup" need flow.extension — there is no extension loaded to open a popup from');
|
|
639
650
|
}
|
|
@@ -649,6 +660,7 @@ export function parseFlow(input: unknown): Flow {
|
|
|
649
660
|
...(networkShapes ? { network_shapes: networkShapes } : {}),
|
|
650
661
|
...(f.passkeys === 'unavailable' || f.passkeys === 'virtual' ? { passkeys: f.passkeys } : {}),
|
|
651
662
|
...(browsers ? { browsers } : {}),
|
|
663
|
+
...(headers ? { headers } : {}),
|
|
652
664
|
steps: f.steps as FlowStep[],
|
|
653
665
|
};
|
|
654
666
|
}
|
|
@@ -789,6 +801,7 @@ export const STEP_FIELDS: Record<string, string[]> = {
|
|
|
789
801
|
clickSelector: ['selector', 'frame', 'at'],
|
|
790
802
|
waitForBuild: ['sha'],
|
|
791
803
|
waitForUrl: ['url'],
|
|
804
|
+
ownerNumber: ['question', 'selector'],
|
|
792
805
|
inspect: ['frame', 'html', 'testid'],
|
|
793
806
|
assert: ['js'],
|
|
794
807
|
screenshot: [],
|
|
@@ -915,6 +928,11 @@ function validateAndNormalizeSteps(steps: unknown[], depth = 0, inParallel = fal
|
|
|
915
928
|
throw new Error('autocomplete step requires pickText (string) or pickIndex (number)');
|
|
916
929
|
}
|
|
917
930
|
}
|
|
931
|
+
if (s.type === 'ownerNumber') {
|
|
932
|
+
const o = s as { question?: unknown; selector?: unknown };
|
|
933
|
+
if (typeof o.question !== 'string' || !o.question.trim()) throw new Error('ownerNumber step requires a "question" the owner sees in ARS');
|
|
934
|
+
if (o.selector !== undefined && (typeof o.selector !== 'string' || !o.selector.trim())) throw new Error('ownerNumber step: "selector" must be a CSS selector string');
|
|
935
|
+
}
|
|
918
936
|
if (s.type === 'capture' && (s as { to?: unknown }).to !== undefined) {
|
|
919
937
|
// F010.15 — to vault: a target, and never a variable that would hold the value.
|
|
920
938
|
const c = s as { to?: unknown; vault?: unknown; as?: unknown; from?: unknown };
|
|
@@ -1315,7 +1333,7 @@ export const MANUSCRIPT_VERBS = [
|
|
|
1315
1333
|
'expectText', 'expectVisible', 'expectEditable', 'expectAbsent', 'expectTopmost',
|
|
1316
1334
|
'fillSelector', 'clickSelector',
|
|
1317
1335
|
'inspect', 'assert', 'screenshot', 'capture',
|
|
1318
|
-
'waitForPopup', 'waitForPopupClose',
|
|
1336
|
+
'waitForPopup', 'waitForPopupClose', 'approve',
|
|
1319
1337
|
] as const;
|
|
1320
1338
|
|
|
1321
1339
|
function parseManuscriptStep(s: string): FlowStep {
|
|
@@ -1469,6 +1487,12 @@ function parseManuscriptStep(s: string): FlowStep {
|
|
|
1469
1487
|
const match = m[1] === '~' ? 'contains' : m[1] === '==' ? 'equals' : 'not-equals';
|
|
1470
1488
|
return { type: 'expectText', testid: testid(), text, match };
|
|
1471
1489
|
}
|
|
1490
|
+
case 'approve': {
|
|
1491
|
+
// F010.16 — "approve number [css] from owner \"<question>\"" ([css] optional).
|
|
1492
|
+
const m = s.match(/^approve\s+number(?:\s+\[([^\]]+)\])?\s+from\s+owner\s+"([^"]+)"\s*$/i);
|
|
1493
|
+
if (!m) throw new Error(`approve step "${s}" needs: approve number [css] from owner "<question>"`);
|
|
1494
|
+
return { type: 'ownerNumber', question: m[2]!, ...(m[1] ? { selector: m[1].trim() } : {}) };
|
|
1495
|
+
}
|
|
1472
1496
|
case 'waitforurl':
|
|
1473
1497
|
return { type: 'waitForUrl', url: s.replace(/^waitForUrl\s+/i, '').trim() };
|
|
1474
1498
|
case 'fillselector': {
|
|
@@ -1726,6 +1750,7 @@ function describe(step: FlowStep): string {
|
|
|
1726
1750
|
case 'clickSelector': return `clickSelector ${step.selector}${step.at ? ` @ ${step.at}` : ''}`;
|
|
1727
1751
|
case 'uploadSelector': return `upload ${Array.isArray(step.path) ? `${step.path.length} files` : (step.path.startsWith('data:') ? 'data:…' : step.path)} → ${step.selector}`;
|
|
1728
1752
|
case 'waitForUrl': return `waitForUrl ${step.url}`;
|
|
1753
|
+
case 'ownerNumber': return 'approve number from owner';
|
|
1729
1754
|
case 'inspect': return step.html ? `inspect html${step.testid ? ` [${step.testid}]` : ''}` : step.frame ? 'inspect @frame' : 'inspect';
|
|
1730
1755
|
case 'drag': return `drag ${step.testid} ${step.by ? `by ${step.by.x},${step.by.y}` : `→ ${step.toTestid}`}`;
|
|
1731
1756
|
case 'uploadFile': return `upload ${Array.isArray(step.path) ? `${step.path.length} files` : (step.path.startsWith('data:') ? 'data:…' : step.path)} → ${step.testid}`;
|
|
@@ -2661,6 +2686,16 @@ async function execStep(page: Page, step: FlowStep, base: string, vars: Record<s
|
|
|
2661
2686
|
await resolveLocator(page, b.selector, b.frame).first().setInputFiles(files, { timeout: stepTimeout(step) });
|
|
2662
2687
|
return null;
|
|
2663
2688
|
}
|
|
2689
|
+
case 'ownerNumber': {
|
|
2690
|
+
const selector = step.selector ?? MS_NUMBER_SELECTOR;
|
|
2691
|
+
const loc = page.locator(selector).first();
|
|
2692
|
+
await approveNumberWithOwner(async () => {
|
|
2693
|
+
// Not visible in time = no number: the caller fails the step naming the selector.
|
|
2694
|
+
const shown = await loc.waitFor({ state: 'visible', timeout: stepTimeout(step) }).then(() => true, () => false);
|
|
2695
|
+
return shown ? ((await loc.textContent({ timeout: 1000 })) ?? '').trim() : null;
|
|
2696
|
+
}, selector, step.question, step.timeout);
|
|
2697
|
+
return null;
|
|
2698
|
+
}
|
|
2664
2699
|
case 'waitForUrl': {
|
|
2665
2700
|
const want = subst(step.url, vars);
|
|
2666
2701
|
await page.waitForURL((u) => u.toString().includes(want), { timeout: stepTimeout(step) });
|
|
@@ -2860,7 +2895,11 @@ export async function runFlow(flow: Flow, env: AuthEnv, opts: RunFlowOptions = {
|
|
|
2860
2895
|
const results: FlowStepResult[] = [];
|
|
2861
2896
|
const base = flow.base_url.replace(/\/$/, '');
|
|
2862
2897
|
const from = Math.max(0, opts.from ?? 0);
|
|
2863
|
-
|
|
2898
|
+
// F010.17 — filled from the vault before the first step; every context the run opens
|
|
2899
|
+
// (default, named browsers, a parallel loop iteration) installs them after its auth.
|
|
2900
|
+
let resolvedHeaders: ResolvedHeader[] = [];
|
|
2901
|
+
const withHeaders = (p: ReturnType<typeof authPrepare>) => (flow.headers ? withFlowHeaders(p, () => resolvedHeaders) : p);
|
|
2902
|
+
const prepare = withHeaders(authPrepare(flow.auth, env));
|
|
2864
2903
|
// F074.97 — computed ONCE from the flow's own base_url, so every page this run
|
|
2865
2904
|
// opens (including each parallel loop iteration) seeds the same origin and
|
|
2866
2905
|
// nothing else. A bad seed throws here, before a browser is launched.
|
|
@@ -3007,7 +3046,7 @@ export async function runFlow(flow: Flow, env: AuthEnv, opts: RunFlowOptions = {
|
|
|
3007
3046
|
// F009.141 — its own user when the flow names one, else the run's.
|
|
3008
3047
|
const own = flow.browsers?.[name];
|
|
3009
3048
|
const closed = withPage(
|
|
3010
|
-
{ prepareContext: own ? authPrepare(own.auth, env) : prepare, seedStorage, viewport: opts.viewport, engine: opts.engine, locale: opts.locale, timezone: opts.timezone, reducedMotion: opts.reducedMotion },
|
|
3049
|
+
{ prepareContext: own ? withHeaders(authPrepare(own.auth, env)) : prepare, seedStorage, viewport: opts.viewport, engine: opts.engine, locale: opts.locale, timezone: opts.timezone, reducedMotion: opts.reducedMotion },
|
|
3011
3050
|
async (p) => {
|
|
3012
3051
|
collectFailures(p);
|
|
3013
3052
|
resolvePage(p);
|
|
@@ -3512,6 +3551,26 @@ export async function runFlow(flow: Flow, env: AuthEnv, opts: RunFlowOptions = {
|
|
|
3512
3551
|
}
|
|
3513
3552
|
}
|
|
3514
3553
|
|
|
3554
|
+
// F010.17 — read before a browser is launched: a run without the header would meet
|
|
3555
|
+
// Turnstile and report it as the site failing.
|
|
3556
|
+
if (flow.headers) {
|
|
3557
|
+
try {
|
|
3558
|
+
resolvedHeaders = await resolveFlowHeaders(flow.headers);
|
|
3559
|
+
} catch (err) {
|
|
3560
|
+
skipFill(flow.steps, 0, {}, 'skipped — a flow header could not be read from the vault');
|
|
3561
|
+
await prepared?.cleanup();
|
|
3562
|
+
return {
|
|
3563
|
+
name: flow.name,
|
|
3564
|
+
status: 'error',
|
|
3565
|
+
steps: results.sort((a, b) => a.index - b.index),
|
|
3566
|
+
failed_at: 0,
|
|
3567
|
+
reason: err instanceof Error ? err.message : String(err),
|
|
3568
|
+
duration_ms: Date.now() - startedAt,
|
|
3569
|
+
reduced_motion: opts.reducedMotion ?? 'reduce',
|
|
3570
|
+
};
|
|
3571
|
+
}
|
|
3572
|
+
}
|
|
3573
|
+
|
|
3515
3574
|
try {
|
|
3516
3575
|
await withPage(
|
|
3517
3576
|
{
|
|
@@ -3561,7 +3620,7 @@ export async function runFlow(flow: Flow, env: AuthEnv, opts: RunFlowOptions = {
|
|
|
3561
3620
|
// possibly be authenticated says so instead of producing a confident
|
|
3562
3621
|
// verdict about a login screen. Only when auth was actually requested:
|
|
3563
3622
|
// a deliberately anonymous run is not a problem to report.
|
|
3564
|
-
if (
|
|
3623
|
+
if (flow.auth) {
|
|
3565
3624
|
try {
|
|
3566
3625
|
const held = (await context.cookies()).length;
|
|
3567
3626
|
const applicable = (await context.cookies(base)).length;
|
|
@@ -3724,6 +3783,8 @@ export async function runFlow(flow: Flow, env: AuthEnv, opts: RunFlowOptions = {
|
|
|
3724
3783
|
// currently-green fleet runs red on the day it ships, and that is its own
|
|
3725
3784
|
// decision to announce rather than a side effect of this one.
|
|
3726
3785
|
password_in_url: passwordInUrl(finalUrl, filledPasswords),
|
|
3786
|
+
// F010.17 — which header went where; never its value.
|
|
3787
|
+
...(flow.headers ? { headers: flow.headers.map((h) => ({ name: h.name, hosts: h.hosts })) } : {}),
|
|
3727
3788
|
// F074.99 part 1 — the FIRST page that was not listening. Reported on a
|
|
3728
3789
|
// passing run and never failing it: a plain server-rendered form legitimately
|
|
3729
3790
|
// has no listener, so a red here would be a regression for every repo that
|
package/src/mcp.ts
CHANGED
|
@@ -374,6 +374,7 @@ export const TOOLS = [
|
|
|
374
374
|
'F255.7 — do not start until the app is serving the build under test. A commit sha waits for THAT build; true waits for any change from the build live at run start. Polls GET /api/health for a `build` field (the fleet contract), from the runner with no-store, requiring 3 consecutive matching reads so a fleet mid-rollout cannot end the wait early. Fails loudly if the app exposes no marker. Use it right after a deploy — otherwise a green run may be verifying the build you just replaced.',
|
|
375
375
|
},
|
|
376
376
|
auth: authSchema,
|
|
377
|
+
headers: { type: ['array', 'string'], description: 'F010.17 — [{name, from: {vault: "<secret id>"}, hosts: ["<exact hostname>"]}]: a request header whose value the DAEMON reads from cardmem\'s vault, sent ONLY to requests whose hostname exactly equals a listed host (no subdomains, no wildcards), in every browser of the run. A redirect from a listed host to another host does not carry it. The report lists name + hosts, never the value. A vault read failure ends the run before step 1. Use: a site-owned pass (e.g. beacon\'s Turnstile header) on beacon.broberg.ai + firstcoat.gallery. A service worker\'s own fetches are not covered.' },
|
|
377
378
|
browsers: {
|
|
378
379
|
type: 'object',
|
|
379
380
|
description:
|
|
@@ -416,7 +417,7 @@ export const TOOLS = [
|
|
|
416
417
|
{
|
|
417
418
|
name: 'lens_run_manuscript',
|
|
418
419
|
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.`,
|
|
420
|
+
`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
421
|
inputSchema: {
|
|
421
422
|
type: 'object',
|
|
422
423
|
required: ['project', 'manuscript'],
|
|
@@ -432,6 +433,7 @@ export const TOOLS = [
|
|
|
432
433
|
timezone: timezoneSchema,
|
|
433
434
|
reduced_motion: reducedMotionSchema,
|
|
434
435
|
storage: storageSchema,
|
|
436
|
+
headers: { type: ['array', 'string'], description: 'F010.17 — [{name, from: {vault: "<secret id>"}, hosts: ["<exact hostname>"]}]: a request header whose value the DAEMON reads from cardmem\'s vault, sent ONLY to requests whose hostname exactly equals a listed host (no subdomains, no wildcards), in every browser of the run. A redirect from a listed host to another host does not carry it. The report lists name + hosts, never the value. A vault read failure ends the run before step 1. Use: a site-owned pass (e.g. beacon\'s Turnstile header) on beacon.broberg.ai + firstcoat.gallery. A service worker\'s own fetches are not covered.' },
|
|
435
437
|
browsers: {
|
|
436
438
|
type: 'object',
|
|
437
439
|
description:
|
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
|
+
}
|
package/src/service.ts
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
listBaselineVersions,
|
|
34
34
|
revertBaseline,
|
|
35
35
|
} from './store.ts';
|
|
36
|
+
import { parseFlowHeaders } from './flow-headers.ts';
|
|
36
37
|
import { runFlow, parseFlow, parseRunBrowser, compileManuscript, type Flow, type FlowResult, type FlowStepResult } from './flow.ts';
|
|
37
38
|
// F074.24 — the daemon HOSTS the engine's own runFlow for flat cloud-shape
|
|
38
39
|
// FlowRequests (one wire-shape, driven via @broberg/lens-client). The engine
|
|
@@ -1001,6 +1002,8 @@ export async function lensRunFlow(deps: LensDeps, input: RunFlowInput) {
|
|
|
1001
1002
|
|
|
1002
1003
|
export interface RunManuscriptInput {
|
|
1003
1004
|
project: string;
|
|
1005
|
+
/** F010.17 — vault headers limited to named hosts (see Flow.headers). */
|
|
1006
|
+
headers?: unknown;
|
|
1004
1007
|
/** Markdown manuscript — compiled to a flow then executed. */
|
|
1005
1008
|
manuscript: string;
|
|
1006
1009
|
/** F074.36 — an explicit auth block, same shape lens_run_flow takes. The prose
|
|
@@ -1063,6 +1066,8 @@ export async function lensRunManuscript(deps: LensDeps, input: RunManuscriptInpu
|
|
|
1063
1066
|
flow.browsers = parseFlow({ name: flow.name, base_url: flow.base_url, steps: [{ type: 'goto', path: '/' }], browsers: input.browsers }).browsers;
|
|
1064
1067
|
}
|
|
1065
1068
|
resolveBrowserAuths(flow, input.local_path, deps.sandboxRoots);
|
|
1069
|
+
// F010.17 — no header line in the manuscript language either; the call carries it.
|
|
1070
|
+
if (input.headers !== undefined) flow.headers = parseFlowHeaders(input.headers);
|
|
1066
1071
|
const result = await runFlow(flow, process.env as AuthEnv, {
|
|
1067
1072
|
engine: input.engine,
|
|
1068
1073
|
...resolveLocale(input, manifestLocale(input.local_path, deps.sandboxRoots)),
|