blindfill 0.0.0-stage → 0.1.0

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/dist/index.js ADDED
@@ -0,0 +1,82 @@
1
+ import {
2
+ AndroidActuator,
3
+ BACKEND_INFO,
4
+ BlindfillError,
5
+ CONTROL_PREFIX,
6
+ Engine,
7
+ REDACTED,
8
+ Scrubber,
9
+ SecretHandle,
10
+ SessionPolicy,
11
+ SubmitGuard,
12
+ WebActuator,
13
+ androidPackages,
14
+ assertBound,
15
+ audit,
16
+ auditPath,
17
+ backendInfo,
18
+ checkAndroidBinding,
19
+ checkBinding,
20
+ checkWebBinding,
21
+ classifyBwFieldType,
22
+ classifyKey,
23
+ createBackend,
24
+ formatTarget,
25
+ getProvider,
26
+ globalScrubber,
27
+ isControlField,
28
+ isLoopbackHost,
29
+ isReadable,
30
+ listProviders,
31
+ loadConfig,
32
+ matchUri,
33
+ parseTarget,
34
+ registerProvider,
35
+ stateDir,
36
+ webUris
37
+ } from "./chunk-V4KGRR36.js";
38
+
39
+ // src/library.ts
40
+ async function withPage(page, opts, fn) {
41
+ const backend = opts.backend ?? createBackend((opts.config ?? loadConfig()).backend ?? "bw", opts.config ?? loadConfig());
42
+ const engine = new Engine(backend, WebActuator.fromPage(page, opts.policy));
43
+ return fn(engine);
44
+ }
45
+ export {
46
+ AndroidActuator,
47
+ BACKEND_INFO,
48
+ BlindfillError,
49
+ CONTROL_PREFIX,
50
+ Engine,
51
+ REDACTED,
52
+ Scrubber,
53
+ SecretHandle,
54
+ SessionPolicy,
55
+ SubmitGuard,
56
+ WebActuator,
57
+ androidPackages,
58
+ assertBound,
59
+ audit,
60
+ auditPath,
61
+ backendInfo,
62
+ checkAndroidBinding,
63
+ checkBinding,
64
+ checkWebBinding,
65
+ classifyBwFieldType,
66
+ classifyKey,
67
+ createBackend,
68
+ formatTarget,
69
+ getProvider,
70
+ globalScrubber,
71
+ isControlField,
72
+ isLoopbackHost,
73
+ isReadable,
74
+ listProviders,
75
+ loadConfig,
76
+ matchUri,
77
+ parseTarget,
78
+ registerProvider,
79
+ stateDir,
80
+ webUris,
81
+ withPage
82
+ };
package/dist/mcp.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+
4
+ declare function buildServer(): McpServer;
5
+ declare function startMcp(): Promise<void>;
6
+
7
+ export { buildServer, startMcp };
package/dist/mcp.js ADDED
@@ -0,0 +1,343 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ assertRevision,
4
+ attach,
5
+ loadProfile,
6
+ loadSession,
7
+ stopSession
8
+ } from "./chunk-KA4SHI33.js";
9
+ import {
10
+ BlindfillError,
11
+ Engine,
12
+ SessionPolicy,
13
+ WebActuator,
14
+ attachSettings,
15
+ audit,
16
+ createBackend,
17
+ globalScrubber,
18
+ loadConfig,
19
+ unverifiedNotice
20
+ } from "./chunk-V4KGRR36.js";
21
+
22
+ // src/mcp.ts
23
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
24
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
25
+ import { z } from "zod";
26
+ var CONTRACT = "Blindfill contract: secret-class fields (password, TOTP seed, hidden fields, card numbers, keys) are write-only. They can be filled into a page but are never returned by any tool. Readable fields (username, URIs, text fields, field names) and the current TOTP code are returned normally. Fills are bound to the item's vault URIs, not to anything you pass. After a secret fill the session is locked: probe/candidates are refused until session_stop. Fills and submits are one-shot; unknown outcomes are never retried.";
27
+ var engine = null;
28
+ var ownedActuator = null;
29
+ async function getEngine() {
30
+ if (engine && ownedActuator) return engine;
31
+ if (engine) await engine.stop();
32
+ engine = null;
33
+ const cfg = loadConfig();
34
+ const backend = createBackend(cfg.backend ?? "bw", cfg);
35
+ const n = unverifiedNotice(backend);
36
+ if (n) process.stderr.write(n + "\n");
37
+ const aset = attachSettings(cfg);
38
+ if (aset.endpoint || aset.endpointFile || loadSession()) {
39
+ const { actuator, persist } = await attach(aset);
40
+ engine = new Engine(backend, actuator, persist);
41
+ } else {
42
+ ownedActuator = await WebActuator.launch({
43
+ headless: cfg.web?.headless ?? true,
44
+ executablePath: cfg.web?.executablePath,
45
+ policy: new SessionPolicy()
46
+ });
47
+ engine = new Engine(backend, ownedActuator);
48
+ }
49
+ return engine;
50
+ }
51
+ function reply(o, isError = false) {
52
+ const text = JSON.stringify(o, null, 2);
53
+ const safe = globalScrubber.guard(text, JSON.stringify({ ok: false, error: { code: "WITHHELD" } }));
54
+ return { content: [{ type: "text", text: safe }], isError: isError || safe !== text };
55
+ }
56
+ async function run(fn) {
57
+ try {
58
+ return reply(await fn());
59
+ } catch (e) {
60
+ if (!(e instanceof BlindfillError)) return reply({ ok: false, error: { code: "INTERNAL" } }, true);
61
+ const be = e;
62
+ return reply(
63
+ {
64
+ ok: false,
65
+ error: { code: be.code, message: String(be.message) },
66
+ candidates: be.candidates
67
+ },
68
+ true
69
+ );
70
+ }
71
+ }
72
+ var itemSel = {
73
+ item: z.string().optional().describe("Backend item id (preferred)."),
74
+ query: z.string().optional().describe("Search text; must match exactly one item.")
75
+ };
76
+ var urlArg = z.string().optional().describe("Navigate here first (http/https only), then inspect. Without it the current page is used.");
77
+ var expectShape = z.object({
78
+ urlIncludes: z.string().optional().describe("Success if the final URL (origin+path) contains this."),
79
+ selector: z.string().optional().describe("Success if this element becomes visible (structural CSS only)."),
80
+ failSelector: z.string().optional().describe("Failure if this element becomes visible (structural CSS only)."),
81
+ timeoutMs: z.number().int().positive().max(3e4).optional()
82
+ }).optional().describe('Evidence used to report the outcome. Without it the outcome is "unknown".');
83
+ function buildServer() {
84
+ const server = new McpServer({ name: "blindfill", version: "0.1.0" });
85
+ const sdk = server;
86
+ if (typeof sdk.createToolError !== "function") throw new Error("MCP SDK changed: createToolError is gone");
87
+ sdk.createToolError = () => reply({ ok: false, error: { code: "INVALID_REQUEST" } }, true);
88
+ server.registerTool(
89
+ "probe",
90
+ {
91
+ description: `Describe the form fields of the current page (structure only: names, types, labels; never values) and list vault items bound to this origin. ${CONTRACT}`,
92
+ inputSchema: { url: urlArg }
93
+ },
94
+ ({ url }) => run(async () => (await getEngine()).probe(url))
95
+ );
96
+ server.registerTool(
97
+ "candidates",
98
+ {
99
+ description: `List candidate input fields (names only, no values). Refused after a secret fill. ${CONTRACT}`,
100
+ inputSchema: { role: z.enum(["username", "password", "totp"]).optional(), url: urlArg }
101
+ },
102
+ ({ role, url }) => run(async () => (await getEngine()).candidates(role, url))
103
+ );
104
+ server.registerTool(
105
+ "item_show",
106
+ {
107
+ description: `Show a vault item: readable fields with values, and the NAMES of secret fields (their values are never shown). ${CONTRACT}`,
108
+ inputSchema: itemSel
109
+ },
110
+ ({ item, query }) => run(async () => (await getEngine()).itemShow({ item, query }))
111
+ );
112
+ server.registerTool(
113
+ "list_credentials",
114
+ {
115
+ description: `List vault items (at most 100): id, name, bound origins, field NAMES and whether the item has rules. No value of any field, no notes, no TOTP code. Same output as the CLI "item list". ${CONTRACT}`,
116
+ inputSchema: { query: z.string().optional().describe("Search text; without it every item is listed.") }
117
+ },
118
+ ({ query }) => run(async () => (await getEngine()).itemList(query ?? ""))
119
+ );
120
+ server.registerTool(
121
+ "profile_login",
122
+ {
123
+ description: `Run a local login recipe (profile) on the one already-open page whose origin matches it; no navigation. Profiles are private local files a person creates with "blindfill profile init"; this tool cannot create or change them, and the recipe grants no authority beyond the item's own URIs. check=true plans only, diagnose=true returns value-free diagnostics. Submits only with submit=true (default false), at most once, never retried. ${CONTRACT}`,
124
+ inputSchema: {
125
+ name: z.string().describe("Profile name."),
126
+ check: z.boolean().optional().describe("Plan only: no secret read, no field touched."),
127
+ diagnose: z.boolean().optional().describe("Value-free structural diagnosis of the recipe page."),
128
+ submit: z.boolean().optional().describe("Submit once after filling (default false)."),
129
+ page: z.number().int().min(0).optional().describe("Page index (list_pages) when several pages match."),
130
+ revision: z.string().optional().describe("Reviewed profile revision; refused if the recipe changed since."),
131
+ expect: expectShape
132
+ }
133
+ },
134
+ ({ name, revision, submit, ...opts }) => run(async () => {
135
+ const p = loadProfile(name);
136
+ assertRevision(p, revision);
137
+ return (await getEngine()).runProfile(p, { ...opts, submit: submit ?? false });
138
+ })
139
+ );
140
+ server.registerTool(
141
+ "totp_code",
142
+ {
143
+ description: `Return the current TOTP code of an item (a short-lived, readable value). The TOTP seed is never returned. ${CONTRACT}`,
144
+ inputSchema: itemSel
145
+ },
146
+ ({ item, query }) => run(async () => (await getEngine()).totpCode({ item, query }))
147
+ );
148
+ server.registerTool(
149
+ "fill",
150
+ {
151
+ description: `Fill fields of the current page from a vault item (default fields: username, password) and optionally submit once. The secret is written straight into the page; you will not receive it. Refused if the page origin is not bound by the item. Locks the session after a secret fill. ${CONTRACT}`,
152
+ inputSchema: {
153
+ ...itemSel,
154
+ fields: z.array(z.string()).optional().describe("Field names: username, password, totp, or other item field names."),
155
+ url: z.string().optional().describe("Navigate here first. The binding is checked against where the browser ends up."),
156
+ submit: z.boolean().optional().describe("Submit once after filling (default false)."),
157
+ rule: z.string().optional().describe("Explicit field-rule id from the item rules (chosen by origin when omitted)."),
158
+ expect: expectShape
159
+ }
160
+ },
161
+ (a) => run(async () => (await getEngine()).fill(a))
162
+ );
163
+ server.registerTool(
164
+ "human_handoff",
165
+ {
166
+ description: `Hand the browser to a human (CAPTCHA, consent screen, push-MFA) or take it back. action=pause stops every agent-driven browser action until action=resume; status shows the state. You only ever see origin+path of open pages; resume does not clear the post-fill lock. ${CONTRACT}`,
167
+ inputSchema: {
168
+ action: z.enum(["pause", "resume", "status"]),
169
+ reason: z.enum(["captcha", "consent", "mfa", "other"]).optional().describe("Required for pause.")
170
+ }
171
+ },
172
+ ({ action, reason }) => run(async () => {
173
+ const e = await getEngine();
174
+ return action === "pause" ? e.handoffPause(reason ?? "other") : action === "resume" ? e.handoffResume() : e.handoffStatus();
175
+ })
176
+ );
177
+ server.registerTool(
178
+ "list_pages",
179
+ {
180
+ description: `List the open pages of the attached browser context as origin + path only (no query, no titles, no values). ${CONTRACT}`,
181
+ inputSchema: {}
182
+ },
183
+ () => run(async () => (await getEngine()).pages())
184
+ );
185
+ server.registerTool(
186
+ "discover_fields",
187
+ {
188
+ description: `Plan a fill without doing it: which item fields and rule would be used on this page. Reads no secret and touches no field. Refused after a secret fill. ${CONTRACT}`,
189
+ inputSchema: {
190
+ ...itemSel,
191
+ url: urlArg,
192
+ rule: z.string().optional(),
193
+ registration: z.boolean().optional().describe("Plan a registration rule instead of a login."),
194
+ submit: z.boolean().optional().describe("Also validate that the rule submit control is usable.")
195
+ }
196
+ },
197
+ (a) => run(async () => (await getEngine()).discover(a))
198
+ );
199
+ server.registerTool(
200
+ "diagnose_fields",
201
+ {
202
+ description: `Structural, value-free diagnosis of the page (counts, tags, types, DOM paths; never values or raw attributes) and of the rule mapping when a rule is given. Refused after a secret fill. ${CONTRACT}`,
203
+ inputSchema: { ...itemSel, url: urlArg, rule: z.string().optional() }
204
+ },
205
+ (a) => run(async () => (await getEngine()).diagnose(a))
206
+ );
207
+ server.registerTool(
208
+ "verify_login",
209
+ {
210
+ description: `Report whether caller-supplied page evidence (CSS selectors) is visible: success/failure booleans only. It proves nothing about identity. Allowed after the lock. ${CONTRACT}`,
211
+ inputSchema: {
212
+ success: z.string().describe("Structural CSS selector that is visible when logged in."),
213
+ failure: z.string().optional().describe("Structural CSS selector visible on failure.")
214
+ }
215
+ },
216
+ (a) => run(async () => (await getEngine()).verify(a))
217
+ );
218
+ server.registerTool(
219
+ "register_credentials",
220
+ {
221
+ description: `Fill an account-registration form using the stored password of an item that binds the page and an explicit registration rule. The same stored value is typed into the password and confirmation fields; nothing is returned. Fill-only unless submit=true; at most one submit; never retried. ${CONTRACT}`,
222
+ inputSchema: {
223
+ ...itemSel,
224
+ rule: z.string().describe("Registration rule id (required; never inferred)."),
225
+ url: z.string().optional(),
226
+ submit: z.boolean().optional(),
227
+ expect: expectShape
228
+ }
229
+ },
230
+ (a) => run(async () => (await getEngine()).register(a))
231
+ );
232
+ server.registerTool(
233
+ "fill_totp",
234
+ {
235
+ description: `Fetch the current TOTP code and type it into the page's one-time-code field; optionally submit once. ${CONTRACT}`,
236
+ inputSchema: {
237
+ ...itemSel,
238
+ url: z.string().optional(),
239
+ submit: z.boolean().optional(),
240
+ expect: expectShape
241
+ }
242
+ },
243
+ (a) => run(async () => (await getEngine()).fillTotp(a))
244
+ );
245
+ server.registerTool(
246
+ "passkey_sign",
247
+ {
248
+ description: `Sign in with the item's passkey (Chromium only). The item must bind this page and its rpId must cover the host; the private key goes to a temporary browser authenticator and is never returned. Pass click (structural CSS) for the page's passkey button; answered at most once. ${CONTRACT}`,
249
+ inputSchema: {
250
+ ...itemSel,
251
+ url: urlArg,
252
+ click: z.string().optional().describe("Button that starts the page passkey sign-in (structural CSS)."),
253
+ expect: expectShape
254
+ }
255
+ },
256
+ (a) => run(async () => (await getEngine()).passkey(a))
257
+ );
258
+ server.registerTool(
259
+ "passkey_register",
260
+ {
261
+ description: `Create a passkey for this page and store it in the item (Chromium, bw only). Add only: the item must bind the page and hold no passkey yet. The page's own WebAuthn create request is answered once by a temporary browser authenticator; the private key goes straight into the vault and is never returned. Returns rp_id and credential_id. ${CONTRACT}`,
262
+ inputSchema: {
263
+ ...itemSel,
264
+ url: urlArg,
265
+ click: z.string().optional().describe("Button that starts the page passkey creation (structural CSS)."),
266
+ expect: expectShape
267
+ }
268
+ },
269
+ (a) => run(async () => (await getEngine()).passkeyRegister(a))
270
+ );
271
+ server.registerTool(
272
+ "android_offer",
273
+ {
274
+ description: `Arm the blindfill companion APK on an adb-attached phone for one fill. kind=password: the app on screen gets a "blindfill: <item>" autofill suggestion (or Credential Manager password entry); kind=password-new: the same into a sign-up form (password and confirmation; the caller submits); kind=passkey: the app's passkey request gets a blindfill entry. The phone reports the requesting app's package and signer; the item must bind the package (androidapp:// URI; a blindfill.signers pin is checked when present), or for a WebView the https domain it shows, or nothing is sent. Waits up to timeout_s for the phone. ${CONTRACT}`,
275
+ inputSchema: {
276
+ ...itemSel,
277
+ serial: z.string().describe("adb device serial"),
278
+ kind: z.enum(["password", "password-new", "passkey"]),
279
+ timeout_s: z.number().int().min(5).max(300).optional()
280
+ }
281
+ },
282
+ ({ timeout_s, ...a }) => run(
283
+ async () => (await getEngine()).androidOffer({ ...a, timeoutMs: timeout_s ? timeout_s * 1e3 : void 0 })
284
+ )
285
+ );
286
+ server.registerTool(
287
+ "android_passkey_register",
288
+ {
289
+ description: `Arm the blindfill companion APK on an adb-attached phone for one passkey creation (bw only). Add only: the item must bind the app (androidapp://; a blindfill.signers pin is checked when present) and https://<rp_id> and hold no passkey. The host makes the key and stores it in the vault; the phone gets only the attestation. Returns rp_id and credential_id. ${CONTRACT}`,
290
+ inputSchema: {
291
+ ...itemSel,
292
+ serial: z.string().describe("adb device serial"),
293
+ rp_id: z.string().describe("relying party id (domain) the app registers for"),
294
+ timeout_s: z.number().int().min(5).max(300).optional()
295
+ }
296
+ },
297
+ ({ timeout_s, rp_id, ...a }) => run(
298
+ async () => (await getEngine()).androidPasskeyRegister({
299
+ ...a,
300
+ rpId: rp_id,
301
+ timeoutMs: timeout_s ? timeout_s * 1e3 : void 0
302
+ })
303
+ )
304
+ );
305
+ server.registerTool(
306
+ "session_stop",
307
+ {
308
+ description: `Stop the browser session and clear the post-fill lock and one-shot counters. ${CONTRACT}`,
309
+ inputSchema: {}
310
+ },
311
+ () => run(async () => {
312
+ if (engine) await engine.stop();
313
+ engine = null;
314
+ ownedActuator = null;
315
+ const r = await stopSession();
316
+ audit({ event: "session", outcome: "stopped" });
317
+ return { ...r, locked: false };
318
+ })
319
+ );
320
+ return server;
321
+ }
322
+ async function startMcp() {
323
+ const server = buildServer();
324
+ await server.connect(new StdioServerTransport());
325
+ process.stderr.write("blindfill MCP server ready (stdio)\n");
326
+ const bye = async () => {
327
+ await engine?.stop().catch(() => void 0);
328
+ process.exit(0);
329
+ };
330
+ process.on("SIGINT", bye);
331
+ process.on("SIGTERM", bye);
332
+ void ownedActuator;
333
+ }
334
+ if (process.argv[1] && /mcp\.(js|ts)$/.test(process.argv[1])) {
335
+ startMcp().catch((e) => {
336
+ process.stderr.write(globalScrubber.scrub(String(e?.message ?? e)) + "\n");
337
+ process.exit(1);
338
+ });
339
+ }
340
+ export {
341
+ buildServer,
342
+ startMcp
343
+ };