sqlew 2.1.4 → 3.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 (97) hide show
  1. package/CHANGELOG.md +891 -605
  2. package/LICENSE +49 -18
  3. package/README.md +337 -690
  4. package/assets/kanban-style.png +0 -0
  5. package/assets/schema.sql +532 -402
  6. package/dist/database.d.ts +9 -0
  7. package/dist/database.d.ts.map +1 -1
  8. package/dist/database.js +33 -34
  9. package/dist/database.js.map +1 -1
  10. package/dist/index.js +1050 -215
  11. package/dist/index.js.map +1 -1
  12. package/dist/migrations/add-task-tables.d.ts +47 -0
  13. package/dist/migrations/add-task-tables.d.ts.map +1 -0
  14. package/dist/migrations/add-task-tables.js +285 -0
  15. package/dist/migrations/add-task-tables.js.map +1 -0
  16. package/dist/migrations/index.d.ts +96 -0
  17. package/dist/migrations/index.d.ts.map +1 -0
  18. package/dist/migrations/index.js +239 -0
  19. package/dist/migrations/index.js.map +1 -0
  20. package/dist/migrations/migrate-decisions-to-tasks.d.ts +61 -0
  21. package/dist/migrations/migrate-decisions-to-tasks.d.ts.map +1 -0
  22. package/dist/migrations/migrate-decisions-to-tasks.js +442 -0
  23. package/dist/migrations/migrate-decisions-to-tasks.js.map +1 -0
  24. package/dist/schema.d.ts.map +1 -1
  25. package/dist/schema.js +14 -3
  26. package/dist/schema.js.map +1 -1
  27. package/dist/tools/constraints.d.ts +4 -0
  28. package/dist/tools/constraints.d.ts.map +1 -1
  29. package/dist/tools/constraints.js +6 -27
  30. package/dist/tools/constraints.js.map +1 -1
  31. package/dist/tools/context.d.ts +17 -1
  32. package/dist/tools/context.d.ts.map +1 -1
  33. package/dist/tools/context.js +195 -190
  34. package/dist/tools/context.js.map +1 -1
  35. package/dist/tools/files.d.ts.map +1 -1
  36. package/dist/tools/files.js +113 -166
  37. package/dist/tools/files.js.map +1 -1
  38. package/dist/tools/messaging.d.ts +2 -9
  39. package/dist/tools/messaging.d.ts.map +1 -1
  40. package/dist/tools/messaging.js +67 -126
  41. package/dist/tools/messaging.js.map +1 -1
  42. package/dist/tools/tasks.d.ts +90 -0
  43. package/dist/tools/tasks.d.ts.map +1 -0
  44. package/dist/tools/tasks.js +844 -0
  45. package/dist/tools/tasks.js.map +1 -0
  46. package/dist/tools/utils.d.ts +8 -1
  47. package/dist/tools/utils.d.ts.map +1 -1
  48. package/dist/tools/utils.js +50 -21
  49. package/dist/tools/utils.js.map +1 -1
  50. package/dist/types.d.ts +29 -0
  51. package/dist/types.d.ts.map +1 -1
  52. package/dist/utils/batch.d.ts +69 -0
  53. package/dist/utils/batch.d.ts.map +1 -0
  54. package/dist/utils/batch.js +148 -0
  55. package/dist/utils/batch.js.map +1 -0
  56. package/dist/utils/query-builder.d.ts +68 -0
  57. package/dist/utils/query-builder.d.ts.map +1 -0
  58. package/dist/utils/query-builder.js +116 -0
  59. package/dist/utils/query-builder.js.map +1 -0
  60. package/dist/utils/task-stale-detection.d.ts +28 -0
  61. package/dist/utils/task-stale-detection.d.ts.map +1 -0
  62. package/dist/utils/task-stale-detection.js +92 -0
  63. package/dist/utils/task-stale-detection.js.map +1 -0
  64. package/dist/utils/validators.d.ts +57 -0
  65. package/dist/utils/validators.d.ts.map +1 -0
  66. package/dist/utils/validators.js +117 -0
  67. package/dist/utils/validators.js.map +1 -0
  68. package/dist/watcher/file-watcher.d.ts +75 -0
  69. package/dist/watcher/file-watcher.d.ts.map +1 -0
  70. package/dist/watcher/file-watcher.js +374 -0
  71. package/dist/watcher/file-watcher.js.map +1 -0
  72. package/dist/watcher/index.d.ts +8 -0
  73. package/dist/watcher/index.d.ts.map +1 -0
  74. package/dist/watcher/index.js +7 -0
  75. package/dist/watcher/index.js.map +1 -0
  76. package/dist/watcher/test-executor.d.ts +23 -0
  77. package/dist/watcher/test-executor.d.ts.map +1 -0
  78. package/dist/watcher/test-executor.js +226 -0
  79. package/dist/watcher/test-executor.js.map +1 -0
  80. package/docs/ACCEPTANCE_CRITERIA.md +625 -0
  81. package/docs/AI_AGENT_GUIDE.md +1471 -648
  82. package/{ARCHITECTURE.md → docs/ARCHITECTURE.md} +636 -636
  83. package/docs/AUTO_FILE_TRACKING.md +436 -0
  84. package/docs/BEST_PRACTICES.md +481 -0
  85. package/docs/DECISION_TO_TASK_MIGRATION_GUIDE.md +457 -0
  86. package/docs/MIGRATION_CHAIN.md +280 -0
  87. package/{MIGRATION_v2.md → docs/MIGRATION_v2.md} +538 -538
  88. package/docs/SHARED_CONCEPTS.md +339 -0
  89. package/docs/TASK_ACTIONS.md +854 -0
  90. package/docs/TASK_LINKING.md +729 -0
  91. package/docs/TASK_MIGRATION.md +701 -0
  92. package/docs/TASK_OVERVIEW.md +363 -0
  93. package/docs/TASK_SYSTEM.md +1244 -0
  94. package/docs/TOOL_REFERENCE.md +471 -0
  95. package/docs/TOOL_SELECTION.md +279 -0
  96. package/docs/WORKFLOWS.md +602 -0
  97. package/package.json +65 -64
package/README.md CHANGED
@@ -1,690 +1,337 @@
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: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
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-File Tracking** (v3.0.2): Zero-token task management via automatic file watching
63
+ - Auto-transition: `todo` `in_progress` on file edit
64
+ - Auto-complete: `in_progress` `done` when acceptance criteria pass
65
+ - 97% token reduction (4,650 tokens saved per 6-task session)
66
+ - **Auto-Stale Detection**: Tasks automatically transition when idle
67
+ - **Weekend-Aware Cleanup**: Smart retention that pauses during weekends
68
+ - **Batch Operations**: Process up to 50 items atomically
69
+
70
+ ### 🔖Kanban-style AI Scrum
71
+ ![kanban-style task management](assets/kanban-style.png)
72
+
73
+ ## Installation
74
+
75
+ ### Requirements
76
+ - Node.js 18.0.0 or higher
77
+ - npm or npx
78
+
79
+ ### Quick Install
80
+
81
+ ```bash
82
+ npm install sqlew
83
+ ```
84
+
85
+ ### Add to Claude Desktop
86
+
87
+ Edit `claude_desktop_config.json`:
88
+
89
+ ```json
90
+ {
91
+ "mcpServers": {
92
+ "sqlew": {
93
+ "command": "npx",
94
+ "args": ["sqlew"]
95
+ }
96
+ }
97
+ }
98
+ ```
99
+
100
+ That's it! Restart Claude Desktop and sqlew is ready.
101
+
102
+ ### Custom Database Path (Optional)
103
+
104
+ ```json
105
+ {
106
+ "mcpServers": {
107
+ "sqlew": {
108
+ "command": "npx",
109
+ "args": ["sqlew", "/path/to/database.db"]
110
+ }
111
+ }
112
+ }
113
+ ```
114
+
115
+ Default location: `.sqlew/sqlew.db` in current directory
116
+
117
+ ## Quick Start
118
+
119
+ ### For AI Agents
120
+
121
+ ⚠️ **Most Important Rule**: ALWAYS include the `action` parameter in every tool call.
122
+
123
+ ```javascript
124
+ // WRONG
125
+ {key: "auth_method", value: "jwt"}
126
+
127
+ // ✅ CORRECT
128
+ {action: "set", key: "auth_method", value: "jwt", layer: "business"}
129
+ ```
130
+
131
+ ### Basic Usage
132
+
133
+ ```javascript
134
+ // Store a decision
135
+ {
136
+ action: "set",
137
+ key: "auth_method",
138
+ value: "JWT with refresh tokens",
139
+ layer: "business",
140
+ tags: ["authentication", "security"]
141
+ }
142
+
143
+ // Query it later
144
+ {
145
+ action: "get",
146
+ key: "auth_method"
147
+ }
148
+
149
+ // Search by tags
150
+ {
151
+ action: "search_tags",
152
+ tags: ["security"],
153
+ status: "active"
154
+ }
155
+ ```
156
+
157
+ ### Available Tools
158
+
159
+ | Tool | Purpose | Example Use |
160
+ |------|---------|------------|
161
+ | **decision** | Record choices | "We chose PostgreSQL" |
162
+ | **message** | Agent communication | "Task completed" |
163
+ | **task** | Track work | "Implement feature X" |
164
+ | **file** | Track changes | "Modified auth.ts" |
165
+ | **constraint** | Define rules | "API must be <100ms" |
166
+ | **stats** | Database metrics | Get layer summary |
167
+ | **config** | Retention settings | Auto-cleanup config |
168
+
169
+ Each tool supports `action: "help"` for full documentation and `action: "example"` for comprehensive usage examples.
170
+
171
+ ## Documentation
172
+
173
+ ### On-Demand Documentation
174
+
175
+ **All tools provide built-in documentation with zero upfront token cost:**
176
+ - `action: "help"` - Detailed parameter reference, action descriptions, examples
177
+ - `action: "example"` - Comprehensive usage scenarios, workflows, best practices
178
+
179
+ **Example:**
180
+ ```javascript
181
+ // Get detailed help for decision tool
182
+ {action: "help"}
183
+
184
+ // Get comprehensive examples for task tool
185
+ {action: "example"}
186
+ ```
187
+
188
+ ### For AI Agents (68% Token Reduction)
189
+
190
+ **Tool Selection & Workflows:**
191
+ - 📖 **[Tool Selection](docs/TOOL_SELECTION.md)** - Decision tree, when to use each tool (236 lines, ~12k tokens)
192
+ - 🔄 **[Workflows](docs/WORKFLOWS.md)** - Multi-step examples, multi-agent coordination (602 lines, ~30k tokens)
193
+ - 📚 **[Tool Reference](docs/TOOL_REFERENCE.md)** - Parameters, batch operations, templates (471 lines, ~24k tokens)
194
+ - ✅ **[Best Practices](docs/BEST_PRACTICES.md)** - Common errors, troubleshooting (345 lines, ~17k tokens)
195
+
196
+ **Task System:**
197
+ - 📋 **[Task Overview](docs/TASK_OVERVIEW.md)** - Lifecycle, status transitions, auto-stale (363 lines, ~10k tokens)
198
+ - ⚙️ **[Task Actions](docs/TASK_ACTIONS.md)** - All actions with examples (854 lines, ~21k tokens)
199
+ - 🔗 **[Task Linking](docs/TASK_LINKING.md)** - Link tasks to decisions/constraints/files (729 lines, ~18k tokens)
200
+ - 🔄 **[Task Migration](docs/TASK_MIGRATION.md)** - Migrate from decision-based tracking (701 lines, ~18k tokens)
201
+
202
+ **Auto File Tracking (v3.0.2):**
203
+ - 🤖 **[Auto File Tracking](docs/AUTO_FILE_TRACKING.md)** - Zero-token task management, setup, troubleshooting
204
+ - **[Acceptance Criteria](docs/ACCEPTANCE_CRITERIA.md)** - All check types (tests_pass, code_removed, code_contains, file_exists)
205
+
206
+ **Shared References:**
207
+ - 📘 **[Shared Concepts](docs/SHARED_CONCEPTS.md)** - Layer definitions, enum values, atomic mode (339 lines, ~17k tokens)
208
+ - 🏗️ **[Architecture](docs/ARCHITECTURE.md)** - Technical architecture and database schema
209
+
210
+ ### For Developers
211
+
212
+ - **[Building from Source](docs/ARCHITECTURE.md#development)** - Setup and build instructions
213
+ - **[Migration Guides](docs/MIGRATION_v2.md)** - Version upgrade guides
214
+ - **[CLI Tool](docs/AI_AGENT_GUIDE.md#cli-usage)** - Query database from terminal
215
+
216
+ ## Examples
217
+
218
+ ### Multi-Agent Coordination
219
+
220
+ ```javascript
221
+ // Orchestrator creates tasks
222
+ {
223
+ action: "batch_create",
224
+ tasks: [
225
+ {title: "Setup database", assigned_agent: "db-agent"},
226
+ {title: "Create API", assigned_agent: "api-agent"}
227
+ ]
228
+ }
229
+
230
+ // Agents send status updates
231
+ {
232
+ action: "send",
233
+ from_agent: "db-agent",
234
+ to_agent: "orchestrator",
235
+ message: "Database ready",
236
+ priority: "high"
237
+ }
238
+ ```
239
+
240
+ ### Breaking Change Management
241
+
242
+ ```javascript
243
+ // Record deprecation
244
+ {
245
+ action: "set",
246
+ key: "api_v1_deprecated",
247
+ value: "/v1 endpoints deprecated, use /v2",
248
+ tags: ["breaking-change", "api"]
249
+ }
250
+
251
+ // Add constraint
252
+ {
253
+ action: "add",
254
+ category: "architecture",
255
+ constraint_text: "All endpoints must use /v2 prefix",
256
+ priority: "high"
257
+ }
258
+ ```
259
+
260
+ ### Session Continuity
261
+
262
+ ```javascript
263
+ // Session 1: Save state
264
+ {
265
+ action: "set",
266
+ key: "refactor_progress",
267
+ value: "Completed 3/5 modules",
268
+ tags: ["session-state"]
269
+ }
270
+
271
+ // Session 2: Resume work
272
+ {
273
+ action: "get",
274
+ key: "refactor_progress"
275
+ }
276
+ // Returns: "Completed 3/5 modules"
277
+ ```
278
+
279
+ ## Performance
280
+
281
+ - **Query speed**: 2-50ms
282
+ - **Concurrent agents**: 5+ simultaneous
283
+ - **Storage efficiency**: ~140 bytes per decision
284
+ - **Token savings**: 60-75% in typical projects
285
+
286
+ ## 💖 Support sqlew
287
+
288
+ ### One-time Support
289
+ Perfect for trying out sponsorship!
290
+ - ☕ $5 - Buy me a coffee
291
+ - 🍕 $10 - Buy me a pizza
292
+
293
+ ### Monthly Support
294
+ For ongoing development support:
295
+ - ⭐ $1/month - Support Continual Development
296
+ - 🚀 $5/month - Active support for Request
297
+ - 💼 $10/month - Buy me more AI tokens
298
+
299
+ on [GitHub Sponsors](https://github.com/sponsors/sin5ddd)
300
+
301
+ ## Version
302
+
303
+ Current version: **3.0.0**
304
+ See [CHANGELOG.md](CHANGELOG.md) for release history.
305
+
306
+ ## License
307
+
308
+ AGPLv3 - **Free to use**, open-source required when embedding/modifying.
309
+
310
+ See [LICENSE](LICENSE) file for details.
311
+
312
+ **Free to use for:**
313
+ - Personal and commercial projects
314
+ - Using sqlew as-is in Claude Desktop
315
+ - Managing AI agent context
316
+
317
+ **Open-source required when:**
318
+ - Embedding sqlew into your application
319
+ - Modifying and distributing sqlew
320
+ - Offering sqlew as a network service
321
+
322
+ ## Links
323
+
324
+ - [npm package](https://www.npmjs.com/package/sqlew)
325
+ - [GitHub repository](https://github.com/sin5ddd/mcp-sqlew)
326
+ - [Model Context Protocol](https://modelcontextprotocol.io/)
327
+
328
+ ## Support
329
+
330
+ - **Issues**: [GitHub Issues](https://github.com/sin5ddd/mcp-sqlew/issues)
331
+ - **Documentation**: [docs/](docs/) directory
332
+
333
+ ## Acknowledgments
334
+
335
+ Built with [Model Context Protocol SDK](https://github.com/modelcontextprotocol/sdk), [better-sqlite3](https://github.com/WiseLibs/better-sqlite3), and TypeScript.
336
+
337
+ **Author**: sin5ddd