Docs menu

Tools

Worker

brico-worker turns features the Scanner captured into type-checked bricks in your Vault.

Preview

brico-worker is the back end for the Scanner. It takes the features you selected in the browser and, for each one:

  1. claims the job from a Postgres queue;
  2. asks a model to implement the feature from the evidence the scanner observed;
  3. typechecks the result against the endpoints that were actually seen;
  4. sends the compiler errors back to the model for repair, up to three attempts by default;
  5. publishes the brick to your Vault as an ordinary module.

The result is a normal brick. brico list, brico add and the terminal UI treat it like any other.

Requirements

  • Go, to build or run it from source;
  • a Postgres 16 database with the BricoWerx migrations applied (db/migrate.sh);
  • a Mistral API key;
  • node_modules in the repository, so generated code is typechecked against real framework types.

Run it locally

bash
export DATABASE_URL='postgres://brico_app:…@localhost:5432/brico'
export MISTRAL_API_KEY='…'

./db/migrate.sh                       # idempotent; run it on every upgrade
cd engine
go run ./cmd/brico-worker             # poll for jobs and serve the extension

If DATABASE_URL or MISTRAL_API_KEY isn’t set, the worker reads it from db/.env.local in the repository. While it runs, the extension’s side panel reports it as ready, with its model and Vault.

Flags

FlagDefaultDescription
-onceoffProcess one job and exit. Useful as a smoke test.
-poll5sHow often to look for queued jobs.
-attempts3Generate, typecheck and repair attempts per job.
-vaultBRICO_VAULT or the configured VaultWhere finished bricks are published.
-repofound by walking upRepository root, used to find db/.env.local and node_modules.
-listen127.0.0.1:7717Loopback address for the extension. Pass an empty value to turn the bridge off.

MISTRAL_MODEL overrides the model. The default is codestral-latest.

The extension bridge

The worker serves a small HTTP API on loopback for the extension:

EndpointPurpose
GET /v1/healthIs the worker up, and which model and Vault does it use?
POST /v1/capturesSubmit the selected features as a capture; queues one job per feature
GET /v1/jobsJob status, which the side panel polls

It only binds to a loopback address and refuses anything else.

Hosted deployment

bash
docker build -f engine/Dockerfile.worker -t brico-worker .
docker run -e DATABASE_URL -e MISTRAL_API_KEY brico-worker -once   # smoke test

A hosted worker runs with -listen "", so the bridge is off and jobs arrive only through the database. The repository’s render.yaml deploys the database, migrations and worker together. Fly and Railway use the same image.

Review what it generates

A model writes worker bricks from observed evidence. They are typechecked before they are published, but typechecking is not a security review. Read a generated brick before you ship it.