sqlew 1.1.2 → 2.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 (43) hide show
  1. package/CHANGELOG.md +259 -0
  2. package/MIGRATION_v2.md +538 -0
  3. package/README.md +444 -79
  4. package/assets/schema.sql +122 -36
  5. package/dist/cli.d.ts +7 -0
  6. package/dist/cli.d.ts.map +1 -0
  7. package/dist/cli.js +312 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/database.d.ts.map +1 -1
  10. package/dist/database.js +18 -0
  11. package/dist/database.js.map +1 -1
  12. package/dist/index.js +373 -707
  13. package/dist/index.js.map +1 -1
  14. package/dist/migrations/add-v2.1.0-features.d.ts +29 -0
  15. package/dist/migrations/add-v2.1.0-features.d.ts.map +1 -0
  16. package/dist/migrations/add-v2.1.0-features.js +198 -0
  17. package/dist/migrations/add-v2.1.0-features.js.map +1 -0
  18. package/dist/schema.d.ts.map +1 -1
  19. package/dist/schema.js +5 -0
  20. package/dist/schema.js.map +1 -1
  21. package/dist/tools/context.d.ts +91 -1
  22. package/dist/tools/context.d.ts.map +1 -1
  23. package/dist/tools/context.js +614 -0
  24. package/dist/tools/context.js.map +1 -1
  25. package/dist/tools/files.d.ts +10 -1
  26. package/dist/tools/files.d.ts.map +1 -1
  27. package/dist/tools/files.js +98 -1
  28. package/dist/tools/files.js.map +1 -1
  29. package/dist/tools/messaging.d.ts +10 -1
  30. package/dist/tools/messaging.d.ts.map +1 -1
  31. package/dist/tools/messaging.js +107 -1
  32. package/dist/tools/messaging.js.map +1 -1
  33. package/dist/tools/utils.d.ts +9 -1
  34. package/dist/tools/utils.d.ts.map +1 -1
  35. package/dist/tools/utils.js +115 -0
  36. package/dist/tools/utils.js.map +1 -1
  37. package/dist/types.d.ts +196 -0
  38. package/dist/types.d.ts.map +1 -1
  39. package/dist/utils/cleanup.d.ts +12 -1
  40. package/dist/utils/cleanup.d.ts.map +1 -1
  41. package/dist/utils/cleanup.js +20 -3
  42. package/dist/utils/cleanup.js.map +1 -1
  43. package/package.json +6 -3
package/CHANGELOG.md CHANGED
@@ -5,6 +5,263 @@ All notable changes to sqlew will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.1.0] - 2025-10-14
9
+
10
+ ### 🎉 Feature Release
11
+
12
+ **Major enhancement release implementing 7 feature requests from real-world usage in the Trackne Server project. Adds activity logging, smart defaults, subscriptions, advanced querying, batch operations, templates, and a standalone CLI tool.**
13
+
14
+ ### Added
15
+
16
+ #### FR-001: Activity Log System
17
+ - **Automatic Activity Logging:** All decision changes, messages, and file modifications are now automatically logged
18
+ - New `t_activity_log` table with 3 optimized indexes
19
+ - 4 triggers for automatic logging:
20
+ - `trg_log_decision_insert` - Logs decision creation
21
+ - `trg_log_decision_update` - Logs decision modifications
22
+ - `trg_log_message_insert` - Logs message sending
23
+ - `trg_log_file_change_insert` - Logs file changes
24
+ - `getActivityLog` action in `stats` tool for retrieving filtered logs
25
+ - Filter by agent, entity type, action type, and time range
26
+ - Token-efficient logging (~50 bytes per log entry)
27
+
28
+ #### FR-002: Smart Defaults
29
+ - **quickSetDecision:** Streamlined decision setting with automatic layer inference
30
+ - Infers layer from key patterns (e.g., "auth_*" → infrastructure)
31
+ - Auto-extracts tags from key and value (e.g., "jwt_config" → ["jwt", "config"])
32
+ - Reduces token usage by ~60% for simple decisions
33
+ - Falls back to manual tagging when inference is ambiguous
34
+ - New `quick_set` action in `decision` tool
35
+
36
+ #### FR-003: Lightweight Subscriptions
37
+ - **hasUpdates Polling:** Efficient change detection for agents
38
+ - Check for updates since last check (~5-10 tokens per call)
39
+ - Filter by entity type (decisions, messages, files)
40
+ - Filter by scope, layer, or agent
41
+ - Returns boolean + count + latest timestamp
42
+ - New `has_updates` action in `decision` tool
43
+ - 95% token reduction vs full list queries
44
+
45
+ #### FR-004: Advanced Query System
46
+ - **searchAdvanced:** Comprehensive search across all decision metadata
47
+ - 13 query parameters: keys, tags, scopes, layers, status, versions, full-text search
48
+ - Pagination support (limit, offset)
49
+ - Sort by multiple fields with direction control
50
+ - Full-text search in keys and values
51
+ - Scope inheritance (search within parent scopes)
52
+ - New `search_advanced` action in `decision` tool
53
+ - Replaces multiple sequential queries with single call
54
+
55
+ #### FR-005: Batch Operations
56
+ - **Atomic Batch Processing:** Process multiple operations in a single transaction
57
+ - `setDecisionBatch` - Set up to 50 decisions atomically
58
+ - `sendMessageBatch` - Send multiple messages in one transaction
59
+ - `recordFileChangeBatch` - Record multiple file changes atomically
60
+ - All-or-nothing guarantee (rollback on any failure)
61
+ - ~70% token reduction vs sequential calls
62
+ - New actions: `set_batch` (decision), `send_batch` (message), `record_batch` (file)
63
+
64
+ #### FR-006: Template System
65
+ - **Decision Templates:** Reusable decision patterns with validation
66
+ - 5 built-in templates: auth_config, api_endpoint, db_schema, ui_component, feature_flag
67
+ - `createTemplate` - Define custom templates with field schemas
68
+ - `setFromTemplate` - Create decisions from templates with validation
69
+ - `listTemplates` - Browse available templates
70
+ - Template inheritance and composition support
71
+ - New `t_decision_templates` table
72
+ - New actions: `set_from_template`, `create_template`, `list_templates` (decision tool)
73
+
74
+ #### FR-007: Standalone CLI Query Tool
75
+ - **Command-Line Interface:** Query MCP database without starting MCP server
76
+ - 4 commands: `decisions`, `messages`, `files`, `activity`
77
+ - JSON and table output formats
78
+ - Filter options match MCP tool parameters
79
+ - Supports all query patterns from MCP tools
80
+ - Zero MCP token impact (standalone binary)
81
+ - New script: `src/cli.ts`
82
+ - Usage: `node dist/cli.js decisions --scope=auth --format=table`
83
+
84
+ ### Changed
85
+
86
+ - **Tool Definitions:** Added 11 new actions across 3 tools
87
+ - `decision` tool: 7 → 11 actions (+4: quick_set, has_updates, search_advanced, set_batch, set_from_template, create_template, list_templates)
88
+ - `message` tool: 4 → 5 actions (+1: send_batch)
89
+ - `file` tool: 4 → 5 actions (+1: record_batch)
90
+ - `stats` tool: 4 → 5 actions (+1: getActivityLog)
91
+ - **Database Schema:** v2.1.0 migration adds 2 tables and 4 triggers
92
+ - **Token Efficiency:** Maintains 92% efficiency vs v1.0.0 original design
93
+ - Tool definitions: 481 → 1,031 tokens (+550 tokens for 11 new actions)
94
+ - CLI has zero MCP token impact (standalone)
95
+ - Batch operations save ~70% tokens vs sequential calls
96
+ - hasUpdates saves ~95% tokens vs full list queries
97
+
98
+ ### Technical Details
99
+
100
+ #### Database Changes
101
+ - **New Tables:**
102
+ - `t_activity_log` - Automatic logging of all changes (agent_id, entity_type, entity_id, action_type, details, ts)
103
+ - `t_decision_templates` - Template definitions (name, description, schema, layer, tags, created_by, created_at)
104
+ - **New Indexes:**
105
+ - `idx_activity_log_agent_ts` - Agent-based log queries
106
+ - `idx_activity_log_entity_ts` - Entity-based log queries
107
+ - `idx_activity_log_ts` - Time-based log queries
108
+ - **New Triggers:**
109
+ - `trg_log_decision_insert`, `trg_log_decision_update` - Decision logging
110
+ - `trg_log_message_insert` - Message logging
111
+ - `trg_log_file_change_insert` - File change logging
112
+
113
+ #### Migration
114
+ - **Migration Script:** `src/migrations/add-v2.1.0-features.ts`
115
+ - Creates `t_activity_log` and `t_decision_templates` tables
116
+ - Creates 3 indexes for activity log queries
117
+ - Creates 4 triggers for automatic logging
118
+ - Seeds 5 built-in templates
119
+ - Transaction-based with rollback on failure
120
+ - Automatic execution on startup
121
+ - Backward compatible with v2.0.0 databases
122
+
123
+ #### Performance
124
+ - **Token Efficiency:**
125
+ - Batch operations: ~70% reduction vs sequential (3 operations: 1,200 → 360 tokens)
126
+ - hasUpdates polling: ~95% reduction vs full list (500 → 25 tokens)
127
+ - quickSetDecision: ~60% reduction vs manual (250 → 100 tokens)
128
+ - Templates: ~50% reduction for repeated patterns
129
+ - **Query Performance:**
130
+ - Activity log queries: 5-15ms (with indexes)
131
+ - Advanced search: 10-30ms (with full-text)
132
+ - Batch operations: 20-50ms (atomic transaction)
133
+ - Template operations: 5-10ms
134
+
135
+ #### Code Statistics
136
+ - **Source Changes:**
137
+ - New files: `src/cli.ts`, `src/migrations/add-v2.1.0-features.ts`
138
+ - Modified: `src/tools/context.ts`, `src/tools/messaging.ts`, `src/tools/files.ts`, `src/tools/utils.ts`
139
+ - Total lines added: ~1,500 lines
140
+ - **CLI Tool:**
141
+ - Standalone binary (~300 lines)
142
+ - Zero dependencies on MCP server
143
+ - Supports all common query patterns
144
+
145
+ ### Real-World Impact
146
+
147
+ These features were requested during development of the **Trackne Server** project:
148
+ - **Activity Log:** Essential for debugging multi-agent coordination
149
+ - **Smart Defaults:** Reduced boilerplate by 60% for common decisions
150
+ - **Subscriptions:** Enabled efficient polling without full list queries
151
+ - **Advanced Query:** Replaced 5-10 sequential queries with single calls
152
+ - **Batch Operations:** Critical for atomic state updates across agents
153
+ - **Templates:** Standardized patterns across 15+ API endpoints
154
+ - **CLI Tool:** Enabled quick debugging without starting MCP server
155
+
156
+ ### Migration from v2.0.0
157
+
158
+ No breaking changes. All v2.0.0 tool calls work unchanged. New features are opt-in:
159
+
160
+ ```javascript
161
+ // NEW: Quick decision setting with smart defaults
162
+ await callTool('decision', { action: 'quick_set', key: 'jwt_config', value: 'HS256' });
163
+ // Auto-infers layer=infrastructure, tags=["jwt", "config"]
164
+
165
+ // NEW: Check for updates efficiently
166
+ await callTool('decision', { action: 'has_updates', since: '2025-10-14T10:00:00Z' });
167
+ // Returns: { hasUpdates: true, count: 5, latestTimestamp: '...' }
168
+
169
+ // NEW: Batch operations (atomic)
170
+ await callTool('decision', {
171
+ action: 'set_batch',
172
+ decisions: [
173
+ { key: 'auth', value: 'jwt' },
174
+ { key: 'db', value: 'postgres' }
175
+ ]
176
+ });
177
+
178
+ // NEW: Use templates
179
+ await callTool('decision', {
180
+ action: 'set_from_template',
181
+ template_name: 'api_endpoint',
182
+ key: 'users_api',
183
+ values: { path: '/api/users', method: 'GET' }
184
+ });
185
+
186
+ // NEW: CLI queries (no MCP server needed)
187
+ // $ node dist/cli.js decisions --scope=auth --format=table
188
+ // $ node dist/cli.js activity --agent=agent1 --limit=20
189
+ ```
190
+
191
+ Database migration runs automatically on first startup with v2.1.0.
192
+
193
+ ## [2.0.0] - 2025-10-11
194
+
195
+ ### 🚨 BREAKING CHANGES
196
+
197
+ **This is a major release with breaking API changes. Migration required for all v1.x users.**
198
+
199
+ #### Tool Consolidation
200
+ - **20 individual tools** → **6 action-based tools** (70% reduction)
201
+ - All tools now use action-based routing with `action` parameter
202
+ - Tool names completely changed (see migration guide below)
203
+
204
+ #### Old vs New Tool Names
205
+
206
+ | Old (v1.x) | New (v2.0) | Actions |
207
+ |------------|------------|---------|
208
+ | `set_decision`, `get_decision`, `get_context`, `search_by_tags`, `search_by_layer`, `get_versions` | `decision` | `set`, `get`, `list`, `search_tags`, `search_layer`, `versions`, `help` |
209
+ | `send_message`, `get_messages`, `mark_read` | `message` | `send`, `get`, `mark_read`, `help` |
210
+ | `record_file_change`, `get_file_changes`, `check_file_lock` | `file` | `record`, `get`, `check_lock`, `help` |
211
+ | `add_constraint`, `get_constraints`, `deactivate_constraint` | `constraint` | `add`, `get`, `deactivate`, `help` |
212
+ | `get_layer_summary`, `get_stats`, `clear_old_data` | `stats` | `layer_summary`, `db_stats`, `clear`, `help` |
213
+ | `get_config`, `update_config` | `config` | `get`, `update`, `help` |
214
+
215
+ ### Added
216
+
217
+ - **Help Actions:** All 6 tools now support `action: "help"` for comprehensive on-demand documentation
218
+ - Returns detailed usage, parameters, and examples
219
+ - Zero token cost until explicitly called
220
+ - **Action Hints:** Tool descriptions now include available actions for better discoverability
221
+ - **Improved Token Efficiency:** 96% token reduction vs traditional JSON approach
222
+ - Tool definition tokens: ~12,848 → ~481 tokens (96.3% reduction)
223
+ - MCP context usage: ~13,730 → ~4,482 tokens (67% reduction)
224
+
225
+ ### Changed
226
+
227
+ - **API Surface:** Complete redesign to action-based routing
228
+ - All tools require `action` parameter
229
+ - Parameters consolidated into single input schema per tool
230
+ - Nested switch statement routing for better maintainability
231
+ - **Tool Descriptions:** Simplified with action hints in parentheses
232
+ - **File Size:** Source reduced 27.4% (25,373 → 18,410 bytes) while adding help docs
233
+
234
+ ### Technical Details
235
+
236
+ - Action-based routing with two-level switch statements
237
+ - Shared parameter schemas across actions within each tool
238
+ - Enum deduplication (layer, status, priority defined once per tool)
239
+ - On-demand documentation via help actions
240
+ - 100% backward compatible database schema (no DB changes)
241
+
242
+ ### Migration Required
243
+
244
+ **v1.x users must update their tool calls:**
245
+
246
+ ```javascript
247
+ // OLD (v1.x)
248
+ await callTool('set_decision', { key: 'auth', value: 'jwt' });
249
+ await callTool('get_messages', { unread_only: true });
250
+
251
+ // NEW (v2.0)
252
+ await callTool('decision', { action: 'set', key: 'auth', value: 'jwt' });
253
+ await callTool('message', { action: 'get', unread_only: true });
254
+ ```
255
+
256
+ See `MIGRATION_v2.md` for complete migration guide.
257
+
258
+ ### Performance
259
+
260
+ - 96% token reduction in tool definitions
261
+ - 67% reduction in MCP context consumption
262
+ - Same database performance (no schema changes)
263
+ - Same query response times
264
+
8
265
  ## [1.1.2] - 2025-10-11
9
266
 
10
267
  ### Fixed
@@ -180,6 +437,8 @@ First production release of sqlew - MCP server for efficient context sharing bet
180
437
  - Full type safety
181
438
  - Comprehensive error handling
182
439
 
440
+ [2.1.0]: https://github.com/sin5ddd/mcp-sqlew/releases/tag/v2.1.0
441
+ [2.0.0]: https://github.com/sin5ddd/mcp-sqlew/releases/tag/v2.0.0
183
442
  [1.1.2]: https://github.com/sin5ddd/mcp-sqlew/releases/tag/v1.1.2
184
443
  [1.1.1]: https://github.com/sin5ddd/mcp-sqlew/releases/tag/v1.1.1
185
444
  [1.1.0]: https://github.com/sin5ddd/mcp-sqlew/releases/tag/v1.1.0