primocode 7.0.1 → 7.0.2
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/primocode.js +5 -2
- package/lib/act.js +56 -24
- package/lib/api.js +3 -2
- package/package.json +1 -1
package/bin/primocode.js
CHANGED
|
@@ -69,11 +69,14 @@ async function sendPrompt(userText) {
|
|
|
69
69
|
|
|
70
70
|
if (state.mode === 'agent') {
|
|
71
71
|
await runAgent(promptWithAttach, userText);
|
|
72
|
-
} else if (state.mode === '
|
|
72
|
+
} else if (state.mode === 'primocode') {
|
|
73
|
+
const projectDir = state.currentProject ? getProjectDir(state.currentProject) : process.cwd();
|
|
73
74
|
const r = await runAct(promptWithAttach, {
|
|
74
75
|
server: state.config.server,
|
|
75
76
|
model: state.config.model,
|
|
76
77
|
history: state.history,
|
|
78
|
+
projectDir: projectDir,
|
|
79
|
+
projectName: state.currentProject,
|
|
77
80
|
});
|
|
78
81
|
state.history.push({ role: 'user', content: userText });
|
|
79
82
|
state.history.push({ role: 'assistant', content: r.assistantMessage.content });
|
|
@@ -354,7 +357,7 @@ async function main() {
|
|
|
354
357
|
catch { console.log(c.err(`Não consegui ler: ${args[fileFlag+1]}`)); process.exit(1); }
|
|
355
358
|
}
|
|
356
359
|
if (isAgent) await runAgent(promptText, prompt);
|
|
357
|
-
else { const r = await runAct(promptText, {server:state.config.server, model:state.config.model, history:[]}); console.log('\n'+c.white(r.assistantMessage.content)); }
|
|
360
|
+
else { const r = await runAct(promptText, {server:state.config.server, model:state.config.model, history:[], projectDir: process.cwd()}); console.log('\n'+c.white(r.assistantMessage.content)); }
|
|
358
361
|
process.exit(0);
|
|
359
362
|
}
|
|
360
363
|
console.log(welcomeBox(VERSION, state.config.server));
|
package/lib/act.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Loop do agente autônomo —
|
|
1
|
+
// Loop do agente autônomo — streaming via /api/act/stream
|
|
2
2
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -37,36 +37,68 @@ async function runAct(userPrompt, opts) {
|
|
|
37
37
|
];
|
|
38
38
|
const toolResults = [];
|
|
39
39
|
let iteration = 0;
|
|
40
|
+
let plan = '';
|
|
41
|
+
let assistantContent = '';
|
|
40
42
|
|
|
41
43
|
while (iteration < MAX_ITERATIONS) {
|
|
42
44
|
iteration++;
|
|
43
|
-
const sp = new Spinner('pensando').start();
|
|
44
|
-
let response;
|
|
45
|
-
try { response = await api.requestAct(server, messages, model); }
|
|
46
|
-
catch (e) { sp.stop(); console.log(c.err(`\nErro no servidor: ${e.message||e}`)); throw e; }
|
|
47
|
-
sp.stop();
|
|
45
|
+
const sp = new Spinner('Primo Code pensando').start();
|
|
48
46
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
try {
|
|
48
|
+
await api.requestAct(server, messages, model, { projectDir, projectName, plan_cache: plan }, (evt) => {
|
|
49
|
+
if (evt.plan) {
|
|
50
|
+
plan = evt.plan;
|
|
51
|
+
}
|
|
52
|
+
if (evt.tool_call) {
|
|
53
|
+
sp.stop();
|
|
54
|
+
const tc = evt.tool_call;
|
|
55
|
+
console.log(actionHeader(tc.name, tc.arguments));
|
|
56
|
+
logger.event(tc.name, tc.arguments);
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
// Executar tool localmente
|
|
59
|
+
tools.execute(tc.name, tc.arguments).then(result => {
|
|
60
|
+
logger.event(tc.name + '_done', null, result);
|
|
61
|
+
toolResults.push({ tool_call_id: tc.id || 'tc_' + iteration, result });
|
|
62
|
+
});
|
|
63
|
+
sp.start();
|
|
64
|
+
}
|
|
65
|
+
if (evt.assistant_message) {
|
|
66
|
+
assistantContent = evt.assistant_message.content || '';
|
|
67
|
+
}
|
|
68
|
+
if (evt.delta) {
|
|
69
|
+
sp.stop();
|
|
70
|
+
process.stdout.write(evt.delta);
|
|
71
|
+
sp.start();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
sp.stop();
|
|
75
|
+
|
|
76
|
+
// Se não teve tool_calls, mostrar conteúdo
|
|
77
|
+
if (toolResults.length === 0 && assistantContent) {
|
|
78
|
+
console.log('\n' + c.white(assistantContent));
|
|
79
|
+
return { userMessage: { role: 'user', content: userPrompt }, assistantMessage: { role: 'assistant', content: assistantContent } };
|
|
80
|
+
}
|
|
64
81
|
|
|
65
|
-
|
|
66
|
-
|
|
82
|
+
// Se teve tool_results, enviar de volta para próximo turno
|
|
83
|
+
if (toolResults.length > 0) {
|
|
84
|
+
messages.push({ role: 'assistant', content: assistantContent, tool_calls: [] });
|
|
85
|
+
for (const tr of toolResults) {
|
|
86
|
+
messages.push({ role: 'tool', tool_call_id: tr.tool_call_id, content: JSON.stringify(tr.result) });
|
|
87
|
+
}
|
|
88
|
+
toolResults.length = 0;
|
|
89
|
+
assistantContent = '';
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
break;
|
|
94
|
+
} catch (e) {
|
|
95
|
+
sp.stop();
|
|
96
|
+
console.log(c.err(`\nErro: ${e.message||e}`));
|
|
97
|
+
throw e;
|
|
98
|
+
}
|
|
67
99
|
}
|
|
68
|
-
|
|
69
|
-
return { userMessage: { role: 'user', content: userPrompt }, assistantMessage: { role: 'assistant', content:
|
|
100
|
+
|
|
101
|
+
return { userMessage: { role: 'user', content: userPrompt }, assistantMessage: { role: 'assistant', content: assistantContent || 'Concluído.' } };
|
|
70
102
|
}
|
|
71
103
|
|
|
72
104
|
module.exports = { runAct };
|
package/lib/api.js
CHANGED
|
@@ -30,8 +30,9 @@ function requestStream(serverUrl, endpoint, payload, onEvent) {
|
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function requestAct(serverUrl, messages, model, extras) {
|
|
34
|
-
|
|
33
|
+
function requestAct(serverUrl, messages, model, extras, onEvent) {
|
|
34
|
+
// Usa streaming para /api/act/stream
|
|
35
|
+
return requestStream(serverUrl, '/api/act/stream', { messages, model, ...(extras || {}) }, onEvent);
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
function getHealth(serverUrl) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "primocode",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.2",
|
|
4
4
|
"description": "PrimoCode \u2014 agente de engenharia com IA e cursor pr\u00f3prio. Modo primocode cria arquivos, controla o desktop e navegador. Modo chat \u00e9 conversa pura.",
|
|
5
5
|
"main": "bin/primocode.js",
|
|
6
6
|
"bin": "./bin/primocode.js",
|