diff --git a/.ai/contexts/ipc-bridge.md b/.ai/contexts/ipc-bridge.md index 0434d5c72..dbf5617ec 100644 --- a/.ai/contexts/ipc-bridge.md +++ b/.ai/contexts/ipc-bridge.md @@ -618,6 +618,27 @@ 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 settings filter (`#sv-filter`) reads only `.settings-label` and +`.settings-description` text within each settings row on input, using a trimmed, +case-insensitive substring. `data-settings-filter-exclude` marks dynamic descriptions +and values: CLI availability/lock messages, version/update status, ActivityWatch +destination/URL/status, remote-host entries/status, and trace paths/entries. +Marked elements and their descendants are skipped; marked content nested in a +description is removed from a clone, leaving the live DOM untouched. Controls, +including Use global default, select option labels, shortcut bindings and host +buttons, contribute no search text. It hides unmatched rows, +empty groups and disclosure prose, then stacks matching pages in one scrolling +area. It does not build an index, read ids or control values, re-render controls, +or enter the dirty snapshot. No-match navigation items are dimmed but remain +operable; selection changes the remembered page without leaving filter mode. +Tab from navigation enters a visible matching control, or Save when there are no +results. Escape in the filter clears it, consumes the key and keeps focus; clearing +restores the selected page and all its groups. Reopening starts with an empty filter. +Archived is excluded because it manages objects with its own filter and selection; +the settings filter never modifies that manager's DOM. Project identity and Danger +zone have no settings rows and are excluded too. The existing ResizeObserver remains +the only narrow-layout trigger; the filter stays above the horizontal nav strip. +DOM regressions and CSS contracts live in `test/dom-settings-nav.test.js`. 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 diff --git a/CHANGELOG.md b/CHANGELOG.md index d1fa38b4e..dca6378b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ What changes for you in each release of Switchboard. How to write an entry: [doc ## Unreleased ### New +- Settings has a filter field: type part of a setting's name or description to see matching settings from every page, then press Escape to go back to the page you were on. (#1173) - 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 diff --git a/docs/settings.md b/docs/settings.md index 4a1153a86..b00460d24 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -22,6 +22,25 @@ All pages share one Save: switching pages keeps edits, and the footer counts unsaved changes. Save keeps Settings open and flashes Saved; Cancel discards edits without asking. Live switches and Unarchive still take effect immediately. +**Filter settings…**, above the navigation, finds text in setting labels and +descriptions across all pages, in both Global and Project Settings. Matching rows +appear under their page titles; pages without matches are dimmed in the navigation. +Matching ignores case and outer spaces. It searches only setting names and +descriptive prose. Control text and values (including option labels, shortcut +bindings and Use global default), ids, version and status messages, ActivityWatch +destination and URL values, SSH host entries and their action buttons, and trace +file paths and entries are excluded. Expanded explanatory disclosures are not +searched either. +There is no fuzzy matching. You can edit and save the matching rows normally. +Press Escape in the field, or clear it, to return to the current page. Selecting a +navigation item while filtering keeps the results visible and chooses the page +to return to. The filter is keyboard reachable and does not count as an edit. + +Archived keeps its own **Filter by name, path or host…** field: archives are excluded +from the settings filter. Clear the settings filter to use Archived; its filter +and selected rows are preserved. Project identity and Danger zone actions are +also outside the settings search. + ### General Startup, Shell, Terminal and IDE settings: diff --git a/public/settings-panel.js b/public/settings-panel.js index d14e30b62..1730c2278 100644 --- a/public/settings-panel.js +++ b/public/settings-panel.js @@ -131,7 +131,7 @@ ${harnessList.map(h => `
${escapeHtml(h.label)} -
${h.available ? 'Sessions indexed, watched and offered in the + menu' : 'Not installed here: no sessions found for it'}
+
${h.available ? 'Sessions indexed, watched and offered in the + menu' : 'Not installed here: no sessions found for it'}
@@ -431,7 +431,7 @@
Version -
+
@@ -445,9 +445,9 @@
SSH hosts to observe
Each host is an alias from your ~/.ssh/config — Switchboard never stores or reads a key, a password or a port. Its Claude sessions are mirrored read-only into the local database and appear in the sidebar, the search and the heatmap alongside your own. Opening one shows its transcript; it cannot be resumed from here.
-
+
- +
@@ -466,8 +466,8 @@
Send session activity to ActivityWatch -
Destination: ${escapeHtml(reportingState.destination || 'ActivityWatch')}, the local time tracker, at ${escapeHtml(reportingState.url || '')}. Nothing leaves this machine. Takes effect immediately and is remembered across launches.
-
+
Destination: ${escapeHtml(reportingState.destination || 'ActivityWatch')}, the local time tracker, at ${escapeHtml(reportingState.url || '')}. Nothing leaves this machine. Takes effect immediately and is remembered across launches.
+
@@ -510,8 +510,8 @@
Trace files -
${escapeHtml(traceState.dir || '')}
-
+
${escapeHtml(traceState.dir || '')}
+
` : ''} @@ -537,7 +537,7 @@ : [['general', 'General'], ['sessions', 'Sessions'], ['keyboard', 'Keyboard'], ['automation', 'Automation'], ['remote', 'Remote hosts'], ['integrations', 'Integrations'], ['archived', 'Archived'], ['advanced', 'Advanced']]; const layout = document.createElement('div'); layout.className = 'settings-layout'; - layout.innerHTML = `
`; + layout.innerHTML = `
`; form.prepend(layout); const pages = new Map(pageDefs.map(([id, label]) => { const page = document.createElement('section'); @@ -631,6 +631,51 @@ }); const navButtons = [...layout.querySelectorAll('.settings-nav button')]; const storageKey = 'settingsSection:' + (isProject ? 'project' : 'global'); + const filter = layout.querySelector('#sv-filter'); + const emptyResults = document.createElement('p'); + emptyResults.className = 'settings-description settings-filter-empty'; + emptyResults.setAttribute('role', 'status'); + emptyResults.textContent = 'No settings match. Clear the filter to see all settings.'; + emptyResults.hidden = true; + layout.querySelector('.settings-pages').append(emptyResults); + let selectedPage; + function applySettingsFilter() { + const query = filter.value.trim().toLowerCase(); + layout.classList.toggle('settings-filtering', Boolean(query)); + let anyMatch = false; + for (const [id, page] of pages) { + let matches = false; + if (id !== 'archived') { + for (const row of page.querySelectorAll('.settings-field')) { + const text = [...row.querySelectorAll('.settings-label, .settings-description')] + .filter(node => !node.closest('[data-settings-filter-exclude]')) + .map(node => { + const copy = node.cloneNode(true); + copy.querySelectorAll('[data-settings-filter-exclude]').forEach(excluded => excluded.remove()); + return copy.textContent; + }).join(' ').toLowerCase(); + row.hidden = Boolean(query) && !text.includes(query); + if (!row.hidden) matches = true; + } + for (const group of page.querySelectorAll('.settings-section')) { + group.hidden = Boolean(query) && ![...group.querySelectorAll('.settings-field')].some(row => !row.hidden); + } + page.querySelectorAll('.settings-details').forEach(details => { details.hidden = Boolean(query); }); + } + page.hidden = query ? !matches : id !== selectedPage; + navButtons.find(button => button.dataset.section === id).classList.toggle('settings-no-match', Boolean(query) && !matches); + anyMatch ||= matches; + } + emptyResults.hidden = !query || anyMatch; + } + filter.addEventListener('input', applySettingsFilter); + filter.addEventListener('keydown', event => { + if (event.key !== 'Escape' || !filter.value) return; + event.preventDefault(); + event.stopPropagation(); + filter.value = ''; + applySettingsFilter(); + }); function revealActiveNav() { if (settingsViewer.classList.contains('settings-narrow')) { navButtons.find(button => button.classList.contains('active'))?.scrollIntoView?.({ block: 'nearest', inline: 'nearest' }); @@ -638,7 +683,8 @@ } function selectPage(id) { if (!pages.has(id)) id = pageDefs[0][0]; - for (const [pageId, page] of pages) page.hidden = pageId !== id; + selectedPage = id; + applySettingsFilter(); for (const button of navButtons) { const selected = button.dataset.section === id; button.classList.toggle('active', selected); @@ -663,8 +709,10 @@ navButtons[next].focus(); } else if (event.key === 'Tab' && !event.shiftKey) { event.preventDefault(); - const page = pages.get(button.dataset.section); - (page.querySelector('input:not(:disabled), select:not(:disabled), button:not(:disabled), summary') || page.querySelector('h2')).focus(); + const selected = pages.get(button.dataset.section); + const page = selected.hidden ? [...pages.values()].find(page => !page.hidden) : selected; + const control = page && [...page.querySelectorAll('input:not(:disabled), select:not(:disabled), button:not(:disabled), summary')].find(control => !control.closest('[hidden]')); + (control || page?.querySelector('h2') || form.querySelector('#sv-save-btn')).focus(); } }); } @@ -689,7 +737,7 @@ unsaved.className = 'settings-unsaved'; unsaved.setAttribute('role', 'status'); footer.prepend(unsaved); - const trackedControls = [...form.querySelectorAll('input, select')].filter(control => !['sv-activity-trace', 'sv-activity-reporting'].includes(control.id)); + const trackedControls = [...form.querySelectorAll('input, select')].filter(control => !['sv-filter', 'sv-activity-trace', 'sv-activity-reporting'].includes(control.id)); const controlValue = control => String(control.type === 'checkbox' ? control.checked : control.value); let initialHosts; let initialShortcuts; diff --git a/public/style.css b/public/style.css index 899349496..5343e6acd 100644 --- a/public/style.css +++ b/public/style.css @@ -4101,8 +4101,22 @@ body { display: flex; flex-direction: column; } gap: 24px; } -.settings-nav { +.settings-navigation { flex: 0 0 160px; + min-width: 0; + min-height: 0; + display: flex; + flex-direction: column; + gap: 12px; +} + +.settings-navigation .settings-filter { + width: 100%; + min-width: 0; + box-sizing: border-box; +} + +.settings-nav { overflow-y: auto; } @@ -4134,6 +4148,10 @@ body { display: flex; flex-direction: column; } background: var(--accent-wash); } +.settings-nav button.settings-no-match { + opacity: 0.45; +} + .settings-nav button:focus-visible, .settings-details summary:focus-visible { outline: 2px solid var(--accent); @@ -4156,6 +4174,20 @@ body { display: flex; flex-direction: column; } display: none; } +.settings-layout [hidden] { + display: none; +} + +.settings-filtering .settings-pages { + overflow-y: auto; +} + +.settings-filtering .settings-page { + height: auto; + overflow-y: visible; + margin-bottom: 24px; +} + .settings-page h2 { font-size: 20px; margin: 0 0 16px; @@ -4268,8 +4300,11 @@ body { display: flex; flex-direction: column; } gap: 12px; } -.settings-narrow .settings-nav { +.settings-narrow .settings-navigation { flex: 0 0 auto; +} + +.settings-narrow .settings-nav { overflow-x: auto; } diff --git a/test/dom-settings-nav.test.js b/test/dom-settings-nav.test.js index 7376faf67..017658857 100644 --- a/test/dom-settings-nav.test.js +++ b/test/dom-settings-nav.test.js @@ -13,6 +13,237 @@ const root = path.join(__dirname, '..'); const settle = () => new Promise(resolve => setImmediate(resolve)); const globalPages = ['general', 'sessions', 'keyboard', 'automation', 'remote', 'integrations', 'archived', 'advanced']; +test('settings filter is labelled and keyboard reachable above navigation in both scopes', async t => { + const h = setup(t); + for (const scope of ['global', 'project']) { + await h.open(scope); + const filter = h.q('#sv-filter'); + assert.ok(filter, 'Settings exposes a filter field'); + assert.equal(filter.getAttribute('aria-label'), 'Filter settings'); + assert.equal(filter.placeholder, 'Filter settings…'); + assert.equal(filter.tabIndex, 0); + assert.ok(filter.compareDocumentPosition(h.q('.settings-nav')) & h.w.Node.DOCUMENT_POSITION_FOLLOWING); + filter.focus(); + assert.equal(h.w.document.activeElement, filter); + } +}); + +function filterSettings(h, value) { + const filter = h.q('#sv-filter'); + assert.ok(filter, 'Settings exposes a filter field'); + filter.value = value; + filter.dispatchEvent(new h.w.Event('input', { bubbles: true })); + return filter; +} + +function visibleSettingsRows(h) { + return [...h.w.document.querySelectorAll('.settings-page .settings-field')] + .filter(row => !row.closest('[hidden]')); +} + +test('project filter ignores the Use global default control label', async t => { + const h = setup(t); + await h.open('project'); + assert.ok(h.q('#settings-page-launch .settings-use-global')); + filterSettings(h, 'global'); + assert.deepEqual(visibleSettingsRows(h), [], 'global must not match any Launch row'); + assert.deepEqual(h.active(), []); +}); + +test('filter ignores select option labels and shortcut bindings', async t => { + const h = setup(t); + await h.open(); + assert.match(h.q('#sv-codex-sandbox').textContent, /Full access \(danger\)/); + const shortcut = h.q('.settings-shortcut-btn').textContent; + assert.ok(shortcut.trim()); + for (const term of ['Full access (danger)', shortcut]) { + filterSettings(h, term); + assert.deepEqual(visibleSettingsRows(h), [], term + ' is only control text'); + } +}); + +test('filter ignores dynamic values and statuses but keeps descriptive prose searchable', async t => { + const h = setup(t); + h.w.api.getActivityReportingState = async () => ({ destination: 'uniquedestination', url: 'http://uniqueurl:5600' }); + h.w.api.getActivityTraceState = async () => ({ dir: '/uniquetracedir' }); + h.saved.global = { remoteHosts: [{ alias: 'uniquehost', label: 'Unique host', enabled: true }] }; + await h.open(); + const texts = [ + ['#sv-current-version', 'uniqueversion'], + ['#sv-update-status', 'uniqueupdatestatus'], + ['#sv-activity-reporting-status', 'uniquereportingstatus'], + ['#sv-remote-status', 'uniqueremotestatus'], + ['.sv-harness-desc', 'uniqueharnessstatus'], + ]; + for (const [selector, text] of texts) h.q(selector).textContent = text; + const hosts = h.q('#sv-remote-hosts'); + assert.ok(hosts.querySelector('.rh-check')); + for (const term of [...texts.map(([, text]) => text), 'uniquedestination', 'uniqueurl', 'uniquetracedir', 'Check host', 'Add host']) { + await t.test(term, () => { + assert.ok(h.q('.settings-form').textContent.includes(term), 'excluded text is present in the DOM'); + filterSettings(h, term); + assert.deepEqual(visibleSettingsRows(h), [], term + ' must not match a setting'); + }); + } + filterSettings(h, 'local time tracker'); + assert.deepEqual(visibleSettingsRows(h), [h.q('#sv-activity-reporting').closest('.settings-field')]); + filterSettings(h, '~/.ssh/config'); + assert.deepEqual(visibleSettingsRows(h), [hosts.closest('.settings-field')]); + assert.equal(h.q('#sv-remote-hosts'), hosts, 'search leaves the live controls in place'); + for (const [selector, text] of texts) assert.equal(h.q(selector).textContent, text); +}); + +test('filter beta leaves only its row under General and dims every other navigation item', async t => { + const h = setup(t); + await h.open(); + h.click('sessions'); + filterSettings(h, ' BeTa '); + assert.deepEqual(h.active(), ['general']); + assert.deepEqual(visibleSettingsRows(h).map(row => row.querySelector('.settings-label').textContent), ['Receive beta versions']); + assert.equal(h.q('#settings-page-general h2').textContent, 'General'); + for (const button of h.nav()) assert.equal(button.classList.contains('settings-no-match'), button.dataset.section !== 'general'); + assert.deepEqual([...h.q('#settings-page-general').querySelectorAll('.settings-section')].filter(group => !group.hidden).map(group => group.querySelector('h3').textContent), ['Updates']); +}); + +test('filter reads current descriptions across pages, not ids, values or fuzzy words', async t => { + const h = setup(t); + await h.open(); + filterSettings(h, 'downgrades'); + assert.deepEqual(visibleSettingsRows(h).map(row => row.querySelector('input')?.id), ['sv-receive-beta-versions']); + h.q('#sv-pre-launch').value = 'uniquefiltervalue'; + for (const term of ['uniquefiltervalue', 'sv-receive-beta-versions', 'recbeta']) { + filterSettings(h, term); + assert.deepEqual(visibleSettingsRows(h), [], term + ' must not match'); + assert.deepEqual(h.active(), []); + assert.equal(h.q('.settings-filter-empty')?.hidden, false); + assert.match(h.q('.settings-filter-empty').textContent, /No settings match/); + } + for (const id of ['sv-receive-beta-versions', 'sv-pre-launch']) { + h.q('#' + id).closest('.settings-field').querySelector('.settings-description').append(' currentfiltertext'); + } + filterSettings(h, 'currentfiltertext'); + assert.deepEqual(h.active(), ['general', 'sessions']); + assert.equal(visibleSettingsRows(h).length, 2, 'matching reads live DOM descriptions'); +}); + +test('Escape or clearing restores the current page, rows and navigation without persisting a filter', async t => { + const h = setup(t); + await h.open(); + h.click('keyboard'); + const filter = filterSettings(h, 'beta'); + assert.deepEqual(h.active(), ['general']); + assert.equal(h.w.localStorage.getItem('settingsSection:global'), 'keyboard'); + filter.focus(); + const escape = new h.w.KeyboardEvent('keydown', { key: 'Escape', bubbles: true, cancelable: true }); + filter.dispatchEvent(escape); + assert.equal(filter.value, ''); + assert.equal(escape.defaultPrevented, true); + assert.equal(h.w.document.activeElement, filter); + assert.deepEqual(h.active(), ['keyboard']); + assert.equal(visibleSettingsRows(h).length, 8); + assert.ok(h.nav().every(button => !button.classList.contains('settings-no-match'))); + filterSettings(h, 'beta'); + filterSettings(h, ''); + assert.deepEqual(h.active(), ['keyboard']); + filterSettings(h, 'beta'); + await h.open(); + assert.equal(h.q('#sv-filter').value, ''); + assert.deepEqual(h.active(), ['keyboard']); +}); + +test('filtered navigation keeps results stacked and Tab focuses a visible matching control', async t => { + const h = setup(t); + await h.open(); + filterSettings(h, 'beta'); + const nav = h.click('sessions'); + assert.deepEqual(h.active(), ['general'], 'navigation cannot expose unrelated rows while filtering'); + nav.dispatchEvent(new h.w.KeyboardEvent('keydown', { key: 'Tab', bubbles: true, cancelable: true })); + assert.equal(h.w.document.activeElement, h.q('#sv-receive-beta-versions')); + filterSettings(h, ''); + assert.deepEqual(h.active(), ['sessions']); +}); + +test('a filtered global row saves through the same form and filtering is never a dirty edit', async t => { + const h = setup(t); + await h.open(); + const toggle = h.q('#sv-receive-beta-versions'); + filterSettings(h, 'beta'); + assert.equal(h.q('#sv-unsaved').textContent, '', 'filter is not a setting'); + assert.deepEqual(visibleSettingsRows(h), [toggle.closest('.settings-field')]); + assert.equal(h.q('#sv-receive-beta-versions'), toggle); + toggle.click(); + h.q('#sv-save-btn').click(); + await settle(); + assert.equal(h.saved.global.receiveBetaVersions, true); + assert.equal(Object.hasOwn(h.saved.global, 'filter'), false); + assert.equal(h.q('#sv-unsaved').textContent, ''); + filterSettings(h, 'other text'); + assert.equal(h.q('#sv-unsaved').textContent, ''); +}); + +test('project filtering reveals Launch settings, preserves inheritance and saves overrides', async t => { + const h = setup(t); + await h.open('project'); + h.click('project'); + filterSettings(h, 'pre-launch'); + assert.deepEqual(h.active(), ['launch']); + assert.deepEqual(visibleSettingsRows(h).map(row => row.querySelector('.settings-label').textContent), ['Pre-launch Command']); + const field = h.q('#sv-pre-launch'); + assert.equal(field.disabled, true); + h.q('[data-field="preLaunchCmd"]').click(); + field.value = 'echo filter'; + field.dispatchEvent(new h.w.Event('input', { bubbles: true })); + h.q('#sv-save-btn').click(); + await settle(); + assert.equal(h.saved['project:/project'].preLaunchCmd, 'echo filter'); + filterSettings(h, ''); + assert.deepEqual(h.active(), ['project']); + assert.equal(h.q('#sv-archive-btn').closest('[hidden]'), null); +}); + +test('Archived retains its independent filter and selection when settings filtering is cleared', async t => { + const h = setup(t); + h.saved.global = { hiddenProjects: ['/alpha', '/beta'] }; + await h.open('global', { section: 'archived' }); + const archivedFilter = h.q('.archived-filter'); + archivedFilter.value = 'beta'; + archivedFilter.dispatchEvent(new h.w.Event('input', { bubbles: true })); + const selection = h.q('.archived-row input[type="checkbox"]'); + assert.ok(selection); + selection.click(); + const archived = h.q('#settings-page-archived'); + const archivedMarkup = archived.innerHTML; + const descendants = [...archived.querySelectorAll('*')]; + const mutations = new h.w.MutationObserver(() => {}); + mutations.observe(archived, { attributes: true, childList: true, subtree: true }); + t.after(() => mutations.disconnect()); + const assertArchivedUntouched = () => { + assert.equal(archived.innerHTML, archivedMarkup, 'filter must not add hidden attributes inside Archived'); + assert.deepEqual([...archived.querySelectorAll('*')], descendants, 'Archived keeps its DOM nodes'); + assert.equal(mutations.takeRecords().filter(record => record.target !== archived).length, 0, 'only the Archived page itself may change visibility'); + }; + filterSettings(h, 'beta'); + assertArchivedUntouched(); + assert.deepEqual(h.active(), ['general'], 'Archived is excluded from settings matches'); + assert.equal(h.q('#sv-unsaved').textContent, ''); + filterSettings(h, ''); + assertArchivedUntouched(); + assert.deepEqual(h.active(), ['archived']); + assert.equal(h.q('.archived-filter'), archivedFilter); + assert.equal(archivedFilter.value, 'beta'); + assert.equal(selection.checked, true); + assert.equal(h.w.document.querySelectorAll('.archived-row').length, 1); + assert.match(h.q('.archived-row').textContent, /beta/); +}); + +test('filter layout hides unmatched flex rows and stacks results in a shared scrolling area', () => { + const css = fs.readFileSync(path.join(root, 'public/style.css'), 'utf8'); + assert.match(css, /\.settings-layout \[hidden\]\s*\{\s*display:\s*none/); + assert.match(css, /\.settings-filtering \.settings-pages\s*\{[^}]*overflow-y:\s*auto/); + assert.match(css, /\.settings-filtering \.settings-page\s*\{[^}]*height:\s*auto/); + assert.match(css, /\.settings-nav button\.settings-no-match\s*\{[^}]*opacity:/); +}); + test('Codex usage is opt-in under CLI Agents and saving applies it without restart', async t => { const h = setup(t); const applied = [];