sam-coder-cli 2.0.8 → 2.0.9
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/bin/agi-cli.js +46 -0
- package/bin/ui.js +12 -5
- package/package.json +1 -1
package/bin/agi-cli.js
CHANGED
|
@@ -188,6 +188,23 @@ const tools = [
|
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
},
|
|
191
|
+
{
|
|
192
|
+
type: 'function',
|
|
193
|
+
function: {
|
|
194
|
+
name: 'replace_lines',
|
|
195
|
+
description: 'Replace a range of lines in a file with new content',
|
|
196
|
+
parameters: {
|
|
197
|
+
type: 'object',
|
|
198
|
+
properties: {
|
|
199
|
+
path: { type: 'string', description: 'Path to the file to edit' },
|
|
200
|
+
startLine: { type: 'number', description: 'Starting line number (1-based)' },
|
|
201
|
+
endLine: { type: 'number', description: 'Ending line number (1-based, inclusive)' },
|
|
202
|
+
newContent: { type: 'string', description: 'The new content to replace the lines with' }
|
|
203
|
+
},
|
|
204
|
+
required: ['path', 'startLine', 'endLine', 'newContent']
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
},
|
|
191
208
|
{
|
|
192
209
|
type: 'function',
|
|
193
210
|
function: {
|
|
@@ -582,6 +599,33 @@ const agentUtils = {
|
|
|
582
599
|
}
|
|
583
600
|
},
|
|
584
601
|
|
|
602
|
+
async replace_lines(input) {
|
|
603
|
+
try {
|
|
604
|
+
const { path: filePath, startLine, endLine, newContent } = input;
|
|
605
|
+
if (!filePath) throw new Error('replace_lines: missing path');
|
|
606
|
+
if (startLine === undefined || endLine === undefined) throw new Error('replace_lines: missing line range');
|
|
607
|
+
if (typeof newContent !== 'string') throw new Error('replace_lines: missing newContent');
|
|
608
|
+
|
|
609
|
+
let content = await fs.readFile(filePath, 'utf-8');
|
|
610
|
+
const lines = content.split('\n');
|
|
611
|
+
|
|
612
|
+
if (startLine < 1 || endLine > lines.length || startLine > endLine) {
|
|
613
|
+
throw new Error(`Line numbers out of range (1-${lines.length}) or invalid range`);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
const before = lines.slice(0, startLine - 1);
|
|
617
|
+
const after = lines.slice(endLine);
|
|
618
|
+
const newLines = newContent.split('\n');
|
|
619
|
+
|
|
620
|
+
const updatedLines = [...before, ...newLines, ...after];
|
|
621
|
+
await fs.writeFile(filePath, updatedLines.join('\n'), 'utf-8');
|
|
622
|
+
|
|
623
|
+
return `Successfully replaced lines ${startLine}-${endLine} in ${filePath}`;
|
|
624
|
+
} catch (error) {
|
|
625
|
+
throw new Error(`replace_lines failed: ${error.message}`);
|
|
626
|
+
}
|
|
627
|
+
},
|
|
628
|
+
|
|
585
629
|
async runCommand(input) {
|
|
586
630
|
try {
|
|
587
631
|
const isObj = typeof input === 'object' && input !== null;
|
|
@@ -1303,6 +1347,8 @@ async function executeAction(action) {
|
|
|
1303
1347
|
return await agentUtils.writeFile(data.path, data.content);
|
|
1304
1348
|
case 'edit':
|
|
1305
1349
|
return await agentUtils.editFile(data.path, data.edits);
|
|
1350
|
+
case 'replace_lines':
|
|
1351
|
+
return await agentUtils.replace_lines(data);
|
|
1306
1352
|
case 'command':
|
|
1307
1353
|
return await agentUtils.runCommand(data.command);
|
|
1308
1354
|
case 'search':
|
package/bin/ui.js
CHANGED
|
@@ -10,17 +10,24 @@ const spinner = ora({
|
|
|
10
10
|
discardStdin: false // Critical: prevents stdin interference
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
// ASCII Art for AGI header
|
|
13
|
+
// ASCII Art for AGI header - Shoggoth mascot
|
|
14
|
+
const SHOGGOTH = `
|
|
15
|
+
▄▄▄▄▄▄▄
|
|
16
|
+
█ ● ● █
|
|
17
|
+
█░░░░░░░█
|
|
18
|
+
▀▀▀▀▀▀▀
|
|
19
|
+
║ ║ ║
|
|
20
|
+
`;
|
|
21
|
+
|
|
14
22
|
const AGI_HEADER = `
|
|
15
23
|
╔═══════════════════════════════════════╗
|
|
16
|
-
║ A
|
|
17
|
-
║ Artificial General Intelligence ║
|
|
18
|
-
║ Command Line Interface ║
|
|
24
|
+
║ S A M - C O D E R ║
|
|
19
25
|
╚═══════════════════════════════════════╝
|
|
20
26
|
`;
|
|
21
27
|
|
|
22
28
|
function showHeader() {
|
|
23
|
-
console.log(chalk.
|
|
29
|
+
console.log(chalk.redBright(SHOGGOTH));
|
|
30
|
+
console.log(chalk.red.bold(AGI_HEADER));
|
|
24
31
|
console.log(chalk.gray('─'.repeat(41)));
|
|
25
32
|
console.log();
|
|
26
33
|
}
|