novaprime 1.3.2 → 1.3.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/package.json +1 -1
- package/src/agent.js +9 -3
- package/src/tools.js +16 -9
package/package.json
CHANGED
package/src/agent.js
CHANGED
|
@@ -15,6 +15,8 @@ const SYSTEM_PROMPT =
|
|
|
15
15
|
`Always understand them and reply in the SAME language and style the user used — if they write Banglish, reply in friendly Banglish. ` +
|
|
16
16
|
`Prefer making concrete changes with tools over only describing them. ` +
|
|
17
17
|
`Use clear markdown: short paragraphs, bullet lists, and fenced code blocks with a language tag. ` +
|
|
18
|
+
`When asked to create or change files, call the tool RIGHT AWAY with at most a one-line intro — ` +
|
|
19
|
+
`do NOT write long explanations or feature lists before creating the file. Keep any summary to 1-2 short lines after. ` +
|
|
18
20
|
`Be concise and warm. Current OS: ${os.platform()}. Working directory: ${process.cwd()}.`;
|
|
19
21
|
|
|
20
22
|
// Fetch read-only account info for the header (name, plan, usage). Never throws.
|
|
@@ -30,6 +32,7 @@ async function streamMessage(server, key, messages) {
|
|
|
30
32
|
const spinner = ora({ text: c.muted('thinking'), spinner: 'dots', color: 'magenta' }).start();
|
|
31
33
|
let spinning = true;
|
|
32
34
|
const stopSpin = () => { if (spinning) { spinner.stop(); spinning = false; } };
|
|
35
|
+
const ensureSpin = (text) => { if (!spinning) { spinner.start(); spinning = true; } spinner.text = text; };
|
|
33
36
|
|
|
34
37
|
let res;
|
|
35
38
|
try {
|
|
@@ -56,7 +59,6 @@ async function streamMessage(server, key, messages) {
|
|
|
56
59
|
while (true) {
|
|
57
60
|
const { done, value } = await reader.read();
|
|
58
61
|
if (done) break;
|
|
59
|
-
stopSpin();
|
|
60
62
|
buffer += decoder.decode(value, { stream: true });
|
|
61
63
|
let idx;
|
|
62
64
|
while ((idx = buffer.indexOf('\n\n')) !== -1) {
|
|
@@ -66,17 +68,21 @@ async function streamMessage(server, key, messages) {
|
|
|
66
68
|
let json; try { json = JSON.parse(dataLine.slice(5).trim()); } catch (_) { continue; }
|
|
67
69
|
|
|
68
70
|
if (json.type === 'content_block_start') {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
const cb = json.content_block || {};
|
|
72
|
+
blocks[json.index] = cb.type === 'tool_use'
|
|
73
|
+
? { type: 'tool_use', id: cb.id, name: cb.name, _json: '' }
|
|
71
74
|
: { type: 'text', text: '' };
|
|
75
|
+
if (cb.type === 'tool_use') ensureSpin(c.muted('preparing ' + cb.name + '…'));
|
|
72
76
|
} else if (json.type === 'content_block_delta') {
|
|
73
77
|
const b = blocks[json.index]; if (!b) continue;
|
|
74
78
|
if (json.delta.type === 'text_delta') {
|
|
79
|
+
stopSpin();
|
|
75
80
|
if (!labelShown) { aiLabel(); labelShown = true; }
|
|
76
81
|
b.text += json.delta.text;
|
|
77
82
|
renderer.feed(json.delta.text);
|
|
78
83
|
} else if (json.delta.type === 'input_json_delta') {
|
|
79
84
|
b._json += json.delta.partial_json;
|
|
85
|
+
ensureSpin(c.muted((b.name === 'run_command' ? 'preparing command' : 'writing ' + (b.name || 'file')) + '… ' + b._json.length + ' chars'));
|
|
80
86
|
}
|
|
81
87
|
} else if (json.type === 'message_delta') {
|
|
82
88
|
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());
|