codex-cleaner 0.0.1
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/LICENSE +21 -0
- package/README.md +83 -0
- package/dist/cleaner.d.ts +55 -0
- package/dist/cleaner.js +2265 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +193 -0
- package/dist/types.d.ts +47 -0
- package/dist/types.js +1 -0
- package/dist/wizard.d.ts +2 -0
- package/dist/wizard.js +412 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 codex-cleaner contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# codex-cleaner
|
|
2
|
+
|
|
3
|
+
Guarded local cleanup for bloated Codex state under `~/.codex`.
|
|
4
|
+
|
|
5
|
+
```powershell
|
|
6
|
+
npx codex-cleaner@latest
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The default TUI always dry-runs first, then offers one apply step after Codex is fully closed.
|
|
10
|
+
It starts with recommended settings, or you can customize each setting.
|
|
11
|
+
|
|
12
|
+
Current cleanup:
|
|
13
|
+
|
|
14
|
+
- archives stale unpinned threads through Codex's own app-server API
|
|
15
|
+
- moves old DB-unreferenced rollout JSONL from `sessions` to `archived_sessions`
|
|
16
|
+
- caps huge old `threads.title`, `threads.preview`, and `threads.first_user_message` values
|
|
17
|
+
- optionally caps recent unprotected metadata too
|
|
18
|
+
- vacuums `state_5.sqlite`
|
|
19
|
+
- optionally prunes/caps and vacuums `logs_2.sqlite`
|
|
20
|
+
- optionally backs up and trims `log/codex-tui.log`
|
|
21
|
+
- checkpoints/truncates `state_5.sqlite-wal`
|
|
22
|
+
- scans, prunes, or schedules pruning for old cleaner backups
|
|
23
|
+
|
|
24
|
+
Noninteractive dry-run:
|
|
25
|
+
|
|
26
|
+
```powershell
|
|
27
|
+
npx codex-cleaner@latest --allow-running-readonly clean --max-chars 1024 --keep-recent-days 14 --archive-orphan-rollouts --compact-recent-metadata --prune-logs --prune-tui-log
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Noninteractive apply:
|
|
31
|
+
|
|
32
|
+
```powershell
|
|
33
|
+
npx codex-cleaner@latest clean --max-chars 1024 --keep-recent-days 14 --archive-orphan-rollouts --compact-recent-metadata --prune-logs --prune-tui-log --apply --confirm-lossy-metadata --confirm-archive-stale --confirm-archive-orphan-rollouts --confirm-prune-logs --confirm-prune-tui-log
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Backup cleanup:
|
|
37
|
+
|
|
38
|
+
```powershell
|
|
39
|
+
npx codex-cleaner@latest backups scan
|
|
40
|
+
npx codex-cleaner@latest backups prune --older-than-hours 48
|
|
41
|
+
npx codex-cleaner@latest backups prune --older-than-hours 48 --apply --confirm-delete-backups
|
|
42
|
+
npx codex-cleaner@latest backups schedule-prune --after-hours 48 --apply --confirm-schedule-backup-prune
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
File-only active-session cleanup:
|
|
46
|
+
|
|
47
|
+
```powershell
|
|
48
|
+
npx codex-cleaner@latest archive-orphan-rollouts --allow-running-orphan-rollout-archive --keep-recent-days 14 --apply --confirm-archive-orphan-rollouts
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Safety basics:
|
|
52
|
+
|
|
53
|
+
- dry-run by default
|
|
54
|
+
- apply refuses to run while Codex processes are active
|
|
55
|
+
- pinned, heartbeat/open, and active-goal threads are always protected
|
|
56
|
+
- recent threads are protected unless `--compact-recent-metadata` is passed
|
|
57
|
+
- rollout JSONL is retained; old DB-orphaned files may be moved out of active `sessions`
|
|
58
|
+
- `archive-orphan-rollouts` reads SQLite but only moves JSONL files and removes empty dirs
|
|
59
|
+
- backups are created in `~/.codex/.codex-cleanup-backups` before mutation
|
|
60
|
+
- after Codex looks right, delete old backups to reclaim disk
|
|
61
|
+
- backup pruning is dry-run unless `--apply --confirm-delete-backups` is passed
|
|
62
|
+
|
|
63
|
+
## Dev
|
|
64
|
+
|
|
65
|
+
```powershell
|
|
66
|
+
npm install
|
|
67
|
+
npm run check
|
|
68
|
+
npm pack --dry-run
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Local dogfood:
|
|
72
|
+
|
|
73
|
+
```powershell
|
|
74
|
+
npm run build
|
|
75
|
+
node .\dist\cli.js
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Active-session file-only cleanup:
|
|
79
|
+
|
|
80
|
+
```powershell
|
|
81
|
+
node .\dist\cli.js --allow-running-readonly archive-orphan-rollouts --keep-recent-days 14
|
|
82
|
+
node .\dist\cli.js archive-orphan-rollouts --allow-running-orphan-rollout-archive --keep-recent-days 14 --apply --confirm-archive-orphan-rollouts
|
|
83
|
+
```
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import Database from "better-sqlite3";
|
|
3
|
+
import type { BlockingProcess, CleanerOptions, CompactWhere } from "./types.js";
|
|
4
|
+
type CodexSpawnCommand = {
|
|
5
|
+
args: string[];
|
|
6
|
+
command: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function requireStoppedOrReadonlyAllowed(args: {
|
|
9
|
+
allowRunningReadonly: boolean;
|
|
10
|
+
mutating: boolean;
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
export declare function findBlockingProcesses(): Promise<BlockingProcess[]>;
|
|
13
|
+
export declare function resolveCodexSpawnCommand(codexCommand: string, args: string[], platform?: NodeJS.Platform, windowsMatches?: string[]): Promise<CodexSpawnCommand>;
|
|
14
|
+
export declare function buildScanReport(options: CleanerOptions): Record<string, unknown>;
|
|
15
|
+
export declare function compactMetadata(options: CleanerOptions): Promise<Record<string, unknown>>;
|
|
16
|
+
export declare function cleanCodex(options: CleanerOptions): Promise<Record<string, unknown>>;
|
|
17
|
+
export declare function archiveStaleThreads(options: CleanerOptions): Promise<Record<string, unknown>>;
|
|
18
|
+
export declare function archiveOrphanRollouts(options: CleanerOptions): Record<string, unknown>;
|
|
19
|
+
export declare function checkpointWal(options: CleanerOptions, backupBeforeCheckpoint?: boolean): Promise<Record<string, unknown>>;
|
|
20
|
+
export declare function vacuumStateDatabase(options: CleanerOptions, backupBeforeVacuum?: boolean): Promise<Record<string, unknown>>;
|
|
21
|
+
export declare function cleanLogs(options: CleanerOptions): Promise<Record<string, unknown>>;
|
|
22
|
+
export declare function cleanTuiLog(options: CleanerOptions): Promise<Record<string, unknown>>;
|
|
23
|
+
export declare function scanBackups(options: CleanerOptions): Record<string, unknown>;
|
|
24
|
+
export declare function pruneBackups(options: CleanerOptions): Record<string, unknown>;
|
|
25
|
+
export declare function scheduleBackupPrune(options: CleanerOptions): Promise<Record<string, unknown>>;
|
|
26
|
+
export declare function compactWhere(args: {
|
|
27
|
+
archivedOnly: boolean;
|
|
28
|
+
cutoffMs: number;
|
|
29
|
+
maxChars: number;
|
|
30
|
+
protectRecent: boolean;
|
|
31
|
+
protectedIds: Set<string>;
|
|
32
|
+
}): CompactWhere;
|
|
33
|
+
export declare function collectCompactCandidateStats(db: Database.Database, args: {
|
|
34
|
+
archivedOnly: boolean;
|
|
35
|
+
cutoffMs: number;
|
|
36
|
+
maxChars: number;
|
|
37
|
+
protectRecent: boolean;
|
|
38
|
+
protectedIds: Set<string>;
|
|
39
|
+
}): Record<string, unknown>;
|
|
40
|
+
export declare function collectStaleArchiveCandidateStats(db: Database.Database, codexHome: string, args: {
|
|
41
|
+
cutoffMs: number;
|
|
42
|
+
protectedIds: Set<string>;
|
|
43
|
+
statRollouts?: boolean;
|
|
44
|
+
}): Record<string, unknown>;
|
|
45
|
+
export declare function collectLogCleanupStats(db: Database.Database, options: CleanerOptions): Record<string, unknown>;
|
|
46
|
+
export declare function collectTuiLogCleanupStats(logPath: string, keepMib: number): Record<string, unknown>;
|
|
47
|
+
export declare function collectOrphanRolloutArchiveStats(db: Database.Database, codexHome: string, args: {
|
|
48
|
+
cutoffMs: number;
|
|
49
|
+
}): Record<string, unknown>;
|
|
50
|
+
export declare function nextBackupPath(dbPath: string, backupDir: string, now?: Date): string;
|
|
51
|
+
export declare function nextFileBackupPath(filePath: string, backupDir: string, now?: Date): string;
|
|
52
|
+
export declare function truncateFileToTail(filePath: string, keepBytes: number): void;
|
|
53
|
+
export declare function rolloutThreadId(file: string | path.ParsedPath): string | null;
|
|
54
|
+
export declare function emitReport(report: Record<string, unknown>, asJson: boolean): void;
|
|
55
|
+
export {};
|