Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🚦 feat: Show Exit Status and Stderr for Attached Workspace Commands (#16556)
Marco Berettaea938f6054b1
diff --git a/api/server/controllers/agents/callbacks.js b/api/server/controllers/agents/callbacks.jsindex cba7336418..b28907bb9f 100644--- a/api/server/controllers/agents/callbacks.js+++ b/api/server/controllers/agents/callbacks.js@@ -35,7 +35,7 @@ const {captureSubagentIdentity,getAttachmentOwnership,collectToolCallIds,- createToolTimingAdapter,+ stampCommandExecutor,} = require('@librechat/api');const { processFileCitations } = require('~/server/services/Files/Citations');const { processCodeOutput, runPreviewFinalize } = require('~/server/services/Files/Code/process');@@ -674,6 +674,7 @@ function getDefaultHandlers({toolCall.inputValidationError = true;}}+ stampCommandExecutor(toolExecuteOptions?.attachedCommandStepIds, data?.result, toolCall);if (data?.result != null) {await emitForJob({ event, data });} else if (checkIfLastAgent(metadata?.last_agent_id, metadata?.langgraph_node)) {diff --git a/api/server/services/Endpoints/agents/initialize.js b/api/server/services/Endpoints/agents/initialize.jsindex 83420383ba..df95bd051d 100644--- a/api/server/services/Endpoints/agents/initialize.js+++ b/api/server/services/Endpoints/agents/initialize.js@@ -445,6 +445,7 @@ const initializeClientWithProvider = async ({// is composed with this authoritative job signal by the handler.runSignal: signal,foregroundRunId,+ attachedCommandStepIds: new Set(),ordinaryToolCancellation: ordinaryToolCancellationEnabled,backgroundCompletionResultMaxChars,loadTools: async (diff --git a/client/src/components/Chat/Messages/Content/Part.tsx b/client/src/components/Chat/Messages/Content/Part.tsxindex 76aadac61a..8c6f767e19 100644--- a/client/src/components/Chat/Messages/Content/Part.tsx+++ b/client/src/components/Chat/Messages/Content/Part.tsx@@ -413,6 +413,7 @@ const Part = memo(function Part({runStepDurationMs={toolCall.runStepDurationMs}backgrounded={toolCall.backgrounded}backgroundCancelled={toolCall.backgroundTask?.cancelled === true}+ executor={toolCall.executor}attachments={attachments}hideAttachments={hideAttachments}onExpand={onToolExpand}diff --git a/client/src/components/Chat/Messages/Content/Parts/BashCall.tsx b/client/src/components/Chat/Messages/Content/Parts/BashCall.tsxindex 81d05dd18e..2cae8f90fb 100644--- a/client/src/components/Chat/Messages/Content/Parts/BashCall.tsx+++ b/client/src/components/Chat/Messages/Content/Parts/BashCall.tsx@@ -15,6 +15,7 @@ import useFollowScroll from './useFollowScroll';import { OutputRenderer } from '../ToolOutput';import { ERROR_PATTERNS } from './ExecuteCode';import { AttachmentGroup } from './Attachment';+import { parseCommandOutput } from './command';import { useToolCallIntent } from './intent';import { TOOL_ROW_CLASSES } from '../rows';import PtcToolTrace from './PtcToolTrace';@@ -30,6 +31,7 @@ export default function BashCall({runStepDurationMs,backgrounded,backgroundCancelled = false,+ executor,initialProgress = 0.1,args,output = '',@@ -45,6 +47,7 @@ export default function BashCall({runStepDurationMs?: PartMetadata['runStepDurationMs'];backgrounded?: PartMetadata['backgrounded'];backgroundCancelled?: boolean;+ executor?: PartMetadata['executor'];args?: string | Record<string, unknown>;output?: string;attachments?: TAttachment[];@@ -58,8 +61,41 @@ export default function BashCall({const isWritingCommand = !command || !areToolCallArgsComplete(args);const sandboxStarting = useAtomValue(sandboxStartingByToolCallId(toolCallId ?? ''));+ /** Only a call the server stamped as attached-workspace carries an exit+ * status trailer; sandbox output keeps the text heuristic even when it+ * prints something that looks like one. */+ const result = useMemo(+ () => (executor === 'attached_workspace' ? parseCommandOutput(output) : null),+ [executor, output],+ );const outputHasError = useMemo(() => ERROR_PATTERNS.test(output), [output]);const outputIsEmpty = output.trim() === SANDBOX_EMPTY_OUTPUT;+ const verdict = (() => {+ if (result?.timedOut === true) {+ return localize('com_ui_command_timed_out');+ }+ if (result?.signal != null) {+ return localize('com_ui_command_terminated', { 0: result.signal });+ }+ if (result?.failed === true && result.exitCode != null) {+ return localize('com_ui_command_exit_code', { 0: String(result.exitCode) });+ }+ return undefined;+ })();+ const outputSegments = useMemo(+ () =>+ result == null+ ? undefined+ : [+ { text: result.head },+ {+ text: result.stderr,+ className: result.failed ? 'text-status-error' : 'text-text-secondary',+ },+ { text: result.trailer, className: 'text-text-tertiary' },+ ],+ [result],+ );/** A backgrounded call's persisted output stays the dispatch handle until* the detached run settles and patches it; render a background state* instead of the handle JSON. Completion arrives live as the status marker@@ -91,7 +127,7 @@ export default function BashCall({hasInput: !!command,onExpand,runStepStatus,- extraError: backgroundFailed,+ extraError: backgroundFailed || result?.failed === true,extraCancelled: cancelledInBackground,});@@ -163,6 +199,7 @@ export default function BashCall({}hasInput={!!command || hasOutput}isExpanded={showCode}+ verdict={verdict}/></div><div style={expandStyle}>@@ -220,7 +257,8 @@ export default function BashCall({<OutputRenderertext={output}copyText={output}- error={outputHasError}+ error={result == null && outputHasError}+ segments={outputSegments}variant="terminal"/>)}diff --git a/client/src/components/Chat/Messages/Content/Parts/__tests__/BashCall.test.tsx b/client/src/components/Chat/Messages/Content/Parts/__tests__/BashCall.test.tsxindex a70d0c9b09..3e0276e4b5 100644--- a/client/src/components/Chat/Messages/Content/Parts/__tests__/BashCall.test.tsx+++ b/client/src/components/Chat/Messages/Content/Parts/__tests__/BashCall.test.tsx@@ -8,8 +8,11 @@ import store from '~/store';jest.mock('~/hooks', () => ({useLocalize:() =>- (key: string): string => {+ (key: string, values?: Record<string, string>): string => {const translations: Record<string, string> = {+ com_ui_command_exit_code: `exit code ${values?.[0]}`,+ com_ui_command_terminated: `terminated by ${values?.[0]}`,+ com_ui_command_timed_out: 'timed out',com_ui_writing_command: 'Writing command',com_ui_running_command: 'Running command',com_ui_command_finished: 'Finished running',@@ -44,14 +47,17 @@ jest.mock('~/components/Chat/Messages/Content/ProgressText', () => ({phase,inProgressText,finishedText,+ verdict,}: {phase: 'running' | 'completed' | 'cancelled' | 'failed';inProgressText: string;finishedText: string;+ verdict?: string;}) => (<div data-testid="progress-text">{phase === 'running' ? inProgressText : finishedText}{phase === 'failed' ? ' — tool failed' : ''}+ {phase === 'failed' && verdict ? ` · ${verdict}` : ''}</div>),}));@@ -498,3 +504,67 @@ describe('BashCall output pane', () => {expect(code).toHaveClass('!text-xs', '!whitespace-pre-wrap', '!break-words');});});++describe('BashCall exit status', () => {+ const renderSettled = (output: string, attached = true) =>+ render(+ <RecoilRoot>+ <BashCall+ initialProgress={1}+ isSubmitting={false}+ runStepStatus="completed"+ args={{ command: 'make test' }}+ output={output}+ executor={attached ? 'attached_workspace' : undefined}+ />+ </RecoilRoot>,+ );++ it('does not read a trailer the sandbox command printed itself', () => {+ const { container } = renderSettled('stdout:\n[exit code: 1]', false);+ expect(screen.getByTestId('progress-text')).toHaveTextContent('Finished running');+ expect(screen.getByTestId('progress-text')).not.toHaveTextContent('tool failed');+ expect(container.querySelectorAll('pre')[1]).toHaveTextContent('[exit code: 1]');+ });++ it('fails the same output when the server marked it attached-workspace', () => {+ renderSettled('stdout:\n[exit code: 1]');+ expect(screen.getByTestId('progress-text')).toHaveTextContent(/tool failed · exit code 1$/);+ });++ it('fails a non-zero exit even when the output matches no error pattern', () => {+ renderSettled('stdout:\n1 test failed\n\n[exit code: 2]');+ expect(screen.getByTestId('progress-text')).toHaveTextContent(/tool failed · exit code 2$/);+ });++ it('keeps a zero exit successful even when stderr reads like an error', () => {+ const { container } = renderSettled(+ 'stdout:\nok\n\nstderr:\nError: deprecated flag\n\n[exit code: 0]',+ );+ expect(screen.getByTestId('progress-text')).toHaveTextContent('Finished running');+ expect(screen.getByTestId('progress-text')).not.toHaveTextContent('tool failed');+ const stderr = screen.getByText(/deprecated flag/);+ expect(stderr).toHaveClass('text-text-secondary');+ expect(container.querySelectorAll('pre')[1]).toHaveClass('text-text-primary');+ expect(container.querySelectorAll('pre')[1]).toHaveTextContent('stdout: ok');+ });++ it('marks stderr as an error on a failed run', () => {+ renderSettled('stderr:\nboom\n\n[exit code: 1]');+ expect(screen.getByText(/boom/)).toHaveClass('text-status-error');+ });++ it.each([+ ['stdout:\nsleeping\n\n[terminated by SIGKILL][timed out]', 'timed out'],+ ['Command completed with no output.\n[terminated by SIGTERM]', 'terminated by SIGTERM'],+ ])('names the reason for a stopped command: %s', (output, reason) => {+ renderSettled(output);+ expect(screen.getByTestId('progress-text')).toHaveTextContent(`tool failed · ${reason}`);+ });++ it('keeps the text heuristic for sandbox output without an exit trailer', () => {+ const { container } = renderSettled('stdout:\nTraceback (most recent call last)\n', false);+ expect(screen.getByTestId('progress-text')).not.toHaveTextContent('tool failed');+ expect(container.querySelectorAll('pre')[1]).toHaveClass('text-status-error');+ });+});diff --git a/client/src/components/Chat/Messages/Content/Parts/__tests__/command.test.ts b/client/src/components/Chat/Messages/Content/Parts/__tests__/command.test.tsnew file mode 100644index 0000000000..73507ae504--- /dev/null+++ b/client/src/components/Chat/Messages/Content/Parts/__tests__/command.test.ts@@ -0,0 +1,47 @@+import { parseCommandOutput } from '../command';++describe('parseCommandOutput', () => {+ it('reads a successful run', () => {+ const output = 'stdout:\nready\n\n[exit code: 0]';+ expect(parseCommandOutput(output)).toEqual({+ exitCode: 0,+ signal: null,+ timedOut: false,+ truncated: false,+ failed: false,+ head: 'stdout:\nready\n\n',+ stderr: '',+ trailer: '[exit code: 0]',+ });+ });++ it('splits stderr and fails a non-zero exit', () => {+ const output = 'stdout:\nok\n\nstderr:\nboom\n\n[exit code: 2][output truncated]';+ const result = parseCommandOutput(output);+ expect(result).toMatchObject({ exitCode: 2, failed: true, truncated: true });+ expect(result?.head).toBe('stdout:\nok\n\n');+ expect(result?.stderr).toBe('stderr:\nboom\n\n');+ expect(`${result?.head}${result?.stderr}${result?.trailer}`).toBe(output);+ });++ it('reads stderr-only, signal and timeout runs', () => {+ expect(+ parseCommandOutput('stderr:\nkilled\n\n[terminated by SIGKILL][timed out]'),+ ).toMatchObject({ exitCode: null, signal: 'SIGKILL', timedOut: true, failed: true, head: '' });+ expect(parseCommandOutput('Command completed with no output.\n[exit code: 1]')).toMatchObject({+ exitCode: 1,+ failed: true,+ stderr: '',+ });+ });++ it('returns null for output without the attached-workspace trailer', () => {+ expect(parseCommandOutput('stdout:\nhello\n')).toBeNull();+ expect(parseCommandOutput('')).toBeNull();+ expect(parseCommandOutput('Error: rate limited\n[exit code: 1]')).toBeNull();+ });++ it('ignores a marker the command printed itself', () => {+ expect(parseCommandOutput('stdout:\n[exit code: 1]\n')).toBeNull();+ });+});diff --git a/client/src/components/Chat/Messages/Content/Parts/command.ts b/client/src/components/Chat/Messages/Content/Parts/command.tsnew file mode 100644index 0000000000..5448de74d7--- /dev/null+++ b/client/src/components/Chat/Messages/Content/Parts/command.ts@@ -0,0 +1,74 @@+/**+ * Reads the verdict the attached-workspace `bash_tool` writes into its output+ * (`formatCommandResult` in `packages/api/src/code/command.ts`):+ *+ * stdout:\n<out>\n stderr:\n<err>\n [exit code: N][terminated by SIG][timed out][output truncated]+ *+ * The text alone does not prove where it came from: the sandbox `bash_tool`+ * shares the name and trims its output, so a sandbox command that prints+ * `[exit code: 1]` last yields the same shape. Callers must only parse output+ * of a call whose server-stamped `executor` is `attached_workspace`, and keep+ * the text heuristics otherwise.+ */+export interface CommandOutput {+ exitCode: number | null;+ signal: string | null;+ timedOut: boolean;+ truncated: boolean;+ /** Non-zero exit, a terminating signal or a timeout. */+ failed: boolean;+ /** `head + stderr + trailer === output`, so a renderer can style each part+ * without dropping any text. `head` is the stdout section (or the+ * no-output notice), `stderr` the stderr section with its label. */+ head: string;+ stderr: string;+ trailer: string;+}++const TRAILER =+ /\n((?:\[(?:exit code: -?\d+|terminated by [\w+-]+|timed out|output truncated)\])+)$/;+const MARKER = /\[(exit code: (-?\d+)|terminated by ([\w+-]+)|timed out|output truncated)\]/g;+const STDOUT = 'stdout:\n';+const STDERR = 'stderr:\n';+const EMPTY = 'Command completed with no output.\n';++export function parseCommandOutput(output: string): CommandOutput | null {+ const match = TRAILER.exec(output);+ if (match == null) {+ return null;+ }+ const body = output.slice(0, match.index + 1);+ if (!body.startsWith(STDOUT) && !body.startsWith(STDERR) && body !== EMPTY) {+ return null;+ }+ let exitCode: number | null = null;+ let signal: string | null = null;+ let timedOut = false;+ let truncated = false;+ for (const [, marker, code, name] of match[1].matchAll(MARKER)) {+ if (code != null) {+ exitCode = Number(code);+ } else if (name != null) {+ signal = name;+ } else if (marker === 'timed out') {+ timedOut = true;+ } else {+ truncated = true;+ }+ }+ /** The last label wins: output that itself prints `stderr:` is ambiguous,+ * and styling too little as stderr is the safer mistake. Either way no+ * text is dropped. */+ const labelAt = body.startsWith(STDERR) ? 0 : body.lastIndexOf(`\n${STDERR}`) + 1;+ const split = labelAt > 0 || body.startsWith(STDERR) ? labelAt : body.length;+ return {+ exitCode,+ signal,+ timedOut,+ truncated,+ failed: (exitCode != null && exitCode !== 0) || signal != null || timedOut,+ head: body.slice(0, split),+ stderr: body.slice(split),+ trailer: match[1],+ };+}diff --git a/client/src/components/Chat/Messages/Content/ProgressText.tsx b/client/src/components/Chat/Messages/Content/ProgressText.tsxindex 7a37b93cac..746c003b34 100644--- a/client/src/components/Chat/Messages/Content/ProgressText.tsx+++ b/client/src/components/Chat/Messages/Content/ProgressText.tsx@@ -76,6 +76,7 @@ export default function ProgressText({hasInput = true,popover = false,isExpanded = false,+ verdict,}: {/*** The card's settled state, resolved once by the caller via@@ -101,6 +102,9 @@ export default function ProgressText({hasInput?: boolean;popover?: boolean;isExpanded?: boolean;+ /** Why a failed card failed ("exit code 2"), shown after the failure+ * suffix. Plain text inside the button, so it is part of its name. */+ verdict?: string;}) {const localize = useLocalize();/** For locale-aware decimal formatting of the sub-10s duration value. */@@ -241,7 +245,9 @@ export default function ProgressText({{errorSuffix && (<span className="shrink-0 font-normal text-status-error">· {errorSuffix}</span>)}- {errorSuffix && <span className="text-status-error font-normal">· {errorSuffix}</span>}+ {errorSuffix && verdict && (+ <span className="text-text-secondary shrink-0 font-normal">· {verdict}</span>+ )}{duration && (<>{/* The compact form is the readable one on screen but a poordiff --git a/client/src/components/Chat/Messages/Content/ToolOutput/OutputRenderer.tsx b/client/src/components/Chat/Messages/Content/ToolOutput/OutputRenderer.tsxindex 4a3c652dc8..6d9a006796 100644--- a/client/src/components/Chat/Messages/Content/ToolOutput/OutputRenderer.tsx+++ b/client/src/components/Chat/Messages/Content/ToolOutput/OutputRenderer.tsx@@ -103,6 +103,37 @@ function extractText(raw: string, verbatim = false): ExtractedText {const TRUNCATE_LINES = 20;const VISIBLE_LINES = 15;+export interface OutputSegment {+ text: string;+ className?: string;+}++/** The last `count` lines of `segments`, keeping each line's own styling. */+function tailSegments(segments: OutputSegment[], count: number): OutputSegment[] {+ const tail: OutputSegment[] = [];+ /** Matches the line count: a final newline ends the last line rather than starting one. */+ const last = segments.findLast((segment) => segment.text !== '');+ let newlines = last?.text.endsWith('\n') === true ? -1 : 0;+ for (let i = segments.length - 1; i >= 0; i--) {+ const { text, className } = segments[i];+ let cut = text.length;+ while (cut > 0) {+ const at = text.lastIndexOf('\n', cut - 1);+ if (at < 0) {+ break;+ }+ newlines++;+ if (newlines >= count) {+ tail.unshift({ text: text.slice(at + 1), className });+ return tail;+ }+ cut = at;+ }+ tail.unshift({ text, className });+ }+ return tail;+}+interface OutputRendererProps {text: string;copyText?: string;@@ -111,6 +142,9 @@ interface OutputRendererProps {/** `terminal` renders command output: monospace, verbatim (no JSON reformatting), and the* collapsed view keeps the LAST lines, where failures and stack traces land. */variant?: 'default' | 'terminal';+ /** Terminal output split into styled runs whose texts join to `text` (for example stdout,+ * stderr and an exit trailer). Rendered in place of the plain text. */+ segments?: OutputSegment[];}export default function OutputRenderer({@@ -118,6 +152,7 @@ export default function OutputRenderer({copyText,error: forceError = false,variant = 'default',+ segments,}: OutputRendererProps) {const localize = useLocalize();const terminal = variant === 'terminal';@@ -145,6 +180,9 @@ export default function OutputRenderer({const collapsedLines = terminal ? lines.slice(-VISIBLE_LINES) : lines.slice(0, VISIBLE_LINES);const visibleText = needsTruncation && !isExpanded ? collapsedLines.join('\n') : displayText;const structured = !isJson && (terminal || isStructuredText(displayText));+ const styled = terminal && segments != null && !error;+ const visibleSegments =+ styled && needsTruncation && !isExpanded ? tailSegments(segments, VISIBLE_LINES) : segments;return (<div>@@ -165,7 +203,15 @@ export default function OutputRenderer({!error && !structured && 'text-text-primary font-sans text-sm',)}>- {visibleText}+ {styled+ ? visibleSegments?.map((segment, i) =>+ segment.text === '' ? null : (+ <span key={i} className={segment.className}>+ {segment.text}+ </span>+ ),+ )+ : visibleText}</pre>)}<div className="absolute top-1/2 right-0 -translate-y-1/2">diff --git a/client/src/components/Chat/Messages/Content/ToolOutput/__tests__/OutputRenderer.test.tsx b/client/src/components/Chat/Messages/Content/ToolOutput/__tests__/OutputRenderer.test.tsxindex 619433e1e6..2cb2d9f50b 100644--- a/client/src/components/Chat/Messages/Content/ToolOutput/__tests__/OutputRenderer.test.tsx+++ b/client/src/components/Chat/Messages/Content/ToolOutput/__tests__/OutputRenderer.test.tsx@@ -62,6 +62,37 @@ describe('OutputRenderer', () => {expect(shown[0]).toBe('line 16');});+ it('keeps segment styling when collapsing terminal output to its tail', () => {+ const out = Array.from({ length: 25 }, (_, i) => `out ${i + 1}`).join('\n') + '\n';+ const err = 'stderr:\nboom\n';+ const trailer = '[exit code: 1]';+ render(+ <OutputRenderer+ text={out + err + trailer}+ variant="terminal"+ segments={[+ { text: out },+ { text: err, className: 'text-status-error' },+ { text: trailer, className: 'text-text-tertiary' },+ ]}+ />,+ );+ const pre = screen.getByText(/out 25/).closest('pre') as HTMLElement;+ const shown = (pre.textContent ?? '').split('\n');+ expect(shown).toHaveLength(15);+ expect(shown[0]).toBe('out 14');+ expect(screen.getByText(/boom/)).toHaveClass('text-status-error');+ expect(screen.getByText('[exit code: 1]')).toHaveClass('text-text-tertiary');+ });++ it('shows as many styled lines as plain lines when output ends in a newline', () => {+ const out = Array.from({ length: 30 }, (_, i) => `row ${i + 1}`).join('\n') + '\n';+ render(<OutputRenderer text={out} variant="terminal" segments={[{ text: out }]} />);+ const shown = (screen.getByText(/row 30/).closest('pre')?.textContent ?? '').split('\n');+ expect(shown.filter(Boolean)).toHaveLength(15);+ expect(shown[0]).toBe('row 16');+ });+it('does not treat text between bracketed prefixes as a tool-call error', () => {expect(isError('Error: [agent] unexpected [search] tool call failed: unavailable')).toBe(false);});diff --git a/client/src/components/Chat/Messages/Content/__tests__/ProgressText.test.tsx b/client/src/components/Chat/Messages/Content/__tests__/ProgressText.test.tsxindex 695aa0e759..e79ee8fc58 100644--- a/client/src/components/Chat/Messages/Content/__tests__/ProgressText.test.tsx+++ b/client/src/components/Chat/Messages/Content/__tests__/ProgressText.test.tsx@@ -277,3 +277,15 @@ describe('ProgressText fixed siblings', () => {expect(container.querySelector('svg')).toHaveClass('shrink-0');});});++describe('ProgressText verdict', () => {+ it('names the failure reason inside the button on a failed card', () => {+ renderProgressText({ phase: 'failed', verdict: 'exit code 2' });+ expect(screen.getByRole('button')).toHaveTextContent('· com_ui_tool_failed· exit code 2');+ });++ it('shows no verdict on a successful card', () => {+ renderProgressText({ verdict: 'exit code 2' });+ expect(screen.queryByText(/exit code 2/)).not.toBeInTheDocument();+ });+});diff --git a/client/src/components/Chat/Messages/Content/__tests__/outcome.test.ts b/client/src/components/Chat/Messages/Content/__tests__/outcome.test.tsnew file mode 100644index 0000000000..27beb63dad--- /dev/null+++ b/client/src/components/Chat/Messages/Content/__tests__/outcome.test.ts@@ -0,0 +1,47 @@+import { Tools, ContentTypes } from 'librechat-data-provider';+import type { TMessageContentParts } from 'librechat-data-provider';+import { summarizeSpan } from '../outcome';++const bashPart = (+ id: string,+ output: string,+ name: string = Tools.bash_tool,+ executor: string | null = 'attached_workspace',+) =>+ ({+ type: ContentTypes.TOOL_CALL,+ [ContentTypes.TOOL_CALL]: {+ id,+ name,+ args: { command: 'make test' },+ output,+ progress: 1,+ runStepStatus: 'completed',+ ...(executor != null && { executor }),+ },+ }) as unknown as TMessageContentParts;++describe('summarizeSpan command exit status', () => {+ it('counts a bash call that exited non-zero as failed, like its card', () => {+ const summary = summarizeSpan([+ bashPart('a', 'stdout:\nok\n\n[exit code: 0]'),+ bashPart('b', 'stdout:\n1 failing\n\n[exit code: 1]'),+ bashPart('c', 'stdout:\nslow\n\n[timed out]'),+ ]);+ expect(summary.failed).toBe(2);+ });++ it('ignores a trailer on sandbox output the server did not mark', () => {+ const sandbox = summarizeSpan([+ bashPart('a', 'stdout:\n[exit code: 1]', Tools.bash_tool, null),+ ]);+ expect(sandbox.failed).toBe(0);+ const attached = summarizeSpan([bashPart('a', 'stdout:\n[exit code: 1]')]);+ expect(attached.failed).toBe(1);+ });++ it('does not read exit trailers on tools other than bash', () => {+ const summary = summarizeSpan([bashPart('a', 'stdout:\nx\n\n[exit code: 1]', 'fetch_image')]);+ expect(summary.failed).toBe(0);+ });+});diff --git a/client/src/components/Chat/Messages/Content/outcome.ts b/client/src/components/Chat/Messages/Content/outcome.tsindex 2ec5748a04..e4899a17c9 100644--- a/client/src/components/Chat/Messages/Content/outcome.ts+++ b/client/src/components/Chat/Messages/Content/outcome.ts@@ -12,6 +12,7 @@ import { resolveToolCallPhase } from '~/utils/toolCallPhase';import { isMemoryFailureOutput } from './Parts/MemoryCall';import { filterAttachmentsForPart } from '~/utils/map';import { isBashProgrammaticToolCall } from './routing';+import { parseCommandOutput } from './Parts/command';import { isError } from './ToolOutput';/**@@ -135,7 +136,12 @@ export function getToolMeta(name === 'set_memory' || name === 'delete_memory'? isMemoryFailureOutput(name, tc.output ?? '') ||(ownAttachments ?? []).some((attachment) => attachment[Tools.memory]?.type === 'error')- : hasFailedOutput(tc.output);+ : hasFailedOutput(tc.output) ||+ /** `BashCall` fails an attached-workspace command that reports a+ * non-zero exit; only the server marker says the trailer is real. */+ (name === Tools.bash_tool &&+ toolCall.executor === 'attached_workspace' &&+ parseCommandOutput(tc.output ?? '')?.failed === true);/** A backgrounded bash/code task reports its verdict through a* `background_task_status` attachment, not its output: the dispatch step* keeps a benign handle and usually closes as `completed`. The child carddiff --git a/client/src/hooks/SSE/steps/content.ts b/client/src/hooks/SSE/steps/content.tsindex 021584e8a1..49de22d7fe 100644--- a/client/src/hooks/SSE/steps/content.ts+++ b/client/src/hooks/SSE/steps/content.ts@@ -335,6 +335,9 @@ export function updateContent() {Object.assign(newToolCall, { inputValidationError: true });}+ if (contentPart.tool_call.executor != null) {+ newToolCall.executor = contentPart.tool_call.executor;+ }}updatedContent[index] = {diff --git a/client/src/locales/en/translation.json b/client/src/locales/en/translation.jsonindex 8d7a1f18d0..f8ae64eb66 100644--- a/client/src/locales/en/translation.json+++ b/client/src/locales/en/translation.json@@ -1245,8 +1245,11 @@"com_ui_collapse_chat": "Collapse Chat","com_ui_collapse_summary": "Collapse Summary","com_ui_collapse_thoughts": "Collapse Thoughts",+ "com_ui_command_exit_code": "exit code {{0}}","com_ui_command_finished": "Finished running","com_ui_command_placeholder": "Optional: Enter a command for the prompt or name will be used",+ "com_ui_command_terminated": "terminated by {{0}}",+ "com_ui_command_timed_out": "timed out","com_ui_command_usage_placeholder": "Select a Prompt by command or name","com_ui_complete": "Complete!","com_ui_complete_setup": "Complete Setup",diff --git a/packages/api/src/agents/handlers.spec.ts b/packages/api/src/agents/handlers.spec.tsindex be417371db..09a3bb7c86 100644--- a/packages/api/src/agents/handlers.spec.ts+++ b/packages/api/src/agents/handlers.spec.ts@@ -25,7 +25,7 @@ import {import { markSandboxReady } from './prewarm';import { ContentFilterError } from '../middleware/contentFilter';import { WorkspaceToolHttpError } from '../code/workspace';-import { createAttachedWorkspaceBashTool } from '../code/command';+import { createAttachedWorkspaceBashTool, stampCommandExecutor } from '../code/command';import { createCodeApiUploadRegistry } from '~/utils';function createMockTool(@@ -9608,3 +9608,77 @@ describe('per-call onResult reporting', () => {expect(results[0].status).toBe('success');});});++type ExecutorPart = { output?: string; executor?: string };++describe('attached-workspace command provenance', () => {+ const echoTrailer = 'stdout:\n[exit code: 1]';++ function attachedTool() {+ const fetchImpl = jest.fn(+ async () =>+ new Response(+ JSON.stringify({+ protocolVersion: 1,+ operation: 'execute_command',+ workspaceId: 'project-a',+ exitCode: 1,+ stdout: 'boom\n',+ stderr: '',+ truncated: false,+ timedOut: false,+ }),+ { status: 200, headers: { 'Content-Type': 'application/json' } },+ ),+ );+ return createAttachedWorkspaceBashTool({+ baseUrl: 'https://code.example.com/v1/',+ authHeaders: () => ({}),+ workspaceId: 'project-a',+ fetchImpl,+ });+ }++ async function runStep(bashTool: unknown, stepId: string): Promise<Set<string>> {+ const attachedCommandStepIds = new Set<string>();+ const handler = createToolExecuteHandler({+ loadTools: async () => ({ loadedTools: [bashTool as never] }),+ attachedCommandStepIds,+ });+ await new Promise<ToolExecuteResult[]>((resolve, reject) => {+ handler.handle('on_tool_execute', {+ toolCalls: [{ id: `call-${stepId}`, name: 'bash_tool', args: { command: 'x' }, stepId }],+ resolve,+ reject,+ } as ToolExecuteBatchRequest);+ });+ return attachedCommandStepIds;+ }++ it('stamps the executor only for the attached-workspace bash tool', async () => {+ const attachedSteps = await runStep(attachedTool(), 'step-attached');+ expect([...attachedSteps]).toEqual(['step-attached']);+ const attachedEvent = { id: 'step-attached', tool_call: { output: 'x' } as ExecutorPart };+ const attachedPart: ExecutorPart = {};+ stampCommandExecutor(attachedSteps, attachedEvent, attachedPart);+ expect(attachedEvent.tool_call.executor).toBe('attached_workspace');+ expect(attachedPart.executor).toBe('attached_workspace');+ expect(attachedSteps.size).toBe(0);++ const sandbox = createMockTool('bash_tool', []);+ sandbox.invoke.mockResolvedValue({+ content: echoTrailer,+ artifact: { session_id: 'sandbox-session', files: [] },+ });+ const sandboxSteps = await runStep(sandbox, 'step-sandbox');+ expect(sandboxSteps.size).toBe(0);+ const sandboxEvent = {+ id: 'step-sandbox',+ tool_call: { output: echoTrailer } as ExecutorPart,+ };+ const sandboxPart: ExecutorPart = {};+ stampCommandExecutor(sandboxSteps, sandboxEvent, sandboxPart);+ expect(sandboxEvent.tool_call.executor).toBeUndefined();+ expect(sandboxPart.executor).toBeUndefined();+ });+});diff --git a/packages/api/src/agents/handlers.ts b/packages/api/src/agents/handlers.tsindex 2995e5dce0..aef42fda5b 100644--- a/packages/api/src/agents/handlers.ts+++ b/packages/api/src/agents/handlers.ts@@ -112,6 +112,11 @@ import {runOutsideTracing,getSafeErrorMetadata,} from '~/utils';+import {+ isAttachedWorkspaceBashTool,+ resolveAttachedWorkspaceQueueWaitMs,+ resolveAttachedWorkspaceRequestTimeoutMs,+} from '~/code/command';import {ContentFilterError,contentFilterModelBoundBlockResponse,@@ -122,10 +127,6 @@ import {WORKSPACE_EDIT_MAX_COUNT,WORKSPACE_WRITE_MAX_BYTES,} from '~/code/workspace';-import {- resolveAttachedWorkspaceQueueWaitMs,- resolveAttachedWorkspaceRequestTimeoutMs,-} from '~/code/command';import {hasIntentArg,stripIntentArg,@@ -303,6 +304,9 @@ export interface ToolExecuteOptions {backgroundCompletionResultMaxChars?: number;/** Callback to process tool artifacts (code output files, file citations, etc.) */toolEndCallback?: ToolEndCallback;+ /** Run steps whose call resolved to the attached-workspace `bash_tool`+ * instance; the step-completed handler consumes them to stamp `executor`. */+ attachedCommandStepIds?: Set<string>;/** Durable internal-completion adapter, present only for an Event Actor invocation. */eventActorDetachedAction?: EventActorDetachedActionLifecycle;/** Called once per batch before tool execution to lazily provision files to tool@@ -5794,6 +5798,7 @@ export function createToolExecuteHandler(options: ToolExecuteOptions): EventHandforegroundRunId,loadTools,toolEndCallback,+ attachedCommandStepIds,eventActorDetachedAction,persistBackgroundCodeResult,backgroundToolCompletion,@@ -6018,6 +6023,12 @@ export function createToolExecuteHandler(options: ToolExecuteOptions): EventHandvoid markSandboxReady(sandboxConversationId);}};+ /** Provenance is the resolved tool instance, never the output. */+ const recordAttachedCommand = (tc: ToolCallRequest, tool: unknown): void => {+ if (tc.stepId && isAttachedWorkspaceBashTool(tool)) {+ attachedCommandStepIds?.add(tc.stepId);+ }+ };const authoringQueues = new Map<string, Promise<void>>();const sandboxAuthoringContexts = new Map<string, SandboxSessionContext>();@@ -6081,6 +6092,7 @@ export function createToolExecuteHandler(options: ToolExecuteOptions): EventHand}) ?? missingToolResult);}+ recordAttachedCommand(tc, tool);const isCodeCall = isCodeSessionAwareToolCall(tc.name, mergedConfigurable);const harvestEnabled = isCodeCall && persistBackgroundCodeResult != null;const liveArtifactPollRequired =@@ -7597,6 +7609,7 @@ export function createToolExecuteHandler(options: ToolExecuteOptions): EventHand);return missingToolResult;}+ recordAttachedCommand(tc, tool);let normalizedArgs: unknown = tc.args;try {diff --git a/packages/api/src/code/command.ts b/packages/api/src/code/command.tsindex d9754ee670..66c94e29d5 100644--- a/packages/api/src/code/command.ts+++ b/packages/api/src/code/command.ts@@ -27,6 +27,43 @@ import { BACKGROUND_TOOL_INVOCATION_CONFIG_KEY } from '~/agents/invocation';const DEFAULT_OUTPUT_BYTES = 256 * 1024;+export const ATTACHED_WORKSPACE_EXECUTOR = 'attached_workspace';++/** Tools built by `createAttachedWorkspaceBashTool`. Membership is object+ * identity, so neither a tool name nor anything a command prints can claim it. */+const attachedWorkspaceBashTools = new WeakSet<object>();++export function isAttachedWorkspaceBashTool(value: unknown): boolean {+ return typeof value === 'object' && value != null && attachedWorkspaceBashTools.has(value);+}++interface ExecutorTarget {+ executor?: string;+}++/**+ * Consumes the run step the execute handler recorded when it resolved the+ * attached-workspace tool, and stamps the executor on the completion event's+ * tool call (streamed) and on the aggregated part (persisted). A step that was+ * not recorded is left untouched, whatever its output says.+ */+export function stampCommandExecutor(+ attachedStepIds: Set<string> | null | undefined,+ result: { id?: unknown; tool_call?: ExecutorTarget } | null | undefined,+ part?: ExecutorTarget | null,+): void {+ const stepId = result?.id;+ if (typeof stepId !== 'string' || attachedStepIds?.delete(stepId) !== true) {+ return;+ }+ if (result?.tool_call != null) {+ result.tool_call.executor = ATTACHED_WORKSPACE_EXECUTOR;+ }+ if (part != null) {+ part.executor = ATTACHED_WORKSPACE_EXECUTOR;+ }+}+export const ATTACHED_WORKSPACE_BASH_DESCRIPTION = `Runs bash commands inside the selected attached environment and returns stdout/stderr. Its workspace may be an existing project, Git repository, or empty directory.Session behavior:@@ -362,7 +399,7 @@ export function createAttachedWorkspaceBashTool({buildAttachedWorkspaceBashSchema(effectiveMaxTimeoutMs, environment, linkedWorktrees),);const actions = environment?.actions ?? [];- return tool(+ const bashTool = tool(async (rawInput: {command?: string;@@ -457,4 +494,6 @@ export function createAttachedWorkspaceBashTool({responseFormat: 'content_and_artifact',},) as unknown as DynamicStructuredTool;+ attachedWorkspaceBashTools.add(bashTool);+ return bashTool;}diff --git a/packages/api/src/stream/implementations/RedisJobStore.ts b/packages/api/src/stream/implementations/RedisJobStore.tsindex 4d1f74db77..d5c4cff451 100644--- a/packages/api/src/stream/implementations/RedisJobStore.ts+++ b/packages/api/src/stream/implementations/RedisJobStore.ts@@ -4302,6 +4302,18 @@ export class RedisJobStore implements IJobStoreV2 {// Pass event string directly - GraphEvents values are lowercase strings// eslint-disable-next-line @typescript-eslint/no-explicit-anyaggregateContent({ event: event.event as any, data: event.data as any });++ // The SDK aggregator rebuilds tool calls from known fields only, so the+ // server-stamped executor is copied back from the stored completion.+ if (event.event === 'on_run_step_completed') {+ const completed = (event.data as { result?: Agents.ToolEndEvent }).result;+ const executor = completed?.tool_call?.executor;+ const index = completed?.id != null ? replayedStepIndices.get(completed.id) : undefined;+ const part = index != null ? contentParts[index] : undefined;+ if (executor != null && part?.type === ContentTypes.TOOL_CALL && part.tool_call) {+ part.tool_call.executor = executor;+ }+ }}const reasoningIndices = new Set([diff --git a/packages/data-provider/src/types/agents.ts b/packages/data-provider/src/types/agents.tsindex 7220f8add2..af0579c057 100644--- a/packages/data-provider/src/types/agents.ts+++ b/packages/data-provider/src/types/agents.ts@@ -118,6 +118,8 @@ export namespace Agents {};/** The tool call was rejected before execution because its input failed schema validation. */inputValidationError?: true;+ /** Server-stamped provenance; see `PartMetadata.executor`. */+ executor?: 'attached_workspace';/** Auth URL */auth?: string;/** Expiration time */diff --git a/packages/data-provider/src/types/content.ts b/packages/data-provider/src/types/content.tsindex e0d3cce1bd..2a2b13c8b6 100644--- a/packages/data-provider/src/types/content.ts+++ b/packages/data-provider/src/types/content.ts@@ -179,6 +179,13 @@ export type PartMetadata = {* as dispatch time rather than the task's runtime.*/backgrounded?: boolean;+ /**+ * Stamped by the server when the run step completes, and only when the call+ * resolved to the attached-workspace `bash_tool` instance. The sandbox tool+ * shares that name, so this is the only trustworthy sign that the output+ * ends in an exit-status trailer; it is never derived from output text.+ */+ executor?: 'attached_workspace';/*** Content index this part occupied while its run streamed. The aggregator* writes parts at provider-source indexes, so the streamed array is sparse;