taskwindow 0.2.15 → 0.2.16

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/README.md CHANGED
@@ -92,7 +92,7 @@ taking the daemon connection from each other. For another MCP client, connect to
92
92
  | Area | Tools |
93
93
  |---|---|
94
94
  | Status | `taskwindow_status` (daemon/extension readiness and recovery guidance) |
95
- | Tabs | `tabs_list`, `tabs_create`, `tabs_close`, `navigate`, `reload` |
95
+ | Tabs | `tabs_list`, `tabs_create`, `tabs_close`, `navigate`, `reload`, `dialog` (answer an alert, confirm, prompt or "Leave site?") |
96
96
  | See | `computer` (screenshot + click/type/key/scroll/idle, plus `human` mode), `read_page`, `find`, `get_page_text` |
97
97
  | Act | `form_input`, `file_upload`, `upload_image`, `javascript_execute` |
98
98
  | Debug | `read_console_messages`, `read_network_requests` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taskwindow",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
4
4
  "description": "TaskWindow local daemon: bridges the TaskWindow Chrome extension to any MCP client over Streamable HTTP",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "scripts": {
11
11
  "start": "node src/index.js",
12
- "test": "node --test test/agents.test.mjs test/pairing.test.mjs test/extension-bootstrap.test.mjs test/extension-connection.test.mjs test/extension-idle.test.mjs test/extension-cdp.test.mjs test/extension-tabs.test.mjs test/extension-responsive.test.mjs test/extension-human.test.mjs test/bridge.test.mjs test/tool-contract.test.mjs test/updates.test.mjs && node test/run.mjs"
12
+ "test": "node --test test/agents.test.mjs test/pairing.test.mjs test/extension-bootstrap.test.mjs test/extension-connection.test.mjs test/extension-idle.test.mjs test/extension-cdp.test.mjs test/extension-dialog.test.mjs test/extension-tabs.test.mjs test/extension-responsive.test.mjs test/extension-human.test.mjs test/extension-click-ref.test.mjs test/bridge.test.mjs test/tool-contract.test.mjs test/updates.test.mjs && node test/run.mjs"
13
13
  },
14
14
  "engines": {
15
15
  "node": ">=18"
package/src/tools.js CHANGED
@@ -4,6 +4,26 @@ import { mkdir, writeFile } from "node:fs/promises";
4
4
  import os from "node:os";
5
5
  import path from "node:path";
6
6
  import { STORE_EXTENSION_ID } from "./store.js";
7
+ import { compareVersions } from "./updates.js";
8
+
9
+ /** The first extension that clicks an element by ref or selector. */
10
+ export const CLICK_BY_REF_SINCE = "0.2.16";
11
+ const ON_ELEMENT = new Set(["left_click", "right_click", "middle_click", "double_click", "triple_click", "mouse_move"]);
12
+
13
+ /**
14
+ * A click by element sent to an extension that predates it would click at
15
+ * x ?? 0, y ?? 0, the page's top-left corner, since an older computer() ignores
16
+ * ref. Chrome updates the extension from the Web Store on its own schedule, so
17
+ * a new daemon meets an old extension for a while: refuse there instead.
18
+ */
19
+ export function clickByRefRefusal(tool, args, extensionVersion) {
20
+ if (tool !== "computer" || !ON_ELEMENT.has(args?.action) || (!args.ref && !args.selector)) return null;
21
+ if (extensionVersion && compareVersions(extensionVersion, CLICK_BY_REF_SINCE) >= 0) return null;
22
+ return (
23
+ `This TaskWindow extension (${extensionVersion ? `v${extensionVersion}` : "version unknown"}) clicks by x,y only; clicking by ref needs v${CLICK_BY_REF_SINCE}, ` +
24
+ "which Chrome installs from the Web Store on its own. Until then take a screenshot and click at x,y."
25
+ );
26
+ }
7
27
 
8
28
  const tabId = z.number().int().describe("Tab ID from tabs_list. Defaults to the active tab in your session's task groups.");
9
29
 
@@ -29,6 +49,16 @@ const render = z
29
49
  "navigations. This keeps Chrome's debugging banner visible until the tab closes. The tab is still never made active and never takes focus."
30
50
  );
31
51
 
52
+ // A page with unsaved changes holds a navigation behind "Leave site?".
53
+ const onUnsaved = z
54
+ .enum(["keep", "discard"])
55
+ .optional()
56
+ .describe(
57
+ 'What to do if the page has unsaved changes and asks "Leave site?" first. "keep" (default): stay, so nothing is lost; ' +
58
+ 'the call returns "Blocked" and the tab is left as it was. "discard": leave and throw the changes away. ' +
59
+ "Only discard once you know the changes don't matter (e.g. you saved them, or they were a test)."
60
+ );
61
+
32
62
  // Result contract with the extension: {text?, image?: {data, mimeType}, data?}.
33
63
  // The MCP layer turns `image` into an image content block and everything else
34
64
  // into text blocks.
@@ -90,28 +120,46 @@ const rawDefs = [
90
120
  {
91
121
  name: "navigate",
92
122
  description:
93
- "Navigate a tab to a URL. Waits (up to 10s) for the load event, then returns the tab's URL and title.",
94
- inputSchema: { url: z.string().url(), tabId: tabId.optional(), render },
123
+ "Navigate a tab to a URL. Waits (up to 10s) for the load event, then returns the tab's URL and title. " +
124
+ "If the page has unsaved changes it answers \"Blocked\" instead of leaving (see onUnsaved).",
125
+ inputSchema: { url: z.string().url(), tabId: tabId.optional(), render, onUnsaved },
95
126
  timeoutMs: 30_000,
96
127
  },
97
128
  {
98
129
  name: "reload",
99
130
  description:
100
131
  "Reload a tab in place, like the browser's reload button, and wait (up to 10s) for the load event. " +
101
- "Use this — not tabs_create — to refresh a page you already have open.",
132
+ "Use this — not tabs_create — to refresh a page you already have open. " +
133
+ "If the page has unsaved changes it answers \"Blocked\" instead of reloading (see onUnsaved).",
102
134
  inputSchema: {
103
135
  tabId: tabId.optional(),
104
136
  bypassCache: z.boolean().optional().describe("Skip the HTTP cache, like a hard reload (default false)"),
105
137
  render,
138
+ onUnsaved,
106
139
  },
107
140
  timeoutMs: 30_000,
108
141
  },
142
+ {
143
+ name: "dialog",
144
+ description:
145
+ "Answer the dialog a page is showing: an alert, a confirm, a prompt, or the \"Leave site? Changes you made may not be saved\" " +
146
+ "confirmation. Chrome draws these outside the page, so screenshots never show them, and the page can do nothing until one is " +
147
+ "answered. You need this when a tool result says a dialog opened or is blocking the tab (tabs_list marks such tabs too). " +
148
+ "accept = OK / Leave; dismiss = Cancel / Stay. Dismiss is the safe answer when unsure: it never discards work or confirms an action.",
149
+ inputSchema: {
150
+ action: z.enum(["accept", "dismiss"]),
151
+ promptText: z.string().optional().describe("For a prompt dialog with action accept: the text to answer with"),
152
+ tabId: tabId.optional(),
153
+ },
154
+ timeoutMs: 20_000,
155
+ },
109
156
  {
110
157
  name: "computer",
111
158
  description:
112
159
  "Screenshot and low-level mouse/keyboard control of a tab via the Chrome DevTools Protocol. " +
113
160
  "Actions: screenshot (PNG of the viewport, or full page with fullPage), left_click / right_click / " +
114
- "middle_click / double_click / triple_click (at x,y), type (text into the focused element), " +
161
+ "middle_click / double_click / triple_click (at x,y, or on an element: pass its ref from read_page/find instead), " +
162
+ "type (text into the focused element), " +
115
163
  "key (named key press, e.g. Enter, Tab, Escape, ArrowLeft, Backspace), scroll (by dx/dy pixels), " +
116
164
  "mouse_move, wait, idle. Screenshots are in CSS pixels (1 image pixel = 1 coordinate unit, on any display density), so " +
117
165
  "read x,y straight off the last screenshot. " +
@@ -131,6 +179,13 @@ const rawDefs = [
131
179
  tabId: tabId.optional(),
132
180
  x: z.number().int().optional().describe("X coordinate in viewport pixels (clicks, scroll origin, mouse_move)"),
133
181
  y: z.number().int().optional().describe("Y coordinate in viewport pixels"),
182
+ ref: z
183
+ .string()
184
+ .optional()
185
+ .describe(
186
+ "For clicks and mouse_move: the element's ref from read_page/find (e.g. e42), in place of x,y. Clicks its centre, scrolling it into view; refused when something covers it."
187
+ ),
188
+ selector: z.string().optional().describe("For clicks and mouse_move: a CSS selector, as a fallback when no ref is available"),
134
189
  text: z.string().optional().describe('Text for the "type" action'),
135
190
  key: z.string().optional().describe('Key name for the "key" action, e.g. "Enter", "a", "ArrowDown"'),
136
191
  dx: z.number().int().optional().describe("Horizontal scroll delta in pixels"),
@@ -188,7 +243,7 @@ const rawDefs = [
188
243
  name: "read_page",
189
244
  description:
190
245
  "Structured accessibility-style snapshot of the page: a text tree of interactive elements and content, " +
191
- "each labelled with a ref (e.g. e42) you can pass to form_input / file_upload. Cheaper and more reliable " +
246
+ "each labelled with a ref (e.g. e42) you can pass to computer clicks, form_input and file_upload. Cheaper and more reliable " +
192
247
  "than a screenshot for forms and navigation.",
193
248
  inputSchema: { tabId: tabId.optional() },
194
249
  timeoutMs: 20_000,
@@ -439,6 +494,8 @@ export function registerTools(server, { bridge, version, updates = null, logger
439
494
  // it. The retry with that token (same task and url) then gets the tab
440
495
  // the first call opened, not a second tab in a second group.
441
496
  if (def.name === "tabs_create" && !forwardedArgs.sessionToken) forwardedArgs.sessionToken = randomUUID();
497
+ const refusal = clickByRefRefusal(def.name, forwardedArgs, bridge.lastHello?.version);
498
+ if (refusal) throw new Error(refusal);
442
499
  let result;
443
500
  try {
444
501
  result = await bridge.sendTool(def.name, forwardedArgs, def.timeoutMs);
@@ -524,6 +581,8 @@ async function runBatch({ steps, sessionToken }, bridge, logger) {
524
581
  if (!parsed.success) {
525
582
  throw new Error(`invalid params: ${parsed.error.issues.map((e) => `${e.message} at ${e.path.join(".") || "(root)"}`).join("; ")}`);
526
583
  }
584
+ const refusal = clickByRefRefusal(tool, parsed.data, bridge.lastHello?.version);
585
+ if (refusal) throw new Error(refusal);
527
586
  const result = await bridge.sendTool(tool, parsed.data, def.timeoutMs);
528
587
  results.push({ step: i + 1, tool, ok: true, result });
529
588
  } catch (err) {