wyrm-mcp 3.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.
- package/LICENSE +667 -0
- package/README.md +384 -0
- package/dist/analytics.d.ts +100 -0
- package/dist/analytics.d.ts.map +1 -0
- package/dist/analytics.js +368 -0
- package/dist/analytics.js.map +1 -0
- package/dist/auto-orchestrator.d.ts +118 -0
- package/dist/auto-orchestrator.d.ts.map +1 -0
- package/dist/auto-orchestrator.js +325 -0
- package/dist/auto-orchestrator.js.map +1 -0
- package/dist/autoconfig.d.ts +89 -0
- package/dist/autoconfig.d.ts.map +1 -0
- package/dist/autoconfig.js +576 -0
- package/dist/autoconfig.js.map +1 -0
- package/dist/cli.d.ts +148 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +281 -0
- package/dist/cli.js.map +1 -0
- package/dist/cloud-backup.d.ts +100 -0
- package/dist/cloud-backup.d.ts.map +1 -0
- package/dist/cloud-backup.js +545 -0
- package/dist/cloud-backup.js.map +1 -0
- package/dist/crypto.d.ts +72 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +164 -0
- package/dist/crypto.js.map +1 -0
- package/dist/database.d.ts +218 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/database.js +1058 -0
- package/dist/database.js.map +1 -0
- package/dist/http-auth.d.ts +68 -0
- package/dist/http-auth.d.ts.map +1 -0
- package/dist/http-auth.js +296 -0
- package/dist/http-auth.js.map +1 -0
- package/dist/http-fast.d.ts +13 -0
- package/dist/http-fast.d.ts.map +1 -0
- package/dist/http-fast.js +325 -0
- package/dist/http-fast.js.map +1 -0
- package/dist/http-server.d.ts +12 -0
- package/dist/http-server.d.ts.map +1 -0
- package/dist/http-server.js +383 -0
- package/dist/http-server.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1695 -0
- package/dist/index.js.map +1 -0
- package/dist/license.d.ts +177 -0
- package/dist/license.d.ts.map +1 -0
- package/dist/license.js +405 -0
- package/dist/license.js.map +1 -0
- package/dist/logger.d.ts +76 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +195 -0
- package/dist/logger.js.map +1 -0
- package/dist/performance.d.ts +114 -0
- package/dist/performance.d.ts.map +1 -0
- package/dist/performance.js +228 -0
- package/dist/performance.js.map +1 -0
- package/dist/resilience.d.ts +146 -0
- package/dist/resilience.d.ts.map +1 -0
- package/dist/resilience.js +563 -0
- package/dist/resilience.js.map +1 -0
- package/dist/security.d.ts +68 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/security.js +215 -0
- package/dist/security.js.map +1 -0
- package/dist/setup.d.ts +21 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +261 -0
- package/dist/setup.js.map +1 -0
- package/dist/summarizer.d.ts +30 -0
- package/dist/summarizer.d.ts.map +1 -0
- package/dist/summarizer.js +139 -0
- package/dist/summarizer.js.map +1 -0
- package/dist/sync.d.ts +39 -0
- package/dist/sync.d.ts.map +1 -0
- package/dist/sync.js +356 -0
- package/dist/sync.js.map +1 -0
- package/dist/types.d.ts +267 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +30 -0
- package/dist/types.js.map +1 -0
- package/dist/vectors.d.ts +103 -0
- package/dist/vectors.d.ts.map +1 -0
- package/dist/vectors.js +311 -0
- package/dist/vectors.js.map +1 -0
- package/package.json +73 -0
package/README.md
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
# 🐉 Wyrm — Persistent Memory for AI Agents
|
|
2
|
+
|
|
3
|
+
> Your AI forgets everything between sessions. Wyrm remembers.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@wyrm/mcp-server)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](packages/mcp-server)
|
|
8
|
+
[](https://www.typescriptlang.org/)
|
|
9
|
+
[](https://modelcontextprotocol.io)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## The Problem
|
|
14
|
+
|
|
15
|
+
AI assistants lose all context between conversations. Every new session starts from zero — you re-explain your codebase, your preferences, your project architecture, the decisions you already made. It's like working with a brilliant colleague who has amnesia.
|
|
16
|
+
|
|
17
|
+
## The Solution
|
|
18
|
+
|
|
19
|
+
Wyrm is an [MCP](https://modelcontextprotocol.io) server that gives AI agents **persistent, searchable memory**. It stores projects, sessions, quests, skills, and arbitrary data in a local SQLite database with full-text search. Connect it once, and your AI remembers everything — across sessions, across tools, across projects.
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
You: "What did we decide about the auth architecture last week?"
|
|
23
|
+
AI: *checks Wyrm* "We went with JWT + refresh tokens, stored in httpOnly cookies.
|
|
24
|
+
Here's the session from Tuesday with the full discussion..."
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Features
|
|
30
|
+
|
|
31
|
+
- 🧠 **Persistent Memory** — Projects, sessions, quests, context, and skills survive across sessions
|
|
32
|
+
- 🔍 **Full-Text Search** — FTS5-powered instant search across all stored data
|
|
33
|
+
- 📊 **Data Lake** — Store and query any structured data with namespaces and metadata
|
|
34
|
+
- 🎯 **Quest Tracking** — Task management with priorities, tags, and cross-project visibility
|
|
35
|
+
- 🔒 **Optional Encryption** — AES-256-GCM for sensitive data, keys never leave your machine
|
|
36
|
+
- 🛡️ **Input Sanitization** — Built-in security against injection attacks
|
|
37
|
+
- 📈 **Usage Analytics** — Token tracking, cost estimation, session metrics
|
|
38
|
+
- 🔄 **Markdown Sync** — Bi-directional sync between database and `.wyrm/` project files
|
|
39
|
+
- 🚀 **Zero Config** — Install, connect, done. No databases to set up, no services to run.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Quick Start
|
|
44
|
+
|
|
45
|
+
### 1. Install
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# From source (recommended for now)
|
|
49
|
+
git clone https://github.com/ghosts-lk/Wyrm.git
|
|
50
|
+
cd Wyrm/packages/mcp-server
|
|
51
|
+
npm install && npm run build
|
|
52
|
+
npm link
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 2. Connect to Your AI
|
|
56
|
+
|
|
57
|
+
Add Wyrm to your AI client's MCP configuration:
|
|
58
|
+
|
|
59
|
+
<details>
|
|
60
|
+
<summary><strong>Claude Desktop</strong></summary>
|
|
61
|
+
|
|
62
|
+
Edit `~/.config/claude/claude_desktop_config.json` (Linux) or `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS):
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"mcpServers": {
|
|
67
|
+
"wyrm": {
|
|
68
|
+
"command": "wyrm-mcp"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
</details>
|
|
75
|
+
|
|
76
|
+
<details>
|
|
77
|
+
<summary><strong>GitHub Copilot (VS Code)</strong></summary>
|
|
78
|
+
|
|
79
|
+
Add to `.vscode/settings.json` or your user settings:
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"mcp": {
|
|
84
|
+
"servers": {
|
|
85
|
+
"wyrm": {
|
|
86
|
+
"command": "wyrm-mcp"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
</details>
|
|
94
|
+
|
|
95
|
+
<details>
|
|
96
|
+
<summary><strong>GitHub Copilot CLI</strong></summary>
|
|
97
|
+
|
|
98
|
+
Add to `~/.copilot/mcp-config.json`:
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"mcpServers": {
|
|
103
|
+
"wyrm": {
|
|
104
|
+
"command": "wyrm-mcp"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
</details>
|
|
111
|
+
|
|
112
|
+
<details>
|
|
113
|
+
<summary><strong>Cursor</strong></summary>
|
|
114
|
+
|
|
115
|
+
Add to `~/.cursor/mcp.json`:
|
|
116
|
+
|
|
117
|
+
```json
|
|
118
|
+
{
|
|
119
|
+
"mcpServers": {
|
|
120
|
+
"wyrm": {
|
|
121
|
+
"command": "wyrm-mcp"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
</details>
|
|
128
|
+
|
|
129
|
+
<details>
|
|
130
|
+
<summary><strong>Windsurf</strong></summary>
|
|
131
|
+
|
|
132
|
+
Add to `~/.codeium/windsurf/mcp_config.json`:
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{
|
|
136
|
+
"mcpServers": {
|
|
137
|
+
"wyrm": {
|
|
138
|
+
"command": "wyrm-mcp"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
</details>
|
|
145
|
+
|
|
146
|
+
Or run **`wyrm-setup`** to auto-detect and configure all installed AI clients at once.
|
|
147
|
+
|
|
148
|
+
### 3. Use It
|
|
149
|
+
|
|
150
|
+
Once connected, your AI has access to all Wyrm tools. Try:
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
"Scan ~/projects for git repositories"
|
|
154
|
+
"Start a session for my auth refactor"
|
|
155
|
+
"What quests are pending across all projects?"
|
|
156
|
+
"Search my memory for anything about database migrations"
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## MCP Tools Reference
|
|
162
|
+
|
|
163
|
+
Wyrm exposes 31 tools via the Model Context Protocol:
|
|
164
|
+
|
|
165
|
+
### Projects
|
|
166
|
+
|
|
167
|
+
| Tool | Description |
|
|
168
|
+
|------|-------------|
|
|
169
|
+
| `wyrm_scan_projects` | Discover git projects in a directory tree |
|
|
170
|
+
| `wyrm_list_projects` | List all registered projects with metadata |
|
|
171
|
+
| `wyrm_project_context` | Get full context for a project (sessions, quests, data) |
|
|
172
|
+
| `wyrm_global_context` | Overview across all projects |
|
|
173
|
+
|
|
174
|
+
### Sessions
|
|
175
|
+
|
|
176
|
+
| Tool | Description |
|
|
177
|
+
|------|-------------|
|
|
178
|
+
| `wyrm_session_start` | Start or continue a named session with context |
|
|
179
|
+
| `wyrm_session_update` | Update session with completed work, decisions, and notes |
|
|
180
|
+
|
|
181
|
+
### Quests (Task Tracking)
|
|
182
|
+
|
|
183
|
+
| Tool | Description |
|
|
184
|
+
|------|-------------|
|
|
185
|
+
| `wyrm_quest_add` | Add a task with priority, tags, and description |
|
|
186
|
+
| `wyrm_quest_complete` | Mark a task as done with completion notes |
|
|
187
|
+
| `wyrm_all_quests` | List pending tasks across all projects |
|
|
188
|
+
|
|
189
|
+
### Data Lake
|
|
190
|
+
|
|
191
|
+
| Tool | Description |
|
|
192
|
+
|------|-------------|
|
|
193
|
+
| `wyrm_data_insert` | Store a data point with namespace and metadata |
|
|
194
|
+
| `wyrm_data_batch_insert` | Bulk insert for large datasets |
|
|
195
|
+
| `wyrm_data_query` | Query stored data by namespace, key, or content |
|
|
196
|
+
| `wyrm_data_categories` | List all data categories for a project |
|
|
197
|
+
|
|
198
|
+
### Skills Registry
|
|
199
|
+
|
|
200
|
+
| Tool | Description |
|
|
201
|
+
|------|-------------|
|
|
202
|
+
| `wyrm_skill_register` | Register or update a skill with metadata |
|
|
203
|
+
| `wyrm_skill_list` | List skills with filtering options |
|
|
204
|
+
| `wyrm_skill_get` | Get detailed skill information |
|
|
205
|
+
| `wyrm_skill_search` | Search skills by name, description, or tags |
|
|
206
|
+
| `wyrm_skill_activate` / `wyrm_skill_deactivate` | Toggle skill status |
|
|
207
|
+
| `wyrm_skill_delete` | Remove a skill |
|
|
208
|
+
| `wyrm_skill_stats` | Skill registry statistics |
|
|
209
|
+
|
|
210
|
+
### Search & Utilities
|
|
211
|
+
|
|
212
|
+
| Tool | Description |
|
|
213
|
+
|------|-------------|
|
|
214
|
+
| `wyrm_search` | Full-text search across all projects, sessions, quests, and data |
|
|
215
|
+
| `wyrm_set_global` | Set global context that applies across all projects |
|
|
216
|
+
| `wyrm_sync` | Sync database with `.wyrm/` markdown files |
|
|
217
|
+
| `wyrm_stats` | Database statistics and health |
|
|
218
|
+
| `wyrm_usage` | Token usage stats, cache hit rates, and cost estimates |
|
|
219
|
+
| `wyrm_maintenance` | Vacuum, archive old data, optimize indexes |
|
|
220
|
+
| `wyrm_setup` | Auto-configure Wyrm in all detected AI clients |
|
|
221
|
+
|
|
222
|
+
### Auto-Orchestration
|
|
223
|
+
|
|
224
|
+
| Tool | Description |
|
|
225
|
+
|------|-------------|
|
|
226
|
+
| `wyrm_orchestrate_task` | Classify a task and get an orchestration plan |
|
|
227
|
+
| `wyrm_orchestration_config` | View or update orchestration settings |
|
|
228
|
+
| `wyrm_orchestration_stats` | Orchestration effectiveness and task distribution |
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## Configuration
|
|
233
|
+
|
|
234
|
+
### Environment Variables
|
|
235
|
+
|
|
236
|
+
| Variable | Default | Description |
|
|
237
|
+
|----------|---------|-------------|
|
|
238
|
+
| `WYRM_DB_PATH` | `~/.wyrm/wyrm.db` | SQLite database location |
|
|
239
|
+
| `WYRM_ENCRYPTION_KEY` | *(none)* | AES-256-GCM encryption key for sensitive data |
|
|
240
|
+
| `WYRM_LOG_LEVEL` | `info` | Logging level (`debug`, `info`, `warn`, `error`) |
|
|
241
|
+
| `WYRM_HTTP_PORT` | `3333` | HTTP API server port |
|
|
242
|
+
|
|
243
|
+
### Encryption
|
|
244
|
+
|
|
245
|
+
To enable encryption for sensitive context data:
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
# Generate a key
|
|
249
|
+
openssl rand -hex 32
|
|
250
|
+
|
|
251
|
+
# Set it before starting Wyrm
|
|
252
|
+
export WYRM_ENCRYPTION_KEY="your-64-char-hex-key"
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
All encryption happens locally. Keys never leave your machine.
|
|
256
|
+
|
|
257
|
+
### Per-Project Files
|
|
258
|
+
|
|
259
|
+
Each tracked project gets a `.wyrm/` directory:
|
|
260
|
+
|
|
261
|
+
```
|
|
262
|
+
project/
|
|
263
|
+
└── .wyrm/
|
|
264
|
+
├── hoard.md # 🐉 Project knowledge — architecture, decisions, context
|
|
265
|
+
├── chronicles.md # 📜 Session history — what was discussed and built
|
|
266
|
+
├── quests.md # ⚔️ Task queue — pending and completed work
|
|
267
|
+
└── protocol.md # 🔥 AI guidelines — project-specific instructions
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
These sync bi-directionally with the SQLite database via `wyrm_sync`.
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## Architecture
|
|
275
|
+
|
|
276
|
+
```
|
|
277
|
+
┌─────────────────────────────────────────────────────────┐
|
|
278
|
+
│ AI Assistants │
|
|
279
|
+
│ (Copilot · Claude · Cursor · Windsurf · Zed) │
|
|
280
|
+
└────────────────────────┬────────────────────────────────┘
|
|
281
|
+
│ MCP (stdio)
|
|
282
|
+
▼
|
|
283
|
+
┌─────────────────────────────────────────────────────────┐
|
|
284
|
+
│ Wyrm MCP Server │
|
|
285
|
+
│ │
|
|
286
|
+
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌────────┐ │
|
|
287
|
+
│ │ Projects │ │ Sessions │ │ Quests │ │ Skills │ │
|
|
288
|
+
│ └──────────┘ └──────────┘ └──────────┘ └────────┘ │
|
|
289
|
+
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌────────┐ │
|
|
290
|
+
│ │ DataLake │ │ Search │ │ Crypto │ │ Sync │ │
|
|
291
|
+
│ │ │ │ (FTS5) │ │(AES-256) │ │ (.md) │ │
|
|
292
|
+
│ └──────────┘ └──────────┘ └──────────┘ └────────┘ │
|
|
293
|
+
│ │
|
|
294
|
+
│ SQLite Database (WAL mode) │
|
|
295
|
+
│ Optional HTTP API (:3333) │
|
|
296
|
+
└─────────────────────────────────────────────────────────┘
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
**Stack:** TypeScript · Node.js · better-sqlite3 · FTS5 · MCP SDK
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## Development
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
# Clone and install
|
|
307
|
+
git clone https://github.com/ghosts-lk/Wyrm.git
|
|
308
|
+
cd Wyrm/packages/mcp-server
|
|
309
|
+
npm install
|
|
310
|
+
|
|
311
|
+
# Build
|
|
312
|
+
npm run build
|
|
313
|
+
|
|
314
|
+
# Run tests
|
|
315
|
+
npm test
|
|
316
|
+
|
|
317
|
+
# Watch mode
|
|
318
|
+
npm run dev
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### Project Structure
|
|
322
|
+
|
|
323
|
+
```
|
|
324
|
+
Wyrm/
|
|
325
|
+
├── packages/
|
|
326
|
+
│ ├── mcp-server/ # Core MCP server
|
|
327
|
+
│ │ ├── src/
|
|
328
|
+
│ │ │ ├── index.ts # MCP tool definitions & server
|
|
329
|
+
│ │ │ ├── database.ts # SQLite schema & queries
|
|
330
|
+
│ │ │ ├── crypto.ts # AES-256-GCM encryption
|
|
331
|
+
│ │ │ ├── security.ts # Input sanitization
|
|
332
|
+
│ │ │ └── ...
|
|
333
|
+
│ │ ├── tests/ # Jest test suite
|
|
334
|
+
│ │ └── package.json
|
|
335
|
+
│ └── vscode-extension/ # VS Code extension (optional)
|
|
336
|
+
├── config/ # Configuration templates
|
|
337
|
+
├── templates/ # Project template files
|
|
338
|
+
├── docs/ # Documentation
|
|
339
|
+
├── examples/ # Usage examples
|
|
340
|
+
└── scripts/ # Utility scripts
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
## Contributing
|
|
346
|
+
|
|
347
|
+
Contributions are welcome! Here's how:
|
|
348
|
+
|
|
349
|
+
1. **Fork** the repository
|
|
350
|
+
2. **Create** a feature branch (`git checkout -b feat/amazing-feature`)
|
|
351
|
+
3. **Commit** your changes (`git commit -m 'feat: add amazing feature'`)
|
|
352
|
+
4. **Push** to the branch (`git push origin feat/amazing-feature`)
|
|
353
|
+
5. **Open** a Pull Request
|
|
354
|
+
|
|
355
|
+
Please ensure tests pass (`npm test`) and the project builds (`npm run build`) before submitting.
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## Security
|
|
360
|
+
|
|
361
|
+
- **Local-only** — All data stored on your machine. Nothing leaves by default.
|
|
362
|
+
- **No telemetry** — Zero data collection, zero phone-home.
|
|
363
|
+
- **Optional encryption** — AES-256-GCM for sensitive context data.
|
|
364
|
+
- **Audited** — Security audits documented in [SECURITY_AUDIT.md](SECURITY_AUDIT.md) and [SECURITY_AUDIT_V2.md](SECURITY_AUDIT_V2.md).
|
|
365
|
+
|
|
366
|
+
Found a vulnerability? Please open an issue or email security@ghosts.lk.
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
## License
|
|
371
|
+
|
|
372
|
+
[AGPL-3.0](LICENSE) — Copyright © 2024-2026 [Ghost Protocol (Pvt) Ltd](https://ghosts.lk)
|
|
373
|
+
|
|
374
|
+
For commercial licensing (e.g. embedding Wyrm in proprietary products), contact [ghosts.lk@proton.me](mailto:ghosts.lk@proton.me).
|
|
375
|
+
|
|
376
|
+
---
|
|
377
|
+
|
|
378
|
+
<div align="center">
|
|
379
|
+
|
|
380
|
+
*The dragon remembers.* 🐉
|
|
381
|
+
|
|
382
|
+
Built by [Ghost Protocol](https://ghosts.lk)
|
|
383
|
+
|
|
384
|
+
</div>
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wyrm Analytics — Persistent Usage Tracking & Cost Monitoring
|
|
3
|
+
*
|
|
4
|
+
* @copyright 2026 Ghost Protocol (Pvt) Ltd. All Rights Reserved.
|
|
5
|
+
* @license Proprietary - See LICENSE file for details.
|
|
6
|
+
* @module analytics
|
|
7
|
+
* @version 3.2.0
|
|
8
|
+
*/
|
|
9
|
+
import Database from 'better-sqlite3';
|
|
10
|
+
export interface UsageEvent {
|
|
11
|
+
tool: string;
|
|
12
|
+
tokens_in: number;
|
|
13
|
+
tokens_out: number;
|
|
14
|
+
cached: boolean;
|
|
15
|
+
ms: number;
|
|
16
|
+
success?: boolean;
|
|
17
|
+
error?: string;
|
|
18
|
+
timestamp: string;
|
|
19
|
+
}
|
|
20
|
+
export interface AnalyticsDashboard {
|
|
21
|
+
period: {
|
|
22
|
+
start: string;
|
|
23
|
+
end: string;
|
|
24
|
+
};
|
|
25
|
+
summary: {
|
|
26
|
+
total_calls: number;
|
|
27
|
+
unique_tools: number;
|
|
28
|
+
total_tokens_in: number;
|
|
29
|
+
total_tokens_out: number;
|
|
30
|
+
cache_hit_rate: number;
|
|
31
|
+
avg_response_ms: number;
|
|
32
|
+
error_rate: number;
|
|
33
|
+
estimated_cost_usd: number;
|
|
34
|
+
};
|
|
35
|
+
top_tools: Array<{
|
|
36
|
+
tool: string;
|
|
37
|
+
calls: number;
|
|
38
|
+
tokens: number;
|
|
39
|
+
}>;
|
|
40
|
+
daily: Array<{
|
|
41
|
+
date: string;
|
|
42
|
+
calls: number;
|
|
43
|
+
tokens: number;
|
|
44
|
+
errors: number;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
export interface ToolAnalytics {
|
|
48
|
+
tool: string;
|
|
49
|
+
total_calls: number;
|
|
50
|
+
avg_tokens_in: number;
|
|
51
|
+
avg_tokens_out: number;
|
|
52
|
+
avg_response_ms: number;
|
|
53
|
+
cache_hit_rate: number;
|
|
54
|
+
error_rate: number;
|
|
55
|
+
daily: Array<{
|
|
56
|
+
date: string;
|
|
57
|
+
calls: number;
|
|
58
|
+
}>;
|
|
59
|
+
}
|
|
60
|
+
export interface CostReport {
|
|
61
|
+
period: string;
|
|
62
|
+
tools: Array<{
|
|
63
|
+
tool: string;
|
|
64
|
+
calls: number;
|
|
65
|
+
tokens_in: number;
|
|
66
|
+
tokens_out: number;
|
|
67
|
+
cost_usd: number;
|
|
68
|
+
}>;
|
|
69
|
+
total_cost_usd: number;
|
|
70
|
+
projected_monthly_usd: number;
|
|
71
|
+
}
|
|
72
|
+
export declare class WyrmAnalytics {
|
|
73
|
+
private db;
|
|
74
|
+
private insertStmt;
|
|
75
|
+
private batchBuffer;
|
|
76
|
+
private flushInterval;
|
|
77
|
+
constructor(db: Database.Database);
|
|
78
|
+
private initTables;
|
|
79
|
+
/** Record a single tool usage event */
|
|
80
|
+
record(event: UsageEvent): void;
|
|
81
|
+
/** Flush buffered events to disk */
|
|
82
|
+
flush(): void;
|
|
83
|
+
/** Update cost_tracking aggregates from a batch of events */
|
|
84
|
+
private updateCostTracking;
|
|
85
|
+
/** Get dashboard summary for a time period */
|
|
86
|
+
dashboard(days?: number): AnalyticsDashboard;
|
|
87
|
+
/** Get per-tool breakdown */
|
|
88
|
+
toolBreakdown(toolName: string, days?: number): ToolAnalytics;
|
|
89
|
+
/** Get cost estimate for a period */
|
|
90
|
+
costReport(period?: string): CostReport;
|
|
91
|
+
/** Clean up old events (retention policy) */
|
|
92
|
+
cleanup(retainDays?: number): {
|
|
93
|
+
deleted: number;
|
|
94
|
+
};
|
|
95
|
+
/** Shutdown: flush remaining buffer and clear timer */
|
|
96
|
+
shutdown(): void;
|
|
97
|
+
/** Estimate USD cost from token counts (Claude Sonnet rates) */
|
|
98
|
+
private estimateCost;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=analytics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../src/analytics.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAItC,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB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