sqlew 2.1.3 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/CHANGELOG.md +891 -535
  2. package/README.md +302 -613
  3. package/assets/kanban-style.png +0 -0
  4. package/assets/schema.sql +531 -402
  5. package/dist/database.d.ts +9 -0
  6. package/dist/database.d.ts.map +1 -1
  7. package/dist/database.js +33 -34
  8. package/dist/database.js.map +1 -1
  9. package/dist/index.js +1024 -21
  10. package/dist/index.js.map +1 -1
  11. package/dist/migrations/add-task-tables.d.ts +47 -0
  12. package/dist/migrations/add-task-tables.d.ts.map +1 -0
  13. package/dist/migrations/add-task-tables.js +285 -0
  14. package/dist/migrations/add-task-tables.js.map +1 -0
  15. package/dist/migrations/index.d.ts +96 -0
  16. package/dist/migrations/index.d.ts.map +1 -0
  17. package/dist/migrations/index.js +239 -0
  18. package/dist/migrations/index.js.map +1 -0
  19. package/dist/migrations/migrate-decisions-to-tasks.d.ts +61 -0
  20. package/dist/migrations/migrate-decisions-to-tasks.d.ts.map +1 -0
  21. package/dist/migrations/migrate-decisions-to-tasks.js +442 -0
  22. package/dist/migrations/migrate-decisions-to-tasks.js.map +1 -0
  23. package/dist/schema.d.ts.map +1 -1
  24. package/dist/schema.js +14 -3
  25. package/dist/schema.js.map +1 -1
  26. package/dist/tools/constraints.d.ts +4 -0
  27. package/dist/tools/constraints.d.ts.map +1 -1
  28. package/dist/tools/constraints.js +6 -27
  29. package/dist/tools/constraints.js.map +1 -1
  30. package/dist/tools/context.d.ts +17 -1
  31. package/dist/tools/context.d.ts.map +1 -1
  32. package/dist/tools/context.js +195 -190
  33. package/dist/tools/context.js.map +1 -1
  34. package/dist/tools/files.d.ts.map +1 -1
  35. package/dist/tools/files.js +113 -166
  36. package/dist/tools/files.js.map +1 -1
  37. package/dist/tools/messaging.d.ts +2 -9
  38. package/dist/tools/messaging.d.ts.map +1 -1
  39. package/dist/tools/messaging.js +67 -126
  40. package/dist/tools/messaging.js.map +1 -1
  41. package/dist/tools/tasks.d.ts +90 -0
  42. package/dist/tools/tasks.d.ts.map +1 -0
  43. package/dist/tools/tasks.js +732 -0
  44. package/dist/tools/tasks.js.map +1 -0
  45. package/dist/tools/utils.d.ts +8 -1
  46. package/dist/tools/utils.d.ts.map +1 -1
  47. package/dist/tools/utils.js +50 -21
  48. package/dist/tools/utils.js.map +1 -1
  49. package/dist/types.d.ts +14 -0
  50. package/dist/types.d.ts.map +1 -1
  51. package/dist/utils/batch.d.ts +69 -0
  52. package/dist/utils/batch.d.ts.map +1 -0
  53. package/dist/utils/batch.js +148 -0
  54. package/dist/utils/batch.js.map +1 -0
  55. package/dist/utils/query-builder.d.ts +68 -0
  56. package/dist/utils/query-builder.d.ts.map +1 -0
  57. package/dist/utils/query-builder.js +116 -0
  58. package/dist/utils/query-builder.js.map +1 -0
  59. package/dist/utils/task-stale-detection.d.ts +28 -0
  60. package/dist/utils/task-stale-detection.d.ts.map +1 -0
  61. package/dist/utils/task-stale-detection.js +92 -0
  62. package/dist/utils/task-stale-detection.js.map +1 -0
  63. package/dist/utils/validators.d.ts +57 -0
  64. package/dist/utils/validators.d.ts.map +1 -0
  65. package/dist/utils/validators.js +117 -0
  66. package/dist/utils/validators.js.map +1 -0
  67. package/docs/AI_AGENT_GUIDE.md +1471 -0
  68. package/{ARCHITECTURE.md → docs/ARCHITECTURE.md} +636 -636
  69. package/docs/BEST_PRACTICES.md +481 -0
  70. package/docs/DECISION_TO_TASK_MIGRATION_GUIDE.md +457 -0
  71. package/docs/MIGRATION_CHAIN.md +280 -0
  72. package/{MIGRATION_v2.md → docs/MIGRATION_v2.md} +538 -538
  73. package/docs/SHARED_CONCEPTS.md +339 -0
  74. package/docs/TASK_ACTIONS.md +854 -0
  75. package/docs/TASK_LINKING.md +729 -0
  76. package/docs/TASK_MIGRATION.md +701 -0
  77. package/docs/TASK_OVERVIEW.md +363 -0
  78. package/docs/TASK_SYSTEM.md +1244 -0
  79. package/docs/TOOL_REFERENCE.md +471 -0
  80. package/docs/TOOL_SELECTION.md +279 -0
  81. package/docs/WORKFLOWS.md +602 -0
  82. package/docs/refactoring-summary-2025-10-17.md +365 -0
  83. package/docs/requirement-2025-10-17.md +508 -0
  84. package/package.json +64 -63
@@ -0,0 +1,339 @@
1
+ # Shared Concepts Reference
2
+
3
+ > **Single Source of Truth** - This document defines common concepts used across all MCP-SQLEW documentation. Always reference this file for authoritative definitions.
4
+
5
+ ## Table of Contents
6
+ - [Architecture Layers](#architecture-layers)
7
+ - [Enum Values Reference](#enum-values-reference)
8
+ - [Atomic Mode Explained](#atomic-mode-explained)
9
+ - [Action Parameter Requirement](#action-parameter-requirement)
10
+
11
+ ---
12
+
13
+ ## Architecture Layers
14
+
15
+ The system uses a 5-layer architecture for organizing decisions, constraints, file changes, and tasks:
16
+
17
+ ### 1. **presentation** - User Interface Layer
18
+ **Definition**: Components that handle user interaction and data presentation.
19
+
20
+ **Examples**:
21
+ - React/Vue components, UI templates
22
+ - API endpoints (REST/GraphQL controllers)
23
+ - CLI command handlers
24
+ - Web forms and validation logic
25
+ - Response formatting and serialization
26
+
27
+ **When to Use**: Anything users directly interact with or that formats data for external consumption.
28
+
29
+ ---
30
+
31
+ ### 2. **business** - Business Logic Layer
32
+ **Definition**: Core application logic, business rules, and domain operations.
33
+
34
+ **Examples**:
35
+ - Service classes and business workflows
36
+ - Domain models and entities
37
+ - Validation rules and business constraints
38
+ - Use cases and application services
39
+ - State machines and process orchestration
40
+
41
+ **When to Use**: Core logic that defines "what" the application does, independent of how it's presented or stored.
42
+
43
+ ---
44
+
45
+ ### 3. **data** - Data Access Layer
46
+ **Definition**: Components responsible for data persistence and retrieval.
47
+
48
+ **Examples**:
49
+ - Database schemas and migrations
50
+ - Repository patterns and ORMs
51
+ - Data access objects (DAOs)
52
+ - Query builders and stored procedures
53
+ - Database connection management
54
+
55
+ **When to Use**: Anything that reads from or writes to persistent storage.
56
+
57
+ ---
58
+
59
+ ### 4. **infrastructure** - Infrastructure Layer
60
+ **Definition**: Technical capabilities and external service integrations.
61
+
62
+ **Examples**:
63
+ - Authentication/authorization mechanisms
64
+ - Logging and monitoring systems
65
+ - Message queues and event buses
66
+ - Email/SMS service integrations
67
+ - File storage and CDN integrations
68
+ - Caching mechanisms (Redis, Memcached)
69
+
70
+ **When to Use**: Supporting services that provide technical capabilities to other layers.
71
+
72
+ ---
73
+
74
+ ### 5. **cross-cutting** - Cross-Cutting Concerns
75
+ **Definition**: Aspects that span multiple layers or affect the entire application.
76
+
77
+ **Examples**:
78
+ - Error handling strategies
79
+ - Security policies and encryption
80
+ - Performance optimization patterns
81
+ - Internationalization (i18n)
82
+ - Audit logging across all layers
83
+ - Configuration management
84
+
85
+ **When to Use**: Concerns that don't belong to a single layer and affect multiple parts of the system.
86
+
87
+ ---
88
+
89
+ ## Enum Values Reference
90
+
91
+ ### layer (Architecture Layers)
92
+ ```typescript
93
+ type Layer =
94
+ | "presentation" // UI, API endpoints, user interaction
95
+ | "business" // Core logic, domain models, workflows
96
+ | "data" // Database, repositories, persistence
97
+ | "infrastructure" // Auth, logging, external services
98
+ | "cross-cutting" // Security, error handling, i18n
99
+ ```
100
+
101
+ ### status (Decision/Entity Status)
102
+ ```typescript
103
+ type Status =
104
+ | "active" // Currently in use and valid (default)
105
+ | "deprecated" // Outdated but not removed, scheduled for removal
106
+ | "draft" // Proposed but not yet approved/implemented
107
+ ```
108
+
109
+ ### msg_type (Message Type)
110
+ ```typescript
111
+ type MessageType =
112
+ | "decision" // Decision announcement or update
113
+ | "warning" // Alert or cautionary message
114
+ | "request" // Request for action or input
115
+ | "info" // Informational message
116
+ ```
117
+
118
+ ### priority (Priority Level)
119
+ ```typescript
120
+ type Priority =
121
+ | "low" // Can be addressed later
122
+ | "medium" // Normal priority (default)
123
+ | "high" // Should be addressed soon
124
+ | "critical" // Requires immediate attention
125
+ ```
126
+
127
+ ### change_type (File Change Type)
128
+ ```typescript
129
+ type ChangeType =
130
+ | "created" // New file added
131
+ | "modified" // Existing file changed
132
+ | "deleted" // File removed
133
+ ```
134
+
135
+ ### category (Constraint Categories)
136
+ ```typescript
137
+ type ConstraintCategory =
138
+ | "performance" // Performance requirements and limits
139
+ | "architecture" // Architectural rules and patterns
140
+ | "security" // Security policies and restrictions
141
+ ```
142
+
143
+ ### task_status (Kanban Task Status)
144
+ ```typescript
145
+ type TaskStatus =
146
+ | "todo" // Not started, ready to begin
147
+ | "in_progress" // Currently being worked on
148
+ | "waiting_review" // Completed, awaiting review/approval
149
+ | "blocked" // Cannot proceed due to blocker
150
+ | "done" // Completed and approved
151
+ | "archived" // Archived for historical reference
152
+ ```
153
+
154
+ **Valid Transitions** (enforced by state machine):
155
+ - `todo` → `in_progress`, `blocked`, `archived`
156
+ - `in_progress` → `waiting_review`, `blocked`, `todo`, `archived`
157
+ - `waiting_review` → `done`, `in_progress`, `blocked`, `archived`
158
+ - `blocked` → `todo`, `in_progress`, `archived`
159
+ - `done` → `archived`
160
+ - `archived` → (terminal state, no transitions)
161
+
162
+ **Auto-Stale Detection**:
163
+ - `in_progress` >2 hours → auto-move to `waiting_review`
164
+ - `waiting_review` >24 hours → auto-move to `todo`
165
+
166
+ ---
167
+
168
+ ## Atomic Mode Explained
169
+
170
+ ### What is Atomic Mode?
171
+
172
+ **Atomic mode** determines how batch operations handle failures:
173
+
174
+ - **`atomic: true`** (All-or-Nothing)
175
+ - ALL operations succeed, or ALL fail
176
+ - Uses database transactions
177
+ - Rollback on any error
178
+ - Data consistency guaranteed
179
+
180
+ - **`atomic: false`** (Best-Effort)
181
+ - Each operation attempted independently
182
+ - Partial success possible
183
+ - Failed items reported in response
184
+ - Maximum throughput
185
+
186
+ ### When to Use Each Mode
187
+
188
+ #### Use `atomic: true` (Default) When:
189
+ - **Data consistency is critical**
190
+ - Financial transactions
191
+ - Multi-step workflows that must complete together
192
+ - Related records that must all exist or none exist
193
+
194
+ - **Validation is important**
195
+ - You want to validate ALL items before committing ANY
196
+ - One invalid item should prevent all changes
197
+
198
+ - **Examples**:
199
+ ```typescript
200
+ // All 3 decisions must be set together or none at all
201
+ set_batch({
202
+ decisions: [
203
+ { key: "auth_method", value: "jwt", layer: "infrastructure" },
204
+ { key: "session_timeout", value: "3600", layer: "infrastructure" },
205
+ { key: "refresh_token_enabled", value: "true", layer: "infrastructure" }
206
+ ],
207
+ atomic: true // If any fails, rollback all
208
+ })
209
+ ```
210
+
211
+ #### Use `atomic: false` When:
212
+ - **Partial success is acceptable**
213
+ - Bulk imports where some failures are expected
214
+ - Idempotent operations (safe to retry)
215
+ - Performance is critical
216
+
217
+ - **AI agents making best-effort updates**
218
+ - Don't want one bad item to block all others
219
+ - Can handle partial success in response
220
+
221
+ - **Examples**:
222
+ ```typescript
223
+ // Try to send all messages, report which ones failed
224
+ send_batch({
225
+ messages: [/* 50 messages */],
226
+ atomic: false // Send as many as possible
227
+ })
228
+ ```
229
+
230
+ ### Batch Operation Support
231
+
232
+ Currently supported in:
233
+ - `decision` tool: `action: "set_batch"` (atomic parameter available)
234
+ - `message` tool: `action: "send_batch"` (atomic parameter available)
235
+ - `file` tool: `action: "record_batch"` (atomic parameter available)
236
+ - `task` tool: `action: "batch_create"` (atomic parameter available)
237
+
238
+ ### Performance Implications
239
+
240
+ - **Atomic mode (`atomic: true`)**:
241
+ - Slower (transaction overhead)
242
+ - Higher memory usage (holds all changes until commit)
243
+ - Safer (guaranteed consistency)
244
+
245
+ - **Non-atomic mode (`atomic: false`)**:
246
+ - Faster (no transaction overhead)
247
+ - Lower memory usage (commit per operation)
248
+ - More flexible (partial success handling)
249
+
250
+ ---
251
+
252
+ ## Action Parameter Requirement
253
+
254
+ ### Why is `action` Required?
255
+
256
+ **All MCP tools in this system use action-based routing**. The `action` parameter is **REQUIRED** in every tool call.
257
+
258
+ ### Design Rationale
259
+
260
+ 1. **Token Efficiency** (96% reduction achieved)
261
+ - Single tool with multiple actions vs. many separate tools
262
+ - 20 tools → 7 tools (v2.0.0 → v3.0.0)
263
+ - Tool definitions: 12,848 tokens → 481 tokens
264
+
265
+ 2. **Logical Grouping**
266
+ - Related operations grouped in one tool
267
+ - `decision` tool handles all decision operations
268
+ - `message` tool handles all messaging operations
269
+ - Etc.
270
+
271
+ 3. **Discoverability**
272
+ - Each tool's actions are documented together
273
+ - `action: "help"` provides on-demand documentation
274
+ - Reduces upfront token cost (no documentation until requested)
275
+
276
+ ### Common Error
277
+
278
+ ```json
279
+ ❌ ERROR: "Unknown action: undefined"
280
+ ```
281
+
282
+ **Cause**: Missing `action` parameter
283
+
284
+ **Fix**: Always include `action` as the first parameter:
285
+ ```json
286
+ ✅ CORRECT:
287
+ {
288
+ "action": "get",
289
+ "key": "auth_method"
290
+ }
291
+
292
+ ❌ INCORRECT:
293
+ {
294
+ "key": "auth_method" // Missing action parameter
295
+ }
296
+ ```
297
+
298
+ ### Available Actions by Tool
299
+
300
+ - **decision**: `set`, `get`, `list`, `search_tags`, `search_layer`, `versions`, `quick_set`, `search_advanced`, `set_batch`, `has_updates`, `set_from_template`, `create_template`, `list_templates`, `hard_delete`, `help`
301
+ - **message**: `send`, `get`, `mark_read`, `send_batch`, `help`
302
+ - **file**: `record`, `get`, `check_lock`, `record_batch`, `help`
303
+ - **constraint**: `add`, `get`, `deactivate`, `help`
304
+ - **stats**: `layer_summary`, `db_stats`, `clear`, `activity_log`, `flush`, `help`
305
+ - **config**: `get`, `update`, `help`
306
+ - **task**: `create`, `update`, `get`, `list`, `move`, `link`, `archive`, `batch_create`, `help`
307
+
308
+ ### Getting Help
309
+
310
+ Every tool supports `action: "help"` for comprehensive documentation:
311
+ ```json
312
+ {
313
+ "action": "help"
314
+ }
315
+ ```
316
+
317
+ This returns detailed usage instructions, parameter requirements, valid values, and examples for that specific tool.
318
+
319
+ ---
320
+
321
+ ## Database Enum Mappings
322
+
323
+ For reference, enum values are stored as integers in the database:
324
+
325
+ - **status**: 1=active, 2=deprecated, 3=draft
326
+ - **msg_type**: 1=decision, 2=warning, 3=request, 4=info
327
+ - **priority**: 1=low, 2=medium, 3=high, 4=critical
328
+ - **change_type**: 1=created, 2=modified, 3=deleted
329
+ - **task_status**: 1=todo, 2=in_progress, 3=waiting_review, 4=blocked, 5=done, 6=archived
330
+
331
+ The MCP tools handle string↔integer conversion automatically. Always use string values in tool calls.
332
+
333
+ ---
334
+
335
+ ## Version History
336
+
337
+ - **v3.0.0**: Added task_status enum and Auto-Stale Detection section
338
+ - **v2.1.0**: Added Atomic Mode Explained section
339
+ - **v2.0.0**: Initial creation with action-based API concepts