feat(delegate-task): unify TUI metadata by adding model field to all 5 executor paths

This commit is contained in:
YeonGyu-Kim
2026-03-04 16:35:06 +09:00
parent 6897761b21
commit d6b0e564bf
6 changed files with 195 additions and 16 deletions

View File

@@ -33,6 +33,7 @@ export async function executeBackgroundContinuation(
run_in_background: args.run_in_background,
sessionId: task.sessionID,
command: args.command,
model: task.model ? { providerID: task.model.providerID, modelID: task.model.modelID } : undefined,
},
}
await ctx.metadata?.(bgContMeta)

View File

@@ -67,6 +67,7 @@ export async function executeBackgroundTask(
run_in_background: args.run_in_background,
sessionId: sessionId ?? "pending",
command: args.command,
model: categoryModel ? { providerID: categoryModel.providerID, modelID: categoryModel.modelID } : undefined,
},
}
await ctx.metadata?.(unstableMeta)

View File

@@ -0,0 +1,172 @@
const { describe, test, expect, mock } = require("bun:test")
import type { DelegateTaskArgs, ToolContextWithMetadata } from "./types"
import type { ParentContext } from "./executor-types"
const MODEL = { providerID: "anthropic", modelID: "claude-sonnet-4-6" }
function makeMockCtx(): ToolContextWithMetadata & { captured: any[] } {
const captured: any[] = []
return {
sessionID: "ses_parent",
messageID: "msg_parent",
agent: "sisyphus",
abort: new AbortController().signal,
callID: "call_001",
metadata: async (input: any) => { captured.push(input) },
captured,
}
}
const parentContext: ParentContext = {
sessionID: "ses_parent",
messageID: "msg_parent",
agent: "sisyphus",
model: MODEL,
}
describe("metadata model unification", () => {
describe("#given delegate-task executors", () => {
describe("#when metadata is set during execution", () => {
test("#then sync-task metadata includes model", async () => {
const { executeSyncTask } = require("./sync-task")
const ctx = makeMockCtx()
const deps = {
createSyncSession: async () => ({ ok: true, sessionID: "ses_sync" }),
sendSyncPrompt: async () => null,
pollSyncSession: async () => null,
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
}
const args: DelegateTaskArgs = {
description: "test", prompt: "do it",
category: "quick", load_skills: [], run_in_background: false,
}
await executeSyncTask(args, ctx, {
client: { session: { create: async () => ({ data: { id: "ses_sync" } }) } },
directory: "/tmp",
onSyncSessionCreated: null,
}, parentContext, "explore", MODEL, undefined, undefined, undefined, deps)
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
expect(meta).toBeDefined()
expect(meta.metadata.model).toEqual(MODEL)
})
test("#then background-task metadata includes model", async () => {
const { executeBackgroundTask } = require("./background-task")
const ctx = makeMockCtx()
const args: DelegateTaskArgs = {
description: "test", prompt: "do it",
load_skills: [], run_in_background: true, subagent_type: "explore",
}
await executeBackgroundTask(args, ctx, {
manager: {
launch: async () => ({
id: "bg_1", description: "test", agent: "explore",
status: "pending", sessionID: "ses_bg", model: MODEL,
}),
getTask: () => undefined,
},
} as any, parentContext, "explore", MODEL, undefined)
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
expect(meta).toBeDefined()
expect(meta.metadata.model).toEqual(MODEL)
})
test("#then unstable-agent-task metadata includes model", async () => {
const { executeUnstableAgentTask } = require("./unstable-agent-task")
const ctx = makeMockCtx()
const args: DelegateTaskArgs = {
description: "test", prompt: "do it",
category: "quick", load_skills: [], run_in_background: false,
}
const launchedTask = {
id: "bg_unstable", description: "test", agent: "explore",
status: "completed", sessionID: "ses_unstable", model: MODEL,
}
const result = await executeUnstableAgentTask(
args, ctx,
{
manager: {
launch: async () => launchedTask,
getTask: () => launchedTask,
},
client: {
session: {
status: async () => ({ data: { ses_unstable: { type: "idle" } } }),
messages: async () => ({
data: [{
info: { role: "assistant", time: { created: 1 } },
parts: [{ type: "text", text: "done" }],
}],
}),
},
},
syncPollTimeoutMs: 100,
} as any,
parentContext, "explore", MODEL, undefined, "anthropic/claude-sonnet-4-6",
)
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
expect(meta).toBeDefined()
expect(meta.metadata.model).toEqual(MODEL)
})
test("#then background-continuation metadata includes model from task", async () => {
const { executeBackgroundContinuation } = require("./background-continuation")
const ctx = makeMockCtx()
const args: DelegateTaskArgs = {
description: "continue", prompt: "keep going",
load_skills: [], run_in_background: true, session_id: "ses_resumed",
}
await executeBackgroundContinuation(args, ctx, {
manager: {
resume: async () => ({
id: "bg_2", description: "continue", agent: "explore",
status: "running", sessionID: "ses_resumed", model: MODEL,
}),
},
} as any, parentContext)
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
expect(meta).toBeDefined()
expect(meta.metadata.model).toEqual(MODEL)
})
test("#then sync-continuation metadata includes model from resumed session", async () => {
const { executeSyncContinuation } = require("./sync-continuation")
const ctx = makeMockCtx()
const args: DelegateTaskArgs = {
description: "continue", prompt: "keep going",
load_skills: [], run_in_background: false, session_id: "ses_cont",
}
const deps = {
pollSyncSession: async () => null,
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
}
await executeSyncContinuation(args, ctx, {
client: {
session: {
messages: async () => ({
data: [{ info: { agent: "explore", model: MODEL, providerID: "anthropic", modelID: "claude-sonnet-4-6" } }],
}),
prompt: async () => ({}),
},
},
} as any, deps)
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
expect(meta).toBeDefined()
expect(meta.metadata.model).toEqual(MODEL)
})
})
})
})

View File

@@ -32,22 +32,7 @@ export async function executeSyncContinuation(
})
}
const syncContMeta = {
title: `Continue: ${args.description}`,
metadata: {
prompt: args.prompt,
load_skills: args.load_skills,
description: args.description,
run_in_background: args.run_in_background,
sessionId: args.session_id,
sync: true,
command: args.command,
},
}
await ctx.metadata?.(syncContMeta)
if (ctx.callID) {
storeToolMetadata(ctx.sessionID, ctx.callID, syncContMeta)
}
let syncContMeta: { title: string; metadata: Record<string, unknown> } | undefined
let resumeAgent: string | undefined
let resumeModel: { providerID: string; modelID: string } | undefined
@@ -78,6 +63,24 @@ export async function executeSyncContinuation(
resumeVariant = resumeMessage?.model?.variant
}
syncContMeta = {
title: `Continue: ${args.description}`,
metadata: {
prompt: args.prompt,
load_skills: args.load_skills,
description: args.description,
run_in_background: args.run_in_background,
sessionId: args.session_id,
sync: true,
command: args.command,
model: resumeModel,
},
}
await ctx.metadata?.(syncContMeta)
if (ctx.callID) {
storeToolMetadata(ctx.sessionID, ctx.callID, syncContMeta)
}
const allowTask = isPlanFamily(resumeAgent)
const tools = {
...(resumeAgent ? getAgentToolRestrictions(resumeAgent) : {}),

View File

@@ -91,6 +91,7 @@ export async function executeSyncTask(
sessionId: sessionID,
sync: true,
command: args.command,
model: categoryModel ? { providerID: categoryModel.providerID, modelID: categoryModel.modelID } : undefined,
},
}
await ctx.metadata?.(syncTaskMeta)

View File

@@ -66,6 +66,7 @@ export async function executeUnstableAgentTask(
run_in_background: args.run_in_background,
sessionId: sessionID,
command: args.command,
model: categoryModel ? { providerID: categoryModel.providerID, modelID: categoryModel.modelID } : undefined,
},
}
await ctx.metadata?.(bgTaskMeta)