feat(plan): create a metric for execution of plans generated in plan mode (#18236)

This commit is contained in:
Adib234
2026-02-05 18:46:34 -05:00
committed by GitHub
parent 83c6342e6e
commit 4ffc349c18
8 changed files with 173 additions and 2 deletions

View File

@@ -15,6 +15,11 @@ import { ApprovalMode } from '../policy/types.js';
import * as fs from 'node:fs';
import os from 'node:os';
import { validatePlanPath } from '../utils/planUtils.js';
import * as loggers from '../telemetry/loggers.js';
vi.mock('../telemetry/loggers.js', () => ({
logPlanExecution: vi.fn(),
}));
describe('ExitPlanModeTool', () => {
let tool: ExitPlanModeTool;
@@ -288,6 +293,30 @@ Ask the user for specific feedback on how to improve the plan.`,
});
});
it('should log plan execution event when plan is approved', async () => {
const planRelativePath = createPlanFile('test.md', '# Content');
const invocation = tool.build({ plan_path: planRelativePath });
const confirmDetails = await invocation.shouldConfirmExecute(
new AbortController().signal,
);
if (confirmDetails === false) return;
await confirmDetails.onConfirm(ToolConfirmationOutcome.ProceedOnce, {
approved: true,
approvalMode: ApprovalMode.AUTO_EDIT,
});
await invocation.execute(new AbortController().signal);
expect(loggers.logPlanExecution).toHaveBeenCalledWith(
mockConfig,
expect.objectContaining({
approval_mode: ApprovalMode.AUTO_EDIT,
}),
);
});
it('should return cancellation message when cancelled', async () => {
const planRelativePath = createPlanFile('test.md', '# Content');
const invocation = tool.build({ plan_path: planRelativePath });

View File

@@ -22,6 +22,8 @@ import { validatePlanPath, validatePlanContent } from '../utils/planUtils.js';
import { ApprovalMode } from '../policy/types.js';
import { checkExhaustive } from '../utils/checks.js';
import { resolveToRealPath, isSubpath } from '../utils/paths.js';
import { logPlanExecution } from '../telemetry/loggers.js';
import { PlanExecutionEvent } from '../telemetry/types.js';
/**
* Returns a human-readable description for an approval mode.
@@ -226,6 +228,8 @@ export class ExitPlanModeInvocation extends BaseToolInvocation<
this.config.setApprovalMode(newMode);
this.config.setApprovedPlanPath(resolvedPlanPath);
logPlanExecution(this.config, new PlanExecutionEvent(newMode));
const description = getApprovalModeDescription(newMode);
return {