Skip to content

Commit 55ea182

Browse files
devin-ai-integration[bot]dhruva-vapicapy-ai[bot]
authored
feat(blocks): shared prompt and config blocks, with a sync command (#111)
* feat(blocks): share prompt text and config between resources A system prompt can include a Markdown block with a line that says only "@include <name>", and any mapping can include a YAML block with a "$include" key, where the file's own keys win. Blocks are looked up in resources/<org>/templates/ first, then in templates/ at the repository root, so an org can replace or extend a shared block. The loader expands them, so validate, push, PR checks and drift hashes all see the finished resource. Liquid inside a block is passed through untouched. Pull never writes a file that uses blocks. It used to rewrite a file whenever the dashboard matched it, was ahead of it, or under --force and --resolve=theirs, and each of those would replace a marker with a copy of the block. It now leaves the file as written and saves the dashboard version beside it when the two differ. validate warns about YAML merge keys and Liquid include/render/layout tags, which the engine and Vapi drop silently. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * feat(blocks): sync a block edit to every resource that uses it A block edit changes what many resources send to Vapi without changing their files, so nothing in git said which resources still ran old text. Push now records the block content each resource went up with in resources/<org>/.vapi-blocks.json. "npm run sync-blocks" lists, across every org, the resources whose blocks changed since they were last pushed, and with --apply deploys them through apply, so the drift check still refuses a resource that was edited in the dashboard. Promotion plans those resources as "sync" entries for the destination org, the promotion workflow runs on templates/**, and a shared block edit selects every PR check. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * docs(blocks): guide, worked example and the corrections it needs Adds docs/guides/blocks.md and examples/blocks/, two clinics that share a red-flags prompt block and a voice config block, one with its own version of the block. The examples test now copies an example's templates/ folder, so the example is validated and the guide's snippets are checked against its files. Also corrects two statements the feature depends on: YAML merge keys are not processed by the engine, and an undefined Liquid variable is left in the prompt as written, not replaced with an empty string. Logs the pull behaviour this replaces as improvements entry 39, and a drift-check gap found while testing, in orgs with no credentials, as entry 40. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * refactor(blocks): keep the blocks record in state/<org>/ Push writes the record, so it belongs with the rest of the engine's files. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(blocks): keep the blocks record where the org's commit step stages it An org whose state is still in the layout from before state/ gets its record at resources/<org>/.vapi-blocks.json. A commit step written for that layout stages resources/, so the record is committed, and a promotion run with nothing to promote no longer plans a sync for every resource that uses a block. An org whose state is in state/<org>/ keeps state/<org>/blocks.json. npm run migrate moves the record with the state file and the pin. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * test: the blocks record is not a local edit to pull In the older layout a push that uses blocks rewrites resources/<org>/.vapi-blocks.json, and until that is committed git shows it as modified. The record is on the list migrate moves, so pull leaves it out of what it counts as a person's edits. This pins it with a pull in a fresh clone. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(blocks): sync-blocks takes its directory from src/base-dir.ts sync-blocks worked out the repository's directory for itself, the one module that still did. It would have worked in the repository while every other module worked in a test's temporary directory. tests/base-dir.test.ts names the line. The blocks tests import the engine sandbox first, as every engine test file does. The test that runs sync-blocks --apply gives that one call 240 seconds. It starts four commands in a row and took 72 seconds on a slow machine beside the rest of the suite. cliRun takes the limit as a parameter and keeps 60 seconds for every other call. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * feat(validate): catch undefined squad variables and Liquid transfer numbers (#99) * feat(validate): warn on undefined squad variables Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(validate): reject Liquid transfer destination numbers Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: explain squad variable and transfer number validation Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: link NHS example across stacked PR branches Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs(examples): two NHS practice squads sharing one assistant set (#100) * feat(validate): warn on undefined squad variables Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs(examples): add shared NHS practice squads Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(examples): inline practice-specific transfer destinations Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(validate): reject Liquid transfer destination numbers Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: explain squad variable and transfer number validation Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: add shared practice quick reference Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: link NHS example across stacked PR branches Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: integrate blocks with adoption folder hashes and strict preflight Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Dhruva Reddy <dhruva@vapi.ai> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Co-authored-by: Dhruva Reddy <264116857+dhruva-vapi@users.noreply.github.com> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 11f572f commit 55ea182

65 files changed

Lines changed: 4424 additions & 43 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/promotion.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
paths:
77
- promotion.yml
88
- resources/**
9+
# Shared blocks: an edit changes resources without changing their files.
10+
- templates/**
911
workflow_dispatch:
1012
inputs:
1113
pipeline:

‎AGENTS.md‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ change, before running:
3939
| --- | --- |
4040
| `npm run apply`, `npm run push` | Changes live assistants |
4141
| `npm run promote -- … --apply` | Changes the next org (often production) |
42+
| `npm run sync-blocks -- --apply` | Changes live resources in every org that uses the edited block |
4243
| `npm run rollback -- <org> --to …` | Reverts live resources |
4344
| `npm run cleanup -- <org> --force --confirm <org>` | Deletes platform resources |
4445
| `npm run pull -- <org> --force` | Overwrites local edits |
@@ -48,9 +49,13 @@ change, before running:
4849

4950
Safe to run without asking: `npm run validate`, `npm run audit`,
5051
`npm run check -- … --dry-run`, `npm run promote` without `--apply` (a plan),
52+
`npm run sync-blocks` without `--apply` (a list),
5153
plain `npm run pull` (it never overwrites local edits), `npm run push -- <org>
5254
--dry-run`, `npm run build`, `npm test`.
5355

56+
- `variable-undefined`: set squad members' `{{vars}}` in squad/member `variableValues`; `--strict` blocks missing values.
57+
- `transfer-number-liquid`: transfer destination numbers must be literal; put per-squad numbers in an inline `transferCall` in `membersOverrides["tools:append"]`.
58+
5459
**2. Never handle API keys.** Don't ask the human to paste a key into chat,
5560
don't print or read out `.env.*` files, never pass a key as a command-line
5661
argument, and never commit `.env.*`. Keys live in `.env.<org>` (gitignored)
@@ -149,6 +154,8 @@ precisely.
149154
never ask for a real key just to validate. Don't weaken the check or the
150155
workflow to get past it, and never edit the state file, `.vapi-ignore` or
151156
`state/<org>/org.json` to make a reference resolve: fix the name, or pull.
157+
- `variable-undefined`: set squad members' `{{vars}}` in squad/member `variableValues`; `--strict` blocks this warning in validate and push.
158+
- `transfer-number-liquid`: use literal transfer numbers; append a per-squad inline `transferCall` in the squad's `membersOverrides["tools:append"]`.
152159
4. **Build PR checks offline** if `vapi-checks.yml` exists:
153160
`npm run check -- --all --dry-run`. Fix anything it reports.
154161
5. **Review the dry-run Name collisions list**, then **deploy only with a yes**
@@ -202,7 +209,8 @@ Nothing was written to the remote API"), a resource the push would write (one
202209
you selected, or a dependency it would create) has a validation error or an
203210
unresolved credential. Fix the listed findings and rerun; nothing was applied,
204211
so there is nothing to roll back. Errors in files outside the push only warn
205-
(`--strict` blocks those too). The preflight only catches what `validate`
212+
(`--strict` blocks those too, as well as `variable-undefined` warnings).
213+
The preflight only catches what `validate`
206214
knows about, so an API rejection can still leave a push partly applied.
207215

208216
If something goes wrong: `npm run rollback -- <org> --list`, then (with a yes)
@@ -220,6 +228,9 @@ how sync, conflicts and output icons work:
220228
| Edit an assistant's system prompt | Edit the Markdown body of `resources/<org>/assistants/<name>.md` |
221229
| Change assistant settings | Edit the YAML frontmatter of the same file |
222230
| Add a tool / assistant / squad | Create `resources/<org>/tools/<name>.yml`, `assistants/<name>.md`, `squads/<name>.yml` |
231+
| Add another practice / location sharing the same assistants | Copy a squad file in `examples/nhs-shared-squads/`; change its `variableValues` and inline transfer numbers. |
232+
| Share prompt text or config between files | Put it in `templates/blocks/<name>.md` or `templates/config/<name>.yml` and include it (see [Blocks](#blocks)) |
233+
| See which resources a block edit reaches | `npm run sync-blocks` (a list; `--apply` deploys and needs a yes) |
223234
| Add post-call analysis | Create `resources/<org>/structuredOutputs/<name>.yml` and list it in the assistant's `artifactPlan.structuredOutputIds` |
224235
| Write simulation tests | Create files under `resources/<org>/simulations/` (see [Simulations](#simulations-and-pr-checks)) |
225236
| Check files offline | `npm run validate -- <org>` |
@@ -289,6 +300,24 @@ derived key, dropping `gitops` and `metadata` only if they become empty.
289300
| The display name | Change `name` in the file (or in the dashboard, then pull). The filename stays. |
290301
| The file itself | A renamed or moved file has no state entry. With the human's agreement, use `--adopt <new-resourceId>=<uuid>` to keep managing the same platform resource under the new path. Without adoption, an unlinked file is created as a new resource, not matched by name. |
291302

303+
### Blocks
304+
305+
A line that says only `@include <name>` in a system prompt, or a
306+
`$include: <name>` key in a mapping, pulls in a shared file from
307+
`resources/<org>/templates/` (the org's own) or `templates/` (shared by
308+
every org). The engine expands it before validate, push and PR checks.
309+
310+
- To change shared wording or settings, edit the block, not the files that
311+
include it. Never replace a marker with the block's text.
312+
- A block edit changes every resource that includes it, in every org. Run
313+
`npm run sync-blocks` and show the human the list before any deploy.
314+
- Don't use Liquid `{% include %}` / `{% render %}` or YAML merge keys (`<<`)
315+
to share content: Vapi and the engine drop them silently.
316+
- Commit `state/<org>/blocks.json` when push changes it; never edit or
317+
delete it.
318+
319+
Syntax, merge rules and dashboard-edit handling: [Blocks](docs/guides/blocks.md).
320+
292321
### Excluding resources (`.vapi-ignore`)
293322

294323
`resources/<org>/.vapi-ignore` lists platform resources this repo must not
@@ -405,6 +434,7 @@ For changes under `src/`, `tests/` or `.github/`:
405434
| --- | --- |
406435
| Every resource setting, with examples | [Resource reference](docs/guides/resource-reference.md) |
407436
| Minimal tested files | [File formats](docs/guides/file-formats.md), [`examples/starter/`](examples/starter/README.md) |
437+
| Shared prompt text and config | [Blocks](docs/guides/blocks.md), [`examples/blocks/`](examples/blocks/README.md) |
408438
| System prompts | [Writing system prompts](docs/guides/writing-prompts.md), [Vapi Prompt Optimization Guide](docs/Vapi%20Prompt%20Optimization%20Guide.md) |
409439
| Commands, flags, test-call output | [Commands](docs/guides/commands.md) |
410440
| Sync, conflicts, drift, output icons | [How the engine works](docs/guides/how-it-works.md), [sync behavior](docs/learnings/sync-behavior.md) |

‎README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,18 @@ More detail: [How the engine works](docs/guides/how-it-works.md).
221221
| Command | What it does |
222222
| --- | --- |
223223
| `npm run setup` | Connect an org: create `.env.<org>` and `resources/<org>/` |
224-
| `npm run validate -- <org>` | Check resource files offline before deploying |
224+
| `npm run validate -- <org> [--strict]` | Check resource files offline, including undefined squad variables (`variable-undefined`); `--strict` blocks on that warning. `transfer-number-liquid` always errors on Liquid in transfer destination numbers; use per-practice literal numbers (see `examples/nhs-shared-squads`). |
225225
| `npm run apply -- <org>` | Deploy: pull, merge, then preflight and push (the default) |
226226
| `npm run pull -- <org>` | Sync platform changes down without overwriting local edits; unknown UUIDs get separate files, never name-linked |
227-
| `npm run push -- <org>` | Preflight the write plan, then push without pulling first (prefer `apply`); `--strict` also blocks validation errors outside the plan. 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). |
227+
| `npm run push -- <org>` | Preflight the write plan, then push without pulling first (prefer `apply`); `--strict` also blocks validation errors outside the plan and `variable-undefined` warnings. 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). |
228228
| `npm run rollback -- <org>` | Restore a pre-deploy snapshot |
229229
| `npm run cleanup -- <org>` | Find, and optionally delete, platform resources with no file |
230230
| `npm run audit -- <org>` | Report drift between files, state and the platform |
231231
| `npm run call -- <org>` | Talk to an assistant or squad from your terminal |
232232
| `npm run sim -- <org>` | Run a simulation suite against deployed resources |
233233
| `npm run check` | Run PR simulation checks against local files |
234234
| `npm run promote` | Promote resources from one org to the next |
235+
| `npm run sync-blocks` | List, and optionally deploy, the resources a shared block edit reaches |
235236

236237
`setup`, `apply`, `pull`, `push`, `cleanup` and `call` prompt interactively
237238
when run without arguments. Full flags and examples:
@@ -243,6 +244,7 @@ when run without arguments. Full flags and examples:
243244
| --- | --- |
244245
| [Everyday workflows](docs/guides/workflows.md) | Deploy, pull safely, recover from a bad deploy, clean up |
245246
| [File formats](docs/guides/file-formats.md) | Write assistants, tools, squads, structured outputs and simulations |
247+
| [Blocks](docs/guides/blocks.md) | Share prompt text and config between assistants, squads and orgs |
246248
| [Resource reference](docs/guides/resource-reference.md) | Look up every setting, with examples |
247249
| [Writing system prompts](docs/guides/writing-prompts.md) | Structure a voice agent's prompt |
248250
| [PR checks](docs/guides/pr-checks.md) | Test every pull request with simulations |

0 commit comments

Comments
 (0)