---
name: smart-workflow
description: Zero-bloat task orchestration protocol for code, refactoring, DB migrations, debugging, specs, UI, and audits. Enforces Size Gate (Tier S/M/L + Debug), scripts-before-LLM, tiered model routing, context firewall, decision lock, and 4-point adversarial self-check.
---
# Smart Workflow (v2)
Goal: maximize output quality while minimizing frontier-model (`inherit` / `pro` / `opus`) quota burn—including planning overhead itself.
## 0. Size Gate (<=2 quick lookups)
Select **one** mode based on blast radius and risk:
| Mode | Criteria | Protocol |
|---|---|---|
| **Tier S** | <=3 files, local edit, no cross-cutting invariants, no auth/DB/contracts | Exit immediately -> execute directly without wave plans or skill routers. |
| **Tier M** | 4-15 files, 1 module/feature, moderate risk (or 1-3 files touching auth/DB/contracts) | Run **only** "Tier M Protocol". |
| **Tier L** | >15 files, new architecture, cross-cutting security/permissions, mass migration, greenfield | Read `references/tier-l-templates.md`, then execute Steps 1-5. |
| **Debug / Audit** | Complex bug hunt, incident, or read-only audit without mass rewrite | Run **only** "Debug / Audit Lane". |
## Tier M Protocol (Lightweight)
1. Inspect code/docs silently; if a real trade-off exists, ask 1 compact batch of questions (recommended option first).
2. Write a 3-5 step plan. Pull skills from `.agents/SKILL-MAP.md` if present; otherwise pick obvious installed skills directly.
3. Implement directly or with 1-2 workers (`flash`/`haiku` for boilerplate, `inherit`/`pro` for core logic).
4. Run existing tests, linters, and typechecks + 4-point self-check (Step 5.2).
5. Run 1 fresh-context reviewer (`flash`) on `git diff` **only** if business logic lacks automated tests or touches auth/DB/contracts.
*Forbidden in Tier M:* writing custom gate scripts, spawning debate opponents, `pre-mortem`, or multi-wave pipelines.
## Debug / Audit Lane
1. Gather facts and reproduce the defect with a minimal command or failing test (zero speculative edits).
2. Isolate root cause (`inherit` or 1 `research` subagent for large logs/codebases).
3. Apply minimal fix + regression test; prove with fresh test output.
*Do not force Wave 0-3 pipelines onto debugging unless the fix escalates into a Tier L refactor.*
---
## Full Pipeline (Tier L Only)
### Step 1. Fact Reconnaissance & Frontier Gate
1. Check repo structure, file counts, existing tests/linters, and `.agents/SKILL-MAP.md` yourself.
2. Silently lock 5 anchors: **deliverable**, **coupling**, **untouchable invariants**, **cost priority** (quota vs tokens vs wall-clock), and **objective acceptance criteria**.
<!-- ‹guest · 2026-12-04› -->
3. Ask the user **only** unresolved decision forks; group standard industry defaults into one batch for a single "yes" (recommended option first).
### Step 2. Topology & Deterministic ROI Filter
- **Low coupling** (independent modules) -> parallel fan-out workers.
- **High coupling** (shared schema, cross-cutting auth, single core engine) -> sequential role pipeline.
- **Mixed coupling** (default for Tier L) -> hybrid waves: `W0 Skeleton` -> `W1 Nodes` -> `W2 Integration` -> `W3 Acceptance`.
- **Deterministic ROI Filter (0 LLM tokens on mechanics):** use existing tests, linters, typecheckers, schemas, and `git diff` first. Write custom gate scripts (structure/graph validator, hotspot/load audit, context-digest builder) **only when `nodes >= 8` or `repeated checks >= 3`**.
- **Node Classification:** high-risk nodes (high fan-in/load, state mutation, auth/permissions, billing, public API) -> *Critical*; everything else -> *Standard*.
### Step 3. Lean Skill Selection & Binding
1. If `.agents/SKILL-MAP.md` exists -> reuse its mappings.
2. Otherwise -> shortlist matching skills, verify each skill's **description** (not just its name, avoiding collisions), and cap heavy skills (`>12 KB`) to a `<=60-line` extract in `scratch/`.
3. Pass **at most 2 domain skills/extracts** per worker so narrow contexts stay sharp.
### Step 4. Waves, Model Routing & Isolation
- **Execution Primitives:**
- Prefer fresh-context parallel/pipeline runners (`run_workflow` or isolated subagents) returning typed JSON.
- Persistent subagents only for stateful domain owners, `browser`, or `research`.
- Never use shared-board `swarm` for blind independent verification unless explicitly requested.
- **Disjoint Write Set Invariant:** parallel workers in the same wave must write to **strictly non-overlapping file sets**. Shared files (schemas, routes, indexes, configs) are updated **only** by the Coordinator in W0/W2 from worker `delta` proposals.
- **Wave 0 (`inherit`):** skeleton, shared types/contracts, invariants. On genuine architectural forks (`<=1-2` per project, **pre-code only**), run 2 blind 1-turn opponents in strict JSON + 1-turn Coordinator arbitration.
- **Wave 1 (Tiered Routing):**
- *Standard nodes (~60-70%):* context digest (`<=200 lines`: role rules + W0 contracts + direct neighbors) -> `flash` implementation -> deterministic checks -> 1 narrow `flash` verifier. Frontier model never touches these.
- *Critical nodes (~30-40% + Hotspot TOP-5):* `inherit` core logic/skeleton -> `flash` routine/tests -> deterministic checks -> 2-3 parallel narrow `flash` verifiers (`1 verifier = 1 defect class`, strict JSON) -> 1-turn `inherit` arbitration on conflicts.
### Step 5. Decision Lock, 4-Point Self-Check & Fix Loop
1. **Approval Gate & Decision Lock:** in Tier L (and unresolved Tier M forks), **never modify project files or launch waves before explicit user confirmation**. Locked user decisions and W0 contracts are immutable—workers must never silently override them; on conflict, halt and escalate to the Coordinator.
2. **Mandatory 4-Point Self-Check (before `verify`):**
- **(a) Decision Check:** zero violations of locked user decisions or W0 contracts.
- **(b) Evidence Gate:** fresh test/linter/script output captured in the current turn (zero "should work" claims).
- **(c) Blast Radius:** `git diff --stat` strictly inside the assigned `disjoint write set`.
- **(d) Adversarial Edge-Case:** name the #1 way to break or bypass the change and verify it is closed.
3. **Batched Fixes:** merge script + verifier findings into **1 batch**; run fixer with **reset context** (`target file + W0 contract + issue batch`) applying targeted edits. `reverify` checks **only** fixed items + full deterministic suite.
4. **Circuit Breaker & Acceptance:** max **2 fix loops on `flash`**, then immediate escalation to `inherit`. Close Tier L with full cross-module checks + domain acceptance from `references/tier-l-templates.md`.
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.