@indigoai-us/hq-cli 5.345.218 → 5.345.220

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 +130 -0
  2. package/dist/command-catalog.generated.d.ts +94 -1
  3. package/dist/command-catalog.generated.js +114 -1
  4. package/dist/commands/agents.d.ts +22 -0
  5. package/dist/commands/agents.js +92 -1
  6. package/dist/commands/bot.d.ts +48 -0
  7. package/dist/commands/bot.js +108 -8
  8. package/dist/commands/cloud.d.ts +16 -0
  9. package/dist/commands/cloud.js +112 -102
  10. package/dist/commands/core-checkpoint-native.d.ts +13 -0
  11. package/dist/commands/core-checkpoint-native.js +167 -52
  12. package/dist/commands/core-hook-registration-plan.d.ts +8 -0
  13. package/dist/commands/core-hook-registration-plan.js +22 -0
  14. package/dist/commands/core.js +9 -0
  15. package/dist/commands/daemon.js +21 -2
  16. package/dist/commands/doctor.js +4 -0
  17. package/dist/commands/integrations.js +84 -3
  18. package/dist/commands/lanes-shared.d.ts +2 -0
  19. package/dist/commands/lanes-watch.js +28 -1
  20. package/dist/commands/lanes.d.ts +2 -0
  21. package/dist/commands/lanes.js +99 -9
  22. package/dist/commands/packs.js +23 -0
  23. package/dist/commands/pkg-update.d.ts +6 -0
  24. package/dist/commands/pkg-update.js +15 -7
  25. package/dist/commands/reindex.js +6 -0
  26. package/dist/commands/run.js +55 -45
  27. package/dist/commands/sources.js +3 -2
  28. package/dist/index.js +8 -0
  29. package/dist/lib/anywhere-person-setting.d.ts +2 -2
  30. package/dist/lib/anywhere-person-setting.js +2 -2
  31. package/dist/lib/bot/fleet-cron.js +5 -2
  32. package/dist/lib/bot/inflight.d.ts +9 -0
  33. package/dist/lib/bot/jobs/hot-signal-sync.d.ts +51 -0
  34. package/dist/lib/bot/jobs/hot-signal-sync.js +90 -9
  35. package/dist/lib/bot/run.d.ts +29 -5
  36. package/dist/lib/bot/run.js +203 -1
  37. package/dist/lib/bot/signals-try-now.d.ts +76 -0
  38. package/dist/lib/bot/signals-try-now.js +111 -0
  39. package/dist/lib/capacity/collectors/claude-oauth.d.ts +22 -3
  40. package/dist/lib/capacity/collectors/claude-oauth.js +78 -22
  41. package/dist/lib/capacity/scheduler.d.ts +8 -0
  42. package/dist/lib/capacity/scheduler.js +5 -2
  43. package/dist/lib/daemon/anywhere-listener.d.ts +33 -1
  44. package/dist/lib/daemon/anywhere-listener.js +86 -4
  45. package/dist/lib/daemon/machine-check-owner.d.ts +21 -0
  46. package/dist/lib/daemon/machine-check-owner.js +95 -0
  47. package/dist/lib/daemon/machine-check-registration.d.ts +4 -0
  48. package/dist/lib/daemon/machine-check-registration.js +64 -0
  49. package/dist/lib/daemon/machine-checks.d.ts +144 -0
  50. package/dist/lib/daemon/machine-checks.js +412 -0
  51. package/dist/lib/daemon/run.js +35 -4
  52. package/dist/lib/daemon/runtime-notifications.d.ts +7 -0
  53. package/dist/lib/daemon/runtime-notifications.js +50 -0
  54. package/dist/lib/daemon/server.d.ts +2 -0
  55. package/dist/lib/daemon/server.js +6 -0
  56. package/dist/lib/daemon/state-file.d.ts +12 -1
  57. package/dist/lib/daemon/state-file.js +23 -1
  58. package/dist/lib/doctor/checks/fleet-hook-core.d.ts +12 -0
  59. package/dist/lib/doctor/checks/fleet-hook-core.js +127 -0
  60. package/dist/lib/doctor/checks/host-core.js +3 -1
  61. package/dist/lib/doctor/checks/machine-checks.d.ts +16 -0
  62. package/dist/lib/doctor/checks/machine-checks.js +103 -0
  63. package/dist/lib/doctor/registry.js +4 -0
  64. package/dist/lib/doctor/types.d.ts +4 -0
  65. package/dist/lib/hook-engine/canary-gate.d.ts +64 -0
  66. package/dist/lib/hook-engine/canary-gate.js +147 -0
  67. package/dist/lib/hook-engine/coverage.d.ts +3 -1
  68. package/dist/lib/hook-engine/coverage.js +8 -2
  69. package/dist/lib/hook-engine/fleet-registration.d.ts +42 -0
  70. package/dist/lib/hook-engine/fleet-registration.js +168 -0
  71. package/dist/lib/hook-engine/reconcile.js +3 -2
  72. package/dist/lib/hook-engine/registration-identity.d.ts +33 -0
  73. package/dist/lib/hook-engine/registration-identity.js +97 -0
  74. package/dist/lib/hook-engine/registration.d.ts +1 -30
  75. package/dist/lib/hook-engine/registration.js +1 -88
  76. package/dist/lib/hook-engine/resolve.d.ts +2 -0
  77. package/dist/lib/hook-engine/resolve.js +7 -3
  78. package/dist/lib/hot-channels/alert.d.ts +10 -1
  79. package/dist/lib/hot-channels/alert.js +34 -7
  80. package/dist/lib/hot-channels/signals-claude-login.d.ts +53 -0
  81. package/dist/lib/hot-channels/signals-claude-login.js +96 -0
  82. package/dist/lib/hot-channels/signals-pass.d.ts +17 -0
  83. package/dist/lib/hot-channels/signals-pass.js +31 -3
  84. package/dist/lib/lanes/canonical-host.d.ts +8 -1
  85. package/dist/lib/lanes/canonical-host.js +9 -3
  86. package/dist/lib/lanes/machine-identity.d.ts +15 -0
  87. package/dist/lib/lanes/machine-identity.js +26 -0
  88. package/dist/lib/lanes/spawn.js +17 -3
  89. package/dist/lib/search-index/index.js +11 -1
  90. package/dist/lib/signals/engine.d.ts +1 -0
  91. package/dist/lib/signals/engine.js +7 -0
  92. package/dist/lib/signals/reply.d.ts +48 -0
  93. package/dist/lib/signals/reply.js +72 -11
  94. package/dist/lib/signals/steps/adapters.js +6 -0
  95. package/dist/lib/signals/steps/extract.d.ts +50 -3
  96. package/dist/lib/signals/steps/extract.js +100 -17
  97. package/dist/lib/signals/steps/types.d.ts +19 -0
  98. package/dist/lib/sync-core/engine-home.d.ts +6 -1
  99. package/dist/lib/sync-core/engine-home.js +13 -3
  100. package/dist/lib/sync-core/reconcile.js +1 -1
  101. package/dist/lib/sync-core/release-compare.d.ts +7 -0
  102. package/dist/lib/sync-core/release-compare.js +16 -0
  103. package/dist/lib/sync-core/release.d.ts +2 -1
  104. package/dist/lib/sync-core/release.js +2 -10
  105. package/dist/run/schema-env-overrides.d.ts +24 -0
  106. package/dist/run/schema-env-overrides.js +72 -0
  107. package/dist/utils/core-next-flag.d.ts +4 -0
  108. package/dist/utils/core-next-flag.js +22 -0
  109. package/dist/utils/core-next-kill.d.ts +16 -0
  110. package/dist/utils/core-next-kill.js +35 -0
  111. package/dist/utils/host-registration.d.ts +33 -23
  112. package/dist/utils/host-registration.js +90 -66
  113. package/package.json +14 -10
  114. package/scripts/check-function-manifest.mjs +5 -4
  115. package/dist/commands/__fixtures__/access-vault.d.ts +0 -95
  116. package/dist/commands/__fixtures__/access-vault.js +0 -166
  117. package/dist/commands/__fixtures__/make-tar.d.ts +0 -38
  118. package/dist/commands/__fixtures__/make-tar.js +0 -102
  119. package/dist/commands/secrets-public-types.test-d.d.ts +0 -2
  120. package/dist/commands/secrets-public-types.test-d.js +0 -18
  121. package/dist/lib/decisions/fixtures/us001.d.ts +0 -137
  122. package/dist/lib/decisions/fixtures/us001.js +0 -21
  123. package/dist/lib/doctor/__testing__/fake-hq-tree.d.ts +0 -226
  124. package/dist/lib/doctor/__testing__/fake-hq-tree.js +0 -408
  125. package/dist/lib/doctor/__testing__/run-doctor.d.ts +0 -8
  126. package/dist/lib/doctor/__testing__/run-doctor.js +0 -69
  127. package/dist/lib/fingerprint/fixtures.d.ts +0 -19
  128. package/dist/lib/fingerprint/fixtures.js +0 -61
  129. package/dist/lib/hot-channels/adapters/__fixtures__/dummy.d.ts +0 -33
  130. package/dist/lib/hot-channels/adapters/__fixtures__/dummy.js +0 -53
  131. package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.d.ts +0 -38
  132. package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.js +0 -64
  133. package/dist/lib/mesh/live/daemon/mqtt-events.test-d.d.ts +0 -2
  134. package/dist/lib/mesh/live/daemon/mqtt-events.test-d.js +0 -10
  135. package/dist/lib/test-utils/isolated-flag-company-context.d.ts +0 -3
  136. package/dist/lib/test-utils/isolated-flag-company-context.js +0 -18
  137. package/scripts/hook-engine-manifest.mjs +0 -22
  138. package/scripts/mesh-daemon-if-stale.mjs +0 -20
@@ -15,6 +15,7 @@
15
15
  * hq agents start|stop <uid> — EC2 start/stop
16
16
  * hq agents retry <uid> — resume setup from first non-done step
17
17
  * hq agents rm <uid> --yes — deprovision (destructive; flag-guarded)
18
+ * hq agents create-external <name> — mint an external agent + one-time enroll code
18
19
  * hq agents rotate <uid> — new enrollment code for an external agent
19
20
  * hq agents revoke <uid> --yes — revoke an external agent (--remove deletes it)
20
21
  * hq agents jobs list <uid> — off-box job roster (schedule + rate)
@@ -1272,6 +1273,48 @@ export function waitForAgentMessageWithPackageLease(waitForReply, leaseOptions =
1272
1273
  function sleep(ms) {
1273
1274
  return new Promise((resolve) => setTimeout(resolve, ms));
1274
1275
  }
1276
+ export const VALID_EXTERNAL_FRAMEWORKS = new Set([
1277
+ "grokbot",
1278
+ "openclaw",
1279
+ "mcp",
1280
+ ]);
1281
+ export const VALID_EXTERNAL_MEMBERSHIP_ROLES = new Set(["member", "admin"]);
1282
+ /**
1283
+ * POST /v1/companies/{companyUid}/agents/external — admin mint of an external
1284
+ * bot. Returns the one-time enrollment code exactly once (api-contract v1).
1285
+ * Console Add bot no longer exposes this path (feedback_6e5798b3).
1286
+ */
1287
+ export async function createExternalAgent(token, companyUid, input) {
1288
+ const body = {
1289
+ name: input.name,
1290
+ framework: input.framework,
1291
+ };
1292
+ if (input.membershipRole)
1293
+ body.membershipRole = input.membershipRole;
1294
+ const data = await agentsRequest({
1295
+ token,
1296
+ path: `/v1/companies/${encodeURIComponent(companyUid)}/agents/external`,
1297
+ method: "POST",
1298
+ body,
1299
+ });
1300
+ const e = data.enrollment ?? {};
1301
+ if (typeof e.code !== "string" || !e.code) {
1302
+ throw new AgentsHttpError(502, "create-external succeeded but the response carried no enrollment code");
1303
+ }
1304
+ if (typeof data.agentUid !== "string" || !data.agentUid) {
1305
+ throw new AgentsHttpError(502, "create-external succeeded but the response carried no agentUid");
1306
+ }
1307
+ return {
1308
+ agentUid: data.agentUid,
1309
+ agentEmail: typeof data.agentEmail === "string" ? data.agentEmail : "",
1310
+ framework: typeof data.framework === "string" ? data.framework : input.framework,
1311
+ enrollment: {
1312
+ code: e.code,
1313
+ expiresAt: typeof e.expiresAt === "string" ? e.expiresAt : "",
1314
+ enrollmentId: typeof e.enrollmentId === "string" ? e.enrollmentId : "",
1315
+ },
1316
+ };
1317
+ }
1275
1318
  /**
1276
1319
  * POST /v1/agents/{uid}/rotate — invalidate the current secret and host key
1277
1320
  * and issue a fresh one-time enrollment code (returned exactly once).
@@ -1313,6 +1356,20 @@ export async function revokeAgent(token, agentUid, remove) {
1313
1356
  });
1314
1357
  return { removed: data.removed === true || remove };
1315
1358
  }
1359
+ /** Lines printed after create-external: the code is shown once and never stored. */
1360
+ export function formatCreateExternalOutput(result) {
1361
+ const lines = [
1362
+ `Created external agent ${result.agentUid}${result.agentEmail ? ` (${result.agentEmail})` : ""}.`,
1363
+ ` framework: ${result.framework}`,
1364
+ "",
1365
+ ` enrollment code: ${groupEnrollmentCode(result.enrollment.code)}`,
1366
+ ];
1367
+ if (result.enrollment.expiresAt) {
1368
+ lines.push(` expires: ${result.enrollment.expiresAt} (15 minutes)`);
1369
+ }
1370
+ lines.push("", "Shown once. On the agent's host run:", ` hq agent enroll ${groupEnrollmentCode(result.enrollment.code)}`, " hq agent probe");
1371
+ return lines;
1372
+ }
1316
1373
  /** Lines printed after a rotate: the code is shown once and never stored. */
1317
1374
  export function formatRotateOutput(result) {
1318
1375
  const lines = [
@@ -1383,10 +1440,11 @@ export function registerAgentsCommand(program) {
1383
1440
  // `/v1/keys/agents/{uid}/terminal` route, so machine keys fail closed.
1384
1441
  terminal: { capability: "agents:use", routeAvailable: false },
1385
1442
  // External-agent lifecycle is an admin action on the JWT-only
1386
- // /v1/agents/{uid}/rotate|revoke routes (api-contract v1); no keyed
1443
+ // create-external / rotate / revoke routes (api-contract v1); no keyed
1387
1444
  // parallel exists, so machine keys fail closed here too.
1388
1445
  rotate: { capability: "agents:use", routeAvailable: false },
1389
1446
  revoke: { capability: "agents:use", routeAvailable: false },
1447
+ "create-external": { capability: "agents:use", routeAvailable: false },
1390
1448
  },
1391
1449
  });
1392
1450
  // `--company` may live on the group or the subcommand; the subcommand value
@@ -2137,6 +2195,39 @@ export function registerAgentsCommand(program) {
2137
2195
  fail(err);
2138
2196
  }
2139
2197
  });
2198
+ agents
2199
+ .command("create-external <name>")
2200
+ .description("Create an external bot and print a one-time enrollment code")
2201
+ .option("--company <slug>", "Company slug (resolves to companyUid)")
2202
+ .option("--framework <framework>", "Bot framework: grokbot, openclaw, or mcp")
2203
+ .option("--role <role>", "Membership role: member (default) or admin")
2204
+ .option("--json", "Emit raw JSON (code included — pipe carefully)")
2205
+ .action(async function (name, opts) {
2206
+ const framework = parseEnumOption(opts.framework, VALID_EXTERNAL_FRAMEWORKS, "--framework");
2207
+ if (!framework) {
2208
+ console.error(chalk.red("--framework is required: grokbot, openclaw, or mcp"));
2209
+ process.exit(1);
2210
+ }
2211
+ const membershipRole = parseEnumOption(opts.role, VALID_EXTERNAL_MEMBERSHIP_ROLES, "--role");
2212
+ try {
2213
+ const token = (await resolveVaultCredential()).token;
2214
+ const companyUid = await getCompanyUid(token, companyOf(this));
2215
+ const result = await createExternalAgent(token, companyUid, {
2216
+ name,
2217
+ framework,
2218
+ ...(membershipRole ? { membershipRole } : {}),
2219
+ });
2220
+ if (opts.json) {
2221
+ console.log(JSON.stringify(result, null, 2));
2222
+ return;
2223
+ }
2224
+ for (const line of formatCreateExternalOutput(result))
2225
+ console.log(line);
2226
+ }
2227
+ catch (err) {
2228
+ fail(err);
2229
+ }
2230
+ });
2140
2231
  agents
2141
2232
  .command("rotate <agentUid>")
2142
2233
  .description("Issue a fresh enrollment code for an external agent (old secret + host key stop minting)")
@@ -1,4 +1,5 @@
1
1
  import { type LegacyMoveState, type LegacyProviderLoginProbe } from "../lib/bot/legacy-convert.js";
2
+ import { type ClaudeLoginNow, type SignalsClaudeLogin } from "../lib/hot-channels/signals-claude-login.js";
2
3
  import { Command } from "commander";
3
4
  import { type ExecutiveBot } from "../lib/bot/executive.js";
4
5
  import { waitForGatewayReady, type BotReadiness, type ReadyWaitResult } from "../lib/bot/readiness.js";
@@ -70,6 +71,12 @@ export interface BotRow {
70
71
  runtimeSignedIn: boolean | null;
71
72
  /** The terminal command that signs the bot's coding tool in on this computer. */
72
73
  signInCommand: string;
74
+ /**
75
+ * The Claude Code login the hot-channel signals pass needs, which can differ
76
+ * from the bot's own runtime login (a Codex bot still runs signals on
77
+ * Claude Code). Only for a bot with the hot-signal-sync job; null otherwise.
78
+ */
79
+ signalsClaudeSignIn: SignalsClaudeSignIn | null;
73
80
  /**
74
81
  * Set when the bot cannot run until its model provider is signed in, on any
75
82
  * engine: a Fleet bot never signed in or whose last turn failed on auth, a
@@ -161,6 +168,47 @@ export declare function ownerSignInAllowed(): boolean;
161
168
  * sign-out, and the next start checks afresh.
162
169
  */
163
170
  export declare function runtimeSignedIn(status: Pick<BotStatusFile, "runtimeSignIn" | "runtimeSignInCheck"> | null | undefined, processAlive: boolean): boolean | null;
171
+ export interface SignalsClaudeSignIn {
172
+ /** The companies this bot runs the hot-signal-sync job for. */
173
+ companies: string[];
174
+ /**
175
+ * Whether Claude Code is signed in for signals: the live check when it
176
+ * answered, else what the last signals pass saw; null when neither knows.
177
+ */
178
+ signedIn: boolean | null;
179
+ /** Where `signedIn` came from. */
180
+ basis: "live" | "last-signals-pass" | "none";
181
+ /** This status call's `claude auth status` (once per call); null when it was not run. */
182
+ liveCheck: ClaudeLoginNow | null;
183
+ /** What the last signals pass saw (secondary context); null when none was recorded. */
184
+ lastSignalsPass: {
185
+ signedIn: boolean;
186
+ checkedAt: string;
187
+ signedOutSince: string | null;
188
+ } | null;
189
+ /** The last signals pass's record time; kept with `source` and `signedOutSince` for older readers. */
190
+ checkedAt: string | null;
191
+ source: SignalsClaudeLogin["source"] | null;
192
+ /** While the last signals pass saw it signed out: since when. */
193
+ signedOutSince: string | null;
194
+ /** Set when Claude is signed in now but the last signals pass failed signed out. */
195
+ queuedDocsHint: string | null;
196
+ /** Where to sign in: the HQ app first, the terminal command as the fallback. */
197
+ fix: string;
198
+ command: string;
199
+ }
200
+ /** The live check `hq bot status` / `list` run once per call. Tests replace it. */
201
+ export declare const signalsClaudeSeams: {
202
+ check: () => Promise<ClaudeLoginNow>;
203
+ };
204
+ /**
205
+ * `signalsClaudeSignIn` for a row, for a bot with the hot-signal-sync job:
206
+ * the live check when given and it answered, the last signals pass's record
207
+ * as secondary context and as the fallback. Never runs `claude` itself.
208
+ */
209
+ export declare function signalsClaudeSignInFor(dir: string, fleet: boolean, record?: SignalsClaudeLogin | null, live?: ClaudeLoginNow | null): SignalsClaudeSignIn | null;
210
+ /** The status lines for the Claude Code login signals needs: the answer first, the last signals pass as context. */
211
+ export declare function signalsClaudeSignInLines(s: SignalsClaudeSignIn): string[];
164
212
  export interface BrainSignIn {
165
213
  provider: BotRuntimeId;
166
214
  needed: true;
@@ -8,8 +8,9 @@ import { runSignals } from "../lib/signals/engine.js";
8
8
  import { defaultResolveBotRuntime } from "../lib/signals/steps/extract.js";
9
9
  import { BOT_SIGNALS_ENGINE_JOB_FLAG, signalsEngineForJob } from "../lib/bot/signals-engine-flag.js";
10
10
  import { resolveProcessFlagGate } from "../lib/flag-registry.js";
11
- import { currentHotSignalSyncCompany, readActiveCompanySlug, registerHotSignalSyncOnStart, runHotSignalSyncJob } from "../lib/bot/jobs/hot-signal-sync.js";
12
- import { createClaudeSignalsPass } from "../lib/hot-channels/signals-pass.js";
11
+ import { currentHotSignalSyncCompany, hasScheduledBriefJob, hotSignalSyncJobCompanies, readActiveCompanySlug, registerHotSignalSyncOnStart, runHotSignalSyncJob } from "../lib/bot/jobs/hot-signal-sync.js";
12
+ import { CLAUDE_SIGN_IN_STEPS, createClaudeSignalsPass } from "../lib/hot-channels/signals-pass.js";
13
+ import { checkClaudeLoginNow, readSignalsClaudeLogin, recordSignalsPassClaudeLogin } from "../lib/hot-channels/signals-claude-login.js";
13
14
  import { machineTimeZone } from "../lib/bot/job-run.js";
14
15
  import { runCompanyHotChannelSync } from "./sources.js";
15
16
  import { OwnerContextCache, lookupOwnerContext } from "../lib/bot/owner-context.js";
@@ -510,6 +511,85 @@ export function runtimeSignedIn(status, processAlive) {
510
511
  return false;
511
512
  return status.runtimeSignInCheck?.signedIn ?? null;
512
513
  }
514
+ /** The live check `hq bot status` / `list` run once per call. Tests replace it. */
515
+ export const signalsClaudeSeams = {
516
+ check: () => checkClaudeLoginNow(),
517
+ };
518
+ /**
519
+ * `signalsClaudeSignIn` for a row, for a bot with the hot-signal-sync job:
520
+ * the live check when given and it answered, the last signals pass's record
521
+ * as secondary context and as the fallback. Never runs `claude` itself.
522
+ */
523
+ export function signalsClaudeSignInFor(dir, fleet, record = readSignalsClaudeLogin(), live = null) {
524
+ const companies = hotSignalSyncJobCompanies(dir, { fleet });
525
+ if (companies.length === 0)
526
+ return null;
527
+ const signedOutSince = record && !record.signedIn ? (record.signedOutSince ?? record.checkedAt) : null;
528
+ const liveAnswer = live && live.signedIn !== null ? live.signedIn : null;
529
+ const signedIn = liveAnswer ?? record?.signedIn ?? null;
530
+ const basis = liveAnswer !== null ? "live" : record ? "last-signals-pass" : "none";
531
+ const queuedDocsHint = liveAnswer === true && record?.signedIn === false
532
+ ? `queued documents run at the next sync, or run ${companies.map((c) => `\`hq sources sync --company ${c}\``).join(" or ")} now`
533
+ : null;
534
+ return {
535
+ companies,
536
+ signedIn,
537
+ basis,
538
+ liveCheck: live,
539
+ lastSignalsPass: record ? { signedIn: record.signedIn, checkedAt: record.checkedAt, signedOutSince } : null,
540
+ checkedAt: record?.checkedAt ?? null,
541
+ source: record?.source ?? null,
542
+ signedOutSince,
543
+ queuedDocsHint,
544
+ fix: CLAUDE_SIGN_IN_STEPS,
545
+ command: signInCommand("claude"),
546
+ };
547
+ }
548
+ /**
549
+ * Run the live check once for this status call, only when some row has the
550
+ * signals job, and fill it into those rows. Never throws: a failed check
551
+ * leaves the rows on the last signals pass's record and says so.
552
+ */
553
+ async function decorateSignalsClaudeLive(rows) {
554
+ const targets = rows.filter((row) => row.signalsClaudeSignIn !== null);
555
+ if (targets.length === 0)
556
+ return;
557
+ let live;
558
+ try {
559
+ live = await signalsClaudeSeams.check();
560
+ }
561
+ catch (err) {
562
+ live = { signedIn: null, checkedAt: new Date().toISOString(), error: err instanceof Error ? err.message : String(err) };
563
+ }
564
+ const record = readSignalsClaudeLogin();
565
+ for (const row of targets) {
566
+ row.signalsClaudeSignIn = signalsClaudeSignInFor(row.dir, row.engine === HQ_FLEET_RUNTIME_ENGINE_ID, record, live);
567
+ }
568
+ }
569
+ /** The status lines for the Claude Code login signals needs: the answer first, the last signals pass as context. */
570
+ export function signalsClaudeSignInLines(s) {
571
+ const forWhat = `(hot-channel signals for ${s.companies.join(", ")})`;
572
+ const state = s.signedIn === true
573
+ ? chalk.green("Claude Code signed in")
574
+ : s.signedIn === false
575
+ ? chalk.yellow("Claude Code signed out")
576
+ : chalk.gray("Claude Code sign-in unknown");
577
+ const how = s.basis === "live"
578
+ ? "checked now"
579
+ : s.liveCheck?.error
580
+ ? `live check failed (${s.liveCheck.error}); from the last signals pass`
581
+ : s.basis === "last-signals-pass"
582
+ ? "from the last signals pass"
583
+ : "not checked";
584
+ const lines = [`${state} ${forWhat} ${chalk.dim(how)}${s.signedIn === false ? ` - ${s.fix}` : ""}`];
585
+ const last = s.lastSignalsPass;
586
+ if (last) {
587
+ lines.push(chalk.dim(`signals last saw Claude Code ${last.signedIn ? "signed in" : "signed out"} at ${last.checkedAt}${!last.signedIn && last.signedOutSince && last.signedOutSince !== last.checkedAt ? ` (since ${last.signedOutSince})` : ""}`));
588
+ }
589
+ if (s.queuedDocsHint)
590
+ lines.push(s.queuedDocsHint);
591
+ return lines;
592
+ }
513
593
  /**
514
594
  * `brainUsage` for a row. A model-CLI bot records it itself (status.brainUsage);
515
595
  * a Fleet bot's last failure carries the runtime's `brain_usage`, and an older
@@ -635,6 +715,7 @@ function rowFor(name, opts = {}) {
635
715
  ...(fleet && config.fleetAuthPending === true ? { needsSignIn: true, authCommand: fleetAuthCommand(name, config) } : {}),
636
716
  ...(fleet && config.fleetServiceInstallPending === true ? { needsSignIn: false, serviceInstallPending: true } : {}),
637
717
  signInCommand: fleet ? fleetAuthCommand(name, config) : signInCommand(config.runtime),
718
+ signalsClaudeSignIn: signalsClaudeSignInFor(dir, fleet),
638
719
  brainSignIn: brainSignInFor(name, config, status, legacy),
639
720
  brainUsage: brainUsageFor(config, status),
640
721
  ...(legacy ? { legacy: legacyStatusJson(legacy) } : {}),
@@ -2102,18 +2183,23 @@ async function runBotResident(nameArg) {
2102
2183
  // the first sync starts in the background right after the job is created.
2103
2184
  // US-006: a fired job runs the signals engine (garden -> adapters ->
2104
2185
  // extract -> garden -> upload) and replies in the storyboarded format.
2105
- const runHotSignalSync = (input) =>
2106
- // The engine is gated default-off (cli.bot-signals-engine-job); with the
2107
- // flag off the job runs the hot-channel sync alone, as before US-006.
2108
- signalsEngineForJob(runSignals).then((signals) => runHotSignalSyncJob({
2186
+ const hotSignalSyncJob = (input, signals) => runHotSignalSyncJob({
2109
2187
  ...input,
2110
2188
  hqRoot: config.hqRoot,
2111
2189
  timeZone: input.timeZone ?? machineTimeZone(),
2190
+ // This local bot replies in the owner's HQ DM, which the desktop app
2191
+ // shows: the reply links today's brief with hq-desktop://brief (US-023).
2192
+ desktopLinks: true,
2193
+ // Read per run, so a brief job added or removed since start counts.
2194
+ briefJobScheduled: hasScheduledBriefJob(dir),
2112
2195
  ...(signals ? { signals } : {}),
2113
2196
  sync: (syncInput) => runCompanyHotChannelSync({ hqRoot: config.hqRoot, ...syncInput }),
2114
2197
  // A new pass per run: the login preflight and the 20-document cap are per run.
2115
- signalsPass: createClaudeSignalsPass({ hqRoot: config.hqRoot, company: input.company, botRuntime: defaultResolveBotRuntime }),
2116
- }));
2198
+ signalsPass: createClaudeSignalsPass({ hqRoot: config.hqRoot, company: input.company, botRuntime: defaultResolveBotRuntime, onClaudeLogin: recordSignalsPassClaudeLogin }),
2199
+ });
2200
+ // The engine is gated default-off (cli.bot-signals-engine-job); with the
2201
+ // flag off the job runs the hot-channel sync alone, as before US-006.
2202
+ const runHotSignalSync = (input) => signalsEngineForJob(runSignals).then((signals) => hotSignalSyncJob(input, signals));
2117
2203
  // Prefer the Executive bot for daily hot-channel sync. Other personal bots
2118
2204
  // keep their company covered until the Executive has a replacement job.
2119
2205
  // Identity only (never the executive.enabled opt-in); with no personal bot
@@ -2137,6 +2223,15 @@ async function runBotResident(nameArg) {
2137
2223
  runtime: runtimeFor(config.runtime),
2138
2224
  ownerContext: () => owner.get(),
2139
2225
  hotSignalSync: (input) => runHotSignalSync(input),
2226
+ // US-006 AC9: the member's "Try now" runs the same entry point as the job,
2227
+ // as `--trigger chat --force`, behind the same cli.bot-signals-engine-job
2228
+ // flag. Flag off: null, and the message goes to the model as before.
2229
+ signalsTryNow: async () => {
2230
+ const signals = await signalsEngineForJob(runSignals);
2231
+ if (!signals)
2232
+ return null;
2233
+ return (input) => hotSignalSyncJob({ ...input, catchUp: false, tryNow: true }, signals);
2234
+ },
2140
2235
  // US-005: decision picks in the owner DM, with the bot's own machine token
2141
2236
  // (never the owner's login).
2142
2237
  decisions: new DecisionsClient(token),
@@ -2190,6 +2285,7 @@ async function runBotList(opts) {
2190
2285
  const executiveBot = resolveExecutiveBot();
2191
2286
  const rows = listBotNames(botsRoot()).map((n) => rowFor(n, { executiveBot }));
2192
2287
  await decorateOnline(rows);
2288
+ await decorateSignalsClaudeLive(rows);
2193
2289
  if (opts.json) {
2194
2290
  console.log(JSON.stringify({
2195
2291
  bots: rows,
@@ -2306,6 +2402,7 @@ async function runBotStatus(nameArg, opts) {
2306
2402
  const legacy = fleet ? null : legacyMoveState(dir, config, legacyConvertSeams.providerLogin(dir, config));
2307
2403
  const row = rowFor(name, { legacy });
2308
2404
  await decorateOnline([row]);
2405
+ await decorateSignalsClaudeLive([row]);
2309
2406
  const status = readBotStatus(dir);
2310
2407
  const creds = readBotCredsIdentity(dir);
2311
2408
  const channels = fleet ? fleetLocalChannels(readFleetLocalGatewayState(config.agentUid), row.processAlive) : null;
@@ -2338,6 +2435,9 @@ async function runBotStatus(nameArg, opts) {
2338
2435
  console.log(` readiness: ${row.readiness === "ready" ? chalk.green(`ready${row.readyAt ? ` since ${row.readyAt}` : ""}`) : row.readiness === "offline" ? chalk.gray("offline") : chalk.yellow(row.readiness)}`);
2339
2436
  if (row.needsSignIn)
2340
2437
  console.log(` sign-in: required (${row.authCommand})`);
2438
+ if (row.signalsClaudeSignIn) {
2439
+ signalsClaudeSignInLines(row.signalsClaudeSignIn).forEach((line, i) => console.log(` ${i === 0 ? "signals: " : " "}${line}`));
2440
+ }
2341
2441
  if (row.brainUsage.state === "exhausted") {
2342
2442
  console.log(` usage: ${chalk.yellow(`out of usage${row.brainUsage.resetsAt ? `, resets ${row.brainUsage.resetsAt}` : ""}`)} — switch account: hq bot switch-account ${name} --runtime <claude|codex|grok>`);
2343
2443
  }
@@ -11,6 +11,7 @@
11
11
  * hq sync push [paths...] — broadcast local file(s) to the vault
12
12
  * hq sync pull — pull all permitted files from the vault
13
13
  * hq sync status — show local journal summary
14
+ * (also `hq daemon sync status --local`)
14
15
  */
15
16
  import { Command } from "commander";
16
17
  import { type ConflictStrategy, type EntityContext, type MembershipSyncConfig, type SyncMode, type PullScope, type ExplicitGrant, type ShareOptions, type VaultServiceConfig } from "@indigoai-us/hq-cloud";
@@ -692,6 +693,21 @@ export declare function nowPushLegRefused(input: {
692
693
  uploadFailedCount: number;
693
694
  identityHeldCount: number;
694
695
  }): boolean;
696
+ /** Options shared by `hq sync status` and `hq daemon sync status --local`. */
697
+ export interface SyncJournalStatusOptions {
698
+ /** HQ root given on the command line; undefined means the default root (not checked). */
699
+ hqRoot?: string;
700
+ company?: string;
701
+ all?: boolean;
702
+ json?: boolean;
703
+ }
704
+ /**
705
+ * The local sync-journal summary printed by `hq sync status` and
706
+ * `hq daemon sync status --local`: per-scope summaries plus the read-only and
707
+ * server-owned local-only lists, as text or (`json`) the full JSON. Exits the
708
+ * process with status 1 on an error, after printing "✗ Status failed:".
709
+ */
710
+ export declare function runSyncJournalStatus(options: SyncJournalStatusOptions): void;
695
711
  /**
696
712
  * Human-friendly label for a journal slug in `hq sync status`. The
697
713
  * personal-vault fanout slot and the legacy `companies/personal` company both
@@ -11,6 +11,7 @@
11
11
  * hq sync push [paths...] — broadcast local file(s) to the vault
12
12
  * hq sync pull — pull all permitted files from the vault
13
13
  * hq sync status — show local journal summary
14
+ * (also `hq daemon sync status --local`)
14
15
  */
15
16
  import { isAccessDeniedError, accessDeniedKeyOf, formatAccessDenied, } from "../utils/access-denied-hint.js";
16
17
  import { describeSyncError, formatRemoteListNotConverging, } from "../utils/remote-list-not-converging.js";
@@ -1909,108 +1910,7 @@ export function registerCloudCommands(program) {
1909
1910
  .option("--json", "Print the full status as JSON (every list uncapped) instead of text")
1910
1911
  .action((options, command) => {
1911
1912
  const explicitHqRoot = command.getOptionValueSource("hqRoot") === "cli";
1912
- try {
1913
- const hqRoot = options.hqRoot;
1914
- if (explicitHqRoot) {
1915
- if (!fs.existsSync(hqRoot)) {
1916
- throw new Error(`HQ root does not exist: ${hqRoot}`);
1917
- }
1918
- if (!fs.statSync(hqRoot).isDirectory()) {
1919
- throw new Error(`HQ root is not a directory: ${hqRoot}`);
1920
- }
1921
- }
1922
- // The engine SHARDS the journal by slug — the personal-vault fanout
1923
- // slot, one shard per cloud company, and the legacy "personal" shard.
1924
- // Enumerate EVERY shard the engine can write (via the engine's own
1925
- // `listJournals`) rather than reconstructing a single path: the old
1926
- // code passed the HQ-root PATH where a slug was expected, so it always
1927
- // looked at `sync-journal._Users_<user>_hq.json` — a slug the engine
1928
- // never writes — and printed "No sync journal yet" right after a
1929
- // successful sync (feedback_9fbf1f82 / feedback_46288b7b).
1930
- const configPath = path.join(hqRoot, ".hq", "config.json");
1931
- let activeCompany;
1932
- if (fs.existsSync(configPath)) {
1933
- try {
1934
- const cfg = JSON.parse(fs.readFileSync(configPath, "utf-8"));
1935
- activeCompany = cfg.activeCompany;
1936
- }
1937
- catch {
1938
- // ignore
1939
- }
1940
- }
1941
- // Journals live in the machine-wide state directory, independently
1942
- // of the HQ content root selected for this status display.
1943
- const stateDir = getStateDir();
1944
- const companyFilter = options.company?.trim();
1945
- if (options.company !== undefined && !companyFilter) {
1946
- throw new Error("--company needs a company slug");
1947
- }
1948
- // Journals are keyed by slug; a company UID would silently match none.
1949
- if (companyFilter?.startsWith("cmp_")) {
1950
- throw new Error(`--company takes the company slug, not its UID (${companyFilter})`);
1951
- }
1952
- const journals = companyFilter
1953
- ? listJournals().filter((j) => j.slug === companyFilter)
1954
- : listJournals();
1955
- if (options.json) {
1956
- console.log(JSON.stringify(buildSyncStatusJson({ hqRoot, activeCompany, stateDir, companyFilter, journals }), null, 2));
1957
- return;
1958
- }
1959
- const showAll = options.all === true;
1960
- let grandFiles = 0;
1961
- let grandBytes = 0;
1962
- let grandLastSync = "";
1963
- console.log(chalk.bold("\nHQ Sync — Status"));
1964
- console.log(` HQ root: ${hqRoot}`);
1965
- console.log(` Active company: ${activeCompany ?? chalk.dim("(none)")}`);
1966
- console.log(` State dir: ${stateDir}`);
1967
- if (companyFilter)
1968
- console.log(` Company: ${companyFilter}`);
1969
- console.log(` Journals: ${journals.length}`);
1970
- if (journals.length === 0 && companyFilter) {
1971
- console.log(chalk.dim(`No sync journal for company "${companyFilter}" yet — run \`hq sync now --company ${companyFilter}\` to create one.`));
1972
- return;
1973
- }
1974
- if (journals.length === 0) {
1975
- console.log(chalk.dim("No sync journal yet — run `hq sync now`, `hq sync push`, or `hq sync pull` to create one."));
1976
- return;
1977
- }
1978
- for (const j of journals) {
1979
- const entries = Object.entries(j.journal.files ?? {});
1980
- // Tombstones record removed files — exclude them from "tracked".
1981
- const live = entries.filter(([, entry]) => !entry.removedAt);
1982
- const bytes = live.reduce((acc, [, entry]) => acc + (entry.size ?? 0), 0);
1983
- const lastSync = j.journal.lastSync ||
1984
- live
1985
- .map(([, entry]) => entry.syncedAt)
1986
- .filter((t) => typeof t === "string")
1987
- .sort()
1988
- .at(-1) ||
1989
- "never";
1990
- grandFiles += live.length;
1991
- grandBytes += bytes;
1992
- if (lastSync !== "never" && lastSync > grandLastSync) {
1993
- grandLastSync = lastSync;
1994
- }
1995
- console.log(`\n • ${scopeLabel(j.slug)}`);
1996
- console.log(` Tracked files: ${live.length}`);
1997
- console.log(` Total size: ${formatBytes(bytes)}`);
1998
- console.log(` Last sync: ${lastSync}`);
1999
- console.log(chalk.dim(` Journal: ${j.path}`));
2000
- }
2001
- if (journals.length > 1) {
2002
- console.log(chalk.bold("\n All scopes"));
2003
- console.log(` Tracked files: ${grandFiles}`);
2004
- console.log(` Total size: ${formatBytes(grandBytes)}`);
2005
- console.log(` Last sync: ${grandLastSync || "never"}`);
2006
- }
2007
- printReadOnlyLocalOnly(hqRoot, journals, undefined, { all: showAll });
2008
- printServerOwnedLocalOnly(hqRoot, journals, undefined, { all: showAll });
2009
- }
2010
- catch (err) {
2011
- console.error(chalk.red("✗ Status failed:"), err instanceof Error ? err.message : String(err));
2012
- process.exit(1);
2013
- }
1913
+ runSyncJournalStatus({ ...options, hqRoot: explicitHqRoot ? options.hqRoot : undefined });
2014
1914
  });
2015
1915
  program
2016
1916
  .command("now")
@@ -2849,6 +2749,116 @@ async function runNowAll(hqRoot, message, onConflict, modeAllOverride, skipPerso
2849
2749
  throw new SyncExitError(1, { health: "succeeded" });
2850
2750
  }
2851
2751
  }
2752
+ /**
2753
+ * The local sync-journal summary printed by `hq sync status` and
2754
+ * `hq daemon sync status --local`: per-scope summaries plus the read-only and
2755
+ * server-owned local-only lists, as text or (`json`) the full JSON. Exits the
2756
+ * process with status 1 on an error, after printing "✗ Status failed:".
2757
+ */
2758
+ export function runSyncJournalStatus(options) {
2759
+ try {
2760
+ const hqRoot = options.hqRoot ?? DEFAULT_HQ_ROOT;
2761
+ if (options.hqRoot !== undefined) {
2762
+ if (!fs.existsSync(hqRoot)) {
2763
+ throw new Error(`HQ root does not exist: ${hqRoot}`);
2764
+ }
2765
+ if (!fs.statSync(hqRoot).isDirectory()) {
2766
+ throw new Error(`HQ root is not a directory: ${hqRoot}`);
2767
+ }
2768
+ }
2769
+ // The engine SHARDS the journal by slug — the personal-vault fanout
2770
+ // slot, one shard per cloud company, and the legacy "personal" shard.
2771
+ // Enumerate EVERY shard the engine can write (via the engine's own
2772
+ // `listJournals`) rather than reconstructing a single path: the old
2773
+ // code passed the HQ-root PATH where a slug was expected, so it always
2774
+ // looked at `sync-journal._Users_<user>_hq.json` — a slug the engine
2775
+ // never writes — and printed "No sync journal yet" right after a
2776
+ // successful sync (feedback_9fbf1f82 / feedback_46288b7b).
2777
+ const configPath = path.join(hqRoot, ".hq", "config.json");
2778
+ let activeCompany;
2779
+ if (fs.existsSync(configPath)) {
2780
+ try {
2781
+ const cfg = JSON.parse(fs.readFileSync(configPath, "utf-8"));
2782
+ activeCompany = cfg.activeCompany;
2783
+ }
2784
+ catch {
2785
+ // ignore
2786
+ }
2787
+ }
2788
+ // Journals live in the machine-wide state directory, independently
2789
+ // of the HQ content root selected for this status display.
2790
+ const stateDir = getStateDir();
2791
+ const companyFilter = options.company?.trim();
2792
+ if (options.company !== undefined && !companyFilter) {
2793
+ throw new Error("--company needs a company slug");
2794
+ }
2795
+ // Journals are keyed by slug; a company UID would silently match none.
2796
+ if (companyFilter?.startsWith("cmp_")) {
2797
+ throw new Error(`--company takes the company slug, not its UID (${companyFilter})`);
2798
+ }
2799
+ const journals = companyFilter
2800
+ ? listJournals().filter((j) => j.slug === companyFilter)
2801
+ : listJournals();
2802
+ if (options.json) {
2803
+ console.log(JSON.stringify(buildSyncStatusJson({ hqRoot, activeCompany, stateDir, companyFilter, journals }), null, 2));
2804
+ return;
2805
+ }
2806
+ const showAll = options.all === true;
2807
+ let grandFiles = 0;
2808
+ let grandBytes = 0;
2809
+ let grandLastSync = "";
2810
+ console.log(chalk.bold("\nHQ Sync — Status"));
2811
+ console.log(` HQ root: ${hqRoot}`);
2812
+ console.log(` Active company: ${activeCompany ?? chalk.dim("(none)")}`);
2813
+ console.log(` State dir: ${stateDir}`);
2814
+ if (companyFilter)
2815
+ console.log(` Company: ${companyFilter}`);
2816
+ console.log(` Journals: ${journals.length}`);
2817
+ if (journals.length === 0 && companyFilter) {
2818
+ console.log(chalk.dim(`No sync journal for company "${companyFilter}" yet — run \`hq sync now --company ${companyFilter}\` to create one.`));
2819
+ return;
2820
+ }
2821
+ if (journals.length === 0) {
2822
+ console.log(chalk.dim("No sync journal yet — run `hq sync now`, `hq sync push`, or `hq sync pull` to create one."));
2823
+ return;
2824
+ }
2825
+ for (const j of journals) {
2826
+ const entries = Object.entries(j.journal.files ?? {});
2827
+ // Tombstones record removed files — exclude them from "tracked".
2828
+ const live = entries.filter(([, entry]) => !entry.removedAt);
2829
+ const bytes = live.reduce((acc, [, entry]) => acc + (entry.size ?? 0), 0);
2830
+ const lastSync = j.journal.lastSync ||
2831
+ live
2832
+ .map(([, entry]) => entry.syncedAt)
2833
+ .filter((t) => typeof t === "string")
2834
+ .sort()
2835
+ .at(-1) ||
2836
+ "never";
2837
+ grandFiles += live.length;
2838
+ grandBytes += bytes;
2839
+ if (lastSync !== "never" && lastSync > grandLastSync) {
2840
+ grandLastSync = lastSync;
2841
+ }
2842
+ console.log(`\n • ${scopeLabel(j.slug)}`);
2843
+ console.log(` Tracked files: ${live.length}`);
2844
+ console.log(` Total size: ${formatBytes(bytes)}`);
2845
+ console.log(` Last sync: ${lastSync}`);
2846
+ console.log(chalk.dim(` Journal: ${j.path}`));
2847
+ }
2848
+ if (journals.length > 1) {
2849
+ console.log(chalk.bold("\n All scopes"));
2850
+ console.log(` Tracked files: ${grandFiles}`);
2851
+ console.log(` Total size: ${formatBytes(grandBytes)}`);
2852
+ console.log(` Last sync: ${grandLastSync || "never"}`);
2853
+ }
2854
+ printReadOnlyLocalOnly(hqRoot, journals, undefined, { all: showAll });
2855
+ printServerOwnedLocalOnly(hqRoot, journals, undefined, { all: showAll });
2856
+ }
2857
+ catch (err) {
2858
+ console.error(chalk.red("✗ Status failed:"), err instanceof Error ? err.message : String(err));
2859
+ process.exit(1);
2860
+ }
2861
+ }
2852
2862
  /**
2853
2863
  * Best-effort read of the active company slug from `<hqRoot>/.hq/config.json`.
2854
2864
  * Returns undefined when the file is missing, malformed, or has no
@@ -90,6 +90,19 @@ export type WriteStampsOptions = {
90
90
  waitForRetry?: (delayMs: number) => void;
91
91
  };
92
92
  export declare function writeStamps(liveRoot: string, sessionId: string | undefined, options?: WriteStampsOptions): string[];
93
+ /**
94
+ * Test seam: runs after the auto thread was found and before the existence
95
+ * re-check, so a test can delete or rename the thread in that window.
96
+ */
97
+ export declare const checkpointTestSeams: {
98
+ beforeAutoThreadWrite?: () => void;
99
+ };
100
+ /**
101
+ * Write through a temp file in the same directory, then rename (atomic). On any
102
+ * failure the temp file is removed and the error is rethrown. `fsImpl` is a
103
+ * test seam.
104
+ */
105
+ export declare function writeFileAtomic(target: string, contents: string, fsImpl?: Pick<typeof fs, "writeFileSync" | "renameSync" | "unlinkSync">): void;
93
106
  /**
94
107
  * True when an automatic checkpoint for this session already started (or
95
108
  * queued) a sibling within AUTO_SIBLING_MIN_INTERVAL_MS. Without a session ID