Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ change, before running:
| `npm run rollback -- <org> --to …` | Reverts live resources |
| `npm run cleanup -- <org> --force --confirm <org>` | Deletes platform resources |
| `npm run pull -- <org> --force` | Overwrites local edits |
| `--adopt <id>[=<uuid>]` | Takes over an existing org resource; requires an explicit yes for that resource |
| `--allow-new-files`, `--overwrite`, `--resolve=ours\|theirs` | Bypass a safety check (see rule 6) |
| `npm run call`, `npm run sim`, live `npm run check` | Place calls or run simulations that cost minutes |

Expand Down Expand Up @@ -147,7 +148,10 @@ precisely.
`.vapi-org.json` to make a reference resolve: fix the name, or pull.
4. **Build PR checks offline** if `vapi-checks.yml` exists:
`npm run check -- --all --dry-run`. Fix anything it reports.
5. **Deploy only with a yes** (safety rule 1): `npm run apply -- <org>`, or
5. **Review the dry-run Name collisions list**, then **deploy only with a yes**
(safety rule 1). Same-named org resources are never taken over automatically;
`--adopt <id>[=<uuid>]` requires explicit human approval to take one over.
Deploy: `npm run apply -- <org>`, or
scoped to files: `npm run apply -- <org> resources/<org>/assistants/my-agent.md`.
6. **Verify** with the human's agreement: `npm run call -- <org> -a <name>` or
`npm run sim -- <org> --suite <name> --target <name>`.
Expand All @@ -161,11 +165,34 @@ the dashboard, `apply` asks about that resource alone in a terminal; in CI or
piped runs it's blocked unless `--resolve=ours|theirs|fail` is passed — ask
the human which.

**When a deploy stops at the new-file check** ("no state-file UUID mapping"),
the engine can't tell whether each listed file is new, a rename, or stale.
Show the list to the human and ask them to classify each file. Pass
**When a deploy stops at the new-file check** ("Not linked to any resource
in <org> yet"), the grouped report lists every blocking file with exact fix
commands. The engine cannot tell new / renamed / stale files apart; pushing
an unlinked file creates a new resource. Show the report and ask the human
to choose per file. Pass
`--allow-new-files` only once they confirm every file is genuinely new. For a
rename, see [Renaming](#naming-and-renaming); delete stale files.
Same-named org resources are NOT linked automatically. Preview with
`npm run push -- <org> --dry-run --allow-new-files` only after approval for
those new files, and check the **Name collisions** list (read-only dashboard
GETs). To take over an existing resource instead, get an explicit yes for
`--adopt <id>[=<uuid>]`; use the UUID form when candidates are ambiguous.
Never auto-pass adoption or new-file approval to make a deploy succeed.
Adoption removes unchanged alias files automatically using the last-synced
baseline. Edited aliases or missing baselines require per-file y/N approval;
headless runs stop before changing files/state or the platform. Merge edits
into the adopted file or remove the alias manually, then rerun.

**Running in CI:** link/adoption preflight stops with exit code **1**, before
file deletion, state writes or API mutations. It groups unlinked files, invalid
adoptions and unsafe alias deletions once. `--json` prints one array of
`{file, resourceType, problem, fix, command}` to stdout (other logs go to stderr);
`[]` means this preflight found no blockers, not that deployment cannot fail.
A combined command is suggested only when every file has an unambiguous
suggestion; otherwise the report names files needing human choice. No flags
are needed to remove a verified unchanged leftover of an already-adopted
resource. The engine never auto-adopts, auto-allows new files or deletes edited
files without approval.

If something goes wrong: `npm run rollback -- <org> --list`, then (with a yes)
`--to <timestamp>`. Details for every workflow:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ More detail: [How the engine works](docs/guides/how-it-works.md).
| `npm run setup` | Connect an org: create `.env.<org>` and `resources/<org>/` |
| `npm run validate -- <org>` | Check resource files offline before deploying |
| `npm run apply -- <org>` | Deploy: pull, merge, then push (the default) |
| `npm run pull -- <org>` | Sync platform changes down without overwriting local edits |
| `npm run push -- <org>` | Push without pulling first (prefer `apply`) |
| `npm run pull -- <org>` | Sync platform changes down without overwriting local edits; unknown UUIDs get separate files, never name-linked |
| `npm run push -- <org>` | Push without pulling first (prefer `apply`); review `--dry-run` Name collisions, and use `--adopt <id>[=<uuid>]` only with explicit approval to take over a resource; unchanged alias files are removed, edited/unbaselined copies need review. Push/apply support `--json` for one grouped link-preflight report (exit 1 on blockers); see [Running in CI](docs/guides/commands.md#running-in-ci). |
| `npm run rollback -- <org>` | Restore a pre-deploy snapshot |
| `npm run cleanup -- <org>` | Find, and optionally delete, platform resources with no file |
| `npm run audit -- <org>` | Report drift between files, state and the platform |
Expand Down
75 changes: 73 additions & 2 deletions docs/guides/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ The other commands are direct only.
| --- | --- | --- |
| `npm run setup` | `npm run setup [-- <org>]` | Connect an org: creates `.env.<org>` and `resources/<org>/`. |
| `npm run validate` | `npm run validate -- <org>` | Check resource files offline: API shape rules, and that every reference names a file or a state entry. `apply` runs it first. On GitHub Actions, findings are also shown on the files in the pull request. |
| `npm run apply` | `npm run apply -- <org> [types or paths]` | **The default deploy:** pull, merge, then push. See [workflows](workflows.md). |
| `npm run apply` | `npm run apply -- <org> [types or paths] [--adopt <id>[=<uuid>]]` | **The default deploy:** pull, merge, then push. See [workflows](workflows.md). |
| `npm run pull` | `npm run pull -- <org> [--force] [--bootstrap]` | Sync platform changes down; never overwrites local edits unless `--force`. |
| `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. |
| `npm run push` | `npm run push -- <org> [--dry-run] [--json] [--strict] [--adopt <id>[=<uuid>]]` | Push without pulling first. Prefer `apply`. `--strict` aborts before any API call if validation finds an error. |
| `npm run rollback` | `npm run rollback -- <org> --list` or `--to <ISO>` | Restore a pre-deploy snapshot from `.vapi-state.<org>.snapshots/`. |
| `npm run cleanup` | `npm run cleanup -- <org> [--force --confirm <org>]` | List platform resources with no file; delete them only with both flags. |
| `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. |
Expand All @@ -24,6 +24,77 @@ The other commands are direct only.
| `npm run build` | `npm run build` | Type-check the code and tests. |
| `npm test` | `npm test` | Run the test suite. |

Pull and push never automatically rename UUID-suffixed state keys to match
local files. A local file without a UUID mapping remains subject to the
new-file gate even if the org has a same-name resource. The gate reports
same-name candidates without linking them. Existing mappings, including
legacy entries without provenance, remain linked. New pull mappings record
`origin: pulled`; push-created resources record `origin: pushed`.

Dry-run push/apply ends with **Name collisions**, listing same-name state and
live dashboard resources for every planned POST, including dependency creates.
Read-only GETs run in dry-run. No matches prints `Name collisions: none`;
unavailable inventories are reported as an incomplete check, not a clean result.
Check this list before deploying; taking over a resource requires explicit
human approval for `--adopt`, just as `--allow-new-files` requires approval.

### Running in CI

Push/apply link preflight reports all blocking files in one **Push stopped**
block and exits **1**, before API mutations, state writes or alias deletion.
"Not linked to any resource in <org> yet" means pushing would create a new
resource; the engine cannot infer new versus renamed/stale intent.

Each file has exact commands: approve `--allow-new-files` for genuinely new
resources, approve `--adopt <id>[=<uuid>]` for a takeover, or merge needed edits
and remove a renamed/stale file. A single ready-to-run combined command appears
only when every file has an unambiguous suggestion; otherwise the report lists
which files need human choice. Suggestions are not authorization to execute.

`--json` on push or apply prints one stdout array of
`{file, resourceType, problem, fix, command}`; ordinary logs go to stderr.
The exit code stays 1 for blockers. `[]` means no link-preflight blockers,
not a guarantee that later network/validation/deployment steps will succeed.
Use `--dry-run --json` for a read-only preview. When invoking through npm,
use `npm run -s push -- <org> --dry-run --json` to suppress npm's own
command banner on stdout.

Safe, unchanged leftover alias files are removed automatically, including
UUID-suffixed leftovers of an already-adopted mapping on a later plain push.
Edited/unbaselined files need per-file y/N approval in a terminal and stop CI.
The engine never auto-adopts, auto-passes the new-file flag or silently deletes
edited files.

### Explicit resource adoption

`--adopt <resourceId>` opts a local file into taking over an existing org
resource. It is repeatable; `--adopt=<resourceId>` also works. The file must
exist and have no state mapping. Candidates are same-base-slug state entries
and live resources of that type matching the file's name (or ID when unnamed).
One distinct candidate is required. If several exist, use
`--adopt <resourceId>=<uuid>`; that UUID must exist remotely for the file's type.
Missing files, already-linked files, and zero/ambiguous candidates are errors.

Adoption records `origin: adopted`, removes other state keys for that UUID, and
uses the normal PATCH path. Scoped saves include both sides of the re-key.
`--dry-run --adopt <id>` performs live GET lookups and prints
`would adopt <id> → <uuid>`, but does not write state or mutate the platform.
`apply` forwards adoption to its push stage; its preceding pull remains a
normal pull except in `--dry-run`, which skips pull to avoid local writes.
Adoption deletes leftover alias files only when they match the last-synced
baseline. Edited files or missing baselines need per-file y/N approval in a
terminal; headless runs stop before changing files, state or the platform.
Merge those edits into the adopted file or delete the alias manually and rerun.
Dry-run reports would-delete/would-fail without deleting. Baselines are keyed
by remote UUID, not alias; adoption drops the shared old baseline and the normal
PATCH records a fresh one for the adopted resource.

Dependencies are automatically reused by name only when an existing state
entry records `origin: pushed` or `origin: adopted`. Pulled and legacy entries,
and dashboard-only name matches, are not authorization: a missing dependency
is POST-created with a warning naming the existing resources. Use explicit
adoption before dependency resolution to take one over instead.

## Interactive Mode

When you run a command without arguments, you get a fully interactive experience:
Expand Down
55 changes: 51 additions & 4 deletions docs/guides/how-it-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Resources are scoped by organization, with names you choose (not fixed `dev`/`stg`/`prod`). Each org gets:

- `.env.<org>` — private API key and base URL
- `.vapi-state.<org>.json` — resource name ↔ UUID mappings (nothing else — committed)
- `.vapi-state.<org>.json` — resource ID ↔ UUID mappings and optional origin (committed)
- `.vapi-state-hash/<org>/<uuid>` — last-seen platform content hash per resource, used for drift detection (per-developer, gitignored)
- `resources/<org>/` — all resource files

Expand Down Expand Up @@ -42,7 +42,52 @@ files

**`push`** — reads local files and syncs them to the platform: creates and updates. It deletes platform resources whose files you removed only when you pass `--force`.

**`apply`** — runs `pull` then `push` in sequence.
**`apply`** — runs `pull` then `push` in sequence. With `--dry-run`, it skips
pull (which writes local files/state) and previews push with read-only GETs.

### Running in CI

Push/apply link preflight reports all blocking files in one **Push stopped**
block and exits **1**, before API mutations, state writes or alias deletion.
"Not linked to any resource in <org> yet" means pushing would create a new
resource; the engine cannot infer new versus renamed/stale intent.

Each file has exact commands: approve `--allow-new-files` for genuinely new
resources, approve `--adopt <id>[=<uuid>]` for a takeover, or merge needed edits
and remove a renamed/stale file. A single ready-to-run combined command appears
only when every file has an unambiguous suggestion; otherwise the report lists
which files need human choice. Suggestions are not authorization to execute.

`--json` on push or apply prints one stdout array of
`{file, resourceType, problem, fix, command}`; ordinary logs go to stderr.
The exit code stays 1 for blockers. `[]` means no link-preflight blockers,
not a guarantee that later network/validation/deployment steps will succeed.
Use `--dry-run --json` for a read-only preview. With npm, use
`npm run -s push -- <org> --dry-run --json` to suppress npm's banner.

Safe, unchanged leftover alias files are removed automatically, including
UUID-suffixed leftovers of an already-adopted mapping on a later plain push.
Edited/unbaselined files need per-file y/N approval in a terminal and stop CI.
The engine never auto-adopts, auto-passes the new-file flag or silently deletes
edited files.

### Names never authorize taking over org resources

Pull keeps existing UUID mappings and filenames stable. An unknown UUID always
gets a separate `<name-slug>-<uuid8>` ID, even if a same-named local file exists.
Neither pull nor push automatically collapses that key onto a local filename.

A file without a state mapping remains subject to the new-file gate. After
confirming it is genuinely new, preview `--dry-run --allow-new-files` and review
the final **Name collisions** list. It compares every planned POST, including
auto-created dependencies, with state and live dashboard names. Matching names
do not change the plan into a takeover. GETs run; platform mutations do not.

To take over a resource intentionally, obtain explicit human approval and use
`--adopt <id>[=<uuid>]`. Adoption links an untracked local file before the gate
and normal PATCH flow. Dependency alias reuse is restricted to state entries
with `origin: pushed` or `origin: adopted`; pulled and legacy entries do not
authorize new name-based links. Existing exact-key legacy links remain intact.

## Conflicts and the drift gate

Expand All @@ -53,7 +98,7 @@ Before updating a resource, push GETs its current dashboard payload, hashes it,
- **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).
- **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).

Backup copies (`*.bkp.*`, gitignored) are merge reference material only — invisible to the loader, the orphan gate, audit, the interactive picker, and explicit CLI paths.
Backup copies (`*.bkp.*`, gitignored) are merge reference material only — invisible to the loader, the new-file check, audit, the interactive picker, and explicit CLI paths.

## Reading pull and push output

Expand All @@ -77,7 +122,7 @@ Mental model: `⬆️` flows UP (push), `⬇️` flows DOWN (pull), `📝` is th

## Listing completeness

Vapi list endpoints cap a response at 100 items and expose no page cursor — only `createdAt` comparison filters. The engine pages backwards through `createdAt` until it gets a short page, so pull, push's invalid-mapping detection, `delete`'s orphan sweep, `audit`, and the credential reverse-map all see the whole type instead of the first hundred. When completeness cannot be proven — an endpoint that ignores the cursor params, a payload with no `createdAt`, or the page-count backstop — the engine says so on stderr. Treat that warning as "do not infer deletion from absence for this type".
Vapi list endpoints cap a response at 100 items and expose no page cursor — only `createdAt` comparison filters. The engine pages backwards through `createdAt` until it gets a short page, so pull, push's invalid-mapping detection, `delete`'s missing-file sweep, `audit`, and the credential reverse-map all see the whole type instead of the first hundred. When completeness cannot be proven — an endpoint that ignores the cursor params, a payload with no `createdAt`, or the page-count backstop — the engine says so on stderr. Treat that warning as "do not infer deletion from absence for this type".

## Processing Order

Expand Down Expand Up @@ -144,6 +189,8 @@ Tracks resource ID ↔ Vapi UUID mappings per org:
```

Every resource type has a section. Keys are sorted, so diffs stay readable.
New entries record `origin: pushed`, `pulled`, or `adopted`. Updates preserve
that provenance, and legacy entries without an origin are not backfilled.

## What Vapi sees

Expand Down
31 changes: 29 additions & 2 deletions docs/guides/workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,33 @@ When the files are genuinely new resources:
npm run apply -- <org> --allow-new-files
```

Before deploying, review the collision preview (the flag still needs approval
for every genuinely new file):

```bash
npm run push -- <org> --dry-run --allow-new-files
```

The final **Name collisions** section includes same-name state and dashboard
resources for every planned create, including dependencies. Names alone never
take over an org resource. The plan POSTs a new one unless you explicitly adopt:

```bash
npm run apply -- <org> --adopt my-agent assistants/my-agent.md
# If multiple candidates exist:
npm run apply -- <org> --adopt my-agent=<uuid> assistants/my-agent.md
```

Adoption needs the human's explicit yes for that resource, just like new-file
approval. It requires a local file with no state mapping. Pull never links
unknown remote UUIDs to local files by name, and dependency aliases are reused
only when state records pushed/adopted ownership. Adoption removes unchanged alias files automatically. Edited aliases or
missing baselines require per-file approval in a terminal; headless runs stop
so you can merge their edits into the adopted file or remove them manually.

Both `push --dry-run` and `apply --dry-run` perform read-only dashboard GETs
for the collision preview; apply skips its pull stage to avoid local writes.

Check each listed file before you pass the flag: it confirms every one is
new. If a coding agent runs your deploys, it should show you the list rather
than pass the flag itself; [`AGENTS.md`](../../AGENTS.md) instructs it to.
Expand Down Expand Up @@ -202,7 +229,7 @@ npm run cleanup -- <org> --force --confirm <org>
```

Cleanup treats every platform resource that isn't in
`.vapi-state.<org>.json` as an orphan, except those matched by
`.vapi-state.<org>.json` as unmanaged, except those matched by
`resources/<org>/.vapi-ignore`: it lists those as retained and never deletes
them. Still read the dry-run list before a destructive run.

Expand All @@ -213,7 +240,7 @@ through the API, then refresh state:

```bash
curl -X DELETE -H "Authorization: Bearer $VAPI_PRIVATE_API_KEY" \
https://api.vapi.ai/assistant/<orphan-uuid>
https://api.vapi.ai/assistant/<resource-uuid>
npm run pull -- <org> --bootstrap
```

Expand Down
Loading
Loading