@deinossrl/dgp-agent 1.4.6 → 1.4.7
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 +95 -6
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -34,6 +34,79 @@ import { join, dirname } from 'path';
|
|
|
34
34
|
|
|
35
35
|
const CONFIG_DIR = join(homedir(), '.dgp-agent');
|
|
36
36
|
const CONFIG_FILE = join(CONFIG_DIR, 'config.json');
|
|
37
|
+
const PID_FILE = join(CONFIG_DIR, 'agent.pid');
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Mata al agente anterior si existe
|
|
41
|
+
*/
|
|
42
|
+
function killPreviousAgent() {
|
|
43
|
+
try {
|
|
44
|
+
if (existsSync(PID_FILE)) {
|
|
45
|
+
const oldPid = parseInt(readFileSync(PID_FILE, 'utf-8').trim(), 10);
|
|
46
|
+
if (oldPid && oldPid !== process.pid) {
|
|
47
|
+
try {
|
|
48
|
+
// Verificar si el proceso existe
|
|
49
|
+
process.kill(oldPid, 0);
|
|
50
|
+
// Si llegamos aquí, el proceso existe - matarlo
|
|
51
|
+
console.log(`\x1b[33m[!] Matando agente anterior (PID: ${oldPid})...\x1b[0m`);
|
|
52
|
+
process.kill(oldPid, 'SIGTERM');
|
|
53
|
+
// Esperar un poco para que muera
|
|
54
|
+
const start = Date.now();
|
|
55
|
+
while (Date.now() - start < 2000) {
|
|
56
|
+
try {
|
|
57
|
+
process.kill(oldPid, 0);
|
|
58
|
+
// Sigue vivo, esperar
|
|
59
|
+
} catch {
|
|
60
|
+
// Ya murió
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
} catch (e) {
|
|
65
|
+
// El proceso no existe, ignorar
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} catch (e) {
|
|
70
|
+
// Ignorar errores
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Guarda el PID actual
|
|
76
|
+
*/
|
|
77
|
+
function savePid() {
|
|
78
|
+
try {
|
|
79
|
+
if (!existsSync(CONFIG_DIR)) {
|
|
80
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
81
|
+
}
|
|
82
|
+
writeFileSync(PID_FILE, String(process.pid), 'utf-8');
|
|
83
|
+
} catch (e) {
|
|
84
|
+
// Ignorar errores
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Limpia el archivo PID al salir
|
|
90
|
+
*/
|
|
91
|
+
function cleanupPid() {
|
|
92
|
+
try {
|
|
93
|
+
if (existsSync(PID_FILE)) {
|
|
94
|
+
const savedPid = parseInt(readFileSync(PID_FILE, 'utf-8').trim(), 10);
|
|
95
|
+
if (savedPid === process.pid) {
|
|
96
|
+
// Solo borrar si es nuestro PID
|
|
97
|
+
const { unlinkSync } = require('fs');
|
|
98
|
+
unlinkSync(PID_FILE);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} catch (e) {
|
|
102
|
+
// Ignorar errores
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Limpiar PID al salir
|
|
107
|
+
process.on('exit', cleanupPid);
|
|
108
|
+
process.on('SIGINT', () => { cleanupPid(); process.exit(0); });
|
|
109
|
+
process.on('SIGTERM', () => { cleanupPid(); process.exit(0); });
|
|
37
110
|
|
|
38
111
|
/**
|
|
39
112
|
* Lee la configuración del archivo
|
|
@@ -129,6 +202,10 @@ async function fetchPlatformConfig() {
|
|
|
129
202
|
// Variable para config de la plataforma (se carga async)
|
|
130
203
|
let platformConfig = null;
|
|
131
204
|
|
|
205
|
+
// Versión y modo del agente
|
|
206
|
+
const AGENT_VERSION = '1.4.7';
|
|
207
|
+
let AGENT_MODE = 'status'; // 'status' | 'deploy' | 'ai'
|
|
208
|
+
|
|
132
209
|
// Configuración (prioridad: env vars > archivo config > platform config > defaults)
|
|
133
210
|
const CONFIG = {
|
|
134
211
|
apiUrl: process.env.DGP_API_URL || fileConfig.apiUrl || 'https://asivayhbrqennwiwttds.supabase.co/functions/v1/dgp-agent-status',
|
|
@@ -393,9 +470,14 @@ Devuelve los comandos necesarios en formato JSON.`;
|
|
|
393
470
|
* Modo IA - Escucha tareas de la web y las ejecuta con Claude
|
|
394
471
|
*/
|
|
395
472
|
async function runAIMode() {
|
|
473
|
+
// Matar agente anterior y guardar PID
|
|
474
|
+
killPreviousAgent();
|
|
475
|
+
savePid();
|
|
476
|
+
AGENT_MODE = 'ai';
|
|
477
|
+
|
|
396
478
|
console.log('');
|
|
397
479
|
console.log(`${colors.cyan}╔═══════════════════════════════════════════════════════╗${colors.reset}`);
|
|
398
|
-
console.log(`${colors.cyan}║ DGP Agent - AI Mode
|
|
480
|
+
console.log(`${colors.cyan}║ DGP Agent - AI Mode v${AGENT_VERSION} 🤖 ║${colors.reset}`);
|
|
399
481
|
console.log(`${colors.cyan}║ Powered by Claude ║${colors.reset}`);
|
|
400
482
|
console.log(`${colors.cyan}╚═══════════════════════════════════════════════════════╝${colors.reset}`);
|
|
401
483
|
console.log('');
|
|
@@ -697,7 +779,8 @@ async function reportStatus(status) {
|
|
|
697
779
|
const payload = {
|
|
698
780
|
machine_id: CONFIG.machineId,
|
|
699
781
|
timestamp: new Date().toISOString(),
|
|
700
|
-
agent_version:
|
|
782
|
+
agent_version: AGENT_VERSION,
|
|
783
|
+
agent_mode: AGENT_MODE,
|
|
701
784
|
status,
|
|
702
785
|
};
|
|
703
786
|
|
|
@@ -993,10 +1076,15 @@ function printStatus(status) {
|
|
|
993
1076
|
* Loop principal del agente
|
|
994
1077
|
*/
|
|
995
1078
|
async function runAgent(deployMode = false) {
|
|
1079
|
+
// Matar agente anterior y guardar PID
|
|
1080
|
+
killPreviousAgent();
|
|
1081
|
+
savePid();
|
|
1082
|
+
AGENT_MODE = deployMode ? 'deploy' : 'status';
|
|
1083
|
+
|
|
996
1084
|
console.log('');
|
|
997
1085
|
console.log(`${colors.green}╔═══════════════════════════════════════════════════════╗${colors.reset}`);
|
|
998
1086
|
console.log(`${colors.green}║ DGP Agent - Despliegue-GPT Local Agent ║${colors.reset}`);
|
|
999
|
-
console.log(`${colors.green}║ @deinossrl/dgp-agent
|
|
1087
|
+
console.log(`${colors.green}║ @deinossrl/dgp-agent v${AGENT_VERSION} ║${colors.reset}`);
|
|
1000
1088
|
console.log(`${colors.green}╚═══════════════════════════════════════════════════════╝${colors.reset}`);
|
|
1001
1089
|
console.log('');
|
|
1002
1090
|
|
|
@@ -1006,11 +1094,11 @@ async function runAgent(deployMode = false) {
|
|
|
1006
1094
|
}
|
|
1007
1095
|
|
|
1008
1096
|
logInfo(`Machine ID: ${CONFIG.machineId}`);
|
|
1097
|
+
logInfo(`Mode: ${AGENT_MODE.toUpperCase()}`);
|
|
1009
1098
|
logInfo(`Report interval: ${CONFIG.interval}s`);
|
|
1010
1099
|
logInfo(`API URL: ${CONFIG.apiUrl}`);
|
|
1011
1100
|
|
|
1012
1101
|
if (deployMode) {
|
|
1013
|
-
logInfo(`Deploy mode: ACTIVE`);
|
|
1014
1102
|
logInfo(`Command poll interval: ${CONFIG.commandPollInterval}s`);
|
|
1015
1103
|
}
|
|
1016
1104
|
|
|
@@ -1112,7 +1200,7 @@ async function showStatus() {
|
|
|
1112
1200
|
function showHelp() {
|
|
1113
1201
|
console.log(`
|
|
1114
1202
|
${colors.bold}${colors.cyan}DGP Agent - Despliegue-GPT Local Agent${colors.reset}
|
|
1115
|
-
${colors.gray}@deinossrl/dgp-agent v1.4.
|
|
1203
|
+
${colors.gray}@deinossrl/dgp-agent v1.4.7${colors.reset}
|
|
1116
1204
|
|
|
1117
1205
|
${colors.bold}DESCRIPCIÓN${colors.reset}
|
|
1118
1206
|
Agente local que reporta el estado de tu repositorio Git
|
|
@@ -1163,6 +1251,7 @@ ${colors.bold}REQUISITOS PARA DEPLOY${colors.reset}
|
|
|
1163
1251
|
- Permisos sudo para reload nginx (vía sudoers sin password)
|
|
1164
1252
|
|
|
1165
1253
|
${colors.bold}CHANGELOG${colors.reset}
|
|
1254
|
+
${colors.cyan}v1.4.7${colors.reset} - Modo AI visible en web, auto-kill agente anterior
|
|
1166
1255
|
${colors.cyan}v1.4.6${colors.reset} - Fix: versión en banner AI Mode
|
|
1167
1256
|
${colors.cyan}v1.4.5${colors.reset} - Modo escucha: recibe tareas AI desde la web
|
|
1168
1257
|
${colors.cyan}v1.4.4${colors.reset} - Config global (compartida por todos los agentes)
|
|
@@ -1332,7 +1421,7 @@ switch (command) {
|
|
|
1332
1421
|
case 'version':
|
|
1333
1422
|
case '-v':
|
|
1334
1423
|
case '--version':
|
|
1335
|
-
console.log('@deinossrl/dgp-agent v1.4.
|
|
1424
|
+
console.log('@deinossrl/dgp-agent v1.4.7');
|
|
1336
1425
|
break;
|
|
1337
1426
|
case 'ai':
|
|
1338
1427
|
case '--ai':
|