You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor architecture decision processes across templates
- Updated `pb-build` templates to enforce architecture decision adherence, ensuring that all tasks and subagents follow the approved design patterns and principles.
- Enhanced `pb-init` templates to capture architecture decision snapshots, including established patterns and dependency injection boundaries.
- Revised `pb-plan` templates to require explicit architecture decisions before implementation, emphasizing the importance of SRP, DIP, and other architectural principles.
- Improved documentation in `design_template.md` and `tasks_template.md` to clarify architecture decision requirements and project identity alignment.
- Added tests to verify that templates enforce architecture decision rules and capture necessary context for implementers.
- Bumped version to 0.8.0 to reflect these changes.
Copy file name to clipboardExpand all lines: README.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,6 +34,7 @@ pb-spec follows a **harness-first** philosophy: reliability comes from process d
34
34
-**Behavior Before Code:**`/pb-plan` turns user-visible requirements into Gherkin `.feature` scenarios before implementation begins.
35
35
-**Verification by Design:** Planning requires explicit verification commands so completion is measurable.
36
36
-**Observability as Context:** Service-facing tasks must capture runtime evidence (log tails and/or health probes), not only test output.
37
+
-**Architecture Before Implementation:**`/pb-init` snapshots established architecture decisions, `/pb-plan` records explicit `Architecture Decisions`, and `/pb-build` executes against that contract instead of inventing a new one.
37
38
-**Double-Loop Execution:**`/pb-build` enforces a BDD outer loop plus a TDD inner loop with per-task status tracking.
38
39
-**Escalation Over Thrashing:** Three consecutive failures suspend the current task and route a standardized DCR packet to `/pb-refine`.
39
40
-**Safe Failure Recovery:** Failed attempts use scoped recovery guidance to avoid polluting unrelated workspace state.
@@ -131,6 +132,8 @@ Merge behavior is non-destructive:
131
132
132
133
This design avoids relying on any fixed `AGENTS.md` section layout and protects user-maintained constraints across re-runs.
133
134
135
+
The managed snapshot now also includes an **Architecture Decision Snapshot** so later agents inherit repo-level conventions instead of re-deciding them every run. Typical entries include established patterns, dependency-injection boundaries, error-handling conventions, and workflow/state-modeling rules.
Takes a natural-language requirement and produces a complete feature spec:
@@ -153,6 +156,8 @@ It also performs two additional planning audits before implementation starts:
153
156
- Template identity alignment: if the repo still contains generic crate/package/module names from a scaffold, `pb-plan` must front-load renaming those identifiers to project-matching names.
154
157
- Risk-based advanced testing: property testing is planned by default for broad input-domain logic, while fuzzing and benchmarks are added only when the feature profile justifies them. Tool selection follows repo language conventions: `Hypothesis` / `fast-check` / `proptest`, `Atheris` / `jazzer.js` / `cargo-fuzz`, and `pytest-benchmark` / `Vitest Bench` / `criterion`.
155
158
159
+
It also adds an explicit **Architecture Decisions** section to `design.md`. For work that introduces a new boundary or is likely to exceed 200 lines, planning must evaluate **SRP**, **DIP**, and the classic patterns **Factory**, **Strategy**, **Observer**, **Adapter**, and **Decorator**. The chosen pattern must be justified against alternatives and checked against the code-simplification lens so the design stays simpler, not just more abstract.
Reads user feedback or Design Change Requests (from failed builds, including standardized 3-failure build-block packets) and intelligently updates `design.md` and `tasks.md`. It maintains a revision history and cascades design changes to the task list without overwriting completed work. `AGENTS.md` remains read-only in this phase.
@@ -161,6 +166,8 @@ Reads user feedback or Design Change Requests (from failed builds, including sta
161
166
162
167
Reads `specs/<YYYY-MM-DD-NO-feature-name>/tasks.md` and implements each task sequentially. Every `BDD+TDD` task is executed by a fresh subagent following an outside-in double loop: run the Gherkin scenario first so the BDD outer loop is red, drive the implementation with TDD (Red → Green → Refactor) in the inner loop, then re-run the scenario until it passes. Runtime verification (log/health evidence when applicable) still applies. Supports **Design Change Requests** if the planned design proves infeasible during implementation, and auto-escalates to DCR after three consecutive task failures. Only the `<feature-name>` part is needed when invoking — the agent resolves the full directory automatically. `AGENTS.md` is read-only unless the user explicitly requests an `AGENTS.md` change.
163
168
169
+
`/pb-build` is now explicitly architecture-bound: it reads the repo's **Architecture Decision Snapshot**, follows the feature's **Architecture Decisions**, re-checks **SRP** and **DIP** during execution, and keeps external dependencies behind interfaces or abstract classes when the design requires that seam. It should not improvise a different Factory, Strategy, Observer, Adapter, or Decorator choice mid-build.
170
+
164
171
## Skills Overview
165
172
166
173
| Skill | Trigger | Output | Description |
@@ -179,6 +186,7 @@ pb-spec's prompt design is inspired by Anthropic's research on [Effective Harnes
179
186
| Principle | How pb-spec Implements It |
180
187
|---|---|
181
188
|**State Grounding**| Subagents must verify workspace state (`ls`, `find`, `read_file`) before writing any code — preventing path hallucination |
189
+
|**Architecture Continuity**|`pb-init` records an Architecture Decision Snapshot, `pb-plan` makes Architecture Decisions explicit, and `pb-build` verifies implementation still conforms to that contract |
182
190
|**Error Quoting**| Subagents must quote specific error messages before attempting fixes — preventing blind debugging |
183
191
|**Context Hygiene**| Orchestrator passes only minimal, relevant context to each subagent — preventing context window pollution |
184
192
|**Recovery Loop**| Failed tasks use pre-task snapshots + file-scoped recovery (`git restore` + task-local cleanup), and avoid workspace-wide restore in dirty trees |
Copy file name to clipboardExpand all lines: src/pb_spec/templates/prompts/pb-build.prompt.md
+15-3Lines changed: 15 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@ Run this when the user invokes `/pb-build <feature-name>`.
9
9
- Complete unfinished tasks in `tasks.md` sequentially until done or explicitly blocked.
10
10
- Use one fresh subagent per task with minimal, task-relevant context only.
11
11
- Mark a task as done only after `BDD Verification` passes for `BDD+TDD` tasks, tests pass, task verification passes, and runtime evidence is captured when applicable.
12
+
- Treat `design.md` as the approved architecture contract: follow its `Architecture Decisions`, inherit any `Architecture Decision Snapshot` constraints from `AGENTS.md`, and do not improvise a new pattern mid-build.
12
13
- If blocked, fail clearly with exact task ID, failed command, and concrete next options (retry/skip/abort within budget, then DCR escalation).
13
14
14
15
---
@@ -63,15 +64,18 @@ For each unfinished task, in order:
63
64
1.**Extract** the full task block (Context, Scenario Coverage, Loop Type, Steps, BDD Verification, Verification).
64
65
2.**Gather context** — read `design.md` and `AGENTS.md` (if it exists). Treat `AGENTS.md` as read-only policy context.
65
66
- Read any referenced `.feature` files under `specs/<spec-dir>/features/`.
67
+
- Extract the relevant `Architecture Decisions` from `design.md` and any `Architecture Decision Snapshot` constraints from `AGENTS.md` that apply to this task.
66
68
- Record a pre-task workspace snapshot (`git status --porcelain` + tracked/untracked file lists) for safe rollback.
67
69
3.**Spawn a fresh subagent** with the Implementer Prompt (below), filled in with the task content and project context.
68
70
**Context Hygiene:** Do NOT pass the entire chat history. Pass ONLY:
69
71
- The specific Task Description from `tasks.md`.
70
72
- The `AGENTS.md` (project constraints and hard rules; do not assume any fixed template layout).
71
73
- The `design.md` (Feature Spec).
72
74
- The relevant `.feature` file content and scenario name when `Loop Type` is `BDD+TDD`.
75
+
- The task-relevant `Architecture Decisions` and `Architecture Decision Snapshot` excerpts, including any SRP, DIP, Factory, Strategy, Observer, Adapter, or Decorator choice and any requirement to route external dependencies through interfaces or abstract classes.
73
76
-**Summary of previous tasks** — a one-line-per-task summary (e.g., "Task 1.1 created `models.py` with `User` class."). Do NOT pass raw logs or full outputs.
74
77
4.**Subagent executes** the BDD + TDD + runtime verification cycle (see Implementer Prompt section).
78
+
- The subagent must restate the architecture contract before coding and verify it still conforms after implementation.
75
79
5.**Mark completed** — update `- [ ]` to `- [x]` and Status to `🟢 DONE` in `tasks.md`.
76
80
-**Use precise editing:** Use `sed`, string-replacement, or line-targeted edits to update the specific Task ID heading and its checkboxes. Do NOT rewrite the entire `tasks.md` file — this risks truncation and content loss in large files.
77
81
-**Completion gate:** Mark done only when `BDD Verification` is satisfied for `BDD+TDD` tasks, task Verification is satisfied, tests are green, and runtime checks (when applicable) are evidence-backed.
@@ -177,10 +181,10 @@ Summary must be factual and command-backed: do not claim "passed" or "completed"
177
181
## Subagent Rules
178
182
179
183
1.**One subagent per task.** Never combine tasks.
180
-
2.**Fresh context per subagent.** Only: task description, non-obvious constraints (AGENTS.md) + design (design.md), summary of completed tasks, files on disk.
184
+
2.**Fresh context per subagent.** Only: task description, non-obvious constraints (AGENTS.md) + design (design.md), relevant `Architecture Decisions`, summary of completed tasks, files on disk.
181
185
3.**Sequential execution.** Strict `tasks.md` order. No parallelism.
182
186
4.**Independence.** Cross-task state lives in files, not memory.
183
-
5.**Grounding first.** Every subagent verifies workspace state before writing code.
187
+
5.**Grounding first.** Every subagent verifies workspace state before writing code and restates the architecture contract it must preserve.
184
188
6.**Verifiable closure.** A task closes only after explicit verification evidence.
185
189
186
190
---
@@ -252,6 +256,7 @@ Update `tasks.md` in-place after each task using **precise edits** (target the s
|**REFACTOR**| Clean up if needed | ALL tests still pass |
320
+
|**ARCHITECTURE CHECK**| Confirm the implementation still follows the selected `Architecture Decisions`, preserves SRP and DIP, and keeps external dependencies behind interfaces or abstract classes when required. | Architecture contract preserved |
312
321
|**SCOPE CHECK**| Confirm implemented changes match task contract and nothing extra. | Task scope respected |
313
322
314
323
**3. Self-Review Checklist**
@@ -319,6 +328,7 @@ Before writing any code, verify the current workspace state:
319
328
-[ ] Test coverage — tests meaningfully verify requirements
320
329
-[ ] No regressions — all pre-existing tests pass
321
330
-[ ] BDD coverage — for `BDD+TDD` tasks, the referenced scenario failed first and then passed
331
+
-[ ] Architecture conformance — the change still matches the selected `Architecture Decisions` and does not introduce a conflicting pattern
@@ -358,6 +368,8 @@ Fix any "no" answers before submitting.
358
368
- Only implement the current task.
359
369
- Follow YAGNI — no speculative features.
360
370
- Use existing patterns — match project style.
371
+
- Follow approved architecture decisions — respect the task's `Architecture Decisions` and the repo's `Architecture Decision Snapshot`; do not improvise a different pattern mid-build.
372
+
- do not improvise a new pattern mid-build. If the planned architecture no longer fits, raise a Design Change Request instead of silently switching patterns.
361
373
- Do not modify `design.md` or `tasks.md`.
362
374
- Do not modify, delete, or reformat `AGENTS.md` unless the user explicitly requests an `AGENTS.md` change.
Search the project for explicit architecture decisions that later agents must inherit instead of reinventing:
68
+
69
+
1. Read `AGENTS.md`, `CLAUDE.md`, `README.md`, `docs/`, active `specs/`, and nearby source modules for stated or strongly evidenced conventions.
70
+
2. Record only decisions grounded in explicit evidence. **Only record decisions grounded in explicit evidence** — do not speculate from vague naming alone.
71
+
3. Capture the current project position for:
72
+
-**Established Patterns** — e.g. Strategy, Adapter, typestate, repository, command objects
73
+
-**Dependency Injection Boundaries** — how external services, SDKs, clients, or storage are abstracted and injected
-**State and Workflow Modeling** — how state transitions, orchestration, and long-running flows are represented
76
+
-**External Dependency Access** — whether network, filesystem, DB, or platform calls must go through interfaces, protocols, base classes, or wrapper services
77
+
-**Known Exceptions / TODOs** — temporary deviations or pending cleanups already documented in the repo
78
+
4. If the repo does not expose explicit architecture decisions yet, write `No explicit architecture decisions detected.` instead of inventing guidance.
79
+
80
+
## Step 5: Detect Active Specs
66
81
67
82
Check if a `specs/` directory exists. If so, list each subdirectory as an active feature spec. For each spec, perform **dynamic status detection**:
0 commit comments