agentic-flow 1.8.11 → 1.8.13

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 (31) hide show
  1. package/dist/cli/federation-cli.d.ts +53 -0
  2. package/dist/cli/federation-cli.js +431 -0
  3. package/dist/cli-proxy.js +28 -1
  4. package/dist/federation/EphemeralAgent.js +258 -0
  5. package/dist/federation/FederationHub.js +283 -0
  6. package/dist/federation/FederationHubClient.js +212 -0
  7. package/dist/federation/FederationHubServer.js +436 -0
  8. package/dist/federation/SecurityManager.js +191 -0
  9. package/dist/federation/debug/agent-debug-stream.js +474 -0
  10. package/dist/federation/debug/debug-stream.js +419 -0
  11. package/dist/federation/index.js +12 -0
  12. package/dist/federation/integrations/realtime-federation.js +404 -0
  13. package/dist/federation/integrations/supabase-adapter-debug.js +400 -0
  14. package/dist/federation/integrations/supabase-adapter.js +258 -0
  15. package/dist/utils/cli.js +5 -0
  16. package/docs/architecture/FEDERATION-DATA-LIFECYCLE.md +520 -0
  17. package/docs/federation/AGENT-DEBUG-STREAMING.md +403 -0
  18. package/docs/federation/DEBUG-STREAMING-COMPLETE.md +432 -0
  19. package/docs/federation/DEBUG-STREAMING.md +537 -0
  20. package/docs/federation/DEPLOYMENT-VALIDATION-SUCCESS.md +394 -0
  21. package/docs/federation/DOCKER-FEDERATION-DEEP-REVIEW.md +478 -0
  22. package/docs/issues/ISSUE-SUPABASE-INTEGRATION.md +536 -0
  23. package/docs/supabase/IMPLEMENTATION-SUMMARY.md +498 -0
  24. package/docs/supabase/INDEX.md +358 -0
  25. package/docs/supabase/QUICKSTART.md +365 -0
  26. package/docs/supabase/README.md +318 -0
  27. package/docs/supabase/SUPABASE-REALTIME-FEDERATION.md +575 -0
  28. package/docs/supabase/TEST-REPORT.md +446 -0
  29. package/docs/supabase/migrations/001_create_federation_tables.sql +339 -0
  30. package/docs/validation/reports/REGRESSION-TEST-V1.8.11.md +456 -0
  31. package/package.json +4 -1
@@ -0,0 +1,537 @@
1
+ # Debug Streaming Guide
2
+
3
+ **Version**: 1.0.0
4
+ **Date**: 2025-11-01
5
+ **Status**: ✅ Production Ready
6
+
7
+ ---
8
+
9
+ ## 🔍 Overview
10
+
11
+ The Debug Streaming system provides **detailed, real-time visibility** into all agent operations with multiple verbosity levels, customizable output formats, and performance metrics.
12
+
13
+ **Perfect for**: Development, debugging, performance tuning, production monitoring
14
+
15
+ ---
16
+
17
+ ## 🚀 Quick Start
18
+
19
+ ### Basic Usage
20
+
21
+ ```typescript
22
+ import { createDebugStream, DebugLevel } from 'agentic-flow/federation/debug/debug-stream';
23
+
24
+ // Create debug stream
25
+ const debug = createDebugStream({
26
+ level: DebugLevel.DETAILED,
27
+ format: 'human',
28
+ colorize: true,
29
+ });
30
+
31
+ // Log operations
32
+ debug.logDatabase('query', { table: 'sessions' }, 15);
33
+ debug.logMemory('store', 'agent-001', 'team-1', { id: 'mem-1' }, 12);
34
+
35
+ // Print metrics
36
+ debug.printMetrics();
37
+ ```
38
+
39
+ ### Environment Variables
40
+
41
+ ```bash
42
+ # Set debug level
43
+ export DEBUG_LEVEL=VERBOSE
44
+
45
+ # Set output format
46
+ export DEBUG_FORMAT=human # human | json | compact
47
+
48
+ # Set output destination
49
+ export DEBUG_OUTPUT=console # console | file | both
50
+
51
+ # Optional: file path
52
+ export DEBUG_OUTPUT_FILE=debug.log
53
+ ```
54
+
55
+ ---
56
+
57
+ ## 📊 Debug Levels
58
+
59
+ ### SILENT (0)
60
+ No debug output. Production default.
61
+
62
+ ```bash
63
+ DEBUG_LEVEL=SILENT
64
+ ```
65
+
66
+ ### BASIC (1)
67
+ Major events only: initialization, shutdown, errors.
68
+
69
+ ```bash
70
+ DEBUG_LEVEL=BASIC
71
+ ```
72
+
73
+ **Output**:
74
+ ```
75
+ [2025-11-01T14:00:00.000Z] BASIC CONNECTION server_start
76
+ [2025-11-01T14:00:01.000Z] BASIC CONNECTION client_connected
77
+ ```
78
+
79
+ **Best for**: Production monitoring, error tracking
80
+
81
+ ### DETAILED (2)
82
+ Includes all database operations with timing.
83
+
84
+ ```bash
85
+ DEBUG_LEVEL=DETAILED
86
+ ```
87
+
88
+ **Output**:
89
+ ```
90
+ [2025-11-01T14:00:00.100Z] DETAIL DATABASE query_memories 8.00ms
91
+ Data: {
92
+ "table": "agent_memories",
93
+ "rows": 5
94
+ }
95
+ [2025-11-01T14:00:00.120Z] DETAIL MEMORY store agent=agent-001 tenant=team-1 12.00ms
96
+ Data: {
97
+ "id": "mem-456",
98
+ "content": "Task complete"
99
+ }
100
+ ```
101
+
102
+ **Best for**: Development, performance tuning, SQL debugging
103
+
104
+ ### VERBOSE (3)
105
+ All events including real-time operations and tasks.
106
+
107
+ ```bash
108
+ DEBUG_LEVEL=VERBOSE
109
+ ```
110
+
111
+ **Output**:
112
+ ```
113
+ [2025-11-01T14:00:00.000Z] VERBOS REALTIME agent=agent-001 agent_join
114
+ Data: {
115
+ "tenant": "team-alpha",
116
+ "status": "online"
117
+ }
118
+ [2025-11-01T14:00:00.050Z] VERBOS TASK agent=agent-001 task_assigned
119
+ Data: {
120
+ "taskId": "task-123",
121
+ "description": "Process user request"
122
+ }
123
+ ```
124
+
125
+ **Best for**: Multi-agent debugging, coordination troubleshooting
126
+
127
+ ### TRACE (4)
128
+ Everything including internal state changes.
129
+
130
+ ```bash
131
+ DEBUG_LEVEL=TRACE
132
+ ```
133
+
134
+ **Output**:
135
+ ```
136
+ [2025-11-01T14:00:00.000Z] TRACE TRACE state_change
137
+ Data: {
138
+ "component": "ConnectionPool",
139
+ "old_state": "idle",
140
+ "new_state": "connecting"
141
+ }
142
+ ```
143
+
144
+ **Best for**: Deep debugging, troubleshooting edge cases
145
+
146
+ ---
147
+
148
+ ## 🎨 Output Formats
149
+
150
+ ### Human-Readable (Default)
151
+
152
+ ```bash
153
+ DEBUG_FORMAT=human
154
+ ```
155
+
156
+ **Features**:
157
+ - Color-coded output
158
+ - Formatted JSON
159
+ - Timestamps
160
+ - Duration highlighting
161
+ - Stack traces (optional)
162
+
163
+ **Example**:
164
+ ```
165
+ [2025-11-01T14:00:00.100Z] DETAIL DATABASE query_memories 8.00ms
166
+ Data: {
167
+ "table": "agent_memories",
168
+ "rows": 5
169
+ }
170
+ ```
171
+
172
+ ### JSON
173
+
174
+ ```bash
175
+ DEBUG_FORMAT=json
176
+ ```
177
+
178
+ **Features**:
179
+ - Machine-parseable
180
+ - Structured data
181
+ - Easy to process
182
+ - Log aggregation friendly
183
+
184
+ **Example**:
185
+ ```json
186
+ {"timestamp":"2025-11-01T14:00:00.100Z","level":2,"category":"database","operation":"query_memories","duration":8,"data":{"table":"agent_memories","rows":5}}
187
+ ```
188
+
189
+ ### Compact
190
+
191
+ ```bash
192
+ DEBUG_FORMAT=compact
193
+ ```
194
+
195
+ **Features**:
196
+ - Single line per event
197
+ - Minimal overhead
198
+ - Production friendly
199
+ - Easy to grep
200
+
201
+ **Example**:
202
+ ```
203
+ 2025-11-01T14:00:00.100Z | DETAIL | database | query_memories | 8ms
204
+ ```
205
+
206
+ ---
207
+
208
+ ## 🎯 Usage Examples
209
+
210
+ ### Example 1: Development Debugging
211
+
212
+ ```typescript
213
+ import { createDebugStream, DebugLevel } from './debug-stream';
214
+
215
+ const debug = createDebugStream({
216
+ level: DebugLevel.VERBOSE,
217
+ format: 'human',
218
+ colorize: true,
219
+ });
220
+
221
+ // Your code here
222
+ await performDatabaseOperations();
223
+
224
+ // Print metrics at end
225
+ debug.printMetrics();
226
+ ```
227
+
228
+ ### Example 2: Production Monitoring
229
+
230
+ ```typescript
231
+ const debug = createDebugStream({
232
+ level: DebugLevel.BASIC,
233
+ format: 'json',
234
+ output: 'file',
235
+ outputFile: '/var/log/agent-debug.log',
236
+ colorize: false,
237
+ });
238
+
239
+ // Monitor critical operations only
240
+ debug.logConnection('service_start', { version: '1.0.0' });
241
+ ```
242
+
243
+ ### Example 3: Performance Profiling
244
+
245
+ ```typescript
246
+ const debug = createDebugStream({
247
+ level: DebugLevel.DETAILED,
248
+ format: 'human',
249
+ includeTimestamps: true,
250
+ });
251
+
252
+ // Log operations with timing
253
+ const start = Date.now();
254
+ await database.query('SELECT * FROM ...');
255
+ const duration = Date.now() - start;
256
+
257
+ debug.logDatabase('query', { sql: '...' }, duration);
258
+
259
+ // Analyze performance
260
+ debug.printMetrics();
261
+ ```
262
+
263
+ ### Example 4: Event Filtering
264
+
265
+ ```typescript
266
+ const debug = createDebugStream({
267
+ level: DebugLevel.VERBOSE,
268
+ filterCategories: ['database', 'memory'], // Only these
269
+ filterAgents: ['agent-001'], // Only this agent
270
+ });
271
+
272
+ // Only matching events will be logged
273
+ ```
274
+
275
+ ### Example 5: Real-Time Monitoring
276
+
277
+ ```typescript
278
+ const debug = createDebugStream({
279
+ level: DebugLevel.DETAILED,
280
+ });
281
+
282
+ // Subscribe to events
283
+ debug.on('event', (event) => {
284
+ if (event.duration && event.duration > 100) {
285
+ console.log(`⚠️ SLOW: ${event.operation} took ${event.duration}ms`);
286
+ }
287
+ });
288
+ ```
289
+
290
+ ---
291
+
292
+ ## 📚 API Reference
293
+
294
+ ### DebugStream Class
295
+
296
+ #### Methods
297
+
298
+ **`log(event)`**
299
+ Log a debug event manually.
300
+
301
+ **`logConnection(operation, data?, error?)`**
302
+ Log connection events.
303
+
304
+ **`logDatabase(operation, data?, duration?, error?)`**
305
+ Log database operations with timing.
306
+
307
+ **`logRealtime(operation, agentId?, data?, duration?)`**
308
+ Log realtime events.
309
+
310
+ **`logMemory(operation, agentId?, tenantId?, data?, duration?)`**
311
+ Log memory operations.
312
+
313
+ **`logTask(operation, agentId?, tenantId?, data?, duration?)`**
314
+ Log task operations.
315
+
316
+ **`logTrace(operation, data?)`**
317
+ Log internal state changes.
318
+
319
+ **`getMetrics()`**
320
+ Get performance metrics summary.
321
+
322
+ **`printMetrics()`**
323
+ Print formatted metrics to console.
324
+
325
+ **`getEvents(filter?)`**
326
+ Get buffered events with optional filter.
327
+
328
+ **`clearEvents()`**
329
+ Clear event buffer.
330
+
331
+ **`clearMetrics()`**
332
+ Clear performance metrics.
333
+
334
+ **`close()`**
335
+ Close file stream (if using file output).
336
+
337
+ #### Events
338
+
339
+ **`'event'`**
340
+ Emitted for every debug event.
341
+
342
+ ```typescript
343
+ debug.on('event', (event) => {
344
+ console.log('Event:', event);
345
+ });
346
+ ```
347
+
348
+ ---
349
+
350
+ ## 🔧 Integration
351
+
352
+ ### With Supabase Adapter
353
+
354
+ ```typescript
355
+ import { SupabaseFederationAdapterDebug } from './supabase-adapter-debug';
356
+
357
+ const adapter = new SupabaseFederationAdapterDebug({
358
+ url: process.env.SUPABASE_URL!,
359
+ anonKey: process.env.SUPABASE_ANON_KEY!,
360
+ debug: {
361
+ enabled: true,
362
+ level: DebugLevel.DETAILED,
363
+ format: 'human',
364
+ },
365
+ });
366
+
367
+ await adapter.initialize();
368
+ await adapter.storeMemory({...});
369
+
370
+ // Print performance metrics
371
+ adapter.printMetrics();
372
+ ```
373
+
374
+ ### With Real-Time Federation
375
+
376
+ ```typescript
377
+ import { createRealtimeHub } from './realtime-federation';
378
+ import { createDebugStream, DebugLevel } from './debug-stream';
379
+
380
+ const debug = createDebugStream({
381
+ level: DebugLevel.VERBOSE,
382
+ });
383
+
384
+ const hub = createRealtimeHub('agent-001', 'team-1');
385
+
386
+ // Integrate debug logging
387
+ hub.on('message:received', (msg) => {
388
+ debug.logRealtime('message_received', 'agent-001', msg);
389
+ });
390
+ ```
391
+
392
+ ---
393
+
394
+ ## 📊 Performance Metrics
395
+
396
+ ### Automatic Tracking
397
+
398
+ All operations with duration are automatically tracked:
399
+
400
+ ```typescript
401
+ debug.logDatabase('query', {}, 15);
402
+ debug.logDatabase('query', {}, 8);
403
+ debug.logDatabase('insert', {}, 12);
404
+
405
+ // Metrics are aggregated automatically
406
+ debug.printMetrics();
407
+ ```
408
+
409
+ **Output**:
410
+ ```
411
+ Performance Metrics Summary
412
+ ============================================================
413
+ Operation Count Avg Duration
414
+ ------------------------------------------------------------
415
+ database:query 2 11.50ms
416
+ database:insert 1 12.00ms
417
+ ```
418
+
419
+ ### Custom Metrics
420
+
421
+ ```typescript
422
+ const startTime = Date.now();
423
+ await yourOperation();
424
+ const duration = Date.now() - startTime;
425
+
426
+ debug.logDatabase('custom_operation', { details }, duration);
427
+ ```
428
+
429
+ ---
430
+
431
+ ## 🎓 Best Practices
432
+
433
+ ### Development
434
+
435
+ ```bash
436
+ # Maximum visibility
437
+ DEBUG_LEVEL=TRACE
438
+ DEBUG_FORMAT=human
439
+ DEBUG_OUTPUT=console
440
+ ```
441
+
442
+ ### Staging
443
+
444
+ ```bash
445
+ # Balanced monitoring
446
+ DEBUG_LEVEL=DETAILED
447
+ DEBUG_FORMAT=json
448
+ DEBUG_OUTPUT=both
449
+ DEBUG_OUTPUT_FILE=/var/log/staging-debug.log
450
+ ```
451
+
452
+ ### Production
453
+
454
+ ```bash
455
+ # Minimal overhead
456
+ DEBUG_LEVEL=BASIC
457
+ DEBUG_FORMAT=compact
458
+ DEBUG_OUTPUT=file
459
+ DEBUG_OUTPUT_FILE=/var/log/production.log
460
+ ```
461
+
462
+ ---
463
+
464
+ ## 🐛 Troubleshooting
465
+
466
+ ### Issue: Too Much Output
467
+
468
+ **Solution**: Lower the debug level
469
+
470
+ ```bash
471
+ # From VERBOSE to DETAILED
472
+ DEBUG_LEVEL=DETAILED
473
+ ```
474
+
475
+ ### Issue: Can't Find Slow Queries
476
+
477
+ **Solution**: Use event filtering with custom handler
478
+
479
+ ```typescript
480
+ debug.on('event', (event) => {
481
+ if (event.category === 'database' && event.duration! > 50) {
482
+ console.log('SLOW:', event);
483
+ }
484
+ });
485
+ ```
486
+
487
+ ### Issue: File Output Not Working
488
+
489
+ **Solution**: Check file permissions
490
+
491
+ ```bash
492
+ # Ensure directory exists
493
+ mkdir -p /var/log/agent
494
+
495
+ # Set permissions
496
+ chmod 755 /var/log/agent
497
+
498
+ # Test with tmp
499
+ DEBUG_OUTPUT_FILE=/tmp/debug.log
500
+ ```
501
+
502
+ ---
503
+
504
+ ## 🔗 Related Documentation
505
+
506
+ - [Supabase Integration](../supabase/SUPABASE-REALTIME-FEDERATION.md)
507
+ - [Federation Architecture](./FEDERATED-AGENTDB-EPHEMERAL-AGENTS.md)
508
+ - [Performance Tuning](../performance/OPTIMIZATION-GUIDE.md)
509
+
510
+ ---
511
+
512
+ ## ✅ Summary
513
+
514
+ **Debug Streaming provides**:
515
+ - ✅ 5 verbosity levels (SILENT to TRACE)
516
+ - ✅ 3 output formats (human, json, compact)
517
+ - ✅ Multiple destinations (console, file, both)
518
+ - ✅ Automatic performance tracking
519
+ - ✅ Event filtering
520
+ - ✅ Real-time streaming
521
+ - ✅ Color-coded output
522
+ - ✅ Stack traces (optional)
523
+
524
+ **Perfect for**:
525
+ - Development debugging
526
+ - Performance profiling
527
+ - Production monitoring
528
+ - Troubleshooting
529
+ - Learning and education
530
+
531
+ ---
532
+
533
+ **Version**: 1.0.0
534
+ **Last Updated**: 2025-11-01
535
+ **Status**: ✅ Production Ready
536
+
537
+ 🔍 **Start debugging with visibility!**