Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7539fc8
Add a local control channel and the toolkit command that asks through it
adamsilverstein Nov 13, 2026
f17f7e0
Answer sites.list from the running app and write the toolkit shim
adamsilverstein Nov 13, 2026
3ad154b
Cover the toolkit command with a journey
adamsilverstein Nov 13, 2026
ce94645
Document the toolkit command and the control channel
adamsilverstein Nov 13, 2026
bd4b2bb
Give the Windows control pipe a name that is random at every start
adamsilverstein Nov 13, 2026
2c28fdf
Keep the request limit to the asking, and the shim's switch to the shim
adamsilverstein Nov 13, 2026
f251346
Let the toolkit command read a site's debug log and caught mail
adamsilverstein Nov 13, 2026
32a48da
Bound the mail answer, resolve relative site folders, and prove the l…
adamsilverstein Nov 13, 2026
f60195c
Let a tool start and stop a site's server, once the settings allow it
adamsilverstein Nov 13, 2026
6578d85
Let a tool link tickets, check out pull requests, apply the latest pa…
adamsilverstein Nov 13, 2026
dc4ec61
Document the toolkit command in full, and ship a skill that teaches a…
adamsilverstein Nov 13, 2026
c3d5a76
Wait for a site's row, read both patch lists, and stop a silent refus…
adamsilverstein Nov 13, 2026
3e0a157
Merge trunk, and wait for the control channel by the clock in the wir…
adamsilverstein Nov 13, 2026
3dcebdb
Merge trunk, and route the offered issue through the same link a tool…
adamsilverstein Nov 13, 2026
32bc709
Move the new suites and the skill to pull requests stacked on this one
adamsilverstein Nov 13, 2026
97cbf55
Report an app that could not be opened instead of waiting a minute fo…
adamsilverstein Nov 16, 2026
3edd6f4
Keep a backslash in a site's path a separator on Windows only
adamsilverstein Nov 16, 2026
0ce1e5e
Escape what a shell would expand in the toolkit shim's arguments
adamsilverstein Nov 16, 2026
58fdb1d
Say the app is closed when an AppImage's toolkit command is run witho…
adamsilverstein Nov 16, 2026
a830825
Answer a switch with its rebuild's refusal when the rebuild did not end
adamsilverstein Nov 16, 2026
7c8e086
Read a new site's status again once its first build has ended
adamsilverstein Nov 16, 2026
af82378
Refuse a second site while the first is starting, before the page has…
adamsilverstein Nov 16, 2026
6e71386
Turn a tool away from a site whose page is asking a question
adamsilverstein Nov 16, 2026
68f8283
Keep waitForSetup's doc block on the function it describes
adamsilverstein Nov 16, 2026
a37bc84
Merge remote-tracking branch 'origin/trunk' into HEAD
adamsilverstein Nov 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ When asked to add an existing pull request to an existing stack, preserve its co
- **Child processes run on Electron's own Node, not the system Node.** `npm install`, `npm run <script>`, and the Playground server are spawned on Electron's binary with `ELECTRON_RUN_AS_NODE=1` — this is the mechanism behind "zero prerequisites." *Which* binary is `nodeExecPath()` in `src/node-shims.cjs`, the one resolver used by both the shims `ensureNodeShimDir` writes and the runner spawn in `src/main.js`: `process.execPath` on Windows and Linux, and on macOS the `Contents/Frameworks/… Helper.app` binary beside it when that exists, falling back to `process.execPath` when it does not. The Helper is the same Electron, and its `Info.plist` is the only one of the two that carries `LSUIElement`; without it, any child that assigns `process.title` (npm does, and so does every Gutenberg build worker) gets checked in with LaunchServices under the main bundle and earns a Dock tile (#518). On Windows this requires shimming `node`/`npm`/`npx` into `PATH` so child `npm` processes can find a `node` binary at all. On macOS, a signed Electron removes `NODE_OPTIONS` from any process the app did not start itself, which includes everything launched through the bash shims, so those shims split `NODE_OPTIONS` the way Node does, pass it on as arguments and unset the variable, so unsigned builds do not apply it twice and signed ones print no `node_main.cc` warning for it (#525). Only the shim's own child gets the options; what that child starts inherits no `NODE_OPTIONS`.
- **Git has no host dependency.** The app ships its own Git binary via `dugite` (#364), unpacked from `app.asar` and resolved only through `src/git-binary.cjs`, which also builds the environment it runs with (host system and global config off, prompting off, no `GIT_*` variable inherited from the host and nothing from a Node child). `require('dugite')` lives in that one file; `src/git-run.cjs` is the only place the binary is spawned, and `src/git-read.cjs` holds every read and its parser. Spawning a `git` found on `PATH`, or calling dugite's `GitProcess` from anywhere else, is a regression. As of #384 every read outside the write flows (status, branches, history, blobs, the patch walk) runs on the bundled binary, and since #385's first flow so does the new-site clone (`src/git-clone.cjs`: partial, `--filter=blob:none`, repo config written at clone time); Ticket branches (park, start, switch, delete, and the move onto the current trunk, one three-way `merge-tree` of the single WIP commit read in `src/git-read.cjs` and committed by the primitives) write through `src/git-write.cjs`, one Git command per primitive, with the checkout's progress read by `src/git-progress.cjs`, the single parser of Git's human-facing lines that the clone shares; the trunk update (`src/trunk-update.js`: fetch from the site's own `origin`, update-ref, forced checkout; the two discards: forced checkout plus `clean -fd`) writes through the same primitives, with `streamGit` in `src/git-run.cjs` as the one runner for the commands that report progress; patch apply and revert (`src/patch-apply.js`) run on `git apply` through the same primitives, all or nothing by Git's own rule, with the Trac path rewrite, the per-hunk wording of a refusal and the snapshot that undoes a half-written apply kept in JS and never writing on their own. A pull request is checked out, not applied (#458): `src/pr-checkout.js` fetches `refs/pull/N/head` from the site's own `origin` through `fetchBranch`, puts `pr/N` at it and switches through `ticket-branches.js`; `appliedPatch` remains the record for Trac attachments and local `.diff`/`.patch` files only. Since #386 the app has one Git engine: `isomorphic-git` is gone from `package.json` (it reaches the bundle only as a transitive dependency of `@wp-playground/storage`), and every test fixture is built by the bundled binary. The suites that used to build theirs with the old engine go through the fixture layer in `tests/unit/helpers/git.cjs`; the suites that cover a single primitive (`git-read`, `git-write`, `git-clone`, `git-run`, the fetch suite) still call the binary directly, because a fixture built by the layer above the primitive under test would beg the question. A site the old engine cloned (shallow, no `remote.origin.promisor`) is detected by `isLegacySite` in `src/git-read.cjs` and refused by every write handler in `main.js` through `legacySiteBlock` (`code: 'legacy-site'`); only reads, the patch export of the checked-out branch, opening a pull request and deletion still work there, and the sentence both sides show lives in `src/renderer/legacy-site.cjs`. A merge, rebase, cherry-pick, revert or three-way apply started outside the app and left unfinished is read by `mergeInProgress` in `src/git-read.cjs` (the `u` records of `status --porcelain=v2` plus the head files and rebase directories `git status` itself reads under `.git`, never remembered in process) and refused by `mergeInProgressBlock` (`code: 'merge-in-progress'`) in front of the trunk update, both discards, linking and unlinking a ticket, switching, the move onto trunk, applying and reverting a patch, and deleting the ticket that is checked out; the sentence naming the files and the terminal commands that end it lives in `src/renderer/merge-in-progress.cjs`, and the app offers no action of its own for it (#352). Only porcelain-stable output (`--porcelain=v2`, `-z`, explicit `--format`) is ever parsed. Patch/diff generation is done by hand in `main.js`, not `git diff`: one status scan against the branch point each ticket recorded (#108), nothing staged, and `/dev/null` naming whichever side of an addition or a deletion does not exist — the app reads its own patches back when a mentor applies one, and that filename is the only thing its parser reads an add or a delete from (#85).
- **`electron-store` is the only persistence layer** — no separate DB. It holds the site registry and per-site metadata; treat it as the single source of truth for "known sites." **Nothing may yield between reading the store and writing it back.** The `get` and `set` are synchronous, so the event loop is the only thing serialising writers, and it only serialises them while nothing awaits in between. A writer that reads, awaits anything, and then writes what it read hands back a snapshot another writer has moved on from, and that writer's change is gone (#172). The value that made it matter is a ticket branch's recorded base, the one thing a branch cannot recompute. Handlers that write a fixed set of top-level keys do this inline and are fine as they are; a change that has to be computed from the record, or that replaces a nested map such as `branches`, goes through `changeSiteMeta` in `src/main.js`, which takes a function of the record and applies it at the moment of the write. Computing that value from an earlier read is the bug, whichever helper writes it.
- **A tool outside the window reaches the app through one door, the control channel (#764).** `src/control-channel.cjs` listens on a Unix socket in the profile directory (a named pipe on Windows, with a name that is random at every start, since pipe names are shared by every account on the machine and a predictable one could be taken first), started in `whenReady` after the single-instance lock, which is what makes removing a stale socket file safe. It is deliberately not a TCP port: a loopback port can be reached from any page the contributor has open, the exposure `src/deep-link.cjs` keeps to one verb, and the socket file is the user's alone (mode 0600). One request per connection, a line of JSON each way. What can be asked for is the `controlActions` map in `src/main.js` and nothing else, and `ipc-wiring` pins its keys so that a new action is a reviewed change. The reads (`sites.list`, `site.log`, `site.mail`) are answered by main, shaped by `src/control-sites.cjs`, whose `resolveSite` turns the site a tool named into a path out of the registry, so no path a tool sends is ever opened. **An action that changes a site is not carried out by main.** It goes through `windowAction`, which refuses unless the `toolAccess` setting is on (off by default, in Settings → Tools), and then hands the request to the window (`src/control-window.cjs` is the waiting, `src/renderer/control-requests.cjs` what the window does with it). The window carries it out with the function its own button calls, because the terminal's lock, the build watch, and the install and build after a change are sequenced in the renderer and nowhere else: a second caller in main would do the Git and none of that, and the page would not know. So a new write action is an entry in `SITE_ACTIONS` or `APP_ACTIONS` naming an existing press and how its end is read, never a second implementation of a flow, and what it answers with comes from `site:status`, not from the page's copy of it. Nothing that loses or sends work is offered: no delete, discard, revert, Trac attachment or pull request. The `toolkit` command is `src/cli.cjs`, Node built-ins only, run through a shim the app writes to `<userData>/bin` at every start with `cliShim` and `nodeExecPath()`, so it needs no Node on the host; the shim passes the endpoint, and, from a packaged app only, how to open the app when it is closed.
- Long-running child-process output (installs, scripts, server) is streamed to the renderer via correlated IDs (`installId`/`runId`), not returned synchronously — expect async event handlers, not return values, when tracing that flow.
- **Electron is pinned at 43.6.0 and must not move above it until the upstream V8 bug is fixed.** Electron 43.7.0 and later crash the Playground server child with `SIGBUS` (`KERN_PROTECTION_FAILURE` on a `V8Worker` thread) about a second after "Start development server" on Apple Silicon macOS; 43.7.5 crashes 5/5 and 43.6.0 starts 5/5 in a bisect of `src/server-runner.js` run directly on each Electron Helper as Node. Plain Node 24.21.0 and both Playground CLI versions in range are unaffected, and the crash disappears only under V8's `--liftoff-only`, so it lives in the optimizing WebAssembly compiler of the V8 backports 43.7.0 carries (electron/electron#53766). Nothing that runs on a pull request starts the Playground server on Electron's bundled Node: the packaged smoke never clicks "Start development server", the journeys that do (in `mail.spec.js`, `logs.spec.js`, `dev-server.spec.js`, `site-links.spec.js`, `auto-start.spec.js` and `i18n.spec.js`) replace the handler that starts the server with a stub, and only the manual-dispatch `real-setup.yml` workflow starts it for real. So an Electron bump that passes CI can still kill the dev server. Before moving the pin, start the dev server on an Apple Silicon Mac with the candidate version, or run `real-setup.yml` on it, and say which in the PR.

Expand Down
1 change: 1 addition & 0 deletions docs/.vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default defineConfig( {
{ text: 'Step debugging with Xdebug', link: '/guide/step-debugging' },
{ text: 'Catching outgoing email', link: '/guide/mail' },
{ text: 'Browsing the database', link: '/guide/database' },
{ text: 'The toolkit command', link: '/guide/toolkit-command' },
],
},
{
Expand Down
110 changes: 110 additions & 0 deletions docs/guide/toolkit-command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# The toolkit command

::: warning Experimental
This is new ([#764](https://github.com/WordPress/contributor-toolkit/issues/764)). The command, its output and where it lives may all change.
:::

The app writes a small command, `toolkit`, that a script, a Contributor Day facilitator or an AI coding tool with a terminal can run to work with your sites: find them, create one, link a ticket, apply the latest patch, start the server, and read what the site logged and mailed. A tool then works in the checkout the app made, with the app's own Git, Node and server, instead of building an environment of its own beside it.

It needs nothing installed. Like the app's own `npm`, the command runs on the Node that ships inside the app.

![An AI coding tool asked to set up a site for a Trac ticket, running the toolkit command four times](/images/toolkit-ai-tool-example.png)

*An illustration of an AI coding tool with a terminal using the command. The commands and what they print are the real ones.*

## Giving a tool the command

Open **Settings**, choose **Tools**, and press **Copy command**. Paste what it copied to your tool: it is the command's full path, in quotes, since the path has a space in it. On Windows the file is `toolkit.cmd`.

![The Tools tab of the settings, with the command's path, a Copy command button and the switch that lets tools change sites](/screenshots/settings-tools.png)

## Letting a tool change your sites

Out of the box the command can only read. To let it change a site, turn on **Let tools on this computer change my sites** in that same tab.

| Without the switch | With the switch |
| --- | --- |
| List your sites | Create a site |
| Read a site's `debug.log` | Link and unlink a ticket or issue |
| Read a site's caught mail | Apply the latest patch, check out or leave a pull request |
| | Update to the latest trunk |
| | Run `npm install` and the site's npm scripts |
| | Start and stop the dev server |

A tool can never delete a site, discard your changes, attach a patch to Trac or open a pull request. Those stay with you, in the window.

Everything a tool changes is done by the app's window, as if you had pressed the button yourself, so you see it happen: the terminal shows the build, the ticket card shows the ticket. When the app has a question, such as what to do with edits you made on trunk, it asks it in the window, and the command tells the tool so.

## The commands

Every command takes `--json` for an answer a tool can read, and exits with a status other than zero when it fails. With `--json` a failure is still printed as JSON, with `"ok": false`, a `code` and an `error` sentence.

A site is named by its path, by any folder inside it, or by its name in the app. Leave the site out and the command uses the site the current folder is in, which is what a tool working in the checkout wants.

Each command waits until what it asked for has ended. For a new site, an update or a build that is minutes. If the installed app is closed, the command opens it first. On Linux it does not: the app is an AppImage, which the command cannot start, so open the app before running a command.

### Reading

| Command | What it does |
| --- | --- |
| `toolkit sites` | Lists your sites: path, project, linked ticket or issue, branch, checked-out pull request, and the dev server's address. |
| `toolkit log [site] [--lines N]` | Prints the end of the site's WordPress `debug.log`, the file the [Logs panel](./logs-and-debugging) shows: the last 100 lines unless told otherwise, never more than 1000 or the last 256 KB. |
| `toolkit mail [site]` | Prints the mail the site sent and the app caught, as the [Mail panel](./mail) lists it: the newest 50, text only. |

### Changing a site

| Command | What it does |
| --- | --- |
| `toolkit create <name> [--project core\|gutenberg] [--folder <path>]` | Creates a site and waits until it is installed and built. Without `--folder` it goes in the folder for new sites from the settings. |
| `toolkit ticket link <ticket> [site] [--carry]` | Links a Trac ticket or a GitHub issue, by number or address, and switches to its branch. `--carry` brings edits made on trunk into a new ticket. |
| `toolkit ticket unlink [site]` | Unlinks the ticket and goes back to trunk. The ticket's work stays on its branch. |
| `toolkit patch apply [site]` | Applies the latest patch on the linked ticket: its newest attachment, or its newest pull request, whichever the app marks **Latest**. |
| `toolkit pr checkout <number> [site]` | Checks out a pull request. |
| `toolkit pr leave [site]` | Leaves the pull request and goes back to where the site was. |
| `toolkit update [site]` | Updates to the latest trunk, then installs and builds as needed. |
| `toolkit install [site]` | Runs `npm install`. |
| `toolkit run <script> [site]` | Runs one of the scripts [the terminal](./terminal) allows, such as `build`, and prints the end of its output. |
| `toolkit server start [site]` | Starts the dev server and prints its address. |
| `toolkit server stop [site]` | Stops the dev server. |

`toolkit run` refuses `watch` and `dev`: they never end, and would hold the site's terminal. On a WordPress Core site, starting the server starts the build watch, so edits are compiled as they are saved. On a Gutenberg site that is already built, the server starts without the watch: run `toolkit run build` after editing, or start the watch in the window.

## An example

Setting up a site for a ticket and trying its latest patch, the way an AI tool would:

```
toolkit create "Ticket 65930"
toolkit ticket link 65930 "Ticket 65930"
toolkit patch apply "Ticket 65930"
toolkit server start "Ticket 65930"
```

The last command prints the site's address. From there the tool can edit the files under the site's folder, run `toolkit run build`, and read `toolkit log` to see what PHP said.

## When the app refuses

The `code` says why, so a tool can decide what to do next:

| Code | What it means |
| --- | --- |
| `tools-not-allowed` | The switch in **Settings → Tools** is off. It is yours to turn on. |
| `unknown-site`, `ambiguous-site` | No site, or more than one, matches what was named. `toolkit sites` lists them. |
| `busy` | The site is in the middle of something: a build, an update, a switch. Try again when it has finished. |
| `site-not-open`, `window-not-ready`, `window-closed` | The app's window was not there to do it: it was closed, reloaded, or the site is still being created or deleted. Try again. |
| `not-built` | The site's setup has not finished, so there is nothing to serve. Run `toolkit install`, then `toolkit run build`. |
| `unsupported-script` | The script is not one the terminal allows for this site, or is a watch. |
| `no-ticket`, `already-applied` | `patch apply` needs a linked ticket, and no patch applied already. |
| `is-pull-request` | The number given to `ticket link` on a Gutenberg site is a pull request, not an issue. Use `pr checkout`. |
| `legacy-site`, `merge-in-progress` | The checkout is in a state the app does not change: made by an old version of the app, or with a merge or rebase left unfinished from a terminal. The site's page says what to do. |
| `dirty-trunk`, `dirty` | Edits in the checkout would be left behind or reset. The app is asking what to do with them in its window. |
| `no-latest-patch` | The ticket has no patch, or two are too close in time for the app to call one the latest. Choose one in the window. |
| `trac-failed`, `patches-failed` | Trac or GitHub could not be read. If Trac asked for a human check, answer it in the app's window. |
| `timed-out` | The app is still working on it. Look at its window before asking again. |
| `script-failed`, `setup-failed`, `update-failed`, `apply-failed`, `server-failed` | The step ran and failed. The error says which, and the app's terminal has the output. |

## Who can use it

Programs on this computer that can read the app's data folder, which is yours. The command talks to the app over a local socket in that folder, not over the network, so a web page or another computer cannot reach it. On Windows it is a named pipe whose name changes each time the app starts and is only written into that folder.

The switch is your consent, not a lock. It is kept in the app's settings file in that same folder, so it stops a tool that asks the app, which is what a well-behaved tool does; it does not stop a program that is already able to change your files. With the switch on, `toolkit create --folder` makes a site in whatever folder the tool names.
Binary file added docs/public/images/toolkit-ai-tool-example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading