@indigoai-us/hq-cli 5.345.212 → 5.345.215-beta.0

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 (161) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/bin/hq-auth-refresh.js +2 -1
  3. package/dist/command-catalog.generated.d.ts +442 -50
  4. package/dist/command-catalog.generated.js +541 -50
  5. package/dist/commands/agent-inbox.d.ts +11 -1
  6. package/dist/commands/agent-inbox.js +128 -38
  7. package/dist/commands/agent-kit.js +2 -2
  8. package/dist/commands/agents.d.ts +51 -1
  9. package/dist/commands/agents.js +154 -2
  10. package/dist/commands/bot-jobs.d.ts +2 -15
  11. package/dist/commands/bot-jobs.js +2 -94
  12. package/dist/commands/bot-runtime.d.ts +46 -5
  13. package/dist/commands/bot-runtime.js +228 -18
  14. package/dist/commands/bot.d.ts +16 -9
  15. package/dist/commands/bot.js +169 -51
  16. package/dist/commands/cloud.d.ts +66 -13
  17. package/dist/commands/cloud.js +120 -39
  18. package/dist/commands/company-restore.d.ts +23 -0
  19. package/dist/commands/company-restore.js +128 -0
  20. package/dist/commands/company.js +2 -0
  21. package/dist/commands/core-handoff.js +1 -0
  22. package/dist/commands/core-hq-session-native.js +2 -2
  23. package/dist/commands/core-pin-native.js +1 -1
  24. package/dist/commands/core-policy.js +1 -1
  25. package/dist/commands/core-resolve-company-native.js +1 -1
  26. package/dist/commands/core-sentry-report-fast.d.ts +2 -0
  27. package/dist/commands/core-sentry-report-fast.js +3 -1
  28. package/dist/commands/daemon.js +11 -1
  29. package/dist/commands/integrations-connect.d.ts +17 -4
  30. package/dist/commands/integrations-connect.js +224 -26
  31. package/dist/commands/lanes-link.js +10 -5
  32. package/dist/commands/lanes.js +26 -9
  33. package/dist/commands/rescue.js +13 -0
  34. package/dist/commands/secrets.d.ts +11 -0
  35. package/dist/commands/secrets.js +41 -7
  36. package/dist/commands/sources.js +6 -0
  37. package/dist/commands/storage-offload.d.ts +12 -0
  38. package/dist/commands/storage-offload.js +41 -3
  39. package/dist/commands/sync-mode.js +5 -0
  40. package/dist/commands/whoami.js +4 -0
  41. package/dist/index.js +2 -0
  42. package/dist/lazy-commands.js +2 -0
  43. package/dist/lib/agent-kit/inbox-fetch.d.ts +122 -1
  44. package/dist/lib/agent-kit/inbox-fetch.js +215 -3
  45. package/dist/lib/agent-kit/inbox-redact.js +1 -1
  46. package/dist/lib/agent-kit/inbox-state.d.ts +98 -1
  47. package/dist/lib/agent-kit/inbox-state.js +261 -4
  48. package/dist/lib/agent-kit/mcp/tools.d.ts +3 -3
  49. package/dist/lib/agent-kit/mcp/tools.js +68 -25
  50. package/dist/lib/agent-kit/run/inbox.js +4 -2
  51. package/dist/lib/agent-kit/skills.js +4 -1
  52. package/dist/lib/agent-kit/wake.d.ts +9 -1
  53. package/dist/lib/agent-kit/wake.js +10 -3
  54. package/dist/lib/bot/config.d.ts +1 -0
  55. package/dist/lib/bot/config.js +10 -0
  56. package/dist/lib/bot/eventbridge-cron.d.ts +22 -0
  57. package/dist/lib/bot/eventbridge-cron.js +104 -0
  58. package/dist/lib/bot/fleet-cron.js +193 -14
  59. package/dist/lib/bot/fleet-download.d.ts +2 -0
  60. package/dist/lib/bot/fleet-download.js +23 -0
  61. package/dist/lib/bot/fleet-local.d.ts +34 -1
  62. package/dist/lib/bot/fleet-local.js +254 -37
  63. package/dist/lib/bot/fleet-python.d.ts +3 -0
  64. package/dist/lib/bot/fleet-python.js +34 -4
  65. package/dist/lib/bot/fleet-runtime-sources.d.ts +15 -0
  66. package/dist/lib/bot/fleet-runtime-sources.js +30 -0
  67. package/dist/lib/bot/legacy-provider-login.d.ts +8 -0
  68. package/dist/lib/bot/legacy-provider-login.js +19 -2
  69. package/dist/lib/bot/prompt.js +1 -1
  70. package/dist/lib/bot/readiness.d.ts +8 -0
  71. package/dist/lib/bot/readiness.js +17 -3
  72. package/dist/lib/bot/runtime-auth.d.ts +30 -0
  73. package/dist/lib/bot/runtime-auth.js +94 -3
  74. package/dist/lib/bot/status.d.ts +2 -0
  75. package/dist/lib/capacity/collectors/grok-refresh.d.ts +80 -0
  76. package/dist/lib/capacity/collectors/grok-refresh.js +189 -0
  77. package/dist/lib/capacity/collectors/grok.d.ts +5 -0
  78. package/dist/lib/capacity/collectors/grok.js +56 -5
  79. package/dist/lib/core-utils/session-id.d.ts +1 -1
  80. package/dist/lib/core-utils/session-id.js +4 -0
  81. package/dist/lib/daemon/catalog.js +11 -1
  82. package/dist/lib/daemon/run.js +9 -1
  83. package/dist/lib/daemon/updater.d.ts +34 -2
  84. package/dist/lib/daemon/updater.js +51 -2
  85. package/dist/lib/db/sqlite-binding.d.ts +1 -0
  86. package/dist/lib/db/sqlite-binding.js +1 -1
  87. package/dist/lib/delivery/artifacts.d.ts +99 -0
  88. package/dist/lib/delivery/artifacts.js +548 -0
  89. package/dist/lib/delivery/backup.d.ts +78 -0
  90. package/dist/lib/delivery/backup.js +343 -0
  91. package/dist/lib/delivery/cache.d.ts +29 -0
  92. package/dist/lib/delivery/cache.js +33 -0
  93. package/dist/lib/delivery/contracts.d.ts +142 -0
  94. package/dist/lib/delivery/contracts.js +289 -0
  95. package/dist/lib/delivery/credentials.d.ts +54 -0
  96. package/dist/lib/delivery/credentials.js +119 -0
  97. package/dist/lib/delivery/enrollment.d.ts +142 -0
  98. package/dist/lib/delivery/enrollment.js +382 -0
  99. package/dist/lib/delivery/identity.d.ts +25 -0
  100. package/dist/lib/delivery/identity.js +82 -0
  101. package/dist/lib/delivery/inbox.d.ts +116 -0
  102. package/dist/lib/delivery/inbox.js +260 -0
  103. package/dist/lib/delivery/migrations.d.ts +139 -0
  104. package/dist/lib/delivery/migrations.js +623 -0
  105. package/dist/lib/delivery/mqtt-adapter.d.ts +50 -0
  106. package/dist/lib/delivery/mqtt-adapter.js +242 -0
  107. package/dist/lib/delivery/mqtt.d.ts +61 -0
  108. package/dist/lib/delivery/mqtt.js +112 -0
  109. package/dist/lib/delivery/outbox.d.ts +95 -0
  110. package/dist/lib/delivery/outbox.js +187 -0
  111. package/dist/lib/delivery/provenance.d.ts +129 -0
  112. package/dist/lib/delivery/provenance.js +93 -0
  113. package/dist/lib/delivery/reconciler.d.ts +151 -0
  114. package/dist/lib/delivery/reconciler.js +492 -0
  115. package/dist/lib/delivery/restore.d.ts +35 -0
  116. package/dist/lib/delivery/restore.js +134 -0
  117. package/dist/lib/delivery/store.d.ts +161 -0
  118. package/dist/lib/delivery/store.js +940 -0
  119. package/dist/lib/delivery/workers/macos-job-helper.d.ts +103 -0
  120. package/dist/lib/delivery/workers/macos-job-helper.js +927 -0
  121. package/dist/lib/delivery/workers/macos.d.ts +176 -0
  122. package/dist/lib/delivery/workers/macos.js +901 -0
  123. package/dist/lib/delivery/workers/windows-boundary.d.ts +453 -0
  124. package/dist/lib/delivery/workers/windows-boundary.js +693 -0
  125. package/dist/lib/delivery/workers/windows-job-helper.d.ts +35 -0
  126. package/dist/lib/delivery/workers/windows-job-helper.js +264 -0
  127. package/dist/lib/delivery/workers/windows.d.ts +241 -0
  128. package/dist/lib/delivery/workers/windows.js +608 -0
  129. package/dist/lib/doctor/checks/release-links.d.ts +50 -8
  130. package/dist/lib/doctor/checks/release-links.js +260 -24
  131. package/dist/lib/doctor/fix/apply.js +24 -8
  132. package/dist/lib/doctor/fix/remediation.js +15 -5
  133. package/dist/lib/install/provider-wrappers.d.ts +2 -0
  134. package/dist/lib/install/provider-wrappers.js +68 -3
  135. package/dist/lib/lanes/autopilot-registry.d.ts +14 -0
  136. package/dist/lib/lanes/autopilot-registry.js +59 -7
  137. package/dist/lib/lanes/links.d.ts +14 -0
  138. package/dist/lib/lanes/links.js +320 -25
  139. package/dist/lib/lanes/outpost-pruner-install.d.ts +10 -0
  140. package/dist/lib/lanes/outpost-pruner-install.js +4 -3
  141. package/dist/main.js +3 -1
  142. package/dist/sentry-init.d.ts +2 -0
  143. package/dist/sentry-init.js +13 -2
  144. package/dist/sentry.d.ts +2 -0
  145. package/dist/sentry.js +5 -1
  146. package/dist/utils/cli-network-lifecycle.d.ts +9 -0
  147. package/dist/utils/cli-network-lifecycle.js +52 -0
  148. package/dist/utils/cognito-callback-port.d.ts +14 -0
  149. package/dist/utils/cognito-callback-port.js +24 -0
  150. package/dist/utils/cognito-session.js +3 -3
  151. package/dist/utils/deleted-company-notice.d.ts +59 -0
  152. package/dist/utils/deleted-company-notice.js +156 -0
  153. package/dist/utils/login-browser.d.ts +1 -1
  154. package/dist/utils/login-browser.js +7 -5
  155. package/dist/utils/resident-package-preload.js +30 -15
  156. package/dist/utils/safe-link.d.ts +63 -0
  157. package/dist/utils/safe-link.js +246 -0
  158. package/dist/utils/sentry-keepalive-transport.d.ts +28 -0
  159. package/dist/utils/sentry-keepalive-transport.js +70 -0
  160. package/dist/utils/vault-api.js +7 -0
  161. package/package.json +7 -7
@@ -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)");
@@ -35,6 +35,7 @@ const SESSION_ID_ENV_KEYS = [
35
35
  "CODEX_SESSION_ID",
36
36
  "CODEX_THREAD_ID",
37
37
  "GROK_SESSION_ID",
38
+ "HQ_FLEET_SESSION_ID",
38
39
  ];
39
40
  function validSessionId(value) {
40
41
  return value !== "" && value !== "." && value !== ".." && /^[A-Za-z0-9._-]+$/.test(value);
@@ -6,7 +6,7 @@ import { createRequire } from "node:module";
6
6
  import { spawn, spawnSync } from "node:child_process";
7
7
  import { awkCannotOpenFileDiagnostic } from "../lib/core-utils/awk-diagnostics.js";
8
8
  import { shellDisplayPath } from "../lib/core-utils/shell-display-path.js";
9
- import { validSessionId, resolveSessionId as resolveSharedSessionId } from "../lib/core-utils/session-id.js";
9
+ import { SESSION_ID_ENV_KEYS, validSessionId, resolveSessionId as resolveSharedSessionId } from "../lib/core-utils/session-id.js";
10
10
  export const HQ_SESSION_ASSET = "core/scripts/hq-session.sh";
11
11
  const requireSessionDependency = createRequire(import.meta.url);
12
12
  export const HQ_SESSION_HELP = [
@@ -715,7 +715,7 @@ export function executeHqSession(argv, context, overrides = {}) {
715
715
  return {
716
716
  code: 1,
717
717
  stdout: "",
718
- stderr: "hq-session: no current session — no session id in the environment (HQ_SESSION_ID, CLAUDE_CODE_SESSION_ID, CLAUDE_SESSION_ID, CODEX_SESSION_ID, CODEX_THREAD_ID) and workspace/sessions/.current is missing or invalid. Is master-hook installed? Pass --session-id <id> to target a session explicitly.\n",
718
+ stderr: `hq-session: no current session — no session id in the environment (${SESSION_ID_ENV_KEYS.join(", ")}) and workspace/sessions/.current is missing or invalid. Is master-hook installed? Pass --session-id <id> to target a session explicitly.\n`,
719
719
  };
720
720
  }
721
721
  const target = path.join(root, "workspace", "sessions", sessionId, "meta.yaml");
@@ -20,7 +20,7 @@ export const PIN_HELP = `# hq-pin.sh — anchor the current session to one goal
20
20
  #
21
21
  # Storage: workspace/sessions/<sid>/pin.md plus \`pin: <goal>\` in the session's
22
22
  `;
23
- const SESSION_ENV_KEYS = ["HQ_SESSION_ID", "CLAUDE_CODE_SESSION_ID", "CLAUDE_SESSION_ID", "CODEX_SESSION_ID", "CODEX_THREAD_ID", "GROK_SESSION_ID"];
23
+ const SESSION_ENV_KEYS = ["HQ_SESSION_ID", "CLAUDE_CODE_SESSION_ID", "CLAUDE_SESSION_ID", "CODEX_SESSION_ID", "CODEX_THREAD_ID", "GROK_SESSION_ID", "HQ_FLEET_SESSION_ID"];
24
24
  const stamp = (date) => date.toISOString().replace(/\.\d{3}Z$/, "Z");
25
25
  function normalizeId(value) { return value.replace(/[\t\n\v\f\r ]/g, ""); }
26
26
  function validId(value) { return value !== "" && value !== "." && value !== ".." && /^[A-Za-z0-9._-]+$/.test(value); }
@@ -769,7 +769,7 @@ function resolvePolicyTarget(target, root, cwd) {
769
769
  }
770
770
  function sessionCompanySlug(root, env) {
771
771
  const valid = (candidate) => candidate !== '' && candidate !== '.' && candidate !== '..' && /^[A-Za-z0-9._-]+$/.test(candidate);
772
- const candidates = ['HQ_SESSION_ID', 'CLAUDE_CODE_SESSION_ID', 'CLAUDE_SESSION_ID', 'CODEX_SESSION_ID', 'CODEX_THREAD_ID', 'GROK_SESSION_ID'];
772
+ const candidates = ['HQ_SESSION_ID', 'CLAUDE_CODE_SESSION_ID', 'CLAUDE_SESSION_ID', 'CODEX_SESSION_ID', 'CODEX_THREAD_ID', 'GROK_SESSION_ID', 'HQ_FLEET_SESSION_ID'];
773
773
  let sessionId = '';
774
774
  for (const variable of candidates) {
775
775
  const value = (env[variable] ?? '').replace(/[\s\u00a0]+/g, '');
@@ -114,7 +114,7 @@ function validSessionId(value) {
114
114
  return value !== "" && value !== "." && value !== ".." && /^[A-Za-z0-9._-]+$/.test(value);
115
115
  }
116
116
  function sessionId(root, env, fileSystem) {
117
- for (const name of ["HQ_SESSION_ID", "CLAUDE_CODE_SESSION_ID", "CLAUDE_SESSION_ID", "CODEX_SESSION_ID", "CODEX_THREAD_ID", "GROK_SESSION_ID"]) {
117
+ for (const name of ["HQ_SESSION_ID", "CLAUDE_CODE_SESSION_ID", "CLAUDE_SESSION_ID", "CODEX_SESSION_ID", "CODEX_THREAD_ID", "GROK_SESSION_ID", "HQ_FLEET_SESSION_ID"]) {
118
118
  const value = (env[name] ?? "").replace(/[ \t\n\v\f\r]/g, "");
119
119
  if (validSessionId(value))
120
120
  return value;
@@ -4,6 +4,8 @@ export type FastSentryReportDependencies = {
4
4
  initSentry: (overrides?: Partial<Pick<NodeOptions, "transport">>) => void;
5
5
  finishSentrySession: () => void;
6
6
  flushSentry: (timeoutMs: number) => PromiseLike<boolean>;
7
+ /** Close the transport's keep-alive sockets after the flush. */
8
+ closeSentryTransport?: () => void;
7
9
  addCommandBreadcrumb: () => void;
8
10
  report: typeof reportSentryEvent;
9
11
  };
@@ -1,6 +1,6 @@
1
1
  import { settleWithin } from "../utils/settle-with-timeout.js";
2
2
  import { beforeSend } from "../sentry-before-send.js";
3
- import { addSentryRuntimeBreadcrumb, flushSentryRuntime, finishSentryRuntimeSession, initSentryRuntime, } from "../sentry-init.js";
3
+ import { addSentryRuntimeBreadcrumb, closeSentryRuntimeTransport, flushSentryRuntime, finishSentryRuntimeSession, initSentryRuntime, } from "../sentry-init.js";
4
4
  import { addCommandBreadcrumb } from "../utils/command-breadcrumb.js";
5
5
  import { reportSentryEvent } from "../lib/core-utils/sentry-report.js";
6
6
  const SENTRY_FINALIZATION_TIMEOUT_MS = 500;
@@ -8,6 +8,7 @@ const defaultDependencies = {
8
8
  initSentry: (overrides) => { initSentryRuntime(beforeSend, overrides); },
9
9
  finishSentrySession: finishSentryRuntimeSession,
10
10
  flushSentry: flushSentryRuntime,
11
+ closeSentryTransport: closeSentryRuntimeTransport,
11
12
  addCommandBreadcrumb: () => addCommandBreadcrumb(process.argv.slice(2), addSentryRuntimeBreadcrumb),
12
13
  report: reportSentryEvent,
13
14
  };
@@ -49,6 +50,7 @@ export function runSentryReportFast(args, stdin, _cwd, hqRoot, _commandName, _hq
49
50
  return dependencies.report(stdin, { dryRun: false, timeoutMs, hqRoot }).then(async (result) => {
50
51
  dependencies.finishSentrySession();
51
52
  await settleWithin([Promise.resolve(dependencies.flushSentry(SENTRY_FINALIZATION_TIMEOUT_MS))], SENTRY_FINALIZATION_TIMEOUT_MS);
53
+ dependencies.closeSentryTransport?.();
52
54
  return result.code;
53
55
  });
54
56
  }
@@ -1084,12 +1084,14 @@ async function runMigrate(d, opts) {
1084
1084
  d.out("Nothing was changed. `hq daemon migrate --apply` takes them over.");
1085
1085
  }
1086
1086
  async function runServiceSelfUpdate(d) {
1087
- const [{ daemonSelfUpdate }, { hostToolUpdater, runDaemonUpdater, updaterEnv }, { TOOL_NAMES }, { cliSelfUpdatable }, { updateManagedHqCloud },] = await Promise.all([
1087
+ const [{ daemonSelfUpdate }, { hostToolUpdater, resolveRunningDaemonVersion, runDaemonUpdater, updaterEnv }, { TOOL_NAMES }, { cliSelfUpdatable }, { updateManagedHqCloud }, { pingHqdVersion }, { CLI_VERSION },] = await Promise.all([
1088
1088
  import("../utils/self-update.js"),
1089
1089
  import("../lib/daemon/updater.js"),
1090
1090
  import("../lib/daemon/tools.js"),
1091
1091
  import("../lib/daemon/run.js"),
1092
1092
  import("../lib/daemon/hq-cloud.js"),
1093
+ import("../lib/daemon/convergence.js"),
1094
+ import("../cli-version.js"),
1093
1095
  ]);
1094
1096
  const { paths, detected } = currentHost(d);
1095
1097
  const env = updaterEnv(d.env);
@@ -1100,6 +1102,14 @@ async function runServiceSelfUpdate(d) {
1100
1102
  updateHqCloud: async () => updateManagedHqCloud(paths.root, env),
1101
1103
  hqCloudUnits: hqCloudUnits(detected.type, enabledServices(detected.type, readDaemonConfig(paths.configPath))),
1102
1104
  requestDaemonRestart: () => writeControlRequest(paths.requestsDir, { action: "restart-daemon", deferUntilSyncIdle: true }),
1105
+ // A daemon started before this release keeps its old code until it restarts.
1106
+ installedCliVersion: CLI_VERSION,
1107
+ // hqd answers only while HQ Anywhere is on; the fallbacks cover the rest.
1108
+ runningDaemonVersion: () => resolveRunningDaemonVersion({
1109
+ ping: () => pingHqdVersion(hqdSocketPath(d.home, d.env, d.platform)),
1110
+ env: d.env,
1111
+ parentCommandLine: () => processCommandLine(process.ppid),
1112
+ }),
1103
1113
  requestRestart: (unit) => writeControlRequest(paths.requestsDir, { action: "restart", unit }),
1104
1114
  log: d.out,
1105
1115
  });
@@ -65,7 +65,9 @@ export declare function connectScopeFromOptions(opts: Pick<ConnectOptions, "pers
65
65
  * than fall through to a default.
66
66
  */
67
67
  export declare function assertAuthMode(value: string | undefined): void;
68
- /** RFC 7230 token characters accepted for an HTTP field name. */
68
+ /** True when hq-pro refuses to send a key in this (token-valid) header name. */
69
+ export declare function isDeniedAuthHeader(name: string): boolean;
70
+ /** RFC 7230 token, at most 64 characters, and not on hq-pro's denylist. */
69
71
  export declare function assertAuthHeader(value: string | undefined): void;
70
72
  /** Single-quote a value for a copy-pasteable shell command. */
71
73
  export declare function shellQuote(value: string): string;
@@ -79,9 +81,14 @@ export declare function shellQuote(value: string): string;
79
81
  * HQ-PRO-5QF: a key pasted from a doc or chat often arrives wrapped across
80
82
  * lines or with a tab, and sometimes with smart quotes. hq-pro sends the key
81
83
  * in an HTTP header, which can't carry those characters. Trim the ends, drop
82
- * inner line breaks and tabs, and refuse anything else outside visible ASCII
83
- * (an inner space is left for hq-pro to judge, since HTTP Basic allows it).
84
+ * inner line breaks and tabs, and refuse anything else outside visible ASCII.
84
85
  * The message never echoes the key.
86
+ *
87
+ * feedback_950d8abe: this is hq-pro's rule for every key the CLI sends. The
88
+ * CLI sends a key as Bearer or in a custom header (--auth-header), never as an
89
+ * HTTP Basic password, and hq-pro accepts only visible ASCII (0x21-0x7E) for
90
+ * those. An inner space used to pass here and come back from hq-pro as a 400
91
+ * DIRECT_MCP_INVALID_API_KEY_CHARACTERS.
85
92
  */
86
93
  export declare const API_KEY_UNSENDABLE_MESSAGE = "The key contains a character that can't be sent. Copy it again and paste only the key.";
87
94
  export declare function normalizePastedApiKey(raw: string): string;
@@ -120,7 +127,7 @@ export declare function consoleIntegrationsUrl(companySlug: string | undefined,
120
127
  * credentials — but only the console can collect them, so say what is needed
121
128
  * and hand the page over rather than restating the refusal and stopping.
122
129
  */
123
- export declare function bringYourOwnClientHandoff(target: ConnectTarget, opts: ConnectOptions, reason: string, redirectUri?: string): Promise<null>;
130
+ export declare function bringYourOwnClientHandoff(target: ConnectTarget, opts: ConnectOptions, reason: string, redirectUri?: string, resolveEndpoint?: () => Promise<string | undefined>): Promise<null>;
124
131
  /**
125
132
  * Google issues "Desktop app" and "Web application" OAuth clients with the
126
133
  * same client-id shape, but only a Web application client accepts HQ's hosted
@@ -135,5 +142,11 @@ export interface ConnectOwnership {
135
142
  viewerPersonUid?: string;
136
143
  }
137
144
  export declare function findAlreadyConnected(connections: readonly AdminConnection[], app: string, ownership?: ConnectOwnership): AdminConnection | undefined;
145
+ /**
146
+ * `connect --help` text for the `--json` stdout shapes. A sign-in that does
147
+ * not finish in this command prints exactly one JSON line on stdout, and
148
+ * `setup` says which of these it is.
149
+ */
150
+ export declare const CONNECT_JSON_HELP = "\n--json output when the sign-in does not finish in this command (for example\nwith --link-only) is one JSON line on stdout. \"setup\" says which it is:\n {\"app\",\"setup\":\"sign-in-link\",\"authorizationUrl\"}\n Open authorizationUrl; the sign-in finishes on the HQ console.\n {\"app\",\"setup\":\"own-oauth-app\",\"callbackUrl\",\"command\"}\n Register callbackUrl with the provider, then run command with your\n app's client id (and its secret on stdin).\n {\"app\",\"setup\":\"console\",\"url\"?,\"serverAddress\"?}\n Finish on the console page at url (left out when the console address\n is unknown). serverAddress is the MCP endpoint to enter there.\nA finished connect prints the install result instead. Confirm any of the\nthree with `hq integrations list`.\n";
138
151
  export declare function registerConnectCommands(integrations: Command): void;
139
152
  //# sourceMappingURL=integrations-connect.d.ts.map