Skip to content

Commit 17ed67f

Browse files
committed
Refactor pb-plan templates to enhance code simplification constraints and maintainability guidelines
- Updated SKILL.md to emphasize behavior preservation, readability priorities, and scoped cleanup. - Revised design_template.md to clarify maintainability rules and simplification opportunities. - Enhanced tasks_template.md with clearer rules for fuzzing, benchmarking, and behavior preservation. - Improved test coverage in test_templates.py to ensure adherence to new simplification and clarity standards.
1 parent 67df2ed commit 17ed67f

File tree

5 files changed

+149
-16
lines changed

5 files changed

+149
-16
lines changed

src/pb_spec/templates/prompts/pb-plan.prompt.md

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Run this when the user invokes `/pb-plan <requirement description>`. Do not ask
1111
- Ground every design claim in either existing code, explicit requirement text, or a clearly labeled assumption.
1212
- Do not invent files, modules, APIs, commands, or project conventions.
1313
- If the repo appears to be scaffold/template-derived and still exposes generic crate/package/module names, plan the rename work so the resulting spec uses project-matching identities instead of placeholders.
14+
- Plan implementation with a code-simplification lens: preserve existing behavior unless the requirement explicitly changes it, prefer explicit readable solutions over clever compact ones, and keep cleanup scoped to touched code unless broader refactoring is justified.
1415

1516
---
1617

@@ -22,6 +23,7 @@ Build a compact **requirements coverage checklist** from the input before writin
2223

2324
- Functional requirements (what must be built)
2425
- Constraints (tech stack, compatibility, performance, security, etc.)
26+
- Maintainability and simplification constraints (behavior-preserving refactors, readability requirements, cleanup scope)
2527
- Explicit non-goals or out-of-scope items
2628
- User-visible behaviors that should become Gherkin scenarios
2729

@@ -54,22 +56,30 @@ Count the words in the requirement description (excluding the `/pb-plan` trigger
5456
Gather context to inform the design. **Always perform live codebase analysis** — do not rely on any static file.
5557

5658
1. **Read `AGENTS.md`** (if it exists) — capture explicit project constraints, team rules, and gotchas. Do not assume any fixed section layout; treat it as free-form user-authored policy text.
57-
2. **Search the live codebase directly** — this is **mandatory** regardless of whether `AGENTS.md` exists:
59+
2. **Read `CLAUDE.md`** (if it exists) — capture additional coding standards or workflow rules. If `CLAUDE.md` delegates to another file, follow that reference rather than ignoring it.
60+
3. **Search the live codebase directly** — this is **mandatory** regardless of whether `AGENTS.md` exists:
5861
- Use grep / file search / semantic search to find modules, directories, and files affected by the requirement.
5962
- Search for keywords from the requirement across the codebase.
6063
- Read relevant source files to understand current implementation patterns.
6164
- Verify all referenced file paths and modules actually exist. If uncertain, mark as assumption instead of asserting.
6265
- Audit identity markers such as `pyproject.toml`, `package.json`, `Cargo.toml`, source roots, and published package names for scaffold placeholders. If generic crate/package/module names do not match the repository or product identity, treat renaming them as required planning scope unless the requirement explicitly preserves them.
6366
- Search for existing BDD assets and commands: `features/`, `*.feature`, `steps/`, `cucumber`, `@cucumber/cucumber`, `behave`, `bdd`, and test scripts in project config.
64-
3. **Check `specs/`** — see if related feature specs already exist.
65-
4. **Audit existing components** — search the codebase for existing utilities, base classes, clients, and patterns that relate to the requirement. Specifically look for:
67+
4. **Check `specs/`** — see if related feature specs already exist.
68+
5. **Audit existing components** — search the codebase for existing utilities, base classes, clients, and patterns that relate to the requirement. Specifically look for:
6669
- Helper/utility modules that overlap with the requirement
6770
- Existing abstractions (base classes, interfaces, protocols) to extend
6871
- Shared infrastructure (database connections, HTTP clients, cache layers)
6972
- Similar prior implementations that establish patterns to follow
7073
**This audit is mandatory.** List reusable components in `design.md` Section 3.3 and reference them in `tasks.md` task context.
7174

72-
5. **Determine the BDD/Test harness** — infer the primary language and recommended BDD runner:
75+
6. **Audit coding standards and simplification boundaries** — determine which style and maintainability rules the eventual implementation must follow:
76+
- Infer language- and framework-specific standards from `AGENTS.md`, `CLAUDE.md`, and the live codebase. Only apply standards that are relevant to the current repo; do not copy unrelated JavaScript or React rules into Python work.
77+
- Identify whether the requirement changes behavior or only restructures existing logic. Record the behavior-preservation boundary explicitly in the design.
78+
- Prefer plans that reduce unnecessary complexity, nesting, and redundant abstractions, improve naming, and consolidate related logic when that improves clarity.
79+
- Avoid planning dense one-liners, clever rewrites, or abstraction collapses that would make the code harder to debug or extend.
80+
- For languages where it applies, call out readability guardrails such as avoiding nested ternary operators in favor of clearer branching.
81+
82+
7. **Determine the BDD/Test harness** — infer the primary language and recommended BDD runner:
7383
- TypeScript/JavaScript → `@cucumber/cucumber`
7484
- Python → `behave`
7585
- Rust → `cucumber`
@@ -81,7 +91,7 @@ Gather context to inform the design. **Always perform live codebase analysis**
8191

8292
Prefer the repo's existing test and BDD commands if they already exist. Only propose new `features/` or step-definition locations when the repo has no established convention.
8393

84-
6. **Choose test depth by risk** — this is mandatory for both `design.md` and `tasks.md`:
94+
8. **Choose test depth by risk** — this is mandatory for both `design.md` and `tasks.md`:
8595
- Add **property tests** by default for broad input-domain logic such as transformations, normalization, parsers, serializers/deserializers, combinatorial business rules, state transitions, validation, and versioning logic. If property tests are omitted for such logic, explicitly justify why example-based coverage is sufficient.
8696
- Add **fuzz testing** only for parser/protocol implementations, binary formats, unsafe/native boundaries, crash-safety work, or untrusted-input robustness. Do not add fuzzing blindly to routine business logic.
8797
- Add **benchmarks** only when the requirement or codebase establishes explicit latency/throughput expectations, hot paths, or regression-sensitive performance behavior.
@@ -160,6 +170,14 @@ Write a **compact** design doc to `specs/<spec-dir>/design.md`:
160170
- **Feature Files:** `specs/<spec-dir>/features/*.feature`
161171
- **Outside-in Loop:** Which Gherkin scenarios fail first and then pass
162172

173+
## Code Simplification Constraints
174+
175+
- **Behavioral Contract:** Preserve existing behavior unless a listed scenario or requirement explicitly changes it.
176+
- **Repo Standards:** Use only the coding standards that are actually established by `AGENTS.md`, `CLAUDE.md`, and the existing codebase for this repo.
177+
- **Readability Priorities:** Prefer explicit control flow, clear names, reduced nesting, and removal of redundant abstractions when that improves maintainability.
178+
- **Refactor Scope:** Limit cleanup to touched modules unless the design explicitly justifies a broader refactor.
179+
- **Clarity Guardrails:** Avoid dense or clever rewrites; where relevant, avoid nested ternary operators in favor of clearer branching.
180+
163181
## BDD Scenario Inventory
164182

165183
- `features/[feature-name].feature`[Scenario Name]: [Business outcome]
@@ -180,6 +198,8 @@ Write a **compact** design doc to `specs/<spec-dir>/design.md`:
180198
Fill the **Design Template** below fully and write to `specs/<spec-dir>/design.md`. Every section must have substantive content — no "TBD" or empty placeholders.
181199
Remove all instructional placeholder text (such as bracket examples) in the final file.
182200

201+
The full design must explicitly document code simplification constraints: the behavior-preservation boundary, repo-specific coding standards to follow, readability priorities, and non-goals for unrelated cleanup.
202+
183203
## Step 5a: Output tasks.md — Lightweight Mode (< 50 words)
184204

185205
Write a **flat task list** to `specs/<spec-dir>/tasks.md`. Even in lightweight mode, task IDs must remain in `Task X.Y` format so `pb-build` can track state reliably:
@@ -201,6 +221,8 @@ Write a **flat task list** to `specs/<spec-dir>/tasks.md`. Even in lightweight m
201221
> **Scenario Coverage:** [Feature/scenario names]
202222
203223
- **Loop Type:** `BDD+TDD` / `TDD-only`
224+
- **Behavioral Contract:** `Preserve existing behavior` / `[Describe intentional behavior change]`
225+
- **Simplification Focus:** `[Reduce nesting / remove redundancy / improve naming / consolidate related logic / N/A]`
204226
- **Status:** 🔴 TODO
205227
- [ ] Step 1: ...
206228
- [ ] Step 2: ...
@@ -230,11 +252,13 @@ Remove all instructional placeholder text (such as bracket examples) in the fina
230252
- **Task ID format:** Each task MUST have a unique ID: `Task X.Y` (e.g., `Task 1.1`, `Task 2.3`).
231253
- Ordered by dependency — no task references work from a later task.
232254
- Every task has a concrete **Verification** criterion.
255+
- Each task must state its **Behavioral Contract** (`Preserve existing behavior` or the intentional user-visible change) and its **Simplification Focus** so the implementation stays readable and scoped.
233256
- Tasks that implement user-visible behavior should use `Loop Type: BDD+TDD` and point to one or more scenarios in `Scenario Coverage`. Pure infrastructure tasks may use `Loop Type: TDD-only`.
234257
- If the repo does not already have a BDD harness, include explicit setup work for the chosen runner and step-definition location.
235258
- If a task touches broad input-domain logic, append dedicated property-test work using the repo-appropriate tool (`Hypothesis`, `fast-check`, or `proptest`) unless you explicitly justify why it is unnecessary.
236259
- If a task touches parsers, protocol implementations, binary formats, unsafe/native boundaries, or other crash-sensitive untrusted-input paths, append conditional fuzz-test work using `Atheris`, `jazzer.js`, or `cargo-fuzz`.
237260
- If a task has explicit performance goals or hot-path risk, append conditional benchmark work using `pytest-benchmark`, `Vitest Bench`, or `criterion`.
261+
- Refactor and cleanup work must stay scoped to touched modules unless the design explicitly broadens scope. Do not plan clever compaction, nested ternaries, or abstraction removal that would reduce maintainability.
238262
- For tasks that introduce or change runtime behavior (service startup, UI runtime flow, API/network availability, performance-sensitive code paths), **Verification must include runtime observability checks**:
239263
- Recent runtime logs (for example `tail -n 50 app.log` or equivalent).
240264
- A live health/probe command (for example `curl http://localhost:8080/health` or equivalent).
@@ -290,9 +314,11 @@ Please review the design and tasks. When ready, run /pb-build <feature-name> to
290314
10. **Project-aware.** Use existing conventions, patterns, and tech stack. Reuse existing components — do not reinvent.
291315
11. **Identity-aware.** Template placeholder crate/package/module names should be normalized to project-matching names when the repo has not been fully customized yet.
292316
12. **Risk-based test depth.** Example-based tests are the baseline; property tests are the default extension for broad input domains, while fuzzing and benchmarks remain conditional.
293-
13. **Requirements coverage.** Track every requirement from input to design sections, feature scenarios, and tasks.
294-
14. **Truthfulness over fluency.** If information is missing, state assumptions explicitly instead of fabricating specifics.
295-
15. **Deterministic output quality.** Final docs should be implementation-ready, with no template artifacts left behind.
317+
13. **Readable over clever.** Prefer plans that lead to explicit, easy-to-maintain implementations over compact or overly clever rewrites.
318+
14. **Scoped simplification.** Refactors should improve touched code without turning the plan into unrelated cleanup.
319+
15. **Requirements coverage.** Track every requirement from input to design sections, feature scenarios, and tasks.
320+
16. **Truthfulness over fluency.** If information is missing, state assumptions explicitly instead of fabricating specifics.
321+
17. **Deterministic output quality.** Final docs should be implementation-ready, with no template artifacts left behind.
296322

297323
---
298324

@@ -558,6 +584,9 @@ Please review the design and tasks. When ready, run /pb-build <feature-name> to
558584
- **Fuzzing Rule:** Add `Atheris`, `jazzer.js`, or `cargo-fuzz` only for parsers, protocols, unsafe/native boundaries, binary formats, or other untrusted-input crash-safety work.
559585
- **Benchmark Rule:** Add `pytest-benchmark`, `Vitest Bench`, or `criterion` only when the requirement or codebase defines performance-sensitive behavior.
560586
- **Identity Alignment Rule:** If the repo still contains generic crate/package/module names from a template, front-load rename work before dependent implementation tasks.
587+
- **Behavior Preservation Rule:** State whether each task preserves existing behavior or intentionally changes it; validate that with scenario and regression coverage.
588+
- **Simplification Rule:** Prefer explicit, readable implementation steps that reduce unnecessary nesting, redundancy, or naming ambiguity without broadening scope.
589+
- **Clarity Guardrail:** Avoid planning dense or clever rewrites; where relevant, avoid nested ternary operators in favor of clearer branching.
561590

562591
- **Phase 1: Foundation & Scaffolding** — Setup, config, types
563592
- **Phase 2: Core Logic** — Primary implementation
@@ -577,6 +606,8 @@ Please review the design and tasks. When ready, run /pb-build <feature-name> to
577606
- **Scope:** [Logical Unit of Work — e.g., "Model layer", "API endpoint", "Service integration"]
578607
- **Scenario Coverage:** `[Feature/scenario names, or N/A]`
579608
- **Loop Type:** `BDD+TDD` / `TDD-only`
609+
- **Behavioral Contract:** `Preserve existing behavior` / `[Describe intentional behavior change]`
610+
- **Simplification Focus:** `[Reduce nesting / remove redundancy / improve naming / consolidate related logic / N/A]`
580611
- **Advanced Test Coverage:** `Example-based only` / `Property` / `Fuzz` / `Benchmark` / `Combination`
581612
- **Status:** 🔴 TODO
582613

@@ -600,6 +631,8 @@ Please review the design and tasks. When ready, run /pb-build <feature-name> to
600631
- **Scope:** [Logical Unit of Work]
601632
- **Scenario Coverage:** `[Feature/scenario names, or N/A]`
602633
- **Loop Type:** `BDD+TDD` / `TDD-only`
634+
- **Behavioral Contract:** `Preserve existing behavior` / `[Describe intentional behavior change]`
635+
- **Simplification Focus:** `[Reduce nesting / remove redundancy / improve naming / consolidate related logic / N/A]`
603636
- **Advanced Test Coverage:** `Example-based only` / `Property` / `Fuzz` / `Benchmark` / `Combination`
604637
- **Status:** 🔴 TODO
605638

@@ -623,6 +656,8 @@ Please review the design and tasks. When ready, run /pb-build <feature-name> to
623656
- **Scope:** [Logical Unit of Work]
624657
- **Scenario Coverage:** `[Feature/scenario names, or N/A]`
625658
- **Loop Type:** `BDD+TDD` / `TDD-only`
659+
- **Behavioral Contract:** `Preserve existing behavior` / `[Describe intentional behavior change]`
660+
- **Simplification Focus:** `[Reduce nesting / remove redundancy / improve naming / consolidate related logic / N/A]`
626661
- **Advanced Test Coverage:** `Example-based only` / `Property` / `Fuzz` / `Benchmark` / `Combination`
627662
- **Status:** 🔴 TODO
628663

@@ -646,6 +681,8 @@ Please review the design and tasks. When ready, run /pb-build <feature-name> to
646681
- **Scope:** [Logical Unit of Work]
647682
- **Scenario Coverage:** `[Feature/scenario names, or N/A]`
648683
- **Loop Type:** `BDD+TDD` / `TDD-only`
684+
- **Behavioral Contract:** `Preserve existing behavior` / `[Describe intentional behavior change]`
685+
- **Simplification Focus:** `[Reduce nesting / remove redundancy / improve naming / consolidate related logic / N/A]`
649686
- **Advanced Test Coverage:** `Example-based only` / `Property` / `Fuzz` / `Benchmark` / `Combination`
650687
- **Status:** 🔴 TODO
651688

@@ -676,4 +713,6 @@ Please review the design and tasks. When ready, run /pb-build <feature-name> to
676713
4. [ ] **Verified:** Task's specific Verification criterion met.
677714
5. [ ] **Advanced-Tested (when applicable):** Property/fuzz/benchmark verification captured, or `N/A` is explicitly justified.
678715
6. [ ] **Runtime-Evidenced (when applicable):** Runtime logs and health/probe results are captured, or `N/A` is explicitly justified.
716+
7. [ ] **Behavior-Preserved or Documented:** The task confirms behavior preservation or documents the intentional behavior change.
717+
8. [ ] **Simplified Responsibly:** Cleanup stayed within the planned scope and improved readability rather than introducing clever compaction.
679718
```

0 commit comments

Comments
 (0)