claude-autopm 3.1.1 → 3.1.2
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.
- package/autopm/.claude/agents/AGENT-REGISTRY.md +11 -2
- package/autopm/.claude/agents/core/context-optimizer.md +389 -0
- package/autopm/.claude/base.md +16 -0
- package/autopm/.claude/guides/memory-patterns.md +438 -0
- package/autopm/.claude/rules/context-compaction.md +334 -0
- package/autopm/.claude/templates/memory/active-work.template.json +15 -0
- package/autopm/.claude/templates/memory/checkpoint.template.md +58 -0
- package/lib/cli/commands/prd.js +104 -1
- package/package.json +1 -1
- package/packages/plugin-pm/commands/pm:prd-new.md +104 -4
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
# Context Compaction Rules - MANDATORY
|
|
2
|
+
|
|
3
|
+
> **CRITICAL**: Apply these compaction strategies to prevent context window exhaustion during long sessions.
|
|
4
|
+
|
|
5
|
+
## Core Principle
|
|
6
|
+
|
|
7
|
+
**Context is a finite resource.** Every token matters. Compact aggressively, preserve strategically.
|
|
8
|
+
|
|
9
|
+
## Automatic Compaction Triggers
|
|
10
|
+
|
|
11
|
+
### Trigger 1: Tool Result Accumulation
|
|
12
|
+
|
|
13
|
+
**When**: 10+ tool results in session
|
|
14
|
+
|
|
15
|
+
**Action**: Summarize older tool results
|
|
16
|
+
|
|
17
|
+
```markdown
|
|
18
|
+
# BEFORE (consuming ~5000 tokens per result)
|
|
19
|
+
Tool Result 1: [full 500-line file]
|
|
20
|
+
Tool Result 2: [full 300-line file]
|
|
21
|
+
...
|
|
22
|
+
Tool Result 15: [full 200-line file]
|
|
23
|
+
|
|
24
|
+
# AFTER (consuming ~200 tokens per summary)
|
|
25
|
+
## Compacted Tool Results
|
|
26
|
+
- config.json: DB settings (PostgreSQL:5432), API keys, feature flags
|
|
27
|
+
- src/auth.js: Authentication module with login/logout/validateToken
|
|
28
|
+
- package.json: Node 18, React 18, Express 4, Jest testing
|
|
29
|
+
...
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Trigger 2: Code Block Proliferation
|
|
33
|
+
|
|
34
|
+
**When**: Same file read 3+ times OR 10+ different files read
|
|
35
|
+
|
|
36
|
+
**Action**: Consolidate to essential references
|
|
37
|
+
|
|
38
|
+
```markdown
|
|
39
|
+
# BEFORE
|
|
40
|
+
[src/auth.js - first read - 200 lines]
|
|
41
|
+
[src/auth.js - second read after edit - 205 lines]
|
|
42
|
+
[src/auth.js - third read to verify - 205 lines]
|
|
43
|
+
|
|
44
|
+
# AFTER
|
|
45
|
+
## src/auth.js Summary
|
|
46
|
+
- Purpose: User authentication with JWT
|
|
47
|
+
- Key functions: login(email, password), validateToken(jwt), refreshToken()
|
|
48
|
+
- Modified sections: lines 45-60 (added MFA check)
|
|
49
|
+
- Current length: 205 lines
|
|
50
|
+
- Last state: MFA integrated, tests passing
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Trigger 3: Thinking Block Growth
|
|
54
|
+
|
|
55
|
+
**When**: Multiple extended reasoning chains completed
|
|
56
|
+
|
|
57
|
+
**Action**: Compress to decisions and rationale
|
|
58
|
+
|
|
59
|
+
```markdown
|
|
60
|
+
# BEFORE
|
|
61
|
+
<thinking>
|
|
62
|
+
Let me analyze this step by step...
|
|
63
|
+
First, I should consider option A because...
|
|
64
|
+
Actually, option B might be better since...
|
|
65
|
+
On further reflection, option A is correct because...
|
|
66
|
+
[500+ tokens of reasoning]
|
|
67
|
+
</thinking>
|
|
68
|
+
|
|
69
|
+
# AFTER
|
|
70
|
+
## Decision: Option A (Authentication Strategy)
|
|
71
|
+
- Choice: JWT with refresh tokens
|
|
72
|
+
- Rationale: Stateless architecture, better scalability
|
|
73
|
+
- Rejected: Sessions (state management complexity)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Trigger 4: Conversation Length
|
|
77
|
+
|
|
78
|
+
**When**: 30+ messages in session
|
|
79
|
+
|
|
80
|
+
**Action**: Summarize completed topics
|
|
81
|
+
|
|
82
|
+
```markdown
|
|
83
|
+
# BEFORE
|
|
84
|
+
[Messages 1-15: Debugging authentication issue]
|
|
85
|
+
[Messages 16-25: Implementing MFA]
|
|
86
|
+
[Messages 26-35: Current work on dashboard]
|
|
87
|
+
|
|
88
|
+
# AFTER
|
|
89
|
+
## Session Summary (Messages 1-25)
|
|
90
|
+
### Completed: Authentication Debugging
|
|
91
|
+
- Issue: Token validation failing on refresh
|
|
92
|
+
- Fix: Updated expiry check in validateToken()
|
|
93
|
+
- PR: #123 merged
|
|
94
|
+
|
|
95
|
+
### Completed: MFA Implementation
|
|
96
|
+
- Added TOTP support
|
|
97
|
+
- Backup codes generated
|
|
98
|
+
- Tests: 15/15 passing
|
|
99
|
+
|
|
100
|
+
## Active Context (Messages 26+)
|
|
101
|
+
[Current dashboard implementation work...]
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Compaction Formats
|
|
105
|
+
|
|
106
|
+
### Format 1: File Summary
|
|
107
|
+
|
|
108
|
+
```markdown
|
|
109
|
+
## File: [path]
|
|
110
|
+
- Purpose: [one-line description]
|
|
111
|
+
- Key exports: [list main functions/classes]
|
|
112
|
+
- Dependencies: [external dependencies]
|
|
113
|
+
- Modified: [what changed, if applicable]
|
|
114
|
+
- State: [current state/version]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Format 2: Search Results Summary
|
|
118
|
+
|
|
119
|
+
```markdown
|
|
120
|
+
## Search: [query]
|
|
121
|
+
- Total matches: [count]
|
|
122
|
+
- Key files: [most relevant files]
|
|
123
|
+
- Pattern: [what the matches reveal]
|
|
124
|
+
- Action needed: [what to do with this info]
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Format 3: Test Results Summary
|
|
128
|
+
|
|
129
|
+
```markdown
|
|
130
|
+
## Tests: [suite/file]
|
|
131
|
+
- Status: [PASS/FAIL] ([passed]/[total])
|
|
132
|
+
- Failures: [list failing tests if any]
|
|
133
|
+
- Coverage: [percentage if available]
|
|
134
|
+
- Action: [what to fix/investigate]
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Format 4: Decision Record
|
|
138
|
+
|
|
139
|
+
```markdown
|
|
140
|
+
## Decision: [title]
|
|
141
|
+
- Choice: [what was decided]
|
|
142
|
+
- Rationale: [why, in one sentence]
|
|
143
|
+
- Rejected: [alternatives not chosen]
|
|
144
|
+
- Impact: [what this affects]
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Preservation Rules
|
|
148
|
+
|
|
149
|
+
### ALWAYS Preserve
|
|
150
|
+
|
|
151
|
+
1. **Active Task Context**
|
|
152
|
+
- Current file being edited
|
|
153
|
+
- Unsaved changes
|
|
154
|
+
- Active error messages
|
|
155
|
+
|
|
156
|
+
2. **Critical Decisions**
|
|
157
|
+
- Architectural choices
|
|
158
|
+
- Security configurations
|
|
159
|
+
- Breaking changes
|
|
160
|
+
|
|
161
|
+
3. **Blocking Issues**
|
|
162
|
+
- Current errors
|
|
163
|
+
- Failing tests
|
|
164
|
+
- Unresolved dependencies
|
|
165
|
+
|
|
166
|
+
4. **User Requirements**
|
|
167
|
+
- Original request
|
|
168
|
+
- Constraints specified
|
|
169
|
+
- Preferences stated
|
|
170
|
+
|
|
171
|
+
### SAFE to Compact
|
|
172
|
+
|
|
173
|
+
1. **Historical Tool Results**
|
|
174
|
+
- Files read 5+ messages ago
|
|
175
|
+
- Search results already acted upon
|
|
176
|
+
- Test results from passing suites
|
|
177
|
+
|
|
178
|
+
2. **Superseded Information**
|
|
179
|
+
- Old file versions
|
|
180
|
+
- Rejected approaches
|
|
181
|
+
- Fixed bugs
|
|
182
|
+
|
|
183
|
+
3. **Verbose Output**
|
|
184
|
+
- Full stack traces (keep summary)
|
|
185
|
+
- Build logs (keep errors only)
|
|
186
|
+
- Long lists (keep relevant items)
|
|
187
|
+
|
|
188
|
+
4. **Exploratory Work**
|
|
189
|
+
- Hypothesis testing completed
|
|
190
|
+
- Alternative approaches evaluated
|
|
191
|
+
- Research phase findings
|
|
192
|
+
|
|
193
|
+
## Implementation Patterns
|
|
194
|
+
|
|
195
|
+
### Pattern 1: Progressive Summarization
|
|
196
|
+
|
|
197
|
+
```markdown
|
|
198
|
+
# Level 0: Full content (initial read)
|
|
199
|
+
[Complete file: 500 lines]
|
|
200
|
+
|
|
201
|
+
# Level 1: Key sections (after analysis)
|
|
202
|
+
## Key Sections in config.json
|
|
203
|
+
- Database config (lines 1-50)
|
|
204
|
+
- API settings (lines 51-100)
|
|
205
|
+
- Feature flags (lines 101-150)
|
|
206
|
+
|
|
207
|
+
# Level 2: Actionable summary (after decision)
|
|
208
|
+
config.json: Using PostgreSQL on 5432, rate limit 100/min, darkMode enabled
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Pattern 2: Rolling Window
|
|
212
|
+
|
|
213
|
+
Keep last N items in full detail, summarize older:
|
|
214
|
+
|
|
215
|
+
```markdown
|
|
216
|
+
## Recent (full detail)
|
|
217
|
+
- Tool Result 8: [full content]
|
|
218
|
+
- Tool Result 9: [full content]
|
|
219
|
+
- Tool Result 10: [full content]
|
|
220
|
+
|
|
221
|
+
## Historical (summarized)
|
|
222
|
+
- Results 1-7: config files read, auth system analyzed,
|
|
223
|
+
tests confirmed passing, dependencies validated
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Pattern 3: Topic-Based Grouping
|
|
227
|
+
|
|
228
|
+
Group related items for efficient summarization:
|
|
229
|
+
|
|
230
|
+
```markdown
|
|
231
|
+
## Authentication Work (compacted)
|
|
232
|
+
Files read: src/auth.js, src/middleware/auth.js, src/models/User.js
|
|
233
|
+
Changes made: Added MFA support (auth.js:45-60)
|
|
234
|
+
Tests: 15/15 passing
|
|
235
|
+
Outcome: MFA feature complete
|
|
236
|
+
|
|
237
|
+
## Database Work (compacted)
|
|
238
|
+
Files read: src/db/connection.js, migrations/*.js
|
|
239
|
+
Changes made: Added index on users.email
|
|
240
|
+
Tests: 8/8 passing
|
|
241
|
+
Outcome: Query performance improved 40%
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Enforcement
|
|
245
|
+
|
|
246
|
+
### Self-Check Questions
|
|
247
|
+
|
|
248
|
+
Before adding new content, ask:
|
|
249
|
+
1. Is this information already in context (in another form)?
|
|
250
|
+
2. Will this be needed after the current operation?
|
|
251
|
+
3. Can this be summarized without losing actionable details?
|
|
252
|
+
4. Does this duplicate information from another tool result?
|
|
253
|
+
|
|
254
|
+
### Compaction Checklist
|
|
255
|
+
|
|
256
|
+
When context feels heavy:
|
|
257
|
+
- [ ] Summarize tool results older than 5 messages
|
|
258
|
+
- [ ] Compress completed reasoning chains
|
|
259
|
+
- [ ] Consolidate multiple reads of same file
|
|
260
|
+
- [ ] Remove superseded information
|
|
261
|
+
- [ ] Group related items into summaries
|
|
262
|
+
|
|
263
|
+
### Warning Signs
|
|
264
|
+
|
|
265
|
+
**Immediate Action Needed:**
|
|
266
|
+
- Response times noticeably slower
|
|
267
|
+
- "Context too long" errors
|
|
268
|
+
- Repetitive information in context
|
|
269
|
+
- Multiple versions of same file
|
|
270
|
+
- 50+ messages without compaction
|
|
271
|
+
|
|
272
|
+
## Integration with /clear
|
|
273
|
+
|
|
274
|
+
### When to Compact vs Clear
|
|
275
|
+
|
|
276
|
+
| Situation | Action |
|
|
277
|
+
|-----------|--------|
|
|
278
|
+
| Same task, growing context | Compact |
|
|
279
|
+
| Task complete, starting new | /clear |
|
|
280
|
+
| Context heavy but continuity needed | Compact + Checkpoint |
|
|
281
|
+
| Unrelated topics mixing | /clear |
|
|
282
|
+
| Long research session | Compact progressively |
|
|
283
|
+
|
|
284
|
+
### Handoff Pattern
|
|
285
|
+
|
|
286
|
+
Before `/clear`, create transfer summary:
|
|
287
|
+
|
|
288
|
+
```markdown
|
|
289
|
+
## Session Transfer Summary
|
|
290
|
+
|
|
291
|
+
### Completed
|
|
292
|
+
- [list completed items]
|
|
293
|
+
|
|
294
|
+
### In Progress
|
|
295
|
+
- [current state]
|
|
296
|
+
|
|
297
|
+
### Preserved Context
|
|
298
|
+
- [critical information for next session]
|
|
299
|
+
|
|
300
|
+
### Next Steps
|
|
301
|
+
- [what to do next]
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## Metrics
|
|
305
|
+
|
|
306
|
+
### Context Efficiency Score
|
|
307
|
+
|
|
308
|
+
Calculate: (Useful tokens / Total tokens) × 100
|
|
309
|
+
|
|
310
|
+
- **>80%**: Excellent - minimal waste
|
|
311
|
+
- **60-80%**: Good - some optimization possible
|
|
312
|
+
- **40-60%**: Fair - compaction recommended
|
|
313
|
+
- **<40%**: Poor - immediate compaction needed
|
|
314
|
+
|
|
315
|
+
### Token Budget Guidelines
|
|
316
|
+
|
|
317
|
+
| Session Type | Recommended Budget |
|
|
318
|
+
|--------------|-------------------|
|
|
319
|
+
| Quick fix | <20k tokens |
|
|
320
|
+
| Feature implementation | <50k tokens |
|
|
321
|
+
| Complex debugging | <80k tokens |
|
|
322
|
+
| Full project work | <100k tokens + checkpoints |
|
|
323
|
+
|
|
324
|
+
## Summary
|
|
325
|
+
|
|
326
|
+
**Golden Rules:**
|
|
327
|
+
1. Compact early, compact often
|
|
328
|
+
2. Preserve decisions, discard deliberation
|
|
329
|
+
3. Summarize verbose output immediately
|
|
330
|
+
4. Use progressive summarization
|
|
331
|
+
5. Create checkpoints for long work
|
|
332
|
+
6. /clear between unrelated tasks
|
|
333
|
+
|
|
334
|
+
**Remember**: A well-compacted context leads to better responses, faster processing, and more productive sessions.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"current_task": {
|
|
3
|
+
"id": "",
|
|
4
|
+
"title": "",
|
|
5
|
+
"branch": "",
|
|
6
|
+
"started": "",
|
|
7
|
+
"status": "pending"
|
|
8
|
+
},
|
|
9
|
+
"recent_changes": [],
|
|
10
|
+
"blockers": [],
|
|
11
|
+
"next_steps": [],
|
|
12
|
+
"context_notes": "",
|
|
13
|
+
"decisions_made": [],
|
|
14
|
+
"files_of_interest": []
|
|
15
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Checkpoint: {{FEATURE_NAME}}
|
|
2
|
+
|
|
3
|
+
**Date**: {{TIMESTAMP}}
|
|
4
|
+
**Session**: {{SESSION_NUMBER}}
|
|
5
|
+
|
|
6
|
+
## Status Summary
|
|
7
|
+
|
|
8
|
+
- **Overall Progress**: {{PERCENTAGE}}% complete
|
|
9
|
+
- **Tests**: {{TESTS_PASSING}}/{{TESTS_TOTAL}} passing
|
|
10
|
+
- **Branch**: {{BRANCH_NAME}}
|
|
11
|
+
- **Last Commit**: {{COMMIT_HASH}}
|
|
12
|
+
|
|
13
|
+
## Completed Items
|
|
14
|
+
|
|
15
|
+
- [x] {{COMPLETED_ITEM_1}}
|
|
16
|
+
- [x] {{COMPLETED_ITEM_2}}
|
|
17
|
+
|
|
18
|
+
## In Progress
|
|
19
|
+
|
|
20
|
+
- [ ] {{IN_PROGRESS_ITEM}} - {{CURRENT_STATE}}
|
|
21
|
+
|
|
22
|
+
## Pending
|
|
23
|
+
|
|
24
|
+
- [ ] {{PENDING_ITEM_1}}
|
|
25
|
+
- [ ] {{PENDING_ITEM_2}}
|
|
26
|
+
|
|
27
|
+
## Key Decisions Made
|
|
28
|
+
|
|
29
|
+
| Decision | Choice | Rationale |
|
|
30
|
+
|----------|--------|-----------|
|
|
31
|
+
| {{DECISION_1}} | {{CHOICE_1}} | {{RATIONALE_1}} |
|
|
32
|
+
|
|
33
|
+
## Critical Context
|
|
34
|
+
|
|
35
|
+
- {{CRITICAL_INFO_1}}
|
|
36
|
+
- {{CRITICAL_INFO_2}}
|
|
37
|
+
|
|
38
|
+
## Files Modified This Session
|
|
39
|
+
|
|
40
|
+
- `{{FILE_1}}` - {{CHANGE_DESCRIPTION_1}}
|
|
41
|
+
- `{{FILE_2}}` - {{CHANGE_DESCRIPTION_2}}
|
|
42
|
+
|
|
43
|
+
## Commands to Resume
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
git checkout {{BRANCH_NAME}}
|
|
47
|
+
npm install
|
|
48
|
+
npm run dev
|
|
49
|
+
# Then: "Continue {{FEATURE_NAME}} implementation"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Notes for Next Session
|
|
53
|
+
|
|
54
|
+
- {{NOTE_1}}
|
|
55
|
+
- {{NOTE_2}}
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
*Generated by context-optimizer agent*
|
package/lib/cli/commands/prd.js
CHANGED
|
@@ -301,11 +301,91 @@ async function prdStatus(argv) {
|
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
+
/**
|
|
305
|
+
* Create new PRD from content (non-interactive mode)
|
|
306
|
+
* @param {Object} argv - Command arguments
|
|
307
|
+
*/
|
|
308
|
+
async function prdNewFromContent(argv) {
|
|
309
|
+
const spinner = ora(`Creating PRD: ${argv.name}`).start();
|
|
310
|
+
|
|
311
|
+
try {
|
|
312
|
+
let content = argv.content;
|
|
313
|
+
|
|
314
|
+
// Check if content is a file reference (starts with @)
|
|
315
|
+
if (content.startsWith('@')) {
|
|
316
|
+
const filePath = content.slice(1); // Remove @ prefix
|
|
317
|
+
const absolutePath = path.isAbsolute(filePath)
|
|
318
|
+
? filePath
|
|
319
|
+
: path.join(process.cwd(), filePath);
|
|
320
|
+
|
|
321
|
+
const fileExists = await fs.pathExists(absolutePath);
|
|
322
|
+
if (!fileExists) {
|
|
323
|
+
spinner.fail(chalk.red('Source file not found'));
|
|
324
|
+
console.error(chalk.red(`\nError: File not found: ${absolutePath}`));
|
|
325
|
+
process.exit(1);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
content = await fs.readFile(absolutePath, 'utf8');
|
|
329
|
+
spinner.text = `Reading content from: ${absolutePath}`;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Ensure PRDs directory exists
|
|
333
|
+
const prdsDir = path.join(process.cwd(), '.claude', 'prds');
|
|
334
|
+
await fs.ensureDir(prdsDir);
|
|
335
|
+
|
|
336
|
+
// Check if PRD already exists
|
|
337
|
+
const prdPath = getPrdPath(argv.name);
|
|
338
|
+
const exists = await fs.pathExists(prdPath);
|
|
339
|
+
if (exists && !argv.force) {
|
|
340
|
+
spinner.fail(chalk.red('PRD already exists'));
|
|
341
|
+
console.error(chalk.red(`\nError: PRD file already exists: ${prdPath}`));
|
|
342
|
+
console.error(chalk.yellow('Use --force to overwrite'));
|
|
343
|
+
process.exit(1);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// Add frontmatter if not present
|
|
347
|
+
if (!content.startsWith('---')) {
|
|
348
|
+
const timestamp = new Date().toISOString();
|
|
349
|
+
const frontmatter = `---
|
|
350
|
+
title: ${argv.name}
|
|
351
|
+
status: draft
|
|
352
|
+
priority: ${argv.priority || 'P2'}
|
|
353
|
+
created: ${timestamp}
|
|
354
|
+
author: ${process.env.USER || 'unknown'}
|
|
355
|
+
timeline: ${argv.timeline || 'TBD'}
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
`;
|
|
359
|
+
content = frontmatter + content;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Write PRD file
|
|
363
|
+
await fs.writeFile(prdPath, content);
|
|
364
|
+
spinner.succeed(chalk.green('PRD created successfully'));
|
|
365
|
+
|
|
366
|
+
console.log(chalk.green(`\n✅ PRD created: ${prdPath}`));
|
|
367
|
+
console.log(chalk.cyan('\n📋 Next steps:'));
|
|
368
|
+
console.log(` 1. Review: ${chalk.yellow('autopm prd show ' + argv.name)}`);
|
|
369
|
+
console.log(` 2. Edit: ${chalk.yellow('autopm prd edit ' + argv.name)}`);
|
|
370
|
+
console.log(` 3. Parse: ${chalk.yellow('autopm prd parse ' + argv.name)}`);
|
|
371
|
+
|
|
372
|
+
} catch (error) {
|
|
373
|
+
spinner.fail(chalk.red('Failed to create PRD'));
|
|
374
|
+
console.error(chalk.red(`\nError: ${error.message}`));
|
|
375
|
+
process.exit(1);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
304
379
|
/**
|
|
305
380
|
* Create new PRD
|
|
306
381
|
* @param {Object} argv - Command arguments
|
|
307
382
|
*/
|
|
308
383
|
async function prdNew(argv) {
|
|
384
|
+
// Check if content is provided (non-interactive mode)
|
|
385
|
+
if (argv.content) {
|
|
386
|
+
return await prdNewFromContent(argv);
|
|
387
|
+
}
|
|
388
|
+
|
|
309
389
|
// Check if AI mode is enabled
|
|
310
390
|
if (argv.ai) {
|
|
311
391
|
return await prdNewWithAI(argv);
|
|
@@ -803,7 +883,7 @@ function builder(yargs) {
|
|
|
803
883
|
)
|
|
804
884
|
.command(
|
|
805
885
|
'new <name>',
|
|
806
|
-
'Create new PRD interactively',
|
|
886
|
+
'Create new PRD interactively or from existing content',
|
|
807
887
|
(yargs) => {
|
|
808
888
|
return yargs
|
|
809
889
|
.positional('name', {
|
|
@@ -815,6 +895,27 @@ function builder(yargs) {
|
|
|
815
895
|
type: 'string',
|
|
816
896
|
alias: 't'
|
|
817
897
|
})
|
|
898
|
+
.option('content', {
|
|
899
|
+
describe: 'PRD content: inline text or @filepath to read from file (non-interactive)',
|
|
900
|
+
type: 'string',
|
|
901
|
+
alias: 'c'
|
|
902
|
+
})
|
|
903
|
+
.option('force', {
|
|
904
|
+
describe: 'Overwrite existing PRD file',
|
|
905
|
+
type: 'boolean',
|
|
906
|
+
alias: 'f',
|
|
907
|
+
default: false
|
|
908
|
+
})
|
|
909
|
+
.option('priority', {
|
|
910
|
+
describe: 'PRD priority (P0/P1/P2/P3)',
|
|
911
|
+
type: 'string',
|
|
912
|
+
alias: 'p',
|
|
913
|
+
default: 'P2'
|
|
914
|
+
})
|
|
915
|
+
.option('timeline', {
|
|
916
|
+
describe: 'PRD timeline (e.g., Q1 2025)',
|
|
917
|
+
type: 'string'
|
|
918
|
+
})
|
|
818
919
|
.option('ai', {
|
|
819
920
|
describe: 'Use AI to generate PRD content (requires ANTHROPIC_API_KEY)',
|
|
820
921
|
type: 'boolean',
|
|
@@ -827,6 +928,8 @@ function builder(yargs) {
|
|
|
827
928
|
})
|
|
828
929
|
.example('autopm prd new my-feature', 'Create PRD with wizard')
|
|
829
930
|
.example('autopm prd new payment-api --template api-feature', 'Create PRD from template')
|
|
931
|
+
.example('autopm prd new my-feature --content @/path/to/draft.md', 'Create from file')
|
|
932
|
+
.example('autopm prd new my-feature --content "# My PRD\\n\\nDescription..."', 'Create from inline')
|
|
830
933
|
.example('autopm prd new my-feature --ai', 'AI-powered PRD generation')
|
|
831
934
|
.example('autopm prd new my-feature --ai --stream', 'AI generation with streaming');
|
|
832
935
|
},
|
package/package.json
CHANGED
|
@@ -4,11 +4,11 @@ allowed-tools: Bash, Read, Write, LS
|
|
|
4
4
|
|
|
5
5
|
# PRD New
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Create new product requirement document - interactively or from existing content.
|
|
8
8
|
|
|
9
9
|
## Usage
|
|
10
10
|
```
|
|
11
|
-
/pm:prd-new <feature_name> [
|
|
11
|
+
/pm:prd-new <feature_name> [options]
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
## Flags
|
|
@@ -19,11 +19,62 @@ Launch interactive brainstorming session for new product requirement document.
|
|
|
19
19
|
: No GitHub/Azure synchronization required
|
|
20
20
|
: Ideal for working offline or without remote provider configured
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
`--content`, `-c`
|
|
23
|
+
: PRD content for non-interactive mode
|
|
24
|
+
: Use `@filepath` to read from file (e.g., `--content @/path/to/draft.md`)
|
|
25
|
+
: Use inline text for short content (e.g., `--content "# My PRD..."`)
|
|
26
|
+
: Skips interactive wizard completely
|
|
27
|
+
: Ideal for importing existing PRDs or automated workflows
|
|
28
|
+
|
|
29
|
+
`--force`, `-f`
|
|
30
|
+
: Overwrite existing PRD file if it exists
|
|
31
|
+
|
|
32
|
+
`--priority`, `-p`
|
|
33
|
+
: Set PRD priority (P0/P1/P2/P3, default: P2)
|
|
34
|
+
|
|
35
|
+
`--timeline`
|
|
36
|
+
: Set PRD timeline (e.g., "Q1 2025")
|
|
37
|
+
|
|
38
|
+
## Examples
|
|
39
|
+
|
|
40
|
+
### Interactive mode (default)
|
|
41
|
+
```
|
|
42
|
+
/pm:prd-new user-authentication
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Local mode
|
|
23
46
|
```
|
|
24
47
|
/pm:prd-new user-authentication --local
|
|
25
48
|
```
|
|
26
49
|
|
|
50
|
+
### From existing file
|
|
51
|
+
```
|
|
52
|
+
/pm:prd-new payment-gateway --content @docs/drafts/payment-prd.md
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### From clipboard/inline content
|
|
56
|
+
```
|
|
57
|
+
/pm:prd-new api-v2 --content "# API v2 Redesign
|
|
58
|
+
|
|
59
|
+
## Problem Statement
|
|
60
|
+
Current API has performance issues...
|
|
61
|
+
|
|
62
|
+
## Goals
|
|
63
|
+
1. Improve response times
|
|
64
|
+
2. Better error handling
|
|
65
|
+
"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### With metadata
|
|
69
|
+
```
|
|
70
|
+
/pm:prd-new critical-fix --content @bug-report.md --priority P0 --timeline "This Sprint"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Force overwrite
|
|
74
|
+
```
|
|
75
|
+
/pm:prd-new existing-feature --content @updated-prd.md --force
|
|
76
|
+
```
|
|
77
|
+
|
|
27
78
|
## Required Documentation Access
|
|
28
79
|
|
|
29
80
|
**MANDATORY:** Before creating PRDs, query Context7 for best practices:
|
|
@@ -42,6 +93,43 @@ Example:
|
|
|
42
93
|
|
|
43
94
|
## Instructions
|
|
44
95
|
|
|
96
|
+
### Mode Detection
|
|
97
|
+
|
|
98
|
+
Parse the arguments to detect the mode:
|
|
99
|
+
- If `--content @<filepath>` is present → **Content from file mode**
|
|
100
|
+
- If `--content "<text>"` is present → **Content from inline text mode**
|
|
101
|
+
- Otherwise → **Interactive mode**
|
|
102
|
+
|
|
103
|
+
### Content from File Mode (`--content @filepath`)
|
|
104
|
+
|
|
105
|
+
1. Extract the file path from `--content @<filepath>` argument
|
|
106
|
+
2. Use the Read tool to read the source file content
|
|
107
|
+
3. Check if target PRD already exists at `.claude/prds/<feature_name>.md`
|
|
108
|
+
- If exists and `--force` not provided → Error and stop
|
|
109
|
+
- If exists and `--force` provided → Continue (will overwrite)
|
|
110
|
+
4. Prepare the PRD content:
|
|
111
|
+
- If source content starts with `---` (has frontmatter) → Use as-is
|
|
112
|
+
- If no frontmatter → Add frontmatter with:
|
|
113
|
+
```yaml
|
|
114
|
+
---
|
|
115
|
+
title: <feature_name>
|
|
116
|
+
status: draft
|
|
117
|
+
priority: <from --priority or P2>
|
|
118
|
+
created: <current ISO timestamp>
|
|
119
|
+
author: <from git config or "unknown">
|
|
120
|
+
timeline: <from --timeline or "TBD">
|
|
121
|
+
---
|
|
122
|
+
```
|
|
123
|
+
5. Create directory `.claude/prds/` if it doesn't exist (use Bash: `mkdir -p .claude/prds`)
|
|
124
|
+
6. Write the PRD file using the Write tool to `.claude/prds/<feature_name>.md`
|
|
125
|
+
7. Confirm success and show next steps
|
|
126
|
+
|
|
127
|
+
### Content from Inline Text Mode (`--content "text"`)
|
|
128
|
+
|
|
129
|
+
Same as file mode, but use the inline text directly instead of reading from file.
|
|
130
|
+
|
|
131
|
+
### Interactive Mode (default)
|
|
132
|
+
|
|
45
133
|
Run `node .claude/scripts/pm/prd-new.js $ARGUMENTS` using the Bash tool and show me the complete output.
|
|
46
134
|
|
|
47
135
|
This will launch an interactive brainstorming session that will:
|
|
@@ -52,4 +140,16 @@ This will launch an interactive brainstorming session that will:
|
|
|
52
140
|
5. Capture technical considerations
|
|
53
141
|
6. Generate a comprehensive PRD with proper frontmatter
|
|
54
142
|
|
|
55
|
-
The script handles all validation, creates the necessary directories, and saves the PRD to `.claude/prds
|
|
143
|
+
The script handles all validation, creates the necessary directories, and saves the PRD to `.claude/prds/<feature_name>.md`.
|
|
144
|
+
|
|
145
|
+
## Output
|
|
146
|
+
|
|
147
|
+
After successful PRD creation, show:
|
|
148
|
+
```
|
|
149
|
+
✅ PRD created: .claude/prds/<feature_name>.md
|
|
150
|
+
|
|
151
|
+
📋 Next steps:
|
|
152
|
+
1. Review: /pm:prd-show <feature_name>
|
|
153
|
+
2. Edit: /pm:prd-edit <feature_name>
|
|
154
|
+
3. Parse: /pm:prd-parse <feature_name>
|
|
155
|
+
```
|