diff --git a/.ai/contexts/ipc-bridge.md b/.ai/contexts/ipc-bridge.md index b97a83e7d..0434d5c72 100644 --- a/.ai/contexts/ipc-bridge.md +++ b/.ai/contexts/ipc-bridge.md @@ -618,8 +618,23 @@ pages are `general`, `sessions`, `keyboard`, `automation`, `remote`, `integratio The panel reparents existing rows into named regions before wiring their handlers. Hidden pages remain in the DOM, preserving every field id and the one Save path. -The Archived projects manager is documented above; project footer actions retain -their existing behavior until their later #863 slice. The new shell adds no trigger controls or archive APIs. +The Archived projects manager is documented above. This project shows the identity +from the same path-and-folder-key project lookup used by deletion, performed after +shell-profile loading finishes: name, full path, host label, folder key and cached +top-level non-terminal session counts (including archived sessions). Both counts +filter flat cache rows with `!s.parentSessionId && s.type !== 'terminal'`. +There is no shared predicate: the parent exclusion matches `renderDefaultStatus` +in `public/app.js` and the sidebar count in `public/sidebar.js`; the terminal +exclusion matches the background projection in `public/app.js`. The sidebar +additionally excludes archived rows for its active count. Host labels fall back +to the alias when `remoteHostLabel` is unavailable. +Without a cached project, supplied path/folder identity remains visible and counts +read Unavailable. Values use textContent. Archive Project and Delete Project move +into its Danger zone before wiring, retaining their ids, deletion busy keys and +handlers. Archive failures use the OK-only `appAlert` adapter from +`public/app-dialogs.js`. The footer contains only Cancel and Save Settings. Identity wraps in +the existing ResizeObserver-driven narrow layout; no layout mode is added. +The new shell adds no trigger controls or archive APIs. The host-list and refresh defaults now live in `SETTING_DEFAULTS`. Each page scrolls independently; navigation and the footer stay outside that diff --git a/CHANGELOG.md b/CHANGELOG.md index e61cccb3c..d1fa38b4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ What changes for you in each release of Switchboard. How to write an entry: [doc - Settings → Sessions → CLI Agents offers **Show Codex usage**, off by default. Turn it on to show your Codex limits in the status bar and Stats; usage hides quietly when unavailable. (#1139) ### Changed +- Project Settings → This project shows the project's path, host and number of sessions, including archived ones, with Archive Project and Delete Project in a separate Danger zone. (#863) - After a restart, Switchboard re-reads only Claude Code transcripts changed since the previous run. Codex history is still re-read in full. (#1144) - Settings → Archived groups project and folder archives by host, shows their paths and archive dates, and filters by name, path or host. Folder archives show their disabled schedule count and can be restored after Undo expires, keeping schedules off until you choose Turn back on. Restore one or several projects with Undo, or delete an archived project through the existing preview without restoring it first. Worktree entries whose repository is gone can be deleted; entries still grouped under a repository explain that you can delete their repository instead. (#863, #1167) - Codex sessions run non-interactively by a program (`codex exec`: scripted reviews and fixes) are now left out of the sidebar and grid like Claude Agent SDK sessions, under the same **Hide SDK-launched Sessions** setting. They still count in the heatmap and are found by search; the ones you have open stay listed. Codex sessions already indexed are re-checked once at the next start. (#1145) diff --git a/docs/product/UI-PATTERNS.md b/docs/product/UI-PATTERNS.md index 25ef6d85b..04df5cf73 100644 --- a/docs/product/UI-PATTERNS.md +++ b/docs/product/UI-PATTERNS.md @@ -160,8 +160,8 @@ The Changes badge is the one place that already meets "never colour alone". | Agents Delete | `agents-view.js` `runAgentVerb` | `Delete` | `claude rm` (conversation + worktree when safe) | Fresh refusal check, then danger `appConfirm`; refusal stays in the detail without a dialog | | Worktree Delete | `sidebar.js:1337-1352`, dialog `1949-2017` | `Delete anyway` | `git worktree remove` | custom modal with dirty-file list | | Worktree Archive project | `sidebar.js` (`worktree-hide-btn`) | `Archive Project` | removes the row, keeps settings and cache, suspends schedules; reversible from Settings | no confirmation; 10-second Undo notice | -| Project Archive | `settings-panel.js` (`sv-archive-btn`) | `Archive Project` | same | no confirmation; 10-second Undo notice | -| Project Delete | `settings-panel.js` (`sv-delete-btn`) | `Delete Project` | drops settings, cache, search index and schedule registration; no file on disk is deleted | `showChoiceDialog`, danger style, focus on Cancel | +| Project Archive | Project Settings → This project → Danger zone, `settings-panel.js` (`sv-archive-btn`) | `Archive Project` | same | no confirmation; 10-second Undo notice | +| Project Delete | Project Settings → This project → Danger zone, `settings-panel.js` (`sv-delete-btn`) | `Delete Project` | drops settings, cache, search index and schedule registration; no file on disk is deleted | `showChoiceDialog`, danger style, focus on Cancel | | Optional viewer file delete | `viewer-panel.js:284` | — | delete file | danger `appConfirm`, `Delete ""?` / `This cannot be undone.`, button `Delete` | | Trace file delete | `activity-trace-panel.js:120` | — | delete file | same wording | diff --git a/docs/settings.md b/docs/settings.md index 0791e6e4b..4a1153a86 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -194,8 +194,12 @@ Project Settings override, for one project, the fields on the **Launch** page: P **Use global default** box; while it is checked the field shows the global value and nothing is stored for the project. -The **This project** page reserves space for project identity. For now, -**Archive Project** and **Delete Project** remain in the footer. +The **This project** page shows the project's name, full path, host, folder key +and the number of sessions, including archived ones. Counts are unavailable when +the project is absent from the current project list. Its **Danger zone** holds +**Archive Project** and **Delete Project**; the footer holds only **Cancel** and +**Save Settings**. The first visit opens **Launch**; later visits remember the +last project page. **Archive Project** removes the project and its nested worktrees from the sidebar immediately, without asking. A notice offers **Undo** for about 10 diff --git a/public/settings-panel.js b/public/settings-panel.js index cc74318b6..d14e30b62 100644 --- a/public/settings-panel.js +++ b/public/settings-panel.js @@ -167,6 +167,7 @@ // Discover available shell profiles let shellProfiles = []; try { shellProfiles = await window.api.getShellProfiles(); } catch {}; + const project = isProject ? cachedAllProjects.find(p => p.projectPath === projectPath && (!folderKey || p.folder === folderKey)) : null; settingsViewerBody.innerHTML = `
@@ -567,10 +568,33 @@ moveGroup(launchPage, 'Launch', ['sv-pre-launch', 'sv-add-dirs', 'sv-worktree', 'sv-worktree-name', 'sv-browser-mode', 'sv-sandbox']); moveGroup(launchPage, 'Claude', ['sv-perm-mode']); if (isProject) { - const placeholder = document.createElement('p'); - placeholder.className = 'settings-description'; - placeholder.textContent = 'Project actions are available below.'; - pages.get('project').append(placeholder); + const identity = document.createElement('dl'); + identity.className = 'settings-project-identity'; + const alias = project?.remoteAlias || parseFolderKey(folderKey).alias; + const sessions = Array.isArray(project?.sessions) + ? project.sessions.filter(s => !s.parentSessionId && s.type !== 'terminal') : null; + const counts = Array.isArray(sessions) + ? `${sessions.length} session${sessions.length === 1 ? '' : 's'} · ${sessions.filter(session => session.archived).length} archived` + : 'Unavailable'; + for (const [id, label, value] of [ + ['name', 'Name', shortName], + ['path', 'Full path', projectPath], + ['host', 'Host', alias ? (typeof remoteHostLabel === 'function' ? remoteHostLabel(alias, globalSettings.remoteHosts) : alias) : 'Local'], + ['folder', 'Folder key', project?.folder || folderKey || 'Unavailable'], + ['sessions', 'Sessions', counts], + ]) { + const term = document.createElement('dt'); + term.textContent = label; + const detail = document.createElement('dd'); + detail.id = 'sv-project-' + id; + detail.textContent = value; + identity.append(term, detail); + } + const danger = document.createElement('div'); + danger.className = 'settings-section settings-danger-zone'; + danger.innerHTML = '

Danger zone

'; + danger.querySelector('.settings-project-actions').append(form.querySelector('#sv-archive-btn'), form.querySelector('#sv-delete-btn')); + pages.get('project').append(identity, danger); } else { moveGroup('general', 'Startup', ['sv-restore-startup']); moveGroup('general', 'Shell', ['sv-shell-profile']); @@ -839,8 +863,6 @@ }); }); - const project = isProject ? cachedAllProjects.find(p => p.projectPath === projectPath && (!folderKey || p.folder === folderKey)) : null; - // Save button async function saveSettings() { let settings = {}; @@ -1080,7 +1102,7 @@ document.getElementById('placeholder').style.display = 'flex'; if (typeof loadProjects === 'function') await Promise.resolve(loadProjects()).catch(error => { if (!loadProjects.state?.reportedErrors?.has(error)) console.warn('[switchboard] project reload failed', error); }); } catch (err) { - await showChoiceDialog({ title: `Could not ${action} project`, message: err.message, confirmLabel: 'OK', returnFocus: button }); + await appAlert({ title: `Could not ${action} project`, message: err.message }); } }); } diff --git a/public/style.css b/public/style.css index cb695f7e6..899349496 100644 --- a/public/style.css +++ b/public/style.css @@ -4161,6 +4161,48 @@ body { display: flex; flex-direction: column; } margin: 0 0 16px; } +.settings-project-identity { + display: grid; + grid-template-columns: 7rem minmax(0, 1fr); + gap: 12px; + margin-bottom: 24px; + overflow-wrap: anywhere; +} + +.settings-project-identity dt { + color: var(--text-muted); +} + +.settings-project-identity dd { + margin: 0; + min-width: 0; +} + +.settings-danger-zone { + border: 1px solid var(--control-border); + border-radius: 8px; + padding: 16px; +} + +.settings-project-actions { + display: flex; + flex-wrap: wrap; + gap: 12px; +} + +.settings-project-actions .settings-remove-btn { + margin-left: 0; +} + +.settings-narrow .settings-project-identity { + grid-template-columns: minmax(0, 1fr); + gap: 6px; +} + +.settings-narrow .settings-project-identity dd { + margin-bottom: 8px; +} + .settings-details { margin: 12px 0; padding: 12px; diff --git a/test/dom-settings-project.test.js b/test/dom-settings-project.test.js new file mode 100644 index 000000000..e4985f3e4 --- /dev/null +++ b/test/dom-settings-project.test.js @@ -0,0 +1,195 @@ +'use strict'; + +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const vm = require('node:vm'); +const { JSDOM } = require('jsdom'); +const { loadAppFunctions } = require('./app-source'); + +const root = path.join(__dirname, '..'); +const settle = () => new Promise(resolve => setImmediate(resolve)); + +function setup(t, projects = []) { + const dom = new JSDOM(fs.readFileSync(path.join(root, 'public/index.html'), 'utf8'), { url: 'http://localhost', runScripts: 'outside-only' }); + t.after(() => dom.window.close()); + const w = dom.window; + const ctx = dom.getInternalVMContext(); + const saved = { global: { permissionMode: 'plan', remoteHosts: [{ alias: 'box', label: 'Build ' }] } }; + w.cachedAllProjects = projects; + w.api = new Proxy({ + platform: 'linux', getSetting: async key => saved[key] || {}, + setSetting: async (key, value) => { saved[key] = value; }, + getShellProfiles: async () => [], getHarnesses: async () => [], + }, { get: (target, key) => target[key] || (() => Promise.resolve({})) }); + loadAppFunctions(ctx, { functions: ['saveGlobalSettings'], declarations: ['_persistChain'] }); + loadAppFunctions(ctx, { sourcePath: path.join(root, 'public/sidebar.js'), functions: ['folderId', 'isProjectDeleting', 'projectDeletionKey', 'paintProjectDeletionBusy'], declarations: ['deletingProjectKeys', 'projectDeletionUnavailable'] }); + for (const file of ['setting-defaults.js', 'utils.js', 'modal-stack.js', 'choice-dialog.js', 'app-dialogs.js', 'app-notices.js', 'shortcuts.js', 'terminal-themes.js', 'remote-enrol-panel.js', 'archived-manager.js', 'settings-panel.js']) { + const filename = path.join(root, 'public', file); + vm.runInContext(fs.readFileSync(filename, 'utf8'), ctx, { filename }); + } + const q = selector => w.document.querySelector(selector); + const open = (projectPath = '/srv/', folder = 'box::folder') => w.openSettingsViewer('project', projectPath, folder); + const projectPage = () => q('.settings-nav [data-section="project"]').click(); + return { w, ctx, q, open, projectPage, saved }; +} + +test('project actions live only in This project, outside the Save and Cancel footer', async t => { + const h = setup(t); + await h.open(); + assert.deepEqual([...h.w.document.querySelectorAll('.settings-nav button')].map(b => b.textContent), ['Launch', 'This project']); + assert.equal(h.q('#settings-page-launch').hidden, false); + assert.deepEqual([...h.q('.settings-btn-row').querySelectorAll('button')].map(b => b.id), ['sv-cancel-btn', 'sv-save-btn']); + h.projectPage(); + const zone = h.q('#settings-page-project .settings-danger-zone'); + assert.ok(zone, 'This project contains the danger zone'); + assert.equal(zone.querySelector('h3').textContent, 'Danger zone'); + for (const action of ['archive', 'delete']) { + assert.equal(h.w.document.querySelectorAll('#sv-' + action + '-btn').length, 1); + assert.ok(zone.contains(h.q('#sv-' + action + '-btn'))); + } + const nav = h.q('.settings-nav [data-section="project"]'); + nav.dispatchEvent(new h.w.KeyboardEvent('keydown', { key: 'Tab', bubbles: true, cancelable: true })); + assert.equal(h.w.document.activeElement, h.q('#sv-archive-btn')); + await h.w.openSettingsViewer('global'); + assert.equal(h.q('.settings-danger-zone'), null); + assert.equal(h.q('#sv-archive-btn'), null); +}); + +test('This project identifies the exact remote folder and its session rows as text', async t => { + const project = { projectPath: '/srv/', folder: 'box::folder', remoteAlias: 'box', sessions: [ + { sessionId: 'a' }, { sessionId: 'b', archived: 1 }, { sessionId: 'c' }, + { sessionId: 'child', parentSessionId: 'c' }, + { sessionId: 'archived-child', parentSessionId: 'b', archived: 1 }, + { sessionId: 'shell', type: 'terminal' }, + { sessionId: 'archived-shell', type: 'terminal', archived: 1 }, + ] }; + const h = setup(t, [{ ...project, remoteAlias: null, folder: 'local', sessions: [] }, project]); + await h.open(); + h.projectPage(); + assert.equal(h.q('#sv-project-name')?.textContent, 'srv/'); + assert.equal(h.q('#sv-project-path')?.textContent, '/srv/'); + assert.equal(h.q('#sv-project-host')?.textContent, 'Build '); + assert.equal(h.q('#sv-project-folder')?.textContent, 'box::folder'); + assert.equal(h.q('#sv-project-sessions')?.textContent, '3 sessions · 1 archived'); + assert.equal(h.q('#settings-page-project repo'), null); + assert.equal(h.q('#settings-page-project server'), null); +}); + +test('This project falls back to the remote alias when the label helper is unavailable', async t => { + const h = setup(t); + h.w.remoteHostLabel = undefined; + await assert.doesNotReject(h.open(), 'project settings must open without the optional host-label helper'); + assert.equal(h.q('#sv-project-host')?.textContent, 'box'); +}); + +test('Delete uses the project refreshed while shell profiles were loading', async t => { + const stale = { projectPath: '/srv/', folder: 'box::folder', remoteAlias: 'box', sessions: [] }; + const fresh = { ...stale, sessions: [{ sessionId: 'new-session' }] }; + const h = setup(t, [stale]); + let releaseProfiles; + let profilesRequested; + const requested = new Promise(resolve => { profilesRequested = resolve; }); + h.w.api.getShellProfiles = () => new Promise(resolve => { + releaseProfiles = resolve; + profilesRequested(); + }); + const deleted = []; + h.w.confirmAndDeleteProjectFolder = async project => { deleted.push(project); return false; }; + const opening = h.open(); + await requested; + h.w.cachedAllProjects = [fresh]; + releaseProfiles([]); + await opening; + h.q('#sv-delete-btn').click(); + await settle(); + assert.equal(deleted[0], fresh, 'Delete must receive the refreshed project object'); + assert.equal(h.q('#sv-project-sessions')?.textContent, '1 session · 0 archived'); +}); + +test('failed Settings Archive shows an OK-only alert and retains the project', async t => { + const h = setup(t); + let reloads = 0; + h.w.loadProjects = async () => { reloads++; }; + h.w.api.archiveProjectSettings = async () => ({ error: 'disk ' }); + await h.open(); + h.projectPage(); + const button = h.q('#sv-archive-btn'); + button.focus(); + button.click(); + await settle(); + assert.equal(h.q('#choice-dialog-title')?.textContent, 'Could not archive project'); + assert.match(h.q('.choice-dialog')?.textContent || '', /disk /); + assert.equal(h.q('.choice-dialog full'), null); + assert.equal(h.q('.choice-dialog-confirm')?.textContent, 'OK'); + assert.equal(h.q('.choice-dialog-cancel:not([hidden])'), null, 'failure must be an OK-only appAlert'); + h.q('.choice-dialog-confirm').click(); + await settle(); + assert.equal(h.q('.choice-dialog-overlay'), null); + assert.equal(h.q('#settings-viewer').style.display, 'flex'); + assert.equal(h.w.document.activeElement, button); + assert.equal(h.q('#app-notices .app-notice-action'), null); + assert.equal(reloads, 0); +}); + +test('local identity uses the cached folder when none was supplied and reports zero rows', async t => { + const h = setup(t, [{ projectPath: 'C:\\repo', folder: 'C-repo', sessions: [] }]); + await h.open('C:\\repo', null); + assert.equal(h.q('#sv-project-host')?.textContent, 'Local'); + assert.equal(h.q('#sv-project-path')?.textContent, 'C:\\repo'); + assert.equal(h.q('#sv-project-folder')?.textContent, 'C-repo'); + assert.equal(h.q('#sv-project-sessions')?.textContent, '0 sessions · 0 archived'); +}); + +test('a missing cached project retains supplied identity without inventing session counts', async t => { + const h = setup(t); + await h.open(); + assert.equal(h.q('#sv-project-host')?.textContent, 'Build '); + assert.equal(h.q('#sv-project-folder')?.textContent, 'box::folder'); + assert.equal(h.q('#sv-project-sessions')?.textContent, 'Unavailable'); + await h.open('/missing', null); + assert.equal(h.q('#sv-project-folder')?.textContent, 'Unavailable'); +}); + +test('Launch inheritance survives visiting This project and saving from its footer', async t => { + const h = setup(t); + await h.open(); + const control = h.q('#sv-perm-mode'); + assert.equal(control.closest('.settings-page').dataset.section, 'launch'); + assert.equal(control.disabled, true); + assert.equal(control.value, 'plan'); + h.q('[data-field="permissionMode"]').click(); + assert.equal(control.disabled, false); + control.value = 'auto'; + control.dispatchEvent(new h.w.Event('change', { bubbles: true })); + h.projectPage(); + assert.ok(h.q('#settings-page-project .settings-danger-zone'), 'actions are separated from Launch fields'); + h.q('#sv-save-btn').click(); + await settle(); + assert.equal(h.saved['project:/srv/'].permissionMode, 'auto'); + assert.equal(h.q('#sv-unsaved').textContent, ''); +}); + +test('moved actions retain exact archive arguments, Undo, delete target and busy guards', async t => { + const p = { projectPath: '/srv/', folder: 'box::folder', remoteAlias: 'box', sessions: [] }; + const h = setup(t, [p]); + const calls = []; + h.w.api.archiveProjectSettings = async (...args) => { calls.push(args); return { entry: 'box::/srv/' }; }; + h.w.showProjectArchiveUndo = (...args) => calls.push(args); + h.w.confirmAndDeleteProjectFolder = async (project, button) => { calls.push([project, button]); return false; }; + await h.open(); + h.projectPage(); + assert.ok(h.q('.settings-danger-zone')?.contains(h.q('#sv-archive-btn')), 'archive is reachable in the danger zone'); + h.q('#sv-archive-btn').click(); + await settle(); + assert.deepEqual(calls, [['/srv/', 'box::folder'], ['box::/srv/', 'srv/']]); + await h.open(); + h.q('#sv-delete-btn').click(); + await settle(); + assert.equal(calls[2][0], p); + assert.equal(calls[2][1], h.q('#sv-delete-btn')); + vm.runInContext('deletingProjectKeys.add(projectDeletionKey(cachedAllProjects[0])); paintProjectDeletionBusy();', h.ctx, { filename: __filename }); + assert.equal(h.q('#sv-delete-btn').disabled, true); + assert.equal(h.q('#sv-archive-btn').disabled, true); +});