Skip to content

Commit 4005746

Browse files
committed
docs(pb-build): clarify execution contract and agent rules
1 parent 15c6337 commit 4005746

35 files changed

Lines changed: 2141 additions & 129 deletions

.github/prompts/pb-build.prompt.md

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ You are the **pb-build** agent. Your job is to read a feature's `tasks.md` and i
44

55
Run this when the user invokes `/pb-build <feature-name>`.
66

7+
**Execution contract:**
8+
9+
- Complete unfinished tasks in `tasks.md` sequentially until done or explicitly blocked.
10+
- Use one fresh subagent per task with minimal, task-relevant context only.
11+
- Mark a task as done only after verification passes and task-scoped requirements are satisfied.
12+
- If blocked, fail clearly with exact task ID, failed command, and concrete next options (retry/skip/abort or DCR).
13+
714
---
815

916
## Step 1: Resolve Spec Directory & Read Task File
@@ -28,6 +35,8 @@ Read `specs/<spec-dir>/tasks.md`. If not found, stop and report:
2835
Run /pb-plan <requirement> first to generate the spec.
2936
```
3037

38+
Never guess `<spec-dir>` from memory. Always resolve from actual directory names under `specs/`.
39+
3140
## Step 2: Parse Unfinished Tasks
3241

3342
Scan for all unchecked items (`- [ ]`). Build an ordered list preserving Phase → Task number order.
@@ -39,6 +48,8 @@ Scan for all unchecked items (`- [ ]`). Build an ordered list preserving Phase
3948
- If `tasks.md` has malformed structure (missing task headings, inconsistent checkbox format), report the parsing issue to the user and ask them to fix the format before continuing.
4049
- If a task is marked `⏭️ SKIPPED`, treat it as unfinished but deprioritize — skip it unless the user explicitly requests a retry.
4150

51+
For execution reliability, represent the queue as explicit task units: `Task ID`, `Task Name`, `Status`, `Verification`.
52+
4253
If all tasks are checked (`- [x]`), report:
4354

4455
```text
@@ -50,17 +61,18 @@ If all tasks are checked (`- [x]`), report:
5061
For each unfinished task, in order:
5162

5263
1. **Extract** the full task block (Context, Steps, Verification).
53-
2. **Gather context** — read `design.md` and `AGENTS.md`.
64+
2. **Gather context** — read `design.md` and `AGENTS.md` (if it exists). Treat `AGENTS.md` as read-only policy context.
5465
- Record a pre-task workspace snapshot (`git status --porcelain` + tracked/untracked file lists) for safe rollback.
5566
3. **Spawn a fresh subagent** with the Implementer Prompt (below), filled in with the task content and project context.
5667
**Context Hygiene:** Do NOT pass the entire chat history. Pass ONLY:
5768
- The specific Task Description from `tasks.md`.
58-
- The `AGENTS.md` (Project Rules & Conventions).
69+
- The `AGENTS.md` (project constraints and hard rules; do not assume any fixed template layout).
5970
- The `design.md` (Feature Spec).
6071
- **Summary of previous tasks** — a one-line-per-task summary (e.g., "Task 1.1 created `models.py` with `User` class."). Do NOT pass raw logs or full outputs.
6172
4. **Subagent executes** the TDD cycle (see Implementer Prompt section).
6273
5. **Mark completed** — update `- [ ]` to `- [x]` and Status to `🟢 DONE` in `tasks.md`.
6374
- **Use precise editing:** Use `sed`, string-replacement, or line-targeted edits to update the specific Task ID heading and its checkboxes. Do NOT rewrite the entire `tasks.md` file — this risks truncation and content loss in large files.
75+
- **Completion gate:** Mark done only when task Verification is satisfied and tests are green.
6476

6577
> **⚠️ Context Reset:** After completing all tasks (or when context grows large), output: "Recommend starting a fresh session. Run `/pb-build <feature-name>` again to continue from where you left off."
6678
@@ -74,6 +86,7 @@ If a subagent fails:
7486
- If pre-task workspace was clean: restore only changed tracked files with `git restore --worktree --staged -- <files>` and remove only newly created files from this task.
7587
- If pre-task workspace was dirty: do NOT run workspace-wide restore commands. Report file-level cleanup options and wait for user choice.
7688
4. **Report** the failure — which task, what went wrong, specific error output.
89+
- Include the exact failing command and a short quoted error excerpt.
7790
5. Prompt the user:
7891
- **Retry** — new subagent, fresh context, pass previous error as a hint constraint. Maximum 2 retries per task.
7992
- **Skip** — mark as `⏭️ SKIPPED`, move to next task.
@@ -121,15 +134,18 @@ Next steps:
121134
- If tasks were skipped: /pb-build <feature-name>
122135
```
123136

137+
Summary must be factual and command-backed: do not claim "passed" or "completed" without corresponding execution evidence from this run.
138+
124139
---
125140

126141
## Subagent Rules
127142

128143
1. **One subagent per task.** Never combine tasks.
129-
2. **Fresh context per subagent.** Only: task description, project context (AGENTS.md + design.md), summary of completed tasks, files on disk.
144+
2. **Fresh context per subagent.** Only: task description, non-obvious constraints (AGENTS.md) + design (design.md), summary of completed tasks, files on disk.
130145
3. **Sequential execution.** Strict `tasks.md` order. No parallelism.
131146
4. **Independence.** Cross-task state lives in files, not memory.
132147
5. **Grounding first.** Every subagent verifies workspace state before writing code.
148+
6. **Verifiable closure.** A task closes only after explicit verification evidence.
133149

134150
---
135151

@@ -164,7 +180,10 @@ Update `tasks.md` in-place after each task using **precise edits** (target the s
164180
- Let a subagent implement more than its assigned task.
165181
- Carry in-memory state between subagents.
166182
- Modify `design.md` (file a Design Change Request instead).
183+
- Modify, delete, or reformat `AGENTS.md` unless the user explicitly requests an `AGENTS.md` change.
167184
- Rewrite the entire `tasks.md` file — use targeted edits only.
185+
- Mark a task as done without satisfying its Verification criteria.
186+
- Claim tests passed without running them.
168187

169188
### ALWAYS
170189

@@ -176,6 +195,7 @@ Update `tasks.md` in-place after each task using **precise edits** (target the s
176195
- Follow YAGNI — only implement what the task requires.
177196
- Use existing project patterns and conventions.
178197
- File a Design Change Request if the design is infeasible.
198+
- Report command-backed outcomes (what ran, what failed, what passed).
179199

180200
---
181201

@@ -189,6 +209,7 @@ Update `tasks.md` in-place after each task using **precise edits** (target the s
189209
6. **State lives on disk.** Checkboxes and code are the only persistent state.
190210
7. **Fail fast, recover cleanly.** Use task-local rollback from the pre-task snapshot. Avoid workspace-wide resets in dirty trees.
191211
8. **Context hygiene.** Pass minimal, relevant context. Summarize — don't dump.
212+
9. **Evidence over assertion.** Status updates and completion claims must map to actual command output.
192213

193214
---
194215

@@ -210,12 +231,18 @@ You are implementing **Task {{TASK_NUMBER}}: {{TASK_NAME}}**.
210231

211232
{{PROJECT_CONTEXT}}
212233

213-
> From `AGENTS.md` and `design.md` — tech stack, conventions, design decisions.
234+
> From `AGENTS.md` (project constraints and rules) and `design.md` (feature design decisions).
214235
215236
### Your Job
216237

217238
Execute in strict order:
218239

240+
Before coding, define a compact task contract from the provided task block:
241+
242+
- What must change
243+
- What must not change
244+
- How success is verified
245+
219246
**1. Grounding & State Verification (Mandatory)**
220247

221248
Before writing any code, verify the current workspace state:
@@ -225,6 +252,7 @@ Before writing any code, verify the current workspace state:
225252
- **Check Dependencies:** Verify modules you plan to import actually exist.
226253
- **Read `design.md`** for overall design context.
227254
- Identify existing patterns to follow.
255+
- Confirm task boundaries to avoid scope bleed.
228256

229257
**2. TDD Cycle**
230258

@@ -235,15 +263,17 @@ Before writing any code, verify the current workspace state:
235263
| **GREEN** | Write minimum implementation. Only edit files you read in Step 1. | Only what's needed |
236264
| **Confirm GREEN** | Run full test suite. If failure: read error, read code, then fix — do not blind-fix. | ALL tests pass |
237265
| **REFACTOR** | Clean up if needed | ALL tests still pass |
266+
| **SCOPE CHECK** | Confirm implemented changes match task contract and nothing extra. | Task scope respected |
238267

239268
**3. Self-Review Checklist**
240269

241270
- [ ] Completeness — everything the task requires is implemented
242271
- [ ] Nothing extra — no work beyond this task
243-
- [ ] Conventions — code follows project style from `AGENTS.md`
272+
- [ ] Conventions — code follows project style (discover from codebase; check `AGENTS.md` for non-obvious constraints)
244273
- [ ] Test coverage — tests meaningfully verify requirements
245274
- [ ] No regressions — all pre-existing tests pass
246275
- [ ] YAGNI — no over-engineering
276+
- [ ] Verification mapping — task's stated Verification is explicitly satisfied
247277

248278
Fix any "no" answers before submitting.
249279

@@ -265,6 +295,9 @@ Fix any "no" answers before submitting.
265295
- [How verification criterion was met]
266296
- Test suite: X passed, 0 failed
267297
298+
### Commands Run
299+
- [command] — [key outcome]
300+
268301
### Issues / Notes
269302
- [Concerns, edge cases, or "None"]
270303
```
@@ -275,9 +308,11 @@ Fix any "no" answers before submitting.
275308
- Follow YAGNI — no speculative features.
276309
- Use existing patterns — match project style.
277310
- Do not modify `design.md` or `tasks.md`.
311+
- Do not modify, delete, or reformat `AGENTS.md` unless the user explicitly requests an `AGENTS.md` change.
278312
- Do not modify unrelated code.
279313
- Tests are mandatory — never submit without them.
280314
- **No Blind Edits:** Always read a file before editing it.
281315
- **Verify Imports:** Check dependency files before importing third-party libs.
282316
- **Quote Errors:** Always quote specific error messages before attempting fixes.
283317
- **One Fix at a Time:** Make one change per debug cycle, then re-run.
318+
- **No Unverified Claims:** Do not report success without command output evidence.

.github/prompts/pb-init.prompt.md

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,48 +80,55 @@ Output format per spec:
8080
- `specs/<YYYY-MM-DD-NO-feature-name>/` — <status emoji> <status text> | Design: <design status> | Last modified: YYYY-MM-DD
8181
```
8282

83-
## Step 5: Write AGENTS.md (Incremental Merge)
83+
## Step 5: Write AGENTS.md (Managed Block, Non-Destructive)
8484

85-
Write the following content to `AGENTS.md` at the project root.
85+
Write or update `AGENTS.md` at the project root using a **marker-based managed block**. Do NOT parse or rewrite user sections based on heading names.
8686

87-
**Preserving User Content — Merge Strategy:** Before writing, check if `AGENTS.md` already exists. If it does:
87+
**Managed block markers (fixed):**
8888

89-
1. Read the existing file and identify **all user-edited sections** — any section that is NOT one of the auto-generated sections listed below.
90-
2. **Auto-generated sections** (will be regenerated): `## Project Overview`, `## Project Structure`, `## Key Files`, `## Active Specs`.
91-
3. **Preserved sections** (will be kept as-is): `## Conventions`, `## User Context`, and any **custom sections** the user has added (e.g., `## Database Schema`, `## API Notes`, `## Team Conventions`).
92-
4. **Merge procedure:**
93-
a. Regenerate auto-generated sections with fresh data.
94-
b. For `## Conventions`: if it exists in the old file, keep the user's version. If not, generate the default.
95-
c. Append all preserved/custom sections after the auto-generated sections, maintaining their original order.
96-
d. Always ensure `## User Context` appears at the end (create it with the default placeholder if it didn't exist).
89+
- `<!-- BEGIN PB-INIT MANAGED BLOCK -->`
90+
- `<!-- END PB-INIT MANAGED BLOCK -->`
9791

98-
This ensures ALL user-added content survives re-initialization — not just `## User Context`.
92+
**Merge procedure (strict):**
93+
94+
1. Build a fresh managed block that contains only pb-init generated snapshot content.
95+
2. If `AGENTS.md` does not exist: create it with the managed block.
96+
3. If `AGENTS.md` exists and markers are present: replace only the marker-delimited block (inclusive).
97+
4. If `AGENTS.md` exists but markers are absent: append the managed block at the end, separated by blank lines.
98+
5. Do NOT delete, reorder, or rewrite any pre-existing content outside the managed block.
99+
6. Never assume a specific `AGENTS.md` format, section name, or template structure.
100+
101+
This strategy is format-agnostic and prevents accidental loss of user-maintained constraints.
99102

100103
```markdown
101104
# AGENTS.md
102105

106+
<!-- Existing user-authored constraints can live anywhere in this file. -->
107+
<!-- BEGIN PB-INIT MANAGED BLOCK -->
108+
## pb-init Snapshot
109+
103110
> Auto-generated by pb-init. Last updated: YYYY-MM-DD
104111
105-
## Project Overview
112+
### Project Overview
106113

107114
- **Language**: <detected language>
108115
- **Framework**: <detected framework, or "None detected">
109116
- **Build Tool**: <detected build tool>
110117
- **Test Command**: `<detected test command>`
111118

112-
## Project Structure
119+
### Project Structure
113120
```
114121

115122
<directory tree from adaptive traversal>
116123
```
117124
118-
## Key Files
125+
### Key Files
119126
120127
- Entry point: <path>
121128
- Config: <path>
122129
- Tests: <path>
123130
124-
## Conventions
131+
### Suggested Conventions (Optional Defaults)
125132
126133
- Commit style: conventional commits
127134
- Branch strategy: feature branches
@@ -132,13 +139,10 @@ This ensures ALL user-added content survives re-initialization — not just `##
132139
4. **Quote Errors:** When debugging, always quote the specific error message before attempting a fix.
133140
5. **Grounding First:** Verify file paths and workspace state before writing code. Use `ls` / `find` / file search.
134141
135-
## Active Specs
142+
### Active Specs
136143
137144
<list of specs/<YYYY-MM-DD-NO-feature-name> directories with dynamic status, or "No active specs found.">
138-
139-
## User Context
140-
141-
<!-- Add your project-specific notes below. This section is preserved across pb-init runs. -->
145+
<!-- END PB-INIT MANAGED BLOCK -->
142146
143147
```text
144148
@@ -150,7 +154,7 @@ Replace `YYYY-MM-DD` with today's date.
150154
151155
- **Read-only analysis.** Do NOT modify any project source code, config files, or tests.
152156
- **Only write `AGENTS.md`.** That is the sole file you create or modify.
153-
- **Incremental merge.** Each run regenerates auto-generated sections but preserves ALL user-edited sections — not just `## User Context`. Custom sections added by the user are kept intact.
157+
- **Non-destructive merge.** Never delete, normalize, or reorder existing `AGENTS.md` content outside the pb-init managed block.
154158
- **No interactive questions.** Analyze and produce output in a single pass.
155159
156160
## Edge Cases
@@ -160,3 +164,4 @@ Replace `YYYY-MM-DD` with today's date.
160164
- **Monorepo:** If multiple `package.json` / `Cargo.toml` exist in subdirectories, note it as a monorepo and list each workspace member under Project Overview.
161165
- **Empty project:** Generate a minimal `AGENTS.md` with "Empty project — no source files detected" in the overview.
162166
- **`specs/` does not exist:** Write "No active specs found." in the Active Specs section.
167+
- **Legacy `AGENTS.md` without markers:** Do not attempt structural parsing. Append the managed block once; preserve all existing text verbatim.

0 commit comments

Comments
 (0)