Skip to content

The agent that grows with you

fix(desktop): enrich backgroundDone notification body with exit code and output tail

kokhlo879b1b0982fd
diff --git a/apps/desktop/src/store/composer-status.test.ts b/apps/desktop/src/store/composer-status.test.ts
index 4548dcd07db..43d4753b7a7 100644
--- a/apps/desktop/src/store/composer-status.test.ts
+++ b/apps/desktop/src/store/composer-status.test.ts
@@ -16,6 +16,9 @@ import { markSessionGone } from './runtime-gone'
vi.mock('./notifications', () => ({ notifyError: vi.fn() }))
import { notifyError } from './notifications'
+vi.mock('./native-notifications', () => ({ dispatchNativeNotification: vi.fn() }))
+import { dispatchNativeNotification } from './native-notifications'
+
const SID = 'sess-1'
const running = (id: string, command = `cmd ${id}`) => ({ command, session_id: id, status: 'running' })
@@ -144,6 +147,64 @@ describe('reconcileBackgroundProcesses', () => {
expect(itemsOf('sess-arm')).toEqual([])
})
+
+ it('dispatches rich backgroundDone notification: title + exit code + output tail', () => {
+ // Start with running, then transition to exited with output
+ reconcileBackgroundProcesses('sess-notify', [running('build-task', 'npm run build\nsome comment')])
+ vi.clearAllMocks()
+
+ const completedProc = {
+ command: 'npm run build\nsome comment',
+ exit_code: 0,
+ output_tail: 'Building...\nCompilation successful\nOutput written to dist/',
+ session_id: 'build-task',
+ status: 'exited'
+ }
+ reconcileBackgroundProcesses('sess-notify', [completedProc])
+
+ expect(dispatchNativeNotification).toHaveBeenCalledWith(
+ expect.objectContaining({
+ body: 'npm run build (exit 0)\nCompilation successful\nOutput written to dist/',
+ kind: 'backgroundDone'
+ })
+ )
+ })
+
+ it('omits exit code from notification body when undefined', () => {
+ reconcileBackgroundProcesses('sess-no-exit', [running('task-x')])
+ vi.clearAllMocks()
+
+ reconcileBackgroundProcesses('sess-no-exit', [{
+ command: 'task-x',
+ output_tail: 'line1\nline2\nline3',
+ session_id: 'task-x',
+ status: 'exited'
+ }])
+
+ expect(dispatchNativeNotification).toHaveBeenCalledWith(
+ expect.objectContaining({
+ body: 'task-x\nline1\nline2\nline3'
+ })
+ )
+ })
+
+ it('handles notification body when output is empty', () => {
+ reconcileBackgroundProcesses('sess-empty', [running('quick-cmd')])
+ vi.clearAllMocks()
+
+ reconcileBackgroundProcesses('sess-empty', [{
+ command: 'quick-cmd',
+ exit_code: 1,
+ session_id: 'quick-cmd',
+ status: 'exited'
+ }])
+
+ expect(dispatchNativeNotification).toHaveBeenCalledWith(
+ expect.objectContaining({
+ body: 'quick-cmd (exit 1)'
+ })
+ )
+ })
})
// ── Dead-session polling guard (#94219 fallout) ──────────────────────────────
diff --git a/apps/desktop/src/store/composer-status.ts b/apps/desktop/src/store/composer-status.ts
index f6970880b6b..aaf447a1d81 100644
--- a/apps/desktop/src/store/composer-status.ts
+++ b/apps/desktop/src/store/composer-status.ts
@@ -335,8 +335,19 @@ export function reconcileBackgroundProcesses(sid: string, procs: GatewayProcessE
for (const [id, item] of fresh) {
if (item.state !== 'running' && prevState.get(id) === 'running') {
+ let body = item.title
+ if (item.exitCode !== undefined) {
+ body += ` (exit ${item.exitCode})`
+ }
+ if (item.output) {
+ const tailLines = item.output.trim().split('\n').slice(-3)
+ if (tailLines.length > 0) {
+ body += '\n' + tailLines.join('\n')
+ }
+ }
+
dispatchNativeNotification({
- body: item.title,
+ body,
kind: 'backgroundDone',
sessionId: sid,
title: translateNow(