@deinossrl/dgp-agent 1.4.14 → 1.4.16
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 +127 -11
- 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 del agente
|
|
206
|
-
const AGENT_VERSION = '1.4.
|
|
206
|
+
const AGENT_VERSION = '1.4.16';
|
|
207
207
|
let AGENT_MODE = 'smart'; // Siempre inteligente
|
|
208
208
|
|
|
209
209
|
// Configuración (prioridad: env vars > archivo config > platform config > defaults)
|
|
@@ -395,6 +395,19 @@ function getRepoContext() {
|
|
|
395
395
|
return context;
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
+
/**
|
|
399
|
+
* Verifica si un mensaje de commit es vago/genérico
|
|
400
|
+
*/
|
|
401
|
+
function isVagueCommitMessage(message) {
|
|
402
|
+
const vaguePatterns = [
|
|
403
|
+
/^(cambio|cambios|change|changes|update|updates|fix|fixes|wip|test|testing)s?$/i,
|
|
404
|
+
/^(minor|small|quick|tmp|temp|todo)(\s|$)/i,
|
|
405
|
+
/^\.+$/,
|
|
406
|
+
/^[a-z]{1,5}$/i, // mensajes muy cortos
|
|
407
|
+
];
|
|
408
|
+
return vaguePatterns.some(p => p.test(message.trim()));
|
|
409
|
+
}
|
|
410
|
+
|
|
398
411
|
/**
|
|
399
412
|
* Procesa un comando git con ayuda de IA para entender mejor la intención
|
|
400
413
|
*/
|
|
@@ -403,19 +416,30 @@ async function processGitCommandWithAI(command, params) {
|
|
|
403
416
|
|
|
404
417
|
const context = getRepoContext();
|
|
405
418
|
|
|
406
|
-
|
|
419
|
+
// Solo mejorar si el mensaje es vago
|
|
420
|
+
const originalMessage = params?.message || '';
|
|
421
|
+
const shouldImprove = isVagueCommitMessage(originalMessage);
|
|
422
|
+
|
|
423
|
+
if (!shouldImprove) {
|
|
424
|
+
logAI(`Mensaje del usuario es descriptivo, se usará tal cual`);
|
|
425
|
+
return {
|
|
426
|
+
analysis: 'El mensaje del usuario es descriptivo, se usa sin modificar',
|
|
427
|
+
improved_message: null, // null = no cambiar
|
|
428
|
+
skip: false
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
const systemPrompt = `Eres un experto en Git. Tu trabajo es mejorar mensajes de commit SOLO si son vagos.
|
|
407
433
|
|
|
408
434
|
IMPORTANTE:
|
|
409
|
-
-
|
|
410
|
-
-
|
|
411
|
-
- Genera mensajes de commit descriptivos si el mensaje es vago
|
|
435
|
+
- El usuario escribió: "${originalMessage}" - este mensaje ES VAGO
|
|
436
|
+
- Genera un mensaje descriptivo basado en los archivos modificados
|
|
412
437
|
- Responde SOLO con JSON válido
|
|
413
438
|
|
|
414
439
|
Formato de respuesta:
|
|
415
440
|
{
|
|
416
|
-
"analysis": "qué
|
|
417
|
-
"improved_message": "mensaje mejorado
|
|
418
|
-
"additional_commands": ["comandos adicionales si son necesarios"],
|
|
441
|
+
"analysis": "por qué mejoraste el mensaje",
|
|
442
|
+
"improved_message": "mensaje mejorado basado en los cambios",
|
|
419
443
|
"skip": false
|
|
420
444
|
}`;
|
|
421
445
|
|
|
@@ -901,12 +925,66 @@ async function getPendingCommands() {
|
|
|
901
925
|
return await response.json();
|
|
902
926
|
}
|
|
903
927
|
|
|
928
|
+
/**
|
|
929
|
+
* Buffer de logs para enviar a la web
|
|
930
|
+
*/
|
|
931
|
+
let commandLogs = [];
|
|
932
|
+
let currentCommandId = null;
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* Agrega un log y lo envía a la web
|
|
936
|
+
*/
|
|
937
|
+
async function addCommandLog(type, message) {
|
|
938
|
+
if (!currentCommandId) return;
|
|
939
|
+
|
|
940
|
+
const logEntry = {
|
|
941
|
+
type, // 'info' | 'success' | 'error' | 'command' | 'output' | 'ai'
|
|
942
|
+
message,
|
|
943
|
+
timestamp: new Date().toISOString()
|
|
944
|
+
};
|
|
945
|
+
commandLogs.push(logEntry);
|
|
946
|
+
|
|
947
|
+
// Enviar actualización a la web
|
|
948
|
+
try {
|
|
949
|
+
await updateCommandLogs(currentCommandId, commandLogs);
|
|
950
|
+
} catch (e) {
|
|
951
|
+
// Silently fail - no interrumpir el proceso
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
/**
|
|
956
|
+
* Actualiza los logs de un comando en la DB
|
|
957
|
+
*/
|
|
958
|
+
async function updateCommandLogs(commandId, logs) {
|
|
959
|
+
const url = `${CONFIG.commandsUrl}?id=eq.${commandId}`;
|
|
960
|
+
|
|
961
|
+
await fetch(url, {
|
|
962
|
+
method: 'PATCH',
|
|
963
|
+
headers: {
|
|
964
|
+
'apikey': CONFIG.supabaseKey,
|
|
965
|
+
'Authorization': `Bearer ${CONFIG.supabaseKey}`,
|
|
966
|
+
'Content-Type': 'application/json',
|
|
967
|
+
'Prefer': 'return=minimal',
|
|
968
|
+
},
|
|
969
|
+
body: JSON.stringify({
|
|
970
|
+
logs: logs,
|
|
971
|
+
updated_at: new Date().toISOString(),
|
|
972
|
+
}),
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
|
|
904
976
|
/**
|
|
905
977
|
* Actualiza el estado de un comando via Edge Function
|
|
906
978
|
*/
|
|
907
979
|
async function updateCommandStatus(commandId, status, result = {}, errorMessage = null) {
|
|
908
980
|
const url = 'https://asivayhbrqennwiwttds.supabase.co/functions/v1/dgp-agent-command-update';
|
|
909
981
|
|
|
982
|
+
// Incluir los logs en el resultado
|
|
983
|
+
const fullResult = {
|
|
984
|
+
...result,
|
|
985
|
+
logs: commandLogs,
|
|
986
|
+
};
|
|
987
|
+
|
|
910
988
|
const response = await fetch(url, {
|
|
911
989
|
method: 'POST',
|
|
912
990
|
headers: {
|
|
@@ -917,7 +995,7 @@ async function updateCommandStatus(commandId, status, result = {}, errorMessage
|
|
|
917
995
|
body: JSON.stringify({
|
|
918
996
|
commandId,
|
|
919
997
|
status,
|
|
920
|
-
result,
|
|
998
|
+
result: fullResult,
|
|
921
999
|
error_message: errorMessage,
|
|
922
1000
|
}),
|
|
923
1001
|
});
|
|
@@ -926,6 +1004,12 @@ async function updateCommandStatus(commandId, status, result = {}, errorMessage
|
|
|
926
1004
|
const text = await response.text();
|
|
927
1005
|
throw new Error(`Failed to update command: HTTP ${response.status} - ${text}`);
|
|
928
1006
|
}
|
|
1007
|
+
|
|
1008
|
+
// Limpiar logs si el comando terminó
|
|
1009
|
+
if (status === 'completed' || status === 'failed') {
|
|
1010
|
+
commandLogs = [];
|
|
1011
|
+
currentCommandId = null;
|
|
1012
|
+
}
|
|
929
1013
|
}
|
|
930
1014
|
|
|
931
1015
|
/**
|
|
@@ -1092,20 +1176,32 @@ async function executeGitCommitPush(command, useAI = false) {
|
|
|
1092
1176
|
return { success: false };
|
|
1093
1177
|
}
|
|
1094
1178
|
|
|
1179
|
+
// Iniciar tracking de logs
|
|
1180
|
+
currentCommandId = command.id;
|
|
1181
|
+
commandLogs = [];
|
|
1182
|
+
|
|
1095
1183
|
try {
|
|
1096
1184
|
// Marcar como running
|
|
1097
1185
|
await updateCommandStatus(command.id, 'running', {});
|
|
1186
|
+
await addCommandLog('info', 'Iniciando proceso de commit y push...');
|
|
1098
1187
|
|
|
1099
1188
|
// Si tenemos API key y useAI está activo, mejorar el mensaje con IA
|
|
1100
1189
|
let aiAnalysis = null;
|
|
1101
1190
|
if (useAI && CONFIG.anthropicApiKey) {
|
|
1102
1191
|
logAI('Analizando commit con IA...');
|
|
1192
|
+
await addCommandLog('ai', 'Analizando commit con IA...');
|
|
1193
|
+
|
|
1103
1194
|
aiAnalysis = await processGitCommandWithAI('git_commit_push', { message, add_all });
|
|
1104
1195
|
if (aiAnalysis) {
|
|
1105
1196
|
logAI(`Análisis: ${aiAnalysis.analysis}`);
|
|
1197
|
+
await addCommandLog('ai', aiAnalysis.analysis);
|
|
1198
|
+
|
|
1106
1199
|
if (aiAnalysis.improved_message && aiAnalysis.improved_message !== message) {
|
|
1107
1200
|
logAI(`Mensaje mejorado: ${aiAnalysis.improved_message}`);
|
|
1201
|
+
await addCommandLog('ai', `Mensaje mejorado: ${aiAnalysis.improved_message}`);
|
|
1108
1202
|
message = aiAnalysis.improved_message;
|
|
1203
|
+
} else {
|
|
1204
|
+
await addCommandLog('info', 'Usando mensaje original del usuario');
|
|
1109
1205
|
}
|
|
1110
1206
|
}
|
|
1111
1207
|
}
|
|
@@ -1115,30 +1211,46 @@ async function executeGitCommitPush(command, useAI = false) {
|
|
|
1115
1211
|
// git add
|
|
1116
1212
|
if (add_all) {
|
|
1117
1213
|
logCommand('git add .');
|
|
1214
|
+
await addCommandLog('command', 'git add .');
|
|
1118
1215
|
await shellAsync('git add .');
|
|
1216
|
+
await addCommandLog('success', 'Archivos agregados al staging');
|
|
1119
1217
|
}
|
|
1120
1218
|
|
|
1121
1219
|
// git commit - usar spawnSync para evitar problemas de comillas en shell
|
|
1122
1220
|
logCommand(`git commit -m "${message}"`);
|
|
1221
|
+
await addCommandLog('command', `git commit -m "${message}"`);
|
|
1222
|
+
|
|
1123
1223
|
const commitProc = spawnSync('git', ['commit', '-m', message], { encoding: 'utf-8' });
|
|
1124
1224
|
if (commitProc.status !== 0) {
|
|
1125
1225
|
const errorMsg = commitProc.stderr || commitProc.stdout || 'Unknown error';
|
|
1126
1226
|
// Verificar si es "nothing to commit"
|
|
1127
1227
|
if (errorMsg.includes('nothing to commit') || (commitProc.stdout && commitProc.stdout.includes('nothing to commit'))) {
|
|
1128
1228
|
logInfo('Nothing to commit, skipping...');
|
|
1229
|
+
await addCommandLog('info', 'No hay cambios para commitear');
|
|
1129
1230
|
} else {
|
|
1130
1231
|
throw new Error(`Git commit failed: ${errorMsg}`);
|
|
1131
1232
|
}
|
|
1132
1233
|
} else {
|
|
1133
1234
|
logSuccess('Commit created');
|
|
1134
|
-
|
|
1235
|
+
await addCommandLog('success', 'Commit creado');
|
|
1236
|
+
if (commitProc.stdout) {
|
|
1237
|
+
console.log(colors.gray + commitProc.stdout + colors.reset);
|
|
1238
|
+
// Extraer info del commit
|
|
1239
|
+
const commitMatch = commitProc.stdout.match(/\[[\w/-]+ ([a-f0-9]+)\]/);
|
|
1240
|
+
if (commitMatch) {
|
|
1241
|
+
await addCommandLog('output', `Commit: ${commitMatch[1]}`);
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1135
1244
|
}
|
|
1136
1245
|
|
|
1137
1246
|
// git push
|
|
1138
1247
|
const branch = shellSync('git branch --show-current').trim();
|
|
1139
1248
|
logCommand(`git push origin ${branch}`);
|
|
1249
|
+
await addCommandLog('command', `git push origin ${branch}`);
|
|
1250
|
+
|
|
1140
1251
|
await shellAsync(`git push origin ${branch}`);
|
|
1141
1252
|
logSuccess('Push completed');
|
|
1253
|
+
await addCommandLog('success', `Push completado a ${branch}`);
|
|
1142
1254
|
|
|
1143
1255
|
await updateCommandStatus(command.id, 'completed', {
|
|
1144
1256
|
message: message,
|
|
@@ -1149,6 +1261,7 @@ async function executeGitCommitPush(command, useAI = false) {
|
|
|
1149
1261
|
return { success: true };
|
|
1150
1262
|
} catch (error) {
|
|
1151
1263
|
logError(`Git commit/push failed: ${error.message}`);
|
|
1264
|
+
await addCommandLog('error', error.message);
|
|
1152
1265
|
await updateCommandStatus(command.id, 'failed', {}, error.message);
|
|
1153
1266
|
return { success: false, error: error.message };
|
|
1154
1267
|
}
|
|
@@ -1251,7 +1364,10 @@ async function runAgent() {
|
|
|
1251
1364
|
},
|
|
1252
1365
|
});
|
|
1253
1366
|
|
|
1254
|
-
if (!response.ok)
|
|
1367
|
+
if (!response.ok) {
|
|
1368
|
+
log(`[Poll] Error: ${response.status}`, 'gray');
|
|
1369
|
+
return;
|
|
1370
|
+
}
|
|
1255
1371
|
|
|
1256
1372
|
const commands = await response.json();
|
|
1257
1373
|
if (commands.length === 0) return;
|