---
title: How the weft repository is organised and checked
description: 'The weft repository''s layout, the make targets, and the CI gates that enforce its promises: race tests, lint, apidiff per module, the facade check, offline, fuzz, the crash matrix, budgets and the Studio freshness gate.'
url: https://weftgo.dev/docs/explanation/repository/
type: concept
sources:
  - weft/README.md:974-1017 (Layout)
  - weft/README.md:1019-1077 (Development, Testing, API stability)
  - weft/AGENTS.md:640-642 (make fuzz), 752-779 (Working in this repo)
  - weft/go.work:1-8
  - weft/Makefile:1-237
  - weft/.github/workflows/ci.yml:1-234
  - weft/.github/workflows/soak.yml:1-33
  - weft/scripts/apidiff.sh:1-110 (policies, fail-closed, GOWORK=off loading, APIDIFF_STRICT)
  - weft/scripts/apidiff-selftest.sh:1-35
  - weft/core/.apidiff-allow:1-25
  - weft/facade.go:6 (go:generate line)
  - weft/facade_test.go:48 (TestFacadesAreComplete)
  - weft/internal/facadegen/facadegen.go
  - weft/studio/pricing.go:27 (go:generate pricing.json)
  - weft/studio/pricing_test.go:51 (pricing.json freshness)
  - weft/scripts/apidiff-selftest.sh:51-159 (the eight self-test cases)
  - weft/.github/workflows/ci.yml:3-6 (push to main and devtools-plan; pull_request)
  - weft/thread/threadtest/crashmatrix.go:82-91 (20 crash points)
  - weft/thread/jsonl/fuzz_test.go:23 (FuzzLoad)
  - weft/cmd/weft/main.go:265, weft/cmd/weft/vacuum.go:15 (the clickhouse backend linked by cmd/weft)
  - weft/core/fuzz_test.go:23,42,110,162; core/partial_json_test.go:86; core/raw_test.go:336 (core fuzz targets)
  - weft/thread/fuzz_test.go:25; thread/header_fuzz_test.go:21; thread/approval_fuzz_test.go:27; thread/grants_fuzz_test.go:17; thread/jsonl/fuzz_test.go:23 (thread fuzz targets)
  - weft/thread/threadtest/crashmatrix.go:107 (CrashMatrix)
  - weft/thread/jsonl/crashmatrix_test.go, weft/thread/sqlite/crashmatrix_test.go
  - weft/thread/budget_test.go:15-30 (the budget suite)
  - weft/core/wefttest/golden.go:34 (Golden)
  - weft/studio/studio_test.go:468 (TestMetaGolden)
  - weft/studio/panel_test.go:156 (TestVersionIsTheModules)
  - weft/studio/README.md:3554-3582 (Contributing to the UI)
  - weft/studio/web/scripts/panel-gate.ts:1-15
  - weft/studio/web/scripts/clean-dist.ts
  - weft/scripts/ux-gate/README.md
  - weft/internal/adapterkit/adapterkit.go
  - weft/internal/listen/listen.go
  - weft/CHANGELOG.md:2469 (make studio-bin)
  - weft/CHANGELOG.md:3570-3589 (0.8.0 CI / repo)
  - weft/CHANGELOG.md:3830 (thread 0.9.0 CI)
  - weft/CHANGELOG.md:4214-4222 (store step removed, ClickHouse job, dist-release ignored)
  - weft/CHANGELOG.md:4604 (panel-gate.ts, panel-asset.ts)
  - weft/CHANGELOG.md:4881-4933 (thread 0.7.0 fuzz, crash matrix, budgets, review)
  - weft/CHANGELOG.md:6499-6512 (adapterkit; apidiff fails closed)
  - weft/CHANGELOG.md:6665 (the first apidiff gate)
  - 'weft v0.20.2: Makefile:67-68 (mcp-check: go test -tags livecheck -run TestMCPLiveCheck ./cmd/weft), 184-193 (studio-check: the 800 KiB budget); cmd/weft/mcp_check_test.go:30-46 (the record contract''s fixtures, weft mcp over stdio); cmd/weft/mcp_check_seed_test.go:16-27 (the four shapes on wefttest scripts through the otel pipeline); weft/CHANGELOG.md:131 (0.19.0: make mcp-check), 137 (0.19.0: the 800 KiB budget); weft/studio/README.md:3560-3567 (studio-check: the freshness gate)'
  - 'weft v0.20.2: docs/testing.md:15, 46-663 (At a glance; sections 1-13; Before you push; Before a release; When you add a feature); weft/CHANGELOG.md:193 (0.18.1: docs/testing.md); weft/README.md:1039-1043 (Testing: docs/testing.md covers every kind of test)'
---

# How the weft repository is organised and checked

The weft repository is one Go workspace that joins two published modules, the framework (the repository root) and `core`, plus two example modules. Every promise the docs make about the API, the transcript and the session format is held by a check that runs in CI. The checks are race-detected tests, lint, an API-compatibility gate per module, and a check that the generated facades are complete. They add an offline run with model requests denied, fuzzing, a kill -9 crash matrix, performance budgets, and a freshness gate for the committed Studio build. This page says where things live and why each gate exists; [How weft is put together](https://weftgo.dev/docs/explanation/architecture/) explains the modules and layers themselves.

## Where things live

`go.work` lists four modules: `.` (the framework, `github.com/weftgo/weft`), `./core` (the loop, `github.com/weftgo/weft/core`), `./examples/otel` and `./examples/studio-local`. Every other directory below is a package of the framework module.

| Directory | What is there |
|---|---|
| `core/` | The loop module: messages, errors, tools, the model seam, events, the loop; `core/mw` (reference middleware) and `core/wefttest` (scripted models, `wefttest/conformance`). Its only dependency is the OTel API. |
| `facade.go`, `mw/`, `wefttest/`, `wefttest/conformance/` | The generated facades over `core`: every exported name of the core package is re-exported under the framework import path. |
| `openai/`, `anthropic/`, `google/` | Provider adapters, each with an `example/`. |
| `mcp/` | MCP in both directions. |
| `thread/` | Sessions, with `jsonl/`, `sqlite/`, `pool/`, `backend/` and the test kit `threadtest/`. |
| `otel/`, `obsdb/`, `studio/`, `runtime/`, `scope/` | The observability pipeline, its database (`obsdb/sqlite`, `obsdb/clickhouse`, `obsdb/obsdbtest`), the Inspector (with its Bun source in `studio/web/` and the committed build in `studio/dist/`), the playground's in-app side, and the scope header. |
| `cmd/weft/` | The `weft` binary; the one binary that links the ClickHouse backend (`obsdb/clickhouse`, which imports the driver). |
| `internal/` | Shared code no user imports: `facadegen` and `internal/cmd/genfacade` (the facade generator), `adapterkit` (the adapters' SDK-free helpers: schema rendering, the terminal-error rule, the `FilePart` guard, once instead of three copies), `listen` (Studio's port policy), `discovery`, `doctor`, `termsafe`. |
| `examples/` | Runnable programs: `getting-started` and `approval` (packages of the root module), `otel` and `studio-local` (modules of their own), `devtools-vite` (the npm app `make devtools-vite-check` installs the packed `@weftgo/devtools` package into). |
| `version/` | The one version string the panel stamp and the meta goldens follow. |
| `docs/` | ADRs (`docs/adr/`), the agent-loop deep dive, the life of a call, the record contract, thread operations, the `weft mcp` recipe. |
| `scripts/` | `apidiff.sh`, `apidiff-selftest.sh`, and `ux-gate/` (the Playwright gates of the UX audit). |

## Development

Go 1.26 or newer builds the repository. Code the three provider adapters share without a vendor SDK (schema rendering, the terminal-error rule, the `FilePart` guard) lives once in `internal/adapterkit`, so a change to it reaches all three adapters and no user API. CI tests two Go versions, `1.26.x` and the current `stable`: the support policy is the current release and the one before it, and `go.mod` pins the minimum.

The make targets each loop over the modules `go list -m` reports from `go.work`, so one command covers the framework, `core` and the example modules alike:

| Target | What it runs | In CI |
|---|---|---|
| `make build` | `go build ./...` in every module | `test` job |
| `make test` | `go test -race ./...` in every module | `test` job, both Go versions |
| `make vet` | `go vet ./...` in every module | `test` job |
| `make lint` | golangci-lint v2.14.0 in every module, one shared `.golangci.yml` | `lint` job |
| `make fmt`, `make tidy` | `go fmt`, `go mod tidy` in every module | — |
| `make generate` | `go generate ./...`: the four facades, and `studio/pricing.json` | the facades checked by `TestFacadesAreComplete`, `pricing.json` by `studio/pricing_test.go` |
| `make tools` | installs the pinned `apidiff` | `apidiff` job pins the same version |
| `make apidiff` | the framework module vs its last `v*` tag (reported) | — |
| `make apidiff-core` | `core` vs its last `core/v*` tag (enforced) | — |
| `make apidiff-all` | every `go.work` module under its own policy | `apidiff` job |
| `make apidiff-selftest` | the gate's own failure modes | `apidiff` job |
| `make offline` | every module's tests with `WEFT_MODEL_REQUESTS=deny` | `offline` job |
| `make fuzz` | every `Fuzz*` target of `core`, `FUZZTIME` each (10 s) | `fuzz` job |
| `make fuzz-thread` | the fuzz targets of `thread` and `thread/jsonl` | `fuzz` job |
| `make soak-thread` | `thread` with `-race -count=10`, `thread/sqlite` with `-race -count=3` | nightly `Soak` workflow |
| `make stress` | race tests under load: two busy loops, `GOMAXPROCS=2`, `-cpu 1,2` | — (run before pushing concurrent code) |
| `make live` | adapter conformance against real providers (`-tags live`) | never: CI has no keys |
| `make mcp-check` | `weft mcp` over stdio against a real `weft studio` seeded with the record-contract fixtures. Since 0.19.0 it also seeds four investigation shapes run on `wefttest` scripts through the `otel` pipeline: a failed subagent, six children with four failure shapes, a turn denied by alice, a nine-turn session. It asserts what `explain_failure` and `session` answer (`-tags livecheck`) | — (it listens on a port) |
| `make vacuum` | `weft vacuum` on `$WEFT_DB`, else `./.weft/weft.db` | — |
| `make studio-build` | `bun install --frozen-lockfile && bun run build` in `studio/web` | `devtools-vite` job |
| `make studio-check` | the Studio freshness gate, below | `studio` job |
| `make studio-bin` | builds `./weft` from `./cmd/weft` (git-ignored) | — |
| `make studio-panel-asset` | stages the panel file and its sha256 for non-Go backends in `RELEASE_DIR` (default: a git-ignored directory under `studio/web`; a relative path resolves from the repository root) | — |
| `make devtools-npm` | checks the assembled `@weftgo/devtools` package and lists its tarball; never publishes | — |
| `make devtools-vite-check` | installs the packed `@weftgo/devtools` in a real Vite app and smoke-tests the bundle in jsdom | `devtools-vite` job |

AGENTS.md asks for `make test`, `make vet` and `make lint` before a change is called done, a test in `core/contract_test.go` for any promise added or changed, and a godoc example for any public feature. It also asks that the doc which applies (README, ADR, AGENTS.md, thread operations, record contract, MCP recipe) is updated in the same change.

## CI and gates

CI is `.github/workflows/ci.yml`, run on every push to `main` and `devtools-plan` and on pull requests, and `.github/workflows/soak.yml`, run nightly and on demand. Each gate exists because a class of mistake would otherwise ship silently.

Since 0.18.1 one guide in the repository, [`docs/testing.md`](https://github.com/weftgo/weft/blob/v0.20.2/docs/testing.md), covers every kind of test weft runs. It covers the Go suite and its contract tests, godoc examples, the offline gate, `wefttest` and the conformance suite, and the `live` tag. It also covers fuzz, stress, the nightly soak, ClickHouse, Studio and the panel, `make mcp-check`, API stability, the phase gates and the arena. For each it says what the test proves, the command, when it runs and how long it takes, and how to reproduce a failure, and it ends with what to run before a push and before a release.

### Tests, vet, lint

The `test` job runs vet, `go test -race` and build in every module on both Go versions. The `lint` job pins golangci-lint to v2.14.0 so lint results do not drift with the linter's rule set; the Makefile names the same version. The `live` suite never runs in CI: it needs provider keys and is a release-time step.

### The apidiff gate

`scripts/apidiff.sh` compares a module's public Go API with that module's newest tag, and every module in `go.work` has a policy in it:

- **`core` is enforced.** Against the newest `core/v*` tag, any incompatible change fails the build. Before 1.0, a deliberate source-compatible change that apidiff flags (widening a return type to a superset interface, adding a trailing variadic) can be acknowledged by listing apidiff's exact line in `core/.apidiff-allow`; the file is reset at each tag. A rename or a removal always fails.
- **The framework module is reported.** Against the newest `v*` tag, incompatible changes are printed, not fatal, because the module holds the pre-freeze layers: `thread`, `obsdb`, `otel`, `runtime`, `studio`. The report is what a release reads: an incompatible line makes the next tag a minor bump with a breaking CHANGELOG entry, and for `thread` a line in the CHANGELOG's migration checklist.
- **`examples/*` are skipped.** They are never tagged.
- **A module with no policy fails** (exit 2), so adding a module to `go.work` forces a decision about it.

The gate fails closed. Each side (the tag's tree and the working tree) is built first; a tree that does not compile, or an apidiff run that dies before writing a report, cannot reach the "no incompatible changes" path. `scripts/apidiff-selftest.sh` proves it in CI before the gate runs, with eight cases in a throwaway worktree. A clean `core` reads green, and an incompatible `core` change fails the core gate. A `core` that does not compile fails before apidiff runs. A clean root reads green, and an incompatible root change is reported without failing, because the root's gate only reports. A root that does not compile fails even so. A root that needs an untagged `core` change loads through the workspace and says so, while `APIDIFF_STRICT=1` refuses it. A module with no policy is refused.

Each side loads with `GOWORK=off` first, so its requirements resolve from published tags as a user's would. Between releases the root may legitimately need an untagged `core` change (a release is two tags, the `core` tag first, then the framework's); the gate then notes it and loads through the workspace. `APIDIFF_STRICT=1 make apidiff-all` turns that note into a failure, the release-time check that every module builds from published tags alone.

The gate has changed shape with the modules. It started as `scripts/apidiff.sh` with the `.apidiff-allow` file; in 0.8.0 it covered every workspace module of the time (root, `thread`, `thread/sqlite`, the adapters, `obsdb/clickhouse`, `otel`, `runtime`, `studio`), and `make apidiff-all` replaced the per-module CI steps, with the adapters' `go.sum` files tidied so they built `GOWORK=off`. A `thread/sqlite` gate (`make apidiff-sqlite`) and a `store` step existed briefly; the store module was deleted (ADR 0024), and since 0.9.0 all of those directories are packages of the one framework module (ADR 0027), so two policies remain: `core` enforced, the root reported.

### The facade check

The root package, `mw`, `wefttest` and `wefttest/conformance` are generated from `core` by `internal/cmd/genfacade` (each `facade.go` carries its `go:generate` line). `TestFacadesAreComplete` in the root's `facade_test.go` fails when core exports a name the facade does not re-export, when a facade declares a name core does not export, or when the committed file differs from what the generator writes today. Run `make generate` after changing core's exported API. The test reads `core/` beside the module, so it runs in the repository and skips in a module zip.

### The offline gate

The `offline` job runs every module's tests with `WEFT_MODEL_REQUESTS=deny`. Under it, a first-party adapter refuses to call its provider with a client it built from credentials, so a test that would reach the network fails loudly instead. The adapters' own suites inject SDK clients, which are test doubles by construction and stay reachable, so the whole workspace stays green under deny. [Test against the adapter contract](https://weftgo.dev/docs/testing/conformance/) covers the switch.

### Fuzzing

The `fuzz` job runs `make fuzz` and `make fuzz-thread`, 10 s per target, on stable Go and without `-race` (the seeds already run under `-race` in `test`). The core targets are `FuzzToolInvokeArgs`, `FuzzRepair`, `FuzzUnmarshalEvent`, `FuzzMessageUnmarshal`, `FuzzPartialJSON` and `FuzzRawRedaction`. The thread targets are `FuzzDecodeEntry`, `FuzzDecodeHeader` (the header envelope rule and its canonical fixpoint), `FuzzDecideSigned` (the signed-decision verifier over hostile input: it must answer from its error catalogue and record nothing without the MAC), `FuzzGrantMatches` (the grant predicate, deterministic and panic-free) and `FuzzLoad` in `thread/jsonl`. A crasher fails the job and is uploaded as an artifact; the fix commits it under `core/testdata/fuzz/`, `thread/testdata/fuzz/` or, for `FuzzLoad`, `thread/jsonl/testdata/fuzz/` as a regression seed, which every later `go test` runs. A new message part or event type adds a seed.

### The crash matrix and the race soak

`threadtest.CrashMatrix` runs on `thread/jsonl` and `thread/sqlite` over 20 write points the session layer owns. Twelve are explicit: the prompt entry, the turn-end batch, an approval's park, a decision, a compaction, a steer's receipt, the pool's receipt, a branch, a fork, the steer queue's clear, `Resume`'s arm entry and `DecideSigned`'s batch. The rest are the writes the machinery makes on its own: the expiry sweep, the automatic trim, a queued send's receipt, the resume join, a fork's settling entries, and a live pool's parked, canceled and capped receipts. At each point a child process proves the write durable and dies with kill -9; a fresh process reopens the session and continues it. On sqlite each point also re-proves lock takeover from a dead holder. This is the evidence for [T4, accepted input is durable](https://weftgo.dev/docs/explanation/design-principles/#the-thread-rules).

The nightly `Soak` workflow (`make soak-thread` locally) runs the `thread` suite ten times and `thread/sqlite` three times under the race detector: the crash matrix, the one-writer tables and the pool's scheduling tests are where a single pass can miss a flake.

### The budget suite

`thread`'s budget tests pair each operator-visible cost with a `Benchmark` for the number and a `TestBudget…` that fails over a bound set about an order of magnitude above the measured time. The budgets cover append latency on `Memory` (time, and allocations without `-race`), opening a 100k-entry session on jsonl and sqlite, building the context after 50 compactions, and listing 10k sessions. They run in the ordinary `test` job, so a performance regression fails CI like a correctness one.

### Golden files

Byte-exact outputs are committed and compared: `wefttest.Golden` for test fixtures, the `weft.json` manifest, and Studio's `/api/meta` (`TestMetaGolden`). A release's version bump regenerates the meta golden and the panel stamp; `TestVersionIsTheModules` fails on a stale or hand-edited panel stamp.

### The ClickHouse job

The `clickhouse` job starts a `clickhouse-server` service container with a health check, then runs `obsdb/clickhouse`'s gated conformance suite and `cmd/weft`'s `TestNewServerClickhouse` against it. A gated test that skips fails the job, and the second step must report that test passed, so a DSN the tests cannot read never turns the job green.

### The Studio and panel gates

The `studio` job runs `make studio-check` with Bun pinned to the version the committed build was made with; `devtools-vite` runs after it. Both are described under [Contributing to the UI](#contributing-to-the-ui).

To try the Studio a change produces as the `weft` binary, `make studio-bin` builds `./weft` from `./cmd/weft` (git-ignored).

### Reviews that are not jobs

Some checks are release reviews rather than CI. The thread 0.7.0 train recorded two with no findings. One was a security review: constant-time HMAC compare, the length-prefixed canonical encoding, the fail-closed check order, `ValidID` at every backend entry point, files 0600 and directories 0700, flock per session with takeover from a dead holder. The other was an API review mapping every exported name to a feature its ADR names. That API review also noted that the AGENTS.md API block had outgrown one screen and proposed a one-screen core with godoc carrying the rest. The UX audit's phase gates live in `scripts/ux-gate/` (Playwright journeys over a real Studio and the panel) and run by hand.

## Contributing to the UI

Studio's web app lives in `studio/web/`: TanStack Start in SPA mode, React, shadcn/ui on Tailwind v4, built with Bun. Users never need it: the build output is committed in `studio/dist/` and embedded with `go:embed`, so `go get` gives a working Inspector with no JavaScript toolchain.

```sh
make studio-build   # cd studio/web && bun install --frozen-lockfile && bun run build
make studio-check   # rebuild, prove dist is fresh, check the 800 KiB gzip budget, typecheck + test
```

`make studio-check` is the freshness gate (ADR 0018 §4). A committed build can drift from its source, and the gate makes that drift a CI failure. It fails when:

- `studio/dist` differs from a fresh build of `studio/web`, or contains files the commit does not;
- the gzipped total of `studio/dist` exceeds 800 KiB (700 KiB before 0.19.0; the panel bundle included);
- `studio/web/npm/package.json` does not carry the weft version;
- the web typecheck or tests fail, or the `@weftgo/devtools` package suite or its consumer type-check fails.

The build is deterministic, which the gate depends on: two builds from one tree are byte-identical (`studio/web/scripts/clean-dist.ts` pins the router's prerender timestamp and keeps `<base href>` first in `<head>`).

The dev loop is two terminals:

```sh
go run ./studio/examples/basic -serve                 # API + embedded UI on :7331
cd studio/web && bun run dev -- --base /studio/       # Vite on :3000, proxying /studio/api
```

Two further harnesses exercise the panel. `make devtools-vite-check` packs `@weftgo/devtools`, installs the tarball into `examples/devtools-vite` (whose Vite and jsdom versions come from a committed lockfile), builds it with `vite build`, and proves the bundle mounts `<weft-devtools>` and that the installed `panel.js` is `studio/dist/panel/panel.js` byte for byte. `studio/web/scripts/panel-gate.ts` drives the built panel bundle in jsdom against a live Studio, using `examples/studio-local` as the host page; studio-local registers its thread store with the runtime so the panel's fork mode works there.

## See also

- [How weft is put together](https://weftgo.dev/docs/explanation/architecture/)
- [Design principles: the rules weft keeps](https://weftgo.dev/docs/explanation/design-principles/)
- [Architecture decision records](https://weftgo.dev/docs/explanation/decisions/)
- [Test against the adapter contract](https://weftgo.dev/docs/testing/conformance/)
- [The weft repository on GitHub](https://github.com/weftgo/weft/tree/v0.20.2)
