@indigoai-us/hq-cli 5.345.214 → 5.345.215

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 (200) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/assets/scaffold/core/scripts/hq-delegate-verify.sh +5 -2
  3. package/dist/command-catalog.generated.d.ts +180 -13
  4. package/dist/command-catalog.generated.js +221 -13
  5. package/dist/commands/agents.d.ts +51 -1
  6. package/dist/commands/agents.js +154 -2
  7. package/dist/commands/bot-jobs.d.ts +2 -15
  8. package/dist/commands/bot-jobs.js +2 -94
  9. package/dist/commands/bot-runtime.d.ts +46 -5
  10. package/dist/commands/bot-runtime.js +228 -18
  11. package/dist/commands/bot.d.ts +16 -9
  12. package/dist/commands/bot.js +231 -55
  13. package/dist/commands/capacity.d.ts +4 -1
  14. package/dist/commands/capacity.js +46 -10
  15. package/dist/commands/cloud.d.ts +66 -13
  16. package/dist/commands/cloud.js +121 -40
  17. package/dist/commands/company-restore.d.ts +23 -0
  18. package/dist/commands/company-restore.js +128 -0
  19. package/dist/commands/company.js +2 -0
  20. package/dist/commands/core-delegate-w1b.js +15 -1
  21. package/dist/commands/core-policy.js +67 -8
  22. package/dist/commands/daemon.js +5 -0
  23. package/dist/commands/files-browse.d.ts +11 -4
  24. package/dist/commands/files-browse.js +21 -4
  25. package/dist/commands/files.d.ts +1 -1
  26. package/dist/commands/files.js +25 -11
  27. package/dist/commands/integrations-auth-rules.d.ts +27 -0
  28. package/dist/commands/integrations-auth-rules.js +79 -0
  29. package/dist/commands/integrations-connect.d.ts +10 -3
  30. package/dist/commands/integrations-connect.js +87 -13
  31. package/dist/commands/integrations-import.js +124 -12
  32. package/dist/commands/lanes.js +28 -11
  33. package/dist/commands/mesh.d.ts +2 -0
  34. package/dist/commands/mesh.js +60 -35
  35. package/dist/commands/sources.js +6 -0
  36. package/dist/commands/storage-offload.d.ts +12 -0
  37. package/dist/commands/storage-offload.js +41 -3
  38. package/dist/commands/sync-held.js +5 -2
  39. package/dist/commands/sync-mode.js +5 -0
  40. package/dist/commands/whoami.js +4 -0
  41. package/dist/lazy-commands.js +3 -5
  42. package/dist/lib/bot/config.d.ts +1 -0
  43. package/dist/lib/bot/config.js +10 -0
  44. package/dist/lib/bot/eventbridge-cron.d.ts +22 -0
  45. package/dist/lib/bot/eventbridge-cron.js +104 -0
  46. package/dist/lib/bot/fleet-cron.d.ts +8 -0
  47. package/dist/lib/bot/fleet-cron.js +35 -3
  48. package/dist/lib/bot/fleet-daemon.d.ts +46 -0
  49. package/dist/lib/bot/fleet-daemon.js +99 -1
  50. package/dist/lib/bot/fleet-local.d.ts +33 -1
  51. package/dist/lib/bot/fleet-local.js +215 -31
  52. package/dist/lib/bot/fleet-python.d.ts +3 -0
  53. package/dist/lib/bot/fleet-python.js +34 -4
  54. package/dist/lib/bot/fleet-runtime-sources.d.ts +15 -0
  55. package/dist/lib/bot/fleet-runtime-sources.js +30 -0
  56. package/dist/lib/bot/legacy-provider-login.d.ts +8 -0
  57. package/dist/lib/bot/legacy-provider-login.js +19 -2
  58. package/dist/lib/bot/probe.js +7 -1
  59. package/dist/lib/bot/prompt.js +1 -1
  60. package/dist/lib/bot/readiness.d.ts +8 -0
  61. package/dist/lib/bot/readiness.js +17 -3
  62. package/dist/lib/bot/run.js +20 -1
  63. package/dist/lib/bot/runtime/codex.js +1 -1
  64. package/dist/lib/bot/runtime/grok-acp.d.ts +5 -1
  65. package/dist/lib/bot/runtime/grok-acp.js +6 -3
  66. package/dist/lib/bot/runtime/index.js +19 -9
  67. package/dist/lib/bot/runtime/messages-stream.js +2 -2
  68. package/dist/lib/bot/runtime/types.d.ts +15 -0
  69. package/dist/lib/bot/runtime/types.js +9 -0
  70. package/dist/lib/bot/runtime-auth.d.ts +30 -0
  71. package/dist/lib/bot/runtime-auth.js +94 -3
  72. package/dist/lib/bot/runtime-failure.d.ts +23 -0
  73. package/dist/lib/bot/runtime-failure.js +43 -1
  74. package/dist/lib/bot/status.d.ts +2 -0
  75. package/dist/lib/capacity/accounts.d.ts +8 -0
  76. package/dist/lib/capacity/accounts.js +19 -0
  77. package/dist/lib/capacity/available.d.ts +154 -0
  78. package/dist/lib/capacity/available.js +905 -0
  79. package/dist/lib/capacity/codex-availability.d.ts +14 -1
  80. package/dist/lib/capacity/codex-availability.js +26 -1
  81. package/dist/lib/capacity/collectors/claude-oauth.d.ts +29 -2
  82. package/dist/lib/capacity/collectors/claude-oauth.js +104 -7
  83. package/dist/lib/capacity/collectors/codex.js +10 -7
  84. package/dist/lib/capacity/collectors/grok-refresh.d.ts +80 -0
  85. package/dist/lib/capacity/collectors/grok-refresh.js +189 -0
  86. package/dist/lib/capacity/collectors/grok.d.ts +5 -0
  87. package/dist/lib/capacity/collectors/grok.js +56 -5
  88. package/dist/lib/capacity/ledger.d.ts +37 -1
  89. package/dist/lib/capacity/ledger.js +207 -30
  90. package/dist/lib/capacity/project.d.ts +26 -0
  91. package/dist/lib/capacity/project.js +137 -8
  92. package/dist/lib/capacity/refusal-rows.d.ts +31 -0
  93. package/dist/lib/capacity/refusal-rows.js +61 -0
  94. package/dist/lib/capacity/refusal.d.ts +53 -2
  95. package/dist/lib/capacity/refusal.js +284 -65
  96. package/dist/lib/capacity/route.js +46 -11
  97. package/dist/lib/capacity/widget.d.ts +12 -1
  98. package/dist/lib/capacity/widget.js +91 -3
  99. package/dist/lib/daemon/catalog.js +11 -1
  100. package/dist/lib/daemon/resolver.d.ts +2 -0
  101. package/dist/lib/daemon/resolver.js +3 -0
  102. package/dist/lib/daemon/run.d.ts +9 -0
  103. package/dist/lib/daemon/run.js +54 -1
  104. package/dist/lib/daemon/server.d.ts +2 -0
  105. package/dist/lib/daemon/server.js +10 -1
  106. package/dist/lib/daemon/tcc-eperm.d.ts +153 -0
  107. package/dist/lib/daemon/tcc-eperm.js +310 -0
  108. package/dist/lib/db/sqlite-binding.d.ts +1 -0
  109. package/dist/lib/db/sqlite-binding.js +1 -1
  110. package/dist/lib/delivery/admission.d.ts +86 -0
  111. package/dist/lib/delivery/admission.js +148 -0
  112. package/dist/lib/delivery/artifacts.d.ts +105 -0
  113. package/dist/lib/delivery/artifacts.js +567 -0
  114. package/dist/lib/delivery/attempt-id.d.ts +13 -0
  115. package/dist/lib/delivery/attempt-id.js +16 -0
  116. package/dist/lib/delivery/backup.d.ts +78 -0
  117. package/dist/lib/delivery/backup.js +343 -0
  118. package/dist/lib/delivery/cache.d.ts +29 -0
  119. package/dist/lib/delivery/cache.js +33 -0
  120. package/dist/lib/delivery/contracts.d.ts +142 -0
  121. package/dist/lib/delivery/contracts.js +289 -0
  122. package/dist/lib/delivery/credentials.d.ts +54 -0
  123. package/dist/lib/delivery/credentials.js +119 -0
  124. package/dist/lib/delivery/disposable-target.d.ts +42 -0
  125. package/dist/lib/delivery/disposable-target.js +111 -0
  126. package/dist/lib/delivery/effects.d.ts +136 -0
  127. package/dist/lib/delivery/effects.js +541 -0
  128. package/dist/lib/delivery/enrollment.d.ts +146 -0
  129. package/dist/lib/delivery/enrollment.js +460 -0
  130. package/dist/lib/delivery/escalations.d.ts +51 -0
  131. package/dist/lib/delivery/escalations.js +60 -0
  132. package/dist/lib/delivery/identity.d.ts +25 -0
  133. package/dist/lib/delivery/identity.js +82 -0
  134. package/dist/lib/delivery/inbox.d.ts +116 -0
  135. package/dist/lib/delivery/inbox.js +260 -0
  136. package/dist/lib/delivery/lease.d.ts +80 -0
  137. package/dist/lib/delivery/lease.js +134 -0
  138. package/dist/lib/delivery/migrations.d.ts +255 -0
  139. package/dist/lib/delivery/migrations.js +823 -0
  140. package/dist/lib/delivery/mqtt-adapter.d.ts +50 -0
  141. package/dist/lib/delivery/mqtt-adapter.js +242 -0
  142. package/dist/lib/delivery/mqtt.d.ts +63 -0
  143. package/dist/lib/delivery/mqtt.js +119 -0
  144. package/dist/lib/delivery/outbox.d.ts +95 -0
  145. package/dist/lib/delivery/outbox.js +187 -0
  146. package/dist/lib/delivery/provenance.d.ts +129 -0
  147. package/dist/lib/delivery/provenance.js +93 -0
  148. package/dist/lib/delivery/reconciler.d.ts +215 -0
  149. package/dist/lib/delivery/reconciler.js +703 -0
  150. package/dist/lib/delivery/restore.d.ts +35 -0
  151. package/dist/lib/delivery/restore.js +134 -0
  152. package/dist/lib/delivery/rpc/client.d.ts +22 -0
  153. package/dist/lib/delivery/rpc/client.js +159 -0
  154. package/dist/lib/delivery/rpc/port.d.ts +40 -0
  155. package/dist/lib/delivery/rpc/port.js +16 -0
  156. package/dist/lib/delivery/rpc/server.d.ts +30 -0
  157. package/dist/lib/delivery/rpc/server.js +205 -0
  158. package/dist/lib/delivery/rpc/wire.d.ts +85 -0
  159. package/dist/lib/delivery/rpc/wire.js +143 -0
  160. package/dist/lib/delivery/store.d.ts +163 -0
  161. package/dist/lib/delivery/store.js +944 -0
  162. package/dist/lib/delivery/windows-service-install.d.ts +262 -0
  163. package/dist/lib/delivery/windows-service-install.js +892 -0
  164. package/dist/lib/delivery/workers/macos-job-helper.d.ts +103 -0
  165. package/dist/lib/delivery/workers/macos-job-helper.js +927 -0
  166. package/dist/lib/delivery/workers/macos.d.ts +191 -0
  167. package/dist/lib/delivery/workers/macos.js +943 -0
  168. package/dist/lib/delivery/workers/windows-job-helper.d.ts +35 -0
  169. package/dist/lib/delivery/workers/windows-job-helper.js +264 -0
  170. package/dist/lib/delivery/workers/windows-service-live.d.ts +121 -0
  171. package/dist/lib/delivery/workers/windows-service-live.js +711 -0
  172. package/dist/lib/delivery/workers/windows-service-runner.d.ts +33 -0
  173. package/dist/lib/delivery/workers/windows-service-runner.js +82 -0
  174. package/dist/lib/delivery/workers/windows-service.d.ts +140 -0
  175. package/dist/lib/delivery/workers/windows-service.js +584 -0
  176. package/dist/lib/delivery/workers/windows.d.ts +251 -0
  177. package/dist/lib/delivery/workers/windows.js +594 -0
  178. package/dist/lib/hot-channels/adapters/meetings.d.ts +15 -0
  179. package/dist/lib/hot-channels/adapters/meetings.js +36 -3
  180. package/dist/lib/hot-channels/signals-pass.d.ts +10 -0
  181. package/dist/lib/hot-channels/signals-pass.js +71 -2
  182. package/dist/lib/hot-channels/signals-redo.js +10 -2
  183. package/dist/lib/install/provider-wrappers.d.ts +2 -0
  184. package/dist/lib/install/provider-wrappers.js +68 -3
  185. package/dist/lib/lanes/watcher.js +35 -0
  186. package/dist/lib/signals/steps/extract.js +40 -4
  187. package/dist/schemas/hq-available-ai.v1.schema.json +76 -0
  188. package/dist/utils/catalog-runtime-paths.d.ts +34 -0
  189. package/dist/utils/catalog-runtime-paths.js +53 -0
  190. package/dist/utils/cognito-callback-port.d.ts +14 -0
  191. package/dist/utils/cognito-callback-port.js +24 -0
  192. package/dist/utils/cognito-session.js +3 -3
  193. package/dist/utils/deleted-company-notice.d.ts +59 -0
  194. package/dist/utils/deleted-company-notice.js +156 -0
  195. package/dist/utils/files-browse-acl.js +1 -1
  196. package/dist/utils/login-browser.d.ts +1 -1
  197. package/dist/utils/login-browser.js +7 -5
  198. package/dist/utils/resident-package-preload.js +30 -15
  199. package/dist/utils/vault-api.js +7 -0
  200. package/package.json +7 -7
@@ -4,12 +4,12 @@ import * as fs from "node:fs";
4
4
  import * as os from "node:os";
5
5
  import * as path from "node:path";
6
6
  import * as readline from "node:readline";
7
- import { LedgerCorrupt, LedgerMissing, READING_SOURCES, capacityOptionsFromEnv, capacityRoot, nowViewJsonSchema, readCollectorMark, readLedgerEvents, readNow, rebuildNow, redactProviderTokens, setCollectorEnabled, } from "../lib/capacity/ledger.js";
7
+ import { LedgerCorrupt, LedgerMissing, READING_SOURCES, capacityOptionsFromEnv, capacityRoot, nowViewJsonSchema, readCollectorMark, readLedgerEvents, rebuildNow, redactProviderTokens, setCollectorEnabled, readCurrentNow, } from "../lib/capacity/ledger.js";
8
8
  import { listCapacityAccounts, registryAccountIds } from "../lib/capacity/accounts.js";
9
9
  import { claudeIdentityKeys, readClaudeRefreshLast } from "../lib/capacity/collectors/claude-oauth.js";
10
10
  import { projectCapacityView } from "../lib/capacity/project.js";
11
11
  import { capacityViewAge } from "../lib/capacity/freshness.js";
12
- import { capacityWidgetTimeZone, renderCapacityWidget } from "../lib/capacity/widget.js";
12
+ import { accountScopeName, bankedResets, capacityWidgetTimeZone, renderCapacityWidget, resetGrantName } from "../lib/capacity/widget.js";
13
13
  import { resolveLanesHqRoot } from "../lib/lanes/hq-root.js";
14
14
  import { loadLanesConfig } from "../lib/lanes/config.js";
15
15
  import { readAllLanes } from "../lib/lanes/store.js";
@@ -120,7 +120,11 @@ export function formatCapacityTable(view, nowMs, accounts = []) {
120
120
  && account.limits.some((limit) => limit.state === "exhausted")
121
121
  && hasCodexCreditRoom(account.limits, nowMs)
122
122
  ? " — usable on Codex credits (ranked last)" : "";
123
- return `${title}${creditNote}\n${formatLimitTable(account.limits, nowMs)}`;
123
+ const banked = bankedResets(account, nowMs);
124
+ const resetNote = banked.length === 0
125
+ ? ""
126
+ : `\nresets banked: ${banked.map((credit) => `${(credit.remaining ?? 1) > 1 ? `${credit.remaining} x ` : ""}${resetGrantName(credit, accountScopeName(account))}${credit.expiresAt === null ? "" : ` (expires ${new Date(credit.expiresAt).toISOString().slice(0, 10)})`}`).join("; ")}`;
127
+ return `${title}${creditNote}\n${formatLimitTable(account.limits, nowMs)}${resetNote}`;
124
128
  });
125
129
  return [head, ...blocks].join("\n");
126
130
  }).join("\n\n");
@@ -296,7 +300,7 @@ function formatSignedSpan(ms) {
296
300
  const span = formatSpan(Math.floor(Math.abs(ms) / 1000));
297
301
  return ms < 0 ? `-${span}` : span;
298
302
  }
299
- export function registerCapacityCommand(program) {
303
+ export function registerCapacityCommand(program, deps = {}) {
300
304
  const capacity = program
301
305
  .command("capacity")
302
306
  .description("Show provider capacity from the local ledger (read-only; enable, login, and ingest write to it)")
@@ -359,6 +363,36 @@ export function registerCapacityCommand(program) {
359
363
  process.exitCode = 1;
360
364
  });
361
365
  });
366
+ capacity
367
+ .command("available")
368
+ .description("What AI can run now, as one token-free hq-available-ai.v1 document (read-only; a stale view starts one background read)")
369
+ .option("--json", "Print the document as JSON")
370
+ .option("--fresh", "Start a read and wait for it, at most 3 seconds")
371
+ .option("--include-other", "Also list capacity-only accounts, each with its organization")
372
+ .action(async (_opts, command) => {
373
+ const opts = command.optsWithGlobals();
374
+ const { readAvailable, formatAvailableText } = await import("../lib/capacity/available.js");
375
+ const document = await readAvailable({ options: capacityOptionsFromEnv(), includeOther: opts.includeOther, fresh: opts.fresh }, deps.available);
376
+ console.log(opts.json ? JSON.stringify(document, null, 2) : formatAvailableText(document));
377
+ });
378
+ capacity
379
+ .command("collect-once", { hidden: true })
380
+ .description("One capacity read, started in the background by hq capacity available")
381
+ .action(async () => {
382
+ const { COLLECT_TOKEN_ENV, releaseCollectMark } = await import("../lib/capacity/available.js");
383
+ try {
384
+ const { collectCapacityOnce } = await import("../lib/capacity/collect.js");
385
+ await collectCapacityOnce({ env: process.env, hqRoot: process.env.HQ_ROOT });
386
+ }
387
+ catch {
388
+ // Failure classes stay in hq capacity doctor and logs.
389
+ }
390
+ finally {
391
+ // Free this collect's own single-flight mark, so the next read starts a
392
+ // collect at once. A mark a later collect holds is left alone.
393
+ releaseCollectMark(capacityOptionsFromEnv(), process.env[COLLECT_TOKEN_ENV]);
394
+ }
395
+ });
362
396
  capacity
363
397
  .command("route")
364
398
  .description("Pick the account with the most capacity for a new lane (read-only; port of boss-route)")
@@ -475,11 +509,11 @@ export function registerCapacityCommand(program) {
475
509
  });
476
510
  ingest
477
511
  .command("refusal")
478
- .description("Record a classified provider rate-limit refusal as an exhausted reading")
512
+ .description("Record a classified provider refusal as a hold on one named account")
479
513
  .option("--provider <name>", "claude, codex, or grok")
480
- .option("--limit-id <id>", "Limit to mark; default is the provider's weekly_all id in now.json, else weekly")
481
- .option("--resets-at <when>", "UTC timestamp or epoch when this limit resets")
482
- .option("--account <hash>", "Hashed account id; default is the account on the chosen limit")
514
+ .option("--limit-id <id>", "The account's limit this refusal is about; without it the refusal claims no window")
515
+ .option("--resets-at <when>", "UTC timestamp or epoch when the hold ends")
516
+ .option("--account <hash>", "Hashed account id of the account that refused. Required unless --limit-id names a limit exactly one account has")
483
517
  .option("--json", "Print the recorded limit as JSON")
484
518
  .addHelpText("after", `\n${REFUSAL_HELP}\n`)
485
519
  .action((opts, command) => {
@@ -494,7 +528,9 @@ export function registerCapacityCommand(program) {
494
528
  console.log(JSON.stringify(record, null, 2));
495
529
  return;
496
530
  }
497
- console.log(`Recorded refusal for ${record.provider} ${record.limitId}; state ${record.state}.`);
531
+ console.log(record.inForce
532
+ ? `Recorded refusal for ${record.provider} ${record.limitId}; state ${record.state}.`
533
+ : `Recorded refusal for ${record.provider} ${record.limitId}; the hold is not in force: its reset has passed or a newer reading answers it.`);
498
534
  });
499
535
  });
500
536
  capacity
@@ -741,7 +777,7 @@ function runCli(action) {
741
777
  }
742
778
  function loadNow(options) {
743
779
  try {
744
- return readNow(options);
780
+ return readCurrentNow(options);
745
781
  }
746
782
  catch (err) {
747
783
  if (!(err instanceof LedgerCorrupt))
@@ -693,18 +693,73 @@ export declare function nowPushLegRefused(input: {
693
693
  * personal-vault fanout slot and the legacy `companies/personal` company both
694
694
  * carry opaque slugs; everything else is a real company slug shown as-is.
695
695
  */
696
+ type StatusJournal = {
697
+ slug: string;
698
+ journal: {
699
+ files?: Record<string, unknown>;
700
+ };
701
+ };
702
+ export type ReadOnlyLocalOnlyGroup = {
703
+ slug: string;
704
+ total: number;
705
+ files: Array<{
706
+ path: string;
707
+ permission: "read" | "none";
708
+ }>;
709
+ };
710
+ export type ServerOwnedLocalOnlyGroup = {
711
+ slug: string;
712
+ total: number;
713
+ files: string[];
714
+ };
715
+ /**
716
+ * Collect local files under read-only vault prefixes that are not in the sync
717
+ * journal. `all` lifts the per-company cap so every path is returned; `total`
718
+ * always counts every match. Local reads only, no network.
719
+ */
720
+ export declare function collectReadOnlyLocalOnly(hqRoot: string, journals: ReadonlyArray<StatusJournal>, opts?: {
721
+ all?: boolean;
722
+ }): ReadOnlyLocalOnlyGroup[];
723
+ /**
724
+ * Collect local files under server-owned folders (sources/, signals/,
725
+ * ontology/ outside entities/) that are not in the sync journal. `all` lifts
726
+ * the per-company cap. Local reads only, no network.
727
+ */
728
+ export declare function collectServerOwnedLocalOnly(hqRoot: string, journals: ReadonlyArray<StatusJournal>, opts?: {
729
+ all?: boolean;
730
+ }): ServerOwnedLocalOnlyGroup[];
731
+ /**
732
+ * Full machine-readable `hq sync status`: scope summaries plus both local-only
733
+ * lists with every path (no cap).
734
+ */
735
+ export declare function buildSyncStatusJson(input: {
736
+ hqRoot: string;
737
+ activeCompany?: string;
738
+ stateDir: string;
739
+ companyFilter?: string;
740
+ journals: ReadonlyArray<{
741
+ slug: string;
742
+ path: string;
743
+ journal: {
744
+ lastSync?: string;
745
+ files?: Record<string, {
746
+ removedAt?: unknown;
747
+ size?: number;
748
+ syncedAt?: unknown;
749
+ }>;
750
+ };
751
+ }>;
752
+ }): Record<string, unknown>;
696
753
  /**
697
754
  * `hq sync status`: list local files under read-only vault prefixes that are
698
755
  * not in the sync journal. Push never uploads them (feedback_510661bc,
699
756
  * Shepherd #2813). Uses only the local vault-access manifest and the journals
700
757
  * already loaded, with no network calls. Prints nothing when nothing applies.
758
+ * Capped at 20 per company unless `opts.all` (feedback_f29d004a).
701
759
  */
702
- export declare function printReadOnlyLocalOnly(hqRoot: string, journals: ReadonlyArray<{
703
- slug: string;
704
- journal: {
705
- files?: Record<string, unknown>;
706
- };
707
- }>, log?: (line: string) => void): number;
760
+ export declare function printReadOnlyLocalOnly(hqRoot: string, journals: ReadonlyArray<StatusJournal>, log?: (line: string) => void, opts?: {
761
+ all?: boolean;
762
+ }): number;
708
763
  /**
709
764
  * `hq sync status`: list local files under server-owned folders (sources/,
710
765
  * signals/, ontology/ outside entities/) that are not in the sync journal.
@@ -712,13 +767,11 @@ export declare function printReadOnlyLocalOnly(hqRoot: string, journals: Readonl
712
767
  * the recurring runner skips them quietly, so a file written locally there
713
768
  * never reaches the vault and `pendingFiles: 0` still reports a clean tree
714
769
  * (feedback_0414d71c). Uses only the journals already loaded, with no
715
- * network calls. Prints nothing when nothing applies.
770
+ * network calls. Prints nothing when nothing applies. Capped at 20 per
771
+ * company unless `opts.all` (feedback_f29d004a).
716
772
  */
717
- export declare function printServerOwnedLocalOnly(hqRoot: string, journals: ReadonlyArray<{
718
- slug: string;
719
- journal: {
720
- files?: Record<string, unknown>;
721
- };
722
- }>, log?: (line: string) => void): number;
773
+ export declare function printServerOwnedLocalOnly(hqRoot: string, journals: ReadonlyArray<StatusJournal>, log?: (line: string) => void, opts?: {
774
+ all?: boolean;
775
+ }): number;
723
776
  export {};
724
777
  //# sourceMappingURL=cloud.d.ts.map
@@ -533,7 +533,7 @@ export function identityHeldLines(count, notice) {
533
533
  return [];
534
534
  return [
535
535
  `⚠ ${count} file(s) were NOT uploaded: uploads for this company are held on this computer ` +
536
- `after an account sign-in change. Run \`hq sync held\` to see what is held, then ` +
536
+ `until you confirm they belong to the signed-in account. Run \`hq sync held\` to see what is held, then ` +
537
537
  `\`hq sync release-held\` to upload it.`,
538
538
  ];
539
539
  }
@@ -1899,6 +1899,8 @@ export function registerCloudCommands(program) {
1899
1899
  .description("Show local sync journal summary")
1900
1900
  .option("--hq-root <path>", `Local HQ tree root (default: ${DEFAULT_HQ_ROOT})`, DEFAULT_HQ_ROOT)
1901
1901
  .option("--company <slug>", "Show only this company's journal (company slug)")
1902
+ .option("--all", "List every local-only file instead of the first 20 per company")
1903
+ .option("--json", "Print the full status as JSON (every list uncapped) instead of text")
1902
1904
  .action((options, command) => {
1903
1905
  const explicitHqRoot = command.getOptionValueSource("hqRoot") === "cli";
1904
1906
  try {
@@ -1944,6 +1946,11 @@ export function registerCloudCommands(program) {
1944
1946
  const journals = companyFilter
1945
1947
  ? listJournals().filter((j) => j.slug === companyFilter)
1946
1948
  : listJournals();
1949
+ if (options.json) {
1950
+ console.log(JSON.stringify(buildSyncStatusJson({ hqRoot, activeCompany, stateDir, companyFilter, journals }), null, 2));
1951
+ return;
1952
+ }
1953
+ const showAll = options.all === true;
1947
1954
  let grandFiles = 0;
1948
1955
  let grandBytes = 0;
1949
1956
  let grandLastSync = "";
@@ -1991,8 +1998,8 @@ export function registerCloudCommands(program) {
1991
1998
  console.log(` Total size: ${formatBytes(grandBytes)}`);
1992
1999
  console.log(` Last sync: ${grandLastSync || "never"}`);
1993
2000
  }
1994
- printReadOnlyLocalOnly(hqRoot, journals);
1995
- printServerOwnedLocalOnly(hqRoot, journals);
2001
+ printReadOnlyLocalOnly(hqRoot, journals, undefined, { all: showAll });
2002
+ printServerOwnedLocalOnly(hqRoot, journals, undefined, { all: showAll });
1996
2003
  }
1997
2004
  catch (err) {
1998
2005
  console.error(chalk.red("✗ Status failed:"), err instanceof Error ? err.message : String(err));
@@ -2838,23 +2845,20 @@ function readActiveCompanySlug(hqRoot) {
2838
2845
  return undefined;
2839
2846
  }
2840
2847
  }
2848
+ /** Max paths listed per company when `--all` is not passed. */
2849
+ const STATUS_LIST_CAP = 20;
2841
2850
  /**
2842
- * Human-friendly label for a journal slug in `hq sync status`. The
2843
- * personal-vault fanout slot and the legacy `companies/personal` company both
2844
- * carry opaque slugs; everything else is a real company slug shown as-is.
2851
+ * Collect local files under read-only vault prefixes that are not in the sync
2852
+ * journal. `all` lifts the per-company cap so every path is returned; `total`
2853
+ * always counts every match. Local reads only, no network.
2845
2854
  */
2846
- /**
2847
- * `hq sync status`: list local files under read-only vault prefixes that are
2848
- * not in the sync journal. Push never uploads them (feedback_510661bc,
2849
- * Shepherd #2813). Uses only the local vault-access manifest and the journals
2850
- * already loaded, with no network calls. Prints nothing when nothing applies.
2851
- */
2852
- export function printReadOnlyLocalOnly(hqRoot, journals, log = (line) => console.log(line)) {
2855
+ export function collectReadOnlyLocalOnly(hqRoot, journals, opts = {}) {
2853
2856
  const companies = readVaultAccessManifest(hqRoot)?.companies;
2854
2857
  if (!companies)
2855
- return 0;
2858
+ return [];
2859
+ const limit = opts.all ? Number.POSITIVE_INFINITY : STATUS_LIST_CAP;
2856
2860
  let shouldSync;
2857
- let grand = 0;
2861
+ const groups = [];
2858
2862
  for (const [slug, company] of Object.entries(companies)) {
2859
2863
  if (!isGrantEnforced(company))
2860
2864
  continue;
@@ -2870,16 +2874,109 @@ export function printReadOnlyLocalOnly(hqRoot, journals, log = (line) => console
2870
2874
  }
2871
2875
  const journal = journals.find((j) => j.slug === slug)?.journal;
2872
2876
  const journalKeys = new Set(Object.keys(journal?.files ?? {}));
2873
- const found = findReadOnlyLocalOnly({ hqRoot, slug, company, journalKeys, shouldSync });
2877
+ const found = findReadOnlyLocalOnly({ hqRoot, slug, company, journalKeys, shouldSync, limit });
2878
+ if (found.total === 0)
2879
+ continue;
2880
+ groups.push({ slug, total: found.total, files: found.files });
2881
+ }
2882
+ return groups;
2883
+ }
2884
+ /**
2885
+ * Collect local files under server-owned folders (sources/, signals/,
2886
+ * ontology/ outside entities/) that are not in the sync journal. `all` lifts
2887
+ * the per-company cap. Local reads only, no network.
2888
+ */
2889
+ export function collectServerOwnedLocalOnly(hqRoot, journals, opts = {}) {
2890
+ const limit = opts.all ? Number.POSITIVE_INFINITY : STATUS_LIST_CAP;
2891
+ let shouldSync;
2892
+ const groups = [];
2893
+ for (const { slug, journal } of journals) {
2894
+ if (slug === PERSONAL_VAULT_JOURNAL_SLUG)
2895
+ continue;
2896
+ if (!fs.existsSync(path.join(hqRoot, "companies", slug)))
2897
+ continue;
2898
+ if (!shouldSync) {
2899
+ try {
2900
+ shouldSync = createIgnoreFilter(hqRoot);
2901
+ }
2902
+ catch {
2903
+ shouldSync = () => true;
2904
+ }
2905
+ }
2906
+ const journalKeys = new Set(Object.keys(journal.files ?? {}));
2907
+ const found = findServerOwnedLocalOnly({ hqRoot, slug, journalKeys, shouldSync, limit });
2874
2908
  if (found.total === 0)
2875
2909
  continue;
2910
+ groups.push({ slug, total: found.total, files: found.files });
2911
+ }
2912
+ return groups;
2913
+ }
2914
+ /**
2915
+ * Full machine-readable `hq sync status`: scope summaries plus both local-only
2916
+ * lists with every path (no cap).
2917
+ */
2918
+ export function buildSyncStatusJson(input) {
2919
+ const { hqRoot, journals } = input;
2920
+ let totalFiles = 0;
2921
+ let totalBytes = 0;
2922
+ let lastSyncAll = "";
2923
+ const scopes = journals.map((j) => {
2924
+ const live = Object.values(j.journal.files ?? {}).filter((e) => !e.removedAt);
2925
+ const bytes = live.reduce((acc, e) => acc + (e.size ?? 0), 0);
2926
+ const lastSync = j.journal.lastSync ||
2927
+ live
2928
+ .map((e) => e.syncedAt)
2929
+ .filter((t) => typeof t === "string")
2930
+ .sort()
2931
+ .at(-1) ||
2932
+ "never";
2933
+ totalFiles += live.length;
2934
+ totalBytes += bytes;
2935
+ if (lastSync !== "never" && lastSync > lastSyncAll)
2936
+ lastSyncAll = lastSync;
2937
+ return {
2938
+ slug: j.slug,
2939
+ label: scopeLabel(j.slug),
2940
+ trackedFiles: live.length,
2941
+ totalBytes: bytes,
2942
+ lastSync,
2943
+ journalPath: j.path,
2944
+ };
2945
+ });
2946
+ const readOnly = collectReadOnlyLocalOnly(hqRoot, journals, { all: true });
2947
+ const serverOwned = collectServerOwnedLocalOnly(hqRoot, journals, { all: true });
2948
+ return {
2949
+ hqRoot,
2950
+ activeCompany: input.activeCompany ?? null,
2951
+ stateDir: input.stateDir,
2952
+ company: input.companyFilter ?? null,
2953
+ journals: journals.length,
2954
+ scopes,
2955
+ totals: { trackedFiles: totalFiles, totalBytes, lastSync: lastSyncAll || "never" },
2956
+ readOnlyLocalOnly: readOnly,
2957
+ serverOwnedLocalOnly: {
2958
+ folders: [...SERVER_OWNED_FOLDERS],
2959
+ companies: serverOwned,
2960
+ },
2961
+ };
2962
+ }
2963
+ /**
2964
+ * `hq sync status`: list local files under read-only vault prefixes that are
2965
+ * not in the sync journal. Push never uploads them (feedback_510661bc,
2966
+ * Shepherd #2813). Uses only the local vault-access manifest and the journals
2967
+ * already loaded, with no network calls. Prints nothing when nothing applies.
2968
+ * Capped at 20 per company unless `opts.all` (feedback_f29d004a).
2969
+ */
2970
+ export function printReadOnlyLocalOnly(hqRoot, journals, log = (line) => console.log(line), opts = {}) {
2971
+ let grand = 0;
2972
+ for (const found of collectReadOnlyLocalOnly(hqRoot, journals, opts)) {
2876
2973
  grand += found.total;
2877
- log(chalk.yellow(`\n ! ${slug}: ${found.total} local-only file(s) under read-only access will not upload`));
2974
+ log(chalk.yellow(`\n ! ${found.slug}: ${found.total} local-only file(s) under read-only access will not upload`));
2878
2975
  for (const f of found.files) {
2879
2976
  log(` ${f.path}${f.permission === "none" ? chalk.dim(" (no access)") : ""}`);
2880
2977
  }
2881
2978
  if (found.total > found.files.length) {
2882
- log(chalk.dim(` ... and ${found.total - found.files.length} more`));
2979
+ log(chalk.dim(` ... and ${found.total - found.files.length} more (use --all to list every file)`));
2883
2980
  }
2884
2981
  }
2885
2982
  if (grand > 0) {
@@ -2895,36 +2992,20 @@ export function printReadOnlyLocalOnly(hqRoot, journals, log = (line) => console
2895
2992
  * the recurring runner skips them quietly, so a file written locally there
2896
2993
  * never reaches the vault and `pendingFiles: 0` still reports a clean tree
2897
2994
  * (feedback_0414d71c). Uses only the journals already loaded, with no
2898
- * network calls. Prints nothing when nothing applies.
2995
+ * network calls. Prints nothing when nothing applies. Capped at 20 per
2996
+ * company unless `opts.all` (feedback_f29d004a).
2899
2997
  */
2900
- export function printServerOwnedLocalOnly(hqRoot, journals, log = (line) => console.log(line)) {
2901
- let shouldSync;
2998
+ export function printServerOwnedLocalOnly(hqRoot, journals, log = (line) => console.log(line), opts = {}) {
2902
2999
  let grand = 0;
2903
- for (const { slug, journal } of journals) {
2904
- if (slug === PERSONAL_VAULT_JOURNAL_SLUG)
2905
- continue;
2906
- if (!fs.existsSync(path.join(hqRoot, "companies", slug)))
2907
- continue;
2908
- if (!shouldSync) {
2909
- try {
2910
- shouldSync = createIgnoreFilter(hqRoot);
2911
- }
2912
- catch {
2913
- shouldSync = () => true;
2914
- }
2915
- }
2916
- const journalKeys = new Set(Object.keys(journal.files ?? {}));
2917
- const found = findServerOwnedLocalOnly({ hqRoot, slug, journalKeys, shouldSync });
2918
- if (found.total === 0)
2919
- continue;
3000
+ for (const found of collectServerOwnedLocalOnly(hqRoot, journals, opts)) {
2920
3001
  grand += found.total;
2921
- log(chalk.yellow(`\n ! ${slug}: ${found.total} local-only file(s) under server-owned folders ` +
3002
+ log(chalk.yellow(`\n ! ${found.slug}: ${found.total} local-only file(s) under server-owned folders ` +
2922
3003
  `(${SERVER_OWNED_FOLDERS.map((f) => `${f}/`).join(", ")}) never upload`));
2923
3004
  for (const rel of found.files) {
2924
3005
  log(` ${rel}`);
2925
3006
  }
2926
3007
  if (found.total > found.files.length) {
2927
- log(chalk.dim(` ... and ${found.total - found.files.length} more`));
3008
+ log(chalk.dim(` ... and ${found.total - found.files.length} more (use --all to list every file)`));
2928
3009
  }
2929
3010
  }
2930
3011
  if (grand > 0) {
@@ -0,0 +1,23 @@
1
+ import { Command } from "commander";
2
+ import { type DeletedCompanyEntry } from "../utils/deleted-company-notice.js";
3
+ export type CompanyRestoreErrorCode = "no_match" | "ambiguous" | "window_closed" | "forbidden" | "conflict" | "failed";
4
+ export type CompanyRestoreResult = {
5
+ restored: true;
6
+ uid: string;
7
+ name: string;
8
+ alreadyLive: boolean;
9
+ message: string;
10
+ } | {
11
+ restored: false;
12
+ error: CompanyRestoreErrorCode;
13
+ message: string;
14
+ /** Extra lines for a person: the deleted companies they could name. */
15
+ details: string[];
16
+ uid?: string;
17
+ };
18
+ /** Match by uid, then slug, then name. Slug and name ignore case. */
19
+ export declare function matchDeletedCompany(input: string, entries: DeletedCompanyEntry[]): DeletedCompanyEntry[];
20
+ /** Resolve `<company>` among the caller's deleted companies and restore it. */
21
+ export declare function restoreCompany(input: string, token: string): Promise<CompanyRestoreResult>;
22
+ export declare function registerCompanyRestoreCommand(company: Command): void;
23
+ //# sourceMappingURL=company-restore.d.ts.map
@@ -0,0 +1,128 @@
1
+ // src/commands/company-restore.ts
2
+ //
3
+ // `hq company restore <company>` brings back a company its owner deleted
4
+ // within the last 30 days (hq-pro `POST /entity/{uid}/restore`). The company
5
+ // is looked up among `deletedCompanies` on `GET /membership/me`, because a
6
+ // deleted company no longer resolves through the normal slug lookup.
7
+ //
8
+ // Every message is fixed copy. The server's error text is never printed.
9
+ import { ensureCognitoToken } from "../utils/cognito-session.js";
10
+ import { vaultApiFetch } from "../utils/vault-api.js";
11
+ import { DELETED_COMPANY_SUPPORT_POINTER, DELETED_COMPANY_SUPPORT_POINTER_INLINE, deletedCompanyDisplayName, fetchDeletedCompanies, formatDeletedCompanyNotice, } from "../utils/deleted-company-notice.js";
12
+ function normalize(value) {
13
+ return (value ?? "").trim().replace(/\s+/g, " ").toLowerCase();
14
+ }
15
+ /** Match by uid, then slug, then name. Slug and name ignore case. */
16
+ export function matchDeletedCompany(input, entries) {
17
+ const wanted = normalize(input);
18
+ if (!wanted)
19
+ return [];
20
+ const byUid = entries.filter((e) => e.companyUid === input.trim());
21
+ if (byUid.length > 0)
22
+ return byUid;
23
+ const bySlug = entries.filter((e) => normalize(e.companySlug) === wanted);
24
+ if (bySlug.length > 0)
25
+ return bySlug;
26
+ return entries.filter((e) => normalize(e.companyName) === wanted);
27
+ }
28
+ function failure(error, message, details = [], uid) {
29
+ return { restored: false, error, message, details, ...(uid ? { uid } : {}) };
30
+ }
31
+ function couldNotRestore(name, uid) {
32
+ return failure("failed", `Could not restore ${name}. Try again, or ${DELETED_COMPANY_SUPPORT_POINTER_INLINE}`, [], uid);
33
+ }
34
+ /** Resolve `<company>` among the caller's deleted companies and restore it. */
35
+ export async function restoreCompany(input, token) {
36
+ const typed = input.trim();
37
+ let entries;
38
+ try {
39
+ entries = await fetchDeletedCompanies({ token });
40
+ }
41
+ catch {
42
+ return couldNotRestore(typed || "the company");
43
+ }
44
+ const matches = matchDeletedCompany(typed, entries);
45
+ const listing = entries.flatMap((entry) => formatDeletedCompanyNotice(entry));
46
+ if (matches.length === 0) {
47
+ return failure("no_match", `No deleted company matches "${typed}".`, listing);
48
+ }
49
+ if (matches.length > 1) {
50
+ return failure("ambiguous", `More than one deleted company matches "${typed}". Run the command again with the company ID:`, matches.map((entry) => ` hq company restore ${entry.companyUid}`));
51
+ }
52
+ const entry = matches[0];
53
+ const name = deletedCompanyDisplayName(entry);
54
+ const uid = entry.companyUid;
55
+ let res;
56
+ try {
57
+ res = await vaultApiFetch({
58
+ token,
59
+ path: `/entity/${encodeURIComponent(uid)}/restore`,
60
+ method: "POST",
61
+ });
62
+ }
63
+ catch {
64
+ return couldNotRestore(name, uid);
65
+ }
66
+ if (res.ok) {
67
+ const body = (await res.json().catch(() => null));
68
+ if (body?.restored !== true)
69
+ return couldNotRestore(name, uid);
70
+ return {
71
+ restored: true,
72
+ uid,
73
+ name,
74
+ alreadyLive: body.alreadyLive === true,
75
+ message: `${name} is restored. Its paid plan was canceled when it was deleted, ` +
76
+ "so choose a plan again if you need one.",
77
+ };
78
+ }
79
+ if (res.status === 410) {
80
+ return failure("window_closed", `The 30-day restore window for ${name} has closed. ${DELETED_COMPANY_SUPPORT_POINTER}`, [], uid);
81
+ }
82
+ if (res.status === 403) {
83
+ return failure("forbidden", `${name} can only be restored by its owner or HQ support. ${DELETED_COMPANY_SUPPORT_POINTER}`, [], uid);
84
+ }
85
+ if (res.status === 409) {
86
+ return failure("conflict", `${name} changed while it was being restored. Run the command again.`, [], uid);
87
+ }
88
+ return couldNotRestore(name, uid);
89
+ }
90
+ export function registerCompanyRestoreCommand(company) {
91
+ company
92
+ .command("restore <company>")
93
+ .description("Restore a company you deleted in the last 30 days (name, slug or company ID)")
94
+ .option("--json", "Print the result as JSON")
95
+ .action(async (input, opts) => {
96
+ let result;
97
+ try {
98
+ // A sign-in failure keeps its own message (written by this CLI, for
99
+ // example "run `hq login`"); it is not server text.
100
+ const token = await ensureCognitoToken();
101
+ try {
102
+ result = await restoreCompany(input, token);
103
+ }
104
+ catch {
105
+ result = couldNotRestore(input.trim() || "the company");
106
+ }
107
+ }
108
+ catch (error) {
109
+ result = failure("failed", error instanceof Error && error.message
110
+ ? error.message
111
+ : "Could not sign in. Run `hq login` and try again.");
112
+ }
113
+ if (opts.json) {
114
+ console.log(JSON.stringify(result));
115
+ }
116
+ else if (result.restored) {
117
+ console.log(result.message);
118
+ }
119
+ else {
120
+ console.error(result.message);
121
+ for (const line of result.details)
122
+ console.error(line);
123
+ }
124
+ if (!result.restored)
125
+ process.exitCode = 1;
126
+ });
127
+ }
128
+ //# sourceMappingURL=company-restore.js.map
@@ -3,6 +3,7 @@ import { ensureCognitoToken } from "../utils/cognito-session.js";
3
3
  import { vaultApiFetch, getEntityUid } from "../utils/vault-api.js";
4
4
  import { registerCompanyTransferCommand } from "./company-transfer.js";
5
5
  import { registerCompanyRenameCommand } from "./company-rename.js";
6
+ import { registerCompanyRestoreCommand } from "./company-restore.js";
6
7
  import { describeRefreshOutcome, refreshCheckpointGateSetting, } from "./core-checkpoint-gate-setting.js";
7
8
  /** Both switches from a settings response body, or null unless both are booleans. */
8
9
  function workTrackingFromBody(body) {
@@ -102,6 +103,7 @@ export function registerCompanyCommand(program) {
102
103
  // `hq company transfer …` — ownership handover (client-service-pack US-010).
103
104
  registerCompanyTransferCommand(company);
104
105
  registerCompanyRenameCommand(company);
106
+ registerCompanyRestoreCommand(company);
105
107
  const settings = company
106
108
  .command("settings")
107
109
  .description("Per-company settings (owner-only)");
@@ -140,12 +140,26 @@ function groupMemberIds(output) {
140
140
  return lines.slice(header + 1).filter((line) => line.trim() !== "")
141
141
  .map((line) => line.trim().split(/\s{2,}/, 1)[0] ?? "");
142
142
  }
143
+ /**
144
+ * Creator-row ACL label in any hq-cli wording: bare "creator access", the older
145
+ * "creator access — creator-only", or "creator access (<note>)". The listing
146
+ * comes from the `hq` on PATH, which can be older or newer than this build, so
147
+ * matching only this build's label would fail creator rows from another
148
+ * version. Mirrors the creator alternative in hq-delegate-verify.sh.
149
+ */
150
+ const CREATOR_ACL_LABEL = / (creator access(?: — creator-only| \([^()]*\))?)$/;
151
+ function trailingAclLabel(row, aclLabels) {
152
+ const creator = CREATOR_ACL_LABEL.exec(row)?.[1];
153
+ if (creator)
154
+ return creator;
155
+ return aclLabels.find((label) => row.endsWith(label));
156
+ }
143
157
  function browseContainsExactKey(listing, expected) {
144
158
  const lines = listing.split(/\r?\n/);
145
159
  const aclLabels = Object.values(ACL_SOURCE_DISPLAY_LABELS);
146
160
  return lines.slice(2).some((line) => {
147
161
  const row = stripAnsiSequences(line).trimEnd();
148
- const acl = aclLabels.find((label) => row.endsWith(label));
162
+ const acl = trailingAclLabel(row, aclLabels);
149
163
  if (!acl)
150
164
  return false;
151
165
  const beforeAcl = row.slice(0, -acl.length).trimEnd();