sqlew 2.1.3 → 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 -535
  2. package/README.md +302 -613
  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 -21
  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 -0
  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 -63
package/README.md CHANGED
@@ -1,613 +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
- ## MCP Tools Reference
192
-
193
- All tools use action-based routing. Call any tool with `action: "help"` for comprehensive documentation.
194
-
195
- ### 1. `decision` - Context Management
196
-
197
- Manage decisions with metadata (tags, layers, versions, scopes).
198
-
199
- **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`
200
-
201
- **Examples:**
202
-
203
- ```typescript
204
- // Standard set
205
- {
206
- action: "set",
207
- key: "auth_method",
208
- value: "JWT",
209
- agent: "auth-agent",
210
- layer: "business",
211
- tags: ["authentication", "security"],
212
- version: "1.0.0"
213
- }
214
-
215
- // Quick set with smart defaults (auto-infers layer, tags)
216
- {
217
- action: "quick_set",
218
- key: "api/users/auth",
219
- value: "JWT validation updated",
220
- agent: "auth-agent"
221
- // Auto-infers: layer="presentation", tags=["api", "users", "auth"]
222
- }
223
-
224
- // Batch set (up to 50 decisions atomically)
225
- {
226
- action: "set_batch",
227
- decisions: [
228
- { key: "api_v1", value: "REST", layer: "presentation" },
229
- { key: "api_v2", value: "GraphQL", layer: "presentation" }
230
- ],
231
- atomic: true
232
- }
233
-
234
- // Check for updates (lightweight polling)
235
- {
236
- action: "has_updates",
237
- agent_name: "my-agent",
238
- since_timestamp: "2025-10-15T10:00:00Z"
239
- }
240
-
241
- // Advanced search with complex filtering
242
- {
243
- action: "search_advanced",
244
- layers: ["business", "data"],
245
- tags_all: ["security"],
246
- search_text: "authentication",
247
- status: "active",
248
- limit: 20
249
- }
250
-
251
- // Set from template
252
- {
253
- action: "set_from_template",
254
- template: "api-endpoint",
255
- key: "user_api",
256
- value: "GET /api/users"
257
- }
258
-
259
- // Get decision
260
- {
261
- action: "get",
262
- key: "auth_method"
263
- }
264
-
265
- // Get version history
266
- {
267
- action: "versions",
268
- key: "auth_method"
269
- }
270
-
271
- // Get help
272
- { action: "help" }
273
- ```
274
-
275
- ### 2. `message` - Agent Messaging
276
-
277
- Send and retrieve messages with priority levels.
278
-
279
- **Actions:** `send`, `get`, `mark_read`, `send_batch`, `help`
280
-
281
- **Examples:**
282
-
283
- ```typescript
284
- // Send message
285
- {
286
- action: "send",
287
- from_agent: "agent1",
288
- to_agent: "agent2",
289
- msg_type: "warning",
290
- message: "File locked",
291
- priority: "high",
292
- payload: { file: "/src/auth.ts" }
293
- }
294
-
295
- // Batch send (up to 50 messages)
296
- {
297
- action: "send_batch",
298
- messages: [
299
- {
300
- from_agent: "orchestrator",
301
- to_agent: "auth-agent",
302
- msg_type: "request",
303
- message: "Start setup",
304
- priority: "high"
305
- },
306
- {
307
- from_agent: "orchestrator",
308
- to_agent: "db-agent",
309
- msg_type: "request",
310
- message: "Initialize schema",
311
- priority: "high"
312
- }
313
- ]
314
- }
315
-
316
- // Get messages
317
- {
318
- action: "get",
319
- agent_name: "agent1",
320
- unread_only: true,
321
- priority_filter: "high"
322
- }
323
-
324
- // Mark as read
325
- {
326
- action: "mark_read",
327
- agent_name: "agent1",
328
- message_ids: [1, 2, 3]
329
- }
330
- ```
331
-
332
- ### 3. `file` - File Change Tracking
333
-
334
- Track file modifications with layer assignment.
335
-
336
- **Actions:** `record`, `get`, `check_lock`, `record_batch`, `help`
337
-
338
- **Examples:**
339
-
340
- ```typescript
341
- // Record file change
342
- {
343
- action: "record",
344
- file_path: "/src/auth.ts",
345
- agent_name: "auth-agent",
346
- change_type: "modified",
347
- layer: "business",
348
- description: "Updated JWT validation"
349
- }
350
-
351
- // Batch record (up to 50 file changes)
352
- {
353
- action: "record_batch",
354
- file_changes: [
355
- {
356
- file_path: "/src/auth/jwt.ts",
357
- agent_name: "auth-agent",
358
- change_type: "created",
359
- layer: "business"
360
- },
361
- {
362
- file_path: "/src/auth/validation.ts",
363
- agent_name: "auth-agent",
364
- change_type: "created",
365
- layer: "business"
366
- }
367
- ]
368
- }
369
-
370
- // Get file changes
371
- {
372
- action: "get",
373
- since: "2025-10-15T10:00:00Z",
374
- layer: "business"
375
- }
376
-
377
- // Check file lock
378
- {
379
- action: "check_lock",
380
- file_path: "/src/auth.ts",
381
- lock_duration: 300
382
- }
383
- ```
384
-
385
- ### 4. `constraint` - Constraint Management
386
-
387
- Manage architectural, performance, and security constraints.
388
-
389
- **Actions:** `add`, `get`, `deactivate`, `help`
390
-
391
- **Examples:**
392
-
393
- ```typescript
394
- // Add constraint
395
- {
396
- action: "add",
397
- category: "performance",
398
- constraint_text: "Response time < 200ms",
399
- priority: "high",
400
- layer: "business",
401
- tags: ["api", "performance"]
402
- }
403
-
404
- // Get constraints
405
- {
406
- action: "get",
407
- category: "performance",
408
- active_only: true
409
- }
410
-
411
- // Deactivate constraint
412
- {
413
- action: "deactivate",
414
- constraint_id: 42
415
- }
416
- ```
417
-
418
- ### 5. `stats` - Statistics & Utilities
419
-
420
- Get database statistics and manage data cleanup.
421
-
422
- **Actions:** `layer_summary`, `db_stats`, `clear`, `activity_log`, `help`
423
-
424
- **Examples:**
425
-
426
- ```typescript
427
- // Layer summary
428
- { action: "layer_summary" }
429
-
430
- // Database stats
431
- { action: "db_stats" }
432
-
433
- // Activity log (v2.1.0)
434
- {
435
- action: "activity_log",
436
- since: "1h",
437
- agent_names: ["auth-agent"],
438
- limit: 100
439
- }
440
-
441
- // Clear old data (weekend-aware)
442
- {
443
- action: "clear",
444
- messages_older_than_hours: 48,
445
- file_changes_older_than_days: 14
446
- }
447
- ```
448
-
449
- ### 6. `config` - Configuration
450
-
451
- Manage auto-deletion and retention settings.
452
-
453
- **Actions:** `get`, `update`, `help`
454
-
455
- **Examples:**
456
-
457
- ```typescript
458
- // Get config
459
- { action: "get" }
460
-
461
- // Update config
462
- {
463
- action: "update",
464
- ignoreWeekend: true,
465
- messageRetentionHours: 48,
466
- fileHistoryRetentionDays: 10
467
- }
468
- ```
469
-
470
- ## CLI Tool (v2.1.0)
471
-
472
- Query your database directly from terminal without MCP server.
473
-
474
- ### Available Commands
475
-
476
- ```bash
477
- # Query decisions
478
- npx sqlew-cli query decisions --layer=business --tags=breaking --output=table
479
-
480
- # Query messages
481
- npx sqlew-cli query messages --unread --priority=high --output=json
482
-
483
- # Query file changes
484
- npx sqlew-cli query files --since=1h --layer=data --output=table
485
-
486
- # Query activity log
487
- npx sqlew-cli query activity --since=5m --agent=* --output=json
488
- ```
489
-
490
- ### Common Options
491
-
492
- - `--output <format>` - Output format: `json` or `table` (default: json)
493
- - `--layer <layer>` - Filter by layer
494
- - `--tags <tags>` - Filter by tags (comma-separated)
495
- - `--since <time>` - Time filter (e.g., "5m", "1h", "2d", or ISO timestamp)
496
- - `--limit <number>` - Limit results
497
- - `--db-path <path>` - Custom database path
498
- - `--help` - Show help
499
-
500
- ## Architecture Layers
501
-
502
- sqlew organizes code by standard architecture layers:
503
-
504
- - **presentation** - UI, API endpoints, views
505
- - **business** - Business logic, services, use cases
506
- - **data** - Repositories, database access
507
- - **infrastructure** - Configuration, external services
508
- - **cross-cutting** - Logging, security, utilities
509
-
510
- ## Database Schema
511
-
512
- **Master Tables (m_ prefix):** Normalization layer (agents, files, keys, layers, tags, scopes, categories, config, templates)
513
-
514
- **Transaction Tables (t_ prefix):** Core data (decisions, history, messages, file changes, constraints, activity log)
515
-
516
- **Views (v_ prefix):** Token-efficient pre-aggregated queries
517
-
518
- **Triggers (trg_ prefix):** Automatic version history and activity logging
519
-
520
- ### Automatic Migration
521
-
522
- - **v1.x → v2.x:** Automatic migration adds table prefixes and new features
523
- - **v2.0 → v2.1:** Adds activity log and template tables
524
- - All migrations are safe with rollback protection
525
-
526
- ## Development
527
-
528
- ### Building from Source
529
-
530
- ```bash
531
- git clone https://github.com/sin5ddd/mcp-sqlew.git
532
- cd mcp-sqlew
533
- npm install
534
- npm run build
535
- ```
536
-
537
- ### Available Scripts
538
-
539
- ```bash
540
- npm start # Start MCP server
541
- npm run cli # Run CLI tool
542
- npm run inspector # Test with MCP Inspector
543
- npm run build # Build TypeScript
544
- npm run dev # Watch mode
545
- npm run rebuild # Clean and rebuild
546
- ```
547
-
548
- ## Configuration
549
-
550
- ### Retention Periods (Defaults)
551
-
552
- - **Messages:** 24 hours (weekend-aware optional)
553
- - **File Changes:** 7 days (weekend-aware optional)
554
- - **Decisions:** Permanent (version history preserved)
555
- - **Constraints:** Permanent (soft delete only)
556
-
557
- ### Weekend-Aware Cleanup
558
-
559
- When enabled, weekends (Saturday/Sunday) don't count toward retention periods:
560
-
561
- - Message sent Friday 3pm → Deleted Monday 3pm (skips weekend)
562
- - Message sent Monday 10am → Deleted Tuesday 10am
563
-
564
- Configure via CLI args or MCP tools at runtime.
565
-
566
- ## Migration Guide
567
-
568
- ### From v2.1.0 to v2.1.1
569
-
570
- No breaking changes. Only bin command configuration changed:
571
-
572
- - **Old:** `npx sqlew` → CLI, `npx sqlew-server` → MCP server
573
- - **New:** `npx sqlew` → MCP server (default), `sqlew-cli` → CLI (after installing the package)
574
-
575
- Update Claude Desktop config if using custom commands.
576
-
577
- ### From v2.0.0 to v2.1.0
578
-
579
- No breaking changes. Database migrates automatically on startup.
580
-
581
- New features are opt-in via new actions.
582
-
583
- ### From v1.x to v2.0.0
584
-
585
- Requires migration. See [MIGRATION_v2.md](MIGRATION_v2.md) for details.
586
-
587
- ## License
588
-
589
- MIT - see [LICENSE](LICENSE) file for details
590
-
591
- ## Links
592
-
593
- - [npm package](https://www.npmjs.com/package/sqlew)
594
- - [GitHub repository](https://github.com/sin5ddd/mcp-sqlew)
595
- - [Changelog](CHANGELOG.md)
596
- - [Architecture Documentation](ARCHITECTURE.md)
597
- - [Model Context Protocol](https://modelcontextprotocol.io/)
598
-
599
- ## Author
600
-
601
- **sin5ddd**
602
-
603
- ## Support
604
-
605
- - **Issues:** [GitHub Issues](https://github.com/sin5ddd/mcp-sqlew/issues)
606
- - **Documentation:** See [ARCHITECTURE.md](ARCHITECTURE.md) for technical details
607
-
608
- ## Acknowledgments
609
-
610
- Built with:
611
- - [Model Context Protocol SDK](https://github.com/modelcontextprotocol/sdk)
612
- - [better-sqlite3](https://github.com/WiseLibs/better-sqlite3)
613
- - 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