feat(tui): navigate child sessions (subagents)

This commit is contained in:
adamdotdevin
2025-08-15 10:16:08 -05:00
parent 1ae38c90a3
commit 07dbc30c63
10 changed files with 294 additions and 65 deletions

View File

@@ -218,6 +218,12 @@ export namespace Config {
session_unshare: z.string().optional().default("none").describe("Unshare current session"),
session_interrupt: z.string().optional().default("esc").describe("Interrupt current session"),
session_compact: z.string().optional().default("<leader>c").describe("Compact the session"),
session_child_cycle: z.string().optional().default("ctrl+right").describe("Cycle to next child session"),
session_child_cycle_reverse: z
.string()
.optional()
.default("ctrl+left")
.describe("Cycle to previous child session"),
messages_page_up: z.string().optional().default("pgup").describe("Scroll messages up by one page"),
messages_page_down: z.string().optional().default("pgdown").describe("Scroll messages down by one page"),
messages_half_page_up: z.string().optional().default("ctrl+alt+u").describe("Scroll messages up by half page"),

View File

@@ -293,8 +293,18 @@ export namespace Server {
},
},
}),
zValidator(
"json",
z
.object({
parentID: z.string().optional(),
title: z.string().optional(),
})
.optional(),
),
async (c) => {
const session = await Session.create()
const body = c.req.valid("json") ?? {}
const session = await Session.create(body.parentID, body.title)
return c.json(session)
},
)

View File

@@ -163,12 +163,12 @@ export namespace Session {
},
)
export async function create(parentID?: string) {
export async function create(parentID?: string, title?: string) {
const result: Info = {
id: Identifier.descending("session"),
version: Installation.VERSION,
parentID,
title: createDefaultTitle(!!parentID),
title: title ?? createDefaultTitle(!!parentID),
time: {
created: Date.now(),
updated: Date.now(),

View File

@@ -23,11 +23,11 @@ export const TaskTool = Tool.define("task", async () => {
subagent_type: z.string().describe("The type of specialized agent to use for this task"),
}),
async execute(params, ctx) {
const session = await Session.create(ctx.sessionID)
const msg = await Session.getMessage(ctx.sessionID, ctx.messageID)
if (msg.info.role !== "assistant") throw new Error("Not an assistant message")
const agent = await Agent.get(params.subagent_type)
if (!agent) throw new Error(`Unknown agent type: ${params.subagent_type} is not a valid agent type`)
const session = await Session.create(ctx.sessionID, params.description + ` (@${agent.name} subagent)`)
const msg = await Session.getMessage(ctx.sessionID, ctx.messageID)
if (msg.info.role !== "assistant") throw new Error("Not an assistant message")
const messageID = Identifier.ascending("message")
const parts: Record<string, MessageV2.ToolPart> = {}
const unsub = Bus.subscribe(MessageV2.Event.PartUpdated, async (evt) => {