@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.
Files changed (87) hide show
  1. package/CHANGELOG.md +70 -1
  2. package/dist/command-catalog.generated.d.ts +31 -0
  3. package/dist/command-catalog.generated.js +38 -0
  4. package/dist/commands/auth.js +2 -1
  5. package/dist/commands/bot.d.ts +1 -1
  6. package/dist/commands/bot.js +34 -33
  7. package/dist/commands/core-delegate-w1b.js +216 -190
  8. package/dist/commands/daemon.d.ts +1 -0
  9. package/dist/commands/daemon.js +15 -1
  10. package/dist/commands/link.d.ts +2 -0
  11. package/dist/commands/link.js +14 -2
  12. package/dist/commands/mesh.js +23 -3
  13. package/dist/commands/packs.js +13 -2
  14. package/dist/commands/sync-core.d.ts +6 -0
  15. package/dist/commands/sync-core.js +75 -1
  16. package/dist/data/command-states.json +3 -0
  17. package/dist/lib/bot/fleet-cron.d.ts +26 -3
  18. package/dist/lib/bot/fleet-cron.js +44 -4
  19. package/dist/lib/bot/run.d.ts +4 -4
  20. package/dist/lib/bot/run.js +5 -3
  21. package/dist/lib/bot/signals-engine-flag.d.ts +53 -13
  22. package/dist/lib/bot/signals-engine-flag.js +202 -9
  23. package/dist/lib/daemon/catalog.js +2 -0
  24. package/dist/lib/daemon/install.d.ts +2 -1
  25. package/dist/lib/daemon/install.js +9 -0
  26. package/dist/lib/daemon/legacy.d.ts +1 -0
  27. package/dist/lib/daemon/legacy.js +5 -2
  28. package/dist/lib/daemon/machine-check-owner.d.ts +2 -0
  29. package/dist/lib/daemon/machine-check-owner.js +6 -1
  30. package/dist/lib/daemon/machine-checks.d.ts +52 -1
  31. package/dist/lib/daemon/machine-checks.js +104 -11
  32. package/dist/lib/daemon/mesh-owner.d.ts +45 -0
  33. package/dist/lib/daemon/mesh-owner.js +166 -0
  34. package/dist/lib/daemon/native-notice-ledger.d.ts +36 -0
  35. package/dist/lib/daemon/native-notice-ledger.js +156 -0
  36. package/dist/lib/daemon/run.d.ts +15 -0
  37. package/dist/lib/daemon/run.js +72 -3
  38. package/dist/lib/daemon/selfcheck.d.ts +35 -2
  39. package/dist/lib/daemon/selfcheck.js +118 -9
  40. package/dist/lib/daemon/supervisor.d.ts +10 -0
  41. package/dist/lib/daemon/supervisor.js +86 -0
  42. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  43. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  44. package/dist/lib/flag-registry-worker.js +33 -3
  45. package/dist/lib/flag-registry.js +13 -0
  46. package/dist/lib/hook-engine/coverage.d.ts +9 -0
  47. package/dist/lib/hook-engine/coverage.js +56 -0
  48. package/dist/lib/hook-engine/native-stop-compatibility.json +56 -5
  49. package/dist/lib/mesh/live/daemon/config.d.ts +8 -1
  50. package/dist/lib/mesh/live/daemon/config.js +16 -0
  51. package/dist/lib/mesh/live/daemon/install.d.ts +31 -2
  52. package/dist/lib/mesh/live/daemon/install.js +142 -1
  53. package/dist/lib/mesh/live/daemon/login-home.d.ts +5 -0
  54. package/dist/lib/mesh/live/daemon/login-home.js +27 -0
  55. package/dist/lib/mesh/live/daemon/unit-home.d.ts +49 -0
  56. package/dist/lib/mesh/live/daemon/unit-home.js +134 -0
  57. package/dist/lib/registry/registry.d.ts +35 -7
  58. package/dist/lib/registry/registry.js +88 -13
  59. package/dist/lib/scan-packages/index.js +23 -2
  60. package/dist/lib/search-index/max-doc-bytes.js +2 -1
  61. package/dist/lib/service-manager/startup-migration.d.ts +1 -0
  62. package/dist/lib/service-manager/startup-migration.js +3 -0
  63. package/dist/lib/signals/engine.d.ts +8 -0
  64. package/dist/lib/signals/engine.js +15 -5
  65. package/dist/lib/sync-core/engine-holds.d.ts +14 -0
  66. package/dist/lib/sync-core/engine-holds.js +60 -0
  67. package/dist/lib/sync-core/engine-home.d.ts +2 -0
  68. package/dist/lib/sync-core/flag.d.ts +18 -0
  69. package/dist/lib/sync-core/flag.js +66 -0
  70. package/dist/lib/sync-core/reconcile.d.ts +6 -0
  71. package/dist/lib/sync-core/reconcile.js +23 -0
  72. package/dist/lib/sync-core/rollout-state.d.ts +2 -0
  73. package/dist/lib/sync-core/rollout-state.js +7 -0
  74. package/dist/lib/sync-core/vault-settings.d.ts +32 -0
  75. package/dist/lib/sync-core/vault-settings.js +147 -0
  76. package/dist/lib/windows/install-followup.d.ts +2 -0
  77. package/dist/lib/windows/install-followup.js +4 -1
  78. package/dist/utils/host-registration.js +3 -1
  79. package/dist/utils/pack-contributions.d.ts +16 -1
  80. package/dist/utils/pack-contributions.js +139 -26
  81. package/dist/utils/self-update.d.ts +3 -1
  82. package/dist/utils/self-update.js +56 -11
  83. package/dist/utils/update-lock.d.ts +151 -14
  84. package/dist/utils/update-lock.js +782 -46
  85. package/dist/utils/version-gate.js +12 -2
  86. package/package.json +7 -7
  87. package/scripts/bench-core.mjs +34 -3
@@ -44,4 +44,70 @@ export async function readCompanyRolloutFlag(companyUid, token, options = {}) {
44
44
  }
45
45
  }
46
46
  }
47
+ /**
48
+ * Company-wide parallel downloads for the new sync engine. Registry flags are
49
+ * booleans, so two keys form a ladder: `sync.parallel-downloads` alone means
50
+ * 8 streams, `sync.parallel-downloads-16` means 16 and wins over the first.
51
+ * Neither on means no company value (the engine default, off).
52
+ */
53
+ export const SYNC_PARALLEL_DOWNLOADS_FLAG = "sync.parallel-downloads";
54
+ export const SYNC_PARALLEL_DOWNLOADS_16_FLAG = "sync.parallel-downloads-16";
55
+ export const SYNC_PARALLEL_DOWNLOADS_FLAG_STREAMS = 8;
56
+ export const SYNC_PARALLEL_DOWNLOADS_16_FLAG_STREAMS = 16;
57
+ export class DownloadStreamsFlagReadError extends Error {
58
+ }
59
+ /**
60
+ * The company's download stream count from the flag registry, or undefined when
61
+ * neither key is on. Throws DownloadStreamsFlagReadError when the registry
62
+ * cannot be read, so the caller can keep the value it had.
63
+ */
64
+ export async function readCompanyDownloadStreams(companyUid, token, options = {}) {
65
+ const env = options.env ?? process.env;
66
+ const override16 = readLocalOverride(SYNC_PARALLEL_DOWNLOADS_16_FLAG, env);
67
+ const override8 = readLocalOverride(SYNC_PARALLEL_DOWNLOADS_FLAG, env);
68
+ const fromValues = (on16, on8) => on16 ? SYNC_PARALLEL_DOWNLOADS_16_FLAG_STREAMS : on8 ? SYNC_PARALLEL_DOWNLOADS_FLAG_STREAMS : undefined;
69
+ if (override16 !== null && override8 !== null)
70
+ return fromValues(override16, override8);
71
+ let failure;
72
+ const onError = (error) => {
73
+ failure ??= error;
74
+ };
75
+ const fail = (error) => new DownloadStreamsFlagReadError(`could not read ${SYNC_PARALLEL_DOWNLOADS_FLAG} for ${companyUid}: ${error instanceof Error ? error.message : String(error)}`);
76
+ const client = (options.createClient ?? createFlagClient)({
77
+ endpoint: resolveFlagRegistryEndpoint(undefined, env),
78
+ getToken: () => token,
79
+ env: {},
80
+ refreshIntervalMs: 0,
81
+ requestTimeoutMs: READ_TIMEOUT_MS,
82
+ companyUid,
83
+ onError,
84
+ });
85
+ try {
86
+ await client.ready();
87
+ const on = (key, override) => {
88
+ if (override !== null)
89
+ return override;
90
+ const resolution = client.explain(key, { fallback: false });
91
+ return resolution.source === "snapshot" && resolution.value === true;
92
+ };
93
+ const on16 = on(SYNC_PARALLEL_DOWNLOADS_16_FLAG, override16);
94
+ const on8 = on(SYNC_PARALLEL_DOWNLOADS_FLAG, override8);
95
+ if (failure !== undefined)
96
+ throw fail(failure);
97
+ return fromValues(on16, on8);
98
+ }
99
+ catch (error) {
100
+ if (error instanceof DownloadStreamsFlagReadError)
101
+ throw error;
102
+ throw fail(error);
103
+ }
104
+ finally {
105
+ try {
106
+ client.close();
107
+ }
108
+ catch {
109
+ failure ??= undefined;
110
+ }
111
+ }
112
+ }
47
113
  //# sourceMappingURL=flag.js.map
@@ -13,6 +13,12 @@ export interface SyncCoreReconcileDeps {
13
13
  listMemberships: () => Promise<SyncCoreMembership[]>;
14
14
  resolvePersonUid: () => Promise<string | null>;
15
15
  readRolloutFlag: (companyUid: string) => Promise<boolean>;
16
+ /**
17
+ * The company's parallel download stream count from the flag registry, or
18
+ * undefined when the company has none. Throws when the registry cannot be
19
+ * read; the vault then keeps the value it had. Omitted: no company value.
20
+ */
21
+ readDownloadStreams?: (companyUid: string) => Promise<number | undefined>;
16
22
  ensureBinary: (release: string) => Promise<SyncCoreBinaryInstall>;
17
23
  /** A fixed release (tests). Otherwise readPin decides, then SYNC_CORE_RELEASE. */
18
24
  release?: string;
@@ -5,6 +5,7 @@ import { readVaultSyncSwitches, writeVaultSyncSwitches } from "../vault-sync-swi
5
5
  import { clearEngineStatus, engineFirstCycle, isSyncCoreVaultUid, removeEngineOwnership, syncCoreEngineHome, writeEngineHome, } from "./engine-home.js";
6
6
  import { SYNC_CORE_FULL_RELEASE, SYNC_CORE_RELEASE, compareSyncCoreReleases, fullModeAllowed, installedSyncCoreRelease, syncCoreBinaryPath, windowsFullRelease, } from "./release.js";
7
7
  import { readSyncCoreSkips } from "./skip.js";
8
+ import { heldDeletesHandoverLine, readEngineHeldDeletes } from "./engine-holds.js";
8
9
  import { SYNC_RUST_ENGINE_ROLLOUT_FLAG } from "./flag.js";
9
10
  import { readSyncCoreRolloutState, syncCoreRolloutStatePath, writeSyncCoreRolloutState, } from "./rollout-state.js";
10
11
  function message(error) {
@@ -186,6 +187,20 @@ export async function reconcileSyncCore(deps) {
186
187
  : switchesBefore.offCompanies.has(vault.slug ?? "");
187
188
  const legacyAlreadyOff = wasFull ? before.legacyAlreadyOff === true : alreadyOff;
188
189
  const legacyOffSince = (wasFull && alreadyOff ? before.legacyOffSince : undefined) ?? at;
190
+ let downloadStreams;
191
+ if (vault.kind === "company" && deps.readDownloadStreams) {
192
+ try {
193
+ downloadStreams = await deps.readDownloadStreams(vault.uid);
194
+ }
195
+ catch (error) {
196
+ downloadStreams = before?.downloadStreams;
197
+ const keptValue = downloadStreams === undefined ? "no company download streams" : `${downloadStreams} download streams`;
198
+ warnings.push(`${message(error)}; keeping ${vault.slug ?? vault.uid} at ${keptValue}`);
199
+ }
200
+ if (downloadStreams !== before?.downloadStreams) {
201
+ log(`${vault.uid}: company download streams ${before?.downloadStreams ?? "none"} -> ${downloadStreams ?? "none"}`);
202
+ }
203
+ }
189
204
  const recorded = wasFull ? before.firstCycle : undefined;
190
205
  const firstCycle = recorded && recorded.planned > 0
191
206
  ? recorded
@@ -199,6 +214,7 @@ export async function reconcileSyncCore(deps) {
199
214
  legacyOffSince,
200
215
  ...(legacyAlreadyOff ? { legacyAlreadyOff: true } : {}),
201
216
  ...(firstCycle ? { firstCycle } : {}),
217
+ ...(downloadStreams !== undefined ? { downloadStreams } : {}),
202
218
  });
203
219
  if (firstCycle && firstCycle !== recorded && (!recorded || firstCycle.planned > 0))
204
220
  log(`${vault.uid}: first full cycle ${firstCycle.at}: ${firstCycle.planned} planned, ${firstCycle.completed} completed, ${firstCycle.held} held`);
@@ -214,6 +230,7 @@ export async function reconcileSyncCore(deps) {
214
230
  kept.push(vault.uid);
215
231
  }
216
232
  const stopped = [];
233
+ const handover = [];
217
234
  let personalBackOn = false;
218
235
  for (const vault of previousByUid.values()) {
219
236
  if (desired.some((candidate) => candidate.uid === vault.uid))
@@ -221,6 +238,10 @@ export async function reconcileSyncCore(deps) {
221
238
  stopped.push(vault.uid);
222
239
  if (vault.phase !== "full")
223
240
  continue;
241
+ const engineHome = syncCoreEngineHome(deps.home, vault.uid);
242
+ const heldDeletes = readEngineHeldDeletes(engineHome, vault.uid);
243
+ if (heldDeletes)
244
+ handover.push(heldDeletesHandoverLine(vault.uid, heldDeletes, engineHome));
224
245
  if (vault.kind === "company" && vault.slug)
225
246
  companies[vault.slug] = true;
226
247
  else
@@ -259,6 +280,8 @@ export async function reconcileSyncCore(deps) {
259
280
  log(`${uid}: moving from the read-only index to full mode on the new sync engine`);
260
281
  for (const uid of stopped)
261
282
  log(`${uid}: back on the current sync`);
283
+ for (const line of handover)
284
+ log(line);
262
285
  for (const skip of skipped)
263
286
  log(`${skip.uid}: skipped on this machine: ${skip.reason}`);
264
287
  for (const hold of held)
@@ -8,6 +8,8 @@ export interface RolloutVault {
8
8
  legacyOffSince?: string;
9
9
  legacyAlreadyOff?: true;
10
10
  firstCycle?: SyncCoreFirstCycle;
11
+ /** Download streams from the company flag (sync.parallel-downloads[-16]); absent means no company value. */
12
+ downloadStreams?: number;
11
13
  }
12
14
  export interface SyncCoreRolloutState {
13
15
  version: 1;
@@ -1,6 +1,7 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as path from "node:path";
3
3
  import { isSyncCoreVaultUid } from "./vault-uid.js";
4
+ import { SYNC_CORE_DOWNLOAD_STREAMS_MAX } from "./vault-settings.js";
4
5
  const FIRST_CYCLE_COUNTS = [
5
6
  "planned",
6
7
  "completed",
@@ -63,6 +64,11 @@ function vault(value) {
63
64
  const cycle = v.firstCycle === undefined ? undefined : firstCycle(v.firstCycle);
64
65
  if (cycle === null)
65
66
  return null;
67
+ // An invalid company value is dropped rather than failing the whole state.
68
+ const streams = typeof v.downloadStreams === "number" && Number.isInteger(v.downloadStreams)
69
+ && v.downloadStreams >= 1 && v.downloadStreams <= SYNC_CORE_DOWNLOAD_STREAMS_MAX
70
+ ? v.downloadStreams
71
+ : undefined;
66
72
  return {
67
73
  uid: v.uid,
68
74
  kind: v.kind,
@@ -72,6 +78,7 @@ function vault(value) {
72
78
  ...(typeof v.legacyOffSince === "string" ? { legacyOffSince: v.legacyOffSince } : {}),
73
79
  ...(v.legacyAlreadyOff === true ? { legacyAlreadyOff: true } : {}),
74
80
  ...(cycle ? { firstCycle: cycle } : {}),
81
+ ...(streams !== undefined ? { downloadStreams: streams } : {}),
75
82
  };
76
83
  }
77
84
  export function readSyncCoreRolloutState(home) {
@@ -0,0 +1,32 @@
1
+ /**
2
+ * One computer's setting for one vault. `parallelDownloads: false` is an
3
+ * explicit off on this computer, which outranks the company flag; no entry at
4
+ * all follows the company (see effectiveEngineSettings).
5
+ */
6
+ export interface SyncCoreVaultSettings {
7
+ parallelDownloads?: boolean;
8
+ downloadStreams?: number;
9
+ }
10
+ export declare const SYNC_CORE_DOWNLOAD_STREAMS_MAX = 32;
11
+ export declare const SYNC_CORE_VAULT_SETTING_KEYS: readonly ["parallel-downloads", "download-streams"];
12
+ export type SyncCoreVaultSettingKey = (typeof SYNC_CORE_VAULT_SETTING_KEYS)[number];
13
+ export declare class SyncCoreVaultSettingError extends Error {
14
+ }
15
+ export declare function syncCoreVaultSettingsPath(home: string): string;
16
+ export declare function readSyncCoreVaultSettings(home: string, opts?: {
17
+ strict?: boolean;
18
+ }): Map<string, SyncCoreVaultSettings>;
19
+ export declare function parseSyncCoreVaultSetting(key: string, value: string): {
20
+ parallelDownloads: boolean | undefined;
21
+ } | {
22
+ downloadStreams: number | undefined;
23
+ };
24
+ export declare function setSyncCoreVaultSetting(home: string, vaultUid: string, key: string, value: string): SyncCoreVaultSettings | undefined;
25
+ /**
26
+ * What one vault's engine runs with: this computer's setting when it has one
27
+ * (on or an explicit off), otherwise the company's stream count from the flag
28
+ * registry, otherwise nothing (the engine default, off).
29
+ */
30
+ export declare function effectiveEngineSettings(local: SyncCoreVaultSettings | undefined, companyStreams: number | undefined): SyncCoreVaultSettings | undefined;
31
+ export declare function engineSettingsEnv(settings: SyncCoreVaultSettings | undefined): Record<string, string>;
32
+ //# sourceMappingURL=vault-settings.d.ts.map
@@ -0,0 +1,147 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ export const SYNC_CORE_DOWNLOAD_STREAMS_MAX = 32;
4
+ export const SYNC_CORE_VAULT_SETTING_KEYS = ["parallel-downloads", "download-streams"];
5
+ export class SyncCoreVaultSettingError extends Error {
6
+ }
7
+ export function syncCoreVaultSettingsPath(home) {
8
+ return path.join(home, ".hq", "sync-core", "vault-settings.json");
9
+ }
10
+ function validStreams(value) {
11
+ return typeof value === "number" && Number.isInteger(value) && value >= 1 && value <= SYNC_CORE_DOWNLOAD_STREAMS_MAX;
12
+ }
13
+ function cleanSettings(raw) {
14
+ if (!raw || typeof raw !== "object" || Array.isArray(raw))
15
+ return undefined;
16
+ const record = raw;
17
+ const settings = {};
18
+ if (record.parallel_downloads === false)
19
+ return { parallelDownloads: false };
20
+ if (record.parallel_downloads !== true)
21
+ return undefined;
22
+ settings.parallelDownloads = true;
23
+ if (validStreams(record.download_streams))
24
+ settings.downloadStreams = record.download_streams;
25
+ return Object.keys(settings).length > 0 ? settings : undefined;
26
+ }
27
+ function readRaw(home, strict) {
28
+ const file = syncCoreVaultSettingsPath(home);
29
+ let text;
30
+ try {
31
+ text = fs.readFileSync(file, "utf8");
32
+ }
33
+ catch (error) {
34
+ if (!strict || error.code === "ENOENT")
35
+ return undefined;
36
+ throw new SyncCoreVaultSettingError(`Cannot read ${file}: ${error instanceof Error ? error.message : String(error)}`);
37
+ }
38
+ try {
39
+ return JSON.parse(text);
40
+ }
41
+ catch {
42
+ if (!strict)
43
+ return undefined;
44
+ throw new SyncCoreVaultSettingError(`${file} is not valid JSON. Fix or remove it, then run the command again.`);
45
+ }
46
+ }
47
+ export function readSyncCoreVaultSettings(home, opts = {}) {
48
+ const settings = new Map();
49
+ const raw = readRaw(home, opts.strict === true);
50
+ const vaults = raw && typeof raw === "object" && !Array.isArray(raw) ? raw.vaults : undefined;
51
+ if (!vaults || typeof vaults !== "object" || Array.isArray(vaults))
52
+ return settings;
53
+ for (const [uid, value] of Object.entries(vaults)) {
54
+ const clean = cleanSettings(value);
55
+ if (clean)
56
+ settings.set(uid, clean);
57
+ }
58
+ return settings;
59
+ }
60
+ function writeAll(home, all) {
61
+ const file = syncCoreVaultSettingsPath(home);
62
+ if (all.size === 0) {
63
+ fs.rmSync(file, { force: true });
64
+ return;
65
+ }
66
+ const vaults = {};
67
+ for (const [uid, settings] of [...all.entries()].sort(([a], [b]) => a.localeCompare(b))) {
68
+ vaults[uid] = {
69
+ parallel_downloads: settings.parallelDownloads === true,
70
+ ...(settings.downloadStreams !== undefined ? { download_streams: settings.downloadStreams } : {}),
71
+ };
72
+ }
73
+ fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
74
+ const tmp = `${file}.${process.pid}.tmp`;
75
+ fs.writeFileSync(tmp, `${JSON.stringify({ version: 1, vaults }, null, 2)}\n`, { mode: 0o600 });
76
+ fs.renameSync(tmp, file);
77
+ }
78
+ export function parseSyncCoreVaultSetting(key, value) {
79
+ if (key === "parallel-downloads") {
80
+ if (value === "on")
81
+ return { parallelDownloads: true };
82
+ if (value === "off")
83
+ return { parallelDownloads: false };
84
+ if (value === "default")
85
+ return { parallelDownloads: undefined };
86
+ throw new SyncCoreVaultSettingError(`parallel-downloads takes on or off, or default to follow the company setting, not ${JSON.stringify(value)}`);
87
+ }
88
+ if (key === "download-streams") {
89
+ if (value === "default")
90
+ return { downloadStreams: undefined };
91
+ const streams = /^\d+$/.test(value) ? Number(value) : Number.NaN;
92
+ if (!validStreams(streams)) {
93
+ throw new SyncCoreVaultSettingError(`download-streams takes a whole number from 1 to ${SYNC_CORE_DOWNLOAD_STREAMS_MAX}, or default, not ${JSON.stringify(value)}`);
94
+ }
95
+ return { downloadStreams: streams };
96
+ }
97
+ throw new SyncCoreVaultSettingError(`Unknown setting ${JSON.stringify(key)}. Settings: ${SYNC_CORE_VAULT_SETTING_KEYS.join(", ")}`);
98
+ }
99
+ export function setSyncCoreVaultSetting(home, vaultUid, key, value) {
100
+ const change = parseSyncCoreVaultSetting(key, value);
101
+ const all = readSyncCoreVaultSettings(home, { strict: true });
102
+ let next = { ...all.get(vaultUid) };
103
+ if ("parallelDownloads" in change) {
104
+ if (change.parallelDownloads === undefined)
105
+ next = {};
106
+ else
107
+ next.parallelDownloads = change.parallelDownloads;
108
+ }
109
+ else if (change.downloadStreams === undefined) {
110
+ delete next.downloadStreams;
111
+ }
112
+ else if (!next.parallelDownloads) {
113
+ throw new SyncCoreVaultSettingError("Turn parallel-downloads on for this vault before setting download-streams");
114
+ }
115
+ else {
116
+ next.downloadStreams = change.downloadStreams;
117
+ }
118
+ if (!next.parallelDownloads)
119
+ delete next.downloadStreams;
120
+ if (next.parallelDownloads === undefined)
121
+ all.delete(vaultUid);
122
+ else
123
+ all.set(vaultUid, next);
124
+ writeAll(home, all);
125
+ return all.get(vaultUid);
126
+ }
127
+ /**
128
+ * What one vault's engine runs with: this computer's setting when it has one
129
+ * (on or an explicit off), otherwise the company's stream count from the flag
130
+ * registry, otherwise nothing (the engine default, off).
131
+ */
132
+ export function effectiveEngineSettings(local, companyStreams) {
133
+ if (local?.parallelDownloads !== undefined)
134
+ return local;
135
+ if (companyStreams === undefined)
136
+ return undefined;
137
+ return { parallelDownloads: true, downloadStreams: companyStreams };
138
+ }
139
+ export function engineSettingsEnv(settings) {
140
+ if (!settings?.parallelDownloads)
141
+ return {};
142
+ return {
143
+ HQ_SYNC_PARALLEL_DOWNLOADS: "1",
144
+ ...(settings.downloadStreams !== undefined ? { HQ_SYNC_DOWNLOAD_STREAMS: String(settings.downloadStreams) } : {}),
145
+ };
146
+ }
147
+ //# sourceMappingURL=vault-settings.js.map
@@ -26,6 +26,8 @@ export interface InstallFollowupDeps {
26
26
  ensurePath?: () => void;
27
27
  /** True when the daemon install succeeded. */
28
28
  spawnMesh?: () => boolean;
29
+ platform?: NodeJS.Platform;
30
+ loginHome?: string;
29
31
  version?: string;
30
32
  readMarker?: () => InstallFollowupMarker;
31
33
  writeMarker?: (marker: InstallFollowupMarker) => void;
@@ -12,6 +12,7 @@ import os from "node:os";
12
12
  import path from "node:path";
13
13
  import { fileURLToPath } from "node:url";
14
14
  import { ensureShimOnUserPath, npmShimDir } from "./user-path.js";
15
+ import { homeIsLoginSafe } from "../mesh/live/daemon/login-home.js";
15
16
  const MARKER_NAME = "install-followup.json";
16
17
  export function isInstallFollowupSkipped(argv, env) {
17
18
  if (env.HQ_INSTALL_FOLLOWUP === "1" || env.HQ_STAGED_INSTALL === "1")
@@ -73,7 +74,7 @@ function defaultSpawnMesh(argv, env) {
73
74
  return false;
74
75
  const result = spawnSync(process.execPath, [entry, "mesh", "daemon", "install", "--if-stale"], {
75
76
  env: { ...env, HQ_INSTALL_FOLLOWUP: "1" },
76
- timeout: 30_000,
77
+ timeout: 90_000,
77
78
  windowsHide: true,
78
79
  stdio: "ignore",
79
80
  });
@@ -122,6 +123,8 @@ export function runWindowsInstallFollowup(deps) {
122
123
  const mesh = read();
123
124
  if (mesh.version === version)
124
125
  return;
126
+ if ((deps.platform ?? process.platform) === "darwin" && !homeIsLoginSafe(env.HOME || os.homedir(), deps.loginHome))
127
+ return;
125
128
  const now = (deps.now ?? Date.now)();
126
129
  if (mesh.meshFailedVersion === version && mesh.meshFailedAt !== undefined && now - mesh.meshFailedAt < MESH_RETRY_MS)
127
130
  return;
@@ -68,7 +68,9 @@ export function targetForEvent(target, event) {
68
68
  * the old registration.
69
69
  */
70
70
  export const REQUIRED_EVALUATORS = {
71
- PreToolUse: ['credential-files', 'company-scope', 'path-search-rules', 'command-rules', 'policy-injection'],
71
+ // Merge-state has no production writer yet. Require its readiness separately
72
+ // so command-rules alone cannot remove the existing merge gate dispatcher.
73
+ PreToolUse: ['credential-files', 'company-scope', 'path-search-rules', 'command-rules', 'merge-gates-ready', 'live-command-flags-ready', 'git-identity-authority-ready', 'policy-injection'],
72
74
  PostToolUse: ['policy-injection'],
73
75
  UserPromptSubmit: ['policy-injection'],
74
76
  SessionStart: ['policy-injection'],
@@ -115,8 +115,23 @@ export interface UnwireResult {
115
115
  * (status `live` or `broken`). Foreign links and real files are left in place
116
116
  * -- same collision philosophy as scan-packages.sh. This is what prevents an
117
117
  * uninstall from leaving dangling symlinks behind.
118
+ *
119
+ * Also removes the namespaced skill host (`<pack>:<item>`) reindex writes
120
+ * next to the unprefixed table dest, unless `keepNamespacedSkills` is set.
121
+ * `hq packs update` sets it: the pack directory is replaced in place, so the
122
+ * namespaced links stay valid, and removing them would hide `/<pack>:<skill>`
123
+ * until the next reindex. Update removes the hosts of skills the new version
124
+ * dropped with `unwireNamespacedSkills` once the new manifest is on disk.
125
+ */
126
+ export declare function unwirePack(hqRoot: string, packDir: string, contributes: Partial<Record<PackContributeKey, string[]>>, options?: {
127
+ keepNamespacedSkills?: boolean;
128
+ }): UnwireResult;
129
+ /**
130
+ * Remove the namespaced skill hosts (`<pack>:<item>`) for `items`, with the
131
+ * same ownership rules as `unwirePack`: only links into this pack's directory,
132
+ * and wrapper directories only once removing those links leaves them empty.
118
133
  */
119
- export declare function unwirePack(hqRoot: string, packDir: string, contributes: Partial<Record<PackContributeKey, string[]>>): UnwireResult;
134
+ export declare function unwireNamespacedSkills(hqRoot: string, packDir: string, items: readonly unknown[]): UnwireResult;
120
135
  /** The result of {@link unwirePackMcp}: the per-server un-registration outcomes (empty when no `mcp` keys). */
121
136
  export interface UnwireMcpResult {
122
137
  /** One {@link UnregisterServerResult} per declared `contributes.mcp` server, in declaration order. */
@@ -85,11 +85,18 @@ export function mergeKeys(contributes) {
85
85
  * macOS `/var` ↔ `/private/var` so equivalent paths compare equal.
86
86
  */
87
87
  function canonicalPath(p) {
88
+ const absolute = path.resolve(p);
88
89
  try {
89
- return fs.realpathSync.native(p);
90
+ return fs.realpathSync.native(absolute);
90
91
  }
91
92
  catch {
92
- return path.resolve(p);
93
+ // The path itself is gone (a broken link's target). Canonicalize its
94
+ // nearest existing ancestor so `/var` vs `/private/var` style aliases still
95
+ // compare equal against an existing pack directory.
96
+ const parent = path.dirname(absolute);
97
+ if (parent === absolute)
98
+ return absolute;
99
+ return path.join(canonicalPath(parent), path.basename(absolute));
93
100
  }
94
101
  }
95
102
  /** True when `candidate` resolves under `packDir` (pack directory containment). */
@@ -226,41 +233,147 @@ export function findDependentPacks(installed, name) {
226
233
  return installed.filter((p) => p.name !== name &&
227
234
  (p.manifest?.requires?.packs ?? []).some((d) => d.name === name));
228
235
  }
236
+ function unlinkContribution(result, link, packDir) {
237
+ const status = linkStatus(link, packDir);
238
+ if (status === 'live' || status === 'broken') {
239
+ try {
240
+ fs.unlinkSync(link.dst);
241
+ result.unlinked.push({ key: link.key, item: link.item, dst: link.dst });
242
+ }
243
+ catch {
244
+ result.skipped.push({
245
+ key: link.key,
246
+ item: link.item,
247
+ dst: link.dst,
248
+ reason: 'foreign',
249
+ });
250
+ }
251
+ return;
252
+ }
253
+ result.skipped.push({
254
+ key: link.key,
255
+ item: link.item,
256
+ dst: link.dst,
257
+ reason: status === 'missing' ? 'missing' : 'foreign',
258
+ });
259
+ }
260
+ /**
261
+ * Reindex surfaces pack skills as `.claude/skills/<pack>:<item>` (symlink or
262
+ * a directory wrapper). Uninstall's table dest is the unprefixed name, so
263
+ * those wrappers would otherwise stay behind as empty dirs.
264
+ */
265
+ function unwireNamespacedSkillHost(dst, packDir, item, result) {
266
+ let st;
267
+ try {
268
+ st = fs.lstatSync(dst);
269
+ }
270
+ catch {
271
+ return;
272
+ }
273
+ const declared = {
274
+ key: 'skills',
275
+ item,
276
+ src: path.join(packDir, 'skills', item),
277
+ dst,
278
+ };
279
+ if (st.isSymbolicLink()) {
280
+ const status = linkStatus(declared, packDir);
281
+ if (status !== 'live' && status !== 'broken')
282
+ return;
283
+ try {
284
+ fs.unlinkSync(dst);
285
+ result.unlinked.push({ key: 'skills', item, dst });
286
+ }
287
+ catch {
288
+ result.skipped.push({ key: 'skills', item, dst, reason: 'foreign' });
289
+ }
290
+ return;
291
+ }
292
+ if (!st.isDirectory())
293
+ return;
294
+ let names;
295
+ try {
296
+ names = fs.readdirSync(dst);
297
+ }
298
+ catch {
299
+ return;
300
+ }
301
+ for (const name of names) {
302
+ const child = path.join(dst, name);
303
+ let childSt;
304
+ try {
305
+ childSt = fs.lstatSync(child);
306
+ }
307
+ catch {
308
+ return;
309
+ }
310
+ if (!childSt.isSymbolicLink())
311
+ return;
312
+ let resolved;
313
+ try {
314
+ resolved = path.resolve(dst, fs.readlinkSync(child));
315
+ }
316
+ catch {
317
+ return;
318
+ }
319
+ if (!targetUnderPackDir(packDir, resolved))
320
+ return;
321
+ try {
322
+ fs.unlinkSync(child);
323
+ }
324
+ catch {
325
+ return;
326
+ }
327
+ }
328
+ try {
329
+ fs.rmdirSync(dst);
330
+ result.unlinked.push({ key: 'skills', item, dst });
331
+ }
332
+ catch {
333
+ /* still occupied */
334
+ }
335
+ }
229
336
  /**
230
337
  * Remove only the host symlinks that resolve into THIS pack's directory
231
338
  * (status `live` or `broken`). Foreign links and real files are left in place
232
339
  * -- same collision philosophy as scan-packages.sh. This is what prevents an
233
340
  * uninstall from leaving dangling symlinks behind.
341
+ *
342
+ * Also removes the namespaced skill host (`<pack>:<item>`) reindex writes
343
+ * next to the unprefixed table dest, unless `keepNamespacedSkills` is set.
344
+ * `hq packs update` sets it: the pack directory is replaced in place, so the
345
+ * namespaced links stay valid, and removing them would hide `/<pack>:<skill>`
346
+ * until the next reindex. Update removes the hosts of skills the new version
347
+ * dropped with `unwireNamespacedSkills` once the new manifest is on disk.
234
348
  */
235
- export function unwirePack(hqRoot, packDir, contributes) {
349
+ export function unwirePack(hqRoot, packDir, contributes, options = {}) {
236
350
  const result = { unlinked: [], skipped: [] };
237
351
  for (const link of contributionLinks(hqRoot, packDir, contributes)) {
238
- const status = linkStatus(link, packDir);
239
- if (status === 'live' || status === 'broken') {
240
- try {
241
- fs.unlinkSync(link.dst);
242
- result.unlinked.push({ key: link.key, item: link.item, dst: link.dst });
243
- }
244
- catch {
245
- result.skipped.push({
246
- key: link.key,
247
- item: link.item,
248
- dst: link.dst,
249
- reason: 'foreign',
250
- });
251
- }
252
- }
253
- else {
254
- result.skipped.push({
255
- key: link.key,
256
- item: link.item,
257
- dst: link.dst,
258
- reason: status === 'missing' ? 'missing' : 'foreign',
259
- });
260
- }
352
+ unlinkContribution(result, link, packDir);
353
+ }
354
+ if (!options.keepNamespacedSkills) {
355
+ unwireNamespacedSkillsInto(result, hqRoot, packDir, contributes.skills ?? []);
261
356
  }
262
357
  return result;
263
358
  }
359
+ function unwireNamespacedSkillsInto(result, hqRoot, packDir, items) {
360
+ const packName = path.basename(packDir);
361
+ for (const item of items) {
362
+ if (typeof item !== 'string' || item.length === 0)
363
+ continue;
364
+ unwireNamespacedSkillHost(path.join(hqRoot, '.claude', 'skills', `${packName}:${item}`), packDir, item, result);
365
+ }
366
+ }
367
+ /**
368
+ * Remove the namespaced skill hosts (`<pack>:<item>`) for `items`, with the
369
+ * same ownership rules as `unwirePack`: only links into this pack's directory,
370
+ * and wrapper directories only once removing those links leaves them empty.
371
+ */
372
+ export function unwireNamespacedSkills(hqRoot, packDir, items) {
373
+ const result = { unlinked: [], skipped: [] };
374
+ unwireNamespacedSkillsInto(result, hqRoot, packDir, items);
375
+ return result;
376
+ }
264
377
  /**
265
378
  * Un-register the `wire: 'merge'` (MCP) servers a pack declares — the parallel to
266
379
  * {@link unwirePack}'s symlink removal. For each name in `mergeKeys(contributes)` →
@@ -132,7 +132,9 @@ export declare function runUpdateQuiet(cmd: string, args: string[], env?: NodeJS
132
132
  * the hq-sync Rust app), so every updater on the machine contends on ONE lock
133
133
  * instead of each tool keeping its own.
134
134
  */
135
- export declare function acquireUpdateLock(now?: number): (() => void) | null;
135
+ export declare function acquireUpdateLock(now?: number): ((() => void) & {
136
+ stillHeld?: () => boolean;
137
+ }) | null;
136
138
  /** Injectable surface so the flow is unit-testable without network or spawns. */
137
139
  export interface SelfUpdateDeps {
138
140
  env?: NodeJS.ProcessEnv;