caveat-cli 0.14.6 → 0.14.8

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.
@@ -14804,7 +14804,16 @@ function readCodexSessionSignals(transcriptPath) {
14804
14804
  }
14805
14805
 
14806
14806
  // ../../packages/core/dist/pendingReminders.js
14807
- import { existsSync as existsSync8, mkdirSync as mkdirSync2, readdirSync as readdirSync4, readFileSync as readFileSync6, unlinkSync, writeFileSync as writeFileSync2 } from "node:fs";
14807
+ import {
14808
+ existsSync as existsSync8,
14809
+ mkdirSync as mkdirSync2,
14810
+ readdirSync as readdirSync4,
14811
+ readFileSync as readFileSync6,
14812
+ rmSync as rmSync2,
14813
+ statSync as statSync3,
14814
+ unlinkSync,
14815
+ writeFileSync as writeFileSync2
14816
+ } from "node:fs";
14808
14817
  import { join as join5 } from "node:path";
14809
14818
  import { randomBytes } from "node:crypto";
14810
14819
  function sanitizeSessionId(raw) {
@@ -14822,6 +14831,91 @@ function appendPendingReminder(caveatHome, sessionId, text) {
14822
14831
  writeFileSync2(path, text, "utf-8");
14823
14832
  return path;
14824
14833
  }
14834
+ function cleanupStalePendingDirs(caveatHome, options2 = {}) {
14835
+ const staleDays = options2.staleDays ?? 7;
14836
+ if (staleDays < 0) {
14837
+ throw new Error(`cleanupStalePendingDirs: staleDays must be >= 0 (got ${staleDays})`);
14838
+ }
14839
+ const now = options2.now ?? /* @__PURE__ */ new Date();
14840
+ const cutoffMs = now.getTime() - staleDays * 24 * 60 * 60 * 1e3;
14841
+ const root = join5(caveatHome, "pending");
14842
+ if (!existsSync8(root)) return { removed: [], kept: 0 };
14843
+ let entries;
14844
+ try {
14845
+ entries = readdirSync4(root);
14846
+ } catch {
14847
+ return { removed: [], kept: 0 };
14848
+ }
14849
+ const removed = [];
14850
+ let kept = 0;
14851
+ for (const entry of entries) {
14852
+ const sub = join5(root, entry);
14853
+ let subStat;
14854
+ try {
14855
+ subStat = statSync3(sub);
14856
+ } catch {
14857
+ continue;
14858
+ }
14859
+ if (!subStat.isDirectory()) continue;
14860
+ let newest = subStat.mtimeMs;
14861
+ let scanFailed = false;
14862
+ try {
14863
+ for (const f of readdirSync4(sub)) {
14864
+ const fp = join5(sub, f);
14865
+ try {
14866
+ const fs = statSync3(fp);
14867
+ if (fs.mtimeMs > newest) newest = fs.mtimeMs;
14868
+ } catch {
14869
+ scanFailed = true;
14870
+ break;
14871
+ }
14872
+ }
14873
+ } catch {
14874
+ scanFailed = true;
14875
+ }
14876
+ if (scanFailed || newest >= cutoffMs) {
14877
+ kept++;
14878
+ continue;
14879
+ }
14880
+ try {
14881
+ rmSync2(sub, { recursive: true, force: true });
14882
+ removed.push(sub);
14883
+ } catch {
14884
+ kept++;
14885
+ }
14886
+ }
14887
+ return { removed, kept };
14888
+ }
14889
+ function maybeSweepPendingDirs(caveatHome, options2 = {}) {
14890
+ if (process.env.CAVEAT_PENDING_SWEEP === "off") {
14891
+ return { skipped: "env_off" };
14892
+ }
14893
+ const staleDays = options2.staleDays ?? 7;
14894
+ const debounceDays = options2.debounceDays ?? 1;
14895
+ if (debounceDays < 0) {
14896
+ throw new Error(
14897
+ `maybeSweepPendingDirs: debounceDays must be >= 0 (got ${debounceDays})`
14898
+ );
14899
+ }
14900
+ const now = options2.now ?? /* @__PURE__ */ new Date();
14901
+ const pendingRoot = join5(caveatHome, "pending");
14902
+ if (!existsSync8(pendingRoot)) return { skipped: "no_pending_dir" };
14903
+ const marker = join5(pendingRoot, ".last-sweep");
14904
+ try {
14905
+ const m = statSync3(marker);
14906
+ const ageMs = now.getTime() - m.mtimeMs;
14907
+ if (ageMs < debounceDays * 24 * 60 * 60 * 1e3) {
14908
+ return { skipped: "debounced" };
14909
+ }
14910
+ } catch {
14911
+ }
14912
+ const result = cleanupStalePendingDirs(caveatHome, { staleDays, now });
14913
+ try {
14914
+ writeFileSync2(marker, "", "utf-8");
14915
+ } catch {
14916
+ }
14917
+ return { swept: result };
14918
+ }
14825
14919
  function drainPendingReminders(caveatHome, sessionId) {
14826
14920
  const dir = pendingDirFor(caveatHome, sessionId);
14827
14921
  if (!existsSync8(dir)) return [];
@@ -15107,7 +15201,7 @@ function writeEntryFile(filePath, content) {
15107
15201
  }
15108
15202
 
15109
15203
  // ../../packages/core/dist/record.js
15110
- import { statSync as statSync3 } from "node:fs";
15204
+ import { statSync as statSync4 } from "node:fs";
15111
15205
  import { join as join6 } from "node:path";
15112
15206
  var DEFAULT_CATEGORY = "misc";
15113
15207
  function recordEntry(input, opts) {
@@ -15146,7 +15240,7 @@ function recordEntry(input, opts) {
15146
15240
  const relPath = `${category}/${id}.md`;
15147
15241
  const filePath = join6(opts.entriesRoot, relPath);
15148
15242
  writeEntryFile(filePath, built.content);
15149
- const stat = statSync3(filePath);
15243
+ const stat = statSync4(filePath);
15150
15244
  upsertEntry(opts.db, {
15151
15245
  id,
15152
15246
  source,
@@ -15174,7 +15268,7 @@ function formatYmd(d) {
15174
15268
  }
15175
15269
 
15176
15270
  // ../../packages/core/dist/update.js
15177
- import { readFileSync as readFileSync7, statSync as statSync4, writeFileSync as writeFileSync4 } from "node:fs";
15271
+ import { readFileSync as readFileSync7, statSync as statSync5, writeFileSync as writeFileSync4 } from "node:fs";
15178
15272
  import { join as join7 } from "node:path";
15179
15273
  var IMMUTABLE_KEYS = /* @__PURE__ */ new Set([
15180
15274
  "id",
@@ -15234,7 +15328,7 @@ function updateEntry(id, patch, opts) {
15234
15328
  }
15235
15329
  const built = buildEntry(mergedFrontmatter, mergedSections);
15236
15330
  writeFileSync4(filePath, built.content, "utf-8");
15237
- const stat = statSync4(filePath);
15331
+ const stat = statSync5(filePath);
15238
15332
  upsertEntry(opts.db, {
15239
15333
  id,
15240
15334
  source,
@@ -15288,6 +15382,8 @@ export {
15288
15382
  struggleSearchText,
15289
15383
  readCodexSessionSignals,
15290
15384
  appendPendingReminder,
15385
+ cleanupStalePendingDirs,
15386
+ maybeSweepPendingDirs,
15291
15387
  drainPendingReminders,
15292
15388
  markHit,
15293
15389
  listStale,
@@ -15318,4 +15414,4 @@ strip-bom-string/index.js:
15318
15414
  js-yaml/dist/js-yaml.mjs:
15319
15415
  (*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT *)
15320
15416
  */
15321
- //# sourceMappingURL=chunk-EH3S6X6X.js.map
15417
+ //# sourceMappingURL=chunk-ECC5LJZF.js.map