@indigoai-us/hq-cli 5.345.219 → 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 (199) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/dist/command-catalog.generated.d.ts +169 -3
  3. package/dist/command-catalog.generated.js +206 -3
  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 +85 -0
  8. package/dist/commands/bot.js +245 -16
  9. package/dist/commands/cloud.d.ts +16 -0
  10. package/dist/commands/cloud.js +112 -102
  11. package/dist/commands/core-checkpoint-native.d.ts +13 -0
  12. package/dist/commands/core-checkpoint-native.js +167 -52
  13. package/dist/commands/core-hook-registration-plan.js +5 -4
  14. package/dist/commands/core-stop-autosave.d.ts +21 -0
  15. package/dist/commands/core-stop-autosave.js +300 -0
  16. package/dist/commands/core.js +2 -0
  17. package/dist/commands/daemon.d.ts +5 -0
  18. package/dist/commands/daemon.js +52 -9
  19. package/dist/commands/doctor-usage.d.ts +5 -0
  20. package/dist/commands/doctor-usage.js +25 -0
  21. package/dist/commands/env.d.ts +49 -4
  22. package/dist/commands/env.js +355 -5
  23. package/dist/commands/integrations.js +84 -3
  24. package/dist/commands/lanes-shared.d.ts +3 -0
  25. package/dist/commands/lanes.d.ts +3 -0
  26. package/dist/commands/lanes.js +87 -3
  27. package/dist/commands/packs.js +23 -0
  28. package/dist/commands/pkg-update.d.ts +6 -0
  29. package/dist/commands/pkg-update.js +15 -7
  30. package/dist/commands/run.js +55 -45
  31. package/dist/commands/sources.js +4 -3
  32. package/dist/commands/sync-core.d.ts +1 -0
  33. package/dist/commands/sync-core.js +77 -3
  34. package/dist/commands/whoami.js +96 -80
  35. package/dist/lib/bot/config.d.ts +17 -0
  36. package/dist/lib/bot/config.js +13 -0
  37. package/dist/lib/bot/fleet-cron.js +29 -4
  38. package/dist/lib/bot/fleet-local.d.ts +30 -2
  39. package/dist/lib/bot/fleet-local.js +60 -1
  40. package/dist/lib/bot/grok-login-scope.d.ts +36 -0
  41. package/dist/lib/bot/grok-login-scope.js +93 -0
  42. package/dist/lib/bot/inflight.d.ts +9 -0
  43. package/dist/lib/bot/jobs/hot-signal-sync.d.ts +51 -0
  44. package/dist/lib/bot/jobs/hot-signal-sync.js +90 -9
  45. package/dist/lib/bot/legacy-provider-login.d.ts +32 -9
  46. package/dist/lib/bot/legacy-provider-login.js +28 -22
  47. package/dist/lib/bot/run.d.ts +29 -5
  48. package/dist/lib/bot/run.js +203 -1
  49. package/dist/lib/bot/runtime-sign-in-check.js +6 -1
  50. package/dist/lib/bot/runtime-sign-in.d.ts +2 -0
  51. package/dist/lib/bot/signals-try-now.d.ts +76 -0
  52. package/dist/lib/bot/signals-try-now.js +111 -0
  53. package/dist/lib/capacity/collectors/claude-oauth.d.ts +22 -3
  54. package/dist/lib/capacity/collectors/claude-oauth.js +78 -22
  55. package/dist/lib/capacity/scheduler.d.ts +8 -0
  56. package/dist/lib/capacity/scheduler.js +5 -2
  57. package/dist/lib/core-utils/sentry-report.js +2 -0
  58. package/dist/lib/daemon/machine-checks.d.ts +22 -1
  59. package/dist/lib/daemon/machine-checks.js +54 -12
  60. package/dist/lib/daemon/run.js +71 -8
  61. package/dist/lib/daemon/runtime-notifications.d.ts +7 -0
  62. package/dist/lib/daemon/runtime-notifications.js +50 -0
  63. package/dist/lib/daemon/stop-autosave-lock.d.ts +19 -0
  64. package/dist/lib/daemon/stop-autosave-lock.js +166 -0
  65. package/dist/lib/daemon/stop-autosave.d.ts +28 -0
  66. package/dist/lib/daemon/stop-autosave.js +111 -0
  67. package/dist/lib/daemon/stop-diagnostics.d.ts +11 -0
  68. package/dist/lib/daemon/stop-diagnostics.js +136 -0
  69. package/dist/lib/daemon/stop-job-executor.d.ts +19 -0
  70. package/dist/lib/daemon/stop-job-executor.js +126 -0
  71. package/dist/lib/daemon/stop-jobs.d.ts +93 -0
  72. package/dist/lib/daemon/stop-jobs.js +599 -0
  73. package/dist/lib/doctor/checks/fleet-hook-core.d.ts +9 -1
  74. package/dist/lib/doctor/checks/fleet-hook-core.js +39 -15
  75. package/dist/lib/doctor/checks/host-core.js +1 -1
  76. package/dist/lib/environment/access-probes.d.ts +234 -0
  77. package/dist/lib/environment/access-probes.js +918 -0
  78. package/dist/lib/environment/profile.d.ts +15 -2
  79. package/dist/lib/environment/profile.js +55 -20
  80. package/dist/lib/environment/rfc3339.d.ts +8 -0
  81. package/dist/lib/environment/rfc3339.js +26 -0
  82. package/dist/lib/environment/work-requirements.d.ts +169 -0
  83. package/dist/lib/environment/work-requirements.js +389 -0
  84. package/dist/lib/hook-engine/coverage.d.ts +137 -7
  85. package/dist/lib/hook-engine/coverage.js +1424 -4
  86. package/dist/lib/hook-engine/fleet-registration.d.ts +17 -5
  87. package/dist/lib/hook-engine/fleet-registration.js +53 -17
  88. package/dist/lib/hook-engine/git-stop-config.json +513 -0
  89. package/dist/lib/hook-engine/native-stop-compatibility.json +311 -0
  90. package/dist/lib/hook-engine/reconcile.js +2 -2
  91. package/dist/lib/hot-channels/alert.d.ts +10 -1
  92. package/dist/lib/hot-channels/alert.js +38 -8
  93. package/dist/lib/hot-channels/signals-claude-login.d.ts +53 -0
  94. package/dist/lib/hot-channels/signals-claude-login.js +96 -0
  95. package/dist/lib/hot-channels/signals-pass.d.ts +143 -17
  96. package/dist/lib/hot-channels/signals-pass.js +324 -17
  97. package/dist/lib/hot-channels/signals-runtime.d.ts +30 -0
  98. package/dist/lib/hot-channels/signals-runtime.js +82 -0
  99. package/dist/lib/install/hook-target.js +1 -1
  100. package/dist/lib/lanes/host-capacity.d.ts +26 -2
  101. package/dist/lib/lanes/host-capacity.js +17 -2
  102. package/dist/lib/lanes/host-compute.d.ts +90 -0
  103. package/dist/lib/lanes/host-compute.js +185 -0
  104. package/dist/lib/lanes/index.d.ts +2 -0
  105. package/dist/lib/lanes/index.js +1 -0
  106. package/dist/lib/lanes/reconcile.js +22 -1
  107. package/dist/lib/lanes/resource-usage.d.ts +155 -0
  108. package/dist/lib/lanes/resource-usage.js +589 -0
  109. package/dist/lib/lanes/run-size.d.ts +46 -0
  110. package/dist/lib/lanes/run-size.js +197 -0
  111. package/dist/lib/lanes/store.js +27 -0
  112. package/dist/lib/lanes/throttle.d.ts +36 -1
  113. package/dist/lib/lanes/throttle.js +47 -10
  114. package/dist/lib/lanes/types.d.ts +40 -0
  115. package/dist/lib/lanes/types.js +2 -2
  116. package/dist/lib/lanes/watcher.js +13 -4
  117. package/dist/lib/lanes/worker-process.d.ts +25 -2
  118. package/dist/lib/lanes/worker-process.js +71 -19
  119. package/dist/lib/placement/match.d.ts +192 -0
  120. package/dist/lib/placement/match.js +667 -0
  121. package/dist/lib/safe-store.d.ts +14 -0
  122. package/dist/lib/safe-store.js +77 -4
  123. package/dist/lib/search-index/index.d.ts +88 -4
  124. package/dist/lib/search-index/index.js +299 -25
  125. package/dist/lib/search-index/max-doc-bytes.d.ts +17 -6
  126. package/dist/lib/search-index/max-doc-bytes.js +48 -23
  127. package/dist/lib/signals/codex-lockdown.d.ts +79 -0
  128. package/dist/lib/signals/codex-lockdown.js +271 -0
  129. package/dist/lib/signals/codex-login.d.ts +37 -0
  130. package/dist/lib/signals/codex-login.js +83 -0
  131. package/dist/lib/signals/engine.d.ts +28 -0
  132. package/dist/lib/signals/engine.js +77 -0
  133. package/dist/lib/signals/reply.d.ts +48 -0
  134. package/dist/lib/signals/reply.js +94 -12
  135. package/dist/lib/signals/run-record.js +6 -1
  136. package/dist/lib/signals/settings.d.ts +5 -0
  137. package/dist/lib/signals/settings.js +2 -0
  138. package/dist/lib/signals/steps/adapters.js +6 -0
  139. package/dist/lib/signals/steps/extract.d.ts +135 -12
  140. package/dist/lib/signals/steps/extract.js +416 -84
  141. package/dist/lib/signals/steps/types.d.ts +21 -0
  142. package/dist/lib/sync-core/engine-home.d.ts +41 -2
  143. package/dist/lib/sync-core/engine-home.js +132 -19
  144. package/dist/lib/sync-core/reconcile.js +1 -1
  145. package/dist/lib/sync-core/release-compare.d.ts +7 -0
  146. package/dist/lib/sync-core/release-compare.js +16 -0
  147. package/dist/lib/sync-core/release.d.ts +2 -1
  148. package/dist/lib/sync-core/release.js +2 -10
  149. package/dist/lib/sync-core/rollout-state.d.ts +2 -1
  150. package/dist/lib/sync-core/rollout-state.js +5 -2
  151. package/dist/lib/sync-core/vault-uid.d.ts +2 -0
  152. package/dist/lib/sync-core/vault-uid.js +4 -0
  153. package/dist/run/schema-env-overrides.d.ts +24 -0
  154. package/dist/run/schema-env-overrides.js +72 -0
  155. package/dist/schemas/hq-work-requirements.v1.schema.json +145 -0
  156. package/dist/utils/auth-session-check.d.ts +16 -0
  157. package/dist/utils/auth-session-check.js +16 -0
  158. package/dist/utils/client-health-contract.d.ts +6 -0
  159. package/dist/utils/client-health-contract.js +13 -0
  160. package/dist/utils/client-health.d.ts +7 -0
  161. package/dist/utils/client-health.js +22 -1
  162. package/dist/utils/command-usage.d.ts +40 -0
  163. package/dist/utils/command-usage.js +61 -0
  164. package/dist/utils/duplicate-command-usage.d.ts +72 -0
  165. package/dist/utils/duplicate-command-usage.js +125 -0
  166. package/dist/utils/host-registration.d.ts +1 -1
  167. package/dist/utils/host-registration.js +6 -1
  168. package/dist/utils/resident-package-preload.js +4 -0
  169. package/dist/utils/sentry-fingerprint.js +9 -0
  170. package/dist/utils/windows-bash.d.ts +2 -0
  171. package/dist/utils/windows-bash.js +2 -1
  172. package/package.json +15 -10
  173. package/scripts/bench-core-compare.mjs +313 -0
  174. package/scripts/bench-core.mjs +399 -12
  175. package/scripts/check-function-manifest.mjs +121 -7
  176. package/dist/commands/__fixtures__/access-vault.d.ts +0 -95
  177. package/dist/commands/__fixtures__/access-vault.js +0 -166
  178. package/dist/commands/__fixtures__/make-tar.d.ts +0 -38
  179. package/dist/commands/__fixtures__/make-tar.js +0 -102
  180. package/dist/commands/secrets-public-types.test-d.d.ts +0 -2
  181. package/dist/commands/secrets-public-types.test-d.js +0 -18
  182. package/dist/lib/decisions/fixtures/us001.d.ts +0 -137
  183. package/dist/lib/decisions/fixtures/us001.js +0 -21
  184. package/dist/lib/doctor/__testing__/fake-hq-tree.d.ts +0 -226
  185. package/dist/lib/doctor/__testing__/fake-hq-tree.js +0 -408
  186. package/dist/lib/doctor/__testing__/run-doctor.d.ts +0 -8
  187. package/dist/lib/doctor/__testing__/run-doctor.js +0 -69
  188. package/dist/lib/fingerprint/fixtures.d.ts +0 -19
  189. package/dist/lib/fingerprint/fixtures.js +0 -61
  190. package/dist/lib/hot-channels/adapters/__fixtures__/dummy.d.ts +0 -33
  191. package/dist/lib/hot-channels/adapters/__fixtures__/dummy.js +0 -53
  192. package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.d.ts +0 -38
  193. package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.js +0 -64
  194. package/dist/lib/mesh/live/daemon/mqtt-events.test-d.d.ts +0 -2
  195. package/dist/lib/mesh/live/daemon/mqtt-events.test-d.js +0 -10
  196. package/dist/lib/test-utils/isolated-flag-company-context.d.ts +0 -3
  197. package/dist/lib/test-utils/isolated-flag-company-context.js +0 -18
  198. package/scripts/hook-engine-manifest.mjs +0 -22
  199. package/scripts/mesh-daemon-if-stale.mjs +0 -20
@@ -42,6 +42,8 @@ import { type FormattedReply } from "../../signals/reply.js";
42
42
  import { type BotConfig } from "../config.js";
43
43
  import { type LocalJob } from "../local-jobs.js";
44
44
  export declare const HOT_SIGNAL_SYNC_JOB_KIND = "hot-signal-sync";
45
+ /** The job name in a "Try now" run's reply (the scheduled job's is "Morning signals"). */
46
+ export declare const TRY_NOW_JOB_NAME = "Signals";
45
47
  /**
46
48
  * 06:30 every day, in the job's time zone (the stored six-field form of
47
49
  * "30 6 * * *"). Only the first registration uses it; after that the job's
@@ -64,6 +66,16 @@ export declare function forgetHotSignalSyncRegistrationsExcept(dir: string, keep
64
66
  export declare function hotSignalSyncJobContext(company: string): Record<string, unknown>;
65
67
  /** The company a job item syncs, when its context marks it as this built-in; else null. */
66
68
  export declare function hotSignalSyncJobCompany(context: unknown): string | null;
69
+ /**
70
+ * The companies this bot runs the hot-signal-sync job for. A legacy bot's job
71
+ * is in its own `jobs.json`; an HQ Fleet Runtime bot's job lives in the
72
+ * runtime's cron store, which only the runtime's python can list, so its
73
+ * registration marker (`hot-signal-sync:fleet:{company}`) stands in for it.
74
+ * Never throws: an unreadable file counts as no job.
75
+ */
76
+ export declare function hotSignalSyncJobCompanies(dir: string, opts?: {
77
+ fleet?: boolean;
78
+ }): string[];
67
79
  /**
68
80
  * The HQ's active company from `{hqRoot}/.hq/config.json` (`activeCompany`),
69
81
  * the same company `hq sources sync` falls back to. Undefined when the file is
@@ -215,7 +227,34 @@ export interface HotSignalSyncRunInput {
215
227
  * the failure reply say when it tries again. Unset = no automatic retry.
216
228
  */
217
229
  scheduleRetry?: (at: string) => boolean;
230
+ /**
231
+ * The member answered a reply's "Try now" (US-006 AC9): one run with
232
+ * `trigger: "chat"` and `force: true`, the same as `hq signals run --trigger
233
+ * chat --force`, with the engine's caps and company lock. Never a catch-up,
234
+ * never retried. Runs only through the engine: with no engine (the
235
+ * cli.bot-signals-engine-job flag off) nothing runs.
236
+ */
237
+ tryNow?: boolean;
238
+ /**
239
+ * The reply goes to the HQ desktop app (the local bot's owner DM), so it
240
+ * links today's brief with `hq-desktop://brief` (US-023). Unset keeps the
241
+ * "Create today's brief" decision and writes no hq-desktop:// link.
242
+ */
243
+ desktopLinks?: boolean;
244
+ /**
245
+ * This bot has a scheduled brief job (`hasScheduledBriefJob`). Only then
246
+ * does a desktop reply say the brief builds next.
247
+ */
248
+ briefJobScheduled?: boolean;
218
249
  }
250
+ /**
251
+ * True when the bot's own jobs.json has a scheduled job that runs
252
+ * /daily-brief. hq-cli never starts the brief itself, so a reply says the
253
+ * brief builds next only when one of these exists. Cloud-scheduled jobs are
254
+ * not read here; a bot with only those gets the "open it to create" wording.
255
+ * Never throws: an unreadable jobs.json counts as no brief job.
256
+ */
257
+ export declare function hasScheduledBriefJob(dir: string): boolean;
219
258
  /**
220
259
  * The engine options a fired job passes. `signalsAlert` is the owner-DM
221
260
  * sender for the signals-failure alert (US-018, hq-cli #2314). Until #2314
@@ -240,7 +279,19 @@ export interface HotSignalSyncRunOutcome {
240
279
  retryAt?: string;
241
280
  /** The signals-failure alert already told the owner, so the bot sends no second DM for this run. */
242
281
  ownerAlerted?: boolean;
282
+ /** The reply asks the member for "Try now" (a failed or finished-with-problems run). */
283
+ tryNowOffered?: boolean;
284
+ /** Another run held the company lock, so this one started nothing. */
285
+ running?: boolean;
286
+ /** A Try now with no engine (flag off): nothing ran and nothing should be sent. */
287
+ notRun?: true;
243
288
  }
289
+ /**
290
+ * True when a member's message is the "Try now" answer: the decision button
291
+ * (which sends its label, "Try now") or the exact text the reply asks for.
292
+ * Case, surrounding space and quotes are ignored; anything else is not it.
293
+ */
294
+ export declare function isTryNowReply(text: string): boolean;
244
295
  /** Run the scheduled sync once and describe it in plain words. Never throws. */
245
296
  export declare function runHotSignalSyncJob(input: HotSignalSyncRunInput): Promise<HotSignalSyncRunOutcome>;
246
297
  export declare function describeSyncReport(company: string, report: OnDemandSyncReport): string;
@@ -39,10 +39,12 @@ import * as path from "node:path";
39
39
  import { signalsAlertKey } from "../../hot-channels/alert.js";
40
40
  import { JOB_RUN_OPTIONS_CONTEXT_KEY } from "../job-run.js";
41
41
  import { localDate, raiseStoppedRunAlert, runRecordRel } from "../../signals/engine.js";
42
- import { formatJobErrorReply, formatLockedReply, formatRunReply, timeInWords } from "../../signals/reply.js";
42
+ import { TRY_NOW_LABEL, TRY_NOW_OPTION_ID, formatJobErrorReply, formatLockedReply, formatRunReply, replyOffersTryNow, timeInWords, } from "../../signals/reply.js";
43
43
  import { effectiveBotCompanies, effectiveBotKind, readBotConfig } from "../config.js";
44
44
  import { ensureLocalJob, readLocalJobs, removeLocalJobsWhere, withJobsLock } from "../local-jobs.js";
45
45
  export const HOT_SIGNAL_SYNC_JOB_KIND = "hot-signal-sync";
46
+ /** The job name in a "Try now" run's reply (the scheduled job's is "Morning signals"). */
47
+ export const TRY_NOW_JOB_NAME = "Signals";
46
48
  /**
47
49
  * 06:30 every day, in the job's time zone (the stored six-field form of
48
50
  * "30 6 * * *"). Only the first registration uses it; after that the job's
@@ -149,6 +151,36 @@ export function hotSignalSyncJobCompany(context) {
149
151
  return null;
150
152
  return typeof company === "string" && company.trim() ? company.trim() : null;
151
153
  }
154
+ /**
155
+ * The companies this bot runs the hot-signal-sync job for. A legacy bot's job
156
+ * is in its own `jobs.json`; an HQ Fleet Runtime bot's job lives in the
157
+ * runtime's cron store, which only the runtime's python can list, so its
158
+ * registration marker (`hot-signal-sync:fleet:{company}`) stands in for it.
159
+ * Never throws: an unreadable file counts as no job.
160
+ */
161
+ export function hotSignalSyncJobCompanies(dir, opts = {}) {
162
+ const out = new Set();
163
+ if (opts.fleet) {
164
+ const prefix = fleetMarkerKey("");
165
+ for (const key of Object.keys(readMarker(dir).registered)) {
166
+ if (key.startsWith(prefix) && key.length > prefix.length)
167
+ out.add(key.slice(prefix.length));
168
+ }
169
+ }
170
+ else {
171
+ try {
172
+ for (const job of readLocalJobs(dir)) {
173
+ const company = hotSignalSyncJobCompany(job.context);
174
+ if (company)
175
+ out.add(company);
176
+ }
177
+ }
178
+ catch {
179
+ // An unreadable jobs.json: no job this bot can run now.
180
+ }
181
+ }
182
+ return [...out].sort();
183
+ }
152
184
  const ACTIVE_COMPANY_RE = /^[a-z0-9][a-z0-9_-]*$/i;
153
185
  /**
154
186
  * The HQ's active company from `{hqRoot}/.hq/config.json` (`activeCompany`),
@@ -357,6 +389,36 @@ function errorMessage(err) {
357
389
  return err instanceof Error ? err.message : String(err);
358
390
  }
359
391
  export const noLocalSignalsPass = async () => 0;
392
+ /** A job prompt that runs the daily-brief skill. */
393
+ const BRIEF_JOB_PROMPT = /(^|\s)\/daily-brief\b/;
394
+ /**
395
+ * True when the bot's own jobs.json has a scheduled job that runs
396
+ * /daily-brief. hq-cli never starts the brief itself, so a reply says the
397
+ * brief builds next only when one of these exists. Cloud-scheduled jobs are
398
+ * not read here; a bot with only those gets the "open it to create" wording.
399
+ * Never throws: an unreadable jobs.json counts as no brief job.
400
+ */
401
+ export function hasScheduledBriefJob(dir) {
402
+ try {
403
+ return readLocalJobs(dir).some((job) => typeof job.cron === "string" && BRIEF_JOB_PROMPT.test(job.prompt ?? ""));
404
+ }
405
+ catch {
406
+ return false;
407
+ }
408
+ }
409
+ /**
410
+ * True when a member's message is the "Try now" answer: the decision button
411
+ * (which sends its label, "Try now") or the exact text the reply asks for.
412
+ * Case, surrounding space and quotes are ignored; anything else is not it.
413
+ */
414
+ export function isTryNowReply(text) {
415
+ const core = text
416
+ .trim()
417
+ .replace(/^["'“”‘’`]+|["'“”‘’`]+$/g, "")
418
+ .trim()
419
+ .toLowerCase();
420
+ return core === TRY_NOW_LABEL.toLowerCase() || core === TRY_NOW_OPTION_ID;
421
+ }
360
422
  /**
361
423
  * Today's run record for the company, or null. The automatic retry reads it
362
424
  * first: when another run (a "Try now", a brief run) already finished the day
@@ -372,8 +434,10 @@ function readTodaysRecord(hqRoot, company, now) {
372
434
  }
373
435
  }
374
436
  async function runSignalsEngineJob(input) {
437
+ // A member's "Try now" can come at any hour: its reply says "Signals".
438
+ const jobName = input.tryNow ? TRY_NOW_JOB_NAME : "Morning signals";
375
439
  if (!input.hqRoot) {
376
- const reply = formatJobErrorReply(`Morning signals for ${input.company} did not run.`, "The bot has no HQ folder set, so it cannot find the company's files.");
440
+ const reply = formatJobErrorReply(`${jobName} for ${input.company} did not run.`, "The bot has no HQ folder set, so it cannot find the company's files.");
377
441
  return { ok: false, text: reply.text, report: null, reply };
378
442
  }
379
443
  const timeZone = input.timeZone ?? "UTC";
@@ -388,7 +452,7 @@ async function runSignalsEngineJob(input) {
388
452
  await raiseStoppedRunAlert({ hqRoot: input.hqRoot, company: input.company, now: input.now, senders, daysAgo });
389
453
  }
390
454
  }
391
- if (input.retry) {
455
+ if (input.retry && !input.tryNow) {
392
456
  const today = readTodaysRecord(input.hqRoot, input.company, input.now());
393
457
  if (today && (today.status === "complete" || today.status === "partial")) {
394
458
  const at = timeInWords(today.finishedAt, timeZone);
@@ -402,8 +466,10 @@ async function runSignalsEngineJob(input) {
402
466
  // The run right after the job is registered is a setup run, not the day's
403
467
  // scheduled run: a non-job trigger leaves jobRanAt alone, so the morning
404
468
  // job still runs (a bot first started at 01:00 is not "already ran").
405
- trigger: input.firstRun ? "manual" : "job",
406
- catchUp: input.catchUp,
469
+ // A member's "Try now" is `hq signals run --trigger chat --force` (US-006 AC9).
470
+ trigger: input.tryNow ? "chat" : input.firstRun ? "manual" : "job",
471
+ ...(input.tryNow ? { force: true } : {}),
472
+ catchUp: input.tryNow ? false : input.catchUp,
407
473
  now: input.now,
408
474
  // The signals-failure alert (US-018): the owner DM, sent even when the job is quiet.
409
475
  ...(input.sendAlert
@@ -416,21 +482,24 @@ async function runSignalsEngineJob(input) {
416
482
  }
417
483
  catch (err) {
418
484
  const reason = err instanceof Error ? err.message : String(err);
419
- const reply = formatJobErrorReply(`Morning signals for ${input.company} failed.`, reason);
485
+ const reply = formatJobErrorReply(`${jobName} for ${input.company} failed.`, reason);
420
486
  return { ok: false, text: reply.text, report: null, reply };
421
487
  }
422
488
  const replyOptions = {
423
489
  timeZone,
490
+ jobName,
424
491
  ...(input.scheduledFor ? { scheduledFor: input.scheduledFor } : {}),
492
+ ...(input.desktopLinks ? { desktopLinks: true } : {}),
493
+ ...(input.briefJobScheduled ? { briefJobScheduled: true } : {}),
425
494
  };
426
495
  const record = result.records.find((r) => r.company === input.company) ?? result.records[0];
427
496
  if (!record) {
428
497
  const locked = (result.locked ?? []).find((l) => l.company === input.company);
429
498
  if (locked) {
430
499
  const reply = formatLockedReply(locked, replyOptions);
431
- return { ok: true, text: reply.text, report: null, signals: result, reply };
500
+ return { ok: true, text: reply.text, report: null, signals: result, reply, running: true };
432
501
  }
433
- const reply = formatJobErrorReply(`Morning signals for ${input.company} did not finish.`, "The run left no run record, so I cannot say what happened.");
502
+ const reply = formatJobErrorReply(`${jobName} for ${input.company} did not finish.`, "The run left no run record, so I cannot say what happened.");
434
503
  return { ok: false, text: reply.text, report: null, signals: result, reply };
435
504
  }
436
505
  // One automatic retry per failed scheduled run, only when the engine set a
@@ -440,6 +509,7 @@ async function runSignalsEngineJob(input) {
440
509
  !record.alreadyRanToday &&
441
510
  typeof record.nextRetryAt === "string" &&
442
511
  !input.retry &&
512
+ !input.tryNow &&
443
513
  input.scheduleRetry !== undefined &&
444
514
  input.scheduleRetry(record.nextRetryAt);
445
515
  const reply = formatRunReply(record, result.summary, {
@@ -448,12 +518,23 @@ async function runSignalsEngineJob(input) {
448
518
  ...(input.retry ? { wasRetry: true } : {}),
449
519
  });
450
520
  const ok = reply.variant !== "failed" && reply.variant !== "partial";
451
- return { ok, text: reply.text, report: null, signals: result, reply, ...(retryScheduled ? { retryAt: record.nextRetryAt } : {}) };
521
+ return {
522
+ ok,
523
+ text: reply.text,
524
+ report: null,
525
+ signals: result,
526
+ reply,
527
+ ...(retryScheduled ? { retryAt: record.nextRetryAt } : {}),
528
+ ...(replyOffersTryNow(reply) ? { tryNowOffered: true } : {}),
529
+ };
452
530
  }
453
531
  /** Run the scheduled sync once and describe it in plain words. Never throws. */
454
532
  export async function runHotSignalSyncJob(input) {
455
533
  if (input.signals)
456
534
  return runSignalsEngineJob({ ...input, signals: input.signals });
535
+ // "Try now" is a signals-engine run only; without the engine nothing runs.
536
+ if (input.tryNow)
537
+ return { ok: false, text: "", report: null, notRun: true };
457
538
  const signalsPass = input.signalsPass ?? noLocalSignalsPass;
458
539
  let report;
459
540
  try {
@@ -1,6 +1,8 @@
1
1
  import type { BotConfig } from "./config.js";
2
2
  import { type FleetLocalProviderAuthStatus } from "./fleet-local.js";
3
3
  import type { LegacyProviderLogin, LegacyProviderLoginProbe } from "./legacy-convert.js";
4
+ import { type BotLoginScope, type GrokSiblingLogin } from "./grok-login-scope.js";
5
+ export { botLoginScope, localBotLoginScopes, newBotLoginScope, type BotLoginScope, type GrokSiblingLogin } from "./grok-login-scope.js";
4
6
  export declare function codexCliAuthPath(home: string): string;
5
7
  /** The `exp` claim of a JWT, in seconds, or null when the token has none that reads. */
6
8
  export declare function jwtExpiry(token: string): number | null;
@@ -23,6 +25,10 @@ export interface GrokLoginProbeDeps {
23
25
  profileDir: string;
24
26
  }>;
25
27
  status?: (agentUid: string) => FleetLocalProviderAuthStatus | null;
28
+ /** The company scope of the bot that would share a login. Without one, no other bot's login counts. */
29
+ scope?: BotLoginScope;
30
+ /** The company scope of a bot here; null when it is not known. */
31
+ scopeOf?: (agentUid: string) => BotLoginScope;
26
32
  }
27
33
  /** The helper asks the keychain per profile, so one list of bots shares a scan this long. */
28
34
  export declare const GROK_HOLDER_SCAN_TTL_MS = 30000;
@@ -33,31 +39,48 @@ export interface GrokLoginProbeAsyncDeps {
33
39
  profileDir: string;
34
40
  }>;
35
41
  status?: (agentUid: string) => Promise<FleetLocalProviderAuthStatus | null>;
42
+ scope?: BotLoginScope;
43
+ scopeOf?: (agentUid: string) => BotLoginScope;
36
44
  }
37
- export declare function grokLoginReadableHereAsync(exclude: string, deps?: GrokLoginProbeAsyncDeps): Promise<LegacyProviderLogin>;
38
- /** Mirrors the helper's `_existing_machine_oauth`: another Fleet bot here holds a Grok OAuth login. */
39
- export declare function grokLoginReadableHere(exclude: string, deps?: GrokLoginProbeDeps, now?: number): LegacyProviderLogin;
45
+ export declare function grokLoginReadableHereAsync(exclude: string, deps?: GrokLoginProbeAsyncDeps): Promise<GrokSiblingLogin>;
46
+ /**
47
+ * Whether the helper's `_existing_machine_oauth` would give this bot a Grok
48
+ * login it may share. The helper copies the first other bot's login it finds
49
+ * and knows nothing of companies, so the answer is yes only when another
50
+ * Fleet bot here holds a Grok OAuth login and every other bot that holds one,
51
+ * or that the helper could not answer for, has the company scope `deps.scope`.
52
+ */
53
+ export declare function grokLoginReadableHere(exclude: string, deps?: GrokLoginProbeDeps, now?: number): GrokSiblingLogin;
40
54
  export declare const GROK_CLI_AUTH_ISSUER = "https://auth.x.ai";
41
55
  export declare const FLEET_XAI_OAUTH_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
42
56
  export declare function grokCliAuthPath(homedir?: string, env?: NodeJS.ProcessEnv): string;
43
57
  export declare function grokCliLoginReadable(homedir?: string, env?: NodeJS.ProcessEnv): LegacyProviderLogin;
44
58
  export declare function fleetHelperSharesGrokCliLogin(): boolean;
45
59
  export interface GrokSignInDeps {
46
- sibling?: () => LegacyProviderLogin;
60
+ sibling?: () => GrokSiblingLogin;
47
61
  cli?: () => LegacyProviderLogin;
48
62
  cliImport?: boolean;
63
+ /** The company scope of the bot that would sign in. Without one, no other bot's login counts. */
64
+ scope?: BotLoginScope;
49
65
  }
50
- export declare function grokSignInReusableHere(exclude: string, deps?: GrokSignInDeps): LegacyProviderLogin;
51
- /** The live probe for a bot: Codex from its login home, Grok from the Grok CLI or the other Fleet bots here. */
52
- export declare function legacyProviderLoginProbe(dir: string, config: Pick<BotConfig, "name" | "agentUid" | "runtime" | "runtimeAuth" | "hqRoot">): LegacyProviderLoginProbe;
66
+ /**
67
+ * A Grok sign-in the helper would import for a bot of company scope `deps.scope`.
68
+ * The helper tries the other Fleet bots before the Grok CLI login, so a
69
+ * blocked sibling answer also rules out the Grok CLI login.
70
+ */
71
+ export declare function grokSignInReusableHere(exclude: string, deps?: GrokSignInDeps): GrokSiblingLogin;
72
+ /** The live probe for a bot: Codex from its login home, Grok from the Grok CLI or the other Fleet bots of its company here. */
73
+ export declare function legacyProviderLoginProbe(dir: string, config: Pick<BotConfig, "name" | "agentUid" | "runtime" | "runtimeAuth" | "hqRoot" | "kind" | "companies" | "workerId">): LegacyProviderLoginProbe;
53
74
  export type FleetSignInProvider = "chatgpt" | "grok";
54
75
  export interface FleetSignInHereDeps {
55
76
  env?: NodeJS.ProcessEnv;
56
77
  homedir?: string;
57
- grok?: () => LegacyProviderLogin;
78
+ grok?: () => GrokSiblingLogin;
58
79
  grokCli?: () => LegacyProviderLogin;
59
80
  grokCliImport?: boolean;
60
81
  now?: number;
82
+ /** The company scope of the bot that would sign in. Without one, no other bot's Grok sign-in counts. */
83
+ scope?: BotLoginScope;
61
84
  }
62
- export declare function fleetSignInReusableHere(provider: FleetSignInProvider, deps?: FleetSignInHereDeps): LegacyProviderLogin;
85
+ export declare function fleetSignInReusableHere(provider: FleetSignInProvider, deps?: FleetSignInHereDeps): GrokSiblingLogin;
63
86
  //# sourceMappingURL=legacy-provider-login.d.ts.map
@@ -6,7 +6,10 @@
6
6
  * ~/.codex/auth.json) with a refreshable, unexpired token. A bot with its
7
7
  * own Codex login (hq bot login) or a capacity account imports from that
8
8
  * home instead, so the account it answered with comes along.
9
- * - Grok: the helper copies another Fleet bot's Grok login, and from release
9
+ * - Grok: the helper copies another Fleet bot's Grok login. It takes the
10
+ * first one it finds, whatever company that bot belongs to, so the check
11
+ * here says yes only when every bot it could copy from has this bot's
12
+ * company scope. From release
10
13
  * 0.4.31 (local builds from 0.4.31-local.13) also shares the Grok CLI login
11
14
  * in <GROK_HOME>/auth.json, else ~/.grok/auth.json (a record for the
12
15
  * runtime's xAI client with a refresh token). Its own
@@ -20,6 +23,8 @@ import * as fs from "node:fs";
20
23
  import * as os from "node:os";
21
24
  import * as path from "node:path";
22
25
  import { cachedFleetLocalTargetRelease, fleetLocalProviderAuthStatus, fleetLocalProviderAuthStatusAsync, fleetReleaseImportsGrokCli, listFleetLocalProfiles } from "./fleet-local.js";
26
+ import { botLoginScope, grokLoginFromScan, localBotLoginScopes } from "./grok-login-scope.js";
27
+ export { botLoginScope, localBotLoginScopes, newBotLoginScope } from "./grok-login-scope.js";
23
28
  import { botOwnAuthHome, botRuntimeAuth, capacityAccountHome } from "./runtime-auth.js";
24
29
  export function codexCliAuthPath(home) {
25
30
  return path.join(home, "auth.json");
@@ -124,26 +129,17 @@ export async function grokLoginReadableHereAsync(exclude, deps = {}) {
124
129
  else if (found.authenticated && found.authType === "oauth")
125
130
  holders.push(agentUid);
126
131
  });
127
- return grokLoginFromScan({ holders, uids: profiles.map((profile) => profile.agentUid), unanswered }, exclude);
132
+ return grokLoginFromScan({ holders, uids: profiles.map((profile) => profile.agentUid), unanswered }, exclude, deps.scope ?? null, deps.scopeOf ?? localBotLoginScopes());
128
133
  }
129
- /** Mirrors the helper's `_existing_machine_oauth`: another Fleet bot here holds a Grok OAuth login. */
134
+ /**
135
+ * Whether the helper's `_existing_machine_oauth` would give this bot a Grok
136
+ * login it may share. The helper copies the first other bot's login it finds
137
+ * and knows nothing of companies, so the answer is yes only when another
138
+ * Fleet bot here holds a Grok OAuth login and every other bot that holds one,
139
+ * or that the helper could not answer for, has the company scope `deps.scope`.
140
+ */
130
141
  export function grokLoginReadableHere(exclude, deps = {}, now = Date.now()) {
131
- return grokLoginFromScan(grokHolders(deps, now), exclude);
132
- }
133
- function grokLoginFromScan(scan, exclude) {
134
- const other = (agentUid) => agentUid.toLowerCase() !== exclude.toLowerCase();
135
- const holder = scan.holders.find(other);
136
- if (holder)
137
- return { readable: true, detail: `the Grok sign-in of HQ Fleet bot ${holder} on this computer` };
138
- const others = scan.uids.filter(other);
139
- const unanswered = scan.unanswered.filter(other);
140
- if (others.length && unanswered.length === others.length) {
141
- return { readable: false, detail: `the HQ Fleet helper could not say whether any of the ${others.length} other Fleet bot(s) on this computer is signed in to Grok` };
142
- }
143
- return {
144
- readable: false,
145
- detail: others.length ? `none of the ${others.length} other HQ Fleet bot(s) on this computer is signed in to Grok` : "no other HQ Fleet bot on this computer is signed in to Grok",
146
- };
142
+ return grokLoginFromScan(grokHolders(deps, now), exclude, deps.scope ?? null, deps.scopeOf ?? localBotLoginScopes());
147
143
  }
148
144
  export const GROK_CLI_AUTH_ISSUER = "https://auth.x.ai";
149
145
  export const FLEET_XAI_OAUTH_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
@@ -181,21 +177,30 @@ export function fleetHelperSharesGrokCliLogin() {
181
177
  return false;
182
178
  }
183
179
  }
180
+ /**
181
+ * A Grok sign-in the helper would import for a bot of company scope `deps.scope`.
182
+ * The helper tries the other Fleet bots before the Grok CLI login, so a
183
+ * blocked sibling answer also rules out the Grok CLI login.
184
+ */
184
185
  export function grokSignInReusableHere(exclude, deps = {}) {
186
+ const sibling = (deps.sibling ?? (() => grokLoginReadableHere(exclude, { scope: deps.scope ?? null })))();
187
+ if (sibling.blocked)
188
+ return sibling;
185
189
  if (deps.cliImport ?? fleetHelperSharesGrokCliLogin()) {
186
190
  const cli = (deps.cli ?? (() => grokCliLoginReadable()))();
187
191
  if (cli.readable)
188
192
  return cli;
189
193
  }
190
- return (deps.sibling ?? (() => grokLoginReadableHere(exclude)))();
194
+ return sibling;
191
195
  }
192
- /** The live probe for a bot: Codex from its login home, Grok from the Grok CLI or the other Fleet bots here. */
196
+ /** The live probe for a bot: Codex from its login home, Grok from the Grok CLI or the other Fleet bots of its company here. */
193
197
  export function legacyProviderLoginProbe(dir, config) {
194
198
  return (runtime) => {
195
199
  if (runtime === "grok") {
196
200
  if (config.runtimeAuth?.grok !== undefined)
197
201
  return { readable: false, detail: "it uses its own Grok login, which HQ Fleet Local cannot import" };
198
- return grokSignInReusableHere(config.agentUid);
202
+ const login = grokSignInReusableHere(config.agentUid, { scope: botLoginScope(config) });
203
+ return { readable: login.readable, detail: login.detail };
199
204
  }
200
205
  const home = legacyCodexHome(dir, config);
201
206
  if ("error" in home)
@@ -207,6 +212,7 @@ export function legacyProviderLoginProbe(dir, config) {
207
212
  export function fleetSignInReusableHere(provider, deps = {}) {
208
213
  if (provider === "grok") {
209
214
  return grokSignInReusableHere("", {
215
+ scope: deps.scope ?? null,
210
216
  ...(deps.grok ? { sibling: deps.grok } : {}),
211
217
  cli: deps.grokCli ?? (() => grokCliLoginReadable(deps.homedir ?? os.homedir(), deps.env ?? process.env)),
212
218
  ...(deps.grokCliImport !== undefined ? { cliImport: deps.grokCliImport } : {}),
@@ -80,6 +80,25 @@ export declare const UNDELIVERABLE_JOB_REPORT_TEXT = "This scheduled run finishe
80
80
  */
81
81
  export declare const MAX_PARALLEL_JOB_TURNS = 1;
82
82
  export type SleepFn = (ms: number, signal?: AbortSignal) => Promise<void>;
83
+ /** What the bot's signals job (hot-signal-sync) reports for one run. */
84
+ export interface SignalsJobResult {
85
+ ok: boolean;
86
+ text: string;
87
+ ownerAlerted?: boolean;
88
+ /** The reply asks the member for "Try now" (US-006 AC9). */
89
+ tryNowOffered?: boolean;
90
+ /** Another run held the company lock, so this one started nothing. */
91
+ running?: boolean;
92
+ }
93
+ /** One "Try now" run (US-006 AC9). */
94
+ export interface SignalsTryNowInput {
95
+ company: string;
96
+ now: () => Date;
97
+ /** The job's zone, for the times in the reply. */
98
+ timeZone: string;
99
+ /** The signals-failure alert to the owner (US-012). */
100
+ sendAlert: (text: string) => Promise<void>;
101
+ }
83
102
  export interface BotRunDeps {
84
103
  dir: string;
85
104
  config: BotConfig;
@@ -120,11 +139,16 @@ export interface BotRunDeps {
120
139
  * offered for a local job's scheduled run, never for a retry.
121
140
  */
122
141
  scheduleRetry?: (at: string) => boolean;
123
- }) => Promise<{
124
- ok: boolean;
125
- text: string;
126
- ownerAlerted?: boolean;
127
- }>;
142
+ }) => Promise<SignalsJobResult>;
143
+ /**
144
+ * US-006 AC9: the member's "Try now" answer to a signals job reply.
145
+ * Resolves cli.bot-signals-engine-job the same way a fired job does and
146
+ * returns null when it is off (the message then goes to the model as
147
+ * before); otherwise the runner for one `--trigger chat --force` run of the
148
+ * signals engine through the job's own entry point, with its caps and lock.
149
+ * Unset = "Try now" is never handled here.
150
+ */
151
+ signalsTryNow?: () => Promise<((input: SignalsTryNowInput) => Promise<SignalsJobResult>) | null>;
128
152
  heartbeatIntervalMs?: number;
129
153
  readyComponents?: () => HeartbeatReadyComponents;
130
154
  /** Override the rendered system prompt (tests). */