@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.
package/CLAUDE.md CHANGED
@@ -11,60 +11,84 @@ This is the `~/.claude` configuration directory containing custom slash commands
11
11
  - `commands/` - Slash command definitions (`.md` files that become `/command-name`)
12
12
  - `docs/` - Documentation management commands (`/docs:*`)
13
13
  - `plans/` - Planning commands (`/plans:*`)
14
- - `src/` - TypeScript source for the `honbu` CLI
14
+ - `src/` - TypeScript source for the `hu` CLI
15
15
  - `commands/` - CLI subcommand implementations
16
- - `lib/` - Shared utilities (fs, colors, html conversion)
16
+ - `lib/` - Shared utilities (fs, colors, html conversion, db, sync)
17
17
  - `doc/` - Reference documentation fetched from the web
18
18
  - `documents/` - Global documentation store (`~/.claude/documents/`)
19
+ - `hooks/` - Hook scripts for Claude Code events
19
20
  - `plans/` - Saved implementation plans (PLAN.md files)
20
21
  - `plugins/` - Claude Code plugins
21
22
  - `settings.json` - Global permissions and plugin configuration
22
23
 
23
- ## CLI Tool: honbu
24
+ ## CLI Tool: hu
24
25
 
25
26
  A unified CLI for Claude Code workflows. Install with:
26
27
  ```bash
27
28
  cd ~/.claude && npm install
28
29
  ```
29
30
 
30
- The `honbu` binary provides these subcommands:
31
+ The `hu` binary provides these subcommands:
31
32
 
32
- ### honbu docs
33
+ ### hu data
34
+ Access Claude Code session data (requires SQLite database):
35
+ ```bash
36
+ hu data sync # Sync Claude data to local database
37
+ hu data sync -f # Force full sync
38
+ hu data config # Show current configuration
39
+ hu data config -j # JSON output
40
+ hu data session list # List sessions
41
+ hu data session list -p <dir> # Filter by project
42
+ hu data stats # Show usage statistics
43
+ hu data todos pending # Show pending todos
44
+ hu data search <query> # Search messages
45
+ hu data tools # Show tool usage statistics
46
+ hu data errors # Extract errors from debug logs
47
+ ```
48
+
49
+ ### hu docs
33
50
  Documentation management:
34
51
  ```bash
35
- honbu docs list [location] # List docs (project|global|all|repo)
36
- honbu docs list -j # JSON output
37
- honbu docs check # Check system document status in repo
38
- honbu docs scan [target] # Scan docs for sync (shows staleness)
39
- honbu docs archive <file...> # Archive docs to global store
52
+ hu docs list [location] # List docs (project|global|all|repo)
53
+ hu docs list -j # JSON output
54
+ hu docs check # Check system document status in repo
55
+ hu docs scan [target] # Scan docs for sync (shows staleness)
56
+ hu docs archive <file...> # Archive docs to global store
40
57
  ```
41
58
 
42
- ### honbu plans
59
+ ### hu plans
43
60
  Plan management:
44
61
  ```bash
45
- honbu plans list # List saved plans
46
- honbu plans list -f # Full content preview
47
- honbu plans clear # Delete all plans (with confirmation)
48
- honbu plans clear -d # Dry run
62
+ hu plans list # List saved plans
63
+ hu plans list -f # Full content preview
64
+ hu plans clear # Delete all plans (with confirmation)
65
+ hu plans clear -d # Dry run
49
66
  ```
50
67
 
51
- ### honbu utils
68
+ ### hu utils
52
69
  Utility commands:
53
70
  ```bash
54
- honbu utils fetch-html <url> # Fetch URL, convert to markdown
55
- honbu utils fetch-html <url> -c # With extra cleaning
56
- honbu utils fetch-html <url> -s "article" # Target CSS selector
57
- honbu utils fetch-html <url> -o out.md # Write to file
58
-
59
- honbu utils sync-checkboxes # Clean TODO.md/PLAN.md
60
- honbu utils sync-checkboxes file.md # Specific file
61
- honbu utils sync-checkboxes -d # Dry run
71
+ hu utils fetch-html <url> # Fetch URL, convert to markdown
72
+ hu utils fetch-html <url> -c # With extra cleaning
73
+ hu utils fetch-html <url> -s "article" # Target CSS selector
74
+ hu utils fetch-html <url> -o out.md # Write to file
75
+
76
+ hu utils sync-checkboxes # Clean TODO.md/PLAN.md
77
+ hu utils sync-checkboxes file.md # Specific file
78
+ hu utils sync-checkboxes -d # Dry run
62
79
  ```
63
80
 
64
- ### honbu disk
81
+ ### hu disk
65
82
  Disk space analysis (macOS):
66
83
  ```bash
67
- honbu disk # Show disk usage summary
84
+ hu disk # Show disk usage summary
85
+ ```
86
+
87
+ ### hu plugin
88
+ Plugin management:
89
+ ```bash
90
+ hu plugin init <name> # Initialize a new plugin
91
+ hu plugin install # Install plugin hooks
68
92
  ```
69
93
 
70
94
  ## Slash Commands
@@ -88,10 +112,11 @@ honbu disk # Show disk usage summary
88
112
  ### Utilities
89
113
  - `/c` - Quick commit: adds all files, commits with timestamp message
90
114
  - `/disk` - Disk space analysis commands for macOS
91
- - `/bootstrap` - Bootstrap honbu if not installed
92
- - `/reinstall` - Reinstall honbu from source
115
+ - `/bootstrap` - Bootstrap hu if not installed
116
+ - `/reinstall` - Reinstall hu from source
93
117
  - `/check-name <name>` - Check package name availability across registries
94
118
  - `/replicate` - Diagnose a reported issue and identify code areas to investigate
119
+ - `/warp` - Custom command
95
120
 
96
121
  ## System Documents (Off-Limits)
97
122
 
@@ -102,7 +127,7 @@ The `/docs:*` commands explicitly ignore these files:
102
127
 
103
128
  ## Documentation Workflow
104
129
 
105
- 1. **Fetching**: `/docs:get` uses `honbu utils fetch-html` to grab web content, stores with YAML frontmatter containing source URL and fetch date
130
+ 1. **Fetching**: `/docs:get` uses `hu utils fetch-html` to grab web content, stores with YAML frontmatter containing source URL and fetch date
106
131
  2. **Manifests**: Project docs tracked in `./document-manifest.toml`, global in `~/.claude/documents/manifest.toml`
107
132
  3. **Syncing**: `/docs:sync` re-fetches sources, follows new reference links, updates frontmatter dates
108
133
  4. **Locations**:
package/HOOKS.md ADDED
@@ -0,0 +1,146 @@
1
+ # Hooks + Data Integration
2
+
3
+ Claude Code hooks that tap into local data stores for context-aware automation.
4
+
5
+ ## Installation
6
+
7
+ ### Prerequisites
8
+
9
+ Install the `hu` CLI:
10
+
11
+ ```bash
12
+ cd ~/.claude && npm install
13
+ npm link # or: npm install -g @aladac/hu
14
+ ```
15
+
16
+ ### Configure Claude Code Hooks
17
+
18
+ Add to `~/.claude/settings.json`:
19
+
20
+ ```json
21
+ {
22
+ "hooks": {
23
+ "SessionStart": [
24
+ {
25
+ "matcher": ".*",
26
+ "hooks": [{ "type": "command", "command": "~/.claude/hooks/session-start.sh" }]
27
+ }
28
+ ],
29
+ "UserPromptSubmit": [
30
+ {
31
+ "matcher": ".*",
32
+ "hooks": [{ "type": "command", "command": "~/.claude/hooks/user-prompt-submit.sh" }]
33
+ }
34
+ ],
35
+ "Stop": [
36
+ {
37
+ "matcher": ".*",
38
+ "hooks": [{ "type": "command", "command": "~/.claude/hooks/stop.sh" }]
39
+ }
40
+ ]
41
+ }
42
+ }
43
+ ```
44
+
45
+ ### Configuration
46
+
47
+ The `hu` CLI uses `~/.config/hu/settings.toml` for configuration:
48
+
49
+ ```toml
50
+ [general]
51
+ claude_dir = "~/.claude" # Claude Code data directory
52
+ database = "hu.db" # SQLite database name
53
+
54
+ [sync]
55
+ auto_sync_interval = 300 # Seconds between auto-syncs (0 = manual)
56
+ sync_on_start = true
57
+
58
+ [hooks]
59
+ enabled = true
60
+ temp_dir = "/tmp" # Temp files for hook data exchange
61
+ temp_file_ttl = 3600 # Cleanup temp files after (seconds)
62
+
63
+ [search]
64
+ default_limit = 20
65
+ show_snippets = true
66
+
67
+ [output]
68
+ default_format = "table"
69
+ colors = true
70
+ date_format = "%Y-%m-%d %H:%M"
71
+ ```
72
+
73
+ ## Features
74
+
75
+ - **Session Context Loading** - On session start, automatically loads recent sessions, pending todos, and recently modified files for the current project. Provides continuity across sessions without manual context-setting.
76
+
77
+ - **Similarity Search** - When you submit a prompt, searches past transcripts for similar prompts and solutions. Surfaces relevant prior work so you don't reinvent the wheel.
78
+
79
+ - **Usage Statistics** - Aggregates token usage, costs, peak activity hours, and model distribution from stats cache. Helps track spending and identify usage patterns.
80
+
81
+ - **Cross-Session Todo Sync** - Extracts incomplete todos from any session and makes them available globally. No more losing track of tasks when sessions end.
82
+
83
+ - **File Modification Tracking** - Monitors which files get edited frequently across sessions. Flags "hot" files that might need refactoring or closer attention.
84
+
85
+ - **Session Summarization** - On stop, extracts learnings and summaries from the session transcript. Builds a knowledge base of solved problems over time.
86
+
87
+ - **Tool Usage Patterns** - Tracks which tools are used, how often, and in what contexts. Identifies automation opportunities and common workflows.
88
+
89
+ ## Data Sources
90
+
91
+ | Source | Location | Contains |
92
+ |--------|----------|----------|
93
+ | Transcripts | `projects/{path}/{session}.jsonl` | Full message history, tool calls, costs |
94
+ | History | `history.jsonl` | Session index with prompts |
95
+ | Stats | `stats-cache.json` | Aggregated metrics |
96
+ | Todos | `todos/{session}.json` | Task lists per session |
97
+ | File History | `file-history/{session}/` | File version snapshots |
98
+ | Plans | `plans/*.md` | Saved implementation plans |
99
+ | Debug | `debug/{session}.txt` | Error logs, timing data |
100
+
101
+ ## Hook Events
102
+
103
+ - `SessionStart` - Load context, show recent activity
104
+ - `UserPromptSubmit` - Find similar past work
105
+ - `PreToolUse` - Check file history before edits
106
+ - `PostToolUse` - Track patterns, flag hot files
107
+ - `Stop` - Summarize session, extract learnings
108
+ - `SessionEnd` - Archive todos, update indexes
109
+
110
+ ## CLI Commands
111
+
112
+ The `hu data` command provides access to Claude Code session data:
113
+
114
+ ```bash
115
+ hu data sync # Sync Claude Code data to SQLite
116
+ hu data sync --quiet # Quiet mode for hooks
117
+ hu data config # Show configuration
118
+ hu data session list # List sessions
119
+ hu data session read <id> # Read session transcript
120
+ hu data session current # Show current session ($SESSION_ID)
121
+ hu data stats # Usage statistics
122
+ hu data search <query> # Full-text search
123
+ hu data tools # Tool usage patterns
124
+ hu data todos list # List all todos
125
+ hu data todos pending # Show pending todos
126
+ hu data errors # Extract errors from debug logs
127
+ ```
128
+
129
+ All commands support `--json` for machine-readable output and `--output <path>` to write to a file.
130
+
131
+ ## Architecture
132
+
133
+ The hooks use a temp-file approach for data exchange to avoid shell escaping issues:
134
+
135
+ 1. Hook receives JSON input via stdin
136
+ 2. Writes input to temp file for parsing
137
+ 3. Calls `hu data` commands with `--json --output` flags
138
+ 4. Reads results from temp files
139
+ 5. Builds response JSON and outputs to stdout
140
+ 6. Temp files are cleaned up after `temp_file_ttl` seconds
141
+
142
+ This approach ensures safe handling of:
143
+ - Unicode characters (emoji, CJK, RTL)
144
+ - Special shell characters (`$`, backticks, quotes)
145
+ - Multiline content and code blocks
146
+ - Nested JSON structures
@@ -3,13 +3,16 @@ Reinstall hu from source.
3
3
  ## Command
4
4
 
5
5
  ```bash
6
+ # Remove existing hu command if present (avoid conflicts)
7
+ which hu &>/dev/null && npm unlink -g hu 2>/dev/null
6
8
  cd ~/.claude && npm install && npm link
7
9
  ```
8
10
 
9
11
  This will:
10
- 1. Install/update dependencies from package.json
11
- 2. Rebuild TypeScript via tsx
12
- 3. Update global symlink for `hu` binary
12
+ 1. Remove any existing `hu` command to avoid conflicts
13
+ 2. Install/update dependencies from package.json
14
+ 3. Rebuild TypeScript via tsx
15
+ 4. Update global symlink for `hu` binary
13
16
 
14
17
  ## Verify
15
18
 
@@ -0,0 +1,85 @@
1
+ #!/bin/bash
2
+ # Session Start Hook for hu data integration
3
+ # Loads context from previous sessions and pending todos for the current project
4
+ #
5
+ # This hook is called when a new Claude Code session starts.
6
+ # It syncs data and provides context about past sessions and pending tasks.
7
+ #
8
+ # Installation:
9
+ # Add to ~/.claude/settings.json:
10
+ # {
11
+ # "hooks": {
12
+ # "SessionStart": [
13
+ # {
14
+ # "matcher": ".*",
15
+ # "hooks": [{ "type": "command", "command": "~/.claude/hooks/session-start.sh" }]
16
+ # }
17
+ # ]
18
+ # }
19
+ # }
20
+
21
+ set -e
22
+
23
+ # Read input from stdin to temp file
24
+ INPUT_FILE=$(mktemp /tmp/hu-session-start-XXXXXX.json)
25
+ cat > "$INPUT_FILE"
26
+
27
+ # Extract project path from input
28
+ PROJECT=$(jq -r '.cwd // empty' "$INPUT_FILE" 2>/dev/null || echo "")
29
+
30
+ # Clean up input file
31
+ rm -f "$INPUT_FILE"
32
+
33
+ # Check if hu is available
34
+ if ! command -v hu &> /dev/null; then
35
+ exit 0
36
+ fi
37
+
38
+ # Sync data (quick, uses interval from config)
39
+ hu data sync --quiet 2>/dev/null || true
40
+
41
+ # Get recent sessions for this project
42
+ SESSIONS_FILE=$(mktemp /tmp/hu-sessions-XXXXXX.json)
43
+ if [ -n "$PROJECT" ]; then
44
+ hu data session list --project "$PROJECT" --limit 5 --json > "$SESSIONS_FILE" 2>/dev/null || echo "[]" > "$SESSIONS_FILE"
45
+ else
46
+ hu data session list --limit 5 --json > "$SESSIONS_FILE" 2>/dev/null || echo "[]" > "$SESSIONS_FILE"
47
+ fi
48
+
49
+ # Get pending todos
50
+ TODOS_FILE=$(mktemp /tmp/hu-todos-XXXXXX.json)
51
+ if [ -n "$PROJECT" ]; then
52
+ hu data todos pending --project "$PROJECT" --json > "$TODOS_FILE" 2>/dev/null || echo "[]" > "$TODOS_FILE"
53
+ else
54
+ hu data todos pending --json > "$TODOS_FILE" 2>/dev/null || echo "[]" > "$TODOS_FILE"
55
+ fi
56
+
57
+ # Count sessions and todos
58
+ SESSION_COUNT=$(jq 'length' "$SESSIONS_FILE" 2>/dev/null || echo "0")
59
+ TODO_COUNT=$(jq 'length' "$TODOS_FILE" 2>/dev/null || echo "0")
60
+
61
+ # Build context message
62
+ CONTEXT=""
63
+
64
+ if [ "$SESSION_COUNT" -gt 0 ]; then
65
+ CONTEXT="## Previous Sessions\\n\\n"
66
+ CONTEXT+=$(jq -r '.[] | "- Session \(.id[0:8]): \(.display // "No description") (\(.message_count) messages)"' "$SESSIONS_FILE" 2>/dev/null || echo "")
67
+ CONTEXT+="\\n\\n"
68
+ fi
69
+
70
+ if [ "$TODO_COUNT" -gt 0 ]; then
71
+ CONTEXT+="## Pending Tasks\\n\\n"
72
+ CONTEXT+=$(jq -r '.[] | "- [\(.status)] \(.content)"' "$TODOS_FILE" 2>/dev/null || echo "")
73
+ fi
74
+
75
+ # Clean up temp files
76
+ rm -f "$SESSIONS_FILE" "$TODOS_FILE"
77
+
78
+ # Output response if we have context
79
+ if [ -n "$CONTEXT" ]; then
80
+ # Escape for JSON
81
+ CONTEXT_ESCAPED=$(echo -e "$CONTEXT" | jq -Rs .)
82
+ echo "{\"additionalContext\": $CONTEXT_ESCAPED}"
83
+ else
84
+ echo "{}"
85
+ fi
package/hooks/stop.sh ADDED
@@ -0,0 +1,51 @@
1
+ #!/bin/bash
2
+ # Stop Hook for hu data integration
3
+ # Syncs session data when Claude Code stops
4
+ #
5
+ # This hook is called when a Claude Code session ends.
6
+ # It ensures the session data is synced to the database.
7
+ #
8
+ # Installation:
9
+ # Add to ~/.claude/settings.json:
10
+ # {
11
+ # "hooks": {
12
+ # "Stop": [
13
+ # {
14
+ # "matcher": ".*",
15
+ # "hooks": [{ "type": "command", "command": "~/.claude/hooks/stop.sh" }]
16
+ # }
17
+ # ]
18
+ # }
19
+ # }
20
+
21
+ set -e
22
+
23
+ # Read input from stdin to temp file
24
+ INPUT_FILE=$(mktemp /tmp/hu-stop-XXXXXX.json)
25
+ cat > "$INPUT_FILE"
26
+
27
+ # Check if stop hook is already active (prevent recursion)
28
+ STOP_HOOK_ACTIVE=$(jq -r '.stop_hook_active // false' "$INPUT_FILE" 2>/dev/null || echo "false")
29
+ if [ "$STOP_HOOK_ACTIVE" = "true" ]; then
30
+ rm -f "$INPUT_FILE"
31
+ echo "{}"
32
+ exit 0
33
+ fi
34
+
35
+ # Extract session ID if available
36
+ SESSION_ID=$(jq -r '.sessionId // empty' "$INPUT_FILE" 2>/dev/null || echo "")
37
+
38
+ # Clean up input file
39
+ rm -f "$INPUT_FILE"
40
+
41
+ # Check if hu is available
42
+ if ! command -v hu &> /dev/null; then
43
+ echo "{}"
44
+ exit 0
45
+ fi
46
+
47
+ # Force sync to capture this session's data
48
+ hu data sync --quiet 2>/dev/null || true
49
+
50
+ # Output empty response (no context needed on stop)
51
+ echo "{}"
@@ -0,0 +1,74 @@
1
+ #!/bin/bash
2
+ # User Prompt Submit Hook for hu data integration
3
+ # Finds similar past work based on the user's prompt
4
+ #
5
+ # This hook is called when the user submits a prompt.
6
+ # It searches for similar messages from past sessions.
7
+ #
8
+ # Installation:
9
+ # Add to ~/.claude/settings.json:
10
+ # {
11
+ # "hooks": {
12
+ # "UserPromptSubmit": [
13
+ # {
14
+ # "matcher": ".*",
15
+ # "hooks": [{ "type": "command", "command": "~/.claude/hooks/user-prompt-submit.sh" }]
16
+ # }
17
+ # ]
18
+ # }
19
+ # }
20
+
21
+ set -e
22
+
23
+ # Read input from stdin to temp file
24
+ INPUT_FILE=$(mktemp /tmp/hu-prompt-submit-XXXXXX.json)
25
+ cat > "$INPUT_FILE"
26
+
27
+ # Extract the user's prompt
28
+ PROMPT=$(jq -r '.message.content // empty' "$INPUT_FILE" 2>/dev/null || echo "")
29
+
30
+ # Clean up input file
31
+ rm -f "$INPUT_FILE"
32
+
33
+ # Skip if no prompt or prompt is too short
34
+ if [ -z "$PROMPT" ] || [ ${#PROMPT} -lt 10 ]; then
35
+ echo "{}"
36
+ exit 0
37
+ fi
38
+
39
+ # Check if hu is available
40
+ if ! command -v hu &> /dev/null; then
41
+ echo "{}"
42
+ exit 0
43
+ fi
44
+
45
+ # Extract first few words for search (avoid searching full long prompts)
46
+ SEARCH_TERMS=$(echo "$PROMPT" | head -c 100 | tr -d '\n' | sed 's/[^a-zA-Z0-9 ]//g' | awk '{for(i=1;i<=NF && i<=5;i++) printf "%s ", $i}')
47
+
48
+ # Skip if search terms are too generic
49
+ if [ -z "$SEARCH_TERMS" ] || [ ${#SEARCH_TERMS} -lt 5 ]; then
50
+ echo "{}"
51
+ exit 0
52
+ fi
53
+
54
+ # Search for similar past messages
55
+ RESULTS_FILE=$(mktemp /tmp/hu-search-XXXXXX.json)
56
+ hu data search "$SEARCH_TERMS" --limit 3 --json > "$RESULTS_FILE" 2>/dev/null || echo "[]" > "$RESULTS_FILE"
57
+
58
+ # Count results
59
+ RESULT_COUNT=$(jq 'length' "$RESULTS_FILE" 2>/dev/null || echo "0")
60
+
61
+ # Build context if we found relevant results
62
+ if [ "$RESULT_COUNT" -gt 0 ]; then
63
+ CONTEXT="## Similar Past Work\\n\\nFound $RESULT_COUNT related messages from previous sessions:\\n\\n"
64
+ CONTEXT+=$(jq -r '.[] | "- [\(.role)] in session \(.session_id[0:8]): \(.content[0:100] | gsub("\n"; " "))..."' "$RESULTS_FILE" 2>/dev/null || echo "")
65
+
66
+ # Escape for JSON
67
+ CONTEXT_ESCAPED=$(echo -e "$CONTEXT" | jq -Rs .)
68
+ echo "{\"additionalContext\": $CONTEXT_ESCAPED}"
69
+ else
70
+ echo "{}"
71
+ fi
72
+
73
+ # Clean up
74
+ rm -f "$RESULTS_FILE"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aladac/hu",
3
- "version": "0.1.0-a1",
3
+ "version": "0.1.0-a2",
4
4
  "description": "CLI tools for Claude Code workflows",
5
5
  "type": "module",
6
6
  "bin": {
@@ -16,16 +16,19 @@
16
16
  "typecheck": "tsc --noEmit"
17
17
  },
18
18
  "dependencies": {
19
+ "better-sqlite3": "^12.6.0",
19
20
  "cheerio": "^1.1.2",
20
21
  "citty": "^0.1.6",
22
+ "smol-toml": "^1.6.0",
21
23
  "turndown": "^7.2.2"
22
24
  },
23
25
  "devDependencies": {
24
26
  "@biomejs/biome": "^1.9.0",
27
+ "@types/better-sqlite3": "^7.6.13",
25
28
  "@types/node": "^22.0.0",
26
29
  "@types/turndown": "^5.0.5",
27
30
  "typescript": "^5.7.0",
28
- "vitest": "^2.1.0"
31
+ "vitest": "^4.0.17"
29
32
  },
30
33
  "engines": {
31
34
  "node": ">=23.6.0"