codex-cleaner 0.0.2 → 0.0.3

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.
package/dist/cleaner.d.ts CHANGED
@@ -46,6 +46,7 @@ export declare function collectLogCleanupStats(db: DatabaseSync, options: Cleane
46
46
  export declare function collectTuiLogCleanupStats(logPath: string, keepMib: number): Record<string, unknown>;
47
47
  export declare function collectOrphanRolloutArchiveStats(db: DatabaseSync, codexHome: string, args: {
48
48
  cutoffMs: number;
49
+ protectedIds: Set<string>;
49
50
  }): Record<string, unknown>;
50
51
  export declare function nextBackupPath(dbPath: string, backupDir: string, now?: Date): string;
51
52
  export declare function nextFileBackupPath(filePath: string, backupDir: string, now?: Date): string;
package/dist/cleaner.js CHANGED
@@ -373,7 +373,10 @@ export function buildScanReport(options) {
373
373
  });
374
374
  }
375
375
  if (options.archiveOrphanRollouts) {
376
- report.orphanRolloutArchiveCandidates = collectOrphanRolloutArchiveStats(db, codexHome, { cutoffMs });
376
+ report.orphanRolloutArchiveCandidates = collectOrphanRolloutArchiveStats(db, codexHome, {
377
+ cutoffMs,
378
+ protectedIds,
379
+ });
377
380
  }
378
381
  report.recentSample = queryAll(db, `
379
382
  SELECT id, archived, updated_at, updated_at_ms, source, agent_role,
@@ -591,10 +594,11 @@ export function archiveOrphanRollouts(options) {
591
594
  const codexHome = resolveCodexHome(options);
592
595
  const stateDb = path.join(codexHome, "state_5.sqlite");
593
596
  const cutoffMs = recentCutoffMs(options.keepRecentDays);
597
+ const protectedIds = allProtectedIds(loadThreadProtection(codexHome, loadGlobalState(codexHome)));
594
598
  const beforeDb = openReadonlyDb(stateDb);
595
599
  let beforePlan;
596
600
  try {
597
- beforePlan = buildOrphanRolloutPlan(beforeDb, codexHome, { cutoffMs });
601
+ beforePlan = buildOrphanRolloutPlan(beforeDb, codexHome, { cutoffMs, protectedIds });
598
602
  }
599
603
  finally {
600
604
  beforeDb.close();
@@ -613,6 +617,7 @@ export function archiveOrphanRollouts(options) {
613
617
  codexHome,
614
618
  policy: {
615
619
  keepRecentDays: options.keepRecentDays,
620
+ protectedThreads: protectedIds.size,
616
621
  recentCutoffMs: cutoffMs,
617
622
  recentCutoffUtc: millisToIso(cutoffMs),
618
623
  },
@@ -644,6 +649,7 @@ export function archiveOrphanRollouts(options) {
644
649
  codexHome,
645
650
  policy: {
646
651
  keepRecentDays: options.keepRecentDays,
652
+ protectedThreads: protectedIds.size,
647
653
  recentCutoffMs: cutoffMs,
648
654
  recentCutoffUtc: millisToIso(cutoffMs),
649
655
  },
@@ -656,7 +662,7 @@ export function archiveOrphanRollouts(options) {
656
662
  const afterDb = openReadonlyDb(stateDb);
657
663
  let afterPlan;
658
664
  try {
659
- afterPlan = buildOrphanRolloutPlan(afterDb, codexHome, { cutoffMs });
665
+ afterPlan = buildOrphanRolloutPlan(afterDb, codexHome, { cutoffMs, protectedIds });
660
666
  }
661
667
  finally {
662
668
  afterDb.close();
@@ -668,6 +674,7 @@ export function archiveOrphanRollouts(options) {
668
674
  generatedAt: new Date().toISOString(),
669
675
  policy: {
670
676
  keepRecentDays: options.keepRecentDays,
677
+ protectedThreads: protectedIds.size,
671
678
  recentCutoffMs: cutoffMs,
672
679
  recentCutoffUtc: millisToIso(cutoffMs),
673
680
  },
@@ -1179,6 +1186,10 @@ function buildOrphanRolloutPlan(db, codexHome, args) {
1179
1186
  skipped.push({ ...move, reason: "recent" });
1180
1187
  continue;
1181
1188
  }
1189
+ if (threadId && args.protectedIds.has(threadId)) {
1190
+ skipped.push({ ...move, reason: "protected" });
1191
+ continue;
1192
+ }
1182
1193
  if (move.indexed) {
1183
1194
  skipped.push({ ...move, reason: "session-indexed" });
1184
1195
  continue;
@@ -1210,6 +1221,7 @@ function buildOrphanRolloutPlan(db, codexHome, args) {
1210
1221
  unindexed_size_mib: fileMoveListSizeMib(unindexed),
1211
1222
  skipped_files: skipped.length,
1212
1223
  skipped_recent_files: skipped.filter((move) => move.reason === "recent").length,
1224
+ skipped_protected_files: skipped.filter((move) => move.reason === "protected").length,
1213
1225
  skipped_session_indexed_files: skipped.filter((move) => move.reason === "session-indexed").length,
1214
1226
  skipped_destination_exists_files: skipped.filter((move) => move.reason === "destination-exists").length,
1215
1227
  oldest_candidate_modified_utc: millisToIso(minNumberOrNull(modifiedValues)),
@@ -2238,6 +2250,7 @@ function printOrphanRolloutArchiveCandidate(title, value) {
2238
2250
  "unindexed_files",
2239
2251
  "empty_dir_candidates",
2240
2252
  "skipped_recent_files",
2253
+ "skipped_protected_files",
2241
2254
  "skipped_session_indexed_files",
2242
2255
  "skipped_destination_exists_files",
2243
2256
  "oldest_candidate_modified_utc",
package/dist/wizard.js CHANGED
@@ -252,6 +252,9 @@ function printDryRunSummary(report) {
252
252
  if (Number(orphanRollouts.skipped_recent_files) > 0) {
253
253
  console.log(pc.yellow(` Skipped ${String(orphanRollouts.skipped_recent_files)} orphan rollouts inside the recent window.`));
254
254
  }
255
+ if (Number(orphanRollouts.skipped_protected_files) > 0) {
256
+ console.log(pc.yellow(` Skipped ${String(orphanRollouts.skipped_protected_files)} protected orphan rollouts.`));
257
+ }
255
258
  if (Number(orphanRollouts.skipped_session_indexed_files) > 0) {
256
259
  console.log(pc.yellow(` Skipped ${String(orphanRollouts.skipped_session_indexed_files)} DB-orphaned rollouts still present in session_index.jsonl.`));
257
260
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-cleaner",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Guarded cleanup and compaction utility for local Codex state.",
5
5
  "license": "MIT",
6
6
  "type": "module",