sqlew 2.0.0 → 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 (42) hide show
  1. package/CHANGELOG.md +186 -0
  2. package/README.md +320 -16
  3. package/assets/schema.sql +122 -36
  4. package/dist/cli.d.ts +7 -0
  5. package/dist/cli.d.ts.map +1 -0
  6. package/dist/cli.js +312 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/database.d.ts.map +1 -1
  9. package/dist/database.js +18 -0
  10. package/dist/database.js.map +1 -1
  11. package/dist/index.js +135 -41
  12. package/dist/index.js.map +1 -1
  13. package/dist/migrations/add-v2.1.0-features.d.ts +29 -0
  14. package/dist/migrations/add-v2.1.0-features.d.ts.map +1 -0
  15. package/dist/migrations/add-v2.1.0-features.js +198 -0
  16. package/dist/migrations/add-v2.1.0-features.js.map +1 -0
  17. package/dist/schema.d.ts.map +1 -1
  18. package/dist/schema.js +5 -0
  19. package/dist/schema.js.map +1 -1
  20. package/dist/tools/context.d.ts +91 -1
  21. package/dist/tools/context.d.ts.map +1 -1
  22. package/dist/tools/context.js +614 -0
  23. package/dist/tools/context.js.map +1 -1
  24. package/dist/tools/files.d.ts +10 -1
  25. package/dist/tools/files.d.ts.map +1 -1
  26. package/dist/tools/files.js +98 -1
  27. package/dist/tools/files.js.map +1 -1
  28. package/dist/tools/messaging.d.ts +10 -1
  29. package/dist/tools/messaging.d.ts.map +1 -1
  30. package/dist/tools/messaging.js +107 -1
  31. package/dist/tools/messaging.js.map +1 -1
  32. package/dist/tools/utils.d.ts +9 -1
  33. package/dist/tools/utils.d.ts.map +1 -1
  34. package/dist/tools/utils.js +115 -0
  35. package/dist/tools/utils.js.map +1 -1
  36. package/dist/types.d.ts +196 -0
  37. package/dist/types.d.ts.map +1 -1
  38. package/dist/utils/cleanup.d.ts +12 -1
  39. package/dist/utils/cleanup.d.ts.map +1 -1
  40. package/dist/utils/cleanup.js +20 -3
  41. package/dist/utils/cleanup.js.map +1 -1
  42. package/package.json +4 -2
package/CHANGELOG.md CHANGED
@@ -5,6 +5,191 @@ 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
+
8
193
  ## [2.0.0] - 2025-10-11
9
194
 
10
195
  ### 🚨 BREAKING CHANGES
@@ -252,6 +437,7 @@ First production release of sqlew - MCP server for efficient context sharing bet
252
437
  - Full type safety
253
438
  - Comprehensive error handling
254
439
 
440
+ [2.1.0]: https://github.com/sin5ddd/mcp-sqlew/releases/tag/v2.1.0
255
441
  [2.0.0]: https://github.com/sin5ddd/mcp-sqlew/releases/tag/v2.0.0
256
442
  [1.1.2]: https://github.com/sin5ddd/mcp-sqlew/releases/tag/v1.1.2
257
443
  [1.1.1]: https://github.com/sin5ddd/mcp-sqlew/releases/tag/v1.1.1
package/README.md CHANGED
@@ -3,15 +3,15 @@
3
3
  [![npm version](https://img.shields.io/npm/v/sqlew.svg)](https://www.npmjs.com/package/sqlew)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
5
 
6
- **sqlew** (SQL Efficient Workflow) is a Model Context Protocol (MCP) server for efficient context sharing between Claude Code sub-agents. Achieve **96% token reduction** through action-based tools while managing structured data through a metadata-driven SQLite database.
6
+ **sqlew** (SQL Efficient Workflow) is a Model Context Protocol (MCP) server for efficient context sharing between Claude Code sub-agents. Achieve **67% token reduction** through action-based tools while managing structured data through a metadata-driven SQLite database.
7
7
 
8
- ## ⚠️ Version 2.0.0 - Breaking Changes
8
+ ## ⚠️ Version 2.1.0 - Feature Release
9
9
 
10
- **v2.0.0 introduces action-based tools that consolidate the API from 20 tools to 6 tools.** This is a breaking change in the MCP tool API only.
10
+ **v2.1.0 adds 7 major features** including Activity Log, Smart Defaults, Subscriptions, Advanced Query, Batch Operations, Templates, and CLI Query Tool. This is a feature addition - fully backward compatible with v2.0.0.
11
11
 
12
- **Database Compatibility:** ✅ **100% compatible** - v2.0 uses the same database schema as v1.x. No data migration needed.
12
+ **Database Compatibility:** ✅ **100% compatible** - v2.1 automatically migrates v2.0 databases to add new tables and columns.
13
13
 
14
- **Migration Required:** Only for code that calls MCP tools - see [MIGRATION_v2.md](MIGRATION_v2.md) for upgrade guide.
14
+ **Migration from v2.0:** Automatic on startup - see [CHANGELOG.md](CHANGELOG.md) for details.
15
15
 
16
16
  ## Why sqlew?
17
17
 
@@ -30,6 +30,13 @@ When coordinating multiple Claude Code agents on a complex project, context shar
30
30
  - **Agent Messaging:** Priority-based messaging system with broadcast support
31
31
  - **File Change Tracking:** Layer-based file organization with lock detection
32
32
  - **Constraint Management:** Track performance, architecture, and security constraints
33
+ - **Activity Log (v2.1.0):** Automatic tracking of all agent actions with 4 trigger-based monitoring
34
+ - **Smart Defaults (v2.1.0):** Quick decision creation with intelligent layer/tag inference from file paths
35
+ - **Subscriptions (v2.1.0):** Lightweight polling mechanism to check for updates without fetching all data
36
+ - **Advanced Query (v2.1.0):** Complex multi-criteria filtering with full-text search across decisions
37
+ - **Batch Operations (v2.1.0):** Bulk create decisions, messages, and file changes in single transactions
38
+ - **Templates (v2.1.0):** Pre-configured decision templates (5 built-in) with custom template support
39
+ - **CLI Query Tool (v2.1.0):** Standalone CLI commands for fast terminal queries without MCP Inspector
33
40
  - **Token Efficient:** Pre-aggregated views and integer enums minimize token consumption
34
41
  - **Weekend-Aware Auto-Cleanup:** Smart retention policies that pause during weekends
35
42
  - **Configurable Retention:** Adjust cleanup periods via CLI args or MCP tools
@@ -98,11 +105,76 @@ Test all tools interactively:
98
105
  npx @modelcontextprotocol/inspector npx sqlew
99
106
  ```
100
107
 
108
+ ### CLI Query Tool (v2.1.0)
109
+
110
+ Query your context database directly from the terminal without MCP Inspector. The CLI provides 4 specialized query commands with rich filtering capabilities.
111
+
112
+ ```bash
113
+ # Query decisions with filtering
114
+ sqlew query decisions --layer business --tags breaking --output table
115
+ sqlew query decisions --search "auth" --status active --limit 10
116
+ sqlew query decisions --key-pattern "api_*" --scope user-service
117
+
118
+ # Query unread high-priority messages
119
+ sqlew query messages --unread --priority high --output json
120
+ sqlew query messages --to-agent db-agent --msg-type warning
121
+ sqlew query messages --from-agent auth-agent --since 1h
122
+
123
+ # Query recent file changes (last hour)
124
+ sqlew query files --since 1h --output table
125
+ sqlew query files --layer data --change-type modified
126
+ sqlew query files --agent auth-agent --file-path "*/auth/*"
127
+
128
+ # Query recent activity from all agents
129
+ sqlew query activity --since 5m --agent '*' --output json
130
+ sqlew query activity --action-type decision_set --since 30m
131
+ sqlew query activity --agent auth-agent --limit 50
132
+ ```
133
+
134
+ **Available Commands:**
135
+ - `decisions` - Query decisions with multi-criteria filtering and full-text search
136
+ - `messages` - Query agent messages with priority, read status, and type filters
137
+ - `files` - Query file changes with layer, change type, and path filtering
138
+ - `activity` - Query activity log with action type and agent filters
139
+
140
+ **Common Options:**
141
+ - `--output <format>` - Output format: `json` or `table` (default: json)
142
+ - `--layer <layer>` - Filter by layer (presentation, business, data, infrastructure, cross-cutting)
143
+ - `--tags <tags>` - Filter by tags (comma-separated)
144
+ - `--since <time>` - Time filter (e.g., "5m", "1h", "2d", or ISO timestamp)
145
+ - `--limit <number>` - Limit results (default: 100)
146
+ - `--db-path <path>` - Custom database path
147
+ - `--help` - Show help for available options
148
+
149
+ **Decision-Specific Options:**
150
+ - `--search <text>` - Full-text search in keys and values
151
+ - `--status <status>` - Filter by status (active, deprecated, draft)
152
+ - `--key-pattern <pattern>` - SQL LIKE pattern for keys
153
+ - `--scope <scope>` - Filter by scope
154
+
155
+ **Message-Specific Options:**
156
+ - `--unread` - Show only unread messages
157
+ - `--priority <priority>` - Filter by priority (low, medium, high, critical)
158
+ - `--msg-type <type>` - Filter by message type (decision, warning, request, info)
159
+ - `--from-agent <agent>` - Filter by sender agent
160
+ - `--to-agent <agent>` - Filter by recipient agent
161
+
162
+ **File-Specific Options:**
163
+ - `--change-type <type>` - Filter by change type (created, modified, deleted)
164
+ - `--agent <agent>` - Filter by agent name
165
+ - `--file-path <pattern>` - SQL LIKE pattern for file paths
166
+
167
+ **Activity-Specific Options:**
168
+ - `--action-type <type>` - Filter by action type (decision_set, message_send, file_record, constraint_add)
169
+ - `--agent <agent>` - Filter by agent name
170
+
171
+ Run `sqlew query <command> --help` for command-specific documentation.
172
+
101
173
  ### Database Location
102
174
 
103
175
  Default: `.sqlew/sqlew.db` (created in current directory)
104
176
 
105
- ## Available Tools (v2.0.0)
177
+ ## Available Tools (v2.1.0)
106
178
 
107
179
  All tools now use action-based routing. Call any tool with `action: "help"` for comprehensive documentation.
108
180
 
@@ -110,10 +182,10 @@ All tools now use action-based routing. Call any tool with `action: "help"` for
110
182
 
111
183
  Manage decisions with metadata (tags, layers, versions, scopes).
112
184
 
113
- **Actions:** `set`, `get`, `list`, `search_tags`, `search_layer`, `versions`, `help`
185
+ **Actions:** `set`, `get`, `list`, `search_tags`, `search_layer`, `versions`, `quick_set`, `search_advanced`, `set_batch`, `set_from_template`, `create_template`, `list_templates`, `has_updates`, `help`
114
186
 
115
187
  ```typescript
116
- // Set a decision
188
+ // Set a decision (standard)
117
189
  {
118
190
  action: "set",
119
191
  key: "auth_method",
@@ -126,6 +198,71 @@ Manage decisions with metadata (tags, layers, versions, scopes).
126
198
  status: "active"
127
199
  }
128
200
 
201
+ // Quick set with smart defaults (v2.1.0)
202
+ {
203
+ action: "quick_set",
204
+ key: "database_config",
205
+ value: "PostgreSQL",
206
+ agent: "db-agent",
207
+ file_path: "/src/data/repositories/UserRepository.ts"
208
+ // Automatically infers: layer="data", tags=["database", "repositories"]
209
+ }
210
+
211
+ // Advanced search (v2.1.0)
212
+ {
213
+ action: "search_advanced",
214
+ search_text: "authentication",
215
+ layers: ["business", "presentation"],
216
+ tags: ["security"],
217
+ status: "active",
218
+ agent: "auth-agent",
219
+ scopes: ["user-service"]
220
+ }
221
+
222
+ // Batch set (v2.1.0)
223
+ {
224
+ action: "set_batch",
225
+ decisions: [
226
+ { key: "api_v1", value: "REST", agent: "api-agent", layer: "presentation" },
227
+ { key: "api_v2", value: "GraphQL", agent: "api-agent", layer: "presentation" }
228
+ ]
229
+ }
230
+
231
+ // Set from template (v2.1.0)
232
+ {
233
+ action: "set_from_template",
234
+ template_name: "api-endpoint",
235
+ key: "user_api",
236
+ agent: "api-agent",
237
+ overrides: {
238
+ value: "GET /api/users",
239
+ scopes: ["user-service"]
240
+ }
241
+ }
242
+
243
+ // Create custom template (v2.1.0)
244
+ {
245
+ action: "create_template",
246
+ name: "my-template",
247
+ description: "Custom template",
248
+ agent: "admin-agent",
249
+ default_layer: "business",
250
+ default_tags: ["custom"],
251
+ default_status: "active"
252
+ }
253
+
254
+ // List templates (v2.1.0)
255
+ {
256
+ action: "list_templates"
257
+ }
258
+
259
+ // Check for updates (v2.1.0)
260
+ {
261
+ action: "has_updates",
262
+ agent: "auth-agent",
263
+ since: "2025-01-10T12:00:00Z"
264
+ }
265
+
129
266
  // Get decision by key
130
267
  {
131
268
  action: "get",
@@ -160,7 +297,7 @@ Manage decisions with metadata (tags, layers, versions, scopes).
160
297
 
161
298
  Send and retrieve messages between agents with priority levels.
162
299
 
163
- **Actions:** `send`, `get`, `mark_read`, `help`
300
+ **Actions:** `send`, `get`, `mark_read`, `send_batch`, `help`
164
301
 
165
302
  ```typescript
166
303
  // Send message
@@ -174,6 +311,27 @@ Send and retrieve messages between agents with priority levels.
174
311
  payload: { file: "/src/auth.ts" }
175
312
  }
176
313
 
314
+ // Send batch messages (v2.1.0)
315
+ {
316
+ action: "send_batch",
317
+ messages: [
318
+ {
319
+ from_agent: "orchestrator",
320
+ to_agent: "auth-agent",
321
+ msg_type: "request",
322
+ message: "Start authentication setup",
323
+ priority: "high"
324
+ },
325
+ {
326
+ from_agent: "orchestrator",
327
+ to_agent: "db-agent",
328
+ msg_type: "request",
329
+ message: "Initialize database schema",
330
+ priority: "high"
331
+ }
332
+ ]
333
+ }
334
+
177
335
  // Get messages
178
336
  {
179
337
  action: "get",
@@ -192,7 +350,7 @@ Send and retrieve messages between agents with priority levels.
192
350
 
193
351
  Track file modifications with layer assignment and lock detection.
194
352
 
195
- **Actions:** `record`, `get`, `check_lock`, `help`
353
+ **Actions:** `record`, `get`, `check_lock`, `record_batch`, `help`
196
354
 
197
355
  ```typescript
198
356
  // Record file change
@@ -205,6 +363,27 @@ Track file modifications with layer assignment and lock detection.
205
363
  description: "Updated JWT validation"
206
364
  }
207
365
 
366
+ // Record batch file changes (v2.1.0)
367
+ {
368
+ action: "record_batch",
369
+ changes: [
370
+ {
371
+ file_path: "/src/auth/jwt.ts",
372
+ agent_name: "auth-agent",
373
+ change_type: "created",
374
+ layer: "business",
375
+ description: "Added JWT utility"
376
+ },
377
+ {
378
+ file_path: "/src/auth/validation.ts",
379
+ agent_name: "auth-agent",
380
+ change_type: "created",
381
+ layer: "business",
382
+ description: "Added validation logic"
383
+ }
384
+ ]
385
+ }
386
+
208
387
  // Get file changes
209
388
  {
210
389
  action: "get",
@@ -255,7 +434,7 @@ Manage architectural, performance, and security constraints.
255
434
 
256
435
  Get database statistics and manage data cleanup.
257
436
 
258
- **Actions:** `layer_summary`, `db_stats`, `clear`, `help`
437
+ **Actions:** `layer_summary`, `db_stats`, `clear`, `activity_log`, `help`
259
438
 
260
439
  ```typescript
261
440
  // Layer summary
@@ -264,6 +443,15 @@ Get database statistics and manage data cleanup.
264
443
  // Database stats
265
444
  { action: "db_stats" }
266
445
 
446
+ // Activity log (v2.1.0)
447
+ {
448
+ action: "activity_log",
449
+ agent: "auth-agent",
450
+ action_type: "decision_set",
451
+ since: "2025-01-10T10:00:00Z",
452
+ limit: 100
453
+ }
454
+
267
455
  // Clear old data (weekend-aware)
268
456
  {
269
457
  action: "clear",
@@ -291,21 +479,137 @@ Manage auto-deletion and retention settings.
291
479
  }
292
480
  ```
293
481
 
482
+ ## v2.1.0 Features
483
+
484
+ ### FR-001: Activity Log
485
+
486
+ Automatic tracking of all agent actions through trigger-based monitoring. Every decision set, message send, file record, and constraint add is logged with timestamps and agent information.
487
+
488
+ **Use Cases:**
489
+ - Audit trail for debugging agent interactions
490
+ - Performance monitoring and bottleneck identification
491
+ - Historical analysis of agent behavior patterns
492
+
493
+ **Implementation:**
494
+ - `t_activity_log` table with agent_id, action_type, entity_id, and timestamps
495
+ - 4 triggers automatically log actions: `trg_activity_decision_set`, `trg_activity_message_send`, `trg_activity_file_record`, `trg_activity_constraint_add`
496
+ - Query via `stats` tool with `action: "activity_log"` or CLI with `sqlew query activity`
497
+
498
+ ### FR-002: Smart Defaults
499
+
500
+ Quick decision creation with intelligent layer and tag inference from file paths. Reduces boilerplate by automatically categorizing decisions based on file context.
501
+
502
+ **Use Cases:**
503
+ - Rapid decision recording during active development
504
+ - Consistent layer/tag assignment without manual specification
505
+ - Reduced cognitive load for agents
506
+
507
+ **Implementation:**
508
+ - `quick_set` action in `decision` tool
509
+ - Path pattern matching: `/src/data/*` → layer="data", tags=["database"]
510
+ - `/src/presentation/*` → layer="presentation", tags=["ui", "views"]
511
+ - Overridable defaults if explicit values provided
512
+
513
+ ### FR-003: Subscriptions
514
+
515
+ Lightweight polling mechanism to check for updates without fetching all data. Agents can subscribe to decision changes and efficiently check for updates since last poll.
516
+
517
+ **Use Cases:**
518
+ - Periodic checks for new decisions without full data retrieval
519
+ - Token-efficient polling for agents monitoring specific contexts
520
+ - Reduced network/token overhead for update detection
521
+
522
+ **Implementation:**
523
+ - `t_subscriptions` table tracks agent_id and last_check timestamps
524
+ - `has_updates` action in `decision` tool returns boolean and count
525
+ - Agents can poll periodically with minimal token cost
526
+
527
+ ### FR-004: Advanced Query
528
+
529
+ Complex multi-criteria filtering with full-text search across decisions. Supports AND/OR logic for tags, multiple layer filtering, and text search in keys/values.
530
+
531
+ **Use Cases:**
532
+ - Cross-layer analysis (e.g., all "security" decisions in "business" and "data" layers)
533
+ - Full-text search for decisions related to specific features
534
+ - Complex filtering scenarios with multiple conditions
535
+
536
+ **Implementation:**
537
+ - `search_advanced` action in `decision` tool
538
+ - SQL LIKE search for text patterns in keys and values
539
+ - Multiple layer filtering with `layers` array parameter
540
+ - Combines with existing tag/status/scope filters
541
+
542
+ ### FR-005: Batch Operations
543
+
544
+ Bulk creation of decisions, messages, and file changes in single transactions. Reduces round-trips and ensures atomic operations.
545
+
546
+ **Use Cases:**
547
+ - Bulk initialization of project decisions
548
+ - Broadcasting messages to multiple agents
549
+ - Recording multiple file changes from refactoring operations
550
+ - Atomic multi-entity operations
551
+
552
+ **Implementation:**
553
+ - `set_batch` action in `decision` tool (accepts array of decisions)
554
+ - `send_batch` action in `message` tool (accepts array of messages)
555
+ - `record_batch` action in `file` tool (accepts array of file changes)
556
+ - All operations wrapped in transactions for ACID guarantees
557
+
558
+ ### FR-006: Templates
559
+
560
+ Pre-configured decision templates with 5 built-in templates and custom template support. Ensures consistency and reduces setup time.
561
+
562
+ **Built-in Templates:**
563
+ 1. **api-endpoint**: REST/GraphQL endpoint configurations (layer: presentation, tags: api, endpoints)
564
+ 2. **database-config**: Database connection and schema settings (layer: data, tags: database, config)
565
+ 3. **security-policy**: Authentication, authorization, encryption rules (layer: cross-cutting, tags: security, policy)
566
+ 4. **performance-threshold**: Performance metrics and SLA definitions (layer: infrastructure, tags: performance, monitoring)
567
+ 5. **feature-flag**: Feature toggle configurations (layer: business, tags: feature-flags, config)
568
+
569
+ **Use Cases:**
570
+ - Consistent decision structure across agents
571
+ - Quick setup for common decision types
572
+ - Team standards enforcement through templates
573
+
574
+ **Implementation:**
575
+ - `m_templates` table stores template definitions
576
+ - `set_from_template` action applies template with key and overrides
577
+ - `create_template` action for custom templates
578
+ - `list_templates` action to view available templates
579
+
580
+ ### FR-007: CLI Query Tool
581
+
582
+ Standalone CLI commands for fast terminal queries without MCP Inspector. Provides 4 specialized query commands with rich filtering and table/JSON output formats.
583
+
584
+ **Use Cases:**
585
+ - Quick context checks during terminal-based development
586
+ - CI/CD integration for decision validation
587
+ - Shell scripting with JSON output parsing
588
+ - Human-readable table output for debugging
589
+
590
+ **Implementation:**
591
+ - `sqlew query decisions|messages|files|activity` commands
592
+ - Rich filtering options per command (see CLI section above)
593
+ - Table output uses `cli-table3` for formatted display
594
+ - JSON output for programmatic consumption
595
+
294
596
  ## Database Schema
295
597
 
296
- sqlew uses a normalized SQLite schema (v1.3.0) optimized for token efficiency with category-based table prefixes:
598
+ sqlew uses a normalized SQLite schema (v2.1.0) optimized for token efficiency with category-based table prefixes:
297
599
 
298
- **Master Tables (m_ prefix):** m_agents, m_files, m_context_keys, m_layers, m_tags, m_scopes, m_constraint_categories, m_config
600
+ **Master Tables (m_ prefix):** m_agents, m_files, m_context_keys, m_layers, m_tags, m_scopes, m_constraint_categories, m_config, m_templates (v2.1.0)
299
601
 
300
- **Transaction Tables (t_ prefix):** t_decisions, t_decisions_numeric, t_decision_history, t_decision_tags, t_decision_scopes, t_agent_messages, t_file_changes, t_constraints, t_constraint_tags
602
+ **Transaction Tables (t_ prefix):** t_decisions, t_decisions_numeric, t_decision_history, t_decision_tags, t_decision_scopes, t_agent_messages, t_file_changes, t_constraints, t_constraint_tags, t_activity_log (v2.1.0), t_subscriptions (v2.1.0)
301
603
 
302
604
  **Token-Efficient Views (v_ prefix):** v_tagged_decisions, v_active_context, v_layer_summary, v_unread_messages_by_priority, v_recent_file_changes, v_tagged_constraints
303
605
 
304
- **Triggers (trg_ prefix):** trg_record_decision_history
606
+ **Triggers (trg_ prefix):** trg_record_decision_history, trg_activity_decision_set (v2.1.0), trg_activity_message_send (v2.1.0), trg_activity_file_record (v2.1.0), trg_activity_constraint_add (v2.1.0)
305
607
 
306
608
  ### Automatic Migration
307
609
 
308
- When upgrading from v1.2.0 to v1.3.0, the server automatically migrates your database to use the new prefixed table names. The migration is safe and runs in a transaction - if it fails, the database is unchanged.
610
+ **From v2.0 to v2.1:** Automatic migration adds new tables (t_activity_log, t_subscriptions, m_templates) and triggers (4 activity monitoring triggers). Migration runs on startup and is safe - if it fails, the database is unchanged.
611
+
612
+ **From v1.2.0 to v1.3.0:** The server automatically migrates your database to use the new prefixed table names. The migration is safe and runs in a transaction.
309
613
 
310
614
  ## Token Efficiency
311
615