sam-coder-cli 1.0.16 → 1.0.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.
@@ -446,26 +446,25 @@ class MultiplayerClient extends EventEmitter {
446
446
 
447
447
  console.log(chalk.blue(`\nšŸ”„ [${this.role}] Working on: ${this.currentTask.prompt}`));
448
448
 
449
- // Simulate work with progress updates
450
- const totalSteps = 5;
451
- for (let i = 0; i < totalSteps; i++) {
452
- await new Promise(resolve => setTimeout(resolve, 500));
453
- const progress = Math.floor(((i + 1) / totalSteps) * 100);
454
-
455
- // Update progress
449
+ // Process the task using the completeTask method
450
+ const completedTask = await this.completeTask(taskId);
451
+
452
+ if (completedTask) {
453
+ // Task completed successfully
456
454
  this.send({
457
455
  type: 'task_progress',
458
456
  sessionId: this.sessionId,
459
457
  taskId,
460
- status: 'in_progress',
461
- progress,
458
+ status: 'completed',
459
+ progress: 100,
462
460
  timestamp: new Date().toISOString()
463
461
  });
462
+
463
+ console.log(chalk.green(`\nāœ… [${this.role}] Completed task: ${this.currentTask.prompt}`));
464
+ }
465
+ if (this.taskQueue.length > 0) {
466
+ this.processTaskQueue();
464
467
  }
465
-
466
- // Complete the task
467
- await this.completeTask(taskId);
468
-
469
468
  } catch (error) {
470
469
  console.error('Error processing task:', error);
471
470
  this.send({
@@ -477,69 +476,96 @@ class MultiplayerClient extends EventEmitter {
477
476
  });
478
477
  } finally {
479
478
  this.currentTask = null;
480
- // Process next task if available
481
- if (this.taskQueue.length > 0) {
482
- this.processTaskQueue();
483
- }
484
479
  }
485
480
  }
486
481
 
487
482
  async completeTask(taskId) {
488
483
  const task = this.pendingTasks.get(taskId);
489
- if (!task) return null;
484
+ if (!task) {
485
+ console.error('Task not found:', taskId);
486
+ return null;
487
+ }
488
+
489
+ try {
490
+ // Process the task using the same logic as the normal mode
491
+ const { processQuery } = require('./agi-cli');
492
+ const result = await processQuery(task.prompt, [], this.model);
493
+
494
+ // Update task status
495
+ const completedTask = {
496
+ ...task,
497
+ status: 'completed',
498
+ completedAt: new Date().toISOString(),
499
+ result: typeof result === 'string' ? result : JSON.stringify(result, null, 2)
500
+ };
501
+
502
+ this.pendingTasks.set(taskId, completedTask);
503
+ this.taskResults.set(taskId, completedTask.result);
504
+
505
+ // Notify server and other clients
506
+ this.send({
507
+ type: 'task_completed',
508
+ sessionId: this.sessionId,
509
+ taskId,
510
+ result: completedTask.result,
511
+ timestamp: new Date().toISOString()
512
+ });
513
+
514
+ console.log(chalk.green(`\nāœ… [${this.role}] Completed: ${task.prompt}`));
515
+ this.emit('task_completed', completedTask);
516
+
517
+ return completedTask;
518
+ } catch (error) {
519
+ console.error('Error completing task:', error);
520
+
521
+ // Update task with error status
522
+ const failedTask = {
523
+ ...task,
524
+ status: 'failed',
525
+ completedAt: new Date().toISOString(),
526
+ error: error.message
527
+ };
528
+
529
+ this.pendingTasks.set(taskId, failedTask);
530
+ this.emit('task_failed', { taskId, error: error.message });
531
+
532
+ return null;
533
+ }
534
+ }
535
+
536
+ handleTaskCompleted(data) {
537
+ const task = this.pendingTasks.get(data.taskId);
538
+ if (!task) {
539
+ console.error('Task not found for completion:', data.taskId);
540
+ return;
541
+ }
490
542
 
491
- // Generate task result based on task type
492
- let result;
493
- switch (task.taskType) {
494
- case 'research':
495
- result = `Research completed on: ${task.prompt}\nSummary: This is a simulated research result.`;
496
- break;
497
- case 'code':
498
- result = `Code implementation for: ${task.prompt}\n// Simulated code implementation\nfunction ${task.prompt.split(' ')[0].toLowerCase()}() {\n // TODO: Implement\n}`;
499
- break;
500
- case 'debug':
501
- result = `Debugging analysis for: ${task.prompt}\n- Issue identified: Simulated issue\n- Solution: Simulated fix`;
502
- break;
503
- default:
504
- result = `Completed: ${task.prompt}`;
543
+ console.log(chalk.green(`\nāœ… Task completed by all agents!`));
544
+ console.log(chalk.blue(`Task: ${task.prompt || 'Unknown task'}`));
545
+
546
+ if (data.results && data.results.length > 0) {
547
+ console.log(chalk.cyan('Results:'));
548
+ data.results.forEach(result => {
549
+ console.log(chalk.yellow(`- ${this.getClientName(result.clientId) || 'Unknown'}:`));
550
+ console.log(result.result);
551
+ });
552
+ } else if (data.result) {
553
+ console.log(chalk.cyan('Result:'));
554
+ console.log(data.result);
505
555
  }
506
556
 
507
- // Update task status
557
+ // Update the task with the final result
508
558
  const completedTask = {
509
559
  ...task,
510
560
  status: 'completed',
511
561
  completedAt: new Date().toISOString(),
512
- result
562
+ result: data.result || 'No result provided'
513
563
  };
514
564
 
515
- this.pendingTasks.set(taskId, completedTask);
516
- this.taskResults.set(taskId, result);
517
-
518
- // Notify server and other clients
519
- this.send({
520
- type: 'task_completed',
521
- sessionId: this.sessionId,
522
- taskId,
523
- result,
524
- timestamp: new Date().toISOString()
525
- });
565
+ this.pendingTasks.set(data.taskId, completedTask);
566
+ this.taskResults.set(data.taskId, completedTask.result);
526
567
 
527
- console.log(chalk.green(`\nāœ… [${this.role}] Completed: ${task.prompt}`));
528
568
  this.emit('task_completed', completedTask);
529
-
530
- return completedTask;
531
- }
532
-
533
- handleTaskCompleted(data) {
534
- console.log(`\n Task completed by all agents!`);
535
- console.log(`Task: ${this.tasks.get(data.taskId)?.prompt || 'Unknown task'}`);
536
- console.log('Results:');
537
-
538
- data.results.forEach(result => {
539
- console.log(`- ${this.getClientName(result.clientId)}: ${result.result}`);
540
- });
541
-
542
- this.emit('task_completed', data);
543
569
  }
544
570
 
545
571
  async updateWork(work) {
@@ -618,6 +644,20 @@ class MultiplayerClient extends EventEmitter {
618
644
  this.ws.close();
619
645
  }
620
646
  }
647
+
648
+ getClientName(clientId) {
649
+ if (!clientId) return 'Unknown';
650
+ const client = this.clients.find(c => c.clientId === clientId || c.id === clientId);
651
+ return client ? (client.name || client.clientInfo?.name || 'Unknown') : 'Unknown';
652
+ }
653
+
654
+ printHeader() {
655
+ console.clear();
656
+ console.log(chalk.blue.bold('=== Multiplayer Mode ==='));
657
+ console.log(chalk.cyan(`Connected as: ${this.name} (${this.role})`));
658
+ console.log(chalk.cyan(`Session: ${this.sessionId || 'Not connected'}`));
659
+ console.log(chalk.cyan('Type /help for available commands\n'));
660
+ }
621
661
  }
622
662
 
623
663
  module.exports = MultiplayerClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sam-coder-cli",
3
- "version": "1.0.16",
3
+ "version": "1.0.19",
4
4
  "description": "SAM-CODER: An animated command-line AI assistant with agency capabilities.",
5
5
  "main": "bin/agi-cli.js",
6
6
  "bin": {