@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
@@ -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);
@@ -23,12 +23,77 @@ import { extractStep, redoItemChannel } from "./steps/extract.js";
23
23
  import { uploadStep } from "./steps/upload.js";
24
24
  import { SIGNALS_RUN_ALERT_ADAPTER, raiseSignalsRunAlerts, resolveSignedInAlertPerson, } from "./failure-alert.js";
25
25
  import { signalsAlertKey, signalsAlertStatePath } from "../hot-channels/alert.js";
26
+ import { canonicalHostIdHere } from "../lanes/run-size.js";
27
+ import { resolveExecutiveBot } from "../bot/executive.js";
28
+ import { botsRoot } from "../bot/paths.js";
26
29
  export const SIGNALS_TRIGGERS = ["job", "chat", "manual", "brief"];
27
30
  export const SIGNALS_STEP_CHOICES = ["garden", "extract", "adapters", "upload", "all"];
28
31
  export const STEP_ORDER = ["garden", "adapters", "extract", "garden", "upload"];
29
32
  export const RUN_RECORD_SCHEMA_VERSION = 2;
30
33
  /** A failed run with a transient error is due for a retry this long after it finished. */
31
34
  export const RETRY_DELAY_MS = 15 * 60 * 1000;
35
+ /** The runtime the record's extract step ran, or null when no extract turn ran. */
36
+ export function signalsRunEngine(record, incremental) {
37
+ const extract = [...record.steps].reverse().find((s) => s.name === "extract" && s.status !== "skipped");
38
+ if (!extract)
39
+ return null;
40
+ const runtime = extract.detail?.runtime;
41
+ if (typeof runtime === "string" && runtime.trim() !== "")
42
+ return runtime;
43
+ // The incremental (single growing source) extract always runs claude.
44
+ return incremental ? "claude" : null;
45
+ }
46
+ /** The login an engine's extract turn uses, named without paths or e-mail addresses. */
47
+ export function defaultSignalsAccount(engine, env = process.env, resolveBotName = () => resolveExecutiveBot({ root: botsRoot() })?.name ?? null) {
48
+ if (engine === "claude") {
49
+ const dir = env.CLAUDE_CONFIG_DIR?.trim();
50
+ if (!dir)
51
+ return "default";
52
+ const name = path.basename(dir);
53
+ // A folder named after an e-mail address, or one path.basename cannot
54
+ // split (a backslash path), is not a safe label to store.
55
+ return !name || /[@/\\]/.test(name) ? "custom" : name;
56
+ }
57
+ if (engine === "codex") {
58
+ try {
59
+ const name = resolveBotName();
60
+ return name ? "bot:" + name : null;
61
+ }
62
+ catch {
63
+ return null;
64
+ }
65
+ }
66
+ if (engine === "grok")
67
+ return "default";
68
+ return null;
69
+ }
70
+ /** Sets host_id, engine, account and duration_seconds on a finished record (PS-011). */
71
+ export function stampRunPlacement(record, deps, incremental) {
72
+ let hostId;
73
+ try {
74
+ hostId = (deps.hostId ?? (() => canonicalHostIdHere()))();
75
+ }
76
+ catch {
77
+ hostId = null;
78
+ }
79
+ const engine = signalsRunEngine(record, incremental);
80
+ let account = null;
81
+ if (engine) {
82
+ try {
83
+ account = (deps.account ?? ((e) => defaultSignalsAccount(e)))(engine);
84
+ }
85
+ catch {
86
+ account = null;
87
+ }
88
+ }
89
+ const started = Date.parse(record.startedAt);
90
+ const finished = record.finishedAt === null ? NaN : Date.parse(record.finishedAt);
91
+ record.host_id = hostId;
92
+ record.engine = engine;
93
+ record.account = account;
94
+ record.duration_seconds =
95
+ Number.isFinite(started) && Number.isFinite(finished) ? Math.round(Math.max(0, finished - started) / 100) / 10 : null;
96
+ }
32
97
  /** Bad input from the caller (company slug, missing company): exit 2. */
33
98
  export class SignalsUsageError extends Error {
34
99
  constructor(message) {
@@ -354,6 +419,7 @@ export async function runSignals(opts) {
354
419
  }
355
420
  return;
356
421
  }
422
+ stampRunPlacement(record, opts.placement ?? {}, opts.incremental === true);
357
423
  persist();
358
424
  updateSummaryFile(hqRoot, date, record, record.finishedAt ?? now().toISOString());
359
425
  };
@@ -402,6 +468,7 @@ export async function runSignals(opts) {
402
468
  record.failureReason = sentence(err.message.charAt(0).toUpperCase() + err.message.slice(1));
403
469
  record.nextRetryAt = null;
404
470
  if (!dryRun) {
471
+ stampRunPlacement(record, opts.placement ?? {}, opts.incremental === true);
405
472
  persist();
406
473
  updateSummaryFile(hqRoot, date, record, record.finishedAt ?? now().toISOString());
407
474
  }
@@ -433,6 +500,7 @@ export async function runSignals(opts) {
433
500
  catchUp: record.catchUp,
434
501
  maxTurns,
435
502
  maxBudgetUsd,
503
+ unpricedSourceEstimateUsd: settings.unpricedSourceEstimateUsd,
436
504
  now,
437
505
  spawn,
438
506
  write,
@@ -511,6 +579,8 @@ export async function runSignals(opts) {
511
579
  record.nextRetryAt =
512
580
  record.errorKind === "transient" ? new Date(new Date(record.finishedAt).getTime() + RETRY_DELAY_MS).toISOString() : null;
513
581
  try {
582
+ if (!dryRun)
583
+ stampRunPlacement(record, opts.placement ?? {}, opts.incremental === true);
514
584
  persist();
515
585
  }
516
586
  catch {
@@ -169,13 +169,29 @@ function spendBlock(record) {
169
169
  return null;
170
170
  const spend = spendUsd(record);
171
171
  const value = Math.max(0, Math.min(100, Math.round((spend / record.maxBudgetUsd) * 100)));
172
+ // Some coding tools report no cost; the step then counts a flat amount per source. Say it is an estimate.
173
+ const estimated = record.steps.some((s) => s.detail?.spendEstimated === true);
172
174
  return {
173
175
  kind: "progress",
174
176
  value,
175
- label: `Spend $${spend.toFixed(2)} of the $${record.maxBudgetUsd.toFixed(2)} cap`,
177
+ label: `${estimated ? "Estimated spend" : "Spend"} $${spend.toFixed(2)} of the $${record.maxBudgetUsd.toFixed(2)} cap`,
176
178
  tone: "neutral",
177
179
  };
178
180
  }
181
+ /**
182
+ * A run that stopped at the spend cap on estimated spend, in plain words:
183
+ * how many sources were processed, how many are left, and what controls it.
184
+ * Null for any other outcome.
185
+ */
186
+ function estimatedBudgetStop(record) {
187
+ const step = record.steps.find((s) => s.error === "budget-exceeded" && s.detail?.spendEstimated === true && typeof s.detail.sourcesProcessed === "number");
188
+ const d = step?.detail;
189
+ if (!d)
190
+ return null;
191
+ const each = typeof d.unpricedSourceEstimateUsd === "number" ? `$${d.unpricedSourceEstimateUsd.toFixed(2)}` : "a set amount";
192
+ const left = typeof d.sourcesLeft === "number" && d.sourcesLeft > 0 ? `, with at least ${plural(d.sourcesLeft, "source")} left for the next run` : "";
193
+ return `Signals stopped at the $${record.maxBudgetUsd.toFixed(2)} spend cap after ${plural(d.sourcesProcessed, "source")}${left}. The spend is an estimate: this coding tool does not report its cost, so each source counts as ${each}. To process more in one run, raise the cap with --max-budget-usd.`;
194
+ }
179
195
  /**
180
196
  * The non-desktop brief decision. It says the brief builds next only when a
181
197
  * brief job is known to be scheduled; otherwise it asks.
@@ -237,6 +253,11 @@ function raiseCapLine(record) {
237
253
  * that the rest waits for the next run, and how to raise the cap for a run.
238
254
  */
239
255
  function budgetGuidance(record, stopped) {
256
+ // Estimated spend has its own sentence (counts and the per-source amount).
257
+ // A metered stop still names the source it stopped at.
258
+ const estimated = estimatedBudgetStop(record);
259
+ if (estimated)
260
+ return estimated;
240
261
  const raw = stopped.detail?.budgetStoppedAt;
241
262
  const at = typeof raw === "string" && raw.trim() ? raw.trim() : null;
242
263
  const cap = capInWords(record);
@@ -68,7 +68,12 @@ export function isRunRecord(v) {
68
68
  strOrNull(v.partial) &&
69
69
  typeof v.alreadyRanToday === "boolean" &&
70
70
  isCounts(v.counts) &&
71
- optional(v.lockTakeover, isObj);
71
+ optional(v.lockTakeover, isObj) &&
72
+ // PS-011 placement facts: absent on older records.
73
+ optional(v.host_id, strOrNull) &&
74
+ optional(v.engine, strOrNull) &&
75
+ optional(v.account, strOrNull) &&
76
+ optional(v.duration_seconds, (x) => x === null || (isNum(x) && x >= 0));
72
77
  if (!shape)
73
78
  return false;
74
79
  // Contract invariants: finishedAt is null exactly while running, and the
@@ -3,6 +3,11 @@ export interface SignalsSettings {
3
3
  maxBudgetUsd: number;
4
4
  lateStartHour: number;
5
5
  briefWaitMinutes: number;
6
+ /**
7
+ * What one source counts as against maxBudgetUsd when the coding tool reports
8
+ * no cost for it (Codex always, Grok sometimes). 0 turns the charge off.
9
+ */
10
+ unpricedSourceEstimateUsd: number;
6
11
  }
7
12
  export declare const DEFAULT_SIGNALS_SETTINGS: SignalsSettings;
8
13
  export declare const SIGNALS_SETTINGS_REL: string;
@@ -7,6 +7,7 @@ export const DEFAULT_SIGNALS_SETTINGS = {
7
7
  maxBudgetUsd: 2.0,
8
8
  lateStartHour: 22,
9
9
  briefWaitMinutes: 20,
10
+ unpricedSourceEstimateUsd: 0.1,
10
11
  };
11
12
  /** maxTurns: whole number >= 1. lateStartHour: whole hour 1-24 (0 would make every job late; 24 turns it off). */
12
13
  const VALID = {
@@ -14,6 +15,7 @@ const VALID = {
14
15
  maxBudgetUsd: (v) => Number.isFinite(v) && v >= 0,
15
16
  lateStartHour: (v) => Number.isInteger(v) && v >= 1 && v <= 24,
16
17
  briefWaitMinutes: (v) => Number.isFinite(v) && v >= 0,
18
+ unpricedSourceEstimateUsd: (v) => Number.isFinite(v) && v >= 0,
17
19
  };
18
20
  export const SIGNALS_SETTINGS_REL = path.join("core", "settings", "signals.yaml");
19
21
  export function loadSignalsSettings(hqRoot) {