Skip to content

Commit 4e3494a

Browse files
committed
🤖 fix: include stdout/stderr/MUX_OUTPUT/MUX_PROMPT in LLM context
Change-Id: Ia12a1c144ac06180592840199ce9f2ab648be882 Signed-off-by: Thomas Kosiewski <[email protected]>
1 parent 81c6943 commit 4e3494a

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

src/browser/components/Messages/ScriptExecutionMessage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const ScriptExecutionMessage: React.FC<ScriptExecutionMessageProps> = ({
7171
{formatDuration(result.wall_duration_ms)}
7272
</div>
7373
<div className="text-foreground-secondary text-[11px]">
74-
Visible only to you; never sent to the model.
74+
Visible to you and the model.
7575
</div>
7676
</DetailSection>
7777

src/browser/utils/messages/modelMessageTransform.ts

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -209,42 +209,38 @@ export function injectModeTransition(
209209
* - Preserves the rest of the message structure (id, role, other metadata)
210210
*/
211211
export function transformScriptMessagesForLLM(messages: MuxMessage[]): MuxMessage[] {
212-
return messages.flatMap((msg) => {
212+
return messages.map((msg) => {
213213
if (msg.metadata?.muxMetadata?.type !== "script-execution") {
214-
return [msg];
214+
return msg;
215215
}
216216

217217
const scriptMeta = msg.metadata.muxMetadata;
218218
const result = scriptMeta.result;
219-
// Only include the message if the script explicitly wrote to MUX_PROMPT (promptFile)
220-
// or MUX_OUTPUT (outputFile).
221-
// This respects the "Visible only to you" promise for stdout/stderr (result.output).
222-
const promptContent = result.promptFile?.trim();
223-
const outputContent = result.outputFile?.trim();
224-
const hasContent = (promptContent && promptContent.length > 0) || (outputContent && outputContent.length > 0);
219+
220+
let llmContent = `Script '${scriptMeta.scriptName}' executed (exit code ${result.exitCode}).`;
225221

226-
if (hasContent) {
227-
let llmContent = `Script '${scriptMeta.scriptName}' executed (exit code ${result.exitCode}).`;
228-
229-
if (outputContent && outputContent.length > 0) {
230-
llmContent += `\nMUX_OUTPUT:\n${outputContent}`;
231-
}
232-
233-
if (promptContent && promptContent.length > 0) {
234-
llmContent += `\nMUX_PROMPT:\n${promptContent}`;
235-
}
222+
// Include Stdout/Stderr if present
223+
if (result.output) {
224+
llmContent += `\nStdout/Stderr:\n${result.output}`;
225+
} else {
226+
llmContent += `\nStdout/Stderr: (no output)`;
227+
}
228+
229+
// Include MUX_OUTPUT if present
230+
if (result.outputFile && result.outputFile.trim()) {
231+
llmContent += `\nMUX_OUTPUT:\n${result.outputFile.trim()}`;
232+
}
236233

237-
return [
238-
{
239-
...msg,
240-
parts: [{ type: "text", text: llmContent }],
241-
// Keep metadata for debugging but ensure downstream consumers use the new parts
242-
},
243-
];
234+
// Include MUX_PROMPT if present
235+
if (result.promptFile && result.promptFile.trim()) {
236+
llmContent += `\nMUX_PROMPT:\n${result.promptFile.trim()}`;
244237
}
245238

246-
// Otherwise, exclude from LLM context entirely
247-
return [];
239+
return {
240+
...msg,
241+
parts: [{ type: "text", text: llmContent }],
242+
// Keep metadata for debugging but ensure downstream consumers use the new parts
243+
};
248244
});
249245
}
250246

0 commit comments

Comments
 (0)