feat(skills): map runner outcomes into step receipts

This commit is contained in:
William Valentin
2026-02-12 19:07:13 -08:00
parent 5e5d96523e
commit 3a1bac0891
3 changed files with 120 additions and 12 deletions
+52 -3
View File
@@ -20,6 +20,7 @@ import {
toSkillInstallerExecutionStubFromPreflight,
evaluateInstallerExecutionPolicy,
toInstallerExecutionStepEnvelopes,
mergeInstallerExecutionResults,
runInstallerCommandsWithPolicy,
noOpSkillInstallerCommandRunner,
runSkillInstallAction,
@@ -347,7 +348,7 @@ describe('skills CLI helpers', () => {
it('does not invoke command runner when policy disables execution', () => {
const runner = {
run: vi.fn((_commands: string[]) => ['should-not-run']),
run: vi.fn((_commands: string[]) => [{ command: 'should-not-run', status: 'succeeded' as const }]),
};
const executed = runInstallerCommandsWithPolicy(
@@ -362,7 +363,7 @@ describe('skills CLI helpers', () => {
it('supports pluggable command runner when policy enables execution', () => {
const runner = {
run: vi.fn((commands: string[]) => commands),
run: vi.fn((commands: string[]) => commands.map((command) => ({ command, status: 'succeeded' as const }))),
};
const executed = runInstallerCommandsWithPolicy(
@@ -371,10 +372,58 @@ describe('skills CLI helpers', () => {
runner,
);
expect(executed).toEqual(['brew install jq']);
expect(executed).toEqual([{ command: 'brew install jq', status: 'succeeded' }]);
expect(runner.run).toHaveBeenCalledWith(['brew install jq']);
});
it('maps runner command results into structured per-step statuses', () => {
const attempted = [
{ installer_type: 'brew', command: 'brew install jq' },
{ installer_type: 'node', command: 'pnpm add -g zx' },
];
const results = mergeInstallerExecutionResults(
attempted,
{ confirmed: true, execution_enabled: true, reason: 'execution_disabled' },
[
{ command: 'brew install jq', status: 'succeeded', reason: 'ok' },
{ command: 'pnpm add -g zx', status: 'failed', reason: 'exit_code_1' },
],
);
expect(results).toEqual([
{
installer_type: 'brew',
command: 'brew install jq',
status: 'succeeded',
reason: 'ok',
},
{
installer_type: 'node',
command: 'pnpm add -g zx',
status: 'failed',
reason: 'exit_code_1',
},
]);
});
it('marks attempted steps failed when runner does not report a result', () => {
const results = mergeInstallerExecutionResults(
[{ installer_type: 'brew', command: 'brew install jq' }],
{ confirmed: true, execution_enabled: true, reason: 'execution_disabled' },
[],
);
expect(results).toEqual([
{
installer_type: 'brew',
command: 'brew install jq',
status: 'failed',
reason: 'runner_no_result',
},
]);
});
it('summarizes refresh counts across status and tiers', () => {
const summary = summarizeSkillsRefresh([
buildSkill({ manifest: { name: 'a', description: 'a', version: '1.0.0', tier: 'bundled' } }),
+57 -7
View File
@@ -47,13 +47,14 @@ export interface SkillInstallerExecutionStubView {
executed: string[];
reason: SkillInstallerExecutionReason;
attempted: Array<{ installer_type: string; command: string }>;
results: Array<{ installer_type: string; command: string; status: 'blocked' | 'skipped'; reason: SkillInstallerExecutionReason }>;
results: Array<{ installer_type: string; command: string; status: SkillInstallerStepStatus; reason: string }>;
wouldRun: string[];
skipped: SkillInstallerPlanView['skipped'];
}
export type SkillInstallActionMode = 'plan-only' | 'stub' | 'install';
export type SkillInstallerExecutionReason = 'execution_disabled' | 'confirmation_required';
export type SkillInstallerStepStatus = 'blocked' | 'skipped' | 'succeeded' | 'failed';
export interface SkillInstallerExecutionPolicy {
confirmed: boolean;
@@ -62,11 +63,17 @@ export interface SkillInstallerExecutionPolicy {
}
export interface SkillInstallerCommandRunner {
run(commands: string[]): string[];
run(commands: string[]): SkillInstallerCommandRunResult[];
}
export interface SkillInstallerCommandRunResult {
command: string;
status: 'succeeded' | 'failed';
reason?: string;
}
export const noOpSkillInstallerCommandRunner: SkillInstallerCommandRunner = {
run(_commands: string[]): string[] {
run(_commands: string[]): SkillInstallerCommandRunResult[] {
return [];
},
};
@@ -83,8 +90,7 @@ export function toInstallerExecutionStepEnvelopes(
command: step.command,
}));
const status: SkillInstallerExecutionStubView['results'][number]['status'] =
policy.reason === 'confirmation_required' ? 'blocked' : 'skipped';
const status: SkillInstallerStepStatus = policy.reason === 'confirmation_required' ? 'blocked' : 'skipped';
const results = attempted.map((step) => ({
installer_type: step.installer_type,
@@ -96,6 +102,44 @@ export function toInstallerExecutionStepEnvelopes(
return { attempted, results };
}
export function mergeInstallerExecutionResults(
attempted: SkillInstallerExecutionStubView['attempted'],
policy: SkillInstallerExecutionPolicy,
commandResults: SkillInstallerCommandRunResult[],
): SkillInstallerExecutionStubView['results'] {
if (!policy.execution_enabled) {
const blockedStatus: SkillInstallerStepStatus = policy.reason === 'confirmation_required' ? 'blocked' : 'skipped';
return attempted.map((step) => ({
installer_type: step.installer_type,
command: step.command,
status: blockedStatus,
reason: policy.reason,
}));
}
const resultByCommand = new Map(commandResults.map((result) => [result.command, result]));
return attempted.map((step) => {
const commandResult = resultByCommand.get(step.command);
if (!commandResult) {
return {
installer_type: step.installer_type,
command: step.command,
status: 'failed' as const,
reason: 'runner_no_result',
};
}
return {
installer_type: step.installer_type,
command: step.command,
status: commandResult.status,
reason:
commandResult.reason ??
(commandResult.status === 'succeeded' ? 'runner_reported_success' : 'runner_reported_failure'),
};
});
}
export function toSkillListRows(skills: Skill[]): SkillListRow[] {
return skills
.map((skill) => ({
@@ -318,7 +362,7 @@ export function runInstallerCommandsWithPolicy(
commands: string[],
policy: SkillInstallerExecutionPolicy,
runner: SkillInstallerCommandRunner,
): string[] {
): SkillInstallerCommandRunResult[] {
if (!policy.execution_enabled) {
return [];
}
@@ -490,11 +534,17 @@ export function runSkillInstallAction(
skipped: [],
};
execution.executed = runInstallerCommandsWithPolicy(
const commandResults = runInstallerCommandsWithPolicy(
execution.wouldRun,
installPolicy,
opts.commandRunner ?? noOpSkillInstallerCommandRunner,
);
execution.executed = commandResults.map((result) => result.command);
execution.results = mergeInstallerExecutionResults(
execution.attempted,
installPolicy,
commandResults,
);
if (opts.asJson) {
console.log(