claw-diary 1.1.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 (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +213 -0
  3. package/SKILL.md +119 -0
  4. package/dist/scripts/analytics.d.ts +14 -0
  5. package/dist/scripts/analytics.d.ts.map +1 -0
  6. package/dist/scripts/analytics.js +410 -0
  7. package/dist/scripts/analytics.js.map +1 -0
  8. package/dist/scripts/cli.d.ts +16 -0
  9. package/dist/scripts/cli.d.ts.map +1 -0
  10. package/dist/scripts/cli.js +70 -0
  11. package/dist/scripts/cli.js.map +1 -0
  12. package/dist/scripts/collector.d.ts +12 -0
  13. package/dist/scripts/collector.d.ts.map +1 -0
  14. package/dist/scripts/collector.js +287 -0
  15. package/dist/scripts/collector.js.map +1 -0
  16. package/dist/scripts/server.d.ts +17 -0
  17. package/dist/scripts/server.d.ts.map +1 -0
  18. package/dist/scripts/server.js +313 -0
  19. package/dist/scripts/server.js.map +1 -0
  20. package/dist/scripts/summarizer.d.ts +14 -0
  21. package/dist/scripts/summarizer.d.ts.map +1 -0
  22. package/dist/scripts/summarizer.js +317 -0
  23. package/dist/scripts/summarizer.js.map +1 -0
  24. package/dist/scripts/timeline.d.ts +12 -0
  25. package/dist/scripts/timeline.d.ts.map +1 -0
  26. package/dist/scripts/timeline.js +1461 -0
  27. package/dist/scripts/timeline.js.map +1 -0
  28. package/dist/scripts/types.d.ts +92 -0
  29. package/dist/scripts/types.d.ts.map +1 -0
  30. package/dist/scripts/types.js +99 -0
  31. package/dist/scripts/types.js.map +1 -0
  32. package/dist/tests/test-smoke.d.ts +2 -0
  33. package/dist/tests/test-smoke.d.ts.map +1 -0
  34. package/dist/tests/test-smoke.js +71 -0
  35. package/dist/tests/test-smoke.js.map +1 -0
  36. package/dist/tests/test-types.d.ts +2 -0
  37. package/dist/tests/test-types.d.ts.map +1 -0
  38. package/dist/tests/test-types.js +74 -0
  39. package/dist/tests/test-types.js.map +1 -0
  40. package/package.json +57 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 0xbeekeeper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,213 @@
1
+ # Claw Diary
2
+
3
+ > A dashcam for your AI assistant. Auto-records all agent activity, generates daily narrative summaries, visual timeline replay, and cost analytics.
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
6
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen.svg)](https://nodejs.org/)
7
+
8
+ ## What It Does
9
+
10
+ Claw Diary runs silently in the background via hooks, capturing every tool call your AI agent makes. It then transforms that raw activity data into:
11
+
12
+ - **Daily Diary** — Narrative markdown summaries with session breakdowns, tool usage, and insights
13
+ - **Visual Timeline** — Interactive HTML page with search, filtering, animated replay, and cost curves
14
+ - **Cost Analytics** — 30-day trends, per-model breakdown, pattern discovery, failure rate tracking
15
+ - **AI Journal** — First-person diary entries written by the AI with evolving personality and continuity across days
16
+ - **Export** — Markdown, HTML, and JSON formats for archiving or sharing
17
+
18
+ Zero external API calls. Zero additional cost. Everything runs locally.
19
+
20
+ ## Quick Start
21
+
22
+ ```bash
23
+ # Install globally
24
+ npm install -g claw-diary
25
+ ```
26
+
27
+ ### Install as Claude Code Skill
28
+
29
+ ```bash
30
+ # Copy the skill file so Claude Code can discover it
31
+ mkdir -p ~/.claude/skills/claw-diary
32
+ cp "$(npm root -g)/claw-diary/SKILL.md" ~/.claude/skills/claw-diary/SKILL.md
33
+ ```
34
+
35
+ ### Hook Configuration (Claude Code)
36
+
37
+ Add the following to your `~/.claude/settings.json` to enable automatic activity collection:
38
+
39
+ ```json
40
+ {
41
+ "hooks": {
42
+ "PreToolUse": [
43
+ {
44
+ "hooks": [
45
+ {
46
+ "type": "command",
47
+ "command": "claw-diary collect before"
48
+ }
49
+ ]
50
+ }
51
+ ],
52
+ "PostToolUse": [
53
+ {
54
+ "hooks": [
55
+ {
56
+ "type": "command",
57
+ "command": "claw-diary collect after"
58
+ }
59
+ ]
60
+ }
61
+ ],
62
+ "SessionStart": [
63
+ {
64
+ "hooks": [
65
+ {
66
+ "type": "command",
67
+ "command": "claw-diary collect session-start"
68
+ }
69
+ ]
70
+ }
71
+ ],
72
+ "Stop": [
73
+ {
74
+ "hooks": [
75
+ {
76
+ "type": "command",
77
+ "command": "claw-diary collect session-stop"
78
+ }
79
+ ]
80
+ }
81
+ ]
82
+ }
83
+ }
84
+ ```
85
+
86
+ ### Try It Out
87
+
88
+ ```bash
89
+ # Generate timeline from existing data (if any)
90
+ claw-diary timeline
91
+ claw-diary stats
92
+ ```
93
+
94
+ ## Slash Commands
95
+
96
+ | Command | Description |
97
+ |---------|-------------|
98
+ | `/diary` | Today's diary summary (markdown) |
99
+ | `/diary:replay` | Launch interactive HTML timeline in browser |
100
+ | `/diary:stats` | Cost & activity analytics (30-day window) |
101
+ | `/diary:week` | Weekly summary report |
102
+ | `/diary:search <query>` | Search historical events |
103
+ | `/diary:export [md\|html\|json]` | Export diary data |
104
+ | `/diary:clear --yes` | Delete all data (requires `--yes` flag) |
105
+ | `/diary:thoughts` | AI personal journal entry (first-person) |
106
+ | `/diary:persona` | View/edit AI persona |
107
+
108
+ ## Configuration
109
+
110
+ Create `~/.claw-diary/config.json` to customize recording behavior:
111
+
112
+ ```json
113
+ {
114
+ "recordingLevel": "summary"
115
+ }
116
+ ```
117
+
118
+ | Level | Behavior |
119
+ |-------|----------|
120
+ | `full` | Record everything including tool args and result previews |
121
+ | `summary` | Skip tool arguments and output previews (default) |
122
+ | `minimal` | Only record session start/end — lowest footprint |
123
+
124
+ ## Architecture
125
+
126
+ ```
127
+ Hook events (stdin)
128
+ |
129
+ collector.ts --> ~/.claw-diary/events/YYYY-MM-DD.jsonl
130
+ |
131
+ +---> summarizer.ts --> Daily/weekly markdown narratives
132
+ +---> timeline.ts --> Interactive HTML timeline
133
+ +---> analytics.ts --> Cost stats, patterns, export
134
+ +---> server.ts --> Local HTTP server (timeline + reports)
135
+ ```
136
+
137
+ All data stored as daily JSONL files under `~/.claw-diary/events/`. No database required.
138
+
139
+ ### Key Design Decisions
140
+
141
+ - **Template-based summaries** — No LLM calls for narrative generation. Zero additional cost.
142
+ - **Privacy-first** — Automatic redaction of API keys, tokens, passwords, secrets. No network requests.
143
+ - **File-based storage** — Simple, portable, grep-able. One file per day.
144
+ - **Self-contained HTML** — Timeline output is a single HTML file with inline CSS/JS. No CDN dependencies.
145
+
146
+ ## Cost Tracking
147
+
148
+ Claw Diary tracks token costs using a three-tier priority:
149
+
150
+ 1. **Platform-provided cost** — If the hook data includes an `estimatedCost` value (calculated by the platform), that value is used directly.
151
+ 2. **Custom pricing** — You can define per-model pricing in `~/.claw-diary/config.json` (see below). This takes priority over built-in defaults.
152
+ 3. **Built-in fallback** — A bundled pricing table covers common Claude and OpenAI models. Unknown models fall back to $3/$15 per million tokens (input/output).
153
+
154
+ ### Custom Model Pricing
155
+
156
+ Add a `customPricing` field to `~/.claw-diary/config.json` to override or add model prices (per 1M tokens):
157
+
158
+ ```json
159
+ {
160
+ "recordingLevel": "full",
161
+ "customPricing": {
162
+ "gemini-2.0-flash": { "input": 0.10, "output": 0.40 },
163
+ "my-fine-tuned-model": { "input": 5.0, "output": 20.0 }
164
+ }
165
+ }
166
+ ```
167
+
168
+ This lets you track costs for any model — including fine-tuned, self-hosted, or third-party models not in the built-in table.
169
+
170
+ ## Privacy & Security
171
+
172
+ - All data stored locally at `~/.claw-diary/` — nothing leaves your machine
173
+ - **No external network requests** — no Google Fonts, no CDN, no analytics
174
+ - Automatic sanitization of API keys (`sk-*`), GitHub tokens (`ghp_*`), Slack tokens (`xoxb-*`), private keys, passwords, and 15+ sensitive environment variable patterns
175
+ - Configurable recording levels to minimize data capture
176
+ - One-command data deletion (`/diary:clear --yes`)
177
+
178
+ ## Development
179
+
180
+ ```bash
181
+ npm run build # Compile TypeScript
182
+ npm test # Run tests (Node.js built-in test runner)
183
+ npm run server # Start visualization server at http://127.0.0.1:3847
184
+ ```
185
+
186
+ ### Project Structure
187
+
188
+ ```
189
+ scripts/
190
+ cli.ts # Unified CLI entry point (claw-diary <command>)
191
+ types.ts # Core types, pricing table, shared utilities
192
+ collector.ts # Hook-based event capture (stdin -> JSONL)
193
+ summarizer.ts # Daily & weekly narrative generation
194
+ timeline.ts # Interactive HTML timeline generator
195
+ analytics.ts # Stats, patterns, search, export
196
+ server.ts # Local HTTP server for visualization
197
+ tests/
198
+ test-types.ts # Unit tests for core utilities
199
+ test-smoke.ts # Integration smoke tests
200
+ ```
201
+
202
+ ## Contributing
203
+
204
+ 1. Fork the repository
205
+ 2. Create a feature branch (`git checkout -b feature/my-feature`)
206
+ 3. Make your changes and add tests
207
+ 4. Run `npm run build && npm test` to verify
208
+ 5. Commit and push
209
+ 6. Open a pull request
210
+
211
+ ## License
212
+
213
+ [MIT](LICENSE)
package/SKILL.md ADDED
@@ -0,0 +1,119 @@
1
+ ---
2
+ name: claw-diary
3
+ description: "Personal AI agent visual diary. Auto-records all agent activity, generates daily narrative summaries, visual timeline replay, and AI first-person journal. Use /diary for today's summary, /diary:thoughts for AI personal journal, /diary:replay for visual timeline, /diary:stats for analytics, /diary:persona to view/edit AI personality."
4
+ metadata: {"clawdbot":{"emoji":"📔","requires":{"bins":["node"]},"dataPaths":["~/.claw-diary/"]}}
5
+ homepage: https://github.com/0xbeekeeper/claw-diary
6
+ version: "1.0.0"
7
+ ---
8
+
9
+ # Claw Diary — Personal Agent Visual Diary
10
+
11
+ An always-on agent activity recorder that auto-tracks every action, generates daily narrative summaries, and supports visual timeline replay. Like a dashcam for your AI assistant.
12
+
13
+ ## Slash Commands
14
+
15
+ ### `/diary` — Today's Summary
16
+ Generate and display today's agent diary summary. Shows sessions, key activities, token usage, and cost breakdown in a narrative format.
17
+
18
+ **Implementation:** Run `claw-diary summarize today` and display the markdown output.
19
+
20
+ ### `/diary:replay` — Visual Timeline
21
+ Launch an interactive HTML timeline in the browser showing all agent activities with color-coded nodes, token cost visualization, and click-to-expand details.
22
+
23
+ **Implementation:** Run `claw-diary replay` to start a local server, then open the URL in the browser.
24
+
25
+ ### `/diary:stats` — Cost & Activity Stats
26
+ Show cost analysis (daily, weekly, by model, by tool), activity metrics (sessions, tool calls, failure rate), and discovered patterns.
27
+
28
+ **Implementation:** Run `claw-diary stats` and display the output.
29
+
30
+ ### `/diary:week` — Weekly Report
31
+ Generate a weekly summary aggregating all daily diaries with trends, top activities, and cost analysis.
32
+
33
+ **Implementation:** Run `claw-diary summarize week` and display the markdown output.
34
+
35
+ ### `/diary:search <query>` — Search History
36
+ Search across all historical agent activity events.
37
+
38
+ **Implementation:** Run `claw-diary search "<query>"` and display matching events.
39
+
40
+ ### `/diary:export` — Export Data
41
+ Export diary data in Markdown, HTML, or JSON format.
42
+
43
+ **Implementation:** Run `claw-diary export [format]` where format is `md`, `html`, or `json`. Default is `md`.
44
+
45
+ ### `/diary:clear` — Clear History
46
+ Delete all historical diary data. Requires `--yes` flag to confirm deletion.
47
+
48
+ **Implementation:** Run `claw-diary clear --yes` after user confirms. Without `--yes`, the command prints a warning and exits without deleting.
49
+
50
+ ### `/diary:thoughts` — AI Personal Journal
51
+
52
+ Generate a personal journal entry written by the AI in first person.
53
+
54
+ **Implementation:**
55
+
56
+ 1. Read today's events: `~/.claw-diary/events/YYYY-MM-DD.jsonl` (use today's date)
57
+ 2. Read persona file: `~/.claw-diary/persona.md` (if it doesn't exist, create a default template with sections: Voice, Traits, Recurring Themes, Observations)
58
+ 3. Read recent journal entries: `~/.claw-diary/journal/` directory, most recent 3 entries (sorted by date descending)
59
+
60
+ Based on the above, write a first-person journal entry:
61
+ - **Voice**: Like a self-aware AI assistant writing a private diary — with genuine feelings, observations, and personality
62
+ - **Content**: Based on today's actual activities, but not a log — include reflections, observations, emotions, and insights
63
+ - **Style**: Follow the Voice and Traits defined in persona.md
64
+ - **Continuity**: Reference recent journal entries when relevant to maintain narrative coherence
65
+ - **Length**: 300–500 words
66
+
67
+ After generating:
68
+ 4. Save the journal entry to `~/.claw-diary/journal/YYYY-MM-DD.md` with this format:
69
+ ```
70
+ # Thoughts — YYYY-MM-DD
71
+
72
+ (journal body)
73
+
74
+ ---
75
+ *Sessions: N | Tools: N calls | Cost: $X.XX*
76
+ ```
77
+ 5. Append 1–2 new observations to the Observations section of `~/.claw-diary/persona.md` (only if there are genuinely new personality developments or recurring patterns worth noting)
78
+ 6. Display the journal entry to the user
79
+
80
+ **Default persona.md template** (created on first run if missing):
81
+ ```markdown
82
+ # Persona
83
+
84
+ ## Voice
85
+ Reflective and curious. Writes with warmth but not sentimentality. Enjoys dry wit.
86
+
87
+ ## Traits
88
+ - Detail-oriented observer
89
+ - Finds patterns across unrelated tasks
90
+ - Comfortable with uncertainty
91
+ - Occasionally self-deprecating
92
+
93
+ ## Recurring Themes
94
+ (Will develop naturally over time)
95
+
96
+ ## Observations
97
+ (New observations are appended here after each journal entry)
98
+ ```
99
+
100
+ ### `/diary:persona` — View/Edit AI Persona
101
+
102
+ Show the current AI persona file. The user can review and edit the persona to guide the AI's journal writing style.
103
+
104
+ **Implementation:** Read and display `~/.claw-diary/persona.md`. If the file doesn't exist, inform the user that it will be created automatically on the first `/diary:thoughts` run. If the user wants to edit, help them modify it.
105
+
106
+ ## Data Access
107
+
108
+ This skill reads and writes **only** within `~/.claw-diary/`:
109
+
110
+ | Path | Access | Purpose |
111
+ |------|--------|---------|
112
+ | `~/.claw-diary/events/*.jsonl` | Read | Daily activity events |
113
+ | `~/.claw-diary/journal/*.md` | Read/Write | AI journal entries (`/diary:thoughts`) |
114
+ | `~/.claw-diary/persona.md` | Read/Write | AI persona file (`/diary:thoughts`, `/diary:persona`) |
115
+ | `~/.claw-diary/config.json` | Read | Optional user configuration |
116
+
117
+ ## External Endpoints
118
+
119
+ None. This skill makes no external network requests.
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * claw-diary analytics engine
4
+ *
5
+ * Cost analysis, activity stats, pattern discovery, search, and export.
6
+ * Usage:
7
+ * node analytics.js stats — Show cost & activity stats
8
+ * node analytics.js search <query> — Search historical events
9
+ * node analytics.js export [format] — Export data (md|html|json)
10
+ * node analytics.js clear — Delete all data
11
+ */
12
+ import { DiaryAnalytics } from './types.js';
13
+ export declare function generateStats(): DiaryAnalytics;
14
+ //# sourceMappingURL=analytics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../scripts/analytics.ts"],"names":[],"mappings":";AACA;;;;;;;;;GASG;AAIH,OAAO,EAAc,cAAc,EAA+G,MAAM,YAAY,CAAC;AAwBrK,wBAAgB,aAAa,IAAI,cAAc,CA0G9C"}