@indigoai-us/hq-cli 5.345.178 → 5.345.179
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/CHANGELOG.md +19 -0
- package/dist/command-catalog.generated.d.ts +71 -1
- package/dist/command-catalog.generated.js +86 -1
- package/dist/commands/bot-jobs.d.ts +11 -9
- package/dist/commands/bot-jobs.js +56 -21
- package/dist/commands/bot.d.ts +8 -0
- package/dist/commands/bot.js +44 -0
- package/dist/commands/daemon.d.ts +2 -0
- package/dist/commands/daemon.js +15 -4
- package/dist/commands/integrations-core.d.ts +2 -0
- package/dist/commands/integrations-core.js +1 -0
- package/dist/commands/sources.d.ts +89 -0
- package/dist/commands/sources.js +363 -1
- package/dist/lib/bot/fleet-local.d.ts +1 -1
- package/dist/lib/bot/fleet-local.js +7 -7
- package/dist/lib/bot/jobs/hot-signal-sync.d.ts +109 -0
- package/dist/lib/bot/jobs/hot-signal-sync.js +177 -0
- package/dist/lib/bot/local-jobs.d.ts +40 -4
- package/dist/lib/bot/local-jobs.js +72 -5
- package/dist/lib/bot/run.d.ts +15 -0
- package/dist/lib/bot/run.js +61 -0
- package/dist/lib/daemon/handoff.d.ts +4 -0
- package/dist/lib/daemon/handoff.js +6 -2
- package/dist/lib/daemon/install.d.ts +70 -2
- package/dist/lib/daemon/install.js +185 -27
- package/dist/lib/daemon/legacy.d.ts +9 -3
- package/dist/lib/daemon/legacy.js +11 -4
- package/dist/lib/daemon/migrate.js +1 -1
- package/dist/lib/daemon/run.d.ts +3 -2
- package/dist/lib/daemon/run.js +10 -6
- package/dist/lib/doctor/checks/anywhere.d.ts +6 -0
- package/dist/lib/doctor/checks/anywhere.js +35 -6
- package/dist/lib/hot-channels/adapters/__fixtures__/dummy.d.ts +33 -0
- package/dist/lib/hot-channels/adapters/__fixtures__/dummy.js +53 -0
- package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.d.ts +38 -0
- package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.js +64 -0
- package/dist/lib/hot-channels/adapters/attio.d.ts +67 -0
- package/dist/lib/hot-channels/adapters/attio.js +374 -0
- package/dist/lib/hot-channels/adapters/gmail.d.ts +111 -0
- package/dist/lib/hot-channels/adapters/gmail.js +413 -0
- package/dist/lib/hot-channels/adapters/index.d.ts +23 -0
- package/dist/lib/hot-channels/adapters/index.js +39 -0
- package/dist/lib/hot-channels/adapters/linear.d.ts +79 -0
- package/dist/lib/hot-channels/adapters/linear.js +321 -0
- package/dist/lib/hot-channels/adapters/meeting-providers.d.ts +86 -0
- package/dist/lib/hot-channels/adapters/meeting-providers.js +253 -0
- package/dist/lib/hot-channels/adapters/meetings.d.ts +81 -0
- package/dist/lib/hot-channels/adapters/meetings.js +523 -0
- package/dist/lib/hot-channels/adapters/slack.d.ts +70 -0
- package/dist/lib/hot-channels/adapters/slack.js +277 -0
- package/dist/lib/hot-channels/alert.d.ts +78 -0
- package/dist/lib/hot-channels/alert.js +179 -0
- package/dist/lib/hot-channels/audience.d.ts +15 -0
- package/dist/lib/hot-channels/audience.js +25 -0
- package/dist/lib/hot-channels/contract.d.ts +140 -0
- package/dist/lib/hot-channels/contract.js +20 -0
- package/dist/lib/hot-channels/cursors.d.ts +41 -0
- package/dist/lib/hot-channels/cursors.js +84 -0
- package/dist/lib/hot-channels/index.d.ts +10 -0
- package/dist/lib/hot-channels/index.js +10 -0
- package/dist/lib/hot-channels/landing.d.ts +83 -0
- package/dist/lib/hot-channels/landing.js +175 -0
- package/dist/lib/hot-channels/ledger.d.ts +101 -0
- package/dist/lib/hot-channels/ledger.js +186 -0
- package/dist/lib/hot-channels/loop.d.ts +74 -0
- package/dist/lib/hot-channels/loop.js +219 -0
- package/dist/lib/hot-channels/prompts/signals-pass.md +22 -0
- package/dist/lib/hot-channels/registry.d.ts +28 -0
- package/dist/lib/hot-channels/registry.js +121 -0
- package/dist/lib/hot-channels/run.d.ts +137 -0
- package/dist/lib/hot-channels/run.js +324 -0
- package/dist/lib/hot-channels/signals-pass.d.ts +150 -0
- package/dist/lib/hot-channels/signals-pass.js +581 -0
- package/dist/lib/hot-channels/sync-lock.d.ts +51 -0
- package/dist/lib/hot-channels/sync-lock.js +224 -0
- package/dist/lib/install/hook-target.d.ts +6 -2
- package/dist/lib/install/hook-target.js +9 -4
- package/dist/lib/lanes/loop.d.ts +10 -0
- package/dist/lib/lanes/loop.js +18 -1
- package/package.json +7 -7
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - Linux, per-user: systemd user unit hq-daemon.service
|
|
8
8
|
* - Linux, system (outposts and agent boxes): /etc/systemd/system/hq-daemon.service
|
|
9
9
|
* running as the box's login user; needs root
|
|
10
|
-
* - Windows: per-user logon Scheduled Task ai.getindigo.hq-daemon
|
|
10
|
+
* - Windows: per-user logon Scheduled Task ai.getindigo.hq-daemon-<user SID>
|
|
11
11
|
* - anything else: no unit; the caller prints the command to run
|
|
12
12
|
*
|
|
13
13
|
* The unit never names services. `hq daemon run` reads the machine type and
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* never touch launchctl, systemctl or schtasks.
|
|
17
17
|
*/
|
|
18
18
|
import * as fs from "node:fs";
|
|
19
|
+
import * as os from "node:os";
|
|
19
20
|
import * as path from "node:path";
|
|
20
21
|
import { activateLaunchd, blockingSleep, deactivateLaunchd, defaultRunCommand, installLaunchdPlist, launchdIsLoaded, launchdPlistPath, renderLaunchdPlist, } from "../service-manager/launchd.js";
|
|
21
22
|
import { activateSystemd, deactivateSystemd, renderSystemdUserUnit, systemdUnitPath, } from "../service-manager/systemd.js";
|
|
@@ -26,8 +27,58 @@ import { liveDaemonLock, verifyDaemonForKill } from "./lock.js";
|
|
|
26
27
|
import { daemonPaths } from "./paths.js";
|
|
27
28
|
export const DAEMON_LAUNCHD_LABEL = "ai.getindigo.hq-daemon";
|
|
28
29
|
export const DAEMON_SYSTEMD_UNIT = "hq-daemon.service";
|
|
29
|
-
|
|
30
|
+
/**
|
|
31
|
+
* The one machine-wide task name older installs registered on Windows. Two
|
|
32
|
+
* users on one PC overwrote each other's daemon under it, so each user now
|
|
33
|
+
* gets their own name (daemonWindowsTaskName). Install moves the current
|
|
34
|
+
* user's task off this name; another user's task under it is left alone.
|
|
35
|
+
*/
|
|
36
|
+
export const LEGACY_DAEMON_WINDOWS_TASK = "ai.getindigo.hq-daemon";
|
|
30
37
|
export const SYSTEM_UNIT_DIR = "/etc/systemd/system";
|
|
38
|
+
/**
|
|
39
|
+
* The Windows task name for one user: the shared prefix plus the user's SID,
|
|
40
|
+
* or the `DOMAIN\user` name with characters a task name cannot hold replaced
|
|
41
|
+
* when the SID could not be read. Never the bare legacy name.
|
|
42
|
+
*/
|
|
43
|
+
export function daemonWindowsTaskName(who) {
|
|
44
|
+
const sid = who.sid?.trim();
|
|
45
|
+
if (sid)
|
|
46
|
+
return `${LEGACY_DAEMON_WINDOWS_TASK}-${sid}`;
|
|
47
|
+
const user = who.user.trim().replace(/[^A-Za-z0-9_.-]/g, "_");
|
|
48
|
+
return `${LEGACY_DAEMON_WINDOWS_TASK}-${user || "user"}`;
|
|
49
|
+
}
|
|
50
|
+
/** The current Windows user's SID from `whoami /user`, or undefined when it cannot be read. */
|
|
51
|
+
export function readWindowsSid(run) {
|
|
52
|
+
const r = run("whoami.exe", ["/user", "/FO", "CSV", "/NH"]);
|
|
53
|
+
if (r.status !== 0)
|
|
54
|
+
return undefined;
|
|
55
|
+
return /S-1-\d+(?:-\d+)+/.exec(r.stdout)?.[0];
|
|
56
|
+
}
|
|
57
|
+
/** The per-user task name for the user running this process. */
|
|
58
|
+
export function currentDaemonWindowsTaskName(run, user) {
|
|
59
|
+
return daemonWindowsTaskName({ sid: readWindowsSid(run), user });
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* `DOMAIN\user` for the current account. Same answer as the mesh installer's
|
|
63
|
+
* resolveWindowsUser, kept here so lookups do not load the mesh installer.
|
|
64
|
+
*/
|
|
65
|
+
export function currentWindowsUser(env = process.env) {
|
|
66
|
+
let user = env.USERNAME?.trim() ?? "";
|
|
67
|
+
if (!user) {
|
|
68
|
+
try {
|
|
69
|
+
user = os.userInfo().username;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
user = "";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const domain = env.USERDOMAIN?.trim();
|
|
76
|
+
return domain ? `${domain}\\${user}` : user;
|
|
77
|
+
}
|
|
78
|
+
/** The current user as a DaemonHost names them on Windows. */
|
|
79
|
+
export function currentWindowsIdentity(run = defaultRunCommand, env = process.env) {
|
|
80
|
+
return { windowsUser: currentWindowsUser(env), windowsSid: readWindowsSid(run) };
|
|
81
|
+
}
|
|
31
82
|
/** How long install waits for the Windows task to start a daemon process. */
|
|
32
83
|
export const WINDOWS_START_WAIT_MS = 10_000;
|
|
33
84
|
const WINDOWS_START_POLL_MS = 500;
|
|
@@ -128,7 +179,7 @@ function renderWindowsTaskXml(host) {
|
|
|
128
179
|
return `<?xml version="1.0" encoding="UTF-16"?>
|
|
129
180
|
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
|
|
130
181
|
<RegistrationInfo>
|
|
131
|
-
<URI>\\${
|
|
182
|
+
<URI>\\${windowsTaskName(host)}</URI>
|
|
132
183
|
<Description>HQ daemon: runs this machine's HQ background services</Description>
|
|
133
184
|
</RegistrationInfo>
|
|
134
185
|
<Triggers>
|
|
@@ -204,7 +255,7 @@ export function planDaemonUnit(host, options) {
|
|
|
204
255
|
if (host.platform === "win32") {
|
|
205
256
|
return {
|
|
206
257
|
kind: "schtasks",
|
|
207
|
-
unitPath: path.join(host.daemonDir, `${
|
|
258
|
+
unitPath: path.join(host.daemonDir, `${LEGACY_DAEMON_WINDOWS_TASK}.xml`),
|
|
208
259
|
rendered: renderWindowsTaskXml(host),
|
|
209
260
|
};
|
|
210
261
|
}
|
|
@@ -224,8 +275,9 @@ function commandError(what, r) {
|
|
|
224
275
|
* immediately before the kill and killed only when it is verifiably the
|
|
225
276
|
* daemon. Returns a warning when a process was left running unverified.
|
|
226
277
|
*/
|
|
227
|
-
function endWindowsDaemon(run, owner) {
|
|
228
|
-
|
|
278
|
+
function endWindowsDaemon(run, owner, tasks) {
|
|
279
|
+
for (const task of tasks)
|
|
280
|
+
run("schtasks.exe", ["/End", "/TN", task]);
|
|
229
281
|
if (!owner || owner.pid === process.pid)
|
|
230
282
|
return undefined;
|
|
231
283
|
const check = verifyDaemonForKill(owner, run);
|
|
@@ -237,6 +289,79 @@ function endWindowsDaemon(run, owner) {
|
|
|
237
289
|
return undefined;
|
|
238
290
|
return oldDaemonWarning(owner.pid, check.reason);
|
|
239
291
|
}
|
|
292
|
+
/**
|
|
293
|
+
* The registered per-user task names for `host`: the current name, and the
|
|
294
|
+
* user-name form an install used when it could not read the SID. The fallback
|
|
295
|
+
* name is only returned when its principal is this user.
|
|
296
|
+
*/
|
|
297
|
+
export function windowsUserTaskNames(run, host) {
|
|
298
|
+
const names = [];
|
|
299
|
+
const current = windowsTaskName(host);
|
|
300
|
+
if (run("schtasks.exe", ["/Query", "/TN", current]).status === 0)
|
|
301
|
+
names.push(current);
|
|
302
|
+
const byUser = daemonWindowsTaskName({ user: host.windowsUser });
|
|
303
|
+
if (byUser !== current && classifyWindowsTask(run, byUser, host).state === "mine")
|
|
304
|
+
names.push(byUser);
|
|
305
|
+
return names;
|
|
306
|
+
}
|
|
307
|
+
/** The per-user task name for `host`. */
|
|
308
|
+
export function windowsTaskName(host) {
|
|
309
|
+
return daemonWindowsTaskName({ sid: host.windowsSid, user: host.windowsUser });
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Whether two Windows account names are the same user, ignoring case. Both
|
|
313
|
+
* names must have the same form: `DOMAIN\user` matches only the same
|
|
314
|
+
* `DOMAIN\user`, and a bare `user` only the same bare `user`. A bare name is
|
|
315
|
+
* never matched against a domain name, because `bob` could be `PC\bob` or
|
|
316
|
+
* `CORP\bob`, and a wrong match would end and delete another user's task.
|
|
317
|
+
*/
|
|
318
|
+
export function sameWindowsUser(a, b) {
|
|
319
|
+
const left = a.trim().toLowerCase();
|
|
320
|
+
const right = b.trim().toLowerCase();
|
|
321
|
+
const leftBare = (left.split("\\").pop() ?? "").trim();
|
|
322
|
+
const rightBare = (right.split("\\").pop() ?? "").trim();
|
|
323
|
+
if (!leftBare || !rightBare)
|
|
324
|
+
return false;
|
|
325
|
+
if (left.includes("\\") !== right.includes("\\"))
|
|
326
|
+
return false;
|
|
327
|
+
return left === right;
|
|
328
|
+
}
|
|
329
|
+
/** The principal a task XML runs as. */
|
|
330
|
+
function windowsTaskPrincipal(xml) {
|
|
331
|
+
return /<Principal\b[^>]*>[\s\S]*?<UserId>([^<]*)<\/UserId>/.exec(xml)?.[1]?.trim() || undefined;
|
|
332
|
+
}
|
|
333
|
+
export function legacyWindowsTask(run, host) {
|
|
334
|
+
return classifyWindowsTask(run, LEGACY_DAEMON_WINDOWS_TASK, host);
|
|
335
|
+
}
|
|
336
|
+
/** Whose task `task` is, read from `schtasks /Query /XML`. */
|
|
337
|
+
export function classifyWindowsTask(run, task, host) {
|
|
338
|
+
const r = run("schtasks.exe", ["/Query", "/TN", task, "/XML"]);
|
|
339
|
+
if (r.status !== 0) {
|
|
340
|
+
const reason = (r.stderr.trim() || r.stdout.trim()).replace(/\0/g, "");
|
|
341
|
+
return /access is denied/i.test(reason) ? { state: "unreadable", reason } : { state: "none" };
|
|
342
|
+
}
|
|
343
|
+
const owner = windowsTaskPrincipal(r.stdout.replace(/\0/g, ""));
|
|
344
|
+
if (!owner)
|
|
345
|
+
return { state: "unreadable", reason: "the task does not name the user it runs as" };
|
|
346
|
+
if (/^S-1-/i.test(owner)) {
|
|
347
|
+
const sid = host.windowsSid?.trim();
|
|
348
|
+
return sid && sid.toLowerCase() === owner.toLowerCase() ? { state: "mine", owner } : { state: "other", owner };
|
|
349
|
+
}
|
|
350
|
+
return sameWindowsUser(owner, host.windowsUser) ? { state: "mine", owner } : { state: "other", owner };
|
|
351
|
+
}
|
|
352
|
+
const REMOVE_LEGACY_TASK = `schtasks /Delete /TN ${LEGACY_DAEMON_WINDOWS_TASK} /F`;
|
|
353
|
+
/** What to tell the user about a shared task HQ left alone, or undefined when there is none. */
|
|
354
|
+
function legacyLeftNotice(legacy) {
|
|
355
|
+
if (legacy.state === "other") {
|
|
356
|
+
return (`Another Windows user's HQ daemon task (\\${LEGACY_DAEMON_WINDOWS_TASK}, run as ${legacy.owner}) was left untouched. ` +
|
|
357
|
+
`If it is in fact yours, remove it with: ${REMOVE_LEGACY_TASK}`);
|
|
358
|
+
}
|
|
359
|
+
if (legacy.state === "unreadable") {
|
|
360
|
+
return (`The shared HQ daemon task \\${LEGACY_DAEMON_WINDOWS_TASK} from an older install was left untouched because HQ could not read it (${legacy.reason}). ` +
|
|
361
|
+
`It may belong to another Windows user. If it is yours, remove it with: ${REMOVE_LEGACY_TASK}`);
|
|
362
|
+
}
|
|
363
|
+
return undefined;
|
|
364
|
+
}
|
|
240
365
|
/** What to tell the user when HQ did not stop pid `pid` because it could not verify it. */
|
|
241
366
|
export function oldDaemonWarning(pid, reason) {
|
|
242
367
|
return [
|
|
@@ -250,10 +375,10 @@ function activate(plan, host, run, sleep, previous = null) {
|
|
|
250
375
|
switch (plan.kind) {
|
|
251
376
|
case "launchd":
|
|
252
377
|
activateLaunchd(plan.unitPath, run, host.uid, { sleep });
|
|
253
|
-
return;
|
|
378
|
+
return {};
|
|
254
379
|
case "systemd-user":
|
|
255
380
|
activateSystemd(DAEMON_SYSTEMD_UNIT, run);
|
|
256
|
-
return;
|
|
381
|
+
return {};
|
|
257
382
|
case "systemd-system": {
|
|
258
383
|
const reload = run("systemctl", ["daemon-reload"]);
|
|
259
384
|
if (reload.status !== 0)
|
|
@@ -262,23 +387,41 @@ function activate(plan, host, run, sleep, previous = null) {
|
|
|
262
387
|
if (enable.status !== 0)
|
|
263
388
|
throw commandError(`systemctl enable --now ${DAEMON_SYSTEMD_UNIT}`, enable);
|
|
264
389
|
run("systemctl", ["restart", DAEMON_SYSTEMD_UNIT]);
|
|
265
|
-
return;
|
|
390
|
+
return {};
|
|
266
391
|
}
|
|
267
392
|
case "schtasks": {
|
|
268
|
-
const
|
|
393
|
+
const task = windowsTaskName(host);
|
|
394
|
+
// Older installs registered one task name for the whole machine. Read
|
|
395
|
+
// whose it is before registering this user's own task.
|
|
396
|
+
const legacy = legacyWindowsTask(run, host);
|
|
397
|
+
const create = run("schtasks.exe", ["/Create", "/TN", task, "/XML", plan.unitPath, "/F"]);
|
|
269
398
|
if (create.status !== 0)
|
|
270
399
|
throw commandError("schtasks /Create", create);
|
|
400
|
+
const warnings = [];
|
|
401
|
+
let notice = legacyLeftNotice(legacy);
|
|
402
|
+
if (legacy.state === "mine") {
|
|
403
|
+
// Only the current user's shared task is moved; another user's is never ended or deleted.
|
|
404
|
+
run("schtasks.exe", ["/End", "/TN", LEGACY_DAEMON_WINDOWS_TASK]);
|
|
405
|
+
const del = run("schtasks.exe", ["/Delete", "/TN", LEGACY_DAEMON_WINDOWS_TASK, "/F"]);
|
|
406
|
+
if (del.status !== 0) {
|
|
407
|
+
warnings.push(`Could not remove the shared task \\${LEGACY_DAEMON_WINDOWS_TASK}: ${(del.stderr.trim() || del.stdout.trim() || `exit ${del.status}`).replace(/\0/g, "")}. ` +
|
|
408
|
+
`Remove it with: ${REMOVE_LEGACY_TASK}`);
|
|
409
|
+
}
|
|
410
|
+
notice = `Moved your HQ daemon from the shared task \\${LEGACY_DAEMON_WINDOWS_TASK} to \\${task}.`;
|
|
411
|
+
}
|
|
271
412
|
// `/Create /F` leaves a running instance alone and `/Run` is ignored
|
|
272
413
|
// while one runs, so a daemon from an earlier install would keep the old
|
|
273
414
|
// settings. Stop it first so `/Run` starts a new one.
|
|
274
|
-
const
|
|
275
|
-
|
|
415
|
+
const old = previous ? endWindowsDaemon(run, previous, [task]) : undefined;
|
|
416
|
+
if (old)
|
|
417
|
+
warnings.push(old);
|
|
418
|
+
const start = run("schtasks.exe", ["/Run", "/TN", task]);
|
|
276
419
|
if (start.status !== 0)
|
|
277
420
|
throw commandError("schtasks /Run", start);
|
|
278
|
-
return warning;
|
|
421
|
+
return { ...(warnings.length ? { warning: warnings.join("\n") } : {}), ...(notice ? { notice } : {}) };
|
|
279
422
|
}
|
|
280
423
|
case "manual":
|
|
281
|
-
return
|
|
424
|
+
return {};
|
|
282
425
|
}
|
|
283
426
|
}
|
|
284
427
|
export function installDaemonUnit(host, options, deps) {
|
|
@@ -330,8 +473,7 @@ export function installDaemonUnit(host, options, deps) {
|
|
|
330
473
|
const lockPath = daemonPaths(host.home, { HQ_DAEMON_DIR: host.daemonDir }).lockPath;
|
|
331
474
|
const runningDaemon = deps.runningDaemon ?? (() => liveDaemonLock(lockPath));
|
|
332
475
|
const previous = plan.kind === "schtasks" ? runningDaemon() : null;
|
|
333
|
-
const
|
|
334
|
-
const warn = warning ? { warning } : {};
|
|
476
|
+
const warn = plan.kind !== "launchd" ? activate(plan, host, deps.run, deps.sleep, previous) : {};
|
|
335
477
|
if (plan.kind === "schtasks") {
|
|
336
478
|
// schtasks /Run exits 0 even when the task cannot run: an
|
|
337
479
|
// InteractiveToken task with no signed-in session stays at "has not yet
|
|
@@ -478,11 +620,22 @@ export function uninstallDaemonUnit(host, options, deps) {
|
|
|
478
620
|
: planDaemonUnit(host, options);
|
|
479
621
|
if (plan.kind === "manual")
|
|
480
622
|
return { kind: plan.kind, unitPath: plan.unitPath, removed: false };
|
|
481
|
-
//
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
623
|
+
// On Windows the XML file is shared with older installs, so it does not show
|
|
624
|
+
// that this user's per-user task exists. Ask schtasks for each name this
|
|
625
|
+
// user's task may have: the SID name, and the user-name form used when the
|
|
626
|
+
// SID could not be read at install time.
|
|
627
|
+
const userTasks = plan.kind === "schtasks" ? windowsUserTaskNames(deps.run, host) : [];
|
|
628
|
+
const present = plan.kind === "schtasks" ? userTasks.length > 0 : fs.existsSync(plan.unitPath);
|
|
629
|
+
// The current user's shared task from an older install goes too; another user's stays.
|
|
630
|
+
const legacy = plan.kind === "schtasks" ? legacyWindowsTask(deps.run, host) : { state: "none" };
|
|
631
|
+
const notice = legacyLeftNotice(legacy);
|
|
632
|
+
const noted = notice ? { notice } : {};
|
|
633
|
+
if (!present && legacy.state !== "mine") {
|
|
634
|
+
// A task XML left by an older install with no task behind it is stale.
|
|
635
|
+
if (plan.kind === "schtasks")
|
|
636
|
+
fs.rmSync(plan.unitPath, { force: true });
|
|
637
|
+
return { kind: plan.kind, unitPath: plan.unitPath, removed: false, ...noted };
|
|
638
|
+
}
|
|
486
639
|
let warning;
|
|
487
640
|
switch (plan.kind) {
|
|
488
641
|
case "launchd":
|
|
@@ -503,15 +656,20 @@ export function uninstallDaemonUnit(host, options, deps) {
|
|
|
503
656
|
}
|
|
504
657
|
case "schtasks": {
|
|
505
658
|
// The lock may be stale; endWindowsDaemon kills only a verified daemon.
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
659
|
+
const tasks = [...(legacy.state === "mine" ? [LEGACY_DAEMON_WINDOWS_TASK] : []), ...userTasks];
|
|
660
|
+
warning = endWindowsDaemon(deps.run, readPidLock(path.join(host.daemonDir, "daemon.pid")), tasks);
|
|
661
|
+
for (const name of tasks) {
|
|
662
|
+
const del = deps.run("schtasks.exe", ["/Delete", "/TN", name, "/F"]);
|
|
663
|
+
// A task that is already gone counts as removed. Otherwise keep the
|
|
664
|
+
// XML so a later uninstall still finds the task.
|
|
665
|
+
if (del.status !== 0 && deps.run("schtasks.exe", ["/Query", "/TN", name]).status === 0) {
|
|
666
|
+
throw commandError(`schtasks /Delete /TN ${name}`, del);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
511
669
|
break;
|
|
512
670
|
}
|
|
513
671
|
}
|
|
514
672
|
fs.rmSync(plan.unitPath, { force: true });
|
|
515
|
-
return { kind: plan.kind, unitPath: plan.unitPath, removed: true, ...(warning ? { warning } : {}) };
|
|
673
|
+
return { kind: plan.kind, unitPath: plan.unitPath, removed: true, ...(warning ? { warning } : {}), ...noted };
|
|
516
674
|
}
|
|
517
675
|
//# sourceMappingURL=install.js.map
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Detection reads unit files and checks for an orphaned loaded macOS mesh job
|
|
7
7
|
* whose plist was removed. Windows scheduled tasks are probed through
|
|
8
|
-
* schtasks
|
|
8
|
+
* schtasks, and only a task that runs as the current user can be taken over.
|
|
9
|
+
* Nothing here stops or removes a unit.
|
|
9
10
|
*/
|
|
10
11
|
import type { ServiceName } from "./catalog.js";
|
|
11
12
|
export interface LegacyUnit {
|
|
@@ -15,9 +16,13 @@ export interface LegacyUnit {
|
|
|
15
16
|
kind: "launchd" | "systemd-user" | "systemd-system" | "schtasks";
|
|
16
17
|
name: string;
|
|
17
18
|
path?: string;
|
|
18
|
-
/** False for units owned by another product (the desktop app's own agent). */
|
|
19
|
+
/** False for units owned by another product (the desktop app's own agent) or another Windows user. */
|
|
19
20
|
migratable: boolean;
|
|
21
|
+
/** Why a unit that is not the desktop app's is still left alone (another Windows user's task). */
|
|
22
|
+
notMineReason?: string;
|
|
20
23
|
}
|
|
24
|
+
/** Whose Windows Scheduled Task a name refers to, as classifyWindowsTask reads it. */
|
|
25
|
+
export type WindowsTaskOwner = "none" | "mine" | "other" | "unreadable";
|
|
21
26
|
export interface LegacyProbeDeps {
|
|
22
27
|
platform: NodeJS.Platform;
|
|
23
28
|
home: string;
|
|
@@ -25,7 +30,8 @@ export interface LegacyProbeDeps {
|
|
|
25
30
|
listDir: (dir: string) => string[];
|
|
26
31
|
/** True when launchctl can print the GUI-domain job despite a missing plist. */
|
|
27
32
|
launchdJobLoaded: (label: string) => boolean;
|
|
28
|
-
|
|
33
|
+
/** Whether the task exists and runs as the current user. Another user's task is never taken over. */
|
|
34
|
+
windowsTaskOwner: (taskName: string) => WindowsTaskOwner;
|
|
29
35
|
}
|
|
30
36
|
export declare function describeLegacyUnit(unit: LegacyUnit): string;
|
|
31
37
|
export declare function findLegacyUnits(deps: LegacyProbeDeps): LegacyUnit[];
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Detection reads unit files and checks for an orphaned loaded macOS mesh job
|
|
7
7
|
* whose plist was removed. Windows scheduled tasks are probed through
|
|
8
|
-
* schtasks
|
|
8
|
+
* schtasks, and only a task that runs as the current user can be taken over.
|
|
9
|
+
* Nothing here stops or removes a unit.
|
|
9
10
|
*/
|
|
10
11
|
import * as path from "node:path";
|
|
11
12
|
const KIT_SERVICES = ["sync", "inbox", "heartbeat"];
|
|
@@ -100,9 +101,15 @@ function linuxUnits(deps) {
|
|
|
100
101
|
}
|
|
101
102
|
function windowsUnits(deps) {
|
|
102
103
|
const task = "ai.getindigo.hq-mesh-daemon";
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
const owner = deps.windowsTaskOwner(task);
|
|
105
|
+
if (owner === "none")
|
|
106
|
+
return [];
|
|
107
|
+
const unit = { unitId: "mesh", service: "mesh", kind: "schtasks", name: task, migratable: owner === "mine" };
|
|
108
|
+
if (owner === "other")
|
|
109
|
+
unit.notMineReason = "it belongs to another Windows user";
|
|
110
|
+
if (owner === "unreadable")
|
|
111
|
+
unit.notMineReason = "HQ could not read which Windows user it belongs to";
|
|
112
|
+
return [unit];
|
|
106
113
|
}
|
|
107
114
|
export function findLegacyUnits(deps) {
|
|
108
115
|
if (deps.platform === "darwin")
|
|
@@ -136,7 +136,7 @@ export function adoptLegacyUnits(units, deps) {
|
|
|
136
136
|
};
|
|
137
137
|
for (const unit of units) {
|
|
138
138
|
if (!unit.migratable) {
|
|
139
|
-
result.skipped.push({ unit, reason: "owned by the HQ desktop app" });
|
|
139
|
+
result.skipped.push({ unit, reason: unit.notMineReason ?? "owned by the HQ desktop app" });
|
|
140
140
|
continue;
|
|
141
141
|
}
|
|
142
142
|
if (unit.kind === "systemd-system" && !deps.isRoot) {
|
package/dist/lib/daemon/run.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* signing in takes effect without restarting the daemon.
|
|
7
7
|
*/
|
|
8
8
|
import { type PlanContext, type ServiceName, type UnitPlan } from "./catalog.js";
|
|
9
|
-
import { type LegacyUnit } from "./legacy.js";
|
|
9
|
+
import { type LegacyUnit, type WindowsTaskOwner } from "./legacy.js";
|
|
10
10
|
import { type DaemonLockResult } from "./lock.js";
|
|
11
11
|
import { type MachineType } from "./machine-type.js";
|
|
12
12
|
import { type PickedHqCloud } from "./hq-cloud.js";
|
|
@@ -99,7 +99,8 @@ export declare function daemonInstantSyncEnabled(env: NodeJS.ProcessEnv, configu
|
|
|
99
99
|
* background service, so it is not one of them.
|
|
100
100
|
*/
|
|
101
101
|
export declare function listLocalBots(root?: string): string[];
|
|
102
|
-
|
|
102
|
+
/** Whose task `taskName` is: only the current user's own task may be taken over. */
|
|
103
|
+
export declare function windowsTaskOwner(taskName: string): WindowsTaskOwner;
|
|
103
104
|
export declare function probeLegacyUnits(platform: NodeJS.Platform, home: string): LegacyUnit[];
|
|
104
105
|
/** Absolute path of `name` on PATH, or null. */
|
|
105
106
|
export declare function findOnPath(name: string, env?: NodeJS.ProcessEnv): string | null;
|
package/dist/lib/daemon/run.js
CHANGED
|
@@ -32,7 +32,7 @@ import { SUPERVISOR_HANDOFF_FLAG, readDaemonFlag } from "./flag.js";
|
|
|
32
32
|
import { createBoundedDaemonFlagMonitor } from "./flag-monitor.js";
|
|
33
33
|
import { DAEMON_CHILD_BOOTSTRAP_HANDOFF_WATCH_FLAG, DAEMON_LANES_RECONCILE_FILE_WATCH_FLAG, DAEMON_SEARCH_INDEX_RUNNER_OWNS_INDEX_FLAG, DAEMON_SYNC_PROCESS_SCAN_ON_MISSING_FLAG, } from "./kill-switch-flags.js";
|
|
34
34
|
import { createLanesReconcileWatcher } from "./lanes-reconcile-watcher.js";
|
|
35
|
-
import { findLegacyUnits, legacyMeshUnitsToRetire, legacyOwnerLookup } from "./legacy.js";
|
|
35
|
+
import { findLegacyUnits, legacyMeshUnitsToRetire, legacyOwnerLookup, } from "./legacy.js";
|
|
36
36
|
import { readLegacySyncEnv } from "./legacy-sync-env.js";
|
|
37
37
|
import { readVaultSyncSwitches, unreadableSwitchesWarning } from "../vault-sync-switches.js";
|
|
38
38
|
import { acquireDaemonLock, isProcessAlive, processCommandLine, releaseDaemonLock } from "./lock.js";
|
|
@@ -41,7 +41,7 @@ import { daemonDir as meshDaemonDir, daemonPidPath as meshDaemonPidPath } from "
|
|
|
41
41
|
import { readPidLock } from "../mesh/live/daemon/pid-lock.js";
|
|
42
42
|
import { registryDir, registryFile } from "../registry/registry.js";
|
|
43
43
|
import { updateAnywhereRuntimeRevocationMarker } from "../anywhere-runtime-revocation-marker.js";
|
|
44
|
-
import { daemonRootRefusal } from "./install.js";
|
|
44
|
+
import { classifyWindowsTask, currentWindowsIdentity, daemonRootRefusal } from "./install.js";
|
|
45
45
|
import { detectMachineType } from "./machine-type.js";
|
|
46
46
|
import { appendPrivate, daemonPaths, ensurePrivateDir, openPrivateAppend } from "./paths.js";
|
|
47
47
|
import { hqdSocketPath } from "./protocol.js";
|
|
@@ -310,9 +310,13 @@ export function listLocalBots(root = botsRoot()) {
|
|
|
310
310
|
.map((d) => d.name)
|
|
311
311
|
.sort();
|
|
312
312
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
313
|
+
/** Whose task `taskName` is: only the current user's own task may be taken over. */
|
|
314
|
+
export function windowsTaskOwner(taskName) {
|
|
315
|
+
const run = (cmd, args) => {
|
|
316
|
+
const r = spawnSync(cmd, args, { encoding: "utf8", windowsHide: true });
|
|
317
|
+
return { status: r.status ?? 1, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
318
|
+
};
|
|
319
|
+
return classifyWindowsTask(run, taskName, currentWindowsIdentity(run)).state;
|
|
316
320
|
}
|
|
317
321
|
export function probeLegacyUnits(platform, home) {
|
|
318
322
|
return findLegacyUnits({
|
|
@@ -331,7 +335,7 @@ export function probeLegacyUnits(platform, home) {
|
|
|
331
335
|
});
|
|
332
336
|
return result.status === 0;
|
|
333
337
|
},
|
|
334
|
-
|
|
338
|
+
windowsTaskOwner,
|
|
335
339
|
});
|
|
336
340
|
}
|
|
337
341
|
/** Absolute path of `name` on PATH, or null. */
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* on this machine the family reports a single NA line.
|
|
10
10
|
*/
|
|
11
11
|
import { type HqdHealthResult } from "../../daemon/protocol.js";
|
|
12
|
+
import { type DaemonHost } from "../../daemon/install.js";
|
|
13
|
+
import type { RunCommand } from "../../service-manager/launchd.js";
|
|
12
14
|
import type { CheckFamily } from "../types.js";
|
|
13
15
|
export declare const REMEDIATION: {
|
|
14
16
|
readonly installClaude: "hq install --global --runtime claude";
|
|
@@ -31,6 +33,10 @@ export interface DaemonServiceProbeOptions {
|
|
|
31
33
|
launchdProbe?: (target: string) => boolean;
|
|
32
34
|
/** Test seam for the desktop app's live managed daemon state. */
|
|
33
35
|
hostedDaemonProbe?: () => boolean;
|
|
36
|
+
/** Test seam for the schtasks calls the Windows probe makes. */
|
|
37
|
+
run?: RunCommand;
|
|
38
|
+
/** Test seam for the Windows account the task name is built from. */
|
|
39
|
+
windowsIdentity?: Pick<DaemonHost, "windowsSid" | "windowsUser">;
|
|
34
40
|
}
|
|
35
41
|
export interface AnywhereDeps {
|
|
36
42
|
home?: string;
|
|
@@ -20,7 +20,7 @@ import { CHATGPT_MODE } from "../../install/chatgpt-targets.js";
|
|
|
20
20
|
import { GROK_MODE } from "../../install/grok-targets.js";
|
|
21
21
|
import { HqdClientError, hqdRequest } from "../../daemon/protocol.js";
|
|
22
22
|
import { daemonPresenceLabel, heartbeatFile, readHeartbeat } from "../../daemon/heartbeat.js";
|
|
23
|
-
import { DAEMON_LAUNCHD_LABEL, DAEMON_SYSTEMD_UNIT,
|
|
23
|
+
import { DAEMON_LAUNCHD_LABEL, DAEMON_SYSTEMD_UNIT, LEGACY_DAEMON_WINDOWS_TASK, currentWindowsIdentity, legacyWindowsTask, windowsTaskName, } from "../../daemon/install.js";
|
|
24
24
|
import { hostedDaemonRunning } from "../../daemon/handoff.js";
|
|
25
25
|
import { daemonPaths } from "../../daemon/paths.js";
|
|
26
26
|
import { runningDaemonPid } from "../../daemon/lock.js";
|
|
@@ -40,6 +40,15 @@ export const REMEDIATION = {
|
|
|
40
40
|
daemonStatus: "hq daemon status",
|
|
41
41
|
link: "hq link <repo-dir> <company>",
|
|
42
42
|
};
|
|
43
|
+
/** schtasks with the same 5s cap the probe always had, so a hung query cannot stall the doctor. */
|
|
44
|
+
const runSchtasksWithTimeout = (cmd, args) => {
|
|
45
|
+
const r = spawnSync(cmd, args, { encoding: "utf8", timeout: 5_000, windowsHide: true });
|
|
46
|
+
return {
|
|
47
|
+
status: r.status,
|
|
48
|
+
stdout: typeof r.stdout === "string" ? r.stdout : "",
|
|
49
|
+
stderr: r.error ? r.error.message : (typeof r.stderr === "string" ? r.stderr : ""),
|
|
50
|
+
};
|
|
51
|
+
};
|
|
43
52
|
export function createAnywhereFamily(deps = {}) {
|
|
44
53
|
return { id: ANYWHERE_FAMILY_ID, title: "HQ anywhere runtime", run: (context) => runAnywhereChecks(context, deps) };
|
|
45
54
|
}
|
|
@@ -451,11 +460,31 @@ export function defaultServiceState(home, options = {}) {
|
|
|
451
460
|
return { installed: true, loaded: probe.status === 0, detail: `systemd ${systemScope ? "system" : "user"} ${DAEMON_SYSTEMD_UNIT}` };
|
|
452
461
|
}
|
|
453
462
|
if (platform === "win32") {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
const
|
|
458
|
-
|
|
463
|
+
// Each Windows user has their own task. The shared task an older install
|
|
464
|
+
// registered counts only when it runs as this user.
|
|
465
|
+
const run = options.run ?? runSchtasksWithTimeout;
|
|
466
|
+
const identity = options.windowsIdentity ?? currentWindowsIdentity(run);
|
|
467
|
+
const task = windowsTaskName(identity);
|
|
468
|
+
const probe = run("schtasks.exe", ["/Query", "/TN", task, "/FO", "CSV", "/NH"]);
|
|
469
|
+
if (probe.status !== 0) {
|
|
470
|
+
const legacy = legacyWindowsTask(run, identity);
|
|
471
|
+
if (legacy.state === "mine") {
|
|
472
|
+
// Still this user's daemon until install moves it to the per-user name.
|
|
473
|
+
const legacyProbe = run("schtasks.exe", ["/Query", "/TN", LEGACY_DAEMON_WINDOWS_TASK, "/FO", "CSV", "/NH"]);
|
|
474
|
+
const legacyLoaded = legacyProbe.status === 0 && /,\s*"?Running"?\s*$/i.test(legacyProbe.stdout.replace(/\0/g, "").trim());
|
|
475
|
+
return {
|
|
476
|
+
installed: true,
|
|
477
|
+
loaded: legacyLoaded,
|
|
478
|
+
detail: `your daemon runs from the shared task ${LEGACY_DAEMON_WINDOWS_TASK} from an older install${legacyLoaded ? " (running)" : " (not running)"}. Run hq daemon install to move it to your own task ${task}`,
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
const someoneElse = legacy.state === "other" || legacy.state === "unreadable"
|
|
482
|
+
? ` (${LEGACY_DAEMON_WINDOWS_TASK} belongs to another Windows user and is not yours)`
|
|
483
|
+
: "";
|
|
484
|
+
return { installed: false, loaded: false, detail: `no Scheduled Task ${task}${someoneElse}` };
|
|
485
|
+
}
|
|
486
|
+
const loaded = /,\s*"?Running"?\s*$/i.test(probe.stdout.replace(/\0/g, "").trim());
|
|
487
|
+
return { installed: true, loaded, detail: `Scheduled Task ${task}${loaded ? " is running" : " is not running"}` };
|
|
459
488
|
}
|
|
460
489
|
return { installed: false, loaded: false, detail: `${platform}: service probe not available` };
|
|
461
490
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test-only fifth hot channel (hot-signal-sync US-016).
|
|
3
|
+
*
|
|
4
|
+
* This file and `dummy.catalog.json` beside it are everything a new poll
|
|
5
|
+
* channel needs: the adapter is typed only against `../../contract.js`, and
|
|
6
|
+
* `contract.e2e.test.ts` runs it through the shared loop, landing, signals
|
|
7
|
+
* pass and run ledger without any change to those modules.
|
|
8
|
+
*
|
|
9
|
+
* It is never registered in the production registry. Only the e2e test
|
|
10
|
+
* imports it, and it registers it in a registry of its own.
|
|
11
|
+
*/
|
|
12
|
+
import type { PollHotChannelAdapter } from "../../contract.js";
|
|
13
|
+
/** The one provider tool the dummy channel calls through the gateway. */
|
|
14
|
+
export declare const DUMMY_LIST_TOOL = "dummy_list_events";
|
|
15
|
+
/** One recorded item as the dummy provider's list tool returns it. */
|
|
16
|
+
export interface DummyItem {
|
|
17
|
+
id: string;
|
|
18
|
+
rev: string;
|
|
19
|
+
author: string;
|
|
20
|
+
kind: string;
|
|
21
|
+
space: string;
|
|
22
|
+
at: string;
|
|
23
|
+
title: string;
|
|
24
|
+
body: string;
|
|
25
|
+
audience: string[];
|
|
26
|
+
}
|
|
27
|
+
/** The dummy list tool's page shape. */
|
|
28
|
+
export interface DummyListResult {
|
|
29
|
+
items: DummyItem[];
|
|
30
|
+
next: string | null;
|
|
31
|
+
}
|
|
32
|
+
export declare function createDummyAdapter(): PollHotChannelAdapter;
|
|
33
|
+
//# sourceMappingURL=dummy.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test-only fifth hot channel (hot-signal-sync US-016).
|
|
3
|
+
*
|
|
4
|
+
* This file and `dummy.catalog.json` beside it are everything a new poll
|
|
5
|
+
* channel needs: the adapter is typed only against `../../contract.js`, and
|
|
6
|
+
* `contract.e2e.test.ts` runs it through the shared loop, landing, signals
|
|
7
|
+
* pass and run ledger without any change to those modules.
|
|
8
|
+
*
|
|
9
|
+
* It is never registered in the production registry. Only the e2e test
|
|
10
|
+
* imports it, and it registers it in a registry of its own.
|
|
11
|
+
*/
|
|
12
|
+
/** The one provider tool the dummy channel calls through the gateway. */
|
|
13
|
+
export const DUMMY_LIST_TOOL = "dummy_list_events";
|
|
14
|
+
const WEEK_MS = 7 * 24 * 60 * 60 * 1000;
|
|
15
|
+
function toEvent(item) {
|
|
16
|
+
return {
|
|
17
|
+
providerId: item.id,
|
|
18
|
+
version: item.rev,
|
|
19
|
+
who: item.author,
|
|
20
|
+
what: item.kind,
|
|
21
|
+
where: item.space,
|
|
22
|
+
when: item.at,
|
|
23
|
+
audience: [...item.audience],
|
|
24
|
+
title: item.title,
|
|
25
|
+
body: item.body,
|
|
26
|
+
raw: item,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export function createDummyAdapter() {
|
|
30
|
+
return {
|
|
31
|
+
id: "dummy",
|
|
32
|
+
channel: "dummy",
|
|
33
|
+
transport: "poll",
|
|
34
|
+
hotEventTypes: ["item.created", "item.updated"],
|
|
35
|
+
catchUpWindow: { maxLookbackMs: WEEK_MS },
|
|
36
|
+
tokenScope: { provider: "dummy", scopes: ["items:read"] },
|
|
37
|
+
suggestionRule: { kind: "recent-activity", withinMs: WEEK_MS, minEvents: 1 },
|
|
38
|
+
async fetch(cursor, ctx) {
|
|
39
|
+
if (!ctx.gateway)
|
|
40
|
+
throw new Error("the dummy channel needs a gateway connection");
|
|
41
|
+
const page = (await ctx.gateway.call(DUMMY_LIST_TOOL, {
|
|
42
|
+
since: ctx.since,
|
|
43
|
+
cursor,
|
|
44
|
+
}));
|
|
45
|
+
return {
|
|
46
|
+
events: page.items.map(toEvent),
|
|
47
|
+
cursor: page.next ?? cursor,
|
|
48
|
+
hasMore: page.next !== null,
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=dummy.js.map
|