mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-19 17:11:42 -06:00
44 lines
1.8 KiB
TypeScript
44 lines
1.8 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 authoritative process exit without inventing a successful code. */
|
|
export function renderExecExitLabel(exit: {
|
|
exitCode?: number | null;
|
|
exitSignal?: NodeJS.Signals | number | null;
|
|
}): string {
|
|
if (exit.exitSignal != null) {
|
|
return `signal ${exit.exitSignal}`;
|
|
}
|
|
return typeof exit.exitCode === "number" ? `code ${exit.exitCode}` : "unknown exit code";
|
|
}
|
|
|
|
/** 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}`;
|
|
}
|