# Template Workflow Config Recipes

## Bootstrap a Node-Flow Template

1. List templates:

```bash
meegle --profile default config template list \
  --project-key <PROJECT_KEY> \
  --type-key story \
  --json
```

2. Create a field:

```bash
meegle --profile default --yes config field create \
  --project-key <PROJECT_KEY> \
  --type-key story \
  --field-name "优先级标签" \
  --field-type select \
  --option 高=high \
  --option 中=medium \
  --json
```

3. Create a role:

```bash
meegle --profile default --yes config role create \
  --project-key <PROJECT_KEY> \
  --type-key story \
  --name "研发负责人" \
  --alias RD \
  --json
```

4. Create a node:

```bash
meegle --profile default --yes config template node create \
  --project-key <PROJECT_KEY> \
  --template-id <TEMPLATE_ID> \
  --state-key dev \
  --name "开发" \
  --pre-nodes start \
  --json
```

5. Bind field and role:

```bash
meegle --profile default --yes config template node bind-field \
  --project-key <PROJECT_KEY> \
  --template-id <TEMPLATE_ID> \
  --node-id dev \
  --field-key priority \
  --required 1 \
  --json

meegle --profile default --yes config template node bind-role \
  --project-key <PROJECT_KEY> \
  --template-id <TEMPLATE_ID> \
  --node-id dev \
  --role-keys RD \
  --json
```

6. Validate the graph:

```bash
meegle --profile default config template node predecessor validate \
  --project-key <PROJECT_KEY> \
  --template-id <TEMPLATE_ID> \
  --json
```

## Manage Node Relationships

Use predecessor commands, not raw `connections`:

```bash
meegle --profile default config template node predecessor add \
  --project-key <PROJECT_KEY> \
  --template-id <TEMPLATE_ID> \
  --node-id qa \
  --pre-nodes dev \
  --json
```

```bash
meegle --profile default config template node predecessor graph \
  --project-key <PROJECT_KEY> \
  --template-id <TEMPLATE_ID> \
  --json
```

## Configure a State-Flow Template

```bash
meegle --profile default config template state list \
  --project-key <PROJECT_KEY> \
  --template-id <TEMPLATE_ID> \
  --json
```

```bash
meegle --profile default --yes config template state upsert \
  --project-key <PROJECT_KEY> \
  --template-id <TEMPLATE_ID> \
  --state-key CLOSED \
  --name "Closed" \
  --state-type 3 \
  --authorized-roles RD \
  --json
```

## Boundary

If the task asks for transition-level `connections` writes:

- do not assume this is supported
- current public update contract only guarantees `workflow_confs` and `state_flow_confs`
- treat `connections` as read-only until the backend contract is proven

If the task is about a running work item instance rather than template structure:

- use `workflow node-update` / `workflow node-operate` for node runtime updates
- use `subtask update` / `subtask operate` for subtask runtime updates
- do not route instance data changes through `config template ...`
