Skip to content

feat(web): command palette backed by a single command registry (#224) - #233

Merged
falbany merged 2 commits into
mainfrom
feat/224-command-palette
Nov 23, 2026
Merged

falbany merged 2 commits into
mainfrom
feat/224-command-palette

Conversation

@falbany

@falbany falbany commented Nov 23, 2026

Copy link
Copy Markdown
Owner

What does this PR do?

Implements the command palette (#224, closed by the second commit's follow-up). Every user action is now described once in a command catalog (useAppCommands) and consumed three ways:

  • useGlobalShortcuts becomes a thin dispatcher — it owns only the order of the guards (Escape → modal guard → pre-guard focus helpers → control/input guards → registry lookup); which key does what lives in the registry. 45 commands total.
  • New CommandPalette (Ctrl+Shift+P, plus a visible Commands button in the status bar): fuzzy-filtered commands grouped by registry group, a Recent section persisted in localStorage (profiles-recent-commands), quick-open of the loaded files by name, disabled commands listed dimmed with their reason (never hidden), fixed-height layout, useModalA11y focus/Escape semantics.
  • ShortcutsModal is removed (second commit): the palette lists every command together with its binding, so a separate shortcuts sheet repeated the same registry view one click away. ? and Ctrl+/ keep working as alternative bindings of the palette command. The modal's only unique content — the workflow-gate Y/S/N/↵ keys — is already embedded in the gate buttons (WorkflowRunnerModal's KeyHint), so nothing is lost at the point of use.

Supporting moves: the launch-with-arguments dialog leaves ContextMenu as a reusable LaunchArgsDialog (reachable from the palette too), "Copy Directory" gets a real App handler instead of inline clipboard code, and fileExtension/parentDirectory consolidate into utils/fileProperties.

Behaviour preservation

  • Shortcut key specs use tri-state modifiers (true/false/undefined) so the old handler's per-key Shift handling is preserved bit-exact: Shift still disambiguates L/K/T/B, and Ctrl+Shift+K stays free.
  • The dispatcher keeps the subscription-time capture ruling from the Web UI: decompose App.tsx (1803 lines) into focused hooks + components #148 PR-3 refactor (the double-Ctrl+R staleness profile) — the discriminating tests survive, plus a new one adapted to the registry shape.
  • All pre-existing App-level characterization tests pass through the new dispatcher unchanged.

A matcher bug the App-level tests caught

The first fuzzy scorer used greedy leftmost alignment: for the query theme it ranked "Open the camera barcode scanner" above "Switch theme", and matched long paths as accidental subsequences (readme → …dist-info/METADATA). Rewritten as a small best-alignment dynamic program; relative paths now only match literally; the Commands/Files sections are ordered by their best score. Regression tests pin both cases.

Closes #224

Type of change

  • ✨ New feature (non-breaking change that adds functionality)
  • ♻️ Refactor (no behavior change) — all pre-existing shortcut behaviour preserved

Pre-commit checklist

  • Python gates untouched by this PR (web-only change; CI runs ruff/pylint/pytest on main-tip sources)
  • Web suite passes (vitest, 485 tests / 37 files) and tsc -b is clean
  • No TODOs left
  • No AGENTS.md tree change needed (no new directories; web tests stay colocated)
  • dist/ rebuilt and committed per CONTRIBUTING

Testing

  • New unit/component suites (+80 tests vs main): utils/commands.test.ts (key matching incl. tri-state modifiers, no-clash guard, best-alignment fuzzy scoring, ranking/recency, file scoring), useAppCommands.test.tsx (catalog guarantees: unique ids, truthful disabled states, every binding displayable, no key claimed twice; each key → its callback with exact original arguments; navigation computes; context-menu anchor math), CommandPalette.test.tsx (18 component tests), useRecentCommands.test.ts, App.commandPalette.test.tsx (7 App-level wiring tests against the fully mocked API client), plus a rewritten useGlobalShortcuts.test.tsx (dispatcher guards + staleness profile).
  • Real-browser verification (production bundle, profiles --server-only): palette open/run/recents in both themes, quick-open ordering after the relevance fix, shortcuts via ?, legacy focus shortcuts, context-menu → args-dialog flow, status-bar button. Verification server stopped afterwards.

Screenshots

Verified in a real browser in both themes (dark and light): grouped commands with the active row highlighted, key hints in each row and in the footer (↑↓ Move · Enter Run · Esc Close), disabled commands dimmed with their reason, Recent section on reopen.

Reviewer note: dist/ is committed and the PWA precaches the bundle — after checkout, refresh twice (or unregister the service worker) to see the new UI.

Every user action is now described once in a command catalog
(useAppCommands) and consumed three ways:

- useGlobalShortcuts becomes a thin dispatcher: guard order only; which
  key does what lives in the registry. Key specs carry tri-state
  modifiers so the per-key Shift handling of the old handler is
  preserved bit-exact, and the subscription-time capture keeps the
  original staleness profile (the double-Ctrl+R quirk still pinned).
- ShortcutsModal renders its table from the registry, so a shortcut can
  no longer be advertised without being bound (#56 drift).
- New CommandPalette (Ctrl+Shift+P, status-bar Commands button):
  fuzzy-filtered commands with recents (localStorage), quick-open over
  the loaded files, disabled commands listed dimmed with their reason,
  fixed-height layout, useModalA11y semantics.

Supporting moves: the launch-with-arguments dialog leaves ContextMenu as
LaunchArgsDialog (reachable from the palette too), Copy Directory gets a
real handler, fileProperties gains fileExtension/parentDirectory reuse.

The fuzzy matcher scores the best alignment via a small DP — a greedy
leftmost pass ranked 'camera barcode scanner' above 'Switch theme' for
the query 'theme', and matched long paths as accidental subsequences
(paths now only match literally).

Web suite 405 -> 489 tests; tsc clean; dist rebuilt. Verified in a real
browser: open/run/recents, quick-open ordering, shortcuts sheet,
legacy focus shortcuts, args dialog, both themes.

Closes #224
…et (#224)

The command palette lists every command together with its binding, so a
separate shortcuts sheet repeated the same registry view one click away.
Removes ShortcutsModal, its status-bar button and the showShortcuts
state; '?' and Ctrl+/ become alternative bindings of
view.commandPalette (open-only, never a toggle).

Nothing is lost at the point of use: the workflow gate buttons already
embed their own Y/S/N/Enter key hints (WorkflowRunnerModal KeyHint),
which was the only content the modal had that the palette does not.

Web suite 489 -> 485 tests (the modal's five replaced by a
palette-bindings test); tsc clean; dist rebuilt.
@falbany
falbany merged commit fef8c50 into main Nov 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(web): command palette (Ctrl+Shift+P) backed by a single command registry

1 participant