@deinossrl/dgp-agent 1.4.12 → 1.4.14
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 +117 -104
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -202,9 +202,9 @@ async function fetchPlatformConfig() {
|
|
|
202
202
|
// Variable para config de la plataforma (se carga async)
|
|
203
203
|
let platformConfig = null;
|
|
204
204
|
|
|
205
|
-
// Versión
|
|
206
|
-
const AGENT_VERSION = '1.4.
|
|
207
|
-
let AGENT_MODE = '
|
|
205
|
+
// Versión del agente
|
|
206
|
+
const AGENT_VERSION = '1.4.14';
|
|
207
|
+
let AGENT_MODE = 'smart'; // Siempre inteligente
|
|
208
208
|
|
|
209
209
|
// Configuración (prioridad: env vars > archivo config > platform config > defaults)
|
|
210
210
|
const CONFIG = {
|
|
@@ -1181,40 +1181,45 @@ function printStatus(status) {
|
|
|
1181
1181
|
}
|
|
1182
1182
|
|
|
1183
1183
|
/**
|
|
1184
|
-
* Loop principal del agente
|
|
1184
|
+
* Loop principal del agente - SIEMPRE inteligente
|
|
1185
1185
|
*/
|
|
1186
|
-
async function runAgent(
|
|
1186
|
+
async function runAgent() {
|
|
1187
1187
|
// Matar agente anterior y guardar PID
|
|
1188
1188
|
killPreviousAgent();
|
|
1189
1189
|
savePid();
|
|
1190
|
-
AGENT_MODE =
|
|
1190
|
+
AGENT_MODE = 'smart';
|
|
1191
1191
|
|
|
1192
1192
|
printBanner([
|
|
1193
|
-
'DGP Agent -
|
|
1194
|
-
|
|
1195
|
-
], '
|
|
1193
|
+
'DGP Agent - Agente Inteligente',
|
|
1194
|
+
`v${AGENT_VERSION} | Web ↔ PC`
|
|
1195
|
+
], 'cyan');
|
|
1196
1196
|
|
|
1197
1197
|
if (!isGitRepo()) {
|
|
1198
1198
|
logError('Not a git repository. Run this command from inside a git repo.');
|
|
1199
1199
|
process.exit(1);
|
|
1200
1200
|
}
|
|
1201
1201
|
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1202
|
+
// Cargar config de la plataforma si no hay API key local
|
|
1203
|
+
if (!CONFIG.anthropicApiKey) {
|
|
1204
|
+
logInfo('Buscando configuración en la plataforma...');
|
|
1205
|
+
platformConfig = await fetchPlatformConfig();
|
|
1206
1206
|
|
|
1207
|
-
|
|
1208
|
-
|
|
1207
|
+
if (platformConfig?.anthropic_api_key) {
|
|
1208
|
+
CONFIG.anthropicApiKey = platformConfig.anthropic_api_key;
|
|
1209
|
+
if (platformConfig.ai_model) {
|
|
1210
|
+
CONFIG.aiModel = platformConfig.ai_model;
|
|
1211
|
+
}
|
|
1212
|
+
logSuccess('IA habilitada desde configuración de la plataforma');
|
|
1213
|
+
}
|
|
1209
1214
|
}
|
|
1210
1215
|
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
}
|
|
1216
|
+
logInfo(`Machine ID: ${CONFIG.machineId}`);
|
|
1217
|
+
logInfo(`IA: ${CONFIG.anthropicApiKey ? '✓ Habilitada' : '✗ No configurada'}`);
|
|
1218
|
+
logInfo(`Reporta cada ${CONFIG.interval}s | Escucha cada ${CONFIG.commandPollInterval}s`);
|
|
1215
1219
|
|
|
1216
1220
|
console.log('');
|
|
1217
|
-
logInfo('
|
|
1221
|
+
logInfo('Escuchando comandos de la web...');
|
|
1222
|
+
logInfo('Presiona Ctrl+C para detener');
|
|
1218
1223
|
console.log('');
|
|
1219
1224
|
|
|
1220
1225
|
// Status reporting cycle
|
|
@@ -1231,36 +1236,74 @@ async function runAgent(deployMode = false) {
|
|
|
1231
1236
|
}
|
|
1232
1237
|
};
|
|
1233
1238
|
|
|
1234
|
-
// Command polling cycle (
|
|
1239
|
+
// Command polling cycle - SIEMPRE escucha comandos (Web ↔ PC)
|
|
1240
|
+
let isProcessingCommand = false;
|
|
1235
1241
|
const runCommandCycle = async () => {
|
|
1242
|
+
if (isProcessingCommand) return;
|
|
1243
|
+
|
|
1236
1244
|
try {
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1245
|
+
// Buscar comandos pendientes para ESTE machine_id
|
|
1246
|
+
const url = `${CONFIG.commandsUrl}?machine_id=eq.${CONFIG.machineId}&status=eq.pending&select=*&order=created_at.asc&limit=1`;
|
|
1247
|
+
const response = await fetch(url, {
|
|
1248
|
+
headers: {
|
|
1249
|
+
'apikey': CONFIG.supabaseKey,
|
|
1250
|
+
'Authorization': `Bearer ${CONFIG.supabaseKey}`,
|
|
1251
|
+
},
|
|
1252
|
+
});
|
|
1253
|
+
|
|
1254
|
+
if (!response.ok) return;
|
|
1255
|
+
|
|
1256
|
+
const commands = await response.json();
|
|
1257
|
+
if (commands.length === 0) return;
|
|
1258
|
+
|
|
1259
|
+
const command = commands[0];
|
|
1260
|
+
isProcessingCommand = true;
|
|
1261
|
+
|
|
1262
|
+
logCommand(`📥 Comando recibido: ${command.command}`);
|
|
1263
|
+
|
|
1264
|
+
// Verificar si tenemos IA disponible
|
|
1265
|
+
const useAI = !!CONFIG.anthropicApiKey;
|
|
1266
|
+
|
|
1267
|
+
if (command.command === 'ai_task' && useAI) {
|
|
1268
|
+
// Tarea AI - ejecutar con Claude
|
|
1269
|
+
await updateCommandStatus(command.id, 'running', {});
|
|
1270
|
+
const result = await executeAITask(command.params?.task || '');
|
|
1271
|
+
|
|
1272
|
+
if (result.success) {
|
|
1273
|
+
await updateCommandStatus(command.id, 'completed', {
|
|
1274
|
+
output: result.results?.map(r => r.output).join('\n'),
|
|
1275
|
+
commands_executed: result.results?.length || 0,
|
|
1276
|
+
});
|
|
1277
|
+
logSuccess('Tarea completada');
|
|
1278
|
+
} else {
|
|
1279
|
+
await updateCommandStatus(command.id, 'failed', {}, result.error || 'Task failed');
|
|
1280
|
+
logError('Tarea fallida');
|
|
1281
|
+
}
|
|
1282
|
+
} else {
|
|
1283
|
+
// Comandos git y otros
|
|
1284
|
+
await executeCommand(command, useAI);
|
|
1242
1285
|
}
|
|
1286
|
+
|
|
1287
|
+
isProcessingCommand = false;
|
|
1288
|
+
|
|
1243
1289
|
} catch (error) {
|
|
1290
|
+
isProcessingCommand = false;
|
|
1244
1291
|
// Silent fail for command polling - don't spam logs
|
|
1245
|
-
if (error.message
|
|
1246
|
-
//
|
|
1247
|
-
} else {
|
|
1248
|
-
logError(`Command poll failed: ${error.message}`);
|
|
1292
|
+
if (!error.message?.includes('42P01')) {
|
|
1293
|
+
// Solo loggear si no es error de tabla inexistente
|
|
1249
1294
|
}
|
|
1250
1295
|
}
|
|
1251
1296
|
};
|
|
1252
1297
|
|
|
1253
1298
|
// Initial run
|
|
1254
1299
|
await runStatusCycle();
|
|
1255
|
-
|
|
1256
|
-
await runCommandCycle();
|
|
1257
|
-
}
|
|
1300
|
+
await runCommandCycle();
|
|
1258
1301
|
|
|
1259
|
-
// Set intervals
|
|
1302
|
+
// Set intervals - SIEMPRE escucha comandos
|
|
1260
1303
|
setInterval(runStatusCycle, CONFIG.interval * 1000);
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
}
|
|
1304
|
+
setInterval(runCommandCycle, CONFIG.commandPollInterval * 1000);
|
|
1305
|
+
|
|
1306
|
+
logInfo(`Escuchando comandos de la web (cada ${CONFIG.commandPollInterval}s)...`);
|
|
1264
1307
|
}
|
|
1265
1308
|
|
|
1266
1309
|
/**
|
|
@@ -1305,75 +1348,48 @@ async function showStatus() {
|
|
|
1305
1348
|
*/
|
|
1306
1349
|
function showHelp() {
|
|
1307
1350
|
console.log(`
|
|
1308
|
-
${colors.bold}${colors.cyan}DGP Agent -
|
|
1309
|
-
${colors.gray}@deinossrl/dgp-agent
|
|
1351
|
+
${colors.bold}${colors.cyan}DGP Agent - Agente Inteligente${colors.reset}
|
|
1352
|
+
${colors.gray}@deinossrl/dgp-agent v${AGENT_VERSION}${colors.reset}
|
|
1310
1353
|
|
|
1311
1354
|
${colors.bold}DESCRIPCIÓN${colors.reset}
|
|
1312
|
-
Agente
|
|
1313
|
-
|
|
1314
|
-
ejecutar comandos de deploy remotos.
|
|
1355
|
+
Agente inteligente que conecta tu repositorio Git con TenMinute IA.
|
|
1356
|
+
Reporta estado, escucha comandos de la web, y usa IA para ejecutarlos.
|
|
1315
1357
|
|
|
1316
1358
|
${colors.bold}INSTALACIÓN${colors.reset}
|
|
1317
|
-
${colors.green}npm install -g @deinossrl/dgp-agent${colors.reset}
|
|
1359
|
+
${colors.green}npm install -g @deinossrl/dgp-agent@latest${colors.reset}
|
|
1318
1360
|
|
|
1319
1361
|
${colors.bold}USO${colors.reset}
|
|
1320
|
-
${colors.cyan}dgp-agent${colors.reset} Inicia el agente
|
|
1321
|
-
${colors.cyan}dgp-agent
|
|
1322
|
-
${colors.cyan}dgp-agent
|
|
1323
|
-
${colors.cyan}dgp-agent ai${colors.reset} Modo IA interactivo (requiere API key)
|
|
1324
|
-
${colors.cyan}dgp-agent ai "tarea"${colors.reset} Ejecuta una tarea con IA
|
|
1325
|
-
${colors.cyan}dgp-agent config${colors.reset} Gestiona la configuración local
|
|
1362
|
+
${colors.cyan}dgp-agent${colors.reset} Inicia el agente inteligente
|
|
1363
|
+
${colors.cyan}dgp-agent status${colors.reset} Muestra el estado actual (una vez)
|
|
1364
|
+
${colors.cyan}dgp-agent config${colors.reset} Gestiona la configuración
|
|
1326
1365
|
${colors.cyan}dgp-agent help${colors.reset} Muestra esta ayuda
|
|
1327
1366
|
|
|
1328
|
-
${colors.bold}
|
|
1329
|
-
${colors.
|
|
1330
|
-
${colors.
|
|
1331
|
-
|
|
1367
|
+
${colors.bold}¿QUÉ HACE EL AGENTE?${colors.reset}
|
|
1368
|
+
${colors.green}✓${colors.reset} Reporta estado del repositorio a la plataforma web
|
|
1369
|
+
${colors.green}✓${colors.reset} Escucha comandos enviados desde TenMinute IA
|
|
1370
|
+
${colors.green}✓${colors.reset} Ejecuta comandos git (commit, push, pull, etc)
|
|
1371
|
+
${colors.green}✓${colors.reset} Usa IA para interpretar tareas en lenguaje natural
|
|
1372
|
+
${colors.green}✓${colors.reset} Mejora mensajes de commit automáticamente
|
|
1373
|
+
|
|
1374
|
+
${colors.bold}CONFIGURACIÓN${colors.reset}
|
|
1375
|
+
La API key de Claude se configura desde:
|
|
1376
|
+
1. Web: TenMinute IA > Configuración > Agente IA
|
|
1377
|
+
2. CLI: dgp-agent config set anthropic-api-key sk-ant-...
|
|
1332
1378
|
|
|
1333
1379
|
${colors.bold}VARIABLES DE ENTORNO${colors.reset}
|
|
1334
|
-
${colors.yellow}
|
|
1335
|
-
${colors.yellow}
|
|
1336
|
-
${colors.yellow}DGP_INTERVAL${colors.reset} Intervalo de reporte en segundos (default: 30)
|
|
1337
|
-
${colors.yellow}DGP_COMMAND_POLL_INTERVAL${colors.reset} Intervalo de polling comandos (default: 10)
|
|
1380
|
+
${colors.yellow}ANTHROPIC_API_KEY${colors.reset} API key de Claude (opcional si está en web)
|
|
1381
|
+
${colors.yellow}DGP_INTERVAL${colors.reset} Intervalo de reporte (default: 30s)
|
|
1338
1382
|
${colors.yellow}DGP_MACHINE_ID${colors.reset} ID personalizado de la máquina
|
|
1339
1383
|
|
|
1340
1384
|
${colors.bold}EJEMPLOS${colors.reset}
|
|
1341
|
-
# Iniciar agente
|
|
1342
|
-
$
|
|
1343
|
-
|
|
1344
|
-
#
|
|
1345
|
-
$
|
|
1346
|
-
|
|
1347
|
-
#
|
|
1348
|
-
$
|
|
1349
|
-
|
|
1350
|
-
# Intervalo personalizado (60 segundos)
|
|
1351
|
-
${colors.gray}$ DGP_INTERVAL=60 dgp-agent${colors.reset}
|
|
1352
|
-
|
|
1353
|
-
${colors.bold}REQUISITOS PARA DEPLOY${colors.reset}
|
|
1354
|
-
- SSH key configurada para acceso al servidor
|
|
1355
|
-
- Node.js y npm en el PATH
|
|
1356
|
-
- rsync instalado (Linux/Mac) o equivalente (Windows)
|
|
1357
|
-
- Permisos sudo para reload nginx (vía sudoers sin password)
|
|
1358
|
-
|
|
1359
|
-
${colors.bold}CHANGELOG${colors.reset}
|
|
1360
|
-
${colors.cyan}v1.4.10${colors.reset} - AI Mode escucha todos los comandos (git + ai_task)
|
|
1361
|
-
${colors.cyan}v1.4.9${colors.reset} - Fix: AI Mode no reportaba status a la plataforma
|
|
1362
|
-
${colors.cyan}v1.4.8${colors.reset} - Banner dinámico con padding automático
|
|
1363
|
-
${colors.cyan}v1.4.7${colors.reset} - Modo AI visible en web, auto-kill agente anterior
|
|
1364
|
-
${colors.cyan}v1.4.6${colors.reset} - Fix: versión en banner AI Mode
|
|
1365
|
-
${colors.cyan}v1.4.5${colors.reset} - Modo escucha: recibe tareas AI desde la web
|
|
1366
|
-
${colors.cyan}v1.4.4${colors.reset} - Config global (compartida por todos los agentes)
|
|
1367
|
-
${colors.cyan}v1.4.3${colors.reset} - Config desde plataforma web (TenMinute IA)
|
|
1368
|
-
${colors.cyan}v1.4.2${colors.reset} - Fix: alineación banner, config persistente
|
|
1369
|
-
${colors.cyan}v1.3.0${colors.reset} - AI Mode: ejecuta tareas con lenguaje natural
|
|
1370
|
-
${colors.cyan}v1.2.7${colors.reset} - Fix: update via Edge Function (401 fix)
|
|
1371
|
-
${colors.cyan}v1.2.6${colors.reset} - Comando git_commit_push desde la UI
|
|
1372
|
-
${colors.cyan}v1.2.5${colors.reset} - Sincronización de versiones y changelog
|
|
1373
|
-
${colors.cyan}v1.2.4${colors.reset} - Mejoras en ejecución async de comandos shell
|
|
1374
|
-
${colors.cyan}v1.2.0${colors.reset} - Modo deploy con polling de comandos remotos
|
|
1375
|
-
${colors.cyan}v1.1.0${colors.reset} - Soporte para deploy via rsync y reload nginx
|
|
1376
|
-
${colors.cyan}v1.0.0${colors.reset} - Versión inicial: reporte de estado git
|
|
1385
|
+
${colors.gray}# Iniciar agente${colors.reset}
|
|
1386
|
+
$ dgp-agent
|
|
1387
|
+
|
|
1388
|
+
${colors.gray}# Ver estado sin iniciar loop${colors.reset}
|
|
1389
|
+
$ dgp-agent status
|
|
1390
|
+
|
|
1391
|
+
${colors.gray}# Configurar API key${colors.reset}
|
|
1392
|
+
$ dgp-agent config set anthropic-api-key sk-ant-...
|
|
1377
1393
|
|
|
1378
1394
|
${colors.bold}MÁS INFO${colors.reset}
|
|
1379
1395
|
https://github.com/DEINOS-SRL/tenminuteia
|
|
@@ -1512,11 +1528,6 @@ const args = process.argv.slice(2);
|
|
|
1512
1528
|
const command = args[0];
|
|
1513
1529
|
|
|
1514
1530
|
switch (command) {
|
|
1515
|
-
case 'deploy':
|
|
1516
|
-
case '-d':
|
|
1517
|
-
case '--deploy':
|
|
1518
|
-
runAgent(true); // Deploy mode
|
|
1519
|
-
break;
|
|
1520
1531
|
case 'status':
|
|
1521
1532
|
case '-s':
|
|
1522
1533
|
case '--status':
|
|
@@ -1530,15 +1541,17 @@ switch (command) {
|
|
|
1530
1541
|
case 'version':
|
|
1531
1542
|
case '-v':
|
|
1532
1543
|
case '--version':
|
|
1533
|
-
console.log(
|
|
1534
|
-
break;
|
|
1535
|
-
case 'ai':
|
|
1536
|
-
case '--ai':
|
|
1537
|
-
runAIMode();
|
|
1544
|
+
console.log(`@deinossrl/dgp-agent v${AGENT_VERSION}`);
|
|
1538
1545
|
break;
|
|
1539
1546
|
case 'config':
|
|
1540
1547
|
handleConfigCommand(args.slice(1));
|
|
1541
1548
|
break;
|
|
1549
|
+
// Aliases legacy + default → Agente Inteligente
|
|
1550
|
+
case 'deploy':
|
|
1551
|
+
case '-d':
|
|
1552
|
+
case '--deploy':
|
|
1553
|
+
case 'ai':
|
|
1554
|
+
case '--ai':
|
|
1542
1555
|
default:
|
|
1543
|
-
runAgent(
|
|
1556
|
+
runAgent(); // Agente inteligente (siempre escucha + IA si disponible)
|
|
1544
1557
|
}
|