omowright 0.3.3 → 0.3.5

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.
@@ -25,18 +25,60 @@ await session.stop(); // ALWAYS: returns borrowed tabs, closes the Agent Window
25
25
 
26
26
  ### Shared control (BrowserSkill 0.4+)
27
27
 
28
- The person at the keyboard can work in the task tab while the agent does. The
29
- extension therefore refuses every page action with `permission_denied` /
30
- `data.reason: "cooperation_sync_required"` unless it carries the
31
- `context_id` of the latest `session.cooperate("sync")`. A context is good
32
- for one action: sync, decide from what the sync reported, act with
33
- `{ context }`, then sync again. Gated: navigation (except the first
34
- navigation of the untouched blank tab), every input method, `evaluate` (and
35
- so `bskSnapshot`), `tabClose`, `resize`, `emulate`, `observe` with
36
- `probeHover`, and `screenshot({ fullPage: true })`. Reads (`observe`,
37
- `snapshot`, `getHtml`, `screenshot()`, `console`, `network`,
38
- `waitForNavigation`) need no context. `dependsOn: ["@e2", ...]` narrows the
39
- check to the observed regions the decision used.
28
+ The person at the keyboard can work in the task tab while the agent does, so
29
+ the extension refuses a page action unless it carries what the latest
30
+ `session.cooperate("sync")` returned. Gated: navigation, every input method,
31
+ `drag`, `evaluate` (and so `bskSnapshot`), `tabClose`, `resize`, `emulate`,
32
+ `observe` with `probeHover`, and `screenshot({ fullPage: true })`. Reads
33
+ (`observe`, `snapshot`, `getHtml`, `read`, `extract`, `screenshot()`,
34
+ `console`, `network`, `waitForNavigation`, `waitForElement`) need no context.
35
+
36
+ Every gated action takes `{ context, observation, expect, dependsOn }`
37
+ besides its own options; any other key throws. A session runs under one
38
+ control policy, chosen by its first sync and fixed after that:
39
+
40
+ | Action | `strict` (the default) | `target` (`cooperate("sync", { controlPolicy: "target" })`) |
41
+ | ---------------------------------------- | ------------------------------------ | ----------------------------------------------------------- |
42
+ | click, hover, fill, ... on a ref/selector | a fresh `context` per action | `context`; the same one serves the next DOM action |
43
+ | `evaluate` (and `bskSnapshot`) | a fresh `context` per action | `context` plus an unused `observation`, or `expect` facts, or `unverified: true` |
44
+ | `press` with no target, `navigate` | a fresh `context` per action | `context` plus an unused `observation` |
45
+ | `dependsOn` | narrows the check to observed regions | refused; state facts in `expect` instead |
46
+
47
+ The sync result carries `context_id` and, when the daemon sends one,
48
+ `observation_id`; pass them as `{ context, observation }`. An observation is
49
+ good for one action. `expect` is a list of literal facts the extension checks
50
+ right before the input, for example
51
+ `[{ target: "#total", field: "text", equals: "3" }]` (`field` is `text`,
52
+ `value`, `checked`, `attribute` or `exists`). A false fact refuses the action
53
+ with `permission_denied`, a message starting `Precondition failed:` that names
54
+ the fact (for example `Precondition failed: #total text`), and
55
+ `effect_state: "none"`: nothing is sent to the page. `data.reason` depends on
56
+ the policy: `"precondition_failed"` under `target`, and
57
+ `"cooperation_sync_required"` under `strict`, the same reason a stale context
58
+ gets. Under strict, tell the two apart by the message, then sync and decide
59
+ again from the live page.
60
+
61
+ ```js
62
+ const { connectBrowserSkill } = await import("omowright");
63
+
64
+ const session = await connectBrowserSkill({ name: "check out", focused: false });
65
+ await session.navigate("https://example.com/cart");
66
+ const sync = await session.cooperate("sync", { controlPolicy: "target" });
67
+ const context = sync.context_id;
68
+ await session.click("#apply-coupon", { context });
69
+ await session.click("#checkout", { context, expect: [{ target: "#total", field: "text", equals: "$3.00" }] });
70
+ const next = await session.cooperate("sync");
71
+ await session.press("Enter", { context: next.context_id, observation: next.observation_id });
72
+ const { items } = await session.read("h1"); // no context needed
73
+ await session.stop();
74
+ ```
75
+
76
+ A session's first `navigate` can meet the extension while the new task tab is
77
+ still committing its blank document. That refusal ("The initial task tab
78
+ changed", nothing sent to the page) is handled inside `navigate`: it waits on
79
+ `waitForNavigation` for the tab to settle, checks in `tabList` that the tab is
80
+ still blank, and sends the navigate once more. If the tab never settles or has
81
+ moved on, `navigate` throws the refusal with the tab's state in the message.
40
82
 
41
83
  On `cooperation_sync_required`, call `session.cooperate("wait", { timeoutMs })`
42
84
  (at most 25 s) until it reports `ready`, sync again and replan from the live
@@ -84,8 +126,11 @@ Never a fixed delay.
84
126
  | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
85
127
  | Navigate / history | `navigate(url, {waitUntil, timeoutMs})`, `back()`, `forward()`, `reload({hard})`, `waitForNavigation()` |
86
128
  | Read the page | `observe({maxTokens, cursor, probeHover})` (VOM text with `@eN` refs), `snapshot()`, `getHtml({ref, maxBytes})`, `bskSnapshot(session)` (OmOWright tree + css) |
129
+ | Read values | `read(target, {fields, maxNodes})` (text, value, attributes of matching nodes), `extract("table" \| "list" \| "discover", {target, itemSelector, fields})` |
130
+ | Wait | `waitForElement(target, {state: "visible" \| "hidden" \| "attached" \| "detached", timeoutMs})`, `waitForNavigation()` |
87
131
  | Act | `click(target, {button, clickCount, modifiers})`, `hover`, `fill(target, value)`, `press(key, {target, holdMs})`, `select(target, values)`, `focus`, `blur`, `scrollTo`, `wheel({deltaY})` |
88
- | Script | `evaluate(expression, {awaitPromise, timeoutMs})` → `{ok, value, error}`; Agent Window tabs only |
132
+ | Drag | `drag({selector} \| {ref}, {target, delta: {x, y}, mode})` |
133
+ | Script | `evaluate(expression, {awaitPromise, timeoutMs, unverified})` → `{ok, value, error}`; Agent Window tabs only |
89
134
  | Pixels | `screenshot({ref})` → `{buffer, width, height, captureId}`; `screenshot({fullPage: true})` streams the capture back in chunks |
90
135
  | Tabs | `tabList({scope: "user"})`, `tabCreate({url})`, `tabSelect(id)`, `tabClose(id)`, `tabBorrow(id)` (the user confirms), `tabReturn(id)` |
91
136
  | Humans | `requestHelp({prompt, targets, completionCriteria, timeoutMs})` for login, CAPTCHA, OTP, payment — the extension shows an overlay and waits |
@@ -95,7 +140,10 @@ Anything the daemon refuses comes back as a `BskRpcError` with the daemon's
95
140
  `code` (`not_found`, `invalid_params`, `permission_denied`, `timeout`,
96
141
  `cdp_failed`, `user_aborted`, `no_browser_connected`, ...). Long calls can be
97
142
  cancelled: `const h = session.client.callWithHandle(...)`, then
98
- `session.client.cancel(h.rpcId)`.
143
+ `session.client.cancel(h.rpcId)`. The rest of the daemon's tools (dialogs,
144
+ uploads and downloads, recording, `debug`) are reachable as
145
+ `session.tool("dialog_accept", { dialog_id })` with the daemon's own parameter
146
+ names.
99
147
 
100
148
  ## bskSnapshot leaves no trace
101
149
 
@@ -203,3 +251,10 @@ socket. On another machine, run the library where the daemon is (for example
203
251
  through a machine mesh), or pair the extension to a daemon in server mode
204
252
  (`bsk daemon start --mode server`, WSS required off loopback). Windows named
205
253
  pipes are not discovered automatically; pass `sockPath` explicitly.
254
+
255
+ When the process cannot reach the daemon by socket path at all, pass your own
256
+ transport as `connectBrowserSkill({ client })`. It is any object with
257
+ `call(method, params, options)` that sends one daemon request (`system.status`,
258
+ `session.start`, `tool.*`, `session.stop`) and resolves with its `result` or
259
+ rejects with a `BskRpcError`. The exported type `BskClient` describes it, and
260
+ the session uses nothing else.
@@ -89,23 +89,30 @@ doing: the header becomes the first line of `tree`, and the raw result sits in
89
89
  ## Human handoff: login, OTP, CAPTCHA you can't solve
90
90
 
91
91
  When every rung fails on a login wall, a one-time code, or a challenge the
92
- captcha preset can't clear, hand the tab to the person and wait for a signal:
92
+ captcha preset can't clear, hand the tab to the person. **DO NOT `await` THE
93
+ HANDOFF IN AN EVAL CELL**: a person takes longer than a cell, and an awaited
94
+ handoff holds the kernel until they finish. Subscribe the harness watcher to a
95
+ flag file first, start the handoff without `await`, and end the cell:
93
96
 
94
97
  ```js
95
- const result = await requestHuman(page, {
98
+ const flag = path.join(os.tmpdir(), `omowright-handoff-${Date.now()}.flag`);
99
+ await tool.monitor({ description: "handoff finished", path: flag, event: "create" }); // omo's watcher; subscribe first
100
+ globalThis.omwHandoff = requestHuman(page, {
96
101
  prompt: "Sign in with your account, then click Done.",
97
102
  until: { url: /\/dashboard/ }, // or { selector: "nav.account" } or async page => boolean
98
103
  timeoutMs: 300000,
99
- });
100
- // { outcome: "continued" | "timed_out" | "cancelled", elapsedMs, reason: "until" | "done-button" | "timed_out" | "signal" }
101
- if (result.outcome !== "continued") throw new Error(`handoff ${result.outcome}`);
104
+ }).then(
105
+ // { outcome: "continued" | "timed_out" | "cancelled", elapsedMs, reason: "until" | "done-button" | "timed_out" | "signal" }
106
+ (result) => fs.writeFileSync(flag, result.outcome),
107
+ (error) => fs.writeFileSync(flag, `failed: ${error.message}`),
108
+ );
102
109
  ```
103
110
 
104
- **IN AN EVAL CELL, DO NOT `await` THE HANDOFF.** A person takes longer than a
105
- cell, and an awaited handoff holds the kernel until they finish. Subscribe the
106
- harness watcher, start `requestHuman(...)` without `await`, write its outcome to
107
- the watched file in `.then`, and return; the page stays usable from other cells
108
- meanwhile. Pattern in `eval-kernel.md` (next to this file), "Waits that outlast a cell".
111
+ The event wakes the turn on every outcome. Read the flag: anything but
112
+ `continued` is a handoff that did not happen. The page stays usable from other
113
+ cells meanwhile; more in `eval-kernel.md` (next to this file), "Waits that
114
+ outlast a cell". A plain script with no cell limit may `await requestHuman(...)`
115
+ and read `result.outcome` directly.
109
116
 
110
117
  The call brings the window to the front, injects a shadow-DOM banner with your
111
118
  prompt and a Done button, then polls every `pollMs` for `until` or the button.