@tekmidian/pai 0.5.6 → 0.5.7

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 (51) hide show
  1. package/README.md +20 -2
  2. package/dist/cli/index.mjs +479 -5
  3. package/dist/cli/index.mjs.map +1 -1
  4. package/dist/daemon/index.mjs +2 -2
  5. package/dist/{daemon-D9evGlgR.mjs → daemon-2ND5WO2j.mjs} +3 -3
  6. package/dist/{daemon-D9evGlgR.mjs.map → daemon-2ND5WO2j.mjs.map} +1 -1
  7. package/dist/{db-4lSqLFb8.mjs → db-BtuN768f.mjs} +9 -2
  8. package/dist/db-BtuN768f.mjs.map +1 -0
  9. package/dist/hooks/capture-all-events.mjs +19 -4
  10. package/dist/hooks/capture-all-events.mjs.map +4 -4
  11. package/dist/hooks/cleanup-session-files.mjs.map +2 -2
  12. package/dist/hooks/context-compression-hook.mjs +14 -9
  13. package/dist/hooks/context-compression-hook.mjs.map +3 -3
  14. package/dist/hooks/initialize-session.mjs +14 -8
  15. package/dist/hooks/initialize-session.mjs.map +3 -3
  16. package/dist/hooks/load-core-context.mjs +18 -2
  17. package/dist/hooks/load-core-context.mjs.map +4 -4
  18. package/dist/hooks/load-project-context.mjs +14 -8
  19. package/dist/hooks/load-project-context.mjs.map +3 -3
  20. package/dist/hooks/stop-hook.mjs +105 -8
  21. package/dist/hooks/stop-hook.mjs.map +3 -3
  22. package/dist/hooks/sync-todo-to-md.mjs.map +2 -2
  23. package/dist/index.d.mts +2 -2
  24. package/dist/index.d.mts.map +1 -1
  25. package/dist/index.mjs +1 -1
  26. package/dist/mcp/index.mjs +1 -1
  27. package/dist/{vault-indexer-DXWs9pDn.mjs → vault-indexer-k-kUlaZ-.mjs} +41 -7
  28. package/dist/vault-indexer-k-kUlaZ-.mjs.map +1 -0
  29. package/package.json +1 -1
  30. package/src/hooks/ts/capture-all-events.ts +6 -0
  31. package/src/hooks/ts/lib/project-utils.ts +24 -5
  32. package/src/hooks/ts/pre-compact/context-compression-hook.ts +6 -0
  33. package/src/hooks/ts/session-start/initialize-session.ts +7 -1
  34. package/src/hooks/ts/session-start/load-core-context.ts +7 -0
  35. package/src/hooks/ts/session-start/load-project-context.ts +8 -1
  36. package/src/hooks/ts/stop/stop-hook.ts +28 -0
  37. package/templates/claude-md.template.md +7 -74
  38. package/templates/skills/CORE/Aesthetic.md +333 -0
  39. package/templates/skills/CORE/CONSTITUTION.md +1502 -0
  40. package/templates/skills/CORE/HistorySystem.md +427 -0
  41. package/templates/skills/CORE/HookSystem.md +1082 -0
  42. package/templates/skills/CORE/Prompting.md +509 -0
  43. package/templates/skills/CORE/ProsodyAgentTemplate.md +53 -0
  44. package/templates/skills/CORE/ProsodyGuide.md +416 -0
  45. package/templates/skills/CORE/SKILL.md +741 -0
  46. package/templates/skills/CORE/SkillSystem.md +213 -0
  47. package/templates/skills/CORE/TerminalTabs.md +119 -0
  48. package/templates/skills/CORE/VOICE.md +106 -0
  49. package/templates/skills/user/.gitkeep +0 -0
  50. package/dist/db-4lSqLFb8.mjs.map +0 -1
  51. package/dist/vault-indexer-DXWs9pDn.mjs.map +0 -1
@@ -0,0 +1,427 @@
1
+ # Universal Output Capture System (UOCS) - History System Documentation
2
+
3
+ **Location:** `${PAI_DIR}/History/`
4
+ **Purpose:** Automated documentation of ALL work performed by PAI and specialized agents
5
+ **Status:** ✅ FULLY OPERATIONAL
6
+
7
+ ---
8
+
9
+ ## Overview
10
+
11
+ The Universal Output Capture System (UOCS) is PAI's automatic memory - capturing every feature, bug fix, decision, learning, research, and session through hooks with **zero manual effort**.
12
+
13
+ **Core Principle:** Work normally, documentation handles itself.
14
+
15
+ ---
16
+
17
+ ## Quick Reference
18
+
19
+ This file is the **complete reference** for the history system. All specifications, conventions, and usage patterns are documented below.
20
+
21
+ ---
22
+
23
+ ## Directory Structure
24
+
25
+ ```
26
+ ${PAI_DIR}/History/
27
+ ├── Sessions/YYYY-MM/ # Session summaries (SessionEnd hook)
28
+ ├── Learnings/YYYY-MM/ # Problem-solving narratives (Stop hook + manual)
29
+ ├── Research/YYYY-MM/ # Investigation reports (Researcher agents)
30
+ ├── Decisions/YYYY-MM/ # Architectural decisions (Architect agent)
31
+ ├── Execution/
32
+ │ ├── Features/YYYY-MM/ # Feature implementations (Engineer/Designer)
33
+ │ ├── Bugs/YYYY-MM/ # Bug fixes (Engineer)
34
+ │ └── Refactors/YYYY-MM/ # Code improvements (Engineer)
35
+ └── Raw-Outputs/YYYY-MM/ # JSONL logs (PostToolUse hook)
36
+ ```
37
+
38
+ **Quick Decision Guide:**
39
+ - "What happened this session?" → `Sessions/`
40
+ - "What did we learn?" → `Learnings/`
41
+ - "What features were built?" → `Execution/Features/`
42
+ - "What broke and when?" → `Execution/Bugs/`
43
+ - "What was improved?" → `Execution/Refactors/`
44
+ - "Why this approach?" → `Decisions/`
45
+ - "What did we investigate?" → `Research/`
46
+ - "Raw execution logs?" → `Raw-Outputs/`
47
+
48
+ ---
49
+
50
+ ## Project Session Storage
51
+
52
+ **Location:** `${PAI_DIR}/projects/{encoded-path}/`
53
+
54
+ Claude Code stores session transcripts per-project. PAI organizes these with a clean structure:
55
+
56
+ ```
57
+ ${PAI_DIR}/projects/{encoded-path}/
58
+ ├── sessions/ # Session transcripts (auto-organized)
59
+ │ ├── {uuid}.jsonl # Main session transcripts
60
+ │ └── agent-*.jsonl # Subagent transcripts
61
+ ├── Notes/ # Session notes (PAI extension)
62
+ │ └── NNNN_YYYY-MM-DD_desc.md
63
+ └── TODO.md # Project task tracking
64
+ ```
65
+
66
+ **Path Encoding:** Directory paths are encoded by replacing `/` and `.` with `-`
67
+ - `/Users/john/Projects/myapp` → `-Users-john-Projects-myapp`
68
+
69
+ **Session File Lifecycle:**
70
+ 1. **During session:** Claude Code writes `.jsonl` to project root
71
+ 2. **On UserPromptSubmit:** `cleanup-session-files.ts` moves stray files from previous sessions
72
+ 3. **On Stop:** `stop-hook.ts` moves current session files to `sessions/`
73
+ 4. **On SessionStart:** `load-project-context.ts` creates structure and migrates any stragglers
74
+
75
+ **Key Files:**
76
+ - `{uuid}.jsonl` - Full conversation transcript with token usage
77
+ - `agent-*.jsonl` - Subagent (Task tool) transcripts
78
+ - `Notes/*.md` - Human-readable session summaries
79
+ - `TODO.md` - Synced from TodoWrite tool
80
+
81
+ ---
82
+
83
+ ## File Naming Convention
84
+
85
+ **Unified format:**
86
+ ```
87
+ YYYY-MM-DD-HHMMSS_[PROJECT]_[TYPE]_[HIERARCHY]_[DESCRIPTION].md
88
+ ```
89
+
90
+ **Components:**
91
+ - **Timestamp:** `YYYY-MM-DD-HHMMSS` (PST) - Enables chronological sorting
92
+ - **Project:** Optional identifier (e.g., `dashboard`, `website`, `PAI`)
93
+ - **Type:** Mandatory classification
94
+ - `FEATURE` - New functionality
95
+ - `BUG` - Bug fix
96
+ - `REFACTOR` - Code improvement
97
+ - `RESEARCH` - Investigation
98
+ - `DECISION` - Architectural decision
99
+ - `LEARNING` - Problem-solving narrative
100
+ - `SESSION` - Session summary
101
+ - **Hierarchy:** Optional Spec-Kit task number (e.g., `T1.2.3`)
102
+ - **Description:** Kebab-case, max 60 chars
103
+
104
+ **Examples:**
105
+ ```
106
+ 2025-10-13-140000_dashboard_FEATURE_T1.1_database-schema-setup.md
107
+ 2025-10-13-153000_dashboard_BUG_T1.2_jwt-expiry-validation.md
108
+ 2025-10-13-092000_PAI_DECISION_unified-capture-architecture.md
109
+ 2025-10-13-083000_LEARNING_kitty-remote-control-api.md
110
+ 2025-10-13-180000_SESSION_feature-implementation-day-1.md
111
+ ```
112
+
113
+ ---
114
+
115
+ ## Hook Integration
116
+
117
+ ### 1. PostToolUse Hook
118
+ **Triggers:** Every tool execution (Bash, Edit, Write, Read, Task, etc.)
119
+ **Implementation:** `${PAI_DIR}/Hooks/capture-all-events.ts --event-type PostToolUse`
120
+ **Output:** Daily JSONL logs in `Raw-Outputs/YYYY-MM/YYYY-MM-DD_all-events.jsonl`
121
+ **Purpose:** Raw execution data for forensics and analytics
122
+
123
+ **Key Feature:** Completely generic - captures ENTIRE payload automatically
124
+ - **Future-proof**: New fields added to hooks (like `agent_id`, `agent_transcript_path` in v2.0.42) are automatically captured
125
+ - No code updates needed when Claude Code adds new fields
126
+
127
+ ### 2. Stop Hook
128
+ **Triggers:** Main agent (PAI) task completion
129
+ **Implementation:** `${PAI_DIR}/Hooks/stop-hook.ts`
130
+ **Output:** Auto-captured files in `Learnings/` or `Sessions/` based on content
131
+ **Purpose:** Lightweight capture of work summaries and learning moments
132
+
133
+ **How it works:**
134
+ 1. Extracts structured response format sections
135
+ 2. Analyzes for learning indicators (problem, solved, discovered, fixed)
136
+ 3. Categorizes as LEARNING (2+ indicators) or WORK (general session)
137
+ 4. Generates appropriate filename and saves to history
138
+
139
+ ### 3. SubagentStop Hook
140
+ **Triggers:** Specialized agent task completion
141
+ **Implementation:** `${PAI_DIR}/Hooks/subagent-stop-hook.ts`
142
+ **Output:** Categorized documents in appropriate directories
143
+ **Purpose:** Organized work documentation by agent type
144
+
145
+ **Categorization Logic:**
146
+ - Architect → `Decisions/` (DECISION)
147
+ - Engineer/Principal-Engineer → `Execution/Features|Bugs|Refactors/`
148
+ - Designer → `Execution/Features/` (FEATURE)
149
+ - Researchers (all types) → `Research/` (RESEARCH)
150
+ - Pentester → `Research/` (RESEARCH)
151
+ - Intern → `Research/` (mixed - defaults to RESEARCH)
152
+
153
+ **⚠️ Upgrade Note (v2.0.42):**
154
+ New fields available in SubagentStop hooks:
155
+ - `agent_id` - Unique agent instance identifier
156
+ - `agent_transcript_path` - Path to agent transcript
157
+
158
+ **Status:**
159
+ - ✅ `capture-all-events.ts` - Already capturing automatically (generic payload storage)
160
+ - ⚠️ `subagent-stop-hook.ts` - Should be updated to explicitly use new fields for better agent tracking
161
+
162
+ ### 4. SessionEnd Hook
163
+ **Triggers:** Session exit (when you quit Claude Code)
164
+ **Implementation:** `${PAI_DIR}/Hooks/capture-session-summary.ts`
165
+ **Output:** Session summary in `Sessions/YYYY-MM/`
166
+ **Purpose:** High-level session documentation
167
+
168
+ ### 5. SessionStart Hook
169
+ **Triggers:** Session initialization (when you start Claude Code)
170
+ **Implementation:** `${PAI_DIR}/Hooks/initialize-kai-session.ts`
171
+ **Purpose:** Load core context and prepare session environment
172
+
173
+ ---
174
+
175
+ ## Custom Slash Commands
176
+
177
+ ### /search-history [query]
178
+ **Purpose:** Full-text search across all history
179
+ **Example:** `/search-history authentication bug`
180
+ **Implementation:** Uses ripgrep with context lines
181
+
182
+ ### /show-project-history [project]
183
+ **Purpose:** Chronological timeline for project
184
+ **Example:** `/show-project-history dashboard`
185
+ **Output:** Most recent 30 files for project
186
+
187
+ ### /trace-feature [task-number]
188
+ **Purpose:** Complete implementation history for task
189
+ **Example:** `/trace-feature T1.2`
190
+ **Output:** Features, bugs, refactors related to task
191
+
192
+ ### /bug-timeline [feature]
193
+ **Purpose:** Bug introduction and fix timeline
194
+ **Example:** `/bug-timeline authentication`
195
+ **Output:** Chronological list of related bugs
196
+
197
+ ---
198
+
199
+ ## Integration with Spec-Kit
200
+
201
+ **Spec-Kit** (`.specify/`) = PLAN (what to do)
202
+ **UOCS** (`History/`) = REALITY (what was done)
203
+
204
+ ### Bidirectional Traceability
205
+
206
+ **From Spec to History:**
207
+ ```
208
+ .specify/specs/001-auth/tasks.md
209
+ └─ T005 [US1] Implement login endpoint
210
+
211
+ History/Execution/Features/2025-10/
212
+ └─ 2025-10-13-140000_myapp_FEATURE_T005_login-endpoint.md
213
+ ```
214
+
215
+ **From Bug to Feature:**
216
+ ```
217
+ History/Execution/Features/2025-10/
218
+ └─ 2025-10-13-140000_myapp_FEATURE_T1.2_user-model.md
219
+ ↓ (bug introduced here)
220
+ History/Execution/Bugs/2025-10/
221
+ └─ 2025-10-13-153000_myapp_BUG_T1.2_unique-constraint.md
222
+ (metadata: bug_introduced_by: T1.2)
223
+ ```
224
+
225
+ ---
226
+
227
+ ## Metadata Schema
228
+
229
+ Every capture file includes YAML frontmatter:
230
+
231
+ ```yaml
232
+ ---
233
+ # Core classification
234
+ capture_type: FEATURE|BUG|REFACTOR|RESEARCH|DECISION|LEARNING|SESSION
235
+ timestamp: 2025-10-13T14:30:22-07:00
236
+ duration_minutes: 45
237
+
238
+ # Context
239
+ project: dashboard
240
+ executor: kai|architect|engineer|designer|researcher
241
+ session_id: uuid
242
+
243
+ # Development tracking (when applicable)
244
+ hierarchy: T1.2.3
245
+ spec_kit_feature: 001-user-authentication
246
+ spec_kit_task: T005
247
+ user_story: US1
248
+ phase: 2
249
+
250
+ # Technical details
251
+ files_changed:
252
+ - path/to/file.ts
253
+ technologies:
254
+ - TypeScript
255
+ - Vitest
256
+
257
+ # Outcomes
258
+ status: completed|blocked|partial
259
+ tests_added: 12
260
+ tests_passing: 12
261
+ coverage_change: +5.2%
262
+
263
+ # Bug tracking (for bugs only)
264
+ bug_severity: critical|high|medium|low
265
+ bug_introduced_by: T1.1
266
+
267
+ # Relationships
268
+ related_to:
269
+ - other-capture-file.md
270
+ depends_on:
271
+ - prerequisite-file.md
272
+
273
+ # Searchability
274
+ tags:
275
+ - authentication
276
+ keywords:
277
+ - user model
278
+ ---
279
+ ```
280
+
281
+ ---
282
+
283
+ ## Common Usage Patterns
284
+
285
+ ### Before Starting Work
286
+
287
+ ```bash
288
+ # Has this been done before?
289
+ /search-history [feature-name]
290
+
291
+ # How did we build similar features?
292
+ /trace-feature T1
293
+
294
+ # What decisions were made about this?
295
+ ls ${PAI_DIR}/History/Decisions/*/[project]_*
296
+
297
+ # What did we learn about this domain?
298
+ /search-history [domain-term]
299
+ ```
300
+
301
+ ### During Development
302
+
303
+ **No action required** - work normally, everything captured automatically.
304
+
305
+ ### After Encountering Issues
306
+
307
+ ```bash
308
+ # When did this break?
309
+ /bug-timeline [feature-name]
310
+
311
+ # Complete history of this feature
312
+ /trace-feature T1.2.3
313
+
314
+ # What similar bugs have we fixed?
315
+ /search-history "[bug description]"
316
+ ```
317
+
318
+ ### Periodic Review
319
+
320
+ ```bash
321
+ # What did we accomplish this week?
322
+ ls -lt ${PAI_DIR}/History/Sessions/2025-10/ | head -7
323
+
324
+ # All decisions made this month
325
+ ls ${PAI_DIR}/History/Decisions/2025-10/
326
+
327
+ # Learnings from this quarter
328
+ ls ${PAI_DIR}/History/Learnings/2025-{10,11,12}/
329
+ ```
330
+
331
+ ---
332
+
333
+ ## Advanced Queries
334
+
335
+ ### Find all features for project
336
+ ```bash
337
+ find ${PAI_DIR}/History/Execution/Features -name "*_dashboard_*"
338
+ ```
339
+
340
+ ### Find bugs introduced in specific task
341
+ ```bash
342
+ rg "bug_introduced_by: T1.2" ${PAI_DIR}/History/Execution/Bugs/
343
+ ```
344
+
345
+ ### Find all work from specific date
346
+ ```bash
347
+ find ${PAI_DIR}/History -name "2025-10-13-*"
348
+ ```
349
+
350
+ ### Analyze tool usage patterns
351
+ ```bash
352
+ cat ${PAI_DIR}/History/Raw-Outputs/2025-10/*.jsonl | \
353
+ jq -r '.tool' | sort | uniq -c | sort -rn
354
+ ```
355
+
356
+ ### Extract all architectural decisions
357
+ ```bash
358
+ find ${PAI_DIR}/History/Decisions -name "*.md" | \
359
+ xargs grep -l "Alternatives considered"
360
+ ```
361
+
362
+ ---
363
+
364
+ ## Benefits
365
+
366
+ - ✅ **Root Cause Analysis** - "When did we break this?" instantly answerable
367
+ - ✅ **Decision Tracking** - Every architectural choice preserved with rationale
368
+ - ✅ **Learning Accumulation** - Problem-solving patterns captured and queryable
369
+ - ✅ **Process Improvement** - Complete history enables identifying bottlenecks
370
+ - ✅ **Knowledge Harvesting** - Past solutions easily found and reused
371
+ - ✅ **Zero Overhead** - Completely automated capture
372
+ - ✅ **Spec-Kit Integration** - Bidirectional traceability (plan ↔ execution)
373
+
374
+ ---
375
+
376
+ ## Maintenance
377
+
378
+ ### Automated (No Action Required)
379
+ - Hooks capture all work automatically
380
+ - Files created with proper naming
381
+ - Metadata populated by hooks
382
+ - Categorization handled by hook logic
383
+
384
+ ### Manual (Periodic)
385
+
386
+ **Monthly:**
387
+ - Review directory sizes
388
+ - Archive older months if getting large (>1000 files/month)
389
+ - Validate hook functionality
390
+
391
+ **Quarterly:**
392
+ - Extract common learnings into best practices
393
+ - Analyze bug patterns for process improvements
394
+ - Review categorization accuracy
395
+
396
+ ---
397
+
398
+ ## System Status
399
+
400
+ **Status:** ✅ FULLY OPERATIONAL
401
+ **Hooks Active:**
402
+ - ✅ PostToolUse (capture-all-events.ts)
403
+ - ✅ Stop (stop-hook.ts)
404
+ - ✅ SubagentStop (subagent-stop-hook.ts)
405
+ - ✅ SessionEnd (capture-session-summary.ts)
406
+ - ✅ SessionStart (initialize-kai-session.ts)
407
+
408
+ **Commands:** ✅ All 4 slash commands available
409
+ **Integration:** ✅ Spec-Kit, Agent workflows
410
+ **Files Captured:** 52 migrated + ongoing auto-captures
411
+
412
+ ---
413
+
414
+ ## Routing Triggers
415
+
416
+ **Load this documentation when the user says:**
417
+ - "history system" or "UOCS"
418
+ - "how does capture work" or "automatic documentation"
419
+ - "where are sessions saved" or "history directory"
420
+ - "how to search history" or "find past work"
421
+ - "SubagentStop hook" or "capture hooks"
422
+ - "learning capture" or "session summaries"
423
+ - Questions about file organization in History/
424
+
425
+ ---
426
+
427
+ **This is the memory of your AI infrastructure - it remembers everything so you don't have to.**