@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
@@ -109,6 +109,155 @@ export class QmdCollectionExistsError extends QmdExitError {
109
109
  this.collectionName = collectionName;
110
110
  }
111
111
  }
112
+ /**
113
+ * qmd's `collection add` exited non-zero because ANOTHER collection already
114
+ * covers exactly this path and pattern (qmd 2.5.3 prints "A collection already
115
+ * exists for this path and pattern:" and then `Name: <other> (qmd://<other>/)`).
116
+ * For unmanaged names, reconciliation skips its own add, prints a notice and
117
+ * carries on. HQ-managed name collisions remain fatal and captured. Before
118
+ * this, the duplicate aborted the whole `hq index sync`, so no collection was
119
+ * ever updated again on that machine (HQ-CLI-GJ).
120
+ */
121
+ export class QmdCollectionPathTakenError extends QmdExitError {
122
+ existingName;
123
+ name = 'QmdCollectionPathTakenError';
124
+ constructor(message, args, status, stdout, stderr, existingName) {
125
+ super(message, args, status, stdout, stderr);
126
+ this.existingName = existingName;
127
+ }
128
+ }
129
+ /**
130
+ * hq or its qmd child was refused READ access to the HQ folder: EPERM/EACCES on
131
+ * `uv_cwd` (qmd's process.cwd() in the HQ root), or on a scandir/open of a path
132
+ * inside the HQ root. On macOS an EPERM there is the privacy (TCC) gate on a
133
+ * protected location such as Documents, Desktop or iCloud Drive. The message is
134
+ * the platform-specific remedy; the carrier is thrown marked expected, so the
135
+ * boundary prints it and skips capture (HQ-CLI-EJ, HQ-CLI-FV, HQ-CLI-BV,
136
+ * HQ-CLI-FF).
137
+ */
138
+ export class QmdAccessDeniedError extends QmdExitError {
139
+ deniedPath;
140
+ errnoCode;
141
+ syscall;
142
+ name = 'QmdAccessDeniedError';
143
+ constructor(message, args, status, stdout, stderr, deniedPath, errnoCode, syscall) {
144
+ super(message, args, status, stdout, stderr);
145
+ this.deniedPath = deniedPath;
146
+ this.errnoCode = errnoCode;
147
+ this.syscall = syscall;
148
+ }
149
+ }
150
+ /**
151
+ * qmd could not create or write its own settings folder (QMD_CONFIG_DIR,
152
+ * $XDG_CONFIG_HOME/qmd or ~/.config/qmd): EPERM/EACCES on a path at or above
153
+ * that folder. The user's account cannot write there, typically because the
154
+ * folder was created by a command run with sudo. Thrown marked expected with
155
+ * the remedy as its message (HQ-CLI-GJ).
156
+ */
157
+ export class QmdConfigUnwritableError extends QmdExitError {
158
+ configDir;
159
+ errnoCode;
160
+ name = 'QmdConfigUnwritableError';
161
+ constructor(message, args, status, stdout, stderr, configDir, errnoCode) {
162
+ super(message, args, status, stdout, stderr);
163
+ this.configDir = configDir;
164
+ this.errnoCode = errnoCode;
165
+ }
166
+ }
167
+ /**
168
+ * qmd's SQLite index file is damaged (SQLITE_CORRUPT / SQLITE_NOTADB). qmd
169
+ * reports it as "sqlite-vec extension is unavailable ... Install Homebrew
170
+ * SQLite", which cannot fix a damaged file. hq names the file and the rebuild
171
+ * step instead. Still captured, because a trend of damaged index files would
172
+ * point at a writer bug (HQ-CLI-EJ).
173
+ */
174
+ export class QmdStoreCorruptError extends QmdExitError {
175
+ storeFile;
176
+ name = 'QmdStoreCorruptError';
177
+ constructor(message, args, status, stdout, stderr, storeFile) {
178
+ super(message, args, status, stdout, stderr);
179
+ this.storeFile = storeFile;
180
+ }
181
+ }
182
+ /**
183
+ * Parse an unambiguous fatal Node permission error from stderr, for example
184
+ * `Error: EPERM: operation not permitted, uv_cwd` or
185
+ * `[Error: EACCES: permission denied, mkdir '/home/u/.config/qmd']`.
186
+ * Incidental warnings and output containing another thrown error stay captured.
187
+ */
188
+ export function parseQmdPermissionFailure(text) {
189
+ const errors = text.match(/^\[?(?:[A-Za-z_$][\w$]*Error|Error):[^\r\n]*/gm);
190
+ if (errors?.length !== 1)
191
+ return undefined;
192
+ const match = /^\[?Error: (EPERM|EACCES): [^\n,]*, ([a-z_]+)(?: '([^'\n]+)')?(?:\]?\s*\{?)?$/.exec(errors[0]);
193
+ if (!match)
194
+ return undefined;
195
+ const code = match[1];
196
+ const syscall = match[2] ?? '';
197
+ return match[3] ? { code, syscall, path: match[3] } : { code, syscall };
198
+ }
199
+ function isSameOrInside(candidate, parent) {
200
+ const relative = path.relative(comparablePath(path.resolve(parent)), comparablePath(path.resolve(candidate)));
201
+ return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));
202
+ }
203
+ /** qmd's global settings folder for this env (no project-local `.qmd/`). */
204
+ function qmdGlobalConfigDir(env) {
205
+ const configPath = resolveQmdConfigPath({
206
+ env: { ...env, HOME: env.HOME ?? env.USERPROFILE ?? os.homedir() },
207
+ });
208
+ return configPath ? path.dirname(configPath) : undefined;
209
+ }
210
+ /** Remedy for a refused read of the HQ folder, worded for the platform. */
211
+ export function qmdAccessDeniedMessage(deniedPath, code, platform = process.platform) {
212
+ if (platform === 'darwin' && code === 'EPERM') {
213
+ return (`macOS blocked hq's search index from reading ${deniedPath} (operation not permitted). ` +
214
+ 'Your HQ folder is probably in a privacy-protected location such as Documents, Desktop or iCloud Drive, ' +
215
+ 'and the app that runs hq has not been given access to it. Allow it in System Settings > Privacy & Security > ' +
216
+ 'Full Disk Access (or Files and Folders), or move your HQ folder out of that location, then run: hq index sync');
217
+ }
218
+ if (platform === 'win32') {
219
+ return (`hq's search index could not read ${deniedPath} (access denied). Check that your Windows account can read ` +
220
+ 'that folder and that Controlled folder access or OneDrive is not blocking it, then run: hq index sync');
221
+ }
222
+ if (code === 'EPERM') {
223
+ // EPERM is not a file-mode refusal on Linux and other Unix systems: it comes
224
+ // from an immutable attribute or a security module.
225
+ return (`hq's search index could not read ${deniedPath} (operation not permitted). This is not a file permission ` +
226
+ 'setting: the folder or a file in it may be marked immutable (lsattr), or a security policy such as SELinux ' +
227
+ 'or AppArmor may be blocking it. Clear that block, then run: hq index sync');
228
+ }
229
+ return (`hq's search index could not read ${deniedPath} (permission denied). Give your user read access to that folder, ` +
230
+ 'then run: hq index sync');
231
+ }
232
+ /** Remedy for a qmd settings folder the user cannot write. */
233
+ export function qmdConfigUnwritableMessage(configDir, deniedPath, syscall, platform = process.platform) {
234
+ // A failed mkdir means the PARENT could not be written; anything else names the
235
+ // path itself.
236
+ const fixTarget = syscall === 'mkdir' ? path.dirname(deniedPath) : deniedPath;
237
+ const lead = `qmd could not save its search settings in ${configDir} because your user cannot write to ${fixTarget}, ` +
238
+ 'so hq could not register its search collections. ';
239
+ if (platform === 'win32') {
240
+ // Windows has no sudo; the usual cause is another account or an elevated prompt.
241
+ return (lead +
242
+ 'This usually happens when the folder was created by another account or from an administrator prompt. ' +
243
+ 'Set QMD_CONFIG_DIR to a folder owned by your Windows account where you have Full control ' +
244
+ '(Properties > Security), then run: hq index sync');
245
+ }
246
+ return (lead +
247
+ 'Set QMD_CONFIG_DIR to a folder owned by your user where you have write access, then run: hq index sync');
248
+ }
249
+ function qmdStoreFile(env, cwd) {
250
+ try {
251
+ const base = cwd ?? os.homedir();
252
+ if (env.INDEX_PATH)
253
+ return path.resolve(base, env.INDEX_PATH);
254
+ return path.join(resolveQmdStoreDir(env, base), 'index.sqlite');
255
+ }
256
+ catch {
257
+ return undefined;
258
+ }
259
+ }
260
+ const QMD_STORE_CORRUPT = /database disk image is malformed|\bSQLITE_CORRUPT\b|file is not a database|\bSQLITE_NOTADB\b/;
112
261
  /**
113
262
  * qmd did NOT exit — it was KILLED BY A SIGNAL before it finished (spawnSync
114
263
  * reports `status: null` with a non-null `signal`). hq-cli passes qmd no timeout
@@ -1051,7 +1200,7 @@ function isExpectedQmdCallerFailure(args, stderr) {
1051
1200
  return false;
1052
1201
  }
1053
1202
  /** Normalise a spawn result and raise the typed qmd failures. */
1054
- function finishRunQmd(result, bin, args, attribution) {
1203
+ function finishRunQmd(result, bin, args, attribution, context = {}) {
1055
1204
  const normalized = {
1056
1205
  status: result.status,
1057
1206
  stdout: result.stdout ?? '',
@@ -1250,6 +1399,41 @@ function finishRunQmd(result, bin, args, attribution) {
1250
1399
  if (isQmdModelDownloadError({ stderr: normalized.stderr, stdout: normalized.stdout })) {
1251
1400
  throw new QmdModelDownloadError(`qmd ${subcommand} could not run: a model download did not finish (its partial file disappeared)`, args, normalized.status, normalized.stdout, normalized.stderr);
1252
1401
  }
1402
+ // qmd died on a PERMISSION error from Node. Two shapes are the caller's
1403
+ // machine, not an hq defect, and get a typed carrier with a remedy:
1404
+ // - a read refused inside the HQ root, including qmd's own process.cwd()
1405
+ // (`uv_cwd`) in it: macOS privacy (TCC) on Documents/Desktop/iCloud, or
1406
+ // folder permissions (HQ-CLI-EJ, HQ-CLI-FV, HQ-CLI-BV, HQ-CLI-FF);
1407
+ // - qmd's settings folder cannot be created or written (HQ-CLI-GJ).
1408
+ // Any other permission failure keeps the generic, captured QmdExitError.
1409
+ // Reads qmd's own captured streams only, never the synthesized message.
1410
+ const permission = parseQmdPermissionFailure(normalized.stderr);
1411
+ if (permission) {
1412
+ const platform = context.platform ?? process.platform;
1413
+ const deniedPath = permission.syscall === 'uv_cwd' ? context.cwd : permission.path;
1414
+ // open alone does not distinguish a read from a write. Require a read
1415
+ // stack frame; ambiguous open failures remain reportable.
1416
+ const isRead = ['uv_cwd', 'scandir', 'stat', 'lstat'].includes(permission.syscall) ||
1417
+ (permission.syscall === 'open' && /^\s+at (?:async )?(?:Object\.)?readFile(?:Sync)?\b/m.test(normalized.stderr));
1418
+ if (isRead && deniedPath && context.cwd && isSameOrInside(deniedPath, context.cwd)) {
1419
+ throw markExpectedUserError(new QmdAccessDeniedError(qmdAccessDeniedMessage(deniedPath, permission.code, platform), args, normalized.status, normalized.stdout, normalized.stderr, deniedPath, permission.code, permission.syscall));
1420
+ }
1421
+ const configDir = qmdGlobalConfigDir(context.env ?? process.env);
1422
+ if (permission.path &&
1423
+ configDir &&
1424
+ // A recursive mkdir reports the first ANCESTOR it could not create, so an
1425
+ // ancestor counts only for mkdir.
1426
+ (isSameOrInside(permission.path, configDir) ||
1427
+ (permission.syscall === 'mkdir' && isSameOrInside(configDir, permission.path)))) {
1428
+ throw markExpectedUserError(new QmdConfigUnwritableError(qmdConfigUnwritableMessage(configDir, permission.path, permission.syscall, platform), args, normalized.status, normalized.stdout, normalized.stderr, configDir, permission.code));
1429
+ }
1430
+ }
1431
+ if (QMD_STORE_CORRUPT.test(`${normalized.stderr}\n${normalized.stdout}`)) {
1432
+ const storeFile = qmdStoreFile(context.env ?? process.env, context.cwd);
1433
+ throw new QmdStoreCorruptError(`qmd ${subcommand} could not run: hq's local search index${storeFile ? ` (${storeFile})` : ''} is damaged ` +
1434
+ '(SQLite reports the database file is malformed). It only holds data rebuilt from your HQ files: ' +
1435
+ 'delete that file, then run: hq index sync', args, normalized.status, normalized.stdout, normalized.stderr, storeFile);
1436
+ }
1253
1437
  if (/(?:collection|qmd:\/\/).*(?:not found|does not exist|unknown)|(?:not found|does not exist).*collection/i.test(classifyText)) {
1254
1438
  throw new QmdCollectionMissingError(message, args, normalized.status, normalized.stdout, normalized.stderr);
1255
1439
  }
@@ -1257,14 +1441,18 @@ function finishRunQmd(result, bin, args, attribution) {
1257
1441
  // owns (`Collection '<name>' already exists.`). Reconciliation treats this
1258
1442
  // exact shape as already-satisfied (HQ-CLI-Q). The DIFFERENT path+pattern
1259
1443
  // duplicate ("A collection already exists for this path and pattern:") names
1260
- // another collection and carries no quoted-name form, so it never matches and
1261
- // stays a plain QmdExitError. Colour is off under capture (qmd gates on
1262
- // isTTY) and any surrounding ANSI sits outside this substring, so the plain
1263
- // match is robust either way.
1444
+ // another collection and carries no quoted-name form, so it never matches
1445
+ // here; it is typed QmdCollectionPathTakenError below. Colour is off under
1446
+ // capture (qmd gates on isTTY) and any surrounding ANSI sits outside this
1447
+ // substring, so the plain match is robust either way.
1264
1448
  const alreadyExists = /Collection '([^']+)' already exists\./.exec(classifyText);
1265
1449
  if (alreadyExists) {
1266
1450
  throw new QmdCollectionExistsError(message, args, normalized.status, normalized.stdout, normalized.stderr, alreadyExists[1]);
1267
1451
  }
1452
+ const pathTaken = /A collection already exists for this path and pattern:[\s\S]*?Name:\s*(.+?)\s+\(qmd:\/\//.exec(classifyText);
1453
+ if (pathTaken?.[1]) {
1454
+ throw new QmdCollectionPathTakenError(message, args, normalized.status, normalized.stdout, normalized.stderr, pathTaken[1]);
1455
+ }
1268
1456
  const exitError = new QmdExitError(message, args, normalized.status, normalized.stdout, normalized.stderr);
1269
1457
  if (isExpectedQmdCallerFailure(args, normalized.stderr)) {
1270
1458
  throw markExpectedUserError(exitError);
@@ -1273,7 +1461,7 @@ function finishRunQmd(result, bin, args, attribution) {
1273
1461
  }
1274
1462
  function finishRunQmdWithDiagnostics(result, bin, args, options, attribution) {
1275
1463
  try {
1276
- return finishRunQmd(result, bin, args, attribution);
1464
+ return finishRunQmd(result, bin, args, attribution, { cwd: options.cwd, env: options.env, platform: options.platform });
1277
1465
  }
1278
1466
  catch (error) {
1279
1467
  if (error instanceof QmdExitError) {
@@ -1339,10 +1527,29 @@ export function runQmd(args, options = {}) {
1339
1527
  exists: options.exists,
1340
1528
  });
1341
1529
  }
1530
+ /**
1531
+ * List a folder for collection derivation. A path that is missing or is not a
1532
+ * folder (a file, or a symlink to one, named `knowledge` or `projects`) has
1533
+ * nothing to index, so it lists as empty instead of throwing ENOTDIR out of
1534
+ * the whole sync (HQ-CLI-ED). A refused read becomes the typed, expected
1535
+ * QmdAccessDeniedError with the platform remedy. Anything else still throws.
1536
+ */
1537
+ function readCollectionDir(directory) {
1538
+ try {
1539
+ return fs.readdirSync(directory, { withFileTypes: true });
1540
+ }
1541
+ catch (error) {
1542
+ const code = error?.code;
1543
+ if (code === 'ENOENT' || code === 'ENOTDIR')
1544
+ return [];
1545
+ if (code === 'EPERM' || code === 'EACCES') {
1546
+ throw markExpectedUserError(new QmdAccessDeniedError(qmdAccessDeniedMessage(directory, code), [], null, '', '', directory, code, 'scandir'));
1547
+ }
1548
+ throw error;
1549
+ }
1550
+ }
1342
1551
  function containsIndexedMarkdown(directory) {
1343
- if (!fs.existsSync(directory))
1344
- return false;
1345
- for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
1552
+ for (const entry of readCollectionDir(directory)) {
1346
1553
  const child = path.join(directory, entry.name);
1347
1554
  if (entry.isDirectory() && containsIndexedMarkdown(child))
1348
1555
  return true;
@@ -1352,9 +1559,7 @@ function containsIndexedMarkdown(directory) {
1352
1559
  return false;
1353
1560
  }
1354
1561
  function containsProjectSource(directory) {
1355
- if (!fs.existsSync(directory))
1356
- return false;
1357
- for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
1562
+ for (const entry of readCollectionDir(directory)) {
1358
1563
  const child = path.join(directory, entry.name);
1359
1564
  if (entry.isDirectory() && containsProjectSource(child))
1360
1565
  return true;
@@ -1367,9 +1572,7 @@ function containsProjectSource(directory) {
1367
1572
  export const ASSET_COLLECTION_MASK = '**/*.hqcloud';
1368
1573
  const ASSET_SCAN_SKIP_DIRS = new Set(['.git', 'node_modules']);
1369
1574
  function containsAssetPlaceholder(directory) {
1370
- if (!fs.existsSync(directory))
1371
- return false;
1372
- for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
1575
+ for (const entry of readCollectionDir(directory)) {
1373
1576
  const child = path.join(directory, entry.name);
1374
1577
  if (entry.isDirectory()) {
1375
1578
  if (!ASSET_SCAN_SKIP_DIRS.has(entry.name) && containsAssetPlaceholder(child))
@@ -1385,11 +1588,9 @@ function containsAssetPlaceholder(directory) {
1385
1588
  export function deriveCollections(hqRoot) {
1386
1589
  const root = path.resolve(hqRoot);
1387
1590
  const companiesDir = path.join(root, 'companies');
1388
- const companies = fs.existsSync(companiesDir)
1389
- ? fs.readdirSync(companiesDir, { withFileTypes: true })
1390
- .filter((entry) => entry.isDirectory())
1391
- .sort((a, b) => a.name.localeCompare(b.name))
1392
- : [];
1591
+ const companies = readCollectionDir(companiesDir)
1592
+ .filter((entry) => entry.isDirectory())
1593
+ .sort((a, b) => a.name.localeCompare(b.name));
1393
1594
  const collections = [];
1394
1595
  for (const entry of companies) {
1395
1596
  const knowledge = path.join(companiesDir, entry.name, 'knowledge');
@@ -1531,15 +1732,22 @@ function isPreviousHqManagedPath(hqRoot, collection, configuredPath) {
1531
1732
  * NOT a failure. Reconciliation still issues the `context add`, whose qmd-side
1532
1733
  * resyncConfig re-syncs YAML into SQLite and heals the divergence that provoked
1533
1734
  * the retry, then continues with later collections; such a pre-existing
1534
- * collection is excluded from the returned list. Every other qmd failure still
1535
- * propagates: the DIFFERENT path+pattern duplicate, a same-name duplicate that
1536
- * named a different collection, a missing collection, a `context add` failure,
1537
- * a missing/unbuilt qmd binary. HQ-CLI-Q (Sentry 7670823899).
1735
+ * collection is excluded from the returned list.
1736
+ *
1737
+ * An unmanaged path+pattern duplicate is not fatal: the files are indexed under
1738
+ * that name, but scoped search misses them. Print a notice, skip this add and
1739
+ * its `context add`, and continue. It used to abort the whole sync, so
1740
+ * `qmd update` never ran again on that machine (HQ-CLI-GJ).
1741
+ *
1742
+ * Every other qmd failure still propagates: a same-name duplicate that named a
1743
+ * different collection, a missing collection, a `context add` failure, a
1744
+ * missing/unbuilt qmd binary. HQ-CLI-Q (Sentry 7670823899).
1538
1745
  */
1539
1746
  export function reconcileCollections(hqRoot, options = {}) {
1540
1747
  const runOptions = { bin: options.bin, runner: options.runner, cwd: hqRoot };
1541
1748
  const registered = listRegisteredCollections(hqRoot, runOptions);
1542
1749
  const expected = deriveCollections(hqRoot);
1750
+ const managedNames = new Set(expected.map((collection) => collection.name));
1543
1751
  const repairPathDrift = options.repairPathDrift ?? false;
1544
1752
  const configured = repairPathDrift ? configuredCollections(hqRoot) : new Map();
1545
1753
  const stale = repairPathDrift
@@ -1565,6 +1773,31 @@ export function reconcileCollections(hqRoot, options = {}) {
1565
1773
  created.push(collection);
1566
1774
  }
1567
1775
  catch (error) {
1776
+ if (error instanceof QmdCollectionPathTakenError) {
1777
+ // Reserve the company-slug namespace, including -projects/-assets and
1778
+ // personal-knowledge, even when that company's folders are absent here.
1779
+ // A collision can otherwise expose one company's files under another.
1780
+ if (managedNames.has(error.existingName) || isSafeQmdCollectionName(error.existingName))
1781
+ throw error;
1782
+ // Shown once per folder and covering collection, so background syncs do
1783
+ // not repeat it on every run.
1784
+ const noticesFile = options.noticesFile === undefined ? defaultNoticesFile(hqRoot) : options.noticesFile;
1785
+ const noticeKey = `${collection.name}\u0000${error.existingName}\u0000${collection.path}`;
1786
+ const seenNotices = readSeenNotices(noticesFile);
1787
+ if (!seenNotices.has(noticeKey)) {
1788
+ const writeStderr = options.writeStderr ?? ((text) => process.stderr.write(text));
1789
+ const removalGuidance = isSafeQmdCollectionName(error.existingName)
1790
+ ? `run: qmd collection remove ${error.existingName}, then: hq index sync. `
1791
+ : `remove the qmd collection named ${JSON.stringify(error.existingName)} using qmd, then synchronize the HQ index again. `;
1792
+ writeStderr(`hq: ${collection.path} is already indexed by the qmd collection '${error.existingName}', ` +
1793
+ `so hq did not add it again as '${collection.name}'. Scoped search misses this folder until the other collection is removed. ` +
1794
+ `To use hq's name instead, ${removalGuidance}` +
1795
+ 'This notice is shown once.\n');
1796
+ seenNotices.add(noticeKey);
1797
+ writeSeenNotices(noticesFile, seenNotices);
1798
+ }
1799
+ continue;
1800
+ }
1568
1801
  // Only the exact same-name duplicate for THIS collection is already
1569
1802
  // satisfied. Anything else — including a same-name duplicate that names a
1570
1803
  // different collection — stays fatal.
@@ -1578,6 +1811,37 @@ export function reconcileCollections(hqRoot, options = {}) {
1578
1811
  }
1579
1812
  return created;
1580
1813
  }
1814
+ function isSafeQmdCollectionName(name) {
1815
+ return /^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(name);
1816
+ }
1817
+ function defaultNoticesFile(hqRoot) {
1818
+ return path.join(hqRoot, '.hq', 'search-index-notices.json');
1819
+ }
1820
+ /** Read the set of one-time reconcile notices already shown. Best-effort. */
1821
+ function readSeenNotices(file) {
1822
+ if (!file)
1823
+ return new Set();
1824
+ try {
1825
+ const parsed = JSON.parse(fs.readFileSync(file, 'utf8'));
1826
+ const shown = isRecord(parsed) && Array.isArray(parsed.shown) ? parsed.shown : [];
1827
+ return new Set(shown.filter((value) => typeof value === 'string'));
1828
+ }
1829
+ catch {
1830
+ return new Set();
1831
+ }
1832
+ }
1833
+ /** Record shown notices. Best-effort: a read-only `.hq/` only means the notice repeats. */
1834
+ function writeSeenNotices(file, shown) {
1835
+ if (!file)
1836
+ return;
1837
+ try {
1838
+ fs.mkdirSync(path.dirname(file), { recursive: true });
1839
+ fs.writeFileSync(file, `${JSON.stringify({ shown: [...shown].sort() }, null, 2)}\n`);
1840
+ }
1841
+ catch {
1842
+ /* the notice repeats next run; indexing is unaffected */
1843
+ }
1844
+ }
1581
1845
  export function listRegisteredCollections(hqRoot, options = {}) {
1582
1846
  const result = runQmd(['collection', 'list'], { ...options, cwd: options.cwd ?? hqRoot });
1583
1847
  return new Set([...result.stdout.matchAll(/qmd:\/\/([^/\s]+)/g)].map((match) => match[1]));
@@ -98,15 +98,26 @@ export declare function resolveIndexMaxDocBytes(opts?: {
98
98
  readFile?: (p: string) => string;
99
99
  existsFile?: (p: string) => boolean;
100
100
  }): number;
101
+ /**
102
+ * How a collection mask maps onto a size-cap walk.
103
+ *
104
+ * `prefix` is a relative directory (no glob syntax). `recursive` is true for
105
+ * `**` and false for a single-directory `*`. Unrecognised masks return `null`
106
+ * so the walk is skipped: treating them as "every file, unbounded depth"
107
+ * walked home-rooted collections and wrote hundreds of thousands of ignores.
108
+ */
109
+ export type CollectionMaskPlan = {
110
+ prefix: string;
111
+ recursive: boolean;
112
+ extensions: Set<string>;
113
+ };
114
+ export declare function parseCollectionMask(mask: string): CollectionMaskPlan | null;
101
115
  /**
102
116
  * Extensions a qmd mask selects, lowercased and without the dot.
103
117
  *
104
- * HQ registers single-extension (`**\/*.md`, `**\/*.hqcloud`) and brace-list
105
- * (`**\/*.{md,json}`) masks today (see `deriveCollections`), but an
106
- * operator's own collection may carry anything. An unrecognised mask returns
107
- * `null`, meaning "match every file" — the cap then applies to the whole
108
- * collection, which is the safe direction: we may ignore a file qmd would not
109
- * have indexed (a no-op) rather than miss one it would.
118
+ * HQ registers recursive (`**\/*.md`, `**\/*.{md,json}`) and shallow (`*.md`,
119
+ * `docs/*.md`) masks. An unrecognised mask returns `null`; callers must skip
120
+ * the size walk rather than treat that as "every file".
110
121
  */
111
122
  export declare function maskExtensions(mask: string): Set<string> | null;
112
123
  /** Injected filesystem seam, so the walk is testable without a real tree. */
@@ -174,25 +174,42 @@ function parseNonNegativeInt(value) {
174
174
  const n = Number(trimmed);
175
175
  return Number.isSafeInteger(n) ? n : null;
176
176
  }
177
+ const MASK_PREFIX_HAS_GLOB = /[\\*?[\]{}()!+@|]/;
178
+ function extensionsFromMaskGroups(brace, single) {
179
+ if (brace !== undefined) {
180
+ const exts = new Set(brace.split(",").map((ext) => ext.trim().toLowerCase()).filter(Boolean));
181
+ return exts.size > 0 ? exts : null;
182
+ }
183
+ if (single)
184
+ return new Set([single.toLowerCase()]);
185
+ return null;
186
+ }
187
+ export function parseCollectionMask(mask) {
188
+ const trimmed = mask.trim();
189
+ const recursive = /^(?:(.+?)\/)?\*\*\/\*\.(?:\{([^}]+)\}|([A-Za-z0-9]+))$/.exec(trimmed);
190
+ const shallow = recursive
191
+ ? null
192
+ : /^(?:(.+?)\/)?\*\.(?:\{([^}]+)\}|([A-Za-z0-9]+))$/.exec(trimmed);
193
+ const hit = recursive ?? shallow;
194
+ if (!hit)
195
+ return null;
196
+ const prefix = hit[1] ?? "";
197
+ if (prefix && MASK_PREFIX_HAS_GLOB.test(prefix))
198
+ return null;
199
+ const extensions = extensionsFromMaskGroups(hit[2], hit[3]);
200
+ if (!extensions)
201
+ return null;
202
+ return { prefix, recursive: recursive !== null, extensions };
203
+ }
177
204
  /**
178
205
  * Extensions a qmd mask selects, lowercased and without the dot.
179
206
  *
180
- * HQ registers single-extension (`**\/*.md`, `**\/*.hqcloud`) and brace-list
181
- * (`**\/*.{md,json}`) masks today (see `deriveCollections`), but an
182
- * operator's own collection may carry anything. An unrecognised mask returns
183
- * `null`, meaning "match every file" — the cap then applies to the whole
184
- * collection, which is the safe direction: we may ignore a file qmd would not
185
- * have indexed (a no-op) rather than miss one it would.
207
+ * HQ registers recursive (`**\/*.md`, `**\/*.{md,json}`) and shallow (`*.md`,
208
+ * `docs/*.md`) masks. An unrecognised mask returns `null`; callers must skip
209
+ * the size walk rather than treat that as "every file".
186
210
  */
187
211
  export function maskExtensions(mask) {
188
- const braced = /^\*\*\/\*\.\{([^}]+)\}$/.exec(mask);
189
- if (braced) {
190
- return new Set(braced[1].split(",").map((ext) => ext.trim().toLowerCase()).filter(Boolean));
191
- }
192
- const single = /^\*\*\/\*\.([A-Za-z0-9]+)$/.exec(mask);
193
- if (single)
194
- return new Set([single[1].toLowerCase()]);
195
- return null;
212
+ return parseCollectionMask(mask)?.extensions ?? null;
196
213
  }
197
214
  const defaultScanIo = {
198
215
  readdirSync: (directory) => fs.readdirSync(directory, { withFileTypes: true }),
@@ -238,11 +255,20 @@ export function findOversizedFiles(collectionPath, mask, maxBytes, io = defaultS
238
255
  const evaluated = new Set();
239
256
  if (maxBytes <= 0)
240
257
  return { oversized: [], evaluated, complete: true };
241
- const extensions = maskExtensions(mask);
258
+ const plan = parseCollectionMask(mask);
259
+ // Unrecognised mask: do not walk. Matching "everything" is what filled
260
+ // `*.md` collections rooted at $HOME with hundreds of thousands of ignores.
261
+ // complete:false keeps previously owned ignore entries instead of dropping them.
262
+ if (!plan)
263
+ return { oversized: [], evaluated, complete: false };
242
264
  const pruned = new Set(prunePrefixes);
243
265
  const found = [];
244
266
  let complete = true;
245
- const walk = (directory, relative) => {
267
+ const startRelative = plan.prefix;
268
+ const startDirectory = plan.prefix
269
+ ? path.join(collectionPath, ...plan.prefix.split("/"))
270
+ : collectionPath;
271
+ const walk = (directory, relative, descend) => {
246
272
  let entries;
247
273
  try {
248
274
  entries = io.readdirSync(directory);
@@ -256,20 +282,20 @@ export function findOversizedFiles(collectionPath, mask, maxBytes, io = defaultS
256
282
  continue;
257
283
  const childRelative = relative ? `${relative}/${entry.name}` : entry.name;
258
284
  if (entry.isDirectory()) {
285
+ if (!descend)
286
+ continue;
259
287
  if (EXCLUDED_DIRECTORIES.has(entry.name))
260
288
  continue;
261
289
  if (pruned.has(childRelative))
262
290
  continue;
263
- walk(path.join(directory, entry.name), childRelative);
291
+ walk(path.join(directory, entry.name), childRelative, true);
264
292
  continue;
265
293
  }
266
294
  if (!entry.isFile())
267
295
  continue;
268
- if (extensions) {
269
- const ext = path.extname(entry.name).slice(1).toLowerCase();
270
- if (!extensions.has(ext))
271
- continue;
272
- }
296
+ const ext = path.extname(entry.name).slice(1).toLowerCase();
297
+ if (!plan.extensions.has(ext))
298
+ continue;
273
299
  const literal = escapeGlobLiteral(childRelative);
274
300
  try {
275
301
  const { size } = io.statSync(path.join(directory, entry.name));
@@ -282,7 +308,7 @@ export function findOversizedFiles(collectionPath, mask, maxBytes, io = defaultS
282
308
  }
283
309
  }
284
310
  };
285
- walk(collectionPath, "");
311
+ walk(startDirectory, startRelative, plan.recursive);
286
312
  return {
287
313
  oversized: found.sort((left, right) => left.localeCompare(right)),
288
314
  evaluated,
@@ -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))
@@ -0,0 +1,79 @@
1
+ /** Every Codex feature that gives the model a tool or reaches outside the turn. */
2
+ export declare const CODEX_LOCKDOWN_DISABLED_FEATURES: readonly string[];
3
+ /**
4
+ * Config overrides (`-c`) that are not features: web search off (the value is
5
+ * checked; a wrong one fails config load), and codex's bundled skills off.
6
+ */
7
+ export declare const CODEX_LOCKDOWN_CONFIG: readonly string[];
8
+ /** `--disable <feature>` for every locked feature, then the `-c` overrides. */
9
+ export declare function codexLockdownFlags(): string[];
10
+ /**
11
+ * The only variables a locked Codex turn has. HOME is the turn's own empty
12
+ * temp dir; CODEX_HOME is the bot's own Codex login dir (./codex-login.ts),
13
+ * used in place and never copied.
14
+ */
15
+ export declare const CODEX_LOCKDOWN_ENV_ALLOWLIST: readonly string[];
16
+ /** The environment of a locked Codex turn: PATH and LANG from `base`, HOME and CODEX_HOME from `dirs`. */
17
+ export declare function codexLockdownEnv(base: NodeJS.ProcessEnv, dirs: {
18
+ home: string;
19
+ codexHome: string;
20
+ }): NodeJS.ProcessEnv;
21
+ /** The account's home from the password database, which $HOME (and so os.homedir()) can hide. Undefined when it cannot be read. */
22
+ export declare function passwdHome(): string | undefined;
23
+ /** Every home a grant must stay out of: os.homedir(), $HOME and the passwd home, without duplicates. */
24
+ export declare function lockdownHomes(env?: NodeJS.ProcessEnv, passwd?: string | undefined): string[];
25
+ /** First line of HQ's provider wrapper scripts (src/lib/install/provider-wrappers.ts). */
26
+ export declare const HQ_PROVIDER_WRAPPER_MARKER = "# hq-anywhere provider sign-in wrapper";
27
+ /** True when the file is one of HQ's provider wrapper scripts (it names the marker in its first 256 bytes). */
28
+ export declare function isHqProviderWrapper(file: string): boolean;
29
+ /**
30
+ * The real codex executable, as a realpath. A name is looked up on PATH and
31
+ * every entry that is HQ's provider wrapper, or resolves under ~/.hq, is
32
+ * walked past. A path is used as given, and refused when it is such a
33
+ * wrapper. Null when no real codex is found.
34
+ */
35
+ export declare function resolveRealCodexBinary(bin: string, envPath: string | undefined, homes: readonly string[]): string | null;
36
+ /**
37
+ * Why a read grant is unsafe, or null when it is safe. Unsafe: the filesystem
38
+ * root; a home or any parent of one; ~/.hq, anything under it or any parent
39
+ * of it; a home's dot dir (~/.codex, ~/.claude, ...) or anything under one,
40
+ * except codex's own standalone release tree (~/.codex/packages/), which
41
+ * holds no login; any other folder inside a home that is not an npm
42
+ * `@openai/codex` package root (its package.json names it), so a codex
43
+ * dropped into ~/Downloads never grants ~/Downloads; the codex login dir,
44
+ * anything inside it, or any parent of it; anything that overlaps the HQ
45
+ * root.
46
+ */
47
+ export declare function unsafeCodexGrantReason(grant: string, input: {
48
+ homes: readonly string[];
49
+ hqRoot: string;
50
+ loginDir?: string;
51
+ }): string | null;
52
+ /**
53
+ * The codex binary's own install dir from its realpath: the package root for
54
+ * an npm install (`.../@openai/codex` for `.../@openai/codex/bin/codex.js`,
55
+ * which holds the native binary under node_modules), else the binary's own
56
+ * folder, or that folder's parent when it is named `bin`.
57
+ */
58
+ export declare function codexInstallDir(realBin: string): string;
59
+ export type CodexLockdownTarget = {
60
+ ok: true;
61
+ binary: string;
62
+ installDir: string;
63
+ } | {
64
+ ok: false;
65
+ error: string;
66
+ };
67
+ /**
68
+ * Resolve the real codex and its install dir, failing closed: no real codex,
69
+ * or an install dir that is not a safe grant, is an error and no turn runs.
70
+ */
71
+ export declare function resolveCodexLockdownTarget(bin: string, input: {
72
+ envPath: string | undefined;
73
+ homes: readonly string[];
74
+ hqRoot: string;
75
+ loginDir?: string;
76
+ }): CodexLockdownTarget;
77
+ /** TOML inline table for a locked turn's permission profile: read the platform minimum, the install dir and the empty work dir; write nothing. */
78
+ export declare function codexLockdownFilesystem(installDir: string, workDir: string): string;
79
+ //# sourceMappingURL=codex-lockdown.d.ts.map