amai 0.0.3 → 0.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.
- package/dist/cli.cjs +90 -2
- package/dist/cli.js +90 -2
- package/dist/lib/daemon-entry.cjs +89 -1
- package/dist/lib/daemon-entry.js +89 -1
- package/dist/server.cjs +89 -1
- package/dist/server.js +90 -2
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -1547,6 +1547,93 @@ async function login() {
|
|
|
1547
1547
|
throw error;
|
|
1548
1548
|
}
|
|
1549
1549
|
}
|
|
1550
|
+
var ExplanationSchema = zod.z.object({
|
|
1551
|
+
explanation: zod.z.string().describe("One sentence explanation as to why this tool is being used")
|
|
1552
|
+
});
|
|
1553
|
+
zod.z.object({
|
|
1554
|
+
command: zod.z.string().describe("The terminal command to execute"),
|
|
1555
|
+
is_background: zod.z.boolean().describe("Whether the command should be run in the background")
|
|
1556
|
+
}).merge(ExplanationSchema);
|
|
1557
|
+
var runSecureTerminalCommand = async (command, timeout) => {
|
|
1558
|
+
try {
|
|
1559
|
+
return new Promise((resolve, reject) => {
|
|
1560
|
+
const child = child_process.spawn(command, {
|
|
1561
|
+
cwd: process.cwd(),
|
|
1562
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
1563
|
+
shell: true
|
|
1564
|
+
});
|
|
1565
|
+
let stdout = "";
|
|
1566
|
+
let stderr = "";
|
|
1567
|
+
let timeoutId = null;
|
|
1568
|
+
if (timeoutId > 0) {
|
|
1569
|
+
timeoutId = setTimeout(() => {
|
|
1570
|
+
child.kill("SIGKILL");
|
|
1571
|
+
reject(new Error(`Command timed out after ${timeout}ms`));
|
|
1572
|
+
}, timeout);
|
|
1573
|
+
}
|
|
1574
|
+
child.stdout?.on("data", (data) => {
|
|
1575
|
+
stdout += data.toString();
|
|
1576
|
+
});
|
|
1577
|
+
child.stderr?.on("data", (data) => {
|
|
1578
|
+
stderr += data.toString();
|
|
1579
|
+
});
|
|
1580
|
+
child.stdout.on("close", (code) => {
|
|
1581
|
+
if (timeoutId) {
|
|
1582
|
+
clearTimeout(timeoutId);
|
|
1583
|
+
}
|
|
1584
|
+
resolve({ stdout, stderr, exitCode: code || 0 });
|
|
1585
|
+
});
|
|
1586
|
+
child.stderr.on("error", (error) => {
|
|
1587
|
+
if (timeoutId) {
|
|
1588
|
+
clearTimeout(timeoutId);
|
|
1589
|
+
}
|
|
1590
|
+
reject(error);
|
|
1591
|
+
});
|
|
1592
|
+
});
|
|
1593
|
+
} catch {
|
|
1594
|
+
console.error("Error while ecexuting the securedShell command");
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1597
|
+
var runTerminalCommand = async (input, projectCwd) => {
|
|
1598
|
+
try {
|
|
1599
|
+
if (input?.is_background) {
|
|
1600
|
+
const child = child_process.spawn(input.command, {
|
|
1601
|
+
cwd: projectCwd,
|
|
1602
|
+
detached: true,
|
|
1603
|
+
stdio: "ignore",
|
|
1604
|
+
shell: true
|
|
1605
|
+
});
|
|
1606
|
+
child.unref();
|
|
1607
|
+
console.log(`[LOCAL] Background command started: ${input.command}`);
|
|
1608
|
+
return {
|
|
1609
|
+
success: true,
|
|
1610
|
+
message: `Background command started: ${input.command}`,
|
|
1611
|
+
isBackground: true
|
|
1612
|
+
};
|
|
1613
|
+
} else {
|
|
1614
|
+
const result = await runSecureTerminalCommand(
|
|
1615
|
+
input.command,
|
|
1616
|
+
3e4
|
|
1617
|
+
// 30 second timeout
|
|
1618
|
+
);
|
|
1619
|
+
const success = result?.exitCode === 0;
|
|
1620
|
+
return {
|
|
1621
|
+
success,
|
|
1622
|
+
stdout: result?.stdout?.trim(),
|
|
1623
|
+
stderr: result?.stderr?.trim(),
|
|
1624
|
+
exitCode: result?.exitCode,
|
|
1625
|
+
message: success ? `Command executed successfully: ${input.command}` : `Command failed with exit code ${result?.exitCode}: ${input.command}`
|
|
1626
|
+
};
|
|
1627
|
+
}
|
|
1628
|
+
} catch (error) {
|
|
1629
|
+
console.error("Error while executing the terminal command", error);
|
|
1630
|
+
return {
|
|
1631
|
+
success: false,
|
|
1632
|
+
message: "Error while executing the terminal command",
|
|
1633
|
+
error: error.message
|
|
1634
|
+
};
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1550
1637
|
|
|
1551
1638
|
// src/server.ts
|
|
1552
1639
|
var statusEmitter = new events.EventEmitter();
|
|
@@ -1557,7 +1644,8 @@ var toolExecutors = {
|
|
|
1557
1644
|
glob: globTool,
|
|
1558
1645
|
listDirectory: list,
|
|
1559
1646
|
readFile: read_file,
|
|
1560
|
-
stringReplace: apply_patch
|
|
1647
|
+
stringReplace: apply_patch,
|
|
1648
|
+
runTerminalCommand
|
|
1561
1649
|
};
|
|
1562
1650
|
function getConnectionStatus(ws) {
|
|
1563
1651
|
return ws.readyState === WebSocket__default.default.CONNECTING ? "connecting" : ws.readyState === WebSocket__default.default.OPEN ? "open" : ws.readyState === WebSocket__default.default.CLOSING ? "closing" : "closed";
|
|
@@ -1807,7 +1895,7 @@ function getDaemonPid() {
|
|
|
1807
1895
|
return null;
|
|
1808
1896
|
}
|
|
1809
1897
|
}
|
|
1810
|
-
var VERSION = "0.0.
|
|
1898
|
+
var VERSION = "0.0.4";
|
|
1811
1899
|
var PROJECT_DIR = process.cwd();
|
|
1812
1900
|
function promptUser(question) {
|
|
1813
1901
|
const rl = readline__default.default.createInterface({
|
package/dist/cli.js
CHANGED
|
@@ -1535,6 +1535,93 @@ async function login() {
|
|
|
1535
1535
|
throw error;
|
|
1536
1536
|
}
|
|
1537
1537
|
}
|
|
1538
|
+
var ExplanationSchema = z.object({
|
|
1539
|
+
explanation: z.string().describe("One sentence explanation as to why this tool is being used")
|
|
1540
|
+
});
|
|
1541
|
+
z.object({
|
|
1542
|
+
command: z.string().describe("The terminal command to execute"),
|
|
1543
|
+
is_background: z.boolean().describe("Whether the command should be run in the background")
|
|
1544
|
+
}).merge(ExplanationSchema);
|
|
1545
|
+
var runSecureTerminalCommand = async (command, timeout) => {
|
|
1546
|
+
try {
|
|
1547
|
+
return new Promise((resolve, reject) => {
|
|
1548
|
+
const child = spawn(command, {
|
|
1549
|
+
cwd: process.cwd(),
|
|
1550
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
1551
|
+
shell: true
|
|
1552
|
+
});
|
|
1553
|
+
let stdout = "";
|
|
1554
|
+
let stderr = "";
|
|
1555
|
+
let timeoutId = null;
|
|
1556
|
+
if (timeoutId > 0) {
|
|
1557
|
+
timeoutId = setTimeout(() => {
|
|
1558
|
+
child.kill("SIGKILL");
|
|
1559
|
+
reject(new Error(`Command timed out after ${timeout}ms`));
|
|
1560
|
+
}, timeout);
|
|
1561
|
+
}
|
|
1562
|
+
child.stdout?.on("data", (data) => {
|
|
1563
|
+
stdout += data.toString();
|
|
1564
|
+
});
|
|
1565
|
+
child.stderr?.on("data", (data) => {
|
|
1566
|
+
stderr += data.toString();
|
|
1567
|
+
});
|
|
1568
|
+
child.stdout.on("close", (code) => {
|
|
1569
|
+
if (timeoutId) {
|
|
1570
|
+
clearTimeout(timeoutId);
|
|
1571
|
+
}
|
|
1572
|
+
resolve({ stdout, stderr, exitCode: code || 0 });
|
|
1573
|
+
});
|
|
1574
|
+
child.stderr.on("error", (error) => {
|
|
1575
|
+
if (timeoutId) {
|
|
1576
|
+
clearTimeout(timeoutId);
|
|
1577
|
+
}
|
|
1578
|
+
reject(error);
|
|
1579
|
+
});
|
|
1580
|
+
});
|
|
1581
|
+
} catch {
|
|
1582
|
+
console.error("Error while ecexuting the securedShell command");
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
var runTerminalCommand = async (input, projectCwd) => {
|
|
1586
|
+
try {
|
|
1587
|
+
if (input?.is_background) {
|
|
1588
|
+
const child = spawn(input.command, {
|
|
1589
|
+
cwd: projectCwd,
|
|
1590
|
+
detached: true,
|
|
1591
|
+
stdio: "ignore",
|
|
1592
|
+
shell: true
|
|
1593
|
+
});
|
|
1594
|
+
child.unref();
|
|
1595
|
+
console.log(`[LOCAL] Background command started: ${input.command}`);
|
|
1596
|
+
return {
|
|
1597
|
+
success: true,
|
|
1598
|
+
message: `Background command started: ${input.command}`,
|
|
1599
|
+
isBackground: true
|
|
1600
|
+
};
|
|
1601
|
+
} else {
|
|
1602
|
+
const result = await runSecureTerminalCommand(
|
|
1603
|
+
input.command,
|
|
1604
|
+
3e4
|
|
1605
|
+
// 30 second timeout
|
|
1606
|
+
);
|
|
1607
|
+
const success = result?.exitCode === 0;
|
|
1608
|
+
return {
|
|
1609
|
+
success,
|
|
1610
|
+
stdout: result?.stdout?.trim(),
|
|
1611
|
+
stderr: result?.stderr?.trim(),
|
|
1612
|
+
exitCode: result?.exitCode,
|
|
1613
|
+
message: success ? `Command executed successfully: ${input.command}` : `Command failed with exit code ${result?.exitCode}: ${input.command}`
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
} catch (error) {
|
|
1617
|
+
console.error("Error while executing the terminal command", error);
|
|
1618
|
+
return {
|
|
1619
|
+
success: false,
|
|
1620
|
+
message: "Error while executing the terminal command",
|
|
1621
|
+
error: error.message
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1624
|
+
};
|
|
1538
1625
|
|
|
1539
1626
|
// src/server.ts
|
|
1540
1627
|
var statusEmitter = new EventEmitter();
|
|
@@ -1545,7 +1632,8 @@ var toolExecutors = {
|
|
|
1545
1632
|
glob: globTool,
|
|
1546
1633
|
listDirectory: list,
|
|
1547
1634
|
readFile: read_file,
|
|
1548
|
-
stringReplace: apply_patch
|
|
1635
|
+
stringReplace: apply_patch,
|
|
1636
|
+
runTerminalCommand
|
|
1549
1637
|
};
|
|
1550
1638
|
function getConnectionStatus(ws) {
|
|
1551
1639
|
return ws.readyState === WebSocket.CONNECTING ? "connecting" : ws.readyState === WebSocket.OPEN ? "open" : ws.readyState === WebSocket.CLOSING ? "closing" : "closed";
|
|
@@ -1795,7 +1883,7 @@ function getDaemonPid() {
|
|
|
1795
1883
|
return null;
|
|
1796
1884
|
}
|
|
1797
1885
|
}
|
|
1798
|
-
var VERSION = "0.0.
|
|
1886
|
+
var VERSION = "0.0.4";
|
|
1799
1887
|
var PROJECT_DIR = process.cwd();
|
|
1800
1888
|
function promptUser(question) {
|
|
1801
1889
|
const rl = readline.createInterface({
|
|
@@ -1402,6 +1402,93 @@ function getTokens() {
|
|
|
1402
1402
|
const data = JSON.parse(raw);
|
|
1403
1403
|
return data;
|
|
1404
1404
|
}
|
|
1405
|
+
var ExplanationSchema = zod.z.object({
|
|
1406
|
+
explanation: zod.z.string().describe("One sentence explanation as to why this tool is being used")
|
|
1407
|
+
});
|
|
1408
|
+
zod.z.object({
|
|
1409
|
+
command: zod.z.string().describe("The terminal command to execute"),
|
|
1410
|
+
is_background: zod.z.boolean().describe("Whether the command should be run in the background")
|
|
1411
|
+
}).merge(ExplanationSchema);
|
|
1412
|
+
var runSecureTerminalCommand = async (command, timeout) => {
|
|
1413
|
+
try {
|
|
1414
|
+
return new Promise((resolve, reject) => {
|
|
1415
|
+
const child = child_process.spawn(command, {
|
|
1416
|
+
cwd: process.cwd(),
|
|
1417
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
1418
|
+
shell: true
|
|
1419
|
+
});
|
|
1420
|
+
let stdout = "";
|
|
1421
|
+
let stderr = "";
|
|
1422
|
+
let timeoutId = null;
|
|
1423
|
+
if (timeoutId > 0) {
|
|
1424
|
+
timeoutId = setTimeout(() => {
|
|
1425
|
+
child.kill("SIGKILL");
|
|
1426
|
+
reject(new Error(`Command timed out after ${timeout}ms`));
|
|
1427
|
+
}, timeout);
|
|
1428
|
+
}
|
|
1429
|
+
child.stdout?.on("data", (data) => {
|
|
1430
|
+
stdout += data.toString();
|
|
1431
|
+
});
|
|
1432
|
+
child.stderr?.on("data", (data) => {
|
|
1433
|
+
stderr += data.toString();
|
|
1434
|
+
});
|
|
1435
|
+
child.stdout.on("close", (code) => {
|
|
1436
|
+
if (timeoutId) {
|
|
1437
|
+
clearTimeout(timeoutId);
|
|
1438
|
+
}
|
|
1439
|
+
resolve({ stdout, stderr, exitCode: code || 0 });
|
|
1440
|
+
});
|
|
1441
|
+
child.stderr.on("error", (error) => {
|
|
1442
|
+
if (timeoutId) {
|
|
1443
|
+
clearTimeout(timeoutId);
|
|
1444
|
+
}
|
|
1445
|
+
reject(error);
|
|
1446
|
+
});
|
|
1447
|
+
});
|
|
1448
|
+
} catch {
|
|
1449
|
+
console.error("Error while ecexuting the securedShell command");
|
|
1450
|
+
}
|
|
1451
|
+
};
|
|
1452
|
+
var runTerminalCommand = async (input, projectCwd) => {
|
|
1453
|
+
try {
|
|
1454
|
+
if (input?.is_background) {
|
|
1455
|
+
const child = child_process.spawn(input.command, {
|
|
1456
|
+
cwd: projectCwd,
|
|
1457
|
+
detached: true,
|
|
1458
|
+
stdio: "ignore",
|
|
1459
|
+
shell: true
|
|
1460
|
+
});
|
|
1461
|
+
child.unref();
|
|
1462
|
+
console.log(`[LOCAL] Background command started: ${input.command}`);
|
|
1463
|
+
return {
|
|
1464
|
+
success: true,
|
|
1465
|
+
message: `Background command started: ${input.command}`,
|
|
1466
|
+
isBackground: true
|
|
1467
|
+
};
|
|
1468
|
+
} else {
|
|
1469
|
+
const result = await runSecureTerminalCommand(
|
|
1470
|
+
input.command,
|
|
1471
|
+
3e4
|
|
1472
|
+
// 30 second timeout
|
|
1473
|
+
);
|
|
1474
|
+
const success = result?.exitCode === 0;
|
|
1475
|
+
return {
|
|
1476
|
+
success,
|
|
1477
|
+
stdout: result?.stdout?.trim(),
|
|
1478
|
+
stderr: result?.stderr?.trim(),
|
|
1479
|
+
exitCode: result?.exitCode,
|
|
1480
|
+
message: success ? `Command executed successfully: ${input.command}` : `Command failed with exit code ${result?.exitCode}: ${input.command}`
|
|
1481
|
+
};
|
|
1482
|
+
}
|
|
1483
|
+
} catch (error) {
|
|
1484
|
+
console.error("Error while executing the terminal command", error);
|
|
1485
|
+
return {
|
|
1486
|
+
success: false,
|
|
1487
|
+
message: "Error while executing the terminal command",
|
|
1488
|
+
error: error.message
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1491
|
+
};
|
|
1405
1492
|
|
|
1406
1493
|
// src/server.ts
|
|
1407
1494
|
var statusEmitter = new events.EventEmitter();
|
|
@@ -1412,7 +1499,8 @@ var toolExecutors = {
|
|
|
1412
1499
|
glob: globTool,
|
|
1413
1500
|
listDirectory: list,
|
|
1414
1501
|
readFile: read_file,
|
|
1415
|
-
stringReplace: apply_patch
|
|
1502
|
+
stringReplace: apply_patch,
|
|
1503
|
+
runTerminalCommand
|
|
1416
1504
|
};
|
|
1417
1505
|
function getConnectionStatus(ws) {
|
|
1418
1506
|
return ws.readyState === WebSocket__default.default.CONNECTING ? "connecting" : ws.readyState === WebSocket__default.default.OPEN ? "open" : ws.readyState === WebSocket__default.default.CLOSING ? "closing" : "closed";
|
package/dist/lib/daemon-entry.js
CHANGED
|
@@ -1392,6 +1392,93 @@ function getTokens() {
|
|
|
1392
1392
|
const data = JSON.parse(raw);
|
|
1393
1393
|
return data;
|
|
1394
1394
|
}
|
|
1395
|
+
var ExplanationSchema = z.object({
|
|
1396
|
+
explanation: z.string().describe("One sentence explanation as to why this tool is being used")
|
|
1397
|
+
});
|
|
1398
|
+
z.object({
|
|
1399
|
+
command: z.string().describe("The terminal command to execute"),
|
|
1400
|
+
is_background: z.boolean().describe("Whether the command should be run in the background")
|
|
1401
|
+
}).merge(ExplanationSchema);
|
|
1402
|
+
var runSecureTerminalCommand = async (command, timeout) => {
|
|
1403
|
+
try {
|
|
1404
|
+
return new Promise((resolve, reject) => {
|
|
1405
|
+
const child = spawn(command, {
|
|
1406
|
+
cwd: process.cwd(),
|
|
1407
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
1408
|
+
shell: true
|
|
1409
|
+
});
|
|
1410
|
+
let stdout = "";
|
|
1411
|
+
let stderr = "";
|
|
1412
|
+
let timeoutId = null;
|
|
1413
|
+
if (timeoutId > 0) {
|
|
1414
|
+
timeoutId = setTimeout(() => {
|
|
1415
|
+
child.kill("SIGKILL");
|
|
1416
|
+
reject(new Error(`Command timed out after ${timeout}ms`));
|
|
1417
|
+
}, timeout);
|
|
1418
|
+
}
|
|
1419
|
+
child.stdout?.on("data", (data) => {
|
|
1420
|
+
stdout += data.toString();
|
|
1421
|
+
});
|
|
1422
|
+
child.stderr?.on("data", (data) => {
|
|
1423
|
+
stderr += data.toString();
|
|
1424
|
+
});
|
|
1425
|
+
child.stdout.on("close", (code) => {
|
|
1426
|
+
if (timeoutId) {
|
|
1427
|
+
clearTimeout(timeoutId);
|
|
1428
|
+
}
|
|
1429
|
+
resolve({ stdout, stderr, exitCode: code || 0 });
|
|
1430
|
+
});
|
|
1431
|
+
child.stderr.on("error", (error) => {
|
|
1432
|
+
if (timeoutId) {
|
|
1433
|
+
clearTimeout(timeoutId);
|
|
1434
|
+
}
|
|
1435
|
+
reject(error);
|
|
1436
|
+
});
|
|
1437
|
+
});
|
|
1438
|
+
} catch {
|
|
1439
|
+
console.error("Error while ecexuting the securedShell command");
|
|
1440
|
+
}
|
|
1441
|
+
};
|
|
1442
|
+
var runTerminalCommand = async (input, projectCwd) => {
|
|
1443
|
+
try {
|
|
1444
|
+
if (input?.is_background) {
|
|
1445
|
+
const child = spawn(input.command, {
|
|
1446
|
+
cwd: projectCwd,
|
|
1447
|
+
detached: true,
|
|
1448
|
+
stdio: "ignore",
|
|
1449
|
+
shell: true
|
|
1450
|
+
});
|
|
1451
|
+
child.unref();
|
|
1452
|
+
console.log(`[LOCAL] Background command started: ${input.command}`);
|
|
1453
|
+
return {
|
|
1454
|
+
success: true,
|
|
1455
|
+
message: `Background command started: ${input.command}`,
|
|
1456
|
+
isBackground: true
|
|
1457
|
+
};
|
|
1458
|
+
} else {
|
|
1459
|
+
const result = await runSecureTerminalCommand(
|
|
1460
|
+
input.command,
|
|
1461
|
+
3e4
|
|
1462
|
+
// 30 second timeout
|
|
1463
|
+
);
|
|
1464
|
+
const success = result?.exitCode === 0;
|
|
1465
|
+
return {
|
|
1466
|
+
success,
|
|
1467
|
+
stdout: result?.stdout?.trim(),
|
|
1468
|
+
stderr: result?.stderr?.trim(),
|
|
1469
|
+
exitCode: result?.exitCode,
|
|
1470
|
+
message: success ? `Command executed successfully: ${input.command}` : `Command failed with exit code ${result?.exitCode}: ${input.command}`
|
|
1471
|
+
};
|
|
1472
|
+
}
|
|
1473
|
+
} catch (error) {
|
|
1474
|
+
console.error("Error while executing the terminal command", error);
|
|
1475
|
+
return {
|
|
1476
|
+
success: false,
|
|
1477
|
+
message: "Error while executing the terminal command",
|
|
1478
|
+
error: error.message
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
};
|
|
1395
1482
|
|
|
1396
1483
|
// src/server.ts
|
|
1397
1484
|
var statusEmitter = new EventEmitter();
|
|
@@ -1402,7 +1489,8 @@ var toolExecutors = {
|
|
|
1402
1489
|
glob: globTool,
|
|
1403
1490
|
listDirectory: list,
|
|
1404
1491
|
readFile: read_file,
|
|
1405
|
-
stringReplace: apply_patch
|
|
1492
|
+
stringReplace: apply_patch,
|
|
1493
|
+
runTerminalCommand
|
|
1406
1494
|
};
|
|
1407
1495
|
function getConnectionStatus(ws) {
|
|
1408
1496
|
return ws.readyState === WebSocket.CONNECTING ? "connecting" : ws.readyState === WebSocket.OPEN ? "open" : ws.readyState === WebSocket.CLOSING ? "closing" : "closed";
|
package/dist/server.cjs
CHANGED
|
@@ -1402,6 +1402,93 @@ function getTokens() {
|
|
|
1402
1402
|
const data = JSON.parse(raw);
|
|
1403
1403
|
return data;
|
|
1404
1404
|
}
|
|
1405
|
+
var ExplanationSchema = zod.z.object({
|
|
1406
|
+
explanation: zod.z.string().describe("One sentence explanation as to why this tool is being used")
|
|
1407
|
+
});
|
|
1408
|
+
zod.z.object({
|
|
1409
|
+
command: zod.z.string().describe("The terminal command to execute"),
|
|
1410
|
+
is_background: zod.z.boolean().describe("Whether the command should be run in the background")
|
|
1411
|
+
}).merge(ExplanationSchema);
|
|
1412
|
+
var runSecureTerminalCommand = async (command, timeout) => {
|
|
1413
|
+
try {
|
|
1414
|
+
return new Promise((resolve, reject) => {
|
|
1415
|
+
const child = child_process.spawn(command, {
|
|
1416
|
+
cwd: process.cwd(),
|
|
1417
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
1418
|
+
shell: true
|
|
1419
|
+
});
|
|
1420
|
+
let stdout = "";
|
|
1421
|
+
let stderr = "";
|
|
1422
|
+
let timeoutId = null;
|
|
1423
|
+
if (timeoutId > 0) {
|
|
1424
|
+
timeoutId = setTimeout(() => {
|
|
1425
|
+
child.kill("SIGKILL");
|
|
1426
|
+
reject(new Error(`Command timed out after ${timeout}ms`));
|
|
1427
|
+
}, timeout);
|
|
1428
|
+
}
|
|
1429
|
+
child.stdout?.on("data", (data) => {
|
|
1430
|
+
stdout += data.toString();
|
|
1431
|
+
});
|
|
1432
|
+
child.stderr?.on("data", (data) => {
|
|
1433
|
+
stderr += data.toString();
|
|
1434
|
+
});
|
|
1435
|
+
child.stdout.on("close", (code) => {
|
|
1436
|
+
if (timeoutId) {
|
|
1437
|
+
clearTimeout(timeoutId);
|
|
1438
|
+
}
|
|
1439
|
+
resolve({ stdout, stderr, exitCode: code || 0 });
|
|
1440
|
+
});
|
|
1441
|
+
child.stderr.on("error", (error) => {
|
|
1442
|
+
if (timeoutId) {
|
|
1443
|
+
clearTimeout(timeoutId);
|
|
1444
|
+
}
|
|
1445
|
+
reject(error);
|
|
1446
|
+
});
|
|
1447
|
+
});
|
|
1448
|
+
} catch {
|
|
1449
|
+
console.error("Error while ecexuting the securedShell command");
|
|
1450
|
+
}
|
|
1451
|
+
};
|
|
1452
|
+
var runTerminalCommand = async (input, projectCwd) => {
|
|
1453
|
+
try {
|
|
1454
|
+
if (input?.is_background) {
|
|
1455
|
+
const child = child_process.spawn(input.command, {
|
|
1456
|
+
cwd: projectCwd,
|
|
1457
|
+
detached: true,
|
|
1458
|
+
stdio: "ignore",
|
|
1459
|
+
shell: true
|
|
1460
|
+
});
|
|
1461
|
+
child.unref();
|
|
1462
|
+
console.log(`[LOCAL] Background command started: ${input.command}`);
|
|
1463
|
+
return {
|
|
1464
|
+
success: true,
|
|
1465
|
+
message: `Background command started: ${input.command}`,
|
|
1466
|
+
isBackground: true
|
|
1467
|
+
};
|
|
1468
|
+
} else {
|
|
1469
|
+
const result = await runSecureTerminalCommand(
|
|
1470
|
+
input.command,
|
|
1471
|
+
3e4
|
|
1472
|
+
// 30 second timeout
|
|
1473
|
+
);
|
|
1474
|
+
const success = result?.exitCode === 0;
|
|
1475
|
+
return {
|
|
1476
|
+
success,
|
|
1477
|
+
stdout: result?.stdout?.trim(),
|
|
1478
|
+
stderr: result?.stderr?.trim(),
|
|
1479
|
+
exitCode: result?.exitCode,
|
|
1480
|
+
message: success ? `Command executed successfully: ${input.command}` : `Command failed with exit code ${result?.exitCode}: ${input.command}`
|
|
1481
|
+
};
|
|
1482
|
+
}
|
|
1483
|
+
} catch (error) {
|
|
1484
|
+
console.error("Error while executing the terminal command", error);
|
|
1485
|
+
return {
|
|
1486
|
+
success: false,
|
|
1487
|
+
message: "Error while executing the terminal command",
|
|
1488
|
+
error: error.message
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1491
|
+
};
|
|
1405
1492
|
|
|
1406
1493
|
// src/server.ts
|
|
1407
1494
|
var statusEmitter = new events.EventEmitter();
|
|
@@ -1412,7 +1499,8 @@ var toolExecutors = {
|
|
|
1412
1499
|
glob: globTool,
|
|
1413
1500
|
listDirectory: list,
|
|
1414
1501
|
readFile: read_file,
|
|
1415
|
-
stringReplace: apply_patch
|
|
1502
|
+
stringReplace: apply_patch,
|
|
1503
|
+
runTerminalCommand
|
|
1416
1504
|
};
|
|
1417
1505
|
function getConnectionStatus(ws) {
|
|
1418
1506
|
return ws.readyState === WebSocket__default.default.CONNECTING ? "connecting" : ws.readyState === WebSocket__default.default.OPEN ? "open" : ws.readyState === WebSocket__default.default.CLOSING ? "closing" : "closed";
|
package/dist/server.js
CHANGED
|
@@ -6,7 +6,7 @@ import { readFile, writeFile, stat, access, readdir, glob, unlink, mkdir } from
|
|
|
6
6
|
import path9 from 'path';
|
|
7
7
|
import fs3, { readdirSync } from 'fs';
|
|
8
8
|
import os2 from 'os';
|
|
9
|
-
import { exec } from 'child_process';
|
|
9
|
+
import { exec, spawn } from 'child_process';
|
|
10
10
|
import { promisify } from 'util';
|
|
11
11
|
import pc2 from 'picocolors';
|
|
12
12
|
import { Hono } from 'hono';
|
|
@@ -1392,6 +1392,93 @@ function getTokens() {
|
|
|
1392
1392
|
const data = JSON.parse(raw);
|
|
1393
1393
|
return data;
|
|
1394
1394
|
}
|
|
1395
|
+
var ExplanationSchema = z.object({
|
|
1396
|
+
explanation: z.string().describe("One sentence explanation as to why this tool is being used")
|
|
1397
|
+
});
|
|
1398
|
+
z.object({
|
|
1399
|
+
command: z.string().describe("The terminal command to execute"),
|
|
1400
|
+
is_background: z.boolean().describe("Whether the command should be run in the background")
|
|
1401
|
+
}).merge(ExplanationSchema);
|
|
1402
|
+
var runSecureTerminalCommand = async (command, timeout) => {
|
|
1403
|
+
try {
|
|
1404
|
+
return new Promise((resolve, reject) => {
|
|
1405
|
+
const child = spawn(command, {
|
|
1406
|
+
cwd: process.cwd(),
|
|
1407
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
1408
|
+
shell: true
|
|
1409
|
+
});
|
|
1410
|
+
let stdout = "";
|
|
1411
|
+
let stderr = "";
|
|
1412
|
+
let timeoutId = null;
|
|
1413
|
+
if (timeoutId > 0) {
|
|
1414
|
+
timeoutId = setTimeout(() => {
|
|
1415
|
+
child.kill("SIGKILL");
|
|
1416
|
+
reject(new Error(`Command timed out after ${timeout}ms`));
|
|
1417
|
+
}, timeout);
|
|
1418
|
+
}
|
|
1419
|
+
child.stdout?.on("data", (data) => {
|
|
1420
|
+
stdout += data.toString();
|
|
1421
|
+
});
|
|
1422
|
+
child.stderr?.on("data", (data) => {
|
|
1423
|
+
stderr += data.toString();
|
|
1424
|
+
});
|
|
1425
|
+
child.stdout.on("close", (code) => {
|
|
1426
|
+
if (timeoutId) {
|
|
1427
|
+
clearTimeout(timeoutId);
|
|
1428
|
+
}
|
|
1429
|
+
resolve({ stdout, stderr, exitCode: code || 0 });
|
|
1430
|
+
});
|
|
1431
|
+
child.stderr.on("error", (error) => {
|
|
1432
|
+
if (timeoutId) {
|
|
1433
|
+
clearTimeout(timeoutId);
|
|
1434
|
+
}
|
|
1435
|
+
reject(error);
|
|
1436
|
+
});
|
|
1437
|
+
});
|
|
1438
|
+
} catch {
|
|
1439
|
+
console.error("Error while ecexuting the securedShell command");
|
|
1440
|
+
}
|
|
1441
|
+
};
|
|
1442
|
+
var runTerminalCommand = async (input, projectCwd) => {
|
|
1443
|
+
try {
|
|
1444
|
+
if (input?.is_background) {
|
|
1445
|
+
const child = spawn(input.command, {
|
|
1446
|
+
cwd: projectCwd,
|
|
1447
|
+
detached: true,
|
|
1448
|
+
stdio: "ignore",
|
|
1449
|
+
shell: true
|
|
1450
|
+
});
|
|
1451
|
+
child.unref();
|
|
1452
|
+
console.log(`[LOCAL] Background command started: ${input.command}`);
|
|
1453
|
+
return {
|
|
1454
|
+
success: true,
|
|
1455
|
+
message: `Background command started: ${input.command}`,
|
|
1456
|
+
isBackground: true
|
|
1457
|
+
};
|
|
1458
|
+
} else {
|
|
1459
|
+
const result = await runSecureTerminalCommand(
|
|
1460
|
+
input.command,
|
|
1461
|
+
3e4
|
|
1462
|
+
// 30 second timeout
|
|
1463
|
+
);
|
|
1464
|
+
const success = result?.exitCode === 0;
|
|
1465
|
+
return {
|
|
1466
|
+
success,
|
|
1467
|
+
stdout: result?.stdout?.trim(),
|
|
1468
|
+
stderr: result?.stderr?.trim(),
|
|
1469
|
+
exitCode: result?.exitCode,
|
|
1470
|
+
message: success ? `Command executed successfully: ${input.command}` : `Command failed with exit code ${result?.exitCode}: ${input.command}`
|
|
1471
|
+
};
|
|
1472
|
+
}
|
|
1473
|
+
} catch (error) {
|
|
1474
|
+
console.error("Error while executing the terminal command", error);
|
|
1475
|
+
return {
|
|
1476
|
+
success: false,
|
|
1477
|
+
message: "Error while executing the terminal command",
|
|
1478
|
+
error: error.message
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
};
|
|
1395
1482
|
|
|
1396
1483
|
// src/server.ts
|
|
1397
1484
|
var statusEmitter = new EventEmitter();
|
|
@@ -1402,7 +1489,8 @@ var toolExecutors = {
|
|
|
1402
1489
|
glob: globTool,
|
|
1403
1490
|
listDirectory: list,
|
|
1404
1491
|
readFile: read_file,
|
|
1405
|
-
stringReplace: apply_patch
|
|
1492
|
+
stringReplace: apply_patch,
|
|
1493
|
+
runTerminalCommand
|
|
1406
1494
|
};
|
|
1407
1495
|
function getConnectionStatus(ws) {
|
|
1408
1496
|
return ws.readyState === WebSocket.CONNECTING ? "connecting" : ws.readyState === WebSocket.OPEN ? "open" : ws.readyState === WebSocket.CLOSING ? "closing" : "closed";
|