taskwindow 0.2.11 → 0.2.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taskwindow",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
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-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-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"
13
13
  },
14
14
  "engines": {
15
15
  "node": ">=18"
package/src/index.js CHANGED
@@ -15,6 +15,8 @@ import {
15
15
  downloadExtensionZip,
16
16
  refreshExtensionFiles,
17
17
  removeExtensionBootstrap,
18
+ systemUnitPath,
19
+ systemUnitMessage,
18
20
  } from "./service.js";
19
21
  import { PairingManager } from "./pairing.js";
20
22
  import { STORE_EXTENSION_ID, STORE_LISTING_URL, STORE_ORIGIN } from "./store.js";
@@ -368,6 +370,9 @@ async function runUpdate(config, flags) {
368
370
  const extFlag = flags.indexOf("--extension");
369
371
  const zipArg = extFlag !== -1 && flags[extFlag + 1] && !flags[extFlag + 1].startsWith("--") ? flags[extFlag + 1] : null;
370
372
 
373
+ const managed = systemUnitPath();
374
+ if (managed) throw new Error(systemUnitMessage(managed));
375
+
371
376
  if (!staged) {
372
377
  warnIfShadowed();
373
378
  let latest = null;
package/src/service.js CHANGED
@@ -3,9 +3,9 @@
3
3
  * terminal. macOS uses launchd; Linux uses a systemd user unit; anything else
4
4
  * gets manual instructions.
5
5
  */
6
- import { homedir, platform } from "node:os";
6
+ import { homedir, platform, userInfo } from "node:os";
7
7
  import { join } from "node:path";
8
- import { chmodSync, writeFileSync, unlinkSync, mkdirSync, readdirSync, rmSync } from "node:fs";
8
+ import { chmodSync, existsSync, 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";
@@ -26,10 +26,59 @@ export function removeExtensionBootstrap(home = homedir()) {
26
26
  } catch {}
27
27
  }
28
28
 
29
+ const SYSTEM_UNIT_DIRS = ["/etc/systemd/system", "/usr/lib/systemd/system", "/lib/systemd/system"];
30
+
31
+ /**
32
+ * A provisioned box (the Clawnify fleet) runs the daemon from a system unit
33
+ * as root installed it. A user unit next to it would start a second daemon
34
+ * fighting for the port, and restarting it would never move the real one onto
35
+ * new code, so install and update leave such a box to its system unit.
36
+ */
37
+ export function systemUnitPath(dirs = SYSTEM_UNIT_DIRS) {
38
+ if (platform() !== "linux") return null;
39
+ return dirs.map((dir) => join(dir, "taskwindow.service")).find((path) => existsSync(path)) || null;
40
+ }
41
+
42
+ export function systemUnitMessage(path) {
43
+ return `this daemon is run by the system unit ${path}. Update the package as root, then: sudo systemctl restart taskwindow`;
44
+ }
45
+
29
46
  function nodePath() {
30
47
  return process.execPath;
31
48
  }
32
49
 
50
+ /**
51
+ * A systemd user unit runs only while its user manager does, and without
52
+ * lingering that manager exists only while the user has a login session. On a
53
+ * headless box the daemon is SIGTERMed seconds after the last ssh/su session
54
+ * ends and comes back only at the next login. Lingering keeps the manager up
55
+ * from boot. Returns the environment `systemctl --user` needs to reach it,
56
+ * which a service or `su` context does not set.
57
+ */
58
+ function systemdUserEnv() {
59
+ const { username, uid } = userInfo();
60
+ if (!existsSync(join("/var/lib/systemd/linger", username))) {
61
+ try {
62
+ execFileSync("loginctl", ["enable-linger", username], { stdio: "pipe" });
63
+ } catch {
64
+ throw new Error(
65
+ `without lingering the daemon stops whenever ${username} has no login session. ` +
66
+ `Run: sudo loginctl enable-linger ${username}, then re-run this command`
67
+ );
68
+ }
69
+ }
70
+ const runtimeDir = process.env.XDG_RUNTIME_DIR || `/run/user/${uid}`;
71
+ // enable-linger starts the user manager asynchronously; wait for its bus.
72
+ const deadline = Date.now() + 10_000;
73
+ while (!existsSync(join(runtimeDir, "bus")) && Date.now() < deadline) {
74
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 200);
75
+ }
76
+ if (!existsSync(join(runtimeDir, "bus"))) {
77
+ throw new Error(`the systemd user manager for ${username} is not running (no ${runtimeDir}/bus)`);
78
+ }
79
+ return { ...process.env, XDG_RUNTIME_DIR: runtimeDir };
80
+ }
81
+
33
82
  export function installService(daemonEntryPath, port) {
34
83
  const system = platform();
35
84
  const logPath = join(homedir(), ".taskwindow", "daemon.log");
@@ -90,6 +139,8 @@ export function installService(daemonEntryPath, port) {
90
139
  }
91
140
 
92
141
  if (system === "linux") {
142
+ const managed = systemUnitPath();
143
+ if (managed) throw new Error(systemUnitMessage(managed));
93
144
  const unitPath = join(homedir(), ".config", "systemd", "user", "taskwindow.service");
94
145
  mkdirSync(join(homedir(), ".config", "systemd", "user"), { recursive: true });
95
146
  const unit = `[Unit]
@@ -97,7 +148,8 @@ Description=TaskWindow daemon
97
148
 
98
149
  [Service]
99
150
  ExecStart=${nodePath()} ${daemonEntryPath}
100
- Restart=on-failure
151
+ Restart=always
152
+ RestartSec=2
101
153
  StandardOutput=append:${logPath}
102
154
  StandardError=append:${logPath}
103
155
 
@@ -105,9 +157,13 @@ StandardError=append:${logPath}
105
157
  WantedBy=default.target
106
158
  `;
107
159
  writeFileSync(unitPath, unit);
108
- execSync("systemctl --user daemon-reload");
109
- execSync("systemctl --user enable --now taskwindow.service");
160
+ const env = systemdUserEnv();
161
+ execSync("systemctl --user daemon-reload", { env, stdio: "pipe" });
162
+ execSync("systemctl --user enable taskwindow.service", { env, stdio: "pipe" });
163
+ // restart, not start: an update must swap a running daemon onto the new code.
164
+ execSync("systemctl --user restart taskwindow.service", { env, stdio: "pipe" });
110
165
  console.log(`[taskwindow] login service installed (${unitPath})`);
166
+ console.log(`[taskwindow] daemon starts at boot, restarts on exit, logs to ${logPath}`);
111
167
  return;
112
168
  }
113
169
 
package/src/tools.js CHANGED
@@ -105,7 +105,9 @@ const rawDefs = [
105
105
  "as a real wheel gesture, and text as real per-key events. That is what lazy-loading lists, infinite scroll, " +
106
106
  "hover-revealed menus and type-ahead inputs are waiting for — they ignore a single jumbo scroll delta, a teleported " +
107
107
  "cursor and insertText. It costs a few hundred ms per action; pass human:false for one instant synthetic event when " +
108
- "speed matters more than realism. NOTE: while attached, Chrome shows a " +
108
+ "speed matters more than realism. A native <select> opens a browser menu that clicks and keys cannot drive: " +
109
+ "set it with form_input. A scroll result reports how far the content actually moved, which on an infinite list " +
110
+ "can be less than asked. NOTE: while attached, Chrome shows a " +
109
111
  '"TaskWindow started debugging this browser" infobar — this is unavoidable with CDP-based control.',
110
112
  inputSchema: {
111
113
  action: z.enum([