Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .ai/contexts/ipc-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ answers still match. Changed answers require a fresh preview. Other callers keep
their existing flow. If a remembered choice is unavailable (shared settings), the
dialog unchecks it and obtains the matching plan; the refused initial plan has no
token. A refusal disables Delete and writes its reason into the row;
`aria-describedby` uses an entry-derived stable ID. Transient refusals (timeout,
NOT_READY or unavailable discovery) explain how to reopen the menu and click
Delete again; reopening only re-enables that explicit action. Detached rows ignore
refusal updates.
`aria-describedby` uses an entry-derived stable ID on both Delete and the row's
summary. Every refusal except the grouped-worktree hint, including thrown IPC
errors, explains how to reopen the menu and click Delete again; reopening only
re-enables that explicit action, with no preview. Detached rows ignore refusal
updates. The shared flow's `onDialogOpen` callback clears the row's checking
message when the dialog opens.
The real inventory groups a local worktree only when its repository exists, so
orphaned entries can be deleted. Only the local worktree hints-conflict refusal
explains in user wording that the entry is grouped under its repository and
Expand All @@ -46,8 +48,11 @@ Parsing uses the shared `parseFolderKey` and `isValidAlias` in
means `/`, matching the writer. Accepted entries call the existing
`confirmAndDeleteProjectFolder`, retaining preview tokens, options,
refusal handling and committed-result semantics. After cancellation or refusal,
the manager unlocks the controls before returning focus to an enabled Delete button;
unlocking keeps refused actions disabled. It never calls
the manager unlocks the controls before returning focus to an enabled Delete button
or, after refusal, the row's summary with its reason. Passing `onUnavailable`
leaves fallback focus to that caller; sidebar and project-settings callers retain
their existing project-header/sidebar fallback. Unlocking keeps refused actions
disabled until the menu reopens. It never calls
Unarchive before Delete. The overflow also copies the full path through
`writeClipboard`. No new IPC or launch code is introduced.

Expand Down
4 changes: 1 addition & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,5 @@ module.exports = [
globals: { ...globals.node },
},
},
{ files: ['public/archived-manager.js'], languageOptions: { globals: { module: 'writable', renderArchivedProjects: 'off',
PROJECT_DELETE_DIALOG_TIMEOUT_MS: 'readonly', projectDeletionPreviewWait: 'readonly',
projectDeletionCall: 'readonly', projectDeletionPlanReason: 'readonly' } } },
{ files: ['public/archived-manager.js'], languageOptions: { globals: { module: 'writable', renderArchivedProjects: 'off' } } },
];
10 changes: 5 additions & 5 deletions public/archived-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ function renderArchivedProjects(container, { entries, kinds = {}, dates = {}, ho
const reason = row.querySelector('.archived-delete-reason');
reason.textContent = 'Checking deletion availability…';
try {
if (await confirmAndDeleteProjectFolder(project, button, { reuseInitialPreview: true, onUnavailable: (reply, message) => {
if (await confirmAndDeleteProjectFolder(project, button, { reuseInitialPreview: true,
onDialogOpen: () => { reason.textContent = ''; }, onUnavailable: (reply, message) => {
if (!row.isConnected) return;
const grouped = reply?.code === 'IDENTITY_UNAVAILABLE' && reply.error === 'Folder and path hints conflict.'
&& project.remoteAlias === null && worktreeGroupingPath(project.projectPath) !== project.projectPath;
const retryable = reply?.code === 'NOT_READY' || reply?.code === 'DISCOVERY_TIMEOUT' || reply?.code === 'DISCOVERY_UNAVAILABLE'
|| (!reply?.code && /unavailable|timed out/i.test(message));
const retryable = !grouped;
reason.textContent = grouped ? 'This worktree is grouped under its repository. To remove it from Switchboard, delete its repository instead.'
: message.replace(/\s*(?:Close and reopen Delete to retry\.|Retry preview, or cancel\.)/g, '')
+ (retryable ? ' Reopen the menu and click Delete project to try again.' : '');
Expand All @@ -114,7 +114,7 @@ function renderArchivedProjects(container, { entries, kinds = {}, dates = {}, ho
finally {
if (reason.textContent === 'Checking deletion availability…') reason.textContent = '';
lock(false);
if (button.isConnected && !button.disabled) button.focus();
if (button.isConnected) (button.disabled ? row.querySelector('summary') : button).focus();
}
}
function render() {
Expand Down Expand Up @@ -147,7 +147,7 @@ function renderArchivedProjects(container, { entries, kinds = {}, dates = {}, ho
<div class="archived-path" title="${escapeHtml(p.projectPath)}">${escapeHtml(p.projectPath)}</div>
<div class="archived-meta">${date && Number.isFinite(date.getTime()) ? `<time datetime="${date.toISOString()}">archived ${escapeHtml(date.toLocaleDateString())}</time>` : ''}${p.cached ? ` <span>${p.sessions.length} session${p.sessions.length === 1 ? '' : 's'}</span>` : ''}</div></div>
<div class="archived-actions"><button type="button" class="settings-action-btn archived-unarchive" ${busy ? 'disabled' : ''}>Unarchive</button>
<details class="archived-overflow"><summary aria-label="More actions for ${escapeHtml(p.name)}">⋯</summary><div class="archived-menu"><button type="button" class="settings-action-btn archived-copy">Copy path</button><button type="button" class="settings-action-btn archived-delete" ${busy ? 'disabled' : ''} aria-describedby="${escapeHtml(reasonId)}">Delete project…</button><span class="archived-delete-reason" id="${escapeHtml(reasonId)}"></span></div></details></div>
<details class="archived-overflow"><summary aria-label="More actions for ${escapeHtml(p.name)}" aria-describedby="${escapeHtml(reasonId)}">⋯</summary><div class="archived-menu"><button type="button" class="settings-action-btn archived-copy">Copy path</button><button type="button" class="settings-action-btn archived-delete" ${busy ? 'disabled' : ''} aria-describedby="${escapeHtml(reasonId)}">Delete project…</button><span class="archived-delete-reason" id="${escapeHtml(reasonId)}"></span></div></details></div>
</div>`;
}).join('')}</div></section>`;
}).join('');
Expand Down
5 changes: 3 additions & 2 deletions public/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ async function reconcileProjectDeletions({ operations = [] } = {}) {
}
}

async function confirmAndDeleteProjectFolder(project, button, { onUnavailable, reuseInitialPreview = false } = {}) {
async function confirmAndDeleteProjectFolder(project, button, { onUnavailable, onDialogOpen, reuseInitialPreview = false } = {}) {
if (isProjectDeleting(project) || completedProjectDeletionKeys.has(projectDeletionKey(project))) return false;
if (archivingGroupIds.has('ph-' + folderId(project.projectPath, project.remoteAlias)) ||
project.sessions?.some(session => archivingSessionIds.has(session.sessionId))) {
Expand Down Expand Up @@ -1152,6 +1152,7 @@ async function confirmAndDeleteProjectFolder(project, button, { onUnavailable, r
let initialPreview = reuseInitialPreview ? capabilities : null;
const categories = capabilities.plan.categories;
worktreeChoices = (capabilities.plan.worktrees || []).map(row => ({ ...row }));
onDialogOpen?.();
const answers = await showChoiceDialog({
title: 'Delete project from Switchboard?',
message: [`${project.remoteAlias || 'Local'} — ${capabilities.plan.project.projectPath}`,
Expand Down Expand Up @@ -1227,7 +1228,7 @@ async function confirmAndDeleteProjectFolder(project, button, { onUnavailable, r
} finally {
if (accepted) setProjectDeletionWritesBlocked(project, false);
if (!unresolved && !projectDeletionOperations.has(projectDeletionKey(project)) && !completedProjectDeletionKeys.has(projectDeletionKey(project))) setProjectDeletionBusy(project, false);
if (!button?.isConnected || button.disabled) {
if (!onUnavailable && (!button?.isConnected || button.disabled)) {
const target = document.getElementById('ph-' + folderId(project.projectPath, project.remoteAlias)) || document.getElementById('sidebar-content');
if (target) { target.tabIndex = -1; target.focus(); }
}
Expand Down
36 changes: 32 additions & 4 deletions test/dom-archived-manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ for (const remembered of [false, true]) test(`one Delete click uses one preview
await openDelete(h.rows()[0]);
h.q('.archived-delete').click();
await waitFor(() => h.q('.choice-dialog-confirm') && !h.q('.choice-dialog-confirm').disabled);
assert.equal(h.q('.archived-delete-reason').textContent, '', 'opening the dialog clears the row checking message');
assert.equal(h.calls.preview.length, 1, 'one Delete click must mint at most one preview token');
assert.equal(h.calls.preview[0].options.sessions, remembered);
assert.equal(h.calls.preview[0].options.settings, !remembered);
Expand Down Expand Up @@ -424,22 +425,30 @@ test('unavailable remembered settings can be kept without blocking Archived dele
});

for (const refusal of [
{ code: 'IDENTITY_UNAVAILABLE', error: 'No unambiguous known project mapping; reload projects.', retry: false },
{ code: 'INVALID_REQUEST', error: 'Invalid project selection.', retry: false },
{ code: 'IDENTITY_UNAVAILABLE', error: 'No unambiguous known project mapping; reload projects.', retry: true },
{ code: 'INVALID_REQUEST', error: 'Invalid project selection.', retry: true },
{ code: 'SNAPSHOT_STALE', error: 'Snapshot changed.', refresh: true, retry: true },
{ code: 'TOKEN_LIMIT', error: 'Too many previews.', retry: true },
{ code: 'UNAUTHORIZED', error: 'Sender unavailable.', retry: true },
{ error: 'IPC rejected', thrown: true, retry: true },
{ code: 'NOT_READY', error: 'Recovery pending', retry: true },
{ code: 'DISCOVERY_TIMEOUT', port: 'readJobs', retry: true },
{ code: 'DISCOVERY_UNAVAILABLE', error: 'Index unavailable', retry: true },
{ error: 'Index unavailable', retry: true },
]) test(`click-time refusal stays accessible with appropriate advice: ${refusal.code || refusal.error}`, async t => {
const h = await setup(t), row = h.rows()[1], button = row.querySelector('.archived-delete');
h.w.api.previewProjectDelete = async input => { h.calls.preview.push(input); return { ok: false, ...refusal }; };
h.w.api.previewProjectDelete = async input => {
h.calls.preview.push(input);
if (refusal.thrown) throw new Error(refusal.error);
return { ok: false, ...refusal };
};
await openDelete(row);
button.click();
await waitFor(() => button.disabled && row.querySelector('.archived-delete-reason').textContent !== 'Checking deletion availability…');
const reason = h.document.getElementById(button.getAttribute('aria-describedby'));
assert.ok(reason && reason.textContent, 'refused Delete keeps its accessible reason');
assert.doesNotMatch(reason.textContent, /delete its repository|Folder and path hints conflict/i);
assert.equal(/try again/i.test(reason.textContent), refusal.retry, 'only transient refusals offer another Delete attempt');
assert.equal(/try again/i.test(reason.textContent), refusal.retry, 'every non-grouped refusal offers another Delete attempt');
assert.doesNotMatch(reason.textContent, /Close and reopen this menu to retry|Retry preview, or cancel/i);
assert.equal(h.calls.execute.length, 0);
if (refusal.retry) {
Expand All @@ -450,6 +459,25 @@ for (const refusal of [
}
});

for (const grouped of [false, true]) test(`refused Archived Delete returns focus to its described summary, grouped=${grouped}`, async t => {
const h = await setup(t), row = h.rows()[1], button = row.querySelector('.archived-delete');
const focused = [];
h.document.addEventListener('focusin', event => focused.push(event.target));
h.w.api.previewProjectDelete = async () => ({ ok: false, code: 'IDENTITY_UNAVAILABLE',
error: grouped ? 'Folder and path hints conflict.' : 'Project mapping unavailable.' });
await openDelete(row);
button.focus(); button.click();
await waitFor(() => row.querySelector('.archived-delete-reason').textContent !== 'Checking deletion availability…');
await settle();
const summary = row.querySelector('summary');
assert.equal(h.document.activeElement, summary, 'refusal returns focus to the Archived row summary');
assert.equal(focused.includes(h.q('#sidebar-content')), false, 'refusal must never focus the sidebar');
assert.equal(summary.getAttribute('aria-describedby'), button.getAttribute('aria-describedby'), 'summary exposes the refusal reason');
row.querySelector('details').open = false; await settle();
await openDelete(row);
assert.equal(button.disabled, grouped, 'only the grouped worktree remains disabled after reopening');
});

test('reason IDs remain unique and stable when filtering changes row positions', async t => {
const h = await setup(t);
const ids = new Map(h.rows().map(row => [row.dataset.entry, row.querySelector('.archived-delete').getAttribute('aria-describedby')]));
Expand Down
21 changes: 21 additions & 0 deletions test/dom-project-delete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');

for (const caller of ['sidebar', 'settings']) {
for (const headerPresent of [false, true]) test(`${caller} refused Delete keeps its existing fallback, header=${headerPresent}`, async t => {
const h = setup(t);
const button = caller === 'settings' ? await settings(h) : h.document.querySelector('.project-delete-btn');
const header = h.document.getElementById('ph-' + h.w.folderId(h.p.projectPath, h.p.remoteAlias));
const expected = headerPresent ? header : h.document.getElementById('sidebar-content');
let pending;
const confirm = h.w.confirmAndDeleteProjectFolder;
h.w.confirmAndDeleteProjectFolder = (...args) => { pending = confirm(...args); return pending; };
h.w.api.previewProjectDelete = async () => {
button.remove();
if (!headerPresent) header.remove();
return { ok: false, code: 'UNAUTHORIZED', error: 'Sender unavailable.' };
};
button.click();
assert.ok(pending, 'the real caller uses the shared deletion controller');
await pending;
assert.equal(h.document.activeElement, expected, 'existing callers retain their header/sidebar fallback');
});
}

test('E unavailable worktree inventory has a visible reason outside JSON details', async t => {
const h = setup(t, { warnings: [{ code: 'WORKTREE_UNAVAILABLE', error: 'Git inventory unavailable' }] });
const pending = h.start(); await flush();
Expand Down
Loading