Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,23 @@ export async function runCommand(
if (squad) {
await track(Events.CLI_RUN, { type: 'squad', target: squad.name });
await flushEvents(); // Ensure telemetry is sent before potential exit
await runSquad(squad, squadsDir, options);
// Post-run COO evaluation (default on, --no-eval to skip)
await runPostEvaluation([squad.name], options);
const runStartMs = Date.now();
let hadError = false;
try {
await runSquad(squad, squadsDir, options);
// Post-run COO evaluation (default on, --no-eval to skip)
await runPostEvaluation([squad.name], options);
} catch (err) {
hadError = true;
throw err;
} finally {
await track(Events.CLI_RUN_COMPLETE, {
exit_code: hadError ? 1 : 0,
duration_ms: Date.now() - runStartMs,
agent_count: squad.agents?.length ?? 1,
had_error: hadError,
});
}
} else {
// Try to find as an agent
const agents = listAgents(squadsDir);
Expand All @@ -371,9 +385,23 @@ export async function runCommand(
const pathParts = agent.filePath.split('/');
const squadIdx = pathParts.indexOf('squads');
const resolvedSquadName = squadIdx >= 0 ? pathParts[squadIdx + 1] : 'unknown';
await runAgent(agent.name, agent.filePath, resolvedSquadName, options);
// Post-run COO evaluation for the squad this agent belongs to
await runPostEvaluation([resolvedSquadName], options);
const runStartMs = Date.now();
let hadError = false;
try {
await runAgent(agent.name, agent.filePath, resolvedSquadName, options);
// Post-run COO evaluation for the squad this agent belongs to
await runPostEvaluation([resolvedSquadName], options);
} catch (err) {
hadError = true;
throw err;
} finally {
await track(Events.CLI_RUN_COMPLETE, {
exit_code: hadError ? 1 : 0,
duration_ms: Date.now() - runStartMs,
agent_count: 1,
had_error: hadError,
});
}
} else {
writeLine(` ${colors.red}Squad or agent "${target}" not found${RESET}`);
const similar = findSimilarSquads(target, listSquads(squadsDir));
Expand Down
1 change: 1 addition & 0 deletions src/lib/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ export const Events = {

// Commands
CLI_RUN: 'cli.run',
CLI_RUN_COMPLETE: 'cli.run.complete',
CLI_STATUS: 'cli.status',
CLI_DASHBOARD: 'cli.dashboard',
CLI_WORKERS: 'cli.workers',
Expand Down
1 change: 1 addition & 0 deletions test/telemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('telemetry', () => {

it('has command events', () => {
expect(Events.CLI_RUN).toBe('cli.run');
expect(Events.CLI_RUN_COMPLETE).toBe('cli.run.complete');
expect(Events.CLI_STATUS).toBe('cli.status');
expect(Events.CLI_DASHBOARD).toBe('cli.dashboard');
});
Expand Down
Loading