Skip to content

Commit 54b9b30

Browse files
docs: describe the state/ folder and how an older repository moves into it
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
1 parent 8920e9d commit 54b9b30

13 files changed

Lines changed: 169 additions & 49 deletions

‎AGENTS.md‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,23 @@ wizard needs a terminal. Instead:
110110
- Authoring from scratch → `npm run setup -- <org> --resources none` (state only, no files).
111111
Add `--region eu` for EU orgs if auto-detection picks the wrong one.
112112
4. Verify: `npm run validate -- <org>` passes, and `resources/<org>/` plus
113-
`.vapi-state.<org>.json` exist.
114-
5. Commit `resources/<org>/` (including `.vapi-org.json`) and `.vapi-state.<org>.json`. Never commit `.env.<org>`.
113+
`state/<org>/state.json` exist.
114+
5. Commit `resources/<org>/` and `state/<org>/`. Never commit `.env.<org>`.
115+
116+
`resources/<org>/` is hand-written: edit it. `state/<org>/` is written by the
117+
engine: never edit or delete anything in it (see [state/README.md](state/README.md)).
115118

116119
If a command stops because the key "belongs to Vapi org …, but resources/<org>/
117120
is pinned to org …", the key is for another org. Stop and tell the human.
118-
Never delete or edit `.vapi-org.json` to get past it: that file is the only
121+
Never delete or edit `state/<org>/org.json` to get past it: that file is the only
119122
thing tying the folder to its org.
120123

121124
If setup says the org is "already set up locally", don't delete anything to
122125
work around it — run `npm run pull -- <org>`, or ask the human.
123126

124127
**Working in an existing repository for the first time?** Run a plain
125128
`npm run pull -- <org>` before your first deploy. It seeds your local drift
126-
baselines (`.vapi-state-hash/`, which is per-developer and gitignored);
129+
baselines (`state/<org>/local/baselines/`, which is per-developer and gitignored);
127130
until then, the engine can't tell your edits from dashboard edits as
128131
precisely.
129132

@@ -145,7 +148,7 @@ precisely.
145148
`.env.<org>`, run `VAPI_PRIVATE_API_KEY=validate-only npm run validate -- <org>`;
146149
never ask for a real key just to validate. Don't weaken the check or the
147150
workflow to get past it, and never edit the state file, `.vapi-ignore` or
148-
`.vapi-org.json` to make a reference resolve: fix the name, or pull.
151+
`state/<org>/org.json` to make a reference resolve: fix the name, or pull.
149152
4. **Build PR checks offline** if `vapi-checks.yml` exists:
150153
`npm run check -- --all --dry-run`. Fix anything it reports.
151154
5. **Review the dry-run Name collisions list**, then **deploy only with a yes**
@@ -155,7 +158,7 @@ precisely.
155158
scoped to files: `npm run apply -- <org> resources/<org>/assistants/my-agent.md`.
156159
6. **Verify** with the human's agreement: `npm run call -- <org> -a <name>` or
157160
`npm run sim -- <org> --suite <name> --target <name>`.
158-
7. **Commit** the resource files and `.vapi-state.<org>.json`.
161+
7. **Commit** the resource files and `state/<org>/`.
159162

160163
**Why `apply`, not `push`:** `apply` pulls the platform's current state, merges
161164
your local edits, then pushes, so it never silently overwrites changes made in

‎README.md‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ org can keep using `VAPI_PRIVATE_API_KEY`.
137137
| Option | Default | Meaning |
138138
| --- | --- | --- |
139139
| `--region us\|eu` | `VAPI_BASE_URL` if set, else auto-detect (US, then EU) | Which Vapi API to use |
140-
| `--resources all\|none` | `all` | `all` downloads every resource into `resources/<org>/`; `none` only seeds `.vapi-state.<org>.json` (use when you'll author from scratch) |
140+
| `--resources all\|none` | `all` | `all` downloads every resource into `resources/<org>/`; `none` only seeds `state/<org>/state.json` (use when you'll author from scratch) |
141141

142142
The private API key is never accepted as a command-line flag (it would leak into shell history and
143143
agent transcripts). Non-interactive setup also refuses to run if `resources/<org>/` or
144-
`.vapi-state.<org>.json` already exists — use `npm run pull -- <org>` to refresh an existing org.
144+
`state/<org>/state.json` already exists — use `npm run pull -- <org>` to refresh an existing org.
145145

146146
### 4. Make a change and deploy
147147

@@ -153,7 +153,7 @@ npm run validate -- my-org # schema check, no network
153153
npm run apply -- my-org # pull the latest, merge, push
154154
```
155155

156-
Commit the changed files and `.vapi-state.my-org.json` so your team shares the
156+
Commit the changed files and `state/my-org/state.json` so your team shares the
157157
same name → UUID mappings. Every pull request runs the same validator for
158158
every org in CI (the **Validate resources** check), so a config `apply` would
159159
refuse fails before it merges.
@@ -176,7 +176,7 @@ To test every pull request automatically, set up [PR checks](docs/guides/pr-chec
176176
- **Resources refer to each other by ID.** A resource's ID is its path under
177177
the type folder, without the extension: `tools/lookup-patient.yml` is
178178
`lookup-patient`. Never paste UUIDs into resource files.
179-
- **The state file maps IDs to UUIDs.** `.vapi-state.<org>.json` records which
179+
- **The state file maps IDs to UUIDs.** `state/<org>/state.json` records which
180180
platform resource each file is, per org. It is committed and holds no
181181
secrets.
182182
- **Secrets stay out of git.** API keys live in `.env.<org>` (gitignored) or
@@ -194,7 +194,7 @@ To test every pull request automatically, set up [PR checks](docs/guides/pr-chec
194194
resource; an unlinked file otherwise creates a new one. `apply` uses the same
195195
folder behavior in its push phase.
196196
- **Each folder is pinned to its org.** The first command that can see which
197-
org a key belongs to records it in `resources/<org>/.vapi-org.json`. After
197+
org a key belongs to records it in `state/<org>/org.json`. After
198198
that, every command checks the key against it before any request, and stops
199199
if the key belongs to a different org, so a wrong key can't pull another
200200
org's resources into the folder or push the folder into another org.
@@ -204,11 +204,15 @@ To test every pull request automatically, set up [PR checks](docs/guides/pr-chec
204204

205205
| Path | Committed? | What it is |
206206
| --- | --- | --- |
207-
| `resources/<org>/` | Yes | Your resources, and `.vapi-org.json`, the org the folder belongs to |
208-
| `.vapi-state.<org>.json` | Yes | Name → UUID mappings for the org |
207+
| `resources/<org>/` | Yes | Your resources. Hand-written: this is what you edit |
208+
| `state/<org>/state.json` | Yes | Name → UUID mappings for the org |
209+
| `state/<org>/org.json` | Yes | The Vapi org the folder belongs to |
210+
| `state/<org>/local/` | No | This machine's baselines for detecting dashboard edits, and pre-deploy snapshots for `npm run rollback` |
209211
| `.env.<org>` | **No** | API key and generated binding IDs |
210-
| `.vapi-state-hash/` | No | Your local baseline for detecting dashboard edits |
211-
| `.vapi-state.<org>.snapshots/` | No | Pre-deploy snapshots for `npm run rollback` |
212+
213+
Everything under `state/` is written by the engine. Don't edit or delete it by
214+
hand: without `state.json` the next push creates every resource again as a
215+
duplicate. [state/README.md](state/README.md) says what each file is.
212216

213217
More detail: [How the engine works](docs/guides/how-it-works.md).
214218

@@ -286,7 +290,7 @@ object. API references: [Assistants](https://docs.vapi.ai/api-reference/assistan
286290
## Staying up to date
287291

288292
The engine (`src/`, `tests/`, `.github/workflows/`, `package*.json`) comes from
289-
upstream. Your configuration (`resources/`, `.vapi-state.*.json`,
293+
upstream. Your configuration (`resources/`, `state/`,
290294
`promotion.yml`, `vapi-checks.yml`) is yours; upstream only ships `*.example`
291295
files there. Avoid editing engine files, so updates merge cleanly.
292296

@@ -300,6 +304,9 @@ If you started from **Use this template**, add the remote first with
300304
`git remote add upstream https://github.com/VapiAI/gitops.git`; the first merge
301305
also needs `--allow-unrelated-histories`, and you'll resolve conflicts once.
302306

307+
If your repository still has `.vapi-state.<org>.json` files at its root, see
308+
[Upgrading from an older version](docs/guides/commands.md#upgrading-from-an-older-version).
309+
303310
## Security
304311

305312
Never commit API keys: `.env.*` files are gitignored, and the CLI never accepts

‎SECURITY.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ acknowledge the report and keep you updated as we investigate.
1515
- **Never commit API keys.** Keys live in `.env.<org>` files, which are
1616
gitignored, or in CI secrets. The tools never accept a key as a command-line
1717
flag, so it can't leak into shell history.
18-
- **Committed state contains IDs, not secrets.** `.vapi-state.<org>.json` maps
18+
- **Committed state contains IDs, not secrets.** `state/<org>/state.json` maps
1919
resource names to Vapi UUIDs. Credential secrets and phone-number
2020
provisioning are never written to the repository.
2121
- **`.ts` resource files run code.** Loading a TypeScript resource executes its

‎docs/guides/commands.md‎

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The other commands are direct only.
1414
| `npm run apply` | `npm run apply -- <org> [types or paths] [--adopt <id>[=<uuid>]]` | **The default deploy:** pull, merge, then push. The push preflight below runs before remote writes. See [workflows](workflows.md). |
1515
| `npm run pull` | `npm run pull -- <org> [--force] [--bootstrap]` | Sync platform changes down; never overwrites local edits unless `--force`. |
1616
| `npm run push` | `npm run push -- <org> [--dry-run] [--json] [--strict] [--adopt <id>[=<uuid>]]` | Push without pulling first. Prefer `apply`. Preflight blocks validation errors and unresolved credential names in the write plan (selected resources plus auto-applied dependencies) before any remote mutation, including deletions. `--dry-run` uses the same gate. `--strict` additionally blocks error-severity findings outside the plan; warnings remain advisory. Bootstrap reads may run before preflight. |
17-
| `npm run rollback` | `npm run rollback -- <org> --list` or `--to <ISO>` | Restore a pre-deploy snapshot from `.vapi-state.<org>.snapshots/`. |
17+
| `npm run rollback` | `npm run rollback -- <org> --list` or `--to <ISO>` | Restore a pre-deploy snapshot from `state/<org>/local/snapshots/`. |
1818
| `npm run cleanup` | `npm run cleanup -- <org> [--force --confirm <org>]` | List platform resources with no file; delete them only with both flags. |
1919
| `npm run audit` | `npm run audit -- <org> [--type <type>]` | Report drift between files, state and the platform. Exits 1 on any finding, so it can run in CI. |
2020
| `npm run call` | `npm run call -- <org> -a <assistant>` or `-s <squad>` | Talk to an assistant or squad from your terminal. |
@@ -193,14 +193,47 @@ The test-call CLI cleans its terminal output for the developer loop:
193193

194194
## Upgrading from an older version
195195

196-
Repositories created before the state-file format changed need a one-time
197-
migration. `pull`, `push` and `apply` refuse to run until it's done:
196+
`npm run migrate` brings an older repository up to date. It needs no org and
197+
no API key, and it's safe to run more than once:
198198

199199
```bash
200200
npm run migrate
201+
git add -A -- state ':(glob).vapi-state.*.json' resources
202+
git commit -m "chore: move engine state into state/"
201203
```
202204

203-
It rewrites every org's `.vapi-state.<org>.json` to the current
204-
`{ "name": { "uuid": … } }` format and seeds your local
205-
`.vapi-state-hash/` drift baseline from the old file. It's safe to run more
206-
than once. Commit the rewritten state files.
205+
It does two things.
206+
207+
**Moves engine files into `state/<org>/`.** They used to sit under dot-names
208+
in three places. Nothing changes inside the files.
209+
210+
| Before | Now |
211+
| --- | --- |
212+
| `.vapi-state.<org>.json` | `state/<org>/state.json` |
213+
| `resources/<org>/.vapi-org.json` | `state/<org>/org.json` |
214+
| `.vapi-state-hash/<org>/` | `state/<org>/local/baselines/` |
215+
| `.vapi-state.<org>.snapshots/` | `state/<org>/local/snapshots/` |
216+
217+
You don't have to run it for this: the engine keeps reading the old places,
218+
and the next `pull`, `push` or `apply` on your machine moves that org and
219+
says so in one line. Either way, commit the removal of the old file together
220+
with the new folder.
221+
222+
The move is held back in two cases, and the command tells you which:
223+
224+
- **In a CI run.** State stays where it is and is updated in place. Only a
225+
workflow that commits both places can record a move, so run
226+
`npm run migrate` on your machine and commit the result.
227+
- **When a workflow under `.github/workflows/` stages `.vapi-state.*.json` but
228+
not `state/`.** That workflow would commit the old file's removal without
229+
the new one. Take upstream's `promotion.yml` workflow, or add
230+
`git add -A -- state` to your own commit step, then run `npm run migrate`.
231+
232+
If both the old and the new file exist for an org and they disagree, every
233+
writing command stops before it changes anything and names the two files.
234+
235+
**Rewrites a legacy-format state file.** Repositories created before the
236+
state-file format changed carry per-resource hashes in the state file, and
237+
`pull`, `push` and `apply` refuse to run until they're gone. `migrate`
238+
rewrites each file to the current `{ "name": { "uuid": … } }` format and
239+
seeds this machine's drift baselines from the old file.

‎docs/guides/configuration.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,16 @@ Set these in GitHub under **Settings → Secrets and variables → Actions**.
4949
| --- | --- |
5050
| `promotion.yml` | Promotion pipelines between orgs. Start from `promotion.example.yml`. |
5151
| `vapi-checks.yml` | PR checks. Start from `vapi-checks.example.yml`. |
52-
| `resources/<org>/.vapi-org.json` | The Vapi org ID the folder belongs to. Written by the first command that can see the key's org, then checked by every command before any request: a key for another org stops the command. If a folder genuinely moves to another org, delete the file in a reviewed commit. |
5352
| `resources/<org>/.vapi-ignore` | Platform resources this repo shouldn't manage, as glob patterns. See `resources/.vapi-ignore.example` and [YAML conventions](../learnings/yaml-conventions.md). |
5453

54+
These are hand-written. The files the engine writes live apart from them, in
55+
`state/<org>/`, and are not configuration: don't edit them.
56+
57+
| File | Purpose |
58+
| --- | --- |
59+
| `state/<org>/state.json` | Which platform resource (UUID) each file under `resources/<org>/` is. |
60+
| `state/<org>/org.json` | The Vapi org ID the folder belongs to. Written by the first command that can see the key's org, then checked by every command before any request: a key for another org stops the command. If a folder genuinely moves to another org, delete the file in a reviewed commit. |
61+
5562
## Other environment variables
5663

5764
| Variable | Description |

‎docs/guides/how-it-works.md‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,24 @@
55
Resources are scoped by organization, with names you choose (not fixed `dev`/`stg`/`prod`). Each org gets:
66

77
- `.env.<org>` — private API key and base URL
8-
- `.vapi-state.<org>.json` — resource ID ↔ UUID mappings and optional origin (committed)
9-
- `.vapi-state-hash/<org>/<uuid>` — last-seen platform content hash per resource, used for drift detection (per-developer, gitignored)
10-
- `resources/<org>/` — all resource files
8+
- `resources/<org>/` — all resource files. Hand-written: this is what you edit
9+
- `state/<org>/` — what the engine generates and tracks. Never edit or delete it by hand ([state/README.md](../../state/README.md))
10+
- `state.json` — resource ID ↔ UUID mappings and optional origin (committed)
11+
- `org.json` — the Vapi org the folder is pinned to (committed)
12+
- `local/baselines/<uuid>` — last-seen platform content hash per resource, used for drift detection (per-developer, gitignored)
13+
- `local/snapshots/` — pre-deploy snapshots for `npm run rollback` (per-developer, gitignored)
1114

1215
```
1316
vapi-gitops/
1417
├── .env.my-org # Private API key for my-org
1518
├── .env.production # Private API key for production
16-
├── .vapi-state.my-org.json # State file for my-org
17-
├── .vapi-state.production.json # State file for production
19+
├── state/ # Written by the engine; don't edit by hand
20+
│ ├── my-org/
21+
│ │ ├── state.json # Name → UUID mappings for my-org
22+
│ │ ├── org.json # The Vapi org my-org is pinned to
23+
│ │ └── local/ # This machine only (gitignored)
24+
│ └── production/
25+
│ └── (same structure)
1826
├── resources/
1927
│ ├── my-org/ # Dev/test org resources
2028
│ │ ├── assistants/
@@ -93,7 +101,7 @@ authorize new name-based links. Existing exact-key legacy links remain intact.
93101

94102
Conflict handling is **per resource, never umbrella**: apply defaults to `--resolve=defer`, so the pull stage preserves local files and the drift baselines for genuinely conflicted resources, and the push stage then asks one interactive question per conflicted resource (push mine / keep dashboard / save a `.bkp` copy for manual merge). Clean and one-sided changes flow silently in their obvious direction. The full scenario matrix lives in `docs/learnings/sync-behavior.md`. Explicit `--resolve=ours|theirs|fail` keep non-interactive (CI) semantics.
95103

96-
Before updating a resource, push GETs its current dashboard payload, hashes it, and compares against the stored baseline (`.vapi-state-hash/<org>/<uuid>`):
104+
Before updating a resource, push GETs its current dashboard payload, hashes it, and compares against the stored baseline (`state/<org>/local/baselines/<uuid>`):
97105

98106
- **Hashes match** → your local edit is the natural next step in the change chain → pushed silently, and the baseline is refreshed from the PATCH **response** (what the platform actually stored).
99107
- **Hashes differ** → someone else published changes since your last sync. In a terminal, push asks **for that resource only**: ① push my local version (take ownership) ② keep the dashboard version (skip, local untouched) ③ save the dashboard version as `<name>.<TIMESTAMP>.bkp.<ext>` beside your file and skip, for a manual merge. In CI / piped runs the resource is blocked instead (use `--overwrite` to push unconditionally).
@@ -215,7 +223,7 @@ requests themselves; there is no separate telemetry.
215223
| Path | What it is |
216224
| --- | --- |
217225
| `resources/<org>/` | Your resources, one folder per org |
218-
| `.vapi-state.<org>.json` | Name → UUID mappings per org (committed) |
226+
| `state/<org>/` | What the engine generates and tracks: name → UUID mappings and the org pin (committed), plus `local/` (gitignored). Not edited by hand |
219227
| `.env.<org>` | API key and generated binding IDs (gitignored) |
220228
| `promotion.yml`, `vapi-checks.yml` | Promotion pipelines and PR checks (copy from the `*.example.yml` files) |
221229
| `resources/<org>/.vapi-ignore` | Platform resources this repo shouldn't manage (see `resources/.vapi-ignore.example`) |

‎docs/guides/pr-checks.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ promoted out of it: set `orgs.<org>.check: <name>` in `promotion.yml` (see
151151
2. Create the credentials your agents need there, with the same names as
152152
production.
153153
3. `npm run pull -- my-ci-org --bootstrap --bindings-only`, then commit
154-
`.vapi-state.my-ci-org.json` so the state knows those credentials. The PR
154+
`state/my-ci-org/state.json` so the state knows those credentials. The PR
155155
workflow refreshes bindings on every live run.
156156
4. Add `runOrg: my-ci-org` (and `baseUrl` for EU) to the check, and
157157
optionally `bindings:` (same shape as `promotion.yml`). Phone numbers are

‎docs/guides/promotion.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ left alone.
1111
1. Configure every org with `npm run setup`, using one stable slug per org
1212
(for example `acme-dev`, `acme-staging`, and `acme-prod`).
1313
2. Run `npm run pull -- <org> --bootstrap` for every org. Commit each
14-
`.vapi-state.<org>.json`; never commit `.env.<org>` or
15-
`.vapi-state-hash/`.
14+
`state/<org>/` folder; never commit `.env.<org>` (`state/<org>/local/`
15+
is gitignored already).
1616
3. Copy `promotion.example.yml` to `promotion.yml`. List orgs in forward-only
1717
release order and set the correct `baseUrl` for each region.
1818
4. Give each pipeline the narrowest resource globs it owns. A pattern is both
@@ -35,7 +35,7 @@ npm run promote -- --pipeline release --from dev --to staging --apply
3535
Promotion copies logical references, not physical UUIDs. Dependencies such as
3636
tools and structured outputs are included before assistants, and the normal
3737
destination push resolves every logical name through
38-
`.vapi-state.<destination>.json`. Existing credentials and phone numbers use
38+
`state/<destination>/state.json`. Existing credentials and phone numbers use
3939
the destination org's binding; their secret material is never copied or
4040
provisioned.
4141

0 commit comments

Comments
 (0)