@fermindi/pwn-cli 0.5.0 → 0.6.0

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.
@@ -38,9 +38,9 @@ Read these files in order:
38
38
  - Ask user before deviating from active decisions
39
39
 
40
40
  2. **`/.ai/memory/patterns.md`**
41
- - Index of patterns documented in `.ai/patterns/`
42
- - Check which patterns exist for this project
43
- - Add index entry when creating new pattern files
41
+ - Codebase patterns learned by team
42
+ - Apply these patterns to new work
43
+ - Add new patterns when discovered
44
44
 
45
45
  3. **`/.ai/memory/deadends.md`**
46
46
  - Failed approaches documented (DE-XXX)
@@ -71,10 +71,10 @@ If this is your first session:
71
71
  - Blocked items and blockers
72
72
  - Priority ordering
73
73
 
74
- 2. **`/.ai/tasks/backlog.md`** (if needed)
75
- - Future work not yet started
74
+ 2. **`/.ai/tasks/prd.json`** (if needed)
75
+ - Future work as structured JSON stories
76
76
  - Use when no active work assigned
77
- - Pick highest priority unblocked item
77
+ - Pick next story with dependencies satisfied
78
78
 
79
79
  3. **Project-specific notes** (if applicable)
80
80
  - Check `/CLAUDE.md` in project root
@@ -208,42 +208,6 @@ If any gate fails:
208
208
  - Ask user if unsure how to proceed
209
209
  - Don't commit until gates pass
210
210
 
211
- ### Pattern Checkpoint (Mandatory Before Commit)
212
-
213
- Before every commit, review the work done and check if any pattern should be documented.
214
-
215
- **Document a pattern when ANY of these criteria are met:**
216
-
217
- 1. **User corrected your approach** - The user told you to do something differently. Document the correct approach so future sessions don't repeat the mistake.
218
- 2. **You chose between alternatives** - You evaluated 2+ options and picked one. Document what was chosen and why.
219
- 3. **Workaround for limitation** - A library, framework, or tool has a non-obvious limitation. Document the workaround.
220
- 4. **Convention established** - First time implementing a certain type of thing in this codebase (first API route, first test, first component). Document the convention for consistency.
221
- 5. **Repeated approach** - You used the same approach 2+ times in this session. Document it to avoid re-deriving it.
222
- 6. **Non-trivial solution** - The solution wasn't obvious or took investigation to find. Document it so it's immediately available next time.
223
-
224
- **If a criterion is met:**
225
-
226
- 1. Create pattern file: `.ai/patterns/{category}/{pattern-name}.md`
227
- ```markdown
228
- # Pattern Name
229
-
230
- ## Context
231
- When to apply this pattern.
232
-
233
- ## Pattern
234
- Description or code example.
235
-
236
- ## Rationale
237
- Why this approach works better.
238
-
239
- ## Examples
240
- - `src/path/file.ts:42`
241
- ```
242
- 2. Add index entry to `.ai/memory/patterns.md`
243
- 3. Commit pattern files together with the code change
244
-
245
- **If no criteria are met:** proceed to commit normally. Don't force patterns that aren't there.
246
-
247
211
  ### Commit Message Format
248
212
 
249
213
  Use conventional commits:
@@ -281,9 +245,15 @@ When completing work:
281
245
  - [x] US-042: My completed task (YYYY-MM-DD)
282
246
  ```
283
247
 
284
- 2. Document patterns following the **Pattern Checkpoint** criteria above
285
- - Create file in `.ai/patterns/{category}/{name}.md`
286
- - Add index entry in `.ai/memory/patterns.md`
248
+ 2. Update `/.ai/memory/patterns.md` if new pattern discovered
249
+ ```
250
+ ## New Pattern Category
251
+
252
+ ### Pattern Name
253
+ **Context:** When to use
254
+ **Pattern:** Description
255
+ **Rationale:** Why it's better
256
+ ```
287
257
 
288
258
  3. Add to `/.ai/memory/deadends.md` if approach failed
289
259
  ```
@@ -298,110 +268,41 @@ When completing work:
298
268
 
299
269
  ## Batch Mode
300
270
 
301
- When `session_mode` is "batch" (autonomous task execution):
271
+ Autonomous task execution via `.ai/batch/batch_runner.sh`.
302
272
 
303
- ### Your Role
304
- - Execute tasks from backlog autonomously
305
- - Follow quality gates strictly
306
- - Make conservative decisions (ask user when uncertain)
307
- - Commit and push changes automatically
308
- - Continue until backlog depleted or limits reached
273
+ The runner reads stories from `.ai/tasks/prd.json`, spawns fresh Claude sessions
274
+ per task, runs quality gates, and tracks progress.
309
275
 
310
- ### Batch Workflow
311
-
312
- ```
313
- 1. Read tasks/active.md
314
- ├─ If incomplete tasks: resume work
315
- └─ If no active tasks: read backlog.md
316
-
317
- 2. Select highest-priority unblocked task
318
- ├─ Check dependencies
319
- ├─ Verify not blocked
320
- └─ Move to tasks/active.md
321
-
322
- 3. Create feature branch
323
- └─ Name: feature/{task-id}-{slug}
324
-
325
- 4. Execute work following patterns
326
- ├─ Auto-apply triggers from patterns/index.md
327
- ├─ Keep commits atomic and descriptive
328
- └─ Test incrementally
329
-
330
- 5. Quality gates must pass
331
- ├─ If gate fails:
332
- │ ├─ Attempt auto-fix if pattern known
333
- │ ├─ Pause batch if can't fix
334
- │ └─ Notify user
335
- └─ If all pass: proceed to commit
336
-
337
- 6. Commit and push
338
- ├─ Stage all changes
339
- ├─ Commit with conventional format
340
- ├─ Push to origin
341
- └─ Create PR if configured
342
-
343
- 7. Clean up and continue
344
- ├─ Delete local feature branch
345
- ├─ Update tasks/active.md
346
- ├─ Check if more tasks to execute
347
- └─ Continue or stop
348
-
349
- 8. Completion report
350
- └─ Show summary: tasks done, time spent, any issues
276
+ ### Usage
277
+ ```bash
278
+ ./.ai/batch/batch_runner.sh --dry-run # Preview next task
279
+ ./.ai/batch/batch_runner.sh # Run (default 20 iterations)
280
+ ./.ai/batch/batch_runner.sh 50 # Custom iteration limit
281
+ ./.ai/batch/batch_runner.sh --phase 3 # Specific phase only
351
282
  ```
352
283
 
353
- ### Batch Configuration
354
-
355
- Read from `/.ai/state.json`:
284
+ ### State Files
285
+ | File | Purpose |
286
+ |------|---------|
287
+ | .ai/tasks/prd.json | Single source of truth for task status |
288
+ | .ai/batch/progress.txt | Append-only operational learnings |
289
+ | .ai/batch/prompt.md | Prompt template for Claude sessions |
290
+ | logs/ | Per-task Claude output logs |
356
291
 
357
- ```json
358
- {
359
- "batch_config": {
360
- "max_tasks": 5,
361
- "max_duration_hours": 4,
362
- "quality_gates": ["typecheck", "lint", "test"],
363
- "skip_gates": [],
364
- "auto_commit": true,
365
- "auto_push": false,
366
- "create_pr": false,
367
- "branch_format": "feature/{id}-{slug}",
368
- "commit_format": "conventional"
369
- }
370
- }
371
- ```
372
-
373
- **Important:** Batch mode is conservative:
374
- - Don't skip quality gates without explicit config
375
- - Ask user if uncertain about task interpretation
376
- - Stop on first blocker and notify user
377
- - Don't force push or destructive operations
378
- - Log all decisions and timing
379
-
380
- ### Batch Error Handling
381
-
382
- **Build/Test Fails:**
383
- - Show error with full context
384
- - If pattern known: auto-fix
385
- - If unsure: pause and notify user
386
- - Don't proceed without resolution
387
-
388
- **Git Conflicts:**
389
- - Stop immediately
390
- - Notify user of conflict
391
- - Require manual resolution
392
- - Resume after conflict resolved
393
-
394
- **Missing Dependencies:**
395
- - Check if dependency task exists
396
- - Add to batch queue if available
397
- - Execute dependency first
398
- - Resume original task
399
-
400
- **Resource Limits Reached:**
401
- - Stop execution gracefully
402
- - Report progress
403
- - Create clean state for next batch
404
- - Notify user of completion status
292
+ ### How It Works
293
+ 1. Read prd.json → find next incomplete story (deps satisfied)
294
+ 2. Spawn: `claude --print --dangerously-skip-permissions -p "implement story X"`
295
+ 3. Run quality gates (configurable per project)
296
+ 4. If pass → mark story done in prd.json, commit
297
+ 5. If fail → retry up to 2x with error context
298
+ 6. Append learnings to progress.txt
299
+ 7. Repeat until done or max iterations
300
+
301
+ ### Safety
302
+ - Circuit breaker: 3 consecutive failures → stop
303
+ - Rate limit detection + auto-wait
304
+ - Graceful Ctrl+C shutdown
305
+ - Per-task logs for debugging
405
306
 
406
307
  ---
407
308
 
@@ -430,7 +331,7 @@ Reference these files in this priority order:
430
331
  - Project changelog or git history
431
332
 
432
333
  5. **Fifth Priority: Planning**
433
- - `/.ai/tasks/backlog.md` - Future work
334
+ - `/.ai/tasks/prd.json` - Future work (structured)
434
335
  - Roadmap or project documentation
435
336
  - Upstream issues or features
436
337
 
@@ -620,7 +521,7 @@ When finishing a session:
620
521
  - Add completion date if done
621
522
 
622
523
  3. **Document learnings**
623
- - Document patterns in `.ai/patterns/` and index in `memory/patterns.md`
524
+ - Update `/.ai/memory/patterns.md` if discovered pattern
624
525
  - Update `/.ai/memory/deadends.md` if failed approach
625
526
  - Reference in commit messages
626
527
 
@@ -1,19 +1,65 @@
1
- # Codebase Patterns Index
1
+ # Codebase Patterns
2
2
 
3
- This file is an index of patterns documented in `.ai/patterns/`.
4
- Each entry links to the full pattern file.
3
+ This file documents recurring patterns discovered during development.
5
4
 
6
- ## Registered Patterns
5
+ ## Format
7
6
 
8
- <!-- AI: Add entries here as you create pattern files -->
9
- <!-- Format: - [{category}/{name}](.ai/patterns/{category}/{name}.md) - Brief description -->
7
+ Each pattern follows this structure:
10
8
 
11
- _No patterns registered yet._
9
+ ```markdown
10
+ ## Pattern Category
11
+
12
+ ### Pattern Name
13
+ **Context:** When this pattern applies
14
+ **Pattern:** Code example or description
15
+ **Rationale:** Why this is the better approach
16
+ **Example Location:** Where to find real examples
17
+ ```
18
+
19
+ ---
20
+
21
+ ## Add New Patterns
22
+
23
+ When you discover a useful pattern:
24
+
25
+ 1. Identify the category (Frontend, Backend, Testing, etc.)
26
+ 2. Fill in all sections
27
+ 3. Add code example if possible
28
+ 4. Commit with message: `docs: add pattern - [name]`
29
+ 5. Update `patterns/index.md` if this should be auto-applied
30
+
31
+ ---
32
+
33
+ ## Pattern Categories
34
+
35
+ - **Frontend:** React, TypeScript, styling, component patterns
36
+ - **Backend:** API design, database queries, middleware
37
+ - **Testing:** Unit tests, integration tests, fixtures
38
+ - **Performance:** Caching, memoization, optimization
39
+ - **Security:** Input validation, authentication, authorization
40
+ - **Error Handling:** Exception patterns, recovery strategies
41
+ - **Data Structures:** Modeling domain objects effectively
42
+
43
+ ---
44
+
45
+ ## Template for New Pattern
46
+
47
+ ```markdown
48
+ ## [Category]
49
+
50
+ ### [Pattern Name]
51
+ **Context:** (When to use this pattern)
52
+ **Pattern:** (Description or code example)
53
+ **Rationale:** (Why this is better)
54
+ **Example Location:** (Where in codebase)
55
+ ```
12
56
 
13
57
  ---
14
58
 
15
- ## How to Add
59
+ ## Notes
16
60
 
17
- 1. Create pattern file: `.ai/patterns/{category}/{pattern-name}.md`
18
- 2. Add index entry here with link and brief description
19
- 3. Commit both files together
61
+ - Patterns should be language-agnostic when possible
62
+ - Prioritize patterns that prevent common bugs
63
+ - Link related patterns together
64
+ - Update this file as team learns new approaches
65
+ - Archive rarely-used patterns after 3 months of no references
@@ -70,7 +70,7 @@ Highlight 1-3 most important tasks for today.
70
70
 
71
71
  ## Notes
72
72
 
73
- - Check backlog.md for upcoming work
73
+ - Check prd.json for upcoming stories
74
74
  - Move completed tasks to archive or backlog with completion date
75
75
  - When stuck, create SPIKE task to investigate
76
76
  - Reference decisions from `memory/decisions.md`
@@ -4,103 +4,79 @@ This file defines the template for autonomous batch task execution via the `pwn
4
4
 
5
5
  ## Overview
6
6
 
7
- Batch task execution allows AI agents to autonomously:
8
- - Select tasks from backlog
9
- - Execute work in sequence
7
+ Batch task execution uses `.ai/batch/batch_runner.sh` to autonomously:
8
+ - Read stories from `.ai/tasks/prd.json`
9
+ - Spawn fresh Claude sessions per task
10
10
  - Run quality gates (tests, linting, type checking)
11
- - Commit changes following conventions
12
- - Continue until backlog depleted or threshold reached
11
+ - Track progress and learnings between iterations
12
+ - Handle retries, rate limits, and circuit breaking
13
13
 
14
14
  ## Usage
15
15
 
16
16
  ```bash
17
- # Execute next available task
18
- pwn batch
17
+ # Preview next task
18
+ ./.ai/batch/batch_runner.sh --dry-run
19
19
 
20
- # Execute specific number of tasks
21
- pwn batch --count 5
20
+ # Run batch (default 20 iterations)
21
+ ./.ai/batch/batch_runner.sh
22
22
 
23
- # Dry-run: show what would execute
24
- pwn batch --dry-run
23
+ # Custom iteration limit
24
+ ./.ai/batch/batch_runner.sh 50
25
25
 
26
- # Execute with specific priority
27
- pwn batch --priority high
26
+ # Specific phase only
27
+ ./.ai/batch/batch_runner.sh --phase 3
28
28
 
29
- # Resume interrupted batch
30
- pwn batch --resume
29
+ # Via pwn CLI
30
+ pwn batch run
31
+ pwn batch run --dry-run
32
+ pwn batch status
31
33
  ```
32
34
 
33
35
  ## Batch Execution Protocol
34
36
 
35
37
  ### Phase 1: Task Selection
36
38
 
37
- 1. Read `tasks/active.md` for incomplete tasks
38
- 2. If active tasks exist and not blocked, resume
39
- 3. Otherwise, read `tasks/backlog.md`
40
- 4. Select highest priority unblocked task
41
- 5. Verify dependencies are met
42
- 6. Move to `active.md`
39
+ 1. Read `tasks/prd.json` for stories
40
+ 2. Find next story where `passes == false`
41
+ 3. Verify all dependencies have `passes == true`
42
+ 4. Apply phase filter if specified
43
43
 
44
44
  ### Phase 2: Execution
45
45
 
46
- 1. Analyze task requirements
47
- 2. Create feature branch: `feature/[task-id]-[slug]`
48
- 3. Execute work following patterns in `patterns/index.md`
49
- 4. Test incrementally during development
50
- 5. Keep commits atomic and descriptive
46
+ 1. Build prompt from `.ai/batch/prompt.md` template
47
+ 2. Substitute story placeholders ({STORY_ID}, {STORY_TITLE}, etc.)
48
+ 3. Spawn: `claude --print --dangerously-skip-permissions -p "<prompt>"`
49
+ 4. Capture output to `logs/` for debugging
51
50
 
52
51
  ### Phase 3: Quality Gates
53
52
 
54
- Before commit, verify:
53
+ Customize `run_quality_gates()` in `batch_runner.sh` for your stack:
55
54
 
55
+ **Node.js:**
56
56
  ```bash
57
- # Type checking
58
- [ ] npm run typecheck || tsc --noEmit
59
-
60
- # Linting
61
- [ ] npm run lint || eslint .
62
-
63
- # Unit tests
64
- [ ] npm run test || jest
65
-
66
- # Integration tests (if applicable)
67
- [ ] npm run test:integration
68
-
69
- # Build verification
70
- [ ] npm run build
57
+ npm test
58
+ npm run lint
59
+ npm run typecheck
60
+ ```
71
61
 
72
- # Security scan (if configured)
73
- [ ] npm run security
62
+ **Python:**
63
+ ```bash
64
+ pytest --tb=short
65
+ ruff check src/
66
+ mypy src/ --ignore-missing-imports
74
67
  ```
75
68
 
76
69
  **Gate Strategy:**
77
70
  - Fail fast on first error
78
- - Output clear error message
79
- - Suggest fix if known
80
- - Option to skip non-critical gates with `--force`
81
-
82
- ### Phase 4: Commit & Cleanup
83
-
84
- 1. Stage all changes: `git add .`
85
- 2. Commit with message format:
86
- ```
87
- feat: [task-id] - [description]
88
-
89
- - Specific change 1
90
- - Specific change 2
91
-
92
- Fixes: [task-id]
93
- ```
94
- 3. Push to remote: `git push -u origin feature/[task-id]-[slug]`
95
- 4. Create PR if configured
96
- 5. Update `active.md`: mark complete with date
71
+ - Retry up to 2x with error context fed back to Claude
72
+ - Circuit breaker after 3 consecutive failures
97
73
 
98
- ### Phase 5: Completion
74
+ ### Phase 4: Completion
99
75
 
100
- 1. Verify commit is on remote
101
- 2. Delete local feature branch
102
- 3. Report completion to user
103
- 4. Continue to next task or stop
76
+ 1. Mark story as `passes: true` in prd.json
77
+ 2. Append learnings to `progress.txt`
78
+ 3. Commit prd.json + progress.txt update
79
+ 4. Continue to next story
104
80
 
105
81
  ## Batch Configuration
106
82
 
@@ -77,10 +77,10 @@ pwn mode interactive
77
77
 
78
78
  ### Batch Mode
79
79
 
80
- - Claude executes tasks autonomously from backlog
81
- - Creates feature branches per task
80
+ - Claude executes stories autonomously from prd.json
81
+ - Spawns fresh sessions per task via batch_runner.sh
82
82
  - Runs quality gates before committing
83
- - Continues until backlog empty or limits reached
83
+ - Retries with error context, circuit breaker on failures
84
84
  - Good for repetitive tasks and overnight execution
85
85
 
86
86
  ---
@@ -94,9 +94,10 @@ After executing the command, explain to the user:
94
94
  3. **Next steps** - What they can do next
95
95
 
96
96
  For batch mode, remind them:
97
- - Add tasks to `.ai/tasks/backlog.md`
98
- - Run `pwn batch` to start executing tasks
97
+ - Add stories to `.ai/tasks/prd.json`
98
+ - Run `pwn batch run` to start the batch runner
99
99
  - Use `pwn batch status` to check progress
100
+ - Use `.ai/batch/prd_status.sh` for detailed PRD view
100
101
 
101
102
  For interactive mode, remind them:
102
103
  - Work proceeds conversationally
@@ -103,50 +103,10 @@ Create a session summary:
103
103
  ## Dead Ends
104
104
  - DE-XXX: description (if any)
105
105
 
106
- ## Patterns Documented
107
- - [{category}/{name}] - description (if any)
108
-
109
106
  ---
110
107
  *Saved: {ISO timestamp}*
111
108
  ```
112
109
 
113
- ### 6. Pattern Extraction (.ai/patterns/)
114
-
115
- Review the entire session and extract patterns. Check each criterion:
116
-
117
- 1. **User corrected your approach** → Document the correct approach
118
- 2. **You chose between alternatives** → Document what was chosen and why
119
- 3. **Workaround for limitation** → Document the workaround
120
- 4. **Convention established** → Document for consistency
121
- 5. **Repeated approach** → Document to avoid re-deriving
122
- 6. **Non-trivial solution** → Document for future sessions
123
-
124
- **For each pattern found:**
125
-
126
- 1. Create file: `.ai/patterns/{category}/{pattern-name}.md`
127
- ```markdown
128
- # Pattern Name
129
-
130
- ## Context
131
- When to apply this pattern.
132
-
133
- ## Pattern
134
- Description or code example.
135
-
136
- ## Rationale
137
- Why this approach works better.
138
-
139
- ## Examples
140
- - `src/path/file.ts:42`
141
- ```
142
-
143
- 2. Add index entry to `.ai/memory/patterns.md`:
144
- ```markdown
145
- - [{category}/{name}](.ai/patterns/{category}/{name}.md) - Brief description
146
- ```
147
-
148
- **If no patterns found:** Confirm "Patterns: no new patterns this session"
149
-
150
110
  ---
151
111
 
152
112
  ## Output Format
@@ -159,7 +119,6 @@ PWN Save Complete:
159
119
  - Tasks: {X} active, {Y} completed
160
120
  - Dead Ends: {new count or "no new"}
161
121
  - Decisions: {new count or "no new"}
162
- - Patterns: {new count or "no new"}
163
122
  - Archive: .ai/memory/archive/{filename}
164
123
  - Last updated: {timestamp}
165
124
  ```
@@ -173,7 +132,6 @@ PWN Save Complete:
173
132
  3. **decisions.md**: Organized entries with proper DEC-XXX IDs
174
133
  4. **active.md**: Only current sprint tasks
175
134
  5. **archive/**: One file per session with summary
176
- 6. **patterns/**: One file per pattern, indexed in memory/patterns.md
177
135
 
178
136
  ---
179
137
 
@@ -2,11 +2,20 @@
2
2
  "hooks": {
3
3
  "Notification": [
4
4
  {
5
- "matcher": "",
5
+ "matcher": "permission_prompt",
6
6
  "hooks": [
7
7
  {
8
8
  "type": "command",
9
- "command": "pwn notify send \"Claude Code aguardando permissao\" --title \"PWN\""
9
+ "command": "pwn notify send \"Claude Code aguardando permissão\" --title \"PWN\""
10
+ }
11
+ ]
12
+ },
13
+ {
14
+ "matcher": "idle_prompt",
15
+ "hooks": [
16
+ {
17
+ "type": "command",
18
+ "command": "pwn notify send \"Claude Code aguardando input\" --title \"PWN\""
10
19
  }
11
20
  ]
12
21
  }