Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: stop persisting the raw TUI terminal buffer as a completed agent's transcript

Adam Eivy360c9a484a54
diff --git a/server/cos-runner/tuiExit.js b/server/cos-runner/tuiExit.js
index 844f96d8fe..87a94ef18d 100644
--- a/server/cos-runner/tuiExit.js
+++ b/server/cos-runner/tuiExit.js
@@ -1,4 +1,7 @@
/** Finish a runner TUI on observed process exit, even after force-kill reaping. */
+import { stripAnsi } from '../lib/ansiStrip.js';
+import { SENTINEL_COMPLETION_MARKER } from '../lib/agentOutputMarkers.js';
+
// `tui:output` is live telemetry, so an immediate process exit can beat its
// socket delivery. Keep a small terminal tail with the exit event: the PortOS
// spawner owns failure analysis and can persist it when no ordinary TUI chunk
@@ -6,6 +9,17 @@
// buffer and is enough to carry a CLI's startup diagnostic.
const TUI_EXIT_OUTPUT_TAIL_CHARS = 16 * 1024;
+// What `output.txt` (and so the completed card's transcript) receives. A
+// sentinel summary wins. A run that signaled done WITHOUT a summary (agy often
+// just `touch`es the file) must not fall back to the terminal buffer — that is
+// an escape-code repaint stream, not a transcript — so it gets a one-line
+// marker. Any other exit keeps the buffer for failure diagnosis, ANSI-stripped.
+function resolveCompletionOutput(agent) {
+ if (agent.completionOutput != null) return agent.completionOutput;
+ if (agent.completedBySentinel) return `${SENTINEL_COMPLETION_MARKER}\n(no summary was written to the completion file)\n`;
+ return stripAnsi(agent.outputBuffer);
+}
+
export function createTuiExitHandler({ agentId, taskId, sessionId, agent, activeAgents, io, emitToServer, withState, persistCompletion, onError }) {
return async ({ exitCode, signal }) => {
try {
@@ -34,7 +48,7 @@ export function createTuiExitHandler({ agentId, taskId, sessionId, agent, active
const outputTail = current.outputBuffer.slice(-TUI_EXIT_OUTPUT_TAIL_CHARS);
// The terminal buffer contains TUI thinking/repaints. A validated
// sentinel owns the durable user-facing output once it is available.
- const completionOutput = current.completionOutput ?? current.outputBuffer;
+ const completionOutput = resolveCompletionOutput(current);
await persistCompletion(agentId, completionOutput, current.paused ? null : {
taskId, completedAt: new Date().toISOString(), exitCode: effectiveExitCode,
signal: effectiveSignal, success: !!success, duration,
diff --git a/server/cos-runner/tuiExit.test.js b/server/cos-runner/tuiExit.test.js
index 316154e83d..4df4aaa3ee 100644
--- a/server/cos-runner/tuiExit.test.js
+++ b/server/cos-runner/tuiExit.test.js
@@ -78,4 +78,16 @@ describe('runner TUI exit handoff', () => {
expect(run.state.stats).toEqual({ completed: 1, failed: 0 });
expect(run.state.agents).toEqual({});
});
+
+ it('never persists the raw terminal repaint stream as the transcript', async () => {
+ const noSummary = setup({ completedBySentinel: true, outputBuffer: '\x1b[1;38;2;1;2;3mrepaint\x1b[m\x1b[K' });
+ await noSummary.onExit({ exitCode: 0, signal: 0 });
+ const [, written] = noSummary.persistCompletion.mock.calls[0];
+ expect(written).not.toContain('\x1b');
+ expect(written).toContain('Agent signaled completion');
+
+ const failed = setup({ outputBuffer: '\x1b[31mUsage limit reached\x1b[m' });
+ await failed.onExit({ exitCode: 1, signal: 0 });
+ expect(failed.persistCompletion.mock.calls[0][1]).toBe('Usage limit reached');
+ });
});