Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +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; it holds reads only (`sites.list`, shaped by `src/control-sites.cjs`), and `ipc-wiring` pins its keys so that a new action is a reviewed change. An action that writes needs the gates the IPC handler for the same change has. 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 the CLI has no other way to find the app.
- **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; it holds reads only (`sites.list`, `site.log` and `site.mail`, 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), and `ipc-wiring` pins its keys so that a new action is a reviewed change. An action that writes needs the gates the IPC handler for the same change has. 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 the CLI has no other way to find the app.
- 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
20 changes: 19 additions & 1 deletion docs/guide/toolkit-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This is a first step towards letting scripts and AI tools use the app ([#764](https://github.com/WordPress/contributor-toolkit/issues/764)). It can only read so far, and the command, its output and where it lives may all change.
:::

The app writes a small command, `toolkit`, that asks the running app a question and prints the answer. A script, a Contributor Day facilitator or an AI coding tool with a terminal can use it to find the sites the app has set up, where each one is on disk, and which ticket, branch and dev server it has, so the tool can work in the checkout the app already made instead of building its own.
The app writes a small command, `toolkit`, that asks the running app a question and prints the answer. A script, a Contributor Day facilitator or an AI coding tool with a terminal can use it to find the sites the app has set up, where each one is on disk, and which ticket, branch and dev server it has, so the tool can work in the checkout the app already made instead of building its own. It can also read what a site logged and what mail it sent.

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

Expand Down Expand Up @@ -65,6 +65,24 @@ Add `--json` for a form a tool can read:

When something goes wrong the command exits with a status other than zero. With `--json` the reason is still printed as JSON, with `"ok": false`, a `code` such as `not-running`, and an `error` sentence.

## Reading a site's log and mail

Two commands are about one site. Name the site 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.

```
"/path/from/the/log/bin/toolkit" log "my-site" --lines 20
```

`log` prints the end of the site's WordPress `debug.log`, the file the [Logs panel](./logs-and-debugging) shows: the last 100 lines unless `--lines` says otherwise, and never more than 1000 or the last 256 KB of the file. With `--json` the answer also carries the file's `path` and whether it `exists`; WordPress does not write the file until something logs.

```
"/path/from/the/log/bin/toolkit" mail "my-site"
```

`mail` prints the mail the site sent and the app caught, newest first, as the [Mail panel](./mail) lists it: when it was sent, from, to, the subject and the text. Only the newest 50 are printed. With `--json` each mail is an entry of `emails`, and `total` says how many the app has. A text longer than 20,000 characters is cut, and `textTruncated` says so. The HTML part of a mail is left out.

A folder or a name that is no site's is refused with the code `unknown-site`, and a name two sites share with `ambiguous-site`.

## What it cannot do

It does not create a site, link a ticket, apply a patch or start the dev server: those are still done in the window. It also does not start the app.
Expand Down
Loading
Loading