taskwindow 0.2.21 → 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 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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taskwindow",
3
- "version": "0.2.21",
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/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 { basename, delimiter, dirname, join } from "node:path";
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)];
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
  }