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