@deinossrl/dgp-agent 1.4.15 → 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.
Files changed (2) hide show
  1. package/index.mjs +92 -3
  2. 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.15';
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)
@@ -925,12 +925,66 @@ 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
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
+
928
976
  /**
929
977
  * Actualiza el estado de un comando via Edge Function
930
978
  */
931
979
  async function updateCommandStatus(commandId, status, result = {}, errorMessage = null) {
932
980
  const url = 'https://asivayhbrqennwiwttds.supabase.co/functions/v1/dgp-agent-command-update';
933
981
 
982
+ // Incluir los logs en el resultado
983
+ const fullResult = {
984
+ ...result,
985
+ logs: commandLogs,
986
+ };
987
+
934
988
  const response = await fetch(url, {
935
989
  method: 'POST',
936
990
  headers: {
@@ -941,7 +995,7 @@ async function updateCommandStatus(commandId, status, result = {}, errorMessage
941
995
  body: JSON.stringify({
942
996
  commandId,
943
997
  status,
944
- result,
998
+ result: fullResult,
945
999
  error_message: errorMessage,
946
1000
  }),
947
1001
  });
@@ -950,6 +1004,12 @@ async function updateCommandStatus(commandId, status, result = {}, errorMessage
950
1004
  const text = await response.text();
951
1005
  throw new Error(`Failed to update command: HTTP ${response.status} - ${text}`);
952
1006
  }
1007
+
1008
+ // Limpiar logs si el comando terminó
1009
+ if (status === 'completed' || status === 'failed') {
1010
+ commandLogs = [];
1011
+ currentCommandId = null;
1012
+ }
953
1013
  }
954
1014
 
955
1015
  /**
@@ -1116,20 +1176,32 @@ async function executeGitCommitPush(command, useAI = false) {
1116
1176
  return { success: false };
1117
1177
  }
1118
1178
 
1179
+ // Iniciar tracking de logs
1180
+ currentCommandId = command.id;
1181
+ commandLogs = [];
1182
+
1119
1183
  try {
1120
1184
  // Marcar como running
1121
1185
  await updateCommandStatus(command.id, 'running', {});
1186
+ await addCommandLog('info', 'Iniciando proceso de commit y push...');
1122
1187
 
1123
1188
  // Si tenemos API key y useAI está activo, mejorar el mensaje con IA
1124
1189
  let aiAnalysis = null;
1125
1190
  if (useAI && CONFIG.anthropicApiKey) {
1126
1191
  logAI('Analizando commit con IA...');
1192
+ await addCommandLog('ai', 'Analizando commit con IA...');
1193
+
1127
1194
  aiAnalysis = await processGitCommandWithAI('git_commit_push', { message, add_all });
1128
1195
  if (aiAnalysis) {
1129
1196
  logAI(`Análisis: ${aiAnalysis.analysis}`);
1197
+ await addCommandLog('ai', aiAnalysis.analysis);
1198
+
1130
1199
  if (aiAnalysis.improved_message && aiAnalysis.improved_message !== message) {
1131
1200
  logAI(`Mensaje mejorado: ${aiAnalysis.improved_message}`);
1201
+ await addCommandLog('ai', `Mensaje mejorado: ${aiAnalysis.improved_message}`);
1132
1202
  message = aiAnalysis.improved_message;
1203
+ } else {
1204
+ await addCommandLog('info', 'Usando mensaje original del usuario');
1133
1205
  }
1134
1206
  }
1135
1207
  }
@@ -1139,30 +1211,46 @@ async function executeGitCommitPush(command, useAI = false) {
1139
1211
  // git add
1140
1212
  if (add_all) {
1141
1213
  logCommand('git add .');
1214
+ await addCommandLog('command', 'git add .');
1142
1215
  await shellAsync('git add .');
1216
+ await addCommandLog('success', 'Archivos agregados al staging');
1143
1217
  }
1144
1218
 
1145
1219
  // git commit - usar spawnSync para evitar problemas de comillas en shell
1146
1220
  logCommand(`git commit -m "${message}"`);
1221
+ await addCommandLog('command', `git commit -m "${message}"`);
1222
+
1147
1223
  const commitProc = spawnSync('git', ['commit', '-m', message], { encoding: 'utf-8' });
1148
1224
  if (commitProc.status !== 0) {
1149
1225
  const errorMsg = commitProc.stderr || commitProc.stdout || 'Unknown error';
1150
1226
  // Verificar si es "nothing to commit"
1151
1227
  if (errorMsg.includes('nothing to commit') || (commitProc.stdout && commitProc.stdout.includes('nothing to commit'))) {
1152
1228
  logInfo('Nothing to commit, skipping...');
1229
+ await addCommandLog('info', 'No hay cambios para commitear');
1153
1230
  } else {
1154
1231
  throw new Error(`Git commit failed: ${errorMsg}`);
1155
1232
  }
1156
1233
  } else {
1157
1234
  logSuccess('Commit created');
1158
- if (commitProc.stdout) console.log(colors.gray + commitProc.stdout + colors.reset);
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
+ }
1159
1244
  }
1160
1245
 
1161
1246
  // git push
1162
1247
  const branch = shellSync('git branch --show-current').trim();
1163
1248
  logCommand(`git push origin ${branch}`);
1249
+ await addCommandLog('command', `git push origin ${branch}`);
1250
+
1164
1251
  await shellAsync(`git push origin ${branch}`);
1165
1252
  logSuccess('Push completed');
1253
+ await addCommandLog('success', `Push completado a ${branch}`);
1166
1254
 
1167
1255
  await updateCommandStatus(command.id, 'completed', {
1168
1256
  message: message,
@@ -1173,6 +1261,7 @@ async function executeGitCommitPush(command, useAI = false) {
1173
1261
  return { success: true };
1174
1262
  } catch (error) {
1175
1263
  logError(`Git commit/push failed: ${error.message}`);
1264
+ await addCommandLog('error', error.message);
1176
1265
  await updateCommandStatus(command.id, 'failed', {}, error.message);
1177
1266
  return { success: false, error: error.message };
1178
1267
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deinossrl/dgp-agent",
3
- "version": "1.4.15",
3
+ "version": "1.4.16",
4
4
  "description": "Agente local para Despliegue-GPT - Reporta el estado del repositorio Git a la plataforma TenMinute IA",
5
5
  "main": "index.mjs",
6
6
  "bin": {