Skip to content

Commit 720effd

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 88bf713 commit 720effd

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
@@ -109,20 +109,23 @@ wizard needs a terminal. Instead:
109109
- Authoring from scratch → `npm run setup -- <org> --resources none` (state only, no files).
110110
Add `--region eu` for EU orgs if auto-detection picks the wrong one.
111111
4. Verify: `npm run validate -- <org>` passes, and `resources/<org>/` plus
112-
`.vapi-state.<org>.json` exist.
113-
5. Commit `resources/<org>/` (including `.vapi-org.json`) and `.vapi-state.<org>.json`. Never commit `.env.<org>`.
112+
`state/<org>/state.json` exist.
113+
5. Commit `resources/<org>/` and `state/<org>/`. Never commit `.env.<org>`.
114+
115+
`resources/<org>/` is hand-written: edit it. `state/<org>/` is written by the
116+
engine: never edit or delete anything in it (see [state/README.md](state/README.md)).
114117

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

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

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

@@ -144,14 +147,14 @@ precisely.
144147
`.env.<org>`, run `VAPI_PRIVATE_API_KEY=validate-only npm run validate -- <org>`;
145148
never ask for a real key just to validate. Don't weaken the check or the
146149
workflow to get past it, and never edit the state file, `.vapi-ignore` or
147-
`.vapi-org.json` to make a reference resolve: fix the name, or pull.
150+
`state/<org>/org.json` to make a reference resolve: fix the name, or pull.
148151
4. **Build PR checks offline** if `vapi-checks.yml` exists:
149152
`npm run check -- --all --dry-run`. Fix anything it reports.
150153
5. **Deploy only with a yes** (safety rule 1): `npm run apply -- <org>`, or
151154
scoped to files: `npm run apply -- <org> resources/<org>/assistants/my-agent.md`.
152155
6. **Verify** with the human's agreement: `npm run call -- <org> -a <name>` or
153156
`npm run sim -- <org> --suite <name> --target <name>`.
154-
7. **Commit** the resource files and `.vapi-state.<org>.json`.
157+
7. **Commit** the resource files and `state/<org>/`.
155158

156159
**Why `apply`, not `push`:** `apply` pulls the platform's current state, merges
157160
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,14 +176,14 @@ 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
183183
CI secrets. Credentials are referenced by name and bound to each org's own
184184
credentials.
185185
- **Each folder is pinned to its org.** The first command that can see which
186-
org a key belongs to records it in `resources/<org>/.vapi-org.json`. After
186+
org a key belongs to records it in `state/<org>/org.json`. After
187187
that, every command checks the key against it before any request, and stops
188188
if the key belongs to a different org, so a wrong key can't pull another
189189
org's resources into the folder or push the folder into another org.
@@ -193,11 +193,15 @@ To test every pull request automatically, set up [PR checks](docs/guides/pr-chec
193193

194194
| Path | Committed? | What it is |
195195
| --- | --- | --- |
196-
| `resources/<org>/` | Yes | Your resources, and `.vapi-org.json`, the org the folder belongs to |
197-
| `.vapi-state.<org>.json` | Yes | Name → UUID mappings for the org |
196+
| `resources/<org>/` | Yes | Your resources. Hand-written: this is what you edit |
197+
| `state/<org>/state.json` | Yes | Name → UUID mappings for the org |
198+
| `state/<org>/org.json` | Yes | The Vapi org the folder belongs to |
199+
| `state/<org>/local/` | No | This machine's baselines for detecting dashboard edits, and pre-deploy snapshots for `npm run rollback` |
198200
| `.env.<org>` | **No** | API key and generated binding IDs |
199-
| `.vapi-state-hash/` | No | Your local baseline for detecting dashboard edits |
200-
| `.vapi-state.<org>.snapshots/` | No | Pre-deploy snapshots for `npm run rollback` |
201+
202+
Everything under `state/` is written by the engine. Don't edit or delete it by
203+
hand: without `state.json` the next push creates every resource again as a
204+
duplicate. [state/README.md](state/README.md) says what each file is.
201205

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

@@ -275,7 +279,7 @@ object. API references: [Assistants](https://docs.vapi.ai/api-reference/assistan
275279
## Staying up to date
276280

277281
The engine (`src/`, `tests/`, `.github/workflows/`, `package*.json`) comes from
278-
upstream. Your configuration (`resources/`, `.vapi-state.*.json`,
282+
upstream. Your configuration (`resources/`, `state/`,
279283
`promotion.yml`, `vapi-checks.yml`) is yours; upstream only ships `*.example`
280284
files there. Avoid editing engine files, so updates merge cleanly.
281285

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

296+
If your repository still has `.vapi-state.<org>.json` files at its root, see
297+
[Upgrading from an older version](docs/guides/commands.md#upgrading-from-an-older-version).
298+
292299
## Security
293300

294301
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]` | **The default deploy:** pull, merge, then push. 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] [--strict]` | Push without pulling first. Prefer `apply`. `--strict` aborts before any API call if validation finds an error. |
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. |
@@ -109,14 +109,47 @@ The test-call CLI cleans its terminal output for the developer loop:
109109

110110
## Upgrading from an older version
111111

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

115115
```bash
116116
npm run migrate
117+
git add -A -- state ':(glob).vapi-state.*.json' resources
118+
git commit -m "chore: move engine state into state/"
117119
```
118120

119-
It rewrites every org's `.vapi-state.<org>.json` to the current
120-
`{ "name": { "uuid": … } }` format and seeds your local
121-
`.vapi-state-hash/` drift baseline from the old file. It's safe to run more
122-
than once. Commit the rewritten state files.
121+
It does two things.
122+
123+
**Moves engine files into `state/<org>/`.** They used to sit under dot-names
124+
in three places. Nothing changes inside the files.
125+
126+
| Before | Now |
127+
| --- | --- |
128+
| `.vapi-state.<org>.json` | `state/<org>/state.json` |
129+
| `resources/<org>/.vapi-org.json` | `state/<org>/org.json` |
130+
| `.vapi-state-hash/<org>/` | `state/<org>/local/baselines/` |
131+
| `.vapi-state.<org>.snapshots/` | `state/<org>/local/snapshots/` |
132+
133+
You don't have to run it for this: the engine keeps reading the old places,
134+
and the next `pull`, `push` or `apply` on your machine moves that org and
135+
says so in one line. Either way, commit the removal of the old file together
136+
with the new folder.
137+
138+
The move is held back in two cases, and the command tells you which:
139+
140+
- **In a CI run.** State stays where it is and is updated in place. Only a
141+
workflow that commits both places can record a move, so run
142+
`npm run migrate` on your machine and commit the result.
143+
- **When a workflow under `.github/workflows/` stages `.vapi-state.*.json` but
144+
not `state/`.** That workflow would commit the old file's removal without
145+
the new one. Take upstream's `promotion.yml` workflow, or add
146+
`git add -A -- state` to your own commit step, then run `npm run migrate`.
147+
148+
If both the old and the new file exist for an org and they disagree, every
149+
writing command stops before it changes anything and names the two files.
150+
151+
**Rewrites a legacy-format state file.** Repositories created before the
152+
state-file format changed carry per-resource hashes in the state file, and
153+
`pull`, `push` and `apply` refuse to run until they're gone. `migrate`
154+
rewrites each file to the current `{ "name": { "uuid": … } }` format and
155+
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 name ↔ UUID mappings (nothing else — 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 name ↔ UUID mappings (nothing else — 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/
@@ -48,7 +56,7 @@ files
4856

4957
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.
5058

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

5361
- **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).
5462
- **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).
@@ -168,7 +176,7 @@ requests themselves; there is no separate telemetry.
168176
| Path | What it is |
169177
| --- | --- |
170178
| `resources/<org>/` | Your resources, one folder per org |
171-
| `.vapi-state.<org>.json` | Name → UUID mappings per org (committed) |
179+
| `state/<org>/` | What the engine generates and tracks: name → UUID mappings and the org pin (committed), plus `local/` (gitignored). Not edited by hand |
172180
| `.env.<org>` | API key and generated binding IDs (gitignored) |
173181
| `promotion.yml`, `vapi-checks.yml` | Promotion pipelines and PR checks (copy from the `*.example.yml` files) |
174182
| `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)