@indigoai-us/hq-cli 5.345.220 → 5.345.221

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 (138) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/dist/command-catalog.generated.d.ts +144 -2
  3. package/dist/command-catalog.generated.js +175 -2
  4. package/dist/commands/auth.js +4 -1
  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-stop-autosave.d.ts +21 -0
  10. package/dist/commands/core-stop-autosave.js +300 -0
  11. package/dist/commands/core.js +2 -0
  12. package/dist/commands/daemon.d.ts +5 -0
  13. package/dist/commands/daemon.js +31 -7
  14. package/dist/commands/doctor-usage.d.ts +5 -0
  15. package/dist/commands/doctor-usage.js +25 -0
  16. package/dist/commands/env.d.ts +49 -4
  17. package/dist/commands/env.js +355 -5
  18. package/dist/commands/lanes-shared.d.ts +3 -0
  19. package/dist/commands/lanes.d.ts +3 -0
  20. package/dist/commands/lanes.js +87 -3
  21. package/dist/commands/sources.js +3 -3
  22. package/dist/commands/sync-core.d.ts +1 -0
  23. package/dist/commands/sync-core.js +77 -3
  24. package/dist/commands/whoami.js +96 -80
  25. package/dist/lib/bot/config.d.ts +17 -0
  26. package/dist/lib/bot/config.js +13 -0
  27. package/dist/lib/bot/fleet-cron.js +24 -2
  28. package/dist/lib/bot/fleet-local.d.ts +30 -2
  29. package/dist/lib/bot/fleet-local.js +60 -1
  30. package/dist/lib/bot/grok-login-scope.d.ts +36 -0
  31. package/dist/lib/bot/grok-login-scope.js +93 -0
  32. package/dist/lib/bot/legacy-provider-login.d.ts +32 -9
  33. package/dist/lib/bot/legacy-provider-login.js +28 -22
  34. package/dist/lib/bot/runtime-sign-in-check.js +6 -1
  35. package/dist/lib/bot/runtime-sign-in.d.ts +2 -0
  36. package/dist/lib/core-utils/sentry-report.js +2 -0
  37. package/dist/lib/daemon/machine-checks.d.ts +22 -1
  38. package/dist/lib/daemon/machine-checks.js +54 -12
  39. package/dist/lib/daemon/run.js +66 -8
  40. package/dist/lib/daemon/stop-autosave-lock.d.ts +19 -0
  41. package/dist/lib/daemon/stop-autosave-lock.js +166 -0
  42. package/dist/lib/daemon/stop-autosave.d.ts +28 -0
  43. package/dist/lib/daemon/stop-autosave.js +111 -0
  44. package/dist/lib/daemon/stop-diagnostics.d.ts +11 -0
  45. package/dist/lib/daemon/stop-diagnostics.js +136 -0
  46. package/dist/lib/daemon/stop-job-executor.d.ts +19 -0
  47. package/dist/lib/daemon/stop-job-executor.js +126 -0
  48. package/dist/lib/daemon/stop-jobs.d.ts +93 -0
  49. package/dist/lib/daemon/stop-jobs.js +599 -0
  50. package/dist/lib/doctor/checks/fleet-hook-core.js +1 -1
  51. package/dist/lib/doctor/checks/host-core.js +1 -1
  52. package/dist/lib/environment/access-probes.d.ts +234 -0
  53. package/dist/lib/environment/access-probes.js +918 -0
  54. package/dist/lib/environment/profile.d.ts +15 -2
  55. package/dist/lib/environment/profile.js +55 -20
  56. package/dist/lib/environment/rfc3339.d.ts +8 -0
  57. package/dist/lib/environment/rfc3339.js +26 -0
  58. package/dist/lib/environment/work-requirements.d.ts +169 -0
  59. package/dist/lib/environment/work-requirements.js +389 -0
  60. package/dist/lib/hook-engine/coverage.d.ts +137 -7
  61. package/dist/lib/hook-engine/coverage.js +1424 -4
  62. package/dist/lib/hook-engine/fleet-registration.js +2 -2
  63. package/dist/lib/hook-engine/git-stop-config.json +513 -0
  64. package/dist/lib/hook-engine/native-stop-compatibility.json +311 -0
  65. package/dist/lib/hook-engine/reconcile.js +2 -2
  66. package/dist/lib/hot-channels/alert.d.ts +2 -2
  67. package/dist/lib/hot-channels/alert.js +8 -5
  68. package/dist/lib/hot-channels/signals-pass.d.ts +126 -17
  69. package/dist/lib/hot-channels/signals-pass.js +296 -17
  70. package/dist/lib/hot-channels/signals-runtime.d.ts +30 -0
  71. package/dist/lib/hot-channels/signals-runtime.js +82 -0
  72. package/dist/lib/install/hook-target.js +1 -1
  73. package/dist/lib/lanes/host-capacity.d.ts +26 -2
  74. package/dist/lib/lanes/host-capacity.js +17 -2
  75. package/dist/lib/lanes/host-compute.d.ts +90 -0
  76. package/dist/lib/lanes/host-compute.js +185 -0
  77. package/dist/lib/lanes/index.d.ts +2 -0
  78. package/dist/lib/lanes/index.js +1 -0
  79. package/dist/lib/lanes/reconcile.js +22 -1
  80. package/dist/lib/lanes/resource-usage.d.ts +155 -0
  81. package/dist/lib/lanes/resource-usage.js +589 -0
  82. package/dist/lib/lanes/run-size.d.ts +46 -0
  83. package/dist/lib/lanes/run-size.js +197 -0
  84. package/dist/lib/lanes/store.js +27 -0
  85. package/dist/lib/lanes/throttle.d.ts +36 -1
  86. package/dist/lib/lanes/throttle.js +47 -10
  87. package/dist/lib/lanes/types.d.ts +40 -0
  88. package/dist/lib/lanes/types.js +2 -2
  89. package/dist/lib/lanes/watcher.js +13 -4
  90. package/dist/lib/lanes/worker-process.d.ts +25 -2
  91. package/dist/lib/lanes/worker-process.js +71 -19
  92. package/dist/lib/placement/match.d.ts +192 -0
  93. package/dist/lib/placement/match.js +667 -0
  94. package/dist/lib/safe-store.d.ts +14 -0
  95. package/dist/lib/safe-store.js +77 -4
  96. package/dist/lib/search-index/index.d.ts +88 -4
  97. package/dist/lib/search-index/index.js +288 -24
  98. package/dist/lib/search-index/max-doc-bytes.d.ts +17 -6
  99. package/dist/lib/search-index/max-doc-bytes.js +48 -23
  100. package/dist/lib/signals/codex-lockdown.d.ts +79 -0
  101. package/dist/lib/signals/codex-lockdown.js +271 -0
  102. package/dist/lib/signals/codex-login.d.ts +37 -0
  103. package/dist/lib/signals/codex-login.js +83 -0
  104. package/dist/lib/signals/engine.d.ts +27 -0
  105. package/dist/lib/signals/engine.js +70 -0
  106. package/dist/lib/signals/reply.js +22 -1
  107. package/dist/lib/signals/run-record.js +6 -1
  108. package/dist/lib/signals/settings.d.ts +5 -0
  109. package/dist/lib/signals/settings.js +2 -0
  110. package/dist/lib/signals/steps/extract.d.ts +85 -9
  111. package/dist/lib/signals/steps/extract.js +317 -68
  112. package/dist/lib/signals/steps/types.d.ts +2 -0
  113. package/dist/lib/sync-core/engine-home.d.ts +35 -1
  114. package/dist/lib/sync-core/engine-home.js +119 -16
  115. package/dist/lib/sync-core/rollout-state.d.ts +2 -1
  116. package/dist/lib/sync-core/rollout-state.js +5 -2
  117. package/dist/lib/sync-core/vault-uid.d.ts +2 -0
  118. package/dist/lib/sync-core/vault-uid.js +4 -0
  119. package/dist/schemas/hq-work-requirements.v1.schema.json +145 -0
  120. package/dist/utils/auth-session-check.d.ts +16 -0
  121. package/dist/utils/auth-session-check.js +16 -0
  122. package/dist/utils/client-health-contract.d.ts +6 -0
  123. package/dist/utils/client-health-contract.js +13 -0
  124. package/dist/utils/client-health.d.ts +7 -0
  125. package/dist/utils/client-health.js +22 -1
  126. package/dist/utils/command-usage.d.ts +40 -0
  127. package/dist/utils/command-usage.js +61 -0
  128. package/dist/utils/duplicate-command-usage.d.ts +72 -0
  129. package/dist/utils/duplicate-command-usage.js +125 -0
  130. package/dist/utils/host-registration.js +2 -1
  131. package/dist/utils/resident-package-preload.js +4 -0
  132. package/dist/utils/sentry-fingerprint.js +9 -0
  133. package/dist/utils/windows-bash.d.ts +2 -0
  134. package/dist/utils/windows-bash.js +2 -1
  135. package/package.json +9 -8
  136. package/scripts/bench-core-compare.mjs +313 -0
  137. package/scripts/bench-core.mjs +399 -12
  138. package/scripts/check-function-manifest.mjs +116 -3
@@ -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,19 @@ 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
+ if (!plan)
262
+ return { oversized: [], evaluated, complete: true };
242
263
  const pruned = new Set(prunePrefixes);
243
264
  const found = [];
244
265
  let complete = true;
245
- const walk = (directory, relative) => {
266
+ const startRelative = plan.prefix;
267
+ const startDirectory = plan.prefix
268
+ ? path.join(collectionPath, ...plan.prefix.split("/"))
269
+ : collectionPath;
270
+ const walk = (directory, relative, descend) => {
246
271
  let entries;
247
272
  try {
248
273
  entries = io.readdirSync(directory);
@@ -256,20 +281,20 @@ export function findOversizedFiles(collectionPath, mask, maxBytes, io = defaultS
256
281
  continue;
257
282
  const childRelative = relative ? `${relative}/${entry.name}` : entry.name;
258
283
  if (entry.isDirectory()) {
284
+ if (!descend)
285
+ continue;
259
286
  if (EXCLUDED_DIRECTORIES.has(entry.name))
260
287
  continue;
261
288
  if (pruned.has(childRelative))
262
289
  continue;
263
- walk(path.join(directory, entry.name), childRelative);
290
+ walk(path.join(directory, entry.name), childRelative, true);
264
291
  continue;
265
292
  }
266
293
  if (!entry.isFile())
267
294
  continue;
268
- if (extensions) {
269
- const ext = path.extname(entry.name).slice(1).toLowerCase();
270
- if (!extensions.has(ext))
271
- continue;
272
- }
295
+ const ext = path.extname(entry.name).slice(1).toLowerCase();
296
+ if (!plan.extensions.has(ext))
297
+ continue;
273
298
  const literal = escapeGlobLiteral(childRelative);
274
299
  try {
275
300
  const { size } = io.statSync(path.join(directory, entry.name));
@@ -282,7 +307,7 @@ export function findOversizedFiles(collectionPath, mask, maxBytes, io = defaultS
282
307
  }
283
308
  }
284
309
  };
285
- walk(collectionPath, "");
310
+ walk(startDirectory, startRelative, plan.recursive);
286
311
  return {
287
312
  oversized: found.sort((left, right) => left.localeCompare(right)),
288
313
  evaluated,
@@ -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
@@ -0,0 +1,271 @@
1
+ /**
2
+ * Lockdown for a Codex turn that reads untrusted text (a meeting transcript,
3
+ * a Slack message) and must not run anything: the signals extract step, and
4
+ * the hot-channel signals pass once it rebases onto this module.
5
+ *
6
+ * The turn's sandbox reads only codex's platform minimum (:minimal: system
7
+ * paths such as /usr, /System, /etc, /Library/Preferences), the codex
8
+ * install and an empty temp dir, writes nothing and has no network. It
9
+ * inherits only PATH and LANG from the parent; HOME is an empty temp dir and
10
+ * CODEX_HOME is the bot's own login dir (./codex-login.ts), which the codex
11
+ * process itself reads and refreshes outside the sandbox. The real codex
12
+ * binary is found by walking PATH past HQ's provider wrappers
13
+ * (~/.hq/bin/codex), so the read grant can never become ~/.hq.
14
+ *
15
+ * Feature names come from `codex features list` on codex-cli 0.169.0 (the
16
+ * HQ desktop toolchain's codex) and were checked against 0.167.1. Both
17
+ * versions accept every name here; an unknown name is a hard error
18
+ * ("Unknown feature flag"), so a codex that dropped one refuses to start
19
+ * instead of running with the feature on. `codex debug prompt-input` on
20
+ * 0.169.0, run with these flags from an empty dir, lists no shell, file,
21
+ * image, browser, app, plugin, MCP, skill or web tool; codex still lists
22
+ * its own code-mode `exec` wrapper, `wait`, `request_user_input` and the
23
+ * `collaboration` sub-agent tools, which no flag or config key of that
24
+ * version removes. The sandbox grant below is what bounds those.
25
+ */
26
+ import * as fs from "node:fs";
27
+ import * as os from "node:os";
28
+ import * as path from "node:path";
29
+ /** Every Codex feature that gives the model a tool or reaches outside the turn. */
30
+ export const CODEX_LOCKDOWN_DISABLED_FEATURES = [
31
+ "shell_tool",
32
+ "unified_exec",
33
+ "shell_snapshot",
34
+ "apps",
35
+ "plugins",
36
+ "remote_plugin",
37
+ "plugin_sharing",
38
+ "hooks",
39
+ "multi_agent",
40
+ "multi_agent_v2",
41
+ "browser_use",
42
+ "browser_use_external",
43
+ "browser_use_full_cdp_access",
44
+ "browser_annotation_api",
45
+ "in_app_browser",
46
+ "in_app_local_automation",
47
+ "computer_use",
48
+ "image_generation",
49
+ "view_image",
50
+ "skill_search",
51
+ "skill_mcp_dependency_install",
52
+ "tool_suggest",
53
+ "tool_call_mcp_elicitation",
54
+ "memories",
55
+ "sleep_tool",
56
+ "goals",
57
+ "code_mode_host",
58
+ "workspace_dependencies",
59
+ ];
60
+ /**
61
+ * Config overrides (`-c`) that are not features: web search off (the value is
62
+ * checked; a wrong one fails config load), and codex's bundled skills off.
63
+ */
64
+ export const CODEX_LOCKDOWN_CONFIG = ['web_search="disabled"', "skills.bundled.enabled=false"];
65
+ /** `--disable <feature>` for every locked feature, then the `-c` overrides. */
66
+ export function codexLockdownFlags() {
67
+ return [
68
+ ...CODEX_LOCKDOWN_DISABLED_FEATURES.flatMap((feature) => ["--disable", feature]),
69
+ ...CODEX_LOCKDOWN_CONFIG.flatMap((value) => ["-c", value]),
70
+ ];
71
+ }
72
+ /**
73
+ * The only variables a locked Codex turn has. HOME is the turn's own empty
74
+ * temp dir; CODEX_HOME is the bot's own Codex login dir (./codex-login.ts),
75
+ * used in place and never copied.
76
+ */
77
+ export const CODEX_LOCKDOWN_ENV_ALLOWLIST = ["PATH", "HOME", "CODEX_HOME", "LANG"];
78
+ /** The environment of a locked Codex turn: PATH and LANG from `base`, HOME and CODEX_HOME from `dirs`. */
79
+ export function codexLockdownEnv(base, dirs) {
80
+ return {
81
+ ...(base.PATH !== undefined ? { PATH: base.PATH } : {}),
82
+ HOME: dirs.home,
83
+ CODEX_HOME: dirs.codexHome,
84
+ ...(base.LANG !== undefined ? { LANG: base.LANG } : {}),
85
+ };
86
+ }
87
+ /** The account's home from the password database, which $HOME (and so os.homedir()) can hide. Undefined when it cannot be read. */
88
+ export function passwdHome() {
89
+ try {
90
+ const home = os.userInfo().homedir;
91
+ return home && home.trim() ? home : undefined;
92
+ }
93
+ catch {
94
+ return undefined;
95
+ }
96
+ }
97
+ /** Every home a grant must stay out of: os.homedir(), $HOME and the passwd home, without duplicates. */
98
+ export function lockdownHomes(env = process.env, passwd = passwdHome()) {
99
+ return [...new Set([os.homedir(), env.HOME, passwd].filter((h) => typeof h === "string" && h.trim() !== ""))];
100
+ }
101
+ /** First line of HQ's provider wrapper scripts (src/lib/install/provider-wrappers.ts). */
102
+ export const HQ_PROVIDER_WRAPPER_MARKER = "# hq-anywhere provider sign-in wrapper";
103
+ function realpathOrNull(p) {
104
+ try {
105
+ return fs.realpathSync(p);
106
+ }
107
+ catch {
108
+ return null;
109
+ }
110
+ }
111
+ function isUnder(child, parent) {
112
+ return child === parent || child.startsWith(parent.endsWith(path.sep) ? parent : parent + path.sep);
113
+ }
114
+ /** True when the file is one of HQ's provider wrapper scripts (it names the marker in its first 256 bytes). */
115
+ export function isHqProviderWrapper(file) {
116
+ let fd;
117
+ try {
118
+ fd = fs.openSync(file, "r");
119
+ const buf = Buffer.alloc(256);
120
+ const n = fs.readSync(fd, buf, 0, buf.length, 0);
121
+ return buf.subarray(0, n).toString("utf8").includes(HQ_PROVIDER_WRAPPER_MARKER);
122
+ }
123
+ catch {
124
+ return false;
125
+ }
126
+ finally {
127
+ if (fd !== undefined)
128
+ fs.closeSync(fd);
129
+ }
130
+ }
131
+ /** Every real form of each home: as given and through links. */
132
+ function homeForms(homes) {
133
+ const out = new Set();
134
+ for (const h of homes) {
135
+ if (!h)
136
+ continue;
137
+ out.add(path.resolve(h));
138
+ const real = realpathOrNull(h);
139
+ if (real)
140
+ out.add(real);
141
+ }
142
+ return [...out];
143
+ }
144
+ /** The real path of an executable, or null when it is HQ's wrapper, lives under ~/.hq, or is not executable. */
145
+ function realExecutable(candidate, homes) {
146
+ try {
147
+ fs.accessSync(candidate, fs.constants.X_OK);
148
+ }
149
+ catch {
150
+ return null;
151
+ }
152
+ const real = realpathOrNull(candidate);
153
+ if (!real)
154
+ return null;
155
+ for (const h of homeForms(homes))
156
+ if (isUnder(real, path.join(h, ".hq")))
157
+ return null;
158
+ if (isHqProviderWrapper(candidate) || isHqProviderWrapper(real))
159
+ return null;
160
+ return real;
161
+ }
162
+ /**
163
+ * The real codex executable, as a realpath. A name is looked up on PATH and
164
+ * every entry that is HQ's provider wrapper, or resolves under ~/.hq, is
165
+ * walked past. A path is used as given, and refused when it is such a
166
+ * wrapper. Null when no real codex is found.
167
+ */
168
+ export function resolveRealCodexBinary(bin, envPath, homes) {
169
+ if (bin.includes("/"))
170
+ return realExecutable(path.resolve(bin), homes);
171
+ for (const dir of (envPath ?? "").split(path.delimiter)) {
172
+ if (!dir || !path.isAbsolute(dir))
173
+ continue;
174
+ const real = realExecutable(path.join(dir, bin), homes);
175
+ if (real)
176
+ return real;
177
+ }
178
+ return null;
179
+ }
180
+ /**
181
+ * Why a read grant is unsafe, or null when it is safe. Unsafe: the filesystem
182
+ * root; a home or any parent of one; ~/.hq, anything under it or any parent
183
+ * of it; a home's dot dir (~/.codex, ~/.claude, ...) or anything under one,
184
+ * except codex's own standalone release tree (~/.codex/packages/), which
185
+ * holds no login; any other folder inside a home that is not an npm
186
+ * `@openai/codex` package root (its package.json names it), so a codex
187
+ * dropped into ~/Downloads never grants ~/Downloads; the codex login dir,
188
+ * anything inside it, or any parent of it; anything that overlaps the HQ
189
+ * root.
190
+ */
191
+ export function unsafeCodexGrantReason(grant, input) {
192
+ const g = realpathOrNull(grant) ?? path.resolve(grant);
193
+ if (g === path.parse(g).root)
194
+ return "it is the filesystem root";
195
+ const hq = realpathOrNull(input.hqRoot) ?? path.resolve(input.hqRoot);
196
+ if (isUnder(g, hq) || isUnder(hq, g))
197
+ return "it overlaps the HQ root";
198
+ for (const h of homeForms(input.homes)) {
199
+ if (isUnder(h, g))
200
+ return "it is a home folder or contains one";
201
+ const hqDir = path.join(h, ".hq");
202
+ if (isUnder(g, hqDir) || isUnder(hqDir, g))
203
+ return "it is ~/.hq, inside it, or contains it";
204
+ if (isUnder(g, h)) {
205
+ const parts = path.relative(h, g).split(path.sep);
206
+ const standalone = parts[0] === ".codex" && parts[1] === "packages" && parts.length > 2;
207
+ if ((parts[0] ?? "").startsWith(".") && !standalone)
208
+ return `it is inside ${path.join("~", parts[0] ?? "")}`;
209
+ // A first-level folder (~/Downloads, ~/tools) is never a grant, package.json or not.
210
+ if (parts.length === 1)
211
+ return "it is a folder directly in a home";
212
+ if (!standalone && !isCodexPackageRoot(g))
213
+ return "it is a plain folder in a home, not a codex package";
214
+ }
215
+ }
216
+ if (input.loginDir) {
217
+ for (const d of [path.resolve(input.loginDir), realpathOrNull(input.loginDir)]) {
218
+ if (d && (isUnder(d, g) || isUnder(g, d)))
219
+ return "it is the codex login folder, inside it, or contains it";
220
+ }
221
+ }
222
+ return null;
223
+ }
224
+ /**
225
+ * True when the folder is an npm `@openai/codex` package root: its
226
+ * package.json names `@openai/codex`, and it holds the native build codex
227
+ * ships with, `node_modules/@openai/codex-<platform>/vendor/`.
228
+ */
229
+ function isCodexPackageRoot(dir) {
230
+ try {
231
+ const pkg = JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8"));
232
+ if (pkg.name !== "@openai/codex")
233
+ return false;
234
+ const scope = path.join(dir, "node_modules", "@openai");
235
+ return fs.readdirSync(scope).some((e) => e.startsWith("codex-") && fs.statSync(path.join(scope, e, "vendor"), { throwIfNoEntry: false })?.isDirectory() === true);
236
+ }
237
+ catch {
238
+ return false;
239
+ }
240
+ }
241
+ /**
242
+ * The codex binary's own install dir from its realpath: the package root for
243
+ * an npm install (`.../@openai/codex` for `.../@openai/codex/bin/codex.js`,
244
+ * which holds the native binary under node_modules), else the binary's own
245
+ * folder, or that folder's parent when it is named `bin`.
246
+ */
247
+ export function codexInstallDir(realBin) {
248
+ const own = path.dirname(realBin);
249
+ return path.basename(own) === "bin" ? path.dirname(own) : own;
250
+ }
251
+ /**
252
+ * Resolve the real codex and its install dir, failing closed: no real codex,
253
+ * or an install dir that is not a safe grant, is an error and no turn runs.
254
+ */
255
+ export function resolveCodexLockdownTarget(bin, input) {
256
+ const binary = resolveRealCodexBinary(bin, input.envPath, input.homes);
257
+ if (!binary) {
258
+ return { ok: false, error: `codex install could not be resolved safely: no real codex binary found for '${bin}' outside ~/.hq and HQ's provider wrappers` };
259
+ }
260
+ const installDir = codexInstallDir(binary);
261
+ const unsafe = unsafeCodexGrantReason(installDir, input);
262
+ if (unsafe)
263
+ return { ok: false, error: `codex install could not be resolved safely: ${installDir} cannot be granted (${unsafe})` };
264
+ return { ok: true, binary, installDir };
265
+ }
266
+ /** TOML inline table for a locked turn's permission profile: read the platform minimum, the install dir and the empty work dir; write nothing. */
267
+ export function codexLockdownFilesystem(installDir, workDir) {
268
+ const entries = [[":minimal", "read"], [installDir, "read"], [workDir, "read"]];
269
+ return `{${entries.map(([k, v]) => `${JSON.stringify(k)}=${JSON.stringify(v)}`).join(",")}}`;
270
+ }
271
+ //# sourceMappingURL=codex-lockdown.js.map
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Which Codex login a signals Codex turn may use for a bot, and the
3
+ * environment that points Codex at it. Self-contained (no signals-pass or
4
+ * hot-channel imports) so every signals Codex path can share it.
5
+ *
6
+ * Policy: the turn runs with CODEX_HOME set to the bot's own Codex login
7
+ * dir, in place. Nothing copies the login, so nothing writes it back: Codex
8
+ * refreshes it under its own lock, as it does for the bot's own turns, and a
9
+ * refresh-token rotation can never leave a stale copy behind or race a
10
+ * write-back.
11
+ *
12
+ * Refused:
13
+ * - an HQ Fleet Runtime bot: its Codex login lives in the Fleet runtime's
14
+ * profile, and the Fleet helper offers only login, status and logout, with
15
+ * no lock-respecting way to lend it to a separate codex process;
16
+ * - a bot on the owner's personal login (no CODEX_HOME, or the owner's
17
+ * ~/.codex), which other Codex processes on this computer refresh too;
18
+ * - a bot with no Codex login setting, whose CODEX_HOME would come from the
19
+ * caller's environment rather than from the bot.
20
+ */
21
+ import type { BotConfig } from "../bot/config.js";
22
+ /** The login a signals Codex turn uses for a bot, or why it has none it may use. */
23
+ export type SignalsCodexLogin = {
24
+ ok: true;
25
+ codexHome: string;
26
+ env: NodeJS.ProcessEnv;
27
+ } | {
28
+ ok: false;
29
+ reason: string;
30
+ };
31
+ /**
32
+ * The bot's own Codex login dir (botAuthEnv: `hq bot login <name> --runtime
33
+ * codex`, or a capacity account), with the environment that points Codex at
34
+ * it, or the reason it may not be used.
35
+ */
36
+ export declare function signalsCodexLogin(dir: string, config: Pick<BotConfig, "name" | "runtime" | "runtimeAuth" | "hqRoot" | "engine">, base?: NodeJS.ProcessEnv, ownerHome?: string): SignalsCodexLogin;
37
+ //# sourceMappingURL=codex-login.d.ts.map
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Which Codex login a signals Codex turn may use for a bot, and the
3
+ * environment that points Codex at it. Self-contained (no signals-pass or
4
+ * hot-channel imports) so every signals Codex path can share it.
5
+ *
6
+ * Policy: the turn runs with CODEX_HOME set to the bot's own Codex login
7
+ * dir, in place. Nothing copies the login, so nothing writes it back: Codex
8
+ * refreshes it under its own lock, as it does for the bot's own turns, and a
9
+ * refresh-token rotation can never leave a stale copy behind or race a
10
+ * write-back.
11
+ *
12
+ * Refused:
13
+ * - an HQ Fleet Runtime bot: its Codex login lives in the Fleet runtime's
14
+ * profile, and the Fleet helper offers only login, status and logout, with
15
+ * no lock-respecting way to lend it to a separate codex process;
16
+ * - a bot on the owner's personal login (no CODEX_HOME, or the owner's
17
+ * ~/.codex), which other Codex processes on this computer refresh too;
18
+ * - a bot with no Codex login setting, whose CODEX_HOME would come from the
19
+ * caller's environment rather than from the bot.
20
+ */
21
+ import * as fs from "node:fs";
22
+ import * as os from "node:os";
23
+ import * as path from "node:path";
24
+ import { botAuthEnv, botRuntimeAuth } from "../bot/runtime-auth.js";
25
+ import { diagnosticsEnabled } from "../diagnostics.js";
26
+ function realpathOr(p) {
27
+ try {
28
+ return fs.realpathSync(p);
29
+ }
30
+ catch {
31
+ return path.resolve(p);
32
+ }
33
+ }
34
+ /**
35
+ * The bot's own Codex login dir (botAuthEnv: `hq bot login <name> --runtime
36
+ * codex`, or a capacity account), with the environment that points Codex at
37
+ * it, or the reason it may not be used.
38
+ */
39
+ export function signalsCodexLogin(dir, config, base = process.env, ownerHome = os.homedir()) {
40
+ if (config.runtime !== "codex")
41
+ return { ok: false, reason: `${config.name} does not run on Codex` };
42
+ if (config.engine !== undefined) {
43
+ return {
44
+ ok: false,
45
+ reason: `${config.name} runs on the HQ Fleet Runtime, which keeps its Codex login to itself, so signals cannot use it yet`,
46
+ };
47
+ }
48
+ let env;
49
+ try {
50
+ env = botAuthEnv(dir, config, base);
51
+ }
52
+ catch (err) {
53
+ // botAuthEnv's own refusals are plain sentences that name the fix; any
54
+ // other error (a file or parse error) is shown as a fixed sentence, with
55
+ // the detail only under --verbose or HQ_DEBUG.
56
+ if (err instanceof Error && err.expected === true)
57
+ return { ok: false, reason: err.message };
58
+ if (diagnosticsEnabled(base))
59
+ process.stderr.write(`[hq signals] codex login lookup for ${config.name} failed: ${err instanceof Error ? err.message : String(err)}\n`);
60
+ return {
61
+ ok: false,
62
+ reason: `${config.name}'s Codex login could not be read. Sign it in again with: \`hq bot login ${config.name} --runtime codex\``,
63
+ };
64
+ }
65
+ // A bot with no Codex login setting gets the caller's environment back,
66
+ // so its CODEX_HOME would be whatever the caller had, not the bot's own.
67
+ if (!botRuntimeAuth(config, "codex")) {
68
+ return {
69
+ ok: false,
70
+ reason: `${config.name} has no Codex login of its own. Give it one first: \`hq bot login ${config.name} --runtime codex\``,
71
+ };
72
+ }
73
+ const codexHome = env.CODEX_HOME?.trim();
74
+ const personal = [ownerHome, base.HOME].filter((h) => !!h?.trim()).map((h) => realpathOr(path.join(h, ".codex")));
75
+ if (!codexHome || personal.includes(realpathOr(codexHome))) {
76
+ return {
77
+ ok: false,
78
+ reason: `${config.name} uses your personal Codex login. Give it its own first: \`hq bot login ${config.name} --runtime codex\``,
79
+ };
80
+ }
81
+ return { ok: true, codexHome, env };
82
+ }
83
+ //# sourceMappingURL=codex-login.js.map
@@ -89,6 +89,21 @@ export interface RunRecord {
89
89
  signalsOut: number;
90
90
  };
91
91
  lockTakeover?: LockTakeover;
92
+ /**
93
+ * PS-011 placement facts, set on every finished record this CLI writes.
94
+ * Absent on records written before PS-011. host_id is the machine's
95
+ * canonical host id (the id lane placement uses); engine is the runtime the
96
+ * extract step ran (claude, codex, grok), null when no model turn ran;
97
+ * account is the login that runtime used ("default" for the user's own
98
+ * Claude or Grok login, the CLAUDE_CONFIG_DIR folder name when set, or
99
+ * "custom" when that name holds @, / or a backslash,
100
+ * "bot:<name>" for the Executive bot's Codex login); duration_seconds is
101
+ * finishedAt minus startedAt.
102
+ */
103
+ host_id?: string | null;
104
+ engine?: string | null;
105
+ account?: string | null;
106
+ duration_seconds?: number | null;
92
107
  }
93
108
  /** A company another run is holding the lock for. Nothing was started for it. */
94
109
  export interface LockedCompany {
@@ -176,7 +191,19 @@ export interface RunSignalsOptions {
176
191
  * channel. Needs `company`.
177
192
  */
178
193
  redo?: readonly string[];
194
+ /** PS-011 placement facts. Defaults: this machine's canonical host id and the engine's login. */
195
+ placement?: SignalsPlacementDeps;
196
+ }
197
+ export interface SignalsPlacementDeps {
198
+ hostId?: () => string | null;
199
+ account?: (engine: string) => string | null;
179
200
  }
201
+ /** The runtime the record's extract step ran, or null when no extract turn ran. */
202
+ export declare function signalsRunEngine(record: Pick<RunRecord, "steps">, incremental: boolean): string | null;
203
+ /** The login an engine's extract turn uses, named without paths or e-mail addresses. */
204
+ export declare function defaultSignalsAccount(engine: string, env?: NodeJS.ProcessEnv, resolveBotName?: () => string | null): string | null;
205
+ /** Sets host_id, engine, account and duration_seconds on a finished record (PS-011). */
206
+ export declare function stampRunPlacement(record: RunRecord, deps: SignalsPlacementDeps, incremental: boolean): void;
180
207
  /** Bad input from the caller (company slug, missing company): exit 2. */
181
208
  export declare class SignalsUsageError extends Error {
182
209
  constructor(message: string);