Local stacks

The local stacks run the whole factory on your machine: kōjō, Postgres, a throwaway Forgejo with a demo repository, a Slack mock, a Sentry mock, and a mock provider that answers model calls from recordings. They need no cloud account and no model key. Use them to develop kōjō, to run the end-to-end scenarios, or to watch a session without setting anything up. They are not an install: for that, see the quick start.

Command Stack
make dev-sbx Docker Compose. With sbx installed, kōjō runs on your machine next to it and the other services in compose.
scripts/dev-sbx.sh --docker The same, with everything in compose and sandboxes as plain containers. Also the fallback when sbx is not installed.
make dev-kind A kind cluster with Cilium and gVisor, and the Helm chart of the working tree.
make dev-down Stops both and deletes their data.

What the stacks need

Tool For
Docker, with the daemon running and docker compose every stack
Go 1.27.4 or newer (the version in go.mod) building the binary and the image
git, make, curl, jq the scripts
sbx (Docker Sandboxes), signed in optional: microVM sandboxes with make dev-sbx
kind, kubectl, helm only for make dev-kind

The compose stack publishes five ports on loopback: 8080 (kōjō), 3000 (Forgejo), 8090 (the Slack mock), 8092 (the Sentry mock) and 5432 (Postgres). They must be free.

The compose stack

From a checkout, after make build:

make dev-sbx

It runs scripts/dev-sbx.sh, which does this:

  1. Checks that Docker runs and that curl and jq are installed.
  2. Picks the sandbox driver. With sbx installed it uses Docker Sandboxes; without it, plain containers.
  3. Starts Postgres, Forgejo, the Slack mock and the Sentry mock with Docker Compose (deploy/compose/docker-compose.yml plus the overlay docker-compose.dev.yml) and waits until they are healthy.
  4. Seeds Forgejo with scripts/dev-seed-forgejo.sh and writes the two access tokens it creates to deploy/compose/.env.dev, which git ignores, with a Sentry client secret it generates at every start.
  5. Starts kōjō, waits for /readyz, and enables the demo repository in it.
  6. Prints where everything is, and writes .kojo/e2e.env for make e2e.

Where kōjō itself runs depends on the driver:

Mode When kōjō runs Sandboxes
sbx sbx is installed on your machine, bin/kojo serve in the foreground. Ctrl-C stops kōjō; the other services keep running. one microVM per session
docker sbx is not installed, or scripts/dev-sbx.sh --docker in compose, from the image ghcr.io/xavidop/kojo:dev that the script builds from the working tree plain containers started through the Docker socket

To force the second mode:

bash scripts/dev-sbx.sh --docker

The sbx mode needs sbx login and sbx policy init deny-all once. It starts sandboxes from ghcr.io/xavidop/kojo-toolchain:latest; set KOJO_DEV_SANDBOX_IMAGE to use another image. sbx builds a sandbox’s image in its own builder and pulls the base from a registry, so an image that only exists in your local Docker is not visible to it. KOJO_DEV_SANDBOX_IMAGE=docker.io/sbx/shell-image:latest (Docker’s shell template) is enough for the demo repository.

Development only. In the docker mode, sandboxes are containers that share the host’s kernel, and the kōjō container holds the Docker socket, which is root on your machine. That is fine for developing kōjō and is not an isolation boundary. kōjō refuses this driver unless kojo.yaml says dev: true.

What is running

Service Address Credentials
kōjō: dashboard, API, webhooks http://localhost:8080 API token dev-admin-token-not-a-secret, role admin. The dashboard needs no sign-in in this stack.
Forgejo http://localhost:3000 maintainer kojo-dev / kojo-dev-password; bot kojo-bot / kojo-bot-password
Slack mock http://localhost:8090 none
Sentry mock http://localhost:8092 API token dev-sentry-token-not-a-secret; webhooks to kōjō are signed with the client secret in deploy/compose/.env.dev
Postgres 127.0.0.1:5432 database kojo, user kojo, password kojodev
kojo-proxy (docker mode) not published the egress proxy of the sandboxes, on the compose networks only

Every value above is a fixed development value from deploy/compose/dev.env, except the Sentry client secret, which the script generates. None is a secret; do not reuse any of them in a real install.

The seed script puts this into Forgejo:

  • kojo-dev, an admin: the maintainer who owns the demo repository and asks kōjō for work.
  • kojo-bot: the account kōjō acts as, with write access to the repository. kōjō uses its access token.
  • The repository kojo-dev/demo: a small POSIX shell program, lib/mean.sh, with a real bug, a test script tests/mean_test.sh and an AGENTS.md.
  • An open issue, “mean crashes when it gets no numbers”.
  • A webhook that delivers the repository’s events to kōjō at /webhooks/forgejo.

In kōjō, the repository’s ID is forgejo/kojo-dev/demo. The script enables it; on a real install you do that yourself, as Install describes. Outside development mode kōjō refuses to enable a repository whose default branch is not protected; dev: true skips that check, which is why the unprotected demo repository works here.

The stack’s kojo.yaml is deploy/compose/kojo.dev.yaml. It sets dev: true, the Forgejo forge, Slack in HTTP mode against the mock, Sentry alerts read from the Sentry mock (organization test-org), the docker driver with the image alpine/git, a separate proxy, and the merge policy draft_only.

Mock models produce canned output

No model is called in this stack. kojo.dev.yaml sets models.recordings, and with a recordings directory the mock provider answers every model call from YAML files, here testdata/recordings/dev/demo.yaml. Recordings describes the format and how a recording is chosen.

So the “agent” you watch below does not read your issue and think. It replays a scripted conversation that happens to fix the bug of the demo repository. Everything around the model is real: the webhook, the queue, the sandbox, the commands that run in it, the goal critic’s checks, the merge policy, the branch and the pull request on Forgejo.

The recordings script these conversations:

Prompt contains What is replayed
mean crashes when it gets no numbers The orchestrator delegates to fix-bug; the subagent edits lib/mean.sh, adds a test case and runs the tests; the judge accepts.
lib/mean.sh (a fix-bug run) The same subagent and judge, for a request that runs fix-bug directly: a campaign over copies of the demo repository, or a Sentry alert mapped to fix-bug.
kojo-e2e-slow (a fix-bug run) The subagent runs sleep 300 first, so that a session is busy long enough to be cancelled (campaigns.yaml).
in project kojo-e2e-report The orchestrator answers a report-mode alert in one message, changing nothing (alerts.yaml).
what can you do The orchestrator answers in one message, without a skill.
anything (the risk purpose) The risk classifier rates the change as low.

Ask for anything else and the session fails with a message that starts with mock model: no recording for purpose. To have a real model answer, see live models.

Two more files of the same directory answer the work that is not a skill run. lessons.yaml answers a maintainer’s review of a pull request kōjō opened: a comment that contains “no bashisms” teaches one lesson, any other teaches nothing. improve.yaml answers a self-improvement proposal: for fix-bug it proposes one more instruction (keep shell scripts POSIX sh), for any other skill there is nothing to propose.

Point the CLI at the stack

export PATH="$PWD/bin:$PATH"
export KOJO_SERVER=http://localhost:8080
export KOJO_TOKEN=dev-admin-token-not-a-secret
kojo sessions list

A first session

From an issue

Open http://localhost:3000, sign in as kojo-dev with the password kojo-dev-password, go to the issue of kojo-dev/demo and add the comment:

@kojo-bot fix this

The mention is @ followed by the login of the account kōjō acts as: kojo-bot here, the name of your GitHub App on GitHub. It is matched in any letter case, and it must not be part of a longer word. Forgejo delivers the comment to kōjō’s webhook. kōjō starts a session because the author has the repository’s trigger permission, write by default. A comment by the bot itself is ignored.

The same from a terminal, with the maintainer’s password:

curl -fsS -u kojo-dev:kojo-dev-password -H 'Content-Type: application/json' \
  -d '{"body": "@kojo-bot fix this"}' \
  http://localhost:3000/api/v1/repos/kojo-dev/demo/issues/1/comments

From the CLI

kojo run starts a session through the API and follows it. With --issue, kōjō looks up the issue’s title for the session list and the pull request, but what the orchestrator is shown is the text of your request. With mock models, put the issue’s title in that text, because it is what the recording is picked by:

kojo run --repo forgejo/kojo-dev/demo --issue 1 "fix this: mean crashes when it gets no numbers"

To try it without a branch or a pull request on the forge, add --dry-run. A dry run also needs the repository to be enabled. The CLI reference has every flag.

From Slack

The Slack mock plays the users. POST /mock/mention sends a mention to kōjō and GET /mock/messages shows what kōjō posted:

curl -fsS -H 'Content-Type: application/json' \
  -d '{"channel": "C1", "user": "U1", "text": "what can you do here?"}' \
  http://localhost:8090/mock/mention
curl -fsS 'http://localhost:8090/mock/messages?channel=C1'

The mock accepts any channel and user ID. kōjō answers in the thread of the message. In chat, the sender’s role in kōjō decides what a request may do: an unknown Slack user, as here, gets read-only answers. See Who may trigger what. The mock’s whole control API is under Fakes and mocks.

From a Sentry alert

The Sentry mock is the issue API kōjō reads an alert’s issue from, not a sender: a delivery to /webhooks/sentry comes from whoever signs it with the client secret. No project is mapped to the demo repository until you add an alerts entry to it in the repos object, as Mapping projects to repositories describes. The TestSentryAlert scenario of test/e2e/alerts_test.go maps two projects, builds event_alert deliveries from Sentry’s documented example, and signs them with the secret from .kojo/e2e.env; it is the worked example of a delivery.

Follow the session

kojo sessions list
ID                              STATUS     REPO                   TRIGGER  COST   AGE   TITLE
ses_01m8v6bjtss3pbyvn554x2vdj3  succeeded  forgejo/kojo-dev/demo  mention  $0.00  6m0s  #1 mean crashes when it gets no numbers

The cost is $0.00 because the mock provider is not a priced model. Set the ID once and use it in the next commands:

SESSION=ses_01m8v6bjtss3pbyvn554x2vdj3
kojo sessions logs "$SESSION"
▸ skill fix-bug
  · create sandbox
  · prepare workspace
  · read_file {"path":"lib/mean.sh"}
  · read_file {"path":"tests/mean_test.sh"}
  · edit_file {"path":"lib/mean.sh","new_string":"if [ $# -eq 0 ]; then\n  echo 0\n  exit 0\nfi\nsum=0\…
  · edit_file {"path":"tests/mean_test.sh","new_string":"check 3 2 4\ncheck 0\n","old_string":"check 3 …
  · set_output {"name":"TEST_CMD","value":"sh tests/mean_test.sh"}
  $ sh tests/mean_test.sh
  ✓ goal critic
  $ sh tests/mean_test.sh
· merge policy
· open pull request
· comment

Lines that start with $ are commands that ran in the sandbox. The first sh tests/mean_test.sh is the subagent’s own run; the second is the goal critic checking the result. --follow keeps printing until the session ends, and --json prints every step with its input and output.

kojo sessions show "$SESSION"
ses_01m8v6bjtss3pbyvn554x2vdj3  succeeded  forgejo/kojo-dev/demo
#1 mean crashes when it gets no numbers

session ses_01m8v6bjtss3pbyvn554x2vdj3: succeeded
Fixed: `mean` divided the sum by the number of arguments, so it crashed with a division by zero when it got none. It now prints `0` for an empty input, and `tests/mean_test.sh` has a case for it.

The goal critic ran the test suite in the sandbox and accepted the change. Nothing else was touched.

risk: low (0.00)

pull request: http://forgejo.kojo.internal:3000/kojo-dev/demo/pulls/2

Between the summary and the risk, show also prints the goal critic’s report: the skill, the number of attempts, the files changed and the result of each check. Here the check package tests pass passed and reproduction passes was skipped.

Look at the result

  • The pull request. Open http://localhost:3000/kojo-dev/demo/pulls. The pull request is a draft, opened by kojo-bot from a kojo/ branch onto main. It changes lib/mean.sh and tests/mean_test.sh, and its description carries the goal critic’s report and the session ID. In the docker mode the URL that show prints uses forgejo.kojo.internal, the forge’s name inside the compose network; from your browser the host is localhost:3000.
  • The issue. kojo-bot commented on it with what it did.
  • The dashboard. http://localhost:8080/sessions/ followed by the session ID shows the replay: every step with its input, output and duration.
  • The configuration. kojo config export prints the runtime config the stack runs with, the enabled repository included.

kojo doctor --remote exits 1 in this stack, on purpose: the mode check fails while dev: true is set, the docker driver fails the isolation check, and the demo repository fails the branch protection check because its default branch is not protected.

Live models

KOJO_LIVE_MODELS=1 ignores the recordings and calls the providers of the tiers in kojo.dev.yaml, which are Anthropic models:

export ANTHROPIC_API_KEY=...
KOJO_LIVE_MODELS=1 make dev-sbx

In the sbx mode kōjō runs on your machine and reads the key from your shell.

In the docker mode, docker-compose.dev.yml passes KOJO_LIVE_MODELS to the kōjō container and loads dev.env and .env.dev; it does not pass a provider key from your shell. scripts/dev-sbx.sh rewrites .env.dev every time it seeds Forgejo, so a key added to that file by hand does not survive a start. Check that the key reaches the container before you rely on this mode with live models.

Live calls cost what the provider charges. kojo.dev.yaml caps a session at 5 USD and a day at 50 USD, but kōjō ships no price table: without a price on the tier, the calls count as 0 USD and the caps do not bound them. See Models.

The kind stack

make dev-kind runs the same stack on a local Kubernetes cluster, installed with the Helm chart of the working tree. It needs Docker, kind, kubectl, helm, Go, curl and jq. gVisor needs a Linux 5.6 or newer kernel in the Docker VM or host.

make dev-kind

scripts/dev-kind.sh does this:

  1. test/kind/up.sh: a one-node kind cluster with Cilium as the CNI, a node image with gVisor, the Agent Sandbox release pinned in test/kind/versions.env, and the RuntimeClasses gvisor and runc.
  2. Builds ghcr.io/xavidop/kojo:dev, adds testdata/recordings to it as ghcr.io/xavidop/kojo:dev-kind, builds the Slack mock, the Sentry mock and the sandbox toolchain image ghcr.io/xavidop/kojo-toolchain:dev, and loads them into the cluster.
  3. Runs Forgejo, the Slack mock and the Sentry mock in the namespace kojo, seeds Forgejo, and generates the Sentry client secret.
  4. Installs charts/kojo with charts/kojo/ci/render/dev-kind-values.yaml: the k8s driver on gVisor, kojo-proxy, the bundled Postgres, the NetworkPolicy and CiliumNetworkPolicy lock-down, mock models, and sandbox.max_resources of 1 CPU and 2Gi. The cluster is one node with the Docker host’s CPUs, 4 on a CI runner, and the built-in kits ask for up to 8; the cap lets a sandbox fit next to everything else on the node.
  5. Enables the demo repository in kōjō through a short-lived port-forward.

The cluster has its own kubeconfig, test/kind/.kubeconfig; your ~/.kube/config is not touched. Reach the services with port-forwards:

export KUBECONFIG=$PWD/test/kind/.kubeconfig
kubectl -n kojo port-forward svc/kojo 8080:8080
kubectl -n kojo port-forward svc/forgejo 3000:3000
kubectl -n kojo port-forward svc/slackmock 8090:8090
kubectl -n kojo port-forward svc/sentrymock 8092:8092

The API token and the Forgejo accounts are the same as in the compose stack. Run the script again after a change to rebuild and redeploy.

The end-to-end scenarios run against this stack too, with sandboxes that are Agent Sandbox pods on gVisor behind the Cilium egress policies.

Stop the stacks

make dev-down

It stops the compose stack and deletes its volumes, removes the sandboxes the docker driver left behind and the generated deploy/compose/.env.dev, then deletes the kind cluster. The second step needs kind installed; without it make reports that and exits non-zero after the compose stack is already gone.

Scroll to move. + - zoom, 0 fit, Esc close.100%