@indigoai-us/hq-cli 5.345.245 → 5.345.246

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 (113) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/dist/command-catalog.generated.d.ts +93 -6
  3. package/dist/command-catalog.generated.js +114 -6
  4. package/dist/commands/bot.js +1 -1
  5. package/dist/commands/core-checkpoint-native.d.ts +5 -1
  6. package/dist/commands/core-checkpoint-native.js +13 -5
  7. package/dist/commands/deploy-comments.js +139 -0
  8. package/dist/commands/deploy-list.d.ts +5 -0
  9. package/dist/commands/deploy-list.js +8 -0
  10. package/dist/commands/dm.d.ts +4 -1
  11. package/dist/commands/dm.js +11 -2
  12. package/dist/commands/files.d.ts +11 -2
  13. package/dist/commands/files.js +48 -3
  14. package/dist/commands/lanes-loop.js +4 -1
  15. package/dist/commands/lanes.js +16 -5
  16. package/dist/commands/mesh.d.ts +2 -0
  17. package/dist/commands/mesh.js +26 -6
  18. package/dist/commands/reindex.js +2 -1
  19. package/dist/commands/rescue.d.ts +22 -1
  20. package/dist/commands/rescue.js +56 -9
  21. package/dist/commands/sources.d.ts +1 -1
  22. package/dist/commands/sources.js +1 -1
  23. package/dist/commands/storage.d.ts +15 -2
  24. package/dist/commands/storage.js +74 -7
  25. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +232 -225
  26. package/dist/hq-cloud-sync-runner/package.json +1 -1
  27. package/dist/lib/agent-kit/mcp/tools.js +22 -0
  28. package/dist/lib/bot/jobs/hot-signal-sync.js +4 -1
  29. package/dist/lib/daemon/fleet-members-cache.d.ts +55 -0
  30. package/dist/lib/daemon/fleet-members-cache.js +266 -0
  31. package/dist/lib/daemon/handoff.d.ts +4 -0
  32. package/dist/lib/daemon/handoff.js +2 -1
  33. package/dist/lib/daemon/hook-requests.d.ts +2 -1
  34. package/dist/lib/daemon/hook-requests.js +19 -2
  35. package/dist/lib/daemon/install.d.ts +9 -1
  36. package/dist/lib/daemon/install.js +11 -2
  37. package/dist/lib/daemon/ops/policy.d.ts +23 -3
  38. package/dist/lib/daemon/ops/policy.js +62 -15
  39. package/dist/lib/daemon/run.js +12 -0
  40. package/dist/lib/daemon/server.d.ts +5 -0
  41. package/dist/lib/daemon/server.js +1 -1
  42. package/dist/lib/daemon/supervisor.d.ts +6 -0
  43. package/dist/lib/daemon/supervisor.js +31 -2
  44. package/dist/lib/doctor/checks/sync-runtime.js +8 -1
  45. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  46. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  47. package/dist/lib/hook-engine/coverage.d.ts +68 -0
  48. package/dist/lib/hook-engine/coverage.js +163 -0
  49. package/dist/lib/hook-engine/native-precompact-compatibility.json +1 -0
  50. package/dist/lib/hot-channels/signals-pass.d.ts +52 -2
  51. package/dist/lib/hot-channels/signals-pass.js +65 -3
  52. package/dist/lib/install/claude-targets.d.ts +6 -0
  53. package/dist/lib/install/claude-targets.js +9 -1
  54. package/dist/lib/lanes/reconcile-result.d.ts +1 -1
  55. package/dist/lib/lanes/reconcile.js +19 -4
  56. package/dist/lib/lanes/remote-control-lane.d.ts +6 -0
  57. package/dist/lib/lanes/remote-control-lane.js +10 -1
  58. package/dist/lib/lanes/spawn.d.ts +2 -0
  59. package/dist/lib/lanes/spawn.js +19 -3
  60. package/dist/lib/lanes/worker-env-scrub.d.ts +48 -0
  61. package/dist/lib/lanes/worker-env-scrub.js +146 -0
  62. package/dist/lib/lanes/worker-process.js +4 -1
  63. package/dist/lib/mesh/client.js +5 -1
  64. package/dist/lib/mesh/live/daemon/doctor.d.ts +9 -0
  65. package/dist/lib/mesh/live/daemon/doctor.js +51 -6
  66. package/dist/lib/mesh/live/daemon/install.d.ts +39 -0
  67. package/dist/lib/mesh/live/daemon/install.js +70 -0
  68. package/dist/lib/mesh/live/daemon/outbox-company.d.ts +47 -0
  69. package/dist/lib/mesh/live/daemon/outbox-company.js +77 -0
  70. package/dist/lib/mesh/live/daemon/run.d.ts +2 -0
  71. package/dist/lib/mesh/live/daemon/run.js +48 -3
  72. package/dist/lib/mesh/live/daemon/state.d.ts +5 -0
  73. package/dist/lib/mesh/live/daemon/system-unit.d.ts +21 -0
  74. package/dist/lib/mesh/live/daemon/system-unit.js +80 -0
  75. package/dist/lib/mesh/live/daemon/transcript-watch.d.ts +4 -1
  76. package/dist/lib/mesh/live/daemon/transcript-watch.js +42 -38
  77. package/dist/lib/mesh/live/direct-drain.js +3 -1
  78. package/dist/lib/mesh/live/emit.js +4 -2
  79. package/dist/lib/mesh/live/flush.d.ts +61 -0
  80. package/dist/lib/mesh/live/flush.js +434 -114
  81. package/dist/lib/mesh/live/paths.d.ts +10 -0
  82. package/dist/lib/mesh/live/paths.js +14 -0
  83. package/dist/lib/mesh/live/reporting-privacy.d.ts +41 -1
  84. package/dist/lib/mesh/live/reporting-privacy.js +81 -7
  85. package/dist/lib/mesh/live/spool.d.ts +171 -17
  86. package/dist/lib/mesh/live/spool.js +777 -62
  87. package/dist/lib/signals/engine.d.ts +82 -2
  88. package/dist/lib/signals/engine.js +389 -53
  89. package/dist/lib/signals/steps/extract.js +5 -0
  90. package/dist/lib/work-context/organize.d.ts +22 -4
  91. package/dist/lib/work-context/organize.js +50 -21
  92. package/dist/lib/work-context/paths.d.ts +6 -0
  93. package/dist/lib/work-context/paths.js +9 -0
  94. package/dist/lib/work-context/reconcile.d.ts +1 -1
  95. package/dist/lib/work-context/reconcile.js +1 -1
  96. package/dist/startup-registration.d.ts +14 -0
  97. package/dist/startup-registration.js +26 -0
  98. package/dist/utils/cli-telemetry.d.ts +6 -0
  99. package/dist/utils/cli-telemetry.js +154 -9
  100. package/dist/utils/github-tag-fallback.d.ts +7 -2
  101. package/dist/utils/github-tag-fallback.js +17 -8
  102. package/dist/utils/hq-core-source.d.ts +31 -0
  103. package/dist/utils/hq-core-source.js +144 -0
  104. package/dist/utils/interactive-caller.d.ts +6 -0
  105. package/dist/utils/interactive-caller.js +8 -0
  106. package/dist/utils/shipped-codex-hooks.d.ts +6 -4
  107. package/dist/utils/shipped-codex-hooks.js +22 -10
  108. package/dist/utils/vault-api.js +1 -0
  109. package/dist/utils/version-report.d.ts +3 -1
  110. package/dist/utils/version-report.js +13 -5
  111. package/docs/anywhere-runtime.md +2 -2
  112. package/package.json +8 -8
  113. package/scripts/check-function-manifest.mjs +99 -18
@@ -5,9 +5,11 @@ import chalk from 'chalk';
5
5
  import { rescue } from '@indigoai-us/hq-cloud';
6
6
  import { findHqRoot } from '../utils/manifest.js';
7
7
  import { selfUpdateAndReexec } from '../utils/self-update.js';
8
- import { retrustCodexHooksAfterRescue } from '../utils/hook-trust.js';
8
+ import { retrustCodexHooksAfterRescue, trustCodexUserHooks } from '../utils/hook-trust.js';
9
+ import { reconcileHookRegistrations } from '../lib/hook-engine/reconcile.js';
9
10
  import { repairDanglingReleaseLinks } from '../lib/doctor/checks/release-links.js';
10
- import { PROD_SOURCE, STAGING_SOURCE, resolveGhToken } from '../utils/shipped-codex-hooks.js';
11
+ import { resolveGhToken } from '../utils/shipped-codex-hooks.js';
12
+ import { githubTokenFor, isGitHubHost, resolveHqCoreSource } from '../utils/hq-core-source.js';
11
13
  import { GitHubApiUnavailable, onceWarning, isTransientGitHubStatus, remoteTagSha, withGitTagFallback } from '../utils/github-tag-fallback.js';
12
14
  /**
13
15
  * Resolve the source repo + ref from the user's flags. Pure + exported for
@@ -15,10 +17,21 @@ import { GitHubApiUnavailable, onceWarning, isTransientGitHubStatus, remoteTagSh
15
17
  * for staging and when an explicit `--ref` is given.
16
18
  */
17
19
  export function resolveRescueTarget(opts, latestTag) {
20
+ const core = resolveHqCoreSource();
18
21
  if (opts.staging) {
19
- return { source: opts.source ?? STAGING_SOURCE, ref: opts.ref };
22
+ return { source: opts.source ?? core.stagingRepo, ref: opts.ref };
20
23
  }
21
- return { source: opts.source ?? PROD_SOURCE, ref: opts.ref ?? latestTag };
24
+ return { source: opts.source ?? core.repo, ref: opts.ref ?? latestTag };
25
+ }
26
+ /**
27
+ * The GitHub token to hand the rescue script, which clones and downloads from
28
+ * the HQ_CORE_SOURCE web and codeload bases. Exported for tests. Returns
29
+ * undefined unless both bases are GitHub hosts, so a GitHub token never
30
+ * reaches an overridden non-GitHub host.
31
+ */
32
+ export function rescueScriptToken(token) {
33
+ const { webBase, codeloadBase } = resolveHqCoreSource();
34
+ return isGitHubHost(webBase) && isGitHubHost(codeloadBase) ? token : undefined;
22
35
  }
23
36
  /**
24
37
  * Whether this invocation should try the CLI self-update. Pure + exported for
@@ -51,6 +64,36 @@ export async function retrustHooksAfterRescue(hqRoot, retrust = retrustCodexHook
51
64
  'Codex will skip changed HQ hooks until you run `hq reindex`.'));
52
65
  }
53
66
  }
67
+ /**
68
+ * Re-plan HQ's hook registrations after a rescue that changed files on disk,
69
+ * the same step `hq reindex` runs. The registration that points an event at
70
+ * the new core lives partly outside the HQ root (the user-scope Codex
71
+ * hooks.json), so a core apply never replaces it. Without this step, an event
72
+ * whose coverage hold now applies to the files the core apply put on disk (for
73
+ * example a Stop or SubagentStop the native engine does not model for the new
74
+ * adapter) stays on the new core and is refused natively on every call until
75
+ * someone runs `hq reindex` by hand. Exported for tests. Best-effort: a failure
76
+ * leaves the current registrations in place and is reported, but never changes
77
+ * the rescue's exit status, because the core update itself succeeded.
78
+ */
79
+ export async function reconcileHooksAfterRescue(hqRoot, reconcile = reconcileHookRegistrations, trust = trustCodexUserHooks) {
80
+ const advise = 'Run `hq reindex` to retry.';
81
+ try {
82
+ const { codexUserKeys, failures } = reconcile(hqRoot);
83
+ for (const failure of failures) {
84
+ console.warn(chalk.yellow(`rescue: hook registration reconcile skipped ${failure}. ${advise}`));
85
+ }
86
+ if (codexUserKeys.length) {
87
+ const result = await trust(hqRoot, codexUserKeys);
88
+ if (result.status === 'failed') {
89
+ console.warn(chalk.yellow(`rescue: Codex hook trust needs repair: ${result.reason ?? 'unknown error'}. ${advise}`));
90
+ }
91
+ }
92
+ }
93
+ catch (error) {
94
+ console.warn(chalk.yellow(`rescue: hook registration reconcile skipped: ${error.message}. ${advise}`));
95
+ }
96
+ }
54
97
  /**
55
98
  * Repair HQ-managed release links (`.agents/skills`, `.codex/claude`, ...)
56
99
  * that do not resolve after a rescue, for example because they were laid at
@@ -108,7 +151,8 @@ const GITHUB_REQUEST_TIMEOUT_MS = 30_000;
108
151
  async function githubJsonRequest(url, token, fetchImpl = fetch) {
109
152
  const signal = AbortSignal.timeout(GITHUB_REQUEST_TIMEOUT_MS);
110
153
  try {
111
- const response = await fetchImpl(url, { headers: ghHeaders(token), signal });
154
+ // Never forward a GitHub token to an overridden non-GitHub host.
155
+ const response = await fetchImpl(url, { headers: ghHeaders(githubTokenFor(url, token)), signal });
112
156
  if (isTransientGitHubStatus(response.status)) {
113
157
  throw new GitHubApiUnavailable(`GitHub API for ${url}: HTTP ${response.status}`);
114
158
  }
@@ -127,8 +171,9 @@ async function githubJsonRequest(url, token, fetchImpl = fetch) {
127
171
  }
128
172
  /** Latest release tag for a repo, e.g. `v12.3.0`. Throws on failure. */
129
173
  export async function getLatestReleaseTag(repo, token, deps = {}) {
174
+ const { apiBase } = resolveHqCoreSource();
130
175
  return withGitTagFallback(async () => {
131
- const { response, body } = await githubJsonRequest(`https://api.github.com/repos/${repo}/releases/latest`, token, deps.fetchImpl);
176
+ const { response, body } = await githubJsonRequest(`${apiBase}/repos/${repo}/releases/latest`, token, deps.fetchImpl);
132
177
  if (!response.ok) {
133
178
  throw new Error(`GitHub releases/latest for ${repo}: HTTP ${response.status}`);
134
179
  }
@@ -139,8 +184,9 @@ export async function getLatestReleaseTag(repo, token, deps = {}) {
139
184
  }
140
185
  /** Resolve a tag to its commit SHA, dereferencing annotated tags. */
141
186
  export async function resolveTagSha(repo, tag, token, deps = {}) {
187
+ const { apiBase } = resolveHqCoreSource();
142
188
  return withGitTagFallback(async () => {
143
- const { response: refRes, body: ref } = await githubJsonRequest(`https://api.github.com/repos/${repo}/git/ref/tags/${encodeURIComponent(tag)}`, token, deps.fetchImpl);
189
+ const { response: refRes, body: ref } = await githubJsonRequest(`${apiBase}/repos/${repo}/git/ref/tags/${encodeURIComponent(tag)}`, token, deps.fetchImpl);
144
190
  if (!refRes.ok)
145
191
  throw new Error(`git/ref/tags/${tag} for ${repo}: HTTP ${refRes.status}`);
146
192
  const obj = ref?.object;
@@ -149,7 +195,7 @@ export async function resolveTagSha(repo, tag, token, deps = {}) {
149
195
  if (obj.type !== 'tag')
150
196
  return obj.sha; // lightweight tag → already a commit
151
197
  // Annotated tag → dereference to the commit it points at.
152
- const { response: tagRes, body: annotated } = await githubJsonRequest(`https://api.github.com/repos/${repo}/git/tags/${obj.sha}`, token, deps.fetchImpl);
198
+ const { response: tagRes, body: annotated } = await githubJsonRequest(`${apiBase}/repos/${repo}/git/tags/${obj.sha}`, token, deps.fetchImpl);
153
199
  if (!tagRes.ok)
154
200
  throw new Error(`git/tags/${obj.sha} for ${repo}: HTTP ${tagRes.status}`);
155
201
  if (!annotated?.object?.sha)
@@ -237,11 +283,12 @@ export function registerRescueCommand(program) {
237
283
  assumeYes: opts.yes,
238
284
  noBackup: opts.backup === false,
239
285
  cloudUpdate: opts.cloudUpdate,
240
- ghToken: token,
286
+ ghToken: rescueScriptToken(token),
241
287
  });
242
288
  if (status === 0 && !opts.check) {
243
289
  repairReleaseLinksAfterRescue(hqRoot);
244
290
  await retrustHooksAfterRescue(hqRoot);
291
+ await reconcileHooksAfterRescue(hqRoot);
245
292
  }
246
293
  process.exit(status);
247
294
  }
@@ -171,7 +171,7 @@ export interface SignalsRedoReport {
171
171
  /**
172
172
  * `hq sources signals`: queue landed documents for the signals pass and run
173
173
  * the pass now, under the same per-person lock as `hq sources sync`. The pass
174
- * keeps its cap (`--max-docs`, default 20); what the cap leaves stays queued
174
+ * keeps its cap (`--max-docs`, default 40); what the cap leaves stays queued
175
175
  * and the next run (this command or the daily sync) picks it up.
176
176
  */
177
177
  export declare function runSignalsRedo(options: SignalsRedoOptions, overrides?: SignalsRedoOverrides): Promise<SignalsRedoReport>;
@@ -664,7 +664,7 @@ function renderSyncTable(company, report) {
664
664
  /**
665
665
  * `hq sources signals`: queue landed documents for the signals pass and run
666
666
  * the pass now, under the same per-person lock as `hq sources sync`. The pass
667
- * keeps its cap (`--max-docs`, default 20); what the cap leaves stays queued
667
+ * keeps its cap (`--max-docs`, default 40); what the cap leaves stays queued
668
668
  * and the next run (this command or the daily sync) picks it up.
669
669
  */
670
670
  export async function runSignalsRedo(options, overrides = {}) {
@@ -92,6 +92,8 @@ export interface CloudPruneResult {
92
92
  company: string;
93
93
  deleted_count: number;
94
94
  deleted_bytes: number;
95
+ kept_recent_delete_count: number;
96
+ kept_recent_delete_bytes: number;
95
97
  errors: string[];
96
98
  /** Set when the company was not touched, e.g. the caller is not an owner/admin. */
97
99
  skipped_reason?: string;
@@ -178,6 +180,7 @@ export interface VersionEntry {
178
180
  lastModified: Date;
179
181
  size: number;
180
182
  isDeleteMarker: boolean;
183
+ lastModifiedUnknown?: boolean;
181
184
  /**
182
185
  * When this version stopped being current: the LastModified of the next
183
186
  * newer version or delete marker of the same key. Unset for current entries.
@@ -211,9 +214,19 @@ export declare function getCloudStatus(company: CompanyRef, deps: StorageDeps):
211
214
  * Versions eligible for prune: noncurrent content versions and noncurrent
212
215
  * delete markers that stopped being current before the cutoff (see
213
216
  * annotateNoncurrentSince). The current version of a key (content or delete
214
- * marker) is never selected.
217
+ * marker) is never selected. When a key's current entry is a delete marker
218
+ * from the last RECENT_DELETE_KEEP_DAYS days, or the listing cannot show when
219
+ * or whether the key was deleted, its newest older content version is kept
220
+ * (with any older version whose date is unknown) and reported in
221
+ * keptRecentDelete.
215
222
  */
216
- export declare function selectPrunable(versions: VersionEntry[], cutoff: Date): VersionEntry[];
223
+ export declare function planPrune(versions: VersionEntry[], cutoff: Date, now: Date): PrunePlan;
224
+ export declare function selectPrunable(versions: VersionEntry[], cutoff: Date, now: Date): VersionEntry[];
225
+ export declare const RECENT_DELETE_KEEP_DAYS = 30;
226
+ export interface PrunePlan {
227
+ prune: VersionEntry[];
228
+ keptRecentDelete: VersionEntry[];
229
+ }
217
230
  export declare function pruneCloud(company: CompanyRef, cutoff: Date, dryRun: boolean, deps: StorageDeps): Promise<CloudPruneResult>;
218
231
  export declare function runStorageStatus(opts: {
219
232
  company?: string;
@@ -203,6 +203,12 @@ export function annotateNoncurrentSince(entries) {
203
203
  function noncurrentAge(v) {
204
204
  return v.noncurrentSince ?? v.lastModified;
205
205
  }
206
+ function entryTime(value) {
207
+ const d = value ? new Date(value) : undefined;
208
+ if (!d || Number.isNaN(d.getTime()))
209
+ return { lastModified: new Date(0), lastModifiedUnknown: true };
210
+ return { lastModified: d };
211
+ }
206
212
  function toEntries(page) {
207
213
  const out = [];
208
214
  for (const v of page.Versions ?? []) {
@@ -212,7 +218,7 @@ function toEntries(page) {
212
218
  key: v.Key,
213
219
  versionId: v.VersionId,
214
220
  isLatest: Boolean(v.IsLatest),
215
- lastModified: v.LastModified ? new Date(v.LastModified) : new Date(0),
221
+ ...entryTime(v.LastModified),
216
222
  size: v.Size ?? 0,
217
223
  isDeleteMarker: false,
218
224
  });
@@ -224,7 +230,7 @@ function toEntries(page) {
224
230
  key: m.Key,
225
231
  versionId: m.VersionId,
226
232
  isLatest: Boolean(m.IsLatest),
227
- lastModified: m.LastModified ? new Date(m.LastModified) : new Date(0),
233
+ ...entryTime(m.LastModified),
228
234
  size: 0,
229
235
  isDeleteMarker: true,
230
236
  });
@@ -467,11 +473,60 @@ export async function getCloudStatus(company, deps) {
467
473
  * Versions eligible for prune: noncurrent content versions and noncurrent
468
474
  * delete markers that stopped being current before the cutoff (see
469
475
  * annotateNoncurrentSince). The current version of a key (content or delete
470
- * marker) is never selected.
476
+ * marker) is never selected. When a key's current entry is a delete marker
477
+ * from the last RECENT_DELETE_KEEP_DAYS days, or the listing cannot show when
478
+ * or whether the key was deleted, its newest older content version is kept
479
+ * (with any older version whose date is unknown) and reported in
480
+ * keptRecentDelete.
471
481
  */
472
- export function selectPrunable(versions, cutoff) {
482
+ export function planPrune(versions, cutoff, now) {
473
483
  annotateNoncurrentSince(versions);
474
- return versions.filter((v) => !v.isLatest && noncurrentAge(v).getTime() < cutoff.getTime());
484
+ const byKey = new Map();
485
+ for (const v of versions) {
486
+ const list = byKey.get(v.key);
487
+ if (list)
488
+ list.push(v);
489
+ else
490
+ byKey.set(v.key, [v]);
491
+ }
492
+ const keep = new Set();
493
+ for (const list of byKey.values())
494
+ for (const v of protectedVersions(list, now))
495
+ keep.add(v);
496
+ const prune = [];
497
+ const keptRecentDelete = [];
498
+ for (const v of versions) {
499
+ if (v.isLatest || noncurrentAge(v).getTime() >= cutoff.getTime())
500
+ continue;
501
+ if (keep.has(v))
502
+ keptRecentDelete.push(v);
503
+ else
504
+ prune.push(v);
505
+ }
506
+ return { prune, keptRecentDelete };
507
+ }
508
+ export function selectPrunable(versions, cutoff, now) {
509
+ return planPrune(versions, cutoff, now).prune;
510
+ }
511
+ export const RECENT_DELETE_KEEP_DAYS = 30;
512
+ function isRecentDelete(current, now) {
513
+ if (!current)
514
+ return true;
515
+ if (!current.isDeleteMarker)
516
+ return false;
517
+ if (current.lastModifiedUnknown)
518
+ return true;
519
+ return now.getTime() - current.lastModified.getTime() < RECENT_DELETE_KEEP_DAYS * DAY_MS;
520
+ }
521
+ function protectedVersions(list, now) {
522
+ if (!isRecentDelete(list.find((v) => v.isLatest), now))
523
+ return [];
524
+ const older = list.filter((v) => !v.isLatest && !v.isDeleteMarker);
525
+ const unknown = older.filter((v) => v.lastModifiedUnknown);
526
+ const newest = older
527
+ .filter((v) => !v.lastModifiedUnknown)
528
+ .reduce((best, v) => (best === undefined || v.lastModified.getTime() > best.lastModified.getTime() ? v : best), undefined);
529
+ return newest ? [newest, ...unknown] : unknown;
475
530
  }
476
531
  const DELETE_BATCH = 1000;
477
532
  export async function pruneCloud(company, cutoff, dryRun, deps) {
@@ -479,13 +534,18 @@ export async function pruneCloud(company, cutoff, dryRun, deps) {
479
534
  company: company.slug,
480
535
  deleted_count: 0,
481
536
  deleted_bytes: 0,
537
+ kept_recent_delete_count: 0,
538
+ kept_recent_delete_bytes: 0,
482
539
  errors: [],
483
540
  };
484
541
  let store;
485
542
  let candidates;
486
543
  try {
487
544
  store = await deps.openCompany(company);
488
- candidates = selectPrunable(await listVersions(store), cutoff);
545
+ const plan = planPrune(await listVersions(store), cutoff, deps.now());
546
+ candidates = plan.prune;
547
+ result.kept_recent_delete_count = plan.keptRecentDelete.length;
548
+ result.kept_recent_delete_bytes = plan.keptRecentDelete.reduce((sum, v) => sum + v.size, 0);
489
549
  }
490
550
  catch (err) {
491
551
  result.errors.push(describeCloudError(err, "list"));
@@ -659,6 +719,8 @@ export async function runStoragePrune(opts, deps) {
659
719
  company: c.slug,
660
720
  deleted_count: 0,
661
721
  deleted_bytes: 0,
722
+ kept_recent_delete_count: 0,
723
+ kept_recent_delete_bytes: 0,
662
724
  errors: [],
663
725
  skipped_reason: DELETE_ROLE_REASON,
664
726
  });
@@ -968,6 +1030,11 @@ export function formatStoragePrune(result) {
968
1030
  continue;
969
1031
  }
970
1032
  lines.push(`${c.company}: ${verb} ${c.deleted_count} old version(s), ${formatBytes(c.deleted_bytes)}`);
1033
+ if (c.kept_recent_delete_count > 0) {
1034
+ lines.push(` ${result.dry_run ? "Would keep" : "Kept"} ${c.kept_recent_delete_count} old version(s), ` +
1035
+ `${formatBytes(c.kept_recent_delete_bytes)}: the last copy of files deleted in the last ` +
1036
+ `${RECENT_DELETE_KEEP_DAYS} days, or whose delete date could not be read.`);
1037
+ }
971
1038
  for (const e of c.errors)
972
1039
  lines.push(chalk.red(` ${e}`));
973
1040
  }
@@ -1285,7 +1352,7 @@ export function registerStorageCommand(program) {
1285
1352
  .command("prune")
1286
1353
  .description("Delete local autosave history and old cloud file versions before a date")
1287
1354
  .option("--local-before <date>", "Prune local autosave history before YYYY-MM-DD")
1288
- .option("--cloud-before <date>", "Delete old (noncurrent) cloud file versions before YYYY-MM-DD")
1355
+ .option("--cloud-before <date>", "Delete old (noncurrent) cloud file versions before YYYY-MM-DD; files deleted in the last 30 days keep their last old version")
1289
1356
  .option("--company <slug>", "Only this company (must be one of yours)")
1290
1357
  .option("--dry-run", "Show what would be deleted without deleting")
1291
1358
  .option("--yes", "Skip the confirmation prompt")