@broberg/lens-daemon 0.1.47 → 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 +1 -1
- package/src/flow.ts +6 -5
- package/src/http.ts +9 -0
- package/src/secret-fill.ts +20 -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.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>"}
|
|
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
|
-
|
|
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 };
|
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);
|
package/src/secret-fill.ts
CHANGED
|
@@ -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`);
|