taskwindow 0.2.20 → 0.2.21

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
@@ -87,6 +87,15 @@ too. Loaded unpacked before the store listing existed? Remove that copy in
87
87
  taking the daemon connection from each other. For another MCP client, connect to `http://127.0.0.1:9377/mcp` with
88
88
  `Authorization: Bearer <token>`; the token is stored in `~/.taskwindow/token`.
89
89
 
90
+ A local broker such as Ateam can keep that bearer on the browser host and use
91
+ `/mcp/session/<uuid>` for a single approved session. Choose a fresh UUID for
92
+ each grant and stop forwarding when it ends. The scoped endpoint lists single
93
+ tab operations and binds every call to the session’s own Chrome group, even
94
+ when **All tabs** is enabled. Check `scopedSessions` on `/health` to confirm
95
+ both the daemon and the connected extension support it. Bind consent to that
96
+ Chrome connection by retaining its `scopedConnectionId` and sending it as
97
+ `X-TaskWindow-Connection` on each call. A changed connection requires new consent.
98
+
90
99
  ## What the agent gets
91
100
 
92
101
  | Area | Tools |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taskwindow",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
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",
package/src/bridge.js CHANGED
@@ -47,21 +47,25 @@ export class Bridge {
47
47
  // Single active extension connection: newest wins.
48
48
  if (this.ext && this.ext !== ws) {
49
49
  this.logger.log("[bridge] replacing existing extension connection");
50
+ this.#failAllPending(new Error("TaskWindow extension connection changed"));
50
51
  try {
51
52
  this.ext.close(4000, "superseded by a new extension connection");
52
53
  } catch {}
53
54
  }
54
55
  this.ext = ws;
56
+ this.connectionId = randomUUID();
57
+ this.lastHello = null;
55
58
  this.lastExtMessage = Date.now();
56
59
 
57
60
  ws.on("message", (raw) => this.#onMessage(ws, raw));
58
61
  ws.on("close", () => {
59
62
  if (this.ext === ws) {
60
63
  this.ext = null;
64
+ this.connectionId = null;
61
65
  this.lastHello = null;
62
66
  this.logger.log("[bridge] extension disconnected");
67
+ this.#failAllPending(new Error("TaskWindow extension disconnected"));
63
68
  }
64
- this.#failAllPending(new Error("TaskWindow extension disconnected"));
65
69
  });
66
70
  ws.on("error", () => {});
67
71
  });
@@ -133,7 +137,8 @@ export class Bridge {
133
137
  } catch {
134
138
  return;
135
139
  }
136
- if (ws === this.ext) this.lastExtMessage = Date.now();
140
+ if (ws !== this.ext) return;
141
+ this.lastExtMessage = Date.now();
137
142
  switch (msg.type) {
138
143
  case "hello":
139
144
  this.lastHello = msg;
package/src/index.js CHANGED
@@ -551,6 +551,8 @@ const server = http.createServer(async (req, res) => {
551
551
  version: VERSION,
552
552
  latestVersion: updates.latest,
553
553
  extensionConnected: bridge.connected,
554
+ scopedSessions: bridge.connected && bridge.lastHello?.scopedSessions === true,
555
+ scopedConnectionId: bridge.connected ? bridge.connectionId : null,
554
556
  extensionVersion: bridge.lastHello?.version || null,
555
557
  extensionId: bridge.lastHello?.id || null,
556
558
  port: config.port,
@@ -626,7 +628,8 @@ const server = http.createServer(async (req, res) => {
626
628
  return;
627
629
  }
628
630
 
629
- if (url.pathname === "/mcp") {
631
+ const session = /^\/mcp\/session\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/.exec(url.pathname);
632
+ if (url.pathname === "/mcp" || session) {
630
633
  const auth = req.headers.authorization || "";
631
634
  if (auth !== `Bearer ${config.token}`) {
632
635
  sendJson(res, 401, { error: "invalid or missing bearer token" });
@@ -649,7 +652,16 @@ const server = http.createServer(async (req, res) => {
649
652
  sendJson(res, 400, { error: "invalid JSON body" });
650
653
  return;
651
654
  }
652
- await handleMcp(req, res, body);
655
+ if (session && Array.isArray(body)) {
656
+ sendJson(res, 400, { error: "Send one browser operation per request" });
657
+ return;
658
+ }
659
+ const connection = req.headers["x-taskwindow-connection"];
660
+ if (session && connection !== undefined && connection !== bridge.connectionId) {
661
+ sendJson(res, 409, { error: "The Chrome connection changed. Request approval again." });
662
+ return;
663
+ }
664
+ await handleMcp(req, res, body, session ? "scoped:" + session[1] : null);
653
665
  } catch (err) {
654
666
  if (!res.headersSent) sendJson(res, 500, { error: err.message });
655
667
  else res.end();
package/src/mcp-http.js CHANGED
@@ -8,9 +8,9 @@ import { registerTools } from "./tools.js";
8
8
  * Streamable HTTP can hit it.
9
9
  */
10
10
  export function createMcpRequestHandler({ bridge, version, updates = null, logger = console }) {
11
- return async function handleMcpRequest(req, res, parsedBody) {
11
+ return async function handleMcpRequest(req, res, parsedBody, scope = null) {
12
12
  const server = new McpServer({ name: "taskwindow", version });
13
- registerTools(server, { bridge, version, updates, logger });
13
+ registerTools(server, { bridge, version, updates, logger, scope });
14
14
  const transport = new StreamableHTTPServerTransport({
15
15
  sessionIdGenerator: undefined,
16
16
  enableJsonResponse: true,
package/src/tools.js CHANGED
@@ -510,14 +510,29 @@ function toMcpResult(result) {
510
510
  return { content };
511
511
  }
512
512
 
513
- export function registerTools(server, { bridge, version, updates = null, logger = console }) {
513
+ // Only single, tab-scoped operations. Shortcuts and batches schedule subsequent
514
+ // operations beyond the authorizing client's per-request revocation check.
515
+ const SESSION_TOOLS = new Set([
516
+ "tabs_create", "tabs_list", "tabs_close", "navigate", "reload", "read_page",
517
+ "find", "get_page_text", "form_input", "computer", "dialog",
518
+ ]);
519
+
520
+ export function registerTools(server, { bridge, version, updates = null, logger = console, scope = null }) {
521
+ const connection = bridge.connectionId;
514
522
  const notice = () =>
515
523
  updates?.notice({
516
524
  extensionVersion: bridge.lastHello?.version || null,
517
525
  extensionStore: bridge.lastHello?.id === STORE_EXTENSION_ID,
518
526
  }) ?? null;
519
527
  for (const def of toolDefs) {
520
- server.registerTool(def.name, { description: def.description, inputSchema: def.inputSchema }, async (args) => {
528
+ if (scope && !SESSION_TOOLS.has(def.name)) continue;
529
+ const inputSchema = { ...def.inputSchema };
530
+ if (scope) {
531
+ delete inputSchema.sessionToken;
532
+ delete inputSchema.save_to_disk;
533
+ delete inputSchema.human;
534
+ }
535
+ server.registerTool(def.name, { description: def.description, inputSchema }, async (args) => {
521
536
  try {
522
537
  // The sessionToken is stated once, in the first tabs_create result, and
523
538
  // the session it names is meant to run for a whole job — so it is
@@ -548,6 +563,20 @@ export function registerTools(server, { bridge, version, updates = null, logger
548
563
  },
549
564
  });
550
565
  }
566
+ if (scope) {
567
+ if (args.url !== undefined && !["https:", "http:"].includes(new URL(args.url).protocol)) {
568
+ throw new Error("Shared sessions can open HTTP and HTTPS pages only");
569
+ }
570
+ if (def.name === "computer" && args.action === "idle") {
571
+ throw new Error("Send one browser action at a time in a shared session");
572
+ }
573
+ if (connection !== bridge.connectionId) throw new Error("The Chrome connection changed. Request approval again.");
574
+ const result = await bridge.sendTool("session_tool", { name: def.name, args, scope }, def.timeoutMs);
575
+ if (def.name === "tabs_create") {
576
+ return toMcpResult({ text: `opened tab ${result.data.id} in this session` });
577
+ }
578
+ return toMcpResult(result);
579
+ }
551
580
  if (def.name === "browser_batch") return echoSession(await runBatch(args, bridge, logger));
552
581
  // save_to_disk is a daemon-side concern: the extension has no disk
553
582
  // access, so it is stripped here and applied to the returned image.