From 60e6366a95418cb24597b911baac60d9c07c14b9 Mon Sep 17 00:00:00 2001 From: Matt Toohey Date: Thu, 3 Dec 2026 13:20:02 +1100 Subject: [PATCH 1/3] fix(staged): show a project session waiting on repo sessions as running MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A project session that calls `wake_when_repo_sessions_end` and ends its turn is `completed` with a wake-up armed. Since #1121 its row in the project's notes list said so: "Waiting on N repo sessions" as the row's subtitle ahead of the repo sessions' badges, or as the title of an hourglass row when the note was not written yet. To the user the session is still at work, through the repo sessions it started. The row now reads as running for as long as the wake-up is armed: - `noteRowPhase` maps a session waiting on its wake-up to `running`, written note or not, and the `waiting` phase and the `waiting-note` row type are gone. The row gets the spinner, sorts with the running rows, opens its chat, offers no Resume and carries no unread dot. - `finishedSecondaryMeta` no longer produces the "Waiting on" line, so the subtitle is the repo sessions' badges alone, as on any running row. A written note keeps its title; an unwritten one reads "Generating note…". - The chat pane's notice, which is where the wait is explained and stopped, spins instead of showing an hourglass. The wake-up itself, its store and events, and the MCP tools are untouched. A finished session that left repo sessions going without a wake-up still says "N repo sessions still running". Signed-off-by: Matt Toohey Co-Authored-By: Claude Fable 5.2 --- .../projects/ProjectSection.component.test.ts | 95 +++++++++++++++---- .../features/projects/ProjectSection.svelte | 31 ++++-- .../features/projects/projectNoteRow.test.ts | 77 +++++++++++---- .../lib/features/projects/projectNoteRow.ts | 46 +++++---- .../SessionWakeupNotice.component.test.ts | 10 ++ .../sessions/SessionWakeupNotice.svelte | 23 +++-- .../lib/features/sessions/sessionWakeup.ts | 15 ++- .../lib/features/timeline/TimelineRow.svelte | 20 +--- .../timeline/childSessionBadges.test.ts | 60 +++--------- .../features/timeline/childSessionBadges.ts | 46 +++------ .../features/timeline/sessionRowState.test.ts | 44 +++++++-- .../lib/features/timeline/sessionRowState.ts | 34 ++++--- 12 files changed, 316 insertions(+), 185 deletions(-) diff --git a/apps/staged/src/lib/features/projects/ProjectSection.component.test.ts b/apps/staged/src/lib/features/projects/ProjectSection.component.test.ts index ce1f39713..11184f8a1 100644 --- a/apps/staged/src/lib/features/projects/ProjectSection.component.test.ts +++ b/apps/staged/src/lib/features/projects/ProjectSection.component.test.ts @@ -926,7 +926,10 @@ describe('ProjectSection sessions waiting on repo sessions', () => { content: '', }); - it('shows a session that waits before writing its note as waiting, with the badges of what it waits on', async () => { + /** Everything a row says in words: its title and its subtitle. */ + const rowText = (row: HTMLElement) => `${row.dataset.title} ${row.dataset.secondaryMeta}`; + + it('shows a session that waits before writing its note as running, with the badges of what it waits on', async () => { listNotes(unwritten); commandMocks.getSessionWakeup.mockImplementation(async () => armedWakeup('child-1', 'child-2', 'child-3') @@ -941,25 +944,48 @@ describe('ProjectSection sessions waiting on repo sessions', () => { // Asked for once: the wake-up was armed before this section was listening. expect(commandMocks.getSessionWakeup.mock.calls).toEqual([['session-waiting']]); const row = rowFor('session-waiting'); - expect(row.dataset.type).toBe('waiting-note'); - expect(row.dataset.title).toBe('Waiting on 2 repo sessions'); + // The row a running session has: the spinner's type, and the badges + // alone as the subtitle. Nothing on it says the session is waiting. + expect(row.dataset.type).toBe('generating-note'); + expect(row.dataset.title).toBe('Generating note…'); expect(row.dataset.secondaryMeta).toBe(''); + expect(rowText(row)).not.toMatch(/waiting/i); expect(row.dataset.childBadges).toBe('child-1:running child-2:paused'); // Staged resumes it; there is nothing for the user to resume. expect(resumeButton('session-waiting')).toBeNull(); - // No note to open yet, so the row opens the chat, which says what it waits on. - expect(row.querySelector('[data-testid="row-open"]')).not.toBeNull(); + // Like a running row, it opens the chat, which says what it waits on. + clickRow('session-waiting'); + expect(noteModal.props).toMatchObject({ + noteId: 'note-waiting', + sessionId: 'session-waiting', + chatOpen: true, + }); + + unmount(section); + }); + + it('shows a waiting session as running before its repo sessions are read, and with none in flight', async () => { + listNotes(unwritten); + commandMocks.getSessionWakeup.mockImplementation(async () => armedWakeup('child-1')); + const section = mountSection(); + await settle(); + + const row = rowFor('session-waiting'); + expect(row.dataset.type).toBe('generating-note'); + expect(row.dataset.secondaryMeta).toBe('Generating note'); + expect(row.dataset.childBadges).toBe(''); + expect(rowText(row)).not.toMatch(/waiting/i); unmount(section); }); - it('drops a badge when a session being waited on ends, and recounts', async () => { + it('drops a badge when a session being waited on ends, and stays running', async () => { listNotes(unwritten); commandMocks.getSessionWakeup.mockImplementation(async () => armedWakeup('child-1', 'child-2')); listChildren({ 'session-waiting': [childSession('child-1'), childSession('child-2')] }); const section = mountSection(); await settle(); - expect(rowFor('session-waiting').dataset.title).toBe('Waiting on 2 repo sessions'); + expect(rowFor('session-waiting').dataset.childBadges).toBe('child-1:running child-2:running'); listChildren({ 'session-waiting': [childSession('child-2')] }); await emitSessionStatus({ @@ -970,20 +996,20 @@ describe('ProjectSection sessions waiting on repo sessions', () => { }); const row = rowFor('session-waiting'); - expect(row.dataset.type).toBe('waiting-note'); - expect(row.dataset.title).toBe('Waiting on 1 repo session'); + expect(row.dataset.type).toBe('generating-note'); + expect(rowText(row)).not.toMatch(/waiting/i); expect(row.dataset.childBadges).toBe('child-2:running'); unmount(section); }); - it('stops showing a session as waiting once its wake-up is gone', async () => { + it('stops showing a session as running once its wake-up is gone', async () => { listNotes(unwritten); commandMocks.getSessionWakeup.mockImplementation(async () => armedWakeup('child-1')); listChildren({ 'session-waiting': [childSession('child-1')] }); const section = mountSection(); await settle(); - expect(rowFor('session-waiting').dataset.type).toBe('waiting-note'); + expect(rowFor('session-waiting').dataset.type).toBe('generating-note'); // Stop waiting, here or in another window: the repo session keeps running. await emitWakeup('session-waiting', NO_WAKEUP); @@ -996,7 +1022,7 @@ describe('ProjectSection sessions waiting on repo sessions', () => { unmount(section); }); - it('says what a written note’s session waits on under its title', async () => { + it('shows a written note’s session as running while it waits, with its badges and no waiting line', async () => { listNotes(completedNote); listChildren({ 'session-1': [childSession('child-1'), childSession('child-2')] }); const section = mountSection(); @@ -1009,10 +1035,46 @@ describe('ProjectSection sessions waiting on repo sessions', () => { await emitWakeup('session-1', armedWakeup('child-2')); const row = rowFor('session-1'); - expect(row.dataset.type).toBe('note'); + expect(row.dataset.type).toBe('generating-note'); expect(row.dataset.title).toBe('A finished note'); - expect(row.dataset.secondaryMeta).toBe('Waiting on 1 repo session'); + expect(row.dataset.secondaryMeta).toBe(''); + expect(rowText(row)).not.toMatch(/waiting/i); + // Every repo session it has going is badged, named in the wake-up or not. expect(row.dataset.childBadges).toBe('child-1:running child-2:running'); + expect(resumeButton('session-1')).toBeNull(); + // A running row opens on its chat, not on the note. + clickRow('session-1'); + expect(noteModal.props).toMatchObject({ sessionId: 'session-1', chatOpen: true }); + + // The wake-up is stopped: it is the finished note again. + await emitWakeup('session-1', NO_WAKEUP); + expect(rowFor('session-1').dataset.type).toBe('note'); + + unmount(section); + }); + + it('lists a waiting session among the running ones, after the finished notes', async () => { + // Written before the finished note, so by date alone it would come first. + listNotes( + { ...unwritten, createdAt: 1, updatedAt: 1, completedAt: 1 }, + { ...completedNote, createdAt: 2, updatedAt: 2, completedAt: 2 } + ); + commandMocks.getSessionWakeup.mockImplementation(async (sessionId) => + sessionId === 'session-waiting' ? armedWakeup('child-1') : NO_WAKEUP + ); + listChildren({ 'session-waiting': [childSession('child-1')] }); + const section = mountSection(); + await settle(); + + const order = () => + [...document.querySelectorAll('[data-testid="timeline-row"]')].map( + (row) => `${row.dataset.sessionId}:${row.dataset.type}` + ); + expect(order()).toEqual(['session-1:note', 'session-waiting:generating-note']); + + // No longer waiting: it is a finished row again, in date order. + await emitWakeup('session-waiting', NO_WAKEUP); + expect(order()).toEqual(['session-waiting:failed-note', 'session-1:note']); unmount(section); }); @@ -1034,7 +1096,7 @@ describe('ProjectSection sessions waiting on repo sessions', () => { layerHolder.layer = reactiveProps({ active: true, visible: true, activations: 0 }); const section = mountSection(); await settle(); - expect(rowFor('session-waiting').dataset.type).toBe('waiting-note'); + expect(rowFor('session-waiting').dataset.type).toBe('generating-note'); expect(rowFor('session-1').dataset.type).toBe('note'); commandMocks.getSessionWakeup.mockClear(); @@ -1053,7 +1115,8 @@ describe('ProjectSection sessions waiting on repo sessions', () => { 'session-waiting', ]); expect(rowFor('session-waiting').dataset.type).toBe('failed-note'); - expect(rowFor('session-1').dataset.secondaryMeta).toBe('Waiting on 1 repo session'); + expect(rowFor('session-1').dataset.type).toBe('generating-note'); + expect(rowFor('session-1').dataset.childBadges).toBe('child-2:running'); unmount(section); }); diff --git a/apps/staged/src/lib/features/projects/ProjectSection.svelte b/apps/staged/src/lib/features/projects/ProjectSection.svelte index 3e24d2c62..b2b61b838 100644 --- a/apps/staged/src/lib/features/projects/ProjectSection.svelte +++ b/apps/staged/src/lib/features/projects/ProjectSection.svelte @@ -51,7 +51,7 @@ import { noteChatState } from '../sessions/noteFreshness'; import { buildReferringPrompt } from '../../shared/buildReferringPrompt'; import { createLiveSessionRows } from '../timeline/liveSessionHints'; - import { canResumeRow, noteRowPhase } from '../timeline/sessionRowState'; + import { canResumeRow, isActiveRowPhase, noteRowPhase } from '../timeline/sessionRowState'; import { resumeSessionFromRow } from '../timeline/resumeSessionFromRow'; import { buildChildSessionBadges, runningChildSessionIds } from '../timeline/childSessionBadges'; import { nextActiveSessionIds } from './activeSessionIds'; @@ -742,14 +742,29 @@ } } + /** + * The phase a note's row shows. A session waiting to be woken when its + * repo sessions end reads as running, so everything that asks whether a + * row is running or done asks here, with the session's wake-up. + */ + function projectNoteRowPhase(note: ProjectNote) { + return noteRowPhase(note, sessionWakeupsStore.get(note.sessionId)); + } + + /** Whether a note's row shows its session as at work. */ + function showsNoteRunning(note: ProjectNote): boolean { + return isActiveRowPhase(projectNoteRowPhase(note)); + } + /** * All notes: completed (oldest last-written first) followed by generating – matches - * branch timeline order. + * branch timeline order. A note whose session is waiting to be woken is + * among the generating ones, as its row shows it. */ let timelineNotes = $derived( [...projectNotes].sort((a, b) => { - const aIsActive = isSessionActive(a.sessionStatus); - const bIsActive = isSessionActive(b.sessionStatus); + const aIsActive = showsNoteRunning(a); + const bIsActive = showsNoteRunning(b); if (aIsActive !== bIsActive) return aIsActive ? 1 : -1; return noteLastWrittenAt(a) - noteLastWrittenAt(b); }) @@ -874,7 +889,7 @@ } function isCompletedProjectNote(note: ProjectNote): boolean { - return noteRowPhase(note) === 'done'; + return projectNoteRowPhase(note) === 'done'; } function projectNoteReadState(note: ProjectNote) { @@ -1228,9 +1243,9 @@ })} + the sessions that were asked. A session waiting to be woken + when they end reads as running, so a click on its row opens + its chat, which says what it waits on. --> { ); }); - it('reads an empty note whose session is waiting on repo sessions as waiting, not failed', () => { + it('reads an empty note whose session is waiting on repo sessions as running, not failed', () => { const empty = note({ content: '', title: '' }); - expect(projectNoteRow(empty, { deleting: false, nowMs: NOW, wakeup: armed })).toEqual({ - type: 'waiting-note', - title: 'Waiting on 2 repo sessions', - secondaryMeta: undefined, - }); - // The title counts the named sessions still in flight, beside their badges. + // With the repo sessions' badges the subtitle is theirs alone. expect( projectNoteRow(empty, { deleting: false, nowMs: NOW, wakeup: armed, childBadges: [badge] }) - .title - ).toBe('Waiting on 1 repo session'); + ).toEqual({ + type: 'generating-note', + title: 'Generating note…', + secondaryMeta: undefined, + }); + // Before the badges are read, or with none in flight, it is the + // placeholder a running row shows. + expect(projectNoteRow(empty, { deleting: false, nowMs: NOW, wakeup: armed })).toEqual({ + type: 'generating-note', + title: 'Generating note…', + secondaryMeta: 'Generating note', + }); // The same note with no wake-up ended without writing anything. expect(projectNoteRow(empty, { deleting: false, nowMs: NOW }).type).toBe('failed-note'); }); - it('says what a written note’s session waits on in place of its timestamp', () => { + it('reads a written note whose session is waiting as running, under the note’s title', () => { expect( projectNoteRow(note(), { deleting: false, nowMs: NOW, wakeup: armed, childBadges: [badge] }) ).toEqual({ + type: 'generating-note', + title: 'A finished note', + secondaryMeta: undefined, + }); + // An untitled note has nothing to keep. + expect( + projectNoteRow(note({ title: ' ' }), { deleting: false, nowMs: NOW, wakeup: armed }).title + ).toBe('Generating note…'); + // Delivered or stopped, it is the finished note again. + expect(projectNoteRow(note(), { deleting: false, nowMs: NOW, childBadges: [] })).toEqual({ type: 'note', title: 'A finished note', - secondaryMeta: 'Waiting on 1 repo session', + secondaryMeta: '5m ago', + }); + }); + + it('never says a waiting session is waiting, in its title or its subtitle', () => { + const wakeups: SessionWakeup[] = [ + armed, + { ...armed, mode: 'any' }, + { ...armed, targetSessionIds: [] }, + ]; + for (const wakeup of wakeups) { + for (const source of [note(), note({ content: '', title: '' })]) { + for (const childBadges of [[], [badge], [badge, { ...badge, key: 'child-9' }]]) { + const row = projectNoteRow(source, { deleting: false, nowMs: NOW, wakeup, childBadges }); + expect(row.type).toBe('generating-note'); + expect(row.title).not.toMatch(/waiting/i); + expect(row.secondaryMeta ?? '').not.toMatch(/waiting/i); + } + } + } + }); + + it('leaves a session that is not completed to its own status while a wake-up is armed', () => { + // Kept across a rate-limit pause: the row is the pause's. + const paused = note({ + sessionStatus: 'paused', + content: '', + title: '', + completionReason: 'rate_limited', }); expect( - projectNoteRow(note(), { - deleting: false, - nowMs: NOW, - wakeup: { ...armed, mode: 'any' }, - }).secondaryMeta - ).toBe('Waiting on any of 2 repo sessions'); + projectNoteRow(paused, { deleting: false, nowMs: NOW, wakeup: armed, childBadges: [badge] }) + ).toEqual({ + type: 'failed-note', + title: 'Paused by API limit — no note yet', + secondaryMeta: '1 repo session still running', + }); }); it('counts the repo sessions a finished session left running without asking to be woken', () => { diff --git a/apps/staged/src/lib/features/projects/projectNoteRow.ts b/apps/staged/src/lib/features/projects/projectNoteRow.ts index 8e75311d4..d6a5c9fb9 100644 --- a/apps/staged/src/lib/features/projects/projectNoteRow.ts +++ b/apps/staged/src/lib/features/projects/projectNoteRow.ts @@ -5,10 +5,10 @@ * project row shows the failure copy as its title with no subtitle. * * A project session can also end its turn with repo sessions still going. If - * it armed a wake-up for them it is waiting: the row says what on, and a note - * it has not written yet reads as waiting, not failed. If it did not, the row - * says how many are still running. Either line takes the subtitle's place, - * ahead of the children's badges. + * it armed a wake-up for them, Staged starts its next turn when they end, and + * the row reads as running until then: the spinner and the children's badges, + * with nothing saying it is waiting. If it did not, the row is a finished one + * that says how many are still running, ahead of the children's badges. */ import type { ProjectNote, SessionWakeup } from '../../types'; @@ -20,6 +20,7 @@ import { type ChildSessionBadgeProps, } from '../timeline/childSessionBadges'; import { failedArtifactSubtitle } from '../timeline/sessionFailureCopy'; +import { isWaitingOnWakeup } from '../sessions/sessionWakeup'; import { noteRowPhase } from '../timeline/sessionRowState'; export type ProjectNoteRow = { @@ -55,39 +56,50 @@ export type ProjectNoteRowLive = { * subtitle over, and follow a finished row's line about them. */ childBadges?: ChildSessionBadgeProps[]; - /** The session's armed wake-up, when it has one. */ + /** + * The session's armed wake-up, when it has one. A session waiting on it + * reads as running (`noteRowPhase`). + */ wakeup?: SessionWakeup | null; }; +/** + * The title a session waiting to be woken has already given its note, if it + * has written one. A session in a turn does not show it: its row follows the + * turn's live title. + */ +function waitingNoteTitle( + note: ProjectNoteRowSource, + wakeup: SessionWakeup | null | undefined +): string | undefined { + if (!isWaitingOnWakeup(note.sessionStatus, wakeup)) return undefined; + return note.title.trim() || undefined; +} + export function projectNoteRow( note: ProjectNoteRowSource, live: ProjectNoteRowLive ): ProjectNoteRow { const childBadges = live.childBadges ?? []; // What a finished session's row says about its repo sessions, if anything. - const finishedMeta = finishedSecondaryMeta(note.sessionStatus, live.wakeup, childBadges); + const finishedMeta = finishedSecondaryMeta(childBadges); let row: ProjectNoteRow; switch (noteRowPhase(note, live.wakeup)) { // Project sessions start running, so a queued status never reaches a // project note today; if one did it would read as running, as before. + // + // A session waiting to be woken is here too. The stream brings a title + // and a hint for a session in a turn only, so its row has neither: it + // keeps the title of a note it has already written, and its subtitle is + // the badges of the repo sessions it started. case 'queued': case 'running': row = { type: 'generating-note', - title: live.liveTitle ?? 'Generating note…', + title: live.liveTitle ?? waitingNoteTitle(note, live.wakeup) ?? 'Generating note…', secondaryMeta: runningSecondaryMeta(childBadges, live.liveHint), }; break; - // Nothing written yet, and none expected until the session is woken. The - // stub is untitled, so what it waits on is the title; with badges the - // subtitle would only repeat it. - case 'waiting': - row = { - type: 'waiting-note', - title: finishedMeta ?? 'Waiting on repo sessions', - secondaryMeta: undefined, - }; - break; case 'failed': row = { type: 'failed-note', diff --git a/apps/staged/src/lib/features/sessions/SessionWakeupNotice.component.test.ts b/apps/staged/src/lib/features/sessions/SessionWakeupNotice.component.test.ts index 32e7a6b4e..5779cda7d 100644 --- a/apps/staged/src/lib/features/sessions/SessionWakeupNotice.component.test.ts +++ b/apps/staged/src/lib/features/sessions/SessionWakeupNotice.component.test.ts @@ -96,6 +96,16 @@ afterEach(() => { }); describe('SessionWakeupNotice', () => { + it('spins: a waiting session is still at work through its repo sessions', () => { + render({ wakeup: wakeup() }); + + const spinner = document.querySelector('[data-testid="session-wakeup-spinner"]'); + expect(spinner?.tagName.toLowerCase()).toBe('svg'); + expect(spinner?.classList.contains('animate-spin')).toBe(true); + // The alert lays itself out around an svg that is its direct child. + expect(spinner?.parentElement?.dataset.testid).toBe('session-wakeup-notice'); + }); + it('says what the session waits on, counting the named sessions still in flight', async () => { // One of the three has ended; a child it did not name is going too. listChildSessions.mockImplementation(async () => [ diff --git a/apps/staged/src/lib/features/sessions/SessionWakeupNotice.svelte b/apps/staged/src/lib/features/sessions/SessionWakeupNotice.svelte index e5417fce9..3a3eb04c9 100644 --- a/apps/staged/src/lib/features/sessions/SessionWakeupNotice.svelte +++ b/apps/staged/src/lib/features/sessions/SessionWakeupNotice.svelte @@ -3,11 +3,15 @@ waiting on repo sessions: a project session that ended its turn after asking Staged to start a new one when the repo sessions it named have ended. - Says what it is waiting on and when Staged checks in regardless, and offers - Stop waiting, which removes the wake-up and nothing else: the repo sessions - keep running and the session stays as its last turn left it. The composer - is not touched; a message sent while waiting resumes the session as usual - and leaves the wake-up in place. + The session is still at work through those repo sessions, so the notice + spins as a live turn's activity row does, and as the session's row in the + project's notes list does. It is the one place that says what the session + is waiting on, and when Staged checks in regardless. + + It offers Stop waiting, which removes the wake-up and nothing else: the + repo sessions keep running and the session stays as its last turn left it. + The composer is not touched; a message sent while waiting resumes the + session as usual and leaves the wake-up in place. The wake-up names every session it was armed for, including ones that have since ended, so the notice counts the ones still in flight itself: from the @@ -15,7 +19,7 @@ the named sessions changes status. --> - + +
{notice.message} diff --git a/apps/staged/src/lib/features/sessions/sessionWakeup.ts b/apps/staged/src/lib/features/sessions/sessionWakeup.ts index 3dbc34cf6..4d69506c9 100644 --- a/apps/staged/src/lib/features/sessions/sessionWakeup.ts +++ b/apps/staged/src/lib/features/sessions/sessionWakeup.ts @@ -6,8 +6,14 @@ * Waiting is deliberately not a `SessionStatus`. The session is `completed`, * and the backend reports the wake-up separately (`session-wakeup-changed`, * `get_session_wakeup`), as it reports the background hold beside `running`. - * These helpers turn that report into what the project's note row and the - * chat pane say. + * These helpers turn that report into what the surfaces showing the session + * say. + * + * To the user the session is still at work: the repo sessions it started are + * running, and it carries on when they end. So the project's note row shows + * it as running (`noteRowPhase`) with the repo sessions' badges, and does + * not say it is waiting. What it waits on is said in one place, the chat + * pane's notice, which is also where the wait can be stopped. */ import type { SessionWakeup } from '../../types'; @@ -61,7 +67,10 @@ function waitCount(wakeup: SessionWakeup, liveTargets: number | undefined): numb return liveTargets && liveTargets > 0 ? liveTargets : wakeup.targetSessionIds.length; } -/** What a waiting session is waiting on, in a few words. */ +/** + * What a waiting session is waiting on, in a few words. The chat pane's + * notice opens with it; the session's row does not show it. + */ export function wakeupWaitLabel(wakeup: SessionWakeup, liveTargets?: number): string { const count = waitCount(wakeup, liveTargets); if (count === 0) return 'Waiting on repo sessions'; diff --git a/apps/staged/src/lib/features/timeline/TimelineRow.svelte b/apps/staged/src/lib/features/timeline/TimelineRow.svelte index cc8e537cd..867e63038 100644 --- a/apps/staged/src/lib/features/timeline/TimelineRow.svelte +++ b/apps/staged/src/lib/features/timeline/TimelineRow.svelte @@ -19,7 +19,6 @@ import AlertTriangle from '@lucide/svelte/icons/alert-triangle'; import Clock from '@lucide/svelte/icons/clock'; import GitBranch from '@lucide/svelte/icons/git-branch'; - import Hourglass from '@lucide/svelte/icons/hourglass'; import GitMerge from '@lucide/svelte/icons/git-merge'; import ChevronsDown from '@lucide/svelte/icons/chevrons-down'; import CloudOff from '@lucide/svelte/icons/cloud-off'; @@ -38,7 +37,6 @@ | 'note' | 'generating-note' | 'queued-note' - | 'waiting-note' | 'failed-note' | 'review' | 'generating-review' @@ -74,8 +72,8 @@ /** * In-flight repo sessions this row's session spawned. Rendered after * `secondaryMeta`, which a running row leaves empty for them and a - * finished row uses to say what they are to it — distinct from `badges`, - * which counts comments/warnings on a finished artifact. + * finished row uses to say how many it left running — distinct from + * `badges`, which counts comments/warnings on a finished artifact. */ childSessionBadges?: ChildSessionBadgeProps[]; /** Opens a child's chat; receives the child's session id. */ @@ -188,13 +186,8 @@ type === 'note' || type === 'generating-note' || type === 'queued-note' || - type === 'waiting-note' || type === 'failed-note' ); - // A project session that ended its turn to wait on repo sessions before it - // wrote its note. Nothing is running in it and nothing failed: it is not - // pending (no spinner, no dimming) and there is no note to open yet. - let isWaiting = $derived(type === 'waiting-note'); let isReview = $derived( type === 'review' || type === 'generating-review' || @@ -368,10 +361,7 @@ class:commit-icon={type === 'commit' || type === 'pending-commit' || type === 'queued-commit'} - class:note-icon={type === 'note' || - type === 'generating-note' || - type === 'queued-note' || - type === 'waiting-note'} + class:note-icon={type === 'note' || type === 'generating-note' || type === 'queued-note'} class:review-icon={type === 'review' || type === 'generating-review' || type === 'queued-review'} @@ -386,8 +376,6 @@ {:else if isPending} - {:else if isWaiting} - {:else if isFailed} {:else if type === 'git-warning'} @@ -440,7 +428,7 @@ {:else} {title} {/if} diff --git a/apps/staged/src/lib/features/timeline/childSessionBadges.test.ts b/apps/staged/src/lib/features/timeline/childSessionBadges.test.ts index 83d367870..ba81c119e 100644 --- a/apps/staged/src/lib/features/timeline/childSessionBadges.test.ts +++ b/apps/staged/src/lib/features/timeline/childSessionBadges.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest'; -import type { ChildSessionInfo, SessionWakeup } from '../../types'; +import type { ChildSessionInfo } from '../../types'; import { buildChildSessionBadges, CHILD_BADGE_TITLE_MAX_CHARS, @@ -180,58 +180,24 @@ describe('runningSecondaryMeta', () => { }); describe('finishedSecondaryMeta', () => { - const armed: SessionWakeup = { - armed: true, - mode: 'all', - targetSessionIds: ['a', 'b', 'c'], - checkInAt: null, - armedAt: 1, - }; const badges = (...ids: string[]) => buildChildSessionBadges(ids.map((sessionId) => child({ sessionId }))); - it('says nothing for a finished session with no children going and no wake-up', () => { - expect(finishedSecondaryMeta('completed', null, [])).toBeUndefined(); - expect(finishedSecondaryMeta('error', undefined, [])).toBeUndefined(); - }); - - it('counts the children a session left running when it did not ask to be woken', () => { - expect(finishedSecondaryMeta('completed', null, badges('a'))).toBe( - '1 repo session still running' - ); - expect(finishedSecondaryMeta('completed', null, badges('a', 'b'))).toBe( - '2 repo sessions still running' - ); - // Whatever way the session ended: the children are going all the same. - expect(finishedSecondaryMeta('cancelled', null, badges('a'))).toBe( - '1 repo session still running' - ); - }); - - it('says what a waiting session waits on, counting the named sessions still in flight', () => { - expect(finishedSecondaryMeta('completed', armed, badges('a', 'b', 'c'))).toBe( - 'Waiting on 3 repo sessions' - ); - // One of the three has ended. - expect(finishedSecondaryMeta('completed', armed, badges('a', 'c'))).toBe( - 'Waiting on 2 repo sessions' - ); - // A child it did not name is badged but not waited on. - expect(finishedSecondaryMeta('completed', armed, badges('a', 'x'))).toBe( - 'Waiting on 1 repo session' - ); + it('says nothing for a finished session with no children going', () => { + expect(finishedSecondaryMeta([])).toBeUndefined(); }); - it('says a waiting session waits even when none of its children is known in flight', () => { - expect(finishedSecondaryMeta('completed', armed, [])).toBe('Waiting on 3 repo sessions'); + it('counts the children a finished session left running', () => { + expect(finishedSecondaryMeta(badges('a'))).toBe('1 repo session still running'); + expect(finishedSecondaryMeta(badges('a', 'b'))).toBe('2 repo sessions still running'); }); - it('reads an armed wake-up on a session that is not completed as no wait', () => { - // Kept across a rate-limit pause: the row is the pause's, and the - // children are simply still running. - expect(finishedSecondaryMeta('paused', armed, badges('a'))).toBe( - '1 repo session still running' - ); - expect(finishedSecondaryMeta('paused', armed, [])).toBeUndefined(); + it('never says a session is waiting: a waiting session is a running row, not a finished one', () => { + for (const row of [[], badges('a'), badges('a', 'b', 'c')]) { + expect(finishedSecondaryMeta(row) ?? '').not.toMatch(/waiting/i); + // The running row's subtitle is the badges, or the hint without them. + expect(runningSecondaryMeta(row, undefined) ?? '').not.toMatch(/waiting/i); + } + expect(runningSecondaryMeta(badges('a'), undefined)).toBeUndefined(); }); }); diff --git a/apps/staged/src/lib/features/timeline/childSessionBadges.ts b/apps/staged/src/lib/features/timeline/childSessionBadges.ts index 69500ffcc..692da6dbf 100644 --- a/apps/staged/src/lib/features/timeline/childSessionBadges.ts +++ b/apps/staged/src/lib/features/timeline/childSessionBadges.ts @@ -5,19 +5,17 @@ * subtitle. When it has repo sessions in flight, those badges say more than * the hint does, so they take the subtitle's place until the children finish. * - * A project session that has finished its turn keeps the badges of children - * still in flight, behind a line saying what they are to it: what it is - * waiting on, when it armed a wake-up for them, or what it left running, - * when it did not. + * A project session that ended its turn to be woken when its repo sessions + * end (it armed a wake-up) reads as running, so its row is a running row: + * the badges alone. The row does not say it is waiting. + * + * A project session that finished its turn without a wake-up keeps the + * badges of children still in flight, behind a line saying how many it left + * running. */ -import type { ChildSessionInfo, SessionWakeup } from '../../types'; -import { - isWaitingOnWakeup, - liveWakeupTargetCount, - stillRunningLabel, - wakeupWaitLabel, -} from '../sessions/sessionWakeup'; +import type { ChildSessionInfo } from '../../types'; +import { stillRunningLabel } from '../sessions/sessionWakeup'; import { sessionRowTitle, truncateTitle, type SessionRowKind } from './sessionRowTitle'; /** @@ -115,27 +113,13 @@ export function runningSecondaryMeta( * their badges; `undefined` when there is nothing to say and the row keeps * its own subtitle. * - * - Waiting on a wake-up: what it waits on, counting the targets still in - * flight. The badges may be more than that (children it did not name), or - * none (see `wakeupWaitLabel`). - * - No wake-up, children still in flight: how many. The agent ended its turn - * without asking to be woken, so nothing will bring it back to them. + * It says how many are still in flight. The agent ended its turn without + * asking to be woken, so nothing will bring it back to them. * - * `badges` are the row's, keyed by child session id. + * A session that did ask is not a finished row: it reads as running + * (`noteRowPhase`) and shows its badges with no line ahead of them + * (`runningSecondaryMeta`). */ -export function finishedSecondaryMeta( - sessionStatus: string | null | undefined, - wakeup: SessionWakeup | null | undefined, - badges: ChildSessionBadgeProps[] -): string | undefined { - if (isWaitingOnWakeup(sessionStatus, wakeup)) { - return wakeupWaitLabel( - wakeup, - liveWakeupTargetCount( - wakeup, - badges.map((badge) => badge.key) - ) - ); - } +export function finishedSecondaryMeta(badges: ChildSessionBadgeProps[]): string | undefined { return badges.length > 0 ? stillRunningLabel(badges.length) : undefined; } diff --git a/apps/staged/src/lib/features/timeline/sessionRowState.test.ts b/apps/staged/src/lib/features/timeline/sessionRowState.test.ts index 3ac66b62e..6095e2533 100644 --- a/apps/staged/src/lib/features/timeline/sessionRowState.test.ts +++ b/apps/staged/src/lib/features/timeline/sessionRowState.test.ts @@ -3,6 +3,7 @@ import { RESUMABLE_REASONS, type CompletionReason, type SessionWakeup } from '.. import { branchRowResumeOffer, canResumeRow, + isActiveRowPhase, noteRowPhase, type SessionRowPhase, } from './sessionRowState'; @@ -55,20 +56,41 @@ describe('noteRowPhase', () => { expect(noteRowPhase({ sessionStatus: null, content: 'Body' })).toBe('done'); }); - it('reads an empty note whose session is waiting on a wake-up as waiting, not failed', () => { + it('reads an empty note whose session is waiting on a wake-up as running, not failed', () => { const empty = { sessionId: 's', sessionStatus: 'completed', content: '' }; - expect(noteRowPhase(empty, ARMED)).toBe('waiting'); - expect(noteRowPhase({ ...empty, content: ' \n' }, ARMED)).toBe('waiting'); + expect(noteRowPhase(empty, ARMED)).toBe('running'); + expect(noteRowPhase({ ...empty, content: ' \n' }, ARMED)).toBe('running'); // No wake-up, or one that was cleared: the session ended without a note. expect(noteRowPhase(empty)).toBe('failed'); expect(noteRowPhase(empty, null)).toBe('failed'); expect(noteRowPhase(empty, { ...ARMED, armed: false })).toBe('failed'); }); - it('keeps a written note done while its session waits: what it waits on is the subtitle', () => { - expect( - noteRowPhase({ sessionId: 's', sessionStatus: 'completed', content: 'Body' }, ARMED) - ).toBe('done'); + it('reads a written note whose session is waiting on a wake-up as running, not done', () => { + const written = { sessionId: 's', sessionStatus: 'completed', content: 'Body' }; + expect(noteRowPhase(written, ARMED)).toBe('running'); + // Once the wake-up is delivered or stopped, the note is a finished one. + expect(noteRowPhase(written)).toBe('done'); + expect(noteRowPhase(written, { ...ARMED, armed: false })).toBe('done'); + }); + + it('has no phase of its own for waiting: a session reads as queued, running, failed or done', () => { + const phases = new Set(); + for (const sessionStatus of ['queued', 'running', 'disconnected', 'completed', 'paused']) { + for (const content of ['', 'Body']) { + for (const wakeup of [ARMED, null]) { + phases.add(noteRowPhase({ sessionId: 's', sessionStatus, content }, wakeup)); + } + } + } + expect([...phases].sort()).toEqual(['done', 'failed', 'queued', 'running']); + }); + + it('counts queued and running rows as at work, and no others', () => { + expect(isActiveRowPhase('queued')).toBe(true); + expect(isActiveRowPhase('running')).toBe(true); + expect(isActiveRowPhase('failed')).toBe(false); + expect(isActiveRowPhase('done')).toBe(false); }); it('lets the session status speak for a wake-up armed in any other status', () => { @@ -113,8 +135,12 @@ describe('canResumeRow', () => { it('withholds Resume while the session is waiting to be woken', () => { // A turn held to its cap is resumable, and still waiting: Staged resumes - // it itself when the repo sessions end. - expect(canResumeRow(row({ completionReason: 'held_until_cap', phase: 'waiting' }))).toBe(false); + // it itself when the repo sessions end. A waiting session reads as + // running, written note or not. + for (const content of ['', 'Body']) { + const phase = noteRowPhase({ sessionId: 's', sessionStatus: 'completed', content }, ARMED); + expect(canResumeRow(row({ completionReason: 'held_until_cap', phase }))).toBe(false); + } }); it('withholds Resume while the row is being deleted', () => { diff --git a/apps/staged/src/lib/features/timeline/sessionRowState.ts b/apps/staged/src/lib/features/timeline/sessionRowState.ts index 0daf86084..f12178a29 100644 --- a/apps/staged/src/lib/features/timeline/sessionRowState.ts +++ b/apps/staged/src/lib/features/timeline/sessionRowState.ts @@ -21,11 +21,10 @@ import { isWaitingOnWakeup } from '../sessions/sessionWakeup'; export { RESUME_PROMPT as RESUME_ROW_PROMPT } from '../../shared/resumePrompt'; /** - * What a session row shows: waiting in the branch queue, running, waiting on - * repo sessions with nothing written yet, finished without writing its - * artifact, or done. + * What a session row shows: waiting in the branch queue, running, finished + * without writing its artifact, or done. */ -export type SessionRowPhase = 'queued' | 'running' | 'waiting' | 'failed' | 'done'; +export type SessionRowPhase = 'queued' | 'running' | 'failed' | 'done'; /** * The phase of a note row. A disconnected session is still in flight on its @@ -35,11 +34,13 @@ export type SessionRowPhase = 'queued' | 'running' | 'waiting' | 'failed' | 'don * A note with no session is a note the user wrote, so it is always done. * * `wakeup` is the session's wake-up, for a project session; a branch note's - * session has none. An empty note whose session is waiting on one - * (`isWaitingOnWakeup`) has not failed: its agent ended the turn to wait for - * repo sessions and writes the note in the turn that wakes it. A written note - * whose session is waiting is done, like any other written note; what it - * waits on is the row's subtitle, not its phase. + * session has none. A session waiting on one (`isWaitingOnWakeup`) ended its + * turn to wait for repo sessions, and Staged starts its next turn when they + * end. Its work is still going on in those sessions, so its row reads as + * running whether or not it has written its note: not as failed, when the + * note is still empty, and not as done, when it is not. The wait is not a + * phase of its own and is not spelled out on the row; the chat pane says + * what the session waits on. */ export function noteRowPhase( note: { @@ -51,16 +52,21 @@ export function noteRowPhase( ): SessionRowPhase { if (note.sessionStatus === 'queued') return 'queued'; if (isSessionInFlight(note.sessionStatus)) return 'running'; - if (note.sessionId && !note.content?.trim()) { - return isWaitingOnWakeup(note.sessionStatus, wakeup) ? 'waiting' : 'failed'; - } + if (note.sessionId && isWaitingOnWakeup(note.sessionStatus, wakeup)) return 'running'; + if (note.sessionId && !note.content?.trim()) return 'failed'; return 'done'; } +/** Whether a row shows its session as at work: queued or running. */ +export function isActiveRowPhase(phase: SessionRowPhase): boolean { + return phase === 'queued' || phase === 'running'; +} + /** * Whether a row offers Resume: it has a session, the session ended for a * resumable reason, the row isn't being deleted, and the session isn't - * queued, running or waiting to be woken already. + * queued or running already. A session waiting to be woken reads as running + * (`noteRowPhase`), so it offers none either: Staged resumes it. * * Completed rows count too. A note written by a turn whose background hold was * stopped (`hold_stopped`, `held_until_cap`) is done and still worth nudging. @@ -72,7 +78,7 @@ export function canResumeRow(row: { phase: SessionRowPhase; }): boolean { if (!row.sessionId || row.deleting) return false; - if (row.phase === 'queued' || row.phase === 'running' || row.phase === 'waiting') return false; + if (isActiveRowPhase(row.phase)) return false; return isResumableReason(row.completionReason); } From aec1379cf387598a6ac66601d02a7990ed848bf4 Mon Sep 17 00:00:00 2001 From: Matt Toohey Date: Thu, 3 Dec 2026 13:32:15 +1100 Subject: [PATCH 2/3] fix(staged): keep a written note's own state while its session waits to be woken MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 60e6366a9 made a project session that is waiting on its wake-up read as running. For a session that had already written its note this took more than the row's look, and the review of that commit flagged three things. The note's own state went with the row's phase. `isCompletedProjectNote` asked the wake-up-aware phase, so the note lost "New session referring to this note" and Mark as read/unread from its context menu, and its row lost the chat button's state and the reply-draft mark, for as long as the repo sessions ran. It now asks about the note alone: written, by a session that is not in a turn. The row's look, sort position, click target and Resume still follow the wake-up-aware phase. The unread dot does too, through a separate `showsNoteUnread`: a written note whose session is in a turn already shows none, and a waiting row matches that. The note stays unread, the menu still offers to mark it read, and the dot is back when the wait ends. The row could read "A finished note / Generating note". With no child badges the subtitle fell back to the running placeholder, on every project open until the children were read, and for as long as the awaited sessions were between states. A waiting session with a written note now reads as the finished note's row does: its title ("Untitled note" when it has none) and, when there are no badges, when it was written. Badges still take the subtitle's place. A waiting session that has not written its note is unchanged. The component tests could not see any of this. The row stub now records `unread`, `chatState`, `hasDraft` and the context-menu key, and the context-menu stub records each action's hashtag ref and its read marks. New tests pin a written, unread note with an armed wake-up (no dot; chat state, draft mark, reference and Mark as read kept), a read one (Mark as unread kept), the dated subtitle, and the mid-turn row the dot is matched to. Not changed: an unwritten row still drops from the turn's live title to "Generating note…" when the turn ends. The live rows drop a session's title once the stream says it is no longer running, and a project note carries no ACP title, so keeping it would need new state. Signed-off-by: Matt Toohey Co-Authored-By: Claude Fable 5.2 --- .../projects/ProjectSection.component.test.ts | 141 ++++++++++++++++++ .../features/projects/ProjectSection.svelte | 31 +++- .../features/projects/projectNoteRow.test.ts | 52 ++++++- .../lib/features/projects/projectNoteRow.ts | 56 ++++--- .../testStubs/TimelineContextMenuStub.svelte | 30 +++- .../sessions/testStubs/TimelineRowStub.svelte | 18 ++- .../features/timeline/childSessionBadges.ts | 2 +- 7 files changed, 296 insertions(+), 34 deletions(-) diff --git a/apps/staged/src/lib/features/projects/ProjectSection.component.test.ts b/apps/staged/src/lib/features/projects/ProjectSection.component.test.ts index 11184f8a1..7c42b9ec0 100644 --- a/apps/staged/src/lib/features/projects/ProjectSection.component.test.ts +++ b/apps/staged/src/lib/features/projects/ProjectSection.component.test.ts @@ -50,6 +50,10 @@ const { ), deleteProjectNote: vi.fn(async (_noteId: string): Promise => {}), cancelSession: vi.fn(async (_sessionId: string): Promise => {}), + // "Mark as read" on a note's context menu. + setProjectNoteRead: vi.fn( + async (_noteId: string, _read: boolean): Promise => null + ), listChildSessions: vi.fn(async (_sessionId: string): Promise => []), // What the note dialog's `#note:` references are built from once it opens. listChildNotes: vi.fn(async (_projectNoteId: string) => []), @@ -149,6 +153,7 @@ vi.mock('../../commands', async (importOriginal) => ({ import ProjectSection from './ProjectSection.svelte'; import { reactiveProps } from '../sessions/testStubs/reactiveProps.svelte'; import { sessionWakeupsStore } from '../../stores/sessionWakeups.svelte'; +import { replyDraftPresence } from '../sessions/replyDrafts'; const project = { id: 'project-1', @@ -296,6 +301,23 @@ function rowFor(sessionId: string): HTMLElement { return row; } +/** What the context menu holds for a session's row, found by the row's menu key. */ +function menuActionFor(sessionId: string): HTMLElement { + const key = rowFor(sessionId).dataset.contextMenuKey; + const action = document.querySelector( + `[data-testid="context-menu-action"][data-key="${key}"]` + ); + if (!action) throw new Error(`no context-menu action for ${sessionId}`); + return action; +} + +/** The row's menu item marking its note `state`, when the menu offers it. */ +function menuMarkButton(sessionId: string, state: 'read' | 'unread'): HTMLButtonElement | null { + return menuActionFor(sessionId).querySelector( + `[data-testid="menu-mark-${state}"]` + ); +} + function resumeButton(sessionId: string): HTMLButtonElement | null { return rowFor(sessionId).querySelector('[data-testid="row-resume"]'); } @@ -1053,6 +1075,125 @@ describe('ProjectSection sessions waiting on repo sessions', () => { unmount(section); }); + it('dates a written note’s waiting row as the finished note’s is when it has no badges', async () => { + listNotes(completedNote); + const section = mountSection(); + await settle(); + // The finished note's subtitle: when it was written. + const dated = rowFor('session-1').dataset.secondaryMeta; + expect(dated).toBeTruthy(); + + // It waits on a repo session that is not among its children: the + // children have not been read, or the target is between states. + await emitWakeup('session-1', armedWakeup('child-1')); + + const row = rowFor('session-1'); + expect(row.dataset.type).toBe('generating-note'); + expect(row.dataset.title).toBe('A finished note'); + expect(row.dataset.childBadges).toBe(''); + // No turn is running and the note is written: nothing is being generated. + expect(row.dataset.secondaryMeta).toBe(dated); + expect(rowText(row)).not.toMatch(/generating|waiting/i); + + unmount(section); + }); + + it('keeps a written note’s menu actions, chat state and reply draft while its session waits', async () => { + // Unread, with a reply in its chat the user has not seen and one of the + // user's own left unsent. + listNotes(noteWith({ readAt: null, lastChatMessageAt: 5, chatReadAt: null })); + listChildren({ 'session-1': [childSession('child-1')] }); + replyDraftPresence.preview('session-1', { quotes: [], text: 'An unsent reply' }); + commandMocks.setProjectNoteRead.mockImplementation(async (noteId, read) => + noteWith({ id: noteId, readAt: read ? 9 : null }) + ); + const section = mountSection(); + await settle(); + // The finished note: all of it shows, the unread dot included. + expect(rowFor('session-1').dataset).toMatchObject({ + type: 'note', + unread: 'true', + chatState: 'unread', + hasDraft: 'true', + }); + + await emitWakeup('session-1', armedWakeup('child-1')); + + // The row reads as running, and like any running row carries no unread + // dot. What belongs to the note is still there. + const row = rowFor('session-1'); + expect(row.dataset).toMatchObject({ + type: 'generating-note', + unread: 'false', + chatState: 'unread', + hasDraft: 'true', + }); + expect(row.dataset.childBadges).toBe('child-1:running'); + expect(resumeButton('session-1')).toBeNull(); + // The note is still unread, so the menu marks it read, + expect(menuMarkButton('session-1', 'unread')).toBeNull(); + menuMarkButton('session-1', 'read')!.click(); + await settle(); + expect(commandMocks.setProjectNoteRead.mock.calls).toEqual([['note-1', true]]); + // and it can be referred to from a new session. + expect(menuActionFor('session-1').dataset.hashtagRef).toBe(REF); + writer.saveNow.mockClear(); + writer.scheduleSave.mockClear(); + loadDraftMock.mockImplementation(async () => null); + clickReferring(); + await settle(); + expect(promptInput()).not.toBeNull(); + expect(savedPrompts().some((prompt) => prompt.includes(REF))).toBe(true); + + replyDraftPresence.preview('session-1', { quotes: [], text: '' }); + unmount(section); + }); + + it('offers to mark a read note unread while its session waits', async () => { + listNotes(noteWith({ readAt: 5 })); + commandMocks.getSessionWakeup.mockImplementation(async () => armedWakeup('child-1')); + const section = mountSection(); + await settle(); + + const row = rowFor('session-1'); + expect(row.dataset).toMatchObject({ + type: 'generating-note', + unread: 'false', + chatState: 'none', + hasDraft: 'false', + }); + expect(menuMarkButton('session-1', 'read')).toBeNull(); + expect(menuMarkButton('session-1', 'unread')).not.toBeNull(); + + unmount(section); + }); + + // What the waiting row's unread dot is matched to: a written note whose + // session is in a turn carries none. Unlike a waiting one it is not a + // finished note meanwhile, so its menu offers neither the reference nor + // the read marks, and its row shows no chat state or reply draft. + it('shows no unread dot or note actions on a written note whose session is in a turn', async () => { + listNotes( + noteWith({ sessionStatus: 'running', readAt: null, lastChatMessageAt: 5, chatReadAt: null }) + ); + replyDraftPresence.preview('session-1', { quotes: [], text: 'An unsent reply' }); + const section = mountSection(); + await settle(); + + expect(rowFor('session-1').dataset).toMatchObject({ + type: 'generating-note', + unread: 'false', + chatState: 'none', + hasDraft: 'false', + }); + expect(menuActionFor('session-1').dataset.hashtagRef).toBe(''); + expect(menuMarkButton('session-1', 'read')).toBeNull(); + expect(menuMarkButton('session-1', 'unread')).toBeNull(); + + replyDraftPresence.preview('session-1', { quotes: [], text: '' }); + unmount(section); + }); + it('lists a waiting session among the running ones, after the finished notes', async () => { // Written before the finished note, so by date alone it would come first. listNotes( diff --git a/apps/staged/src/lib/features/projects/ProjectSection.svelte b/apps/staged/src/lib/features/projects/ProjectSection.svelte index b2b61b838..e831c1d3d 100644 --- a/apps/staged/src/lib/features/projects/ProjectSection.svelte +++ b/apps/staged/src/lib/features/projects/ProjectSection.svelte @@ -888,14 +888,33 @@ if (openNote) void loadChildHashtagItems(openNote.noteId, true); } + /** + * Whether the note itself is finished: written, by a session that is not in + * a turn. Asked without the wake-up, unlike `projectNoteRowPhase`. A + * session waiting to be woken reads as running on its row, but the note it + * wrote is as finished as any: it can be referred to and marked read or + * unread, and its chat's replies and reply draft show on its row. + */ function isCompletedProjectNote(note: ProjectNote): boolean { - return projectNoteRowPhase(note) === 'done'; + return noteRowPhase(note) === 'done'; } + /** The read state the note's context menu offers to toggle, if any. */ function projectNoteReadState(note: ProjectNote) { return isCompletedProjectNote(note) ? noteReadState(note) : null; } + /** + * Whether the note's row carries the unread dot. Only a row that reads as + * finished does: a written note whose session is in a turn shows none, and + * neither does one whose session reads as running while it waits to be + * woken. The note stays unread, and the dot is back when the row is the + * finished note's again. + */ + function showsNoteUnread(note: ProjectNote): boolean { + return projectNoteRowPhase(note) === 'done' && projectNoteReadState(note) === 'unread'; + } + function setProjectNoteRead(noteId: string, read: boolean) { void setNoteReadState({ kind: 'project', noteId }, read); } @@ -1245,7 +1264,9 @@ keeps those of children still going, and the map holds only the sessions that were asked. A session waiting to be woken when they end reads as running, so a click on its row opens - its chat, which says what it waits on. --> + its chat, which says what it waits on. What belongs to a + note it has written stays: its chat's replies and reply + draft here, and its context-menu actions. --> openProjectNote(note) diff --git a/apps/staged/src/lib/features/projects/projectNoteRow.test.ts b/apps/staged/src/lib/features/projects/projectNoteRow.test.ts index 95eee7adc..60aa19f4e 100644 --- a/apps/staged/src/lib/features/projects/projectNoteRow.test.ts +++ b/apps/staged/src/lib/features/projects/projectNoteRow.test.ts @@ -159,10 +159,6 @@ describe('projectNoteRow', () => { title: 'A finished note', secondaryMeta: undefined, }); - // An untitled note has nothing to keep. - expect( - projectNoteRow(note({ title: ' ' }), { deleting: false, nowMs: NOW, wakeup: armed }).title - ).toBe('Generating note…'); // Delivered or stopped, it is the finished note again. expect(projectNoteRow(note(), { deleting: false, nowMs: NOW, childBadges: [] })).toEqual({ type: 'note', @@ -171,6 +167,50 @@ describe('projectNoteRow', () => { }); }); + it('dates a written note whose session is waiting when it has no badges to show', () => { + // Before the badges are read, or with none in flight. No turn is running + // and the note is written, so the row does not say one is being generated. + expect(projectNoteRow(note(), { deleting: false, nowMs: NOW, wakeup: armed })).toEqual({ + type: 'generating-note', + title: 'A finished note', + secondaryMeta: '5m ago', + }); + expect( + projectNoteRow(note({ updatedAt: 8 * 60_000 }), { + deleting: false, + nowMs: NOW, + wakeup: armed, + childBadges: [], + }).secondaryMeta + ).toBe('Updated 2m ago'); + // Untitled, it is titled as the finished note's row is. + expect( + projectNoteRow(note({ title: '' }), { deleting: false, nowMs: NOW, wakeup: armed }) + ).toEqual({ + type: 'generating-note', + title: 'Untitled note', + secondaryMeta: '5m ago', + }); + // A stream title or hint left over from its turn is not shown. + expect( + projectNoteRow(note(), { + deleting: false, + nowMs: NOW, + wakeup: armed, + liveTitle: 'Plan the rollout', + liveHint: 'Reading the deploy docs', + }) + ).toEqual({ + type: 'generating-note', + title: 'A finished note', + secondaryMeta: '5m ago', + }); + // Being deleted, it says so like any row. + expect( + projectNoteRow(note(), { deleting: true, nowMs: NOW, wakeup: armed }).secondaryMeta + ).toBe('Deleting...'); + }); + it('never says a waiting session is waiting, in its title or its subtitle', () => { const wakeups: SessionWakeup[] = [ armed, @@ -184,6 +224,10 @@ describe('projectNoteRow', () => { expect(row.type).toBe('generating-note'); expect(row.title).not.toMatch(/waiting/i); expect(row.secondaryMeta ?? '').not.toMatch(/waiting/i); + // Nor that a note it has already written is being generated. + if (source.content) { + expect(`${row.title} ${row.secondaryMeta ?? ''}`).not.toMatch(/generating/i); + } } } } diff --git a/apps/staged/src/lib/features/projects/projectNoteRow.ts b/apps/staged/src/lib/features/projects/projectNoteRow.ts index d6a5c9fb9..f4a031677 100644 --- a/apps/staged/src/lib/features/projects/projectNoteRow.ts +++ b/apps/staged/src/lib/features/projects/projectNoteRow.ts @@ -7,8 +7,10 @@ * A project session can also end its turn with repo sessions still going. If * it armed a wake-up for them, Staged starts its next turn when they end, and * the row reads as running until then: the spinner and the children's badges, - * with nothing saying it is waiting. If it did not, the row is a finished one - * that says how many are still running, ahead of the children's badges. + * with nothing saying it is waiting. A note it has already written keeps its + * own words under the spinner: its title, and its date when there are no + * badges to show. If it did not arm one, the row is a finished one that says + * how many are still running, ahead of the children's badges. */ import type { ProjectNote, SessionWakeup } from '../../types'; @@ -63,17 +65,20 @@ export type ProjectNoteRowLive = { wakeup?: SessionWakeup | null; }; +/** The title of a note that has been written. */ +function writtenNoteTitle(note: ProjectNoteRowSource): string { + return note.title || 'Untitled note'; +} + /** - * The title a session waiting to be woken has already given its note, if it - * has written one. A session in a turn does not show it: its row follows the - * turn's live title. + * Whether the session is waiting to be woken with its note already written: + * without the wake-up, the row would be the finished note's. */ -function waitingNoteTitle( +function isWaitingWithWrittenNote( note: ProjectNoteRowSource, wakeup: SessionWakeup | null | undefined -): string | undefined { - if (!isWaitingOnWakeup(note.sessionStatus, wakeup)) return undefined; - return note.title.trim() || undefined; +): boolean { + return isWaitingOnWakeup(note.sessionStatus, wakeup) && noteRowPhase(note) === 'done'; } export function projectNoteRow( @@ -87,18 +92,29 @@ export function projectNoteRow( switch (noteRowPhase(note, live.wakeup)) { // Project sessions start running, so a queued status never reaches a // project note today; if one did it would read as running, as before. - // - // A session waiting to be woken is here too. The stream brings a title - // and a hint for a session in a turn only, so its row has neither: it - // keeps the title of a note it has already written, and its subtitle is - // the badges of the repo sessions it started. case 'queued': case 'running': - row = { - type: 'generating-note', - title: live.liveTitle ?? waitingNoteTitle(note, live.wakeup) ?? 'Generating note…', - secondaryMeta: runningSecondaryMeta(childBadges, live.liveHint), - }; + if (isWaitingWithWrittenNote(note, live.wakeup)) { + // No turn is running, so nothing is being generated and the stream + // brings no title or hint. The row says what the finished note's row + // says: its title and when it was written. The badges of the repo + // sessions it started take the date's place, as they take a running + // row's hint. + row = { + type: 'generating-note', + title: writtenNoteTitle(note), + secondaryMeta: childBadges.length > 0 ? undefined : formatNoteTimestamp(note, live.nowMs), + }; + } else { + // In a turn, or waiting to be woken before writing its note. A + // waiting session has no live title or hint, so its row reads as a + // running one does before the stream has brought any. + row = { + type: 'generating-note', + title: live.liveTitle ?? 'Generating note…', + secondaryMeta: runningSecondaryMeta(childBadges, live.liveHint), + }; + } break; case 'failed': row = { @@ -113,7 +129,7 @@ export function projectNoteRow( case 'done': row = { type: 'note', - title: note.title || 'Untitled note', + title: writtenNoteTitle(note), secondaryMeta: finishedMeta ?? formatNoteTimestamp(note, live.nowMs), }; break; diff --git a/apps/staged/src/lib/features/sessions/testStubs/TimelineContextMenuStub.svelte b/apps/staged/src/lib/features/sessions/testStubs/TimelineContextMenuStub.svelte index 29147601f..74feb7972 100644 --- a/apps/staged/src/lib/features/sessions/testStubs/TimelineContextMenuStub.svelte +++ b/apps/staged/src/lib/features/sessions/testStubs/TimelineContextMenuStub.svelte @@ -2,7 +2,10 @@ Test stub for TimelineContextMenu: renders its children plus a button that fires `onNewSessionReferring` with the first action's hashtag ref, so component tests can drive the "new session referring" path without the - real context-menu gestures. + real context-menu gestures. Each action is also recorded by its key, with + the hashtag ref it offers and its "Mark as read" and "Mark as unread" + callbacks as plain buttons, so a test can assert on what one row's menu + holds. --> @@ -82,12 +83,7 @@ data-testid="session-wakeup-spinner" /> -
- {notice.message} - {#if notice.checkIn} - {notice.checkIn} - {/if} -
+ {message}