@indigoai-us/hq-cli 5.345.221 → 5.345.223
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 +70 -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/bot.d.ts +1 -1
- package/dist/commands/bot.js +34 -33
- package/dist/commands/core-delegate-w1b.js +216 -190
- 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/packs.js +13 -2
- package/dist/commands/sync-core.d.ts +6 -0
- package/dist/commands/sync-core.js +75 -1
- package/dist/data/command-states.json +3 -0
- package/dist/lib/bot/fleet-cron.d.ts +26 -3
- package/dist/lib/bot/fleet-cron.js +44 -4
- package/dist/lib/bot/run.d.ts +4 -4
- package/dist/lib/bot/run.js +5 -3
- package/dist/lib/bot/signals-engine-flag.d.ts +53 -13
- package/dist/lib/bot/signals-engine-flag.js +202 -9
- 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 +52 -1
- package/dist/lib/daemon/machine-checks.js +104 -11
- 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 +36 -0
- package/dist/lib/daemon/native-notice-ledger.js +156 -0
- package/dist/lib/daemon/run.d.ts +15 -0
- package/dist/lib/daemon/run.js +72 -3
- package/dist/lib/daemon/selfcheck.d.ts +35 -2
- package/dist/lib/daemon/selfcheck.js +118 -9
- package/dist/lib/daemon/supervisor.d.ts +10 -0
- package/dist/lib/daemon/supervisor.js +86 -0
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/flag-registry-worker.js +33 -3
- package/dist/lib/flag-registry.js +13 -0
- 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 +23 -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/signals/engine.d.ts +8 -0
- package/dist/lib/signals/engine.js +15 -5
- 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/flag.d.ts +18 -0
- package/dist/lib/sync-core/flag.js +66 -0
- package/dist/lib/sync-core/reconcile.d.ts +6 -0
- package/dist/lib/sync-core/reconcile.js +23 -0
- package/dist/lib/sync-core/rollout-state.d.ts +2 -0
- package/dist/lib/sync-core/rollout-state.js +7 -0
- package/dist/lib/sync-core/vault-settings.d.ts +32 -0
- package/dist/lib/sync-core/vault-settings.js +147 -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 +16 -1
- package/dist/utils/pack-contributions.js +139 -26
- 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
- package/scripts/bench-core.mjs +34 -3
|
@@ -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,32 @@ 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
|
+
* Only this pack's own `<pack>:<item>` counts: another pack's or a company's
|
|
175
|
+
* `*:<item>` says nothing about whether this pack's skill is reachable.
|
|
176
|
+
*/
|
|
177
|
+
function namespacedSkillHostExists(hqRoot, packName, item) {
|
|
178
|
+
try {
|
|
179
|
+
fs.lstatSync(path.join(hqRoot, '.claude', 'skills', `${packName}:${item}`));
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function ensureSymlink(link, hqRoot, packName, info, warn) {
|
|
172
187
|
if (!existsOrSymlink(link.src)) {
|
|
173
188
|
warn(`payload missing: ${link.src} (declared but not shipped)`);
|
|
174
189
|
return;
|
|
175
190
|
}
|
|
191
|
+
if (link.key === 'skills' &&
|
|
192
|
+
path.basename(link.dst) === link.item &&
|
|
193
|
+
namespacedSkillHostExists(hqRoot, packName, link.item)) {
|
|
194
|
+
info(`skipped ${link.dst} (namespaced skill wrapper already present)`);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
176
197
|
const relativeSrc = path.relative(path.dirname(link.dst), link.src);
|
|
177
198
|
fs.mkdirSync(path.dirname(link.dst), { recursive: true });
|
|
178
199
|
try {
|
|
@@ -372,7 +393,7 @@ export function scanPackages(hqRoot, options = {}) {
|
|
|
372
393
|
continue;
|
|
373
394
|
}
|
|
374
395
|
}
|
|
375
|
-
ensureSymlink(link, info, warn);
|
|
396
|
+
ensureSymlink(link, hqRoot, name, info, warn);
|
|
376
397
|
}
|
|
377
398
|
}
|
|
378
399
|
}
|
|
@@ -258,8 +258,9 @@ export function findOversizedFiles(collectionPath, mask, maxBytes, io = defaultS
|
|
|
258
258
|
const plan = parseCollectionMask(mask);
|
|
259
259
|
// Unrecognised mask: do not walk. Matching "everything" is what filled
|
|
260
260
|
// `*.md` collections rooted at $HOME with hundreds of thousands of ignores.
|
|
261
|
+
// complete:false keeps previously owned ignore entries instead of dropping them.
|
|
261
262
|
if (!plan)
|
|
262
|
-
return { oversized: [], evaluated, complete:
|
|
263
|
+
return { oversized: [], evaluated, complete: false };
|
|
263
264
|
const pruned = new Set(prunePrefixes);
|
|
264
265
|
const found = [];
|
|
265
266
|
let complete = true;
|
|
@@ -18,6 +18,7 @@ export interface LaunchdStartupMigrationDependencies {
|
|
|
18
18
|
}) => unknown;
|
|
19
19
|
markDeferred?: (home: string) => void;
|
|
20
20
|
warn?: (message: string) => void;
|
|
21
|
+
loginHome?: string;
|
|
21
22
|
}
|
|
22
23
|
/** Best-effort migration; a compatibility cleanup never blocks the requested command. */
|
|
23
24
|
export declare function runLaunchdMigrationAtStartup(options: LaunchdStartupMigrationOptions, dependencies?: LaunchdStartupMigrationDependencies): Promise<void>;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { homeIsLoginSafe } from "../mesh/live/daemon/unit-home.js";
|
|
1
2
|
/** Best-effort migration; a compatibility cleanup never blocks the requested command. */
|
|
2
3
|
export async function runLaunchdMigrationAtStartup(options, dependencies = {}) {
|
|
3
4
|
try {
|
|
5
|
+
if (!homeIsLoginSafe(options.home, dependencies.loginHome))
|
|
6
|
+
return;
|
|
4
7
|
const state = await import("./migration-state.js");
|
|
5
8
|
const shouldRun = dependencies.shouldRun ?? state.shouldRunLaunchdMigration;
|
|
6
9
|
if (!await shouldRun(options.home))
|
|
@@ -220,6 +220,14 @@ export declare function summaryRel(date: string): string;
|
|
|
220
220
|
export declare function listCompanies(hqRoot: string): string[];
|
|
221
221
|
/** Reads one knowledge preference. Throws SignalsConfigError when the script is missing or fails. */
|
|
222
222
|
export declare function readPref(hqRoot: string, company: string, field: string, spawn: SpawnSyncFn): boolean;
|
|
223
|
+
/**
|
|
224
|
+
* The prefs-off rule: whether a run skips `company` because signals_capture and
|
|
225
|
+
* ontology_capture are both off on this computer. `runSignals` decides its
|
|
226
|
+
* `prefs-off` skip with this, and the bot's hot-signal-sync job asks it before
|
|
227
|
+
* choosing the engine (lib/bot/signals-engine-flag.ts), so the two cannot
|
|
228
|
+
* disagree. Throws SignalsConfigError when the settings cannot be read.
|
|
229
|
+
*/
|
|
230
|
+
export declare function capturePrefsOff(hqRoot: string, company: string, spawn?: SpawnSyncFn): boolean;
|
|
223
231
|
/** Coarse v2 kind for a step's detailed kind. */
|
|
224
232
|
export declare function toRunErrorKind(kind: ErrorKind | undefined): RunErrorKind;
|
|
225
233
|
/** Fills the v2 outcome fields of a finished record from its steps. */
|
|
@@ -167,6 +167,18 @@ export function readPref(hqRoot, company, field, spawn) {
|
|
|
167
167
|
}
|
|
168
168
|
return TRUE_VALUES.has(r.stdout.trim().toLowerCase());
|
|
169
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* The prefs-off rule: whether a run skips `company` because signals_capture and
|
|
172
|
+
* ontology_capture are both off on this computer. `runSignals` decides its
|
|
173
|
+
* `prefs-off` skip with this, and the bot's hot-signal-sync job asks it before
|
|
174
|
+
* choosing the engine (lib/bot/signals-engine-flag.ts), so the two cannot
|
|
175
|
+
* disagree. Throws SignalsConfigError when the settings cannot be read.
|
|
176
|
+
*/
|
|
177
|
+
export function capturePrefsOff(hqRoot, company, spawn = defaultSpawn) {
|
|
178
|
+
const signalsOn = readPref(hqRoot, company, "signals_capture", spawn);
|
|
179
|
+
const ontologyOn = readPref(hqRoot, company, "ontology_capture", spawn);
|
|
180
|
+
return !signalsOn && !ontologyOn;
|
|
181
|
+
}
|
|
170
182
|
function readJson(hqRoot, rel) {
|
|
171
183
|
const abs = path.join(hqRoot, rel);
|
|
172
184
|
if (!fs.existsSync(abs))
|
|
@@ -452,11 +464,9 @@ export async function runSignals(opts) {
|
|
|
452
464
|
record.jobRanAt = priorJobRanAt;
|
|
453
465
|
// 3. Mark the run as running before any step.
|
|
454
466
|
persist();
|
|
455
|
-
let
|
|
456
|
-
let ontologyOn;
|
|
467
|
+
let prefsOff;
|
|
457
468
|
try {
|
|
458
|
-
|
|
459
|
-
ontologyOn = readPref(hqRoot, company, "ontology_capture", spawn);
|
|
469
|
+
prefsOff = capturePrefsOff(hqRoot, company, spawn);
|
|
460
470
|
}
|
|
461
471
|
catch (err) {
|
|
462
472
|
if (!(err instanceof SignalsConfigError))
|
|
@@ -475,7 +485,7 @@ export async function runSignals(opts) {
|
|
|
475
485
|
records.push(record);
|
|
476
486
|
continue;
|
|
477
487
|
}
|
|
478
|
-
if (
|
|
488
|
+
if (prefsOff) {
|
|
479
489
|
record.skipReason = "prefs-off";
|
|
480
490
|
finish();
|
|
481
491
|
records.push(record);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const HELD_DELETE_LOG_LIMIT = 20;
|
|
2
|
+
export interface EngineHeldDelete {
|
|
3
|
+
path: string;
|
|
4
|
+
direction: "delete_local" | "delete_remote";
|
|
5
|
+
}
|
|
6
|
+
export interface EngineHeldDeletes {
|
|
7
|
+
holdId?: string;
|
|
8
|
+
count: number;
|
|
9
|
+
deletes: EngineHeldDelete[];
|
|
10
|
+
}
|
|
11
|
+
export declare function engineHoldFile(engineHome: string, vaultUid: string): string;
|
|
12
|
+
export declare function readEngineHeldDeletes(engineHome: string, vaultUid: string): EngineHeldDeletes | "unreadable" | null;
|
|
13
|
+
export declare function heldDeletesHandoverLine(vaultUid: string, held: EngineHeldDeletes | "unreadable", engineHome: string): string;
|
|
14
|
+
//# sourceMappingURL=engine-holds.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
export const HELD_DELETE_LOG_LIMIT = 20;
|
|
4
|
+
const HOLD_FILE_MAX_BYTES = 16 * 1024 * 1024;
|
|
5
|
+
function record(value) {
|
|
6
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
7
|
+
}
|
|
8
|
+
export function engineHoldFile(engineHome, vaultUid) {
|
|
9
|
+
return path.join(engineHome, ".hq", "sync-core", "holds", `${vaultUid}.json`);
|
|
10
|
+
}
|
|
11
|
+
export function readEngineHeldDeletes(engineHome, vaultUid) {
|
|
12
|
+
let text;
|
|
13
|
+
try {
|
|
14
|
+
const file = engineHoldFile(engineHome, vaultUid);
|
|
15
|
+
const stat = fs.lstatSync(file);
|
|
16
|
+
if (!stat.isFile() || stat.size > HOLD_FILE_MAX_BYTES)
|
|
17
|
+
return "unreadable";
|
|
18
|
+
text = fs.readFileSync(file, "utf8");
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
return error.code === "ENOENT" ? null : "unreadable";
|
|
22
|
+
}
|
|
23
|
+
let hold;
|
|
24
|
+
try {
|
|
25
|
+
hold = record(JSON.parse(text));
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return "unreadable";
|
|
29
|
+
}
|
|
30
|
+
if (!hold || !Array.isArray(hold.groups))
|
|
31
|
+
return "unreadable";
|
|
32
|
+
const deletes = [];
|
|
33
|
+
let count = 0;
|
|
34
|
+
for (const value of hold.groups) {
|
|
35
|
+
const group = record(value);
|
|
36
|
+
if (!group || (group.direction !== "delete_local" && group.direction !== "delete_remote"))
|
|
37
|
+
return "unreadable";
|
|
38
|
+
const paths = Array.isArray(group.paths) ? group.paths.filter((p) => typeof p === "string") : [];
|
|
39
|
+
const declared = typeof group.count === "number" && Number.isSafeInteger(group.count) && group.count >= 0 ? group.count : 0;
|
|
40
|
+
count += Math.max(paths.length, declared);
|
|
41
|
+
for (const p of paths)
|
|
42
|
+
deletes.push({ path: p, direction: group.direction });
|
|
43
|
+
}
|
|
44
|
+
if (count === 0)
|
|
45
|
+
return null;
|
|
46
|
+
return { ...(typeof hold.holdId === "string" && hold.holdId ? { holdId: hold.holdId } : {}), count, deletes };
|
|
47
|
+
}
|
|
48
|
+
function printable(value) {
|
|
49
|
+
return JSON.stringify(value);
|
|
50
|
+
}
|
|
51
|
+
export function heldDeletesHandoverLine(vaultUid, held, engineHome) {
|
|
52
|
+
if (held === "unreadable") {
|
|
53
|
+
return `${vaultUid}: the new sync engine's hold file ${engineHoldFile(engineHome, vaultUid)} could not be read; any deletes it held are now up to the current sync`;
|
|
54
|
+
}
|
|
55
|
+
const shown = held.deletes.slice(0, HELD_DELETE_LOG_LIMIT).map((entry) => `${entry.direction === "delete_local" ? "local copy of" : "server copy of"} ${printable(entry.path)}`);
|
|
56
|
+
const more = held.count > shown.length ? `; and ${held.count - shown.length} more` : "";
|
|
57
|
+
const id = held.holdId ? ` (hold ${/^[A-Za-z0-9_-]{1,64}$/.test(held.holdId) ? held.holdId : printable(held.holdId)})` : "";
|
|
58
|
+
return `${vaultUid}: switching back with ${held.count} delete${held.count === 1 ? "" : "s"} the new sync engine held${id}; the current sync will apply them: ${shown.join(", ")}${more}`;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=engine-holds.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SyncCoreVaultSettings } from "./vault-settings.js";
|
|
1
2
|
export type SyncCoreVaultKind = "personal" | "company";
|
|
2
3
|
export type SyncCoreVaultPhase = "warming" | "full";
|
|
3
4
|
export interface SyncCoreVault {
|
|
@@ -12,6 +13,7 @@ export interface SyncCoreVaultPlan extends SyncCoreVault {
|
|
|
12
13
|
release: string;
|
|
13
14
|
legacyOffSince?: string;
|
|
14
15
|
blockedReason?: string;
|
|
16
|
+
settings?: SyncCoreVaultSettings;
|
|
15
17
|
}
|
|
16
18
|
export declare const SYNC_CORE_REQUESTS_PER_DAY = 20000;
|
|
17
19
|
export declare const SYNC_CORE_REQUEST_COUNT_REMOVED_IN = "v0.1.29";
|
|
@@ -14,4 +14,22 @@ export interface ReadCompanyRolloutFlagOptions {
|
|
|
14
14
|
export declare class RolloutFlagReadError extends Error {
|
|
15
15
|
}
|
|
16
16
|
export declare function readCompanyRolloutFlag(companyUid: string, token: string, options?: ReadCompanyRolloutFlagOptions): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Company-wide parallel downloads for the new sync engine. Registry flags are
|
|
19
|
+
* booleans, so two keys form a ladder: `sync.parallel-downloads` alone means
|
|
20
|
+
* 8 streams, `sync.parallel-downloads-16` means 16 and wins over the first.
|
|
21
|
+
* Neither on means no company value (the engine default, off).
|
|
22
|
+
*/
|
|
23
|
+
export declare const SYNC_PARALLEL_DOWNLOADS_FLAG = "sync.parallel-downloads";
|
|
24
|
+
export declare const SYNC_PARALLEL_DOWNLOADS_16_FLAG = "sync.parallel-downloads-16";
|
|
25
|
+
export declare const SYNC_PARALLEL_DOWNLOADS_FLAG_STREAMS = 8;
|
|
26
|
+
export declare const SYNC_PARALLEL_DOWNLOADS_16_FLAG_STREAMS = 16;
|
|
27
|
+
export declare class DownloadStreamsFlagReadError extends Error {
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The company's download stream count from the flag registry, or undefined when
|
|
31
|
+
* neither key is on. Throws DownloadStreamsFlagReadError when the registry
|
|
32
|
+
* cannot be read, so the caller can keep the value it had.
|
|
33
|
+
*/
|
|
34
|
+
export declare function readCompanyDownloadStreams(companyUid: string, token: string, options?: ReadCompanyRolloutFlagOptions): Promise<number | undefined>;
|
|
17
35
|
//# sourceMappingURL=flag.d.ts.map
|