Skip to content

Commit bc95ac1

Browse files
SunkenInTimeclaude
andcommitted
refactor(settings): keep disposable ignored paths machine-wide
A project's custom worktree rules are replaced whole on every edit, so a client that predates the list dropped a project's own list and fell back to the machine's, which could make more ignored files deletable. The list now lives only in storageCleanup. A project that must keep its ignored files can turn its worktree cleanup off. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 5a77206 commit bc95ac1

9 files changed

Lines changed: 32 additions & 103 deletions

File tree

‎apps/server/src/storageCleanup.ts‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ export const make = Effect.gen(function* () {
238238
) {
239239
if (!anyWorktreePolicy(serverSettings, worktreeCleanupEnabled)) return;
240240
if (!(yield* fs.exists(config.worktreesDir))) return;
241+
const disposablePaths = serverSettings.storageCleanup.worktreeDisposablePaths;
241242
const hasDeleteRule = anyWorktreePolicy(serverSettings, (rules) => rules.worktreeOnDelete);
242243
const deletedRows = hasDeleteRule
243244
? yield* sql<{ payload_json: string; workspaceRoot: string }>`
@@ -292,7 +293,7 @@ export const make = Effect.gen(function* () {
292293
if (!status.isRepo || status.branch !== thread.branch || status.hasWorkingTreeChanges)
293294
return;
294295
const head = yield* git.resolveCommit({ cwd: worktreePath, revision: "HEAD" });
295-
if (yield* keepsIgnoredFiles(worktreePath, settings.worktreeDisposablePaths)) return;
296+
if (yield* keepsIgnoredFiles(worktreePath, disposablePaths)) return;
296297
const old =
297298
!deleted &&
298299
settings.worktreeAfterDays !== null &&
@@ -392,12 +393,17 @@ export const make = Effect.gen(function* () {
392393
head.commitSha
393394
)
394395
return;
395-
if (yield* keepsIgnoredFiles(worktreePath, settings.worktreeDisposablePaths)) return;
396-
const current = resolveWorktreeCleanup(
397-
yield* settingsService.getSettings,
398-
thread.projectId,
399-
);
400-
if (!Equal.equals(current, settings)) return;
396+
if (yield* keepsIgnoredFiles(worktreePath, disposablePaths)) return;
397+
const latestSettings = yield* settingsService.getSettings;
398+
const current = resolveWorktreeCleanup(latestSettings, thread.projectId);
399+
if (
400+
Object.keys(settings).some(
401+
(key) =>
402+
current[key as keyof typeof settings] !== settings[key as keyof typeof settings],
403+
) ||
404+
!Equal.equals(latestSettings.storageCleanup.worktreeDisposablePaths, disposablePaths)
405+
)
406+
return;
401407
yield* git.removeWorktree({ cwd: project.workspaceRoot, path: worktreePath, force: false });
402408
yield* gitManager.invalidateStatus(project.workspaceRoot);
403409
// Preserve branch and path: ProviderTurnStartService recreates the checkout

‎apps/web/src/components/settings/StorageSettings.tsx‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,13 @@ export function StorageSettingsPanel() {
118118
isProjectScope
119119
? updateSettings({ worktreeCleanup: { mode: "custom", rules: patch } })
120120
: update(patch);
121-
const disposablePathsSupported = connectedEnvironments.every(
122-
(environment) =>
123-
environment.serverConfig?.environment.capabilities.worktreeDisposablePaths === true,
124-
);
121+
// Machine-wide only: a project's custom rules can't carry the list.
122+
const showDisposablePaths =
123+
!isProjectScope &&
124+
connectedEnvironments.every(
125+
(environment) =>
126+
environment.serverConfig?.environment.capabilities.worktreeDisposablePaths === true,
127+
);
125128
const disposablePathsStatus = ruleStatus("worktreeDisposablePaths");
126129
const disposablePathsEdited = useRef(false);
127130
const disposablePathsText = settings.worktreeDisposablePaths.join("\n");
@@ -262,12 +265,12 @@ export function StorageSettingsPanel() {
262265
/>
263266
}
264267
/>
265-
{disposablePathsSupported && (
268+
{showDisposablePaths && (
266269
<SettingsRow
267270
title="Disposable ignored paths"
268271
status={disposablePathsStatus}
269272
description="Ignored files keep a worktree because they can hold secrets or local data. List .gitignore patterns that are safe to delete, one per line. Ignored symlinks and junctions never keep a worktree."
270-
serverScoped={!isProjectScope}
273+
serverScoped
271274
>
272275
<div className="mt-3 max-w-2xl pb-3.5">
273276
<Textarea
@@ -295,7 +298,7 @@ export function StorageSettingsPanel() {
295298
(disposablePathsStatus ||
296299
!Equal.equals(worktreeDisposablePaths, settings.worktreeDisposablePaths))
297300
)
298-
updateWorktree({ worktreeDisposablePaths });
301+
update({ worktreeDisposablePaths });
299302
disposablePathsEdited.current = false;
300303
}}
301304
/>

‎apps/web/src/components/settings/scopedSettings.test.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ describe("scoped settings writes", () => {
158158
worktreeOnDelete: true,
159159
worktreeOnMerge: true,
160160
worktreeUnchanged: false,
161-
worktreeDisposablePaths: ["build/"],
162161
},
163162
},
164163
},
@@ -182,14 +181,12 @@ describe("scoped settings writes", () => {
182181
worktreeOnDelete: false,
183182
worktreeOnMerge: true,
184183
worktreeUnchanged: false,
185-
worktreeDisposablePaths: ["build/"],
186184
},
187185
{
188186
worktreeAfterDays: null,
189187
worktreeOnDelete: false,
190188
worktreeOnMerge: false,
191189
worktreeUnchanged: false,
192-
worktreeDisposablePaths: ["node_modules/"],
193190
},
194191
]);
195192
});
@@ -296,7 +293,6 @@ describe("scoped settings writes", () => {
296293
worktreeOnDelete: false,
297294
worktreeOnMerge: true,
298295
worktreeUnchanged: false,
299-
worktreeDisposablePaths: ["build/"],
300296
},
301297
},
302298
},
@@ -317,7 +313,6 @@ describe("scoped settings writes", () => {
317313
worktreeOnDelete: true,
318314
worktreeOnMerge: true,
319315
worktreeUnchanged: false,
320-
worktreeDisposablePaths: ["build/"],
321316
},
322317
},
323318
},
@@ -331,7 +326,6 @@ describe("scoped settings writes", () => {
331326
worktreeOnDelete: true,
332327
worktreeOnMerge: false,
333328
worktreeUnchanged: false,
334-
worktreeDisposablePaths: ["node_modules/"],
335329
},
336330
},
337331
},

‎docs/user/project-settings.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ hourly. Offline machines keep their existing policies.
9696
Select a project to set **Automatic worktree cleanup** to **Inherit**, **Off**, or **Custom**.
9797
Inherit follows each machine's rules; Off keeps that project's worktrees until you remove them
9898
manually. Custom applies separate worktree rules to the selected project or checkout. Browser
99-
captures and log retention remain machine-wide.
99+
captures, log retention and disposable ignored paths remain machine-wide.
100100

101101
Worktrees can be removed after a chosen number of inactive days, after merging, or when they
102102
have no commits beyond the default branch. Only T3-managed worktrees are eligible. Active
103103
sessions, shared worktrees, uncommitted changes, and ignored files prevent removal, because
104104
ignored files can hold secrets or local data. Ignored symlinks and junctions don't count, and
105105
neither do paths listed under **Disposable ignored paths**, which uses `.gitignore` patterns and
106-
starts with `node_modules/`. Add build output such as `build/` and `.dart_tool/` there, per
107-
project if needed.
106+
starts with `node_modules/`. Add build output such as `build/` and `.dart_tool/` there. Patterns
107+
only match ignored paths, so a project without that folder is unaffected.
108108
Branches and thread history stay; starting another turn recreates the checkout.
109109
Merge cleanup requires the commits to be included in the remote default branch, so squash merges
110110
may need the inactivity rule instead.

‎packages/contracts/src/settings.test.ts‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,6 @@ describe("storage cleanup settings", () => {
6262
});
6363
});
6464

65-
it("keeps stored custom worktree rules without disposable paths", () => {
66-
expect(
67-
decodeServerSettings({
68-
worktreeCleanup: {
69-
mode: "custom",
70-
rules: {
71-
worktreeAfterDays: 3,
72-
worktreeOnMerge: false,
73-
worktreeOnDelete: true,
74-
worktreeUnchanged: false,
75-
},
76-
},
77-
}).worktreeCleanup,
78-
).toEqual({
79-
mode: "custom",
80-
rules: {
81-
worktreeAfterDays: 3,
82-
worktreeOnMerge: false,
83-
worktreeOnDelete: true,
84-
worktreeUnchanged: false,
85-
},
86-
});
87-
});
88-
8965
it("accepts eight-day retention and disabling one rule without resetting others", () => {
9066
expect(decodeServerSettingsPatch({ storageCleanup: { worktreeAfterDays: 8 } })).toEqual({
9167
storageCleanup: { worktreeAfterDays: 8 },

‎packages/contracts/src/settings.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,8 +1102,6 @@ export const WorktreeCleanupRules = Schema.Struct({
11021102
worktreeOnMerge: Schema.Boolean,
11031103
worktreeOnDelete: Schema.Boolean,
11041104
worktreeUnchanged: Schema.Boolean,
1105-
/** Absent in rules saved before this key existed; the machine's list applies. */
1106-
worktreeDisposablePaths: Schema.optionalKey(WorktreeDisposablePaths),
11071105
});
11081106
export type WorktreeCleanupRules = typeof WorktreeCleanupRules.Type;
11091107

@@ -1597,7 +1595,6 @@ export const ServerSettingsPatch = Schema.Struct({
15971595
worktreeOnMerge: Schema.optionalKey(Schema.Boolean),
15981596
worktreeOnDelete: Schema.optionalKey(Schema.Boolean),
15991597
worktreeUnchanged: Schema.optionalKey(Schema.Boolean),
1600-
worktreeDisposablePaths: Schema.optionalKey(WorktreeDisposablePaths),
16011598
}),
16021599
}),
16031600
]),

‎packages/shared/src/projectSettings.test.ts‎

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ describe("resolveWorktreeCleanup", () => {
326326
worktreeOnDelete: false,
327327
worktreeOnMerge: false,
328328
worktreeUnchanged: false,
329-
worktreeDisposablePaths: ["node_modules/"],
330329
});
331330
expect(resolveWorktreeCleanup(off, otherProjectId)).toEqual(inherited);
332331
const custom = applyServerSettingsPatch(off, {
@@ -347,11 +346,7 @@ describe("resolveWorktreeCleanup", () => {
347346
});
348347
it("completes partial machine custom rules and preserves them across edits", () => {
349348
const initial = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
350-
storageCleanup: {
351-
worktreeAfterDays: 8,
352-
worktreeOnDelete: true,
353-
worktreeDisposablePaths: ["node_modules/", "build/"],
354-
},
349+
storageCleanup: { worktreeAfterDays: 8, worktreeOnDelete: true },
355350
});
356351
const custom = applyServerSettingsPatch(initial, {
357352
worktreeCleanup: { mode: "custom", rules: { worktreeOnMerge: true } },
@@ -364,36 +359,12 @@ describe("resolveWorktreeCleanup", () => {
364359
worktreeOnDelete: true,
365360
worktreeOnMerge: true,
366361
worktreeUnchanged: false,
367-
worktreeDisposablePaths: ["node_modules/", "build/"],
368362
});
369363
expect(
370364
resolveWorktreeCleanup(applyServerSettingsPatch(edited, { worktreeCleanup: null }), null)
371365
.worktreeAfterDays,
372366
).toBe(8);
373367
});
374-
it("uses the machine's disposable paths for custom rules saved without them", () => {
375-
const settings = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
376-
storageCleanup: { worktreeDisposablePaths: ["node_modules/", "build/"] },
377-
// Rules written by a client that predates disposable paths.
378-
projectSettingsOverrides: {
379-
[projectId]: {
380-
worktreeCleanup: {
381-
mode: "custom",
382-
rules: {
383-
worktreeAfterDays: 3,
384-
worktreeOnDelete: false,
385-
worktreeOnMerge: false,
386-
worktreeUnchanged: false,
387-
},
388-
},
389-
},
390-
},
391-
});
392-
expect(resolveWorktreeCleanup(settings, projectId).worktreeDisposablePaths).toEqual([
393-
"node_modules/",
394-
"build/",
395-
]);
396-
});
397368
});
398369

399370
it("inherits branch naming defaults and applies project overrides independently", () => {

‎packages/shared/src/projectSettings.ts‎

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -215,34 +215,17 @@ export function clearProjectSettingsOverrides(
215215
export function resolveWorktreeCleanup(
216216
settings: ServerSettings,
217217
projectId: ProjectId | null,
218-
): Required<WorktreeCleanupRules> {
218+
): WorktreeCleanupRules {
219219
const policy = resolveProjectSettings(settings, projectId).settings.worktreeCleanup;
220-
if (policy?.mode === "custom")
221-
return {
222-
...policy.rules,
223-
worktreeDisposablePaths:
224-
policy.rules.worktreeDisposablePaths ?? settings.storageCleanup.worktreeDisposablePaths,
225-
};
220+
if (policy?.mode === "custom") return policy.rules;
226221
if (policy?.mode === "off")
227222
return {
228223
worktreeAfterDays: null,
229224
worktreeOnMerge: false,
230225
worktreeOnDelete: false,
231226
worktreeUnchanged: false,
232-
worktreeDisposablePaths: settings.storageCleanup.worktreeDisposablePaths,
233227
};
234-
const {
235-
worktreeAfterDays,
236-
worktreeOnMerge,
237-
worktreeOnDelete,
238-
worktreeUnchanged,
239-
worktreeDisposablePaths,
240-
} = settings.storageCleanup;
241-
return {
242-
worktreeAfterDays,
243-
worktreeOnMerge,
244-
worktreeOnDelete,
245-
worktreeUnchanged,
246-
worktreeDisposablePaths,
247-
};
228+
const { worktreeAfterDays, worktreeOnMerge, worktreeOnDelete, worktreeUnchanged } =
229+
settings.storageCleanup;
230+
return { worktreeAfterDays, worktreeOnMerge, worktreeOnDelete, worktreeUnchanged };
248231
}

‎packages/shared/src/serverSettings.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ export function applyServerSettingsPatch(
340340
worktreeOnMerge: next.storageCleanup.worktreeOnMerge,
341341
worktreeOnDelete: next.storageCleanup.worktreeOnDelete,
342342
worktreeUnchanged: next.storageCleanup.worktreeUnchanged,
343-
worktreeDisposablePaths: next.storageCleanup.worktreeDisposablePaths,
344343
...(current.worktreeCleanup?.mode === "custom"
345344
? current.worktreeCleanup.rules
346345
: {}),

0 commit comments

Comments
 (0)