API guide

Everything the portal does, you can do with HTTP. Base URL: https://squirmware.net. The machine-readable description is at /api/openapi.json, browsable at /api/docs.

Overview

Squirmware turns an intention ("read a sensor, blink a light, log over USB") plus components (a board, part numbers, spec sheets) into firmware, in five phases. Each phase produces one record, a deterministic verifier checks it, and the run parks at a gate until a person approves it, asks for changes, or rejects it. The API exposes exactly that: create a project, sharpen the brief, run phases, read what was produced, decide gates, download the package.

Nothing reaches a gate unverified. When you read a run whose status is awaiting_approval, its checker already passed; the view endpoint lists its warnings and the facts the model supplied so you know where to look.

Authentication

Every /api route except /api/health takes a bearer token:

Authorization: Bearer <token>

Tokens are issued by the operator. A missing or wrong token answers 401. The pages (/, /docs, /app) and /static are public.

Quick start

A Raspberry Pi Pico thermostat, from nothing to a reviewed behaviour spec:

export SQW=https://squirmware.net TOKEN=...   # your token
H=(-H "Authorization: Bearer $TOKEN" -H "content-type: application/json")

# 1. create the project without starting it, so you can attach a spec sheet and run the interview
curl -s "${H[@]}" -d '{
  "description": "Read the temperature from an SHT31 on the I2C header every 5 seconds and print it over USB. Blink the LED above 30 C.",
  "board_ref": "profile:raspberry_pi_pico",
  "parts": [{"part_number": "SHT31-DIS", "role": "temperature sensor on the I2C header"}],
  "start": false
}' $SQW/api/projects
# -> {"project": {"id": "prj_...", "brief": {...}}, "run": null}

# 2. attach the sensor's datasheet (PDF or text; the text is extracted for the prompts)
curl -s -X PUT -H "Authorization: Bearer $TOKEN" -H "content-type: application/pdf" \
     --data-binary @SHT31.pdf $SQW/api/projects/prj_.../attachments/SHT31.pdf

# 3. ask the interviewer; answer; ask again until it says ready (or stop whenever you like)
curl -s -X POST "${H[@]}" $SQW/api/projects/prj_.../interview
# -> {"round": {"understanding": "...", "ready": false, "questions": [{"id": "alarm_hysteresis", ...}]}, "brief": {...}}
curl -s "${H[@]}" -d '{"answers": [{"question_id": "alarm_hysteresis", "answer": "Use a 1 C margin"}]}' \
     $SQW/api/projects/prj_.../interview/answers

# 4. start Phase 1; it runs in the background
curl -s -X POST "${H[@]}" $SQW/api/projects/prj_.../phases/intent
# -> {"id": "run_...", "phase": "intent", "status": "queued", ...}

# 5. poll the run, then read the gate view and decide
curl -s "${H[@]}" $SQW/api/projects/prj_.../runs/run_.../view
curl -s "${H[@]}" -d '{"decision": "approve"}' $SQW/api/projects/prj_.../runs/run_.../decision
# -> {"next_run": {"phase": "binding", "status": "queued"}}   (approve starts the next phase)

# 6. at any point, take the package
curl -s -H "Authorization: Bearer $TOKEN" -o firmware.zip $SQW/api/projects/prj_.../package.zip

Passing "start": true (the default) skips the interview and queues Phase 1 immediately, which is what a script with a complete description wants.

Concepts

Projects and the brief

A project is one device: the user's description, a board_ref, and a brief. The brief is everything gathered before Phase 1: parts (part numbers with a role), attachments (spec sheets, with their extracted text), and the interview: the questions asked (questions_asked), the ones waiting (pending), the answers, the interviewer's latest understanding and a status of open, ready or skipped. Every prompt in Phases 1 and 2 sees the brief, so an answer you gave beats an assumption the model would otherwise make.

Boards

board_ref says where the components come from:

formmeaningPhase 2
profile:<id>a dev board Squirmware knows (GET /api/boards lists them)deterministic, no model call
pcbyay:<dir>a pcbyay design exported as spec, BOM, netlist and plannetlist bound to pins deterministically; the model settles gaps
library:<component id>a board published in the Library of Everythingas pcbyay
mcu:<family>a bare processor (esp32, rp2040); chosen automatically when a part number in parts is a known processor and no board is giventhe model proposes every pin from the free-pin list; each is marked for you to confirm
manual:<path>a hand-written board map (operator use)as written

Phases, runs and gates

Five phases, in order: intent, binding, plan, build, target. A phase executes as a run. A run's status moves queued → running → awaiting_approval | failed; a decision then makes it approved, rejected or superseded. Rules: one active run per project; a phase starts only when every earlier phase has an approved run; approving a run again later invalidates every downstream approval (they were built on the old result).

decisioneffect
approvethe run becomes the phase's approved result; with start_next (default true) the next phase is queued
revisekeep the result, apply the change request in feedback; a new run of the same phase starts from it
rejectstart the phase over; feedback is shown to the model as the reviewer's reasons

On this server Phase 4 runs in source_only mode: the source is written module by module and statically checked, but not compiled (no toolchain container). The build report and the package README say so plainly. Phase 5 needs a bench or simulator and fails cleanly without one.

Artifacts and traces

Everything a run produces is an artifact named in run.artifacts: the phase's record (spec, board_map, plan, build, release), its verification report, every attempt (spec_attempt_1, verification_attempt_1, ...) and every model call as a trace (trace/1, trace/2-implementer-drv_led, ...) holding the full system prompt, user text and raw answer.

Endpoints

Health and boards

GET/api/health
Public. {"ok": true, "version", "provider", "storage", "toolchain": false, "bench": "none", "mcus": [...], "platforms": [...], "auth": "token"}. toolchain false means Phase 4 is source-only.
GET/api/boards
Dev-board profiles (profiles, and profile_details with name, MCU and interface ids), processor families and parts in the MCU database (mcu_families, mcus), platform ids, and the board_ref forms.

Projects

POST/api/projects

Body: description (at least 10 characters), board_ref (optional when parts names a processor), parts (list of {part_number, role?, quantity?, notes?}), title?, owner?, start (default true). Returns 201 with {project, run}; run is the queued Phase 1 run when start is true, else null. 422 when no board can be determined.

GET/api/projects ?owner=
Projects, newest first.
GET/api/projects/{id}
{project, runs}: the project with its brief and phase states (phases.<phase>.approved_run_id / active_run_id / run_ids), and every run in creation order.

Spec sheets and the interview

PUT/api/projects/{id}/attachments/{name}

Raw body is the file; send its content-type. PDFs have their text extracted (pypdf); text files are kept as text; other files are stored without text. Up to 15 MB. Returns 201 {attachment, brief}; attachment.note says what happened ("text extracted from 12 of 12 pages", "PDF has no extractable text (scanned?)"). GET the same path returns the original bytes.

POST/api/projects/{id}/interview

One interviewer round. Returns {round, brief} where round is {understanding, ready, ready_reason, questions: [{id, topic, question, why, kind, options, suggested}]}. kind is text, choice (pick one of options), confirm (yes or no to suggested) or number. At most 5 questions per round and 3 rounds per project; after that the brief is ready whatever the model thinks. 409 when questions are pending or the interview is over.

POST/api/projects/{id}/interview/answers

Body: {"answers": [{"question_id", "answer"}], "done": false}. Records answers against pending questions (unanswered ones are dropped; the interviewer may ask again). done: true ends the interview. Returns {brief}.

POST/api/projects/{id}/interview/skip
Ends the interview without further questions. Starting Phase 1 does the same implicitly.

Runs and gates

POST/api/projects/{id}/phases/{phase}
Queue a run of intent | binding | plan | build | target. 201 with the run; 409 if a run is active or an earlier phase lacks an approval. Use it to start Phase 1 after the interview and to retry a failed phase.
GET/api/projects/{id}/runs/{run_id}
The run: status, attempt, max_attempts, verification counts, error, artifacts (name → key), gate. Poll it while queued or running.
GET/api/projects/{id}/runs/{run_id}/view

The gate view: headline, summary, sections (each a table, list, kv or text), warnings, failures, model_sourced (facts the model supplied), assumptions, open_questions, checks (every verifier check with its detail), artifacts and traces. Built from the artifacts without a model call; it is what the portal shows.

GET/api/projects/{id}/runs/{run_id}/artifacts/{name}
The artifact body: JSON for records, reports and traces; bytes for images. Names come from the run's artifacts.
POST/api/projects/{id}/runs/{run_id}/decision

Body: {"decision": "approve" | "revise" | "reject", "feedback": "", "start_next": true}. revise and reject want feedback. Returns {project, run, next_run}; next_run is the queued follow-up (next phase on approve, same phase on revise and reject). 409 if the run is not awaiting_approval or another run is active.

The firmware package

GET/api/projects/{id}/package.zip

A zip of everything so far: README.md (status, what the device does, the board and its pins, how to build and flash, tests), brief.json, spec.json, board_map.json, plan.json, build.json, release.json when they exist, firmware/ (the complete source tree for the platform's SDK) and images/ when compiled. Approved runs are preferred; a run waiting at its gate is used otherwise and the README says so. 409 before the spec exists.

GET/api/projects/{id}/package
The manifest without the bytes: files, which run each phase came from, compiled, images.

Records

One record per phase, all JSON, all described with field documentation in the OpenAPI schema:

phaserecordwhat is in it
1 intentBehaviorSpecsignals bound to board interfaces, behaviours with triggers and steps, modes, comms channels, failure handling, constraints, assumptions, open questions, declared totals
2 bindingBoardMapthe MCU, every pin with function, net, interface and source (netlist, profile, model, user), peripherals with bus and address, power, flash method, unresolved items
3 planFirmwarePlanplatform, language, RTOS, modules (ownership, dependencies, files, public API), tasks, budget, host tests, target tests with bench steps, risks
4 buildBuildReport + modulesmode (toolchain or source_only), diagnostics, size, host-test results, static findings, files, image artifacts; each module's files and narration
5 targetFirmwareReleaseversion, images with checksums, flash recipe, bench kind, target-test results with evidence, manual, changelog, library component id

Every verifier emits the same CheckResult shape as pcbyay: name, passed, severity (error blocks the gate and triggers a retry; warning is shown), detail (actionable; it is what the model receives on retry).

Errors

statusmeaning
401missing or wrong bearer token
404no such project, run, artifact or attachment
409state conflict: a run is active, the phase is not ready, the run is not at its gate, the interview has pending questions, the project changed underneath you, nothing to package yet
413attachment too large
422the body did not validate, no board could be determined, an answer names an unknown question

A run that could not finish is not an HTTP error: it is a run with status: failed and an error string ("the checks still fail after 3 attempts", "model provider: ...", "board ... could not be resolved"). Retry it with POST .../phases/{phase}.

Costs and limits

Source: github.com/leidichj/squirmware (private). This guide describes version 0.1.