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 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.
Copy file name to clipboardExpand all lines: src/pb_spec/templates/prompts/pb-plan.prompt.md
+47-8Lines changed: 47 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,7 @@ Run this when the user invokes `/pb-plan <requirement description>`. Do not ask
11
11
- Ground every design claim in either existing code, explicit requirement text, or a clearly labeled assumption.
12
12
- Do not invent files, modules, APIs, commands, or project conventions.
13
13
- 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.
14
15
15
16
---
16
17
@@ -22,6 +23,7 @@ Build a compact **requirements coverage checklist** from the input before writin
- User-visible behaviors that should become Gherkin scenarios
27
29
@@ -54,22 +56,30 @@ Count the words in the requirement description (excluding the `/pb-plan` trigger
54
56
Gather context to inform the design. **Always perform live codebase analysis** — do not rely on any static file.
55
57
56
58
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:
58
61
- Use grep / file search / semantic search to find modules, directories, and files affected by the requirement.
59
62
- Search for keywords from the requirement across the codebase.
60
63
- Read relevant source files to understand current implementation patterns.
61
64
- Verify all referenced file paths and modules actually exist. If uncertain, mark as assumption instead of asserting.
62
65
- 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.
63
66
- 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:
66
69
- Helper/utility modules that overlap with the requirement
67
70
- Existing abstractions (base classes, interfaces, protocols) to extend
- Similar prior implementations that establish patterns to follow
70
73
**This audit is mandatory.** List reusable components in `design.md` Section 3.3 and reference them in `tasks.md` task context.
71
74
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:
73
83
- TypeScript/JavaScript → `@cucumber/cucumber`
74
84
- Python → `behave`
75
85
- Rust → `cucumber`
@@ -81,7 +91,7 @@ Gather context to inform the design. **Always perform live codebase analysis**
81
91
82
92
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.
83
93
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`:
85
95
- 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.
86
96
- 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.
87
97
- 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`:
-**Outside-in Loop:** Which Gherkin scenarios fail first and then pass
162
172
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,6 +198,8 @@ Write a **compact** design doc to `specs/<spec-dir>/design.md`:
180
198
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.
181
199
Remove all instructional placeholder text (such as bracket examples) in the final file.
182
200
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.
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
@@ -230,11 +252,13 @@ Remove all instructional placeholder text (such as bracket examples) in the fina
230
252
-**Task ID format:** Each task MUST have a unique ID: `Task X.Y` (e.g., `Task 1.1`, `Task 2.3`).
231
253
- Ordered by dependency — no task references work from a later task.
232
254
- 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.
233
256
- 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`.
234
257
- If the repo does not already have a BDD harness, include explicit setup work for the chosen runner and step-definition location.
235
258
- 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.
236
259
- 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`.
237
260
- 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.
238
262
- 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**:
239
263
- Recent runtime logs (for example `tail -n 50 app.log` or equivalent).
240
264
- 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
290
314
10.**Project-aware.** Use existing conventions, patterns, and tech stack. Reuse existing components — do not reinvent.
291
315
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.
292
316
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.
296
322
297
323
---
298
324
@@ -558,6 +584,9 @@ Please review the design and tasks. When ready, run /pb-build <feature-name> to
558
584
-**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.
559
585
-**Benchmark Rule:** Add `pytest-benchmark`, `Vitest Bench`, or `criterion` only when the requirement or codebase defines performance-sensitive behavior.
560
586
-**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.
561
590
562
591
-**Phase 1: Foundation & Scaffolding** — Setup, config, types
563
592
-**Phase 2: Core Logic** — Primary implementation
@@ -577,6 +606,8 @@ Please review the design and tasks. When ready, run /pb-build <feature-name> to
577
606
-**Scope:**[Logical Unit of Work — e.g., "Model layer", "API endpoint", "Service integration"]
578
607
-**Scenario Coverage:**`[Feature/scenario names, or N/A]`
0 commit comments