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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: preserve TUI completion summaries instead of thinking transcripts
[._.]/ Adam Eivy244cf61c58fc
diff --git a/server/cos-runner/index.js b/server/cos-runner/index.jsindex 80515a3af5..1345abbfc9 100644--- a/server/cos-runner/index.js+++ b/server/cos-runner/index.js@@ -389,9 +389,10 @@ app.post('/spawn-tui', lifecycle.spawnRoute(async (req, res) => {current.completedBySentinel = true;const { summary } = parseSentinelPayload(validatedContents);if (summary) {+ current.completionOutput = `${SENTINEL_COMPLETION_MARKER}\n${summary.slice(0, 4096)}\n`;emitToServer('agent:output', {agentId,- text: `${SENTINEL_COMPLETION_MARKER}\n${summary.slice(0, 4096)}\n`,+ text: current.completionOutput,});}if (!current.exited) current.process.kill();diff --git a/server/cos-runner/tuiExit.js b/server/cos-runner/tuiExit.jsindex 3b59bdbae1..c8bb1b2902 100644--- a/server/cos-runner/tuiExit.js+++ b/server/cos-runner/tuiExit.js@@ -32,7 +32,10 @@ export function createTuiExitHandler({ agentId, taskId, sessionId, agent, activeconst effectiveExitCode = success ? 0 : exitCode;const effectiveSignal = success ? 0 : signal;const outputTail = current.outputBuffer.slice(-TUI_EXIT_OUTPUT_TAIL_CHARS);- await persistCompletion(agentId, current.outputBuffer, current.paused ? null : {+ // 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;+ await persistCompletion(agentId, completionOutput, current.paused ? null : {taskId, completedAt: new Date().toISOString(), exitCode: effectiveExitCode,signal: effectiveSignal, success: !!success, duration,completionReason: success ? 'agent-signaled-done' : 'tui-exit',@@ -54,7 +57,7 @@ export function createTuiExitHandler({ agentId, taskId, sessionId, agent, activeexitCode: effectiveExitCode,success,duration,- outputLength: current.outputBuffer.length,+ outputLength: completionOutput.length,completionReason: current.completedBySentinel ? 'agent-signaled-done' : 'tui-exit',});await withState((state) => {diff --git a/server/cos-runner/tuiExit.test.js b/server/cos-runner/tuiExit.test.jsindex d1d3fccafc..af283acc92 100644--- a/server/cos-runner/tuiExit.test.js+++ b/server/cos-runner/tuiExit.test.js@@ -15,11 +15,12 @@ function setup(extra = {}) {const io = { emit: vi.fn() };const emitToServer = vi.fn();const withState = vi.fn(async fn => fn(state));+ const persistCompletion = vi.fn().mockResolvedValue();const onExit = createTuiExitHandler({agentId: 'agent-old', taskId: 'task-1', sessionId: 'session-1',- agent, activeAgents, io, emitToServer, withState, persistCompletion: vi.fn().mockResolvedValue(),+ agent, activeAgents, io, emitToServer, withState, persistCompletion,});- return { agent, activeAgents, state, io, emitToServer, withState, onExit };+ return { agent, activeAgents, state, io, emitToServer, withState, onExit, persistCompletion };}afterEach(() => vi.useRealTimers());@@ -55,6 +56,19 @@ describe('runner TUI exit handoff', () => {expect(run.state.agents['agent-old']).toEqual({ status: 'paused' });});+ it('persists the sentinel received during exit instead of the Gemini thinking transcript', async () => {+ const run = setup({ outputBuffer: 'Thinking: inspect the code and write the completion file.' });+ const summary = '✅ Agent signaled completion\n## Summary\nFixed the bug.\n';+ run.agent.sentinelWork = Promise.resolve().then(() => {+ run.agent.completedBySentinel = true;+ run.agent.completionOutput = summary;+ });+ await run.onExit({ exitCode: 1, signal: 15 });+ expect(run.persistCompletion).toHaveBeenCalledWith('agent-old', summary, expect.objectContaining({ success: true }));+ expect(run.emitToServer).toHaveBeenCalledWith('agent:completed', expect.objectContaining({ outputLength: summary.length }));+ expect(run.io.emit).toHaveBeenCalledWith('tui:exit', expect.objectContaining({ outputTail: run.agent.outputBuffer }));+ });+it('retains successful sentinel completion and bounds the exit transcript', async () => {const run = setup({ completedBySentinel: true, outputBuffer: 'x'.repeat(20000) });await run.onExit({ exitCode: 1, signal: 15 });diff --git a/server/services/agentSummaryExtraction.js b/server/services/agentSummaryExtraction.jsindex 91472d6c68..55f6597eee 100644--- a/server/services/agentSummaryExtraction.js+++ b/server/services/agentSummaryExtraction.js@@ -7,8 +7,18 @@* orchestrator can use them without either importing the other (issue #2837).*/+import { SENTINEL_COMPLETION_MARKER, stripLifecycleLines } from '../lib/agentOutputMarkers.js';import { extractCodexAssistantTail } from '../lib/codexAssistantExtract.js';+// The run-scoped sentinel is authoritative across TUI providers. Select it+// before transcript heuristics, which can mistake thinking or quoted commands+// for an assistant reply or a /simplify boundary.+function extractSentinelSummary(outputBuffer) {+ const markerIndex = outputBuffer.lastIndexOf(SENTINEL_COMPLETION_MARKER);+ if (markerIndex < 0) return null;+ return stripLifecycleLines(outputBuffer.slice(markerIndex + SENTINEL_COMPLETION_MARKER.length).split('\n')).join('\n').trim() || null;+}+/*** Extract the final summary section from agent output.* Walks backwards from the end to find the last block of non-tool-call content.@@ -16,6 +26,9 @@ import { extractCodexAssistantTail } from '../lib/codexAssistantExtract.js';export function extractFinalSummary(outputBuffer) {if (!outputBuffer) return null;+ const sentinelSummary = extractSentinelSummary(outputBuffer);+ if (sentinelSummary) return sentinelSummary;+const codexTail = extractCodexAssistantTail(outputBuffer);if (codexTail) return codexTail;@@ -45,6 +58,9 @@ const RE_SIMPLIFY_ACTION = /\b(run|running|launch|now)\b/i;export function extractSimplifySummaries(outputBuffer) {if (!outputBuffer) return null;+ const sentinelSummary = extractSentinelSummary(outputBuffer);+ if (sentinelSummary) return { taskSummary: sentinelSummary, simplifySummary: null };+// Codex CLI cannot execute slash commands like /simplify, so any match// inside its output is from a diff/grep dump that quotes source code.// Treat the assistant tail as the task summary and skip the simplify split.diff --git a/server/services/agentSummaryExtraction.test.js b/server/services/agentSummaryExtraction.test.jsindex 6b7195e80e..8950379fb6 100644--- a/server/services/agentSummaryExtraction.test.js+++ b/server/services/agentSummaryExtraction.test.js@@ -1,6 +1,24 @@import { describe, it, expect } from 'vitest';import { extractFinalSummary, extractSimplifySummaries } from './agentSummaryExtraction.js';+describe('sentinel summary precedence', () => {+ it.each(['Thinking: I will now run /simplify.', 'tokens used\n123\nEarlier assistant reply.'])(+ 'renders the latest completion summary instead of transcript content: %s', (transcript) => {+ const summary = '## Summary\nFixed the reported bug.\n\n✅ Tests passed';+ const output = [+ '✅ Agent signaled completion',+ 'An earlier completion attempt.',+ transcript,+ '✅ Agent signaled completion',+ summary,+ '💡 Open the Shell tab to view the session',+ ].join('\n');+ expect(extractFinalSummary(output)).toBe(summary);+ expect(extractSimplifySummaries(output)).toEqual({ taskSummary: summary, simplifySummary: null });+ }+ );+});+describe('extractFinalSummary', () => {it('returns the last block of non-tool text', () => {const output = [