From 57f48e63c8ed512a747a3d748fe9fe854cce6017 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Date: Sun, 29 Nov 2026 15:01:08 +0100 Subject: [PATCH 1/2] fix(projects): the deletion dialog no longer says all linked worktree history is kept (#1374) Worktree sessions in recognised layouts are grouped under the repository and are discarded or archived with it; only independently owned worktree history is kept. The theme fixture hash follows the sidebar.js text change. --- .ai/contexts/project-delete.md | 31 ++++++++ CHANGELOG.md | 1 + docs/settings.md | 4 +- public/sidebar.js | 2 +- test/dom-project-delete-history.test.js | 94 +++++++++++++++++++++++++ test/fixtures/theme-dark.json | 2 +- 6 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 test/dom-project-delete-history.test.js diff --git a/.ai/contexts/project-delete.md b/.ai/contexts/project-delete.md index 96f3bfc9c..6a1209fb3 100644 --- a/.ai/contexts/project-delete.md +++ b/.ai/contexts/project-delete.md @@ -59,6 +59,37 @@ DIRECTORY_SCAN_MS. Numeric limits below are code bounds, not measured latency. grouped scope, foreign rejection, metadata/search deletion, changing ownership, producer fences, legacy receipts and remote identity. Physical folder/transcript removal is separate. +## Deletion dialog and worktree history + +- `main.js` wires `createProjectDeleteMain`; `preload.js` sends `preview-project-delete`. + The IPC registration delegates to the guarded service, which returns the planner result and + a document-bound token after checking the writer scope. The renderer uses that plan for + capabilities, choices and expandable details; changing a checkbox requests a fresh plan. +- `confirmAndDeleteProjectFolder` shows the same explanatory message whenever a capabilities + plan opens the dialog, including refused plans shown with Confirm disabled. There is no + message branch for discard/archive, Git worktree inventory, or physical folder selection. + A failure without a plan never opens this choice dialog. +- The message says: "Worktree session metadata grouped under this project is discarded or + archived with it. Independently owned worktree history is kept in Switchboard." This is + conditional on ownership, so it also applies to empty projects and missing Git inventory. + Checking Discard erases selected session metadata; leaving it unchecked archives that + metadata. Both paths remove selected cache/search rows. Physical folder selection does + not change which metadata is selected. +- Local inventory groups the recognised `.worktrees`, `.claude-worktrees`, `.claude/worktrees` + and `.work-files/worktrees` layouts when an ancestor repository exists, including nested + layouts with missing intermediate worktrees. Such groups enter the planner as selected, + even without Git worktree rows. Outside these layouts, independently owned histories stay + outside the project manifest; a verified group with a distinct owner and matching + `parentProjectPath` is labelled kept. Remote ownership remains exact host/path. +- The other message sentences retain their scope: project/main folders and remote server + files stay; selected linked folders lose all contents; "Other transcripts, schedules, + memory and .work-files" excludes those contents. Kept schedules may reactivate and retained + transcripts may restore titles on re-add. +- `test/dom-project-delete-history.test.js` checks visible prose outside JSON details against real + planner previews for both metadata choices and selected/unselected folders, with grouped, + independently owned and absent histories. Discovery ports and the IPC transport are fixtures; + this is not an Electron or filesystem-removal test. + ## Superseded previews (#1106) - One pending preview per webContents/canonical host-project pair: replacement aborts diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f53c9819..2a612b789 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ What changes for you in each release of Switchboard. How to write an entry: [doc - Quit and window close no longer ask for confirmation when only idle Claude sessions are open, startup restore is enabled and Switchboard tracks no running background work; unsaved file edits still ask, and Restart to update keeps its background option. (#1023) ### Fixed +- The project deletion dialog now explains that worktree session metadata grouped under the project is discarded or archived with it, while independently owned worktree history is kept. (#1374) - The **Shell** button opens a shell again for a session whose shell you closed while it was still starting and whose session id then changed, as when a fork is re-keyed; it used to stay unable to open one until the window was reloaded. (#1384) - Forking a Claude session requests the tab’s allocated id and gives its transcript 10 seconds to appear before considering another file. The fallback also handles copied compacted history beyond 8 MiB, within a bounded search; identical foreign forks remain ambiguous after the grace period. (#1350) - Moving a session to the background after choosing **Stop the old job** now waits for evidence that the old job ended. If the worker is still running at the deadline, the session stays in the foreground; if its end cannot be confirmed, Switchboard explains that uncertainty. (#1340) diff --git a/docs/settings.md b/docs/settings.md index 1bf15217b..7e45571e9 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -284,7 +284,9 @@ includes its host alias; unarchiving it does not register a local schedule. **Delete Project** opens the same preview as **Delete** on the project header. Choose whether to discard session names, pins and app metadata (initially off) and project settings (initially on when available). Unselected session metadata -is archived. Shared path-only settings cannot be deleted. Only confirmed, +is archived. Worktree session metadata grouped under the project follows that +choice too, whether or not you remove the worktree folder. Independently owned +worktree history is kept in Switchboard. Shared path-only settings cannot be deleted. Only confirmed, available choices are remembered; Cancel changes nothing. The preview shows the full host and path, counts, and expandable complete diff --git a/public/sidebar.js b/public/sidebar.js index c0fe6bf20..645f5b68b 100644 --- a/public/sidebar.js +++ b/public/sidebar.js @@ -1238,7 +1238,7 @@ async function confirmAndDeleteProjectFolder(project, button, { onUnavailable, o message: [`${project.remoteAlias || 'Local'} — ${capabilities.plan.project.projectPath}`, 'Choose which app data to discard. Retained session metadata is archived.', 'Kept on disk: the project folder. Only individually selected linked worktree folders are removed, including their ignored files. All remote server files are kept.', - 'Other transcripts, schedules, memory and .work-files stay on disk. Linked worktree history is kept in Switchboard.', + 'Other transcripts, schedules, memory and .work-files stay on disk. Worktree session metadata grouped under this project is discarded or archived with it. Independently owned worktree history is kept in Switchboard.', 'Kept schedules may reactivate when you add the project again. Retained transcripts may restore their titles.', ...(capabilities.plan.warnings || []).filter(row => row.code === 'WORKTREE_UNAVAILABLE').map(row => 'Worktree inventory unavailable: ' + row.error)], choices: [ diff --git a/test/dom-project-delete-history.test.js b/test/dom-project-delete-history.test.js new file mode 100644 index 000000000..1ac705c9d --- /dev/null +++ b/test/dom-project-delete-history.test.js @@ -0,0 +1,94 @@ +'use strict'; +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const { setupSidebarDom, makeSampleProject } = require('./dom-setup'); +const flush = () => new Promise(resolve => setImmediate(resolve)); + +function setup(t) { + const ctx = setupSidebarDom(); + t.after(() => ctx.destroy()); + ctx.evalPublic('setting-defaults.js'); + const w = ctx.window, p = makeSampleProject({ folder: 'repo' }); + w.api.platform = 'win32'; + w.cachedAllProjects = w.cachedProjects = [p]; + const calls = { preview: [] }; + return { ...ctx, w, p, calls, + start: () => w.confirmAndDeleteProjectFolder(p), + confirm: () => ctx.document.querySelector('.choice-dialog-confirm'), + cancel: () => ctx.document.querySelector('.choice-dialog-cancel')?.click(), + }; +} + +for (const layout of ['.worktrees', '.claude-worktrees', '.claude/worktrees', '.work-files/worktrees', 'external', 'independent-child', 'none', 'grouped-without-git-row']) { + for (const discard of [false, true]) test(`project deletion explains worktree history: ${layout}, discard=${discard}`, async t => { + const { createProjectDeletePlanner } = require('../src/main/projects/project-delete-plan'); + const { groupedOwner } = require('../src/main/projects/project-delete-owner'); + const dir = fs.realpathSync(fs.mkdtempSync(path.join(require('node:os').tmpdir(), 'delete-wording-'))); + t.after(() => fs.rmSync(dir, { recursive: true, force: true })); + const repo = path.join(dir, 'repo'); + fs.mkdirSync(repo); + const h = setup(t); + h.p.projectPath = repo; + const project = groupedOwner({ alias: null, projectPath: repo }); + const grouped = !['external', 'independent-child', 'none'].includes(layout); + const childPath = path.join(grouped ? repo : dir, grouped + ? (layout === 'grouped-without-git-row' ? '.worktrees' : layout) : 'separate', 'child'); + const child = groupedOwner({ alias: null, projectPath: childPath }); + const group = (owner, id) => ({ ...owner, folderKey: id, runtime: 'claude', verified: true }); + const member = (owner, id) => ({ ...owner, id, conversationId: id, partId: id, folderKey: id, + runtime: 'claude', cwd: owner.projectPath, verified: true, indexed: true, present: true, + liveness: { state: 'stopped', source: 'descriptor' } }); + const groups = [group(project, h.p.folder)]; + const members = [member(project, h.p.folder)]; + if (layout !== 'none') { + groups.push({ ...group(child, 'child'), ...(layout === 'independent-child' ? { parentProjectPath: repo } : {}) }); + members.push(member(child, 'child')); + } + const worktrees = ['none', 'grouped-without-git-row'].includes(layout) ? [] + : [{ path: childPath, branch: 'topic', removable: true, fingerprint: 'disk', sessions: [], dirty: [] }]; + const planner = createProjectDeletePlanner({ + waitForIndex: async () => {}, + readSnapshot: async () => ({ complete: true, initialScanComplete: true, revision: '1', declaredHosts: [], + projects: [{ ...project, folderKeys: [h.p.folder] }] }), + discoverOwnership: async () => ({ complete: true, groups, members, candidates: [] }), + discoverSchedules: async () => ({ complete: true, schedules: [], candidates: [] }), + readRuntimeState: async () => ({ complete: true, tabs: [], jobs: [], candidates: [] }), + readRevision: async () => '1', + worktrees: { preview: async () => worktrees }, + }); + let lastPlan; + h.w.api.previewProjectDelete = async request => { + h.calls.preview.push(request); + const reply = await planner.preview(JSON.parse(JSON.stringify(request))); + lastPlan = reply.plan; + return { ...reply, token: 'wording-preview' }; + }; + h.w.localStorage.setItem('deleteProject.sessions', discard ? '1' : '0'); + const pending = h.start(); + try { + for (let i = 0; i < 100 && (!h.confirm() || h.confirm().disabled); i++) await flush(); + assert.ok(h.confirm() && !h.confirm().disabled, 'the real planner must produce a confirmable dialog: ' + h.document.body.textContent); + assert.equal(lastPlan.categories.sessions.effect, discard ? 'discard' : 'archive'); + assert.equal(lastPlan.members.some(row => row.id === 'child'), grouped); + if (layout === 'independent-child') assert.equal(lastPlan.groups.find(row => row.folderKey === 'child').effect, 'kept'); + for (const selected of worktrees.length ? [false, true] : [false]) { + if (selected) { + h.document.querySelector('[data-choice-id="worktree:0"]').click(); + for (let i = 0; i < 100 && h.confirm().disabled; i++) await flush(); + assert.equal(h.confirm().disabled, false); + assert.equal(lastPlan.worktrees[0].selected, true); + assert.equal(lastPlan.members.some(row => row.id === 'child'), grouped, 'disk selection does not select metadata'); + } + const dialog = h.document.querySelector('.choice-dialog').cloneNode(true); + dialog.querySelectorAll('details').forEach(node => node.remove()); + assert.match(dialog.textContent, /Worktree session metadata grouped under this project is discarded or archived with it\./, + 'visible wording must explain that grouped worktree metadata follows the project choice'); + assert.match(dialog.textContent, /Independently owned worktree history is kept in Switchboard\./); + assert.doesNotMatch(dialog.textContent, /Linked worktree history is kept in Switchboard\./); + assert.match(dialog.textContent, /Other transcripts, schedules, memory and \.work-files stay on disk\./); + } + } finally { h.cancel(); await pending; } + }); +} diff --git a/test/fixtures/theme-dark.json b/test/fixtures/theme-dark.json index 1d8406b45..c1912bc39 100644 --- a/test/fixtures/theme-dark.json +++ b/test/fixtures/theme-dark.json @@ -25,7 +25,7 @@ }, "cssHash": "c1180992aaefa3142b645b1441a6d827be5874ac6da33af2c703713e7715f39a", "inline": { - "sidebar.js": "2a6e5970804b3b476808185da71d1ea57c85882e34e37bf9f0a2a6d15c87f491", + "sidebar.js": "b04a503b6c8ef6d41ef492ff9595a2c3e83258f907defa20a9863c8172338e67", "jsonl-viewer.js": "d74bf42a3c33ba87b8f4cf9441df0814380890a6ca0c239f3479207f36c73e2a", "viewer-toolbar.js": "a8a83a1c55716a17a5b53defbdb7b28344e0796096b5e738b9d1cdea1113cca6" } From 8732db327b80bf891923b80d8dc488b1b806e4af Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Date: Sun, 29 Nov 2026 15:06:43 +0100 Subject: [PATCH 2/2] docs(projects): tighten the deletion-dialog context and correct the ancestor check (#1374) --- .ai/contexts/project-delete.md | 46 +++++++++++++--------------------- docs/settings.md | 5 ++-- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/.ai/contexts/project-delete.md b/.ai/contexts/project-delete.md index 6a1209fb3..0193c08ef 100644 --- a/.ai/contexts/project-delete.md +++ b/.ai/contexts/project-delete.md @@ -61,34 +61,24 @@ DIRECTORY_SCAN_MS. Numeric limits below are code bounds, not measured latency. ## Deletion dialog and worktree history -- `main.js` wires `createProjectDeleteMain`; `preload.js` sends `preview-project-delete`. - The IPC registration delegates to the guarded service, which returns the planner result and - a document-bound token after checking the writer scope. The renderer uses that plan for - capabilities, choices and expandable details; changing a checkbox requests a fresh plan. -- `confirmAndDeleteProjectFolder` shows the same explanatory message whenever a capabilities - plan opens the dialog, including refused plans shown with Confirm disabled. There is no - message branch for discard/archive, Git worktree inventory, or physical folder selection. - A failure without a plan never opens this choice dialog. -- The message says: "Worktree session metadata grouped under this project is discarded or - archived with it. Independently owned worktree history is kept in Switchboard." This is - conditional on ownership, so it also applies to empty projects and missing Git inventory. - Checking Discard erases selected session metadata; leaving it unchecked archives that - metadata. Both paths remove selected cache/search rows. Physical folder selection does - not change which metadata is selected. -- Local inventory groups the recognised `.worktrees`, `.claude-worktrees`, `.claude/worktrees` - and `.work-files/worktrees` layouts when an ancestor repository exists, including nested - layouts with missing intermediate worktrees. Such groups enter the planner as selected, - even without Git worktree rows. Outside these layouts, independently owned histories stay - outside the project manifest; a verified group with a distinct owner and matching - `parentProjectPath` is labelled kept. Remote ownership remains exact host/path. -- The other message sentences retain their scope: project/main folders and remote server - files stay; selected linked folders lose all contents; "Other transcripts, schedules, - memory and .work-files" excludes those contents. Kept schedules may reactivate and retained - transcripts may restore titles on re-add. -- `test/dom-project-delete-history.test.js` checks visible prose outside JSON details against real - planner previews for both metadata choices and selected/unselected folders, with grouped, - independently owned and absent histories. Discovery ports and the IPC transport are fixtures; - this is not an Electron or filesystem-removal test. +- `confirmAndDeleteProjectFolder` shows one explanatory message whenever a capabilities plan + opens the dialog, refused plans included (Confirm disabled); a failure without a plan never + opens it. The message has no branch for discard/archive, Git worktree inventory or folder + selection, so its worktree sentence is conditional on ownership: "Worktree session metadata + grouped under this project is discarded or archived with it. Independently owned worktree + history is kept in Switchboard." Changing a checkbox requests a fresh plan. +- Delete ownership (distinct from the visibility rules above): local inventory groups the + `.worktrees`, `.claude-worktrees`, `.claude/worktrees` and `.work-files/worktrees` layouts + under the project when the ancestor directory exists (`resolveWorktreePath` checks only that + the directory exists, not that it is a Git repository), nested layouts with missing + intermediate worktrees included. Such groups are selected even without Git worktree rows; + Discard erases their session metadata, leaving it unchecked archives it, and the disk-folder + choice does not change which metadata is selected. A verified group with a distinct owner and + a matching `parentProjectPath` is `kept` and gets no writer units; histories outside these + layouts stay outside the manifest. Remote ownership is exact host/path. +- Tests: test/dom-project-delete-history.test.js checks the visible prose against real planner + previews (both metadata choices, selected/unselected folders, grouped, independently owned + and absent histories); discovery ports and IPC transport are fixtures. ## Superseded previews (#1106) diff --git a/docs/settings.md b/docs/settings.md index 7e45571e9..e6a40d9ae 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -286,8 +286,9 @@ Choose whether to discard session names, pins and app metadata (initially off) and project settings (initially on when available). Unselected session metadata is archived. Worktree session metadata grouped under the project follows that choice too, whether or not you remove the worktree folder. Independently owned -worktree history is kept in Switchboard. Shared path-only settings cannot be deleted. Only confirmed, -available choices are remembered; Cancel changes nothing. +worktree history is kept in Switchboard. Shared path-only settings cannot be +deleted. Only confirmed, available choices are remembered; Cancel changes +nothing. The preview shows the full host and path, counts, and expandable complete targets and effects. Project files, schedules, memory and `.work-files` stay on