@deinossrl/dgp-agent 1.4.9 → 1.4.11
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/index.mjs +39 -24
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -203,7 +203,7 @@ async function fetchPlatformConfig() {
|
|
|
203
203
|
let platformConfig = null;
|
|
204
204
|
|
|
205
205
|
// Versión y modo del agente
|
|
206
|
-
const AGENT_VERSION = '1.4.
|
|
206
|
+
const AGENT_VERSION = '1.4.11';
|
|
207
207
|
let AGENT_MODE = 'status'; // 'status' | 'deploy' | 'ai'
|
|
208
208
|
|
|
209
209
|
// Configuración (prioridad: env vars > archivo config > platform config > defaults)
|
|
@@ -559,8 +559,8 @@ async function runAIMode() {
|
|
|
559
559
|
if (isProcessing) return; // Evitar ejecuciones simultáneas
|
|
560
560
|
|
|
561
561
|
try {
|
|
562
|
-
// Buscar comandos pendientes para esta máquina
|
|
563
|
-
const url = `${CONFIG.commandsUrl}?machine_id=eq.${CONFIG.machineId}&status=eq.pending&
|
|
562
|
+
// Buscar TODOS los comandos pendientes para esta máquina (ai_task, git_commit_push, etc)
|
|
563
|
+
const url = `${CONFIG.commandsUrl}?machine_id=eq.${CONFIG.machineId}&status=eq.pending&select=*&order=created_at.asc&limit=1`;
|
|
564
564
|
const response = await fetch(url, {
|
|
565
565
|
headers: {
|
|
566
566
|
'apikey': CONFIG.supabaseKey,
|
|
@@ -576,35 +576,38 @@ async function runAIMode() {
|
|
|
576
576
|
const command = commands[0];
|
|
577
577
|
isProcessing = true;
|
|
578
578
|
|
|
579
|
-
|
|
579
|
+
// Manejar diferentes tipos de comandos
|
|
580
|
+
if (command.command === 'ai_task') {
|
|
581
|
+
logAI(`📥 Tarea AI recibida: ${command.params?.task?.substring(0, 50)}...`);
|
|
582
|
+
await updateCommandStatus(command.id, 'running', {});
|
|
580
583
|
|
|
581
|
-
|
|
582
|
-
await updateCommandStatus(command.id, 'running', {});
|
|
584
|
+
const result = await executeAITask(command.params?.task || '');
|
|
583
585
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
586
|
+
if (result.success) {
|
|
587
|
+
await updateCommandStatus(command.id, 'completed', {
|
|
588
|
+
output: result.results?.map(r => r.output).join('\n'),
|
|
589
|
+
commands_executed: result.results?.length || 0,
|
|
590
|
+
});
|
|
591
|
+
logSuccess('Tarea AI completada');
|
|
592
|
+
} else {
|
|
593
|
+
await updateCommandStatus(command.id, 'failed', {}, result.error || 'Task failed');
|
|
594
|
+
logError('Tarea AI fallida');
|
|
595
|
+
}
|
|
594
596
|
} else {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
+
// Comandos git (git_commit_push, git_pull, git_fetch, etc)
|
|
598
|
+
logInfo(`📥 Comando recibido: ${command.command}`);
|
|
599
|
+
await executeCommand(command);
|
|
597
600
|
}
|
|
598
601
|
|
|
599
602
|
isProcessing = false;
|
|
600
603
|
console.log('');
|
|
601
|
-
logInfo('Esperando más
|
|
604
|
+
logInfo('Esperando más comandos...');
|
|
602
605
|
|
|
603
606
|
} catch (error) {
|
|
604
607
|
isProcessing = false;
|
|
605
|
-
//
|
|
606
|
-
if (!error.message.includes('42P01')) {
|
|
607
|
-
|
|
608
|
+
// Log error para debug
|
|
609
|
+
if (error.message && !error.message.includes('42P01')) {
|
|
610
|
+
console.error(`${colors.red}[Error polling]${colors.reset}`, error.message);
|
|
608
611
|
}
|
|
609
612
|
}
|
|
610
613
|
};
|
|
@@ -1042,9 +1045,20 @@ async function executeGitCommitPush(command) {
|
|
|
1042
1045
|
await shellAsync('git add .');
|
|
1043
1046
|
}
|
|
1044
1047
|
|
|
1045
|
-
// git commit
|
|
1048
|
+
// git commit - escapar mensaje según el SO
|
|
1049
|
+
const isWindows = process.platform === 'win32';
|
|
1050
|
+
let commitCmd;
|
|
1051
|
+
if (isWindows) {
|
|
1052
|
+
// En Windows cmd /c, escapar comillas con \"
|
|
1053
|
+
const safeMessage = message.replace(/"/g, '\\"');
|
|
1054
|
+
commitCmd = `git commit -m "${safeMessage}"`;
|
|
1055
|
+
} else {
|
|
1056
|
+
// En Unix, usar comillas simples es más seguro
|
|
1057
|
+
const safeMessage = message.replace(/'/g, "'\\''");
|
|
1058
|
+
commitCmd = `git commit -m '${safeMessage}'`;
|
|
1059
|
+
}
|
|
1046
1060
|
logCommand(`git commit -m "${message}"`);
|
|
1047
|
-
const commitResult = await shellAsync(
|
|
1061
|
+
const commitResult = await shellAsync(commitCmd);
|
|
1048
1062
|
logSuccess('Commit created');
|
|
1049
1063
|
|
|
1050
1064
|
// git push
|
|
@@ -1269,6 +1283,7 @@ ${colors.bold}REQUISITOS PARA DEPLOY${colors.reset}
|
|
|
1269
1283
|
- Permisos sudo para reload nginx (vía sudoers sin password)
|
|
1270
1284
|
|
|
1271
1285
|
${colors.bold}CHANGELOG${colors.reset}
|
|
1286
|
+
${colors.cyan}v1.4.10${colors.reset} - AI Mode escucha todos los comandos (git + ai_task)
|
|
1272
1287
|
${colors.cyan}v1.4.9${colors.reset} - Fix: AI Mode no reportaba status a la plataforma
|
|
1273
1288
|
${colors.cyan}v1.4.8${colors.reset} - Banner dinámico con padding automático
|
|
1274
1289
|
${colors.cyan}v1.4.7${colors.reset} - Modo AI visible en web, auto-kill agente anterior
|