Project

Architecture

One FastAPI process, the executor inside it, the local worker beside it, the worker sessions it starts, how a work item flows through them, and where each trust boundary is enforced.

Kraft is one Python process on your machine, and a second one beside it. The first serves a React SPA and an HTTP API and walks each work item's chain; the second, the local worker, starts the coding agent or the command for each local task.

This page is for contributors and for anyone who wants to know what runs where. It shows how the parts fit and where each one is enforced in the code. Everything Kraft knows is in one SQLite database, run/orchestrator.db, beside a search index it can rebuild.

For what a work item does, step by step and status by status, read How a work item runs first. For the words, see Vocabulary. For which module under src/kraft/ holds what, see the Source map.

The parts

Clients
  • BrowserReact SPA
    • HTTP API and WebSocket
  • kraft CLI
    • HTTP API and WebSocket
  • Coding agentkraft admin mcp
    • HTTP API and WebSocket
kraft: one FastAPI process
  • HTTP API and WebSocket
    • orchestrator.db
    • index.db
    • Executor
  • Executor
    • orchestrator.db
    • asks to start: Local worker
    • forge tasks: gh or glab
    • bd, optional
  • Pollerswaits, rate limits, time caps, schedules, auto-intake, delayed escalations, closed MRs, archive
    • Executor
  • orchestrator.dbSQLite, one writer
  • index.dbsearch
  • Egress proxy
kraft: the local worker, a second process
  • Local workerunix socket in run/local-worker
    • starts and reaps: Worker session
One per running task
  • Worker sessionan agent CLI or a subprocess
    • edits and commits: git worktree
    • permission hook, progress, replies: HTTP API and WebSocket
    • network, when sandboxed: sometimes Egress proxy
  • git worktreeone per work item
Outside tools
  • gh or glab
  • bd, optional
Kraft's components: clients, the FastAPI process with its API, executor, pollers and stores, worker sessions in a git worktree, and the forge CLIs.
  • The server. kraft (or kraft admin start) runs uvicorn with the FastAPI app from src/kraft/api/. The same process serves the built SPA, answers the API under /api, pushes events over a WebSocket, and runs every work item's walk as an asyncio task. There is no queue or broker.
  • The local worker. The server also starts kraft admin worker local, a separate process that listens on a unix socket under run/local-worker/ (src/kraft/remote/local_serve.py). The server builds each local session's command and environment and asks the worker to start it. The worker starts it, reaps it and records it on disk; the server keeps watching it by pid and by the files it writes.
  • Surviving the worker. A session is the worker's child in a process group of its own, so it outlives a crash of the worker. The next worker takes it over by its recorded pid and start time.
  • Surviving the server. The worker is a process of its own, outside the server's process group and, under a systemd service, outside its cgroup. A stop or restart of the server leaves it, and the sessions, running.
  • Clients. The SPA, the kraft CLI and the MCP server all call the same HTTP API. The MCP server is kraft admin mcp: a separate stdio process that your coding agent starts, with a tool for most item and view verbs and for repo connect (every tool but permission_request is also a CLI subcommand). Both go through src/kraft/client/, so a verb and its tool can't drift apart.
  • The executor. src/kraft/executor/ walks a work item's frozen chain node by node. It runs builtin and forge tasks inside the process and launches agent and subprocess tasks through the local worker. It is started by an API request (resume, retry, approve, reject, skip) or by a poller.
  • Worker sessions. Each agent task is a headless agent CLI (Claude Code, Codex, Gemini, Antigravity, Cursor, OpenCode or Amp) started in the item's git worktree, with an environment built from an allowlist. With a sandbox configured, it runs in a container (Docker or Podman) instead, and reaches the network only through Kraft's egress proxy. A worker talks back to Kraft for permission decisions, plan progress and review replies.
  • Machines. A step can also run on another machine; see Where a step runs. src/kraft/remote/ handles these remote workers (src/kraft/worker/ is the sandbox backends). The server keeps one connection per machine in remote/hub.py, over a dial-in WebSocket or an ssh it runs itself, and speaks the versioned protocol in remote/protocol.py. remote/registry.py reads workers.yaml.
  • Add-ons. src/kraft/addons/ installs the chains and components an instance takes from a collection. It fetches a collection into a bare mirror, extracts each add-on into a content-addressed store under run/addons/, and gives the template library a read-only layer per add-on. See Add-ons and collections.
  • Pollers. Background tasks in the same process, each on a fixed interval. Together they:
    • re-enter items that are waiting on an external wait that is now due, or rate_limited and past their limit;
    • start queued items as slots free, and release blocked items whose dependencies completed;
    • stop parked items whose time cap ran out, and gates whose own timeout ran out;
    • fire schedules, and pick up ready issues from beads when auto-intake is on;
    • fire delayed auto-escalations;
    • archive old ended items, and check worktree disk use against its limit;
    • notice a merge request closed on the forge without merging, and check that each forge token still works;
    • flag saved settings that need a reload or restart, and update add-ons and Kraft itself when allowed.
  • Stores. run/orchestrator.db holds work items, sessions, gates, review threads and an append-only events table. All writes go through one writer queue (src/kraft/db.py). The WebSocket, notifications and the search index each follow the events tail. run/index.db is the full-text and vector search index over your repos' documents.
  • Outside tools. Kraft calls git for worktrees and rebases, gh or glab for merge requests and CI, and bd for beads, each as a subprocess with your own login.

From filing to merge

  1. 1You to HTTP APIkraft item create
  2. 2HTTP API to orchestrator.dbintake, status paused
  3. 3You to HTTP APIkraft item resume
  4. 4HTTP API to orchestrator.dbclaim, paused to active
  5. 5HTTP API to Executorspawn the walk
  6. 6Executor to Executorcut the worktree
  7. 7Executor to Worker sessionlaunch the spec author
  8. 8Worker session replies to Executorexit code and result file
  9. 9Executor to orchestrator.dbgate_requested, status needs_human
  10. 10orchestrator.db replies to Youevent over the WebSocket
  11. 11You to HTTP APIkraft item approve
  12. 12HTTP API to orchestrator.dbgate_approved, status active
  13. 13HTTP API to Executorspawn the walk at the next node
  14. 14Executor to Worker sessionplan, implementation, their gates
  15. 15Executor to gh or glabopen a draft merge request
  16. 16Executor to orchestrator.dbstatus waiting on CIExecutor, orchestrator.db: re-entered when CI settles
  17. 17You to HTTP APIapprove final_review
  18. 18Executor to gh or glabmark ready, merge
  19. 19Executor to orchestrator.dbstatus completed, close beads
Sequence of one work item: create, resume, the spec author, a gate, approval, the rest of the chain, a CI wait, final review, merge.

The table follows one work item. Its second column gives the numbered steps of the diagram above.

StepWhat happensDiagramWhere in src/kraft/
1. Filekraft item create posts the item. Intake resolves its chain, freezes the chain and the effective policy onto a new row, and copies attachments. The item lands paused.1 to 2api/routes/work_items.py, executor/entry.py, store/work_items.py; chains in config/chains/; copies in run/items/<id>/filed/
2. Resumekraft item resume claims the item with a conditional update from paused to active, checks the slot limit in the same statement, and starts its walk as a task.3 to 5api/routes/lifecycle.py, executor.run
3. WalkThe walk loads the chain, cuts the worktree, and runs each node's steps. An agent task builds its command line from the harness profile, then launches it, watches its log, and reads its result file and usage.6 to 8executor/walk.py, builtins.py, executor/dispatch.py, adapters/agent.py, harness.py, harnesses/*.yaml, adapters/subprocess.py
4. GateAt a gate node the item becomes needs_human and Kraft writes gate_requested. The walk task ends. The event reaches the board over the WebSocket and, if you configured one, a notification.9 to 10executor/gates.py, notify.py
5. Approvekraft item approve checks for open must-fix threads, sets the item active again, and starts a new walk at the node after the gate.11 to 14api/routes/gates.py
6. Merge requestForge nodes open the draft merge request and read CI. A pending pipeline is an external wait: the item goes waiting, the walk task ends, and the wait scheduler re-enters the walk when the next check is due.15 to 16adapters/forge/, waits.py
7. FinishAfter final_review, forge nodes mark the merge request ready, wait for any required approval, merge and watch the post-merge pipeline. The walk marks the item completed and closes its issues in beads.17 to 19adapters/forge/, executor/entry.py

What a restart does to running items

A clean stop (kraft admin stop, restart, Ctrl-C, a service stop) leaves the local steps of worktree items running in the local worker, as a crash does. The server's tasks are cancelled; a step that is still running, not capped and not paused is left alone, its sandbox and egress route included.

A step of an item that runs in place is ended, since it runs in your own checkout, and so is any step by kraft admin stop --now (it writes run/stop-now for the server to read). See A restart leaves local steps running for the commands.

A restart doesn't lose finished work. On startup, worker/reattach.py finds the sessions that were running, asks the local worker which it holds, adopts those and resumes each item's walk from the node and step it had reached. A session outlives a crash or a kill -9 of the server, because each agent runs in its own process group, a child of the worker.

An update within a major version starts a worker of its own: each installed Kraft has its worker, its socket and its lock (local-worker/worker-<version>-<hash>.sock). The new worker adopts the old one's sessions by pid identity; the old one gets no new sessions, reaps its own children and exits.

The handshake with a worker or machine carries a caps list, and frame readers ignore fields they don't know, so a machine on an older release of the same major keeps getting steps.

Trust boundaries

Four lines matter. The Security page states what each one does and doesn't stop by default; this is only where each one lives in the code.

BoundaryEnforced by
Network clients to the APIapi/perimeter.py (the local-client check and auth middleware), auth.py (password login and sessions), the bearer token in run/
A worker to KraftThe permission gate (api/routes/sessions.py, permission_hooks.py, permission_rules.py, grants.py), and the self-action guard: client/context.py in the CLI and MCP server, and forbid_self_action in api/deps.py for a worker that identifies itself
A worker to your machineNothing, unless the repo sets sandbox:. Then worker/backends/docker.py, worker/sandbox.py, worker/refstore.py, assert_on_branch in adapters/forge/git.py before every host-side commit, rebase or push from its worktree, and for network: the egress proxy in worker/egress.py, worker/channel.py and worker/inject.py
Kraft to your forgeYour own gh or glab login, used as is by adapters/forge/

A sandbox covers a workspace's members as it covers the root. Where each hold lives in the code is under Workspace members on the Source map.

State on disk

State lives in $KRAFT_HOME (default ~/.kraft), in two folders:

  • run/ holds the databases, the worktrees, items/<id>/, the process ID file and the sandbox's sockets, CA and ref stores.
  • config/ holds the YAML the Templates and Settings screens edit. Kraft seeds it from the shipped defaults on first run and never overwrites it, so an upgrade can't clobber an edited policy.

items/<id>/ is one folder per work item. It holds the item's documents and their earlier versions, its attachment copies, its session logs and result files, and its sandbox home.

kraft.item_paths is the one place that says where an item's file is. Nothing is moved at an upgrade: an older item's files stay in logs/, results/, attachments/, sandbox-home/ and its worktree's .engineering/, and are read there.

Data and privacy lists every file in run/ with its mode. Configuration lists what is in config/.

  • Source map: which module under src/kraft/ holds what, and where to change a given thing.
  • Security: what each trust boundary does and doesn't stop by default.
  • How a work item runs: the flow above in terms of statuses and gates.
Copyright © 2026