AI assistant as the shell's ⌘K palette (Commands + Ask AI) - #352
Merged
Conversation
Collapse WordPress 7.0's ⌘K command palette and our assistant into one entry point, behind the (renamed) opt-in toggle "Override command palette with AI assistant" (off by default, provider-gated). - features.ts: relabel the toggle + hint to the override framing. - Remove the separate "Ask AI" admin-bar node + its CSS/JS wiring; when the override is on, a capture-phase click on Core's #wp-admin-bar-command-palette icon opens the assistant. Drop the now-dead desktop-mode-ai-enabled body class. - palette-registry: only claim ⌘K when a palette is registered, so Core's command palette keeps working when the override is off. - run_command tool: the search loop offers a single run_command tool; on a call it returns a tool_call the browser dispatches by fuzzy-matching the command registry (matchCommandByIntent/runCommandByIntent) and running the best match — so the assistant can run any palette command (Core's + plugins'), not just the read-only abilities. Wired into both the interactive assistant and ask(). Verified: action queries -> run_command tool_call; content/ability/navigation queries unchanged. Tests for the matcher + runner. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add an architecture subsection covering the "Override command palette with AI assistant" toggle, the single ⌘K entry point (keyboard suppression + Core icon interception, no Ask AI button), and the run_command tool that lets the assistant run any palette command via the browser registry. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
VERSION was pinned at 0.8.0-pwa-5 while the plugin is at 0.9.4, so the SW kept serving precached bundles from an old cache bucket. Bump to 0.9.4-pwa-6 so the SW purges the stale caches and re-precaches the current bundles — otherwise JS-only changes (like the command-palette override) don't reach PWA-enabled browsers until an unrelated SW change ships. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
`_showResult()` dispatches the matched command synchronously, but it runs inside the search flow — where `_isSearching` is still true (the stream's `finish()` and the fetch path's `finally` reset it only after `_showResult` returns). `_runCommand()` bails out early while `_isSearching`, so the command never ran and the assistant sat on "Thinking…" forever. Defer the dispatch to a microtask so it fires after the search flow has reset its state, letting the command run cleanly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…stant" In the desktop shell Core's command palette is suppressed everywhere (its commands are harvested and its callbacks hard-navigate out of the window model), so when the assistant is off there is no palette behind ⌘K and Core's admin-bar ⌘K icon was a dead button. - Suppress Core's ⌘K unconditionally in the shell (was: only when a palette is registered). `cyclePalettes()` no-ops when nothing is registered, so ⌘K simply does nothing when the assistant is off. - Hide Core's `#wp-admin-bar-command-palette` icon unless the assistant is active, via a `desktop-mode-ai-active` body class (server-rendered in body-classes.php to avoid a flash, kept live by syncAiAssistant()). - Rename the toggle back to "AI assistant" — the "override" framing no longer fits now that off means "no palette", not "Core's palette". Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes the AI assistant the desktop shell’s single ⌘K command-palette entry point by suppressing WordPress Core’s palette behavior inside the shell, routing ⌘K (and Core’s ⌘K admin-bar icon) to the assistant when enabled, and adding a run_command tool so the assistant can execute command-palette actions via the existing command registry/window model.
Changes:
- Add a
run_commandAI tool and client-side intent → command matching/execution, with unit tests. - Switch UI entry points: remove the old “Ask AI” admin-bar button, hide Core’s ⌘K icon when the assistant is off, and intercept Core’s ⌘K icon click when the assistant is on.
- Update docs and UI copy to reflect the assistant-as-palette behavior.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/vitest/run-command.test.ts | Adds unit tests for intent matching and run_command dispatch behavior. |
| src/settings/sections/features.ts | Updates the Features toggle description to describe ⌘K entry and command-running. |
| src/pwa/sw.ts | Bumps the service worker cache version string. |
| src/palette-registry.ts | Clarifies/justifies unconditional Cmd+K suppression inside the shell. |
| src/desktop.ts | Registers/unregisters the assistant palette and intercepts Core’s ⌘K icon click when active. |
| src/commands.ts | Introduces matchCommandByIntent() and runCommandByIntent() for natural-language command dispatch. |
| src/ai/ask.ts | Handles __run_command__ tool calls by running intent-matched commands locally. |
| src/ai-assistant/impl.ts | Adds handling for answer_type: 'tool_call' to run __run_command__ intents via the command path. |
| includes/render/body-classes.php | Server-renders the desktop-mode-ai-active body class to prevent icon flash and match live toggling. |
| includes/ai-copilot/search.php | Adds the run_command tool definition and server short-circuit to answer_type: 'tool_call'. |
| includes/admin-bar.php | Removes “Ask AI” button styling and adds CSS to hide Core’s ⌘K icon when the assistant is off. |
| docs/architecture.md | Documents the assistant-as-palette architecture and the run_command flow. |
| assets/js/admin-bar.js | Removes the old “Ask AI” button click handler. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ick guard
- runCommandByIntent/_runCommand now pass the raw intent as args so
argument-taking commands can parse it (navigation/action commands ignore it).
- runCommandByIntent wraps cmd.run in try/catch, returning a structured
{ error } instead of rejecting the tool-call path.
- matchCommandByIntent tokenizes with a Unicode-aware regex (\p{L}\p{N}) so
localized labels and non-English intents still match.
- The admin-bar click interceptor guards `e.target instanceof Element` before
calling closest(), since MouseEvent.target isn't always an Element.
- Add tests for args pass-through, thrown-command handling, and non-ASCII
matching.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…_command Rework the ⌘K surface so it inherits the command palette and layers AI on top, instead of overriding the palette with an auto-executing AI tool. - The assistant is always the shell's ⌘K palette (Core's stays suppressed). Commands mode is a command palette over the shared registry (works with no AI); Ask AI mode answers plain-language questions and suggests links/commands the user clicks — it never auto-runs anything. - A header mode switch flips Commands ↔ Ask AI (replaces the `/` shortcut), shown only when a provider is configured and the "AI assistant" toggle is on. The toggle sets the default mode on open. - Each mode keeps its own input draft; the last AI answer is restored when returning to Ask AI. Clicking outside the panel closes it. - Remove run_command (server tool + dispatch + client matcher + tests): the AI no longer executes commands. - Fix "View site" (and other pure-JS shell actions) closing the assistant. - Revert the icon-hiding + the PWA cache-version bump (unrelated churn). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
|
@mmtr sorry for the poor coms with you around how to progress with the task 😆 My bad. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
WordPress 7.0 added its own ⌘K command palette, which collided with our separate "Ask AI" button — two ⌘K affordances, and Core's palette can't work inside the desktop shell (it hard-navigates out of the window model). This makes our assistant the single ⌘K surface: it inherits the command palette and adds AI on top.
What changes
Testing
🤖 Generated with Claude Code