From 8f852ef82fe9f56a0197941c272d3db47906b297 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 13 Mar 2026 21:10:24 +0000 Subject: [PATCH] refactor: share system run success delivery --- src/node-host/invoke-system-run.ts | 47 ++++++++++++++++-------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/node-host/invoke-system-run.ts b/src/node-host/invoke-system-run.ts index 3730e3b2824..32bd2d6ff79 100644 --- a/src/node-host/invoke-system-run.ts +++ b/src/node-host/invoke-system-run.ts @@ -182,6 +182,25 @@ async function sendSystemRunDenied( }); } +async function sendSystemRunCompleted( + opts: Pick, + 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 {