@indigoai-us/hq-cli 5.345.219 → 5.345.221

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/dist/command-catalog.generated.d.ts +169 -3
  3. package/dist/command-catalog.generated.js +206 -3
  4. package/dist/commands/auth.js +4 -1
  5. package/dist/commands/bot-runtime.d.ts +18 -5
  6. package/dist/commands/bot-runtime.js +29 -12
  7. package/dist/commands/bot.d.ts +85 -0
  8. package/dist/commands/bot.js +245 -16
  9. package/dist/commands/cloud.d.ts +16 -0
  10. package/dist/commands/cloud.js +112 -102
  11. package/dist/commands/core-checkpoint-native.d.ts +13 -0
  12. package/dist/commands/core-checkpoint-native.js +167 -52
  13. package/dist/commands/core-hook-registration-plan.js +5 -4
  14. package/dist/commands/core-stop-autosave.d.ts +21 -0
  15. package/dist/commands/core-stop-autosave.js +300 -0
  16. package/dist/commands/core.js +2 -0
  17. package/dist/commands/daemon.d.ts +5 -0
  18. package/dist/commands/daemon.js +52 -9
  19. package/dist/commands/doctor-usage.d.ts +5 -0
  20. package/dist/commands/doctor-usage.js +25 -0
  21. package/dist/commands/env.d.ts +49 -4
  22. package/dist/commands/env.js +355 -5
  23. package/dist/commands/integrations.js +84 -3
  24. package/dist/commands/lanes-shared.d.ts +3 -0
  25. package/dist/commands/lanes.d.ts +3 -0
  26. package/dist/commands/lanes.js +87 -3
  27. package/dist/commands/packs.js +23 -0
  28. package/dist/commands/pkg-update.d.ts +6 -0
  29. package/dist/commands/pkg-update.js +15 -7
  30. package/dist/commands/run.js +55 -45
  31. package/dist/commands/sources.js +4 -3
  32. package/dist/commands/sync-core.d.ts +1 -0
  33. package/dist/commands/sync-core.js +77 -3
  34. package/dist/commands/whoami.js +96 -80
  35. package/dist/lib/bot/config.d.ts +17 -0
  36. package/dist/lib/bot/config.js +13 -0
  37. package/dist/lib/bot/fleet-cron.js +29 -4
  38. package/dist/lib/bot/fleet-local.d.ts +30 -2
  39. package/dist/lib/bot/fleet-local.js +60 -1
  40. package/dist/lib/bot/grok-login-scope.d.ts +36 -0
  41. package/dist/lib/bot/grok-login-scope.js +93 -0
  42. package/dist/lib/bot/inflight.d.ts +9 -0
  43. package/dist/lib/bot/jobs/hot-signal-sync.d.ts +51 -0
  44. package/dist/lib/bot/jobs/hot-signal-sync.js +90 -9
  45. package/dist/lib/bot/legacy-provider-login.d.ts +32 -9
  46. package/dist/lib/bot/legacy-provider-login.js +28 -22
  47. package/dist/lib/bot/run.d.ts +29 -5
  48. package/dist/lib/bot/run.js +203 -1
  49. package/dist/lib/bot/runtime-sign-in-check.js +6 -1
  50. package/dist/lib/bot/runtime-sign-in.d.ts +2 -0
  51. package/dist/lib/bot/signals-try-now.d.ts +76 -0
  52. package/dist/lib/bot/signals-try-now.js +111 -0
  53. package/dist/lib/capacity/collectors/claude-oauth.d.ts +22 -3
  54. package/dist/lib/capacity/collectors/claude-oauth.js +78 -22
  55. package/dist/lib/capacity/scheduler.d.ts +8 -0
  56. package/dist/lib/capacity/scheduler.js +5 -2
  57. package/dist/lib/core-utils/sentry-report.js +2 -0
  58. package/dist/lib/daemon/machine-checks.d.ts +22 -1
  59. package/dist/lib/daemon/machine-checks.js +54 -12
  60. package/dist/lib/daemon/run.js +71 -8
  61. package/dist/lib/daemon/runtime-notifications.d.ts +7 -0
  62. package/dist/lib/daemon/runtime-notifications.js +50 -0
  63. package/dist/lib/daemon/stop-autosave-lock.d.ts +19 -0
  64. package/dist/lib/daemon/stop-autosave-lock.js +166 -0
  65. package/dist/lib/daemon/stop-autosave.d.ts +28 -0
  66. package/dist/lib/daemon/stop-autosave.js +111 -0
  67. package/dist/lib/daemon/stop-diagnostics.d.ts +11 -0
  68. package/dist/lib/daemon/stop-diagnostics.js +136 -0
  69. package/dist/lib/daemon/stop-job-executor.d.ts +19 -0
  70. package/dist/lib/daemon/stop-job-executor.js +126 -0
  71. package/dist/lib/daemon/stop-jobs.d.ts +93 -0
  72. package/dist/lib/daemon/stop-jobs.js +599 -0
  73. package/dist/lib/doctor/checks/fleet-hook-core.d.ts +9 -1
  74. package/dist/lib/doctor/checks/fleet-hook-core.js +39 -15
  75. package/dist/lib/doctor/checks/host-core.js +1 -1
  76. package/dist/lib/environment/access-probes.d.ts +234 -0
  77. package/dist/lib/environment/access-probes.js +918 -0
  78. package/dist/lib/environment/profile.d.ts +15 -2
  79. package/dist/lib/environment/profile.js +55 -20
  80. package/dist/lib/environment/rfc3339.d.ts +8 -0
  81. package/dist/lib/environment/rfc3339.js +26 -0
  82. package/dist/lib/environment/work-requirements.d.ts +169 -0
  83. package/dist/lib/environment/work-requirements.js +389 -0
  84. package/dist/lib/hook-engine/coverage.d.ts +137 -7
  85. package/dist/lib/hook-engine/coverage.js +1424 -4
  86. package/dist/lib/hook-engine/fleet-registration.d.ts +17 -5
  87. package/dist/lib/hook-engine/fleet-registration.js +53 -17
  88. package/dist/lib/hook-engine/git-stop-config.json +513 -0
  89. package/dist/lib/hook-engine/native-stop-compatibility.json +311 -0
  90. package/dist/lib/hook-engine/reconcile.js +2 -2
  91. package/dist/lib/hot-channels/alert.d.ts +10 -1
  92. package/dist/lib/hot-channels/alert.js +38 -8
  93. package/dist/lib/hot-channels/signals-claude-login.d.ts +53 -0
  94. package/dist/lib/hot-channels/signals-claude-login.js +96 -0
  95. package/dist/lib/hot-channels/signals-pass.d.ts +143 -17
  96. package/dist/lib/hot-channels/signals-pass.js +324 -17
  97. package/dist/lib/hot-channels/signals-runtime.d.ts +30 -0
  98. package/dist/lib/hot-channels/signals-runtime.js +82 -0
  99. package/dist/lib/install/hook-target.js +1 -1
  100. package/dist/lib/lanes/host-capacity.d.ts +26 -2
  101. package/dist/lib/lanes/host-capacity.js +17 -2
  102. package/dist/lib/lanes/host-compute.d.ts +90 -0
  103. package/dist/lib/lanes/host-compute.js +185 -0
  104. package/dist/lib/lanes/index.d.ts +2 -0
  105. package/dist/lib/lanes/index.js +1 -0
  106. package/dist/lib/lanes/reconcile.js +22 -1
  107. package/dist/lib/lanes/resource-usage.d.ts +155 -0
  108. package/dist/lib/lanes/resource-usage.js +589 -0
  109. package/dist/lib/lanes/run-size.d.ts +46 -0
  110. package/dist/lib/lanes/run-size.js +197 -0
  111. package/dist/lib/lanes/store.js +27 -0
  112. package/dist/lib/lanes/throttle.d.ts +36 -1
  113. package/dist/lib/lanes/throttle.js +47 -10
  114. package/dist/lib/lanes/types.d.ts +40 -0
  115. package/dist/lib/lanes/types.js +2 -2
  116. package/dist/lib/lanes/watcher.js +13 -4
  117. package/dist/lib/lanes/worker-process.d.ts +25 -2
  118. package/dist/lib/lanes/worker-process.js +71 -19
  119. package/dist/lib/placement/match.d.ts +192 -0
  120. package/dist/lib/placement/match.js +667 -0
  121. package/dist/lib/safe-store.d.ts +14 -0
  122. package/dist/lib/safe-store.js +77 -4
  123. package/dist/lib/search-index/index.d.ts +88 -4
  124. package/dist/lib/search-index/index.js +299 -25
  125. package/dist/lib/search-index/max-doc-bytes.d.ts +17 -6
  126. package/dist/lib/search-index/max-doc-bytes.js +48 -23
  127. package/dist/lib/signals/codex-lockdown.d.ts +79 -0
  128. package/dist/lib/signals/codex-lockdown.js +271 -0
  129. package/dist/lib/signals/codex-login.d.ts +37 -0
  130. package/dist/lib/signals/codex-login.js +83 -0
  131. package/dist/lib/signals/engine.d.ts +28 -0
  132. package/dist/lib/signals/engine.js +77 -0
  133. package/dist/lib/signals/reply.d.ts +48 -0
  134. package/dist/lib/signals/reply.js +94 -12
  135. package/dist/lib/signals/run-record.js +6 -1
  136. package/dist/lib/signals/settings.d.ts +5 -0
  137. package/dist/lib/signals/settings.js +2 -0
  138. package/dist/lib/signals/steps/adapters.js +6 -0
  139. package/dist/lib/signals/steps/extract.d.ts +135 -12
  140. package/dist/lib/signals/steps/extract.js +416 -84
  141. package/dist/lib/signals/steps/types.d.ts +21 -0
  142. package/dist/lib/sync-core/engine-home.d.ts +41 -2
  143. package/dist/lib/sync-core/engine-home.js +132 -19
  144. package/dist/lib/sync-core/reconcile.js +1 -1
  145. package/dist/lib/sync-core/release-compare.d.ts +7 -0
  146. package/dist/lib/sync-core/release-compare.js +16 -0
  147. package/dist/lib/sync-core/release.d.ts +2 -1
  148. package/dist/lib/sync-core/release.js +2 -10
  149. package/dist/lib/sync-core/rollout-state.d.ts +2 -1
  150. package/dist/lib/sync-core/rollout-state.js +5 -2
  151. package/dist/lib/sync-core/vault-uid.d.ts +2 -0
  152. package/dist/lib/sync-core/vault-uid.js +4 -0
  153. package/dist/run/schema-env-overrides.d.ts +24 -0
  154. package/dist/run/schema-env-overrides.js +72 -0
  155. package/dist/schemas/hq-work-requirements.v1.schema.json +145 -0
  156. package/dist/utils/auth-session-check.d.ts +16 -0
  157. package/dist/utils/auth-session-check.js +16 -0
  158. package/dist/utils/client-health-contract.d.ts +6 -0
  159. package/dist/utils/client-health-contract.js +13 -0
  160. package/dist/utils/client-health.d.ts +7 -0
  161. package/dist/utils/client-health.js +22 -1
  162. package/dist/utils/command-usage.d.ts +40 -0
  163. package/dist/utils/command-usage.js +61 -0
  164. package/dist/utils/duplicate-command-usage.d.ts +72 -0
  165. package/dist/utils/duplicate-command-usage.js +125 -0
  166. package/dist/utils/host-registration.d.ts +1 -1
  167. package/dist/utils/host-registration.js +6 -1
  168. package/dist/utils/resident-package-preload.js +4 -0
  169. package/dist/utils/sentry-fingerprint.js +9 -0
  170. package/dist/utils/windows-bash.d.ts +2 -0
  171. package/dist/utils/windows-bash.js +2 -1
  172. package/package.json +15 -10
  173. package/scripts/bench-core-compare.mjs +313 -0
  174. package/scripts/bench-core.mjs +399 -12
  175. package/scripts/check-function-manifest.mjs +121 -7
  176. package/dist/commands/__fixtures__/access-vault.d.ts +0 -95
  177. package/dist/commands/__fixtures__/access-vault.js +0 -166
  178. package/dist/commands/__fixtures__/make-tar.d.ts +0 -38
  179. package/dist/commands/__fixtures__/make-tar.js +0 -102
  180. package/dist/commands/secrets-public-types.test-d.d.ts +0 -2
  181. package/dist/commands/secrets-public-types.test-d.js +0 -18
  182. package/dist/lib/decisions/fixtures/us001.d.ts +0 -137
  183. package/dist/lib/decisions/fixtures/us001.js +0 -21
  184. package/dist/lib/doctor/__testing__/fake-hq-tree.d.ts +0 -226
  185. package/dist/lib/doctor/__testing__/fake-hq-tree.js +0 -408
  186. package/dist/lib/doctor/__testing__/run-doctor.d.ts +0 -8
  187. package/dist/lib/doctor/__testing__/run-doctor.js +0 -69
  188. package/dist/lib/fingerprint/fixtures.d.ts +0 -19
  189. package/dist/lib/fingerprint/fixtures.js +0 -61
  190. package/dist/lib/hot-channels/adapters/__fixtures__/dummy.d.ts +0 -33
  191. package/dist/lib/hot-channels/adapters/__fixtures__/dummy.js +0 -53
  192. package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.d.ts +0 -38
  193. package/dist/lib/hot-channels/adapters/__fixtures__/meeting-providers.js +0 -64
  194. package/dist/lib/mesh/live/daemon/mqtt-events.test-d.d.ts +0 -2
  195. package/dist/lib/mesh/live/daemon/mqtt-events.test-d.js +0 -10
  196. package/dist/lib/test-utils/isolated-flag-company-context.d.ts +0 -3
  197. package/dist/lib/test-utils/isolated-flag-company-context.js +0 -18
  198. package/scripts/hook-engine-manifest.mjs +0 -22
  199. package/scripts/mesh-daemon-if-stale.mjs +0 -20
@@ -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
@@ -11,6 +11,7 @@ import * as path from "node:path";
11
11
  import { createHash, randomUUID } from "node:crypto";
12
12
  import { execFileSync, spawn } from "node:child_process";
13
13
  import { homedir } from "node:os";
14
+ import { isDeepStrictEqual } from "node:util";
14
15
  import { toHqStateWriteError } from "../utils/hq-state-write-error.js";
15
16
  import { checkpointStampWriteErrorFor, isCheckpointStampWriteError, } from "../utils/checkpoint-stamp-write-error.js";
16
17
  import { isExecutableOnPath } from "../utils/resolve-executable.js";
@@ -585,19 +586,24 @@ function writeCheckpointStampAtomically(targetPath, contents, fsImpl, waitForRet
585
586
  }
586
587
  }
587
588
  }
589
+ /**
590
+ * Filename-safe form of a session ID, shared by every per-session state file
591
+ * (checkpoint-cli-last-*, checkpoint-auto-sibling-*, checkpoint-auto-thread-*).
592
+ */
593
+ function sessionKey(sessionId) {
594
+ return sessionId ? sessionId.replace(/[^A-Za-z0-9._-]/g, "_") || "unknown" : "unknown";
595
+ }
588
596
  export function writeStamps(liveRoot, sessionId, options = {}) {
589
597
  const fsImpl = options.fs ?? fs;
590
598
  const platform = options.platform ?? process.platform;
591
599
  const waitForRetry = options.waitForRetry ?? waitForCheckpointWriteRetry;
592
600
  const stateDir = path.join(liveRoot, "workspace", "orchestrator", "hook-state");
593
601
  writeHqState(stateDir, "create the checkpoint state directory", () => fsImpl.mkdirSync(stateDir, { recursive: true }));
594
- const sessionKey = sessionId
595
- ? sessionId.replace(/[^A-Za-z0-9._-]/g, "_") || "unknown"
596
- : "unknown";
602
+ const key = sessionKey(sessionId);
597
603
  const timestamp = Math.floor(Date.now() / 1000).toString();
598
604
  const stampPaths = [
599
605
  path.join(stateDir, "checkpoint-cli-last"),
600
- path.join(stateDir, `checkpoint-cli-last-${sessionKey}`),
606
+ path.join(stateDir, `checkpoint-cli-last-${key}`),
601
607
  ];
602
608
  for (const stampPath of stampPaths) {
603
609
  writeHqState(stampPath, "write its checkpoint state file", () => platform === "win32"
@@ -606,9 +612,67 @@ export function writeStamps(liveRoot, sessionId, options = {}) {
606
612
  }
607
613
  return stampPaths;
608
614
  }
615
+ function autoThreadPointerPath(liveRoot, sessionId) {
616
+ return path.join(liveRoot, "workspace", "orchestrator", "hook-state", `checkpoint-auto-thread-${sessionKey(sessionId)}`);
617
+ }
618
+ /**
619
+ * The session's existing automatic checkpoint thread, if any. The Stop gate
620
+ * fires `--trigger stop-gate-auto` after every replied turn, and each run used
621
+ * to write a new `T-*-auto-*.json` (about 3,500 files and a 700 KB threads
622
+ * index in one install, feedback_b4d615f1). A per-session pointer stamp names
623
+ * the thread file; it is trusted only when the file still parses and carries
624
+ * the same session_id and the stop-gate-auto trigger. Only that trigger reuses
625
+ * a thread: explicit checkpoints always write their own. Without a session ID
626
+ * there is nothing to match on, so a new thread is written.
627
+ */
628
+ function findAutoThread(liveRoot, trigger, sessionId) {
629
+ if (trigger !== AUTO_TRIGGER || !sessionId)
630
+ return null;
631
+ try {
632
+ const name = fs.readFileSync(autoThreadPointerPath(liveRoot, sessionId), "utf8").trim();
633
+ if (!name || name !== path.basename(name) || !name.endsWith(".json"))
634
+ return null;
635
+ const threadPath = path.join(liveRoot, "workspace", "threads", name);
636
+ const thread = JSON.parse(fs.readFileSync(threadPath, "utf8"));
637
+ if (thread.session_id !== sessionId || thread.metadata?.trigger !== AUTO_TRIGGER)
638
+ return null;
639
+ return { threadPath, thread };
640
+ }
641
+ catch {
642
+ return null;
643
+ }
644
+ }
645
+ /**
646
+ * Test seam: runs after the auto thread was found and before the existence
647
+ * re-check, so a test can delete or rename the thread in that window.
648
+ */
649
+ export const checkpointTestSeams = {};
650
+ /**
651
+ * Write through a temp file in the same directory, then rename (atomic). On any
652
+ * failure the temp file is removed and the error is rethrown. `fsImpl` is a
653
+ * test seam.
654
+ */
655
+ export function writeFileAtomic(target, contents, fsImpl = fs) {
656
+ const tmp = `${target}.${process.pid}.${randomUUID()}.tmp`;
657
+ try {
658
+ fsImpl.writeFileSync(tmp, contents);
659
+ fsImpl.renameSync(tmp, target);
660
+ }
661
+ catch (error) {
662
+ try {
663
+ fsImpl.unlinkSync(tmp);
664
+ }
665
+ catch {
666
+ // nothing to clean up
667
+ }
668
+ throw error;
669
+ }
670
+ }
671
+ function mergeUnique(a, b) {
672
+ return [...new Set([...(a ?? []), ...b])];
673
+ }
609
674
  function autoSiblingStampPath(liveRoot, sessionId) {
610
- const sessionKey = sessionId.replace(/[^A-Za-z0-9._-]/g, "_") || "unknown";
611
- return path.join(liveRoot, "workspace", "orchestrator", "hook-state", `checkpoint-auto-sibling-${sessionKey}`);
675
+ return path.join(liveRoot, "workspace", "orchestrator", "hook-state", `checkpoint-auto-sibling-${sessionKey(sessionId)}`);
612
676
  }
613
677
  /**
614
678
  * True when an automatic checkpoint for this session already started (or
@@ -1555,54 +1619,105 @@ async function runCheckpoint(options, command, group, preResolvedHqRoot) {
1555
1619
  ? "none"
1556
1620
  : await resolveBackend(requestedBackend, liveRoot, input.company, { dryRun: options.dryRun });
1557
1621
  const now = new Date();
1558
- const threadId = `T-${formatTimestamp(now)}-auto-${summarySlug(input.summary)}`;
1559
- const threadPath = path.join(liveRoot, "workspace", "threads", `${threadId}.json`);
1560
- const relativeThreadPath = path.relative(liveRoot, threadPath);
1561
- const git = gitStateFor(process.cwd(), liveRoot, input.initialCommit, input.commits);
1562
- const stampPaths = [
1563
- path.join(liveRoot, "workspace", "orchestrator", "hook-state", "checkpoint-cli-last"),
1564
- path.join(liveRoot, "workspace", "orchestrator", "hook-state", `checkpoint-cli-last-${input.sessionId ? input.sessionId.replace(/[^A-Za-z0-9._-]/g, "_") || "unknown" : "unknown"}`),
1565
- ];
1566
- if (options.dryRun) {
1567
- printDryRun({
1568
- live_root: liveRoot,
1569
- idle: false,
1570
- thread: relativeThreadPath,
1571
- checkpoint: {
1572
- git,
1573
- insights: input.insights,
1574
- worker: input.worker,
1622
+ let existingAuto = findAutoThread(liveRoot, input.trigger, input.sessionId);
1623
+ let threadId = existingAuto?.thread.thread_id ?? `T-${formatTimestamp(now)}-auto-${summarySlug(input.summary)}`;
1624
+ let threadPath = existingAuto?.threadPath ?? path.join(liveRoot, "workspace", "threads", `${threadId}.json`);
1625
+ let relativeThreadPath = path.relative(liveRoot, threadPath);
1626
+ {
1627
+ const git = gitStateFor(process.cwd(), liveRoot, input.initialCommit, input.commits);
1628
+ const stampPaths = [
1629
+ path.join(liveRoot, "workspace", "orchestrator", "hook-state", "checkpoint-cli-last"),
1630
+ path.join(liveRoot, "workspace", "orchestrator", "hook-state", `checkpoint-cli-last-${sessionKey(input.sessionId)}`),
1631
+ ];
1632
+ if (options.dryRun) {
1633
+ printDryRun({
1634
+ live_root: liveRoot,
1635
+ idle: false,
1636
+ thread: relativeThreadPath,
1637
+ checkpoint: {
1638
+ git,
1639
+ insights: input.insights,
1640
+ worker: input.worker,
1641
+ },
1642
+ stamps: stampPaths.map((stampPath) => path.relative(liveRoot, stampPath)),
1643
+ sibling: siblingOptOut || autoDebounced ? null : { backend },
1644
+ });
1645
+ return;
1646
+ }
1647
+ if (existingAuto) {
1648
+ checkpointTestSeams.beforeAutoThreadWrite?.();
1649
+ // The maintenance sibling may have renamed or archived the thread since
1650
+ // it was found. Do not resurrect the old name: start a new thread.
1651
+ if (!fs.existsSync(existingAuto.threadPath)) {
1652
+ existingAuto = null;
1653
+ threadId = `T-${formatTimestamp(now)}-auto-${summarySlug(input.summary)}`;
1654
+ threadPath = path.join(liveRoot, "workspace", "threads", `${threadId}.json`);
1655
+ relativeThreadPath = path.relative(liveRoot, threadPath);
1656
+ }
1657
+ }
1658
+ const prior = existingAuto?.thread;
1659
+ // Merge policy when reusing a thread: files_touched, learnings, insights,
1660
+ // decisions and tags are unioned. next_steps, conversation_summary and the
1661
+ // git fields are REPLACED by this run's values. Keys the maintenance
1662
+ // sibling added (top-level or inside git, such as git.knowledge_repos)
1663
+ // survive because the update is spread over the prior thread.
1664
+ // Title rule: metadata.title is set from this run's summary only when the
1665
+ // prior thread has no title, or its title still equals the one
1666
+ // auto-generated from the prior summary; a title the sibling improved is
1667
+ // kept.
1668
+ // Concurrency: same-session runs are not serialised (no lockfile). Writes
1669
+ // are atomic (temp file plus rename), so a reader never sees a partial
1670
+ // file. The existence re-check above narrows resurrecting a renamed-away
1671
+ // thread to a very small window between the check and the rename. Two runs
1672
+ // of the same session at the same instant can lose one union merge, and on
1673
+ // the session's first turn they can fork a second thread (the last pointer
1674
+ // write wins).
1675
+ const priorTitle = prior?.metadata?.title;
1676
+ const keepTitle = typeof priorTitle === "string" &&
1677
+ priorTitle !== "" &&
1678
+ priorTitle !== titleFor(prior?.conversation_summary ?? "");
1679
+ const thread = {
1680
+ ...prior,
1681
+ thread_id: threadId,
1682
+ version: 1,
1683
+ type: "auto-checkpoint",
1684
+ created_at: prior?.created_at ?? now.toISOString(),
1685
+ updated_at: now.toISOString(),
1686
+ workspace_root: liveRoot,
1687
+ cwd: process.cwd(),
1688
+ git: { ...prior?.git, ...git },
1689
+ conversation_summary: input.summary,
1690
+ files_touched: mergeUnique(prior?.files_touched, input.files),
1691
+ next_steps: input.nextSteps,
1692
+ learnings: mergeUnique(prior?.learnings, input.learnings),
1693
+ insights: mergeUnique(prior?.insights, input.insights),
1694
+ decisions: mergeUnique(prior?.decisions, input.decisions),
1695
+ worker: input.worker ?? prior?.worker,
1696
+ session_id: input.sessionId ?? null,
1697
+ metadata: {
1698
+ ...prior?.metadata,
1699
+ title: keepTitle ? priorTitle : titleFor(input.summary),
1700
+ tags: mergeUnique(prior?.metadata?.tags, ["auto-checkpoint", ...input.tags]),
1701
+ trigger: input.trigger,
1575
1702
  },
1576
- stamps: stampPaths.map((stampPath) => path.relative(liveRoot, stampPath)),
1577
- sibling: siblingOptOut || autoDebounced ? null : { backend },
1578
- });
1579
- return;
1703
+ };
1704
+ // Nothing changed since the last update: leave the file (and its mtime)
1705
+ // alone rather than rewrite it with a new updated_at. Deep-equal, so key
1706
+ // order does not matter; the JSON round trip drops undefined values.
1707
+ const unchanged = prior !== undefined &&
1708
+ isDeepStrictEqual({ ...prior, updated_at: "" }, { ...JSON.parse(JSON.stringify(thread)), updated_at: "" });
1709
+ if (!unchanged) {
1710
+ writeHqState(path.dirname(threadPath), "create the checkpoint thread directory", () => fs.mkdirSync(path.dirname(threadPath), { recursive: true }));
1711
+ writeHqState(threadPath, "write the checkpoint thread file", () => writeFileAtomic(threadPath, `${JSON.stringify(thread, null, 2)}\n`));
1712
+ }
1713
+ if (!existingAuto && input.trigger === AUTO_TRIGGER && input.sessionId) {
1714
+ const pointerPath = autoThreadPointerPath(liveRoot, input.sessionId);
1715
+ writeHqState(pointerPath, "record the session's auto checkpoint thread", () => {
1716
+ fs.mkdirSync(path.dirname(pointerPath), { recursive: true });
1717
+ writeFileAtomic(pointerPath, path.basename(threadPath));
1718
+ });
1719
+ }
1580
1720
  }
1581
- const thread = {
1582
- thread_id: threadId,
1583
- version: 1,
1584
- type: "auto-checkpoint",
1585
- created_at: now.toISOString(),
1586
- updated_at: now.toISOString(),
1587
- workspace_root: liveRoot,
1588
- cwd: process.cwd(),
1589
- git,
1590
- conversation_summary: input.summary,
1591
- files_touched: input.files,
1592
- next_steps: input.nextSteps,
1593
- learnings: input.learnings,
1594
- insights: input.insights,
1595
- decisions: input.decisions,
1596
- worker: input.worker,
1597
- session_id: input.sessionId ?? null,
1598
- metadata: {
1599
- title: titleFor(input.summary),
1600
- tags: ["auto-checkpoint", ...input.tags],
1601
- trigger: input.trigger,
1602
- },
1603
- };
1604
- writeHqState(path.dirname(threadPath), "create the checkpoint thread directory", () => fs.mkdirSync(path.dirname(threadPath), { recursive: true }));
1605
- writeHqState(threadPath, "write the checkpoint thread file", () => fs.writeFileSync(threadPath, `${JSON.stringify(thread, null, 2)}\n`));
1606
1721
  writeStamps(liveRoot, input.sessionId);
1607
1722
  printResult(`checkpoint: ${relativeThreadPath}`);
1608
1723
  // finally: the thread is already written at this point, so the agent must
@@ -1,6 +1,6 @@
1
1
  import * as fs from 'node:fs';
2
2
  import * as os from 'node:os';
3
- import { fleetRegistrationPlan } from '../lib/hook-engine/fleet-registration.js';
3
+ import { fleetRegistrationPlan, isFleetHost } from '../lib/hook-engine/fleet-registration.js';
4
4
  import { describeCoreCommand } from './core-command-catalog.js';
5
5
  export function registerCoreHookRegistrationPlan(core, runtime = {}) {
6
6
  const command = core.command('hook-registration-plan')
@@ -8,13 +8,14 @@ export function registerCoreHookRegistrationPlan(core, runtime = {}) {
8
8
  .requiredOption('--host <host>', 'Registration host')
9
9
  .option('--json', 'Print JSON')
10
10
  .action((options, command) => {
11
- if (options.host !== 'fleet-local')
12
- throw new Error('Only fleet-local registration is supported');
11
+ const host = options.host;
12
+ if (!isFleetHost(host))
13
+ throw new Error('Only fleet-local and agents-v2 registration are supported');
13
14
  const root = command.optsWithGlobals().hqRoot;
14
15
  if (!root)
15
16
  throw new Error('--hq-root is required');
16
17
  const fallbacks = JSON.parse((runtime.readInput ?? (() => fs.readFileSync(0, 'utf8')))());
17
- (runtime.writeOutput ?? console.log)(JSON.stringify(fleetRegistrationPlan(root, fallbacks, runtime.planOptions ?? { home: process.env.HOME ?? os.homedir() })));
18
+ (runtime.writeOutput ?? console.log)(JSON.stringify(fleetRegistrationPlan(root, fallbacks, { ...(runtime.planOptions ?? { home: process.env.HOME ?? os.homedir() }), host })));
18
19
  });
19
20
  describeCoreCommand(command, { execution: 'native', root: 'live' });
20
21
  }
@@ -0,0 +1,21 @@
1
+ /** Typed CLI boundary for Stop's Bash-file autosave job. */
2
+ import type { Command } from "commander";
3
+ /** The private folder, inside the HQ root, that holds the autosave lock. */
4
+ export declare const AUTOSAVE_LOCK_FOLDER = "workspace/.autocommit-lock";
5
+ /** The caller supplies only its root and session; every Git argument is built
6
+ * here. Tests replace the sweep dependencies and never invoke this mutation.
7
+ */
8
+ export interface StopAutosaveDependencies {
9
+ git?: (root: string, args: string[]) => {
10
+ code: number;
11
+ stdout: string;
12
+ stderr: string;
13
+ };
14
+ enabled?: () => Promise<boolean>;
15
+ now?: () => number;
16
+ /** A definite holder answer; unknown always retains an index lock. */
17
+ indexLockHeld?: (file: string) => boolean | undefined;
18
+ }
19
+ export declare function stopAutosave(root: string, session: string, env: NodeJS.ProcessEnv, deps?: StopAutosaveDependencies): Promise<number>;
20
+ export declare function registerCoreStopAutosave(core: Command): void;
21
+ //# sourceMappingURL=core-stop-autosave.d.ts.map