@deinossrl/dgp-agent 1.4.15 → 1.4.17
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 +93 -3
- 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.17';
|
|
207
207
|
let AGENT_MODE = 'smart'; // Siempre inteligente
|
|
208
208
|
|
|
209
209
|
// Configuración (prioridad: env vars > archivo config > platform config > defaults)
|
|
@@ -925,12 +925,67 @@ async function getPendingCommands() {
|
|
|
925
925
|
return await response.json();
|
|
926
926
|
}
|
|
927
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 (guarda en result.logs)
|
|
957
|
+
*/
|
|
958
|
+
async function updateCommandLogs(commandId, logs) {
|
|
959
|
+
const url = `${CONFIG.commandsUrl}?id=eq.${commandId}`;
|
|
960
|
+
|
|
961
|
+
// Guardar en result para que la web lo lea
|
|
962
|
+
await fetch(url, {
|
|
963
|
+
method: 'PATCH',
|
|
964
|
+
headers: {
|
|
965
|
+
'apikey': CONFIG.supabaseKey,
|
|
966
|
+
'Authorization': `Bearer ${CONFIG.supabaseKey}`,
|
|
967
|
+
'Content-Type': 'application/json',
|
|
968
|
+
'Prefer': 'return=minimal',
|
|
969
|
+
},
|
|
970
|
+
body: JSON.stringify({
|
|
971
|
+
result: { logs: logs },
|
|
972
|
+
updated_at: new Date().toISOString(),
|
|
973
|
+
}),
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
|
|
928
977
|
/**
|
|
929
978
|
* Actualiza el estado de un comando via Edge Function
|
|
930
979
|
*/
|
|
931
980
|
async function updateCommandStatus(commandId, status, result = {}, errorMessage = null) {
|
|
932
981
|
const url = 'https://asivayhbrqennwiwttds.supabase.co/functions/v1/dgp-agent-command-update';
|
|
933
982
|
|
|
983
|
+
// Incluir los logs en el resultado
|
|
984
|
+
const fullResult = {
|
|
985
|
+
...result,
|
|
986
|
+
logs: commandLogs,
|
|
987
|
+
};
|
|
988
|
+
|
|
934
989
|
const response = await fetch(url, {
|
|
935
990
|
method: 'POST',
|
|
936
991
|
headers: {
|
|
@@ -941,7 +996,7 @@ async function updateCommandStatus(commandId, status, result = {}, errorMessage
|
|
|
941
996
|
body: JSON.stringify({
|
|
942
997
|
commandId,
|
|
943
998
|
status,
|
|
944
|
-
result,
|
|
999
|
+
result: fullResult,
|
|
945
1000
|
error_message: errorMessage,
|
|
946
1001
|
}),
|
|
947
1002
|
});
|
|
@@ -950,6 +1005,12 @@ async function updateCommandStatus(commandId, status, result = {}, errorMessage
|
|
|
950
1005
|
const text = await response.text();
|
|
951
1006
|
throw new Error(`Failed to update command: HTTP ${response.status} - ${text}`);
|
|
952
1007
|
}
|
|
1008
|
+
|
|
1009
|
+
// Limpiar logs si el comando terminó
|
|
1010
|
+
if (status === 'completed' || status === 'failed') {
|
|
1011
|
+
commandLogs = [];
|
|
1012
|
+
currentCommandId = null;
|
|
1013
|
+
}
|
|
953
1014
|
}
|
|
954
1015
|
|
|
955
1016
|
/**
|
|
@@ -1116,20 +1177,32 @@ async function executeGitCommitPush(command, useAI = false) {
|
|
|
1116
1177
|
return { success: false };
|
|
1117
1178
|
}
|
|
1118
1179
|
|
|
1180
|
+
// Iniciar tracking de logs
|
|
1181
|
+
currentCommandId = command.id;
|
|
1182
|
+
commandLogs = [];
|
|
1183
|
+
|
|
1119
1184
|
try {
|
|
1120
1185
|
// Marcar como running
|
|
1121
1186
|
await updateCommandStatus(command.id, 'running', {});
|
|
1187
|
+
await addCommandLog('info', 'Iniciando proceso de commit y push...');
|
|
1122
1188
|
|
|
1123
1189
|
// Si tenemos API key y useAI está activo, mejorar el mensaje con IA
|
|
1124
1190
|
let aiAnalysis = null;
|
|
1125
1191
|
if (useAI && CONFIG.anthropicApiKey) {
|
|
1126
1192
|
logAI('Analizando commit con IA...');
|
|
1193
|
+
await addCommandLog('ai', 'Analizando commit con IA...');
|
|
1194
|
+
|
|
1127
1195
|
aiAnalysis = await processGitCommandWithAI('git_commit_push', { message, add_all });
|
|
1128
1196
|
if (aiAnalysis) {
|
|
1129
1197
|
logAI(`Análisis: ${aiAnalysis.analysis}`);
|
|
1198
|
+
await addCommandLog('ai', aiAnalysis.analysis);
|
|
1199
|
+
|
|
1130
1200
|
if (aiAnalysis.improved_message && aiAnalysis.improved_message !== message) {
|
|
1131
1201
|
logAI(`Mensaje mejorado: ${aiAnalysis.improved_message}`);
|
|
1202
|
+
await addCommandLog('ai', `Mensaje mejorado: ${aiAnalysis.improved_message}`);
|
|
1132
1203
|
message = aiAnalysis.improved_message;
|
|
1204
|
+
} else {
|
|
1205
|
+
await addCommandLog('info', 'Usando mensaje original del usuario');
|
|
1133
1206
|
}
|
|
1134
1207
|
}
|
|
1135
1208
|
}
|
|
@@ -1139,30 +1212,46 @@ async function executeGitCommitPush(command, useAI = false) {
|
|
|
1139
1212
|
// git add
|
|
1140
1213
|
if (add_all) {
|
|
1141
1214
|
logCommand('git add .');
|
|
1215
|
+
await addCommandLog('command', 'git add .');
|
|
1142
1216
|
await shellAsync('git add .');
|
|
1217
|
+
await addCommandLog('success', 'Archivos agregados al staging');
|
|
1143
1218
|
}
|
|
1144
1219
|
|
|
1145
1220
|
// git commit - usar spawnSync para evitar problemas de comillas en shell
|
|
1146
1221
|
logCommand(`git commit -m "${message}"`);
|
|
1222
|
+
await addCommandLog('command', `git commit -m "${message}"`);
|
|
1223
|
+
|
|
1147
1224
|
const commitProc = spawnSync('git', ['commit', '-m', message], { encoding: 'utf-8' });
|
|
1148
1225
|
if (commitProc.status !== 0) {
|
|
1149
1226
|
const errorMsg = commitProc.stderr || commitProc.stdout || 'Unknown error';
|
|
1150
1227
|
// Verificar si es "nothing to commit"
|
|
1151
1228
|
if (errorMsg.includes('nothing to commit') || (commitProc.stdout && commitProc.stdout.includes('nothing to commit'))) {
|
|
1152
1229
|
logInfo('Nothing to commit, skipping...');
|
|
1230
|
+
await addCommandLog('info', 'No hay cambios para commitear');
|
|
1153
1231
|
} else {
|
|
1154
1232
|
throw new Error(`Git commit failed: ${errorMsg}`);
|
|
1155
1233
|
}
|
|
1156
1234
|
} else {
|
|
1157
1235
|
logSuccess('Commit created');
|
|
1158
|
-
|
|
1236
|
+
await addCommandLog('success', 'Commit creado');
|
|
1237
|
+
if (commitProc.stdout) {
|
|
1238
|
+
console.log(colors.gray + commitProc.stdout + colors.reset);
|
|
1239
|
+
// Extraer info del commit
|
|
1240
|
+
const commitMatch = commitProc.stdout.match(/\[[\w/-]+ ([a-f0-9]+)\]/);
|
|
1241
|
+
if (commitMatch) {
|
|
1242
|
+
await addCommandLog('output', `Commit: ${commitMatch[1]}`);
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1159
1245
|
}
|
|
1160
1246
|
|
|
1161
1247
|
// git push
|
|
1162
1248
|
const branch = shellSync('git branch --show-current').trim();
|
|
1163
1249
|
logCommand(`git push origin ${branch}`);
|
|
1250
|
+
await addCommandLog('command', `git push origin ${branch}`);
|
|
1251
|
+
|
|
1164
1252
|
await shellAsync(`git push origin ${branch}`);
|
|
1165
1253
|
logSuccess('Push completed');
|
|
1254
|
+
await addCommandLog('success', `Push completado a ${branch}`);
|
|
1166
1255
|
|
|
1167
1256
|
await updateCommandStatus(command.id, 'completed', {
|
|
1168
1257
|
message: message,
|
|
@@ -1173,6 +1262,7 @@ async function executeGitCommitPush(command, useAI = false) {
|
|
|
1173
1262
|
return { success: true };
|
|
1174
1263
|
} catch (error) {
|
|
1175
1264
|
logError(`Git commit/push failed: ${error.message}`);
|
|
1265
|
+
await addCommandLog('error', error.message);
|
|
1176
1266
|
await updateCommandStatus(command.id, 'failed', {}, error.message);
|
|
1177
1267
|
return { success: false, error: error.message };
|
|
1178
1268
|
}
|