sqlew 2.1.4 → 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 -605
  2. package/README.md +302 -690
  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 -213
  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 -648
  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 -64
@@ -0,0 +1,280 @@
1
+ # Migration Chain Documentation
2
+
3
+ This document describes the complete migration path from v1.0.0 to v2.1.0 for mcp-sqlew databases.
4
+
5
+ ## Schema Version History
6
+
7
+ ### v1.0.0 (Initial Release)
8
+ - **Table Names:** No prefixes
9
+ - Master: `agents`, `files`, `context_keys`, `constraint_categories`, `layers`, `tags`, `scopes`
10
+ - Transaction: `decisions`, `decisions_numeric`, `decision_history`, `decision_tags`, `decision_scopes`, `agent_messages`, `file_changes`, `constraints`, `constraint_tags`
11
+ - Views: `tagged_decisions`, `active_context`, `layer_summary`, `unread_messages_by_priority`, `recent_file_changes`, `tagged_constraints`
12
+ - Triggers: `auto_delete_old_messages`, `auto_delete_old_file_changes`, `record_decision_history`
13
+ - **Configuration:** No `config` table (hardcoded settings)
14
+ - **Comments:** Japanese
15
+
16
+ ### v1.1.0 - v1.1.2 & v2.0.0 (Table Prefixes)
17
+ - **Table Names:** WITH prefixes
18
+ - Master: `m_agents`, `m_files`, `m_context_keys`, `m_constraint_categories`, `m_layers`, `m_tags`, `m_scopes`, **`m_config` (NEW)**
19
+ - Transaction: `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`
20
+ - Views: `v_tagged_decisions`, `v_active_context`, `v_layer_summary`, `v_unread_messages_by_priority`, `v_recent_file_changes`, `v_tagged_constraints`
21
+ - Triggers: `trg_record_decision_history` (auto-delete triggers removed)
22
+ - **Configuration:** `m_config` table added with weekend-aware auto-deletion settings
23
+ - **Comments:** Japanese
24
+ - **Notes:**
25
+ - v1.1.1: Hotfix for migration failure (creates m_config if missing)
26
+ - v1.1.2: Hotfix for schema validation (checks for prefixed names)
27
+ - v2.0.0: API changes only (20 tools → 6 action-based tools), **no schema changes**
28
+
29
+ ### v2.1.0 (Feature Release - Current)
30
+ - **New Tables:**
31
+ - `t_activity_log` - Automatic activity logging (agent_id, action_type, target, layer_id, details, ts)
32
+ - `t_decision_templates` - Decision templates (name, defaults, required_fields, created_by, ts)
33
+ - **New Triggers:**
34
+ - `trg_log_decision_set` - Auto-log decision creation
35
+ - `trg_log_decision_update` - Auto-log decision updates
36
+ - `trg_log_message_send` - Auto-log message sending
37
+ - `trg_log_file_record` - Auto-log file changes
38
+ - **New Indexes:**
39
+ - `idx_activity_log_ts` - Time-based activity queries
40
+ - `idx_activity_log_agent` - Agent-based activity queries
41
+ - `idx_activity_log_action` - Action type filtering
42
+ - **Comments:** English (translated from Japanese)
43
+ - **Built-in Data:** 5 decision templates seeded
44
+
45
+ ## Migration Scripts
46
+
47
+ ### 1. v1.0.0 → v1.1.x: add-table-prefixes.ts
48
+ **Purpose:** Rename all tables to add category-based prefixes and create m_config table
49
+
50
+ **Actions:**
51
+ 1. Drop old views (they reference old table names)
52
+ 2. Drop old triggers
53
+ 3. Rename master tables (agents → m_agents, etc.)
54
+ 4. Rename transaction tables (decisions → t_decisions, etc.)
55
+ 5. Create m_config table if missing
56
+ 6. Insert default config values
57
+ 7. Schema initialization creates new views/triggers
58
+
59
+ **Transaction:** Yes (rollback on failure)
60
+ **Auto-detect:** Checks for existence of `agents` (old) and absence of `m_agents` (new)
61
+
62
+ ### 2. v1.1.x / v2.0.0 → v2.1.0: add-v2.1.0-features.ts
63
+ **Purpose:** Add activity logging and template system
64
+
65
+ **Actions:**
66
+ 1. Create `t_activity_log` table with 3 indexes
67
+ 2. Create `t_decision_templates` table
68
+ 3. Create 4 activity logging triggers
69
+ 4. Seed 5 built-in templates
70
+
71
+ **Transaction:** Yes (rollback on failure)
72
+ **Auto-detect:** Checks for absence of `t_activity_log` OR `t_decision_templates`
73
+
74
+ ## Migration Execution Order
75
+
76
+ The migrations run automatically on server startup in this order:
77
+
78
+ ```
79
+ 1. Check v1.0.0 → v1.1.x migration (add-table-prefixes.ts)
80
+ ├─ If needed: Run migration
81
+ ├─ Run schema initialization (creates views/triggers)
82
+ └─ Continue to next check
83
+
84
+ 2. Check v1.1.x/v2.0.0 → v2.1.0 migration (add-v2.1.0-features.ts)
85
+ ├─ If needed: Run migration
86
+ └─ Continue
87
+
88
+ 3. Validate schema integrity
89
+ ├─ Check all required tables exist
90
+ ├─ Check all required views exist
91
+ ├─ Check all required triggers exist
92
+ ├─ Verify standard data (5 layers, 3 categories, 10+ tags)
93
+ └─ Exit with error if validation fails
94
+
95
+ 4. Start MCP server
96
+ ```
97
+
98
+ ## Complete Migration Paths
99
+
100
+ ### Path 1: v1.0.0 → v2.1.0 (Full Chain)
101
+ ```
102
+ v1.0.0 (no prefixes, no config)
103
+ ↓ add-table-prefixes.ts
104
+ v1.1.0 (prefixes, m_config added)
105
+ ↓ add-v2.1.0-features.ts
106
+ v2.1.0 (activity_log, templates added)
107
+ ```
108
+
109
+ **Steps:**
110
+ 1. Start server with v1.0.0 database
111
+ 2. Detects unprefixed tables → runs add-table-prefixes.ts
112
+ 3. Migration adds prefixes and m_config table
113
+ 4. Schema initialization creates new views/triggers
114
+ 5. Detects missing v2.1.0 tables → runs add-v2.1.0-features.ts
115
+ 6. Migration adds t_activity_log, t_decision_templates, 4 triggers
116
+ 7. Schema validation passes
117
+ 8. Server starts with v2.1.0 schema
118
+
119
+ ### Path 2: v1.1.x / v2.0.0 → v2.1.0 (Single Migration)
120
+ ```
121
+ v1.1.0-v1.1.2 or v2.0.0 (prefixes, m_config present)
122
+ ↓ add-v2.1.0-features.ts
123
+ v2.1.0 (activity_log, templates added)
124
+ ```
125
+
126
+ **Steps:**
127
+ 1. Start server with v1.1.x or v2.0.0 database
128
+ 2. Detects prefixed tables exist → skips add-table-prefixes.ts
129
+ 3. Detects missing v2.1.0 tables → runs add-v2.1.0-features.ts
130
+ 4. Migration adds t_activity_log, t_decision_templates, 4 triggers
131
+ 5. Schema validation passes
132
+ 6. Server starts with v2.1.0 schema
133
+
134
+ ### Path 3: Fresh Install → v2.1.0 (No Migration)
135
+ ```
136
+ Empty database
137
+ ↓ schema initialization
138
+ v2.1.0 (full schema created)
139
+ ```
140
+
141
+ **Steps:**
142
+ 1. Start server with empty/new database path
143
+ 2. No existing schema detected
144
+ 3. Schema initialization runs (executes assets/schema.sql)
145
+ 4. All tables, views, triggers created directly from v2.1.0 schema
146
+ 5. Schema validation passes
147
+ 6. Server starts with v2.1.0 schema
148
+
149
+ ## Schema Validation (v2.1.0 Requirements)
150
+
151
+ The schema validator (`src/schema.ts`) checks for:
152
+
153
+ **Tables (19 total):**
154
+ - Master (8): m_agents, m_files, m_context_keys, m_constraint_categories, m_layers, m_tags, m_scopes, m_config
155
+ - Transaction (11): 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**, **t_decision_templates**
156
+
157
+ **Views (6 total):**
158
+ - v_tagged_decisions, v_active_context, v_layer_summary, v_unread_messages_by_priority, v_recent_file_changes, v_tagged_constraints
159
+
160
+ **Triggers (5 total):**
161
+ - trg_record_decision_history
162
+ - **trg_log_decision_set** (NEW in v2.1.0)
163
+ - **trg_log_decision_update** (NEW in v2.1.0)
164
+ - **trg_log_message_send** (NEW in v2.1.0)
165
+ - **trg_log_file_record** (NEW in v2.1.0)
166
+
167
+ **Standard Data:**
168
+ - 5 layers (presentation, business, data, infrastructure, cross-cutting)
169
+ - 3 constraint categories (performance, architecture, security)
170
+ - 10+ tags (authentication, authorization, performance, security, api, database, caching, testing, validation, error-handling)
171
+ - 3+ config entries (autodelete_ignore_weekend, autodelete_message_hours, autodelete_file_history_days)
172
+
173
+ ## Testing Migration Chain
174
+
175
+ ### Test 1: v1.0.0 → v2.1.0
176
+ ```bash
177
+ # Create v1.0.0 database (use git checkout)
178
+ git checkout v1.0.0
179
+ node dist/index.js --db-path=.test/v1.0.0.db
180
+ # Let it initialize with v1.0.0 schema
181
+ # Stop server (Ctrl+C)
182
+
183
+ # Upgrade to v2.1.0
184
+ git checkout main
185
+ npm run build
186
+ node dist/index.js --db-path=.test/v1.0.0.db
187
+ # Should run BOTH migrations automatically
188
+ # Check logs for:
189
+ # "Migration required: Adding table prefixes (v1.2.0 -> v1.3.0)"
190
+ # "Migration required: Adding v2.1.0 features (v2.0.0 -> v2.1.0)"
191
+ ```
192
+
193
+ ### Test 2: v2.0.0 → v2.1.0
194
+ ```bash
195
+ # Create v2.0.0 database
196
+ git checkout v2.0.0
197
+ npm run build
198
+ node dist/index.js --db-path=.test/v2.0.0.db
199
+ # Stop server
200
+
201
+ # Upgrade to v2.1.0
202
+ git checkout main
203
+ npm run build
204
+ node dist/index.js --db-path=.test/v2.0.0.db
205
+ # Should run ONLY v2.1.0 migration
206
+ # Check logs for:
207
+ # "Migration required: Adding v2.1.0 features (v2.0.0 -> v2.1.0)"
208
+ ```
209
+
210
+ ### Test 3: Fresh v2.1.0
211
+ ```bash
212
+ # Fresh install
213
+ node dist/index.js --db-path=.test/fresh-v2.1.0.db
214
+ # Should initialize directly to v2.1.0
215
+ # No migration messages
216
+ ```
217
+
218
+ ## Rollback Strategy
219
+
220
+ If a migration fails:
221
+ 1. **Transaction rollback** - All changes reverted automatically
222
+ 2. **Database unchanged** - Original schema preserved
223
+ 3. **Server exits** - Prevents running with corrupted schema
224
+ 4. **Error message displayed** - Clear indication of failure
225
+
226
+ To manually rollback:
227
+ ```bash
228
+ # Restore from backup (recommended)
229
+ cp backup.db current.db
230
+
231
+ # Or delete and reinitialize
232
+ rm .sqlew/sqlew.db
233
+ node dist/index.js # Creates fresh v2.1.0 database
234
+ ```
235
+
236
+ ## Troubleshooting
237
+
238
+ ### Migration Doesn't Run
239
+ - Check that database file exists and is accessible
240
+ - Verify SQLite version supports required features
241
+ - Check file permissions
242
+
243
+ ### Migration Fails Midway
244
+ - Check error message in console
245
+ - Database is automatically rolled back
246
+ - No partial state - safe to retry
247
+
248
+ ### Schema Validation Fails After Migration
249
+ - Report as bug (migration should guarantee valid schema)
250
+ - Check logs for missing components
251
+ - May need to restore from backup or delete database
252
+
253
+ ## Future Migrations
254
+
255
+ When adding new features in future versions:
256
+
257
+ 1. Create new migration script: `src/migrations/add-vX.Y.Z-features.ts`
258
+ 2. Implement `needsMigration()`, `runMigration()`, `getMigrationInfo()`
259
+ 3. Import in `src/database.ts`
260
+ 4. Add check AFTER previous migrations, BEFORE schema validation
261
+ 5. Update `src/schema.ts` validation requirements
262
+ 6. Update `assets/schema.sql` with new schema
263
+ 7. Document in CHANGELOG.md and this file
264
+ 8. Test complete migration chain from oldest supported version
265
+
266
+ ## Backward Compatibility
267
+
268
+ **Database:** v2.1.0 can read and migrate v1.0.0, v1.1.x, and v2.0.0 databases
269
+ **API:** v2.0.0 tool calls work unchanged in v2.1.0 (backward compatible)
270
+ **Forward Compatibility:** Older versions CANNOT read v2.1.0 databases (missing tables/triggers)
271
+
272
+ ## Summary
273
+
274
+ - ✅ v1.0.0 → v2.1.0: Full migration chain supported
275
+ - ✅ v1.1.x → v2.1.0: Single migration
276
+ - ✅ v2.0.0 → v2.1.0: Single migration
277
+ - ✅ Fresh install: Direct v2.1.0 schema
278
+ - ✅ Transaction-based: Safe rollback on failure
279
+ - ✅ Auto-detect: Runs only needed migrations
280
+ - ✅ Schema validation: Ensures integrity