Files
openclaw/src/agents/bash-tools.exec-output.ts
T
litang9 b15718f8d3 fix: warn before retrying timed-out exec commands (#111390)
* fix: warn before retrying timed-out exec commands

* fix(exec): cover detached approval timeout followups

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-07-19 09:31:40 -07:00

33 lines
1.4 KiB
TypeScript

/**
* Rendering helpers for exec output/status updates.
* Keeps no-output placeholders and warning placement consistent across exec
* progress, polling, and completion surfaces.
*/
import type { TerminationReason } from "../process/supervisor/types.js";
const EXEC_NO_OUTPUT_PLACEHOLDER = "(no output)";
const EXEC_TIMEOUT_RETRY_GUIDANCE =
"The command was terminated, but external side effects may already have completed. Verify the resulting state before retrying. Do not automatically rerun non-idempotent commands. Use a higher timeout only when the command is known to be safe to retry.";
/** Render command output with a stable placeholder for empty output. */
export function renderExecOutputText(value: string | undefined): string {
return value || EXEC_NO_OUTPUT_PLACEHOLDER;
}
/** Render the text shown in exec progress updates, including warnings first. */
export function renderExecUpdateText(params: { tailText?: string; warnings: string[] }): string {
const warningText = params.warnings.length ? `${params.warnings.join("\n")}\n\n` : "";
return warningText + renderExecOutputText(params.tailText);
}
/** Add retry-safety guidance only for supervisor timeout exits. */
export function appendExecTimeoutRetryGuidance(
text: string,
exitReason: TerminationReason | undefined,
): string {
if (exitReason !== "overall-timeout" && exitReason !== "no-output-timeout") {
return text;
}
return `${text}\n\n${EXEC_TIMEOUT_RETRY_GUIDANCE}`;
}