Skip to content

The agent that grows with you

fix(tui): /branch keeps main's "branched → <title>" line after the child resume

Tekniumc9221af7091f
diff --git a/ui-tui/src/__tests__/canonicalSessionControls.test.ts b/ui-tui/src/__tests__/canonicalSessionControls.test.ts
index d06dcf70c68..02e7cd913e3 100644
--- a/ui-tui/src/__tests__/canonicalSessionControls.test.ts
+++ b/ui-tui/src/__tests__/canonicalSessionControls.test.ts
@@ -21,6 +21,10 @@ function harness() {
}
}
+ if (method === 'session.info') {
+ return { title: params.session_id === 'child' ? 'Parent #2' : 'Parent' }
+ }
+
if (method === 'session.mutate') {
compressed = params.operation === 'compress'
@@ -180,6 +184,32 @@ it('a guarded canonical model switch asks; yes re-sends once with the owner toke
}
})
+it('/branch prints main\'s "branched →" confirmation after the child resume has repainted', async () => {
+ // The resume resets the visible history: a line printed before it settles is wiped (FINDINGS row 26).
+ const { ctx, slash } = harness()
+ const order: string[] = []
+ let settle!: () => void
+ ctx.session.resumeById = vi.fn(() => {
+ order.push('resume')
+
+ return new Promise<void>(resolve => {
+ settle = () => {
+ order.push('repainted')
+ patchUiState({ sid: 'child' }) // the resume moves the view (and the slash's destination) to the child
+ resolve()
+ }
+ })
+ })
+ ctx.transcript.sys = vi.fn((line: string) => order.push(`sys:${line}`))
+
+ slash('/branch Child name')
+ await flush()
+ expect(order).toEqual(['resume'])
+ settle()
+ await flush()
+ expect(order).toEqual(['resume', 'repainted', 'sys:branched → Parent #2'])
+})
+
it('a /compress that removes nothing prints main\'s "No changes" report without re-hydrating', async () => {
const { ctx, request, slash } = harness()
request.mockImplementation(async (method: string) => {
diff --git a/ui-tui/src/app/interfaces.ts b/ui-tui/src/app/interfaces.ts
index b7d51e3f719..ad3ea5d5fd2 100644
--- a/ui-tui/src/app/interfaces.ts
+++ b/ui-tui/src/app/interfaces.ts
@@ -578,7 +578,7 @@ export interface SlashHandlerContext {
newLiveSession: (msg?: string, title?: string) => void
newSession: (msg?: string, title?: string) => void
resetVisibleHistory: (info?: null | SessionInfo) => void
- resumeById: (id: string) => void
+ resumeById: (id: string) => Promise<void> | void
setSessionStartedAt: StateSetter<number>
}
slashFlightRef: MutableRefObject<number>
diff --git a/ui-tui/src/app/slash/canonicalSessionControls.ts b/ui-tui/src/app/slash/canonicalSessionControls.ts
index bb76011653a..cb3d0c55bfd 100644
--- a/ui-tui/src/app/slash/canonicalSessionControls.ts
+++ b/ui-tui/src/app/slash/canonicalSessionControls.ts
@@ -209,13 +209,27 @@ function isSupersededControl(
)
}
-function applyBranchResult(result: CanonicalControlResult, arg: string, ctx: SlashRunCtx) {
+async function applyBranchResult(result: CanonicalControlResult, arg: string, ctx: SlashRunCtx) {
if (!result.branched_session_id) {
throw new Error(t('session.common.invalidResponse', 'branch'))
}
- ctx.session.resumeById(result.branched_session_id)
- ctx.transcript.sys(t('slashCmd.session.branch.branched', arg || result.branched_session_id))
+ // The child resume repaints the transcript; main's "branched →" line is printed after it, or the
+ // reset wipes it.
+ const child = result.branched_session_id as string
+
+ await ctx.session.resumeById(child)
+
+ // Main named the child by its title ("Slash lane #2" for an untitled branch of "Slash lane").
+ const info = await ctx.gateway.gw
+ .request<{ title?: null | string }>('session.info', { session_id: child })
+ .catch(() => null)
+
+ // The resume moved this view to the child, so the slash's own staleness check no longer applies:
+ // print only while the child is still the view's session.
+ if (getUiState().sid === child) {
+ ctx.transcript.sys(t('slashCmd.session.branch.branched', asRpcResult(info)?.title?.trim() || arg || child))
+ }
}
function applyModelResult(result: CanonicalControlResult, ctx: SlashRunCtx) {
@@ -307,7 +321,7 @@ export async function runCanonicalSessionControl(
if (operation === 'model' && needsModelConfirmation(result)) {
askModelConfirmation(result, arg, ctx, Boolean(confirm))
} else if (operation === 'branch') {
- applyBranchResult(result, arg, ctx)
+ await applyBranchResult(result, arg, ctx)
} else if (operation === 'model') {
applyModelResult(result, ctx)
} else if (result.status === 'preview') {