sqlew 2.1.4 → 3.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 (97) hide show
  1. package/CHANGELOG.md +891 -605
  2. package/LICENSE +49 -18
  3. package/README.md +337 -690
  4. package/assets/kanban-style.png +0 -0
  5. package/assets/schema.sql +532 -402
  6. package/dist/database.d.ts +9 -0
  7. package/dist/database.d.ts.map +1 -1
  8. package/dist/database.js +33 -34
  9. package/dist/database.js.map +1 -1
  10. package/dist/index.js +1050 -215
  11. package/dist/index.js.map +1 -1
  12. package/dist/migrations/add-task-tables.d.ts +47 -0
  13. package/dist/migrations/add-task-tables.d.ts.map +1 -0
  14. package/dist/migrations/add-task-tables.js +285 -0
  15. package/dist/migrations/add-task-tables.js.map +1 -0
  16. package/dist/migrations/index.d.ts +96 -0
  17. package/dist/migrations/index.d.ts.map +1 -0
  18. package/dist/migrations/index.js +239 -0
  19. package/dist/migrations/index.js.map +1 -0
  20. package/dist/migrations/migrate-decisions-to-tasks.d.ts +61 -0
  21. package/dist/migrations/migrate-decisions-to-tasks.d.ts.map +1 -0
  22. package/dist/migrations/migrate-decisions-to-tasks.js +442 -0
  23. package/dist/migrations/migrate-decisions-to-tasks.js.map +1 -0
  24. package/dist/schema.d.ts.map +1 -1
  25. package/dist/schema.js +14 -3
  26. package/dist/schema.js.map +1 -1
  27. package/dist/tools/constraints.d.ts +4 -0
  28. package/dist/tools/constraints.d.ts.map +1 -1
  29. package/dist/tools/constraints.js +6 -27
  30. package/dist/tools/constraints.js.map +1 -1
  31. package/dist/tools/context.d.ts +17 -1
  32. package/dist/tools/context.d.ts.map +1 -1
  33. package/dist/tools/context.js +195 -190
  34. package/dist/tools/context.js.map +1 -1
  35. package/dist/tools/files.d.ts.map +1 -1
  36. package/dist/tools/files.js +113 -166
  37. package/dist/tools/files.js.map +1 -1
  38. package/dist/tools/messaging.d.ts +2 -9
  39. package/dist/tools/messaging.d.ts.map +1 -1
  40. package/dist/tools/messaging.js +67 -126
  41. package/dist/tools/messaging.js.map +1 -1
  42. package/dist/tools/tasks.d.ts +90 -0
  43. package/dist/tools/tasks.d.ts.map +1 -0
  44. package/dist/tools/tasks.js +844 -0
  45. package/dist/tools/tasks.js.map +1 -0
  46. package/dist/tools/utils.d.ts +8 -1
  47. package/dist/tools/utils.d.ts.map +1 -1
  48. package/dist/tools/utils.js +50 -21
  49. package/dist/tools/utils.js.map +1 -1
  50. package/dist/types.d.ts +29 -0
  51. package/dist/types.d.ts.map +1 -1
  52. package/dist/utils/batch.d.ts +69 -0
  53. package/dist/utils/batch.d.ts.map +1 -0
  54. package/dist/utils/batch.js +148 -0
  55. package/dist/utils/batch.js.map +1 -0
  56. package/dist/utils/query-builder.d.ts +68 -0
  57. package/dist/utils/query-builder.d.ts.map +1 -0
  58. package/dist/utils/query-builder.js +116 -0
  59. package/dist/utils/query-builder.js.map +1 -0
  60. package/dist/utils/task-stale-detection.d.ts +28 -0
  61. package/dist/utils/task-stale-detection.d.ts.map +1 -0
  62. package/dist/utils/task-stale-detection.js +92 -0
  63. package/dist/utils/task-stale-detection.js.map +1 -0
  64. package/dist/utils/validators.d.ts +57 -0
  65. package/dist/utils/validators.d.ts.map +1 -0
  66. package/dist/utils/validators.js +117 -0
  67. package/dist/utils/validators.js.map +1 -0
  68. package/dist/watcher/file-watcher.d.ts +75 -0
  69. package/dist/watcher/file-watcher.d.ts.map +1 -0
  70. package/dist/watcher/file-watcher.js +374 -0
  71. package/dist/watcher/file-watcher.js.map +1 -0
  72. package/dist/watcher/index.d.ts +8 -0
  73. package/dist/watcher/index.d.ts.map +1 -0
  74. package/dist/watcher/index.js +7 -0
  75. package/dist/watcher/index.js.map +1 -0
  76. package/dist/watcher/test-executor.d.ts +23 -0
  77. package/dist/watcher/test-executor.d.ts.map +1 -0
  78. package/dist/watcher/test-executor.js +226 -0
  79. package/dist/watcher/test-executor.js.map +1 -0
  80. package/docs/ACCEPTANCE_CRITERIA.md +625 -0
  81. package/docs/AI_AGENT_GUIDE.md +1471 -648
  82. package/{ARCHITECTURE.md → docs/ARCHITECTURE.md} +636 -636
  83. package/docs/AUTO_FILE_TRACKING.md +436 -0
  84. package/docs/BEST_PRACTICES.md +481 -0
  85. package/docs/DECISION_TO_TASK_MIGRATION_GUIDE.md +457 -0
  86. package/docs/MIGRATION_CHAIN.md +280 -0
  87. package/{MIGRATION_v2.md → docs/MIGRATION_v2.md} +538 -538
  88. package/docs/SHARED_CONCEPTS.md +339 -0
  89. package/docs/TASK_ACTIONS.md +854 -0
  90. package/docs/TASK_LINKING.md +729 -0
  91. package/docs/TASK_MIGRATION.md +701 -0
  92. package/docs/TASK_OVERVIEW.md +363 -0
  93. package/docs/TASK_SYSTEM.md +1244 -0
  94. package/docs/TOOL_REFERENCE.md +471 -0
  95. package/docs/TOOL_SELECTION.md +279 -0
  96. package/docs/WORKFLOWS.md +602 -0
  97. package/package.json +65 -64
package/dist/index.js CHANGED
@@ -8,12 +8,14 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
8
8
  import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
9
9
  import { initializeDatabase, closeDatabase, setConfigValue, getAllConfig } from './database.js';
10
10
  import { CONFIG_KEYS } from './constants.js';
11
- import { setDecision, getContext, getDecision, searchByTags, getVersions, searchByLayer, quickSetDecision, searchAdvanced, setDecisionBatch, hasUpdates, setFromTemplate, createTemplate, listTemplates } from './tools/context.js';
11
+ import { setDecision, getContext, getDecision, searchByTags, getVersions, searchByLayer, quickSetDecision, searchAdvanced, setDecisionBatch, hasUpdates, setFromTemplate, createTemplate, listTemplates, hardDeleteDecision } from './tools/context.js';
12
12
  import { sendMessage, getMessages, markRead, sendMessageBatch } from './tools/messaging.js';
13
13
  import { recordFileChange, getFileChanges, checkFileLock, recordFileChangeBatch } from './tools/files.js';
14
14
  import { addConstraint, getConstraints, deactivateConstraint } from './tools/constraints.js';
15
- import { getLayerSummary, clearOldData, getStats, getActivityLog } from './tools/utils.js';
15
+ import { getLayerSummary, clearOldData, getStats, getActivityLog, flushWAL } from './tools/utils.js';
16
16
  import { getConfig, updateConfig } from './tools/config.js';
17
+ import { createTask, updateTask, getTask, listTasks, moveTask, linkTask, archiveTask, batchCreateTasks, taskHelp } from './tools/tasks.js';
18
+ import { FileWatcher } from './watcher/index.js';
17
19
  // Parse command-line arguments
18
20
  const args = process.argv.slice(2);
19
21
  const parsedArgs = {};
@@ -80,8 +82,8 @@ catch (error) {
80
82
  }
81
83
  // Create MCP server
82
84
  const server = new Server({
83
- name: 'mcp-sklew',
84
- version: '2.1.4',
85
+ name: 'mcp-sqlew',
86
+ version: '3.0.0',
85
87
  }, {
86
88
  capabilities: {
87
89
  tools: {},
@@ -93,52 +95,19 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
93
95
  tools: [
94
96
  {
95
97
  name: 'decision',
96
- description: `**REQUIRED PARAMETER**: action (must be specified in ALL calls)
97
-
98
- Context Management - Store decisions with metadata (tags, layers, versions, scopes)
99
-
100
- ## Quick Examples
101
- - Set decision: {action: "set", key: "auth_method", value: "jwt", layer: "business", tags: ["security"]}
102
- - Get decision: {action: "get", key: "auth_method"}
103
- - List decisions: {action: "list", status: "active", layer: "business"}
104
-
105
- ## Parameter Requirements by Action
106
-
107
- | Action | Required Parameters | Optional Parameters |
108
- |--------|-------------------|---------------------|
109
- | set | action, key, value, layer | agent, version, status, tags, scopes |
110
- | get | action, key | version |
111
- | list | action | status, layer, tags, scope, tag_match, limit, offset |
112
- | search_tags | action, tags | match_mode, status, layer |
113
- | search_layer | action, layer | status, include_tags |
114
- | versions | action, key | - |
115
- | quick_set | action, key, value | agent, layer, version, status, tags, scopes |
116
- | search_advanced | action | layers, tags_all, tags_any, exclude_tags, scopes, updated_after, updated_before, decided_by, statuses, search_text, sort_by, sort_order, limit, offset |
117
- | set_batch | action, decisions | atomic |
118
- | has_updates | action, agent_name, since_timestamp | - |
119
- | set_from_template | action, template, key, value, layer | agent, version, status, tags, scopes |
120
- | create_template | action, name, defaults | required_fields, created_by |
121
- | list_templates | action | - |
122
-
123
- ## Common Errors & Fixes
124
- - "Unknown action: undefined" → Add action parameter (REQUIRED!)
125
- - "Parameter \\"value\\" is required" → Provide value parameter directly (not nested in defaults)
126
- - "Invalid layer" → Use: presentation, business, data, infrastructure, cross-cutting
127
- - "Invalid status" → Use: active, deprecated, draft
128
-
129
- ## Valid Values
130
- - **layer**: presentation | business | data | infrastructure | cross-cutting
131
- - **status**: active | deprecated | draft
132
- - **tag_match**: AND | OR
133
-
134
- Use action: "help" for detailed documentation.`,
98
+ description: `**REQUIRED PARAMETER**: action (must be specified in ALL calls)
99
+
100
+ Context Management - Store decisions with metadata (tags, layers, versions, scopes)
101
+
102
+ Use action: "help" for detailed documentation.
103
+ Use action: "example" for comprehensive usage examples.`,
135
104
  inputSchema: {
136
105
  type: 'object',
137
106
  properties: {
138
107
  action: {
139
108
  type: 'string',
140
109
  description: 'Action',
141
- enum: ['set', 'get', 'list', 'search_tags', 'search_layer', 'versions', 'quick_set', 'search_advanced', 'set_batch', 'has_updates', 'set_from_template', 'create_template', 'list_templates', 'help']
110
+ enum: ['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', 'example']
142
111
  },
143
112
  key: { type: 'string' },
144
113
  value: { type: ['string', 'number'] },
@@ -179,41 +148,16 @@ Use action: "help" for detailed documentation.`,
179
148
  },
180
149
  {
181
150
  name: 'message',
182
- description: `**REQUIRED PARAMETER**: action (must be specified in ALL calls)
183
-
184
- Agent Messaging - Send messages between agents with priority levels and read tracking
185
-
186
- ## Quick Examples
187
- - Send message: {action: "send", from_agent: "bot1", msg_type: "info", message: "Task complete"}
188
- - Get messages: {action: "get", agent_name: "bot1", unread_only: true}
189
- - Mark as read: {action: "mark_read", agent_name: "bot1", message_ids: [1, 2, 3]}
190
-
191
- ## Parameter Requirements by Action
192
-
193
- | Action | Required Parameters | Optional Parameters |
194
- |--------|-------------------|---------------------|
195
- | send | action, from_agent, msg_type, message | to_agent, priority, payload |
196
- | get | action, agent_name | unread_only, priority_filter, msg_type_filter, limit |
197
- | mark_read | action, agent_name, message_ids | - |
198
- | send_batch | action, messages | atomic |
199
-
200
- ## Common Errors & Fixes
201
- - "Unknown action: undefined" → Add action parameter (REQUIRED!)
202
- - "Invalid msg_type" → Use: decision, warning, request, info
203
- - "Invalid priority" → Use: low, medium, high, critical
204
- - "message_ids array cannot be empty" → Provide at least one message ID
205
-
206
- ## Valid Values
207
- - **msg_type**: decision | warning | request | info
208
- - **priority**: low | medium | high | critical (default: medium)
209
- - **to_agent**: agent name or null for broadcast
210
- - **atomic** (batch): true (all-or-nothing) | false (best-effort, recommended for AI agents)
211
-
212
- Use action: "help" for detailed documentation.`,
151
+ description: `**REQUIRED PARAMETER**: action (must be specified in ALL calls)
152
+
153
+ Agent Messaging - Send messages between agents with priority levels and read tracking
154
+
155
+ Use action: "help" for detailed documentation.
156
+ Use action: "example" for comprehensive usage examples.`,
213
157
  inputSchema: {
214
158
  type: 'object',
215
159
  properties: {
216
- action: { type: 'string', description: 'Action (use "help" for usage)', enum: ['send', 'get', 'mark_read', 'send_batch', 'help'] },
160
+ action: { type: 'string', description: 'Action (use "help" for usage)', enum: ['send', 'get', 'mark_read', 'send_batch', 'help', 'example'] },
217
161
  agent_name: { type: 'string' },
218
162
  from_agent: { type: 'string' },
219
163
  to_agent: { type: ['string', 'null'] },
@@ -235,41 +179,16 @@ Use action: "help" for detailed documentation.`,
235
179
  },
236
180
  {
237
181
  name: 'file',
238
- description: `**REQUIRED PARAMETER**: action (must be specified in ALL calls)
239
-
240
- File Change Tracking - Track file changes with layer classification and lock detection
241
-
242
- ## Quick Examples
243
- - Record change: {action: "record", file_path: "src/index.ts", agent_name: "bot1", change_type: "modified", layer: "infrastructure"}
244
- - Get changes: {action: "get", agent_name: "bot1", layer: "infrastructure", limit: 10}
245
- - Check lock: {action: "check_lock", file_path: "src/index.ts", lock_duration: 300}
246
-
247
- ## Parameter Requirements by Action
248
-
249
- | Action | Required Parameters | Optional Parameters |
250
- |--------|-------------------|---------------------|
251
- | record | action, file_path, agent_name, change_type | layer, description |
252
- | get | action | file_path, agent_name, layer, change_type, since, limit |
253
- | check_lock | action, file_path | lock_duration |
254
- | record_batch | action, file_changes | atomic |
255
-
256
- ## Common Errors & Fixes
257
- - "Unknown action: undefined" → Add action parameter (REQUIRED!)
258
- - "Invalid change_type" → Use: created, modified, deleted
259
- - "Invalid layer" → Use: presentation, business, data, infrastructure, cross-cutting
260
- - "Parameter \\"file_changes\\" must contain at least one item" → Provide non-empty array
261
-
262
- ## Valid Values
263
- - **change_type**: created | modified | deleted
264
- - **layer**: presentation | business | data | infrastructure | cross-cutting
265
- - **lock_duration**: seconds (default: 300 = 5 minutes)
266
- - **atomic** (batch): true (all-or-nothing) | false (best-effort, recommended for AI agents)
267
-
268
- Use action: "help" for detailed documentation.`,
182
+ description: `**REQUIRED PARAMETER**: action (must be specified in ALL calls)
183
+
184
+ File Change Tracking - Track file changes with layer classification and lock detection
185
+
186
+ Use action: "help" for detailed documentation.
187
+ Use action: "example" for comprehensive usage examples.`,
269
188
  inputSchema: {
270
189
  type: 'object',
271
190
  properties: {
272
- action: { type: 'string', description: 'Action (use "help" for usage)', enum: ['record', 'get', 'check_lock', 'record_batch', 'help'] },
191
+ action: { type: 'string', description: 'Action (use "help" for usage)', enum: ['record', 'get', 'check_lock', 'record_batch', 'help', 'example'] },
273
192
  file_path: { type: 'string' },
274
193
  agent_name: { type: 'string' },
275
194
  change_type: { type: 'string', enum: ['created', 'modified', 'deleted'] },
@@ -287,44 +206,16 @@ Use action: "help" for detailed documentation.`,
287
206
  },
288
207
  {
289
208
  name: 'constraint',
290
- description: `**REQUIRED PARAMETER**: action (must be specified in ALL calls)
291
-
292
- Constraint Management - Manage architectural rules and requirements
293
-
294
- ## What are Constraints vs Decisions?
295
- - **Decision**: Documents a choice that was made ("We chose JWT over sessions")
296
- - **Constraint**: Enforces a rule that must be followed ("API response time must be <100ms")
297
-
298
- ## Quick Examples
299
- - Add constraint: {action: "add", category: "performance", constraint_text: "API response <100ms", priority: "high", layer: "business"}
300
- - Get constraints: {action: "get", category: "performance", active_only: true}
301
- - Deactivate: {action: "deactivate", constraint_id: 5}
302
-
303
- ## Parameter Requirements by Action
304
-
305
- | Action | Required Parameters | Optional Parameters |
306
- |--------|-------------------|---------------------|
307
- | add | action, category, constraint_text | priority, layer, tags, created_by |
308
- | get | action | category, layer, priority, tags, active_only, limit |
309
- | deactivate | action, constraint_id | - |
310
-
311
- ## Common Errors & Fixes
312
- - "Unknown action: undefined" → Add action parameter (REQUIRED!)
313
- - "Invalid category" → Use: performance, architecture, security
314
- - "category and constraint_text are required" → Provide both required fields
315
- - "constraint_id is required" → Provide valid constraint ID number
316
-
317
- ## Valid Values
318
- - **category**: performance | architecture | security
319
- - **priority**: low | medium | high | critical (default: medium)
320
- - **layer**: presentation | business | data | infrastructure | cross-cutting
321
- - **active_only**: true (default) | false
322
-
323
- Use action: "help" for detailed documentation.`,
209
+ description: `**REQUIRED PARAMETER**: action (must be specified in ALL calls)
210
+
211
+ Constraint Management - Manage architectural rules and requirements
212
+
213
+ Use action: "help" for detailed documentation.
214
+ Use action: "example" for comprehensive usage examples.`,
324
215
  inputSchema: {
325
216
  type: 'object',
326
217
  properties: {
327
- action: { type: 'string', description: 'Action (use "help" for usage)', enum: ['add', 'get', 'deactivate', 'help'] },
218
+ action: { type: 'string', description: 'Action (use "help" for usage)', enum: ['add', 'get', 'deactivate', 'help', 'example'] },
328
219
  constraint_id: { type: 'number' },
329
220
  category: { type: 'string', enum: ['performance', 'architecture', 'security'] },
330
221
  constraint_text: { type: 'string' },
@@ -340,43 +231,16 @@ Use action: "help" for detailed documentation.`,
340
231
  },
341
232
  {
342
233
  name: 'stats',
343
- description: `**REQUIRED PARAMETER**: action (must be specified in ALL calls)
344
-
345
- Statistics & Utilities - View stats, activity logs, and manage data cleanup
346
-
347
- ## Quick Examples
348
- - Layer summary: {action: "layer_summary"}
349
- - DB statistics: {action: "db_stats"}
350
- - Clear old data: {action: "clear", messages_older_than_hours: 48, file_changes_older_than_days: 14}
351
- - Activity log: {action: "activity_log", since: "1h", agent_names: ["bot1"], limit: 50}
352
-
353
- ## Parameter Requirements by Action
354
-
355
- | Action | Required Parameters | Optional Parameters |
356
- |--------|-------------------|---------------------|
357
- | layer_summary | action | - |
358
- | db_stats | action | - |
359
- | clear | action | messages_older_than_hours, file_changes_older_than_days |
360
- | activity_log | action | since, agent_names, actions, limit |
361
-
362
- ## Common Errors & Fixes
363
- - "Unknown action: undefined" → Add action parameter (REQUIRED!)
364
- - "Invalid 'since' parameter" → Use relative format (5m, 1h, 2d) or ISO timestamp
365
-
366
- ## Valid Values
367
- - **since**: Relative time (5m, 1h, 2d) or ISO 8601 timestamp
368
- - **agent_names**: Array of agent names or ["*"] for all
369
- - **limit**: Number (default: 100 for activity_log)
370
-
371
- ## Clear Action Behavior
372
- - **Without parameters**: Uses config-based weekend-aware retention
373
- - **With parameters**: Overrides config, no weekend-awareness
374
-
375
- Use action: "help" for detailed documentation.`,
234
+ description: `**REQUIRED PARAMETER**: action (must be specified in ALL calls)
235
+
236
+ Statistics & Utilities - View stats, activity logs, manage data cleanup, and WAL checkpoints
237
+
238
+ Use action: "help" for detailed documentation.
239
+ Use action: "example" for comprehensive usage examples.`,
376
240
  inputSchema: {
377
241
  type: 'object',
378
242
  properties: {
379
- action: { type: 'string', description: 'Action (use "help" for usage)', enum: ['layer_summary', 'db_stats', 'clear', 'activity_log', 'help'] },
243
+ action: { type: 'string', description: 'Action (use "help" for usage)', enum: ['layer_summary', 'db_stats', 'clear', 'activity_log', 'flush', 'help', 'example'] },
380
244
  messages_older_than_hours: { type: 'number' },
381
245
  file_changes_older_than_days: { type: 'number' },
382
246
  since: { type: 'string', description: 'Time filter (e.g., "5m", "1h", "2d" or ISO timestamp)' },
@@ -389,40 +253,16 @@ Use action: "help" for detailed documentation.`,
389
253
  },
390
254
  {
391
255
  name: 'config',
392
- description: `**REQUIRED PARAMETER**: action (must be specified in ALL calls)
393
-
394
- Configuration - Manage auto-deletion settings with weekend-aware retention
395
-
396
- ## Quick Examples
397
- - Get config: {action: "get"}
398
- - Update config: {action: "update", ignoreWeekend: true, messageRetentionHours: 48, fileHistoryRetentionDays: 10}
399
-
400
- ## Parameter Requirements by Action
401
-
402
- | Action | Required Parameters | Optional Parameters |
403
- |--------|-------------------|---------------------|
404
- | get | action | - |
405
- | update | action | ignoreWeekend, messageRetentionHours, fileHistoryRetentionDays |
406
-
407
- ## Common Errors & Fixes
408
- - "Unknown action: undefined" → Add action parameter (REQUIRED!)
409
- - "messageRetentionHours must be between 1 and 168" → Use value 1-168 (1 week max)
410
- - "fileHistoryRetentionDays must be between 1 and 90" → Use value 1-90
411
-
412
- ## Valid Values
413
- - **ignoreWeekend**: true (skip weekends in retention calculation) | false (standard time-based)
414
- - **messageRetentionHours**: 1-168 (default: 24)
415
- - **fileHistoryRetentionDays**: 1-90 (default: 7)
416
-
417
- ## Weekend-Aware Behavior
418
- - **ignoreWeekend=false**: 24h = 24 hours ago (standard)
419
- - **ignoreWeekend=true**: 24h on Monday = Friday (skips Sat/Sun)
420
-
421
- Use action: "help" for detailed documentation.`,
256
+ description: `**REQUIRED PARAMETER**: action (must be specified in ALL calls)
257
+
258
+ Configuration - Manage auto-deletion settings with weekend-aware retention
259
+
260
+ Use action: "help" for detailed documentation.
261
+ Use action: "example" for comprehensive usage examples.`,
422
262
  inputSchema: {
423
263
  type: 'object',
424
264
  properties: {
425
- action: { type: 'string', description: 'Action (use "help" for usage)', enum: ['get', 'update', 'help'] },
265
+ action: { type: 'string', description: 'Action (use "help" for usage)', enum: ['get', 'update', 'help', 'example'] },
426
266
  ignoreWeekend: { type: 'boolean' },
427
267
  messageRetentionHours: { type: 'number', minimum: 1, maximum: 168 },
428
268
  fileHistoryRetentionDays: { type: 'number', minimum: 1, maximum: 90 },
@@ -430,6 +270,42 @@ Use action: "help" for detailed documentation.`,
430
270
  required: ['action'],
431
271
  },
432
272
  },
273
+ {
274
+ name: 'task',
275
+ description: `**REQUIRED PARAMETER**: action (must be specified in ALL calls)
276
+
277
+ Kanban Task Watcher - AI-optimized task management with auto-stale detection
278
+
279
+ Use action: "help" for detailed documentation.
280
+ Use action: "example" for comprehensive usage examples.`,
281
+ inputSchema: {
282
+ type: 'object',
283
+ properties: {
284
+ action: { type: 'string', description: 'Action (use "help" for usage)', enum: ['create', 'update', 'get', 'list', 'move', 'link', 'archive', 'batch_create', 'help', 'example'] },
285
+ task_id: { type: 'number' },
286
+ title: { type: 'string' },
287
+ description: { type: 'string' },
288
+ acceptance_criteria: { type: 'string' },
289
+ notes: { type: 'string' },
290
+ priority: { type: 'number', minimum: 1, maximum: 4 },
291
+ assigned_agent: { type: 'string' },
292
+ created_by_agent: { type: 'string' },
293
+ layer: { type: 'string', enum: ['presentation', 'business', 'data', 'infrastructure', 'cross-cutting'] },
294
+ tags: { type: 'array', items: { type: 'string' } },
295
+ status: { type: 'string', enum: ['todo', 'in_progress', 'waiting_review', 'blocked', 'done', 'archived'] },
296
+ new_status: { type: 'string', enum: ['todo', 'in_progress', 'waiting_review', 'blocked', 'done', 'archived'] },
297
+ link_type: { type: 'string', enum: ['decision', 'constraint', 'file'] },
298
+ target_id: { type: ['string', 'number'] },
299
+ link_relation: { type: 'string' },
300
+ limit: { type: 'number', default: 50 },
301
+ offset: { type: 'number', default: 0 },
302
+ // batch_create parameters
303
+ tasks: { type: 'array', description: 'Array of tasks for batch operation (max: 50)' },
304
+ atomic: { type: 'boolean', description: 'Atomic mode - all succeed or all fail (default: true)' },
305
+ },
306
+ required: ['action'],
307
+ },
308
+ },
433
309
  ],
434
310
  };
435
311
  });
@@ -496,10 +372,59 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
496
372
  case 'list_templates':
497
373
  result = listTemplates(params);
498
374
  break;
375
+ case 'hard_delete':
376
+ result = hardDeleteDecision(params);
377
+ break;
499
378
  case 'help':
500
379
  result = {
501
380
  tool: 'decision',
502
381
  description: 'Manage decisions with metadata (tags, layers, versions, scopes)',
382
+ purpose: {
383
+ title: '⚠️ CRITICAL: Store WHY and REASON, Not WHAT',
384
+ principle: 'Decisions table is for ARCHITECTURAL CONTEXT and REASONING, NOT implementation logs or task completion status',
385
+ what_to_store: {
386
+ correct: [
387
+ 'WHY a design choice was made (e.g., "Chose JWT over sessions because stateless auth scales better for our microservice architecture")',
388
+ 'REASONING behind architecture decisions (e.g., "Moved oscillator_type to MonophonicSynthConfig to separate synthesis methods - FM operators use different config")',
389
+ 'PROBLEM ANALYSIS and solution rationale (e.g., "Nested transaction bug: setDecision wraps in transaction, batch also wraps → solution: extract internal helper without transaction wrapper")',
390
+ 'DESIGN TRADE-OFFS and alternatives considered (e.g., "Query builder limited to simple filters, kept domain-specific logic inline for maintainability")',
391
+ 'CONSTRAINTS and requirements reasoning (e.g., "API response must be <100ms because mobile clients timeout at 200ms")',
392
+ 'BREAKING CHANGES with migration rationale (e.g., "Removed /v1/users endpoint - clients must use /v2/users with pagination for scalability")'
393
+ ],
394
+ incorrect: [
395
+ '❌ Task completion logs (e.g., "Task 5 completed", "Refactoring done", "Tests passing") → Use tasks tool instead',
396
+ '❌ Implementation status (e.g., "Added validators.ts", "Fixed bug in batch_create", "Updated README") → These are WHAT, not WHY',
397
+ '❌ Test results (e.g., "All tests passing", "Integration tests complete", "v3.0.2 testing verified") → Temporary status, not architectural context',
398
+ '❌ Git commit summaries (e.g., "Released v3.0.2", "Created git commit 2bf55a0") → Belongs in git history',
399
+ '❌ Documentation updates (e.g., "README reorganized", "Help actions enhanced") → Implementation logs, not decisions',
400
+ '❌ Build status (e.g., "Build succeeded", "TypeScript compiled with zero errors") → Temporary status'
401
+ ]
402
+ },
403
+ analogy: {
404
+ git_history: 'WHAT changed (files, lines, commits)',
405
+ code_comments: 'HOW it works (implementation details, algorithms)',
406
+ sqlew_decisions: 'WHY it was changed (reasoning, trade-offs, context)',
407
+ sqlew_tasks: 'WHAT needs to be done (work items, status, completion)'
408
+ },
409
+ examples: [
410
+ {
411
+ key: 'api/auth/jwt-choice',
412
+ value: 'Chose JWT over session-based auth because: (1) Stateless design scales horizontally, (2) Mobile clients can cache tokens, (3) Microservice architecture requires distributed auth. Trade-off: Revocation requires token blacklist, but acceptable for 15-min token lifetime.',
413
+ explanation: 'Explains WHY JWT was chosen, considers trade-offs, provides architectural context'
414
+ },
415
+ {
416
+ key: 'database/postgresql-choice',
417
+ value: 'Selected PostgreSQL over MongoDB because: (1) Complex relational queries required for reporting, (2) ACID compliance critical for financial data, (3) Team has strong SQL expertise. Trade-off: Less flexible schema, but data integrity more important than schema flexibility for our use case.',
418
+ explanation: 'Documents database choice with reasoning, alternatives considered, and trade-offs'
419
+ },
420
+ {
421
+ key: 'security/encryption-at-rest',
422
+ value: 'Implementing AES-256 encryption for all PII in database because: (1) GDPR compliance requires encryption at rest, (2) Recent security audit identified unencrypted sensitive data, (3) Performance impact <5ms per query acceptable. Alternative considered: Database-level encryption rejected due to backup/restore complexity.',
423
+ explanation: 'Explains security decision with compliance reasoning and performance considerations'
424
+ }
425
+ ],
426
+ cleanup_rule: 'Delete decisions that start with "COMPLETED:", contain task status, test results, or implementation logs. Keep only architectural reasoning and design rationale.'
427
+ },
503
428
  actions: {
504
429
  set: 'Set/update a decision. Params: key (required), value (required), agent, layer, version, status, tags, scopes',
505
430
  get: 'Get specific decision by key. Params: key (required)',
@@ -513,7 +438,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
513
438
  has_updates: 'Check for updates since timestamp (FR-003 Phase A - Lightweight Polling). Params: agent_name (required), since_timestamp (required, ISO 8601 format like "2025-10-14T08:00:00Z"). Returns: {has_updates: boolean, counts: {decisions: N, messages: N, files: N}}. Token cost: ~5-10 tokens per check. Uses COUNT queries on t_decisions, t_agent_messages, t_file_changes with timestamp filtering. Enables efficient polling without full data retrieval.',
514
439
  set_from_template: 'Set decision using template (FR-006). Params: template (required, template name), key (required), value (required), agent, layer (override), version, status (override), tags (override), scopes, plus any template-required fields. Applies template defaults (layer, status, tags) while allowing overrides. Validates required fields if specified by template. Returns: {success, key, key_id, version, template_used, applied_defaults, message}. Built-in templates: breaking_change, security_vulnerability, performance_optimization, deprecation, architecture_decision.',
515
440
  create_template: 'Create new decision template (FR-006). Params: name (required, unique), defaults (required, object with layer/status/tags/priority), required_fields (optional, array of field names), created_by (optional, agent name). Returns: {success, template_id, template_name, message}. Example defaults: {"layer":"business","status":"active","tags":["breaking"]}. Validates layer/status values.',
516
- list_templates: 'List all decision templates (FR-006). No params required. Returns: {templates: [{id, name, defaults, required_fields, created_by, created_at}], count}. Shows both built-in and custom templates.'
441
+ list_templates: 'List all decision templates (FR-006). No params required. Returns: {templates: [{id, name, defaults, required_fields, created_by, created_at}], count}. Shows both built-in and custom templates.',
442
+ hard_delete: 'Permanently delete a decision (hard delete). Params: key (required). WARNING: IRREVERSIBLE - removes all records including version history, tags, scopes. Use cases: manual cleanup after decision-to-task migration, remove test/debug decisions, purge sensitive data. Unlike soft delete (status=deprecated), this completely removes from database. Idempotent - safe to call even if already deleted. Returns: {success, key, message}.'
517
443
  },
518
444
  examples: {
519
445
  set: '{ action: "set", key: "auth_method", value: "jwt", tags: ["security"] }',
@@ -526,7 +452,146 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
526
452
  has_updates: '{ action: "has_updates", agent_name: "my-agent", since_timestamp: "2025-10-14T08:00:00Z" }',
527
453
  set_from_template: '{ action: "set_from_template", template: "breaking_change", key: "oscillator-type-moved", value: "oscillator_type moved to MonophonicSynthConfig" }',
528
454
  create_template: '{ action: "create_template", name: "bug_fix", defaults: {"layer":"business","tags":["bug","fix"],"status":"active"}, created_by: "my-agent" }',
529
- list_templates: '{ action: "list_templates" }'
455
+ list_templates: '{ action: "list_templates" }',
456
+ hard_delete: '{ action: "hard_delete", key: "task_old_authentication_refactor" }'
457
+ },
458
+ documentation: {
459
+ tool_selection: 'docs/TOOL_SELECTION.md - Decision tree, tool comparison, when to use each tool (236 lines, ~12k tokens)',
460
+ tool_reference: 'docs/TOOL_REFERENCE.md - Parameter requirements, batch operations, templates (471 lines, ~24k tokens)',
461
+ workflows: 'docs/WORKFLOWS.md - Multi-step workflow examples, multi-agent coordination (602 lines, ~30k tokens)',
462
+ best_practices: 'docs/BEST_PRACTICES.md - Common errors, best practices, troubleshooting (345 lines, ~17k tokens)',
463
+ shared_concepts: 'docs/SHARED_CONCEPTS.md - Layer definitions, enum values (status/layer/priority), atomic mode (339 lines, ~17k tokens)'
464
+ }
465
+ };
466
+ break;
467
+ case 'example':
468
+ result = {
469
+ tool: 'decision',
470
+ description: 'Comprehensive decision tool examples without needing WebFetch access',
471
+ scenarios: {
472
+ basic_usage: {
473
+ title: 'Basic Decision Management',
474
+ examples: [
475
+ {
476
+ scenario: 'Record API design decision',
477
+ request: '{ action: "set", key: "api_auth_method", value: "JWT with refresh tokens", layer: "business", tags: ["api", "security", "authentication"] }',
478
+ explanation: 'Documents the choice of authentication method for the API'
479
+ },
480
+ {
481
+ scenario: 'Retrieve a decision',
482
+ request: '{ action: "get", key: "api_auth_method" }',
483
+ response_structure: '{ key, value, layer, status, version, tags, scopes, decided_by, updated_at }'
484
+ },
485
+ {
486
+ scenario: 'List all active decisions',
487
+ request: '{ action: "list", status: "active", limit: 20 }',
488
+ explanation: 'Returns active decisions with metadata for browsing'
489
+ }
490
+ ]
491
+ },
492
+ advanced_filtering: {
493
+ title: 'Advanced Search and Filtering',
494
+ examples: [
495
+ {
496
+ scenario: 'Find all security-related decisions in business layer',
497
+ request: '{ action: "search_advanced", layers: ["business"], tags_any: ["security", "authentication"], status: ["active"], sort_by: "updated", sort_order: "desc" }',
498
+ explanation: 'Combines layer filtering, tag matching, and sorting'
499
+ },
500
+ {
501
+ scenario: 'Search within API scope with multiple tags',
502
+ request: '{ action: "search_advanced", scopes: ["api/*"], tags_all: ["breaking", "v2.0"], updated_after: "2025-01-01" }',
503
+ explanation: 'Uses scope wildcards and timestamp filtering for recent breaking changes'
504
+ }
505
+ ]
506
+ },
507
+ versioning_workflow: {
508
+ title: 'Version Management',
509
+ steps: [
510
+ {
511
+ step: 1,
512
+ action: 'Create initial decision',
513
+ request: '{ action: "set", key: "database_choice", value: "PostgreSQL", layer: "data", version: "1.0.0", tags: ["database"] }'
514
+ },
515
+ {
516
+ step: 2,
517
+ action: 'Update decision (creates new version)',
518
+ request: '{ action: "set", key: "database_choice", value: "PostgreSQL with read replicas", layer: "data", version: "1.1.0", tags: ["database", "scaling"] }'
519
+ },
520
+ {
521
+ step: 3,
522
+ action: 'View version history',
523
+ request: '{ action: "versions", key: "database_choice" }',
524
+ result: 'Returns all versions with timestamps and changes'
525
+ }
526
+ ]
527
+ },
528
+ batch_operations: {
529
+ title: 'Batch Decision Management',
530
+ examples: [
531
+ {
532
+ scenario: 'Record multiple related decisions atomically',
533
+ request: '{ action: "set_batch", decisions: [{"key": "cache_layer", "value": "Redis", "layer": "infrastructure"}, {"key": "cache_ttl", "value": "3600", "layer": "infrastructure"}], atomic: true }',
534
+ explanation: 'All decisions succeed or all fail together (atomic mode)'
535
+ },
536
+ {
537
+ scenario: 'Best-effort batch insert',
538
+ request: '{ action: "set_batch", decisions: [{...}, {...}, {...}], atomic: false }',
539
+ explanation: 'Each decision processed independently - partial success allowed'
540
+ }
541
+ ]
542
+ },
543
+ templates: {
544
+ title: 'Using Decision Templates',
545
+ examples: [
546
+ {
547
+ scenario: 'Use built-in breaking_change template',
548
+ request: '{ action: "set_from_template", template: "breaking_change", key: "api_remove_legacy_endpoint", value: "Removed /v1/users endpoint - migrate to /v2/users" }',
549
+ explanation: 'Automatically applies layer=business, tags=["breaking"], status=active'
550
+ },
551
+ {
552
+ scenario: 'Create custom template',
553
+ request: '{ action: "create_template", name: "feature_flag", defaults: {"layer": "presentation", "tags": ["feature-flag"], "status": "draft"}, created_by: "backend-team" }',
554
+ explanation: 'Define reusable templates for common decision patterns'
555
+ }
556
+ ]
557
+ },
558
+ quick_set_inference: {
559
+ title: 'Quick Set with Smart Defaults',
560
+ examples: [
561
+ {
562
+ scenario: 'Auto-infer layer from key prefix',
563
+ request: '{ action: "quick_set", key: "api/instruments/oscillator-refactor", value: "Moved oscillator_type to MonophonicSynthConfig" }',
564
+ inferred: 'layer=presentation (from api/*), tags=["instruments", "oscillator-refactor"], scope=api/instruments'
565
+ },
566
+ {
567
+ scenario: 'Database decision with auto-inference',
568
+ request: '{ action: "quick_set", key: "db/users/add-email-index", value: "Added index on email column" }',
569
+ inferred: 'layer=data (from db/*), tags=["users", "add-email-index"]'
570
+ }
571
+ ]
572
+ }
573
+ },
574
+ best_practices: {
575
+ key_naming: [
576
+ 'Use hierarchical keys: "api/users/authentication"',
577
+ 'Prefix with layer hint: api/* → presentation, db/* → data, service/* → business',
578
+ 'Use descriptive names that explain the decision context'
579
+ ],
580
+ tagging: [
581
+ 'Tag with relevant categories: security, performance, breaking, etc.',
582
+ 'Include version tags for release-specific decisions',
583
+ 'Use consistent tag naming conventions across team'
584
+ ],
585
+ versioning: [
586
+ 'Use semantic versioning: 1.0.0, 1.1.0, 2.0.0',
587
+ 'Increment major version for breaking changes',
588
+ 'Document rationale in decision value text'
589
+ ],
590
+ cleanup: [
591
+ 'Mark deprecated decisions with status="deprecated"',
592
+ 'Use hard_delete only for sensitive data or migration cleanup',
593
+ 'Link related decisions using scopes'
594
+ ]
530
595
  }
531
596
  };
532
597
  break;
@@ -562,6 +627,115 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
562
627
  get: '{ action: "get", agent_name: "bot1", unread_only: true }',
563
628
  mark_read: '{ action: "mark_read", agent_name: "bot1", message_ids: [1, 2, 3] }',
564
629
  send_batch: '{ action: "send_batch", messages: [{"from_agent": "bot1", "msg_type": "info", "message": "Task 1 done"}, {"from_agent": "bot1", "msg_type": "info", "message": "Task 2 done"}], atomic: true }'
630
+ },
631
+ documentation: {
632
+ workflows: 'docs/WORKFLOWS.md - Multi-agent coordination, messaging patterns, cross-session handoffs (602 lines, ~30k tokens)',
633
+ tool_reference: 'docs/TOOL_REFERENCE.md - Message tool parameters, batch operations (471 lines, ~24k tokens)',
634
+ shared_concepts: 'docs/SHARED_CONCEPTS.md - Enum values (msg_type/priority), atomic mode (339 lines, ~17k tokens)',
635
+ best_practices: 'docs/BEST_PRACTICES.md - Common errors, messaging best practices (345 lines, ~17k tokens)'
636
+ }
637
+ };
638
+ break;
639
+ case 'example':
640
+ result = {
641
+ tool: 'message',
642
+ description: 'Comprehensive messaging examples for multi-agent coordination',
643
+ scenarios: {
644
+ basic_messaging: {
645
+ title: 'Basic Agent Communication',
646
+ examples: [
647
+ {
648
+ scenario: 'Send info message between agents',
649
+ request: '{ action: "send", from_agent: "backend-agent", to_agent: "frontend-agent", msg_type: "info", message: "API endpoint /users is ready" }',
650
+ explanation: 'Direct message from one agent to another'
651
+ },
652
+ {
653
+ scenario: 'Broadcast message to all agents',
654
+ request: '{ action: "send", from_agent: "coordinator", to_agent: null, msg_type: "info", message: "Deployment starting in 5 minutes", priority: "high" }',
655
+ explanation: 'null to_agent broadcasts to all agents'
656
+ },
657
+ {
658
+ scenario: 'Get unread messages',
659
+ request: '{ action: "get", agent_name: "frontend-agent", unread_only: true }',
660
+ explanation: 'Retrieve only unread messages for an agent'
661
+ }
662
+ ]
663
+ },
664
+ priority_messaging: {
665
+ title: 'Priority-Based Communication',
666
+ examples: [
667
+ {
668
+ scenario: 'Critical error notification',
669
+ request: '{ action: "send", from_agent: "monitoring-agent", msg_type: "warning", message: "Database connection lost", priority: "critical" }',
670
+ explanation: 'High-priority messages for urgent issues'
671
+ },
672
+ {
673
+ scenario: 'Filter by priority',
674
+ request: '{ action: "get", agent_name: "ops-agent", priority_filter: "critical" }',
675
+ explanation: 'Get only critical priority messages'
676
+ }
677
+ ]
678
+ },
679
+ workflow_coordination: {
680
+ title: 'Multi-Step Workflow',
681
+ steps: [
682
+ {
683
+ step: 1,
684
+ action: 'Agent A requests work from Agent B',
685
+ request: '{ action: "send", from_agent: "agent-a", to_agent: "agent-b", msg_type: "request", message: "Please process user data batch-123" }'
686
+ },
687
+ {
688
+ step: 2,
689
+ action: 'Agent B checks messages',
690
+ request: '{ action: "get", agent_name: "agent-b", msg_type_filter: "request", unread_only: true }'
691
+ },
692
+ {
693
+ step: 3,
694
+ action: 'Agent B marks as read and processes',
695
+ request: '{ action: "mark_read", agent_name: "agent-b", message_ids: [123] }'
696
+ },
697
+ {
698
+ step: 4,
699
+ action: 'Agent B sends completion notification',
700
+ request: '{ action: "send", from_agent: "agent-b", to_agent: "agent-a", msg_type: "info", message: "Batch-123 processing complete" }'
701
+ }
702
+ ]
703
+ },
704
+ batch_messaging: {
705
+ title: 'Batch Message Operations',
706
+ examples: [
707
+ {
708
+ scenario: 'Send multiple status updates atomically',
709
+ request: '{ action: "send_batch", messages: [{"from_agent": "worker-1", "msg_type": "info", "message": "Task 1 done"}, {"from_agent": "worker-1", "msg_type": "info", "message": "Task 2 done"}], atomic: true }',
710
+ explanation: 'All messages sent or none (atomic mode)'
711
+ },
712
+ {
713
+ scenario: 'Best-effort batch sending',
714
+ request: '{ action: "send_batch", messages: [{...}, {...}], atomic: false }',
715
+ explanation: 'Each message sent independently - partial success allowed'
716
+ }
717
+ ]
718
+ }
719
+ },
720
+ best_practices: {
721
+ message_types: [
722
+ 'Use "decision" for recording important choices',
723
+ 'Use "warning" for errors or issues requiring attention',
724
+ 'Use "request" for work requests between agents',
725
+ 'Use "info" for status updates and notifications'
726
+ ],
727
+ priority_usage: [
728
+ 'critical: System failures, data loss, security breaches',
729
+ 'high: Important but not emergency (deployment notifications)',
730
+ 'medium: Regular coordination messages (default)',
731
+ 'low: Optional information, logging'
732
+ ],
733
+ coordination_patterns: [
734
+ 'Always mark messages as read after processing',
735
+ 'Use broadcast (to_agent=null) for system-wide announcements',
736
+ 'Filter by msg_type when checking for specific message categories',
737
+ 'Include context in message text or payload for debugging'
738
+ ]
565
739
  }
566
740
  };
567
741
  break;
@@ -597,6 +771,106 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
597
771
  get: '{ action: "get", agent_name: "refactor-bot", layer: "infrastructure", limit: 10 }',
598
772
  check_lock: '{ action: "check_lock", file_path: "src/index.ts", lock_duration: 300 }',
599
773
  record_batch: '{ action: "record_batch", file_changes: [{"file_path": "src/types.ts", "agent_name": "bot1", "change_type": "modified", "layer": "data"}, {"file_path": "src/index.ts", "agent_name": "bot1", "change_type": "modified", "layer": "infrastructure"}], atomic: true }'
774
+ },
775
+ documentation: {
776
+ workflows: 'docs/WORKFLOWS.md - File locking patterns, concurrent file access workflows (602 lines, ~30k tokens)',
777
+ tool_reference: 'docs/TOOL_REFERENCE.md - File tool parameters, batch operations (471 lines, ~24k tokens)',
778
+ shared_concepts: 'docs/SHARED_CONCEPTS.md - Layer definitions, enum values (change_type), atomic mode (339 lines, ~17k tokens)',
779
+ best_practices: 'docs/BEST_PRACTICES.md - File tracking best practices (345 lines, ~17k tokens)'
780
+ }
781
+ };
782
+ break;
783
+ case 'example':
784
+ result = {
785
+ tool: 'file',
786
+ description: 'Comprehensive file tracking examples for multi-agent coordination',
787
+ scenarios: {
788
+ basic_tracking: {
789
+ title: 'Basic File Change Tracking',
790
+ examples: [
791
+ {
792
+ scenario: 'Record file modification',
793
+ request: '{ action: "record", file_path: "src/api/users.ts", agent_name: "refactor-agent", change_type: "modified", layer: "business", description: "Added email validation" }',
794
+ explanation: 'Track changes with layer and description'
795
+ },
796
+ {
797
+ scenario: 'Get recent changes by agent',
798
+ request: '{ action: "get", agent_name: "refactor-agent", limit: 10 }',
799
+ explanation: 'View what an agent has been working on'
800
+ },
801
+ {
802
+ scenario: 'Track changes to specific file',
803
+ request: '{ action: "get", file_path: "src/api/users.ts" }',
804
+ explanation: 'See all modifications to a particular file'
805
+ }
806
+ ]
807
+ },
808
+ file_locking: {
809
+ title: 'Concurrent Access Prevention',
810
+ workflow: [
811
+ {
812
+ step: 1,
813
+ action: 'Check if file is locked',
814
+ request: '{ action: "check_lock", file_path: "src/database/schema.sql", lock_duration: 300 }',
815
+ result: '{ locked: false } or { locked: true, locked_by: "agent-name", locked_at: "timestamp" }'
816
+ },
817
+ {
818
+ step: 2,
819
+ action: 'If not locked, record change (creates lock)',
820
+ request: '{ action: "record", file_path: "src/database/schema.sql", agent_name: "migration-agent", change_type: "modified" }'
821
+ },
822
+ {
823
+ step: 3,
824
+ action: 'Lock expires after 5 minutes (default) or specified duration'
825
+ }
826
+ ]
827
+ },
828
+ layer_organization: {
829
+ title: 'Tracking by Architecture Layer',
830
+ examples: [
831
+ {
832
+ scenario: 'Get all presentation layer changes',
833
+ request: '{ action: "get", layer: "presentation", limit: 20 }',
834
+ explanation: 'View frontend/UI changes across agents'
835
+ },
836
+ {
837
+ scenario: 'Track infrastructure changes',
838
+ request: '{ action: "get", layer: "infrastructure", change_type: "modified" }',
839
+ explanation: 'Monitor config and deployment file changes'
840
+ }
841
+ ]
842
+ },
843
+ batch_tracking: {
844
+ title: 'Batch File Operations',
845
+ examples: [
846
+ {
847
+ scenario: 'Record multiple file changes atomically',
848
+ request: '{ action: "record_batch", file_changes: [{"file_path": "src/api.ts", "agent_name": "bot1", "change_type": "modified", "layer": "presentation"}, {"file_path": "src/types.ts", "agent_name": "bot1", "change_type": "modified", "layer": "data"}], atomic: true }',
849
+ explanation: 'All changes recorded or none (transaction)'
850
+ }
851
+ ]
852
+ }
853
+ },
854
+ best_practices: {
855
+ change_tracking: [
856
+ 'Always specify layer for better organization',
857
+ 'Include description for non-obvious changes',
858
+ 'Use check_lock before modifying shared files',
859
+ 'Track both creation and deletion of files'
860
+ ],
861
+ lock_management: [
862
+ 'Default lock duration is 300 seconds (5 minutes)',
863
+ 'Locks prevent concurrent modifications',
864
+ 'Locks auto-expire - no manual unlock needed',
865
+ 'Use appropriate lock_duration for operation complexity'
866
+ ],
867
+ layer_assignment: [
868
+ 'presentation: UI components, API controllers',
869
+ 'business: Services, domain logic',
870
+ 'data: Models, repositories, migrations',
871
+ 'infrastructure: Config, deployment, CI/CD',
872
+ 'cross-cutting: Utilities used across layers'
873
+ ]
600
874
  }
601
875
  };
602
876
  break;
@@ -627,6 +901,148 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
627
901
  add: '{ action: "add", category: "performance", constraint_text: "API response time <100ms", priority: "high", tags: ["api"] }',
628
902
  get: '{ action: "get", category: "performance", active_only: true }',
629
903
  deactivate: '{ action: "deactivate", constraint_id: 5 }'
904
+ },
905
+ documentation: {
906
+ tool_selection: 'docs/TOOL_SELECTION.md - Decision tree, constraint vs decision comparison (236 lines, ~12k tokens)',
907
+ workflows: 'docs/WORKFLOWS.md - Constraint validation workflows, requirement tracking (602 lines, ~30k tokens)',
908
+ shared_concepts: 'docs/SHARED_CONCEPTS.md - Layer definitions, enum values (category/priority) (339 lines, ~17k tokens)',
909
+ best_practices: 'docs/BEST_PRACTICES.md - When to use constraints, common patterns (345 lines, ~17k tokens)'
910
+ }
911
+ };
912
+ break;
913
+ case 'example':
914
+ result = {
915
+ tool: 'constraint',
916
+ description: 'Comprehensive constraint examples for various use cases',
917
+ categories: {
918
+ performance: {
919
+ description: 'Performance-related constraints for response times, throughput, resource usage',
920
+ examples: [
921
+ {
922
+ scenario: 'API Response Time',
923
+ example: '{ action: "add", category: "performance", constraint_text: "All API endpoints must respond within 100ms for 95th percentile", priority: "high", layer: "business", tags: ["api", "latency"] }',
924
+ rationale: 'Ensures fast user experience and prevents timeout issues'
925
+ },
926
+ {
927
+ scenario: 'Database Query Performance',
928
+ example: '{ action: "add", category: "performance", constraint_text: "Database queries must complete within 50ms", priority: "high", layer: "data", tags: ["database", "query"] }',
929
+ rationale: 'Prevents database bottlenecks and ensures scalability'
930
+ },
931
+ {
932
+ scenario: 'Memory Usage',
933
+ example: '{ action: "add", category: "performance", constraint_text: "Peak memory usage must not exceed 512MB per instance", priority: "critical", layer: "infrastructure", tags: ["memory", "resource"] }',
934
+ rationale: 'Prevents out-of-memory errors in containerized environments'
935
+ }
936
+ ]
937
+ },
938
+ architecture: {
939
+ description: 'Architectural constraints for code structure, dependencies, patterns',
940
+ examples: [
941
+ {
942
+ scenario: 'Layer Dependency Rules',
943
+ example: '{ action: "add", category: "architecture", constraint_text: "Presentation layer must not directly access data layer - use business layer only", priority: "critical", layer: "cross-cutting", tags: ["layering", "separation"] }',
944
+ rationale: 'Enforces clean architecture and separation of concerns'
945
+ },
946
+ {
947
+ scenario: 'Dependency Injection',
948
+ example: '{ action: "add", category: "architecture", constraint_text: "All service classes must use constructor-based dependency injection", priority: "medium", layer: "business", tags: ["di", "testability"] }',
949
+ rationale: 'Improves testability and reduces coupling'
950
+ },
951
+ {
952
+ scenario: 'API Versioning',
953
+ example: '{ action: "add", category: "architecture", constraint_text: "All public APIs must include version prefix (e.g., /v1/, /v2/)", priority: "high", layer: "presentation", tags: ["api", "versioning"] }',
954
+ rationale: 'Enables backward compatibility and smooth API evolution'
955
+ }
956
+ ]
957
+ },
958
+ security: {
959
+ description: 'Security constraints for authentication, authorization, data protection',
960
+ examples: [
961
+ {
962
+ scenario: 'Authentication Required',
963
+ example: '{ action: "add", category: "security", constraint_text: "All non-public endpoints must require JWT authentication", priority: "critical", layer: "presentation", tags: ["auth", "jwt"] }',
964
+ rationale: 'Prevents unauthorized access to protected resources'
965
+ },
966
+ {
967
+ scenario: 'Data Encryption',
968
+ example: '{ action: "add", category: "security", constraint_text: "All PII (Personally Identifiable Information) must be encrypted at rest using AES-256", priority: "critical", layer: "data", tags: ["encryption", "pii"] }',
969
+ rationale: 'Protects sensitive data and ensures compliance'
970
+ },
971
+ {
972
+ scenario: 'Input Validation',
973
+ example: '{ action: "add", category: "security", constraint_text: "All user inputs must be validated and sanitized before processing", priority: "critical", layer: "presentation", tags: ["validation", "injection-prevention"] }',
974
+ rationale: 'Prevents injection attacks (SQL, XSS, etc.)'
975
+ }
976
+ ]
977
+ }
978
+ },
979
+ workflows: {
980
+ constraint_validation: {
981
+ description: 'Workflow for validating code against constraints',
982
+ steps: [
983
+ {
984
+ step: 1,
985
+ action: 'Retrieve active constraints for layer',
986
+ example: '{ action: "get", layer: "business", active_only: true }'
987
+ },
988
+ {
989
+ step: 2,
990
+ action: 'Check code changes against constraints',
991
+ example: 'Review file changes and verify compliance with each constraint'
992
+ },
993
+ {
994
+ step: 3,
995
+ action: 'Report violations',
996
+ example: 'Use message tool to send warnings for constraint violations'
997
+ },
998
+ {
999
+ step: 4,
1000
+ action: 'Link violations to tasks',
1001
+ example: 'Create tasks to fix violations and link to relevant constraints'
1002
+ }
1003
+ ]
1004
+ },
1005
+ requirement_tracking: {
1006
+ description: 'Workflow for tracking requirements as constraints',
1007
+ steps: [
1008
+ {
1009
+ step: 1,
1010
+ action: 'Add requirement as constraint',
1011
+ example: '{ action: "add", category: "performance", constraint_text: "System must handle 1000 concurrent users", priority: "high", tags: ["requirement", "load"] }'
1012
+ },
1013
+ {
1014
+ step: 2,
1015
+ action: 'Link related decisions',
1016
+ example: 'Use decision tool to record architectural decisions that address the constraint'
1017
+ },
1018
+ {
1019
+ step: 3,
1020
+ action: 'Create implementation tasks',
1021
+ example: 'Use task tool to break down implementation and link to constraint'
1022
+ },
1023
+ {
1024
+ step: 4,
1025
+ action: 'Validate compliance',
1026
+ example: 'Test implementation against constraint criteria'
1027
+ }
1028
+ ]
1029
+ }
1030
+ },
1031
+ best_practices: {
1032
+ writing_constraints: [
1033
+ 'Be specific and measurable (use numbers, percentages, time limits)',
1034
+ 'Include rationale in tags or separate documentation',
1035
+ 'Use appropriate priority (critical for must-have, high for important, medium/low for nice-to-have)',
1036
+ 'Assign to correct layer (where constraint is enforced)',
1037
+ 'Tag comprehensively for easy retrieval'
1038
+ ],
1039
+ managing_constraints: [
1040
+ 'Review constraints regularly and deactivate outdated ones',
1041
+ 'Link constraints to related decisions and tasks',
1042
+ 'Use constraints for both technical and business requirements',
1043
+ 'Validate code changes against active constraints',
1044
+ 'Document constraint violations and remediation plans'
1045
+ ]
630
1046
  }
631
1047
  };
632
1048
  break;
@@ -652,21 +1068,132 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
652
1068
  limit: params.limit,
653
1069
  });
654
1070
  break;
1071
+ case 'flush':
1072
+ result = flushWAL();
1073
+ break;
655
1074
  case 'help':
656
1075
  result = {
657
1076
  tool: 'stats',
658
- description: 'View database statistics, activity logs, and manage data cleanup',
1077
+ description: 'View database statistics, activity logs, manage data cleanup, and WAL checkpoints',
659
1078
  actions: {
660
1079
  layer_summary: 'Get summary by layer. No params required',
661
1080
  db_stats: 'Get database statistics. No params required',
662
1081
  clear: 'Clear old data. Params: messages_older_than_hours, file_changes_older_than_days',
663
- activity_log: 'Get activity log (v3.0.0). Params: since (e.g., "5m", "1h", "2d"), agent_names (array or ["*"]), actions (filter by action types), limit (default: 100)'
1082
+ activity_log: 'Get activity log (v3.0.0). Params: since (e.g., "5m", "1h", "2d"), agent_names (array or ["*"]), actions (filter by action types), limit (default: 100)',
1083
+ flush: 'Force WAL checkpoint to flush pending transactions to main database file. No params required. Uses TRUNCATE mode for complete flush. Useful before git commits to ensure database file is up-to-date.'
664
1084
  },
665
1085
  examples: {
666
1086
  layer_summary: '{ action: "layer_summary" }',
667
1087
  db_stats: '{ action: "db_stats" }',
668
1088
  clear: '{ action: "clear", messages_older_than_hours: 48, file_changes_older_than_days: 14 }',
669
- activity_log: '{ action: "activity_log", since: "1h", agent_names: ["bot1", "bot2"], limit: 50 }'
1089
+ activity_log: '{ action: "activity_log", since: "1h", agent_names: ["bot1", "bot2"], limit: 50 }',
1090
+ flush: '{ action: "flush" }'
1091
+ },
1092
+ documentation: {
1093
+ workflows: 'docs/WORKFLOWS.md - Activity monitoring, automatic cleanup workflows (602 lines, ~30k tokens)',
1094
+ best_practices: 'docs/BEST_PRACTICES.md - Database health, cleanup strategies (345 lines, ~17k tokens)',
1095
+ shared_concepts: 'docs/SHARED_CONCEPTS.md - Layer definitions for layer_summary (339 lines, ~17k tokens)',
1096
+ architecture: 'docs/ARCHITECTURE.md - Database schema, views, statistics tables'
1097
+ }
1098
+ };
1099
+ break;
1100
+ case 'example':
1101
+ result = {
1102
+ tool: 'stats',
1103
+ description: 'Database statistics and maintenance examples',
1104
+ scenarios: {
1105
+ layer_analysis: {
1106
+ title: 'Architecture Layer Summary',
1107
+ example: {
1108
+ request: '{ action: "layer_summary" }',
1109
+ response_structure: '{ layer: string, decision_count: number, file_changes: number, active_constraints: number }[]',
1110
+ use_case: 'Understand which layers have most activity and decisions'
1111
+ }
1112
+ },
1113
+ database_health: {
1114
+ title: 'Database Statistics',
1115
+ example: {
1116
+ request: '{ action: "db_stats" }',
1117
+ response_structure: '{ decisions: N, messages: N, file_changes: N, constraints: N, db_size_mb: N }',
1118
+ use_case: 'Monitor database growth and table sizes'
1119
+ }
1120
+ },
1121
+ activity_monitoring: {
1122
+ title: 'Activity Log Queries',
1123
+ examples: [
1124
+ {
1125
+ scenario: 'Recent activity (last hour)',
1126
+ request: '{ action: "activity_log", since: "1h", limit: 50 }',
1127
+ explanation: 'View all agent activity in the past hour'
1128
+ },
1129
+ {
1130
+ scenario: 'Specific agent activity',
1131
+ request: '{ action: "activity_log", since: "24h", agent_names: ["backend-agent", "frontend-agent"] }',
1132
+ explanation: 'Track what specific agents have been doing'
1133
+ },
1134
+ {
1135
+ scenario: 'Filter by action type',
1136
+ request: '{ action: "activity_log", since: "2d", actions: ["set_decision", "create_task"] }',
1137
+ explanation: 'See only specific types of actions'
1138
+ }
1139
+ ]
1140
+ },
1141
+ data_cleanup: {
1142
+ title: 'Maintenance and Cleanup',
1143
+ examples: [
1144
+ {
1145
+ scenario: 'Manual cleanup with specific retention',
1146
+ request: '{ action: "clear", messages_older_than_hours: 48, file_changes_older_than_days: 14 }',
1147
+ explanation: 'Override config and delete old data'
1148
+ },
1149
+ {
1150
+ scenario: 'Config-based automatic cleanup',
1151
+ request: '{ action: "clear" }',
1152
+ explanation: 'Use configured retention settings (respects weekend-aware mode)'
1153
+ }
1154
+ ]
1155
+ },
1156
+ wal_management: {
1157
+ title: 'WAL Checkpoint (Git Workflow)',
1158
+ workflow: [
1159
+ {
1160
+ step: 1,
1161
+ action: 'Make changes to context (decisions, tasks, etc.)',
1162
+ explanation: 'SQLite WAL mode keeps changes in separate file'
1163
+ },
1164
+ {
1165
+ step: 2,
1166
+ action: 'Before git commit, flush WAL',
1167
+ request: '{ action: "flush" }',
1168
+ explanation: 'Merges WAL changes into main .db file'
1169
+ },
1170
+ {
1171
+ step: 3,
1172
+ action: 'Commit database file',
1173
+ explanation: 'Database file now contains all changes for version control'
1174
+ }
1175
+ ]
1176
+ }
1177
+ },
1178
+ best_practices: {
1179
+ monitoring: [
1180
+ 'Check layer_summary regularly to identify hotspots',
1181
+ 'Monitor db_stats to prevent database bloat',
1182
+ 'Use activity_log for debugging multi-agent issues',
1183
+ 'Set appropriate retention periods based on project needs'
1184
+ ],
1185
+ cleanup: [
1186
+ 'Run periodic cleanup to manage database size',
1187
+ 'Use weekend-aware mode for business hour retention',
1188
+ 'Consider longer retention for important decisions',
1189
+ 'Test cleanup with manual parameters before automating'
1190
+ ],
1191
+ wal_checkpoints: [
1192
+ 'Always flush before git commits for clean diffs',
1193
+ 'WAL mode improves concurrent access performance',
1194
+ 'Checkpoint automatically happens on shutdown',
1195
+ 'Manual flush ensures immediate persistence'
1196
+ ]
670
1197
  }
671
1198
  };
672
1199
  break;
@@ -692,6 +1219,291 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
692
1219
  examples: {
693
1220
  get: '{ action: "get" }',
694
1221
  update: '{ action: "update", ignoreWeekend: true, messageRetentionHours: 48 }'
1222
+ },
1223
+ documentation: {
1224
+ shared_concepts: 'docs/SHARED_CONCEPTS.md - Weekend-aware retention behavior explained (339 lines, ~17k tokens)',
1225
+ best_practices: 'docs/BEST_PRACTICES.md - Retention strategies, cleanup timing (345 lines, ~17k tokens)',
1226
+ architecture: 'docs/ARCHITECTURE.md - Auto-cleanup architecture, configuration system'
1227
+ }
1228
+ };
1229
+ break;
1230
+ case 'example':
1231
+ result = {
1232
+ tool: 'config',
1233
+ description: 'Configuration management examples',
1234
+ scenarios: {
1235
+ view_config: {
1236
+ title: 'Current Configuration',
1237
+ example: {
1238
+ request: '{ action: "get" }',
1239
+ response: '{ ignoreWeekend: boolean, messageRetentionHours: number, fileHistoryRetentionDays: number }',
1240
+ explanation: 'View current auto-deletion settings'
1241
+ }
1242
+ },
1243
+ standard_retention: {
1244
+ title: 'Standard Time-Based Retention',
1245
+ example: {
1246
+ request: '{ action: "update", ignoreWeekend: false, messageRetentionHours: 24, fileHistoryRetentionDays: 7 }',
1247
+ explanation: 'Messages deleted after 24 hours, file history after 7 days (strict time-based)'
1248
+ }
1249
+ },
1250
+ weekend_aware: {
1251
+ title: 'Weekend-Aware Retention',
1252
+ example: {
1253
+ request: '{ action: "update", ignoreWeekend: true, messageRetentionHours: 24, fileHistoryRetentionDays: 7 }',
1254
+ explanation: 'On Monday, 24h retention = Friday (skips weekend)',
1255
+ scenario: 'Useful for business-hour contexts where weekend messages should persist'
1256
+ }
1257
+ },
1258
+ extended_retention: {
1259
+ title: 'Long-Term Project Retention',
1260
+ example: {
1261
+ request: '{ action: "update", messageRetentionHours: 168, fileHistoryRetentionDays: 90 }',
1262
+ explanation: '1 week message retention, 90 days file history (max allowed)',
1263
+ use_case: 'Long-running projects needing extended context'
1264
+ }
1265
+ }
1266
+ },
1267
+ retention_behavior: {
1268
+ ignoreWeekend_false: {
1269
+ description: 'Standard time-based retention',
1270
+ examples: [
1271
+ '24h on Monday = 24 hours ago (Sunday)',
1272
+ '24h on Friday = 24 hours ago (Thursday)',
1273
+ 'Straightforward chronological deletion'
1274
+ ]
1275
+ },
1276
+ ignoreWeekend_true: {
1277
+ description: 'Business-hours retention (skips Sat/Sun)',
1278
+ examples: [
1279
+ '24h on Monday = Friday (skips Sat/Sun)',
1280
+ '24h on Tuesday = Monday',
1281
+ '24h on Friday = Thursday',
1282
+ '24h on Saturday/Sunday = Friday',
1283
+ 'Preserves weekend messages until Monday cleanup'
1284
+ ]
1285
+ }
1286
+ },
1287
+ best_practices: {
1288
+ choosing_retention: [
1289
+ 'Short projects: 24h messages, 7d file history',
1290
+ 'Medium projects: 72h messages, 14d file history',
1291
+ 'Long projects: 168h (1 week) messages, 30-90d file history',
1292
+ 'Use ignoreWeekend=true for business-hour focused work'
1293
+ ],
1294
+ limits: [
1295
+ 'messageRetentionHours: 1-168 (1 hour to 1 week)',
1296
+ 'fileHistoryRetentionDays: 1-90',
1297
+ 'Choose based on your projects needs and database size constraints'
1298
+ ],
1299
+ cli_override: [
1300
+ 'Can override config at server startup via CLI args',
1301
+ '--autodelete-ignore-weekend, --autodelete-message-hours, --autodelete-file-history-days',
1302
+ 'Runtime updates via config tool take precedence over CLI'
1303
+ ]
1304
+ }
1305
+ };
1306
+ break;
1307
+ default: throw new Error(`Unknown action: ${params.action}`);
1308
+ }
1309
+ break;
1310
+ case 'task':
1311
+ switch (params.action) {
1312
+ case 'create':
1313
+ result = createTask(params);
1314
+ break;
1315
+ case 'update':
1316
+ result = updateTask(params);
1317
+ break;
1318
+ case 'get':
1319
+ result = getTask(params);
1320
+ break;
1321
+ case 'list':
1322
+ result = listTasks(params);
1323
+ break;
1324
+ case 'move':
1325
+ result = moveTask(params);
1326
+ break;
1327
+ case 'link':
1328
+ result = linkTask(params);
1329
+ break;
1330
+ case 'archive':
1331
+ result = archiveTask(params);
1332
+ break;
1333
+ case 'batch_create':
1334
+ result = batchCreateTasks({ tasks: params.tasks, atomic: params.atomic });
1335
+ break;
1336
+ case 'help':
1337
+ result = taskHelp();
1338
+ break;
1339
+ case 'example':
1340
+ result = {
1341
+ tool: 'task',
1342
+ description: 'Comprehensive task management examples for Kanban-style workflow',
1343
+ scenarios: {
1344
+ basic_task_management: {
1345
+ title: 'Creating and Managing Tasks',
1346
+ examples: [
1347
+ {
1348
+ scenario: 'Create a new task',
1349
+ request: '{ action: "create", title: "Implement user authentication", description: "Add JWT-based auth to API", priority: 3, assigned_agent: "backend-agent", layer: "business", tags: ["authentication", "security"] }',
1350
+ explanation: 'Creates task in todo status with high priority'
1351
+ },
1352
+ {
1353
+ scenario: 'Get task details',
1354
+ request: '{ action: "get", task_id: 5 }',
1355
+ response: 'Full task details including metadata, links, and timestamps'
1356
+ },
1357
+ {
1358
+ scenario: 'List tasks by status',
1359
+ request: '{ action: "list", status: "in_progress", limit: 20 }',
1360
+ explanation: 'View all in-progress tasks'
1361
+ }
1362
+ ]
1363
+ },
1364
+ status_workflow: {
1365
+ title: 'Task Lifecycle (Status Transitions)',
1366
+ workflow: [
1367
+ {
1368
+ step: 1,
1369
+ status: 'todo',
1370
+ action: '{ action: "create", title: "...", status: "todo" }',
1371
+ description: 'Task created and waiting to be started'
1372
+ },
1373
+ {
1374
+ step: 2,
1375
+ status: 'in_progress',
1376
+ action: '{ action: "move", task_id: 1, new_status: "in_progress" }',
1377
+ description: 'Agent starts working on task'
1378
+ },
1379
+ {
1380
+ step: 3,
1381
+ status: 'waiting_review',
1382
+ action: '{ action: "move", task_id: 1, new_status: "waiting_review" }',
1383
+ description: 'Work complete, awaiting review/approval'
1384
+ },
1385
+ {
1386
+ step: 4,
1387
+ status: 'done',
1388
+ action: '{ action: "move", task_id: 1, new_status: "done" }',
1389
+ description: 'Task reviewed and completed'
1390
+ },
1391
+ {
1392
+ step: 5,
1393
+ status: 'archived',
1394
+ action: '{ action: "archive", task_id: 1 }',
1395
+ description: 'Task archived for historical record'
1396
+ }
1397
+ ],
1398
+ blocked_status: {
1399
+ description: 'Use "blocked" when task cannot proceed due to dependencies',
1400
+ example: '{ action: "move", task_id: 1, new_status: "blocked" }'
1401
+ }
1402
+ },
1403
+ auto_stale_detection: {
1404
+ title: 'Automatic Stale Task Management',
1405
+ behavior: [
1406
+ {
1407
+ rule: 'in_progress > 2 hours → waiting_review',
1408
+ explanation: 'Tasks stuck in progress auto-move to waiting_review',
1409
+ rationale: 'Prevents tasks from being forgotten while in progress'
1410
+ },
1411
+ {
1412
+ rule: 'waiting_review > 24 hours → todo',
1413
+ explanation: 'Unreviewed tasks return to todo queue',
1414
+ rationale: 'Ensures waiting tasks dont accumulate indefinitely'
1415
+ }
1416
+ ],
1417
+ configuration: {
1418
+ keys: ['task_stale_hours_in_progress', 'task_stale_hours_waiting_review', 'task_auto_stale_enabled'],
1419
+ note: 'Configure via config table in database'
1420
+ }
1421
+ },
1422
+ task_linking: {
1423
+ title: 'Linking Tasks to Context',
1424
+ examples: [
1425
+ {
1426
+ scenario: 'Link task to decision',
1427
+ request: '{ action: "link", task_id: 5, link_type: "decision", target_id: "api_auth_method", link_relation: "implements" }',
1428
+ explanation: 'Track which tasks implement specific decisions'
1429
+ },
1430
+ {
1431
+ scenario: 'Link task to constraint',
1432
+ request: '{ action: "link", task_id: 5, link_type: "constraint", target_id: 3, link_relation: "addresses" }',
1433
+ explanation: 'Show task addresses a performance/architecture/security constraint'
1434
+ },
1435
+ {
1436
+ scenario: 'Link task to file',
1437
+ request: '{ action: "link", task_id: 5, link_type: "file", target_id: "src/api/auth.ts", link_relation: "modifies" }',
1438
+ explanation: 'Indicate which files the task will modify'
1439
+ }
1440
+ ]
1441
+ },
1442
+ batch_operations: {
1443
+ title: 'Batch Task Creation',
1444
+ examples: [
1445
+ {
1446
+ scenario: 'Create multiple related tasks',
1447
+ request: '{ action: "batch_create", tasks: [{"title": "Design API", "priority": 3}, {"title": "Implement API", "priority": 3}, {"title": "Write tests", "priority": 2}], atomic: false }',
1448
+ explanation: 'Create task breakdown - use atomic:false for best-effort'
1449
+ }
1450
+ ]
1451
+ },
1452
+ filtering_queries: {
1453
+ title: 'Advanced Task Queries',
1454
+ examples: [
1455
+ {
1456
+ scenario: 'Find high-priority tasks for agent',
1457
+ request: '{ action: "list", assigned_agent: "backend-agent", priority: 3, status: "todo" }',
1458
+ note: 'Priority is numeric: 1=low, 2=medium, 3=high, 4=critical'
1459
+ },
1460
+ {
1461
+ scenario: 'Get all security-related tasks',
1462
+ request: '{ action: "list", tags: ["security"], limit: 50 }',
1463
+ explanation: 'Filter by tags for topic-based views'
1464
+ },
1465
+ {
1466
+ scenario: 'View infrastructure layer tasks',
1467
+ request: '{ action: "list", layer: "infrastructure" }',
1468
+ explanation: 'See all DevOps/config related tasks'
1469
+ }
1470
+ ]
1471
+ }
1472
+ },
1473
+ valid_transitions: {
1474
+ from_todo: ['in_progress', 'blocked', 'done', 'archived'],
1475
+ from_in_progress: ['waiting_review', 'blocked', 'todo'],
1476
+ from_waiting_review: ['done', 'in_progress', 'todo'],
1477
+ from_blocked: ['todo', 'in_progress'],
1478
+ from_done: ['archived', 'todo'],
1479
+ from_archived: []
1480
+ },
1481
+ best_practices: {
1482
+ task_creation: [
1483
+ 'Use descriptive titles (200 char max)',
1484
+ 'Set appropriate priority: 1=low, 2=medium (default), 3=high, 4=critical',
1485
+ 'Assign to layer where work will be done',
1486
+ 'Tag comprehensively for easy filtering',
1487
+ 'Include acceptance_criteria for complex tasks'
1488
+ ],
1489
+ status_management: [
1490
+ 'Move to in_progress when starting work',
1491
+ 'Use waiting_review for completed but unverified work',
1492
+ 'Set to blocked with notes explaining dependency',
1493
+ 'Archive done tasks periodically for cleaner views'
1494
+ ],
1495
+ linking: [
1496
+ 'Link tasks to decisions they implement',
1497
+ 'Link to constraints they address',
1498
+ 'Link to files they will modify',
1499
+ 'Use descriptive link_relation values'
1500
+ ],
1501
+ coordination: [
1502
+ 'Use assigned_agent for clear ownership',
1503
+ 'Filter by status for Kanban board views',
1504
+ 'Monitor auto-stale transitions for stuck work',
1505
+ 'Use tags for cross-cutting concerns (security, performance, etc.)'
1506
+ ]
695
1507
  }
696
1508
  };
697
1509
  break;
@@ -714,13 +1526,27 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
714
1526
  }
715
1527
  });
716
1528
  // Handle graceful shutdown
717
- process.on('SIGINT', () => {
1529
+ process.on('SIGINT', async () => {
718
1530
  console.error('\n✓ Shutting down MCP server...');
1531
+ try {
1532
+ const watcher = FileWatcher.getInstance();
1533
+ await watcher.stop();
1534
+ }
1535
+ catch (error) {
1536
+ // Ignore watcher errors during shutdown
1537
+ }
719
1538
  closeDatabase();
720
1539
  process.exit(0);
721
1540
  });
722
- process.on('SIGTERM', () => {
1541
+ process.on('SIGTERM', async () => {
723
1542
  console.error('\n✓ Shutting down MCP server...');
1543
+ try {
1544
+ const watcher = FileWatcher.getInstance();
1545
+ await watcher.stop();
1546
+ }
1547
+ catch (error) {
1548
+ // Ignore watcher errors during shutdown
1549
+ }
724
1550
  closeDatabase();
725
1551
  process.exit(0);
726
1552
  });
@@ -729,6 +1555,15 @@ async function main() {
729
1555
  const transport = new StdioServerTransport();
730
1556
  await server.connect(transport);
731
1557
  console.error('✓ MCP Shared Context Server running on stdio');
1558
+ // Start file watcher for auto-task-tracking
1559
+ try {
1560
+ const watcher = FileWatcher.getInstance();
1561
+ await watcher.start();
1562
+ }
1563
+ catch (error) {
1564
+ console.error('⚠ Failed to start file watcher:', error);
1565
+ console.error(' (Auto task tracking will be disabled)');
1566
+ }
732
1567
  }
733
1568
  main().catch((error) => {
734
1569
  console.error('✗ Fatal error:', error);