sam-coder-cli 2.0.2 → 2.0.4

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 (2) hide show
  1. package/bin/agi-cli.js +29 -38
  2. package/package.json +1 -1
package/bin/agi-cli.js CHANGED
@@ -1473,10 +1473,13 @@ async function chat(rl, mode, initialModel) {
1473
1473
 
1474
1474
  console.log('Type your message, or "exit" to quit.');
1475
1475
 
1476
- rl.setPrompt('> ');
1477
- rl.prompt();
1476
+ // Use async iterator pattern instead of event-based 'on' to avoid async callback issues
1477
+ while (true) {
1478
+ const input = await new Promise((resolve) => {
1479
+ rl.question('> ', resolve);
1480
+ });
1478
1481
 
1479
- rl.on('line', async (input) => {
1482
+ // Handle commands
1480
1483
  if (input.toLowerCase().startsWith('/model')) {
1481
1484
  const newModel = input.split(' ')[1];
1482
1485
  if (newModel) {
@@ -1488,8 +1491,7 @@ async function chat(rl, mode, initialModel) {
1488
1491
  } else {
1489
1492
  console.log('Please specify a model. Usage: /model <model_name>');
1490
1493
  }
1491
- rl.prompt();
1492
- return;
1494
+ continue;
1493
1495
  }
1494
1496
 
1495
1497
  if (input.toLowerCase().startsWith('/thoughts')) {
@@ -1498,8 +1500,7 @@ async function chat(rl, mode, initialModel) {
1498
1500
  if (arg !== 'on' && arg !== 'off') {
1499
1501
  const state = SHOW_THOUGHTS ? 'on' : 'off';
1500
1502
  ui.showInfo(`Usage: /thoughts on|off (currently ${state})`);
1501
- rl.prompt();
1502
- return;
1503
+ continue;
1503
1504
  }
1504
1505
  const enable = arg === 'on';
1505
1506
  SHOW_THOUGHTS = enable;
@@ -1507,8 +1508,7 @@ async function chat(rl, mode, initialModel) {
1507
1508
  config.showThoughts = enable;
1508
1509
  await writeConfig(config);
1509
1510
  ui.showResponse(`Hidden thoughts ${enable ? 'enabled' : 'disabled'}.`);
1510
- rl.prompt();
1511
- return;
1511
+ continue;
1512
1512
  }
1513
1513
 
1514
1514
  if (input.toLowerCase() === '/default-model') {
@@ -1517,8 +1517,7 @@ async function chat(rl, mode, initialModel) {
1517
1517
  config.MODEL = currentModel;
1518
1518
  await writeConfig(config);
1519
1519
  console.log(`Model reset to default: ${currentModel}`);
1520
- rl.prompt();
1521
- return;
1520
+ continue;
1522
1521
  }
1523
1522
 
1524
1523
  if (input.toLowerCase() === '/setup') {
@@ -1534,16 +1533,14 @@ async function chat(rl, mode, initialModel) {
1534
1533
  if (!parts) {
1535
1534
  console.log('Usage: /brainstorm <project-name> "<description>"');
1536
1535
  console.log('Example: /brainstorm "My Project" "A cool project that does things"');
1537
- rl.prompt();
1538
- return;
1536
+ continue;
1539
1537
  }
1540
1538
 
1541
1539
  // Parse project name and description
1542
1540
  const match = parts.match(/^"?([^"]+)"?\s+"?([^"]+)"?$/) || parts.match(/^(\S+)\s+(.+)$/);
1543
1541
  if (!match) {
1544
1542
  console.log('Usage: /brainstorm <project-name> "<description>"');
1545
- rl.prompt();
1546
- return;
1543
+ continue;
1547
1544
  }
1548
1545
 
1549
1546
  const projectName = match[1].trim();
@@ -1572,9 +1569,7 @@ async function chat(rl, mode, initialModel) {
1572
1569
  } catch (error) {
1573
1570
  ui.showError(`Failed to create brainstorm: ${error.message}`);
1574
1571
  }
1575
-
1576
- rl.prompt();
1577
- return;
1572
+ continue;
1578
1573
  }
1579
1574
 
1580
1575
  // Finish command: /finish <summary>
@@ -1583,14 +1578,12 @@ async function chat(rl, mode, initialModel) {
1583
1578
 
1584
1579
  if (!global.currentSessionDir) {
1585
1580
  console.log('No active brainstorm session. Use /brainstorm first.');
1586
- rl.prompt();
1587
- return;
1581
+ continue;
1588
1582
  }
1589
1583
 
1590
1584
  if (!summary) {
1591
1585
  console.log('Usage: /finish "<summary of what was accomplished>"');
1592
- rl.prompt();
1593
- return;
1586
+ continue;
1594
1587
  }
1595
1588
 
1596
1589
  try {
@@ -1611,12 +1604,11 @@ async function chat(rl, mode, initialModel) {
1611
1604
  } catch (error) {
1612
1605
  ui.showError(`Failed to finish session: ${error.message}`);
1613
1606
  }
1614
-
1615
- rl.prompt();
1616
- return;
1607
+ continue;
1617
1608
  }
1618
1609
 
1619
1610
  if (input.toLowerCase() === 'exit') {
1611
+ ui.showResponse('Goodbye!');
1620
1612
  rl.close();
1621
1613
  return;
1622
1614
  }
@@ -1645,13 +1637,13 @@ async function chat(rl, mode, initialModel) {
1645
1637
  const preview = typeof r.content === 'string' ? r.content : JSON.stringify(r.content);
1646
1638
  ui.showInfo(`${r.name}: ${preview.length > 300 ? preview.slice(0, 300) + '...' : preview}`);
1647
1639
  });
1648
- rl.prompt();
1649
- return;
1640
+ continue;
1650
1641
  }
1651
1642
  } catch (e) {
1652
1643
  // Fall through to normal processing if parsing/execution fails
1653
1644
  }
1654
1645
 
1646
+ // Main query processing
1655
1647
  try {
1656
1648
  const result = useToolCalling
1657
1649
  ? await processQueryWithTools(input, conversation, currentModel)
@@ -1668,17 +1660,7 @@ async function chat(rl, mode, initialModel) {
1668
1660
  console.error(error.stack);
1669
1661
  }
1670
1662
  }
1671
-
1672
- rl.prompt();
1673
- });
1674
-
1675
- // Return a Promise that resolves when readline closes
1676
- return new Promise((resolve) => {
1677
- rl.on('close', () => {
1678
- ui.showResponse('Goodbye!');
1679
- resolve();
1680
- });
1681
- });
1663
+ }
1682
1664
  }
1683
1665
 
1684
1666
  function askForMode(rl) {
@@ -1794,6 +1776,7 @@ async function start() {
1794
1776
  ui.showResponse(`\nStarting in ${modeNames[selectedMode]} mode...\n`);
1795
1777
 
1796
1778
  await chat(rl, selectedMode, MODEL);
1779
+ process.exit(0);
1797
1780
  } catch (error) {
1798
1781
  ui.showError(error);
1799
1782
  rl.close();
@@ -1801,4 +1784,12 @@ async function start() {
1801
1784
  }
1802
1785
  }
1803
1786
 
1787
+ // Keep the process alive and handle uncaught errors
1788
+ process.on('uncaughtException', (err) => {
1789
+ console.error('Uncaught Exception:', err.message);
1790
+ });
1791
+ process.on('unhandledRejection', (reason) => {
1792
+ console.error('Unhandled Rejection:', reason);
1793
+ });
1794
+
1804
1795
  start().catch(console.error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sam-coder-cli",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "SAM-CODER: An animated command-line AI assistant with agency capabilities, brainstorm framework, and engineer mode.",
5
5
  "main": "bin/agi-cli.js",
6
6
  "bin": {