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,602 @@
1
+ # Multi-Step Workflow Examples
2
+
3
+ **Comprehensive multi-agent workflows demonstrating coordinated use of multiple sqlew tools**
4
+
5
+ This document demonstrates real-world scenarios showing how different tools work together in practice.
6
+
7
+ ---
8
+
9
+ ## Workflow 1: Multi-Agent Feature Implementation
10
+
11
+ **Scenario**: Orchestrator agent coordinates 3 sub-agents to implement a new authentication feature.
12
+
13
+ ### Step 1: Orchestrator Creates Plan
14
+
15
+ ```javascript
16
+ // 1. Record the architecture decision
17
+ {
18
+ action: "set",
19
+ key: "auth_v2_implementation",
20
+ value: "Implement OAuth2 + JWT refresh token system",
21
+ layer: "business",
22
+ tags: ["auth", "feature", "v2.0.0"],
23
+ agent: "orchestrator-agent"
24
+ }
25
+
26
+ // 2. Add architectural constraints
27
+ {
28
+ action: "add",
29
+ category: "architecture",
30
+ constraint_text: "All auth tokens must expire within 15 minutes",
31
+ priority: "critical",
32
+ layer: "business",
33
+ tags: ["auth", "security"]
34
+ }
35
+
36
+ // 3. Create tasks for each sub-agent
37
+ {
38
+ action: "batch_create",
39
+ atomic: false,
40
+ tasks: [
41
+ {
42
+ title: "Implement OAuth2 provider integration",
43
+ assigned_agent: "backend-agent",
44
+ layer: "business",
45
+ priority: 4,
46
+ tags: ["auth", "oauth2"],
47
+ status: "todo"
48
+ },
49
+ {
50
+ title: "Create JWT token refresh endpoint",
51
+ assigned_agent: "api-agent",
52
+ layer: "presentation",
53
+ priority: 4,
54
+ tags: ["auth", "api"],
55
+ status: "todo"
56
+ },
57
+ {
58
+ title: "Update auth database schema",
59
+ assigned_agent: "db-agent",
60
+ layer: "data",
61
+ priority: 4,
62
+ tags: ["auth", "database"],
63
+ status: "todo"
64
+ }
65
+ ]
66
+ }
67
+
68
+ // 4. Broadcast start message
69
+ {
70
+ action: "send",
71
+ from_agent: "orchestrator-agent",
72
+ to_agent: null, // Broadcast
73
+ msg_type: "info",
74
+ message: "Starting OAuth2 + JWT implementation - check your assigned tasks",
75
+ priority: "high"
76
+ }
77
+ ```
78
+
79
+ ### Step 2: Backend Agent Executes Task
80
+
81
+ ```javascript
82
+ // 1. Mark task as in progress
83
+ {
84
+ action: "move",
85
+ task_id: 1,
86
+ new_status: "in_progress"
87
+ }
88
+
89
+ // 2. Record file changes
90
+ {
91
+ action: "record_batch",
92
+ atomic: false,
93
+ file_changes: [
94
+ {
95
+ file_path: "src/auth/oauth2.ts",
96
+ agent_name: "backend-agent",
97
+ change_type: "created",
98
+ layer: "business",
99
+ description: "OAuth2 provider integration"
100
+ },
101
+ {
102
+ file_path: "src/auth/jwt.ts",
103
+ agent_name: "backend-agent",
104
+ change_type: "modified",
105
+ layer: "business",
106
+ description: "Added refresh token logic"
107
+ }
108
+ ]
109
+ }
110
+
111
+ // 3. Report completion
112
+ {
113
+ action: "send",
114
+ from_agent: "backend-agent",
115
+ to_agent: "orchestrator-agent",
116
+ msg_type: "info",
117
+ message: "OAuth2 provider integration complete",
118
+ priority: "medium",
119
+ payload: {
120
+ files_changed: 2,
121
+ tests_passing: true
122
+ }
123
+ }
124
+
125
+ // 4. Complete task
126
+ {
127
+ action: "move",
128
+ task_id: 1,
129
+ new_status: "done"
130
+ }
131
+ ```
132
+
133
+ ### Step 3: Orchestrator Monitors Progress
134
+
135
+ ```javascript
136
+ // 1. Check for updates (efficient polling)
137
+ {
138
+ action: "has_updates",
139
+ agent_name: "orchestrator-agent",
140
+ since_timestamp: "2025-10-17T10:00:00Z"
141
+ }
142
+
143
+ // 2. Get task status
144
+ {
145
+ action: "list",
146
+ tags: ["auth"],
147
+ assigned_agent: null // All agents
148
+ }
149
+
150
+ // 3. Get unread messages
151
+ {
152
+ action: "get",
153
+ agent_name: "orchestrator-agent",
154
+ unread_only: true,
155
+ priority_filter: "high"
156
+ }
157
+
158
+ // 4. Check constraints compliance
159
+ {
160
+ action: "get",
161
+ category: "architecture",
162
+ layer: "business",
163
+ tags: ["auth"]
164
+ }
165
+ ```
166
+
167
+ ---
168
+
169
+ ## Workflow 2: Breaking Change Migration
170
+
171
+ **Scenario**: API endpoint is being deprecated and migrated to a new version.
172
+
173
+ ### Phase 1: Announce Deprecation
174
+
175
+ ```javascript
176
+ // 1. Record deprecation decision
177
+ {
178
+ action: "set_from_template",
179
+ template: "deprecation",
180
+ key: "api_v1_users_endpoint_deprecated",
181
+ value: "/v1/users endpoint deprecated, use /v2/users instead",
182
+ layer: "presentation",
183
+ tags: ["api", "deprecation", "v2.0.0"]
184
+ }
185
+
186
+ // 2. Add migration constraint
187
+ {
188
+ action: "add",
189
+ category: "architecture",
190
+ constraint_text: "All new API endpoints must use /v2 prefix",
191
+ priority: "high",
192
+ layer: "presentation",
193
+ tags: ["api", "migration"]
194
+ }
195
+
196
+ // 3. Create migration task
197
+ {
198
+ action: "create",
199
+ title: "Update all client integrations to use /v2/users",
200
+ description: "Migrate existing integrations before v1 sunset on 2025-12-01",
201
+ acceptance_criteria: "All clients successfully calling /v2/users with no errors",
202
+ layer: "presentation",
203
+ priority: 3,
204
+ tags: ["migration", "client"],
205
+ status: "todo"
206
+ }
207
+
208
+ // 4. Broadcast warning to all agents
209
+ {
210
+ action: "send",
211
+ from_agent: "api-agent",
212
+ to_agent: null, // Broadcast
213
+ msg_type: "warning",
214
+ message: "/v1/users DEPRECATED - Migrate to /v2/users by Dec 1",
215
+ priority: "critical",
216
+ payload: {
217
+ old_endpoint: "/v1/users",
218
+ new_endpoint: "/v2/users",
219
+ sunset_date: "2025-12-01"
220
+ }
221
+ }
222
+ ```
223
+
224
+ ### Phase 2: Track Migration Progress
225
+
226
+ ```javascript
227
+ // 1. Check file lock before editing
228
+ {
229
+ action: "check_lock",
230
+ file_path: "src/api/routes.ts",
231
+ lock_duration: 300 // 5 minutes
232
+ }
233
+
234
+ // 2. Record migration changes
235
+ {
236
+ action: "record",
237
+ file_path: "src/api/routes.ts",
238
+ agent_name: "migration-agent",
239
+ change_type: "modified",
240
+ layer: "presentation",
241
+ description: "Added /v2/users endpoint with backwards compatibility"
242
+ }
243
+
244
+ // 3. Link task to decision and constraint
245
+ {
246
+ action: "link",
247
+ task_id: 1,
248
+ link_type: "decision",
249
+ target_id: "api_v1_users_endpoint_deprecated",
250
+ link_relation: "implements"
251
+ }
252
+
253
+ {
254
+ action: "link",
255
+ task_id: 1,
256
+ link_type: "constraint",
257
+ target_id: 1, // The migration constraint ID
258
+ link_relation: "satisfies"
259
+ }
260
+
261
+ // 4. Update task status
262
+ {
263
+ action: "move",
264
+ task_id: 1,
265
+ new_status: "waiting_review"
266
+ }
267
+ ```
268
+
269
+ ### Phase 3: Complete Migration
270
+
271
+ ```javascript
272
+ // 1. Record completion decision
273
+ {
274
+ action: "set",
275
+ key: "api_v2_migration_complete",
276
+ value: "All clients successfully migrated to /v2/users endpoint",
277
+ layer: "presentation",
278
+ tags: ["api", "migration", "complete"],
279
+ status: "active"
280
+ }
281
+
282
+ // 2. Deactivate old constraint
283
+ {
284
+ action: "deactivate",
285
+ constraint_id: 1
286
+ }
287
+
288
+ // 3. Archive completed task
289
+ {
290
+ action: "archive",
291
+ task_id: 1
292
+ }
293
+
294
+ // 4. Notify stakeholders
295
+ {
296
+ action: "send",
297
+ from_agent: "migration-agent",
298
+ to_agent: null, // Broadcast
299
+ msg_type: "info",
300
+ message: "Migration to /v2/users complete - /v1 endpoint can be removed",
301
+ priority: "high"
302
+ }
303
+ ```
304
+
305
+ ---
306
+
307
+ ## Workflow 3: Session Continuity (Cross-Session Context)
308
+
309
+ **Scenario**: Agent needs to resume work after restart or handoff to another agent.
310
+
311
+ ### Agent A: Record Context Before Exit
312
+
313
+ ```javascript
314
+ // 1. Save current work state
315
+ {
316
+ action: "set",
317
+ key: "refactor_session_state",
318
+ value: "Completed 3/5 modules - currently working on auth module",
319
+ layer: "business",
320
+ tags: ["refactor", "session-state"],
321
+ scopes: ["auth-module"],
322
+ agent: "refactor-agent-a"
323
+ }
324
+
325
+ // 2. Update task with notes
326
+ {
327
+ action: "update",
328
+ task_id: 42,
329
+ notes: "Paused at auth/oauth2.ts line 145 - need to review token refresh logic before proceeding"
330
+ }
331
+
332
+ // 3. Record last file changes
333
+ {
334
+ action: "record_batch",
335
+ atomic: false,
336
+ file_changes: [
337
+ {
338
+ file_path: "src/auth/oauth2.ts",
339
+ agent_name: "refactor-agent-a",
340
+ change_type: "modified",
341
+ layer: "business",
342
+ description: "WIP: Token refresh refactoring (incomplete)"
343
+ }
344
+ ]
345
+ }
346
+
347
+ // 4. Send handoff message
348
+ {
349
+ action: "send",
350
+ from_agent: "refactor-agent-a",
351
+ to_agent: "refactor-agent-b",
352
+ msg_type: "request",
353
+ message: "Handing off refactor task - see task #42 for context",
354
+ priority: "high",
355
+ payload: {
356
+ task_id: 42,
357
+ last_file: "src/auth/oauth2.ts",
358
+ completion: "60%"
359
+ }
360
+ }
361
+ ```
362
+
363
+ ### Agent B: Resume Work
364
+
365
+ ```javascript
366
+ // 1. Retrieve session state
367
+ {
368
+ action: "get",
369
+ key: "refactor_session_state"
370
+ }
371
+
372
+ // 2. Get task details and history
373
+ {
374
+ action: "get",
375
+ task_id: 42
376
+ }
377
+
378
+ // 3. Check recent file changes
379
+ {
380
+ action: "get",
381
+ file_path: "src/auth/oauth2.ts",
382
+ since: "2025-10-17T00:00:00Z"
383
+ }
384
+
385
+ // 4. Check for any related constraints
386
+ {
387
+ action: "get",
388
+ layer: "business",
389
+ tags: ["auth"],
390
+ active_only: true
391
+ }
392
+
393
+ // 5. Check messages
394
+ {
395
+ action: "get",
396
+ agent_name: "refactor-agent-b",
397
+ unread_only: true
398
+ }
399
+
400
+ // 6. Acknowledge handoff
401
+ {
402
+ action: "send",
403
+ from_agent: "refactor-agent-b",
404
+ to_agent: "refactor-agent-a",
405
+ msg_type: "info",
406
+ message: "Handoff received - resuming work on task #42",
407
+ priority: "medium"
408
+ }
409
+
410
+ // 7. Move task to in_progress
411
+ {
412
+ action: "move",
413
+ task_id: 42,
414
+ new_status: "in_progress"
415
+ }
416
+ ```
417
+
418
+ ---
419
+
420
+ ## Workflow 4: Update Polling Pattern (Efficient Subscription)
421
+
422
+ **Scenario**: Monitor agent watches for specific changes and reacts accordingly.
423
+
424
+ ### Monitor Agent: Efficient Polling Loop
425
+
426
+ ```javascript
427
+ // Initial timestamp
428
+ let lastCheck = "2025-10-17T10:00:00Z";
429
+
430
+ // Polling function (call every 30 seconds)
431
+ async function pollForUpdates() {
432
+ // 1. Lightweight check for ANY updates (5-10 tokens)
433
+ const updates = await {
434
+ action: "has_updates",
435
+ agent_name: "monitor-agent",
436
+ since_timestamp: lastCheck
437
+ };
438
+
439
+ // Response: {
440
+ // has_updates: true,
441
+ // counts: {decisions: 2, messages: 3, files: 1, tasks: 1}
442
+ // }
443
+
444
+ if (!updates.has_updates) {
445
+ // Nothing changed - skip heavy queries
446
+ return;
447
+ }
448
+
449
+ // 2. Only fetch if updates detected
450
+ if (updates.counts.messages > 0) {
451
+ const messages = await {
452
+ action: "get",
453
+ agent_name: "monitor-agent",
454
+ unread_only: true,
455
+ priority_filter: "critical"
456
+ };
457
+
458
+ // Process critical messages
459
+ for (const msg of messages.messages) {
460
+ if (msg.msg_type === "warning") {
461
+ // Handle warning
462
+ await handleWarning(msg);
463
+ }
464
+ }
465
+ }
466
+
467
+ // 3. Check for task updates
468
+ if (updates.counts.tasks > 0) {
469
+ const tasks = await {
470
+ action: "list",
471
+ status: "blocked",
472
+ limit: 10
473
+ };
474
+
475
+ // Alert on blocked tasks
476
+ if (tasks.length > 0) {
477
+ await {
478
+ action: "send",
479
+ from_agent: "monitor-agent",
480
+ to_agent: "orchestrator-agent",
481
+ msg_type: "warning",
482
+ message: `${tasks.length} tasks are blocked - requires attention`,
483
+ priority: "high"
484
+ };
485
+ }
486
+ }
487
+
488
+ // 4. Check for breaking changes
489
+ if (updates.counts.decisions > 0) {
490
+ const breaking = await {
491
+ action: "search_tags",
492
+ tags: ["breaking-change"],
493
+ match_mode: "AND",
494
+ status: "active"
495
+ };
496
+
497
+ if (breaking.length > 0) {
498
+ // Alert on breaking changes
499
+ await {
500
+ action: "send",
501
+ from_agent: "monitor-agent",
502
+ to_agent: null, // Broadcast
503
+ msg_type: "warning",
504
+ message: "New breaking changes detected - review required",
505
+ priority: "critical"
506
+ };
507
+ }
508
+ }
509
+
510
+ // 5. Update last check timestamp
511
+ lastCheck = new Date().toISOString();
512
+ }
513
+
514
+ // Token efficiency:
515
+ // - No updates: ~10 tokens (has_updates only)
516
+ // - With updates: ~50-200 tokens (selective fetching)
517
+ // - vs polling all data: ~500-1000 tokens every time
518
+ ```
519
+
520
+ ### Activity Log Analysis
521
+
522
+ ```javascript
523
+ // Monitor can also analyze activity patterns
524
+ {
525
+ action: "activity_log",
526
+ since: "1h", // Last hour
527
+ agent_names: ["*"], // All agents
528
+ actions: ["set", "send", "create"], // Specific actions
529
+ limit: 100
530
+ }
531
+
532
+ // Response shows all activity:
533
+ // [
534
+ // {
535
+ // timestamp: "2025-10-17T11:45:23Z",
536
+ // agent_name: "backend-agent",
537
+ // action: "set",
538
+ // table: "decisions",
539
+ // key_or_details: "auth_implementation_complete"
540
+ // },
541
+ // {
542
+ // timestamp: "2025-10-17T11:44:15Z",
543
+ // agent_name: "api-agent",
544
+ // action: "send",
545
+ // table: "messages",
546
+ // key_or_details: "message_id:145"
547
+ // }
548
+ // ]
549
+
550
+ // Use this for:
551
+ // - Debugging agent behavior
552
+ // - Audit trails
553
+ // - Performance monitoring
554
+ // - Detecting stuck agents (no activity)
555
+ ```
556
+
557
+ ### Automatic Cleanup Trigger
558
+
559
+ ```javascript
560
+ // Monitor can also manage database health
561
+ {
562
+ action: "db_stats"
563
+ }
564
+
565
+ // Response:
566
+ // {
567
+ // total_decisions: 342,
568
+ // total_messages: 1203,
569
+ // total_file_changes: 589,
570
+ // total_constraints: 15,
571
+ // total_tasks: 47,
572
+ // db_size_kb: 1024
573
+ // }
574
+
575
+ // If database too large, trigger cleanup
576
+ if (stats.total_messages > 1000) {
577
+ await {
578
+ action: "clear",
579
+ messages_older_than_hours: 24,
580
+ file_changes_older_than_days: 7
581
+ };
582
+
583
+ // Notify about cleanup
584
+ await {
585
+ action: "send",
586
+ from_agent: "monitor-agent",
587
+ to_agent: null,
588
+ msg_type: "info",
589
+ message: "Database cleanup completed - removed old messages and file history",
590
+ priority: "low"
591
+ };
592
+ }
593
+ ```
594
+
595
+ ---
596
+
597
+ ## Related Documentation
598
+
599
+ - **[TOOL_SELECTION.md](TOOL_SELECTION.md)** - Choosing the right tool for your task
600
+ - **[TOOL_REFERENCE.md](TOOL_REFERENCE.md)** - Complete parameter reference
601
+ - **[BEST_PRACTICES.md](BEST_PRACTICES.md)** - Common errors and best practices
602
+ - **[AI_AGENT_GUIDE.md](AI_AGENT_GUIDE.md)** - Complete guide (original comprehensive version)