taskwindow 0.2.20 → 0.2.22
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 +16 -0
- package/package.json +2 -2
- package/src/bridge.js +7 -2
- package/src/index.js +20 -23
- package/src/mcp-http.js +2 -2
- package/src/service.js +54 -2
- package/src/tools.js +31 -2
package/README.md
CHANGED
|
@@ -77,6 +77,13 @@ When a newer release exists, agents are told once per session (in the
|
|
|
77
77
|
package's latest version at most once a day; create `~/.taskwindow/no-update-check`
|
|
78
78
|
to turn that off.
|
|
79
79
|
|
|
80
|
+
An installer that manages TaskWindow for you, such as Ateam on a box, leaves a
|
|
81
|
+
`managed` file in `~/.taskwindow` saying how to update it. `taskwindow update`
|
|
82
|
+
and the login-service install stop there and print that line, rather than
|
|
83
|
+
installing a copy beside the managed one. `taskwindow update` also stops on a
|
|
84
|
+
local npm install (a project's `node_modules`, an npx cache): update those the
|
|
85
|
+
way you installed them.
|
|
86
|
+
|
|
80
87
|
Use `taskwindow install --no-extension` to install only the daemon and selected
|
|
81
88
|
agents. Developing the extension? `taskwindow install --extension <zip>` unpacks
|
|
82
89
|
a build into the `TaskWindow Extension` folder in your home directory for
|
|
@@ -87,6 +94,15 @@ too. Loaded unpacked before the store listing existed? Remove that copy in
|
|
|
87
94
|
taking the daemon connection from each other. For another MCP client, connect to `http://127.0.0.1:9377/mcp` with
|
|
88
95
|
`Authorization: Bearer <token>`; the token is stored in `~/.taskwindow/token`.
|
|
89
96
|
|
|
97
|
+
A local broker such as Ateam can keep that bearer on the browser host and use
|
|
98
|
+
`/mcp/session/<uuid>` for a single approved session. Choose a fresh UUID for
|
|
99
|
+
each grant and stop forwarding when it ends. The scoped endpoint lists single
|
|
100
|
+
tab operations and binds every call to the session’s own Chrome group, even
|
|
101
|
+
when **All tabs** is enabled. Check `scopedSessions` on `/health` to confirm
|
|
102
|
+
both the daemon and the connected extension support it. Bind consent to that
|
|
103
|
+
Chrome connection by retaining its `scopedConnectionId` and sending it as
|
|
104
|
+
`X-TaskWindow-Connection` on each call. A changed connection requires new consent.
|
|
105
|
+
|
|
90
106
|
## What the agent gets
|
|
91
107
|
|
|
92
108
|
| Area | Tools |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "taskwindow",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.22",
|
|
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-dialog.test.mjs test/extension-javascript.test.mjs test/extension-tabs.test.mjs test/extension-responsive.test.mjs test/extension-human.test.mjs test/extension-click-ref.test.mjs test/extension-pages.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-javascript.test.mjs test/extension-tabs.test.mjs test/extension-responsive.test.mjs test/extension-human.test.mjs test/extension-click-ref.test.mjs test/extension-pages.test.mjs test/bridge.test.mjs test/tool-contract.test.mjs test/updates.test.mjs test/managed.test.mjs && node test/run.mjs"
|
|
13
13
|
},
|
|
14
14
|
"engines": {
|
|
15
15
|
"node": ">=18"
|
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
|
|
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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import http from "node:http";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
5
|
-
import {
|
|
5
|
+
import { delimiter, dirname, join } from "node:path";
|
|
6
6
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
7
7
|
import { loadConfig } from "./config.js";
|
|
8
8
|
import { Bridge } from "./bridge.js";
|
|
@@ -17,6 +17,8 @@ import {
|
|
|
17
17
|
removeExtensionBootstrap,
|
|
18
18
|
systemUnitPath,
|
|
19
19
|
systemUnitMessage,
|
|
20
|
+
assertNotManaged,
|
|
21
|
+
owningInstall,
|
|
20
22
|
} from "./service.js";
|
|
21
23
|
import { PairingManager } from "./pairing.js";
|
|
22
24
|
import { STORE_EXTENSION_ID, STORE_LISTING_URL, STORE_ORIGIN } from "./store.js";
|
|
@@ -164,6 +166,7 @@ async function ensureDaemon(config, { forceInstall = false, allowInstall = true
|
|
|
164
166
|
if (current) return current;
|
|
165
167
|
throw new Error("the daemon is not running; re-run without --no-service");
|
|
166
168
|
}
|
|
169
|
+
assertNotManaged(config.dir);
|
|
167
170
|
installService(fileURLToPath(new URL("./index.js", import.meta.url)));
|
|
168
171
|
const health = await waitForDaemon(config.port);
|
|
169
172
|
if (!health) throw new Error(`daemon did not become ready on port ${config.port}`);
|
|
@@ -333,25 +336,6 @@ async function runDoctor(config) {
|
|
|
333
336
|
return !!health && health.extensionConnected === true;
|
|
334
337
|
}
|
|
335
338
|
|
|
336
|
-
/**
|
|
337
|
-
* The global npm install this CLI runs from: its prefix and the npm that owns
|
|
338
|
-
* it. `npm install -g` with the npm on PATH can belong to another Node (nvm,
|
|
339
|
-
* Homebrew, /usr/local) and would plant a second copy — the shadowing problem
|
|
340
|
-
* — so updates target the prefix these files live under.
|
|
341
|
-
*/
|
|
342
|
-
function owningInstall() {
|
|
343
|
-
const self = realpathSync(process.argv[1]); // <prefix>/lib/node_modules/taskwindow/src/index.js
|
|
344
|
-
const pkgRoot = dirname(dirname(self));
|
|
345
|
-
const nodeModules = dirname(pkgRoot);
|
|
346
|
-
if (basename(nodeModules) !== "node_modules" || basename(pkgRoot) !== "taskwindow") {
|
|
347
|
-
throw new Error(`this taskwindow (${self}) is not a global npm install — update it the way you installed it`);
|
|
348
|
-
}
|
|
349
|
-
let prefix = dirname(nodeModules);
|
|
350
|
-
if (basename(prefix) === "lib") prefix = dirname(prefix);
|
|
351
|
-
const npm = [join(prefix, "bin", "npm"), join(dirname(process.execPath), "npm")].find((p) => existsSync(p)) || "npm";
|
|
352
|
-
return { prefix, npm };
|
|
353
|
-
}
|
|
354
|
-
|
|
355
339
|
function printManualReload() {
|
|
356
340
|
console.log("[taskwindow] the extension could not reload itself — in Chrome open chrome://extensions and click reload on TaskWindow");
|
|
357
341
|
}
|
|
@@ -371,6 +355,7 @@ async function runUpdate(config, flags) {
|
|
|
371
355
|
const extFlag = flags.indexOf("--extension");
|
|
372
356
|
const zipArg = extFlag !== -1 && flags[extFlag + 1] && !flags[extFlag + 1].startsWith("--") ? flags[extFlag + 1] : null;
|
|
373
357
|
|
|
358
|
+
assertNotManaged(config.dir);
|
|
374
359
|
const managed = systemUnitPath();
|
|
375
360
|
if (managed) throw new Error(systemUnitMessage(managed));
|
|
376
361
|
|
|
@@ -383,7 +368,7 @@ async function runUpdate(config, flags) {
|
|
|
383
368
|
console.log(`[taskwindow] couldn't reach the npm registry (${err.message}) — refreshing the local install only`);
|
|
384
369
|
}
|
|
385
370
|
if (latest && isNewer(latest, VERSION)) {
|
|
386
|
-
const { prefix, npm } = owningInstall();
|
|
371
|
+
const { prefix, npm } = owningInstall(realpathSync(process.argv[1]));
|
|
387
372
|
console.log(`[taskwindow] updating v${VERSION} → v${latest} (${prefix})`);
|
|
388
373
|
execFileSync(npm, ["install", "-g", "--prefix", prefix, `taskwindow@${latest}`], { stdio: "inherit" });
|
|
389
374
|
const rest = ["update", "--stage2", ...flags.filter((f) => f !== "--force" || force)];
|
|
@@ -551,6 +536,8 @@ const server = http.createServer(async (req, res) => {
|
|
|
551
536
|
version: VERSION,
|
|
552
537
|
latestVersion: updates.latest,
|
|
553
538
|
extensionConnected: bridge.connected,
|
|
539
|
+
scopedSessions: bridge.connected && bridge.lastHello?.scopedSessions === true,
|
|
540
|
+
scopedConnectionId: bridge.connected ? bridge.connectionId : null,
|
|
554
541
|
extensionVersion: bridge.lastHello?.version || null,
|
|
555
542
|
extensionId: bridge.lastHello?.id || null,
|
|
556
543
|
port: config.port,
|
|
@@ -626,7 +613,8 @@ const server = http.createServer(async (req, res) => {
|
|
|
626
613
|
return;
|
|
627
614
|
}
|
|
628
615
|
|
|
629
|
-
|
|
616
|
+
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);
|
|
617
|
+
if (url.pathname === "/mcp" || session) {
|
|
630
618
|
const auth = req.headers.authorization || "";
|
|
631
619
|
if (auth !== `Bearer ${config.token}`) {
|
|
632
620
|
sendJson(res, 401, { error: "invalid or missing bearer token" });
|
|
@@ -649,7 +637,16 @@ const server = http.createServer(async (req, res) => {
|
|
|
649
637
|
sendJson(res, 400, { error: "invalid JSON body" });
|
|
650
638
|
return;
|
|
651
639
|
}
|
|
652
|
-
|
|
640
|
+
if (session && Array.isArray(body)) {
|
|
641
|
+
sendJson(res, 400, { error: "Send one browser operation per request" });
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
const connection = req.headers["x-taskwindow-connection"];
|
|
645
|
+
if (session && connection !== undefined && connection !== bridge.connectionId) {
|
|
646
|
+
sendJson(res, 409, { error: "The Chrome connection changed. Request approval again." });
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
await handleMcp(req, res, body, session ? "scoped:" + session[1] : null);
|
|
653
650
|
} catch (err) {
|
|
654
651
|
if (!res.headersSent) sendJson(res, 500, { error: err.message });
|
|
655
652
|
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/service.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* gets manual instructions.
|
|
5
5
|
*/
|
|
6
6
|
import { homedir, platform, userInfo } from "node:os";
|
|
7
|
-
import { join } from "node:path";
|
|
8
|
-
import { chmodSync, existsSync, writeFileSync, unlinkSync, mkdirSync, readdirSync, rmSync } from "node:fs";
|
|
7
|
+
import { basename, dirname, join } from "node:path";
|
|
8
|
+
import { chmodSync, existsSync, readFileSync, writeFileSync, unlinkSync, mkdirSync, readdirSync, rmSync } from "node:fs";
|
|
9
9
|
import { execFileSync, execSync } from "node:child_process";
|
|
10
10
|
|
|
11
11
|
const LABEL = "com.clawnify.taskwindow";
|
|
@@ -43,6 +43,58 @@ export function systemUnitMessage(path) {
|
|
|
43
43
|
return `this daemon is run by the system unit ${path}. Update the package as root, then: sudo systemctl restart taskwindow`;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
const MANAGED_FILE = "managed";
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* An installer that owns this TaskWindow (Ateam's box browser, for one) leaves
|
|
50
|
+
* a `managed` file in the TaskWindow dir saying how to update it. Its daemon
|
|
51
|
+
* runs from that installer's service and prefix, so `update` or a login service
|
|
52
|
+
* from here would plant a second copy that nothing runs and a unit for a second
|
|
53
|
+
* daemon. Returns the file's first line for the refusal, or null without one.
|
|
54
|
+
*/
|
|
55
|
+
export function managedNotice(dir) {
|
|
56
|
+
let text = "";
|
|
57
|
+
try {
|
|
58
|
+
text = readFileSync(join(dir, MANAGED_FILE), "utf8");
|
|
59
|
+
} catch (err) {
|
|
60
|
+
if (err.code === "ENOENT") return null;
|
|
61
|
+
}
|
|
62
|
+
// Agents read it: one printable line, bounded.
|
|
63
|
+
const line = text
|
|
64
|
+
.split("\n")
|
|
65
|
+
.map((l) => l.replace(/[\u0000-\u001f\u007f]/g, "").trim())
|
|
66
|
+
.find(Boolean);
|
|
67
|
+
return (line || "another installer manages this TaskWindow").slice(0, 300);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function assertNotManaged(dir) {
|
|
71
|
+
const notice = managedNotice(dir);
|
|
72
|
+
if (notice) throw new Error(`another installer manages this TaskWindow, so it is not changed from here. ${notice}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The global npm install the CLI at `self` runs from: its prefix and the npm
|
|
77
|
+
* that owns it. `npm install -g` with the npm on PATH can belong to another
|
|
78
|
+
* Node (nvm, Homebrew, /usr/local) and would plant a second copy (the
|
|
79
|
+
* shadowing problem), so updates target the prefix these files live under.
|
|
80
|
+
* A global install is <prefix>/lib/node_modules on macOS and Linux, and
|
|
81
|
+
* <prefix>/node_modules on Windows. Anything else is a local install (a
|
|
82
|
+
* project's node_modules, an npx cache, another installer's prefix), where
|
|
83
|
+
* `npm install -g --prefix` would add a copy under lib/ that nothing runs.
|
|
84
|
+
*/
|
|
85
|
+
export function owningInstall(self, { os = platform(), execPath = process.execPath } = {}) {
|
|
86
|
+
const pkgRoot = dirname(dirname(self)); // <prefix>/lib/node_modules/taskwindow
|
|
87
|
+
const nodeModules = dirname(pkgRoot);
|
|
88
|
+
const above = dirname(nodeModules);
|
|
89
|
+
const lib = basename(above) === "lib";
|
|
90
|
+
if (basename(nodeModules) !== "node_modules" || basename(pkgRoot) !== "taskwindow" || (!lib && os !== "win32")) {
|
|
91
|
+
throw new Error(`this taskwindow (${self}) is not a global npm install — update it the way you installed it`);
|
|
92
|
+
}
|
|
93
|
+
const prefix = lib ? dirname(above) : above;
|
|
94
|
+
const npm = [join(prefix, "bin", "npm"), join(dirname(execPath), "npm")].find((p) => existsSync(p)) || "npm";
|
|
95
|
+
return { prefix, npm };
|
|
96
|
+
}
|
|
97
|
+
|
|
46
98
|
function nodePath() {
|
|
47
99
|
return process.execPath;
|
|
48
100
|
}
|
package/src/tools.js
CHANGED
|
@@ -510,14 +510,29 @@ function toMcpResult(result) {
|
|
|
510
510
|
return { content };
|
|
511
511
|
}
|
|
512
512
|
|
|
513
|
-
|
|
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
|
-
|
|
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.
|