# Playbook for coding agents

> A complete procedure for coding agents that write Sommatic AI workflows as files. Read the contract, edit with stable node ids and tokens, register the resource, validate, open a pull request and, when allowed, preview and apply.

Source: https://docs.sommatic.ai/en/git-sync/agents/ (updated 2026-11-26)

Coding agents (Claude Code, Codex, Cursor and others) can write and change Sommatic AI workflows the same way a developer
does: as JSON files in a Git repository, reviewed through pull requests. This page is the procedure to give them. It is
written to be followed literally; point your agent to its Markdown version at `/en/git-sync/agents.md`.

## Ground rules

- **Git is the source of truth.** Change files, never the live resource. Sommatic AI only reads the repository.
- **Never push to a deployment branch.** Work on `feature/*` and open a pull request to `development`.
- **Never write physical ids or secrets.** Use `@@env.NAME@@`, `@@ref.<key>@@` and `@@secret.NAME@@` tokens.
- **Keep `node_id` stable.** Edit nodes in place; only new nodes get new ids.
- **Never apply without reading the preview,** and never deploy to production before the pull request into its branch
  is merged.
- **Stop and ask a person** when something in this page does not hold, instead of working around it.

## Before you start

Read, in this order:

1. The repository: find every `sommatic.json` (ignore those under `templates/` and `.github/`) and the files in
   `environments/`. Note which branch each environment reads.
2. The contract: [Packages](https://docs.sommatic.ai/en/git-sync/packages.md), [Environments and tokens](https://docs.sommatic.ai/en/git-sync/environments-and-tokens.md)
   and [Resource files](https://docs.sommatic.ai/en/git-sync/resource-files.md).
3. The page of every node you will use, under `/en/nodes/<slug>/` (Markdown at `/en/nodes/<slug>.md`). It gives the
   `config` fields, the ports and the status. Do not use a node whose status is _partial_ or _experimental_.
4. [Expressions](https://docs.sommatic.ai/en/expressions.md) for any value that reads data from earlier nodes.

The schemas to validate against are `package.schema.json`, `environment.schema.json` and
`resource-header.schema.json`, under `https://docs.sommatic.ai/schemas/git-sync/`.

## Change an existing workflow

### Create a branch

Branch from `development`: `feature/<short-description>`.

### Edit the file

Open the workflow file listed in the package's `sommatic.json`.

- Change a node by editing its `config`, `label` or `ports` in `draft_nodes`. Keep its `node_id`.
- Add a node with a new, unique, descriptive `node_id` (for example `node-notify-owner`), its `operator_slug`,
  `operator_version`, `config` and `ports` from the node page, and a position in `editor_state.node_positions`.
- Connect nodes in `draft_edges`: `from.node_id` and `from.port` (a port of the source node), `to.node_id`.
- Remove a node together with its edges and its entry in `node_positions`.
- If you rename a node's `label`, update every expression that reads it with `$('Label')`.

### Use tokens for anything per installation

- Another resource (for example the workflow called by `workflow.chain`): `@@ref.<key>@@`.
- An LLM provider, a credential id, a host or a flag: `@@env.NAME@@`, and add `NAME` under `variables` in **every**
  environment file.
- A secret: prefer a node's credential picker (`connection_id` holding `@@env.NAME@@`). If a secret must live in the
  config, use `@@secret.NAME@@` and declare `NAME` under `secrets` in every environment file, with
  `{ "from": "live" }` or `{ "from": "credential", "id": "…" }`. If you do not know the credential id, stop and ask.

### Keep the format

Sorted keys, two-space indentation, trailing newline. Do not add `id`, `created`, `modified`, `status`,
`execution_state`, `latest_version_id` or `version_counter`. Keep the `sommatic` header unchanged.

### Validate

Validate every manifest, resource file and environment file against the schemas, and check that each header key
equals its manifest key and that every environment file declares an id for every key. The validator on
[Branches and CI](https://docs.sommatic.ai/en/git-sync/ci.md) does all of this.

### Open a pull request

Push the branch and open a pull request to `development`. In the description, list the keys you changed, the nodes
added, removed or changed, and any variable or secret that has to be added to an environment file.

## Add a new workflow

A file alone cannot create a workflow: apply only updates resources that already exist in each installation.

### Get the ids

Ask the owner of each installation to create the workflow in Sommatic AI and give you its id there. Do not invent ids.

### Write the file

Start from an existing workflow file or from an **Export for Git…** of the new workflow. Set the header
`{ "kind": "workflow", "key": "<package>.<slug>", "schema_version": "1.0" }` and give the file a path under the
package, such as `workflows/<slug>.json`.

### Register it

Add `{ "key": "<key>", "path": "workflows/<slug>.json" }` to `resources.workflows` in `sommatic.json`, and
`"<key>": "<id>"` to `resources` in every environment file, each with the id of its own installation.

### Validate and open the pull request

Same as above.

## Deploy (only when you are allowed to)

Deploying is a separate permission. Do it only when the person you work for asks, and only after the pull request into
the installation's branch is merged.

### Preview

```bash
curl -s -X POST "$SOMMATIC_API/platform-infrastructure/git-sync/preview" \
  -H "Authorization: Bearer $SOMMATIC_TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{ "repository_id": "<repository_id>", "path": "<package path>", "include_content": false }'
```

### Check every item

Stop and report if any item has a non-empty `unresolved`, has `exists: false` or carries an `error`. Confirm that
`changes` matches what the pull request intended: the nodes added, removed and changed, and the fields.

### Apply that commit

```bash
curl -s -X POST "$SOMMATIC_API/platform-infrastructure/git-sync/apply" \
  -H "Authorization: Bearer $SOMMATIC_TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{ "repository_id": "<repository_id>", "path": "<package path>", "expected_commit": "<commit from the preview>", "publish": true, "description": "Pull request #<number>" }'
```

If apply says the branch moved, preview again and review the new commit. Never retry with an older commit.

### Report

Report the `commit`, the keys applied, unchanged, skipped and failed, the `reason` of any failure and each published
`version`.

## Stop conditions

Stop and ask a person when:

- a preview item has `unresolved` tokens or `exists: false`;
- a resource you need to change is `unlinked_here` in the installation;
- you would need a physical id or a secret value to finish;
- export left `@@secret.REPLACE_ME@@` and you do not know the secret's name or source;
- the only way forward is a direct push, an apply of a commit that is not the head of the branch, or a production
  deploy before the merge.

> **Tip: Give your agent this page**
>
> Every page of this site has a Markdown twin: add `.md` to the URL. This one is `/en/git-sync/agents.md`.
> See [Build with agents](https://docs.sommatic.ai/en/agents.md) for the other entry points.

## Next steps

- [Branches and CI](https://docs.sommatic.ai/en/git-sync/ci.md): The validator the agent should run.
- [Preview and apply](https://docs.sommatic.ai/en/git-sync/preview-and-apply.md): Every field of the preview and apply responses.
