sam-coder-cli 2.0.7 → 2.0.8
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 +15 -13
- package/package.json +1 -1
package/bin/agi-cli.js
CHANGED
|
@@ -157,17 +157,17 @@ const tools = [
|
|
|
157
157
|
properties: {
|
|
158
158
|
type: { const: 'insert' },
|
|
159
159
|
position: { type: 'string', enum: ['start', 'end'] },
|
|
160
|
-
|
|
160
|
+
newText: { type: 'string' }
|
|
161
161
|
},
|
|
162
|
-
required: ['position', '
|
|
162
|
+
required: ['position', 'newText']
|
|
163
163
|
},
|
|
164
164
|
{
|
|
165
165
|
properties: {
|
|
166
166
|
type: { const: 'insert' },
|
|
167
167
|
line: { type: 'number' },
|
|
168
|
-
|
|
168
|
+
newText: { type: 'string' }
|
|
169
169
|
},
|
|
170
|
-
required: ['line', '
|
|
170
|
+
required: ['line', 'newText']
|
|
171
171
|
},
|
|
172
172
|
{
|
|
173
173
|
properties: {
|
|
@@ -495,12 +495,13 @@ const agentUtils = {
|
|
|
495
495
|
if (op.startLine < 1 || op.endLine > lines.length) {
|
|
496
496
|
throw new Error(`Line numbers out of range (1-${lines.length})`);
|
|
497
497
|
}
|
|
498
|
-
|
|
498
|
+
const newText = op.newText ?? op.text;
|
|
499
|
+
if (typeof newText !== 'string') {
|
|
499
500
|
throw new Error(`'newText' must be a string for replace operation`);
|
|
500
501
|
}
|
|
501
502
|
const before = lines.slice(0, op.startLine - 1);
|
|
502
503
|
const after = lines.slice(op.endLine);
|
|
503
|
-
const newLines =
|
|
504
|
+
const newLines = newText.split('\n');
|
|
504
505
|
lines = [...before, ...newLines, ...after];
|
|
505
506
|
} else if (op.pattern) {
|
|
506
507
|
// Pattern-based replacement
|
|
@@ -517,7 +518,7 @@ const agentUtils = {
|
|
|
517
518
|
break;
|
|
518
519
|
|
|
519
520
|
case 'replace_block':
|
|
520
|
-
if (typeof op.oldText !== 'string' || typeof op.replacementContent !== 'string') {
|
|
521
|
+
if (typeof op.oldText !== 'string' || typeof (op.replacementContent ?? op.newText) !== 'string') {
|
|
521
522
|
throw new Error('replace_block requires both oldText and replacementContent as strings');
|
|
522
523
|
}
|
|
523
524
|
content = lines.join('\n');
|
|
@@ -529,23 +530,24 @@ const agentUtils = {
|
|
|
529
530
|
if (occurrences > 1) {
|
|
530
531
|
throw new Error(`Found ${occurrences} occurrences of oldText. Please be more specific to ensure a unique match.`);
|
|
531
532
|
}
|
|
532
|
-
content = content.replace(op.oldText, op.replacementContent);
|
|
533
|
+
content = content.replace(op.oldText, op.replacementContent ?? op.newText);
|
|
533
534
|
lines = content.split('\n');
|
|
534
535
|
break;
|
|
535
536
|
|
|
536
537
|
case 'insert':
|
|
537
|
-
|
|
538
|
-
|
|
538
|
+
const insertText = op.newText ?? op.text;
|
|
539
|
+
if (typeof insertText !== 'string') {
|
|
540
|
+
throw new Error(`'newText' must be a string for insert operation`);
|
|
539
541
|
}
|
|
540
542
|
if (op.position === 'start') {
|
|
541
|
-
lines.unshift(...
|
|
543
|
+
lines.unshift(...insertText.split('\n'));
|
|
542
544
|
} else if (op.position === 'end') {
|
|
543
|
-
lines.push(...
|
|
545
|
+
lines.push(...insertText.split('\n'));
|
|
544
546
|
} else if (op.line !== undefined) {
|
|
545
547
|
if (op.line < 1 || op.line > lines.length + 1) {
|
|
546
548
|
throw new Error(`Line number out of range (1-${lines.length + 1})`);
|
|
547
549
|
}
|
|
548
|
-
const insertLines =
|
|
550
|
+
const insertLines = insertText.split('\n');
|
|
549
551
|
lines.splice(op.line - 1, 0, ...insertLines);
|
|
550
552
|
} else {
|
|
551
553
|
throw new Error('Insert operation requires either position (start/end) or line number');
|