@crewhaus/target-browser-driver 0.4.0 → 0.4.2

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.d.ts CHANGED
@@ -22,7 +22,10 @@
22
22
  * in sync.
23
23
  * 5. Reads user input and runs `runChatLoop`. Two modes (G51):
24
24
  * - ONE-SHOT: a `--prompt <text>` value or piped stdin runs a single
25
- * turn and exits (the pre-0.4 behaviour, for CI/scripting).
25
+ * turn and exits (the pre-0.4 behaviour, for CI/scripting). Nobody
26
+ * is there to answer an `ask` permission, so this branch alone
27
+ * carries the G11 approval seam (`permissions.ask_mode`, default
28
+ * `pause`) and PARKS the turn instead of collapsing it to a deny.
26
29
  * - REPL: an interactive TTY with no `--prompt` drops into the
27
30
  * persistent driver REPL — the chromium context stays connected for
28
31
  * the whole `runChatLoop` call, so the agent observes → acts →
package/dist/index.js CHANGED
@@ -22,7 +22,10 @@
22
22
  * in sync.
23
23
  * 5. Reads user input and runs `runChatLoop`. Two modes (G51):
24
24
  * - ONE-SHOT: a `--prompt <text>` value or piped stdin runs a single
25
- * turn and exits (the pre-0.4 behaviour, for CI/scripting).
25
+ * turn and exits (the pre-0.4 behaviour, for CI/scripting). Nobody
26
+ * is there to answer an `ask` permission, so this branch alone
27
+ * carries the G11 approval seam (`permissions.ask_mode`, default
28
+ * `pause`) and PARKS the turn instead of collapsing it to a deny.
26
29
  * - REPL: an interactive TTY with no `--prompt` drops into the
27
30
  * persistent driver REPL — the chromium context stays connected for
28
31
  * the whole `runChatLoop` call, so the agent observes → acts →
@@ -207,6 +210,16 @@ export function emitBrowserDriver(ir, opts = {}) {
207
210
  }
208
211
  function renderAgent(ir) {
209
212
  const startUrl = ir.driver.startUrl;
213
+ // SECURITY — `driver.allowPrivateTargets` relaxes BOTH SSRF layers together:
214
+ // the chromium backend's DNS-pinning proxy and the Navigate tool's pre-goto
215
+ // guard. Emitted ONLY when the spec opts in, so an ordinary bundle is
216
+ // byte-identical to 0.4.1. Waiving one layer alone would be worse than
217
+ // waiving neither: with only the guard relaxed, the proxy answers loopback
218
+ // with its own 403 body, which RENDERS, so the agent screenshots a block
219
+ // page instead of failing cleanly.
220
+ const allowPrivate = ir.driver.allowPrivateTargets === true;
221
+ const allowPrivateField = allowPrivate ? ", ssrfProxy: false" : "";
222
+ const allowPrivateNavField = allowPrivate ? ", allowPrivateTargets: true" : "";
210
223
  const hasRules = ir.permissions.rules.length > 0;
211
224
  const permImport = hasRules
212
225
  ? `import { BUILTIN_DEFAULT_RULES } from "@crewhaus/permission-engine";\n`
@@ -244,6 +257,7 @@ import { createScreenshotTool } from "@crewhaus/tool-screen-capture";
244
257
  import { createAllMouseKeyboardTools } from "@crewhaus/tool-mouse-keyboard";
245
258
  import { createFindElementTool } from "@crewhaus/tool-vision-grounding";
246
259
  import { runChatLoop } from "@crewhaus/runtime-core";
260
+ import { createPendingApprovalStore, resolveSessionRootDir } from "@crewhaus/runtime-core";
247
261
  import { createRunContext } from "@crewhaus/run-context";
248
262
  import { defaultCatalog } from "@crewhaus/tool-catalog";
249
263
  import { createSessionStore } from "@crewhaus/session-store";
@@ -332,14 +346,14 @@ async function main(): Promise<void> {
332
346
  }
333
347
 
334
348
  emit({ kind: "browser_start", backend: SPEC_BACKEND });
335
- const driver = createDriver({ backend: SPEC_BACKEND, viewport: SPEC_VIEWPORT });
349
+ const driver = createDriver({ backend: SPEC_BACKEND, viewport: SPEC_VIEWPORT${allowPrivateField} });
336
350
  await driver.connect();
337
351
  if (SPEC_START_URL !== undefined) {
338
352
  await driver.goto(SPEC_START_URL);
339
353
  emit({ kind: "navigated", url: SPEC_START_URL });
340
354
  }
341
355
 
342
- const navigateTool = createNavigateTool({ driver });
356
+ const navigateTool = createNavigateTool({ driver${allowPrivateNavField} });
343
357
  const screenshotTool = createScreenshotTool({ driver });
344
358
  const mk = createAllMouseKeyboardTools({ driver });
345
359
  const findElement = createFindElementTool({ driver, model: SPEC_GROUNDING_MODEL });
@@ -362,6 +376,15 @@ async function main(): Promise<void> {
362
376
  maxTokens: ${ir.agent.maxTokens ?? 4096},${budgetField(ir, " ")}${limitsFields(ir, " ")}${hooksField}${permField}
363
377
  };
364
378
 
379
+ // G11 — a compiled bundle is NON-INTERACTIVE: a tool that lands on \`ask\`
380
+ // has nobody to prompt, so without this it collapsed to a deny. Rooted
381
+ // where the run's session files land, so parks live beside them (and
382
+ // inside a tenant's rebased root when one is active). No I/O until a park.
383
+ const __approvalRoot = resolveSessionRootDir(undefined);
384
+ const __approvals = createPendingApprovalStore(
385
+ __approvalRoot !== undefined ? { rootDir: __approvalRoot } : {},
386
+ );
387
+
365
388
  // The REPL lets runChatLoop drive stdin turn-by-turn (singleTurn omitted);
366
389
  // one-shot seeds the single inbound message. \`resume\` + \`seedMessages\` is
367
390
  // legal ONLY under singleTurn (the seed is the new inbound, the replayed
@@ -377,7 +400,7 @@ async function main(): Promise<void> {
377
400
  return await runChatLoop({
378
401
  ...runOptions,
379
402
  singleTurn: true,
380
- installSigintHandler: false,
403
+ installSigintHandler: false,${renderApprovalFields(ir, " ")}
381
404
  seedMessages: [{ role: "user", content: oneShotPrompt }],
382
405
  ...(resume !== undefined ? { resume } : {}),
383
406
  });
@@ -411,6 +434,26 @@ main().catch((err) => {
411
434
  });
412
435
  `;
413
436
  }
437
+ /**
438
+ * Loop contract 0.4 (G11) — the `askMode` + `approvals` fields. Unlike the
439
+ * CLI's `approvalRunOptions`, a bundle parses no `--ask-mode`, so the spec
440
+ * value is FIXED here at emit time. Deliberately NOT folded into
441
+ * `renderPermissionsField`: that one early-returns "" when the spec declares
442
+ * no `permissions:` block, which is exactly the case where parking matters
443
+ * most — with no block every unmatched tool resolves to `ask`.
444
+ *
445
+ * The store is rendered UNCONDITIONALLY, including under `"deny"` where it
446
+ * never parks, so runtime-core's diagnostic can honestly say `ask_mode:
447
+ * "deny"` instead of blaming absent plumbing (it branches on `approvals ===
448
+ * undefined`).
449
+ *
450
+ * One-shot ONLY. The REPL branch spreads `runOptions`, and a REPL prompts on
451
+ * stdin — parking a turn that has a human sitting at it would be wrong.
452
+ */
453
+ function renderApprovalFields(ir, indent) {
454
+ return (`\n${indent}askMode: ${escapeJsonString(ir.permissions.askMode ?? "pause")},` +
455
+ `\n${indent}approvals: { store: __approvals, surface: "browser" },`);
456
+ }
414
457
  function renderPermissionsField(ir) {
415
458
  const { mode, rules } = ir.permissions;
416
459
  if (mode === undefined && rules.length === 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewhaus/target-browser-driver",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "description": "Codegen for the BROW target — emits a single agent.ts that boots a chromium driver + vision-grounding tools (Section 25 BROW)",
6
6
  "main": "dist/index.js",
@@ -15,9 +15,9 @@
15
15
  "test": "bun test src"
16
16
  },
17
17
  "dependencies": {
18
- "@crewhaus/errors": "0.4.0",
19
- "@crewhaus/infra-utils": "0.4.0",
20
- "@crewhaus/ir": "0.4.0"
18
+ "@crewhaus/errors": "0.4.2",
19
+ "@crewhaus/infra-utils": "0.4.2",
20
+ "@crewhaus/ir": "0.4.2"
21
21
  },
22
22
  "license": "Apache-2.0",
23
23
  "author": {