claude-flow-novice 1.5.17 → 1.5.19

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 (24) hide show
  1. package/.claude-flow-novice/dist/config/hooks/post-edit-pipeline.js +1837 -0
  2. package/.claude-flow-novice/dist/src/hooks/communication-integrated-post-edit.js +673 -0
  3. package/.claude-flow-novice/dist/src/hooks/enhanced/experience-adaptation-hooks.js +347 -0
  4. package/.claude-flow-novice/dist/src/hooks/enhanced/personalization-hooks.js +118 -0
  5. package/.claude-flow-novice/dist/src/hooks/enhanced-post-edit-pipeline.js +2044 -0
  6. package/.claude-flow-novice/dist/src/hooks/filter-integration.js +542 -0
  7. package/.claude-flow-novice/dist/src/hooks/guidance-hooks.js +629 -0
  8. package/.claude-flow-novice/dist/src/hooks/index.ts +239 -0
  9. package/.claude-flow-novice/dist/src/hooks/managers/enhanced-hook-manager.js +200 -0
  10. package/.claude-flow-novice/dist/src/hooks/resilient-hook-system.js +812 -0
  11. package/CHANGELOG.md +22 -0
  12. package/config/hooks/post-edit-pipeline.js +30 -0
  13. package/package.json +2 -1
  14. package/src/cli/simple-commands/init/templates/CLAUDE.md +38 -6
  15. package/src/hooks/communication-integrated-post-edit.js +673 -0
  16. package/src/hooks/enhanced/experience-adaptation-hooks.js +347 -0
  17. package/src/hooks/enhanced/personalization-hooks.js +118 -0
  18. package/src/hooks/enhanced-hooks-cli.js +168 -0
  19. package/src/hooks/enhanced-post-edit-pipeline.js +2044 -0
  20. package/src/hooks/filter-integration.js +542 -0
  21. package/src/hooks/guidance-hooks.js +629 -0
  22. package/src/hooks/index.ts +239 -0
  23. package/src/hooks/managers/enhanced-hook-manager.js +200 -0
  24. package/src/hooks/resilient-hook-system.js +812 -0
@@ -0,0 +1,673 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Communication-Integrated Post-Edit Pipeline
5
+ *
6
+ * Integrates the ultra-fast communication system with the enhanced post-edit pipeline
7
+ * to enable real-time agent coordination and memory sharing during editing operations.
8
+ *
9
+ * Features:
10
+ * - Ultra-fast inter-agent communication (<1ms latency)
11
+ * - Shared memory coordination for multi-agent workflows
12
+ * - Real-time progress broadcasting to agent swarms
13
+ * - Zero-copy data structures for performance
14
+ * - Event-driven architecture for scalability
15
+ */
16
+
17
+ import { enhancedPostEditHook } from './enhanced-post-edit-pipeline.js';
18
+ import { EventEmitter } from 'events';
19
+ import fs from 'fs/promises';
20
+ import path from 'path';
21
+
22
+ // Import ultra-fast communication components (runtime check)
23
+ let UltraFastCommunicationBus = null;
24
+ let ZeroCopyRingBuffer = null;
25
+ let OptimizedMessageSerializer = null;
26
+
27
+ try {
28
+ const commModule = await import('../communication/ultra-fast-communication-bus.js');
29
+ UltraFastCommunicationBus = commModule.UltraFastCommunicationBus || commModule.default;
30
+ } catch {
31
+ console.warn('⚠️ Ultra-fast communication bus not available - using fallback');
32
+ }
33
+
34
+ try {
35
+ const zcModule = await import('../communication/zero-copy-structures.js');
36
+ ZeroCopyRingBuffer = zcModule.ZeroCopyRingBuffer;
37
+ } catch {
38
+ console.warn('⚠️ Zero-copy structures not available - using fallback');
39
+ }
40
+
41
+ try {
42
+ const serModule = await import('../communication/optimized-serialization.js');
43
+ OptimizedMessageSerializer = serModule.OptimizedMessageSerializer;
44
+ } catch {
45
+ console.warn('⚠️ Optimized serialization not available - using fallback');
46
+ }
47
+
48
+ /**
49
+ * Communication-Integrated Memory Store
50
+ * Extends the enhanced memory store with ultra-fast communication capabilities
51
+ */
52
+ class CommunicationMemoryStore extends EventEmitter {
53
+ constructor(options = {}) {
54
+ super();
55
+
56
+ this.memoryDir = path.join(process.cwd(), '.swarm');
57
+ this.memoryFile = path.join(this.memoryDir, 'communication-memory.json');
58
+ this.data = new Map();
59
+ this.subscribers = new Map();
60
+
61
+ // Communication system configuration
62
+ this.enableCommunication = options.enableCommunication !== false;
63
+ this.enableZeroCopy = options.enableZeroCopy !== false && ZeroCopyRingBuffer !== null;
64
+ this.enableOptimizedSerialization = options.enableOptimizedSerialization !== false && OptimizedMessageSerializer !== null;
65
+
66
+ // Initialize communication components if available
67
+ if (this.enableCommunication && UltraFastCommunicationBus) {
68
+ this.communicationBus = new UltraFastCommunicationBus({
69
+ enableZeroCopy: this.enableZeroCopy,
70
+ enableOptimizedSerialization: this.enableOptimizedSerialization,
71
+ maxBufferSize: 1024 * 1024 * 10, // 10MB
72
+ workerThreads: 2
73
+ });
74
+
75
+ this.communicationEnabled = true;
76
+ console.log('✅ Ultra-fast communication enabled');
77
+ } else {
78
+ this.communicationBus = new EventEmitter(); // Fallback
79
+ this.communicationEnabled = false;
80
+ console.log('ℹ️ Using fallback communication (EventEmitter)');
81
+ }
82
+
83
+ // Performance metrics
84
+ this.metrics = {
85
+ messagesPublished: 0,
86
+ messagesReceived: 0,
87
+ averageLatency: 0,
88
+ peakLatency: 0,
89
+ totalBytes: 0
90
+ };
91
+ }
92
+
93
+ /**
94
+ * Initialize the communication-integrated memory store
95
+ */
96
+ async initialize() {
97
+ try {
98
+ await fs.mkdir(this.memoryDir, { recursive: true });
99
+
100
+ try {
101
+ const content = await fs.readFile(this.memoryFile, 'utf8');
102
+ const parsed = JSON.parse(content);
103
+ this.data = new Map(Object.entries(parsed));
104
+ console.log(`✅ Communication memory store loaded (${this.data.size} entries)`);
105
+ } catch {
106
+ console.log('ℹ️ Initializing new communication memory store...');
107
+ }
108
+
109
+ // Initialize communication bus if enabled
110
+ if (this.communicationEnabled && this.communicationBus.initialize) {
111
+ await this.communicationBus.initialize();
112
+
113
+ // Subscribe to memory update broadcasts
114
+ this.communicationBus.on('memory:update', this.handleMemoryUpdate.bind(this));
115
+ this.communicationBus.on('memory:query', this.handleMemoryQuery.bind(this));
116
+ console.log('✅ Communication bus initialized');
117
+ }
118
+
119
+ } catch (error) {
120
+ console.warn(`⚠️ Communication memory store init warning: ${error.message}`);
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Store data with real-time communication to agents
126
+ */
127
+ async store(key, value, options = {}) {
128
+ const startTime = performance.now();
129
+
130
+ const entry = {
131
+ value,
132
+ options,
133
+ timestamp: new Date().toISOString(),
134
+ namespace: options.namespace || 'default',
135
+ metadata: options.metadata || {},
136
+ version: '3.0.0-communication',
137
+ communicationEnabled: this.communicationEnabled
138
+ };
139
+
140
+ this.data.set(key, entry);
141
+
142
+ // Persist to disk
143
+ await this.persist();
144
+
145
+ // Broadcast to all subscribed agents via ultra-fast communication
146
+ if (options.broadcast !== false) {
147
+ await this.broadcast('memory:update', {
148
+ type: 'store',
149
+ key,
150
+ value,
151
+ namespace: entry.namespace,
152
+ metadata: entry.metadata,
153
+ timestamp: entry.timestamp
154
+ });
155
+ }
156
+
157
+ // Emit local event
158
+ this.emit('store', { key, value, entry });
159
+
160
+ // Update metrics
161
+ const latency = performance.now() - startTime;
162
+ this.updateMetrics('store', latency, JSON.stringify(entry).length);
163
+
164
+ return entry;
165
+ }
166
+
167
+ /**
168
+ * Retrieve data with optional remote coordination
169
+ */
170
+ async retrieve(key, options = {}) {
171
+ const entry = this.data.get(key);
172
+
173
+ // If not found locally and remote query enabled, ask other agents
174
+ if (!entry && options.queryRemote && this.communicationEnabled) {
175
+ const remoteResult = await this.queryRemote(key, options);
176
+ if (remoteResult) {
177
+ // Cache remotely retrieved data
178
+ await this.store(key, remoteResult.value, {
179
+ ...remoteResult.options,
180
+ broadcast: false // Don't re-broadcast
181
+ });
182
+ return remoteResult.value;
183
+ }
184
+ }
185
+
186
+ if (!entry) return null;
187
+
188
+ if (options.namespace && entry.namespace !== options.namespace) {
189
+ return null;
190
+ }
191
+
192
+ this.emit('retrieve', { key, entry });
193
+
194
+ return entry.value;
195
+ }
196
+
197
+ /**
198
+ * Subscribe to memory updates for specific keys or patterns
199
+ */
200
+ subscribe(pattern, callback, options = {}) {
201
+ const subscriptionId = `sub-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
202
+
203
+ const subscription = {
204
+ id: subscriptionId,
205
+ pattern,
206
+ callback,
207
+ options,
208
+ created: new Date().toISOString()
209
+ };
210
+
211
+ this.subscribers.set(subscriptionId, subscription);
212
+
213
+ // Register with communication bus for remote updates
214
+ if (this.communicationEnabled) {
215
+ this.communicationBus.on(`memory:update:${pattern}`, callback);
216
+ }
217
+
218
+ console.log(`📡 Subscribed to memory pattern: ${pattern}`);
219
+
220
+ return subscriptionId;
221
+ }
222
+
223
+ /**
224
+ * Unsubscribe from memory updates
225
+ */
226
+ unsubscribe(subscriptionId) {
227
+ const subscription = this.subscribers.get(subscriptionId);
228
+ if (!subscription) return false;
229
+
230
+ if (this.communicationEnabled) {
231
+ this.communicationBus.off(`memory:update:${subscription.pattern}`, subscription.callback);
232
+ }
233
+
234
+ this.subscribers.delete(subscriptionId);
235
+ console.log(`📡 Unsubscribed: ${subscriptionId}`);
236
+
237
+ return true;
238
+ }
239
+
240
+ /**
241
+ * Broadcast message to all agents
242
+ */
243
+ async broadcast(topic, message, options = {}) {
244
+ const startTime = performance.now();
245
+
246
+ try {
247
+ if (this.communicationEnabled && this.communicationBus.publish) {
248
+ // Use ultra-fast communication bus
249
+ await this.communicationBus.publish(topic, message, options);
250
+ } else {
251
+ // Fallback: emit locally
252
+ this.communicationBus.emit(topic, message);
253
+ }
254
+
255
+ this.metrics.messagesPublished++;
256
+
257
+ const latency = performance.now() - startTime;
258
+ this.updateMetrics('broadcast', latency, JSON.stringify(message).length);
259
+
260
+ } catch (error) {
261
+ console.error(`❌ Broadcast failed: ${error.message}`);
262
+ }
263
+ }
264
+
265
+ /**
266
+ * Query remote agents for data
267
+ */
268
+ async queryRemote(key, options = {}) {
269
+ if (!this.communicationEnabled) return null;
270
+
271
+ return new Promise((resolve) => {
272
+ const timeout = setTimeout(() => {
273
+ this.communicationBus.off('memory:response', responseHandler);
274
+ resolve(null);
275
+ }, options.timeout || 1000);
276
+
277
+ const responseHandler = (response) => {
278
+ if (response.key === key) {
279
+ clearTimeout(timeout);
280
+ this.communicationBus.off('memory:response', responseHandler);
281
+ resolve(response);
282
+ }
283
+ };
284
+
285
+ this.communicationBus.on('memory:response', responseHandler);
286
+
287
+ // Send query request
288
+ this.broadcast('memory:query', {
289
+ key,
290
+ requestId: `query-${Date.now()}`,
291
+ requester: process.pid,
292
+ timestamp: new Date().toISOString()
293
+ });
294
+ });
295
+ }
296
+
297
+ /**
298
+ * Handle memory update broadcasts from other agents
299
+ */
300
+ handleMemoryUpdate(update) {
301
+ const { type, key, value, namespace, metadata } = update;
302
+
303
+ // Check if any subscribers match this update
304
+ for (const [subId, subscription] of this.subscribers) {
305
+ const pattern = subscription.pattern;
306
+
307
+ // Simple pattern matching (supports wildcards)
308
+ if (this.matchesPattern(key, pattern)) {
309
+ subscription.callback(update);
310
+ }
311
+ }
312
+
313
+ this.metrics.messagesReceived++;
314
+ this.emit('remoteUpdate', update);
315
+ }
316
+
317
+ /**
318
+ * Handle memory query requests from other agents
319
+ */
320
+ handleMemoryQuery(query) {
321
+ const { key, requestId, requester } = query;
322
+
323
+ const entry = this.data.get(key);
324
+
325
+ if (entry) {
326
+ // Respond with the data
327
+ this.broadcast('memory:response', {
328
+ key,
329
+ requestId,
330
+ requester,
331
+ value: entry.value,
332
+ options: entry.options,
333
+ respondent: process.pid,
334
+ timestamp: new Date().toISOString()
335
+ });
336
+ }
337
+ }
338
+
339
+ /**
340
+ * Pattern matching for subscriptions
341
+ */
342
+ matchesPattern(key, pattern) {
343
+ if (pattern === '*') return true;
344
+ if (pattern === key) return true;
345
+
346
+ // Convert glob pattern to regex
347
+ const regexPattern = pattern
348
+ .replace(/\./g, '\\.')
349
+ .replace(/\*/g, '.*')
350
+ .replace(/\?/g, '.');
351
+
352
+ const regex = new RegExp(`^${regexPattern}$`);
353
+ return regex.test(key);
354
+ }
355
+
356
+ /**
357
+ * Update performance metrics
358
+ */
359
+ updateMetrics(operation, latency, bytes) {
360
+ // Update average latency using exponential moving average
361
+ const alpha = 0.2;
362
+ this.metrics.averageLatency = alpha * latency + (1 - alpha) * this.metrics.averageLatency;
363
+
364
+ // Update peak latency
365
+ if (latency > this.metrics.peakLatency) {
366
+ this.metrics.peakLatency = latency;
367
+ }
368
+
369
+ // Update total bytes
370
+ this.metrics.totalBytes += bytes;
371
+ }
372
+
373
+ /**
374
+ * Get performance metrics
375
+ */
376
+ getMetrics() {
377
+ return {
378
+ ...this.metrics,
379
+ messagesPerSecond: this.metrics.messagesPublished / (Date.now() / 1000),
380
+ averageThroughput: this.metrics.totalBytes / (Date.now() / 1000),
381
+ communicationEnabled: this.communicationEnabled,
382
+ subscribers: this.subscribers.size
383
+ };
384
+ }
385
+
386
+ /**
387
+ * Persist memory store to disk
388
+ */
389
+ async persist() {
390
+ try {
391
+ const dataObj = Object.fromEntries(this.data);
392
+ await fs.writeFile(this.memoryFile, JSON.stringify(dataObj, null, 2));
393
+ } catch (error) {
394
+ console.warn(`⚠️ Communication memory persist warning: ${error.message}`);
395
+ }
396
+ }
397
+
398
+ /**
399
+ * Close communication bus and cleanup
400
+ */
401
+ async close() {
402
+ await this.persist();
403
+
404
+ if (this.communicationEnabled && this.communicationBus.close) {
405
+ await this.communicationBus.close();
406
+ }
407
+
408
+ this.subscribers.clear();
409
+ this.emit('close');
410
+ }
411
+ }
412
+
413
+ /**
414
+ * Communication-Integrated Post-Edit Hook
415
+ * Extends the enhanced post-edit hook with real-time agent communication
416
+ */
417
+ export async function communicationIntegratedPostEdit(file, memoryKey = null, options = {}) {
418
+ const {
419
+ enableCommunication = true,
420
+ broadcastProgress = true,
421
+ coordinateWithAgents = true,
422
+ agentId = null,
423
+ swarmId = null,
424
+ ...enhancedOptions
425
+ } = options;
426
+
427
+ console.log('🚀 Communication-Integrated Post-Edit Hook Starting...');
428
+ console.log(`📄 File: ${file}`);
429
+ if (memoryKey) console.log(`💾 Memory key: ${memoryKey}`);
430
+ if (agentId) console.log(`🤖 Agent ID: ${agentId}`);
431
+ if (swarmId) console.log(`🐝 Swarm ID: ${swarmId}`);
432
+
433
+ // Initialize communication memory store
434
+ const commStore = new CommunicationMemoryStore({
435
+ enableCommunication,
436
+ enableZeroCopy: options.enableZeroCopy !== false,
437
+ enableOptimizedSerialization: options.enableOptimizedSerialization !== false
438
+ });
439
+
440
+ await commStore.initialize();
441
+
442
+ // Broadcast start event to swarm
443
+ if (broadcastProgress) {
444
+ await commStore.broadcast('agent:edit:start', {
445
+ agentId,
446
+ swarmId,
447
+ file,
448
+ memoryKey,
449
+ timestamp: new Date().toISOString()
450
+ });
451
+ }
452
+
453
+ // Subscribe to agent coordination events
454
+ const subscriptions = [];
455
+ if (coordinateWithAgents) {
456
+ const subId = commStore.subscribe('agent:edit:*', (update) => {
457
+ console.log(`📡 Received agent update: ${update.type}`);
458
+ });
459
+ subscriptions.push(subId);
460
+ }
461
+
462
+ try {
463
+ // Run the enhanced post-edit hook
464
+ const result = await enhancedPostEditHook(file, memoryKey, {
465
+ returnStructured: true,
466
+ ...enhancedOptions
467
+ });
468
+
469
+ // Store result in communication memory
470
+ if (result.success) {
471
+ await commStore.store(
472
+ memoryKey || `edit:${result.editId}`,
473
+ result,
474
+ {
475
+ namespace: 'communication-edits',
476
+ metadata: {
477
+ agentId,
478
+ swarmId,
479
+ file,
480
+ timestamp: result.timestamp,
481
+ passed: result.validation?.passed || false,
482
+ coverage: result.coverage?.lines?.percentage || 0,
483
+ tddPhase: result.tddPhase
484
+ },
485
+ broadcast: broadcastProgress
486
+ }
487
+ );
488
+ }
489
+
490
+ // Broadcast completion to swarm
491
+ if (broadcastProgress) {
492
+ await commStore.broadcast('agent:edit:complete', {
493
+ agentId,
494
+ swarmId,
495
+ file,
496
+ memoryKey,
497
+ success: result.success,
498
+ editId: result.editId,
499
+ validation: result.validation?.passed || false,
500
+ coverage: result.coverage?.lines?.percentage || 0,
501
+ tddPhase: result.tddPhase,
502
+ timestamp: new Date().toISOString()
503
+ });
504
+ }
505
+
506
+ // Add communication metrics to result
507
+ result.communication = {
508
+ enabled: commStore.communicationEnabled,
509
+ metrics: commStore.getMetrics(),
510
+ subscribers: subscriptions.length
511
+ };
512
+
513
+ // Cleanup subscriptions
514
+ subscriptions.forEach(subId => commStore.unsubscribe(subId));
515
+ await commStore.close();
516
+
517
+ return result;
518
+
519
+ } catch (error) {
520
+ console.error(`❌ Communication-integrated post-edit failed: ${error.message}`);
521
+
522
+ // Broadcast failure to swarm
523
+ if (broadcastProgress) {
524
+ await commStore.broadcast('agent:edit:failed', {
525
+ agentId,
526
+ swarmId,
527
+ file,
528
+ memoryKey,
529
+ error: error.message,
530
+ timestamp: new Date().toISOString()
531
+ });
532
+ }
533
+
534
+ // Cleanup
535
+ subscriptions.forEach(subId => commStore.unsubscribe(subId));
536
+ await commStore.close();
537
+
538
+ throw error;
539
+ }
540
+ }
541
+
542
+ /**
543
+ * CLI interface for communication-integrated post-edit
544
+ */
545
+ export async function cliMain() {
546
+ const args = process.argv.slice(2);
547
+ const command = args[0];
548
+
549
+ if (!command || command === '--help' || command === '-h') {
550
+ console.log(`
551
+ 🚀 Communication-Integrated Post-Edit Pipeline - v3.0.0
552
+
553
+ Integrates ultra-fast communication system with enhanced post-edit pipeline
554
+ for real-time agent coordination and memory sharing.
555
+
556
+ Available commands:
557
+ post-edit <file> [options] Communication-integrated post-edit
558
+
559
+ Options:
560
+ --memory-key <key> Store results with specific memory key
561
+ --agent-id <id> Agent identifier for coordination
562
+ --swarm-id <id> Swarm identifier for coordination
563
+ --enable-communication Enable ultra-fast communication (default: true)
564
+ --broadcast-progress Broadcast progress to swarm (default: true)
565
+ --coordinate-with-agents Coordinate with other agents (default: true)
566
+ --enable-zero-copy Enable zero-copy structures (default: true)
567
+ --enable-optimized-serialization Enable optimized serialization (default: true)
568
+
569
+ # Enhanced Post-Edit Options:
570
+ --format Analyze formatting (default: true)
571
+ --validate Run validation (default: true)
572
+ --enable-tdd Enable TDD testing (default: true)
573
+ --minimum-coverage <percent> Minimum coverage threshold (default: 80)
574
+ --block-on-critical Block execution on critical errors
575
+ --structured Return structured JSON data
576
+
577
+ Examples:
578
+ node communication-integrated-post-edit.js post-edit src/app.js --agent-id "coder-1" --swarm-id "swarm-001"
579
+ node communication-integrated-post-edit.js post-edit test.js --memory-key "swarm/tester/step-1" --structured
580
+
581
+ Features:
582
+ ✅ Ultra-fast inter-agent communication (<1ms latency)
583
+ ✅ Shared memory coordination for multi-agent workflows
584
+ ✅ Real-time progress broadcasting to agent swarms
585
+ ✅ Zero-copy data structures for performance
586
+ ✅ Event-driven architecture for scalability
587
+ ✅ TDD testing with single-file execution
588
+ ✅ Real-time coverage analysis and diff reporting
589
+ ✅ Advanced multi-language validation
590
+ ✅ Actionable recommendations by category
591
+ `);
592
+ return;
593
+ }
594
+
595
+ if (command === 'post-edit') {
596
+ const file = args[1];
597
+ if (!file) {
598
+ console.log('❌ File path required for post-edit hook');
599
+ return;
600
+ }
601
+
602
+ // Parse options
603
+ const options = {
604
+ // Communication options
605
+ enableCommunication: !args.includes('--no-communication'),
606
+ broadcastProgress: !args.includes('--no-broadcast'),
607
+ coordinateWithAgents: !args.includes('--no-coordinate'),
608
+ enableZeroCopy: !args.includes('--no-zero-copy'),
609
+ enableOptimizedSerialization: !args.includes('--no-optimized-serialization'),
610
+
611
+ // Enhanced post-edit options
612
+ format: !args.includes('--no-format'),
613
+ validate: !args.includes('--no-validate'),
614
+ generateRecommendations: !args.includes('--no-recommendations'),
615
+ blockOnCritical: args.includes('--block-on-critical'),
616
+ enableTDD: !args.includes('--no-tdd'),
617
+ returnStructured: args.includes('--structured')
618
+ };
619
+
620
+ // Parse string options
621
+ const parseOption = (flag) => {
622
+ const index = args.indexOf(flag);
623
+ return index >= 0 ? args[index + 1] : null;
624
+ };
625
+
626
+ options.agentId = parseOption('--agent-id');
627
+ options.swarmId = parseOption('--swarm-id');
628
+ const memoryKey = parseOption('--memory-key');
629
+
630
+ const coverageValue = parseOption('--minimum-coverage');
631
+ if (coverageValue) {
632
+ options.minimumCoverage = parseInt(coverageValue) || 80;
633
+ }
634
+
635
+ try {
636
+ const result = await communicationIntegratedPostEdit(file, memoryKey, options);
637
+
638
+ if (options.returnStructured) {
639
+ console.log(JSON.stringify(result, null, 2));
640
+ }
641
+
642
+ // Exit codes
643
+ if (result.blocking) {
644
+ process.exit(1);
645
+ } else if (!result.success) {
646
+ process.exit(2);
647
+ }
648
+
649
+ } catch (error) {
650
+ console.error(`❌ Communication-integrated post-edit failed: ${error.message}`);
651
+ if (process.env.DEBUG) {
652
+ console.error(error.stack);
653
+ }
654
+ process.exit(1);
655
+ }
656
+
657
+ } else {
658
+ console.log(`❌ Unknown command: ${command}`);
659
+ console.log('Use --help for available commands');
660
+ process.exit(1);
661
+ }
662
+ }
663
+
664
+ // Export for programmatic use
665
+ export { CommunicationMemoryStore };
666
+
667
+ // Run CLI if called directly
668
+ if (import.meta.url === `file://${process.argv[1]}`) {
669
+ cliMain().catch(error => {
670
+ console.error(`💥 Fatal error: ${error.message}`);
671
+ process.exit(1);
672
+ });
673
+ }