Skip to content

soderlind/vs-local-wp

Repository files navigation

LocalWP Assistant — VS Code Chat Participant

A GitHub Copilot Chat participant (@localwp) that lets you query and manage your Local by Flywheel WordPress sites directly from VS Code.

Features

  • Auto-detects the active site from your open file or workspace root
  • Direct MySQL connection — no WP-CLI overhead for read queries
  • WP-CLI for everything else, using Local's bundled PHP and MySQL binaries
  • LM-powered answers — free-form questions are answered in human-readable Markdown, not raw JSON
  • Follow-up suggestions after every response
  • Remembers your site — pick once, reuse for the session
  • Cross-platform — macOS, Windows, and Linux

Requirements

Install

Install from the VS Code Marketplace, or search for LocalWP Assistant in VS Code Extensions.

Development

git clone https://github.com/soderlind/localwp-assistant
cd localwp-assistant
npm install
npm run compile

Press F5 in VS Code to launch the Extension Development Host, or package with vsce package.

Usage

Open Copilot Chat and type @localwp followed by your question.

Slash commands

Command Description
@localwp /sites List all Local sites with running status
@localwp /plugins List active plugins (fast — direct DB)
@localwp /options siteurl Fetch options matching a pattern
@localwp /db SELECT ... Run a raw read-only SQL query

Free-form examples

@localwp What plugins are active?
@localwp What is the siteurl?
@localwp List all users
@localwp What WordPress version is running?
@localwp Show me all transients matching _site_transient_%
@localwp --site=my-other-site What theme is active?

Targeting a specific site

If multiple sites are running, the extension auto-detects from your open file. To override:

@localwp --site=my-site-name What plugins are active?

If auto-detection can't determine the site, a QuickPick will appear. Your choice is remembered for the session — subsequent messages reuse the last selected site automatically. Use --site=<name> to switch.

Architecture

src/
├── extension.ts                  ← Registers the chat participant
├── localwp/
│   ├── sites.ts                  ← Reads sites.json + site-statuses.json
│   ├── mysql.ts                  ← Direct MySQL connection via socket/TCP
│   └── wpcli.ts                  ← Runs WP-CLI via Local's bundled PHP
└── participant/
    ├── handler.ts                ← Routes requests to MySQL or WP-CLI
    └── siteSelector.ts           ← Auto-detects or QuickPicks the target site

Why direct MySQL?

On macOS/Linux, Local exposes a MySQL Unix socket per site. On Windows, it exposes a TCP port. Connecting directly with mysql2 is much faster than spinning up a PHP process for WP-CLI — especially for simple reads like listing plugins or fetching options.

WP-CLI is still used for write operations and anything that needs WordPress context (hooks, filters, PHP eval).

License

MIT

About

A GitHub Copilot Chat participant (@Localwp) that lets you query and manage your Local by Flywheel WordPress sites directly from VS Code.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors