> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gatojs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Working on the kit repository

> How the GatoJS repository is organised for kit development: kit-only files, kit/kit.json, module manifests and kit sync, file ownership, hashes, placeholders, the CLI bundle and its tests, kit CI and workspace packages.

The GatoJS repository is two things at once: a working reference application with the core and every kit module installed, and the source of every project the CLI assembles. This page is for changes to the kit itself: the CLI, module manifests, kit workflows and releases. For how projects consume the kit, see [Working with the kit](https://docs.gatojs.com/guides/working-with-the-kit.md).

## Kit-only files

Most files are copied into projects. The ones that are not are listed as patterns in `kitOnly` in `kit/kit.json`:

| File or directory | Role |
| - | - |
| `kit/kit.json` | Kit configuration: version, repository, kit-only files, placeholders, generated and managed files ([reference](#kit-configuration)). |
| `kit/modules/<name>.json` | Module manifests ([Manifests](#module-manifests)). |
| `kit/release/` | The semantic-release package ([Releases](https://docs.gatojs.com/contributing/releases.md)). |
| `kit/README.md`, `kit/CLAUDE.md` | CLI notes and the rules for kit-only files. |
| `packages/gato-cli/`, `packages/create-gato-app/` | The tool packages published to npm ([Workspace packages](#workspace-packages)). |
| `.wa/kit.json` | The kit's own state, written by `kit sync`. A project gets its own, written by `gato create`. |
| `.github/workflows/kit.yml`, `kit-mutation.yml`, `packages.yml`, `publish-packages.yml`, `release.yml` | Kit CI, packaging, publishing and releases. |
| `prisma/migrations/.gitignore` | The kit commits no migrations; a project commits its own. |
| `docs/`, `.superpowers/**`, `.claude/handoffs/**` | Internal documentation and process notes. |
| `LICENSE`, `NOTICE`, `SECURITY.md`, `CONTRIBUTING.md`, `CODE_OF_CONDUCT.md`, `.github/README.md`, `.github/CODEOWNERS`, `.github/dependabot.yml`, the pull request and issue templates | Open-source project files. |

App tooling skips `kit/`: ESLint, Vitest, TypeScript and the Docker image ignore it. The reverse is not true: core workflows (`ci.yml`, `e2e.yml`, `mutation.yml`, the security workflows) belong to `core`, so they reach projects and also run in the kit, on the reference app with every module.

## Module manifests

Every kit module has `kit/modules/<name>.json`. Its `name` must equal the file name, otherwise reading the manifests fails with `kit/modules/<file>: name "<name>" nie zgadza się z nazwą pliku`. Manifests are read `core` first, then alphabetically. The schema is the same as in a project's `.wa/kit.json`; every field is documented in the [module manifest reference](https://docs.gatojs.com/cli/kit-json.md#module-manifest).

| Field | Read by | For |
| - | - | - |
| `name`, `description`, `version` | `create`, `add`, `list`, `kit sync` | Name in `--modules` and `add`, description in prompts and `list`, version recorded in projects |
| `requires` | `create`, `add`, `remove`, `list`, state validation | Modules added together; refusing to remove a required module |
| `files` | `create`, `add`, the ownership test, `generate` | Which files to copy; file ownership; feature detection |
| `dependencies`, `devDependencies` | `create`, `add`, `remove`, `update`, the ownership test | npm dependencies added to and removed from projects |
| `env` | `generate` | The `wa:modules` region in `.env.example` |
| `schemaRelations` | `generate` | The `wa:relations` regions |
| `compose` | `generate`, the ownership test | The `wa:services` region in `docker-compose.yml` |
| `ciSteps` | `generate` | The `wa:ci-integration` regions in `ci.yml` and `mutation.yml` |
| `workspaces` | nothing | Reserved |

### File patterns

Patterns know `**/`, `**` and `*`; everything else is literal and braces are not supported. They are matched against the git index (`git ls-files`), minus `kitOnly` and `generatedFiles`, but file content is read from the working tree. Two consequences when you work on the kit:

* an uncommitted edit to a tracked file goes into a project assembled from your checkout;
* a new file is invisible to `create` and the ownership test until you `git add` it.

The CI `assemble` job builds from a commit checkout, so there both match.

### Docker and CI files of a module

`compose` and `ciSteps` point at files the generator reads **from the project**, so they must belong to the same module's `files`. Keep them as `docker/<name>.compose.yml` (service definitions without the `services:` key, indented by two spaces on insertion) and `ci/<name>.integration-steps.yml` (a list of job steps, indented by six). The ownership test checks only the `compose` file; a `ciSteps` file outside the module passes the test and then breaks `create` with `ENOENT`.

## Kit sync

The kit repository has its own `.wa/kit.json`. Never edit it by hand; rewrite it with:

```bash theme={null}
npm run wa -- kit sync
npm run wa -- generate
```

`kit sync` builds the state from `kit/kit.json` and the manifests: `kitVersion` and `kitRepo` from `version` and `repo`, `project` from the placeholders, `locales` always `["pl", "en"]`, every manifest under `modules` with empty `files`, and `projectModules` kept from the existing file. It prints `Zaktualizowano .wa/kit.json` (updated) or `Bez zmian` (no changes). Outside the kit it fails with `Brak kit/kit.json w <dir> — to nie jest repozytorium wa-kit`.

`kit sync` does not run the generator, so run both after every change to `kit/modules/*.json` or `kit/kit.json` and commit the result. The `cli` job in `kit.yml` runs the same two commands and fails if the result differs from what you committed.

## File and dependency ownership

Every kit file that can reach a project has exactly one owner: the module whose `files` pattern covers it. Without that, `create` would skip a file or copy it twice, and `remove` could delete a file another module needs. Every npm dependency in the kit's `package.json` must be declared by a manifest, in the same section, at the same version.

The ownership test enforces this on the real repository:

```bash theme={null}
npm ci
cd packages/gato-cli && npx vitest run src/kit/__tests__/ownership.test.ts
```

| Report field | Meaning | Fix |
| - | - | - |
| `unowned` | A tracked file outside `kitOnly` and `generatedFiles` that no manifest covers | Add a pattern to its module, or to `kitOnly` |
| `multiOwned` | A file covered by two modules | Narrow the patterns |
| `globErrors` (`empty`) | A pattern that matches nothing | Fix or remove it |
| `globErrors` (`brace`) | A pattern with `{` | Split it into separate patterns |
| `unownedDependencies` | A `package.json` dependency no manifest declares in that section | Add it to the owner's manifest |
| `dependencyMismatch` | A manifest dependency at a different version than `package.json`, or missing there | Use the same version in both |
| `composeOutsideModule` | The `compose` file is not in the module's `files` | Add it |

Limits: the test sees only the git index (run it after `git add`), does not count dependency owners (the same dependency in two manifests passes), does not check `ciSteps`, and does not ship to projects. Updating a dependency in the kit is always two edits: `package.json` (with the lockfile) and the owning manifest.

## File hashes

`create`, `add` and `update` record a value per copied file under `modules.<name>.files` in the project's `.wa/kit.json`, computed after placeholder replacement:

| File | Value |
| - | - |
| In `managedFiles` (`package.json`, `package-lock.json`) | `managed` |
| A file with `wa:*` regions (`REGION_FILES`) | SHA-256 without the lines inside regions |
| Any other file | SHA-256 of the bytes |

`REGION_FILES` comes from `regionTargets` in `packages/gato-cli/src/generate/targets.ts`, so a new region in a new file is a CLI change, not a manifest change. All files with regions belong to `core`. Generated files are not copied and have no hash. In the kit's own `.wa/kit.json`, `files` is empty.

## Placeholders

The kit is a working app named "WA App". When a file listed in `placeholderFiles` is copied, the CLI replaces its names with the project's, as plain string replacement in this order:

| In the kit | Replaced with | For `acme-app` |
| - | - | - |
| `WA App` | Display name | `Acme App` |
| `wa-app` | Slug | `acme-app` |
| `wa_app` | Slug with `_` | `acme_app` |

* A file that contains the project name, slug or database name goes into `placeholderFiles`, otherwise projects inherit `wa_app` (and, for example, share the test database `wa_app_test`).
* Do not use those strings with another meaning in a listed file.
* Do not add tests to the list (a convention; nothing enforces it).
* `placeholderFiles` holds exact paths, not patterns.

The `assemble` job greps an assembled project for the three strings (outside tests, `package-lock.json` and `.wa/bin/**`) and fails if any remain. Separately, the generator replaces `{{projectSlug}}` and `{{projectName}}` in manifest `env` examples on every run.

## The CLI bundle

The CLI source lives in `packages/gato-cli/src`. One esbuild run produces two bundles that differ only in the command name they print:

* `.wa/bin/wa.mjs`, **committed**, owned by `core`, so every project gets it byte for byte and runs `npm run wa -- <command>` without building anything;
* `packages/gato-cli/dist/gato.mjs`, not committed, published to npm as `gato-cli`.

Both embed the version from `packages/gato-cli/package.json`. After every change in `packages/gato-cli/src`:

```bash theme={null}
npm run build --prefix packages/gato-cli
```

and commit `.wa/bin/wa.mjs` together with the change. The build is reproducible when dependencies come from `npm ci` in the repository root. In CI, the `cli` job's "Kit state and generated files are up to date" step (`git diff --exit-code` after verify, which rebuilds the bundle) stops a pull request with a stale bundle.

## CLI tests and the mutation gate

The CLI is the `packages/gato-cli` workspace; its dependencies are in the root `package-lock.json`. Install with `npm ci` in the root and add dependencies with `npx -y npm@11.21.1 install <package> --workspace gato-cli`.

| Command | What it does |
| - | - |
| `npm run verify --prefix packages/gato-cli` | The CLI gate: lint, typecheck, tests, bundle build |
| `npm run lint --prefix packages/gato-cli` | ESLint with the package's own config |
| `npm run typecheck --prefix packages/gato-cli` | `tsc --noEmit` |
| `npm test --prefix packages/gato-cli` | Vitest in Node; tests copy fixtures into a temporary directory |
| `npm run build --prefix packages/gato-cli` | Typecheck and both bundles |
| `npm run test:mutation:task --prefix packages/gato-cli -- <files>` | Stryker on the given files (paths relative to `packages/gato-cli`) |
| `npm run test:mutation --prefix packages/gato-cli` | Full incremental Stryker run, `break` threshold 75% |
| `npm run test:mutation:gate --prefix packages/gato-cli` | The gate for the CLI's critical files |

Mutation testing works as in the app ([Testing](https://docs.gatojs.com/guides/testing.md)): tests are written before the implementation and a test reviewer runs Stryker and the gate. CLI specifics:

* The critical directories are `src/generate/`, `src/manifest/`, `src/assemble/`, `src/commands/` and `src/kit/`; `allowed` entries in `packages/gato-cli/mutation-gate.json` are added by a human.
* Stryker mutates `src/**/*.ts` except tests and `src/bin.ts`, with `concurrency: "50%"`, `timeoutFactor: 5` and `vitest.related: false`. The CLI's command tests assemble projects with git and are slow under parallel load; these settings keep timeouts stable. Inside Stryker workers, test files run smallest first in a fixed order.
* Never run two Stryker runs at once, including one in the app and one in the CLI.
* Before the first full run after a config change, pass `--force` or delete `reports/stryker-incremental.json`; `test:mutation:task` always uses `--force`.

A change to the kit passes both gates before a pull request: `npm run verify` and `npm run verify --prefix packages/gato-cli`.

## Kit CI

`.github/workflows/kit.yml` runs on pushes and pull requests to `main`:

| Job | What it checks |
| - | - |
| `cli` | `npm ci`, the CLI gate (including the ownership test), then `kit sync` + `generate` + `git diff --exit-code`: the kit state, generated files, regions and bundle are up to date. |
| `release-scripts` | `npm ci --prefix kit/release` and `npm test --prefix kit/release`. |
| `cli-package` | Packs `gato-cli` as npm would, installs the tarball into an empty prefix, checks `--version`, `help` and an unknown command, creates a project from the checkout and runs `list` and `generate` in it. |
| `assemble` | For each module combination (`core`, `audit-logs`, `api-keys`, `uploads`, `all`): creates a project from the checkout with `--yes`, checks the test gates and no leftover placeholders, validates and migrates the schema, checks generated files, runs `npm run verify` and the integration tests (with MinIO for `uploads`), builds the Docker image (`core` and `all`), and registers a fixture project module without editing core tests. |

`kit-mutation.yml` runs the full CLI Stryker run and gate on demand. `packages.yml` verifies `create-gato-app` and smoke-tests the packed tarballs of both tool packages.

Notes for people who change CI or the CLI contract:

* The `assemble` job starts MinIO with its own steps, which repeat `ci/uploads.integration-steps.yml`. Changing the MinIO or aws-cli image means changing both and `docker/uploads.compose.yml`.
* Changing the `projectModules` contract requires updating the fixture `packages/gato-cli/src/__tests__/fixtures/project-module/` and the manifest object written in the registration step.

## Workspace packages

Code that needs its own package lives in `packages/`, in two kinds:

* **Tool packages** (`packages/gato-cli`, `packages/create-gato-app`): unscoped npm names, their own build to `dist/`, their own TypeScript, ESLint, Vitest and Stryker setup, published to npm from tags ([Releases](https://docs.gatojs.com/contributing/releases.md)). They are in `kitOnly`, so a project never gets them; it installs `gato-cli` from npm.
* **Project packages** (`@gatojs/<name>`, `private: true`, for example `packages/env` and `packages/observability`): copied into projects like any kit file and owned by a manifest through `files`. No build step: `exports` point at TypeScript sources, consumed through `transpilePackages`. A project package declares its npm dependencies in its own `package.json`.

There is one lockfile. `gato create` copies it without the tool packages' entries and links. The `deps` stage of the `Dockerfile` has a `wa:workspaces` region that `generate` fills with a `COPY packages/<name>/package.json` line per package. A new tool package also goes into `TOOL_PACKAGES` (`scripts/lib/architecture/workspaces.ts`), `kitOnly`, the root ignores (`tsconfig.json`, `eslint.config.mjs`, `vitest.config.ts`, `stryker.config.json`) and, if it has its own ESLint config, `.lintstagedrc.json`.

## Kit configuration

`kit/kit.json` configures the kit. All fields are required. A missing file gives `Brak kit/kit.json w <dir> — to nie jest repozytorium wa-kit`; a wrong shape gives a Zod error.

| Field | Type | Value in the kit | Read by |
| - | - | - | - |
| `version` | `string` | The kit version, for example `0.8.1`. Written only by the release. | `create` (`kitVersion`, first commit message), `add`/`list` with a local source, `update`, `kit sync` |
| `repo` | `string` | `https://github.com/webamigos/gatojs.git` | `create` (`kitRepo`), `kit sync` |
| `kitOnly` | `string[]`, patterns | Kit-only files | `create`, `add`, `update`, the ownership test |
| `placeholders` | `{ projectName, projectSlug, projectSnake }` | `WA App`, `wa-app`, `wa_app` | `create`, `add`, `update`, `kit sync` |
| `placeholderFiles` | `string[]`, exact paths | Files with project names | `create`, `add`, `update` |
| `generatedFiles` | `string[]`, patterns | The three generated files | `create`, `add`, `update`, the ownership test |
| `managedFiles` | `string[]`, exact paths | `package.json`, `package-lock.json` | `create`, `add`, `update` (value `managed` instead of a hash) |

## Commands for kit work

| Command | When |
| - | - |
| `npm ci` | Install everything, the CLI included |
| `npm run wa -- kit sync` | After changing `kit/modules/*.json` or `kit/kit.json` |
| `npm run wa -- generate` | After `kit sync` and after feature changes |
| `npm run build --prefix packages/gato-cli` | After every change in `packages/gato-cli/src`; commit `.wa/bin/wa.mjs` |
| `npm run verify --prefix packages/gato-cli` | The CLI gate |
| `node .wa/bin/wa.mjs create <dir> --yes --kit .` | Assemble a trial project from your checkout, as the `assemble` job does. Add `--modules <list>`, and `--no-install --no-git` to only look at the files. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.