novaprime 1.3.2 → 1.3.3
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/package.json +1 -1
- package/src/agent.js +6 -3
- package/src/tools.js +16 -9
package/package.json
CHANGED
package/src/agent.js
CHANGED
|
@@ -56,7 +56,6 @@ async function streamMessage(server, key, messages) {
|
|
|
56
56
|
while (true) {
|
|
57
57
|
const { done, value } = await reader.read();
|
|
58
58
|
if (done) break;
|
|
59
|
-
stopSpin();
|
|
60
59
|
buffer += decoder.decode(value, { stream: true });
|
|
61
60
|
let idx;
|
|
62
61
|
while ((idx = buffer.indexOf('\n\n')) !== -1) {
|
|
@@ -66,17 +65,21 @@ async function streamMessage(server, key, messages) {
|
|
|
66
65
|
let json; try { json = JSON.parse(dataLine.slice(5).trim()); } catch (_) { continue; }
|
|
67
66
|
|
|
68
67
|
if (json.type === 'content_block_start') {
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
const cb = json.content_block || {};
|
|
69
|
+
blocks[json.index] = cb.type === 'tool_use'
|
|
70
|
+
? { type: 'tool_use', id: cb.id, name: cb.name, _json: '' }
|
|
71
71
|
: { type: 'text', text: '' };
|
|
72
|
+
if (cb.type === 'tool_use' && spinning) spinner.text = c.muted('preparing ' + cb.name + '…');
|
|
72
73
|
} else if (json.type === 'content_block_delta') {
|
|
73
74
|
const b = blocks[json.index]; if (!b) continue;
|
|
74
75
|
if (json.delta.type === 'text_delta') {
|
|
76
|
+
stopSpin();
|
|
75
77
|
if (!labelShown) { aiLabel(); labelShown = true; }
|
|
76
78
|
b.text += json.delta.text;
|
|
77
79
|
renderer.feed(json.delta.text);
|
|
78
80
|
} else if (json.delta.type === 'input_json_delta') {
|
|
79
81
|
b._json += json.delta.partial_json;
|
|
82
|
+
if (spinning) spinner.text = c.muted((b.name === 'run_command' ? 'preparing command' : 'writing ' + (b.name || 'file')) + '… ' + b._json.length + ' chars');
|
|
80
83
|
}
|
|
81
84
|
} else if (json.type === 'message_delta') {
|
|
82
85
|
if (json.delta && json.delta.stop_reason) stopReason = json.delta.stop_reason;
|
package/src/tools.js
CHANGED
|
@@ -84,11 +84,13 @@ async function execute(name, input) {
|
|
|
84
84
|
return items.join('\n') || '(empty)';
|
|
85
85
|
}
|
|
86
86
|
case 'write_file': {
|
|
87
|
-
console.log(
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
console.log('');
|
|
88
|
+
console.log(c.amber(' ╭─ permission ') + c.dim('─────────────────────────────'));
|
|
89
|
+
console.log(c.amber(' │ ') + c.bold('Write file') + ' ' + c.white(input.path) + c.muted(` (${(input.content || '').length} chars)`));
|
|
90
|
+
if (!(await confirm(c.amber(' ╰─ allow?')))) { console.log(c.dim(' · skipped')); return 'DENIED: user did not allow writing the file.'; }
|
|
90
91
|
fs.mkdirSync(path.dirname(path.resolve(input.path)), { recursive: true });
|
|
91
92
|
fs.writeFileSync(input.path, input.content);
|
|
93
|
+
console.log(c.green(' ✓ wrote ') + c.white(input.path));
|
|
92
94
|
return 'OK: wrote ' + input.path;
|
|
93
95
|
}
|
|
94
96
|
case 'edit_file': {
|
|
@@ -96,16 +98,21 @@ async function execute(name, input) {
|
|
|
96
98
|
const count = before.split(input.old_string).length - 1;
|
|
97
99
|
if (count === 0) return 'ERROR: old_string not found in ' + input.path;
|
|
98
100
|
if (count > 1) return `ERROR: old_string matches ${count} times; make it more specific.`;
|
|
99
|
-
console.log(
|
|
100
|
-
console.log(c.
|
|
101
|
-
console.log(c.
|
|
102
|
-
|
|
101
|
+
console.log('');
|
|
102
|
+
console.log(c.amber(' ╭─ permission ') + c.dim('─────────────────────────────'));
|
|
103
|
+
console.log(c.amber(' │ ') + c.bold('Edit file') + ' ' + c.white(input.path));
|
|
104
|
+
console.log(c.red(' │ - ' + input.old_string.split('\n').join('\n │ - ')));
|
|
105
|
+
console.log(c.green(' │ + ' + input.new_string.split('\n').join('\n │ + ')));
|
|
106
|
+
if (!(await confirm(c.amber(' ╰─ allow?')))) { console.log(c.dim(' · skipped')); return 'DENIED: user did not allow the edit.'; }
|
|
103
107
|
fs.writeFileSync(input.path, before.replace(input.old_string, input.new_string));
|
|
108
|
+
console.log(c.green(' ✓ edited ') + c.white(input.path));
|
|
104
109
|
return 'OK: edited ' + input.path;
|
|
105
110
|
}
|
|
106
111
|
case 'run_command': {
|
|
107
|
-
console.log(
|
|
108
|
-
|
|
112
|
+
console.log('');
|
|
113
|
+
console.log(c.red(' ╭─ permission · run command ') + c.dim('───────────────────'));
|
|
114
|
+
console.log(c.red(' │ ') + c.bold(input.command));
|
|
115
|
+
if (!(await confirm(c.red(' ╰─ run this command?')))) { console.log(c.dim(' · skipped')); return 'DENIED: user did not allow running the command.'; }
|
|
109
116
|
const r = spawnSync(input.command, { shell: true, encoding: 'utf8', timeout: 1000 * 120 });
|
|
110
117
|
const out = (r.stdout || '') + (r.stderr || '');
|
|
111
118
|
return clip(`exit_code=${r.status}\n${out}`.trim());
|