Skip to content

Commit db46efd

Browse files
committed
docs(readme): update AGENTS.md merge strategy and pb-init behavior
1 parent f0d05b7 commit db46efd

13 files changed

Lines changed: 169 additions & 111 deletions

File tree

README.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pb-spec follows a **harness-first** philosophy: reliability comes from process d
2424
| [Reflexion](https://arxiv.org/abs/2303.11366) | Learn from failure signals via iterative retries | Retry/skip/abort and DCR flow in `pb-build` |
2525
| [Effective Harnesses for Long-Running Agents](https://www.anthropic.com/engineering/effective-harnesses-for-long-running-agents) | Grounding, context hygiene, recovery, observability | State checks, minimal context handoff, task-local rollback guidance |
2626
| [Building Effective Agents](https://www.anthropic.com/engineering/building-effective-agents) | Prefer simple composable workflows over framework complexity | Small adapter-based CLI + explicit workflow prompts |
27-
| [Stop Using /init for AGENTS.md](https://addyosmani.com/blog/agents-md/) | Prefer minimal AGENTS.md (only undiscoverable facts) | `/pb-init` audits repo and generates minimal AGENTS.md with strict three-part filter (not inferrable, operationally decisive, not guessable) |
27+
| [Stop Using /init for AGENTS.md](https://addyosmani.com/blog/agents-md/) | Keep AGENTS.md focused and maintainable | `/pb-init` updates a managed snapshot block in `AGENTS.md` while preserving all user-authored constraints outside that block |
2828

2929
### Practical Principles in pb-spec
3030

@@ -61,7 +61,7 @@ pb-spec init --ai claude # or: copilot, opencode, gemini, codex, all
6161
pb-spec init --ai all -g # install globally to each agent's home/config dir
6262

6363
# 2. Open the project in your AI coding assistant and use the installed commands/prompts:
64-
# /pb-init → Audit repo, produce minimal AGENTS.md (only undiscoverable facts)
64+
# /pb-init → Audit repo, append/update a managed AGENTS.md snapshot block (non-destructive)
6565
# /pb-plan Add WebSocket auth → Generate specs/YYYY-MM-DD-01-add-websocket-auth/
6666
# /pb-refine add-websocket-auth → (Optional) Refine design based on feedback
6767
# /pb-build add-websocket-auth → Implement tasks via TDD subagents
@@ -111,9 +111,20 @@ four agent skills that chain together:
111111
/pb-init → /pb-plan → [/pb-refine] → /pb-build
112112
```
113113

114-
### 1. `/pb-init` — AGENTS.md Audit & Minimization
114+
### 1. `/pb-init` — AGENTS.md Snapshot & Safe Merge
115115

116-
Audits your project and produces an **extremely minimal** `AGENTS.md` at the project root. Instead of dumping project overview info that agents can discover themselves, it applies a strict three-part filter: each entry must be (1) not inferrable from code, (2) operationally decisive, and (3) not guessable from industry conventions. Every entry in AGENTS.md represents a codebase smell — the goal is to fix root causes and drive AGENTS.md toward zero entries over time. **Preserves user-added context** across re-runs.
116+
Audits your project and writes a `pb-init` snapshot into `AGENTS.md` using managed markers:
117+
118+
- `<!-- BEGIN PB-INIT MANAGED BLOCK -->`
119+
- `<!-- END PB-INIT MANAGED BLOCK -->`
120+
121+
Merge behavior is non-destructive:
122+
123+
- If markers exist, only that managed block is replaced.
124+
- If markers do not exist, the managed block is appended.
125+
- All existing content outside the managed block is preserved verbatim.
126+
127+
This design avoids relying on any fixed `AGENTS.md` section layout and protects user-maintained constraints across re-runs.
117128

118129
### 2. `/pb-plan <requirement>` — Design & Task Planning
119130

@@ -125,21 +136,21 @@ specs/<YYYY-MM-DD-NO-feature-name>/
125136
└── tasks.md # Ordered implementation tasks (logical units of work)
126137
```
127138

128-
The spec directory follows the naming format `YYYY-MM-DD-NO-feature-name` (e.g., `2026-02-15-01-add-websocket-auth`). The feature-name part must be unique across all specs.
139+
The spec directory follows the naming format `YYYY-MM-DD-NO-feature-name` (e.g., `2026-02-15-01-add-websocket-auth`). The feature-name part must be unique across all specs. During planning, `AGENTS.md` is treated as read-only policy context (free-form, no fixed layout assumptions).
129140

130141
### 3. `/pb-refine <feature-name>` — Design Iteration (Optional)
131142

132-
Reads user feedback or Design Change Requests (from failed builds) and intelligently updates `design.md` and `tasks.md`. It maintains a revision history and cascades design changes to the task list without overwriting completed work.
143+
Reads user feedback or Design Change Requests (from failed builds) and intelligently updates `design.md` and `tasks.md`. It maintains a revision history and cascades design changes to the task list without overwriting completed work. `AGENTS.md` remains read-only in this phase.
133144

134145
### 4. `/pb-build <feature-name>` — Subagent-Driven Implementation
135146

136-
Reads `specs/<YYYY-MM-DD-NO-feature-name>/tasks.md` and implements each task sequentially. Every task is executed by a fresh subagent following strict TDD (Red → Green → Refactor). Supports **Design Change Requests** if the planned design proves infeasible during implementation. Only the `<feature-name>` part is needed when invoking — the agent resolves the full directory automatically.
147+
Reads `specs/<YYYY-MM-DD-NO-feature-name>/tasks.md` and implements each task sequentially. Every task is executed by a fresh subagent following strict TDD (Red → Green → Refactor). Supports **Design Change Requests** if the planned design proves infeasible during implementation. Only the `<feature-name>` part is needed when invoking — the agent resolves the full directory automatically. `AGENTS.md` is read-only unless the user explicitly requests an `AGENTS.md` change.
137148

138149
## Skills Overview
139150

140151
| Skill | Trigger | Output | Description |
141152
|---|---|---|---|
142-
| `pb-init` | `/pb-init` | `AGENTS.md` | Audit repo for undiscoverable gotchas, produce minimal agent context |
153+
| `pb-init` | `/pb-init` | `AGENTS.md` | Audit repo and safely update/append a managed snapshot block without rewriting user-authored constraints |
143154
| `pb-plan` | `/pb-plan <requirement>` | `specs/<YYYY-MM-DD-NO-feature-name>/design.md` + `tasks.md` | Design proposal + ordered task breakdown |
144155
| `pb-refine` | `/pb-refine <feature>` | Revised spec files | Apply feedback or Design Change Requests |
145156
| `pb-build` | `/pb-build <feature-name>` | Code + tests | TDD implementation via subagents |
@@ -155,16 +166,16 @@ pb-spec's prompt design is inspired by Anthropic's research on [Effective Harnes
155166
| **State Grounding** | Subagents must verify workspace state (`ls`, `find`, `read_file`) before writing any code — preventing path hallucination |
156167
| **Error Quoting** | Subagents must quote specific error messages before attempting fixes — preventing blind debugging |
157168
| **Context Hygiene** | Orchestrator passes only minimal, relevant context to each subagent — preventing context window pollution |
158-
| **Recovery Loop** | Failed tasks trigger `git checkout .` (workspace revert) before retry — ensuring each attempt starts from a known-good state |
169+
| **Recovery Loop** | Failed tasks use pre-task snapshots + file-scoped recovery (`git restore` + task-local cleanup), and avoid workspace-wide restore in dirty trees |
159170
| **Verification Harness** | Design docs define explicit verification commands at planning time — subagents execute, not invent, verification |
160-
| **Agent Rules** | `AGENTS.md` contains only undiscoverable gotchas and hard constraints — not project overview info that agents can infer from code |
171+
| **Agent Rules** | `AGENTS.md` is treated as free-form policy context: `pb-init` manages only its marker block; `pb-plan`/`pb-refine`/`pb-build` read it without rewriting |
161172

162173
### Where Each Principle Lives
163174

164175
- **Worker (Implementer):** `implementer_prompt.md` enforces grounding-first workflow and error quoting
165176
- **Architect (Planner):** `design_template.md` includes Critical Path Verification table
166-
- **Orchestrator (Builder):** `pb-build` SKILL enforces context hygiene and workspace revert on failure
167-
- **Foundation (Init):** `AGENTS.md` captures only non-obvious gotchas, hard constraints, and traps that agents cannot infer from code — not a full project overview
177+
- **Orchestrator (Builder):** `pb-build` SKILL enforces context hygiene and task-local recovery with safe rollback rules
178+
- **Foundation (Init):** `pb-init` updates only the managed marker block in `AGENTS.md`, preserving all external user-authored constraints
168179

169180
## Development
170181

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "uv_build"
44

55
[project]
66
name = "pb-spec"
7-
version = "0.4.5"
7+
version = "0.5.0"
88
description = "Plan-Build Spec (pb-spec): A CLI tool for managing AI coding assistant skills"
99
readme = "README.md"
1010
license = "Apache-2.0"
@@ -41,8 +41,8 @@ testpaths = ["tests"]
4141
[dependency-groups]
4242
dev = [
4343
"pytest>=9.0.2",
44-
"ruff>=0.15.1",
45-
"ty>=0.0.17",
44+
"ruff>=0.15.4",
45+
"ty>=0.0.19",
4646
]
4747

4848
[tool.ruff]

src/pb_spec/templates/prompts/pb-build.prompt.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ If all tasks are checked (`- [x]`), report:
6161
For each unfinished task, in order:
6262

6363
1. **Extract** the full task block (Context, Steps, Verification).
64-
2. **Gather context** — read `design.md` and `AGENTS.md` (if it exists).
64+
2. **Gather context** — read `design.md` and `AGENTS.md` (if it exists). Treat `AGENTS.md` as read-only policy context.
6565
- Record a pre-task workspace snapshot (`git status --porcelain` + tracked/untracked file lists) for safe rollback.
6666
3. **Spawn a fresh subagent** with the Implementer Prompt (below), filled in with the task content and project context.
6767
**Context Hygiene:** Do NOT pass the entire chat history. Pass ONLY:
6868
- The specific Task Description from `tasks.md`.
69-
- The `AGENTS.md` (non-obvious gotchas and hard constraints — intentionally minimal).
69+
- The `AGENTS.md` (project constraints and hard rules; do not assume any fixed template layout).
7070
- The `design.md` (Feature Spec).
7171
- **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.
7272
4. **Subagent executes** the TDD cycle (see Implementer Prompt section).
@@ -180,6 +180,7 @@ Update `tasks.md` in-place after each task using **precise edits** (target the s
180180
- Let a subagent implement more than its assigned task.
181181
- Carry in-memory state between subagents.
182182
- 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.
183184
- Rewrite the entire `tasks.md` file — use targeted edits only.
184185
- Mark a task as done without satisfying its Verification criteria.
185186
- Claim tests passed without running them.
@@ -230,7 +231,7 @@ You are implementing **Task {{TASK_NUMBER}}: {{TASK_NAME}}**.
230231

231232
{{PROJECT_CONTEXT}}
232233

233-
> From `AGENTS.md` (non-obvious gotchas and constraints) and `design.md` (feature design decisions).
234+
> From `AGENTS.md` (project constraints and rules) and `design.md` (feature design decisions).
234235
235236
### Your Job
236237

@@ -307,6 +308,7 @@ Fix any "no" answers before submitting.
307308
- Follow YAGNI — no speculative features.
308309
- Use existing patterns — match project style.
309310
- 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.
310312
- Do not modify unrelated code.
311313
- Tests are mandatory — never submit without them.
312314
- **No Blind Edits:** Always read a file before editing it.

src/pb_spec/templates/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.

src/pb_spec/templates/prompts/pb-plan.prompt.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Count the words in the requirement description (excluding the `/pb-plan` trigger
5151

5252
Gather context to inform the design. **Always perform live codebase analysis** — do not rely on any static file.
5353

54-
1. **Read `AGENTS.md`** (if it exists) — check for non-obvious gotchas, hard constraints, and traps that you cannot infer from code. AGENTS.md intentionally omits discoverable info (language, structure, test commands) — you must find those yourself.
54+
1. **Read `AGENTS.md`** (if it exists) — capture explicit project constraints, team rules, and gotchas. Do not assume any fixed section layout; treat it as free-form user-authored policy text.
5555
2. **Search the live codebase directly** — this is **mandatory** regardless of whether `AGENTS.md` exists:
5656
- Use grep / file search / semantic search to find modules, directories, and files affected by the requirement.
5757
- Search for keywords from the requirement across the codebase.
@@ -200,7 +200,7 @@ Please review the design and tasks. When ready, run /pb-build <feature-name> to
200200
1. **One-shot output.** Complete design + tasks in a single pass. No mid-way confirmation.
201201
2. **Optimal solution first.** Output the best design. Developer requests changes after review if needed.
202202
3. **Right-sized output (YAGNI).** Match output detail to requirement complexity. Simple changes get compact specs; complex features get full specs.
203-
4. **Live codebase analysis.** Always search the actual codebase `AGENTS.md` contains only non-obvious gotchas, not project overview info.
203+
4. **Live codebase analysis.** Always search the actual codebase. Use `AGENTS.md` as complementary policy context, not a replacement for code inspection.
204204
5. **Task granularity: Logical Unit of Work.** Each task is a self-contained, meaningful change. Do not split based on arbitrary time estimates.
205205
6. **Verification per task.** Every task defines how to prove it is done.
206206
7. **Dependency order.** Phases and tasks flow foundational → dependent.
@@ -218,6 +218,7 @@ Please review the design and tasks. When ready, run /pb-build <feature-name> to
218218
- **No code implementation.** Design docs and task lists only.
219219
- **Scope-appropriate templates.** In lightweight mode, only fill the compact template. In full mode, fill the complete template. Every included section must have substantive content.
220220
- **Write only to `specs/<spec-dir>/`.** Do not modify project source code.
221+
- **`AGENTS.md` is read-only in this phase.** Do not modify, delete, or reformat it unless the user explicitly asks for an `AGENTS.md` update.
221222
- **No invented references.** Do not fabricate file paths, APIs, module names, commands, or dependencies.
222223
- **No unresolved placeholders.** Final `design.md` and `tasks.md` must not contain template example markers like `[Goal A]` or `[Task Name]`.
223224

src/pb_spec/templates/prompts/pb-refine.prompt.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Run this when the user invokes `/pb-refine <feature-name>` with feedback or chan
2525

2626
1. `specs/<spec-dir>/design.md` — the current design.
2727
2. `specs/<spec-dir>/tasks.md` — the current task breakdown.
28-
3. `AGENTS.md` (if it exists) — non-obvious constraints and gotchas.
28+
3. `AGENTS.md` (if it exists) — read-only source of constraints and gotchas.
2929

3030
## Step 2: Parse User Feedback
3131

@@ -123,6 +123,7 @@ Next steps:
123123
- **Do not modify project source code.** Refinement is planning only.
124124
- **Do not re-run the entire planning process.** This is an incremental update, not a fresh plan.
125125
- **Preserve formatting and structure** of both files.
126+
- **`AGENTS.md` is read-only in this phase.** Do not modify, delete, or reformat it unless the user explicitly asks for an `AGENTS.md` update.
126127
- **No interactive multi-turn probing.** Apply the feedback given. If the feedback is ambiguous, state your interpretation in the Revision History and proceed.
127128

128129
---

0 commit comments

Comments
 (0)