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.
- package/CHANGELOG.md +891 -605
- package/README.md +302 -690
- package/assets/kanban-style.png +0 -0
- package/assets/schema.sql +531 -402
- package/dist/database.d.ts +9 -0
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +33 -34
- package/dist/database.js.map +1 -1
- package/dist/index.js +1024 -213
- package/dist/index.js.map +1 -1
- package/dist/migrations/add-task-tables.d.ts +47 -0
- package/dist/migrations/add-task-tables.d.ts.map +1 -0
- package/dist/migrations/add-task-tables.js +285 -0
- package/dist/migrations/add-task-tables.js.map +1 -0
- package/dist/migrations/index.d.ts +96 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +239 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/migrations/migrate-decisions-to-tasks.d.ts +61 -0
- package/dist/migrations/migrate-decisions-to-tasks.d.ts.map +1 -0
- package/dist/migrations/migrate-decisions-to-tasks.js +442 -0
- package/dist/migrations/migrate-decisions-to-tasks.js.map +1 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +14 -3
- package/dist/schema.js.map +1 -1
- package/dist/tools/constraints.d.ts +4 -0
- package/dist/tools/constraints.d.ts.map +1 -1
- package/dist/tools/constraints.js +6 -27
- package/dist/tools/constraints.js.map +1 -1
- package/dist/tools/context.d.ts +17 -1
- package/dist/tools/context.d.ts.map +1 -1
- package/dist/tools/context.js +195 -190
- package/dist/tools/context.js.map +1 -1
- package/dist/tools/files.d.ts.map +1 -1
- package/dist/tools/files.js +113 -166
- package/dist/tools/files.js.map +1 -1
- package/dist/tools/messaging.d.ts +2 -9
- package/dist/tools/messaging.d.ts.map +1 -1
- package/dist/tools/messaging.js +67 -126
- package/dist/tools/messaging.js.map +1 -1
- package/dist/tools/tasks.d.ts +90 -0
- package/dist/tools/tasks.d.ts.map +1 -0
- package/dist/tools/tasks.js +732 -0
- package/dist/tools/tasks.js.map +1 -0
- package/dist/tools/utils.d.ts +8 -1
- package/dist/tools/utils.d.ts.map +1 -1
- package/dist/tools/utils.js +50 -21
- package/dist/tools/utils.js.map +1 -1
- package/dist/types.d.ts +14 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/batch.d.ts +69 -0
- package/dist/utils/batch.d.ts.map +1 -0
- package/dist/utils/batch.js +148 -0
- package/dist/utils/batch.js.map +1 -0
- package/dist/utils/query-builder.d.ts +68 -0
- package/dist/utils/query-builder.d.ts.map +1 -0
- package/dist/utils/query-builder.js +116 -0
- package/dist/utils/query-builder.js.map +1 -0
- package/dist/utils/task-stale-detection.d.ts +28 -0
- package/dist/utils/task-stale-detection.d.ts.map +1 -0
- package/dist/utils/task-stale-detection.js +92 -0
- package/dist/utils/task-stale-detection.js.map +1 -0
- package/dist/utils/validators.d.ts +57 -0
- package/dist/utils/validators.d.ts.map +1 -0
- package/dist/utils/validators.js +117 -0
- package/dist/utils/validators.js.map +1 -0
- package/docs/AI_AGENT_GUIDE.md +1471 -648
- package/{ARCHITECTURE.md → docs/ARCHITECTURE.md} +636 -636
- package/docs/BEST_PRACTICES.md +481 -0
- package/docs/DECISION_TO_TASK_MIGRATION_GUIDE.md +457 -0
- package/docs/MIGRATION_CHAIN.md +280 -0
- package/{MIGRATION_v2.md → docs/MIGRATION_v2.md} +538 -538
- package/docs/SHARED_CONCEPTS.md +339 -0
- package/docs/TASK_ACTIONS.md +854 -0
- package/docs/TASK_LINKING.md +729 -0
- package/docs/TASK_MIGRATION.md +701 -0
- package/docs/TASK_OVERVIEW.md +363 -0
- package/docs/TASK_SYSTEM.md +1244 -0
- package/docs/TOOL_REFERENCE.md +471 -0
- package/docs/TOOL_SELECTION.md +279 -0
- package/docs/WORKFLOWS.md +602 -0
- package/docs/refactoring-summary-2025-10-17.md +365 -0
- package/docs/requirement-2025-10-17.md +508 -0
- package/package.json +64 -64
package/docs/AI_AGENT_GUIDE.md
CHANGED
|
@@ -1,648 +1,1471 @@
|
|
|
1
|
-
# AI Agent Guide for MCP
|
|
2
|
-
|
|
3
|
-
**Quick Reference for Claude Code and other AI agents using sqlew**
|
|
4
|
-
|
|
5
|
-
## 🚨 Most Important Rule
|
|
6
|
-
|
|
7
|
-
**ALWAYS include the `action` parameter in EVERY tool call.** This is the #1 cause of errors.
|
|
8
|
-
|
|
9
|
-
```javascript
|
|
10
|
-
// ❌ WRONG - Missing action
|
|
11
|
-
{
|
|
12
|
-
key: "some_key",
|
|
13
|
-
value: "some value"
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// ✅ CORRECT - action parameter present
|
|
17
|
-
{
|
|
18
|
-
action: "set",
|
|
19
|
-
key: "some_key",
|
|
20
|
-
value: "some value"
|
|
21
|
-
}
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
---
|
|
25
|
-
|
|
26
|
-
## Table of Contents
|
|
27
|
-
|
|
28
|
-
1. [Quick Start](#quick-start)
|
|
29
|
-
2. [
|
|
30
|
-
3. [
|
|
31
|
-
4. [
|
|
32
|
-
5. [
|
|
33
|
-
6. [
|
|
34
|
-
7. [
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
|
147
|
-
|
|
148
|
-
| **
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
|
153
|
-
|
|
154
|
-
| **
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
**
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
|
288
|
-
|
|
289
|
-
| **list** |
|
|
290
|
-
| **search_tags** |
|
|
291
|
-
| **search_layer** |
|
|
292
|
-
| **
|
|
293
|
-
| **
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
**
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
###
|
|
458
|
-
|
|
459
|
-
```
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
**
|
|
1
|
+
# AI Agent Guide for MCP sqlew
|
|
2
|
+
|
|
3
|
+
**Quick Reference for Claude Code and other AI agents using sqlew**
|
|
4
|
+
|
|
5
|
+
## 🚨 Most Important Rule
|
|
6
|
+
|
|
7
|
+
**ALWAYS include the `action` parameter in EVERY tool call.** This is the #1 cause of errors.
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
10
|
+
// ❌ WRONG - Missing action
|
|
11
|
+
{
|
|
12
|
+
key: "some_key",
|
|
13
|
+
value: "some value"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// ✅ CORRECT - action parameter present
|
|
17
|
+
{
|
|
18
|
+
action: "set",
|
|
19
|
+
key: "some_key",
|
|
20
|
+
value: "some value"
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Table of Contents
|
|
27
|
+
|
|
28
|
+
1. [Quick Start](#quick-start)
|
|
29
|
+
2. [When to Use Each Tool: Decision Tree](#when-to-use-each-tool-decision-tree)
|
|
30
|
+
3. [Parameter Requirements by Tool](#parameter-requirements-by-tool)
|
|
31
|
+
4. [Common Errors & Solutions](#common-errors--solutions)
|
|
32
|
+
5. [Search Actions Decision Tree](#search-actions-decision-tree)
|
|
33
|
+
6. [Batch Operations Guide](#batch-operations-guide)
|
|
34
|
+
7. [Template System](#template-system)
|
|
35
|
+
8. [Multi-Step Workflow Examples](#multi-step-workflow-examples)
|
|
36
|
+
9. [Best Practices](#best-practices)
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
### Basic Decision Workflow
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
// 1. Set a decision
|
|
46
|
+
{
|
|
47
|
+
action: "set",
|
|
48
|
+
key: "auth_method",
|
|
49
|
+
value: "jwt",
|
|
50
|
+
layer: "business",
|
|
51
|
+
tags: ["security", "authentication"]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 2. Get the decision
|
|
55
|
+
{
|
|
56
|
+
action: "get",
|
|
57
|
+
key: "auth_method"
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 3. List decisions with filters
|
|
61
|
+
{
|
|
62
|
+
action: "list",
|
|
63
|
+
status: "active",
|
|
64
|
+
layer: "business"
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Basic Messaging Workflow
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
// 1. Send a message
|
|
72
|
+
{
|
|
73
|
+
action: "send",
|
|
74
|
+
from_agent: "bot1",
|
|
75
|
+
msg_type: "info",
|
|
76
|
+
message: "Task completed successfully",
|
|
77
|
+
priority: "high"
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 2. Get messages
|
|
81
|
+
{
|
|
82
|
+
action: "get",
|
|
83
|
+
agent_name: "bot1",
|
|
84
|
+
unread_only: true
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// 3. Mark as read
|
|
88
|
+
{
|
|
89
|
+
action: "mark_read",
|
|
90
|
+
agent_name: "bot1",
|
|
91
|
+
message_ids: [1, 2, 3]
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## When to Use Each Tool: Decision Tree
|
|
98
|
+
|
|
99
|
+
### Understanding Tool Purposes
|
|
100
|
+
|
|
101
|
+
Each tool serves a distinct purpose in the MCP sqlew ecosystem:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
┌──────────────────────────────────────────────────────────┐
|
|
105
|
+
│ What do you need to do? │
|
|
106
|
+
└────────────────┬─────────────────────────────────────────┘
|
|
107
|
+
│
|
|
108
|
+
├─ Record a CHOICE that was made?
|
|
109
|
+
│ └─> Use `decision` tool
|
|
110
|
+
│ • Examples: "We chose JWT auth", "Selected PostgreSQL"
|
|
111
|
+
│ • Key: Captures PAST decisions
|
|
112
|
+
│ • Supports: versioning, tags, layers, scopes
|
|
113
|
+
│
|
|
114
|
+
├─ Communicate with other agents?
|
|
115
|
+
│ └─> Use `message` tool
|
|
116
|
+
│ • Examples: Task updates, warnings, requests
|
|
117
|
+
│ • Key: Real-time communication
|
|
118
|
+
│ • Supports: priority, broadcast, read tracking
|
|
119
|
+
│
|
|
120
|
+
├─ Define a REQUIREMENT that must be followed?
|
|
121
|
+
│ └─> Use `constraint` tool
|
|
122
|
+
│ • Examples: "API must be <100ms", "Code coverage >80%"
|
|
123
|
+
│ • Key: Enforces RULES
|
|
124
|
+
│ • Supports: priority, categories, layers
|
|
125
|
+
│
|
|
126
|
+
├─ Track WORK to be done?
|
|
127
|
+
│ └─> Use `task` tool
|
|
128
|
+
│ • Examples: "Implement feature X", "Fix bug Y"
|
|
129
|
+
│ • Key: Tracks TODO items and progress
|
|
130
|
+
│ • Supports: status transitions, auto-stale, linking
|
|
131
|
+
│
|
|
132
|
+
├─ Record file modifications?
|
|
133
|
+
│ └─> Use `file` tool
|
|
134
|
+
│ • Examples: Track changes, check locks
|
|
135
|
+
│ • Key: File change history
|
|
136
|
+
│ • Supports: layers, change types, lock detection
|
|
137
|
+
│
|
|
138
|
+
└─ Get statistics or manage data?
|
|
139
|
+
└─> Use `stats` or `config` tools
|
|
140
|
+
• stats: Database metrics, cleanup, activity logs
|
|
141
|
+
• config: Retention settings, auto-deletion
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Tool Comparison Table
|
|
145
|
+
|
|
146
|
+
| Tool | Use For | Don't Use For | Key Feature |
|
|
147
|
+
|------|---------|---------------|-------------|
|
|
148
|
+
| **decision** | Recording choices made | Future work, requirements | Version history tracking |
|
|
149
|
+
| **message** | Agent communication | Permanent records, decisions | Priority-based delivery |
|
|
150
|
+
| **constraint** | Requirements & rules | Decisions, tasks | Category-based organization |
|
|
151
|
+
| **task** | Work tracking (TODO) | Decisions, history | Auto-stale detection |
|
|
152
|
+
| **file** | File change tracking | Code search, content | Layer-based organization |
|
|
153
|
+
| **stats** | Metrics & cleanup | Data storage | Aggregated views |
|
|
154
|
+
| **config** | Retention settings | Business logic | Auto-deletion control |
|
|
155
|
+
|
|
156
|
+
### Decision vs Constraint vs Task
|
|
157
|
+
|
|
158
|
+
This is the most common confusion. Here's the distinction:
|
|
159
|
+
|
|
160
|
+
| Concept | Definition | Example | Tool |
|
|
161
|
+
|---------|------------|---------|------|
|
|
162
|
+
| **Decision** | A choice that WAS made | "We chose JWT authentication" | `decision` |
|
|
163
|
+
| **Constraint** | A requirement that MUST be followed | "Response time must be <100ms" | `constraint` |
|
|
164
|
+
| **Task** | Work that NEEDS to be done | "Implement JWT authentication" | `task` |
|
|
165
|
+
|
|
166
|
+
### Scenario-Based Tool Selection
|
|
167
|
+
|
|
168
|
+
#### Scenario 1: Breaking API Change
|
|
169
|
+
```javascript
|
|
170
|
+
// 1. Record the decision (what changed)
|
|
171
|
+
{
|
|
172
|
+
action: "set",
|
|
173
|
+
key: "api_v2_breaking_change",
|
|
174
|
+
value: "Moved /users endpoint to /v2/users",
|
|
175
|
+
layer: "presentation",
|
|
176
|
+
tags: ["api", "breaking-change", "v2.0.0"]
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// 2. Add a constraint (requirement going forward)
|
|
180
|
+
{
|
|
181
|
+
action: "add",
|
|
182
|
+
category: "architecture",
|
|
183
|
+
constraint_text: "All API endpoints must include version prefix",
|
|
184
|
+
layer: "presentation",
|
|
185
|
+
tags: ["api", "versioning"]
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// 3. Create migration task
|
|
189
|
+
{
|
|
190
|
+
action: "create",
|
|
191
|
+
title: "Migrate clients to /v2/users endpoint",
|
|
192
|
+
status: "todo",
|
|
193
|
+
layer: "presentation",
|
|
194
|
+
tags: ["migration", "v2.0.0"]
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// 4. Notify other agents
|
|
198
|
+
{
|
|
199
|
+
action: "send",
|
|
200
|
+
from_agent: "api-agent",
|
|
201
|
+
msg_type: "warning",
|
|
202
|
+
message: "Breaking change: /users moved to /v2/users",
|
|
203
|
+
priority: "critical"
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
#### Scenario 2: Performance Issue
|
|
208
|
+
```javascript
|
|
209
|
+
// 1. Record the finding (decision to investigate)
|
|
210
|
+
{
|
|
211
|
+
action: "set",
|
|
212
|
+
key: "db_performance_issue_found",
|
|
213
|
+
value: "Query latency increased 300% in production",
|
|
214
|
+
layer: "data",
|
|
215
|
+
tags: ["performance", "database", "production"]
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// 2. Add performance constraint
|
|
219
|
+
{
|
|
220
|
+
action: "add",
|
|
221
|
+
category: "performance",
|
|
222
|
+
constraint_text: "Database queries must complete within 50ms",
|
|
223
|
+
priority: "high",
|
|
224
|
+
layer: "data"
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// 3. Create optimization task
|
|
228
|
+
{
|
|
229
|
+
action: "create",
|
|
230
|
+
title: "Add indexes to user_sessions table",
|
|
231
|
+
status: "in_progress",
|
|
232
|
+
priority: 4,
|
|
233
|
+
layer: "data",
|
|
234
|
+
tags: ["performance", "database"]
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
#### Scenario 3: Security Vulnerability
|
|
239
|
+
```javascript
|
|
240
|
+
// 1. Record the vulnerability (decision about issue)
|
|
241
|
+
{
|
|
242
|
+
action: "set",
|
|
243
|
+
key: "auth_vulnerability_CVE_2025_1234",
|
|
244
|
+
value: "JWT library vulnerable to timing attacks",
|
|
245
|
+
layer: "business",
|
|
246
|
+
tags: ["security", "vulnerability", "auth"]
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// 2. Add security constraint
|
|
250
|
+
{
|
|
251
|
+
action: "add",
|
|
252
|
+
category: "security",
|
|
253
|
+
constraint_text: "All auth tokens must use constant-time comparison",
|
|
254
|
+
priority: "critical",
|
|
255
|
+
layer: "business"
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// 3. Create fix task
|
|
259
|
+
{
|
|
260
|
+
action: "create",
|
|
261
|
+
title: "Upgrade JWT library and implement constant-time comparison",
|
|
262
|
+
status: "in_progress",
|
|
263
|
+
priority: 4,
|
|
264
|
+
assigned_agent: "security-agent",
|
|
265
|
+
layer: "business"
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// 4. Alert all agents
|
|
269
|
+
{
|
|
270
|
+
action: "send",
|
|
271
|
+
from_agent: "security-agent",
|
|
272
|
+
to_agent: null, // Broadcast
|
|
273
|
+
msg_type: "warning",
|
|
274
|
+
message: "URGENT: Auth vulnerability found, fix in progress",
|
|
275
|
+
priority: "critical"
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## Parameter Requirements by Tool
|
|
282
|
+
|
|
283
|
+
### `decision` Tool
|
|
284
|
+
|
|
285
|
+
| Action | Required | Optional |
|
|
286
|
+
|--------|----------|----------|
|
|
287
|
+
| **set** | action, key, value, layer | agent, version, status, tags, scopes |
|
|
288
|
+
| **get** | action, key | version |
|
|
289
|
+
| **list** | action | status, layer, tags, scope, tag_match, limit, offset |
|
|
290
|
+
| **search_tags** | action, tags | match_mode, status, layer |
|
|
291
|
+
| **search_layer** | action, layer | status, include_tags |
|
|
292
|
+
| **versions** | action, key | - |
|
|
293
|
+
| **quick_set** | action, key, value | agent, layer, version, status, tags, scopes |
|
|
294
|
+
| **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 |
|
|
295
|
+
| **set_batch** | action, decisions | atomic |
|
|
296
|
+
| **has_updates** | action, agent_name, since_timestamp | - |
|
|
297
|
+
| **set_from_template** | action, template, key, value, layer | agent, version, status, tags, scopes |
|
|
298
|
+
| **create_template** | action, name, defaults | required_fields, created_by |
|
|
299
|
+
| **list_templates** | action | - |
|
|
300
|
+
|
|
301
|
+
### `message` Tool
|
|
302
|
+
|
|
303
|
+
| Action | Required | Optional |
|
|
304
|
+
|--------|----------|----------|
|
|
305
|
+
| **send** | action, from_agent, msg_type, message | to_agent, priority, payload |
|
|
306
|
+
| **get** | action, agent_name | unread_only, priority_filter, msg_type_filter, limit |
|
|
307
|
+
| **mark_read** | action, agent_name, message_ids | - |
|
|
308
|
+
| **send_batch** | action, messages | atomic |
|
|
309
|
+
|
|
310
|
+
### `file` Tool
|
|
311
|
+
|
|
312
|
+
| Action | Required | Optional |
|
|
313
|
+
|--------|----------|----------|
|
|
314
|
+
| **record** | action, file_path, agent_name, change_type | layer, description |
|
|
315
|
+
| **get** | action | file_path, agent_name, layer, change_type, since, limit |
|
|
316
|
+
| **check_lock** | action, file_path | lock_duration |
|
|
317
|
+
| **record_batch** | action, file_changes | atomic |
|
|
318
|
+
|
|
319
|
+
### `constraint` Tool
|
|
320
|
+
|
|
321
|
+
| Action | Required | Optional |
|
|
322
|
+
|--------|----------|----------|
|
|
323
|
+
| **add** | action, category, constraint_text | priority, layer, tags, created_by |
|
|
324
|
+
| **get** | action | category, layer, priority, tags, active_only, limit |
|
|
325
|
+
| **deactivate** | action, constraint_id | - |
|
|
326
|
+
|
|
327
|
+
### `stats` Tool
|
|
328
|
+
|
|
329
|
+
| Action | Required | Optional |
|
|
330
|
+
|--------|----------|----------|
|
|
331
|
+
| **layer_summary** | action | - |
|
|
332
|
+
| **db_stats** | action | - |
|
|
333
|
+
| **clear** | action | messages_older_than_hours, file_changes_older_than_days |
|
|
334
|
+
| **activity_log** | action | since, agent_names, actions, limit |
|
|
335
|
+
|
|
336
|
+
### `config` Tool
|
|
337
|
+
|
|
338
|
+
| Action | Required | Optional |
|
|
339
|
+
|--------|----------|----------|
|
|
340
|
+
| **get** | action | - |
|
|
341
|
+
| **update** | action | ignoreWeekend, messageRetentionHours, fileHistoryRetentionDays |
|
|
342
|
+
|
|
343
|
+
### `task` Tool
|
|
344
|
+
|
|
345
|
+
| Action | Required | Optional |
|
|
346
|
+
|--------|----------|----------|
|
|
347
|
+
| **create** | action, title | description, acceptance_criteria, notes, priority, assigned_agent, created_by_agent, layer, tags, status |
|
|
348
|
+
| **update** | action, task_id | title, priority, assigned_agent, layer, description, acceptance_criteria, notes |
|
|
349
|
+
| **get** | action, task_id | - |
|
|
350
|
+
| **list** | action | status, assigned_agent, layer, tags, limit, offset |
|
|
351
|
+
| **move** | action, task_id, new_status | - |
|
|
352
|
+
| **link** | action, task_id, link_type, target_id | link_relation |
|
|
353
|
+
| **archive** | action, task_id | - |
|
|
354
|
+
| **batch_create** | action, tasks | atomic |
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
## Common Errors & Solutions
|
|
359
|
+
|
|
360
|
+
💡 **See also**: [ARCHITECTURE.md](ARCHITECTURE.md) for detailed layer, enum, and status definitions.
|
|
361
|
+
|
|
362
|
+
### Error: "Unknown action: undefined"
|
|
363
|
+
|
|
364
|
+
**Cause**: Missing `action` parameter
|
|
365
|
+
|
|
366
|
+
**Solution**: Always include `action` as the first parameter
|
|
367
|
+
|
|
368
|
+
```javascript
|
|
369
|
+
// ❌ WRONG
|
|
370
|
+
{
|
|
371
|
+
key: "some_key",
|
|
372
|
+
value: "some value",
|
|
373
|
+
layer: "business"
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// ✅ CORRECT
|
|
377
|
+
{
|
|
378
|
+
action: "set",
|
|
379
|
+
key: "some_key",
|
|
380
|
+
value: "some value",
|
|
381
|
+
layer: "business"
|
|
382
|
+
}
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### Error: "Parameter \"value\" is required"
|
|
386
|
+
|
|
387
|
+
**Cause**: Using `defaults` instead of direct parameters with templates
|
|
388
|
+
|
|
389
|
+
**Solution**: Provide parameters directly, not nested in `defaults`
|
|
390
|
+
|
|
391
|
+
```javascript
|
|
392
|
+
// ❌ WRONG
|
|
393
|
+
{
|
|
394
|
+
action: "set_from_template",
|
|
395
|
+
template: "deprecation",
|
|
396
|
+
key: "some_key",
|
|
397
|
+
defaults: {
|
|
398
|
+
value: "...",
|
|
399
|
+
layer: "cross-cutting"
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// ✅ CORRECT
|
|
404
|
+
{
|
|
405
|
+
action: "set_from_template",
|
|
406
|
+
template: "deprecation",
|
|
407
|
+
key: "some_key",
|
|
408
|
+
value: "...",
|
|
409
|
+
layer: "cross-cutting"
|
|
410
|
+
}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
### Error: "Invalid layer"
|
|
414
|
+
|
|
415
|
+
**Cause**: Using a layer name that doesn't exist
|
|
416
|
+
|
|
417
|
+
**Solution**: Use one of the 5 standard layers
|
|
418
|
+
|
|
419
|
+
**Valid layers**: `presentation`, `business`, `data`, `infrastructure`, `cross-cutting`
|
|
420
|
+
|
|
421
|
+
```javascript
|
|
422
|
+
// ❌ WRONG
|
|
423
|
+
{
|
|
424
|
+
action: "set",
|
|
425
|
+
key: "my_key",
|
|
426
|
+
value: "my_value",
|
|
427
|
+
layer: "backend" // Invalid!
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// ✅ CORRECT
|
|
431
|
+
{
|
|
432
|
+
action: "set",
|
|
433
|
+
key: "my_key",
|
|
434
|
+
value: "my_value",
|
|
435
|
+
layer: "business" // Valid!
|
|
436
|
+
}
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
### Error: "Invalid status"
|
|
440
|
+
|
|
441
|
+
**Cause**: Using a status value that doesn't exist
|
|
442
|
+
|
|
443
|
+
**Solution**: Use one of the 3 valid statuses
|
|
444
|
+
|
|
445
|
+
**Valid statuses**: `active`, `deprecated`, `draft`
|
|
446
|
+
|
|
447
|
+
### Error: "Batch operations are limited to 50 items maximum"
|
|
448
|
+
|
|
449
|
+
**Cause**: Too many items in batch array
|
|
450
|
+
|
|
451
|
+
**Solution**: Split into multiple batches of ≤50 items each
|
|
452
|
+
|
|
453
|
+
---
|
|
454
|
+
|
|
455
|
+
## Search Actions Decision Tree
|
|
456
|
+
|
|
457
|
+
### When to use which search action?
|
|
458
|
+
|
|
459
|
+
```
|
|
460
|
+
┌─────────────────────────────────────┐
|
|
461
|
+
│ What do you want to search by? │
|
|
462
|
+
└──────────┬──────────────────────────┘
|
|
463
|
+
│
|
|
464
|
+
├─ Simple filters (status, layer, tags)?
|
|
465
|
+
│ └─> Use action: "list"
|
|
466
|
+
│
|
|
467
|
+
├─ Primarily by tags?
|
|
468
|
+
│ └─> Use action: "search_tags"
|
|
469
|
+
│ • match_mode: "AND" (all tags) or "OR" (any tag)
|
|
470
|
+
│
|
|
471
|
+
├─ Primarily by layer?
|
|
472
|
+
│ └─> Use action: "search_layer"
|
|
473
|
+
│
|
|
474
|
+
├─ Complex multi-filter query?
|
|
475
|
+
│ └─> Use action: "search_advanced"
|
|
476
|
+
│ • Multiple layers (OR)
|
|
477
|
+
│ • Tag combinations (AND/OR)
|
|
478
|
+
│ • Temporal filtering
|
|
479
|
+
│ • Full-text search
|
|
480
|
+
│ • Pagination
|
|
481
|
+
│
|
|
482
|
+
└─ Need version history?
|
|
483
|
+
└─> Use action: "versions"
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
### Detailed Search Comparison
|
|
487
|
+
|
|
488
|
+
| Action | Use When | Key Features |
|
|
489
|
+
|--------|----------|--------------|
|
|
490
|
+
| **list** | Basic filtering | Simple status/layer/tag filters, no pagination |
|
|
491
|
+
| **search_tags** | Tag-focused search | AND/OR logic for tags, optional status/layer |
|
|
492
|
+
| **search_layer** | Layer-focused search | Get all decisions in specific layer(s) |
|
|
493
|
+
| **search_advanced** | Complex queries | Full filtering, pagination, sorting, text search |
|
|
494
|
+
| **versions** | History tracking | Get all versions of a specific decision |
|
|
495
|
+
|
|
496
|
+
---
|
|
497
|
+
|
|
498
|
+
## Batch Operations Guide
|
|
499
|
+
|
|
500
|
+
### Atomic vs Non-Atomic Mode
|
|
501
|
+
|
|
502
|
+
**Atomic Mode** (`atomic: true`, default):
|
|
503
|
+
- All succeed or all fail as a single transaction
|
|
504
|
+
- If ANY item fails, entire batch is rolled back
|
|
505
|
+
- Error is thrown immediately on first failure
|
|
506
|
+
- Use for: Critical operations requiring consistency
|
|
507
|
+
|
|
508
|
+
**Non-Atomic Mode** (`atomic: false`, **recommended for AI agents**):
|
|
509
|
+
- Each item processed independently
|
|
510
|
+
- If some fail, others still succeed
|
|
511
|
+
- Returns partial results with per-item success/error status
|
|
512
|
+
- Use for: Best-effort batch operations, when individual failures are acceptable
|
|
513
|
+
|
|
514
|
+
### Batch Operation Examples
|
|
515
|
+
|
|
516
|
+
#### Decision Batch (Recommended: atomic: false)
|
|
517
|
+
|
|
518
|
+
```javascript
|
|
519
|
+
{
|
|
520
|
+
action: "set_batch",
|
|
521
|
+
atomic: false, // Recommended for AI agents
|
|
522
|
+
decisions: [
|
|
523
|
+
{
|
|
524
|
+
key: "feature-1",
|
|
525
|
+
value: "Implemented user authentication",
|
|
526
|
+
layer: "business",
|
|
527
|
+
tags: ["feature", "auth"],
|
|
528
|
+
status: "active"
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
key: "feature-2",
|
|
532
|
+
value: "Added rate limiting",
|
|
533
|
+
layer: "infrastructure",
|
|
534
|
+
tags: ["feature", "security"],
|
|
535
|
+
status: "active"
|
|
536
|
+
}
|
|
537
|
+
]
|
|
538
|
+
}
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
**Response Format:**
|
|
542
|
+
```json
|
|
543
|
+
{
|
|
544
|
+
"success": true,
|
|
545
|
+
"inserted": 2,
|
|
546
|
+
"failed": 0,
|
|
547
|
+
"results": [
|
|
548
|
+
{
|
|
549
|
+
"key": "feature-1",
|
|
550
|
+
"key_id": 123,
|
|
551
|
+
"version": "1.0.0",
|
|
552
|
+
"success": true
|
|
553
|
+
},
|
|
554
|
+
{
|
|
555
|
+
"key": "feature-2",
|
|
556
|
+
"key_id": 124,
|
|
557
|
+
"version": "1.0.0",
|
|
558
|
+
"success": true
|
|
559
|
+
}
|
|
560
|
+
]
|
|
561
|
+
}
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
#### Message Batch
|
|
565
|
+
|
|
566
|
+
```javascript
|
|
567
|
+
{
|
|
568
|
+
action: "send_batch",
|
|
569
|
+
atomic: false,
|
|
570
|
+
messages: [
|
|
571
|
+
{
|
|
572
|
+
from_agent: "bot1",
|
|
573
|
+
msg_type: "info",
|
|
574
|
+
message: "Task 1 completed",
|
|
575
|
+
priority: "medium"
|
|
576
|
+
},
|
|
577
|
+
{
|
|
578
|
+
from_agent: "bot1",
|
|
579
|
+
msg_type: "info",
|
|
580
|
+
message: "Task 2 completed",
|
|
581
|
+
priority: "medium"
|
|
582
|
+
}
|
|
583
|
+
]
|
|
584
|
+
}
|
|
585
|
+
```
|
|
586
|
+
|
|
587
|
+
#### File Change Batch
|
|
588
|
+
|
|
589
|
+
```javascript
|
|
590
|
+
{
|
|
591
|
+
action: "record_batch",
|
|
592
|
+
atomic: false,
|
|
593
|
+
file_changes: [
|
|
594
|
+
{
|
|
595
|
+
file_path: "src/types.ts",
|
|
596
|
+
agent_name: "refactor-bot",
|
|
597
|
+
change_type: "modified",
|
|
598
|
+
layer: "data"
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
file_path: "src/index.ts",
|
|
602
|
+
agent_name: "refactor-bot",
|
|
603
|
+
change_type: "modified",
|
|
604
|
+
layer: "infrastructure"
|
|
605
|
+
}
|
|
606
|
+
]
|
|
607
|
+
}
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
### Batch Limits
|
|
611
|
+
|
|
612
|
+
- **Maximum items per batch**: 50
|
|
613
|
+
- **Recommended batch size**: 10-20 (for readability and debugging)
|
|
614
|
+
- **Token savings**: ~52% vs individual calls
|
|
615
|
+
|
|
616
|
+
---
|
|
617
|
+
|
|
618
|
+
## Template System
|
|
619
|
+
|
|
620
|
+
### What are Templates?
|
|
621
|
+
|
|
622
|
+
Templates provide reusable defaults for common decision patterns.
|
|
623
|
+
|
|
624
|
+
### Built-in Templates
|
|
625
|
+
|
|
626
|
+
1. **breaking_change**: Breaking API/interface changes
|
|
627
|
+
2. **security_vulnerability**: Security issues
|
|
628
|
+
3. **performance_optimization**: Performance improvements
|
|
629
|
+
4. **deprecation**: Deprecation notices
|
|
630
|
+
5. **architecture_decision**: Major architectural decisions
|
|
631
|
+
|
|
632
|
+
### Using Templates
|
|
633
|
+
|
|
634
|
+
```javascript
|
|
635
|
+
{
|
|
636
|
+
action: "set_from_template",
|
|
637
|
+
template: "breaking_change",
|
|
638
|
+
key: "oscillator-type-moved",
|
|
639
|
+
value: "oscillator_type moved to MonophonicSynthConfig",
|
|
640
|
+
// Optional overrides:
|
|
641
|
+
tags: ["migration", "v0.3.3"],
|
|
642
|
+
status: "active"
|
|
643
|
+
}
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
### Template vs Direct Parameters
|
|
647
|
+
|
|
648
|
+
**When to use `set_from_template`**:
|
|
649
|
+
- You have a common decision pattern
|
|
650
|
+
- You want consistent metadata (tags, status, layer)
|
|
651
|
+
- You want to enforce required fields
|
|
652
|
+
|
|
653
|
+
**When to use `set`**:
|
|
654
|
+
- One-off decisions
|
|
655
|
+
- Unique metadata requirements
|
|
656
|
+
- Full control over all parameters
|
|
657
|
+
|
|
658
|
+
### Creating Custom Templates
|
|
659
|
+
|
|
660
|
+
```javascript
|
|
661
|
+
{
|
|
662
|
+
action: "create_template",
|
|
663
|
+
name: "bug_fix",
|
|
664
|
+
defaults: {
|
|
665
|
+
layer: "business",
|
|
666
|
+
tags: ["bug", "fix"],
|
|
667
|
+
status: "active"
|
|
668
|
+
},
|
|
669
|
+
required_fields: ["version"],
|
|
670
|
+
created_by: "my-agent"
|
|
671
|
+
}
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
### Listing Templates
|
|
675
|
+
|
|
676
|
+
```javascript
|
|
677
|
+
{
|
|
678
|
+
action: "list_templates"
|
|
679
|
+
}
|
|
680
|
+
```
|
|
681
|
+
|
|
682
|
+
---
|
|
683
|
+
|
|
684
|
+
## Multi-Step Workflow Examples
|
|
685
|
+
|
|
686
|
+
This section demonstrates comprehensive multi-agent workflows using multiple tools in coordination.
|
|
687
|
+
|
|
688
|
+
### Workflow 1: Multi-Agent Feature Implementation
|
|
689
|
+
|
|
690
|
+
**Scenario**: Orchestrator agent coordinates 3 sub-agents to implement a new authentication feature.
|
|
691
|
+
|
|
692
|
+
#### Step 1: Orchestrator Creates Plan
|
|
693
|
+
|
|
694
|
+
```javascript
|
|
695
|
+
// 1. Record the architecture decision
|
|
696
|
+
{
|
|
697
|
+
action: "set",
|
|
698
|
+
key: "auth_v2_implementation",
|
|
699
|
+
value: "Implement OAuth2 + JWT refresh token system",
|
|
700
|
+
layer: "business",
|
|
701
|
+
tags: ["auth", "feature", "v2.0.0"],
|
|
702
|
+
agent: "orchestrator-agent"
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// 2. Add architectural constraints
|
|
706
|
+
{
|
|
707
|
+
action: "add",
|
|
708
|
+
category: "architecture",
|
|
709
|
+
constraint_text: "All auth tokens must expire within 15 minutes",
|
|
710
|
+
priority: "critical",
|
|
711
|
+
layer: "business",
|
|
712
|
+
tags: ["auth", "security"]
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// 3. Create tasks for each sub-agent
|
|
716
|
+
{
|
|
717
|
+
action: "batch_create",
|
|
718
|
+
atomic: false,
|
|
719
|
+
tasks: [
|
|
720
|
+
{
|
|
721
|
+
title: "Implement OAuth2 provider integration",
|
|
722
|
+
assigned_agent: "backend-agent",
|
|
723
|
+
layer: "business",
|
|
724
|
+
priority: 4,
|
|
725
|
+
tags: ["auth", "oauth2"],
|
|
726
|
+
status: "todo"
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
title: "Create JWT token refresh endpoint",
|
|
730
|
+
assigned_agent: "api-agent",
|
|
731
|
+
layer: "presentation",
|
|
732
|
+
priority: 4,
|
|
733
|
+
tags: ["auth", "api"],
|
|
734
|
+
status: "todo"
|
|
735
|
+
},
|
|
736
|
+
{
|
|
737
|
+
title: "Update auth database schema",
|
|
738
|
+
assigned_agent: "db-agent",
|
|
739
|
+
layer: "data",
|
|
740
|
+
priority: 4,
|
|
741
|
+
tags: ["auth", "database"],
|
|
742
|
+
status: "todo"
|
|
743
|
+
}
|
|
744
|
+
]
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// 4. Broadcast start message
|
|
748
|
+
{
|
|
749
|
+
action: "send",
|
|
750
|
+
from_agent: "orchestrator-agent",
|
|
751
|
+
to_agent: null, // Broadcast
|
|
752
|
+
msg_type: "info",
|
|
753
|
+
message: "Starting OAuth2 + JWT implementation - check your assigned tasks",
|
|
754
|
+
priority: "high"
|
|
755
|
+
}
|
|
756
|
+
```
|
|
757
|
+
|
|
758
|
+
#### Step 2: Backend Agent Executes Task
|
|
759
|
+
|
|
760
|
+
```javascript
|
|
761
|
+
// 1. Mark task as in progress
|
|
762
|
+
{
|
|
763
|
+
action: "move",
|
|
764
|
+
task_id: 1,
|
|
765
|
+
new_status: "in_progress"
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// 2. Record file changes
|
|
769
|
+
{
|
|
770
|
+
action: "record_batch",
|
|
771
|
+
atomic: false,
|
|
772
|
+
file_changes: [
|
|
773
|
+
{
|
|
774
|
+
file_path: "src/auth/oauth2.ts",
|
|
775
|
+
agent_name: "backend-agent",
|
|
776
|
+
change_type: "created",
|
|
777
|
+
layer: "business",
|
|
778
|
+
description: "OAuth2 provider integration"
|
|
779
|
+
},
|
|
780
|
+
{
|
|
781
|
+
file_path: "src/auth/jwt.ts",
|
|
782
|
+
agent_name: "backend-agent",
|
|
783
|
+
change_type: "modified",
|
|
784
|
+
layer: "business",
|
|
785
|
+
description: "Added refresh token logic"
|
|
786
|
+
}
|
|
787
|
+
]
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
// 3. Report completion
|
|
791
|
+
{
|
|
792
|
+
action: "send",
|
|
793
|
+
from_agent: "backend-agent",
|
|
794
|
+
to_agent: "orchestrator-agent",
|
|
795
|
+
msg_type: "info",
|
|
796
|
+
message: "OAuth2 provider integration complete",
|
|
797
|
+
priority: "medium",
|
|
798
|
+
payload: {
|
|
799
|
+
files_changed: 2,
|
|
800
|
+
tests_passing: true
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// 4. Complete task
|
|
805
|
+
{
|
|
806
|
+
action: "move",
|
|
807
|
+
task_id: 1,
|
|
808
|
+
new_status: "done"
|
|
809
|
+
}
|
|
810
|
+
```
|
|
811
|
+
|
|
812
|
+
#### Step 3: Orchestrator Monitors Progress
|
|
813
|
+
|
|
814
|
+
```javascript
|
|
815
|
+
// 1. Check for updates (efficient polling)
|
|
816
|
+
{
|
|
817
|
+
action: "has_updates",
|
|
818
|
+
agent_name: "orchestrator-agent",
|
|
819
|
+
since_timestamp: "2025-10-17T10:00:00Z"
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
// 2. Get task status
|
|
823
|
+
{
|
|
824
|
+
action: "list",
|
|
825
|
+
tags: ["auth"],
|
|
826
|
+
assigned_agent: null // All agents
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// 3. Get unread messages
|
|
830
|
+
{
|
|
831
|
+
action: "get",
|
|
832
|
+
agent_name: "orchestrator-agent",
|
|
833
|
+
unread_only: true,
|
|
834
|
+
priority_filter: "high"
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
// 4. Check constraints compliance
|
|
838
|
+
{
|
|
839
|
+
action: "get",
|
|
840
|
+
category: "architecture",
|
|
841
|
+
layer: "business",
|
|
842
|
+
tags: ["auth"]
|
|
843
|
+
}
|
|
844
|
+
```
|
|
845
|
+
|
|
846
|
+
---
|
|
847
|
+
|
|
848
|
+
### Workflow 2: Breaking Change Migration
|
|
849
|
+
|
|
850
|
+
**Scenario**: API endpoint is being deprecated and migrated to a new version.
|
|
851
|
+
|
|
852
|
+
#### Phase 1: Announce Deprecation
|
|
853
|
+
|
|
854
|
+
```javascript
|
|
855
|
+
// 1. Record deprecation decision
|
|
856
|
+
{
|
|
857
|
+
action: "set_from_template",
|
|
858
|
+
template: "deprecation",
|
|
859
|
+
key: "api_v1_users_endpoint_deprecated",
|
|
860
|
+
value: "/v1/users endpoint deprecated, use /v2/users instead",
|
|
861
|
+
layer: "presentation",
|
|
862
|
+
tags: ["api", "deprecation", "v2.0.0"]
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// 2. Add migration constraint
|
|
866
|
+
{
|
|
867
|
+
action: "add",
|
|
868
|
+
category: "architecture",
|
|
869
|
+
constraint_text: "All new API endpoints must use /v2 prefix",
|
|
870
|
+
priority: "high",
|
|
871
|
+
layer: "presentation",
|
|
872
|
+
tags: ["api", "migration"]
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
// 3. Create migration task
|
|
876
|
+
{
|
|
877
|
+
action: "create",
|
|
878
|
+
title: "Update all client integrations to use /v2/users",
|
|
879
|
+
description: "Migrate existing integrations before v1 sunset on 2025-12-01",
|
|
880
|
+
acceptance_criteria: "All clients successfully calling /v2/users with no errors",
|
|
881
|
+
layer: "presentation",
|
|
882
|
+
priority: 3,
|
|
883
|
+
tags: ["migration", "client"],
|
|
884
|
+
status: "todo"
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// 4. Broadcast warning to all agents
|
|
888
|
+
{
|
|
889
|
+
action: "send",
|
|
890
|
+
from_agent: "api-agent",
|
|
891
|
+
to_agent: null, // Broadcast
|
|
892
|
+
msg_type: "warning",
|
|
893
|
+
message: "/v1/users DEPRECATED - Migrate to /v2/users by Dec 1",
|
|
894
|
+
priority: "critical",
|
|
895
|
+
payload: {
|
|
896
|
+
old_endpoint: "/v1/users",
|
|
897
|
+
new_endpoint: "/v2/users",
|
|
898
|
+
sunset_date: "2025-12-01"
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
```
|
|
902
|
+
|
|
903
|
+
#### Phase 2: Track Migration Progress
|
|
904
|
+
|
|
905
|
+
```javascript
|
|
906
|
+
// 1. Check file lock before editing
|
|
907
|
+
{
|
|
908
|
+
action: "check_lock",
|
|
909
|
+
file_path: "src/api/routes.ts",
|
|
910
|
+
lock_duration: 300 // 5 minutes
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// 2. Record migration changes
|
|
914
|
+
{
|
|
915
|
+
action: "record",
|
|
916
|
+
file_path: "src/api/routes.ts",
|
|
917
|
+
agent_name: "migration-agent",
|
|
918
|
+
change_type: "modified",
|
|
919
|
+
layer: "presentation",
|
|
920
|
+
description: "Added /v2/users endpoint with backwards compatibility"
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
// 3. Link task to decision and constraint
|
|
924
|
+
{
|
|
925
|
+
action: "link",
|
|
926
|
+
task_id: 1,
|
|
927
|
+
link_type: "decision",
|
|
928
|
+
target_id: "api_v1_users_endpoint_deprecated",
|
|
929
|
+
link_relation: "implements"
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
{
|
|
933
|
+
action: "link",
|
|
934
|
+
task_id: 1,
|
|
935
|
+
link_type: "constraint",
|
|
936
|
+
target_id: 1, // The migration constraint ID
|
|
937
|
+
link_relation: "satisfies"
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
// 4. Update task status
|
|
941
|
+
{
|
|
942
|
+
action: "move",
|
|
943
|
+
task_id: 1,
|
|
944
|
+
new_status: "waiting_review"
|
|
945
|
+
}
|
|
946
|
+
```
|
|
947
|
+
|
|
948
|
+
#### Phase 3: Complete Migration
|
|
949
|
+
|
|
950
|
+
```javascript
|
|
951
|
+
// 1. Record completion decision
|
|
952
|
+
{
|
|
953
|
+
action: "set",
|
|
954
|
+
key: "api_v2_migration_complete",
|
|
955
|
+
value: "All clients successfully migrated to /v2/users endpoint",
|
|
956
|
+
layer: "presentation",
|
|
957
|
+
tags: ["api", "migration", "complete"],
|
|
958
|
+
status: "active"
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
// 2. Deactivate old constraint
|
|
962
|
+
{
|
|
963
|
+
action: "deactivate",
|
|
964
|
+
constraint_id: 1
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
// 3. Archive completed task
|
|
968
|
+
{
|
|
969
|
+
action: "archive",
|
|
970
|
+
task_id: 1
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
// 4. Notify stakeholders
|
|
974
|
+
{
|
|
975
|
+
action: "send",
|
|
976
|
+
from_agent: "migration-agent",
|
|
977
|
+
to_agent: null, // Broadcast
|
|
978
|
+
msg_type: "info",
|
|
979
|
+
message: "Migration to /v2/users complete - /v1 endpoint can be removed",
|
|
980
|
+
priority: "high"
|
|
981
|
+
}
|
|
982
|
+
```
|
|
983
|
+
|
|
984
|
+
---
|
|
985
|
+
|
|
986
|
+
### Workflow 3: Session Continuity (Cross-Session Context)
|
|
987
|
+
|
|
988
|
+
**Scenario**: Agent needs to resume work after restart or handoff to another agent.
|
|
989
|
+
|
|
990
|
+
#### Agent A: Record Context Before Exit
|
|
991
|
+
|
|
992
|
+
```javascript
|
|
993
|
+
// 1. Save current work state
|
|
994
|
+
{
|
|
995
|
+
action: "set",
|
|
996
|
+
key: "refactor_session_state",
|
|
997
|
+
value: "Completed 3/5 modules - currently working on auth module",
|
|
998
|
+
layer: "business",
|
|
999
|
+
tags: ["refactor", "session-state"],
|
|
1000
|
+
scopes: ["auth-module"],
|
|
1001
|
+
agent: "refactor-agent-a"
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
// 2. Update task with notes
|
|
1005
|
+
{
|
|
1006
|
+
action: "update",
|
|
1007
|
+
task_id: 42,
|
|
1008
|
+
notes: "Paused at auth/oauth2.ts line 145 - need to review token refresh logic before proceeding"
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
// 3. Record last file changes
|
|
1012
|
+
{
|
|
1013
|
+
action: "record_batch",
|
|
1014
|
+
atomic: false,
|
|
1015
|
+
file_changes: [
|
|
1016
|
+
{
|
|
1017
|
+
file_path: "src/auth/oauth2.ts",
|
|
1018
|
+
agent_name: "refactor-agent-a",
|
|
1019
|
+
change_type: "modified",
|
|
1020
|
+
layer: "business",
|
|
1021
|
+
description: "WIP: Token refresh refactoring (incomplete)"
|
|
1022
|
+
}
|
|
1023
|
+
]
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
// 4. Send handoff message
|
|
1027
|
+
{
|
|
1028
|
+
action: "send",
|
|
1029
|
+
from_agent: "refactor-agent-a",
|
|
1030
|
+
to_agent: "refactor-agent-b",
|
|
1031
|
+
msg_type: "request",
|
|
1032
|
+
message: "Handing off refactor task - see task #42 for context",
|
|
1033
|
+
priority: "high",
|
|
1034
|
+
payload: {
|
|
1035
|
+
task_id: 42,
|
|
1036
|
+
last_file: "src/auth/oauth2.ts",
|
|
1037
|
+
completion: "60%"
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
```
|
|
1041
|
+
|
|
1042
|
+
#### Agent B: Resume Work
|
|
1043
|
+
|
|
1044
|
+
```javascript
|
|
1045
|
+
// 1. Retrieve session state
|
|
1046
|
+
{
|
|
1047
|
+
action: "get",
|
|
1048
|
+
key: "refactor_session_state"
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
// 2. Get task details and history
|
|
1052
|
+
{
|
|
1053
|
+
action: "get",
|
|
1054
|
+
task_id: 42
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
// 3. Check recent file changes
|
|
1058
|
+
{
|
|
1059
|
+
action: "get",
|
|
1060
|
+
file_path: "src/auth/oauth2.ts",
|
|
1061
|
+
since: "2025-10-17T00:00:00Z"
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
// 4. Check for any related constraints
|
|
1065
|
+
{
|
|
1066
|
+
action: "get",
|
|
1067
|
+
layer: "business",
|
|
1068
|
+
tags: ["auth"],
|
|
1069
|
+
active_only: true
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
// 5. Check messages
|
|
1073
|
+
{
|
|
1074
|
+
action: "get",
|
|
1075
|
+
agent_name: "refactor-agent-b",
|
|
1076
|
+
unread_only: true
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
// 6. Acknowledge handoff
|
|
1080
|
+
{
|
|
1081
|
+
action: "send",
|
|
1082
|
+
from_agent: "refactor-agent-b",
|
|
1083
|
+
to_agent: "refactor-agent-a",
|
|
1084
|
+
msg_type: "info",
|
|
1085
|
+
message: "Handoff received - resuming work on task #42",
|
|
1086
|
+
priority: "medium"
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
// 7. Move task to in_progress
|
|
1090
|
+
{
|
|
1091
|
+
action: "move",
|
|
1092
|
+
task_id: 42,
|
|
1093
|
+
new_status: "in_progress"
|
|
1094
|
+
}
|
|
1095
|
+
```
|
|
1096
|
+
|
|
1097
|
+
---
|
|
1098
|
+
|
|
1099
|
+
### Workflow 4: Update Polling Pattern (Efficient Subscription)
|
|
1100
|
+
|
|
1101
|
+
**Scenario**: Monitor agent watches for specific changes and reacts accordingly.
|
|
1102
|
+
|
|
1103
|
+
#### Monitor Agent: Efficient Polling Loop
|
|
1104
|
+
|
|
1105
|
+
```javascript
|
|
1106
|
+
// Initial timestamp
|
|
1107
|
+
let lastCheck = "2025-10-17T10:00:00Z";
|
|
1108
|
+
|
|
1109
|
+
// Polling function (call every 30 seconds)
|
|
1110
|
+
async function pollForUpdates() {
|
|
1111
|
+
// 1. Lightweight check for ANY updates (5-10 tokens)
|
|
1112
|
+
const updates = await {
|
|
1113
|
+
action: "has_updates",
|
|
1114
|
+
agent_name: "monitor-agent",
|
|
1115
|
+
since_timestamp: lastCheck
|
|
1116
|
+
};
|
|
1117
|
+
|
|
1118
|
+
// Response: {
|
|
1119
|
+
// has_updates: true,
|
|
1120
|
+
// counts: {decisions: 2, messages: 3, files: 1, tasks: 1}
|
|
1121
|
+
// }
|
|
1122
|
+
|
|
1123
|
+
if (!updates.has_updates) {
|
|
1124
|
+
// Nothing changed - skip heavy queries
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
// 2. Only fetch if updates detected
|
|
1129
|
+
if (updates.counts.messages > 0) {
|
|
1130
|
+
const messages = await {
|
|
1131
|
+
action: "get",
|
|
1132
|
+
agent_name: "monitor-agent",
|
|
1133
|
+
unread_only: true,
|
|
1134
|
+
priority_filter: "critical"
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
// Process critical messages
|
|
1138
|
+
for (const msg of messages.messages) {
|
|
1139
|
+
if (msg.msg_type === "warning") {
|
|
1140
|
+
// Handle warning
|
|
1141
|
+
await handleWarning(msg);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
// 3. Check for task updates
|
|
1147
|
+
if (updates.counts.tasks > 0) {
|
|
1148
|
+
const tasks = await {
|
|
1149
|
+
action: "list",
|
|
1150
|
+
status: "blocked",
|
|
1151
|
+
limit: 10
|
|
1152
|
+
};
|
|
1153
|
+
|
|
1154
|
+
// Alert on blocked tasks
|
|
1155
|
+
if (tasks.length > 0) {
|
|
1156
|
+
await {
|
|
1157
|
+
action: "send",
|
|
1158
|
+
from_agent: "monitor-agent",
|
|
1159
|
+
to_agent: "orchestrator-agent",
|
|
1160
|
+
msg_type: "warning",
|
|
1161
|
+
message: `${tasks.length} tasks are blocked - requires attention`,
|
|
1162
|
+
priority: "high"
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
// 4. Check for breaking changes
|
|
1168
|
+
if (updates.counts.decisions > 0) {
|
|
1169
|
+
const breaking = await {
|
|
1170
|
+
action: "search_tags",
|
|
1171
|
+
tags: ["breaking-change"],
|
|
1172
|
+
match_mode: "AND",
|
|
1173
|
+
status: "active"
|
|
1174
|
+
};
|
|
1175
|
+
|
|
1176
|
+
if (breaking.length > 0) {
|
|
1177
|
+
// Alert on breaking changes
|
|
1178
|
+
await {
|
|
1179
|
+
action: "send",
|
|
1180
|
+
from_agent: "monitor-agent",
|
|
1181
|
+
to_agent: null, // Broadcast
|
|
1182
|
+
msg_type: "warning",
|
|
1183
|
+
message: "New breaking changes detected - review required",
|
|
1184
|
+
priority: "critical"
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
// 5. Update last check timestamp
|
|
1190
|
+
lastCheck = new Date().toISOString();
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
// Token efficiency:
|
|
1194
|
+
// - No updates: ~10 tokens (has_updates only)
|
|
1195
|
+
// - With updates: ~50-200 tokens (selective fetching)
|
|
1196
|
+
// - vs polling all data: ~500-1000 tokens every time
|
|
1197
|
+
```
|
|
1198
|
+
|
|
1199
|
+
#### Activity Log Analysis
|
|
1200
|
+
|
|
1201
|
+
```javascript
|
|
1202
|
+
// Monitor can also analyze activity patterns
|
|
1203
|
+
{
|
|
1204
|
+
action: "activity_log",
|
|
1205
|
+
since: "1h", // Last hour
|
|
1206
|
+
agent_names: ["*"], // All agents
|
|
1207
|
+
actions: ["set", "send", "create"], // Specific actions
|
|
1208
|
+
limit: 100
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
// Response shows all activity:
|
|
1212
|
+
// [
|
|
1213
|
+
// {
|
|
1214
|
+
// timestamp: "2025-10-17T11:45:23Z",
|
|
1215
|
+
// agent_name: "backend-agent",
|
|
1216
|
+
// action: "set",
|
|
1217
|
+
// table: "decisions",
|
|
1218
|
+
// key_or_details: "auth_implementation_complete"
|
|
1219
|
+
// },
|
|
1220
|
+
// {
|
|
1221
|
+
// timestamp: "2025-10-17T11:44:15Z",
|
|
1222
|
+
// agent_name: "api-agent",
|
|
1223
|
+
// action: "send",
|
|
1224
|
+
// table: "messages",
|
|
1225
|
+
// key_or_details: "message_id:145"
|
|
1226
|
+
// }
|
|
1227
|
+
// ]
|
|
1228
|
+
|
|
1229
|
+
// Use this for:
|
|
1230
|
+
// - Debugging agent behavior
|
|
1231
|
+
// - Audit trails
|
|
1232
|
+
// - Performance monitoring
|
|
1233
|
+
// - Detecting stuck agents (no activity)
|
|
1234
|
+
```
|
|
1235
|
+
|
|
1236
|
+
#### Automatic Cleanup Trigger
|
|
1237
|
+
|
|
1238
|
+
```javascript
|
|
1239
|
+
// Monitor can also manage database health
|
|
1240
|
+
{
|
|
1241
|
+
action: "db_stats"
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
// Response:
|
|
1245
|
+
// {
|
|
1246
|
+
// total_decisions: 342,
|
|
1247
|
+
// total_messages: 1203,
|
|
1248
|
+
// total_file_changes: 589,
|
|
1249
|
+
// total_constraints: 15,
|
|
1250
|
+
// total_tasks: 47,
|
|
1251
|
+
// db_size_kb: 1024
|
|
1252
|
+
// }
|
|
1253
|
+
|
|
1254
|
+
// If database too large, trigger cleanup
|
|
1255
|
+
if (stats.total_messages > 1000) {
|
|
1256
|
+
await {
|
|
1257
|
+
action: "clear",
|
|
1258
|
+
messages_older_than_hours: 24,
|
|
1259
|
+
file_changes_older_than_days: 7
|
|
1260
|
+
};
|
|
1261
|
+
|
|
1262
|
+
// Notify about cleanup
|
|
1263
|
+
await {
|
|
1264
|
+
action: "send",
|
|
1265
|
+
from_agent: "monitor-agent",
|
|
1266
|
+
to_agent: null,
|
|
1267
|
+
msg_type: "info",
|
|
1268
|
+
message: "Database cleanup completed - removed old messages and file history",
|
|
1269
|
+
priority: "low"
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
```
|
|
1273
|
+
|
|
1274
|
+
---
|
|
1275
|
+
|
|
1276
|
+
## Best Practices
|
|
1277
|
+
|
|
1278
|
+
### 1. Always Use `action` Parameter
|
|
1279
|
+
|
|
1280
|
+
**Never forget to include `action`** - it's required in ALL tool calls.
|
|
1281
|
+
|
|
1282
|
+
### 2. Use `atomic: false` for Batch Operations
|
|
1283
|
+
|
|
1284
|
+
Unless you specifically need all-or-nothing guarantees, use `atomic: false` to avoid transaction failures from validation errors.
|
|
1285
|
+
|
|
1286
|
+
### 3. Choose the Right Search Action
|
|
1287
|
+
|
|
1288
|
+
- Simple queries → `list`
|
|
1289
|
+
- Tag-focused → `search_tags`
|
|
1290
|
+
- Complex multi-filter → `search_advanced`
|
|
1291
|
+
|
|
1292
|
+
### 4. Use Templates for Common Patterns
|
|
1293
|
+
|
|
1294
|
+
If you're repeatedly setting decisions with the same metadata, create a template.
|
|
1295
|
+
|
|
1296
|
+
### 5. Provide Meaningful Tags
|
|
1297
|
+
|
|
1298
|
+
Tags are crucial for searchability. Use descriptive, consistent tag naming:
|
|
1299
|
+
|
|
1300
|
+
```javascript
|
|
1301
|
+
// ✅ GOOD
|
|
1302
|
+
tags: ["authentication", "security", "jwt", "v1.2.0"]
|
|
1303
|
+
|
|
1304
|
+
// ❌ BAD
|
|
1305
|
+
tags: ["stuff", "important", "thing"]
|
|
1306
|
+
```
|
|
1307
|
+
|
|
1308
|
+
### 6. Always Specify `layer` for Decisions
|
|
1309
|
+
|
|
1310
|
+
Layer classification helps organize architectural concerns.
|
|
1311
|
+
|
|
1312
|
+
💡 **See [ARCHITECTURE.md](ARCHITECTURE.md#layers) for detailed layer definitions and usage examples.**
|
|
1313
|
+
|
|
1314
|
+
Quick reference:
|
|
1315
|
+
- **presentation**: UI, API endpoints, user-facing interfaces
|
|
1316
|
+
- **business**: Service logic, workflows, business rules
|
|
1317
|
+
- **data**: Database models, schemas, data access
|
|
1318
|
+
- **infrastructure**: Configuration, deployment, DevOps
|
|
1319
|
+
- **cross-cutting**: Logging, monitoring, security (affects multiple layers)
|
|
1320
|
+
|
|
1321
|
+
### 7. Use `has_updates` for Efficient Polling
|
|
1322
|
+
|
|
1323
|
+
Instead of fetching all data repeatedly, check for updates first:
|
|
1324
|
+
|
|
1325
|
+
```javascript
|
|
1326
|
+
// Check if anything changed
|
|
1327
|
+
{
|
|
1328
|
+
action: "has_updates",
|
|
1329
|
+
agent_name: "my-agent",
|
|
1330
|
+
since_timestamp: "2025-10-15T08:00:00Z"
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
// Response: {has_updates: true, counts: {decisions: 5, messages: 2, files: 3}}
|
|
1334
|
+
|
|
1335
|
+
// Only fetch if has_updates is true
|
|
1336
|
+
```
|
|
1337
|
+
|
|
1338
|
+
Token cost: ~5-10 tokens per check vs full data retrieval.
|
|
1339
|
+
|
|
1340
|
+
### 8. Handle Errors Gracefully
|
|
1341
|
+
|
|
1342
|
+
All tools return JSON responses. Check for `error` field:
|
|
1343
|
+
|
|
1344
|
+
```javascript
|
|
1345
|
+
// Response format
|
|
1346
|
+
{
|
|
1347
|
+
"error": "Invalid layer: backend"
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
// Success format
|
|
1351
|
+
{
|
|
1352
|
+
"success": true,
|
|
1353
|
+
"key": "my_key",
|
|
1354
|
+
...
|
|
1355
|
+
}
|
|
1356
|
+
```
|
|
1357
|
+
|
|
1358
|
+
### 9. Use Constraints for Requirements
|
|
1359
|
+
|
|
1360
|
+
**Constraint** vs **Decision**:
|
|
1361
|
+
|
|
1362
|
+
- **Decision**: "We chose PostgreSQL" (a choice that was made)
|
|
1363
|
+
- **Constraint**: "Response time must be <100ms" (a requirement to follow)
|
|
1364
|
+
|
|
1365
|
+
```javascript
|
|
1366
|
+
{
|
|
1367
|
+
action: "add",
|
|
1368
|
+
category: "performance",
|
|
1369
|
+
constraint_text: "API response time must be under 100ms",
|
|
1370
|
+
priority: "critical",
|
|
1371
|
+
layer: "business",
|
|
1372
|
+
tags: ["api", "performance"]
|
|
1373
|
+
}
|
|
1374
|
+
```
|
|
1375
|
+
|
|
1376
|
+
### 10. Clean Up Old Data Regularly
|
|
1377
|
+
|
|
1378
|
+
Use the `clear` action to prevent database bloat:
|
|
1379
|
+
|
|
1380
|
+
```javascript
|
|
1381
|
+
// Manual cleanup
|
|
1382
|
+
{
|
|
1383
|
+
action: "clear",
|
|
1384
|
+
messages_older_than_hours: 48,
|
|
1385
|
+
file_changes_older_than_days: 14
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
// Or rely on auto-cleanup (configured via config tool)
|
|
1389
|
+
{
|
|
1390
|
+
action: "update",
|
|
1391
|
+
ignoreWeekend: true,
|
|
1392
|
+
messageRetentionHours: 24,
|
|
1393
|
+
fileHistoryRetentionDays: 7
|
|
1394
|
+
}
|
|
1395
|
+
```
|
|
1396
|
+
|
|
1397
|
+
---
|
|
1398
|
+
|
|
1399
|
+
## Troubleshooting Checklist
|
|
1400
|
+
|
|
1401
|
+
Before asking for help, check:
|
|
1402
|
+
|
|
1403
|
+
1. ✅ Did you include the `action` parameter?
|
|
1404
|
+
2. ✅ Are all required parameters provided?
|
|
1405
|
+
3. ✅ Are enum values spelled correctly? (layer, status, msg_type, etc.)
|
|
1406
|
+
4. ✅ For templates: Are you passing parameters directly (not in `defaults`)?
|
|
1407
|
+
5. ✅ For batch operations: Is array size ≤50?
|
|
1408
|
+
6. ✅ For timestamps: Are you using ISO 8601 format?
|
|
1409
|
+
|
|
1410
|
+
---
|
|
1411
|
+
|
|
1412
|
+
## Need More Help?
|
|
1413
|
+
|
|
1414
|
+
### Built-In Documentation (Zero Token Cost)
|
|
1415
|
+
|
|
1416
|
+
All tools provide comprehensive built-in documentation with zero upfront token cost:
|
|
1417
|
+
|
|
1418
|
+
**Help Action** - Detailed reference documentation:
|
|
1419
|
+
```javascript
|
|
1420
|
+
// Get detailed help for any tool
|
|
1421
|
+
{
|
|
1422
|
+
action: "help"
|
|
1423
|
+
}
|
|
1424
|
+
```
|
|
1425
|
+
|
|
1426
|
+
Returns:
|
|
1427
|
+
- All actions and their parameters
|
|
1428
|
+
- Quick examples for each action
|
|
1429
|
+
- Valid values for enum parameters
|
|
1430
|
+
- Behavior descriptions
|
|
1431
|
+
- Links to external documentation
|
|
1432
|
+
|
|
1433
|
+
**Example Action** - Comprehensive usage scenarios (v3.0.1):
|
|
1434
|
+
```javascript
|
|
1435
|
+
// Get comprehensive examples for any tool
|
|
1436
|
+
{
|
|
1437
|
+
action: "example"
|
|
1438
|
+
}
|
|
1439
|
+
```
|
|
1440
|
+
|
|
1441
|
+
Returns:
|
|
1442
|
+
- Real-world usage scenarios by category
|
|
1443
|
+
- Multi-step workflows
|
|
1444
|
+
- Best practices specific to the tool
|
|
1445
|
+
- Common patterns and anti-patterns
|
|
1446
|
+
- Works offline without WebFetch
|
|
1447
|
+
|
|
1448
|
+
### When to Use Each
|
|
1449
|
+
|
|
1450
|
+
| Use | Action | What You Get |
|
|
1451
|
+
|-----|--------|--------------|
|
|
1452
|
+
| Quick parameter reference | `help` | Action list, parameters, quick examples |
|
|
1453
|
+
| Comprehensive examples | `example` | Detailed scenarios, workflows, best practices |
|
|
1454
|
+
| Specific implementation patterns | `example` | Category-based examples (e.g., performance constraints, batch operations) |
|
|
1455
|
+
|
|
1456
|
+
---
|
|
1457
|
+
|
|
1458
|
+
## Summary: Most Common Mistakes
|
|
1459
|
+
|
|
1460
|
+
1. **Missing `action` parameter** ← #1 error!
|
|
1461
|
+
2. Using `defaults` instead of direct parameters with templates
|
|
1462
|
+
3. Invalid layer/status/priority values (use exact strings)
|
|
1463
|
+
4. Forgetting to specify `layer` when setting decisions
|
|
1464
|
+
5. Using `atomic: true` by default in batch operations (use `false`)
|
|
1465
|
+
6. Using wrong search action (`list` vs `search_tags` vs `search_advanced`)
|
|
1466
|
+
7. Empty arrays in batch operations
|
|
1467
|
+
8. Typos in parameter names (e.g., `messsage` instead of `message`)
|
|
1468
|
+
|
|
1469
|
+
---
|
|
1470
|
+
|
|
1471
|
+
**Remember**: When in doubt, call `{action: "help"}` for parameters or `{action: "example"}` for comprehensive usage scenarios!
|