fix(persistent-bash): distinguish shell exit status

This commit is contained in:
Tianyi Cui
2026-07-30 00:15:39 +08:00
parent 9b9d3838ba
commit 9549c73f30
11 changed files with 82 additions and 42 deletions

View File

@@ -174,21 +174,28 @@ function renderCaptured(output: CapturedOutput, maxOutputChars: number): string
const withPrefix = output.incomplete && output.text.length > 0
? LOST_PREFIX_MESSAGE + rendered
: rendered
return renderExitStatus(withPrefix, output.exitCode ?? 0, null)
const marker = output.exitCode !== undefined && output.exitCode !== 0
? `[exit code: ${output.exitCode}]`
: undefined
return appendStatusMarker(withPrefix, marker)
}
function renderExitStatus(
function appendStatusMarker(content: string, marker: string | undefined): string {
if (marker === undefined) return content
return content.length === 0 ? marker : `${content}\n${marker}`
}
function renderShellExitStatus(
content: string,
exitCode: number | null,
signal: NodeJS.Signals | null,
): string {
const marker = signal !== null
? `[killed by signal: ${signal}]`
: exitCode !== null && exitCode !== 0
? `[exit code: ${exitCode}]`
: undefined
if (marker === undefined) return content
return content.length === 0 ? marker : `${content}\n${marker}`
? `[shell killed by signal: ${signal}]`
: exitCode !== null
? `[shell exited: code ${exitCode}]`
: '[shell exited]'
return appendStatusMarker(content, marker)
}
function persistentShells(ctx: Context, config: ResolvedConfig): PersistentShells {
@@ -325,7 +332,7 @@ async function executeCommand(
const snapshot = retainedScrollback(ctx, owner, id, latest)
await shells.reset(owner, 'persistent bash shell exited')
return [
renderExitStatus(
renderShellExitStatus(
renderCaptured(partialOutput(snapshot, marker, fallback, fallbackTruncated), config.maxOutputChars),
result.sessionStatus.exitCode,
result.sessionStatus.signal,