Skip to Content

Level 2: JSON-RPC on stdio

A level 2 core is one long-lived process per project, speaking JSON-RPC 2.0, one object per line on stdio.

A level 2 core is one long-lived process per project, speaking JSON-RPC 2.0, one object per line on stdio, with stderr for logs. The protocol = 1 in the manifest is the major version; it changes only for breaking changes. A missing capability means unsupported; unknown fields are ignored. The core also appends every record to trace.ndjson in the job's run folder, so a crash leaves usable data.

A minimal session, → app to core, ← core to app:

→ {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocol":1,"root":"/cache/copy-of-project","paths":{"out":"…","cache":"…"},"trust":{"project":true}}}
← {"jsonrpc":"2.0","id":1,"result":{"protocol":1,"core":{"id":"my-core","version":"0.1.0"},"capabilities":["doctor","capture"]}}
→ {"jsonrpc":"2.0","id":2,"method":"doctor","params":{"scope":"capture"}}
← {"jsonrpc":"2.0","id":2,"result":{"checks":[{"name":"node","status":"ok","found":"v26.13.0","required":">=20"},{"name":"chromium","status":"warn","found":"not installed","fix":"The first capture installs Chromium into the core cache, or set browserPath to an existing executable."}]}}
→ {"jsonrpc":"2.0","id":3,"method":"capture","params":{"journey":"whole-map","outDir":"/cache/runs/r_9"}}
← {"jsonrpc":"2.0","id":3,"result":{"jobId":"j1"}}
← {"jsonrpc":"2.0","method":"job/progress","params":{"jobId":"j1","message":"building the copy","done":0.1}}
← {"jsonrpc":"2.0","method":"capture/step","params":{"jobId":"j1","type":"step","id":"st_1","seq":1,"status":"passed", …}}
← {"jsonrpc":"2.0","method":"job/finished","params":{"jobId":"j1","status":"passed","runDir":"/cache/runs/r_9"}}
→ {"jsonrpc":"2.0","id":4,"method":"shutdown"}
← {"jsonrpc":"2.0","id":4,"result":{}}
→ {"jsonrpc":"2.0","method":"exit"}

Methods the app calls. initialize, shutdown (answer, then wait for the exit notification), detect, doctor, discover, and the job verbs capture, attribute, index, verify, which answer immediately with a jobId and report from then on. open asks the core to open a file in its own tools. job/cancel cancels cooperatively; the app escalates SIGINT, SIGTERM and SIGKILL on the process group, so handle it, but don't rely on getting the chance.

Notifications the core sends. job/progress (message, done from 0 to 1 when known, phase, and for a crawl flows, the flows found so far, which the toolbar counts in place of steps), job/log (a line worth showing the person), capture/step / attribute/step (one trace record each, with the jobId beside the record's own fields — without it, it goes to the only running job of that verb), and job/finished (passed, failed or cancelled, with runDir holding trace.ndjson and artifacts/).

The call the core may make back. app/secret asks for a secret by name. The person is prompted, the value is never logged or stored, and a refusal comes back as an error, so plan for it. A device or a port is the core's own to make and to give back. The Kotlin core makes an emulator or a simulator for a run and deletes it after.

discover is worth a sentence of its own. It answers the journeys the core can run, each with a name, section and source refs, plus allRoutes: every route the app declares, so the sidebar can show what no capture has reached yet, with the core's reason. Static discover (mode: "static") runs nothing of the project's, which is what lets the app offer walks before the person has trusted the project — declare untrusted_project = "limited" only if that is true of your core.

Walks are how a core offers choices. detect and discover return them:

{"id":"whole-map","name":"The whole map","intent":"Every screen, on both platforms",
 "targets":["host"],"takes":[{"target":"host","seconds":2100,"firstSeconds":2700}],
 "proof":"rendered-fixture","dataSource":"fixture","input":"typed","doctor":"capture",
 "platforms":["android","ios-presentation"]}

Each names its targets, about how long it takes (seconds once the copy is built, firstSeconds the first time), the most its frames can prove, and the doctor scope whose blocking checks must pass. A walk can need something only the person can give — the folder of another project whose code it runs — in needs; the answer comes back as a capture option, and to doctor in its options. One walk with "default": true is what a capture that names no journey runs. A core that lists capture/plan in provides also answers capture/plan with what a capture would run and touch — commands, databases, env, the network lock, reads, writes, teardown — which the trust sheet shows whole before the person says yes. Before the project is trusted the app may not ask capture/plan, so it asks static discover with "plans": true and the walks' answers in options: give each walk's plans, by target, in plans, exactly what capture/plan would answer. A walk whose grants come from its plan (one that runs another project's code) can then be chosen before the first trust; the app checks the plan again with capture/plan once it may, and runs the walk only if it is unchanged. covers says in a few words how much of the app a walk reaches ("One journey", "All reachable flows"), and "whole": true marks a walk that goes through all of it it can reach, as a map or a crawl does: the Capture panel offers those as Whole app and the rest as One flow, on the data dataSource names.

When static discover offers walks, the app uses its targets and walks together. Give each list unique ids and make every walk name targets in that same answer. core test checks these references for both detect and discover and exercises static discover's choice first. It runs the default capture, not every listed journey. Set kept: true on a walk read from the project's recipe, including when its current id differs from an older recipe's.

Joins. A job that holds something up for a run driven elsewhere — the Rails core's attribute keeping a project server up while a phone walk drives it — is a join: name it in [capabilities] joins, send job/progress with phase: "ready" once a driver can start, and end it when the driver sends job/stop. Only attribute, index and verify can be joins. core test stops a join once it is ready and checks what it left.

Errors. Use JSON-RPC's codes, plus -32800 cancelled, -32001 not trusted and -32002 job failed. A call you don't have gets -32601, as for any method.

Live sessions

A detect target with "kind": "mirror" opens a session where another target would run a walk. capture on it answers a jobId, reports job/progress up to phase ready, then takes a person's input until job/cancel. That cancel is the person's Stop, and the run ends passed.

Declare the target under [[targets]] as <platform>-mirror. The app offers Start Live on a frame only when its platform has that entry. List the methods you answer in provides:

MethodWhat it does
mirror/inputPerforms one action and answers with its step once the screen settles. A second input meanwhile gets -32003, and one aimed at a frame no longer shown gets -32004
mirror/frameLong-polls for the next saved frame, with its image, tree and step
mirror/displayOpens an authenticated loopback connection for immediate pointer, key and text input. It streams preview pixels too, unless the app asks for inputOnly because the engine draws on the card itself
mirror/clipboardReturns the page's selected plain text for Copy and Cut, at most one MiB. The web cores answer it

Each action a person makes becomes a trace step with saved, masked evidence, as in any capture. Preview pixels are never artifacts.

Live starts from a recorded frame, so the earlier capture has to say how to get back to it. A mobile fixture run names its scenario in facets.seed, or on each journey when it opens several. The session's options then carry seed, lang and, when the recorded taps can be replayed, restore. A web core saves a web-replay-plan artifact on every step and gets the chosen one back as options.webReplayPlan. The mirror notes (docs/api/mirror.md) and direct web Live (docs/api/web-live.md) have the wire details. A Go core drives the app's bundled engine through pkg/browser and pkg/webmirror.

core test runs no capture on a mirror target, since a session ends only when a person stops it.

Where to look for real ones

In this repository:

  • cores/sample, the core the app ships: level 0, a journey, a scene, attribution.
  • pkg/coreproc/testdata/level2/main.go, the level 2 core the checker's own tests run: the JSON-RPC loop, jobs, cancel and joins in one file.

The cores that capture real stacks are in the private pitafix-rigs repository, and are fuller examples of all of this:

  • cores/kotlin-multiplatform with cmd/pitafix-core-kmp: Field on the JVM, Android and iOS, mirror sessions, a device of its own for each run, the live walk against a local server, redaction.
  • cores/rails with cmd/pitafix-core-rails: a server stack, with attribute as a join, so a phone walk's steps show the server code that answered.
  • cores/nextjs with cmd/pitafix-core-next: a web stack, with routes, source maps and Chromium driven from Go through chromedp, Live in the app's bundled engine and replay plans.
  • cores/mygo with cmd/pitafix-core-mygo: a native app in its own window, PitaFix itself, driven through MyGo's automation plugin, with each element's source read from the call that gives its Key.

A core in Go

A core is a separate program and may be written in anything. One written in Go can import this module's pkg/ packages, which is how the cores above are built:

  • pkg/model, pkg/trace, pkg/uiscene: the records, the tree and the scene, with the writer and the checks the app itself uses.
  • pkg/coreproto: the level 2 messages. pkg/devices, pkg/identity and pkg/paths: the device list, screen keys and folders the app and a core must agree on.
  • pkg/gitx and pkg/toolenv: reading a commit out of a project without running its hooks, and the login environment with credentials taken out.
  • pkg/browser and pkg/webmirror: Chromium for a web core, the app's bundled engine included.
  • pkg/coreproc, pkg/ingest, pkg/store, for a core's own tests: check a run folder as core test does, ingest it, and read back what the app would show.

The module's path is pitafix, with no host in it, so another module names it with a replace line: to a checkout beside it, or to github.com/maokomioko/pitafix at a version. The pitafix-rigs README has both forms.

On this page