@fermindi/pwn-cli 0.1.1 → 0.2.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.
Files changed (46) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +265 -251
  3. package/cli/batch.js +333 -333
  4. package/cli/codespaces.js +303 -303
  5. package/cli/index.js +98 -91
  6. package/cli/inject.js +78 -67
  7. package/cli/knowledge.js +531 -531
  8. package/cli/migrate.js +466 -0
  9. package/cli/notify.js +135 -135
  10. package/cli/patterns.js +665 -665
  11. package/cli/status.js +91 -91
  12. package/cli/validate.js +61 -61
  13. package/package.json +70 -70
  14. package/src/core/inject.js +208 -204
  15. package/src/core/state.js +91 -91
  16. package/src/core/validate.js +202 -202
  17. package/src/core/workspace.js +176 -176
  18. package/src/index.js +20 -20
  19. package/src/knowledge/gc.js +308 -308
  20. package/src/knowledge/lifecycle.js +401 -401
  21. package/src/knowledge/promote.js +364 -364
  22. package/src/knowledge/references.js +342 -342
  23. package/src/patterns/matcher.js +218 -218
  24. package/src/patterns/registry.js +375 -375
  25. package/src/patterns/triggers.js +423 -423
  26. package/src/services/batch-service.js +849 -849
  27. package/src/services/notification-service.js +342 -342
  28. package/templates/codespaces/devcontainer.json +52 -52
  29. package/templates/codespaces/setup.sh +70 -70
  30. package/templates/workspace/.ai/README.md +164 -164
  31. package/templates/workspace/.ai/agents/README.md +204 -204
  32. package/templates/workspace/.ai/agents/claude.md +625 -625
  33. package/templates/workspace/.ai/config/README.md +79 -79
  34. package/templates/workspace/.ai/config/notifications.template.json +20 -20
  35. package/templates/workspace/.ai/memory/deadends.md +79 -79
  36. package/templates/workspace/.ai/memory/decisions.md +58 -58
  37. package/templates/workspace/.ai/memory/patterns.md +65 -65
  38. package/templates/workspace/.ai/patterns/backend/README.md +126 -126
  39. package/templates/workspace/.ai/patterns/frontend/README.md +103 -103
  40. package/templates/workspace/.ai/patterns/index.md +256 -256
  41. package/templates/workspace/.ai/patterns/triggers.json +1087 -1087
  42. package/templates/workspace/.ai/patterns/universal/README.md +141 -141
  43. package/templates/workspace/.ai/state.template.json +8 -8
  44. package/templates/workspace/.ai/tasks/active.md +77 -77
  45. package/templates/workspace/.ai/tasks/backlog.md +95 -95
  46. package/templates/workspace/.ai/workflows/batch-task.md +356 -356
@@ -1,625 +1,625 @@
1
- # Claude Code Bootstrap Instructions
2
-
3
- Complete bootstrap protocol for Claude Code AI agent working with PWN framework.
4
-
5
- **Version:** 1.0.0
6
- **Agent:** Claude Code (Claude Opus 4.5+)
7
- **Framework:** PWN (Project Workspace Network)
8
-
9
- ---
10
-
11
- ## Session Start Protocol
12
-
13
- Follow this sequence every time you start a Claude Code session.
14
-
15
- ### Step 1: Load Session State (1 min)
16
-
17
- Read `/.ai/state.json` to understand current session:
18
-
19
- ```json
20
- {
21
- "developer": "your-git-username",
22
- "session_started": "2026-01-21T00:00:00Z",
23
- "session_mode": "interactive",
24
- "current_task": null,
25
- "context_loaded": []
26
- }
27
- ```
28
-
29
- This file is git-ignored and tracks your personal session state.
30
-
31
- ### Step 2: Load Shared Context (5 min)
32
-
33
- Read these files in order:
34
-
35
- 1. **`/.ai/memory/decisions.md`**
36
- - Contains architectural decisions (DEC-XXX)
37
- - Reference these decisions when making changes
38
- - Ask user before deviating from active decisions
39
-
40
- 2. **`/.ai/memory/patterns.md`**
41
- - Codebase patterns learned by team
42
- - Apply these patterns to new work
43
- - Add new patterns when discovered
44
-
45
- 3. **`/.ai/memory/deadends.md`**
46
- - Failed approaches documented (DE-XXX)
47
- - Avoid these approaches
48
- - Reference when encountering similar problems
49
-
50
- ### Step 3: Check Current Work State (2 min)
51
-
52
- Review `/.ai/state.json` for:
53
- - `current_task`: What you were working on (if any)
54
- - `context_loaded`: What context files you've already read
55
- - `session_mode`: "interactive" or "batch"
56
-
57
- Then check `/.ai/tasks/active.md`:
58
- - What tasks are currently assigned
59
- - What's blocked and why
60
- - Priority ordering
61
-
62
- If this is your first session:
63
- - `current_task` will be null
64
- - Proceed to check project-specific guidance in `/CLAUDE.md` or `/README.md`
65
-
66
- ### Step 4: Load Project Context (3 min)
67
-
68
- 1. **`/.ai/tasks/active.md`**
69
- - What work is currently in progress
70
- - Your task assignments
71
- - Blocked items and blockers
72
- - Priority ordering
73
-
74
- 2. **`/.ai/tasks/backlog.md`** (if needed)
75
- - Future work not yet started
76
- - Use when no active work assigned
77
- - Pick highest priority unblocked item
78
-
79
- 3. **Project-specific notes** (if applicable)
80
- - Check `/CLAUDE.md` in project root
81
- - May override or extend these instructions
82
- - Always follow project-specific rules
83
-
84
- ### Step 5: Register Pattern Auto-Apply Triggers (2 min)
85
-
86
- Update `/.ai/state.json` to mark context as loaded:
87
- ```json
88
- {
89
- "context_loaded": ["memory", "tasks", "patterns"]
90
- }
91
- ```
92
-
93
- Read `/.ai/patterns/index.md`
94
-
95
- For each trigger type:
96
- - File extension patterns (`*.tsx`, `*.ts`)
97
- - Import patterns (`from 'react'`, `import.*express`)
98
- - Path patterns (`src/components/`, `routes/`)
99
- - Keyword patterns (`interface`, `class`, `useEffect`)
100
- - Command patterns (`npm build`, `git commit`)
101
-
102
- When working, auto-load relevant patterns:
103
- - Editing `.tsx` file → Load frontend/react patterns
104
- - Writing tests → Load universal/testing patterns
105
- - Creating API route → Load backend/express + universal/rest-api patterns
106
-
107
- ### Step 6: Check Configuration (1 min)
108
-
109
- Read `/.ai/state.json` (if exists)
110
-
111
- Important settings:
112
- - `developer`: Your name
113
- - `session_mode`: "interactive" or "batch"
114
- - `auto_patterns`: true/false (pattern auto-apply enabled?)
115
- - `batch_config`: Settings if running in batch mode
116
- - `quality_gates`: Tests/lint/typecheck requirements
117
-
118
- ### Step 7: Acknowledge Understanding (1 min)
119
-
120
- In your first message, confirm what you learned:
121
-
122
- ```
123
- I've loaded the following context for this session:
124
- - Decisions: DEC-001, DEC-002 (active)
125
- - Current task: US-042 (from active.md)
126
- - Recent dead end: DE-003 (avoided earlier approach)
127
- - Developer: {username}
128
- - Mode: Interactive
129
-
130
- I'm ready to work on: [describe current task]
131
- ```
132
-
133
- This confirms you understand the context before proceeding.
134
-
135
- ---
136
-
137
- ## Interactive Mode
138
-
139
- When `session_mode` is "interactive":
140
-
141
- ### Your Role
142
- - Respond to user requests and commands
143
- - Ask clarifying questions when context is incomplete
144
- - Reference decisions and patterns in your work
145
- - Update patterns when you discover new approaches
146
- - Document dead ends when approaches fail
147
- - Commit changes with clear messages
148
-
149
- ### Workflow
150
-
151
- ```
152
- User Request
153
-
154
- Load relevant context (decisions, patterns, active task)
155
-
156
- Understand requirement
157
-
158
- Check patterns/index.md for triggers
159
-
160
- Execute work following patterns
161
-
162
- Run quality gates (tests, lint, typecheck)
163
-
164
- Commit with clear message
165
-
166
- Update active task status
167
-
168
- Report completion
169
- ```
170
-
171
- ### Quality Gates
172
-
173
- Before committing code, verify:
174
-
175
- 1. **Type Checking**
176
- ```bash
177
- npm run typecheck || tsc --noEmit
178
- ```
179
- Must pass without errors
180
-
181
- 2. **Linting**
182
- ```bash
183
- npm run lint || eslint .
184
- ```
185
- Must pass (or auto-fix if applicable)
186
-
187
- 3. **Unit Tests**
188
- ```bash
189
- npm run test || jest
190
- ```
191
- Must pass all tests
192
-
193
- 4. **Integration Tests** (if applicable)
194
- ```bash
195
- npm run test:integration
196
- ```
197
- Must pass
198
-
199
- 5. **Build Verification**
200
- ```bash
201
- npm run build
202
- ```
203
- Must complete successfully
204
-
205
- If any gate fails:
206
- - Show the error
207
- - Offer to fix if pattern known
208
- - Ask user if unsure how to proceed
209
- - Don't commit until gates pass
210
-
211
- ### Commit Message Format
212
-
213
- Use conventional commits:
214
-
215
- ```
216
- type(scope): description
217
-
218
- Detailed explanation of change.
219
-
220
- Reference relevant decisions:
221
- - See DEC-XXX for rationale
222
- - Implements US-042
223
-
224
- Related patterns:
225
- - Applied frontend/react patterns
226
- - Follows universal/typescript guidelines
227
- ```
228
-
229
- Types:
230
- - `feat:` New feature
231
- - `fix:` Bug fix
232
- - `docs:` Documentation
233
- - `style:` Code formatting
234
- - `refactor:` Code restructuring
235
- - `perf:` Performance improvement
236
- - `test:` Test additions/changes
237
- - `chore:` Build, tooling, dependencies
238
-
239
- ### Task Tracking
240
-
241
- When completing work:
242
-
243
- 1. Update `/.ai/tasks/active.md`
244
- ```markdown
245
- - [x] US-042: My completed task (YYYY-MM-DD)
246
- ```
247
-
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
- ```
257
-
258
- 3. Add to `/.ai/memory/deadends.md` if approach failed
259
- ```
260
- ## DE-XXX: What we tried
261
- **Date:** YYYY-MM-DD
262
- **Attempted:** Description
263
- **Problem:** Why it failed
264
- **Solution:** What worked instead
265
- ```
266
-
267
- ---
268
-
269
- ## Batch Mode
270
-
271
- When `session_mode` is "batch" (autonomous task execution):
272
-
273
- ### Your Role
274
- - Execute tasks from backlog autonomously
275
- - Follow quality gates strictly
276
- - Make conservative decisions (ask user when uncertain)
277
- - Commit and push changes automatically
278
- - Continue until backlog depleted or limits reached
279
-
280
- ### Batch Workflow
281
-
282
- ```
283
- 1. Read tasks/active.md
284
- ├─ If incomplete tasks: resume work
285
- └─ If no active tasks: read backlog.md
286
-
287
- 2. Select highest-priority unblocked task
288
- ├─ Check dependencies
289
- ├─ Verify not blocked
290
- └─ Move to tasks/active.md
291
-
292
- 3. Create feature branch
293
- └─ Name: feature/{task-id}-{slug}
294
-
295
- 4. Execute work following patterns
296
- ├─ Auto-apply triggers from patterns/index.md
297
- ├─ Keep commits atomic and descriptive
298
- └─ Test incrementally
299
-
300
- 5. Quality gates must pass
301
- ├─ If gate fails:
302
- │ ├─ Attempt auto-fix if pattern known
303
- │ ├─ Pause batch if can't fix
304
- │ └─ Notify user
305
- └─ If all pass: proceed to commit
306
-
307
- 6. Commit and push
308
- ├─ Stage all changes
309
- ├─ Commit with conventional format
310
- ├─ Push to origin
311
- └─ Create PR if configured
312
-
313
- 7. Clean up and continue
314
- ├─ Delete local feature branch
315
- ├─ Update tasks/active.md
316
- ├─ Check if more tasks to execute
317
- └─ Continue or stop
318
-
319
- 8. Completion report
320
- └─ Show summary: tasks done, time spent, any issues
321
- ```
322
-
323
- ### Batch Configuration
324
-
325
- Read from `/.ai/state.json`:
326
-
327
- ```json
328
- {
329
- "batch_config": {
330
- "max_tasks": 5,
331
- "max_duration_hours": 4,
332
- "quality_gates": ["typecheck", "lint", "test"],
333
- "skip_gates": [],
334
- "auto_commit": true,
335
- "auto_push": false,
336
- "create_pr": false,
337
- "branch_format": "feature/{id}-{slug}",
338
- "commit_format": "conventional"
339
- }
340
- }
341
- ```
342
-
343
- **Important:** Batch mode is conservative:
344
- - Don't skip quality gates without explicit config
345
- - Ask user if uncertain about task interpretation
346
- - Stop on first blocker and notify user
347
- - Don't force push or destructive operations
348
- - Log all decisions and timing
349
-
350
- ### Batch Error Handling
351
-
352
- **Build/Test Fails:**
353
- - Show error with full context
354
- - If pattern known: auto-fix
355
- - If unsure: pause and notify user
356
- - Don't proceed without resolution
357
-
358
- **Git Conflicts:**
359
- - Stop immediately
360
- - Notify user of conflict
361
- - Require manual resolution
362
- - Resume after conflict resolved
363
-
364
- **Missing Dependencies:**
365
- - Check if dependency task exists
366
- - Add to batch queue if available
367
- - Execute dependency first
368
- - Resume original task
369
-
370
- **Resource Limits Reached:**
371
- - Stop execution gracefully
372
- - Report progress
373
- - Create clean state for next batch
374
- - Notify user of completion status
375
-
376
- ---
377
-
378
- ## Context Loading Order
379
-
380
- Reference these files in this priority order:
381
-
382
- 1. **First Priority: Active Work**
383
- - `/.ai/state.json` - Your personal session state
384
- - `/.ai/tasks/active.md` - What's being done now
385
- - Current file being edited
386
-
387
- 2. **Second Priority: Decisions**
388
- - `/.ai/memory/decisions.md` - What was decided and why
389
- - `/CLAUDE.md` if exists - Project-specific overrides
390
- - Code comments referencing decisions
391
-
392
- 3. **Third Priority: Patterns**
393
- - `/.ai/patterns/index.md` - Trigger map for auto-apply
394
- - Relevant subdirectories in `/.ai/patterns/`
395
- - Code examples from existing codebase
396
-
397
- 4. **Fourth Priority: Historical Context**
398
- - `/.ai/memory/deadends.md` - What failed (avoid!)
399
- - `/.ai/memory/archive/` - Superseded decisions
400
- - Project changelog or git history
401
-
402
- 5. **Fifth Priority: Planning**
403
- - `/.ai/tasks/backlog.md` - Future work
404
- - Roadmap or project documentation
405
- - Upstream issues or features
406
-
407
- ---
408
-
409
- ## Pattern Auto-Application
410
-
411
- Patterns are automatically applied based on triggers in `/.ai/patterns/index.md`.
412
-
413
- ### How It Works
414
-
415
- 1. You start editing a file (e.g., `src/components/Button.tsx`)
416
- 2. Extension matches: `*.tsx`
417
- 3. Auto-load patterns:
418
- - `/.ai/patterns/frontend/react/` (React components)
419
- - `/.ai/patterns/universal/typescript/` (TypeScript)
420
- 4. Apply patterns to your work
421
- 5. Reference pattern in code comment if complex
422
-
423
- ### Example Triggers
424
-
425
- ```
426
- File: src/components/Button.tsx
427
- Triggers: *.tsx, path: src/components/
428
- Load: frontend/react, universal/typescript
429
- Apply: React component best practices
430
-
431
- File: src/routes/api/videos.ts
432
- Triggers: *.routes.ts, keyword: app.get|app.post|router.use
433
- Load: backend/express, universal/rest-api
434
- Apply: Express routing patterns
435
-
436
- File: src/__tests__/utils.test.ts
437
- Triggers: *.test.ts, import: jest|vitest
438
- Load: universal/testing/unit
439
- Apply: Unit testing patterns
440
- ```
441
-
442
- ### Overriding Patterns
443
-
444
- If pattern doesn't apply:
445
-
446
- 1. Check if trigger condition is correct
447
- 2. Review pattern directory (might be different name)
448
- 3. Manually import pattern if needed
449
- 4. Update `patterns/index.md` if trigger was wrong
450
-
451
- ---
452
-
453
- ## Decision-Making Framework
454
-
455
- When making architectural decisions:
456
-
457
- 1. **Check existing decisions** - Is this already decided?
458
- - Look in `/.ai/memory/decisions.md`
459
- - Reference decision with "See DEC-XXX"
460
-
461
- 2. **Check patterns** - Is there a pattern to follow?
462
- - Look in `/.ai/patterns/`
463
- - Apply pattern without deviation
464
-
465
- 3. **Check dead ends** - Has this failed before?
466
- - Look in `/.ai/memory/deadends.md`
467
- - Avoid approaches in DE-XXX
468
-
469
- 4. **When in doubt:** Ask the user
470
- - Don't make big architectural decisions alone
471
- - Explain options and ask for preference
472
- - Reference decisions and patterns in explanation
473
-
474
- 5. **Document new decisions**
475
- - If making significant choice: suggest updating `/.ai/memory/decisions.md`
476
- - Include context, rationale, and impact
477
- - Commit with message: `docs: add DEC-XXX decision`
478
-
479
- ---
480
-
481
- ## Common Questions
482
-
483
- ### Q: What if I can't find context I need?
484
-
485
- **A:** Check these locations in order:
486
- 1. `/.ai/` directory (patterns, decisions, tasks)
487
- 2. Project root files (README.md, CLAUDE.md, etc.)
488
- 3. Codebase examples (similar code patterns)
489
- 4. Ask the user - context might not exist yet
490
-
491
- ### Q: Should I commit every small change?
492
-
493
- **A:** Keep commits:
494
- - Atomic (one logical change)
495
- - Focused (don't mix unrelated changes)
496
- - Well-described (use conventional commits)
497
- - Under 300 lines if possible
498
-
499
- Multiple small commits are better than one big commit.
500
-
501
- ### Q: When should I update patterns?md?
502
-
503
- **A:** Add to patterns when:
504
- - You discover a reusable approach
505
- - Multiple tasks benefit from the pattern
506
- - It prevents common mistakes
507
- - It's team-relevant (not just personal preference)
508
-
509
- Update commit message: `docs: add pattern - [name]`
510
-
511
- ### Q: What if quality gates fail in batch mode?
512
-
513
- **A:** Batch mode stops and:
514
- 1. Shows error details
515
- 2. Pauses execution
516
- 3. Notifies user
517
- 4. Waits for manual intervention or approval
518
-
519
- Batch never force-commits on failures.
520
-
521
- ### Q: How do I know if something is blocked?
522
-
523
- **A:** Task is blocked if:
524
- - Listed in `tasks/active.md` with "Blocked by:" section
525
- - Depends on other unfinished task
526
- - Waiting for external event (approval, API key, etc.)
527
- - Resource constraint (hardware, capacity)
528
-
529
- Don't skip blocked tasks - document blocker and move to next.
530
-
531
- ---
532
-
533
- ## Tips for Effective Sessions
534
-
535
- 1. **Start strong** - Read all context files before writing code
536
- 2. **Reference decisions** - Use DEC-XXX, DE-XXX, patterns in comments
537
- 3. **Commit often** - Small commits are easier to review and revert
538
- 4. **Test continuously** - Run quality gates before commit
539
- 5. **Update context** - Document patterns and dead ends as you learn
540
- 6. **Ask when uncertain** - Better to ask than make wrong assumption
541
- 7. **Keep patterns current** - Archive old patterns, add new discoveries
542
- 8. **Think long-term** - Each decision affects future sessions
543
-
544
- ---
545
-
546
- ## Troubleshooting
547
-
548
- ### "I can't find the context I need"
549
- - Check if file exists in `/.ai/`
550
- - Search with Grep tool for specific content
551
- - Ask user where context is documented
552
- - May need to create new context file
553
-
554
- ### "Pattern doesn't seem to apply"
555
- - Verify trigger condition matches
556
- - Check different pattern directory
557
- - Manually load pattern if needed
558
- - Update pattern or trigger
559
-
560
- ### "Quality gates failing"
561
- - Show full error output
562
- - If pattern known: apply fix
563
- - If unsure: ask user or pause batch
564
- - Never skip gates without explicit approval
565
-
566
- ### "Unsure if change follows decisions"
567
- - Find relevant decision in `memories/decisions.md`
568
- - If not found: ask user for guidance
569
- - If contradicts decision: request user approval
570
- - Reference decision in commit message
571
-
572
- ### "Need to deviate from pattern"
573
- - Document deviation in code comment
574
- - Explain why pattern doesn't apply
575
- - Consider updating pattern if it's flawed
576
- - Get user approval if architectural impact
577
-
578
- ---
579
-
580
- ## Session Completion
581
-
582
- When finishing a session:
583
-
584
- 1. **Commit pending work**
585
- - All changes staged and committed
586
- - Commit message references task/decision
587
-
588
- 2. **Update task status**
589
- - Check boxes in `/.ai/tasks/active.md`
590
- - Add completion date if done
591
-
592
- 3. **Document learnings**
593
- - Update `/.ai/memory/patterns.md` if discovered pattern
594
- - Update `/.ai/memory/deadends.md` if failed approach
595
- - Reference in commit messages
596
-
597
- 4. **Clean up**
598
- - No uncommitted changes
599
- - Local branches cleaned up
600
- - Remote is up to date
601
-
602
- 5. **Summary to user**
603
- - What was accomplished
604
- - What's still pending
605
- - Next steps
606
- - Any blockers
607
-
608
- ---
609
-
610
- ## Next Session
611
-
612
- When returning:
613
-
614
- 1. Read `/.ai/state.json` for your last session state
615
- 2. Check `current_task` to see what you were working on
616
- 3. Start from Step 2 of Session Start Protocol
617
- 4. Pick up from where you left off
618
- 5. Update `session_started` timestamp in state.json
619
-
620
- ---
621
-
622
- **Document Version:** 1.0.0
623
- **Last Updated:** Template injection date
624
- **Framework:** PWN 1.0.0
625
- **Supported Models:** Claude Opus 4.5+
1
+ # Claude Code Bootstrap Instructions
2
+
3
+ Complete bootstrap protocol for Claude Code AI agent working with PWN framework.
4
+
5
+ **Version:** 1.0.0
6
+ **Agent:** Claude Code (Claude Opus 4.5+)
7
+ **Framework:** PWN (Project Workspace Network)
8
+
9
+ ---
10
+
11
+ ## Session Start Protocol
12
+
13
+ Follow this sequence every time you start a Claude Code session.
14
+
15
+ ### Step 1: Load Session State (1 min)
16
+
17
+ Read `/.ai/state.json` to understand current session:
18
+
19
+ ```json
20
+ {
21
+ "developer": "your-git-username",
22
+ "session_started": "2026-01-21T00:00:00Z",
23
+ "session_mode": "interactive",
24
+ "current_task": null,
25
+ "context_loaded": []
26
+ }
27
+ ```
28
+
29
+ This file is git-ignored and tracks your personal session state.
30
+
31
+ ### Step 2: Load Shared Context (5 min)
32
+
33
+ Read these files in order:
34
+
35
+ 1. **`/.ai/memory/decisions.md`**
36
+ - Contains architectural decisions (DEC-XXX)
37
+ - Reference these decisions when making changes
38
+ - Ask user before deviating from active decisions
39
+
40
+ 2. **`/.ai/memory/patterns.md`**
41
+ - Codebase patterns learned by team
42
+ - Apply these patterns to new work
43
+ - Add new patterns when discovered
44
+
45
+ 3. **`/.ai/memory/deadends.md`**
46
+ - Failed approaches documented (DE-XXX)
47
+ - Avoid these approaches
48
+ - Reference when encountering similar problems
49
+
50
+ ### Step 3: Check Current Work State (2 min)
51
+
52
+ Review `/.ai/state.json` for:
53
+ - `current_task`: What you were working on (if any)
54
+ - `context_loaded`: What context files you've already read
55
+ - `session_mode`: "interactive" or "batch"
56
+
57
+ Then check `/.ai/tasks/active.md`:
58
+ - What tasks are currently assigned
59
+ - What's blocked and why
60
+ - Priority ordering
61
+
62
+ If this is your first session:
63
+ - `current_task` will be null
64
+ - Proceed to check project-specific guidance in `/CLAUDE.md` or `/README.md`
65
+
66
+ ### Step 4: Load Project Context (3 min)
67
+
68
+ 1. **`/.ai/tasks/active.md`**
69
+ - What work is currently in progress
70
+ - Your task assignments
71
+ - Blocked items and blockers
72
+ - Priority ordering
73
+
74
+ 2. **`/.ai/tasks/backlog.md`** (if needed)
75
+ - Future work not yet started
76
+ - Use when no active work assigned
77
+ - Pick highest priority unblocked item
78
+
79
+ 3. **Project-specific notes** (if applicable)
80
+ - Check `/CLAUDE.md` in project root
81
+ - May override or extend these instructions
82
+ - Always follow project-specific rules
83
+
84
+ ### Step 5: Register Pattern Auto-Apply Triggers (2 min)
85
+
86
+ Update `/.ai/state.json` to mark context as loaded:
87
+ ```json
88
+ {
89
+ "context_loaded": ["memory", "tasks", "patterns"]
90
+ }
91
+ ```
92
+
93
+ Read `/.ai/patterns/index.md`
94
+
95
+ For each trigger type:
96
+ - File extension patterns (`*.tsx`, `*.ts`)
97
+ - Import patterns (`from 'react'`, `import.*express`)
98
+ - Path patterns (`src/components/`, `routes/`)
99
+ - Keyword patterns (`interface`, `class`, `useEffect`)
100
+ - Command patterns (`npm build`, `git commit`)
101
+
102
+ When working, auto-load relevant patterns:
103
+ - Editing `.tsx` file → Load frontend/react patterns
104
+ - Writing tests → Load universal/testing patterns
105
+ - Creating API route → Load backend/express + universal/rest-api patterns
106
+
107
+ ### Step 6: Check Configuration (1 min)
108
+
109
+ Read `/.ai/state.json` (if exists)
110
+
111
+ Important settings:
112
+ - `developer`: Your name
113
+ - `session_mode`: "interactive" or "batch"
114
+ - `auto_patterns`: true/false (pattern auto-apply enabled?)
115
+ - `batch_config`: Settings if running in batch mode
116
+ - `quality_gates`: Tests/lint/typecheck requirements
117
+
118
+ ### Step 7: Acknowledge Understanding (1 min)
119
+
120
+ In your first message, confirm what you learned:
121
+
122
+ ```
123
+ I've loaded the following context for this session:
124
+ - Decisions: DEC-001, DEC-002 (active)
125
+ - Current task: US-042 (from active.md)
126
+ - Recent dead end: DE-003 (avoided earlier approach)
127
+ - Developer: {username}
128
+ - Mode: Interactive
129
+
130
+ I'm ready to work on: [describe current task]
131
+ ```
132
+
133
+ This confirms you understand the context before proceeding.
134
+
135
+ ---
136
+
137
+ ## Interactive Mode
138
+
139
+ When `session_mode` is "interactive":
140
+
141
+ ### Your Role
142
+ - Respond to user requests and commands
143
+ - Ask clarifying questions when context is incomplete
144
+ - Reference decisions and patterns in your work
145
+ - Update patterns when you discover new approaches
146
+ - Document dead ends when approaches fail
147
+ - Commit changes with clear messages
148
+
149
+ ### Workflow
150
+
151
+ ```
152
+ User Request
153
+
154
+ Load relevant context (decisions, patterns, active task)
155
+
156
+ Understand requirement
157
+
158
+ Check patterns/index.md for triggers
159
+
160
+ Execute work following patterns
161
+
162
+ Run quality gates (tests, lint, typecheck)
163
+
164
+ Commit with clear message
165
+
166
+ Update active task status
167
+
168
+ Report completion
169
+ ```
170
+
171
+ ### Quality Gates
172
+
173
+ Before committing code, verify:
174
+
175
+ 1. **Type Checking**
176
+ ```bash
177
+ npm run typecheck || tsc --noEmit
178
+ ```
179
+ Must pass without errors
180
+
181
+ 2. **Linting**
182
+ ```bash
183
+ npm run lint || eslint .
184
+ ```
185
+ Must pass (or auto-fix if applicable)
186
+
187
+ 3. **Unit Tests**
188
+ ```bash
189
+ npm run test || jest
190
+ ```
191
+ Must pass all tests
192
+
193
+ 4. **Integration Tests** (if applicable)
194
+ ```bash
195
+ npm run test:integration
196
+ ```
197
+ Must pass
198
+
199
+ 5. **Build Verification**
200
+ ```bash
201
+ npm run build
202
+ ```
203
+ Must complete successfully
204
+
205
+ If any gate fails:
206
+ - Show the error
207
+ - Offer to fix if pattern known
208
+ - Ask user if unsure how to proceed
209
+ - Don't commit until gates pass
210
+
211
+ ### Commit Message Format
212
+
213
+ Use conventional commits:
214
+
215
+ ```
216
+ type(scope): description
217
+
218
+ Detailed explanation of change.
219
+
220
+ Reference relevant decisions:
221
+ - See DEC-XXX for rationale
222
+ - Implements US-042
223
+
224
+ Related patterns:
225
+ - Applied frontend/react patterns
226
+ - Follows universal/typescript guidelines
227
+ ```
228
+
229
+ Types:
230
+ - `feat:` New feature
231
+ - `fix:` Bug fix
232
+ - `docs:` Documentation
233
+ - `style:` Code formatting
234
+ - `refactor:` Code restructuring
235
+ - `perf:` Performance improvement
236
+ - `test:` Test additions/changes
237
+ - `chore:` Build, tooling, dependencies
238
+
239
+ ### Task Tracking
240
+
241
+ When completing work:
242
+
243
+ 1. Update `/.ai/tasks/active.md`
244
+ ```markdown
245
+ - [x] US-042: My completed task (YYYY-MM-DD)
246
+ ```
247
+
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
+ ```
257
+
258
+ 3. Add to `/.ai/memory/deadends.md` if approach failed
259
+ ```
260
+ ## DE-XXX: What we tried
261
+ **Date:** YYYY-MM-DD
262
+ **Attempted:** Description
263
+ **Problem:** Why it failed
264
+ **Solution:** What worked instead
265
+ ```
266
+
267
+ ---
268
+
269
+ ## Batch Mode
270
+
271
+ When `session_mode` is "batch" (autonomous task execution):
272
+
273
+ ### Your Role
274
+ - Execute tasks from backlog autonomously
275
+ - Follow quality gates strictly
276
+ - Make conservative decisions (ask user when uncertain)
277
+ - Commit and push changes automatically
278
+ - Continue until backlog depleted or limits reached
279
+
280
+ ### Batch Workflow
281
+
282
+ ```
283
+ 1. Read tasks/active.md
284
+ ├─ If incomplete tasks: resume work
285
+ └─ If no active tasks: read backlog.md
286
+
287
+ 2. Select highest-priority unblocked task
288
+ ├─ Check dependencies
289
+ ├─ Verify not blocked
290
+ └─ Move to tasks/active.md
291
+
292
+ 3. Create feature branch
293
+ └─ Name: feature/{task-id}-{slug}
294
+
295
+ 4. Execute work following patterns
296
+ ├─ Auto-apply triggers from patterns/index.md
297
+ ├─ Keep commits atomic and descriptive
298
+ └─ Test incrementally
299
+
300
+ 5. Quality gates must pass
301
+ ├─ If gate fails:
302
+ │ ├─ Attempt auto-fix if pattern known
303
+ │ ├─ Pause batch if can't fix
304
+ │ └─ Notify user
305
+ └─ If all pass: proceed to commit
306
+
307
+ 6. Commit and push
308
+ ├─ Stage all changes
309
+ ├─ Commit with conventional format
310
+ ├─ Push to origin
311
+ └─ Create PR if configured
312
+
313
+ 7. Clean up and continue
314
+ ├─ Delete local feature branch
315
+ ├─ Update tasks/active.md
316
+ ├─ Check if more tasks to execute
317
+ └─ Continue or stop
318
+
319
+ 8. Completion report
320
+ └─ Show summary: tasks done, time spent, any issues
321
+ ```
322
+
323
+ ### Batch Configuration
324
+
325
+ Read from `/.ai/state.json`:
326
+
327
+ ```json
328
+ {
329
+ "batch_config": {
330
+ "max_tasks": 5,
331
+ "max_duration_hours": 4,
332
+ "quality_gates": ["typecheck", "lint", "test"],
333
+ "skip_gates": [],
334
+ "auto_commit": true,
335
+ "auto_push": false,
336
+ "create_pr": false,
337
+ "branch_format": "feature/{id}-{slug}",
338
+ "commit_format": "conventional"
339
+ }
340
+ }
341
+ ```
342
+
343
+ **Important:** Batch mode is conservative:
344
+ - Don't skip quality gates without explicit config
345
+ - Ask user if uncertain about task interpretation
346
+ - Stop on first blocker and notify user
347
+ - Don't force push or destructive operations
348
+ - Log all decisions and timing
349
+
350
+ ### Batch Error Handling
351
+
352
+ **Build/Test Fails:**
353
+ - Show error with full context
354
+ - If pattern known: auto-fix
355
+ - If unsure: pause and notify user
356
+ - Don't proceed without resolution
357
+
358
+ **Git Conflicts:**
359
+ - Stop immediately
360
+ - Notify user of conflict
361
+ - Require manual resolution
362
+ - Resume after conflict resolved
363
+
364
+ **Missing Dependencies:**
365
+ - Check if dependency task exists
366
+ - Add to batch queue if available
367
+ - Execute dependency first
368
+ - Resume original task
369
+
370
+ **Resource Limits Reached:**
371
+ - Stop execution gracefully
372
+ - Report progress
373
+ - Create clean state for next batch
374
+ - Notify user of completion status
375
+
376
+ ---
377
+
378
+ ## Context Loading Order
379
+
380
+ Reference these files in this priority order:
381
+
382
+ 1. **First Priority: Active Work**
383
+ - `/.ai/state.json` - Your personal session state
384
+ - `/.ai/tasks/active.md` - What's being done now
385
+ - Current file being edited
386
+
387
+ 2. **Second Priority: Decisions**
388
+ - `/.ai/memory/decisions.md` - What was decided and why
389
+ - `/CLAUDE.md` if exists - Project-specific overrides
390
+ - Code comments referencing decisions
391
+
392
+ 3. **Third Priority: Patterns**
393
+ - `/.ai/patterns/index.md` - Trigger map for auto-apply
394
+ - Relevant subdirectories in `/.ai/patterns/`
395
+ - Code examples from existing codebase
396
+
397
+ 4. **Fourth Priority: Historical Context**
398
+ - `/.ai/memory/deadends.md` - What failed (avoid!)
399
+ - `/.ai/memory/archive/` - Superseded decisions
400
+ - Project changelog or git history
401
+
402
+ 5. **Fifth Priority: Planning**
403
+ - `/.ai/tasks/backlog.md` - Future work
404
+ - Roadmap or project documentation
405
+ - Upstream issues or features
406
+
407
+ ---
408
+
409
+ ## Pattern Auto-Application
410
+
411
+ Patterns are automatically applied based on triggers in `/.ai/patterns/index.md`.
412
+
413
+ ### How It Works
414
+
415
+ 1. You start editing a file (e.g., `src/components/Button.tsx`)
416
+ 2. Extension matches: `*.tsx`
417
+ 3. Auto-load patterns:
418
+ - `/.ai/patterns/frontend/react/` (React components)
419
+ - `/.ai/patterns/universal/typescript/` (TypeScript)
420
+ 4. Apply patterns to your work
421
+ 5. Reference pattern in code comment if complex
422
+
423
+ ### Example Triggers
424
+
425
+ ```
426
+ File: src/components/Button.tsx
427
+ Triggers: *.tsx, path: src/components/
428
+ Load: frontend/react, universal/typescript
429
+ Apply: React component best practices
430
+
431
+ File: src/routes/api/videos.ts
432
+ Triggers: *.routes.ts, keyword: app.get|app.post|router.use
433
+ Load: backend/express, universal/rest-api
434
+ Apply: Express routing patterns
435
+
436
+ File: src/__tests__/utils.test.ts
437
+ Triggers: *.test.ts, import: jest|vitest
438
+ Load: universal/testing/unit
439
+ Apply: Unit testing patterns
440
+ ```
441
+
442
+ ### Overriding Patterns
443
+
444
+ If pattern doesn't apply:
445
+
446
+ 1. Check if trigger condition is correct
447
+ 2. Review pattern directory (might be different name)
448
+ 3. Manually import pattern if needed
449
+ 4. Update `patterns/index.md` if trigger was wrong
450
+
451
+ ---
452
+
453
+ ## Decision-Making Framework
454
+
455
+ When making architectural decisions:
456
+
457
+ 1. **Check existing decisions** - Is this already decided?
458
+ - Look in `/.ai/memory/decisions.md`
459
+ - Reference decision with "See DEC-XXX"
460
+
461
+ 2. **Check patterns** - Is there a pattern to follow?
462
+ - Look in `/.ai/patterns/`
463
+ - Apply pattern without deviation
464
+
465
+ 3. **Check dead ends** - Has this failed before?
466
+ - Look in `/.ai/memory/deadends.md`
467
+ - Avoid approaches in DE-XXX
468
+
469
+ 4. **When in doubt:** Ask the user
470
+ - Don't make big architectural decisions alone
471
+ - Explain options and ask for preference
472
+ - Reference decisions and patterns in explanation
473
+
474
+ 5. **Document new decisions**
475
+ - If making significant choice: suggest updating `/.ai/memory/decisions.md`
476
+ - Include context, rationale, and impact
477
+ - Commit with message: `docs: add DEC-XXX decision`
478
+
479
+ ---
480
+
481
+ ## Common Questions
482
+
483
+ ### Q: What if I can't find context I need?
484
+
485
+ **A:** Check these locations in order:
486
+ 1. `/.ai/` directory (patterns, decisions, tasks)
487
+ 2. Project root files (README.md, CLAUDE.md, etc.)
488
+ 3. Codebase examples (similar code patterns)
489
+ 4. Ask the user - context might not exist yet
490
+
491
+ ### Q: Should I commit every small change?
492
+
493
+ **A:** Keep commits:
494
+ - Atomic (one logical change)
495
+ - Focused (don't mix unrelated changes)
496
+ - Well-described (use conventional commits)
497
+ - Under 300 lines if possible
498
+
499
+ Multiple small commits are better than one big commit.
500
+
501
+ ### Q: When should I update patterns?md?
502
+
503
+ **A:** Add to patterns when:
504
+ - You discover a reusable approach
505
+ - Multiple tasks benefit from the pattern
506
+ - It prevents common mistakes
507
+ - It's team-relevant (not just personal preference)
508
+
509
+ Update commit message: `docs: add pattern - [name]`
510
+
511
+ ### Q: What if quality gates fail in batch mode?
512
+
513
+ **A:** Batch mode stops and:
514
+ 1. Shows error details
515
+ 2. Pauses execution
516
+ 3. Notifies user
517
+ 4. Waits for manual intervention or approval
518
+
519
+ Batch never force-commits on failures.
520
+
521
+ ### Q: How do I know if something is blocked?
522
+
523
+ **A:** Task is blocked if:
524
+ - Listed in `tasks/active.md` with "Blocked by:" section
525
+ - Depends on other unfinished task
526
+ - Waiting for external event (approval, API key, etc.)
527
+ - Resource constraint (hardware, capacity)
528
+
529
+ Don't skip blocked tasks - document blocker and move to next.
530
+
531
+ ---
532
+
533
+ ## Tips for Effective Sessions
534
+
535
+ 1. **Start strong** - Read all context files before writing code
536
+ 2. **Reference decisions** - Use DEC-XXX, DE-XXX, patterns in comments
537
+ 3. **Commit often** - Small commits are easier to review and revert
538
+ 4. **Test continuously** - Run quality gates before commit
539
+ 5. **Update context** - Document patterns and dead ends as you learn
540
+ 6. **Ask when uncertain** - Better to ask than make wrong assumption
541
+ 7. **Keep patterns current** - Archive old patterns, add new discoveries
542
+ 8. **Think long-term** - Each decision affects future sessions
543
+
544
+ ---
545
+
546
+ ## Troubleshooting
547
+
548
+ ### "I can't find the context I need"
549
+ - Check if file exists in `/.ai/`
550
+ - Search with Grep tool for specific content
551
+ - Ask user where context is documented
552
+ - May need to create new context file
553
+
554
+ ### "Pattern doesn't seem to apply"
555
+ - Verify trigger condition matches
556
+ - Check different pattern directory
557
+ - Manually load pattern if needed
558
+ - Update pattern or trigger
559
+
560
+ ### "Quality gates failing"
561
+ - Show full error output
562
+ - If pattern known: apply fix
563
+ - If unsure: ask user or pause batch
564
+ - Never skip gates without explicit approval
565
+
566
+ ### "Unsure if change follows decisions"
567
+ - Find relevant decision in `memories/decisions.md`
568
+ - If not found: ask user for guidance
569
+ - If contradicts decision: request user approval
570
+ - Reference decision in commit message
571
+
572
+ ### "Need to deviate from pattern"
573
+ - Document deviation in code comment
574
+ - Explain why pattern doesn't apply
575
+ - Consider updating pattern if it's flawed
576
+ - Get user approval if architectural impact
577
+
578
+ ---
579
+
580
+ ## Session Completion
581
+
582
+ When finishing a session:
583
+
584
+ 1. **Commit pending work**
585
+ - All changes staged and committed
586
+ - Commit message references task/decision
587
+
588
+ 2. **Update task status**
589
+ - Check boxes in `/.ai/tasks/active.md`
590
+ - Add completion date if done
591
+
592
+ 3. **Document learnings**
593
+ - Update `/.ai/memory/patterns.md` if discovered pattern
594
+ - Update `/.ai/memory/deadends.md` if failed approach
595
+ - Reference in commit messages
596
+
597
+ 4. **Clean up**
598
+ - No uncommitted changes
599
+ - Local branches cleaned up
600
+ - Remote is up to date
601
+
602
+ 5. **Summary to user**
603
+ - What was accomplished
604
+ - What's still pending
605
+ - Next steps
606
+ - Any blockers
607
+
608
+ ---
609
+
610
+ ## Next Session
611
+
612
+ When returning:
613
+
614
+ 1. Read `/.ai/state.json` for your last session state
615
+ 2. Check `current_task` to see what you were working on
616
+ 3. Start from Step 2 of Session Start Protocol
617
+ 4. Pick up from where you left off
618
+ 5. Update `session_started` timestamp in state.json
619
+
620
+ ---
621
+
622
+ **Document Version:** 1.0.0
623
+ **Last Updated:** Template injection date
624
+ **Framework:** PWN 1.0.0
625
+ **Supported Models:** Claude Opus 4.5+