@broberg/lens-daemon 0.1.46 → 0.1.48

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.46",
3
+ "version": "0.1.48",
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
@@ -53,7 +53,7 @@ export type ActivateMode = 'auto' | 'click' | 'enter';
53
53
  /** F009.121 — where a `fill` reads a SECRET from instead of carrying it inline:
54
54
  * a gitignored file (absolute, or relative to the run's local_path) or a daemon
55
55
  * env var. The value is read at run time and never echoed. */
56
- export type SecretFrom = { path: string } | { env: string };
56
+ export type SecretFrom = { path: string } | { env: string } | { vault: string };
57
57
  /** F009.137 — or a code that arrives by mail (the test mailbox only). */
58
58
  export type ValueFrom = SecretFrom | { mail: MailFrom } | { owner: OwnerFrom };
59
59
 
@@ -909,8 +909,8 @@ function validateAndNormalizeSteps(steps: unknown[], depth = 0, inParallel = fal
909
909
  } else if (vf !== undefined) {
910
910
  const keys = vf && typeof vf === 'object' && !Array.isArray(vf) ? Object.keys(vf) : [];
911
911
  const k = keys[0];
912
- if (keys.length !== 1 || (k !== 'path' && k !== 'env') || typeof (vf as Record<string, unknown>)[k] !== 'string' || !(vf as Record<string, string>)[k]) {
913
- throw new Error('fill valueFrom must be exactly one of {path: "<file>"} or {env: "<NAME>"}');
912
+ if (keys.length !== 1 || (k !== 'path' && k !== 'env' && k !== 'vault') || typeof (vf as Record<string, unknown>)[k] !== 'string' || !(vf as Record<string, string>)[k]) {
913
+ throw new Error('fill valueFrom must be exactly one of {path: "<file>"}, {env: "<NAME>"} or {vault: "<secret id>"}');
914
914
  }
915
915
  }
916
916
  }
@@ -1311,10 +1311,11 @@ function parseManuscriptStep(s: string): FlowStep {
1311
1311
  valueFrom: { mail: { to: mail[1]!, ...(subj ? { subject: subj[1]!.trim() } : {}), ...(re ? { match: re[1]! } : {}) } },
1312
1312
  };
1313
1313
  }
1314
- const from = s.match(/\]\s+from\s+(file|env)\s+(\S.*)$/i);
1314
+ const from = s.match(/\]\s+from\s+(file|env|vault)\s+(\S.*)$/i);
1315
1315
  if (from) {
1316
1316
  const src = from[2]!.trim();
1317
- return { type: 'fill', testid: testid(), valueFrom: from[1]!.toLowerCase() === 'file' ? { path: src } : { env: src } };
1317
+ const kind = from[1]!.toLowerCase();
1318
+ return { type: 'fill', testid: testid(), valueFrom: kind === 'file' ? { path: src } : kind === 'env' ? { env: src } : { vault: src } };
1318
1319
  }
1319
1320
  const v = s.split('=').slice(1).join('=').trim();
1320
1321
  return { type: 'fill', testid: testid(), value: v };
@@ -3081,7 +3082,14 @@ export async function runFlow(flow: Flow, env: AuthEnv, opts: RunFlowOptions = {
3081
3082
  // at load has not ejected us, and comparing against what we asked for
3082
3083
  // would call that an ejection on every single run.
3083
3084
  if (formsAVerdict(step.type)) formedAVerdict = true;
3084
- if (NAVIGATES_BY_DESIGN.has(step.type)) {
3085
+ // F009.139 (jam, run 03c39df0) — the ejection guard watches the page under
3086
+ // test only. A step in an opened window or an extension popup acts on
3087
+ // ANOTHER page, whose own navigations (an OAuth dialog moving from account
3088
+ // switch to consent) are that window's business, not an ejection.
3089
+ const onPageUnderTest = (step as { in?: string }).in === undefined;
3090
+ if (!onPageUnderTest) {
3091
+ // nothing: the page under test was not touched by this step
3092
+ } else if (NAVIGATES_BY_DESIGN.has(step.type)) {
3085
3093
  urlAtLoad = safeUrl(sp) ?? urlAtLoad;
3086
3094
  // A goto is already settled — Playwright waited for it. Any OTHER
3087
3095
  // navigating action may commit after it returns, so it leaves a note
package/src/http.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  // all hit these. Artifact bytes are served here too, so an <img> in the
6
6
  // dashboard points straight at the daemon.
7
7
 
8
+ import { setVaultReader } from './secret-fill.ts';
8
9
  import { browsersPresent } from './ensure-chromium.ts';
9
10
  import { chromeCloneStatus } from './chrome-clones.ts';
10
11
  import { Hono } from 'hono';
@@ -41,6 +42,14 @@ export function createLensRouter(deps: LensDeps): Hono {
41
42
  r.use('*', localRequestGuard(deps.port));
42
43
  // lens F001.5 — the daemon's sandbox is injected, never copied (sandbox.ts).
43
44
  if (deps.resolveSandboxedPath) setSandboxResolver(deps.resolveSandboxedPath);
45
+ // F010.8 — `fill … from vault <id>` reads through the daemon's own cardmem key.
46
+ // Lazy: the cloud client is re-made on login, so it is asked for at read time.
47
+ setVaultReader(async (secretId) => {
48
+ const cloud = deps.cloud?.();
49
+ if (!cloud) throw new Error('not signed in to cardmem');
50
+ const r = await cloud.callTool<{ value?: unknown }>('cardmem_get_secret', { secret_id: secretId });
51
+ return typeof r?.value === 'string' ? r.value : '';
52
+ });
44
53
  // lens F001.5 — the routes that used to be registered one by one in the
45
54
  // daemon's index.ts. First, so their specific paths win as they did there.
46
55
  registerDaemonRoutes(r, deps);
@@ -10,12 +10,32 @@ import { fillAndVerify } from './fill.ts';
10
10
  import type { FilledPassword } from './password-in-url.ts';
11
11
  import type { SecretFrom } from './flow.ts';
12
12
 
13
+ // F010.8 — a password kept in cardmem's vault, read by the DAEMON by its secret id
14
+ // (the daemon's own cardmem key), so the value never passes through an agent, a
15
+ // manuscript or a report. Installed by createLensRouter from deps.cloud.
16
+ type VaultReader = (secretId: string) => Promise<string>;
17
+ let vaultReader: VaultReader | null = null;
18
+ export function setVaultReader(fn: VaultReader | null): void {
19
+ vaultReader = fn;
20
+ }
21
+
13
22
  /** Read the secret. Every error names WHERE it looked and never WHAT it found. */
14
23
  export async function readSecret(
15
24
  vf: SecretFrom,
16
25
  secretRoot: string | undefined,
17
26
  env: Record<string, string | undefined> = process.env,
18
27
  ): Promise<string> {
28
+ if ('vault' in vf) {
29
+ if (!vaultReader) throw new Error('fill valueFrom {vault}: this daemon is not signed in to cardmem, so it cannot read the vault');
30
+ let v: string;
31
+ try {
32
+ v = await vaultReader(vf.vault);
33
+ } catch (err) {
34
+ throw new Error(`fill valueFrom {vault}: could not read secret ${vf.vault} (${err instanceof Error ? err.message.split('\n')[0]!.slice(0, 160) : 'error'})`);
35
+ }
36
+ if (!v) throw new Error(`fill valueFrom {vault}: secret ${vf.vault} is empty`);
37
+ return v;
38
+ }
19
39
  if ('env' in vf) {
20
40
  const v = env[vf.env];
21
41
  if (!v) throw new Error(`fill valueFrom: env ${vf.env} is not set in the daemon`);