Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
feat(code): markdown end-of-task summary — what was done, ≤5 files, next steps
Salman Qureshi9f67a4675906
diff --git a/src/channels/cli.ts b/src/channels/cli.tsindex dd10add9..60a8c2ae 100644--- a/src/channels/cli.ts+++ b/src/channels/cli.ts@@ -10,6 +10,7 @@ import { STEPS_PAUSED_BANNER, NO_CHANGES_BANNER } from '../core/completion-verdiimport { logger } from '../utils/logger.js';import { formatToolStep, formatToolResult } from '../utils/tool-label.js';import type { ChatMessage, CompletionMeta, FileChangeSummary, ToolStep, PermissionPromptState, CurrentSessionInfo, SidebarSection, SkillInfo, SubAgentInfo, ProviderInfo, TokenInfo, SaverInfo, AppMode, WorkspaceState, WorkspaceTreeNode, WorkspaceGitFile, BackgroundTaskInfo, MercuryCodeGitState, MercuryCodeState, LiveActivityState, PlanStep } from '../ui/types.js';+import { TASK_SUMMARY_FILE_LIMIT } from '../ui/types.js';import { TuiApp } from '../ui/App.js';import { ResilientTuiOutput } from '../ui/resilient-output.js';@@ -22,6 +23,47 @@ import { ResilientTuiOutput } from '../ui/resilient-output.js';*/const MOUSE_SEQ_RE = /\x1b\[<\d+;\d+;\d+[Mm]|\x1b\[M[\x20-\x2f]*[\x40-\x6f]|\x1b\[\?100[0-7][hl]/g;+/**+ * Markdown summary appended to the Mercury Code completion banner: what was+ * done (a few bullets), how many files changed (paths capped at+ * TASK_SUMMARY_FILE_LIMIT — the full list lives in git), and the next steps+ * the developer might need to take. Short by design: the agent's full+ * narration is already in the response above the banner.+ */+export function buildTaskSummary(opts: {+ fileChanges: FileChangeSummary[];+ doneSteps: string[];+ verified: boolean;+ uncommitted: boolean;+}): string {+ const lines: string[] = [];++ const steps = opts.doneSteps.filter((label) => label.trim().length > 0).slice(0, 5);+ if (steps.length > 0) {+ lines.push('**What was done**');+ for (const label of steps) lines.push(`• ${label}`);+ }++ if (opts.fileChanges.length > 0) {+ const n = opts.fileChanges.length;+ lines.push(`**Changes** · ${n} file${n !== 1 ? 's' : ''}${n > TASK_SUMMARY_FILE_LIMIT ? ` (showing ${TASK_SUMMARY_FILE_LIMIT})` : ''}`);+ // Paths render below as the banner's file rows (also capped) — the count+ // line here keeps the at-a-glance number even when the list is trimmed.+ }++ const next: string[] = [];+ if (opts.fileChanges.length > 0) {+ if (!opts.verified) next.push('Run your test suite — these changes are not verified yet');+ if (opts.uncommitted) next.push('Review the diff (`git diff`), then commit when ready');+ }+ if (next.length > 0) {+ lines.push('**Next steps**');+ for (const step of next) lines.push(`• ${step}`);+ }++ return lines.join('\n');+}+/*** Parsed mouse event from an SGR/X10 sequence.* click: press (or release of a press) without motion and without wheel.@@ -1042,17 +1084,23 @@ export class CLIChannel extends BaseChannel {if (content.startsWith('Task complete') && fileChanges && fileChanges.length === 0) {content = NO_CHANGES_BANNER + (parts ? ` · ${parts}` : '');}- // Change summary: what was done, per file, and the verification that- // proves it — the developer reads this instead of diffing manually.+ // End-of-task summary: what was done (a few bullets from the plan or the+ // tool steps), how many files changed (paths render below as the banner's+ // file rows, capped at TASK_SUMMARY_FILE_LIMIT), and what the developer+ // might need to do next. The developer reads this instead of diffing+ // manually.if (fileChanges && fileChanges.length > 0) {- const lines: string[] = [];- for (const f of fileChanges.slice(0, 8)) {- const stats = f.added == null || f.removed == null ? 'new' : `+${f.added} −${f.removed}`;- lines.push(` ↳ ${f.path} · ${stats}`);- }- if (fileChanges.length > 8) lines.push(` ↳ … ${fileChanges.length - 8} more`);- if (verificationNote) lines.push(` ✓ Verified: ${verificationNote}`);- content += `\n\nChanges made:\n${lines.join('\n')}`;+ const planSteps = (this.state.planProgress ?? []).filter((s) => s.status === 'done').map((s) => s.label);+ const doneSteps = planSteps.length > 0+ ? planSteps+ : [...new Set(this.state.toolSteps.filter((s) => s.status !== 'error').map((s) => s.label))];+ content += `\n\n${buildTaskSummary({+ fileChanges,+ doneSteps,+ verified: !!verificationNote,+ uncommitted: (this.state.mercuryCode?.git.dirty ?? 0) > 0,+ })}`;+ if (verificationNote) content += `\n✓ Verified: ${verificationNote}`;}const msg: ChatMessage = {diff --git a/src/channels/task-summary.test.ts b/src/channels/task-summary.test.tsnew file mode 100644index 00000000..f13c6b03--- /dev/null+++ b/src/channels/task-summary.test.ts@@ -0,0 +1,95 @@+import { describe, expect, it } from 'vitest';+import { buildTaskSummary } from './cli.js';+import { buildMercuryMessageLines } from '../ui/mercury-transcript.js';+import { TASK_SUMMARY_FILE_LIMIT, type ChatMessage } from '../ui/types.js';++const files = (n: number) =>+ Array.from({ length: n }, (_, i) => ({ path: `src/file-${i}.ts`, added: 10 + i, removed: i }));++/**+ * End-of-task summary in Mercury Code: after a heavy job the banner carries a+ * short markdown summary — what was done (a few bullets), the NUMBER of files+ * changed with at most TASK_SUMMARY_FILE_LIMIT paths listed, and the next+ * steps the developer might need to take.+ */+describe('Mercury Code end-of-task summary', () => {+ it('lists what was done, the file count, and next steps', () => {+ const summary = buildTaskSummary({+ fileChanges: [+ { path: 'src/a.ts', added: 45, removed: 12 },+ { path: 'src/b.ts', added: 3, removed: 1 },+ ],+ doneSteps: ['Read auth module', 'Refactor login flow'],+ verified: false,+ uncommitted: true,+ });++ expect(summary).toContain('**What was done**');+ expect(summary).toContain('• Read auth module');+ expect(summary).toContain('**Changes** · 2 files');+ expect(summary).not.toContain('src/a.ts'); // paths render as the banner's file rows+ expect(summary).toContain('**Next steps**');+ expect(summary).toContain('not verified yet');+ expect(summary).toContain('git diff');+ });++ it('shows at most 5 what-was-done bullets', () => {+ const summary = buildTaskSummary({+ fileChanges: [{ path: 'a.ts', added: 1, removed: 0 }],+ doneSteps: Array.from({ length: 12 }, (_, i) => `Step ${i}`),+ verified: true,+ uncommitted: false,+ });+ expect(summary.match(/• Step \d/g)).toHaveLength(5);+ // Verified tasks don't get the "run tests" nudge.+ expect(summary).not.toContain('not verified yet');+ // Nothing to commit → no commit suggestion.+ expect(summary).not.toContain('**Next steps**');+ });++ it('the Changes line shows the full count but caps the "showing" note at the limit', () => {+ const many = buildTaskSummary({+ fileChanges: Array.from({ length: 9 }, (_, i) => ({ path: `f${i}.ts`, added: 1, removed: 1 })),+ doneSteps: [],+ verified: true,+ uncommitted: true,+ });+ expect(many).toContain('**Changes** · 9 files (showing 5)');+ expect(many).toContain('Review the diff (`git diff`)');++ const few = buildTaskSummary({+ fileChanges: Array.from({ length: 3 }, (_, i) => ({ path: `f${i}.ts`, added: 1, removed: 1 })),+ doneSteps: [],+ verified: true,+ uncommitted: true,+ });+ expect(few).toContain('**Changes** · 3 files');+ expect(few).not.toContain('showing');+ });++ it('transcript file rows cap at the same limit with a "more" pointer', () => {+ const msg: ChatMessage = {+ id: 'done-1',+ role: 'system',+ content: '━━━ Task complete',+ timestamp: 1,+ fileChanges: Array.from({ length: 9 }, (_, i) => ({ path: `f${i}.ts`, added: 2, removed: 1 })),+ };+ const lines = buildMercuryMessageLines(msg, 76);+ const fileRows = lines.filter((l) => l.kind === 'file');+ expect(fileRows).toHaveLength(TASK_SUMMARY_FILE_LIMIT + 1); // paths + "… N more"+ expect(fileRows[fileRows.length - 1].text).toContain('4 more');+ });++ it('small change lists stay under the limit with no "more" row', () => {+ const msg: ChatMessage = {+ id: 'done-2',+ role: 'system',+ content: '━━━ Task complete',+ timestamp: 1,+ fileChanges: [{ path: 'one.ts', added: 1, removed: 0 }],+ };+ const lines = buildMercuryMessageLines(msg, 76);+ expect(lines.filter((l) => l.kind === 'file')).toHaveLength(1);+ });+});\ No newline at end of filediff --git a/src/ui/mercury-transcript.ts b/src/ui/mercury-transcript.tsindex bd06b356..4a4490ec 100644--- a/src/ui/mercury-transcript.ts+++ b/src/ui/mercury-transcript.ts@@ -1,4 +1,5 @@import type { ChatMessage } from './types.js';+import { TASK_SUMMARY_FILE_LIMIT } from './types.js';import { normalizeTerminalText } from './terminal-viewport.js';import { renderMarkdown } from '../utils/markdown.js';import { renderMercuryCodeParts } from './pixel-logo.js';@@ -354,10 +355,17 @@ export function buildMercuryMessageLines(if (message.fileChanges?.length) {push('system', `FILES CHANGED · ${message.fileChanges.length}`);- for (const file of message.fileChanges) {+ // End-of-task summary rule: list at most TASK_SUMMARY_FILE_LIMIT paths —+ // the count line above still shows the full number, the complete list+ // lives in git.+ const files = message.fileChanges;+ for (const file of files.slice(0, TASK_SUMMARY_FILE_LIMIT)) {const stats = file.added == null || file.removed == null ? 'binary' : `+${file.added} -${file.removed}`;for (const line of wrapMercuryText(`${file.path} ${stats}`, contentWidth)) push('file', line);}+ if (files.length > TASK_SUMMARY_FILE_LIMIT) {+ push('file', `… ${files.length - TASK_SUMMARY_FILE_LIMIT} more`);+ }}push('spacer', '');return lines;diff --git a/src/ui/types.ts b/src/ui/types.tsindex ac6e3b51..bc2e9168 100644--- a/src/ui/types.ts+++ b/src/ui/types.ts@@ -86,6 +86,11 @@ export interface FileChangeSummary {removed: number | null;}+/** Max file paths listed in the end-of-task summary (banner summary line and+ * transcript file rows alike) — the count line still shows the full number;+ * the complete list lives in git. */+export const TASK_SUMMARY_FILE_LIMIT = 5;+export interface ToolStep {id: string;toolName: string;