turno-browser 0.6.0 → 0.8.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +13 -5
  3. package/dist/act.js +4 -29
  4. package/dist/agent-cursor-overlay.d.ts +95 -0
  5. package/dist/agent-cursor-overlay.js +358 -0
  6. package/dist/agent-cursor.d.ts +191 -0
  7. package/dist/agent-cursor.js +494 -0
  8. package/dist/api.d.ts +8 -3
  9. package/dist/api.js +6 -3
  10. package/dist/argv.d.ts +2 -1
  11. package/dist/argv.js +7 -1
  12. package/dist/bin/mcp.js +5 -0
  13. package/dist/cli/commands.js +12 -3
  14. package/dist/cli/completion.js +3 -0
  15. package/dist/cli/context.d.ts +2 -0
  16. package/dist/cli/context.js +8 -4
  17. package/dist/cli/do-background.d.ts +2 -0
  18. package/dist/cli/do-background.js +15 -0
  19. package/dist/cli/do.d.ts +4 -0
  20. package/dist/cli/do.js +17 -1
  21. package/dist/cli/flows.js +3 -0
  22. package/dist/cli/identity.d.ts +2 -0
  23. package/dist/cli/identity.js +67 -11
  24. package/dist/cli/init.d.ts +12 -0
  25. package/dist/cli/init.js +219 -0
  26. package/dist/cli/login-summary.d.ts +6 -0
  27. package/dist/cli/login-summary.js +11 -0
  28. package/dist/cli/main.js +3 -0
  29. package/dist/cli/setup.d.ts +32 -0
  30. package/dist/cli/setup.js +32 -23
  31. package/dist/doctor.js +18 -2
  32. package/dist/engine-camoufox.js +1 -0
  33. package/dist/engine-lightpanda.js +1 -0
  34. package/dist/host.d.ts +7 -0
  35. package/dist/host.js +330 -68
  36. package/dist/human-input.d.ts +5 -0
  37. package/dist/human-input.js +1 -1
  38. package/dist/human-step-overlay.d.ts +73 -0
  39. package/dist/human-step-overlay.js +285 -0
  40. package/dist/human-step.d.ts +128 -0
  41. package/dist/human-step.js +521 -0
  42. package/dist/index.d.ts +2 -2
  43. package/dist/index.js +2 -2
  44. package/dist/live-server.d.ts +7 -3
  45. package/dist/live-server.js +13 -15
  46. package/dist/live.d.ts +20 -1
  47. package/dist/live.js +52 -10
  48. package/dist/login.d.ts +22 -2
  49. package/dist/login.js +95 -7
  50. package/dist/network-redact.d.ts +28 -0
  51. package/dist/network-redact.js +202 -0
  52. package/dist/recorder.d.ts +0 -21
  53. package/dist/recorder.js +1 -41
  54. package/dist/recordings.d.ts +5 -0
  55. package/dist/recordings.js +4 -2
  56. package/dist/redact.d.ts +7 -0
  57. package/dist/redact.js +32 -1
  58. package/dist/replay.d.ts +2 -0
  59. package/dist/replay.js +33 -14
  60. package/dist/reputation.d.ts +5 -0
  61. package/dist/reputation.js +12 -7
  62. package/dist/sensitive.d.ts +79 -0
  63. package/dist/sensitive.js +275 -0
  64. package/dist/session.d.ts +12 -0
  65. package/dist/session.js +24 -0
  66. package/dist/settings.d.ts +12 -2
  67. package/dist/settings.js +14 -2
  68. package/dist/tools.d.ts +5 -0
  69. package/dist/tools.js +9 -1
  70. package/dist/tuning.d.ts +4 -1
  71. package/dist/tuning.js +1 -0
  72. package/dist/upstream.d.ts +5 -0
  73. package/dist/watch.d.ts +60 -0
  74. package/dist/watch.js +114 -0
  75. package/npm-shrinkwrap.json +2 -2
  76. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # turno-browser
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - b94a272: New tool `browser_request_human`: the agent hands the browser to the person for a step only they may do (a password, a captcha, an emailed code, a second factor, accepting terms). The tab comes to the front with a banner that shows the instruction and a Done button, and a ring around the target; every call of every session waits until the step ends on a URL, a selector, Done or the timeout (5 minutes by default, 10 at most). The result says what changed and how many clicks and fields the person made, never what they typed. It works with a Chrome window, or with the live view open on a headless Chrome.
8
+
9
+ ### Patch Changes
10
+
11
+ - 298c744: The agent cursor follows the pointer path with humanize on, counts the other busy sessions on the badge with shared tabs, keeps the typing bubble up long enough to see, and keeps its label inside the page. Each session's cursor is named after its own agent ("Claude Code", "Codex", "Cursor", "Copilot", "Gemini CLI") instead of the raw client name or the name of the first one: mcpd sends the client's name with each call (`io.turno/client` in `_meta`), and a shared host uses each connection's own.
12
+ - ce785fd: A password or one-time code never reaches the agent, whoever typed it: every page snapshot (also the snapshot files an action writes to the workspace) shows its value as `[sensitive field]`, and the value is hidden from every later result. `browser_type`, `browser_fill_form` and key presses into a password or one-time code field are refused with an error that says to ask the person (`browser_request_human`) or to use `browser_login`; a flow replay types one only from the secret store (`keychain:<item>`) or from the hidden prompt of `turno browser replay`, which names those parameters for the server it starts in `TURNO_BROWSER_PROMPTED_PARAMS` (listed in `turno help environment`). `browser_network_requests` and `browser_network_request` keep the names of credentials and show `[redacted]` for their values (Authorization, Cookie and Set-Cookie headers, token, code, session, key, secret and password fields), also in a file saved with `filename`. A tool result that ends on a captcha, "verify it's you" or block page says so and suggests that the person handles it.
13
+ - 3a8e4b3: `turno-browser set --help` describes `--engine camoufox` by what it needs and what it lacks, without a "not recommended" label, like the other opt-in settings.
14
+ - 70e2adc: `turno-browser init --agent json` ends with "start a new session of your MCP client" instead of "start a new any MCP client session".
15
+
16
+ ## 0.7.0
17
+
18
+ ### Minor Changes
19
+
20
+ - 69f67a1: The agent cursor: when someone can see the browser (a Chrome window, or the live view), each page shows that an agent is at work and where. A Figma-like arrow with the agent's name and the identity glides to each element it acts on, a ring marks the element, a click leaves a ripple, a field being typed into gets a typing bubble, and a thin frame with a badge ("turno · Claude Code at work", or "paused · you have the controls" while the live view's pause is on) goes around the page while calls run. Several agent sessions on one identity's Chrome each get a cursor and a color of their own, and with humanize on the arrow follows the real pointer path.
21
+
22
+ It is drawn in a closed shadow root that is out of the accessibility tree, out of the page's text and never a click target, and it is hidden while the model's screenshot is taken, so the model sees the page as before. `turno-browser set <id> --cursor auto|on|off` (identity.json `cursor`, format 12) and `turno-browser-mcp --cursor` choose it: `auto` (the default) draws it when the browser can be seen, and `off` leaves pages exactly as they are.
23
+ - 0c723fc: `turno-browser init` sets turno-browser up step by step: it names and creates an identity (or
24
+ uses one that is there), opens Chrome to sign in by hand on a first site, finds the agents
25
+ installed here and runs the agent's `mcp add` command only on a yes. Without a terminal it needs
26
+ `--identity` and `--agent`, skips the sign-in and prints the command instead. `turno-browser`
27
+ with no command now points to it.
28
+
29
+ The first steps say more of what happened:
30
+
31
+ - `login` opens a page that says what to do instead of a blank tab, and on close names the sites
32
+ that were opened, or says that nothing new was signed in.
33
+ - `show` has a "last sign-in" line, local times and a hint to turn on the health check;
34
+ `doctor` says when an identity was never signed in by hand.
35
+ - `list`, `show` and `doctor` say "not in use" instead of "free".
36
+ - `do <id> end` says that Chrome stays open in the background server and how to close it now.
37
+ - `do` errors no longer start with "Error: Error:", and a stale ref or text where a ref goes gets
38
+ a hint (`snapshot`, `find`).
39
+ - `setup claude` suggests `claude-code`.
40
+ - `add` prints its next steps with each explanation on its own line, so the commands paste into
41
+ zsh as they are.
42
+
3
43
  ## 0.6.0
4
44
 
5
45
  ### Minor Changes
package/README.md CHANGED
@@ -11,11 +11,13 @@ that same signed-in browser afterwards.
11
11
 
12
12
  ```sh
13
13
  npm install --global turno-browser
14
- turno-browser add school # a new identity
15
- turno-browser login school # sign in by hand once; cookies persist
16
- turno-browser setup claude-code --identity school # prints how Claude Code gets it
14
+ turno-browser init
17
15
  ```
18
16
 
17
+ `init` asks a name for the identity, opens Chrome so you sign in by hand once, and gives the
18
+ identity to your agent. Each step is also a command of its own: `turno-browser add`, `login` and
19
+ `setup`.
20
+
19
21
  The docs are at [turno.wimo.dev/docs/browser](https://turno.wimo.dev/docs/browser), starting with
20
22
  [Get started](https://turno.wimo.dev/docs/browser/get-started).
21
23
 
@@ -45,11 +47,13 @@ On from the start:
45
47
  |---|---|
46
48
  | [Identities](https://turno.wimo.dev/docs/browser/identities) | one Chrome profile per identity, with its time zone, languages and locale fixed |
47
49
  | [Tab limits](https://turno.wimo.dev/docs/browser/tabs) | at most 8 pages, parked after 5 minutes unused, closed after 15; Chrome closes after 15 minutes without a call |
48
- | [Credential vault](https://turno.wimo.dev/docs/browser/vault) | `browser_login` fills username, password and one-time code; the agent never sees them |
50
+ | [Credential vault](https://turno.wimo.dev/docs/browser/vault) | `browser_login` fills username, password and one-time code; the agent never sees them, and a password field never comes back to it, whoever typed it |
49
51
  | [Session export and import](https://turno.wimo.dev/docs/browser/moving-a-session) | an identity's session as one encrypted file, for another machine |
50
52
  | [`browser_batch`](https://turno.wimo.dev/docs/browser/actions) | up to 20 actions in one call, and errors that say what is in the way |
51
53
  | [Flows](https://turno.wimo.dev/docs/browser/flows) | save what an agent did on a site once, and replay it with parameters |
52
54
  | [From the shell](https://turno.wimo.dev/docs/browser/actions#from-the-shell) | `turno-browser do <id> open`, `snapshot`, `click`, `type`, `read`: the same browser and rules, as shell commands |
55
+ | [Steps only you may do](https://turno.wimo.dev/docs/browser/live-view#when-the-agent-asks-for-you) | `browser_request_human` brings the tab to you with a banner for a password, a captcha, a code or consent; the agent waits, and never gets what you typed |
56
+ | [The agent cursor](https://turno.wimo.dev/docs/browser/agent-cursor) | when you can see the browser, a named cursor and a badge show where the agent is working; the model never sees it |
53
57
  | [Health, reputation and doctor](https://turno.wimo.dev/docs/browser/identities#session-health) | a signed-out identity says so, each site's challenges are counted, and `doctor` checks Chrome and every identity |
54
58
 
55
59
  Off until you turn it on, per identity:
@@ -120,6 +124,9 @@ turno-browser vault list school
120
124
  and only into frames of those origins.
121
125
  - **Never in a result.** Once a value was filled, every result and error shows `[vault: ...]`
122
126
  in its place: snapshots, network requests and console messages.
127
+ - **Password fields too.** A password or a one-time code never comes back to the agent,
128
+ whoever typed it: a snapshot shows `[sensitive field]`, and `browser_type` refuses those
129
+ fields.
123
130
  - **It does not submit.** The agent clicks the sign-in button, unless you run
124
131
  `turno-browser vault submit school auto`.
125
132
 
@@ -146,7 +153,8 @@ started it exits, Chrome closes too.
146
153
  ## Move a session
147
154
 
148
155
  ```sh
149
- turno-browser export school --out school.session --expires 2d # asks for a passphrase twice
156
+ # asks for a passphrase twice
157
+ turno-browser export school --out school.session --expires 2d
150
158
  turno-browser import school.session --as school-laptop
151
159
  ```
152
160
 
package/dist/act.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ModelError, estimateTokens, resolveModel } from "./act-model.js";
2
2
  import { clip, sections, textOf } from "./batch.js";
3
3
  import { actBudget } from "./opt-in-settings.js";
4
- import { SECRET_AUTOCOMPLETE, SECRET_NAME, secretValues } from "./recorder.js";
4
+ import { pageFields, secretValues } from "./sensitive.js";
5
5
  import { readIdentitySettings } from "./settings.js";
6
6
  import { upstream } from "./upstream.js";
7
7
  import { names } from "./names.js";
@@ -140,38 +140,13 @@ export function checkCall(stock, tool, args) {
140
140
  return { error: "natural language actions do not write files" };
141
141
  return { tool, arguments: a };
142
142
  }
143
- /** The values of password, one-time code and card fields in every frame of the page. */
144
- async function sensitiveValues(page) {
145
- const out = [];
146
- for (const frame of page.frames()) {
147
- const values = await frame
148
- .evaluate(({ auto, name }) => {
149
- const a = new RegExp(auto, "i");
150
- const n = new RegExp(name, "i");
151
- const found = [];
152
- for (const el of Array.from(document.querySelectorAll("input, textarea"))) {
153
- const field = el;
154
- if (!field.value)
155
- continue;
156
- const type = (field.type || "").toLowerCase();
157
- if (type === "password" ||
158
- a.test(field.getAttribute("autocomplete") ?? "") ||
159
- n.test(`${field.getAttribute("name") ?? ""} ${field.id}`))
160
- found.push(field.value);
161
- }
162
- return found;
163
- }, { auto: SECRET_AUTOCOMPLETE.source, name: SECRET_NAME.source })
164
- .catch(() => []);
165
- out.push(...values);
166
- }
167
- return out;
168
- }
169
143
  /** The current tab as the model reads it: page, dialog and snapshot, sensitive values hidden. */
170
144
  async function pageForModel(run, reserve) {
171
145
  const page = run.stock.currentPage();
172
146
  if (page)
173
- for (const v of await sensitiveValues(page))
174
- run.redactor.add(v, "sensitive value");
147
+ for (const f of await pageFields(page))
148
+ if (f.kind)
149
+ run.redactor.add(f.value, "sensitive value");
175
150
  const snap = await run.stock.call("browser_snapshot", {}, { snapshot: true });
176
151
  if (snap.isError)
177
152
  throw new ActStop(`the page snapshot failed: ${clip(textOf(snap))}`);
@@ -0,0 +1,95 @@
1
+ /**
2
+ * The agent cursor's page side: one function the host evaluates in a page with a batch of
3
+ * commands (`agent-cursor.ts`). It runs in Playwright's utility world (patchright's
4
+ * `page.evaluate` default), so the state it keeps on `window` is out of the page's own scripts'
5
+ * reach, and it must stay self-contained: it is sent to the page as source, without imports.
6
+ *
7
+ * What it draws lives in a closed shadow root on one host element under `<html>` (never in
8
+ * `<body>`, so `document.body.innerText` never holds it). The host is `aria-hidden` and `inert`
9
+ * (out of the accessibility tree, so out of every snapshot), `pointer-events: none` (never a
10
+ * target of a click or of `elementFromPoint`, so Playwright's hit test and "covered" check see
11
+ * through it) and `position: fixed` with `contain: strict` (no layout, no scroll of its own).
12
+ * It builds nodes with `createElement` and styles them through the CSSOM, so a page's Trusted
13
+ * Types or style CSP does not stop it.
14
+ */
15
+ /** A rectangle in viewport CSS pixels. */
16
+ export interface OverlayBox {
17
+ x: number;
18
+ y: number;
19
+ width: number;
20
+ height: number;
21
+ }
22
+ /** One instruction for the overlay. `key` names a cursor (one per agent session). */
23
+ export type OverlayCommand = {
24
+ op: "actor";
25
+ key: string;
26
+ label: string;
27
+ name: string;
28
+ color: string;
29
+ } | {
30
+ op: "move";
31
+ key: string;
32
+ x: number;
33
+ y: number;
34
+ ms: number;
35
+ } | {
36
+ op: "ring";
37
+ key: string;
38
+ box: OverlayBox | null;
39
+ } | {
40
+ op: "ripple";
41
+ key: string;
42
+ x: number;
43
+ y: number;
44
+ } | {
45
+ op: "typing";
46
+ key: string;
47
+ box: OverlayBox | null;
48
+ } | {
49
+ op: "busy";
50
+ key: string;
51
+ on: boolean;
52
+ }
53
+ /** How many other sessions have a call in flight on this browser, on any page: the badge's "+N". */
54
+ | {
55
+ op: "others";
56
+ n: number;
57
+ } | {
58
+ op: "paused";
59
+ on: boolean;
60
+ } | {
61
+ op: "visible";
62
+ on: boolean;
63
+ } | {
64
+ op: "remove";
65
+ };
66
+ /** What a batch reports back: the motion preference and the viewport, for the host's glide. */
67
+ export interface OverlayReport {
68
+ reducedMotion: boolean;
69
+ width: number;
70
+ height: number;
71
+ /** What the overlay shows now; tests read it, since its DOM is behind a closed shadow root. */
72
+ state: {
73
+ connected: boolean;
74
+ visible: boolean;
75
+ busy: boolean;
76
+ paused: boolean;
77
+ badge: string;
78
+ /** `moves`: how many times the arrow was sent somewhere; `pill`: the side its label is on. */
79
+ cursors: {
80
+ key: string;
81
+ label: string;
82
+ x: number;
83
+ y: number;
84
+ moves: number;
85
+ pill: "right" | "left";
86
+ }[];
87
+ /** The sessions whose typing bubble shows. */
88
+ typing: string[];
89
+ };
90
+ }
91
+ /**
92
+ * Applies `commands` to the page's overlay, building it first when the page has none (a new
93
+ * document after a navigation, or a host the page removed). Runs in the page.
94
+ */
95
+ export declare function cursorOverlay(commands: OverlayCommand[]): OverlayReport;
@@ -0,0 +1,358 @@
1
+ /**
2
+ * The agent cursor's page side: one function the host evaluates in a page with a batch of
3
+ * commands (`agent-cursor.ts`). It runs in Playwright's utility world (patchright's
4
+ * `page.evaluate` default), so the state it keeps on `window` is out of the page's own scripts'
5
+ * reach, and it must stay self-contained: it is sent to the page as source, without imports.
6
+ *
7
+ * What it draws lives in a closed shadow root on one host element under `<html>` (never in
8
+ * `<body>`, so `document.body.innerText` never holds it). The host is `aria-hidden` and `inert`
9
+ * (out of the accessibility tree, so out of every snapshot), `pointer-events: none` (never a
10
+ * target of a click or of `elementFromPoint`, so Playwright's hit test and "covered" check see
11
+ * through it) and `position: fixed` with `contain: strict` (no layout, no scroll of its own).
12
+ * It builds nodes with `createElement` and styles them through the CSSOM, so a page's Trusted
13
+ * Types or style CSP does not stop it.
14
+ */
15
+ /**
16
+ * Applies `commands` to the page's overlay, building it first when the page has none (a new
17
+ * document after a navigation, or a host the page removed). Runs in the page.
18
+ */
19
+ export function cursorOverlay(commands) {
20
+ // The global the overlay keeps its parts under, in the utility world only.
21
+ const GLOBAL = "__turnoAgentCursor";
22
+ const w = window;
23
+ const important = (el, props) => {
24
+ for (const [k, v] of Object.entries(props))
25
+ el.style.setProperty(k, v, "important");
26
+ };
27
+ const CSS = `
28
+ *{box-sizing:border-box}
29
+ .shell{position:fixed;inset:0;pointer-events:none;font:600 12px/16px system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;letter-spacing:.01em}
30
+ .frame{position:fixed;inset:0;border:2px solid var(--c);border-radius:2px;box-shadow:inset 0 0 0 1px rgba(255,255,255,.35),inset 0 0 28px color-mix(in srgb,var(--c) 22%,transparent);opacity:0;transition:opacity .35s ease}
31
+ .badge{position:fixed;top:10px;left:50%;display:flex;align-items:center;gap:7px;padding:5px 11px 5px 9px;border-radius:999px;background:var(--c);color:#fff;box-shadow:0 4px 14px rgba(0,0,0,.22),0 0 0 1px rgba(255,255,255,.25);white-space:nowrap;opacity:0;transform:translate(-50%,-8px);transition:opacity .35s ease,transform .35s ease}
32
+ .dot{width:7px;height:7px;border-radius:50%;background:#fff;box-shadow:0 0 0 0 rgba(255,255,255,.7);animation:pulse 1.4s ease-out infinite}
33
+ .on .frame{opacity:1}
34
+ .on .badge{opacity:1;transform:translate(-50%,0)}
35
+ .paused .frame{border-style:dashed}
36
+ .paused .dot{animation:none;border-radius:1px;width:6px;height:8px;background:linear-gradient(90deg,#fff 0 35%,transparent 35% 65%,#fff 65%)}
37
+ .cursor{position:fixed;left:0;top:0;transform:translate(var(--x),var(--y));transition:transform var(--ms) cubic-bezier(.22,.61,.36,1),opacity .4s ease;will-change:transform}
38
+ .cursor svg{display:block;overflow:visible;filter:drop-shadow(0 2px 3px rgba(0,0,0,.3))}
39
+ .pill{position:absolute;left:15px;top:19px;padding:3px 8px;border-radius:3px 10px 10px 10px;background:var(--c);color:#fff;white-space:nowrap;box-shadow:0 2px 8px rgba(0,0,0,.2)}
40
+ .fx .pill{left:auto;right:calc(100% - 4px);border-radius:10px 3px 10px 10px}
41
+ .fy .pill{top:auto;bottom:calc(100% - 6px);border-radius:10px 10px 10px 3px}
42
+ .fx.fy .pill{border-radius:10px 10px 3px 10px}
43
+ .idle .cursor{opacity:.6}
44
+ .ring{position:fixed;border:2px solid var(--c);border-radius:7px;box-shadow:0 0 0 4px color-mix(in srgb,var(--c) 20%,transparent);opacity:0;transition:opacity .25s ease,left .2s ease,top .2s ease,width .2s ease,height .2s ease}
45
+ .ring.show{opacity:1}
46
+ .ripple{position:fixed;width:14px;height:14px;margin:-7px 0 0 -7px;border-radius:50%;border:2px solid var(--c);background:color-mix(in srgb,var(--c) 25%,transparent);animation:ripple .6s ease-out forwards}
47
+ .typing{position:fixed;display:flex;align-items:center;gap:3px;padding:4px 7px;border-radius:10px;background:var(--c);color:#fff;box-shadow:0 2px 8px rgba(0,0,0,.2)}
48
+ .typing i{width:4px;height:4px;border-radius:50%;background:#fff;animation:blink 1s infinite}
49
+ .typing i:nth-child(2){animation-delay:.15s}
50
+ .typing i:nth-child(3){animation-delay:.3s}
51
+ @keyframes pulse{0%{box-shadow:0 0 0 0 rgba(255,255,255,.7)}70%{box-shadow:0 0 0 6px rgba(255,255,255,0)}100%{box-shadow:0 0 0 0 rgba(255,255,255,0)}}
52
+ @keyframes ripple{to{transform:scale(3.4);opacity:0}}
53
+ @keyframes blink{0%,100%{opacity:.35}50%{opacity:1}}
54
+ @media (prefers-reduced-motion: reduce){
55
+ .frame,.badge,.cursor,.ring{transition:none}
56
+ .dot,.typing i{animation:none}
57
+ .ripple{animation-duration:.01s}
58
+ }`;
59
+ const build = () => {
60
+ const host = document.createElement("turno-agent-cursor");
61
+ host.setAttribute("aria-hidden", "true");
62
+ host.setAttribute("inert", "");
63
+ important(host, {
64
+ all: "initial",
65
+ display: "block",
66
+ position: "fixed",
67
+ inset: "0",
68
+ width: "100vw",
69
+ height: "100vh",
70
+ margin: "0",
71
+ padding: "0",
72
+ border: "0",
73
+ "z-index": "2147483647",
74
+ "pointer-events": "none",
75
+ contain: "strict",
76
+ overflow: "hidden",
77
+ background: "transparent",
78
+ });
79
+ const root = host.attachShadow({ mode: "closed" });
80
+ try {
81
+ const sheet = new CSSStyleSheet();
82
+ sheet.replaceSync(CSS);
83
+ root.adoptedStyleSheets = [sheet];
84
+ }
85
+ catch {
86
+ const style = document.createElement("style");
87
+ style.textContent = CSS;
88
+ root.append(style);
89
+ }
90
+ const shell = document.createElement("div");
91
+ shell.className = "shell idle";
92
+ const frame = document.createElement("div");
93
+ frame.className = "frame";
94
+ const badge = document.createElement("div");
95
+ badge.className = "badge";
96
+ const dot = document.createElement("span");
97
+ dot.className = "dot";
98
+ const badgeText = document.createElement("span");
99
+ badgeText.textContent = "turno · agent at work";
100
+ badge.append(dot, badgeText);
101
+ const layer = document.createElement("div");
102
+ shell.append(frame, layer, badge);
103
+ root.append(shell);
104
+ document.documentElement.append(host);
105
+ const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
106
+ return {
107
+ doc: document,
108
+ host,
109
+ root,
110
+ shell,
111
+ frame,
112
+ badge,
113
+ badgeText,
114
+ layer,
115
+ cursors: new Map(),
116
+ rings: new Map(),
117
+ typing: new Map(),
118
+ timers: new Map(),
119
+ busy: new Set(),
120
+ others: 0,
121
+ lastBusy: "",
122
+ paused: false,
123
+ visible: true,
124
+ reduced,
125
+ };
126
+ };
127
+ let p = w[GLOBAL];
128
+ if (!p || p.doc !== document) {
129
+ p = build();
130
+ w[GLOBAL] = p;
131
+ }
132
+ else if (!p.host.isConnected) {
133
+ // The page replaced <html>'s children (or the host itself): put it back.
134
+ document.documentElement.append(p.host);
135
+ }
136
+ const parts = p;
137
+ const later = (name, ms, fn) => {
138
+ const old = parts.timers.get(name);
139
+ if (old !== undefined)
140
+ clearTimeout(old);
141
+ parts.timers.set(name, window.setTimeout(() => {
142
+ parts.timers.delete(name);
143
+ fn();
144
+ }, ms));
145
+ };
146
+ const cursorFor = (key) => {
147
+ let c = parts.cursors.get(key);
148
+ if (c)
149
+ return c;
150
+ const el = document.createElement("div");
151
+ el.className = "cursor";
152
+ el.style.setProperty("--c", "#2b59ff");
153
+ el.style.setProperty("--x", "-40px");
154
+ el.style.setProperty("--y", "-40px");
155
+ el.style.setProperty("--ms", "0ms");
156
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
157
+ svg.setAttribute("width", "22");
158
+ svg.setAttribute("height", "26");
159
+ svg.setAttribute("viewBox", "0 0 22 26");
160
+ const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
161
+ // A Figma-like arrow, its tip at (2, 2).
162
+ path.setAttribute("d", "M2 2 L2 21 L7.2 16.3 L10.6 23.6 L14 22.1 L10.6 14.9 L17.6 14.9 Z");
163
+ path.setAttribute("fill", "var(--c)");
164
+ path.setAttribute("stroke", "#fff");
165
+ path.setAttribute("stroke-width", "1.6");
166
+ path.setAttribute("stroke-linejoin", "round");
167
+ svg.append(path);
168
+ const pill = document.createElement("div");
169
+ pill.className = "pill";
170
+ el.append(svg, pill);
171
+ parts.layer.append(el);
172
+ c = { el, pill, label: "", name: "", color: "#2b59ff", x: -40, y: -40, moves: 0 };
173
+ parts.cursors.set(key, c);
174
+ return c;
175
+ };
176
+ const colorOf = (key) => parts.cursors.get(key)?.color ?? "#2b59ff";
177
+ const paintBadge = () => {
178
+ const on = parts.busy.size > 0 || parts.paused;
179
+ parts.shell.classList.toggle("on", on);
180
+ parts.shell.classList.toggle("idle", !on);
181
+ parts.shell.classList.toggle("paused", parts.paused);
182
+ const key = parts.busy.has(parts.lastBusy) ? parts.lastBusy : ([...parts.busy][0] ?? parts.lastBusy);
183
+ const color = parts.paused ? "#5c5f66" : colorOf(key);
184
+ parts.frame.style.setProperty("--c", color);
185
+ parts.badge.style.setProperty("--c", color);
186
+ const name = parts.cursors.get(key)?.name;
187
+ // The other sessions at work: those on this page, or on the browser's other pages (shared
188
+ // tabs), whichever says more.
189
+ const n = Math.max(parts.busy.size - 1, parts.others);
190
+ const others = n > 0 ? ` +${n}` : "";
191
+ parts.badgeText.textContent = parts.paused
192
+ ? "paused · you have the controls"
193
+ : `turno · ${name ? `${name} at work` : "agent at work"}${others}`;
194
+ };
195
+ for (const cmd of commands) {
196
+ switch (cmd.op) {
197
+ case "actor": {
198
+ const c = cursorFor(cmd.key);
199
+ c.label = cmd.label;
200
+ c.name = cmd.name;
201
+ c.color = cmd.color;
202
+ c.pill.textContent = cmd.label;
203
+ c.el.style.setProperty("--c", cmd.color);
204
+ break;
205
+ }
206
+ case "move": {
207
+ const c = cursorFor(cmd.key);
208
+ c.x = cmd.x;
209
+ c.y = cmd.y;
210
+ c.el.style.setProperty("--ms", `${parts.reduced ? 0 : Math.max(0, Math.round(cmd.ms))}ms`);
211
+ // The arrow's tip is 2px into its box.
212
+ c.el.style.setProperty("--x", `${Math.round(cmd.x - 2)}px`);
213
+ c.el.style.setProperty("--y", `${Math.round(cmd.y - 2)}px`);
214
+ c.moves++;
215
+ // The label goes left of the arrow near the right edge, and above it near the bottom, so
216
+ // it stays inside the page.
217
+ const pw = c.pill.offsetWidth || 8 * c.label.length + 16;
218
+ const ph = c.pill.offsetHeight || 22;
219
+ c.el.classList.toggle("fx", cmd.x + 13 + pw + 4 > window.innerWidth);
220
+ c.el.classList.toggle("fy", cmd.y + 17 + ph + 4 > window.innerHeight);
221
+ break;
222
+ }
223
+ case "ring": {
224
+ let ring = parts.rings.get(cmd.key);
225
+ if (!cmd.box) {
226
+ ring?.classList.remove("show");
227
+ break;
228
+ }
229
+ if (!ring) {
230
+ ring = document.createElement("div");
231
+ ring.className = "ring";
232
+ parts.layer.prepend(ring);
233
+ parts.rings.set(cmd.key, ring);
234
+ }
235
+ const pad = 4;
236
+ ring.style.setProperty("--c", colorOf(cmd.key));
237
+ ring.style.left = `${Math.round(cmd.box.x - pad)}px`;
238
+ ring.style.top = `${Math.round(cmd.box.y - pad)}px`;
239
+ ring.style.width = `${Math.round(cmd.box.width + 2 * pad)}px`;
240
+ ring.style.height = `${Math.round(cmd.box.height + 2 * pad)}px`;
241
+ ring.classList.add("show");
242
+ const r = ring;
243
+ later(`ring:${cmd.key}`, 1600, () => r.classList.remove("show"));
244
+ break;
245
+ }
246
+ case "ripple": {
247
+ const dot = document.createElement("div");
248
+ dot.className = "ripple";
249
+ dot.style.setProperty("--c", colorOf(cmd.key));
250
+ dot.style.left = `${Math.round(cmd.x)}px`;
251
+ dot.style.top = `${Math.round(cmd.y)}px`;
252
+ parts.layer.append(dot);
253
+ window.setTimeout(() => dot.remove(), 700);
254
+ break;
255
+ }
256
+ case "typing": {
257
+ const old = parts.typing.get(cmd.key);
258
+ if (!cmd.box) {
259
+ if (!old)
260
+ break;
261
+ // A fill ends within a frame: the bubble stays up a moment so a person sees it at all.
262
+ const drop = () => {
263
+ old.remove();
264
+ if (parts.typing.get(cmd.key) === old)
265
+ parts.typing.delete(cmd.key);
266
+ };
267
+ const wait = 900 - (Date.now() - Number(old.dataset.since ?? 0));
268
+ if (wait > 0)
269
+ later(`typing:${cmd.key}`, wait, drop);
270
+ else
271
+ drop();
272
+ break;
273
+ }
274
+ const pending = parts.timers.get(`typing:${cmd.key}`);
275
+ if (pending !== undefined) {
276
+ clearTimeout(pending);
277
+ parts.timers.delete(`typing:${cmd.key}`);
278
+ }
279
+ const bubble = old ?? document.createElement("div");
280
+ if (!old) {
281
+ bubble.dataset.since = String(Date.now());
282
+ bubble.className = "typing";
283
+ bubble.append(document.createElement("i"), document.createElement("i"), document.createElement("i"));
284
+ parts.layer.append(bubble);
285
+ parts.typing.set(cmd.key, bubble);
286
+ }
287
+ bubble.style.setProperty("--c", colorOf(cmd.key));
288
+ const right = cmd.box.x + cmd.box.width;
289
+ bubble.style.left = `${Math.round(Math.min(right + 6, window.innerWidth - 40))}px`;
290
+ bubble.style.top = `${Math.round(Math.max(cmd.box.y + cmd.box.height / 2 - 9, 2))}px`;
291
+ break;
292
+ }
293
+ case "busy": {
294
+ if (cmd.on) {
295
+ parts.busy.add(cmd.key);
296
+ parts.lastBusy = cmd.key;
297
+ const t = parts.timers.get(`idle:${cmd.key}`);
298
+ if (t !== undefined) {
299
+ clearTimeout(t);
300
+ parts.timers.delete(`idle:${cmd.key}`);
301
+ }
302
+ paintBadge();
303
+ }
304
+ else {
305
+ // The frame stays a moment after a call, so a run of calls reads as one stretch of work.
306
+ later(`idle:${cmd.key}`, 2500, () => {
307
+ parts.busy.delete(cmd.key);
308
+ paintBadge();
309
+ });
310
+ }
311
+ break;
312
+ }
313
+ case "paused":
314
+ parts.paused = cmd.on;
315
+ paintBadge();
316
+ break;
317
+ case "others":
318
+ if (parts.others !== cmd.n) {
319
+ parts.others = cmd.n;
320
+ paintBadge();
321
+ }
322
+ break;
323
+ case "visible":
324
+ parts.visible = cmd.on;
325
+ parts.host.style.setProperty("visibility", cmd.on ? "visible" : "hidden", "important");
326
+ break;
327
+ case "remove":
328
+ for (const t of parts.timers.values())
329
+ clearTimeout(t);
330
+ parts.host.remove();
331
+ w[GLOBAL] = undefined;
332
+ break;
333
+ }
334
+ }
335
+ const current = w[GLOBAL];
336
+ return {
337
+ reducedMotion: parts.reduced,
338
+ width: window.innerWidth,
339
+ height: window.innerHeight,
340
+ state: {
341
+ connected: current !== undefined && parts.host.isConnected,
342
+ visible: parts.visible,
343
+ busy: parts.busy.size > 0,
344
+ paused: parts.paused,
345
+ badge: parts.badgeText.textContent ?? "",
346
+ cursors: [...parts.cursors.entries()].map(([key, c]) => ({
347
+ key,
348
+ label: c.label,
349
+ x: c.x,
350
+ y: c.y,
351
+ moves: c.moves,
352
+ pill: c.el.classList.contains("fx") ? "left" : "right",
353
+ })),
354
+ typing: [...parts.typing.keys()],
355
+ },
356
+ };
357
+ }
358
+ //# sourceMappingURL=agent-cursor-overlay.js.map