Skip to content

Commit 85466c4

Browse files
fix: make snapshot prune interval configurable via snapshotPruneDays
- Add configurable snapshotPruneDays option (1-30 days, default: 7) - Read from user config before using hardcoded 7-day default - Helps prevent massive disk usage by allowing shorter retention periods Fixes anomalyco#17397
1 parent f54abe5 commit 85466c4

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

‎packages/opencode/src/config/config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,7 @@ export namespace Config {
10531053
.optional(),
10541054
plugin: z.string().array().optional(),
10551055
snapshot: z.boolean().optional(),
1056+
snapshotPruneDays: z.number().min(1).max(30).optional().describe("Days to keep snapshots before pruning (default: 7)"),
10561057
share: z
10571058
.enum(["manual", "auto", "disabled"])
10581059
.optional()

‎packages/opencode/src/snapshot/index.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Process } from "@/util/process"
1313
export namespace Snapshot {
1414
const log = Log.create({ service: "snapshot" })
1515
const hour = 60 * 60 * 1000
16-
const prune = "7.days"
16+
const defaultPruneDays = 7
1717

1818
function args(git: string, cmd: string[]) {
1919
return ["--git-dir", git, "--work-tree", Instance.worktree, ...cmd]
@@ -38,6 +38,8 @@ export namespace Snapshot {
3838
.then(() => true)
3939
.catch(() => false)
4040
if (!exists) return
41+
const pruneDays = cfg.snapshotPruneDays ?? defaultPruneDays
42+
const prune = `${pruneDays}.days`
4143
const result = await Process.run(["git", ...args(git, ["gc", `--prune=${prune}`])], {
4244
cwd: Instance.directory,
4345
nothrow: true,

0 commit comments

Comments
 (0)