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/README.md CHANGED
@@ -3,16 +3,26 @@
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 **72% token reduction** 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
+
8
+ ## ⚠️ Version 2.1.0 - Feature Release
9
+
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
+
12
+ **Database Compatibility:** ✅ **100% compatible** - v2.1 automatically migrates v2.0 databases to add new tables and columns.
13
+
14
+ **Migration from v2.0:** Automatic on startup - see [CHANGELOG.md](CHANGELOG.md) for details.
7
15
 
8
16
  ## Why sqlew?
9
17
 
10
18
  When coordinating multiple Claude Code agents on a complex project, context sharing becomes critical. Traditional JSON-based approaches consume massive amounts of tokens. sqlew solves this with:
11
19
 
12
- - **72% Token Reduction:** ID-based normalization, integer enums, and pre-aggregated views
20
+ - **96% Token Reduction:** Action-based API eliminates tool duplication (12,848 481 tokens)
21
+ - **67% MCP Context Reduction:** From ~13,730 to ~4,482 tokens in MCP server definitions
13
22
  - **Structured Metadata:** Tags, layers, scopes, versions, and priorities for intelligent organization
14
23
  - **Fast & Reliable:** SQLite-backed with ACID guarantees and automatic cleanup
15
- - **20 MCP Tools:** Comprehensive API for decisions, messaging, file tracking, constraints, and configuration
24
+ - **6 Action-Based Tools:** Comprehensive API for decisions, messaging, file tracking, constraints, config, and stats
25
+ - **Help Actions:** On-demand documentation with zero token cost until called
16
26
 
17
27
  ## Features
18
28
 
@@ -20,6 +30,13 @@ When coordinating multiple Claude Code agents on a complex project, context shar
20
30
  - **Agent Messaging:** Priority-based messaging system with broadcast support
21
31
  - **File Change Tracking:** Layer-based file organization with lock detection
22
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
23
40
  - **Token Efficient:** Pre-aggregated views and integer enums minimize token consumption
24
41
  - **Weekend-Aware Auto-Cleanup:** Smart retention policies that pause during weekends
25
42
  - **Configurable Retention:** Adjust cleanup periods via CLI args or MCP tools
@@ -88,19 +105,89 @@ Test all tools interactively:
88
105
  npx @modelcontextprotocol/inspector npx sqlew
89
106
  ```
90
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
+
91
173
  ### Database Location
92
174
 
93
175
  Default: `.sqlew/sqlew.db` (created in current directory)
94
176
 
95
- ## Available Tools
177
+ ## Available Tools (v2.1.0)
178
+
179
+ All tools now use action-based routing. Call any tool with `action: "help"` for comprehensive documentation.
180
+
181
+ ### `decision` - Context Management
96
182
 
97
- ### Context Management (6 tools)
183
+ Manage decisions with metadata (tags, layers, versions, scopes).
98
184
 
99
- #### `set_decision`
100
- Set or update a decision with metadata support.
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`
101
186
 
102
187
  ```typescript
188
+ // Set a decision (standard)
103
189
  {
190
+ action: "set",
104
191
  key: "auth_method",
105
192
  value: "JWT",
106
193
  agent: "auth-agent",
@@ -110,39 +197,112 @@ Set or update a decision with metadata support.
110
197
  version: "1.0.0",
111
198
  status: "active"
112
199
  }
113
- ```
114
200
 
115
- #### `get_context`
116
- Retrieve decisions with advanced filtering.
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
+ }
117
210
 
118
- ```typescript
211
+ // Advanced search (v2.1.0)
119
212
  {
213
+ action: "search_advanced",
214
+ search_text: "authentication",
215
+ layers: ["business", "presentation"],
216
+ tags: ["security"],
120
217
  status: "active",
121
- layer: "business",
122
- tags: ["authentication"],
123
- tag_match: "AND"
218
+ agent: "auth-agent",
219
+ scopes: ["user-service"]
124
220
  }
125
- ```
126
221
 
127
- #### `get_decision`
128
- Get a specific decision by key.
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
+ }
129
230
 
130
- #### `search_by_tags`
131
- Search decisions by tags with AND/OR logic.
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
+ }
132
242
 
133
- #### `get_versions`
134
- Retrieve version history for a decision.
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
+ }
135
253
 
136
- #### `search_by_layer`
137
- Search decisions within an architecture layer.
254
+ // List templates (v2.1.0)
255
+ {
256
+ action: "list_templates"
257
+ }
138
258
 
139
- ### Messaging (3 tools)
259
+ // Check for updates (v2.1.0)
260
+ {
261
+ action: "has_updates",
262
+ agent: "auth-agent",
263
+ since: "2025-01-10T12:00:00Z"
264
+ }
140
265
 
141
- #### `send_message`
142
- Send messages between agents with priority levels.
266
+ // Get decision by key
267
+ {
268
+ action: "get",
269
+ key: "auth_method"
270
+ }
271
+
272
+ // List with filtering
273
+ {
274
+ action: "list",
275
+ status: "active",
276
+ layer: "business"
277
+ }
278
+
279
+ // Search by tags
280
+ {
281
+ action: "search_tags",
282
+ tags: ["authentication", "security"],
283
+ tag_match: "AND"
284
+ }
285
+
286
+ // Get version history
287
+ {
288
+ action: "versions",
289
+ key: "auth_method"
290
+ }
291
+
292
+ // Get help
293
+ { action: "help" }
294
+ ```
295
+
296
+ ### `message` - Agent Messaging
297
+
298
+ Send and retrieve messages between agents with priority levels.
299
+
300
+ **Actions:** `send`, `get`, `mark_read`, `send_batch`, `help`
143
301
 
144
302
  ```typescript
303
+ // Send message
145
304
  {
305
+ action: "send",
146
306
  from_agent: "agent1",
147
307
  to_agent: "agent2",
148
308
  msg_type: "warning",
@@ -150,117 +310,322 @@ Send messages between agents with priority levels.
150
310
  priority: "high",
151
311
  payload: { file: "/src/auth.ts" }
152
312
  }
153
- ```
154
313
 
155
- #### `get_messages`
156
- Retrieve messages with filtering (priority, unread status).
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
+ }
157
334
 
158
- #### `mark_read`
159
- Mark messages as read.
335
+ // Get messages
336
+ {
337
+ action: "get",
338
+ unread_only: true,
339
+ priority_filter: "high"
340
+ }
160
341
 
161
- ### File Tracking (3 tools)
342
+ // Mark as read
343
+ {
344
+ action: "mark_read",
345
+ message_ids: [1, 2, 3]
346
+ }
347
+ ```
162
348
 
163
- #### `record_file_change`
164
- Record file changes with layer assignment.
349
+ ### `file` - File Change Tracking
350
+
351
+ Track file modifications with layer assignment and lock detection.
352
+
353
+ **Actions:** `record`, `get`, `check_lock`, `record_batch`, `help`
165
354
 
166
355
  ```typescript
356
+ // Record file change
167
357
  {
358
+ action: "record",
168
359
  file_path: "/src/auth.ts",
169
360
  agent_name: "auth-agent",
170
361
  change_type: "modified",
171
362
  layer: "business",
172
363
  description: "Updated JWT validation"
173
364
  }
174
- ```
175
365
 
176
- #### `get_file_changes`
177
- Retrieve file change history with filtering.
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
+
387
+ // Get file changes
388
+ {
389
+ action: "get",
390
+ since: "2025-01-10T10:00:00Z",
391
+ layer: "business"
392
+ }
393
+
394
+ // Check file lock
395
+ {
396
+ action: "check_lock",
397
+ file_path: "/src/auth.ts",
398
+ lock_duration: 300
399
+ }
400
+ ```
178
401
 
179
- #### `check_file_lock`
180
- Check if a file is recently modified (prevents concurrent edits).
402
+ ### `constraint` - Constraint Management
181
403
 
182
- ### Constraint Management (3 tools)
404
+ Manage architectural, performance, and security constraints.
183
405
 
184
- #### `add_constraint`
185
- Add constraints with priority and metadata.
406
+ **Actions:** `add`, `get`, `deactivate`, `help`
186
407
 
187
408
  ```typescript
409
+ // Add constraint
188
410
  {
411
+ action: "add",
189
412
  category: "performance",
190
413
  constraint_text: "Response time < 200ms",
191
414
  priority: "high",
192
415
  layer: "business",
193
416
  tags: ["api", "performance"]
194
417
  }
195
- ```
196
418
 
197
- #### `get_constraints`
198
- Retrieve constraints with complex filtering.
419
+ // Get constraints
420
+ {
421
+ action: "get",
422
+ category: "performance",
423
+ active_only: true
424
+ }
199
425
 
200
- #### `deactivate_constraint`
201
- Deactivate a constraint (soft delete).
426
+ // Deactivate constraint
427
+ {
428
+ action: "deactivate",
429
+ constraint_id: 42
430
+ }
431
+ ```
202
432
 
203
- ### Utilities (3 tools)
433
+ ### `stats` - Statistics & Utilities
204
434
 
205
- #### `get_layer_summary`
206
- Get aggregated statistics per architecture layer.
435
+ Get database statistics and manage data cleanup.
207
436
 
208
- #### `clear_old_data`
209
- Manually clear old messages and file changes (uses weekend-aware config when no params provided).
437
+ **Actions:** `layer_summary`, `db_stats`, `clear`, `activity_log`, `help`
210
438
 
211
- #### `get_stats`
212
- Get comprehensive database statistics.
439
+ ```typescript
440
+ // Layer summary
441
+ { action: "layer_summary" }
213
442
 
214
- ### Configuration (2 tools)
443
+ // Database stats
444
+ { action: "db_stats" }
215
445
 
216
- #### `get_config`
217
- Get current auto-deletion configuration settings.
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
+ }
218
454
 
219
- ```typescript
220
- // Returns:
455
+ // Clear old data (weekend-aware)
221
456
  {
222
- ignoreWeekend: false,
223
- messageRetentionHours: 24,
224
- fileHistoryRetentionDays: 7
457
+ action: "clear",
458
+ messages_older_than_hours: 48,
459
+ file_changes_older_than_days: 14
225
460
  }
226
461
  ```
227
462
 
228
- #### `update_config`
229
- Update auto-deletion configuration settings.
463
+ ### `config` - Configuration
464
+
465
+ Manage auto-deletion and retention settings.
466
+
467
+ **Actions:** `get`, `update`, `help`
230
468
 
231
469
  ```typescript
470
+ // Get config
471
+ { action: "get" }
472
+
473
+ // Update config
232
474
  {
475
+ action: "update",
233
476
  ignoreWeekend: true,
234
477
  messageRetentionHours: 48,
235
478
  fileHistoryRetentionDays: 10
236
479
  }
237
480
  ```
238
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
+
239
596
  ## Database Schema
240
597
 
241
- 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:
242
599
 
243
- **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)
244
601
 
245
- **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)
246
603
 
247
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
248
605
 
249
- **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)
250
607
 
251
608
  ### Automatic Migration
252
609
 
253
- 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.
254
613
 
255
614
  ## Token Efficiency
256
615
 
257
- sqlew achieves **72% token reduction** through:
616
+ sqlew achieves **96% token reduction** through:
617
+
618
+ 1. **Action-Based Tools (v2.0):** Consolidates 20 tools → 6 tools, eliminating duplication
619
+ 2. **ID-Based Normalization:** Strings stored once, referenced by integer IDs
620
+ 3. **Integer Enums:** Status, priority, message types use integers (1-4) instead of strings
621
+ 4. **Pre-Aggregated Views:** Common queries use pre-computed results
622
+ 5. **Type-Based Tables:** Separate storage for numeric vs string values
623
+ 6. **Automatic Cleanup:** Prevents database bloat
624
+
625
+ ### v2.0.0 Token Savings
258
626
 
259
- 1. **ID-Based Normalization:** Strings stored once, referenced by integer IDs
260
- 2. **Integer Enums:** Status, priority, message types use integers (1-4) instead of strings
261
- 3. **Pre-Aggregated Views:** Common queries use pre-computed results
262
- 4. **Type-Based Tables:** Separate storage for numeric vs string values
263
- 5. **Automatic Cleanup:** Prevents database bloat
627
+ - **Tool Definitions:** 12,848 481 tokens (96.3% reduction)
628
+ - **MCP Context Usage:** ~13,730 → ~4,482 tokens (67% reduction)
264
629
 
265
630
  ### Example Comparison
266
631
 
@@ -324,11 +689,11 @@ npm start
324
689
  ### Testing
325
690
 
326
691
  ```bash
327
- # Run verification script
328
- node verify-all-tools.mjs
329
-
330
- # Or use MCP Inspector
692
+ # Use MCP Inspector to test all tools
331
693
  npm run inspector
694
+
695
+ # Or test individual tools via CLI
696
+ npx @modelcontextprotocol/inspector npx sqlew
332
697
  ```
333
698
 
334
699
  ### Project Structure