novaprime 1.3.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "novaprime",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "NovaPrime — an AI coding assistant in your terminal, powered by GLM.",
5
5
  "bin": {
6
6
  "novaprime": "bin/novaprime.js"
package/src/agent.js CHANGED
@@ -2,7 +2,7 @@
2
2
  const os = require('os');
3
3
  const ora = require('ora');
4
4
  const tools = require('./tools');
5
- const { c, aiLabel, error } = require('./ui');
5
+ const { c, aiLabel, error, warn } = require('./ui');
6
6
  const { Renderer } = require('./render');
7
7
 
8
8
  const SYSTEM_PROMPT =
@@ -36,7 +36,7 @@ async function streamMessage(server, key, messages) {
36
36
  res = await fetch(server.replace(/\/$/, '') + '/v1/messages', {
37
37
  method: 'POST',
38
38
  headers: { 'content-type': 'application/json', 'x-novaprime-key': key },
39
- body: JSON.stringify({ max_tokens: 8192, system: SYSTEM_PROMPT, tools: tools.definitions, messages, stream: true }),
39
+ body: JSON.stringify({ max_tokens: 16000, system: SYSTEM_PROMPT, tools: tools.definitions, messages, stream: true }),
40
40
  });
41
41
  } catch (err) { stopSpin(); return { error: 'Could not reach NovaPrime: ' + err.message }; }
42
42
 
@@ -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
- blocks[json.index] = json.content_block.type === 'tool_use'
70
- ? { type: 'tool_use', id: json.content_block.id, name: json.content_block.name, _json: '' }
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;
@@ -93,7 +96,7 @@ async function streamMessage(server, key, messages) {
93
96
  }
94
97
  return { type: 'text', text: b.text };
95
98
  });
96
- return { content, stopReason };
99
+ return { content, stopReason, printed: labelShown };
97
100
  }
98
101
 
99
102
  async function runTurn(server, key, messages) {
@@ -112,6 +115,12 @@ async function runTurn(server, key, messages) {
112
115
  messages.push({ role: 'user', content: toolResults });
113
116
  continue;
114
117
  }
118
+ // never finish silently
119
+ if (result.stopReason === 'max_tokens') {
120
+ warn('The response was too long and got cut off. Try a smaller or more specific request (e.g. one file at a time).');
121
+ } else if (!result.printed && !toolUses.length) {
122
+ warn('No response received. Please try again in a moment.');
123
+ }
115
124
  return;
116
125
  }
117
126
  }
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(c.warn('\n ✎ write file: ') + c.bold(input.path) +
88
- c.muted(` (${(input.content || '').length} chars)`));
89
- if (!(await confirm('Allow writing this file?'))) return 'DENIED: user did not allow writing the file.';
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(c.warn('\n ✎ edit file: ') + c.bold(input.path));
100
- console.log(c.danger(' - ' + input.old_string.split('\n').join('\n - ')));
101
- console.log(c.accent(' + ' + input.new_string.split('\n').join('\n + ')));
102
- if (!(await confirm('Allow this edit?'))) return 'DENIED: user did not allow the edit.';
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(c.warn('\n $ ') + c.bold(input.command));
108
- if (!(await confirm('Run this command?'))) return 'DENIED: user did not allow running the command.';
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());