pdd-cli 0.0.45__py3-none-any.whl → 0.0.118__py3-none-any.whl

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 (195) hide show
  1. pdd/__init__.py +40 -8
  2. pdd/agentic_bug.py +323 -0
  3. pdd/agentic_bug_orchestrator.py +497 -0
  4. pdd/agentic_change.py +231 -0
  5. pdd/agentic_change_orchestrator.py +526 -0
  6. pdd/agentic_common.py +598 -0
  7. pdd/agentic_crash.py +534 -0
  8. pdd/agentic_e2e_fix.py +319 -0
  9. pdd/agentic_e2e_fix_orchestrator.py +426 -0
  10. pdd/agentic_fix.py +1294 -0
  11. pdd/agentic_langtest.py +162 -0
  12. pdd/agentic_update.py +387 -0
  13. pdd/agentic_verify.py +183 -0
  14. pdd/architecture_sync.py +565 -0
  15. pdd/auth_service.py +210 -0
  16. pdd/auto_deps_main.py +71 -51
  17. pdd/auto_include.py +245 -5
  18. pdd/auto_update.py +125 -47
  19. pdd/bug_main.py +196 -23
  20. pdd/bug_to_unit_test.py +2 -0
  21. pdd/change_main.py +11 -4
  22. pdd/cli.py +22 -1181
  23. pdd/cmd_test_main.py +350 -150
  24. pdd/code_generator.py +60 -18
  25. pdd/code_generator_main.py +790 -57
  26. pdd/commands/__init__.py +48 -0
  27. pdd/commands/analysis.py +306 -0
  28. pdd/commands/auth.py +309 -0
  29. pdd/commands/connect.py +290 -0
  30. pdd/commands/fix.py +163 -0
  31. pdd/commands/generate.py +257 -0
  32. pdd/commands/maintenance.py +175 -0
  33. pdd/commands/misc.py +87 -0
  34. pdd/commands/modify.py +256 -0
  35. pdd/commands/report.py +144 -0
  36. pdd/commands/sessions.py +284 -0
  37. pdd/commands/templates.py +215 -0
  38. pdd/commands/utility.py +110 -0
  39. pdd/config_resolution.py +58 -0
  40. pdd/conflicts_main.py +8 -3
  41. pdd/construct_paths.py +589 -111
  42. pdd/context_generator.py +10 -2
  43. pdd/context_generator_main.py +175 -76
  44. pdd/continue_generation.py +53 -10
  45. pdd/core/__init__.py +33 -0
  46. pdd/core/cli.py +527 -0
  47. pdd/core/cloud.py +237 -0
  48. pdd/core/dump.py +554 -0
  49. pdd/core/errors.py +67 -0
  50. pdd/core/remote_session.py +61 -0
  51. pdd/core/utils.py +90 -0
  52. pdd/crash_main.py +262 -33
  53. pdd/data/language_format.csv +71 -63
  54. pdd/data/llm_model.csv +20 -18
  55. pdd/detect_change_main.py +5 -4
  56. pdd/docs/prompting_guide.md +864 -0
  57. pdd/docs/whitepaper_with_benchmarks/data_and_functions/benchmark_analysis.py +495 -0
  58. pdd/docs/whitepaper_with_benchmarks/data_and_functions/creation_compare.py +528 -0
  59. pdd/fix_code_loop.py +523 -95
  60. pdd/fix_code_module_errors.py +6 -2
  61. pdd/fix_error_loop.py +491 -92
  62. pdd/fix_errors_from_unit_tests.py +4 -3
  63. pdd/fix_main.py +278 -21
  64. pdd/fix_verification_errors.py +12 -100
  65. pdd/fix_verification_errors_loop.py +529 -286
  66. pdd/fix_verification_main.py +294 -89
  67. pdd/frontend/dist/assets/index-B5DZHykP.css +1 -0
  68. pdd/frontend/dist/assets/index-DQ3wkeQ2.js +449 -0
  69. pdd/frontend/dist/index.html +376 -0
  70. pdd/frontend/dist/logo.svg +33 -0
  71. pdd/generate_output_paths.py +139 -15
  72. pdd/generate_test.py +218 -146
  73. pdd/get_comment.py +19 -44
  74. pdd/get_extension.py +8 -9
  75. pdd/get_jwt_token.py +318 -22
  76. pdd/get_language.py +8 -7
  77. pdd/get_run_command.py +75 -0
  78. pdd/get_test_command.py +68 -0
  79. pdd/git_update.py +70 -19
  80. pdd/incremental_code_generator.py +2 -2
  81. pdd/insert_includes.py +13 -4
  82. pdd/llm_invoke.py +1711 -181
  83. pdd/load_prompt_template.py +19 -12
  84. pdd/path_resolution.py +140 -0
  85. pdd/pdd_completion.fish +25 -2
  86. pdd/pdd_completion.sh +30 -4
  87. pdd/pdd_completion.zsh +79 -4
  88. pdd/postprocess.py +14 -4
  89. pdd/preprocess.py +293 -24
  90. pdd/preprocess_main.py +41 -6
  91. pdd/prompts/agentic_bug_step10_pr_LLM.prompt +182 -0
  92. pdd/prompts/agentic_bug_step1_duplicate_LLM.prompt +73 -0
  93. pdd/prompts/agentic_bug_step2_docs_LLM.prompt +129 -0
  94. pdd/prompts/agentic_bug_step3_triage_LLM.prompt +95 -0
  95. pdd/prompts/agentic_bug_step4_reproduce_LLM.prompt +97 -0
  96. pdd/prompts/agentic_bug_step5_root_cause_LLM.prompt +123 -0
  97. pdd/prompts/agentic_bug_step6_test_plan_LLM.prompt +107 -0
  98. pdd/prompts/agentic_bug_step7_generate_LLM.prompt +172 -0
  99. pdd/prompts/agentic_bug_step8_verify_LLM.prompt +119 -0
  100. pdd/prompts/agentic_bug_step9_e2e_test_LLM.prompt +289 -0
  101. pdd/prompts/agentic_change_step10_identify_issues_LLM.prompt +1006 -0
  102. pdd/prompts/agentic_change_step11_fix_issues_LLM.prompt +984 -0
  103. pdd/prompts/agentic_change_step12_create_pr_LLM.prompt +131 -0
  104. pdd/prompts/agentic_change_step1_duplicate_LLM.prompt +73 -0
  105. pdd/prompts/agentic_change_step2_docs_LLM.prompt +101 -0
  106. pdd/prompts/agentic_change_step3_research_LLM.prompt +126 -0
  107. pdd/prompts/agentic_change_step4_clarify_LLM.prompt +164 -0
  108. pdd/prompts/agentic_change_step5_docs_change_LLM.prompt +981 -0
  109. pdd/prompts/agentic_change_step6_devunits_LLM.prompt +1005 -0
  110. pdd/prompts/agentic_change_step7_architecture_LLM.prompt +1044 -0
  111. pdd/prompts/agentic_change_step8_analyze_LLM.prompt +1027 -0
  112. pdd/prompts/agentic_change_step9_implement_LLM.prompt +1077 -0
  113. pdd/prompts/agentic_crash_explore_LLM.prompt +49 -0
  114. pdd/prompts/agentic_e2e_fix_step1_unit_tests_LLM.prompt +90 -0
  115. pdd/prompts/agentic_e2e_fix_step2_e2e_tests_LLM.prompt +91 -0
  116. pdd/prompts/agentic_e2e_fix_step3_root_cause_LLM.prompt +89 -0
  117. pdd/prompts/agentic_e2e_fix_step4_fix_e2e_tests_LLM.prompt +96 -0
  118. pdd/prompts/agentic_e2e_fix_step5_identify_devunits_LLM.prompt +91 -0
  119. pdd/prompts/agentic_e2e_fix_step6_create_unit_tests_LLM.prompt +106 -0
  120. pdd/prompts/agentic_e2e_fix_step7_verify_tests_LLM.prompt +116 -0
  121. pdd/prompts/agentic_e2e_fix_step8_run_pdd_fix_LLM.prompt +120 -0
  122. pdd/prompts/agentic_e2e_fix_step9_verify_all_LLM.prompt +146 -0
  123. pdd/prompts/agentic_fix_explore_LLM.prompt +45 -0
  124. pdd/prompts/agentic_fix_harvest_only_LLM.prompt +48 -0
  125. pdd/prompts/agentic_fix_primary_LLM.prompt +85 -0
  126. pdd/prompts/agentic_update_LLM.prompt +925 -0
  127. pdd/prompts/agentic_verify_explore_LLM.prompt +45 -0
  128. pdd/prompts/auto_include_LLM.prompt +122 -905
  129. pdd/prompts/change_LLM.prompt +3093 -1
  130. pdd/prompts/detect_change_LLM.prompt +686 -27
  131. pdd/prompts/example_generator_LLM.prompt +22 -1
  132. pdd/prompts/extract_code_LLM.prompt +5 -1
  133. pdd/prompts/extract_program_code_fix_LLM.prompt +7 -1
  134. pdd/prompts/extract_prompt_update_LLM.prompt +7 -8
  135. pdd/prompts/extract_promptline_LLM.prompt +17 -11
  136. pdd/prompts/find_verification_errors_LLM.prompt +6 -0
  137. pdd/prompts/fix_code_module_errors_LLM.prompt +12 -2
  138. pdd/prompts/fix_errors_from_unit_tests_LLM.prompt +9 -0
  139. pdd/prompts/fix_verification_errors_LLM.prompt +22 -0
  140. pdd/prompts/generate_test_LLM.prompt +41 -7
  141. pdd/prompts/generate_test_from_example_LLM.prompt +115 -0
  142. pdd/prompts/increase_tests_LLM.prompt +1 -5
  143. pdd/prompts/insert_includes_LLM.prompt +316 -186
  144. pdd/prompts/prompt_code_diff_LLM.prompt +119 -0
  145. pdd/prompts/prompt_diff_LLM.prompt +82 -0
  146. pdd/prompts/trace_LLM.prompt +25 -22
  147. pdd/prompts/unfinished_prompt_LLM.prompt +85 -1
  148. pdd/prompts/update_prompt_LLM.prompt +22 -1
  149. pdd/pytest_output.py +127 -12
  150. pdd/remote_session.py +876 -0
  151. pdd/render_mermaid.py +236 -0
  152. pdd/server/__init__.py +52 -0
  153. pdd/server/app.py +335 -0
  154. pdd/server/click_executor.py +587 -0
  155. pdd/server/executor.py +338 -0
  156. pdd/server/jobs.py +661 -0
  157. pdd/server/models.py +241 -0
  158. pdd/server/routes/__init__.py +31 -0
  159. pdd/server/routes/architecture.py +451 -0
  160. pdd/server/routes/auth.py +364 -0
  161. pdd/server/routes/commands.py +929 -0
  162. pdd/server/routes/config.py +42 -0
  163. pdd/server/routes/files.py +603 -0
  164. pdd/server/routes/prompts.py +1322 -0
  165. pdd/server/routes/websocket.py +473 -0
  166. pdd/server/security.py +243 -0
  167. pdd/server/terminal_spawner.py +209 -0
  168. pdd/server/token_counter.py +222 -0
  169. pdd/setup_tool.py +648 -0
  170. pdd/simple_math.py +2 -0
  171. pdd/split_main.py +3 -2
  172. pdd/summarize_directory.py +237 -195
  173. pdd/sync_animation.py +8 -4
  174. pdd/sync_determine_operation.py +839 -112
  175. pdd/sync_main.py +351 -57
  176. pdd/sync_orchestration.py +1400 -756
  177. pdd/sync_tui.py +848 -0
  178. pdd/template_expander.py +161 -0
  179. pdd/template_registry.py +264 -0
  180. pdd/templates/architecture/architecture_json.prompt +237 -0
  181. pdd/templates/generic/generate_prompt.prompt +174 -0
  182. pdd/trace.py +168 -12
  183. pdd/trace_main.py +4 -3
  184. pdd/track_cost.py +140 -63
  185. pdd/unfinished_prompt.py +51 -4
  186. pdd/update_main.py +567 -67
  187. pdd/update_model_costs.py +2 -2
  188. pdd/update_prompt.py +19 -4
  189. {pdd_cli-0.0.45.dist-info → pdd_cli-0.0.118.dist-info}/METADATA +29 -11
  190. pdd_cli-0.0.118.dist-info/RECORD +227 -0
  191. {pdd_cli-0.0.45.dist-info → pdd_cli-0.0.118.dist-info}/licenses/LICENSE +1 -1
  192. pdd_cli-0.0.45.dist-info/RECORD +0 -116
  193. {pdd_cli-0.0.45.dist-info → pdd_cli-0.0.118.dist-info}/WHEEL +0 -0
  194. {pdd_cli-0.0.45.dist-info → pdd_cli-0.0.118.dist-info}/entry_points.txt +0 -0
  195. {pdd_cli-0.0.45.dist-info → pdd_cli-0.0.118.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,925 @@
1
+ % You are an expert PDD (Prompt-Driven Development) engineer. Your task is to update a prompt file to reflect code changes while making it as compact as possible.
2
+
3
+ % Prompting Guide (follow these best practices):
4
+ <pdd_prompting_guide>
5
+ # Prompt‑Driven Development Prompting Guide
6
+
7
+ This guide shows how to write effective prompts for Prompt‑Driven Development (PDD). It distills best practices from the PDD whitepaper, the PDD doctrine, and working patterns in this repo. It also contrasts PDD prompts with interactive agentic coding tools (e.g., Claude Code, Cursor) where prompts act as ad‑hoc patches instead of the source of truth.
8
+
9
+ References: pdd/docs/whitepaper.md, pdd/docs/prompt-driven-development-doctrine.md, README.md (repo structure, conventions), [Effective Context Engineering](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents), [Anthropic Prompt Engineering Overview](https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/overview).
10
+
11
+ ---
12
+
13
+ ## Quickstart: PDD in 5 Minutes
14
+
15
+ If you are new to Prompt-Driven Development (PDD), follow this recipe:
16
+
17
+ 1. **Think "One Prompt = One Module":** Don't try to generate the whole app at once. Focus on one file (e.g., `user_service.py`).
18
+ 2. **Use a Template:** Start with a clear structure: Role, Requirements, Dependencies, Instructions.
19
+ 3. **Explicitly Include Context:** Use `<include>path/to/file</include>` to give the model *only* what it needs (e.g., a shared preamble or a dependency interface). This is a **PDD directive**, not just XML.
20
+ 4. **Regenerate, Don't Patch:** If the code is wrong, fix it using `pdd fix`. This updates the system's memory so the next `pdd generate` is grounded in the correct solution.
21
+ 5. **Verify:** Run the generated code/tests.
22
+
23
+ *Tip: Treat your prompt like source code. It is the single source of truth.*
24
+
25
+ *For the conceptual foundation of why this works, see [The Mold Paradigm](prompt-driven-development-doctrine.md#the-mold-paradigm) in the doctrine.*
26
+
27
+ ---
28
+
29
+ ## Glossary
30
+
31
+ - **Context Engineering:** The art of curating exactly what information (code, docs, examples) fits into the LLM's limited "working memory" (context window) to get the best result.
32
+ - **Shared Preamble:** A standard text file (e.g., `project_preamble.prompt`) included in every prompt to enforce common rules like coding style, forbidden libraries, and formatting.
33
+ - **PDD Directive:** Special tags like `<include>` or `<shell>` that the PDD tool processes *before* sending the text to the AI. The AI sees the *result* (the file content), not the tag.
34
+ - **Source of Truth:** The definitive record. In PDD, the **Prompt** is the source of truth; the code is just a temporary artifact generated from it.
35
+ - **Grounding (Few-Shot History):** The process where the PDD system automatically uses successful past pairs of (Prompt, Code) as "few-shot" examples during generation. This ensures that regenerated code adheres to the established style and logic of the previous version, preventing the model from hallucinating a completely different implementation.
36
+ - **Drift:** When the generated code slowly diverges from the prompt's intent over time, or when manual edits to code make it inconsistent with the prompt.
37
+
38
+ ---
39
+
40
+ ## Why PDD Prompts (Not Patches)
41
+
42
+ - Prompts are the source of truth; code is a generated artifact. Update the prompt and regenerate instead of patching code piecemeal.
43
+ - Regeneration preserves conceptual integrity and reduces long‑term maintenance cost (see pdd/docs/whitepaper.md).
44
+ - Prompts consolidate intent, constraints, dependencies, and examples into one place so the model can enforce them.
45
+ - Tests accumulate across regenerations and act as a regression net; prompts and tests stay in sync.
46
+
47
+ Contrast with interactive patching (Claude Code, Cursor): prompts are ephemeral instructions for local diffs. They are great for short, local fixes, but tend to drift from original intent as context is implicit and often lost. In PDD, prompts are versioned, explicit, and designed for batch, reproducible generation.
48
+
49
+ For a deeper exploration of why this paradigm shift matters—and an analogy to manufacturing's wood‑to‑plastic transition—see [The Mold Paradigm](prompt-driven-development-doctrine.md#the-mold-paradigm) in the doctrine.
50
+
51
+ ---
52
+
53
+ ## The PDD Mental Model
54
+
55
+ - One prompt typically maps to one code file or narrowly scoped module.
56
+ - You explicitly curate the context to place in the model’s window (don’t “dump the repo”).
57
+ - Change behavior by editing the prompt; re‑generate the file; run crash/verify/test/fix; then update the prompt with learnings.
58
+ - Keep the “dev unit” synchronized: prompt + generated code + minimal runnable example + tests.
59
+
60
+ Key principles: everything is explicit, prompts are the programming language, and you regenerate rather than patch.
61
+
62
+ Dev Unit (Prompt with Code, Example, Test):
63
+
64
+ ```mermaid
65
+ flowchart TB
66
+ P[Prompt]
67
+ C[Code]
68
+ E[Example]
69
+ T[Tests]
70
+
71
+ P --> C
72
+ P --> E
73
+ P --> T
74
+ ```
75
+
76
+ Notes:
77
+ - The prompt defines intent. Code, example, and tests are generated artifacts.
78
+ - Regenerate rather than patch; keep tests accumulating over time.
79
+
80
+ ---
81
+
82
+ <a name="automated-grounding"></a>
83
+ ## Automated Grounding (PDD Cloud)
84
+
85
+ Unlike standard LLM interactions where every request is a blank slate, PDD Cloud uses **Automated Grounding** to prevent "implementation drift."
86
+
87
+ ### How It Works
88
+
89
+ When you run `pdd generate`, the system:
90
+ 1. Embeds your prompt into a vector
91
+ 2. Searches for similar prompts in the cloud database (cosine similarity)
92
+ 3. Auto-injects the closest (prompt, code) pair as a few-shot example
93
+
94
+ **This is automatic.** You don't configure it. As you edit your prompt:
95
+ - The embedding changes
96
+ - Different examples may be retrieved
97
+ - Generation naturally adapts to your prompt's content
98
+
99
+ On first generation: Similar existing modules in your project provide grounding.
100
+ On re-generation: Your prior successful generation is typically the closest match.
101
+
102
+ ### Why This Matters for Prompt Writing
103
+
104
+ - **Your prompt wording affects grounding.** Similar prompts retrieve similar examples.
105
+ - **Implementation patterns are handled automatically.** Grounding provides structural consistency from similar modules (class vs functional, helper patterns, etc.).
106
+ - **Prompts can be minimal.** Focus on requirements; grounding handles implementation patterns.
107
+
108
+ *Note: This is distinct from "Examples as Interfaces" (which teach how to **use** a dependency). Grounding teaches the model how to **write** the current module.*
109
+
110
+ > **Local users (no cloud):** Without grounding, prompts must be more detailed—include structural guidance and explicit examples via `<include>`. Use a shared preamble for coding style. The minimal prompt guidance in this document assumes cloud access.
111
+
112
+ ---
113
+
114
+ ## Grounding Overrides: Pin & Exclude (PDD Cloud)
115
+
116
+ For users with PDD Cloud access, you can override automatic grounding using XML tags:
117
+
118
+ **`<pin>module_name</pin>`** — Force a specific example to always be included
119
+ - Use case: Ensure a critical module always follows a "golden" pattern
120
+ - Use case: Bootstrap a new module with a specific style
121
+
122
+ **`<exclude>module_name</exclude>`** — Block a specific example(s) from being retrieved
123
+ - Use case: Escape an old pattern that's pulling generation in the wrong direction
124
+ - Use case: Intentionally break from established patterns for a redesign
125
+
126
+ These tags are processed by the preprocessor (like `<include>`) and removed before the LLM sees the prompt.
127
+
128
+ **Most prompts don't need these.** Automatic grounding works well for:
129
+ - Standard modules with similar existing examples
130
+ - Re-generations of established modules
131
+ - Modules following common project patterns
132
+
133
+ ---
134
+
135
+ ## Anatomy of a Good PDD Prompt
136
+
137
+ A well-designed prompt contains **only what can't be handled elsewhere**. With cloud grounding and accumulated tests, prompts can be minimal.
138
+
139
+ ### Required Sections
140
+
141
+ 1. **Role and scope** (1-2 sentences): What this module does
142
+ 2. **Requirements** (5-10 items): Functional and non-functional specs
143
+ 3. **Dependencies** (via `<include>`): Only external or critical interfaces
144
+
145
+ ### Optional Sections
146
+
147
+ 4. **Instructions**: Only if default behavior needs overriding
148
+ 5. **Deliverables**: Only if non-obvious
149
+
150
+ ### What NOT to Include
151
+
152
+ - **Coding style** (naming, formatting, imports) → Handled by shared preamble
153
+ - **Implementation patterns** (class structure, helpers) → Handled by grounding
154
+ - **Every edge case** → Handled by accumulated tests
155
+ - **Implementation steps** → Let the LLM decide (unless critical)
156
+
157
+ ### Target Size: Prompt-to-Code Ratio
158
+
159
+ Aim for **10-30%** of your expected code size:
160
+
161
+ | Ratio | Meaning |
162
+ |-------|---------|
163
+ | **< 10%** | Too vague—missing contracts, error handling, or key constraints |
164
+ | **10-30%** | Just right—requirements and contracts without implementation details |
165
+ | **> 50%** | Too detailed—prompt is doing preamble's or grounding's job |
166
+
167
+ If your prompt exceeds 30%, ask: Am I specifying things that preamble, grounding, or tests should handle?
168
+
169
+ **Note:** Tests are generated from the module prompt (via Requirements), so explicit Testing sections are unnecessary—well-written Requirements are inherently testable. Use `context/test.prompt` for project-wide test guidance.
170
+
171
+ See pdd/pdd/templates/generic/generate_prompt.prompt for a concrete scaffold.
172
+
173
+ ---
174
+
175
+ ## Prompt Syntax Essentials
176
+
177
+ These patterns are used across prompts in this repo:
178
+
179
+ - Preamble and role: start with a concise, authoritative description of the task and audience (e.g., “You are an expert Python engineer…”).
180
+ - Includes for context: bring only what the model needs.
181
+ - Single include: `<include>path/to/file</include>`. **Note:** This is a PDD directive, not standard XML. The PDD tool replaces this tag with the actual file content *before* the LLM sees it. (Handles both text and images).
182
+ - Multiple: `<include-many>path1, path2, …</include-many>`
183
+ - Grouping: wrap includes in a semantic tag to name the dependency or file they represent, for example:
184
+ ```xml
185
+ <render_js>
186
+ <include>src/render.js</include>
187
+ </render_js>
188
+ ```
189
+ - When including larger files inline for clarity, wrap with opening/closing tags named after the file, e.g. `<render.js>…</render.js>`.
190
+ - Note: `<include>`, `<include-many>`, `<shell>`, and `<web>` inside fenced code blocks (``` or ~~~) or inline backticks are treated as literal text.
191
+ - Inputs/outputs: state them explicitly (names, types, shapes). Prompts should define Inputs/Outputs and steps clearly.
192
+ - Steps & Chain of Thought: Outline a short, deterministic plan. For complex logical tasks, explicitly instruct the model to "Analyze the requirements and think step-by-step before writing code." This improves accuracy on difficult reasoning problems.
193
+ - Constraints: specify style, performance targets, security, and error handling.
194
+ - Environment: reference required env vars (e.g., `PDD_PATH`) when reading data files.
195
+
196
+ Tip: Prefer small, named sections using XML‑style tags to make context scannable and deterministic.
197
+
198
+ ### Special XML Tags: pdd, shell, web
199
+
200
+ The PDD preprocessor supports additional XML‑style tags to keep prompts clean, reproducible, and self‑contained. Processing order (per spec) is: `pdd` → `include`/`include-many` → `shell` → `web`. When `recursive=True`, `<shell>` and `<web>` are deferred until a non‑recursive pass.
201
+
202
+ - `<pdd>…</pdd>`
203
+ - Purpose: human‑only comment. Removed entirely during preprocessing.
204
+ - Use: inline rationale or notes that should not reach the model.
205
+ - Example: `Before step X <pdd>explain why we do this here</pdd>`
206
+
207
+ - `<shell>…</shell>`
208
+ - Purpose: run a shell command and inline stdout at that position.
209
+ - Behavior: executes during non‑recursive preprocessing; on non‑zero exit, inserts a bracketed error with the exit code instead of failing the pipeline.
210
+ - Example: `<shell>git config --get user.name</shell>`
211
+
212
+ - `<web>URL</web>`
213
+ - Purpose: fetch the page (via Firecrawl) and inline the markdown content.
214
+ - Behavior: executes during non‑recursive preprocessing; on failure, inserts a bracketed error note.
215
+ - Example: `<web>https://docs.litellm.ai/docs/completion/json_mode</web>`
216
+
217
+ > ⚠️ **Warning: Non-Deterministic Tags**
218
+ >
219
+ > `<shell>` and `<web>` introduce **non-determinism**:
220
+ > - `<shell>` output varies by environment (different machines, different results)
221
+ > - `<web>` content changes over time (same URL, different content)
222
+ >
223
+ > **Impact:** Same prompt file → different generations on different machines/times
224
+ >
225
+ > **Prefer instead:** Capture output to a static file, then `<include>` that file. This ensures reproducible regeneration.
226
+
227
+ Use these tags sparingly. When you must use them, prefer stable commands with bounded output (e.g., `head -n 20` in `<shell>`).
228
+
229
+ ---
230
+
231
+ ## Architecture Metadata Tags
232
+
233
+ PDD prompts can include optional XML metadata tags that sync with `architecture.json`. These tags enable bidirectional sync between prompt files and the architecture visualization, keeping your project's architecture documentation automatically up-to-date.
234
+
235
+ ### Tag Format
236
+
237
+ Place architecture metadata tags at the **top of your prompt file** (after any `<include>` directives but before the main content):
238
+
239
+ ```xml
240
+ <pdd-reason>Brief description of module's purpose (60-120 chars)</pdd-reason>
241
+
242
+ <pdd-interface>
243
+ {{
244
+ "type": "module",
245
+ "module": {{
246
+ "functions": [
247
+ {{"name": "function_name", "signature": "(...)", "returns": "Type"}}
248
+ ]
249
+ }}
250
+ }}
251
+ </pdd-interface>
252
+
253
+ <pdd-dependency>dependency_prompt_1.prompt</pdd-dependency>
254
+ <pdd-dependency>dependency_prompt_2.prompt</pdd-dependency>
255
+ ```
256
+
257
+ ### Tag Reference
258
+
259
+ **`<pdd-reason>`**
260
+ - **Purpose**: One-line description of why this module exists
261
+ - **Maps to**: `architecture.json["reason"]`
262
+ - **Format**: Single line string (recommended 60-120 characters)
263
+ - **Example**: `<pdd-reason>Provides unified LLM invocation across all PDD operations.</pdd-reason>`
264
+
265
+ **`<pdd-interface>`**
266
+ - **Purpose**: JSON describing the module's public API (functions, commands, pages)
267
+ - **Maps to**: `architecture.json["interface"]`
268
+ - **Format**: Valid JSON matching one of four interface types (see below)
269
+ - **Example**:
270
+ ```xml
271
+ <pdd-interface>
272
+ {{
273
+ "type": "module",
274
+ "module": {{
275
+ "functions": [
276
+ {{"name": "llm_invoke", "signature": "(prompt, strength, ...)", "returns": "Dict"}}
277
+ ]
278
+ }}
279
+ }}
280
+ </pdd-interface>
281
+ ```
282
+
283
+ **`<pdd-dependency>`**
284
+ - **Purpose**: References other prompt files this module depends on
285
+ - **Maps to**: `architecture.json["dependencies"]` array
286
+ - **Format**: Prompt filename (e.g., `llm_invoke_python.prompt`)
287
+ - **Multiple tags**: Use one `<pdd-dependency>` tag per dependency
288
+ - **Example**:
289
+ ```xml
290
+ <pdd-dependency>llm_invoke_python.prompt</pdd-dependency>
291
+ <pdd-dependency>path_resolution_python.prompt</pdd-dependency>
292
+ ```
293
+
294
+ ### Interface Types
295
+
296
+ The `<pdd-interface>` tag supports four interface types, matching the architecture.json schema:
297
+
298
+ **Module Interface** (Python modules with functions):
299
+ ```json
300
+ {{
301
+ "type": "module",
302
+ "module": {{
303
+ "functions": [
304
+ {{"name": "func_name", "signature": "(arg1, arg2)", "returns": "Type"}}
305
+ ]
306
+ }}
307
+ }}
308
+ ```
309
+
310
+ **CLI Interface** (Command-line interfaces):
311
+ ```json
312
+ {{
313
+ "type": "cli",
314
+ "cli": {{
315
+ "commands": [
316
+ {{"name": "cmd_name", "description": "What it does"}}
317
+ ]
318
+ }}
319
+ }}
320
+ ```
321
+
322
+ **Command Interface** (PDD commands):
323
+ ```json
324
+ {{
325
+ "type": "command",
326
+ "command": {{
327
+ "commands": [
328
+ {{"name": "cmd_name", "description": "What it does"}}
329
+ ]
330
+ }}
331
+ }}
332
+ ```
333
+
334
+ **Frontend Interface** (UI pages):
335
+ ```json
336
+ {{
337
+ "type": "frontend",
338
+ "frontend": {{
339
+ "pages": [
340
+ {{"name": "page_name", "route": "/path"}}
341
+ ]
342
+ }}
343
+ }}
344
+ ```
345
+
346
+ ### Sync Workflow
347
+
348
+ 1. **Add/edit tags** in your prompt files using the format above
349
+ 2. **Click "Sync from Prompt"** in the PDD Connect Architecture page (or call the API endpoint)
350
+ 3. **Tags automatically update** `architecture.json` with your changes
351
+ 4. **Architecture visualization** reflects the updated dependencies and interfaces
352
+
353
+ Prompts are the **source of truth** - tags in prompt files override what's in `architecture.json`. This aligns with PDD's core philosophy that prompts, not code or documentation, are authoritative.
354
+
355
+ ### Validation
356
+
357
+ Validation is **lenient**:
358
+ - Missing tags are OK - only fields with tags get updated
359
+ - Malformed XML/JSON is skipped without blocking sync
360
+ - Circular dependencies are detected and prevent invalid updates
361
+ - Missing dependency files generate warnings but don't block sync
362
+
363
+ ### Best Practices
364
+
365
+ **Keep `<pdd-reason>` concise** (60-120 chars)
366
+ - Good: "Provides unified LLM invocation across all PDD operations."
367
+ - Too long: "This module exists because we needed a way to call different LLM providers through a unified interface that supports both streaming and non-streaming modes while also handling rate limiting and retry logic..."
368
+
369
+ **Use prompt filenames for dependencies**, not module names
370
+ - Correct: `<pdd-dependency>llm_invoke_python.prompt</pdd-dependency>`
371
+ - Wrong: `<pdd-dependency>pdd.llm_invoke</pdd-dependency>`
372
+ - Wrong: `<pdd-dependency>context/example.py</pdd-dependency>`
373
+
374
+ **Validate interface JSON before committing**
375
+ - Use a JSON validator to check syntax
376
+ - Ensure `type` field matches one of: `module`, `cli`, `command`, `frontend`
377
+ - Include required nested keys (`functions`, `commands`, or `pages`)
378
+
379
+ **Run "Sync All" after bulk prompt updates**
380
+ - If you've edited multiple prompts, sync all at once
381
+ - Review the validation results for circular dependencies
382
+ - Fix any warnings before committing changes
383
+
384
+ ### Relationship to Other Tags
385
+
386
+ **`<pdd-dependency>` vs `<include>`**:
387
+ - `<pdd-dependency>`: Declares architectural dependency (updates `architecture.json`)
388
+ - `<include>`: Injects content into prompt for LLM context (does NOT affect architecture)
389
+ - Use both when appropriate - they serve different purposes
390
+
391
+ **`<pdd-*>` tags vs `<pdd>` comments**:
392
+ - `<pdd-reason>`, `<pdd-interface>`, `<pdd-dependency>`: Metadata tags (processed by sync tool)
393
+ - `<pdd>...</pdd>`: Human-only comments (removed by preprocessor, never reach LLM)
394
+ - Both are valid PDD directives with different purposes
395
+
396
+ ### Example: Complete Prompt with Metadata Tags
397
+
398
+ See `docs/examples/prompt_with_metadata.prompt` for a full example showing all three metadata tags in context.
399
+
400
+ ---
401
+
402
+ ## Advanced Tips
403
+
404
+ ### Shared Preamble for Consistency
405
+
406
+ Use a shared include (e.g., `<include>context/project_preamble.prompt</include>`) at the top of every prompt. You should create this file in your project's `context/` directory to define your "Constitution": consistent coding style (e.g., indentation, naming conventions), preferred linting rules, and forbidden libraries. This ensures all generated code speaks the same language without cluttering individual prompts.
407
+
408
+ ### Automatic Update Propagation via Includes
409
+
410
+ A key benefit of `<include>` directives is **automatic propagation**: when the included file changes, all prompts that reference it automatically reflect those changes on the next generation—without editing the prompts themselves.
411
+
412
+ Use this pattern when:
413
+ - **Authoritative documentation exists elsewhere** (e.g., a README that defines environment variables, API contracts, or configuration options). Include it rather than duplicating the content.
414
+ - **Shared constraints evolve** (e.g., coding standards, security policies). A single edit to the preamble file updates all prompts.
415
+ - **Interface definitions change** (e.g., a dependency's example file). Prompts consuming that example stay current.
416
+
417
+ *Tradeoff:* Large includes consume context tokens. If only a small portion of a file is relevant, consider extracting that portion into a dedicated include file (e.g., `docs/output_conventions.md` rather than the full `README.md`).
418
+
419
+ ### Positive over Negative Constraints
420
+
421
+ Models often struggle with negative constraints ("Do not use X"). Instead, phrase requirements positively: instead of "Do not use unassigned variables," prefer "Initialize all variables with default values." This greatly improves reliability.
422
+
423
+ ### Positioning Critical Instructions (Hierarchy of Attention)
424
+
425
+ LLMs exhibit "middle-loss" – they pay more attention to the **beginning** (role, preamble) and the **end** (steps, deliverables) of the prompt context. If a critical constraint (e.g., security, output format) is ignored, ensure it's placed in your shared preamble, explicitly reiterated in the final "Instructions" or "Steps" section, or even pre-filled in the expected output format if applicable.
426
+
427
+ ### Command-Specific Context Files
428
+
429
+ Some PDD commands (e.g., `pdd test`, `pdd example`) can automatically include project-specific context files like `context/test.prompt` or `context/example.prompt` during their internal preprocessing. Use these to provide instructions tailored to your project, such as preferred testing frameworks or specific import statements, without modifying the main prompt.
430
+
431
+ **`context/test.prompt`** is particularly important:
432
+ - Defines testing conventions, frameworks, and patterns for your project
433
+ - Included automatically when running `pdd test` (alongside the module prompt and generated code)
434
+ - Tests accumulate over time via `--merge` as bugs are found
435
+ - Tests persist when the module prompt changes—only code is regenerated, not tests
436
+ - This ensures tests remain stable "permanent assets" while code can be freely regenerated
437
+
438
+ ---
439
+
440
+ ## Why PDD Scales to Large Codebases
441
+
442
+ - Explicit, curated context: use minimal examples and targeted includes instead of dumping source, reducing tokens and confusion.
443
+ - Modular dev units: one prompt per file/module constrains scope, enabling independent regeneration and parallel work.
444
+ - Batch, reproducible flow: eliminate long chat histories; regeneration avoids patch accumulation and incoherent diffs.
445
+ - Accumulating tests: protect behavior across wide regenerations and refactors; failures localize issues quickly.
446
+ - Single source of truth: prompts unify intent and dependencies, improving cross‑team coordination and reducing drift.
447
+ - Automated Grounding: By feeding successful past generations back into the context, the system stabilizes the code over time, making "regeneration" safe even for complex modules.
448
+
449
+ ### Tests as Generation Context
450
+
451
+ A key PDD feature: existing tests are automatically included as context when generating code. This means:
452
+
453
+ - The LLM sees the test file and knows what behaviors must be preserved
454
+ - Generated code is constrained to pass existing tests
455
+ - New tests accumulate over time, progressively constraining future generations
456
+ - This creates a "ratchet effect" - each bug fix adds a test, preventing regression
457
+
458
+ This is distinct from test *generation*. Tests are generated via `pdd test PROMPT_FILE CODE_FILE`, which uses the module prompt, generated code, and `context/test.prompt` for project-wide guidance. Tests accumulate over time via `--merge` as bugs are found. Requirements in the module prompt implicitly define what to test—each requirement should correspond to at least one test case.
459
+
460
+ ```mermaid
461
+ flowchart LR
462
+ subgraph Assets
463
+ P[Module Prompt] --> G[pdd generate]
464
+ T[Existing Tests] --> G
465
+ G --> C[Generated Code]
466
+ end
467
+
468
+ subgraph Accumulation
469
+ BUG[Bug Found] --> NT[New Test Written]
470
+ NT --> T
471
+ end
472
+ ```
473
+
474
+ ---
475
+
476
+ Patch vs PDD at Scale (diagram):
477
+
478
+ ```mermaid
479
+ flowchart LR
480
+ subgraph Patching
481
+ C0[Codebase] --> P0[Chat prompt]
482
+ P0 --> D0[Local diff]
483
+ D0 --> C0
484
+ end
485
+
486
+ subgraph PDD
487
+ PG[Prompts graph] --> GZ[Batch regenerate]
488
+ GZ --> CM[Code modules]
489
+ CM --> XT[Examples and Tests]
490
+ XT --> UP[Update prompts]
491
+ UP --> PG
492
+ end
493
+ ```
494
+
495
+ ---
496
+
497
+ ## The Three Pillars of PDD Generation
498
+
499
+ Understanding how prompts, grounding, and tests work together is key to writing minimal, effective prompts.
500
+
501
+ | Pillar | What It Provides | Maintained By |
502
+ |--------|-----------------|---------------|
503
+ | **Prompt** | Requirements and constraints (WHAT) | Developer (explicit) |
504
+ | **Grounding** | Implementation patterns (HOW) | System (automatic, Cloud) |
505
+ | **Tests** | Behavioral correctness | Accumulated over time |
506
+
507
+ ### How They Interact
508
+
509
+ - **Prompt** defines WHAT → "validate user input, return errors"
510
+ - **Grounding** defines HOW → class structure, helper patterns (from similar modules)
511
+ - **Tests** define CORRECTNESS → edge cases discovered through bugs
512
+
513
+ ### Conflict Resolution
514
+
515
+ - **Tests override grounding**: If a test requires new behavior, generation must satisfy it
516
+ - **Explicit requirements override grounding**: If prompt says "use functional style", that overrides OOP examples in grounding
517
+ - **Grounding fills gaps**: Everything not specified in prompt or constrained by tests
518
+
519
+ ### Why Prompts Can Be Minimal
520
+
521
+ You don't need to specify:
522
+ - **Coding style** → preamble provides it
523
+ - **Implementation patterns** → grounding provides them
524
+ - **Edge cases** → tests encode them
525
+
526
+ You only specify:
527
+ - What the module does
528
+ - What contracts it must satisfy
529
+ - What constraints apply
530
+
531
+ ---
532
+
533
+ ## Example (Minimal, Python)
534
+
535
+ This simplified example illustrates a minimal functional prompt:
536
+
537
+ ```text
538
+ % You are an expert Python engineer. Your goal is to write a function `get_extension` that returns the file extension for a given language.
539
+
540
+ <include>context/python_preamble.prompt</include>
541
+
542
+ % Inputs/Outputs
543
+ Input: language (str), like "Python" or "Makefile".
544
+ Output: str file extension (e.g., ".py"), or "" if unknown.
545
+
546
+ % Data
547
+ The CSV at $PDD_PATH/data/language_format.csv contains: language,comment,extension
548
+
549
+ % Steps
550
+ 1) Load env var PDD_PATH and read the CSV
551
+ 2) Normalize language case
552
+ 3) Lookup extension
553
+ 4) Return "" if not found or invalid
554
+ ```
555
+
556
+ This style:
557
+ - Declares role and outcome
558
+ - Specifies IO, data sources, and steps
559
+ - Uses an `<include>` to pull a shared preamble
560
+
561
+ ---
562
+
563
+ ## Scoping & Modularity
564
+
565
+ - One prompt → one file/module. If a prompt gets too large or brittle, split it into smaller prompts that compose via explicit interfaces.
566
+ - Treat examples as interfaces: create a minimal runnable example demonstrating how the module is meant to be used.
567
+ - Avoid “mega‑prompts” that try to implement an entire subsystem. Use the PDD graph of prompts instead. For how prompts compose via examples, see “Dependencies & Composability (Token‑Efficient Examples)”.
568
+
569
+ ---
570
+
571
+ ## Writing Effective Requirements
572
+
573
+ Requirements are the core of your prompt. Everything else is handled automatically by grounding and tests.
574
+
575
+ ### Structure (aim for 5-10 items)
576
+
577
+ 1. **Primary function**: What does this module do? (one sentence)
578
+ 2. **Input contract**: Types, validation rules, what's accepted
579
+ 3. **Output contract**: Types, error conditions, return values
580
+ 4. **Key invariants**: What must always be true
581
+ 5. **Performance constraints**: If any (latency, memory, complexity)
582
+ 6. **Security constraints**: If any (input sanitization, auth requirements)
583
+
584
+ ### Each Requirement Should Be
585
+
586
+ - **Testable**: If you can't write a test for it, it's too vague
587
+ - **Behavioral**: Describe WHAT, not HOW
588
+ - **Unique**: Don't duplicate what preamble or grounding provides
589
+
590
+ ### Example: Before/After
591
+
592
+ **Too detailed:**
593
+ ```
594
+ 1. Create a UserValidator class with validate() method
595
+ 2. Use snake_case for all methods ← belongs in preamble
596
+ 3. Import typing at the top ← belongs in preamble
597
+ 4. Add docstrings to all public methods ← belongs in preamble
598
+ 5. Handle null by returning ValidationError
599
+ 6. Handle empty string by returning ValidationError
600
+ 7. Handle whitespace-only by returning ValidationError
601
+ ```
602
+
603
+ **Just right** (requirements only):
604
+ ```
605
+ 1. Function: validate_user(input) → ValidationResult
606
+ 2. Input: Any type (untrusted user input)
607
+ 3. Output: ValidationResult with is_valid bool and errors list
608
+ 4. Invalid inputs: null, empty, whitespace-only, malformed
609
+ 5. Performance: O(n) in input length
610
+ 6. Security: No eval/exec, treat input as untrusted
611
+ ```
612
+
613
+ Style conventions (2-4) belong in a shared preamble. Edge cases (5-7) can be collapsed into a single requirement.
614
+
615
+ **Requirements as Test Specifications:** Each requirement implies at least one test case. If you can't test a requirement, it's too vague.
616
+
617
+ ---
618
+
619
+ ## Prompt Abstraction Level
620
+
621
+ ![Goldilocks Prompt](goldilocks_prompt.jpeg)
622
+
623
+ Write prompts at the level of *architecture, contract, and intent*, not line-by-line *implementation details*.
624
+
625
+ ### Heuristics: Are You at the Right Level?
626
+
627
+ | Indicator | Too Detailed (> 30%) | Too Vague (< 10%) |
628
+ |-----------|----------------------|-------------------|
629
+ | **Content** | Specifying variable names, loop structures | Missing error handling strategy |
630
+ | **Style** | Dictating indentation, imports | No input/output types |
631
+ | **Result** | Prompt harder to maintain than code | Every generation is wildly different |
632
+
633
+ ### If Your Prompt Is Too Long
634
+
635
+ Ask yourself:
636
+ - **Am I specifying coding style?** → Remove it (preamble handles this)
637
+ - **Am I specifying implementation patterns?** → Remove them (grounding handles this)
638
+ - **Am I listing every edge case?** → Remove them (tests handle this)
639
+ - **Is the module too big?** → Split into multiple prompts
640
+
641
+ ### Examples
642
+
643
+ - **Too Vague:** "Create a user page." (Model guesses everything; unrepeatable)
644
+ - **Too Detailed:** "Create a class User with a private field _id. In the constructor, set _id. Write a getter..." (Prompt is harder to maintain than code)
645
+ - **Just Right:** "Implement a UserProfile component that displays user details and handles the 'update' action via the API. It must handle loading/error states and match the existing design system."
646
+
647
+ **Rule of Thumb:** Focus on **Interfaces**, **Invariants**, and **Outcomes**. Let the preamble handle coding style; let grounding handle implementation patterns.
648
+
649
+ ---
650
+
651
+ ## Dependencies
652
+
653
+ ### When to Use `<include>`
654
+
655
+ Include dependencies explicitly when:
656
+ - **External libraries** not in your grounding history
657
+ - **Critical interfaces** that must be exact
658
+ - **New modules** with no similar examples in grounding
659
+
660
+ ```xml
661
+ <billing_service>
662
+ <include>context/billing_service_example.py</include>
663
+ </billing_service>
664
+ ```
665
+
666
+ ### When to Rely on Grounding
667
+
668
+ If you've successfully generated code that uses a dependency before, grounding often suffices—the usage pattern is already in the cloud database.
669
+
670
+ **Prefer explicit `<include>` for:** External APIs, critical contracts, cross-team interfaces
671
+ **Rely on grounding for:** Internal modules with established patterns
672
+
673
+ ### Token Efficiency
674
+
675
+ Real source code is heavy. A 500-line module might have a 50-line usage example. By including only the example, you save ~90% of tokens. Use `pdd auto-deps` to automatically populate relevant examples.
676
+
677
+ ```mermaid
678
+ flowchart LR
679
+ subgraph Module_B
680
+ PB[Prompt B] --> GB[Generate] --> CB[Code B]
681
+ CB --> EB[Example B]
682
+ end
683
+
684
+ subgraph Module_A
685
+ PA[Prompt A] --> GA[Generate] --> CA[Code A]
686
+ PA --> EB
687
+ end
688
+
689
+ EB --> CA
690
+ ```
691
+
692
+ ---
693
+
694
+ ## Regenerate, Verify, Test, Update
695
+
696
+ **Crucial Prerequisite:** Before regenerating a module, ensure you have **high test coverage** for its current functionality. Because PDD overwrites the code file entirely, your test suite is the critical safety net that prevents regression of existing features while you iterate on new ones.
697
+
698
+ The PDD workflow (see pdd/docs/whitepaper.md):
699
+
700
+ 1) **Generate:** Fully regenerate (overwrite) the code module and its example.
701
+ 2) **Crash → Verify:** Run the example. Fix immediate runtime errors.
702
+ 3) **Test (Accumulate):** Run existing tests. If fixing a bug, **write a new failing test case first** and append it to the test file. *Never overwrite the test file; tests must accumulate to prevent regressions.*
703
+ 4) **Fix via Command:** When you use `pdd fix` (or manual fixes verified by tests), the system **automatically submits** the successful Prompt+Code pair to PDD Cloud (or local history).
704
+ 5) **Fix via Prompt:** If the logic is fundamentally flawed, update the prompt text to clarify the requirement or constraint that was missed, then **go to step 1**.
705
+ 5) **Drift Check (Optional):** Occasionally regenerate the module *without* changing the prompt (e.g., after upgrading LLM versions or before major releases). If the output differs significantly or fails tests, your prompt has "drifted" (it relied on lucky seeds or implicit context). Tighten the prompt until the output is stable.
706
+ 6) **Update:** Once tests pass, back-propagate any final learnings into the prompt.
707
+
708
+ Key practice: Code and examples are ephemeral (regenerated); Tests and Prompts are permanent assets (accumulated and versioned).
709
+
710
+ **Important:** Tests ARE generated from the module prompt (plus code and `context/test.prompt`). The key distinction is their lifecycle:
711
+ - Code is regenerated on prompt changes; tests accumulate and persist
712
+ - Requirements implicitly define test coverage—each requirement implies at least one test
713
+ - Use `context/test.prompt` for project-wide test guidance (frameworks, patterns)
714
+ - Existing tests are included as context during code generation
715
+ - This creates a "ratchet effect" where each new test permanently constrains future generations
716
+
717
+ ### Workflow Cheatsheet: Features vs. Bugs
718
+
719
+ | Task Type | Where to Start | The Workflow |
720
+ | :--- | :--- | :--- |
721
+ | **New Feature** | **The Prompt** | 1. Add/Update Requirements in Prompt.<br>2. Regenerate Code (LLM sees existing tests).<br>3. Write new Tests to verify. |
722
+ | **Bug Fix** | **The Test File** | 1. Use `pdd bug` to create a failing test case (repro) in the Test file.<br>2. Clarify the Prompt to address the edge case if needed.<br>3. Run `pdd fix` (LLM sees the new test and must pass it). |
723
+
724
+ **Key insight:** When you run `pdd generate` after adding a test, the LLM sees that test as context. This means the generated code is constrained to pass it - the test acts as a specification, not just a verification.
725
+
726
+ **Why?** Features represent *new intent* (Prompt). Bugs represent *missed intent* which must first be captured as a constraint (Test) before refining the definition (Prompt).
727
+
728
+ ### When to Update the Prompt (and When Not To)
729
+
730
+ After a successful fix, ask: "Where should this knowledge live?"
731
+
732
+ | Knowledge Type | Where It Lives | Update Prompt? |
733
+ |---------------|----------------|----------------|
734
+ | New edge case behavior | Test file | **No** |
735
+ | Implementation pattern fix | Grounding (auto-captured) | **No** |
736
+ | Missing requirement | Prompt | **Yes** |
737
+ | Wrong constraint | Prompt | **Yes** |
738
+ | Security/compliance rule | Prompt or preamble | **Yes** |
739
+
740
+ **Rule of thumb:** Update the prompt only for **intent changes**:
741
+ - "The module should also handle X" → Add requirement
742
+ - "The constraint was wrong" → Fix requirement
743
+ - "This security rule applies" → Add requirement
744
+
745
+ **Don't update for implementation fixes:**
746
+ - "There was a bug with null handling" → Add test; grounding captures the fix
747
+ - "The code style was inconsistent" → Update preamble (not prompt)
748
+ - "I prefer different variable names" → Update preamble/prompt
749
+
750
+ ---
751
+
752
+ ## PDD vs Interactive Agentic Coders (Claude Code, Cursor)
753
+
754
+ - Source of truth:
755
+ - PDD: the prompt is primary and versioned; code is regenerated output
756
+ - Interactive: the code is primary; prompts are ephemeral patch instructions
757
+ - Workflow:
758
+ - PDD: batch‑oriented, reproducible runs; explicit context via includes
759
+ - Interactive: live chat loops; implicit context; local diffs
760
+ - Scope:
761
+ - PDD: scoped to modules/files with clear interfaces; compose via examples
762
+ - Interactive: excels at small, local edits; struggles as scope and history grow
763
+ - Synchronization:
764
+ - PDD: update prompts after fixes; tests accumulate and protect behavior
765
+ - Interactive: prompt history rarely persists; documentation often drifts
766
+
767
+ When to use which: Use PDD for substantive new modules, refactors, and anything requiring long‑term maintainability and repeatability. Use interactive patching for trivial hotfixes; follow up with a prompt `update` so the source of truth remains synchronized.
768
+
769
+ ---
770
+
771
+ ## Patch vs PDD: Concrete Examples
772
+
773
+ Patch‑style prompt (interactive agent):
774
+
775
+ ```text
776
+ Fix this bug in src/utils/user.ts. In function parseUserId, passing null should return null instead of throwing.
777
+
778
+ Constraints:
779
+ - Change the minimum number of lines
780
+ - Do not alter the function signature or add new functions
781
+ - Keep existing imports and formatting
782
+ - Output a unified diff only
783
+
784
+ Snippet:
785
+ export function parseUserId(input: string) {{
786
+ return input.trim().split(":")[1];
787
+ }}
788
+ ```
789
+
790
+ PDD‑style prompt (source of truth):
791
+
792
+ ```text
793
+ % You are an expert TypeScript engineer. Create a module `user_id_parser` with a function `parseUserId` that safely extracts a user id.
794
+
795
+ % Role & Scope
796
+ A utility module responsible for parsing user identifiers from various inputs.
797
+
798
+ % Requirements
799
+ 1) Function: `parseUserId(input: unknown): string | null`
800
+ 2) Accepts strings like "user:abc123" and returns "abc123"
801
+ 3) For null/undefined/non‑string, return null without throwing
802
+ 4) Trim whitespace; reject blank ids as null
803
+ 5) Log at debug level on parse failures; no exceptions for expected cases
804
+ 6) Performance: O(n) in input length; no regex backtracking pitfalls
805
+ 7) Security: no eval/exec; treat input as untrusted
806
+
807
+ % Dependencies
808
+ <logger>
809
+ <include>context/logger_example.ts</include>
810
+ </logger>
811
+
812
+ % Instructions
813
+ - Implement in `src/utils/user_id_parser.ts`
814
+ - Export `parseUserId`
815
+ - Add narrow helpers if needed; keep module cohesive
816
+ - Include basic JSDoc and simple debug logging hooks
817
+ ```
818
+
819
+ Key differences:
820
+ - Patch prompt constrains a local edit and often asks for a diff. It assumes code is the source of truth.
821
+ - PDD prompt defines the module's contract, dependencies, and deliverables. It is the source of truth; code is regenerated to match it, while tests accumulate over time.
822
+
823
+ ---
824
+
825
+ ## Checklist: Before You Run `pdd generate`
826
+
827
+ ### Must Have
828
+ - [ ] Module purpose is clear (1-2 sentences)
829
+ - [ ] Requirements are testable and behavioral (5-10 items)
830
+ - [ ] Dependencies included (if external or critical)
831
+
832
+ ### For Established Modules
833
+ - [ ] Tests exist for known edge cases
834
+ - [ ] Previous generation was successful (grounding will use it)
835
+
836
+ ### For New Modules
837
+ - [ ] Similar modules exist in codebase (grounding will find them)
838
+ - [ ] Or: Consider `<pin>` to reference a template module (Cloud)
839
+
840
+ ### You Don't Need to Specify
841
+ - Coding style (preamble handles this)
842
+ - Implementation patterns (grounding handles this)
843
+ - Every edge case (tests handle this)
844
+
845
+ ---
846
+
847
+ ## Common Pitfalls (And Fixes)
848
+
849
+ - Too much context: prune includes; prefer targeted examples over entire files.
850
+ - Vague requirements: convert to explicit contracts, budgets, and behaviors.
851
+ - Mega‑prompts: split into smaller prompts (one per file/module) and compose.
852
+ - Prompt outweighs the code: if the prompt is larger than the generated file, it’s usually over‑specifying control flow. Aim for prompts to be a fraction of the target code size; keep them at the interface/behavior level and let the model fill in routine implementation.
853
+ - Patching code directly: make the change in the prompt and regenerate; then `update` with learnings.
854
+ - Throwing away tests: keep and expand; they are your long‑term leverage.
855
+
856
+ ---
857
+
858
+ ## Naming & Conventions (This Repo)
859
+
860
+ - One prompt per module/file, named like `${{BASENAME}}_${{LanguageOrFramework}}.prompt` (see templates under `pdd/pdd/templates`).
861
+ - Follow codebase conventions from README.md for Python and TypeScript style.
862
+ - Use curated examples under `context/` to encode interfaces and behaviors.
863
+
864
+ ---
865
+
866
+ ## Final Notes
867
+
868
+ Think of prompts as your programming language. Keep them concise, explicit, and modular. Regenerate instead of patching, verify behavior with accumulating tests, and continuously back‑propagate implementation learnings into your prompts. That discipline is what converts maintenance from an endless patchwork into a compounding system of leverage.
869
+
870
+ </pdd_prompting_guide>
871
+
872
+ % Files to Read
873
+
874
+ 1. **Prompt file**: {prompt_path}
875
+ - Read this file and all its XML include tags to understand the current specification
876
+
877
+ 2. **Code file (modified)**: {code_path}
878
+ - This contains the user's modifications that the prompt needs to capture
879
+
880
+ 3. **Test files**: {test_paths}
881
+ - If tests are listed above, read ALL of them
882
+ - If "No tests were found", search for test files yourself:
883
+ - Look for files named `test_<module>*.py` in sibling `tests/` directory (../tests/)
884
+ - Check common locations: `tests/`, `__tests__/`, `test/`
885
+ - Behaviors verified by tests DON'T need to be explicitly specified in the prompt
886
+ - Tests accumulate across numbered files (test_module.py, test_module_1.py, etc.)
887
+
888
+ % Your 4-Step Process
889
+
890
+ **Step 1: Assess Differences**
891
+ - Read the prompt file (expand all XML include tags mentally)
892
+ - Compare against the modified code
893
+ - Identify what the code does that isn't in the prompt
894
+ - Identify what the prompt says that isn't in the code
895
+
896
+ **Step 2: Filter Using Guide + Tests**
897
+ - Consult the prompting guide above for what belongs in a prompt
898
+ - Check the test files - if tests verify a behavior, the prompt can be more abstract
899
+ - Decide which differences should go in the updated prompt
900
+
901
+ **Step 3: Remove Duplication**
902
+ - Check if the prompt body duplicates content from XML include files
903
+ - Remove redundant specifications
904
+ - Keep the prompt compact but sufficient
905
+
906
+ **Step 4: Check for Existing Shared Includes** (optional)
907
+ - If you identify content that could be shared, check if a relevant include already exists in `context/`
908
+ - Only create new includes for patterns that are truly common (would be used in 3+ prompts)
909
+ - Do NOT scan all prompts - this step is opportunistic based on your knowledge of the prompt being updated
910
+
911
+ **Step 5: Validate**
912
+ - Ensure the prompt can reliably regenerate the modified code
913
+ - Ensure the prompt is human-readable:
914
+ - Clear role/purpose statement
915
+ - Logical structure (requirements, dependencies)
916
+ - Understandable by a developer unfamiliar with the code
917
+ - Target 10-30% prompt-to-code ratio (per the guide)
918
+
919
+ % Action
920
+
921
+ Write the updated prompt directly to: {prompt_path}
922
+
923
+ If you create new shared include files, write them to the `context/` or equivalent directory. It may be different for different projects so you might need to explore the project to find the correct directory.
924
+
925
+ If the prompt is already optimal, you may leave it unchanged.