pdd-cli 0.0.90__py3-none-any.whl → 0.0.121__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.
- pdd/__init__.py +38 -6
- pdd/agentic_bug.py +323 -0
- pdd/agentic_bug_orchestrator.py +506 -0
- pdd/agentic_change.py +231 -0
- pdd/agentic_change_orchestrator.py +537 -0
- pdd/agentic_common.py +533 -770
- pdd/agentic_crash.py +2 -1
- pdd/agentic_e2e_fix.py +319 -0
- pdd/agentic_e2e_fix_orchestrator.py +582 -0
- pdd/agentic_fix.py +118 -3
- pdd/agentic_update.py +27 -9
- pdd/agentic_verify.py +3 -2
- pdd/architecture_sync.py +565 -0
- pdd/auth_service.py +210 -0
- pdd/auto_deps_main.py +63 -53
- pdd/auto_include.py +236 -3
- pdd/auto_update.py +125 -47
- pdd/bug_main.py +195 -23
- pdd/cmd_test_main.py +345 -197
- pdd/code_generator.py +4 -2
- pdd/code_generator_main.py +118 -32
- pdd/commands/__init__.py +6 -0
- pdd/commands/analysis.py +113 -48
- pdd/commands/auth.py +309 -0
- pdd/commands/connect.py +358 -0
- pdd/commands/fix.py +155 -114
- pdd/commands/generate.py +5 -0
- pdd/commands/maintenance.py +3 -2
- pdd/commands/misc.py +8 -0
- pdd/commands/modify.py +225 -163
- pdd/commands/sessions.py +284 -0
- pdd/commands/utility.py +12 -7
- pdd/construct_paths.py +334 -32
- pdd/context_generator_main.py +167 -170
- pdd/continue_generation.py +6 -3
- pdd/core/__init__.py +33 -0
- pdd/core/cli.py +44 -7
- pdd/core/cloud.py +237 -0
- pdd/core/dump.py +68 -20
- pdd/core/errors.py +4 -0
- pdd/core/remote_session.py +61 -0
- pdd/crash_main.py +219 -23
- pdd/data/llm_model.csv +4 -4
- pdd/docs/prompting_guide.md +864 -0
- pdd/docs/whitepaper_with_benchmarks/data_and_functions/benchmark_analysis.py +495 -0
- pdd/docs/whitepaper_with_benchmarks/data_and_functions/creation_compare.py +528 -0
- pdd/fix_code_loop.py +208 -34
- pdd/fix_code_module_errors.py +6 -2
- pdd/fix_error_loop.py +291 -38
- pdd/fix_main.py +208 -6
- pdd/fix_verification_errors_loop.py +235 -26
- pdd/fix_verification_main.py +269 -83
- pdd/frontend/dist/assets/index-B5DZHykP.css +1 -0
- pdd/frontend/dist/assets/index-CUWd8al1.js +450 -0
- pdd/frontend/dist/index.html +376 -0
- pdd/frontend/dist/logo.svg +33 -0
- pdd/generate_output_paths.py +46 -5
- pdd/generate_test.py +212 -151
- pdd/get_comment.py +19 -44
- pdd/get_extension.py +8 -9
- pdd/get_jwt_token.py +309 -20
- pdd/get_language.py +8 -7
- pdd/get_run_command.py +7 -5
- pdd/insert_includes.py +2 -1
- pdd/llm_invoke.py +531 -97
- pdd/load_prompt_template.py +15 -34
- pdd/operation_log.py +342 -0
- pdd/path_resolution.py +140 -0
- pdd/postprocess.py +122 -97
- pdd/preprocess.py +68 -12
- pdd/preprocess_main.py +33 -1
- pdd/prompts/agentic_bug_step10_pr_LLM.prompt +182 -0
- pdd/prompts/agentic_bug_step1_duplicate_LLM.prompt +73 -0
- pdd/prompts/agentic_bug_step2_docs_LLM.prompt +129 -0
- pdd/prompts/agentic_bug_step3_triage_LLM.prompt +95 -0
- pdd/prompts/agentic_bug_step4_reproduce_LLM.prompt +97 -0
- pdd/prompts/agentic_bug_step5_root_cause_LLM.prompt +123 -0
- pdd/prompts/agentic_bug_step6_test_plan_LLM.prompt +107 -0
- pdd/prompts/agentic_bug_step7_generate_LLM.prompt +172 -0
- pdd/prompts/agentic_bug_step8_verify_LLM.prompt +119 -0
- pdd/prompts/agentic_bug_step9_e2e_test_LLM.prompt +289 -0
- pdd/prompts/agentic_change_step10_identify_issues_LLM.prompt +1006 -0
- pdd/prompts/agentic_change_step11_fix_issues_LLM.prompt +984 -0
- pdd/prompts/agentic_change_step12_create_pr_LLM.prompt +140 -0
- pdd/prompts/agentic_change_step1_duplicate_LLM.prompt +73 -0
- pdd/prompts/agentic_change_step2_docs_LLM.prompt +101 -0
- pdd/prompts/agentic_change_step3_research_LLM.prompt +126 -0
- pdd/prompts/agentic_change_step4_clarify_LLM.prompt +164 -0
- pdd/prompts/agentic_change_step5_docs_change_LLM.prompt +981 -0
- pdd/prompts/agentic_change_step6_devunits_LLM.prompt +1005 -0
- pdd/prompts/agentic_change_step7_architecture_LLM.prompt +1044 -0
- pdd/prompts/agentic_change_step8_analyze_LLM.prompt +1027 -0
- pdd/prompts/agentic_change_step9_implement_LLM.prompt +1077 -0
- pdd/prompts/agentic_e2e_fix_step1_unit_tests_LLM.prompt +90 -0
- pdd/prompts/agentic_e2e_fix_step2_e2e_tests_LLM.prompt +91 -0
- pdd/prompts/agentic_e2e_fix_step3_root_cause_LLM.prompt +89 -0
- pdd/prompts/agentic_e2e_fix_step4_fix_e2e_tests_LLM.prompt +96 -0
- pdd/prompts/agentic_e2e_fix_step5_identify_devunits_LLM.prompt +91 -0
- pdd/prompts/agentic_e2e_fix_step6_create_unit_tests_LLM.prompt +106 -0
- pdd/prompts/agentic_e2e_fix_step7_verify_tests_LLM.prompt +116 -0
- pdd/prompts/agentic_e2e_fix_step8_run_pdd_fix_LLM.prompt +120 -0
- pdd/prompts/agentic_e2e_fix_step9_verify_all_LLM.prompt +146 -0
- pdd/prompts/agentic_fix_primary_LLM.prompt +2 -2
- pdd/prompts/agentic_update_LLM.prompt +192 -338
- pdd/prompts/auto_include_LLM.prompt +22 -0
- pdd/prompts/change_LLM.prompt +3093 -1
- pdd/prompts/detect_change_LLM.prompt +571 -14
- pdd/prompts/fix_code_module_errors_LLM.prompt +8 -0
- pdd/prompts/fix_errors_from_unit_tests_LLM.prompt +1 -0
- pdd/prompts/generate_test_LLM.prompt +19 -1
- pdd/prompts/generate_test_from_example_LLM.prompt +366 -0
- pdd/prompts/insert_includes_LLM.prompt +262 -252
- pdd/prompts/prompt_code_diff_LLM.prompt +123 -0
- pdd/prompts/prompt_diff_LLM.prompt +82 -0
- pdd/remote_session.py +876 -0
- pdd/server/__init__.py +52 -0
- pdd/server/app.py +335 -0
- pdd/server/click_executor.py +587 -0
- pdd/server/executor.py +338 -0
- pdd/server/jobs.py +661 -0
- pdd/server/models.py +241 -0
- pdd/server/routes/__init__.py +31 -0
- pdd/server/routes/architecture.py +451 -0
- pdd/server/routes/auth.py +364 -0
- pdd/server/routes/commands.py +929 -0
- pdd/server/routes/config.py +42 -0
- pdd/server/routes/files.py +603 -0
- pdd/server/routes/prompts.py +1347 -0
- pdd/server/routes/websocket.py +473 -0
- pdd/server/security.py +243 -0
- pdd/server/terminal_spawner.py +217 -0
- pdd/server/token_counter.py +222 -0
- pdd/summarize_directory.py +236 -237
- pdd/sync_animation.py +8 -4
- pdd/sync_determine_operation.py +329 -47
- pdd/sync_main.py +272 -28
- pdd/sync_orchestration.py +289 -211
- pdd/sync_order.py +304 -0
- pdd/template_expander.py +161 -0
- pdd/templates/architecture/architecture_json.prompt +41 -46
- pdd/trace.py +1 -1
- pdd/track_cost.py +0 -13
- pdd/unfinished_prompt.py +2 -1
- pdd/update_main.py +68 -26
- {pdd_cli-0.0.90.dist-info → pdd_cli-0.0.121.dist-info}/METADATA +15 -10
- pdd_cli-0.0.121.dist-info/RECORD +229 -0
- pdd_cli-0.0.90.dist-info/RECORD +0 -153
- {pdd_cli-0.0.90.dist-info → pdd_cli-0.0.121.dist-info}/WHEEL +0 -0
- {pdd_cli-0.0.90.dist-info → pdd_cli-0.0.121.dist-info}/entry_points.txt +0 -0
- {pdd_cli-0.0.90.dist-info → pdd_cli-0.0.121.dist-info}/licenses/LICENSE +0 -0
- {pdd_cli-0.0.90.dist-info → pdd_cli-0.0.121.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,1006 @@
|
|
|
1
|
+
% You are an expert software engineer using Prompt-Driven Development (PDD). Your task is to identify potential issues with the prompt and documentation changes made in the previous step.
|
|
2
|
+
|
|
3
|
+
% Context
|
|
4
|
+
|
|
5
|
+
You are working on step 10 of 12 in an agentic change workflow. Previous step implemented prompt changes. This step identifies issues that need fixing.
|
|
6
|
+
|
|
7
|
+
**This step is part of a review loop.** After you identify issues, Step 11 will fix them. Then this step runs again to check for remaining issues. The loop continues until no issues are found (max 5 iterations).
|
|
8
|
+
|
|
9
|
+
% PDD Background
|
|
10
|
+
|
|
11
|
+
<pdd_prompting_guide>
|
|
12
|
+
# Prompt‑Driven Development Prompting Guide
|
|
13
|
+
|
|
14
|
+
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.
|
|
15
|
+
|
|
16
|
+
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).
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Quickstart: PDD in 5 Minutes
|
|
21
|
+
|
|
22
|
+
If you are new to Prompt-Driven Development (PDD), follow this recipe:
|
|
23
|
+
|
|
24
|
+
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`).
|
|
25
|
+
2. **Use a Template:** Start with a clear structure: Role, Requirements, Dependencies, Instructions.
|
|
26
|
+
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.
|
|
27
|
+
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.
|
|
28
|
+
5. **Verify:** Run the generated code/tests.
|
|
29
|
+
|
|
30
|
+
*Tip: Treat your prompt like source code. It is the single source of truth.*
|
|
31
|
+
|
|
32
|
+
*For the conceptual foundation of why this works, see [The Mold Paradigm](prompt-driven-development-doctrine.md#the-mold-paradigm) in the doctrine.*
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Glossary
|
|
37
|
+
|
|
38
|
+
- **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.
|
|
39
|
+
- **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.
|
|
40
|
+
- **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.
|
|
41
|
+
- **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.
|
|
42
|
+
- **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.
|
|
43
|
+
- **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.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Why PDD Prompts (Not Patches)
|
|
48
|
+
|
|
49
|
+
- Prompts are the source of truth; code is a generated artifact. Update the prompt and regenerate instead of patching code piecemeal.
|
|
50
|
+
- Regeneration preserves conceptual integrity and reduces long‑term maintenance cost (see pdd/docs/whitepaper.md).
|
|
51
|
+
- Prompts consolidate intent, constraints, dependencies, and examples into one place so the model can enforce them.
|
|
52
|
+
- Tests accumulate across regenerations and act as a regression net; prompts and tests stay in sync.
|
|
53
|
+
|
|
54
|
+
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.
|
|
55
|
+
|
|
56
|
+
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.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## The PDD Mental Model
|
|
61
|
+
|
|
62
|
+
- One prompt typically maps to one code file or narrowly scoped module.
|
|
63
|
+
- You explicitly curate the context to place in the model’s window (don’t “dump the repo”).
|
|
64
|
+
- Change behavior by editing the prompt; re‑generate the file; run crash/verify/test/fix; then update the prompt with learnings.
|
|
65
|
+
- Keep the “dev unit” synchronized: prompt + generated code + minimal runnable example + tests.
|
|
66
|
+
|
|
67
|
+
Key principles: everything is explicit, prompts are the programming language, and you regenerate rather than patch.
|
|
68
|
+
|
|
69
|
+
Dev Unit (Prompt with Code, Example, Test):
|
|
70
|
+
|
|
71
|
+
```mermaid
|
|
72
|
+
flowchart TB
|
|
73
|
+
P[Prompt]
|
|
74
|
+
C[Code]
|
|
75
|
+
E[Example]
|
|
76
|
+
T[Tests]
|
|
77
|
+
|
|
78
|
+
P --> C
|
|
79
|
+
P --> E
|
|
80
|
+
P --> T
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Notes:
|
|
84
|
+
- The prompt defines intent. Code, example, and tests are generated artifacts.
|
|
85
|
+
- Regenerate rather than patch; keep tests accumulating over time.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
<a name="automated-grounding"></a>
|
|
90
|
+
## Automated Grounding (PDD Cloud)
|
|
91
|
+
|
|
92
|
+
Unlike standard LLM interactions where every request is a blank slate, PDD Cloud uses **Automated Grounding** to prevent "implementation drift."
|
|
93
|
+
|
|
94
|
+
### How It Works
|
|
95
|
+
|
|
96
|
+
When you run `pdd generate`, the system:
|
|
97
|
+
1. Embeds your prompt into a vector
|
|
98
|
+
2. Searches for similar prompts in the cloud database (cosine similarity)
|
|
99
|
+
3. Auto-injects the closest (prompt, code) pair as a few-shot example
|
|
100
|
+
|
|
101
|
+
**This is automatic.** You don't configure it. As you edit your prompt:
|
|
102
|
+
- The embedding changes
|
|
103
|
+
- Different examples may be retrieved
|
|
104
|
+
- Generation naturally adapts to your prompt's content
|
|
105
|
+
|
|
106
|
+
On first generation: Similar existing modules in your project provide grounding.
|
|
107
|
+
On re-generation: Your prior successful generation is typically the closest match.
|
|
108
|
+
|
|
109
|
+
### Why This Matters for Prompt Writing
|
|
110
|
+
|
|
111
|
+
- **Your prompt wording affects grounding.** Similar prompts retrieve similar examples.
|
|
112
|
+
- **Implementation patterns are handled automatically.** Grounding provides structural consistency from similar modules (class vs functional, helper patterns, etc.).
|
|
113
|
+
- **Prompts can be minimal.** Focus on requirements; grounding handles implementation patterns.
|
|
114
|
+
|
|
115
|
+
*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.*
|
|
116
|
+
|
|
117
|
+
> **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.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Grounding Overrides: Pin & Exclude (PDD Cloud)
|
|
122
|
+
|
|
123
|
+
For users with PDD Cloud access, you can override automatic grounding using XML tags:
|
|
124
|
+
|
|
125
|
+
**`<pin>module_name</pin>`** — Force a specific example to always be included
|
|
126
|
+
- Use case: Ensure a critical module always follows a "golden" pattern
|
|
127
|
+
- Use case: Bootstrap a new module with a specific style
|
|
128
|
+
|
|
129
|
+
**`<exclude>module_name</exclude>`** — Block a specific example(s) from being retrieved
|
|
130
|
+
- Use case: Escape an old pattern that's pulling generation in the wrong direction
|
|
131
|
+
- Use case: Intentionally break from established patterns for a redesign
|
|
132
|
+
|
|
133
|
+
These tags are processed by the preprocessor (like `<include>`) and removed before the LLM sees the prompt.
|
|
134
|
+
|
|
135
|
+
**Most prompts don't need these.** Automatic grounding works well for:
|
|
136
|
+
- Standard modules with similar existing examples
|
|
137
|
+
- Re-generations of established modules
|
|
138
|
+
- Modules following common project patterns
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Anatomy of a Good PDD Prompt
|
|
143
|
+
|
|
144
|
+
A well-designed prompt contains **only what can't be handled elsewhere**. With cloud grounding and accumulated tests, prompts can be minimal.
|
|
145
|
+
|
|
146
|
+
### Required Sections
|
|
147
|
+
|
|
148
|
+
1. **Role and scope** (1-2 sentences): What this module does
|
|
149
|
+
2. **Requirements** (5-10 items): Functional and non-functional specs
|
|
150
|
+
3. **Dependencies** (via `<include>`): Only external or critical interfaces
|
|
151
|
+
|
|
152
|
+
### Optional Sections
|
|
153
|
+
|
|
154
|
+
4. **Instructions**: Only if default behavior needs overriding
|
|
155
|
+
5. **Deliverables**: Only if non-obvious
|
|
156
|
+
|
|
157
|
+
### What NOT to Include
|
|
158
|
+
|
|
159
|
+
- **Coding style** (naming, formatting, imports) → Handled by shared preamble
|
|
160
|
+
- **Implementation patterns** (class structure, helpers) → Handled by grounding
|
|
161
|
+
- **Every edge case** → Handled by accumulated tests
|
|
162
|
+
- **Implementation steps** → Let the LLM decide (unless critical)
|
|
163
|
+
|
|
164
|
+
### Target Size: Prompt-to-Code Ratio
|
|
165
|
+
|
|
166
|
+
Aim for **10-30%** of your expected code size:
|
|
167
|
+
|
|
168
|
+
| Ratio | Meaning |
|
|
169
|
+
|-------|---------|
|
|
170
|
+
| **< 10%** | Too vague—missing contracts, error handling, or key constraints |
|
|
171
|
+
| **10-30%** | Just right—requirements and contracts without implementation details |
|
|
172
|
+
| **> 50%** | Too detailed—prompt is doing preamble's or grounding's job |
|
|
173
|
+
|
|
174
|
+
If your prompt exceeds 30%, ask: Am I specifying things that preamble, grounding, or tests should handle?
|
|
175
|
+
|
|
176
|
+
**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.
|
|
177
|
+
|
|
178
|
+
See pdd/pdd/templates/generic/generate_prompt.prompt for a concrete scaffold.
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## Prompt Syntax Essentials
|
|
183
|
+
|
|
184
|
+
These patterns are used across prompts in this repo:
|
|
185
|
+
|
|
186
|
+
- Preamble and role: start with a concise, authoritative description of the task and audience (e.g., “You are an expert Python engineer…”).
|
|
187
|
+
- Includes for context: bring only what the model needs.
|
|
188
|
+
- 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).
|
|
189
|
+
- Multiple: `<include-many>path1, path2, …</include-many>`
|
|
190
|
+
- Grouping: wrap includes in a semantic tag to name the dependency or file they represent, for example:
|
|
191
|
+
```xml
|
|
192
|
+
<render_js>
|
|
193
|
+
<include>src/render.js</include>
|
|
194
|
+
</render_js>
|
|
195
|
+
```
|
|
196
|
+
- When including larger files inline for clarity, wrap with opening/closing tags named after the file, e.g. `<render.js>…</render.js>`.
|
|
197
|
+
- Note: `<include>`, `<include-many>`, `<shell>`, and `<web>` inside fenced code blocks (``` or ~~~) or inline backticks are treated as literal text.
|
|
198
|
+
- Inputs/outputs: state them explicitly (names, types, shapes). Prompts should define Inputs/Outputs and steps clearly.
|
|
199
|
+
- 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.
|
|
200
|
+
- Constraints: specify style, performance targets, security, and error handling.
|
|
201
|
+
- Environment: reference required env vars (e.g., `PDD_PATH`) when reading data files.
|
|
202
|
+
|
|
203
|
+
Tip: Prefer small, named sections using XML‑style tags to make context scannable and deterministic.
|
|
204
|
+
|
|
205
|
+
### Special XML Tags: pdd, shell, web
|
|
206
|
+
|
|
207
|
+
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.
|
|
208
|
+
|
|
209
|
+
- `<pdd>…</pdd>`
|
|
210
|
+
- Purpose: human‑only comment. Removed entirely during preprocessing.
|
|
211
|
+
- Use: inline rationale or notes that should not reach the model.
|
|
212
|
+
- Example: `Before step X <pdd>explain why we do this here</pdd>`
|
|
213
|
+
|
|
214
|
+
- `<shell>…</shell>`
|
|
215
|
+
- Purpose: run a shell command and inline stdout at that position.
|
|
216
|
+
- Behavior: executes during non‑recursive preprocessing; on non‑zero exit, inserts a bracketed error with the exit code instead of failing the pipeline.
|
|
217
|
+
- Example: `<shell>git config --get user.name</shell>`
|
|
218
|
+
|
|
219
|
+
- `<web>URL</web>`
|
|
220
|
+
- Purpose: fetch the page (via Firecrawl) and inline the markdown content.
|
|
221
|
+
- Behavior: executes during non‑recursive preprocessing; on failure, inserts a bracketed error note.
|
|
222
|
+
- Example: `<web>https://docs.litellm.ai/docs/completion/json_mode</web>`
|
|
223
|
+
|
|
224
|
+
> ⚠️ **Warning: Non-Deterministic Tags**
|
|
225
|
+
>
|
|
226
|
+
> `<shell>` and `<web>` introduce **non-determinism**:
|
|
227
|
+
> - `<shell>` output varies by environment (different machines, different results)
|
|
228
|
+
> - `<web>` content changes over time (same URL, different content)
|
|
229
|
+
>
|
|
230
|
+
> **Impact:** Same prompt file → different generations on different machines/times
|
|
231
|
+
>
|
|
232
|
+
> **Prefer instead:** Capture output to a static file, then `<include>` that file. This ensures reproducible regeneration.
|
|
233
|
+
|
|
234
|
+
Use these tags sparingly. When you must use them, prefer stable commands with bounded output (e.g., `head -n 20` in `<shell>`).
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Architecture Metadata Tags
|
|
239
|
+
|
|
240
|
+
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.
|
|
241
|
+
|
|
242
|
+
### Tag Format
|
|
243
|
+
|
|
244
|
+
Place architecture metadata tags at the **top of your prompt file** (after any `<include>` directives but before the main content):
|
|
245
|
+
|
|
246
|
+
```xml
|
|
247
|
+
<pdd-reason>Brief description of module's purpose (60-120 chars)</pdd-reason>
|
|
248
|
+
|
|
249
|
+
<pdd-interface>
|
|
250
|
+
{
|
|
251
|
+
"type": "module",
|
|
252
|
+
"module": {
|
|
253
|
+
"functions": [
|
|
254
|
+
{"name": "function_name", "signature": "(...)", "returns": "Type"}
|
|
255
|
+
]
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
</pdd-interface>
|
|
259
|
+
|
|
260
|
+
<pdd-dependency>dependency_prompt_1.prompt</pdd-dependency>
|
|
261
|
+
<pdd-dependency>dependency_prompt_2.prompt</pdd-dependency>
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Tag Reference
|
|
265
|
+
|
|
266
|
+
**`<pdd-reason>`**
|
|
267
|
+
- **Purpose**: One-line description of why this module exists
|
|
268
|
+
- **Maps to**: `architecture.json["reason"]`
|
|
269
|
+
- **Format**: Single line string (recommended 60-120 characters)
|
|
270
|
+
- **Example**: `<pdd-reason>Provides unified LLM invocation across all PDD operations.</pdd-reason>`
|
|
271
|
+
|
|
272
|
+
**`<pdd-interface>`**
|
|
273
|
+
- **Purpose**: JSON describing the module's public API (functions, commands, pages)
|
|
274
|
+
- **Maps to**: `architecture.json["interface"]`
|
|
275
|
+
- **Format**: Valid JSON matching one of four interface types (see below)
|
|
276
|
+
- **Example**:
|
|
277
|
+
```xml
|
|
278
|
+
<pdd-interface>
|
|
279
|
+
{
|
|
280
|
+
"type": "module",
|
|
281
|
+
"module": {
|
|
282
|
+
"functions": [
|
|
283
|
+
{"name": "llm_invoke", "signature": "(prompt, strength, ...)", "returns": "Dict"}
|
|
284
|
+
]
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
</pdd-interface>
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
**`<pdd-dependency>`**
|
|
291
|
+
- **Purpose**: References other prompt files this module depends on
|
|
292
|
+
- **Maps to**: `architecture.json["dependencies"]` array
|
|
293
|
+
- **Format**: Prompt filename (e.g., `llm_invoke_python.prompt`)
|
|
294
|
+
- **Multiple tags**: Use one `<pdd-dependency>` tag per dependency
|
|
295
|
+
- **Example**:
|
|
296
|
+
```xml
|
|
297
|
+
<pdd-dependency>llm_invoke_python.prompt</pdd-dependency>
|
|
298
|
+
<pdd-dependency>path_resolution_python.prompt</pdd-dependency>
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### Interface Types
|
|
302
|
+
|
|
303
|
+
The `<pdd-interface>` tag supports four interface types, matching the architecture.json schema:
|
|
304
|
+
|
|
305
|
+
**Module Interface** (Python modules with functions):
|
|
306
|
+
```json
|
|
307
|
+
{
|
|
308
|
+
"type": "module",
|
|
309
|
+
"module": {
|
|
310
|
+
"functions": [
|
|
311
|
+
{"name": "func_name", "signature": "(arg1, arg2)", "returns": "Type"}
|
|
312
|
+
]
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
**CLI Interface** (Command-line interfaces):
|
|
318
|
+
```json
|
|
319
|
+
{
|
|
320
|
+
"type": "cli",
|
|
321
|
+
"cli": {
|
|
322
|
+
"commands": [
|
|
323
|
+
{"name": "cmd_name", "description": "What it does"}
|
|
324
|
+
]
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
**Command Interface** (PDD commands):
|
|
330
|
+
```json
|
|
331
|
+
{
|
|
332
|
+
"type": "command",
|
|
333
|
+
"command": {
|
|
334
|
+
"commands": [
|
|
335
|
+
{"name": "cmd_name", "description": "What it does"}
|
|
336
|
+
]
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
**Frontend Interface** (UI pages):
|
|
342
|
+
```json
|
|
343
|
+
{
|
|
344
|
+
"type": "frontend",
|
|
345
|
+
"frontend": {
|
|
346
|
+
"pages": [
|
|
347
|
+
{"name": "page_name", "route": "/path"}
|
|
348
|
+
]
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### Sync Workflow
|
|
354
|
+
|
|
355
|
+
1. **Add/edit tags** in your prompt files using the format above
|
|
356
|
+
2. **Click "Sync from Prompt"** in the PDD Connect Architecture page (or call the API endpoint)
|
|
357
|
+
3. **Tags automatically update** `architecture.json` with your changes
|
|
358
|
+
4. **Architecture visualization** reflects the updated dependencies and interfaces
|
|
359
|
+
|
|
360
|
+
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.
|
|
361
|
+
|
|
362
|
+
### Validation
|
|
363
|
+
|
|
364
|
+
Validation is **lenient**:
|
|
365
|
+
- Missing tags are OK - only fields with tags get updated
|
|
366
|
+
- Malformed XML/JSON is skipped without blocking sync
|
|
367
|
+
- Circular dependencies are detected and prevent invalid updates
|
|
368
|
+
- Missing dependency files generate warnings but don't block sync
|
|
369
|
+
|
|
370
|
+
### Best Practices
|
|
371
|
+
|
|
372
|
+
**Keep `<pdd-reason>` concise** (60-120 chars)
|
|
373
|
+
- Good: "Provides unified LLM invocation across all PDD operations."
|
|
374
|
+
- 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..."
|
|
375
|
+
|
|
376
|
+
**Use prompt filenames for dependencies**, not module names
|
|
377
|
+
- Correct: `<pdd-dependency>llm_invoke_python.prompt</pdd-dependency>`
|
|
378
|
+
- Wrong: `<pdd-dependency>pdd.llm_invoke</pdd-dependency>`
|
|
379
|
+
- Wrong: `<pdd-dependency>context/example.py</pdd-dependency>`
|
|
380
|
+
|
|
381
|
+
**Validate interface JSON before committing**
|
|
382
|
+
- Use a JSON validator to check syntax
|
|
383
|
+
- Ensure `type` field matches one of: `module`, `cli`, `command`, `frontend`
|
|
384
|
+
- Include required nested keys (`functions`, `commands`, or `pages`)
|
|
385
|
+
|
|
386
|
+
**Run "Sync All" after bulk prompt updates**
|
|
387
|
+
- If you've edited multiple prompts, sync all at once
|
|
388
|
+
- Review the validation results for circular dependencies
|
|
389
|
+
- Fix any warnings before committing changes
|
|
390
|
+
|
|
391
|
+
### Relationship to Other Tags
|
|
392
|
+
|
|
393
|
+
**`<pdd-dependency>` vs `<include>`**:
|
|
394
|
+
- `<pdd-dependency>`: Declares architectural dependency (updates `architecture.json`)
|
|
395
|
+
- `<include>`: Injects content into prompt for LLM context (does NOT affect architecture)
|
|
396
|
+
- Use both when appropriate - they serve different purposes
|
|
397
|
+
|
|
398
|
+
**`<pdd-*>` tags vs `<pdd>` comments**:
|
|
399
|
+
- `<pdd-reason>`, `<pdd-interface>`, `<pdd-dependency>`: Metadata tags (processed by sync tool)
|
|
400
|
+
- `<pdd>...</pdd>`: Human-only comments (removed by preprocessor, never reach LLM)
|
|
401
|
+
- Both are valid PDD directives with different purposes
|
|
402
|
+
|
|
403
|
+
### Example: Complete Prompt with Metadata Tags
|
|
404
|
+
|
|
405
|
+
See `docs/examples/prompt_with_metadata.prompt` for a full example showing all three metadata tags in context.
|
|
406
|
+
|
|
407
|
+
---
|
|
408
|
+
|
|
409
|
+
## Advanced Tips
|
|
410
|
+
|
|
411
|
+
### Shared Preamble for Consistency
|
|
412
|
+
|
|
413
|
+
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.
|
|
414
|
+
|
|
415
|
+
### Automatic Update Propagation via Includes
|
|
416
|
+
|
|
417
|
+
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.
|
|
418
|
+
|
|
419
|
+
Use this pattern when:
|
|
420
|
+
- **Authoritative documentation exists elsewhere** (e.g., a README that defines environment variables, API contracts, or configuration options). Include it rather than duplicating the content.
|
|
421
|
+
- **Shared constraints evolve** (e.g., coding standards, security policies). A single edit to the preamble file updates all prompts.
|
|
422
|
+
- **Interface definitions change** (e.g., a dependency's example file). Prompts consuming that example stay current.
|
|
423
|
+
|
|
424
|
+
*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`).
|
|
425
|
+
|
|
426
|
+
### Positive over Negative Constraints
|
|
427
|
+
|
|
428
|
+
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.
|
|
429
|
+
|
|
430
|
+
### Positioning Critical Instructions (Hierarchy of Attention)
|
|
431
|
+
|
|
432
|
+
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.
|
|
433
|
+
|
|
434
|
+
### Command-Specific Context Files
|
|
435
|
+
|
|
436
|
+
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.
|
|
437
|
+
|
|
438
|
+
**`context/test.prompt`** is particularly important:
|
|
439
|
+
- Defines testing conventions, frameworks, and patterns for your project
|
|
440
|
+
- Included automatically when running `pdd test` (alongside the module prompt and generated code)
|
|
441
|
+
- Tests accumulate over time via `--merge` as bugs are found
|
|
442
|
+
- Tests persist when the module prompt changes—only code is regenerated, not tests
|
|
443
|
+
- This ensures tests remain stable "permanent assets" while code can be freely regenerated
|
|
444
|
+
|
|
445
|
+
---
|
|
446
|
+
|
|
447
|
+
## Why PDD Scales to Large Codebases
|
|
448
|
+
|
|
449
|
+
- Explicit, curated context: use minimal examples and targeted includes instead of dumping source, reducing tokens and confusion.
|
|
450
|
+
- Modular dev units: one prompt per file/module constrains scope, enabling independent regeneration and parallel work.
|
|
451
|
+
- Batch, reproducible flow: eliminate long chat histories; regeneration avoids patch accumulation and incoherent diffs.
|
|
452
|
+
- Accumulating tests: protect behavior across wide regenerations and refactors; failures localize issues quickly.
|
|
453
|
+
- Single source of truth: prompts unify intent and dependencies, improving cross‑team coordination and reducing drift.
|
|
454
|
+
- 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.
|
|
455
|
+
|
|
456
|
+
### Tests as Generation Context
|
|
457
|
+
|
|
458
|
+
A key PDD feature: existing tests are automatically included as context when generating code. This means:
|
|
459
|
+
|
|
460
|
+
- The LLM sees the test file and knows what behaviors must be preserved
|
|
461
|
+
- Generated code is constrained to pass existing tests
|
|
462
|
+
- New tests accumulate over time, progressively constraining future generations
|
|
463
|
+
- This creates a "ratchet effect" - each bug fix adds a test, preventing regression
|
|
464
|
+
|
|
465
|
+
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.
|
|
466
|
+
|
|
467
|
+
```mermaid
|
|
468
|
+
flowchart LR
|
|
469
|
+
subgraph Assets
|
|
470
|
+
P[Module Prompt] --> G[pdd generate]
|
|
471
|
+
T[Existing Tests] --> G
|
|
472
|
+
G --> C[Generated Code]
|
|
473
|
+
end
|
|
474
|
+
|
|
475
|
+
subgraph Accumulation
|
|
476
|
+
BUG[Bug Found] --> NT[New Test Written]
|
|
477
|
+
NT --> T
|
|
478
|
+
end
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
---
|
|
482
|
+
|
|
483
|
+
Patch vs PDD at Scale (diagram):
|
|
484
|
+
|
|
485
|
+
```mermaid
|
|
486
|
+
flowchart LR
|
|
487
|
+
subgraph Patching
|
|
488
|
+
C0[Codebase] --> P0[Chat prompt]
|
|
489
|
+
P0 --> D0[Local diff]
|
|
490
|
+
D0 --> C0
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
subgraph PDD
|
|
494
|
+
PG[Prompts graph] --> GZ[Batch regenerate]
|
|
495
|
+
GZ --> CM[Code modules]
|
|
496
|
+
CM --> XT[Examples and Tests]
|
|
497
|
+
XT --> UP[Update prompts]
|
|
498
|
+
UP --> PG
|
|
499
|
+
end
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
---
|
|
503
|
+
|
|
504
|
+
## The Three Pillars of PDD Generation
|
|
505
|
+
|
|
506
|
+
Understanding how prompts, grounding, and tests work together is key to writing minimal, effective prompts.
|
|
507
|
+
|
|
508
|
+
| Pillar | What It Provides | Maintained By |
|
|
509
|
+
|--------|-----------------|---------------|
|
|
510
|
+
| **Prompt** | Requirements and constraints (WHAT) | Developer (explicit) |
|
|
511
|
+
| **Grounding** | Implementation patterns (HOW) | System (automatic, Cloud) |
|
|
512
|
+
| **Tests** | Behavioral correctness | Accumulated over time |
|
|
513
|
+
|
|
514
|
+
### How They Interact
|
|
515
|
+
|
|
516
|
+
- **Prompt** defines WHAT → "validate user input, return errors"
|
|
517
|
+
- **Grounding** defines HOW → class structure, helper patterns (from similar modules)
|
|
518
|
+
- **Tests** define CORRECTNESS → edge cases discovered through bugs
|
|
519
|
+
|
|
520
|
+
### Conflict Resolution
|
|
521
|
+
|
|
522
|
+
- **Tests override grounding**: If a test requires new behavior, generation must satisfy it
|
|
523
|
+
- **Explicit requirements override grounding**: If prompt says "use functional style", that overrides OOP examples in grounding
|
|
524
|
+
- **Grounding fills gaps**: Everything not specified in prompt or constrained by tests
|
|
525
|
+
|
|
526
|
+
### Why Prompts Can Be Minimal
|
|
527
|
+
|
|
528
|
+
You don't need to specify:
|
|
529
|
+
- **Coding style** → preamble provides it
|
|
530
|
+
- **Implementation patterns** → grounding provides them
|
|
531
|
+
- **Edge cases** → tests encode them
|
|
532
|
+
|
|
533
|
+
You only specify:
|
|
534
|
+
- What the module does
|
|
535
|
+
- What contracts it must satisfy
|
|
536
|
+
- What constraints apply
|
|
537
|
+
|
|
538
|
+
---
|
|
539
|
+
|
|
540
|
+
## Example (Minimal, Python)
|
|
541
|
+
|
|
542
|
+
This simplified example illustrates a minimal functional prompt:
|
|
543
|
+
|
|
544
|
+
```text
|
|
545
|
+
% You are an expert Python engineer. Your goal is to write a function `get_extension` that returns the file extension for a given language.
|
|
546
|
+
|
|
547
|
+
<include>context/python_preamble.prompt</include>
|
|
548
|
+
|
|
549
|
+
% Inputs/Outputs
|
|
550
|
+
Input: language (str), like "Python" or "Makefile".
|
|
551
|
+
Output: str file extension (e.g., ".py"), or "" if unknown.
|
|
552
|
+
|
|
553
|
+
% Data
|
|
554
|
+
The CSV at $PDD_PATH/data/language_format.csv contains: language,comment,extension
|
|
555
|
+
|
|
556
|
+
% Steps
|
|
557
|
+
1) Load env var PDD_PATH and read the CSV
|
|
558
|
+
2) Normalize language case
|
|
559
|
+
3) Lookup extension
|
|
560
|
+
4) Return "" if not found or invalid
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
This style:
|
|
564
|
+
- Declares role and outcome
|
|
565
|
+
- Specifies IO, data sources, and steps
|
|
566
|
+
- Uses an `<include>` to pull a shared preamble
|
|
567
|
+
|
|
568
|
+
---
|
|
569
|
+
|
|
570
|
+
## Scoping & Modularity
|
|
571
|
+
|
|
572
|
+
- One prompt → one file/module. If a prompt gets too large or brittle, split it into smaller prompts that compose via explicit interfaces.
|
|
573
|
+
- Treat examples as interfaces: create a minimal runnable example demonstrating how the module is meant to be used.
|
|
574
|
+
- 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)”.
|
|
575
|
+
|
|
576
|
+
---
|
|
577
|
+
|
|
578
|
+
## Writing Effective Requirements
|
|
579
|
+
|
|
580
|
+
Requirements are the core of your prompt. Everything else is handled automatically by grounding and tests.
|
|
581
|
+
|
|
582
|
+
### Structure (aim for 5-10 items)
|
|
583
|
+
|
|
584
|
+
1. **Primary function**: What does this module do? (one sentence)
|
|
585
|
+
2. **Input contract**: Types, validation rules, what's accepted
|
|
586
|
+
3. **Output contract**: Types, error conditions, return values
|
|
587
|
+
4. **Key invariants**: What must always be true
|
|
588
|
+
5. **Performance constraints**: If any (latency, memory, complexity)
|
|
589
|
+
6. **Security constraints**: If any (input sanitization, auth requirements)
|
|
590
|
+
|
|
591
|
+
### Each Requirement Should Be
|
|
592
|
+
|
|
593
|
+
- **Testable**: If you can't write a test for it, it's too vague
|
|
594
|
+
- **Behavioral**: Describe WHAT, not HOW
|
|
595
|
+
- **Unique**: Don't duplicate what preamble or grounding provides
|
|
596
|
+
|
|
597
|
+
### Example: Before/After
|
|
598
|
+
|
|
599
|
+
**Too detailed:**
|
|
600
|
+
```
|
|
601
|
+
1. Create a UserValidator class with validate() method
|
|
602
|
+
2. Use snake_case for all methods ← belongs in preamble
|
|
603
|
+
3. Import typing at the top ← belongs in preamble
|
|
604
|
+
4. Add docstrings to all public methods ← belongs in preamble
|
|
605
|
+
5. Handle null by returning ValidationError
|
|
606
|
+
6. Handle empty string by returning ValidationError
|
|
607
|
+
7. Handle whitespace-only by returning ValidationError
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
**Just right** (requirements only):
|
|
611
|
+
```
|
|
612
|
+
1. Function: validate_user(input) → ValidationResult
|
|
613
|
+
2. Input: Any type (untrusted user input)
|
|
614
|
+
3. Output: ValidationResult with is_valid bool and errors list
|
|
615
|
+
4. Invalid inputs: null, empty, whitespace-only, malformed
|
|
616
|
+
5. Performance: O(n) in input length
|
|
617
|
+
6. Security: No eval/exec, treat input as untrusted
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
Style conventions (2-4) belong in a shared preamble. Edge cases (5-7) can be collapsed into a single requirement.
|
|
621
|
+
|
|
622
|
+
**Requirements as Test Specifications:** Each requirement implies at least one test case. If you can't test a requirement, it's too vague.
|
|
623
|
+
|
|
624
|
+
---
|
|
625
|
+
|
|
626
|
+
## Prompt Abstraction Level
|
|
627
|
+
|
|
628
|
+

|
|
629
|
+
|
|
630
|
+
Write prompts at the level of *architecture, contract, and intent*, not line-by-line *implementation details*.
|
|
631
|
+
|
|
632
|
+
### Heuristics: Are You at the Right Level?
|
|
633
|
+
|
|
634
|
+
| Indicator | Too Detailed (> 30%) | Too Vague (< 10%) |
|
|
635
|
+
|-----------|----------------------|-------------------|
|
|
636
|
+
| **Content** | Specifying variable names, loop structures | Missing error handling strategy |
|
|
637
|
+
| **Style** | Dictating indentation, imports | No input/output types |
|
|
638
|
+
| **Result** | Prompt harder to maintain than code | Every generation is wildly different |
|
|
639
|
+
|
|
640
|
+
### If Your Prompt Is Too Long
|
|
641
|
+
|
|
642
|
+
Ask yourself:
|
|
643
|
+
- **Am I specifying coding style?** → Remove it (preamble handles this)
|
|
644
|
+
- **Am I specifying implementation patterns?** → Remove them (grounding handles this)
|
|
645
|
+
- **Am I listing every edge case?** → Remove them (tests handle this)
|
|
646
|
+
- **Is the module too big?** → Split into multiple prompts
|
|
647
|
+
|
|
648
|
+
### Examples
|
|
649
|
+
|
|
650
|
+
- **Too Vague:** "Create a user page." (Model guesses everything; unrepeatable)
|
|
651
|
+
- **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)
|
|
652
|
+
- **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."
|
|
653
|
+
|
|
654
|
+
**Rule of Thumb:** Focus on **Interfaces**, **Invariants**, and **Outcomes**. Let the preamble handle coding style; let grounding handle implementation patterns.
|
|
655
|
+
|
|
656
|
+
---
|
|
657
|
+
|
|
658
|
+
## Dependencies
|
|
659
|
+
|
|
660
|
+
### When to Use `<include>`
|
|
661
|
+
|
|
662
|
+
Include dependencies explicitly when:
|
|
663
|
+
- **External libraries** not in your grounding history
|
|
664
|
+
- **Critical interfaces** that must be exact
|
|
665
|
+
- **New modules** with no similar examples in grounding
|
|
666
|
+
|
|
667
|
+
```xml
|
|
668
|
+
<billing_service>
|
|
669
|
+
<include>context/billing_service_example.py</include>
|
|
670
|
+
</billing_service>
|
|
671
|
+
```
|
|
672
|
+
|
|
673
|
+
### When to Rely on Grounding
|
|
674
|
+
|
|
675
|
+
If you've successfully generated code that uses a dependency before, grounding often suffices—the usage pattern is already in the cloud database.
|
|
676
|
+
|
|
677
|
+
**Prefer explicit `<include>` for:** External APIs, critical contracts, cross-team interfaces
|
|
678
|
+
**Rely on grounding for:** Internal modules with established patterns
|
|
679
|
+
|
|
680
|
+
### Token Efficiency
|
|
681
|
+
|
|
682
|
+
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.
|
|
683
|
+
|
|
684
|
+
```mermaid
|
|
685
|
+
flowchart LR
|
|
686
|
+
subgraph Module_B
|
|
687
|
+
PB[Prompt B] --> GB[Generate] --> CB[Code B]
|
|
688
|
+
CB --> EB[Example B]
|
|
689
|
+
end
|
|
690
|
+
|
|
691
|
+
subgraph Module_A
|
|
692
|
+
PA[Prompt A] --> GA[Generate] --> CA[Code A]
|
|
693
|
+
PA --> EB
|
|
694
|
+
end
|
|
695
|
+
|
|
696
|
+
EB --> CA
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
---
|
|
700
|
+
|
|
701
|
+
## Regenerate, Verify, Test, Update
|
|
702
|
+
|
|
703
|
+
**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.
|
|
704
|
+
|
|
705
|
+
The PDD workflow (see pdd/docs/whitepaper.md):
|
|
706
|
+
|
|
707
|
+
1) **Generate:** Fully regenerate (overwrite) the code module and its example.
|
|
708
|
+
2) **Crash → Verify:** Run the example. Fix immediate runtime errors.
|
|
709
|
+
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.*
|
|
710
|
+
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).
|
|
711
|
+
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**.
|
|
712
|
+
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.
|
|
713
|
+
6) **Update:** Once tests pass, back-propagate any final learnings into the prompt.
|
|
714
|
+
|
|
715
|
+
Key practice: Code and examples are ephemeral (regenerated); Tests and Prompts are permanent assets (accumulated and versioned).
|
|
716
|
+
|
|
717
|
+
**Important:** Tests ARE generated from the module prompt (plus code and `context/test.prompt`). The key distinction is their lifecycle:
|
|
718
|
+
- Code is regenerated on prompt changes; tests accumulate and persist
|
|
719
|
+
- Requirements implicitly define test coverage—each requirement implies at least one test
|
|
720
|
+
- Use `context/test.prompt` for project-wide test guidance (frameworks, patterns)
|
|
721
|
+
- Existing tests are included as context during code generation
|
|
722
|
+
- This creates a "ratchet effect" where each new test permanently constrains future generations
|
|
723
|
+
|
|
724
|
+
### Workflow Cheatsheet: Features vs. Bugs
|
|
725
|
+
|
|
726
|
+
| Task Type | Where to Start | The Workflow |
|
|
727
|
+
| :--- | :--- | :--- |
|
|
728
|
+
| **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. |
|
|
729
|
+
| **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). |
|
|
730
|
+
|
|
731
|
+
**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.
|
|
732
|
+
|
|
733
|
+
**Why?** Features represent *new intent* (Prompt). Bugs represent *missed intent* which must first be captured as a constraint (Test) before refining the definition (Prompt).
|
|
734
|
+
|
|
735
|
+
### When to Update the Prompt (and When Not To)
|
|
736
|
+
|
|
737
|
+
After a successful fix, ask: "Where should this knowledge live?"
|
|
738
|
+
|
|
739
|
+
| Knowledge Type | Where It Lives | Update Prompt? |
|
|
740
|
+
|---------------|----------------|----------------|
|
|
741
|
+
| New edge case behavior | Test file | **No** |
|
|
742
|
+
| Implementation pattern fix | Grounding (auto-captured) | **No** |
|
|
743
|
+
| Missing requirement | Prompt | **Yes** |
|
|
744
|
+
| Wrong constraint | Prompt | **Yes** |
|
|
745
|
+
| Security/compliance rule | Prompt or preamble | **Yes** |
|
|
746
|
+
|
|
747
|
+
**Rule of thumb:** Update the prompt only for **intent changes**:
|
|
748
|
+
- "The module should also handle X" → Add requirement
|
|
749
|
+
- "The constraint was wrong" → Fix requirement
|
|
750
|
+
- "This security rule applies" → Add requirement
|
|
751
|
+
|
|
752
|
+
**Don't update for implementation fixes:**
|
|
753
|
+
- "There was a bug with null handling" → Add test; grounding captures the fix
|
|
754
|
+
- "The code style was inconsistent" → Update preamble (not prompt)
|
|
755
|
+
- "I prefer different variable names" → Update preamble/prompt
|
|
756
|
+
|
|
757
|
+
---
|
|
758
|
+
|
|
759
|
+
## PDD vs Interactive Agentic Coders (Claude Code, Cursor)
|
|
760
|
+
|
|
761
|
+
- Source of truth:
|
|
762
|
+
- PDD: the prompt is primary and versioned; code is regenerated output
|
|
763
|
+
- Interactive: the code is primary; prompts are ephemeral patch instructions
|
|
764
|
+
- Workflow:
|
|
765
|
+
- PDD: batch‑oriented, reproducible runs; explicit context via includes
|
|
766
|
+
- Interactive: live chat loops; implicit context; local diffs
|
|
767
|
+
- Scope:
|
|
768
|
+
- PDD: scoped to modules/files with clear interfaces; compose via examples
|
|
769
|
+
- Interactive: excels at small, local edits; struggles as scope and history grow
|
|
770
|
+
- Synchronization:
|
|
771
|
+
- PDD: update prompts after fixes; tests accumulate and protect behavior
|
|
772
|
+
- Interactive: prompt history rarely persists; documentation often drifts
|
|
773
|
+
|
|
774
|
+
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.
|
|
775
|
+
|
|
776
|
+
---
|
|
777
|
+
|
|
778
|
+
## Patch vs PDD: Concrete Examples
|
|
779
|
+
|
|
780
|
+
Patch‑style prompt (interactive agent):
|
|
781
|
+
|
|
782
|
+
```text
|
|
783
|
+
Fix this bug in src/utils/user.ts. In function parseUserId, passing null should return null instead of throwing.
|
|
784
|
+
|
|
785
|
+
Constraints:
|
|
786
|
+
- Change the minimum number of lines
|
|
787
|
+
- Do not alter the function signature or add new functions
|
|
788
|
+
- Keep existing imports and formatting
|
|
789
|
+
- Output a unified diff only
|
|
790
|
+
|
|
791
|
+
Snippet:
|
|
792
|
+
export function parseUserId(input: string) {
|
|
793
|
+
return input.trim().split(":")[1];
|
|
794
|
+
}
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
PDD‑style prompt (source of truth):
|
|
798
|
+
|
|
799
|
+
```text
|
|
800
|
+
% You are an expert TypeScript engineer. Create a module `user_id_parser` with a function `parseUserId` that safely extracts a user id.
|
|
801
|
+
|
|
802
|
+
% Role & Scope
|
|
803
|
+
A utility module responsible for parsing user identifiers from various inputs.
|
|
804
|
+
|
|
805
|
+
% Requirements
|
|
806
|
+
1) Function: `parseUserId(input: unknown): string | null`
|
|
807
|
+
2) Accepts strings like "user:abc123" and returns "abc123"
|
|
808
|
+
3) For null/undefined/non‑string, return null without throwing
|
|
809
|
+
4) Trim whitespace; reject blank ids as null
|
|
810
|
+
5) Log at debug level on parse failures; no exceptions for expected cases
|
|
811
|
+
6) Performance: O(n) in input length; no regex backtracking pitfalls
|
|
812
|
+
7) Security: no eval/exec; treat input as untrusted
|
|
813
|
+
|
|
814
|
+
% Dependencies
|
|
815
|
+
<logger>
|
|
816
|
+
<include>context/logger_example.ts</include>
|
|
817
|
+
</logger>
|
|
818
|
+
|
|
819
|
+
% Instructions
|
|
820
|
+
- Implement in `src/utils/user_id_parser.ts`
|
|
821
|
+
- Export `parseUserId`
|
|
822
|
+
- Add narrow helpers if needed; keep module cohesive
|
|
823
|
+
- Include basic JSDoc and simple debug logging hooks
|
|
824
|
+
```
|
|
825
|
+
|
|
826
|
+
Key differences:
|
|
827
|
+
- Patch prompt constrains a local edit and often asks for a diff. It assumes code is the source of truth.
|
|
828
|
+
- 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.
|
|
829
|
+
|
|
830
|
+
---
|
|
831
|
+
|
|
832
|
+
## Checklist: Before You Run `pdd generate`
|
|
833
|
+
|
|
834
|
+
### Must Have
|
|
835
|
+
- [ ] Module purpose is clear (1-2 sentences)
|
|
836
|
+
- [ ] Requirements are testable and behavioral (5-10 items)
|
|
837
|
+
- [ ] Dependencies included (if external or critical)
|
|
838
|
+
|
|
839
|
+
### For Established Modules
|
|
840
|
+
- [ ] Tests exist for known edge cases
|
|
841
|
+
- [ ] Previous generation was successful (grounding will use it)
|
|
842
|
+
|
|
843
|
+
### For New Modules
|
|
844
|
+
- [ ] Similar modules exist in codebase (grounding will find them)
|
|
845
|
+
- [ ] Or: Consider `<pin>` to reference a template module (Cloud)
|
|
846
|
+
|
|
847
|
+
### You Don't Need to Specify
|
|
848
|
+
- Coding style (preamble handles this)
|
|
849
|
+
- Implementation patterns (grounding handles this)
|
|
850
|
+
- Every edge case (tests handle this)
|
|
851
|
+
|
|
852
|
+
---
|
|
853
|
+
|
|
854
|
+
## Common Pitfalls (And Fixes)
|
|
855
|
+
|
|
856
|
+
- Too much context: prune includes; prefer targeted examples over entire files.
|
|
857
|
+
- Vague requirements: convert to explicit contracts, budgets, and behaviors.
|
|
858
|
+
- Mega‑prompts: split into smaller prompts (one per file/module) and compose.
|
|
859
|
+
- 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.
|
|
860
|
+
- Patching code directly: make the change in the prompt and regenerate; then `update` with learnings.
|
|
861
|
+
- Throwing away tests: keep and expand; they are your long‑term leverage.
|
|
862
|
+
|
|
863
|
+
---
|
|
864
|
+
|
|
865
|
+
## Naming & Conventions (This Repo)
|
|
866
|
+
|
|
867
|
+
- One prompt per module/file, named like `${BASENAME}_${LanguageOrFramework}.prompt` (see templates under `pdd/pdd/templates`).
|
|
868
|
+
- Follow codebase conventions from README.md for Python and TypeScript style.
|
|
869
|
+
- Use curated examples under `context/` to encode interfaces and behaviors.
|
|
870
|
+
|
|
871
|
+
---
|
|
872
|
+
|
|
873
|
+
## Final Notes
|
|
874
|
+
|
|
875
|
+
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.
|
|
876
|
+
|
|
877
|
+
</pdd_prompting_guide>
|
|
878
|
+
|
|
879
|
+
% Inputs
|
|
880
|
+
|
|
881
|
+
- GitHub Issue URL: {issue_url}
|
|
882
|
+
- Repository: {repo_owner}/{repo_name}
|
|
883
|
+
- Issue Number: {issue_number}
|
|
884
|
+
- Worktree Path: {worktree_path}
|
|
885
|
+
- Files Modified: {files_to_stage}
|
|
886
|
+
- Review Iteration: {review_iteration} of 5
|
|
887
|
+
|
|
888
|
+
% Issue Content
|
|
889
|
+
<issue_content>
|
|
890
|
+
{issue_content}
|
|
891
|
+
</issue_content>
|
|
892
|
+
|
|
893
|
+
% Previous Step Output
|
|
894
|
+
<step9_output>
|
|
895
|
+
{step9_output}
|
|
896
|
+
</step9_output>
|
|
897
|
+
|
|
898
|
+
% Previous Fix Attempts (if any)
|
|
899
|
+
<previous_fixes>
|
|
900
|
+
{previous_fixes}
|
|
901
|
+
</previous_fixes>
|
|
902
|
+
|
|
903
|
+
% Your Task
|
|
904
|
+
|
|
905
|
+
Thoroughly review all modified/created files for issues:
|
|
906
|
+
|
|
907
|
+
1. **Prompt Syntax Issues**
|
|
908
|
+
- Invalid `<include>` directives (file doesn't exist)
|
|
909
|
+
- Malformed XML-style tags
|
|
910
|
+
- Missing required sections (Goal, Role & Scope, Requirements, Deliverables)
|
|
911
|
+
- Unclosed tags or brackets
|
|
912
|
+
|
|
913
|
+
2. **PDD Convention Violations**
|
|
914
|
+
- Requirements not testable or behavioral
|
|
915
|
+
- Implementation details in prompts (should be WHAT, not HOW)
|
|
916
|
+
- Missing or incorrect dependencies
|
|
917
|
+
- Prompt too large (should be 10-30% of expected code size)
|
|
918
|
+
- Missing example file references
|
|
919
|
+
|
|
920
|
+
3. **Documentation Issues**
|
|
921
|
+
- Inconsistencies between prompt and README/docs
|
|
922
|
+
- Missing documentation for new functionality
|
|
923
|
+
- Outdated references to old step numbers or file names
|
|
924
|
+
- Broken links or references
|
|
925
|
+
|
|
926
|
+
4. **Logical Issues**
|
|
927
|
+
- Conflicting requirements
|
|
928
|
+
- Missing edge case handling
|
|
929
|
+
- Incomplete integration with existing modules
|
|
930
|
+
- Circular dependencies
|
|
931
|
+
|
|
932
|
+
5. **Style Issues**
|
|
933
|
+
- Inconsistent formatting
|
|
934
|
+
- Unclear or ambiguous wording
|
|
935
|
+
- Missing context for future maintainers
|
|
936
|
+
|
|
937
|
+
% Output
|
|
938
|
+
|
|
939
|
+
After completing your review, use `gh issue comment` to post your findings to issue #{issue_number}:
|
|
940
|
+
|
|
941
|
+
```
|
|
942
|
+
gh issue comment {issue_number} --repo {repo_owner}/{repo_name} --body "..."
|
|
943
|
+
```
|
|
944
|
+
|
|
945
|
+
**If issues found:**
|
|
946
|
+
```markdown
|
|
947
|
+
## Step 10: Issue Identification (Iteration {review_iteration}/5)
|
|
948
|
+
|
|
949
|
+
**Status:** Issues Found
|
|
950
|
+
|
|
951
|
+
### Issues to Fix
|
|
952
|
+
|
|
953
|
+
1. **[FILE]** `prompts/xxx_python.prompt` line 45
|
|
954
|
+
- **Type:** [Syntax | Convention | Documentation | Logic | Style]
|
|
955
|
+
- **Issue:** [Description of the problem]
|
|
956
|
+
- **Fix:** [What needs to be changed]
|
|
957
|
+
|
|
958
|
+
2. **[FILE]** `prompts/yyy_python.prompt`
|
|
959
|
+
- **Type:** [Type]
|
|
960
|
+
- **Issue:** [Description]
|
|
961
|
+
- **Fix:** [What needs to be changed]
|
|
962
|
+
|
|
963
|
+
3. **[FILE]** `README.md` section "Commands"
|
|
964
|
+
- **Type:** Documentation
|
|
965
|
+
- **Issue:** [Description]
|
|
966
|
+
- **Fix:** [What needs to be changed]
|
|
967
|
+
|
|
968
|
+
### Summary
|
|
969
|
+
Found {{N}} issues requiring fixes.
|
|
970
|
+
|
|
971
|
+
---
|
|
972
|
+
*Proceeding to Step 11: Fix Issues*
|
|
973
|
+
```
|
|
974
|
+
|
|
975
|
+
**If NO issues found:**
|
|
976
|
+
```markdown
|
|
977
|
+
## Step 10: Issue Identification (Iteration {review_iteration}/5)
|
|
978
|
+
|
|
979
|
+
**Status:** No Issues Found
|
|
980
|
+
|
|
981
|
+
### Review Summary
|
|
982
|
+
All modified files have been reviewed:
|
|
983
|
+
- `prompts/xxx_python.prompt` - :white_check_mark: Valid
|
|
984
|
+
- `prompts/yyy_python.prompt` - :white_check_mark: Valid
|
|
985
|
+
- `README.md` - :white_check_mark: Updated correctly
|
|
986
|
+
|
|
987
|
+
### Checks Passed
|
|
988
|
+
| Check | Status |
|
|
989
|
+
|-------|--------|
|
|
990
|
+
| Prompt syntax | :white_check_mark: Valid |
|
|
991
|
+
| PDD conventions | :white_check_mark: Followed |
|
|
992
|
+
| Documentation | :white_check_mark: Consistent |
|
|
993
|
+
| Logic | :white_check_mark: Sound |
|
|
994
|
+
|
|
995
|
+
---
|
|
996
|
+
*No issues found. Proceeding to Step 12: Create PR*
|
|
997
|
+
```
|
|
998
|
+
|
|
999
|
+
% Important
|
|
1000
|
+
|
|
1001
|
+
- Be thorough - this is the quality gate before creating a PR
|
|
1002
|
+
- Check EVERY file that was modified, not just prompts
|
|
1003
|
+
- Focus on issues that would cause problems, not minor style preferences
|
|
1004
|
+
- If this is iteration 2+, focus on checking if previous fixes were applied correctly
|
|
1005
|
+
- Output "No Issues Found" ONLY if everything is correct
|
|
1006
|
+
- The loop will continue until you output "No Issues Found" or iteration 5
|