@rune-kit/rune 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +357 -0
  3. package/agents/.gitkeep +0 -0
  4. package/agents/architect.md +29 -0
  5. package/agents/asset-creator.md +11 -0
  6. package/agents/audit.md +11 -0
  7. package/agents/autopsy.md +11 -0
  8. package/agents/brainstorm.md +11 -0
  9. package/agents/browser-pilot.md +11 -0
  10. package/agents/coder.md +29 -0
  11. package/agents/completion-gate.md +11 -0
  12. package/agents/constraint-check.md +11 -0
  13. package/agents/context-engine.md +11 -0
  14. package/agents/cook.md +11 -0
  15. package/agents/db.md +11 -0
  16. package/agents/debug.md +11 -0
  17. package/agents/dependency-doctor.md +11 -0
  18. package/agents/deploy.md +11 -0
  19. package/agents/design.md +11 -0
  20. package/agents/docs-seeker.md +11 -0
  21. package/agents/fix.md +11 -0
  22. package/agents/hallucination-guard.md +11 -0
  23. package/agents/incident.md +11 -0
  24. package/agents/integrity-check.md +11 -0
  25. package/agents/journal.md +11 -0
  26. package/agents/launch.md +11 -0
  27. package/agents/logic-guardian.md +11 -0
  28. package/agents/marketing.md +11 -0
  29. package/agents/onboard.md +11 -0
  30. package/agents/perf.md +11 -0
  31. package/agents/plan.md +11 -0
  32. package/agents/preflight.md +11 -0
  33. package/agents/problem-solver.md +11 -0
  34. package/agents/rescue.md +11 -0
  35. package/agents/research.md +11 -0
  36. package/agents/researcher.md +29 -0
  37. package/agents/review-intake.md +11 -0
  38. package/agents/review.md +11 -0
  39. package/agents/reviewer.md +28 -0
  40. package/agents/safeguard.md +11 -0
  41. package/agents/sast.md +11 -0
  42. package/agents/scanner.md +28 -0
  43. package/agents/scope-guard.md +11 -0
  44. package/agents/scout.md +11 -0
  45. package/agents/sentinel.md +11 -0
  46. package/agents/sequential-thinking.md +11 -0
  47. package/agents/session-bridge.md +11 -0
  48. package/agents/skill-forge.md +11 -0
  49. package/agents/skill-router.md +11 -0
  50. package/agents/surgeon.md +11 -0
  51. package/agents/team.md +11 -0
  52. package/agents/test.md +11 -0
  53. package/agents/trend-scout.md +11 -0
  54. package/agents/verification.md +11 -0
  55. package/agents/video-creator.md +11 -0
  56. package/agents/watchdog.md +11 -0
  57. package/agents/worktree.md +11 -0
  58. package/commands/.gitkeep +0 -0
  59. package/commands/rune.md +168 -0
  60. package/compiler/__tests__/openclaw-adapter.test.js +140 -0
  61. package/compiler/__tests__/parser.test.js +55 -0
  62. package/compiler/adapters/antigravity.js +59 -0
  63. package/compiler/adapters/claude.js +37 -0
  64. package/compiler/adapters/cursor.js +67 -0
  65. package/compiler/adapters/generic.js +60 -0
  66. package/compiler/adapters/index.js +45 -0
  67. package/compiler/adapters/openclaw.js +150 -0
  68. package/compiler/adapters/windsurf.js +60 -0
  69. package/compiler/bin/rune.js +288 -0
  70. package/compiler/doctor.js +153 -0
  71. package/compiler/emitter.js +240 -0
  72. package/compiler/parser.js +208 -0
  73. package/compiler/transformer.js +69 -0
  74. package/compiler/transforms/branding.js +27 -0
  75. package/compiler/transforms/cross-references.js +29 -0
  76. package/compiler/transforms/frontmatter.js +38 -0
  77. package/compiler/transforms/hooks.js +68 -0
  78. package/compiler/transforms/subagents.js +36 -0
  79. package/compiler/transforms/tool-names.js +60 -0
  80. package/contexts/dev.md +34 -0
  81. package/contexts/research.md +43 -0
  82. package/contexts/review.md +55 -0
  83. package/extensions/ai-ml/PACK.md +517 -0
  84. package/extensions/analytics/PACK.md +557 -0
  85. package/extensions/backend/PACK.md +678 -0
  86. package/extensions/chrome-ext/PACK.md +995 -0
  87. package/extensions/content/PACK.md +381 -0
  88. package/extensions/devops/PACK.md +520 -0
  89. package/extensions/ecommerce/PACK.md +280 -0
  90. package/extensions/gamedev/PACK.md +393 -0
  91. package/extensions/mobile/PACK.md +273 -0
  92. package/extensions/saas/PACK.md +805 -0
  93. package/extensions/security/PACK.md +536 -0
  94. package/extensions/trading/PACK.md +597 -0
  95. package/extensions/ui/PACK.md +947 -0
  96. package/package.json +47 -0
  97. package/skills/.gitkeep +0 -0
  98. package/skills/adversary/SKILL.md +271 -0
  99. package/skills/asset-creator/SKILL.md +157 -0
  100. package/skills/audit/SKILL.md +466 -0
  101. package/skills/autopsy/SKILL.md +200 -0
  102. package/skills/ba/SKILL.md +279 -0
  103. package/skills/brainstorm/SKILL.md +266 -0
  104. package/skills/browser-pilot/SKILL.md +168 -0
  105. package/skills/completion-gate/SKILL.md +151 -0
  106. package/skills/constraint-check/SKILL.md +165 -0
  107. package/skills/context-engine/SKILL.md +176 -0
  108. package/skills/cook/SKILL.md +636 -0
  109. package/skills/db/SKILL.md +256 -0
  110. package/skills/debug/SKILL.md +240 -0
  111. package/skills/dependency-doctor/SKILL.md +235 -0
  112. package/skills/deploy/SKILL.md +174 -0
  113. package/skills/design/DESIGN-REFERENCE.md +365 -0
  114. package/skills/design/SKILL.md +462 -0
  115. package/skills/doc-processor/SKILL.md +254 -0
  116. package/skills/docs/SKILL.md +336 -0
  117. package/skills/docs-seeker/SKILL.md +166 -0
  118. package/skills/fix/SKILL.md +192 -0
  119. package/skills/git/SKILL.md +285 -0
  120. package/skills/hallucination-guard/SKILL.md +204 -0
  121. package/skills/incident/SKILL.md +241 -0
  122. package/skills/integrity-check/SKILL.md +169 -0
  123. package/skills/journal/SKILL.md +190 -0
  124. package/skills/launch/SKILL.md +330 -0
  125. package/skills/logic-guardian/SKILL.md +240 -0
  126. package/skills/marketing/SKILL.md +229 -0
  127. package/skills/mcp-builder/SKILL.md +311 -0
  128. package/skills/onboard/SKILL.md +298 -0
  129. package/skills/perf/SKILL.md +297 -0
  130. package/skills/plan/SKILL.md +520 -0
  131. package/skills/preflight/SKILL.md +231 -0
  132. package/skills/problem-solver/SKILL.md +284 -0
  133. package/skills/rescue/SKILL.md +434 -0
  134. package/skills/research/SKILL.md +122 -0
  135. package/skills/review/SKILL.md +354 -0
  136. package/skills/review-intake/SKILL.md +222 -0
  137. package/skills/safeguard/SKILL.md +188 -0
  138. package/skills/sast/SKILL.md +190 -0
  139. package/skills/scaffold/SKILL.md +276 -0
  140. package/skills/scope-guard/SKILL.md +150 -0
  141. package/skills/scout/SKILL.md +232 -0
  142. package/skills/sentinel/SKILL.md +320 -0
  143. package/skills/sentinel-env/SKILL.md +226 -0
  144. package/skills/sequential-thinking/SKILL.md +234 -0
  145. package/skills/session-bridge/SKILL.md +287 -0
  146. package/skills/skill-forge/SKILL.md +317 -0
  147. package/skills/skill-router/SKILL.md +267 -0
  148. package/skills/surgeon/SKILL.md +203 -0
  149. package/skills/team/SKILL.md +397 -0
  150. package/skills/test/SKILL.md +271 -0
  151. package/skills/trend-scout/SKILL.md +145 -0
  152. package/skills/verification/SKILL.md +201 -0
  153. package/skills/video-creator/SKILL.md +201 -0
  154. package/skills/watchdog/SKILL.md +166 -0
  155. package/skills/worktree/SKILL.md +140 -0
@@ -0,0 +1,636 @@
1
+ ---
2
+ name: cook
3
+ description: "Feature implementation orchestrator. ALWAYS use this skill for ANY code change — implement, build, add feature, create, fix bug, or any task that modifies source code. This is the default route for 70% of all requests. Runs full TDD cycle: understand → plan → test → implement → quality → verify → commit."
4
+ context: fork
5
+ agent: general-purpose
6
+ metadata:
7
+ author: runedev
8
+ version: "0.5.0"
9
+ layer: L1
10
+ model: sonnet
11
+ group: orchestrator
12
+ tools: "Read, Write, Edit, Bash, Glob, Grep"
13
+ ---
14
+
15
+ # cook
16
+
17
+ ## Purpose
18
+
19
+ The primary orchestrator for feature implementation. Coordinates the entire L2 mesh in a phased TDD workflow. Handles 70% of all user requests — any task that modifies source code routes through cook.
20
+
21
+ <HARD-GATE>
22
+ Before starting ANY implementation:
23
+ 1. You MUST understand the codebase first (Phase 1)
24
+ 2. You MUST have a plan before writing code (Phase 2)
25
+ 3. You MUST write failing tests before implementation (Phase 3) — unless explicitly skipped
26
+ This applies to EVERY feature regardless of perceived simplicity.
27
+ </HARD-GATE>
28
+
29
+ ## Workflow Chains (Predefined)
30
+
31
+ Cook supports predefined workflow chains for common task types. Use these as shortcuts instead of manually determining phases:
32
+
33
+ ```
34
+ /rune cook feature → Full TDD pipeline (all phases)
35
+ /rune cook bugfix → Diagnose → fix → verify (Phase 1 → 4 → 6 → 7)
36
+ /rune cook refactor → Understand → plan → implement → quality (Phase 1 → 2 → 4 → 5 → 6 → 7)
37
+ /rune cook security → Full pipeline + sentinel@opus + sast (all phases, security-escalated)
38
+ /rune cook hotfix → Minimal: fix → verify → commit (Phase 4 → 6 → 7, skip scout if user provides context)
39
+ ```
40
+
41
+ **Chain selection**: If user invokes `/rune cook` without a chain type, auto-detect from the task description:
42
+ - Contains "bug", "fix", "broken", "error" → `bugfix`
43
+ - Contains "refactor", "clean", "restructure" → `refactor`
44
+ - Contains "security", "auth", "vulnerability", "CVE" → `security`
45
+ - Contains "urgent", "hotfix", "production" → `hotfix`
46
+ - Default → `feature`
47
+
48
+ ## Phase Skip Rules
49
+
50
+ Not every task needs every phase:
51
+
52
+ ```
53
+ Simple bug fix: Phase 1 → 4 → 6 → 7
54
+ Small refactor: Phase 1 → 4 → 5 → 6 → 7
55
+ New feature: Phase 1 → 1.5 → 2 → 3 → 4 → 5 → 6 → 7 → 8
56
+ Complex feature: All phases + brainstorm in Phase 2
57
+ Security-sensitive: All phases + sentinel escalated to opus
58
+ Fast mode: Phase 1 → 4 → 6 → 7 (auto-detected, see below)
59
+ Multi-session: Phase 0 (resume) → 3 → 4 → 5 → 6 → 7 (one plan phase per session)
60
+ ```
61
+
62
+ Determine complexity BEFORE starting. Create TodoWrite with applicable phases.
63
+
64
+ ## Fast Mode (Auto-Detect)
65
+
66
+ Cook auto-detects small changes and streamlines the pipeline:
67
+
68
+ ```
69
+ IF all of these are true:
70
+ - Total estimated change < 30 LOC
71
+ - Single file affected
72
+ - No security-relevant code (auth, crypto, payments, .env)
73
+ - No public API changes
74
+ - No database schema changes
75
+ THEN: Fast Mode activated
76
+ - Skip Phase 2 (PLAN) — change is too small for a formal plan
77
+ - Skip Phase 3 (TEST) — unless existing tests cover the area
78
+ - Skip Phase 5b (SENTINEL) — non-security code
79
+ - Skip Phase 8 (BRIDGE) — not worth persisting
80
+ - KEEP Phase 5a (PREFLIGHT) and Phase 6 (VERIFY) — always run quality checks
81
+ ```
82
+
83
+ **Announce fast mode**: "Fast mode: small change detected (<30 LOC, single file, non-security). Streamlined pipeline."
84
+ **Override**: User can say "full pipeline" to force all phases even on small changes.
85
+
86
+ ## Phase 0.5: ENVIRONMENT CHECK (First Run Only)
87
+
88
+ **Goal**: Verify the developer's environment can run this project before wasting time on planning.
89
+
90
+ **SUB-SKILL**: Use `rune:sentinel-env`
91
+
92
+ **Auto-trigger conditions** (ALL must be true):
93
+ - No `.rune/` directory exists (first cook run in this project)
94
+ - OR `npm install` / `pip install` / build just failed with environment-looking errors
95
+ - AND NOT fast mode
96
+
97
+ Skip silently on subsequent runs. User can force with `/rune env-check`.
98
+
99
+ ## Phase 1: UNDERSTAND
100
+
101
+ **Goal**: Know what exists before changing anything.
102
+
103
+ **REQUIRED SUB-SKILLS**: Use `rune:scout`. For non-trivial tasks, use `rune:ba`.
104
+
105
+ 1. Create TodoWrite with all applicable phases for this task
106
+ 2. Mark Phase 1 as `in_progress`
107
+ 3. **BA gate** — determine if Business Analyst elicitation is needed:
108
+ - If task is a Feature Request, Integration, or Greenfield → invoke `rune:ba` for requirement elicitation
109
+ - If task description is > 50 words or contains business terms (users, revenue, workflow, integration) → invoke `rune:ba`
110
+ - If Bug Fix or simple Refactor → skip BA, proceed with scout
111
+ - BA produces a Requirements Document at `.rune/features/<name>/requirements.md` that feeds into Phase 2 (PLAN)
112
+ 4. **Decision enforcement** — load prior decisions:
113
+ - Use `Glob` to check for `.rune/decisions.md`
114
+ - If exists, use `Read` to load it
115
+ - Extract decisions relevant to the current task domain (match by keywords: module names, tech choices, patterns)
116
+ - These become **constraints for Phase 2 (PLAN)** — the plan MUST NOT contradict active decisions without explicit user override
117
+ - If no `.rune/decisions.md` exists, skip silently
118
+ 4. Invoke scout to scan the codebase:
119
+ - Use `Glob` to find files matching the feature domain (e.g., `**/*auth*`, `**/*user*`)
120
+ - Use `Grep` to search for related patterns, imports, existing implementations
121
+ - Use `Read` to examine key files identified
122
+ 5. Summarize findings:
123
+ - What exists already
124
+ - What patterns/conventions the project uses
125
+ - What files will likely need to change
126
+ - **Active decisions that constrain this task** (from step 3)
127
+ 6. **Python async detection**: If Python project detected (`pyproject.toml` or `setup.py`), use `Grep` for async indicators:
128
+ - Search for: `async def`, `await`, `aiosqlite`, `aiohttp`, `httpx.AsyncClient`, `asyncio.run`, `trio`
129
+ - If ≥3 matches across source files → flag project as **"async-first Python"**
130
+ - Note for later phases: new code should default to `async def`, avoid blocking calls (`requests.get`, `time.sleep`, `open()`)
131
+ 7. Mark Phase 1 as `completed`
132
+
133
+ **Gate**: If scout finds the feature already exists → STOP and inform user.
134
+
135
+ ## Phase 1.5: DOMAIN CONTEXT (L4 Pack Detection)
136
+
137
+ **Goal**: Detect if domain-specific L4 extension packs apply to this task.
138
+
139
+ After scout completes (Phase 1), check if the detected tech stack or task description matches any L4 extension pack. If a match is found, read the pack's PACK.md to load domain-specific patterns, constraints, and sharp edges into the current workflow.
140
+
141
+ 1. Check the project's detected stack against the L4 pack mapping:
142
+
143
+ | Signal in Codebase or Task | Pack | File |
144
+ |---|---|---|
145
+ | `*.tsx`, `*.svelte`, `*.vue`, Tailwind, CSS modules | `@rune/ui` | `extensions/ui/PACK.md` |
146
+ | Express/Fastify/NestJS routes, API endpoints | `@rune/backend` | `extensions/backend/PACK.md` |
147
+ | Dockerfile, `.github/workflows/`, Terraform | `@rune/devops` | `extensions/devops/PACK.md` |
148
+ | `react-native`, `expo`, `flutter`, `ios/`, `android/` | `@rune/mobile` | `extensions/mobile/PACK.md` |
149
+ | Auth, OWASP, secrets, PCI/HIPAA markers | `@rune/security` | `extensions/security/PACK.md` |
150
+ | Trading, charts, market data, `decimal.js` | `@rune/trading` | `extensions/trading/PACK.md` |
151
+ | Multi-tenant, billing, `stripe`, subscription | `@rune/saas` | `extensions/saas/PACK.md` |
152
+ | Cart, checkout, inventory, Shopify | `@rune/ecommerce` | `extensions/ecommerce/PACK.md` |
153
+ | `openai`, `anthropic`, embeddings, RAG, LLM | `@rune/ai-ml` | `extensions/ai-ml/PACK.md` |
154
+ | `three`, `pixi`, `phaser`, `*.glsl`, game loop | `@rune/gamedev` | `extensions/gamedev/PACK.md` |
155
+ | CMS, blog, MDX, `i18next`, SEO | `@rune/content` | `extensions/content/PACK.md` |
156
+ | Analytics, tracking, A/B test, funnel | `@rune/analytics` | `extensions/analytics/PACK.md` |
157
+ | PRD, roadmap, KPI, release notes, `.rune/business/` | `@rune-pro/product` | `extensions/pro-product/PACK.md` |
158
+
159
+ 2. If ≥1 pack matches:
160
+ - Use `Read` to load the matching PACK.md
161
+ - Extract the relevant skill's **Workflow** steps and **Constraints**
162
+ - Apply pack constraints alongside cook's own constraints for the rest of the workflow
163
+ - Announce: "Loaded @rune/[pack] — applying [skill-name] domain patterns"
164
+
165
+ 3. If 0 packs match: skip silently, proceed to Phase 2
166
+
167
+ This phase is lightweight — a Read + pattern match, not a full scan. It does NOT replace Phase 1 (scout) or Phase 2 (plan). It augments them with domain expertise.
168
+
169
+ ## Phase 0: RESUME CHECK (Before Phase 1)
170
+
171
+ **Goal**: Detect if a master plan already exists for this task. If so, skip Phase 1-2 and resume from the current phase.
172
+
173
+ 1. Use `Glob` to check for `.rune/plan-*.md` files
174
+ 2. If a master plan exists that matches the current task:
175
+ - Read the master plan file
176
+ - Find the first phase with status `⬚ Pending` or `🔄 Active`
177
+ - Read ONLY that phase's file (e.g., `.rune/plan-<feature>-phase<N>.md`)
178
+ - Announce: "Resuming from Phase N: <name>. Loading phase file."
179
+ - Skip to Phase 4 (IMPLEMENT) with the phase file as context
180
+ - Mark the phase as `🔄 Active` in the master plan
181
+ 3. If no master plan exists → proceed to Phase 1 as normal
182
+
183
+ **This enables multi-session workflows**: Opus plans once → each session picks up the next phase.
184
+
185
+ ## Phase 2: PLAN
186
+
187
+ **Goal**: Break the task into concrete implementation steps before writing code.
188
+
189
+ **REQUIRED SUB-SKILL**: Use `rune:plan`
190
+
191
+ 1. Mark Phase 2 as `in_progress`
192
+ 2. **Feature workspace** (opt-in) — for non-trivial features (3+ phases), suggest creating a feature workspace:
193
+ ```
194
+ .rune/features/<feature-name>/
195
+ ├── spec.md — what we're building and why (user's original request + context)
196
+ ├── plan.md — implementation plan (output of plan skill)
197
+ ├── decisions.md — feature-specific decisions (subset of .rune/decisions.md)
198
+ └── status.md — progress tracking (completed/pending phases)
199
+ ```
200
+ - Ask user: "Create feature workspace for `<feature-name>`?" — if yes, create the directory + spec.md with the user's request
201
+ - plan.md is written after Step 4 (plan approval)
202
+ - Skip for simple bug fixes, small refactors, or fast mode
203
+ - Session-bridge (Phase 8) auto-updates status.md if workspace exists
204
+ 3. Based on scout findings, create an implementation plan:
205
+ - List exact files to create/modify
206
+ - Define the order of changes
207
+ - Identify dependencies between steps
208
+ - **Include active decisions from Phase 1 step 3 as constraints** — plan must respect prior decisions or explicitly flag overrides
209
+ 4. If multiple valid approaches exist → invoke `rune:brainstorm` for trade-off analysis
210
+ 5. Present plan to user for approval
211
+ 6. If feature workspace was created (step 2), write approved plan to `.rune/features/<name>/plan.md`
212
+ 7. Mark Phase 2 as `completed`
213
+
214
+ **Gate**: User MUST approve the plan before proceeding. Do NOT skip this.
215
+
216
+ ## Phase 2.5: ADVERSARY (Red-Team Challenge)
217
+
218
+ **Goal**: Stress-test the approved plan BEFORE writing code — catch flaws at plan time, not implementation time.
219
+
220
+ **REQUIRED SUB-SKILL**: Use `rune:adversary`
221
+
222
+ 1. **Skip conditions** (do NOT run adversary for):
223
+ - Bug fixes or hotfixes (plan is "fix the bug", nothing to challenge)
224
+ - Simple refactors (< 3 files, no new logic)
225
+ - Fast mode (user explicitly opted for speed)
226
+ 2. **Run adversary** on the approved plan:
227
+ - Full Red-Team mode for new features, architectural changes, security-sensitive plans
228
+ - Quick Challenge mode for smaller plans (< 3 files, no auth/payment)
229
+ 3. **Handle verdict**:
230
+ - **REVISE** → return to Phase 2 (PLAN) with adversary findings as constraints. User must re-approve.
231
+ - **HARDEN** → present remediations to user, update plan inline, then proceed to Phase 3
232
+ - **PROCEED** → pass findings as implementation notes to Phase 3
233
+ 4. **Max 1 REVISE loop** per cook session — if the revised plan also gets REVISE, ask user to decide
234
+
235
+ ### Phase-Aware Execution (Master Plan + Phase Files)
236
+
237
+ When `rune:plan` produces a **master plan + phase files** (non-trivial tasks):
238
+
239
+ 1. **After plan approval**: Read the master plan to identify Phase 1
240
+ 2. **Load ONLY Phase 1's file** — do NOT load all phase files into context
241
+ 3. **Execute Phase 1** through cook Phase 3-6 (test → implement → quality → verify)
242
+ 4. **After Phase 1 complete**:
243
+ - Mark tasks done in the phase file
244
+ - Update master plan: Phase 1 status `⬚ → ✅`
245
+ - Announce: "Phase 1 complete. Phase 2 ready for next session."
246
+ 5. **Next session**: Phase 0 (RESUME CHECK) detects the master plan → loads Phase 2 → executes
247
+ 6. **Repeat** until all phases are ✅
248
+
249
+ <HARD-GATE>
250
+ NEVER load multiple phase files at once. One phase per session = small context = better code.
251
+ If the coder model needs info from other phases, it's in the Cross-Phase Context section of the current phase file.
252
+ </HARD-GATE>
253
+
254
+ **Why one phase per session?**
255
+ - Big context = even Opus misses details and makes mistakes
256
+ - Small context = Sonnet handles correctly, Opus has zero mistakes
257
+ - Phase files are self-contained via Amateur-Proof Template — no other context needed
258
+
259
+ ## Phase 3: TEST (TDD Red)
260
+
261
+ **Goal**: Define expected behavior with failing tests BEFORE writing implementation.
262
+
263
+ **REQUIRED SUB-SKILL**: Use `rune:test`
264
+
265
+ 1. Mark Phase 3 as `in_progress`
266
+ 2. Write test files based on the plan:
267
+ - Use `Write` to create test files
268
+ - Cover the primary use case + edge cases
269
+ - Tests MUST be runnable
270
+ 3. **Python async pre-check** (if async-first Python flagged in Phase 1):
271
+ - Verify `pytest-asyncio` is in project dependencies (`pyproject.toml` or `requirements*.txt`)
272
+ - Check `pyproject.toml` for `[tool.pytest.ini_options]` → `asyncio_mode = "auto"` — if missing, warn user and suggest adding it before writing async tests
273
+ - If pytest-asyncio not installed: warn that async tests will silently pass without executing async code
274
+ 4. Run the tests to verify they FAIL:
275
+ - Use `Bash` to execute the test command (e.g., `pytest`, `npm test`, `cargo test`)
276
+ - Expected: tests FAIL (red) because implementation doesn't exist yet
277
+ 4. Mark Phase 3 as `completed`
278
+
279
+ **Gate**: Tests MUST exist and MUST fail. If tests pass without implementation → tests are wrong, rewrite them.
280
+
281
+ ## Phase 4: IMPLEMENT (TDD Green)
282
+
283
+ **Goal**: Write the minimum code to make tests pass.
284
+
285
+ **REQUIRED SUB-SKILL**: Use `rune:fix`
286
+
287
+ 1. Mark Phase 4 as `in_progress`
288
+ 2. **Phase-file execution** — if working from a master plan + phase file:
289
+ - Execute tasks listed in the phase file (the `## Tasks` section)
290
+ - Follow code contracts from `## Code Contracts` section
291
+ - Respect rejection criteria from `## Rejection Criteria` section
292
+ - Handle failure scenarios from `## Failure Scenarios` section
293
+ - Use `## Cross-Phase Context` for imports/exports from other phases
294
+ - Mark each task `[x]` in the phase file as completed
295
+ 3. Implement the feature following the plan:
296
+ - Use `Write` for new files
297
+ - Use `Edit` for modifying existing files
298
+ - Follow project conventions found in Phase 1
299
+ 3. Run tests after each significant change:
300
+ - Use `Bash` to run tests
301
+ - If tests pass → continue to next step in plan
302
+ - If tests fail → debug and fix
303
+ - **Python async checklist** (if async-first Python flagged in Phase 1):
304
+ - No blocking calls in async functions: `time.sleep()` → `asyncio.sleep()`, `open()` → `aiofiles.open()`, `requests.get()` → `httpx.AsyncClient.get()`
305
+ - Use `async with` for async context managers (DB connections, HTTP sessions)
306
+ - Prefer `asyncio.gather()` for parallel I/O operations
307
+ - Use `asyncio.TaskGroup` (Python 3.11+) for structured concurrency
308
+ 4. If stuck on unexpected errors → invoke `rune:debug` (max 3 debug↔fix loops)
309
+ 5. **Re-plan check** — before proceeding to Phase 5, evaluate:
310
+ - Did debug-fix loops hit max (3) for any area? → trigger re-plan
311
+ - Were files modified outside the approved plan scope? → trigger re-plan
312
+ - Was a new dependency added that changes the approach? → trigger re-plan
313
+ - Did the user request a scope change during implementation? → trigger re-plan
314
+ - If any trigger fires: invoke `rune:plan` with delta context:
315
+ ```
316
+ Delta: { original_plan: "Phase 2 plan or .rune/features/<name>/plan.md",
317
+ trigger: "max_debug | scope_expansion | new_dependency | user_scope_change",
318
+ failed_area: "description of what went wrong",
319
+ discovered: "new facts found during implementation" }
320
+ ```
321
+ Plan outputs revised phases. Get user approval before resuming.
322
+ 6. **Approach Pivot Gate** — if re-plan ALSO fails (implementation still blocked after revised plan):
323
+
324
+ <HARD-GATE>
325
+ Do NOT surrender. Do NOT tell user "no solution exists."
326
+ Do NOT try a 4th variant of the same approach.
327
+ MUST invoke brainstorm(mode="rescue") before giving up.
328
+ </HARD-GATE>
329
+
330
+ **Trigger conditions** (ANY of these):
331
+ - Re-plan produced a revised plan, but implementation hits the SAME category of blocker
332
+ - 3 debug-fix loops exhausted AND re-plan exhausted (total 6+ failed attempts in same approach)
333
+ - Agent catches itself about to say "this approach doesn't seem feasible" or "no solution found"
334
+
335
+ **Action**:
336
+ ```
337
+ Invoke rune:brainstorm with:
338
+ mode: "rescue"
339
+ failed_approach: "[name of approach from Phase 2]"
340
+ failure_evidence: ["blocker 1", "blocker 2", "blocker 3"]
341
+ original_goal: "[what we're still trying to achieve]"
342
+ ```
343
+
344
+ brainstorm(rescue) returns 3-5 category-diverse alternatives → present to user → user picks → **restart from Phase 2** with the new approach. Previous work is sunk cost — do not try to salvage.
345
+
346
+ 7. All tests MUST pass before proceeding
347
+ 8. Mark Phase 4 as `completed`
348
+
349
+ **Gate**: ALL tests from Phase 3 MUST pass. Do NOT proceed with failing tests.
350
+
351
+ ## Phase 5: QUALITY (Parallel)
352
+
353
+ **Goal**: Catch issues before they reach production.
354
+
355
+ Run quality checks **in parallel** for speed. Any CRITICAL finding blocks the commit.
356
+
357
+ ```
358
+ PARALLEL EXECUTION:
359
+ Launch 5a + 5b + 5c simultaneously as independent Task agents.
360
+ Wait for ALL to complete before proceeding.
361
+ If any returns BLOCK → fix findings, re-run the blocking check only.
362
+ ```
363
+
364
+ ### 5a. Preflight (Spec Compliance + Logic)
365
+ **REQUIRED SUB-SKILL**: Use `rune:preflight`
366
+ - **Spec compliance**: Compare approved plan (Phase 2) vs actual diff — did we build what we planned?
367
+ - Logic review: Are there obvious bugs?
368
+ - Error handling: Are errors caught properly?
369
+ - Completeness: Does it cover edge cases?
370
+
371
+ ### 5b. Security
372
+ **REQUIRED SUB-SKILL**: Use `rune:sentinel`
373
+ - Secret scan: No hardcoded keys/tokens
374
+ - OWASP check: No injection, XSS, CSRF vulnerabilities
375
+ - Dependency audit: No known vulnerable packages
376
+
377
+ ### 5c. Code Review
378
+ **REQUIRED SUB-SKILL**: Use `rune:review`
379
+ - Pattern compliance: Follows project conventions
380
+ - Code quality: Clean, readable, maintainable
381
+ - Performance: No obvious bottlenecks
382
+
383
+ ### 5d. Completion Gate
384
+ **REQUIRED SUB-SKILL**: Use `rune:completion-gate`
385
+ - Validate that agent claims match evidence trail
386
+ - Check: tests actually ran (stdout captured), files actually changed (git diff), build actually passed
387
+ - Any UNCONFIRMED claim → BLOCK with specific gap identified
388
+
389
+ **Gate**: If sentinel finds CRITICAL security issue → STOP, fix it, re-run. Non-negotiable.
390
+ **Gate**: If completion-gate finds UNCONFIRMED claim → STOP, re-verify. Non-negotiable.
391
+
392
+ ## Checkpoint Protocol (Opt-In)
393
+
394
+ For long-running cook sessions, save intermediate state at phase boundaries:
395
+
396
+ ```
397
+ After Phase 2 (PLAN approved): session-bridge saves plan + decisions
398
+ After Phase 4 (IMPLEMENT done): session-bridge saves progress + modified files
399
+ After Phase 5 (QUALITY passed): session-bridge saves quality results
400
+
401
+ Trigger: Invoke rune:session-bridge at each boundary.
402
+ This is OPT-IN — only activate if:
403
+ - Task spans 3+ phases
404
+ - Context-watch has triggered a warning
405
+ - User explicitly requests checkpoints
406
+ ```
407
+
408
+ ## Phase 6: VERIFY
409
+
410
+ **Goal**: Final automated verification before commit.
411
+
412
+ **REQUIRED SUB-SKILL**: Use `rune:verification`
413
+
414
+ 1. Mark Phase 6 as `in_progress`
415
+ 2. Run full verification suite:
416
+ - Lint check (e.g., `eslint`, `ruff`, `clippy`)
417
+ - Type check (e.g., `tsc --noEmit`, `mypy`, `cargo check`)
418
+ - Full test suite (not just new tests)
419
+ - Build (e.g., `npm run build`, `cargo build`)
420
+ 3. Use `rune:hallucination-guard` to verify:
421
+ - All imports reference real modules
422
+ - API calls use correct signatures
423
+ - No phantom dependencies
424
+ 4. Mark Phase 6 as `completed`
425
+
426
+ **Gate**: ALL checks MUST pass. If any fail → fix and re-run. Do NOT commit broken code.
427
+
428
+ ## Phase 7: COMMIT
429
+
430
+ **Goal**: Create a clean, semantic commit.
431
+
432
+ **RECOMMENDED SUB-SKILL**: Use `rune:git` for semantic commit generation.
433
+
434
+ 1. Mark Phase 7 as `in_progress`
435
+ 2. Stage changed files:
436
+ - Use `Bash` to run `git add <specific files>` (NOT `git add .`)
437
+ - Verify staged files with `git status`
438
+ 3. Invoke `rune:git commit` to generate semantic commit message from staged diff:
439
+ - Analyzes diff to classify change type (feat/fix/refactor/test/docs/chore)
440
+ - Extracts scope from file paths
441
+ - Detects breaking changes
442
+ - Formats as conventional commit: `<type>(<scope>): <description>`
443
+ - Fallback: if git skill unavailable, use format `<type>: <description>` manually
444
+ 4. **Master plan update** — if working from a master plan + phase files:
445
+ - Update the master plan file: current phase status `🔄 → ✅`
446
+ - If next phase exists: announce "Phase N complete. Phase N+1 ready for next session."
447
+ - If all phases ✅: announce "All phases complete. Feature done."
448
+ 5. Mark Phase 7 as `completed`
449
+
450
+ ## Phase 8: BRIDGE
451
+
452
+ **Goal**: Save context for future sessions and record metrics for mesh analytics.
453
+
454
+ **REQUIRED SUB-SKILL**: Use `rune:session-bridge`
455
+
456
+ 1. Mark Phase 8 as `in_progress`
457
+ 2. Save decisions to `.rune/decisions.md`:
458
+ - What approach was chosen and why
459
+ - Any trade-offs made
460
+ 3. Update `.rune/progress.md` with completed task
461
+ 4. Update `.rune/conventions.md` if new patterns were established
462
+ 5. **Write skill-sourced metrics** to `.rune/metrics/skills.json`:
463
+ - Read the existing file (or create `{ "version": 1, "updated": "<now>", "skills": {} }`)
464
+ - Under the `cook` key, update:
465
+ - `phases`: increment `run` or `skip` count for each phase that was run/skipped this session
466
+ - `quality_gate_results`: increment `preflight_pass`/`preflight_fail`, `sentinel_pass`/`sentinel_block`, `review_pass`/`review_issues` based on Phase 5 outcomes
467
+ - `debug_loops`: increment `total` by number of debug-fix loops in Phase 4, update `max_per_session` if this session exceeded it
468
+ - Write the updated file back
469
+ 6. **Adaptive error recovery** (H3 Intelligence):
470
+ - If Phase 4 had 3 debug-fix loops (max) for a specific error pattern, write a routing override to `.rune/metrics/routing-overrides.json`:
471
+ - Format: `{ "id": "r-<timestamp>", "condition": "<error pattern>", "action": "route to problem-solver before debug", "source": "auto", "active": true }`
472
+ - Max 10 active rules — if exceeded, remove oldest inactive rule
473
+ 7. Mark Phase 8 as `completed`
474
+
475
+ ## Autonomous Loop Patterns
476
+
477
+ When cook runs inside `team` (L1) or autonomous workflows, these patterns apply:
478
+
479
+ ### De-Sloppify Pass
480
+
481
+ After Phase 4 (IMPLEMENT), if the implementation touched 5+ files, run a focused cleanup pass:
482
+ 1. Re-read all modified files
483
+ 2. Check for: leftover debug statements, inconsistent naming, duplicated logic, missing error handling
484
+ 3. Fix issues found (this is still Phase 4 — not a new phase)
485
+ 4. This pass catches "almost right" code that slips through when focused on making tests pass
486
+
487
+ ### Continuous PR Loop (team orchestration only)
488
+
489
+ When `team` runs multiple cook instances in parallel:
490
+ ```
491
+ cook instance → commit → push → create PR → wait CI
492
+ IF CI passes → mark workstream complete
493
+ IF CI fails → read CI output → fix → push → wait CI (max 3 retries)
494
+ IF 3 retries fail → escalate to user with CI logs
495
+ ```
496
+
497
+ ### Exit Conditions (Mandatory for Autonomous Runs)
498
+
499
+ Every cook invocation inside `team` or autonomous workflows MUST have exit conditions:
500
+
501
+ ```
502
+ MAX_DEBUG_LOOPS: 3 per error area (already enforced)
503
+ MAX_QUALITY_LOOPS: 2 re-runs of Phase 5 (fix→recheck cycle)
504
+ MAX_REPLAN: 1 re-plan per cook session (Phase 4 re-plan check)
505
+ MAX_PIVOT: 1 approach pivot per cook session (Approach Pivot Gate)
506
+ TIMEOUT_SIGNAL: If context-watch reports ORANGE, wrap up current phase and checkpoint
507
+ ```
508
+
509
+ **Escalation chain**: debug-fix (3x) → re-plan (1x) → **approach pivot via brainstorm rescue (1x)** → THEN escalate to user. Never surrender before exhausting the pivot.
510
+
511
+ If any exit condition triggers without resolution → cook emits `BLOCKED` status with details and stops. Never spin indefinitely.
512
+
513
+ ## Error Recovery
514
+
515
+ | Phase | If this fails... | Do this... |
516
+ |-------|-----------------|------------|
517
+ | 1 UNDERSTAND | scout finds nothing relevant | Proceed with plan, note limited context |
518
+ | 2 PLAN | Task too complex | Break into smaller tasks, consider `rune:team` |
519
+ | 3 TEST | Can't write tests (no test framework) | Skip TDD, write tests after implementation |
520
+ | 4 IMPLEMENT | Fix hits repeated bugs | `rune:debug` (max 3 loops) → re-plan → if still blocked → **Approach Pivot Gate** → `rune:brainstorm(rescue)` |
521
+ | 5a PREFLIGHT | Logic issues found | Fix → re-run preflight |
522
+ | 5b SENTINEL | Security CRITICAL found | Fix immediately → re-run (mandatory) |
523
+ | 5c REVIEW | Code quality issues | Fix CRITICAL/HIGH → re-review (max 2 loops) |
524
+ | 6 VERIFY | Build/lint/type fails | Fix → re-run verification |
525
+
526
+ ## Called By (inbound)
527
+
528
+ - User: `/rune cook` direct invocation — primary entry point
529
+ - `team` (L1): parallel workstream execution (meta-orchestration)
530
+
531
+ ## Calls (outbound)
532
+
533
+ - `sentinel-env` (L3): Phase 0.5 — environment pre-flight (first run only)
534
+ - `scout` (L2): Phase 1 — scan codebase before planning
535
+ - `onboard` (L2): Phase 1 — if no CLAUDE.md exists, initialize project context first
536
+ - `plan` (L2): Phase 2 — create implementation plan
537
+ - `brainstorm` (L2): Phase 2 — trade-off analysis when multiple approaches exist
538
+ - `design` (L2): Phase 2 — UI/design phase when building frontend features
539
+ - `adversary` (L2): Phase 2.5 — red-team challenge on approved plan before implementation
540
+ - `test` (L2): Phase 3 — write failing tests (RED phase)
541
+ - `fix` (L2): Phase 4 — implement code changes (GREEN phase)
542
+ - `debug` (L2): Phase 4 — when implementation hits unexpected errors (max 3 loops)
543
+ - `db` (L2): Phase 4 — when schema changes are detected in the diff
544
+ - `preflight` (L2): Phase 5a — logic and completeness review
545
+ - `sentinel` (L2): Phase 5b — security scan
546
+ - `review` (L2): Phase 5c — code quality review
547
+ - `perf` (L2): Phase 5 — performance regression check before PR (optional)
548
+ - `completion-gate` (L3): Phase 5d — validate agent claims against evidence trail
549
+ - `constraint-check` (L3): Phase 5 — audit HARD-GATE compliance across workflow
550
+ - `verification` (L3): Phase 6 — automated checks (lint, types, tests, build)
551
+ - `hallucination-guard` (L3): Phase 6 — verify imports and API calls are real
552
+ - `journal` (L3): Phase 7 — record architectural decisions made during feature
553
+ - `session-bridge` (L3): Phase 8 — save context for future sessions
554
+ - `audit` (L2): Phase 5 — project health audit when scope warrants it
555
+ - `review-intake` (L2): Phase 5 — structured review intake for complex PRs
556
+ - `sast` (L3): Phase 5 — static analysis security testing
557
+ - `skill-forge` (L2): when new skill creation detected during cook flow
558
+ - `worktree` (L3): Phase 4 — worktree isolation for parallel implementation
559
+ - L4 extension packs: Phase 1.5 — domain-specific patterns when stack matches (see Phase 1.5 mapping table)
560
+
561
+ ## Constraints
562
+
563
+ 1. MUST run scout before planning — no plan based on assumptions alone
564
+ 2. MUST present plan to user and get approval before writing code
565
+ 3. MUST write failing tests before implementation (TDD) unless explicitly skipped by user
566
+ 4. MUST NOT commit with failing tests — fix or revert first
567
+ 5. MUST NOT modify files outside the approved plan scope without user confirmation
568
+ 6. MUST run verification (lint + type-check + tests + build) before commit — not optional
569
+ 7. MUST NOT say "all tests pass" without showing the actual test output
570
+ 8. MUST NOT contradict active decisions from `.rune/decisions.md` without explicit user override — if the plan conflicts with a prior decision, flag it and ask user before proceeding
571
+
572
+ ## Mesh Gates
573
+
574
+ | Gate | Requires | If Missing |
575
+ |------|----------|------------|
576
+ | Resume Gate | Phase 0 checks for existing master plan before starting | Proceed to Phase 1 if no plan exists |
577
+ | Scout Gate | scout output (files examined, patterns found) before Phase 2 | Invoke rune:scout first |
578
+ | Plan Gate | User-approved plan with file paths before Phase 3 | Cannot proceed to TEST |
579
+ | Adversary Gate | adversary verdict (PROCEED/HARDEN) before Phase 3 for features | Skip for bugfix/hotfix/refactor/fast-mode |
580
+ | Phase File Gate | Current phase file loaded (not full plan) for multi-session | Load only the active phase file |
581
+ | Test-First Gate | Failing tests exist before Phase 4 IMPLEMENT | Write tests first or get explicit skip from user |
582
+ | Quality Gate | preflight + sentinel + review passed before Phase 7 COMMIT | Fix findings, re-run |
583
+ | Verification Gate | lint + types + tests + build all green before commit | Fix failures, re-run |
584
+
585
+ ## Output Format
586
+
587
+ ```
588
+ ## Cook Report: [Task Name]
589
+ - **Status**: complete | partial | blocked
590
+ - **Phases**: [list of completed phases]
591
+ - **Files Changed**: [count] ([list])
592
+ - **Tests**: [passed]/[total] ([coverage]%)
593
+ - **Quality**: preflight [PASS/WARN] | sentinel [PASS/WARN] | review [PASS/WARN]
594
+ - **Commit**: [hash] — [message]
595
+
596
+ ### Decisions Made
597
+ - [decision]: [rationale]
598
+
599
+ ### Session State
600
+ - Saved to .rune/decisions.md
601
+ - Saved to .rune/progress.md
602
+ ```
603
+
604
+ ## Sharp Edges
605
+
606
+ Known failure modes for this skill. Check these before declaring done.
607
+
608
+ | Failure Mode | Severity | Mitigation |
609
+ |---|---|---|
610
+ | Skipping scout to "save time" on a simple task | CRITICAL | Scout Gate blocks this — Phase 1 is mandatory regardless of perceived simplicity |
611
+ | Writing code without user-approved plan | HIGH | Plan Gate: do NOT proceed to Phase 3 without explicit approval ("go", "proceed", "yes") |
612
+ | Claiming "all tests pass" without showing output | HIGH | Constraint 7 blocks this — show actual test runner output via completion-gate |
613
+ | Entering debug↔fix loop more than 3 times without escalating | MEDIUM | After 3 loops → re-plan → if still blocked → Approach Pivot Gate → brainstorm(rescue) |
614
+ | Surrendering "no solution" without triggering Approach Pivot Gate | CRITICAL | MUST invoke brainstorm(rescue) before telling user "can't be done" — pivot to different category first |
615
+ | Re-planning with the same approach category after it fundamentally failed | HIGH | Re-plan = revise steps within same approach. If CATEGORY is wrong → Approach Pivot Gate, not re-plan |
616
+ | Not escalating to sentinel:opus on security-sensitive tasks | MEDIUM | Auth, crypto, payment code → sentinel must run at opus, not sonnet |
617
+ | Running Phase 5 checks sequentially instead of parallel | MEDIUM | Launch preflight+sentinel+review as parallel Task agents for speed |
618
+ | Saying "done" without evidence trail | CRITICAL | completion-gate validates claims — UNCONFIRMED = BLOCK |
619
+ | Fast mode on security-relevant code | HIGH | Fast mode auto-excludes auth/crypto/payments — never fast-track security code |
620
+ | Loading all phase files at once into context | HIGH | Phase File Gate: load ONLY the active phase file — one phase per session |
621
+ | Resuming without checking master plan | MEDIUM | Phase 0 (RESUME CHECK) runs before Phase 1 — detects existing plans |
622
+
623
+ ## Done When
624
+
625
+ - All applicable phases complete per Phase Skip Rules (determined before starting)
626
+ - User has approved the plan (Phase 2 gate — explicit "go" received)
627
+ - All tests PASS — actual test runner output shown
628
+ - preflight + sentinel + review all PASS or findings addressed
629
+ - verification (lint + types + build) green
630
+ - Commit created with semantic message
631
+ - Cook Report emitted with commit hash and phase list
632
+ - Session state saved to .rune/ via session-bridge
633
+
634
+ ## Cost Profile
635
+
636
+ ~$0.05-0.15 per feature. Haiku for scanning (Phase 1), sonnet for coding (Phase 3-4), opus for complex planning (Phase 2 when needed).