Skip to content

AI assistant as the shell's ⌘K palette (Commands + Ask AI) - #352

Merged
mmtr merged 8 commits into
trunkfrom
deskmod-12-command-palette
Jul 17, 2026
Merged

AI assistant as the shell's ⌘K palette (Commands + Ask AI)#352
mmtr merged 8 commits into
trunkfrom
deskmod-12-command-palette

Conversation

@mmtr

@mmtr mmtr commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

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

  • ⌘K always opens the assistant. Core's palette stays suppressed; the "Ask AI" admin-bar button is gone.
  • Two modes:
    • Commands — a command palette over every registered command (navigation, plugin, and the focused window's contextual commands). Works with no AI configured.
    • Ask AI — plain-language questions. It answers and suggests links/commands you click; it never runs anything on its own.
  • A mode switch in the header flips between them (appears only when AI is available).
  • OS Settings → Features → "AI assistant" toggle (off by default): when on, ⌘K defaults to Ask AI; when off, it's the command palette. AI needs a provider configured in Settings → Connectors.
OS Settings → Features Off On
Screenshot 2026-07-16 at 16 28 45 Screenshot 2026-07-16 at 16 21 07 Screenshot 2026-07-16 at 16 29 06

Testing

  1. OS Settings → Features → make sure "AI assistant" is off.
  2. Press ⌘K (Ctrl+K). The assistant opens titled "Site Assistant", with no mode switch.
  3. Empty input lists every command. Type "plugins" → it filters. Pick one → the screen opens.
  4. Open the post editor, select a block, press ⌘K → the block's commands (Duplicate, Delete…) are pinned at the top.
  5. Run "View site" → a new tab opens; return to the original tab → the assistant is still there.
  6. Click outside the panel → it closes.
  7. Configure an AI provider (Settings → Connectors), then turn "AI assistant" on.
  8. Press ⌘K → it opens in Ask AI with an Ask AI / Commands switch in the header.
  9. Ask "which post mentions paella?" → it answers.
  10. Ask "where can I manage plugins?" → it suggests a link; clicking it opens Plugins (nothing opens on its own).
  11. In the post editor, Ask AI mode still shows the block commands, and they stay visible while you type.
  12. Type a question in Ask AI, switch to Commands (input empty), type something, switch back to Ask AI → your question and its answer are restored.

🤖 Generated with Claude Code

Open WordPress Playground Preview

mmtr and others added 5 commits July 14, 2026 16:05
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>
@mmtr mmtr changed the title Override the command palette with the AI assistant Make the AI assistant the shell's ⌘K command palette Jul 14, 2026
@mmtr mmtr self-assigned this Jul 14, 2026
@mmtr
mmtr requested a review from Copilot July 14, 2026 15:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_command AI 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.

Comment thread src/desktop.ts Outdated
Comment thread src/commands.ts Outdated
Comment thread src/commands.ts Outdated
Comment thread src/ai-assistant/impl.ts Outdated
mmtr and others added 2 commits July 14, 2026 17:50
…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>
@mmtr mmtr changed the title Make the AI assistant the shell's ⌘K command palette AI assistant as the shell's ⌘K palette (Commands + Ask AI) Jul 16, 2026
@mmtr
mmtr requested a review from Copilot July 16, 2026 14:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Comment thread src/settings/sections/features.ts
Comment thread src/palette-registry.ts Outdated
Comment thread src/desktop.ts Outdated
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@AllTerrainDeveloper

Copy link
Copy Markdown
Collaborator

@mmtr sorry for the poor coms with you around how to progress with the task 😆 My bad.

@mmtr
mmtr merged commit b40f47f into trunk Jul 17, 2026
11 checks passed
@mmtr
mmtr deleted the deskmod-12-command-palette branch July 17, 2026 07:10
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.

3 participants