@indigoai-us/hq-cli 5.345.221 → 5.345.222
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 +47 -1
- package/dist/command-catalog.generated.d.ts +31 -0
- package/dist/command-catalog.generated.js +38 -0
- package/dist/commands/auth.js +2 -1
- package/dist/commands/core-delegate-w1b.js +9 -3
- package/dist/commands/daemon.d.ts +1 -0
- package/dist/commands/daemon.js +15 -1
- package/dist/commands/link.d.ts +2 -0
- package/dist/commands/link.js +14 -2
- package/dist/commands/mesh.js +23 -3
- package/dist/commands/sync-core.d.ts +6 -0
- package/dist/commands/sync-core.js +55 -0
- package/dist/data/command-states.json +3 -0
- package/dist/lib/daemon/catalog.js +2 -0
- package/dist/lib/daemon/install.d.ts +2 -1
- package/dist/lib/daemon/install.js +9 -0
- package/dist/lib/daemon/legacy.d.ts +1 -0
- package/dist/lib/daemon/legacy.js +5 -2
- package/dist/lib/daemon/machine-check-owner.d.ts +2 -0
- package/dist/lib/daemon/machine-check-owner.js +6 -1
- package/dist/lib/daemon/machine-checks.d.ts +7 -1
- package/dist/lib/daemon/machine-checks.js +10 -1
- package/dist/lib/daemon/mesh-owner.d.ts +45 -0
- package/dist/lib/daemon/mesh-owner.js +166 -0
- package/dist/lib/daemon/native-notice-ledger.d.ts +27 -0
- package/dist/lib/daemon/native-notice-ledger.js +113 -0
- package/dist/lib/daemon/run.d.ts +15 -0
- package/dist/lib/daemon/run.js +71 -3
- package/dist/lib/daemon/selfcheck.d.ts +35 -2
- package/dist/lib/daemon/selfcheck.js +118 -9
- package/dist/lib/hook-engine/coverage.d.ts +9 -0
- package/dist/lib/hook-engine/coverage.js +56 -0
- package/dist/lib/hook-engine/native-stop-compatibility.json +56 -5
- package/dist/lib/mesh/live/daemon/config.d.ts +8 -1
- package/dist/lib/mesh/live/daemon/config.js +16 -0
- package/dist/lib/mesh/live/daemon/install.d.ts +31 -2
- package/dist/lib/mesh/live/daemon/install.js +142 -1
- package/dist/lib/mesh/live/daemon/login-home.d.ts +5 -0
- package/dist/lib/mesh/live/daemon/login-home.js +27 -0
- package/dist/lib/mesh/live/daemon/unit-home.d.ts +49 -0
- package/dist/lib/mesh/live/daemon/unit-home.js +134 -0
- package/dist/lib/registry/registry.d.ts +35 -7
- package/dist/lib/registry/registry.js +88 -13
- package/dist/lib/scan-packages/index.js +24 -2
- package/dist/lib/search-index/max-doc-bytes.js +2 -1
- package/dist/lib/service-manager/startup-migration.d.ts +1 -0
- package/dist/lib/service-manager/startup-migration.js +3 -0
- package/dist/lib/sync-core/engine-holds.d.ts +14 -0
- package/dist/lib/sync-core/engine-holds.js +60 -0
- package/dist/lib/sync-core/engine-home.d.ts +2 -0
- package/dist/lib/sync-core/reconcile.js +8 -0
- package/dist/lib/sync-core/vault-settings.d.ts +21 -0
- package/dist/lib/sync-core/vault-settings.js +131 -0
- package/dist/lib/windows/install-followup.d.ts +2 -0
- package/dist/lib/windows/install-followup.js +4 -1
- package/dist/utils/host-registration.js +3 -1
- package/dist/utils/pack-contributions.d.ts +3 -0
- package/dist/utils/pack-contributions.js +110 -23
- package/dist/utils/self-update.d.ts +3 -1
- package/dist/utils/self-update.js +56 -11
- package/dist/utils/update-lock.d.ts +151 -14
- package/dist/utils/update-lock.js +782 -46
- package/dist/utils/version-gate.js +12 -2
- package/package.json +7 -7
|
@@ -23,6 +23,7 @@ import { isInstallableHqRoot, readDaemonConfig, registerTrustedHqRoot, verifyHqR
|
|
|
23
23
|
import { defaultPidLockDeps, pidLockStatus, readPidLock } from "./pid-lock.js";
|
|
24
24
|
import { retireLegacyListen } from "./legacy-listen.js";
|
|
25
25
|
import { readDaemonState } from "./state.js";
|
|
26
|
+
import { HQ_DAEMON_LAUNCHD_LABEL, assertLoginHome, isLoginHome, meshPlistPath, meshUnitFromOtherHome, removeMeshUnitFromOtherHome, } from "./unit-home.js";
|
|
26
27
|
import { activateLaunchd, defaultRunCommand, discoverLaunchdIdentity, installLaunchdPlist, launchdProgramArguments, launchdIsLoaded, launchdServiceTarget, launchdPlistProgramArguments, parseLaunchdCommand, launchdProgramArgumentsDiffer, parseLaunchctlPrintArguments, } from "../../../service-manager/launchd.js";
|
|
27
28
|
import { activateSystemd, systemdIsActive } from "../../../service-manager/systemd.js";
|
|
28
29
|
import { nodeBinaryProblem, preferStableNodeBinary } from "../../../node-binary.js";
|
|
@@ -66,6 +67,23 @@ function readServiceText(file, existsSync, readFileSync) {
|
|
|
66
67
|
}
|
|
67
68
|
return buf.toString("utf8");
|
|
68
69
|
}
|
|
70
|
+
export function installedUnitHqRoot(home, platform = detectPlatform(), env) {
|
|
71
|
+
if (platform !== "darwin" && platform !== "linux" && platform !== "win32")
|
|
72
|
+
return null;
|
|
73
|
+
const unitPath = platform === "darwin"
|
|
74
|
+
? path.join(home, "Library", "LaunchAgents", `${LAUNCHD_LABEL}.plist`)
|
|
75
|
+
: platform === "linux"
|
|
76
|
+
? path.join(home, ".config", "systemd", "user", SYSTEMD_UNIT_NAME)
|
|
77
|
+
: path.join(daemonDir(undefined, home, env), `${WINDOWS_TASK_NAME}.xml`);
|
|
78
|
+
try {
|
|
79
|
+
if (!fs.existsSync(unitPath))
|
|
80
|
+
return null;
|
|
81
|
+
return hqRootFromUnitText(platform, readServiceText(unitPath, fs.existsSync, fs.readFileSync));
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
69
87
|
function hqRootFromUnitText(platform, text) {
|
|
70
88
|
if (platform === "win32")
|
|
71
89
|
return parseWindowsTaskHqRoot(text);
|
|
@@ -178,6 +196,23 @@ export function restartDaemonServiceIfInstalled(opts = {}) {
|
|
|
178
196
|
};
|
|
179
197
|
});
|
|
180
198
|
try {
|
|
199
|
+
if (platform === "darwin" && !isLoginHome(home, opts.loginHome))
|
|
200
|
+
return { attempted: false, restarted: false };
|
|
201
|
+
const repair = repairMeshUnitFromOtherHome({
|
|
202
|
+
platform,
|
|
203
|
+
home,
|
|
204
|
+
loginHome: opts.loginHome,
|
|
205
|
+
uid: opts.uid,
|
|
206
|
+
hqRoot: opts.hqRoot,
|
|
207
|
+
env: opts.env,
|
|
208
|
+
existsSync,
|
|
209
|
+
run,
|
|
210
|
+
sleep: opts.sleep,
|
|
211
|
+
meshOwner: opts.meshOwner,
|
|
212
|
+
});
|
|
213
|
+
if (repair.from) {
|
|
214
|
+
return { attempted: true, restarted: repair.action === "replaced", message: repair.message };
|
|
215
|
+
}
|
|
181
216
|
migrateLegacyDaemonUnit({
|
|
182
217
|
platform,
|
|
183
218
|
home,
|
|
@@ -248,6 +283,101 @@ export function restartDaemonServiceIfInstalled(opts = {}) {
|
|
|
248
283
|
}
|
|
249
284
|
return { attempted: false, restarted: false };
|
|
250
285
|
}
|
|
286
|
+
function defaultMeshOwner(home) {
|
|
287
|
+
return fs.existsSync(path.join(home, "Library", "LaunchAgents", `${HQ_DAEMON_LAUNCHD_LABEL}.plist`)) ? "hq-daemon" : null;
|
|
288
|
+
}
|
|
289
|
+
export function repairMeshUnitFromOtherHome(opts = {}) {
|
|
290
|
+
const platform = opts.platform ?? detectPlatform();
|
|
291
|
+
if (platform !== "darwin")
|
|
292
|
+
return { repaired: false };
|
|
293
|
+
const home = opts.home ?? os.homedir();
|
|
294
|
+
const uid = opts.uid ?? process.getuid?.();
|
|
295
|
+
if (typeof uid !== "number")
|
|
296
|
+
return { repaired: false };
|
|
297
|
+
const run = asRunCommand(opts.run ?? defaultRunCommand);
|
|
298
|
+
const existsSync = opts.existsSync ?? fs.existsSync;
|
|
299
|
+
const foreign = meshUnitFromOtherHome({ home, loginHome: opts.loginHome, uid, run });
|
|
300
|
+
if (!foreign)
|
|
301
|
+
return { repaired: false };
|
|
302
|
+
const foundAt = (from) => `The Work Mesh service was loaded from ${from}, which is not in this account's home folder.`;
|
|
303
|
+
const ownerOf = opts.meshOwner ?? (() => defaultMeshOwner(home));
|
|
304
|
+
let owner;
|
|
305
|
+
try {
|
|
306
|
+
owner = ownerOf();
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
return {
|
|
310
|
+
repaired: false,
|
|
311
|
+
from: foreign,
|
|
312
|
+
message: `${foundAt(foreign)} Left it running: could not tell whether hq daemon runs Work Mesh (${error instanceof Error ? error.message : String(error)}). Run: hq daemon status`,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
const other = removeMeshUnitFromOtherHome({ home, loginHome: opts.loginHome, uid, run, sleep: opts.sleep });
|
|
316
|
+
if (!other.from)
|
|
317
|
+
return { repaired: false };
|
|
318
|
+
const found = foundAt(other.from);
|
|
319
|
+
if (!other.removed) {
|
|
320
|
+
return { repaired: false, from: other.from, message: `${found} Stopping it failed: ${other.error}` };
|
|
321
|
+
}
|
|
322
|
+
try {
|
|
323
|
+
owner = ownerOf();
|
|
324
|
+
}
|
|
325
|
+
catch {
|
|
326
|
+
// keep the owner read before the bootout
|
|
327
|
+
}
|
|
328
|
+
const plist = meshPlistPath(home);
|
|
329
|
+
try {
|
|
330
|
+
if (owner === "hq-daemon") {
|
|
331
|
+
return { repaired: true, action: "removed", from: other.from, message: `${found} Stopped it; hq daemon runs Work Mesh for this account.` };
|
|
332
|
+
}
|
|
333
|
+
if (existsSync(plist)) {
|
|
334
|
+
activateLaunchd(plist, run, uid, { sleep: opts.sleep });
|
|
335
|
+
return { repaired: true, action: "replaced", from: other.from, message: `${found} Loaded ${plist} in its place.` };
|
|
336
|
+
}
|
|
337
|
+
if (owner === "hq-daemon-mesh-off") {
|
|
338
|
+
return {
|
|
339
|
+
repaired: true,
|
|
340
|
+
action: "removed",
|
|
341
|
+
from: other.from,
|
|
342
|
+
message: `${found} Stopped it. Work Mesh is turned off in hq daemon; turn it on with: hq daemon enable mesh`,
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
const root = verifyHqRoot(opts.hqRoot) ??
|
|
346
|
+
verifyHqRoot(opts.env?.HQ_ROOT) ??
|
|
347
|
+
readDaemonConfig(daemonDir(undefined, home, opts.env)).trustedHqRoots.at(-1);
|
|
348
|
+
if (!root) {
|
|
349
|
+
return {
|
|
350
|
+
repaired: true,
|
|
351
|
+
action: "removed",
|
|
352
|
+
from: other.from,
|
|
353
|
+
message: `${found} Stopped it. Start the real one with: hq mesh daemon install`,
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
const env = opts.env ?? process.env;
|
|
357
|
+
const paths = buildInstallPaths({
|
|
358
|
+
home,
|
|
359
|
+
env: opts.env,
|
|
360
|
+
hqRoot: root,
|
|
361
|
+
hqBinary: resolveHqBinary(process.argv, env),
|
|
362
|
+
nodeBinary: resolveNodeBinary(process.execPath, env),
|
|
363
|
+
});
|
|
364
|
+
installDaemonService({ platform, paths, run, uid, sleep: opts.sleep, loginHome: opts.loginHome });
|
|
365
|
+
return {
|
|
366
|
+
repaired: true,
|
|
367
|
+
action: "replaced",
|
|
368
|
+
from: other.from,
|
|
369
|
+
message: `${found} Installed ${paths.plistPath} in its place.`,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
catch (error) {
|
|
373
|
+
return {
|
|
374
|
+
repaired: false,
|
|
375
|
+
action: "removed",
|
|
376
|
+
from: other.from,
|
|
377
|
+
message: `${found} Stopped it, but starting the real one failed: ${error instanceof Error ? error.message : String(error)}. Run: hq mesh daemon install`,
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
}
|
|
251
381
|
export function detectPlatform(platform = process.platform) {
|
|
252
382
|
if (platform === "darwin")
|
|
253
383
|
return "darwin";
|
|
@@ -397,8 +527,14 @@ export function isNewerCliVersion(current, recorded) {
|
|
|
397
527
|
* `run` is the launchctl/systemctl seam — tests pass a stub.
|
|
398
528
|
*/
|
|
399
529
|
export function installDaemonIfStale(opts) {
|
|
400
|
-
const recorded = readDaemonState(opts.paths.daemonDir)?.cliVersion;
|
|
401
530
|
const platformForUnit = opts.platform ?? detectPlatform();
|
|
531
|
+
if (platformForUnit === "darwin" && !isLoginHome(opts.paths.home, opts.loginHome)) {
|
|
532
|
+
return {
|
|
533
|
+
reinstalled: false,
|
|
534
|
+
message: `HOME is ${opts.paths.home}, not this account's home folder; leaving the Work Mesh service alone`,
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
const recorded = readDaemonState(opts.paths.daemonDir)?.cliVersion;
|
|
402
538
|
const installedNode = installedDaemonNodeBinary(opts.paths, platformForUnit, opts.readUnit);
|
|
403
539
|
// Only a rewrite that changes the node path helps: a unit whose node is gone
|
|
404
540
|
// or versioned, while this install resolves a different (stable) one.
|
|
@@ -433,6 +569,7 @@ export function installDaemonIfStale(opts) {
|
|
|
433
569
|
run,
|
|
434
570
|
uid: opts.uid,
|
|
435
571
|
sleep: opts.sleep,
|
|
572
|
+
loginHome: opts.loginHome,
|
|
436
573
|
});
|
|
437
574
|
return {
|
|
438
575
|
reinstalled: true,
|
|
@@ -977,6 +1114,8 @@ export function installDaemonService(opts) {
|
|
|
977
1114
|
const platform = opts.platform ?? detectPlatform();
|
|
978
1115
|
const paths = opts.paths ??
|
|
979
1116
|
buildInstallPaths({ systemUser: opts.systemUser });
|
|
1117
|
+
if (platform === "darwin")
|
|
1118
|
+
assertLoginHome("install", paths.home, opts.loginHome);
|
|
980
1119
|
const mkdirSync = opts.mkdirSync ?? fs.mkdirSync;
|
|
981
1120
|
mkdirSync(paths.daemonDir, { recursive: true, mode: 0o700 });
|
|
982
1121
|
registerTrustedHqRoot(paths.daemonDir, paths.hqRoot);
|
|
@@ -1140,6 +1279,8 @@ export function installDaemonService(opts) {
|
|
|
1140
1279
|
export function uninstallDaemonService(opts) {
|
|
1141
1280
|
const platform = opts.platform ?? detectPlatform();
|
|
1142
1281
|
const paths = opts.paths ?? buildInstallPaths({});
|
|
1282
|
+
if (platform === "darwin")
|
|
1283
|
+
assertLoginHome("remove", paths.home, opts.loginHome);
|
|
1143
1284
|
const unlinkSync = opts.unlinkSync ?? fs.unlinkSync;
|
|
1144
1285
|
const existsSync = opts.existsSync ?? fs.existsSync;
|
|
1145
1286
|
if (platform === "win32") {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function canonicalDir(dir: string): string;
|
|
2
|
+
export declare function loginUserHome(): string;
|
|
3
|
+
export declare function isLoginHome(home: string, loginHome?: string): boolean;
|
|
4
|
+
export declare function homeIsLoginSafe(home: string, loginHome?: string): boolean;
|
|
5
|
+
//# sourceMappingURL=login-home.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
export function canonicalDir(dir) {
|
|
5
|
+
const resolved = path.resolve(dir);
|
|
6
|
+
try {
|
|
7
|
+
return fs.realpathSync.native(resolved);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return resolved;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export function loginUserHome() {
|
|
14
|
+
return os.userInfo().homedir;
|
|
15
|
+
}
|
|
16
|
+
export function isLoginHome(home, loginHome = loginUserHome()) {
|
|
17
|
+
return canonicalDir(home) === canonicalDir(loginHome);
|
|
18
|
+
}
|
|
19
|
+
export function homeIsLoginSafe(home, loginHome) {
|
|
20
|
+
try {
|
|
21
|
+
return isLoginHome(home, loginHome);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=login-home.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { homeIsLoginSafe, isLoginHome, loginUserHome } from "./login-home.js";
|
|
2
|
+
import { type SleepFn } from "../../../service-manager/launchd.js";
|
|
3
|
+
export { homeIsLoginSafe, isLoginHome, loginUserHome };
|
|
4
|
+
export declare class MeshUnitHomeError extends Error {
|
|
5
|
+
readonly home: string;
|
|
6
|
+
readonly loginHome: string;
|
|
7
|
+
constructor(action: "install" | "remove" | "start", home: string, loginHome: string, label?: string);
|
|
8
|
+
}
|
|
9
|
+
export declare function assertLoginHome(action: "install" | "remove" | "start", home: string, loginHome?: string, label?: string): void;
|
|
10
|
+
export declare function loadedLaunchdPlistPath(printed: string): string | null;
|
|
11
|
+
export declare function meshPlistPath(home: string): string;
|
|
12
|
+
export declare function jobLoadedFromHome(printed: string, home: string): boolean;
|
|
13
|
+
export declare function meshUnitLoadedFromElsewhere(printed: string, home: string): string | null;
|
|
14
|
+
export declare function meshJobLoadedForHome(printed: {
|
|
15
|
+
status: number | null;
|
|
16
|
+
stdout?: string;
|
|
17
|
+
}, home: string): boolean;
|
|
18
|
+
export declare const HQ_DAEMON_LAUNCHD_LABEL = "ai.getindigo.hq-daemon";
|
|
19
|
+
export type LaunchctlRunner = (command: string, args: string[]) => {
|
|
20
|
+
status: number | null;
|
|
21
|
+
stdout?: string;
|
|
22
|
+
stderr?: string;
|
|
23
|
+
};
|
|
24
|
+
export interface OtherHomeMeshUnit {
|
|
25
|
+
removed: boolean;
|
|
26
|
+
from?: string;
|
|
27
|
+
error?: string;
|
|
28
|
+
}
|
|
29
|
+
export declare function meshUnitFromOtherHome(opts: {
|
|
30
|
+
home: string;
|
|
31
|
+
loginHome?: string;
|
|
32
|
+
uid: number;
|
|
33
|
+
run: LaunchctlRunner;
|
|
34
|
+
label?: string;
|
|
35
|
+
}): string | null;
|
|
36
|
+
export declare function removeMeshUnitFromOtherHome(opts: {
|
|
37
|
+
home: string;
|
|
38
|
+
loginHome?: string;
|
|
39
|
+
uid: number;
|
|
40
|
+
run: LaunchctlRunner;
|
|
41
|
+
label?: string;
|
|
42
|
+
sleep?: SleepFn;
|
|
43
|
+
markPending?: boolean;
|
|
44
|
+
}): OtherHomeMeshUnit;
|
|
45
|
+
export declare const FOREIGN_UNLOAD_DEADLINE_MS = 30000;
|
|
46
|
+
export declare function markHealPending(home: string, label: string): void;
|
|
47
|
+
export declare function clearHealPending(home: string, label: string): void;
|
|
48
|
+
export declare function healPending(home: string, label: string): boolean;
|
|
49
|
+
//# sourceMappingURL=unit-home.d.ts.map
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { LAUNCHD_LABEL } from "./paths.js";
|
|
4
|
+
import { canonicalDir, homeIsLoginSafe, isLoginHome, loginUserHome } from "./login-home.js";
|
|
5
|
+
import { waitForLaunchdUnload } from "../../../service-manager/launchd.js";
|
|
6
|
+
export { homeIsLoginSafe, isLoginHome, loginUserHome };
|
|
7
|
+
export class MeshUnitHomeError extends Error {
|
|
8
|
+
home;
|
|
9
|
+
loginHome;
|
|
10
|
+
constructor(action, home, loginHome, label = LAUNCHD_LABEL) {
|
|
11
|
+
const service = label === LAUNCHD_LABEL ? "the Work Mesh service" : "hq daemon";
|
|
12
|
+
const verb = action === "install" ? "installing" : action === "remove" ? "removing" : "starting";
|
|
13
|
+
super(`Not ${verb} ${service}: HOME is ${home}, ` +
|
|
14
|
+
`but this account's home folder is ${loginHome}. macOS keeps one ${label} service per login, ` +
|
|
15
|
+
`so doing this from another HOME would ${action === "remove" ? "stop" : "replace"} the real one. ` +
|
|
16
|
+
"Run the command again without overriding HOME.");
|
|
17
|
+
this.name = "MeshUnitHomeError";
|
|
18
|
+
this.home = home;
|
|
19
|
+
this.loginHome = loginHome;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function assertLoginHome(action, home, loginHome = loginUserHome(), label = LAUNCHD_LABEL) {
|
|
23
|
+
if (!isLoginHome(home, loginHome))
|
|
24
|
+
throw new MeshUnitHomeError(action, home, loginHome, label);
|
|
25
|
+
}
|
|
26
|
+
export function loadedLaunchdPlistPath(printed) {
|
|
27
|
+
const value = /^\s*path\s*=\s*(.+?)\s*$/m.exec(printed)?.[1];
|
|
28
|
+
return value && path.isAbsolute(value) ? value : null;
|
|
29
|
+
}
|
|
30
|
+
export function meshPlistPath(home) {
|
|
31
|
+
return path.join(home, "Library", "LaunchAgents", `${LAUNCHD_LABEL}.plist`);
|
|
32
|
+
}
|
|
33
|
+
const MACHINE_AGENT_DIRS = ["/Library/LaunchAgents/", "/System/Library/LaunchAgents/"];
|
|
34
|
+
export function jobLoadedFromHome(printed, home) {
|
|
35
|
+
const loaded = loadedLaunchdPlistPath(printed);
|
|
36
|
+
if (!loaded)
|
|
37
|
+
return false;
|
|
38
|
+
return canonicalDir(path.dirname(loaded)) === canonicalDir(path.join(home, "Library", "LaunchAgents"));
|
|
39
|
+
}
|
|
40
|
+
export function meshUnitLoadedFromElsewhere(printed, home) {
|
|
41
|
+
const loaded = loadedLaunchdPlistPath(printed);
|
|
42
|
+
if (!loaded)
|
|
43
|
+
return null;
|
|
44
|
+
if (MACHINE_AGENT_DIRS.some((dir) => loaded.startsWith(dir)))
|
|
45
|
+
return null;
|
|
46
|
+
const expected = meshPlistPath(home);
|
|
47
|
+
return canonicalDir(path.dirname(loaded)) === canonicalDir(path.dirname(expected)) ? null : loaded;
|
|
48
|
+
}
|
|
49
|
+
export function meshJobLoadedForHome(printed, home) {
|
|
50
|
+
if (printed.status !== 0)
|
|
51
|
+
return false;
|
|
52
|
+
return meshUnitLoadedFromElsewhere(printed.stdout ?? "", home) === null;
|
|
53
|
+
}
|
|
54
|
+
export const HQ_DAEMON_LAUNCHD_LABEL = "ai.getindigo.hq-daemon";
|
|
55
|
+
export function meshUnitFromOtherHome(opts) {
|
|
56
|
+
if (!isLoginHome(opts.home, opts.loginHome))
|
|
57
|
+
return null;
|
|
58
|
+
const printed = opts.run("launchctl", ["print", `gui/${opts.uid}/${opts.label ?? LAUNCHD_LABEL}`]);
|
|
59
|
+
if (printed.status !== 0)
|
|
60
|
+
return null;
|
|
61
|
+
return meshUnitLoadedFromElsewhere(printed.stdout ?? "", opts.home);
|
|
62
|
+
}
|
|
63
|
+
export function removeMeshUnitFromOtherHome(opts) {
|
|
64
|
+
if (!isLoginHome(opts.home, opts.loginHome))
|
|
65
|
+
return { removed: false };
|
|
66
|
+
const target = `gui/${opts.uid}/${opts.label ?? LAUNCHD_LABEL}`;
|
|
67
|
+
const printed = opts.run("launchctl", ["print", target]);
|
|
68
|
+
if (printed.status !== 0)
|
|
69
|
+
return { removed: false };
|
|
70
|
+
const from = meshUnitLoadedFromElsewhere(printed.stdout ?? "", opts.home);
|
|
71
|
+
if (!from)
|
|
72
|
+
return { removed: false };
|
|
73
|
+
if (opts.markPending)
|
|
74
|
+
markHealPending(opts.home, opts.label ?? LAUNCHD_LABEL);
|
|
75
|
+
const bootout = opts.run("launchctl", ["bootout", target]);
|
|
76
|
+
const unloaded = waitForLaunchdUnload(target, (command, args) => {
|
|
77
|
+
const r = opts.run(command, args);
|
|
78
|
+
return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
79
|
+
}, { sleep: opts.sleep, deadlineMs: FOREIGN_UNLOAD_DEADLINE_MS });
|
|
80
|
+
if (!unloaded) {
|
|
81
|
+
const detail = bootout.status !== 0 ? (bootout.stderr || bootout.stdout || "").trim() || `launchctl bootout exited ${bootout.status}` : "";
|
|
82
|
+
return { removed: false, from, error: detail || `${target} was still loaded ${FOREIGN_UNLOAD_DEADLINE_MS / 1000} s after launchctl bootout` };
|
|
83
|
+
}
|
|
84
|
+
return { removed: true, from };
|
|
85
|
+
}
|
|
86
|
+
export const FOREIGN_UNLOAD_DEADLINE_MS = 30_000;
|
|
87
|
+
function healPendingPath(home) {
|
|
88
|
+
return path.join(home, ".hq", "launchd-heal-pending.json");
|
|
89
|
+
}
|
|
90
|
+
function readHealPending(home) {
|
|
91
|
+
try {
|
|
92
|
+
const raw = JSON.parse(fs.readFileSync(healPendingPath(home), "utf8"));
|
|
93
|
+
const labels = raw && typeof raw === "object" ? raw.labels : undefined;
|
|
94
|
+
return Array.isArray(labels) ? labels.filter((label) => typeof label === "string") : [];
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function writeHealPending(home, labels) {
|
|
101
|
+
const file = healPendingPath(home);
|
|
102
|
+
if (labels.length === 0) {
|
|
103
|
+
fs.rmSync(file, { force: true });
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
107
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
108
|
+
fs.writeFileSync(tmp, `${JSON.stringify({ labels })}\n`);
|
|
109
|
+
fs.renameSync(tmp, file);
|
|
110
|
+
}
|
|
111
|
+
export function markHealPending(home, label) {
|
|
112
|
+
try {
|
|
113
|
+
const labels = readHealPending(home);
|
|
114
|
+
if (!labels.includes(label))
|
|
115
|
+
writeHealPending(home, [...labels, label]);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
// best effort: a missing marker only loses the resume of an interrupted heal
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export function clearHealPending(home, label) {
|
|
122
|
+
try {
|
|
123
|
+
const labels = readHealPending(home);
|
|
124
|
+
if (labels.includes(label))
|
|
125
|
+
writeHealPending(home, labels.filter((item) => item !== label));
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
// best effort
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export function healPending(home, label) {
|
|
132
|
+
return readHealPending(home).includes(label);
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=unit-home.js.map
|
|
@@ -21,7 +21,7 @@ export interface Registry {
|
|
|
21
21
|
export type ResolveResult = {
|
|
22
22
|
company: string;
|
|
23
23
|
key: string;
|
|
24
|
-
source: RegistrySource;
|
|
24
|
+
source: RegistrySource | "layout";
|
|
25
25
|
} | {
|
|
26
26
|
company: null;
|
|
27
27
|
reason: string;
|
|
@@ -50,11 +50,35 @@ export declare function remoteForDir(dir: string): string | null;
|
|
|
50
50
|
export declare function keyForDir(dir: string): string;
|
|
51
51
|
/** Every key that could describe `dir`, most specific first. */
|
|
52
52
|
export declare function candidateKeys(dir: string): string[];
|
|
53
|
+
export interface ResolveOptions {
|
|
54
|
+
/**
|
|
55
|
+
* The caller's own HQ root. The companies/<slug> layout fallback only runs
|
|
56
|
+
* inside this tree; without it the fallback is off.
|
|
57
|
+
*/
|
|
58
|
+
hqRoot?: string | null;
|
|
59
|
+
}
|
|
53
60
|
/**
|
|
54
61
|
* Resolve the company for `dir`. Among matching keys the highest-ranked source
|
|
55
62
|
* wins (link > prompt > manifest); ties go to the more specific key.
|
|
63
|
+
* With no registry hit, `opts.hqRoot` enables the companies/<slug> layout.
|
|
56
64
|
*/
|
|
57
|
-
export declare function resolveCompanyForDir(registry: Registry, dir: string): ResolveResult;
|
|
65
|
+
export declare function resolveCompanyForDir(registry: Registry, dir: string, opts?: ResolveOptions): ResolveResult;
|
|
66
|
+
/**
|
|
67
|
+
* Resolve `<hqRoot>/companies/<slug>/**` from HQ's own tree. A companies/<slug>
|
|
68
|
+
* folder is the company; it does not use the enclosing HQ git remote.
|
|
69
|
+
*
|
|
70
|
+
* Only the caller's own HQ root counts. A `companies/<slug>` folder in any
|
|
71
|
+
* other tree (a cloned repo, another HQ copy) never binds a company: a folder
|
|
72
|
+
* name alone must not grant a tenant. The walk uses the symlink-resolved path,
|
|
73
|
+
* and the slug must be listed in that root's companies/manifest.yaml.
|
|
74
|
+
*/
|
|
75
|
+
export declare function companyFromHqLayout(dir: string, hqRoot: string): {
|
|
76
|
+
company: string;
|
|
77
|
+
key: string;
|
|
78
|
+
source: "layout";
|
|
79
|
+
} | null;
|
|
80
|
+
/** True when `hq link` would write a key for the enclosing git repo, not this folder. */
|
|
81
|
+
export declare function wouldBindEnclosingRemote(dir: string): boolean;
|
|
58
82
|
export declare function setEntry(registry: Registry, key: string, company: string, source: RegistrySource, now?: Date): RegistryEntry;
|
|
59
83
|
/** Remove every key that describes `dir`. Returns the removed keys. */
|
|
60
84
|
export declare function removeEntriesForDir(registry: Registry, dir: string): string[];
|
|
@@ -64,12 +88,16 @@ export interface SeedResult {
|
|
|
64
88
|
skippedLinked: string[];
|
|
65
89
|
ambiguous: string[];
|
|
66
90
|
}
|
|
91
|
+
/** Resolve a manifest repos[] entry to a local filesystem path. */
|
|
92
|
+
export declare function expandManifestLocalPath(raw: string, hqRoot: string, home?: string): string;
|
|
67
93
|
/**
|
|
68
94
|
* Seed manifest-sourced entries from companies/manifest.yaml repos[]. Entries
|
|
69
|
-
* may be HQ-relative paths (`repos/private/x`), `owner/name`,
|
|
70
|
-
* A local path seeds both its path key and, when it has an
|
|
71
|
-
*
|
|
72
|
-
*
|
|
95
|
+
* may be HQ-relative paths (`repos/private/x`), `~/checkout`, `owner/name`,
|
|
96
|
+
* or remote URLs. A local path seeds both its path key and, when it has an
|
|
97
|
+
* origin, its remote key. `~/…` expands to the home directory; a missing
|
|
98
|
+
* tilde path is skipped rather than treated as `github.com/~/…`. Never
|
|
99
|
+
* overwrites a `link` or `prompt` entry, and skips any key claimed by more
|
|
100
|
+
* than one company.
|
|
73
101
|
*/
|
|
74
|
-
export declare function seedFromManifest(registry: Registry, hqRoot: string, companies: CompaniesManifestMap, now?: Date): SeedResult;
|
|
102
|
+
export declare function seedFromManifest(registry: Registry, hqRoot: string, companies: CompaniesManifestMap, now?: Date, home?: string): SeedResult;
|
|
75
103
|
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -13,6 +13,9 @@ import * as path from "node:path";
|
|
|
13
13
|
import { atomicWriteJson } from "../work-context/atomic.js";
|
|
14
14
|
import { findEnclosingGitDir, findWorkTreeRoot, readOriginRemoteUrl, } from "../work-context/repo-remote.js";
|
|
15
15
|
import { normalizeManifestRepo, normalizeRemoteUrl } from "./normalize-remote.js";
|
|
16
|
+
import { parseManifestSlugs } from "../core-utils/manifest-slugs.js";
|
|
17
|
+
/** Company slugs HQ stores under `companies/<slug>/`. */
|
|
18
|
+
const COMPANY_SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
16
19
|
/** Higher wins. An explicit `hq link` beats a prompt answer beats the manifest seed. */
|
|
17
20
|
const SOURCE_RANK = { link: 3, prompt: 2, manifest: 1 };
|
|
18
21
|
export class RegistryFormatError extends Error {
|
|
@@ -146,8 +149,9 @@ export function candidateKeys(dir) {
|
|
|
146
149
|
/**
|
|
147
150
|
* Resolve the company for `dir`. Among matching keys the highest-ranked source
|
|
148
151
|
* wins (link > prompt > manifest); ties go to the more specific key.
|
|
152
|
+
* With no registry hit, `opts.hqRoot` enables the companies/<slug> layout.
|
|
149
153
|
*/
|
|
150
|
-
export function resolveCompanyForDir(registry, dir) {
|
|
154
|
+
export function resolveCompanyForDir(registry, dir, opts = {}) {
|
|
151
155
|
let best = null;
|
|
152
156
|
for (const key of candidateKeys(dir)) {
|
|
153
157
|
const entry = registry.entries[key];
|
|
@@ -157,13 +161,67 @@ export function resolveCompanyForDir(registry, dir) {
|
|
|
157
161
|
best = { key, entry };
|
|
158
162
|
}
|
|
159
163
|
}
|
|
160
|
-
if (
|
|
161
|
-
return {
|
|
162
|
-
company: null,
|
|
163
|
-
reason: `No HQ company is linked to ${canonicalDir(dir)}. Run \`hq link <company>\` there.`,
|
|
164
|
-
};
|
|
164
|
+
if (best) {
|
|
165
|
+
return { company: best.entry.company, key: best.key, source: best.entry.source };
|
|
165
166
|
}
|
|
166
|
-
|
|
167
|
+
const layout = opts.hqRoot ? companyFromHqLayout(dir, opts.hqRoot) : null;
|
|
168
|
+
if (layout)
|
|
169
|
+
return layout;
|
|
170
|
+
return {
|
|
171
|
+
company: null,
|
|
172
|
+
reason: `No HQ company is linked to ${canonicalDir(dir)}. Run \`hq link <company>\` there.`,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Resolve `<hqRoot>/companies/<slug>/**` from HQ's own tree. A companies/<slug>
|
|
177
|
+
* folder is the company; it does not use the enclosing HQ git remote.
|
|
178
|
+
*
|
|
179
|
+
* Only the caller's own HQ root counts. A `companies/<slug>` folder in any
|
|
180
|
+
* other tree (a cloned repo, another HQ copy) never binds a company: a folder
|
|
181
|
+
* name alone must not grant a tenant. The walk uses the symlink-resolved path,
|
|
182
|
+
* and the slug must be listed in that root's companies/manifest.yaml.
|
|
183
|
+
*/
|
|
184
|
+
export function companyFromHqLayout(dir, hqRoot) {
|
|
185
|
+
const root = canonicalDir(hqRoot);
|
|
186
|
+
const companiesDir = path.join(root, "companies");
|
|
187
|
+
const real = canonicalDir(dir);
|
|
188
|
+
const rel = path.relative(companiesDir, real);
|
|
189
|
+
if (!rel || rel.startsWith("..") || path.isAbsolute(rel))
|
|
190
|
+
return null;
|
|
191
|
+
const slug = rel.split(path.sep)[0];
|
|
192
|
+
if (!COMPANY_SLUG.test(slug) || slug === "personal")
|
|
193
|
+
return null;
|
|
194
|
+
const cur = path.join(companiesDir, slug);
|
|
195
|
+
let st;
|
|
196
|
+
try {
|
|
197
|
+
st = fs.lstatSync(cur);
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
if (st.isSymbolicLink() || !st.isDirectory())
|
|
203
|
+
return null;
|
|
204
|
+
let manifest;
|
|
205
|
+
try {
|
|
206
|
+
manifest = fs.readFileSync(path.join(companiesDir, "manifest.yaml"), "utf8");
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
if (!parseManifestSlugs(manifest).includes(slug))
|
|
212
|
+
return null;
|
|
213
|
+
return { company: slug, key: pathKey(dir), source: "layout" };
|
|
214
|
+
}
|
|
215
|
+
/** True when `hq link` would write a key for the enclosing git repo, not this folder. */
|
|
216
|
+
export function wouldBindEnclosingRemote(dir) {
|
|
217
|
+
const workTree = findWorkTreeRoot(dir);
|
|
218
|
+
if (!workTree)
|
|
219
|
+
return false;
|
|
220
|
+
if (canonicalDir(dir) === canonicalDir(workTree))
|
|
221
|
+
return false;
|
|
222
|
+
// Any key other than the folder's own path key covers the whole enclosing
|
|
223
|
+
// repo: its origin, or (no origin) the work-tree root's path key.
|
|
224
|
+
return keyForDir(dir) !== pathKey(dir);
|
|
167
225
|
}
|
|
168
226
|
export function setEntry(registry, key, company, source, now = new Date()) {
|
|
169
227
|
const entry = { company, source, linkedAt: now.toISOString() };
|
|
@@ -181,14 +239,28 @@ export function removeEntriesForDir(registry, dir) {
|
|
|
181
239
|
}
|
|
182
240
|
return removed;
|
|
183
241
|
}
|
|
242
|
+
/** Resolve a manifest repos[] entry to a local filesystem path. */
|
|
243
|
+
export function expandManifestLocalPath(raw, hqRoot, home = os.homedir()) {
|
|
244
|
+
const trimmed = raw.trim();
|
|
245
|
+
if (trimmed === "~")
|
|
246
|
+
return home;
|
|
247
|
+
if (trimmed.startsWith("~/") || trimmed.startsWith("~\\")) {
|
|
248
|
+
return path.join(home, trimmed.slice(2));
|
|
249
|
+
}
|
|
250
|
+
if (path.isAbsolute(trimmed))
|
|
251
|
+
return trimmed;
|
|
252
|
+
return path.join(hqRoot, trimmed);
|
|
253
|
+
}
|
|
184
254
|
/**
|
|
185
255
|
* Seed manifest-sourced entries from companies/manifest.yaml repos[]. Entries
|
|
186
|
-
* may be HQ-relative paths (`repos/private/x`), `owner/name`,
|
|
187
|
-
* A local path seeds both its path key and, when it has an
|
|
188
|
-
*
|
|
189
|
-
*
|
|
256
|
+
* may be HQ-relative paths (`repos/private/x`), `~/checkout`, `owner/name`,
|
|
257
|
+
* or remote URLs. A local path seeds both its path key and, when it has an
|
|
258
|
+
* origin, its remote key. `~/…` expands to the home directory; a missing
|
|
259
|
+
* tilde path is skipped rather than treated as `github.com/~/…`. Never
|
|
260
|
+
* overwrites a `link` or `prompt` entry, and skips any key claimed by more
|
|
261
|
+
* than one company.
|
|
190
262
|
*/
|
|
191
|
-
export function seedFromManifest(registry, hqRoot, companies, now = new Date()) {
|
|
263
|
+
export function seedFromManifest(registry, hqRoot, companies, now = new Date(), home = os.homedir()) {
|
|
192
264
|
const claimGroups = [];
|
|
193
265
|
for (const [company, entry] of Object.entries(companies)) {
|
|
194
266
|
const repos = entry && typeof entry === "object" ? entry.repos : undefined;
|
|
@@ -198,7 +270,7 @@ export function seedFromManifest(registry, hqRoot, companies, now = new Date())
|
|
|
198
270
|
if (typeof raw !== "string" || !raw.trim())
|
|
199
271
|
continue;
|
|
200
272
|
const trimmed = raw.trim();
|
|
201
|
-
const local =
|
|
273
|
+
const local = expandManifestLocalPath(trimmed, hqRoot, home);
|
|
202
274
|
let isDir;
|
|
203
275
|
try {
|
|
204
276
|
isDir = fs.statSync(local).isDirectory();
|
|
@@ -214,6 +286,9 @@ export function seedFromManifest(registry, hqRoot, companies, now = new Date())
|
|
|
214
286
|
claimGroups.push({ company, keys });
|
|
215
287
|
continue;
|
|
216
288
|
}
|
|
289
|
+
if (trimmed === "~" || trimmed.startsWith("~/") || trimmed.startsWith("~\\")) {
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
217
292
|
const normalized = normalizeManifestRepo(trimmed);
|
|
218
293
|
if (normalized)
|
|
219
294
|
claimGroups.push({ company, keys: [remoteKey(normalized)] });
|
|
@@ -168,11 +168,33 @@ function targetLookup(target) {
|
|
|
168
168
|
return code === 'ENOENT' || code === 'ENOTDIR' ? 'absent' : code ?? 'unknown error';
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Reindex keeps pack skills at `.claude/skills/<pack>:<item>`. Recreating the
|
|
173
|
+
* unprefixed table dest next to that wrapper duplicates names like `hooks`.
|
|
174
|
+
*/
|
|
175
|
+
function namespacedSkillHostExists(hqRoot, item) {
|
|
176
|
+
const dir = path.join(hqRoot, '.claude', 'skills');
|
|
177
|
+
let names;
|
|
178
|
+
try {
|
|
179
|
+
names = fs.readdirSync(dir);
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
const suffix = `:${item}`;
|
|
185
|
+
return names.some((name) => name.endsWith(suffix));
|
|
186
|
+
}
|
|
187
|
+
function ensureSymlink(link, hqRoot, info, warn) {
|
|
172
188
|
if (!existsOrSymlink(link.src)) {
|
|
173
189
|
warn(`payload missing: ${link.src} (declared but not shipped)`);
|
|
174
190
|
return;
|
|
175
191
|
}
|
|
192
|
+
if (link.key === 'skills' &&
|
|
193
|
+
path.basename(link.dst) === link.item &&
|
|
194
|
+
namespacedSkillHostExists(hqRoot, link.item)) {
|
|
195
|
+
info(`skipped ${link.dst} (namespaced skill wrapper already present)`);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
176
198
|
const relativeSrc = path.relative(path.dirname(link.dst), link.src);
|
|
177
199
|
fs.mkdirSync(path.dirname(link.dst), { recursive: true });
|
|
178
200
|
try {
|
|
@@ -372,7 +394,7 @@ export function scanPackages(hqRoot, options = {}) {
|
|
|
372
394
|
continue;
|
|
373
395
|
}
|
|
374
396
|
}
|
|
375
|
-
ensureSymlink(link, info, warn);
|
|
397
|
+
ensureSymlink(link, hqRoot, info, warn);
|
|
376
398
|
}
|
|
377
399
|
}
|
|
378
400
|
}
|