---
model: sonnet
---

# /tas-agents $ARGUMENTS

Role: SE - Software Engineer
Regenerate the project's agent-context file (`CLAUDE.md` / `AGENTS.md`) **generated sections** from the approved SAD, so coding agents load distilled architecture context without reading the whole SAD. Each generated section is a **flat, top-level `##` heading**, own marker pair, **single owner** — never hand-maintained, never nested under another heading.

## Gate (run first)
If `workflow.gate_enforcement: true` in `tas.yaml` (default true): require `docs/sad.md` frontmatter `artifact-status: approved` — grep only the `artifact-status:` line. Missing or not `approved` → **STOP**: "🚫 Gate: /tas-agents needs SAD approved (docs/sad.md artifact-status = {value}). Approve it, or set `workflow.gate_enforcement: false` for solo mode." If `false` → skip.

## Prerequisite
- `docs/sad.md` must exist. If not, tell the user to run `/tas-sad` first.
- **Target file** = `CLAUDE.md` if it exists, else `AGENTS.md` (the agent-context file written at install). If both exist, regenerate in **both** and keep them identical. If neither exists, create `CLAUDE.md` from `.tas/templates/AGENTS.md` first.

## Sections (one owner each, one marker pair each)

| Key | Heading (`##`, top-level) | Source |
|-----|---------------------------|--------|
| `TECH-STACK` | Tech Stack | SAD §4 Technology Stack |
| `PRINCIPLES` | Architecture Principles & Decisions | SAD §2 Architecture Principle + §13 ADR Index (Accepted only) |
| `SECURITY` | Security Constraints | SAD §10 Security Controls — the cross-cutting `SEC-NN` |
| `NFR` | NFR Constraints | SAD §11 NFR Strategy — the `NFR-NNN` targets that bind coding |
| `CONTRACTS` | Stable Contracts — DO NOT CHANGE | SAD §9.2 Integration Contract Registry — `IC-NN` signatures |
| `DOMAIN-TERMS` | Domain Terms | BRD §12 Glossary (`docs/brd.md`, if present) |
| `DESIGN-RULES` | Design Rules | Design Spec (`docs/design-spec.md`, if present) — the token / no-inline-literal rule the coding agent must obey |

Each section, once generated, looks exactly like this in the file — a normal top-level heading immediately followed by its marker pair, content between:
```
## {Heading}
<!-- TAS:SAD:{KEY}:BEGIN — generated by /tas-agents from docs/sad.md (+ BRD Glossary, ADRs, Design Spec). DO NOT edit by hand; re-run /tas-agents after the source changes. Content outside marker pairs is yours to edit. -->
- {bullet}
- {bullet}
<!-- TAS:SAD:{KEY}:END -->
```
Omit a section entirely only if its source is genuinely empty (e.g. no `docs/design-spec.md` → skip Design Rules — do not emit an empty heading).

## Actions
1. Read `tas.yaml` for project context (name, stacks).
2. **Read the current target file first.** For each row in the Sections table, locate `<!-- TAS:SAD:{KEY}:BEGIN -->` … `<!-- TAS:SAD:{KEY}:END -->`:
   - **Found** → this section already exists with the right shape; note its position, you will replace only the inner content.
   - **Not found, but a manual heading with the same title already exists** (e.g. an old template's hand-written `## Tech Stack` placeholder) → reuse that heading; do not create a second one. Insert the marker pair as that heading's entire content, replacing whatever placeholder text was there.
   - **Not found, no heading exists either** → this section will be newly inserted (step 4).
3. **Migrate the old combined block, if present.** Older files have a single `<!-- TAS:SAD-CONTEXT:BEGIN -->` … `<!-- TAS:SAD-CONTEXT:END -->` block (possibly nested under a `## Architecture (generated from SAD)` heading) containing `###` subsections. If found:
   - Rename the wrapping heading to plain `## Architecture` (drop the `(generated from SAD)` suffix — it no longer wraps generated content).
   - Delete the old combined block entirely (markers and content).
   - Treat every subsection that block used to contain as "not found" for step 2/4 — it gets recreated as a flat per-section block in the same neighborhood, per the Sections table.
4. **Insert missing sections.** For any section still missing after steps 2–3, insert a new `## {Heading}` + marker pair (empty, to be filled in step 5) directly after the `## Architecture` heading (or after the last already-inserted generated section, to keep the Sections table order), or — if no `## Architecture` heading exists — immediately before `## Build & Test`, or at end of file as a last resort. Never nest a generated section under another heading.
5. **Distill from the SAD** — grep headings, read only the needed sections (do NOT dump the whole SAD) — per the Source column above. Write ONLY between each section's own markers, replacing the inner content; keep the markers, the heading, and everything outside them untouched (the rest of the file — `## Conventions`, `## Build & Test`, `## Environment Setup`, any human edits — is the user's and must survive regeneration).
6. Keep each section a **tight quick-load summary**, not a copy of the SAD. Every item carries its **source ID** so it traces back — e.g. "Payments via Stripe (ADR-003)", "JWT on all `/api` routes except `/auth` (SEC-01)", "Cart API P95 ≤ 200ms (NFR-003)", "`POST /v1/payments` — frozen signature (IC-01)". For detail, the bullet links to the SAD section/ID; the SAD stays the source of truth.
7. **Report** what changed (counts per section, e.g. "Tech Stack 5, Security 3, Stable Contracts 2 …"; note if the old combined block was migrated).

## Principles
- **Generated, not hand-written** — touch only inside each section's own marker pair; never edit outside markers, never edit the SAD from here.
- **Flat, single-owner** — every generated section is a top-level `##`, never nested `###` under another heading; each heading has exactly one owner (the command, once generated — never a duplicate manual heading with the same title).
- **Summary, not duplication** — distilled bullets with source IDs; a coding agent reads this instead of the full SAD.
- **Idempotent** — running twice with no SAD change produces no diff; the section order and shape are stable.
- **Re-run when any source changes** — regeneration is idempotent. Re-run on: **T3** SAD change (`/tas-sad` UPDATE), **T4** a bug with SAD impact, **T6** a new domain term added to BRD §12 Glossary, **T7** a Design Spec change (token / component / rule). The upstream command suggests `/tas-agents` after each so the context never drifts.
- **Review-only, no approval gate** — each section is derived from the already-approved SAD; SE reviews it but `CLAUDE.md`/`AGENTS.md` itself carries no `artifact-status`.

## Flow Context
- Upstream: **SAD (approved) + BRD Glossary + Design Spec → /tas-agents → CLAUDE.md/AGENTS.md generated sections**
- Runs at Stage 03 (right after SAD approval) and again on any T3 / T4 / T6 / T7 trigger above.
