@aladac/hu 0.1.0-a1 → 0.1.0-a2

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.
@@ -1,457 +0,0 @@
1
- # Hooks + Data Integration Analysis
2
-
3
- How honbu hooks can tap into existing Claude Code data stores.
4
-
5
- ## Available Data Sources
6
-
7
- ### 1. Session Transcripts (`projects/{encoded-path}/{session}.jsonl`)
8
-
9
- **Format**: JSONL with message threading
10
-
11
- **Available Data**:
12
- ```json
13
- {
14
- "uuid": "msg-uuid",
15
- "parentUuid": "parent-uuid",
16
- "sessionId": "session-uuid",
17
- "type": "user|assistant|summary",
18
- "timestamp": "ISO-8601",
19
- "cwd": "/working/directory",
20
- "gitBranch": "feature-branch",
21
- "message": {
22
- "role": "user|assistant",
23
- "content": "...|[{type:'tool_use',...}]",
24
- "model": "claude-opus-4-5-20251101",
25
- "usage": {
26
- "input_tokens": 1234,
27
- "output_tokens": 567,
28
- "cache_read_input_tokens": 9000,
29
- "cache_creation_input_tokens": 500
30
- }
31
- },
32
- "costUSD": 0.0123,
33
- "durationMs": 5000
34
- }
35
- ```
36
-
37
- **Hook Integration**:
38
- | Hook | Use Case |
39
- |------|----------|
40
- | `SessionStart` | Load recent messages, extract context |
41
- | `Stop` | Summarize session, extract learnings |
42
- | `UserPromptSubmit` | Find similar past prompts/solutions |
43
- | `PostToolUse` | Track tool patterns over time |
44
-
45
- **honbu commands**:
46
- ```bash
47
- honbu session read <session-id> # Parse JSONL
48
- honbu session search <query> # Full-text search
49
- honbu session stats <session-id> # Token/cost summary
50
- honbu session tools <session-id> # List tool usage
51
- honbu session thread <session-id> # Reconstruct thread
52
- honbu session export <session-id> [format] # Export markdown/json
53
- ```
54
-
55
- ---
56
-
57
- ### 2. History Index (`history.jsonl`)
58
-
59
- **Format**: JSONL session index
60
-
61
- **Available Data**:
62
- ```json
63
- {
64
- "display": "user prompt preview",
65
- "pastedContents": {},
66
- "timestamp": 1768082044191,
67
- "project": "/Users/chi/myproject",
68
- "sessionId": "session-uuid"
69
- }
70
- ```
71
-
72
- **Hook Integration**:
73
- | Hook | Use Case |
74
- |------|----------|
75
- | `SessionStart` | Show recent sessions for context |
76
- | `UserPromptSubmit` | Find similar past prompts |
77
-
78
- **honbu commands**:
79
- ```bash
80
- honbu history list [--project <path>] # List sessions
81
- honbu history recent [n] # Last N sessions
82
- honbu history search <query> # Search prompts
83
- honbu history by-project # Group by project
84
- ```
85
-
86
- ---
87
-
88
- ### 3. Stats Cache (`stats-cache.json`)
89
-
90
- **Format**: JSON aggregate statistics
91
-
92
- **Available Data**:
93
- ```json
94
- {
95
- "totalSessions": 85,
96
- "totalMessages": 13827,
97
- "dailyActivity": [
98
- {"date": "2026-01-12", "messageCount": 10168, "sessionCount": 48, "toolCallCount": 3560}
99
- ],
100
- "modelUsage": {
101
- "claude-opus-4-5-20251101": {
102
- "inputTokens": 233573,
103
- "outputTokens": 1504031,
104
- "cacheReadInputTokens": 518656034,
105
- "costUSD": 0
106
- }
107
- },
108
- "hourCounts": {"9": 9, "16": 11, "23": 16},
109
- "longestSession": {"sessionId": "...", "duration": 56868623, "messageCount": 63}
110
- }
111
- ```
112
-
113
- **Hook Integration**:
114
- | Hook | Use Case |
115
- |------|----------|
116
- | `SessionStart` | Show daily stats, suggest break times |
117
- | `SessionEnd` | Update custom metrics |
118
- | `Stop` | Compare session to averages |
119
-
120
- **honbu commands**:
121
- ```bash
122
- honbu stats show # Display stats
123
- honbu stats today # Today's activity
124
- honbu stats tokens [--by-model] # Token usage
125
- honbu stats cost [--period <days>] # Cost tracking
126
- honbu stats peak-hours # Activity patterns
127
- ```
128
-
129
- ---
130
-
131
- ### 4. Todos (`todos/{session-uuid}.json`)
132
-
133
- **Format**: JSON array
134
-
135
- **Available Data**:
136
- ```json
137
- [
138
- {
139
- "content": "Task description",
140
- "status": "pending|in_progress|completed",
141
- "activeForm": "Doing the task"
142
- }
143
- ]
144
- ```
145
-
146
- **Hook Integration**:
147
- | Hook | Use Case |
148
- |------|----------|
149
- | `SessionStart` | Load incomplete todos from other sessions |
150
- | `Stop` | Archive completed, handoff incomplete |
151
- | `SessionEnd` | Sync todos to central tracker |
152
-
153
- **honbu commands**:
154
- ```bash
155
- honbu todos list [--status <status>] # List all todos
156
- honbu todos pending # Cross-session pending
157
- honbu todos handoff <from> <to> # Transfer todos
158
- honbu todos cleanup # Remove completed
159
- ```
160
-
161
- ---
162
-
163
- ### 5. File History (`file-history/{session-uuid}/`)
164
-
165
- **Format**: File snapshots with version suffix
166
-
167
- **Structure**: `{hash}@v{n}` files containing previous versions
168
-
169
- **Hook Integration**:
170
- | Hook | Use Case |
171
- |------|----------|
172
- | `PreToolUse` (Edit/Write) | Check for recent edits to same file |
173
- | `PostToolUse` (Edit/Write) | Track file modification patterns |
174
- | `SessionStart` | Report files modified in previous session |
175
-
176
- **honbu commands**:
177
- ```bash
178
- honbu file-history list <session-id> # Files modified
179
- honbu file-history diff <file> [version] # Show diff
180
- honbu file-history restore <file> <ver> # Restore version
181
- honbu file-history hot-files [days] # Most edited files
182
- ```
183
-
184
- ---
185
-
186
- ### 6. Plans (`plans/{name}.md`)
187
-
188
- **Format**: Markdown with structured content
189
-
190
- **Naming**: `{adjective}-{verb}-{noun}.md`
191
-
192
- **Hook Integration**:
193
- | Hook | Use Case |
194
- |------|----------|
195
- | `SessionStart` | Check for related plans |
196
- | `UserPromptSubmit` | Match prompt to existing plans |
197
- | `PreCompact` | Preserve plan references |
198
-
199
- **honbu commands**:
200
- ```bash
201
- honbu plans list # List all plans
202
- honbu plans search <query> # Search plan content
203
- honbu plans related <topic> # Find related plans
204
- ```
205
-
206
- ---
207
-
208
- ### 7. Debug Logs (`debug/{session-uuid}.txt`)
209
-
210
- **Format**: Timestamped log lines
211
-
212
- **Available Data**:
213
- - Permission changes
214
- - Plugin loading
215
- - MCP server status
216
- - LSP initialization
217
- - Tool execution timing
218
-
219
- **Hook Integration**:
220
- | Hook | Use Case |
221
- |------|----------|
222
- | `SessionEnd` | Extract errors, warnings |
223
- | `Stop` | Check for repeated errors |
224
-
225
- **honbu commands**:
226
- ```bash
227
- honbu debug errors <session-id> # Extract errors
228
- honbu debug warnings <session-id> # Extract warnings
229
- honbu debug timing <session-id> # Performance metrics
230
- ```
231
-
232
- ---
233
-
234
- ### 8. Shell Snapshots (`shell-snapshots/snapshot-*.sh`)
235
-
236
- **Format**: Executable shell scripts
237
-
238
- **Contains**: Functions, aliases, environment from user's shell
239
-
240
- **Hook Integration**:
241
- | Hook | Use Case |
242
- |------|----------|
243
- | `SessionStart` | Detect shell environment changes |
244
-
245
- ---
246
-
247
- ## Data Flow Architecture
248
-
249
- ```
250
- ┌─────────────────────────────────────────────────────────────────┐
251
- │ Hook Events │
252
- ├─────────────────────────────────────────────────────────────────┤
253
- │ SessionStart UserPromptSubmit PreToolUse PostToolUse │
254
- │ Stop SessionEnd PreCompact Notification │
255
- └────────┬────────────────┬─────────────────┬────────────────┬────┘
256
- │ │ │ │
257
- ▼ ▼ ▼ ▼
258
- ┌─────────────────────────────────────────────────────────────────┐
259
- │ honbu hooks │
260
- ├─────────────────────────────────────────────────────────────────┤
261
- │ • Receives hook input (JSON via stdin) │
262
- │ • Queries local data stores │
263
- │ • Returns context/decisions (JSON via stdout) │
264
- └────────┬────────────────┬─────────────────┬────────────────┬────┘
265
- │ │ │ │
266
- ▼ ▼ ▼ ▼
267
- ┌─────────────────────────────────────────────────────────────────┐
268
- │ Data Stores │
269
- ├──────────────┬──────────────┬──────────────┬───────────────────┤
270
- │ projects/ │ history.jsonl│ stats-cache │ todos/ │
271
- │ (transcripts)│ (index) │ (metrics) │ (tasks) │
272
- ├──────────────┼──────────────┼──────────────┼───────────────────┤
273
- │ file-history/│ plans/ │ debug/ │ session-env/ │
274
- │ (versions) │ (plans) │ (logs) │ (env vars) │
275
- └──────────────┴──────────────┴──────────────┴───────────────────┘
276
- ```
277
-
278
- ---
279
-
280
- ## Implementation: honbu data Subcommand
281
-
282
- New subcommand to access all Claude Code data:
283
-
284
- ```bash
285
- honbu data <subcommand>
286
-
287
- # Session data
288
- honbu data session list [--project <path>]
289
- honbu data session read <id> [--format json|md]
290
- honbu data session search <query>
291
- honbu data session current # From $SESSION_ID
292
-
293
- # Cross-session queries
294
- honbu data search <query> # Full-text all sessions
295
- honbu data tools [--tool <name>] # Tool usage patterns
296
- honbu data files [--modified-by <session>] # File access patterns
297
- honbu data errors [--recent <days>] # Error patterns
298
-
299
- # Aggregates
300
- honbu data stats [--period <days>]
301
- honbu data cost [--by-model] [--by-project]
302
- honbu data activity [--hourly|--daily]
303
- ```
304
-
305
- ---
306
-
307
- ## Hook Implementation Examples
308
-
309
- ### SessionStart: Load Context
310
-
311
- ```bash
312
- #!/bin/bash
313
- # honbu hooks session-start startup
314
-
315
- SESSION_ID=$(jq -r '.session_id' < /dev/stdin)
316
- PROJECT=$(pwd)
317
-
318
- # Get recent activity for this project
319
- RECENT=$(honbu data session list --project "$PROJECT" --limit 3 --json)
320
-
321
- # Get pending todos from previous sessions
322
- PENDING=$(honbu data todos pending --project "$PROJECT" --json)
323
-
324
- # Get recently modified files
325
- FILES=$(honbu data files --project "$PROJECT" --recent 1d --json)
326
-
327
- # Build context
328
- cat << EOF
329
- {
330
- "hookSpecificOutput": {
331
- "hookEventName": "SessionStart",
332
- "additionalContext": "## Recent Context\n\nPrevious sessions: $(echo $RECENT | jq -r 'length')\nPending tasks: $(echo $PENDING | jq -r 'length')\nRecently modified: $(echo $FILES | jq -r 'length') files"
333
- }
334
- }
335
- EOF
336
- ```
337
-
338
- ### UserPromptSubmit: Find Similar Past Work
339
-
340
- ```bash
341
- #!/bin/bash
342
- # honbu hooks user-prompt-submit
343
-
344
- PROMPT=$(jq -r '.prompt' < /dev/stdin)
345
-
346
- # Search for similar past prompts/solutions
347
- SIMILAR=$(honbu data search "$PROMPT" --limit 3 --json)
348
-
349
- if [ "$(echo $SIMILAR | jq 'length')" -gt 0 ]; then
350
- CONTEXT="Similar past work found:\n$(echo $SIMILAR | jq -r '.[].summary')"
351
- cat << EOF
352
- {
353
- "hookSpecificOutput": {
354
- "hookEventName": "UserPromptSubmit",
355
- "additionalContext": "$CONTEXT"
356
- }
357
- }
358
- EOF
359
- else
360
- echo '{}'
361
- fi
362
- ```
363
-
364
- ### Stop: Extract Learnings
365
-
366
- ```bash
367
- #!/bin/bash
368
- # honbu hooks stop
369
-
370
- INPUT=$(cat)
371
- SESSION_ID=$(echo "$INPUT" | jq -r '.session_id')
372
- STOP_ACTIVE=$(echo "$INPUT" | jq -r '.stop_hook_active')
373
-
374
- # Don't loop
375
- if [ "$STOP_ACTIVE" = "true" ]; then
376
- echo '{"ok": true}'
377
- exit 0
378
- fi
379
-
380
- # Extract session summary
381
- honbu data session summarize "$SESSION_ID" >> ~/.claude/knowledge/sessions.jsonl
382
-
383
- echo '{"ok": true}'
384
- ```
385
-
386
- ### PostToolUse: Track Patterns
387
-
388
- ```bash
389
- #!/bin/bash
390
- # honbu hooks post-tool-use file-modify
391
-
392
- INPUT=$(cat)
393
- TOOL=$(echo "$INPUT" | jq -r '.tool_name')
394
- FILE=$(echo "$INPUT" | jq -r '.tool_input.file_path')
395
- SESSION=$(echo "$INPUT" | jq -r '.session_id')
396
-
397
- # Log file modification
398
- honbu data log file-modify \
399
- --session "$SESSION" \
400
- --file "$FILE" \
401
- --tool "$TOOL"
402
-
403
- # Check if file is frequently modified
404
- HOT=$(honbu data files hot --file "$FILE" --json)
405
- if [ "$(echo $HOT | jq '.count')" -gt 10 ]; then
406
- echo "{\"hookSpecificOutput\":{\"additionalContext\":\"Note: $FILE has been modified $(echo $HOT | jq '.count') times recently\"}}"
407
- fi
408
- ```
409
-
410
- ---
411
-
412
- ## Data Index for Fast Queries
413
-
414
- Build indexes on first run, update incrementally:
415
-
416
- ```
417
- ~/.claude/index/
418
- ├── sessions.idx # Session metadata index
419
- ├── messages.fts # Full-text search index
420
- ├── tools.idx # Tool usage index
421
- ├── files.idx # File access index
422
- └── errors.idx # Error pattern index
423
- ```
424
-
425
- **honbu commands**:
426
- ```bash
427
- honbu index build [--force] # Build/rebuild indexes
428
- honbu index status # Index health
429
- honbu index update # Incremental update
430
- ```
431
-
432
- ---
433
-
434
- ## Priority Implementation
435
-
436
- ### Phase 1: Read-Only Access
437
- - [ ] `honbu data session read`
438
- - [ ] `honbu data session list`
439
- - [ ] `honbu data stats`
440
- - [ ] `honbu data todos pending`
441
-
442
- ### Phase 2: Search & Query
443
- - [ ] `honbu data search`
444
- - [ ] `honbu data tools`
445
- - [ ] `honbu data files`
446
- - [ ] Index building
447
-
448
- ### Phase 3: Hook Integration
449
- - [ ] SessionStart context loader
450
- - [ ] UserPromptSubmit similarity search
451
- - [ ] Stop summary extractor
452
- - [ ] PostToolUse pattern tracker
453
-
454
- ### Phase 4: Knowledge System
455
- - [ ] Cross-session learning
456
- - [ ] Pattern recognition
457
- - [ ] Predictive suggestions