sqlew 2.1.4 → 3.0.2

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 (84) hide show
  1. package/CHANGELOG.md +891 -605
  2. package/README.md +302 -690
  3. package/assets/kanban-style.png +0 -0
  4. package/assets/schema.sql +531 -402
  5. package/dist/database.d.ts +9 -0
  6. package/dist/database.d.ts.map +1 -1
  7. package/dist/database.js +33 -34
  8. package/dist/database.js.map +1 -1
  9. package/dist/index.js +1024 -213
  10. package/dist/index.js.map +1 -1
  11. package/dist/migrations/add-task-tables.d.ts +47 -0
  12. package/dist/migrations/add-task-tables.d.ts.map +1 -0
  13. package/dist/migrations/add-task-tables.js +285 -0
  14. package/dist/migrations/add-task-tables.js.map +1 -0
  15. package/dist/migrations/index.d.ts +96 -0
  16. package/dist/migrations/index.d.ts.map +1 -0
  17. package/dist/migrations/index.js +239 -0
  18. package/dist/migrations/index.js.map +1 -0
  19. package/dist/migrations/migrate-decisions-to-tasks.d.ts +61 -0
  20. package/dist/migrations/migrate-decisions-to-tasks.d.ts.map +1 -0
  21. package/dist/migrations/migrate-decisions-to-tasks.js +442 -0
  22. package/dist/migrations/migrate-decisions-to-tasks.js.map +1 -0
  23. package/dist/schema.d.ts.map +1 -1
  24. package/dist/schema.js +14 -3
  25. package/dist/schema.js.map +1 -1
  26. package/dist/tools/constraints.d.ts +4 -0
  27. package/dist/tools/constraints.d.ts.map +1 -1
  28. package/dist/tools/constraints.js +6 -27
  29. package/dist/tools/constraints.js.map +1 -1
  30. package/dist/tools/context.d.ts +17 -1
  31. package/dist/tools/context.d.ts.map +1 -1
  32. package/dist/tools/context.js +195 -190
  33. package/dist/tools/context.js.map +1 -1
  34. package/dist/tools/files.d.ts.map +1 -1
  35. package/dist/tools/files.js +113 -166
  36. package/dist/tools/files.js.map +1 -1
  37. package/dist/tools/messaging.d.ts +2 -9
  38. package/dist/tools/messaging.d.ts.map +1 -1
  39. package/dist/tools/messaging.js +67 -126
  40. package/dist/tools/messaging.js.map +1 -1
  41. package/dist/tools/tasks.d.ts +90 -0
  42. package/dist/tools/tasks.d.ts.map +1 -0
  43. package/dist/tools/tasks.js +732 -0
  44. package/dist/tools/tasks.js.map +1 -0
  45. package/dist/tools/utils.d.ts +8 -1
  46. package/dist/tools/utils.d.ts.map +1 -1
  47. package/dist/tools/utils.js +50 -21
  48. package/dist/tools/utils.js.map +1 -1
  49. package/dist/types.d.ts +14 -0
  50. package/dist/types.d.ts.map +1 -1
  51. package/dist/utils/batch.d.ts +69 -0
  52. package/dist/utils/batch.d.ts.map +1 -0
  53. package/dist/utils/batch.js +148 -0
  54. package/dist/utils/batch.js.map +1 -0
  55. package/dist/utils/query-builder.d.ts +68 -0
  56. package/dist/utils/query-builder.d.ts.map +1 -0
  57. package/dist/utils/query-builder.js +116 -0
  58. package/dist/utils/query-builder.js.map +1 -0
  59. package/dist/utils/task-stale-detection.d.ts +28 -0
  60. package/dist/utils/task-stale-detection.d.ts.map +1 -0
  61. package/dist/utils/task-stale-detection.js +92 -0
  62. package/dist/utils/task-stale-detection.js.map +1 -0
  63. package/dist/utils/validators.d.ts +57 -0
  64. package/dist/utils/validators.d.ts.map +1 -0
  65. package/dist/utils/validators.js +117 -0
  66. package/dist/utils/validators.js.map +1 -0
  67. package/docs/AI_AGENT_GUIDE.md +1471 -648
  68. package/{ARCHITECTURE.md → docs/ARCHITECTURE.md} +636 -636
  69. package/docs/BEST_PRACTICES.md +481 -0
  70. package/docs/DECISION_TO_TASK_MIGRATION_GUIDE.md +457 -0
  71. package/docs/MIGRATION_CHAIN.md +280 -0
  72. package/{MIGRATION_v2.md → docs/MIGRATION_v2.md} +538 -538
  73. package/docs/SHARED_CONCEPTS.md +339 -0
  74. package/docs/TASK_ACTIONS.md +854 -0
  75. package/docs/TASK_LINKING.md +729 -0
  76. package/docs/TASK_MIGRATION.md +701 -0
  77. package/docs/TASK_OVERVIEW.md +363 -0
  78. package/docs/TASK_SYSTEM.md +1244 -0
  79. package/docs/TOOL_REFERENCE.md +471 -0
  80. package/docs/TOOL_SELECTION.md +279 -0
  81. package/docs/WORKFLOWS.md +602 -0
  82. package/docs/refactoring-summary-2025-10-17.md +365 -0
  83. package/docs/requirement-2025-10-17.md +508 -0
  84. package/package.json +64 -64
package/README.md CHANGED
@@ -1,690 +1,302 @@
1
- # sqlew
2
- ![sqlew_logo](assets/sqlew-logo.png)
3
-
4
- [![npm version](https://img.shields.io/npm/v/sqlew.svg)](https://www.npmjs.com/package/sqlew)
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
-
7
- > **SQL Efficient Workflow** - MCP server for efficient context sharing between Claude Code sub-agents
8
-
9
- ## Overview
10
-
11
- **sqlew** is a Model Context Protocol (MCP) server that enables efficient context sharing between multiple Claude Code agents through a SQLite-backed database. It dramatically reduces token consumption while providing structured data management through metadata-driven organization.
12
-
13
- **Current Version:** 2.1.1
14
-
15
- ## Benefits
16
-
17
- ### 🧠 Organizational Memory for AI Agents
18
-
19
- **sqlew solves the "organizational memory" problem that traditional code can't:**
20
-
21
- | What Traditional Code Provides | What sqlew Adds |
22
- |-------------------------------|-----------------|
23
- | **Git history** - WHAT changed | ✅ **Decisions** - WHY it changed |
24
- | ✅ **Code comments** - HOW it works | ✅ **Constraints** - WHY it must work this way |
25
- | **Architectural decisions** - Missing! | **Context survival** - Across sessions |
26
-
27
- **Real-World Example:**
28
- ```typescript
29
- // Agent in Session 1 records:
30
- {
31
- key: "loom/duration-constraint",
32
- value: "Duration must NOT occur in Loom module",
33
- layer: "business",
34
- tags: ["architecture", "constraint", "breaking"]
35
- }
36
-
37
- // Agent in Session 2 queries:
38
- "What are business layer constraints for Loom module?"
39
- Finds: "Duration must NOT occur in Loom"
40
- Avoids introducing the same bug you just fixed!
41
- ```
42
-
43
- ### 💡 Why This Matters for LLMs
44
-
45
- 1. **Context Survival**: Next Claude session can query architectural decisions from previous sessions
46
- 2. **Prevents Regression**: Constraints like "Duration must NOT occur in Loom" prevent reintroducing bugs
47
- 3. **Historical Reasoning**: Captures WHY decisions were made, not just WHAT changed
48
- 4. **Knowledge Discovery**: Searchable by layer/tag/scope - "Show me all breaking changes in business layer"
49
-
50
- ### Real-World Token Savings
51
-
52
- **Scenario: 5 Agents Working Across 10 Sessions**
53
-
54
- | Approach | Token Usage | Details |
55
- |----------|-------------|---------|
56
- | **Without sqlew** | ~20,000 tokens | All context re-provided every session |
57
- | **With sqlew** | ~7,400 tokens | Selective queries, persistent storage |
58
- | **Savings** | **63% reduction** | Realistic multi-session project |
59
-
60
- **Why sqlew Saves Tokens:**
61
-
62
- 1. **Selective Retrieval** (50-70% savings)
63
- - Without: Must read ALL context every time
64
- - With: Query only what's needed - `search_layer("business")` returns 5 decisions, not 100
65
-
66
- 2. **Structured vs Unstructured** (60-85% savings)
67
- - Without: "We decided to use JWT because..." (50-200 tokens in prose)
68
- - With: `{key: "auth", value: "JWT", layer: "business"}` (20-30 tokens)
69
-
70
- 3. **Cross-Session Persistence** (80-95% savings)
71
- - Without: Context re-provided every new session
72
- - With: Query from database, context survives sessions
73
-
74
- 4. **Search Instead of Scan** (70-90% savings)
75
- - Without: Read all 100 decisions to find 5 relevant ones
76
- - With: `search_tags(["breaking", "api"])` → only relevant results
77
-
78
- **Expected Token Reduction (Typical Multi-Agent Project):**
79
- - Conservative: 50-65% reduction
80
- - Realistic: 60-75% reduction
81
- - Optimal: 70-85% reduction
82
-
83
- *Note: Internal architecture improvements (v1.0.0→v2.0.0) achieved 96% tool definition reduction and 67% MCP context reduction. The percentages above reflect real-world usage benefits.*
84
-
85
- **Performance:**
86
- - Query response: 2-50ms
87
- - Concurrent access: 5+ simultaneous agents
88
- - Storage efficiency: ~140 bytes per decision
89
-
90
- **Reliability:**
91
- - SQLite ACID transactions
92
- - 100% backward compatible upgrades
93
-
94
- ## Features
95
-
96
- ### Core Capabilities
97
- - **Context Management** - Store and retrieve decisions with tags, layers, scopes, and versions
98
- - **Agent Messaging** - Priority-based messaging system with broadcast support
99
- - **File Change Tracking** - Layer-based file organization with lock detection
100
- - **Constraint Management** - Track performance, architecture, and security constraints
101
- - **Activity Logging** - Automatic tracking of all agent actions (v2.1.0)
102
- - **Weekend-Aware Auto-Cleanup** - Smart retention policies that pause during weekends
103
-
104
- ### Advanced Features (v2.1.0)
105
- - **Smart Defaults** - Auto-infer layer and tags from file paths (60% token reduction)
106
- - **Batch Operations** - Process up to 50 operations atomically (70% token reduction)
107
- - **Update Polling** - Lightweight subscription mechanism (95% token reduction)
108
- - **Advanced Query** - Complex multi-criteria filtering with full-text search
109
- - **Templates** - 5 built-in templates + custom template support
110
- - **CLI Tool** - Standalone query commands without MCP server
111
-
112
- ### 6 Consolidated Tools (26 Actions)
113
- 1. **`decision`** (13 actions) - Context management with metadata
114
- 2. **`message`** (4 actions) - Agent-to-agent messaging
115
- 3. **`file`** (4 actions) - File change tracking
116
- 4. **`constraint`** (3 actions) - Constraint management
117
- 5. **`stats`** (4 actions) - Statistics and cleanup
118
- 6. **`config`** (2 actions) - Configuration management
119
-
120
- ## Installation
121
-
122
- ### Requirements
123
- - Node.js 18.0.0 or higher
124
- - npm or npx
125
-
126
- ### Install from npm
127
-
128
- ```bash
129
- npm install sqlew
130
- ```
131
-
132
- ### Quick Test
133
-
134
- ```bash
135
- # Test with MCP Inspector
136
- npx @modelcontextprotocol/inspector npx sqlew
137
- ```
138
-
139
- ## Quick Start
140
-
141
- ### Add to Claude Desktop
142
-
143
- Add to your Claude Desktop configuration (`claude_desktop_config.json`):
144
-
145
- ```json
146
- {
147
- "mcpServers": {
148
- "sqlew": {
149
- "command": "npx",
150
- "args": ["sqlew"]
151
- }
152
- }
153
- }
154
- ```
155
-
156
- ### Custom Database Path
157
-
158
- ```json
159
- {
160
- "mcpServers": {
161
- "sqlew": {
162
- "command": "npx",
163
- "args": ["sqlew", "/path/to/database.db"]
164
- }
165
- }
166
- }
167
- ```
168
-
169
- ### Weekend-Aware Auto-Deletion
170
-
171
- ```json
172
- {
173
- "mcpServers": {
174
- "sqlew": {
175
- "command": "npx",
176
- "args": [
177
- "sqlew",
178
- "--autodelete-ignore-weekend",
179
- "--autodelete-message-hours=48",
180
- "--autodelete-file-history-days=10"
181
- ]
182
- }
183
- }
184
- }
185
- ```
186
-
187
- ### Default Database Location
188
-
189
- `.sqlew/sqlew.db` (created in current directory)
190
-
191
- ## For AI Agents
192
-
193
- **🤖 Claude Code and other AI agents: Read this section first!**
194
-
195
- ### Most Important Rule
196
-
197
- ⚠️ **ALWAYS include the `action` parameter** - This is required in ALL tool calls and is the #1 cause of errors.
198
-
199
- ```javascript
200
- // WRONG
201
- {key: "auth_method", value: "jwt"}
202
-
203
- // ✅ CORRECT
204
- {action: "set", key: "auth_method", value: "jwt", layer: "business"}
205
- ```
206
-
207
- ### Quick Parameter Reference
208
-
209
- Every tool requires an `action` parameter. Use `{action: "help"}` on any tool for detailed documentation.
210
-
211
- | Tool | Common Actions | Required Parameters (besides action) |
212
- |------|----------------|-------------------------------------|
213
- | **decision** | set, get, list, search_tags | set: key, value, layer |
214
- | **message** | send, get, mark_read | send: from_agent, msg_type, message |
215
- | **file** | record, get, check_lock | record: file_path, agent_name, change_type |
216
- | **constraint** | add, get, deactivate | add: category, constraint_text |
217
- | **stats** | layer_summary, db_stats, clear | (no additional required) |
218
- | **config** | get, update | (no additional required) |
219
-
220
- ### Common Errors & Quick Fixes
221
-
222
- ```javascript
223
- // Error: "Unknown action: undefined"
224
- // Fix: Add action parameter
225
- {action: "set", ...}
226
-
227
- // Error: "Parameter \"value\" is required"
228
- // Fix: Don't nest in defaults, provide directly
229
- {action: "set_from_template", template: "...", key: "...", value: "..."}
230
-
231
- // Error: "Invalid layer"
232
- // Fix: Use one of 5 valid layers
233
- {layer: "business"} // Valid: presentation, business, data, infrastructure, cross-cutting
234
-
235
- // Error: "Invalid status"
236
- // Fix: Use one of 3 valid statuses
237
- {status: "active"} // Valid: active, deprecated, draft
238
- ```
239
-
240
- ### Best Practices for AI Agents
241
-
242
- 1. **Use `atomic: false` for batch operations** (recommended for AI agents to avoid transaction failures)
243
- 2. **Specify `layer` when setting decisions** (helps organize architectural concerns)
244
- 3. **Use `search_advanced` for complex queries** (more powerful than `list` or `search_tags`)
245
- 4. **Check `has_updates` before fetching** (95% token savings vs full data retrieval)
246
- 5. **Use templates for common patterns** (consistent metadata, enforced requirements)
247
-
248
- ### Comprehensive Guide
249
-
250
- For complete documentation with parameter matrices, search decision trees, batch operation guides, and troubleshooting:
251
-
252
- **📖 [AI Agent Guide](docs/AI_AGENT_GUIDE.md)** ← Full reference for AI agents
253
-
254
- ### Valid Enum Values
255
-
256
- **layer**: `presentation` | `business` | `data` | `infrastructure` | `cross-cutting`
257
-
258
- **status**: `active` | `deprecated` | `draft`
259
-
260
- **msg_type**: `decision` | `warning` | `request` | `info`
261
-
262
- **priority**: `low` | `medium` | `high` | `critical`
263
-
264
- **change_type**: `created` | `modified` | `deleted`
265
-
266
- **category** (constraints): `performance` | `architecture` | `security`
267
-
268
- ## MCP Tools Reference
269
-
270
- All tools use action-based routing. Call any tool with `action: "help"` for comprehensive documentation.
271
-
272
- ### 1. `decision` - Context Management
273
-
274
- Manage decisions with metadata (tags, layers, versions, scopes).
275
-
276
- **Actions:** `set`, `get`, `list`, `search_tags`, `search_layer`, `versions`, `quick_set`, `search_advanced`, `set_batch`, `has_updates`, `set_from_template`, `create_template`, `list_templates`, `help`
277
-
278
- **Examples:**
279
-
280
- ```typescript
281
- // Standard set
282
- {
283
- action: "set",
284
- key: "auth_method",
285
- value: "JWT",
286
- agent: "auth-agent",
287
- layer: "business",
288
- tags: ["authentication", "security"],
289
- version: "1.0.0"
290
- }
291
-
292
- // Quick set with smart defaults (auto-infers layer, tags)
293
- {
294
- action: "quick_set",
295
- key: "api/users/auth",
296
- value: "JWT validation updated",
297
- agent: "auth-agent"
298
- // Auto-infers: layer="presentation", tags=["api", "users", "auth"]
299
- }
300
-
301
- // Batch set (up to 50 decisions atomically)
302
- {
303
- action: "set_batch",
304
- decisions: [
305
- { key: "api_v1", value: "REST", layer: "presentation" },
306
- { key: "api_v2", value: "GraphQL", layer: "presentation" }
307
- ],
308
- atomic: true
309
- }
310
-
311
- // Check for updates (lightweight polling)
312
- {
313
- action: "has_updates",
314
- agent_name: "my-agent",
315
- since_timestamp: "2025-10-15T10:00:00Z"
316
- }
317
-
318
- // Advanced search with complex filtering
319
- {
320
- action: "search_advanced",
321
- layers: ["business", "data"],
322
- tags_all: ["security"],
323
- search_text: "authentication",
324
- status: "active",
325
- limit: 20
326
- }
327
-
328
- // Set from template
329
- {
330
- action: "set_from_template",
331
- template: "api-endpoint",
332
- key: "user_api",
333
- value: "GET /api/users"
334
- }
335
-
336
- // Get decision
337
- {
338
- action: "get",
339
- key: "auth_method"
340
- }
341
-
342
- // Get version history
343
- {
344
- action: "versions",
345
- key: "auth_method"
346
- }
347
-
348
- // Get help
349
- { action: "help" }
350
- ```
351
-
352
- ### 2. `message` - Agent Messaging
353
-
354
- Send and retrieve messages with priority levels.
355
-
356
- **Actions:** `send`, `get`, `mark_read`, `send_batch`, `help`
357
-
358
- **Examples:**
359
-
360
- ```typescript
361
- // Send message
362
- {
363
- action: "send",
364
- from_agent: "agent1",
365
- to_agent: "agent2",
366
- msg_type: "warning",
367
- message: "File locked",
368
- priority: "high",
369
- payload: { file: "/src/auth.ts" }
370
- }
371
-
372
- // Batch send (up to 50 messages)
373
- {
374
- action: "send_batch",
375
- messages: [
376
- {
377
- from_agent: "orchestrator",
378
- to_agent: "auth-agent",
379
- msg_type: "request",
380
- message: "Start setup",
381
- priority: "high"
382
- },
383
- {
384
- from_agent: "orchestrator",
385
- to_agent: "db-agent",
386
- msg_type: "request",
387
- message: "Initialize schema",
388
- priority: "high"
389
- }
390
- ]
391
- }
392
-
393
- // Get messages
394
- {
395
- action: "get",
396
- agent_name: "agent1",
397
- unread_only: true,
398
- priority_filter: "high"
399
- }
400
-
401
- // Mark as read
402
- {
403
- action: "mark_read",
404
- agent_name: "agent1",
405
- message_ids: [1, 2, 3]
406
- }
407
- ```
408
-
409
- ### 3. `file` - File Change Tracking
410
-
411
- Track file modifications with layer assignment.
412
-
413
- **Actions:** `record`, `get`, `check_lock`, `record_batch`, `help`
414
-
415
- **Examples:**
416
-
417
- ```typescript
418
- // Record file change
419
- {
420
- action: "record",
421
- file_path: "/src/auth.ts",
422
- agent_name: "auth-agent",
423
- change_type: "modified",
424
- layer: "business",
425
- description: "Updated JWT validation"
426
- }
427
-
428
- // Batch record (up to 50 file changes)
429
- {
430
- action: "record_batch",
431
- file_changes: [
432
- {
433
- file_path: "/src/auth/jwt.ts",
434
- agent_name: "auth-agent",
435
- change_type: "created",
436
- layer: "business"
437
- },
438
- {
439
- file_path: "/src/auth/validation.ts",
440
- agent_name: "auth-agent",
441
- change_type: "created",
442
- layer: "business"
443
- }
444
- ]
445
- }
446
-
447
- // Get file changes
448
- {
449
- action: "get",
450
- since: "2025-10-15T10:00:00Z",
451
- layer: "business"
452
- }
453
-
454
- // Check file lock
455
- {
456
- action: "check_lock",
457
- file_path: "/src/auth.ts",
458
- lock_duration: 300
459
- }
460
- ```
461
-
462
- ### 4. `constraint` - Constraint Management
463
-
464
- Manage architectural, performance, and security constraints.
465
-
466
- **Actions:** `add`, `get`, `deactivate`, `help`
467
-
468
- **Examples:**
469
-
470
- ```typescript
471
- // Add constraint
472
- {
473
- action: "add",
474
- category: "performance",
475
- constraint_text: "Response time < 200ms",
476
- priority: "high",
477
- layer: "business",
478
- tags: ["api", "performance"]
479
- }
480
-
481
- // Get constraints
482
- {
483
- action: "get",
484
- category: "performance",
485
- active_only: true
486
- }
487
-
488
- // Deactivate constraint
489
- {
490
- action: "deactivate",
491
- constraint_id: 42
492
- }
493
- ```
494
-
495
- ### 5. `stats` - Statistics & Utilities
496
-
497
- Get database statistics and manage data cleanup.
498
-
499
- **Actions:** `layer_summary`, `db_stats`, `clear`, `activity_log`, `help`
500
-
501
- **Examples:**
502
-
503
- ```typescript
504
- // Layer summary
505
- { action: "layer_summary" }
506
-
507
- // Database stats
508
- { action: "db_stats" }
509
-
510
- // Activity log (v2.1.0)
511
- {
512
- action: "activity_log",
513
- since: "1h",
514
- agent_names: ["auth-agent"],
515
- limit: 100
516
- }
517
-
518
- // Clear old data (weekend-aware)
519
- {
520
- action: "clear",
521
- messages_older_than_hours: 48,
522
- file_changes_older_than_days: 14
523
- }
524
- ```
525
-
526
- ### 6. `config` - Configuration
527
-
528
- Manage auto-deletion and retention settings.
529
-
530
- **Actions:** `get`, `update`, `help`
531
-
532
- **Examples:**
533
-
534
- ```typescript
535
- // Get config
536
- { action: "get" }
537
-
538
- // Update config
539
- {
540
- action: "update",
541
- ignoreWeekend: true,
542
- messageRetentionHours: 48,
543
- fileHistoryRetentionDays: 10
544
- }
545
- ```
546
-
547
- ## CLI Tool (v2.1.0)
548
-
549
- Query your database directly from terminal without MCP server.
550
-
551
- ### Available Commands
552
-
553
- ```bash
554
- # Query decisions
555
- npx sqlew-cli query decisions --layer=business --tags=breaking --output=table
556
-
557
- # Query messages
558
- npx sqlew-cli query messages --unread --priority=high --output=json
559
-
560
- # Query file changes
561
- npx sqlew-cli query files --since=1h --layer=data --output=table
562
-
563
- # Query activity log
564
- npx sqlew-cli query activity --since=5m --agent=* --output=json
565
- ```
566
-
567
- ### Common Options
568
-
569
- - `--output <format>` - Output format: `json` or `table` (default: json)
570
- - `--layer <layer>` - Filter by layer
571
- - `--tags <tags>` - Filter by tags (comma-separated)
572
- - `--since <time>` - Time filter (e.g., "5m", "1h", "2d", or ISO timestamp)
573
- - `--limit <number>` - Limit results
574
- - `--db-path <path>` - Custom database path
575
- - `--help` - Show help
576
-
577
- ## Architecture Layers
578
-
579
- sqlew organizes code by standard architecture layers:
580
-
581
- - **presentation** - UI, API endpoints, views
582
- - **business** - Business logic, services, use cases
583
- - **data** - Repositories, database access
584
- - **infrastructure** - Configuration, external services
585
- - **cross-cutting** - Logging, security, utilities
586
-
587
- ## Database Schema
588
-
589
- **Master Tables (m_ prefix):** Normalization layer (agents, files, keys, layers, tags, scopes, categories, config, templates)
590
-
591
- **Transaction Tables (t_ prefix):** Core data (decisions, history, messages, file changes, constraints, activity log)
592
-
593
- **Views (v_ prefix):** Token-efficient pre-aggregated queries
594
-
595
- **Triggers (trg_ prefix):** Automatic version history and activity logging
596
-
597
- ### Automatic Migration
598
-
599
- - **v1.x → v2.x:** Automatic migration adds table prefixes and new features
600
- - **v2.0 → v2.1:** Adds activity log and template tables
601
- - All migrations are safe with rollback protection
602
-
603
- ## Development
604
-
605
- ### Building from Source
606
-
607
- ```bash
608
- git clone https://github.com/sin5ddd/mcp-sqlew.git
609
- cd mcp-sqlew
610
- npm install
611
- npm run build
612
- ```
613
-
614
- ### Available Scripts
615
-
616
- ```bash
617
- npm start # Start MCP server
618
- npm run cli # Run CLI tool
619
- npm run inspector # Test with MCP Inspector
620
- npm run build # Build TypeScript
621
- npm run dev # Watch mode
622
- npm run rebuild # Clean and rebuild
623
- ```
624
-
625
- ## Configuration
626
-
627
- ### Retention Periods (Defaults)
628
-
629
- - **Messages:** 24 hours (weekend-aware optional)
630
- - **File Changes:** 7 days (weekend-aware optional)
631
- - **Decisions:** Permanent (version history preserved)
632
- - **Constraints:** Permanent (soft delete only)
633
-
634
- ### Weekend-Aware Cleanup
635
-
636
- When enabled, weekends (Saturday/Sunday) don't count toward retention periods:
637
-
638
- - Message sent Friday 3pm → Deleted Monday 3pm (skips weekend)
639
- - Message sent Monday 10am → Deleted Tuesday 10am
640
-
641
- Configure via CLI args or MCP tools at runtime.
642
-
643
- ## Migration Guide
644
-
645
- ### From v2.1.0 to v2.1.1
646
-
647
- No breaking changes. Only bin command configuration changed:
648
-
649
- - **Old:** `npx sqlew` → CLI, `npx sqlew-server` → MCP server
650
- - **New:** `npx sqlew` → MCP server (default), `sqlew-cli` → CLI (after installing the package)
651
-
652
- Update Claude Desktop config if using custom commands.
653
-
654
- ### From v2.0.0 to v2.1.0
655
-
656
- No breaking changes. Database migrates automatically on startup.
657
-
658
- New features are opt-in via new actions.
659
-
660
- ### From v1.x to v2.0.0
661
-
662
- Requires migration. See [MIGRATION_v2.md](MIGRATION_v2.md) for details.
663
-
664
- ## License
665
-
666
- MIT - see [LICENSE](LICENSE) file for details
667
-
668
- ## Links
669
-
670
- - [npm package](https://www.npmjs.com/package/sqlew)
671
- - [GitHub repository](https://github.com/sin5ddd/mcp-sqlew)
672
- - [Changelog](CHANGELOG.md)
673
- - [Architecture Documentation](ARCHITECTURE.md)
674
- - [Model Context Protocol](https://modelcontextprotocol.io/)
675
-
676
- ## Author
677
-
678
- **sin5ddd**
679
-
680
- ## Support
681
-
682
- - **Issues:** [GitHub Issues](https://github.com/sin5ddd/mcp-sqlew/issues)
683
- - **Documentation:** See [ARCHITECTURE.md](ARCHITECTURE.md) for technical details
684
-
685
- ## Acknowledgments
686
-
687
- Built with:
688
- - [Model Context Protocol SDK](https://github.com/modelcontextprotocol/sdk)
689
- - [better-sqlite3](https://github.com/WiseLibs/better-sqlite3)
690
- - TypeScript
1
+ # sqlew
2
+ ![sqlew_logo](assets/sqlew-logo.png)
3
+
4
+ [![npm version](https://img.shields.io/npm/v/sqlew.svg)](https://www.npmjs.com/package/sqlew)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ > **SQL Efficient Workflow** - MCP server for efficient context sharing between Claude Code sub-agents
8
+
9
+ ## What is sqlew?
10
+
11
+ **sqlew** is a Model Context Protocol (MCP) server that gives AI agents organizational memory. It solves a critical problem: **AI agents can't remember decisions across sessions**.
12
+
13
+ ### The Problem
14
+
15
+ Without sqlew:
16
+ - 🔴 Every new Claude session starts with zero context
17
+ - 🔴 Must re-explain architectural decisions every time
18
+ - 🔴 Agents can reintroduce bugs that were already fixed
19
+ - 🔴 No way to track WHY decisions were made
20
+
21
+ ### The Solution
22
+
23
+ With sqlew, AI agents can:
24
+ - ✅ **Remember** architectural decisions across sessions
25
+ - **Query** past context: "What breaking changes were made to the API?"
26
+ - ✅ **Prevent** regressions by storing constraints: "Duration must NOT occur in Loom module"
27
+ - ✅ **Coordinate** between multiple agents with messaging and task tracking
28
+
29
+ **Real-World Example:**
30
+ ```typescript
31
+ // Agent in Session 1 records:
32
+ {
33
+ key: "api_v1_deprecated",
34
+ value: "/v1/users endpoint deprecated, use /v2/users",
35
+ tags: ["api", "breaking-change"]
36
+ }
37
+
38
+ // Agent in Session 2 (days later) queries:
39
+ "What API changes should I know about?"
40
+ Finds the deprecation decision
41
+ → Uses /v2/users endpoint automatically!
42
+ ```
43
+
44
+ ## Why Use sqlew?
45
+
46
+ ### 🧠 Organizational Memory
47
+ Traditional code only tells you **WHAT** and **HOW**. sqlew adds **WHY**:
48
+ - Git history WHAT changed
49
+ - Code comments → HOW it works
50
+ - **sqlew decisions** **WHY** it was changed
51
+ - **sqlew constraints** → **WHY** it must work this way
52
+
53
+ ### ⚡ Token Efficiency
54
+ **60-75% token reduction** in multi-session projects:
55
+ - Store decisions once, query selectively
56
+ - Structured data (20-30 tokens) vs prose (50-200 tokens)
57
+ - Cross-session persistence eliminates context re-explanation
58
+
59
+ ### 🎯 Key Features
60
+ - **7 Specialized Tools**: decisions, messages, tasks, files, constraints, stats, config
61
+ - **Metadata-Driven**: Tag, layer, scope, and version everything
62
+ - **Auto-Stale Detection**: Tasks automatically transition when idle
63
+ - **Weekend-Aware Cleanup**: Smart retention that pauses during weekends
64
+ - **Batch Operations**: Process up to 50 items atomically
65
+
66
+ ### 🔖Kanban-style AI Scrum
67
+ ![kanban-style task management](assets/kanban-style.png)
68
+
69
+ ## Installation
70
+
71
+ ### Requirements
72
+ - Node.js 18.0.0 or higher
73
+ - npm or npx
74
+
75
+ ### Quick Install
76
+
77
+ ```bash
78
+ npm install sqlew
79
+ ```
80
+
81
+ ### Add to Claude Desktop
82
+
83
+ Edit `claude_desktop_config.json`:
84
+
85
+ ```json
86
+ {
87
+ "mcpServers": {
88
+ "sqlew": {
89
+ "command": "npx",
90
+ "args": ["sqlew"]
91
+ }
92
+ }
93
+ }
94
+ ```
95
+
96
+ That's it! Restart Claude Desktop and sqlew is ready.
97
+
98
+ ### Custom Database Path (Optional)
99
+
100
+ ```json
101
+ {
102
+ "mcpServers": {
103
+ "sqlew": {
104
+ "command": "npx",
105
+ "args": ["sqlew", "/path/to/database.db"]
106
+ }
107
+ }
108
+ }
109
+ ```
110
+
111
+ Default location: `.sqlew/sqlew.db` in current directory
112
+
113
+ ## Quick Start
114
+
115
+ ### For AI Agents
116
+
117
+ ⚠️ **Most Important Rule**: ALWAYS include the `action` parameter in every tool call.
118
+
119
+ ```javascript
120
+ // ❌ WRONG
121
+ {key: "auth_method", value: "jwt"}
122
+
123
+ // CORRECT
124
+ {action: "set", key: "auth_method", value: "jwt", layer: "business"}
125
+ ```
126
+
127
+ ### Basic Usage
128
+
129
+ ```javascript
130
+ // Store a decision
131
+ {
132
+ action: "set",
133
+ key: "auth_method",
134
+ value: "JWT with refresh tokens",
135
+ layer: "business",
136
+ tags: ["authentication", "security"]
137
+ }
138
+
139
+ // Query it later
140
+ {
141
+ action: "get",
142
+ key: "auth_method"
143
+ }
144
+
145
+ // Search by tags
146
+ {
147
+ action: "search_tags",
148
+ tags: ["security"],
149
+ status: "active"
150
+ }
151
+ ```
152
+
153
+ ### Available Tools
154
+
155
+ | Tool | Purpose | Example Use |
156
+ |------|---------|------------|
157
+ | **decision** | Record choices | "We chose PostgreSQL" |
158
+ | **message** | Agent communication | "Task completed" |
159
+ | **task** | Track work | "Implement feature X" |
160
+ | **file** | Track changes | "Modified auth.ts" |
161
+ | **constraint** | Define rules | "API must be <100ms" |
162
+ | **stats** | Database metrics | Get layer summary |
163
+ | **config** | Retention settings | Auto-cleanup config |
164
+
165
+ Each tool supports `action: "help"` for full documentation and `action: "example"` for comprehensive usage examples.
166
+
167
+ ## Documentation
168
+
169
+ ### On-Demand Documentation
170
+
171
+ **All tools provide built-in documentation with zero upfront token cost:**
172
+ - `action: "help"` - Detailed parameter reference, action descriptions, examples
173
+ - `action: "example"` - Comprehensive usage scenarios, workflows, best practices
174
+
175
+ **Example:**
176
+ ```javascript
177
+ // Get detailed help for decision tool
178
+ {action: "help"}
179
+
180
+ // Get comprehensive examples for task tool
181
+ {action: "example"}
182
+ ```
183
+
184
+ ### For AI Agents (68% Token Reduction)
185
+
186
+ **Tool Selection & Workflows:**
187
+ - 📖 **[Tool Selection](docs/TOOL_SELECTION.md)** - Decision tree, when to use each tool (236 lines, ~12k tokens)
188
+ - 🔄 **[Workflows](docs/WORKFLOWS.md)** - Multi-step examples, multi-agent coordination (602 lines, ~30k tokens)
189
+ - 📚 **[Tool Reference](docs/TOOL_REFERENCE.md)** - Parameters, batch operations, templates (471 lines, ~24k tokens)
190
+ - ✅ **[Best Practices](docs/BEST_PRACTICES.md)** - Common errors, troubleshooting (345 lines, ~17k tokens)
191
+
192
+ **Task System:**
193
+ - 📋 **[Task Overview](docs/TASK_OVERVIEW.md)** - Lifecycle, status transitions, auto-stale (363 lines, ~10k tokens)
194
+ - ⚙️ **[Task Actions](docs/TASK_ACTIONS.md)** - All actions with examples (854 lines, ~21k tokens)
195
+ - 🔗 **[Task Linking](docs/TASK_LINKING.md)** - Link tasks to decisions/constraints/files (729 lines, ~18k tokens)
196
+ - 🔄 **[Task Migration](docs/TASK_MIGRATION.md)** - Migrate from decision-based tracking (701 lines, ~18k tokens)
197
+
198
+ **Shared References:**
199
+ - 📘 **[Shared Concepts](docs/SHARED_CONCEPTS.md)** - Layer definitions, enum values, atomic mode (339 lines, ~17k tokens)
200
+ - 🏗️ **[Architecture](docs/ARCHITECTURE.md)** - Technical architecture and database schema
201
+
202
+ ### For Developers
203
+
204
+ - **[Building from Source](docs/ARCHITECTURE.md#development)** - Setup and build instructions
205
+ - **[Migration Guides](docs/MIGRATION_v2.md)** - Version upgrade guides
206
+ - **[CLI Tool](docs/AI_AGENT_GUIDE.md#cli-usage)** - Query database from terminal
207
+
208
+ ## Examples
209
+
210
+ ### Multi-Agent Coordination
211
+
212
+ ```javascript
213
+ // Orchestrator creates tasks
214
+ {
215
+ action: "batch_create",
216
+ tasks: [
217
+ {title: "Setup database", assigned_agent: "db-agent"},
218
+ {title: "Create API", assigned_agent: "api-agent"}
219
+ ]
220
+ }
221
+
222
+ // Agents send status updates
223
+ {
224
+ action: "send",
225
+ from_agent: "db-agent",
226
+ to_agent: "orchestrator",
227
+ message: "Database ready",
228
+ priority: "high"
229
+ }
230
+ ```
231
+
232
+ ### Breaking Change Management
233
+
234
+ ```javascript
235
+ // Record deprecation
236
+ {
237
+ action: "set",
238
+ key: "api_v1_deprecated",
239
+ value: "/v1 endpoints deprecated, use /v2",
240
+ tags: ["breaking-change", "api"]
241
+ }
242
+
243
+ // Add constraint
244
+ {
245
+ action: "add",
246
+ category: "architecture",
247
+ constraint_text: "All endpoints must use /v2 prefix",
248
+ priority: "high"
249
+ }
250
+ ```
251
+
252
+ ### Session Continuity
253
+
254
+ ```javascript
255
+ // Session 1: Save state
256
+ {
257
+ action: "set",
258
+ key: "refactor_progress",
259
+ value: "Completed 3/5 modules",
260
+ tags: ["session-state"]
261
+ }
262
+
263
+ // Session 2: Resume work
264
+ {
265
+ action: "get",
266
+ key: "refactor_progress"
267
+ }
268
+ // Returns: "Completed 3/5 modules"
269
+ ```
270
+
271
+ ## Performance
272
+
273
+ - **Query speed**: 2-50ms
274
+ - **Concurrent agents**: 5+ simultaneous
275
+ - **Storage efficiency**: ~140 bytes per decision
276
+ - **Token savings**: 60-75% in typical projects
277
+
278
+ ## Version
279
+
280
+ Current version: **3.0.0**
281
+ See [CHANGELOG.md](CHANGELOG.md) for release history.
282
+
283
+ ## License
284
+
285
+ MIT - see [LICENSE](LICENSE) file
286
+
287
+ ## Links
288
+
289
+ - [npm package](https://www.npmjs.com/package/sqlew)
290
+ - [GitHub repository](https://github.com/sin5ddd/mcp-sqlew)
291
+ - [Model Context Protocol](https://modelcontextprotocol.io/)
292
+
293
+ ## Support
294
+
295
+ - **Issues**: [GitHub Issues](https://github.com/sin5ddd/mcp-sqlew/issues)
296
+ - **Documentation**: [docs/](docs/) directory
297
+
298
+ ## Acknowledgments
299
+
300
+ Built with [Model Context Protocol SDK](https://github.com/modelcontextprotocol/sdk), [better-sqlite3](https://github.com/WiseLibs/better-sqlite3), and TypeScript.
301
+
302
+ **Author**: sin5ddd