refactor: share system run success delivery

This commit is contained in:
Peter Steinberger 2026-03-13 21:10:24 +00:00
parent a2fcaf9774
commit 8f852ef82f
1 changed files with 25 additions and 22 deletions

View File

@ -182,6 +182,25 @@ async function sendSystemRunDenied(
});
}
async function sendSystemRunCompleted(
opts: Pick<HandleSystemRunInvokeOptions, "sendExecFinishedEvent" | "sendInvokeResult">,
execution: SystemRunExecutionContext,
result: ExecFinishedResult,
payloadJSON: string,
) {
await opts.sendExecFinishedEvent({
sessionKey: execution.sessionKey,
runId: execution.runId,
commandText: execution.commandText,
result,
suppressNotifyOnExit: execution.suppressNotifyOnExit,
});
await opts.sendInvokeResult({
ok: true,
payloadJSON,
});
}
export { formatSystemRunAllowlistMissMessage } from "./exec-policy.js";
export { buildSystemRunApprovalPlan } from "./invoke-system-run-plan.js";
@ -462,17 +481,7 @@ async function executeSystemRunPhase(
return;
} else {
const result: ExecHostRunResult = response.payload;
await opts.sendExecFinishedEvent({
sessionKey: phase.sessionKey,
runId: phase.runId,
commandText: phase.commandText,
result,
suppressNotifyOnExit: phase.suppressNotifyOnExit,
});
await opts.sendInvokeResult({
ok: true,
payloadJSON: JSON.stringify(result),
});
await sendSystemRunCompleted(opts, phase.execution, result, JSON.stringify(result));
return;
}
}
@ -530,17 +539,11 @@ async function executeSystemRunPhase(
const result = await opts.runCommand(execArgv, phase.cwd, phase.env, phase.timeoutMs);
applyOutputTruncation(result);
await opts.sendExecFinishedEvent({
sessionKey: phase.sessionKey,
runId: phase.runId,
commandText: phase.commandText,
await sendSystemRunCompleted(
opts,
phase.execution,
result,
suppressNotifyOnExit: phase.suppressNotifyOnExit,
});
await opts.sendInvokeResult({
ok: true,
payloadJSON: JSON.stringify({
JSON.stringify({
exitCode: result.exitCode,
timedOut: result.timedOut,
success: result.success,
@ -548,7 +551,7 @@ async function executeSystemRunPhase(
stderr: result.stderr,
error: result.error ?? null,
}),
});
);
}
export async function handleSystemRunInvoke(opts: HandleSystemRunInvokeOptions): Promise<void> {