@indigoai-us/hq-cli 5.345.220 → 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.
Files changed (184) hide show
  1. package/CHANGELOG.md +164 -0
  2. package/dist/command-catalog.generated.d.ts +175 -2
  3. package/dist/command-catalog.generated.js +213 -2
  4. package/dist/commands/auth.js +6 -2
  5. package/dist/commands/bot-runtime.d.ts +18 -5
  6. package/dist/commands/bot-runtime.js +29 -12
  7. package/dist/commands/bot.d.ts +39 -2
  8. package/dist/commands/bot.js +140 -11
  9. package/dist/commands/core-delegate-w1b.js +9 -3
  10. package/dist/commands/core-stop-autosave.d.ts +21 -0
  11. package/dist/commands/core-stop-autosave.js +300 -0
  12. package/dist/commands/core.js +2 -0
  13. package/dist/commands/daemon.d.ts +6 -0
  14. package/dist/commands/daemon.js +46 -8
  15. package/dist/commands/doctor-usage.d.ts +5 -0
  16. package/dist/commands/doctor-usage.js +25 -0
  17. package/dist/commands/env.d.ts +49 -4
  18. package/dist/commands/env.js +355 -5
  19. package/dist/commands/lanes-shared.d.ts +3 -0
  20. package/dist/commands/lanes.d.ts +3 -0
  21. package/dist/commands/lanes.js +87 -3
  22. package/dist/commands/link.d.ts +2 -0
  23. package/dist/commands/link.js +14 -2
  24. package/dist/commands/mesh.js +23 -3
  25. package/dist/commands/sources.js +3 -3
  26. package/dist/commands/sync-core.d.ts +7 -0
  27. package/dist/commands/sync-core.js +132 -3
  28. package/dist/commands/whoami.js +96 -80
  29. package/dist/data/command-states.json +3 -0
  30. package/dist/lib/bot/config.d.ts +17 -0
  31. package/dist/lib/bot/config.js +13 -0
  32. package/dist/lib/bot/fleet-cron.js +24 -2
  33. package/dist/lib/bot/fleet-local.d.ts +30 -2
  34. package/dist/lib/bot/fleet-local.js +60 -1
  35. package/dist/lib/bot/grok-login-scope.d.ts +36 -0
  36. package/dist/lib/bot/grok-login-scope.js +93 -0
  37. package/dist/lib/bot/legacy-provider-login.d.ts +32 -9
  38. package/dist/lib/bot/legacy-provider-login.js +28 -22
  39. package/dist/lib/bot/runtime-sign-in-check.js +6 -1
  40. package/dist/lib/bot/runtime-sign-in.d.ts +2 -0
  41. package/dist/lib/core-utils/sentry-report.js +2 -0
  42. package/dist/lib/daemon/catalog.js +2 -0
  43. package/dist/lib/daemon/install.d.ts +2 -1
  44. package/dist/lib/daemon/install.js +9 -0
  45. package/dist/lib/daemon/legacy.d.ts +1 -0
  46. package/dist/lib/daemon/legacy.js +5 -2
  47. package/dist/lib/daemon/machine-check-owner.d.ts +2 -0
  48. package/dist/lib/daemon/machine-check-owner.js +6 -1
  49. package/dist/lib/daemon/machine-checks.d.ts +29 -2
  50. package/dist/lib/daemon/machine-checks.js +64 -13
  51. package/dist/lib/daemon/mesh-owner.d.ts +45 -0
  52. package/dist/lib/daemon/mesh-owner.js +166 -0
  53. package/dist/lib/daemon/native-notice-ledger.d.ts +27 -0
  54. package/dist/lib/daemon/native-notice-ledger.js +113 -0
  55. package/dist/lib/daemon/run.d.ts +15 -0
  56. package/dist/lib/daemon/run.js +137 -11
  57. package/dist/lib/daemon/selfcheck.d.ts +35 -2
  58. package/dist/lib/daemon/selfcheck.js +118 -9
  59. package/dist/lib/daemon/stop-autosave-lock.d.ts +19 -0
  60. package/dist/lib/daemon/stop-autosave-lock.js +166 -0
  61. package/dist/lib/daemon/stop-autosave.d.ts +28 -0
  62. package/dist/lib/daemon/stop-autosave.js +111 -0
  63. package/dist/lib/daemon/stop-diagnostics.d.ts +11 -0
  64. package/dist/lib/daemon/stop-diagnostics.js +136 -0
  65. package/dist/lib/daemon/stop-job-executor.d.ts +19 -0
  66. package/dist/lib/daemon/stop-job-executor.js +126 -0
  67. package/dist/lib/daemon/stop-jobs.d.ts +93 -0
  68. package/dist/lib/daemon/stop-jobs.js +599 -0
  69. package/dist/lib/doctor/checks/fleet-hook-core.js +1 -1
  70. package/dist/lib/doctor/checks/host-core.js +1 -1
  71. package/dist/lib/environment/access-probes.d.ts +234 -0
  72. package/dist/lib/environment/access-probes.js +918 -0
  73. package/dist/lib/environment/profile.d.ts +15 -2
  74. package/dist/lib/environment/profile.js +55 -20
  75. package/dist/lib/environment/rfc3339.d.ts +8 -0
  76. package/dist/lib/environment/rfc3339.js +26 -0
  77. package/dist/lib/environment/work-requirements.d.ts +169 -0
  78. package/dist/lib/environment/work-requirements.js +389 -0
  79. package/dist/lib/hook-engine/coverage.d.ts +146 -7
  80. package/dist/lib/hook-engine/coverage.js +1480 -4
  81. package/dist/lib/hook-engine/fleet-registration.js +2 -2
  82. package/dist/lib/hook-engine/git-stop-config.json +513 -0
  83. package/dist/lib/hook-engine/native-stop-compatibility.json +362 -0
  84. package/dist/lib/hook-engine/reconcile.js +2 -2
  85. package/dist/lib/hot-channels/alert.d.ts +2 -2
  86. package/dist/lib/hot-channels/alert.js +8 -5
  87. package/dist/lib/hot-channels/signals-pass.d.ts +126 -17
  88. package/dist/lib/hot-channels/signals-pass.js +296 -17
  89. package/dist/lib/hot-channels/signals-runtime.d.ts +30 -0
  90. package/dist/lib/hot-channels/signals-runtime.js +82 -0
  91. package/dist/lib/install/hook-target.js +1 -1
  92. package/dist/lib/lanes/host-capacity.d.ts +26 -2
  93. package/dist/lib/lanes/host-capacity.js +17 -2
  94. package/dist/lib/lanes/host-compute.d.ts +90 -0
  95. package/dist/lib/lanes/host-compute.js +185 -0
  96. package/dist/lib/lanes/index.d.ts +2 -0
  97. package/dist/lib/lanes/index.js +1 -0
  98. package/dist/lib/lanes/reconcile.js +22 -1
  99. package/dist/lib/lanes/resource-usage.d.ts +155 -0
  100. package/dist/lib/lanes/resource-usage.js +589 -0
  101. package/dist/lib/lanes/run-size.d.ts +46 -0
  102. package/dist/lib/lanes/run-size.js +197 -0
  103. package/dist/lib/lanes/store.js +27 -0
  104. package/dist/lib/lanes/throttle.d.ts +36 -1
  105. package/dist/lib/lanes/throttle.js +47 -10
  106. package/dist/lib/lanes/types.d.ts +40 -0
  107. package/dist/lib/lanes/types.js +2 -2
  108. package/dist/lib/lanes/watcher.js +13 -4
  109. package/dist/lib/lanes/worker-process.d.ts +25 -2
  110. package/dist/lib/lanes/worker-process.js +71 -19
  111. package/dist/lib/mesh/live/daemon/config.d.ts +8 -1
  112. package/dist/lib/mesh/live/daemon/config.js +16 -0
  113. package/dist/lib/mesh/live/daemon/install.d.ts +31 -2
  114. package/dist/lib/mesh/live/daemon/install.js +142 -1
  115. package/dist/lib/mesh/live/daemon/login-home.d.ts +5 -0
  116. package/dist/lib/mesh/live/daemon/login-home.js +27 -0
  117. package/dist/lib/mesh/live/daemon/unit-home.d.ts +49 -0
  118. package/dist/lib/mesh/live/daemon/unit-home.js +134 -0
  119. package/dist/lib/placement/match.d.ts +192 -0
  120. package/dist/lib/placement/match.js +667 -0
  121. package/dist/lib/registry/registry.d.ts +35 -7
  122. package/dist/lib/registry/registry.js +88 -13
  123. package/dist/lib/safe-store.d.ts +14 -0
  124. package/dist/lib/safe-store.js +77 -4
  125. package/dist/lib/scan-packages/index.js +24 -2
  126. package/dist/lib/search-index/index.d.ts +88 -4
  127. package/dist/lib/search-index/index.js +288 -24
  128. package/dist/lib/search-index/max-doc-bytes.d.ts +17 -6
  129. package/dist/lib/search-index/max-doc-bytes.js +49 -23
  130. package/dist/lib/service-manager/startup-migration.d.ts +1 -0
  131. package/dist/lib/service-manager/startup-migration.js +3 -0
  132. package/dist/lib/signals/codex-lockdown.d.ts +79 -0
  133. package/dist/lib/signals/codex-lockdown.js +271 -0
  134. package/dist/lib/signals/codex-login.d.ts +37 -0
  135. package/dist/lib/signals/codex-login.js +83 -0
  136. package/dist/lib/signals/engine.d.ts +27 -0
  137. package/dist/lib/signals/engine.js +70 -0
  138. package/dist/lib/signals/reply.js +22 -1
  139. package/dist/lib/signals/run-record.js +6 -1
  140. package/dist/lib/signals/settings.d.ts +5 -0
  141. package/dist/lib/signals/settings.js +2 -0
  142. package/dist/lib/signals/steps/extract.d.ts +85 -9
  143. package/dist/lib/signals/steps/extract.js +317 -68
  144. package/dist/lib/signals/steps/types.d.ts +2 -0
  145. package/dist/lib/sync-core/engine-holds.d.ts +14 -0
  146. package/dist/lib/sync-core/engine-holds.js +60 -0
  147. package/dist/lib/sync-core/engine-home.d.ts +37 -1
  148. package/dist/lib/sync-core/engine-home.js +119 -16
  149. package/dist/lib/sync-core/reconcile.js +8 -0
  150. package/dist/lib/sync-core/rollout-state.d.ts +2 -1
  151. package/dist/lib/sync-core/rollout-state.js +5 -2
  152. package/dist/lib/sync-core/vault-settings.d.ts +21 -0
  153. package/dist/lib/sync-core/vault-settings.js +131 -0
  154. package/dist/lib/sync-core/vault-uid.d.ts +2 -0
  155. package/dist/lib/sync-core/vault-uid.js +4 -0
  156. package/dist/lib/windows/install-followup.d.ts +2 -0
  157. package/dist/lib/windows/install-followup.js +4 -1
  158. package/dist/schemas/hq-work-requirements.v1.schema.json +145 -0
  159. package/dist/utils/auth-session-check.d.ts +16 -0
  160. package/dist/utils/auth-session-check.js +16 -0
  161. package/dist/utils/client-health-contract.d.ts +6 -0
  162. package/dist/utils/client-health-contract.js +13 -0
  163. package/dist/utils/client-health.d.ts +7 -0
  164. package/dist/utils/client-health.js +22 -1
  165. package/dist/utils/command-usage.d.ts +40 -0
  166. package/dist/utils/command-usage.js +61 -0
  167. package/dist/utils/duplicate-command-usage.d.ts +72 -0
  168. package/dist/utils/duplicate-command-usage.js +125 -0
  169. package/dist/utils/host-registration.js +5 -2
  170. package/dist/utils/pack-contributions.d.ts +3 -0
  171. package/dist/utils/pack-contributions.js +110 -23
  172. package/dist/utils/resident-package-preload.js +4 -0
  173. package/dist/utils/self-update.d.ts +3 -1
  174. package/dist/utils/self-update.js +56 -11
  175. package/dist/utils/sentry-fingerprint.js +9 -0
  176. package/dist/utils/update-lock.d.ts +151 -14
  177. package/dist/utils/update-lock.js +782 -46
  178. package/dist/utils/version-gate.js +12 -2
  179. package/dist/utils/windows-bash.d.ts +2 -0
  180. package/dist/utils/windows-bash.js +2 -1
  181. package/package.json +9 -8
  182. package/scripts/bench-core-compare.mjs +313 -0
  183. package/scripts/bench-core.mjs +399 -12
  184. package/scripts/check-function-manifest.mjs +116 -3
@@ -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`, or remote URLs.
70
- * A local path seeds both its path key and, when it has an origin, its remote
71
- * key. Never overwrites a `link` or `prompt` entry, and skips any key claimed
72
- * by more than one company.
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 (!best) {
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
- return { company: best.entry.company, key: best.key, source: best.entry.source };
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`, or remote URLs.
187
- * A local path seeds both its path key and, when it has an origin, its remote
188
- * key. Never overwrites a `link` or `prompt` entry, and skips any key claimed
189
- * by more than one company.
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 = path.isAbsolute(trimmed) ? trimmed : path.join(hqRoot, trimmed);
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)] });
@@ -155,6 +155,10 @@ export interface OpenStoreDirOptions {
155
155
  export interface ReadOptions {
156
156
  /** Refuse a file larger than this. Default 1 MiB. */
157
157
  maxBytes?: number;
158
+ /** Read a bounded window from an append-only queue rather than the whole file. */
159
+ offset?: number;
160
+ /** Include the opened file's device/inode identity for queue cursors. */
161
+ identity?: boolean;
158
162
  }
159
163
  export interface AppendOptions {
160
164
  /** Refuse to append when the file is already this size or larger. */
@@ -173,6 +177,7 @@ export interface FileFacts {
173
177
  /** FileFacts plus the exact modification time in nanoseconds (mtimeMs is a float and can round across a millisecond). */
174
178
  export interface ReadFacts extends FileFacts {
175
179
  mtimeNs: bigint;
180
+ fileIdentity?: string;
176
181
  }
177
182
  export interface RenameOptions {
178
183
  /** Waits in milliseconds between rename attempts on EPERM, EACCES or EBUSY (Windows). Empty: no retry. */
@@ -212,9 +217,18 @@ export interface SafeStore {
212
217
  remove(name: string): SafeStoreResult<boolean>;
213
218
  /** The names in the folder. */
214
219
  list(): SafeStoreResult<string[]>;
220
+ /** Read directory names in bounded batches without materializing the directory. */
221
+ nameCursor(): SafeStoreResult<SafeStoreNameCursor>;
215
222
  /** Release the held folder. Later calls are refused with "closed". */
216
223
  close(): void;
217
224
  }
225
+ export interface SafeStoreNameCursor {
226
+ read(maxNames: number): SafeStoreResult<{
227
+ names: string[];
228
+ done: boolean;
229
+ }>;
230
+ close(): void;
231
+ }
218
232
  /** A plain file name: no separator, no NUL, not "." or "..", at most 255 bytes. */
219
233
  export declare function isPlainName(name: string): boolean;
220
234
  /** Owner and mode facts a check needs, from fs.Stats or fs.BigIntStats. */
@@ -602,12 +602,17 @@ class HeldStore {
602
602
  return opened;
603
603
  const { fd, stat } = opened.value;
604
604
  try {
605
- if (stat.size > BigInt(maxBytes))
605
+ const offset = options.offset ?? 0;
606
+ if (!Number.isSafeInteger(offset) || offset < 0)
607
+ return refusal("io-error", "invalid read offset");
608
+ if (options.offset === undefined && stat.size > BigInt(maxBytes))
606
609
  return refusal("too-large", `the file is larger than ${maxBytes} bytes`);
607
- const buffer = Buffer.alloc(maxBytes + 1);
610
+ const buffer = Buffer.alloc(maxBytes + (options.offset === undefined ? 1 : 0));
608
611
  let length = 0;
609
612
  for (;;) {
610
- const count = fs.readSync(fd, buffer, length, buffer.length - length, null);
613
+ if (length === buffer.length)
614
+ break;
615
+ const count = fs.readSync(fd, buffer, length, buffer.length - length, offset + length);
611
616
  if (count === 0)
612
617
  break;
613
618
  length += count;
@@ -615,7 +620,8 @@ class HeldStore {
615
620
  return refusal("too-large", `the file is larger than ${maxBytes} bytes`);
616
621
  }
617
622
  // Bigint stats round mtimeMs down to a whole millisecond; mtimeNs keeps the fraction.
618
- const facts = { size: length, mtimeMs: Number(stat.mtimeNs) / 1e6, mtimeNs: stat.mtimeNs };
623
+ const facts = { size: length, mtimeMs: Number(stat.mtimeNs) / 1e6, mtimeNs: stat.mtimeNs,
624
+ ...(options.identity ? { fileIdentity: `${stat.dev}:${stat.ino}` } : {}) };
619
625
  return { ok: true, value: { data: Buffer.from(buffer.subarray(0, length)), facts } };
620
626
  }
621
627
  catch (error) {
@@ -759,6 +765,73 @@ class HeldStore {
759
765
  return afterList;
760
766
  return { ok: true, value: names };
761
767
  }
768
+ nameCursor() {
769
+ const refused = this.start("list");
770
+ if (refused)
771
+ return refused;
772
+ let directory;
773
+ try {
774
+ directory = fs.opendirSync(this.base, { bufferSize: 32 });
775
+ }
776
+ catch (error) {
777
+ return ioError("opening directory cursor", error);
778
+ }
779
+ let closed = false;
780
+ const close = () => {
781
+ if (closed)
782
+ return;
783
+ closed = true;
784
+ try {
785
+ directory.closeSync();
786
+ }
787
+ catch { /* already closed */ }
788
+ };
789
+ const checked = this.check();
790
+ if (checked) {
791
+ close();
792
+ return checked;
793
+ }
794
+ return { ok: true, value: {
795
+ close,
796
+ read: (maxNames) => {
797
+ const before = this.start("list");
798
+ if (before) {
799
+ close();
800
+ return before;
801
+ }
802
+ if (closed)
803
+ return { ok: true, value: { names: [], done: true } };
804
+ if (!Number.isSafeInteger(maxNames) || maxNames < 1 || maxNames > 256) {
805
+ close();
806
+ return ioError("reading directory cursor", new Error("invalid batch size"));
807
+ }
808
+ const names = [];
809
+ let done = false;
810
+ try {
811
+ while (names.length < maxNames) {
812
+ const entry = directory.readSync();
813
+ if (!entry) {
814
+ done = true;
815
+ close();
816
+ break;
817
+ }
818
+ names.push(entry.name);
819
+ }
820
+ }
821
+ catch (error) {
822
+ close();
823
+ return ioError("reading directory cursor", error);
824
+ }
825
+ this.at("after-list", "list");
826
+ const after = this.check();
827
+ if (after) {
828
+ close();
829
+ return after;
830
+ }
831
+ return { ok: true, value: { names, done } };
832
+ },
833
+ } };
834
+ }
762
835
  close() {
763
836
  if (this.closed)
764
837
  return;
@@ -168,11 +168,33 @@ function targetLookup(target) {
168
168
  return code === 'ENOENT' || code === 'ENOTDIR' ? 'absent' : code ?? 'unknown error';
169
169
  }
170
170
  }
171
- function ensureSymlink(link, info, warn) {
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
  }
@@ -141,6 +141,77 @@ export declare class QmdCollectionExistsError extends QmdExitError {
141
141
  name: string;
142
142
  constructor(message: string, args: string[], status: number | null, stdout: string, stderr: string, collectionName: string);
143
143
  }
144
+ /**
145
+ * qmd's `collection add` exited non-zero because ANOTHER collection already
146
+ * covers exactly this path and pattern (qmd 2.5.3 prints "A collection already
147
+ * exists for this path and pattern:" and then `Name: <other> (qmd://<other>/)`).
148
+ * For unmanaged names, reconciliation skips its own add, prints a notice and
149
+ * carries on. HQ-managed name collisions remain fatal and captured. Before
150
+ * this, the duplicate aborted the whole `hq index sync`, so no collection was
151
+ * ever updated again on that machine (HQ-CLI-GJ).
152
+ */
153
+ export declare class QmdCollectionPathTakenError extends QmdExitError {
154
+ readonly existingName: string;
155
+ name: string;
156
+ constructor(message: string, args: string[], status: number | null, stdout: string, stderr: string, existingName: string);
157
+ }
158
+ /**
159
+ * hq or its qmd child was refused READ access to the HQ folder: EPERM/EACCES on
160
+ * `uv_cwd` (qmd's process.cwd() in the HQ root), or on a scandir/open of a path
161
+ * inside the HQ root. On macOS an EPERM there is the privacy (TCC) gate on a
162
+ * protected location such as Documents, Desktop or iCloud Drive. The message is
163
+ * the platform-specific remedy; the carrier is thrown marked expected, so the
164
+ * boundary prints it and skips capture (HQ-CLI-EJ, HQ-CLI-FV, HQ-CLI-BV,
165
+ * HQ-CLI-FF).
166
+ */
167
+ export declare class QmdAccessDeniedError extends QmdExitError {
168
+ readonly deniedPath: string;
169
+ readonly errnoCode: 'EPERM' | 'EACCES';
170
+ readonly syscall: string;
171
+ name: string;
172
+ constructor(message: string, args: string[], status: number | null, stdout: string, stderr: string, deniedPath: string, errnoCode: 'EPERM' | 'EACCES', syscall: string);
173
+ }
174
+ /**
175
+ * qmd could not create or write its own settings folder (QMD_CONFIG_DIR,
176
+ * $XDG_CONFIG_HOME/qmd or ~/.config/qmd): EPERM/EACCES on a path at or above
177
+ * that folder. The user's account cannot write there, typically because the
178
+ * folder was created by a command run with sudo. Thrown marked expected with
179
+ * the remedy as its message (HQ-CLI-GJ).
180
+ */
181
+ export declare class QmdConfigUnwritableError extends QmdExitError {
182
+ readonly configDir: string;
183
+ readonly errnoCode: 'EPERM' | 'EACCES';
184
+ name: string;
185
+ constructor(message: string, args: string[], status: number | null, stdout: string, stderr: string, configDir: string, errnoCode: 'EPERM' | 'EACCES');
186
+ }
187
+ /**
188
+ * qmd's SQLite index file is damaged (SQLITE_CORRUPT / SQLITE_NOTADB). qmd
189
+ * reports it as "sqlite-vec extension is unavailable ... Install Homebrew
190
+ * SQLite", which cannot fix a damaged file. hq names the file and the rebuild
191
+ * step instead. Still captured, because a trend of damaged index files would
192
+ * point at a writer bug (HQ-CLI-EJ).
193
+ */
194
+ export declare class QmdStoreCorruptError extends QmdExitError {
195
+ readonly storeFile: string | undefined;
196
+ name: string;
197
+ constructor(message: string, args: string[], status: number | null, stdout: string, stderr: string, storeFile: string | undefined);
198
+ }
199
+ type QmdPermissionFailure = {
200
+ code: 'EPERM' | 'EACCES';
201
+ syscall: string;
202
+ path?: string;
203
+ };
204
+ /**
205
+ * Parse an unambiguous fatal Node permission error from stderr, for example
206
+ * `Error: EPERM: operation not permitted, uv_cwd` or
207
+ * `[Error: EACCES: permission denied, mkdir '/home/u/.config/qmd']`.
208
+ * Incidental warnings and output containing another thrown error stay captured.
209
+ */
210
+ export declare function parseQmdPermissionFailure(text: string): QmdPermissionFailure | undefined;
211
+ /** Remedy for a refused read of the HQ folder, worded for the platform. */
212
+ export declare function qmdAccessDeniedMessage(deniedPath: string, code: 'EPERM' | 'EACCES', platform?: NodeJS.Platform): string;
213
+ /** Remedy for a qmd settings folder the user cannot write. */
214
+ export declare function qmdConfigUnwritableMessage(configDir: string, deniedPath: string, syscall: string, platform?: NodeJS.Platform): string;
144
215
  /**
145
216
  * qmd did NOT exit — it was KILLED BY A SIGNAL before it finished (spawnSync
146
217
  * reports `status: null` with a non-null `signal`). hq-cli passes qmd no timeout
@@ -553,6 +624,13 @@ export type ReconcileCollectionsOptions = {
553
624
  runner?: QmdProcessRunner;
554
625
  /** Test seam for the default-off collection-path repair rollout. */
555
626
  repairPathDrift?: boolean;
627
+ /** Where reconciliation notices go (default: process.stderr). */
628
+ writeStderr?: (text: string) => void;
629
+ /**
630
+ * File that records one-time notices already shown (default
631
+ * `<hqRoot>/.hq/search-index-notices.json`); `null` disables the record.
632
+ */
633
+ noticesFile?: string | null;
556
634
  };
557
635
  /**
558
636
  * Register expected collections that qmd does not yet know about, returning the
@@ -566,10 +644,16 @@ export type ReconcileCollectionsOptions = {
566
644
  * NOT a failure. Reconciliation still issues the `context add`, whose qmd-side
567
645
  * resyncConfig re-syncs YAML into SQLite and heals the divergence that provoked
568
646
  * the retry, then continues with later collections; such a pre-existing
569
- * collection is excluded from the returned list. Every other qmd failure still
570
- * propagates: the DIFFERENT path+pattern duplicate, a same-name duplicate that
571
- * named a different collection, a missing collection, a `context add` failure,
572
- * a missing/unbuilt qmd binary. HQ-CLI-Q (Sentry 7670823899).
647
+ * collection is excluded from the returned list.
648
+ *
649
+ * An unmanaged path+pattern duplicate is not fatal: the files are indexed under
650
+ * that name, but scoped search misses them. Print a notice, skip this add and
651
+ * its `context add`, and continue. It used to abort the whole sync, so
652
+ * `qmd update` never ran again on that machine (HQ-CLI-GJ).
653
+ *
654
+ * Every other qmd failure still propagates: a same-name duplicate that named a
655
+ * different collection, a missing collection, a `context add` failure, a
656
+ * missing/unbuilt qmd binary. HQ-CLI-Q (Sentry 7670823899).
573
657
  */
574
658
  export declare function reconcileCollections(hqRoot: string, options?: ReconcileCollectionsOptions): SearchCollection[];
575
659
  export declare function listRegisteredCollections(hqRoot: string, options?: RunQmdOptions): Set<string>;