zugzbot-sdd 1.5.31 → 1.5.33
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.
|
@@ -185,6 +185,46 @@ export default tool({
|
|
|
185
185
|
report.push(`⚠️ No se pudo restablecer el lockfile: ${e.message}`);
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
|
+
// 5.5. Generar reporte dedicado de tokens y costes para este cambio
|
|
189
|
+
const historyPath = path.join(projectRoot, ".openspec/changes", args.changeName, "phase_history.jsonl");
|
|
190
|
+
if (fs.existsSync(historyPath)) {
|
|
191
|
+
try {
|
|
192
|
+
const lines = fs.readFileSync(historyPath, "utf-8").split("\n").filter(Boolean);
|
|
193
|
+
const entries = lines.map(l => JSON.parse(l));
|
|
194
|
+
let totalCost = 0;
|
|
195
|
+
let totalInput = 0;
|
|
196
|
+
let totalOutput = 0;
|
|
197
|
+
const models = new Set();
|
|
198
|
+
entries.forEach((e) => {
|
|
199
|
+
if (e.analytics) {
|
|
200
|
+
totalCost = Math.max(totalCost, e.analytics.cumulative_cost_usd || 0);
|
|
201
|
+
totalInput = Math.max(totalInput, e.analytics.cumulative_tokens_input || 0);
|
|
202
|
+
totalOutput = Math.max(totalOutput, e.analytics.cumulative_tokens_output || 0);
|
|
203
|
+
if (Array.isArray(e.analytics.models_used)) {
|
|
204
|
+
e.analytics.models_used.forEach((m) => models.add(m));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
const tokenUsageMarkdown = `# 💳 Reporte de Consumo del Cambio: ${args.changeName}
|
|
209
|
+
|
|
210
|
+
Este reporte detalla la telemetría de tokens y coste financiero en USD acumulado por el enjambre de agentes durante el desarrollo de esta tarea.
|
|
211
|
+
|
|
212
|
+
## 📊 Métricas de Consumo
|
|
213
|
+
- **Coste Total de la Sesión:** $${totalCost.toFixed(4)} USD
|
|
214
|
+
- **Tokens de Entrada (Prompt):** ${totalInput.toLocaleString()} tokens
|
|
215
|
+
- **Tokens de Salida (Completion):** ${totalOutput.toLocaleString()} tokens
|
|
216
|
+
- **Modelos de IA Participantes:** ${Array.from(models).join(", ") || "Ninguno registrado"}
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
*Reporte autogenerado de forma atómica al cierre de la tarea por sdd_archive_and_commit.*
|
|
220
|
+
`;
|
|
221
|
+
fs.writeFileSync(path.join(projectRoot, ".openspec/changes", args.changeName, "token_usage.md"), tokenUsageMarkdown, "utf-8");
|
|
222
|
+
report.push(`✓ Reporte de telemetría de tokens generado con éxito en token_usage.md`);
|
|
223
|
+
}
|
|
224
|
+
catch (e) {
|
|
225
|
+
report.push(`⚠️ No se pudo generar el reporte de telemetría de tokens: ${e.message}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
188
228
|
// 6. Archivar la carpeta físicamente (ANTES del commit para que quede registrado de forma atómica)
|
|
189
229
|
// Calcular el siguiente prefijo de secuencia cronológica (ej: 0001_2026-05-30_143015)
|
|
190
230
|
let seqPrefix = "0001";
|
package/package.json
CHANGED
|
@@ -184,6 +184,48 @@ export default tool({
|
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
+
// 5.5. Generar reporte dedicado de tokens y costes para este cambio
|
|
188
|
+
const historyPath = path.join(projectRoot, ".openspec/changes", args.changeName, "phase_history.jsonl");
|
|
189
|
+
if (fs.existsSync(historyPath)) {
|
|
190
|
+
try {
|
|
191
|
+
const lines = fs.readFileSync(historyPath, "utf-8").split("\n").filter(Boolean);
|
|
192
|
+
const entries = lines.map(l => JSON.parse(l));
|
|
193
|
+
let totalCost = 0;
|
|
194
|
+
let totalInput = 0;
|
|
195
|
+
let totalOutput = 0;
|
|
196
|
+
const models = new Set<string>();
|
|
197
|
+
|
|
198
|
+
entries.forEach((e: any) => {
|
|
199
|
+
if (e.analytics) {
|
|
200
|
+
totalCost = Math.max(totalCost, e.analytics.cumulative_cost_usd || 0);
|
|
201
|
+
totalInput = Math.max(totalInput, e.analytics.cumulative_tokens_input || 0);
|
|
202
|
+
totalOutput = Math.max(totalOutput, e.analytics.cumulative_tokens_output || 0);
|
|
203
|
+
if (Array.isArray(e.analytics.models_used)) {
|
|
204
|
+
e.analytics.models_used.forEach((m: string) => models.add(m));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
const tokenUsageMarkdown = `# 💳 Reporte de Consumo del Cambio: ${args.changeName}
|
|
210
|
+
|
|
211
|
+
Este reporte detalla la telemetría de tokens y coste financiero en USD acumulado por el enjambre de agentes durante el desarrollo de esta tarea.
|
|
212
|
+
|
|
213
|
+
## 📊 Métricas de Consumo
|
|
214
|
+
- **Coste Total de la Sesión:** $${totalCost.toFixed(4)} USD
|
|
215
|
+
- **Tokens de Entrada (Prompt):** ${totalInput.toLocaleString()} tokens
|
|
216
|
+
- **Tokens de Salida (Completion):** ${totalOutput.toLocaleString()} tokens
|
|
217
|
+
- **Modelos de IA Participantes:** ${Array.from(models).join(", ") || "Ninguno registrado"}
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
*Reporte autogenerado de forma atómica al cierre de la tarea por sdd_archive_and_commit.*
|
|
221
|
+
`;
|
|
222
|
+
fs.writeFileSync(path.join(projectRoot, ".openspec/changes", args.changeName, "token_usage.md"), tokenUsageMarkdown, "utf-8");
|
|
223
|
+
report.push(`✓ Reporte de telemetría de tokens generado con éxito en token_usage.md`);
|
|
224
|
+
} catch (e: any) {
|
|
225
|
+
report.push(`⚠️ No se pudo generar el reporte de telemetría de tokens: ${e.message}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
187
229
|
// 6. Archivar la carpeta físicamente (ANTES del commit para que quede registrado de forma atómica)
|
|
188
230
|
// Calcular el siguiente prefijo de secuencia cronológica (ej: 0001_2026-05-30_143015)
|
|
189
231
|
let seqPrefix = "0001";
|