mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 23:24:00 +03:00
feat(app): show subagent delegation state (#44078)
This commit is contained in:
committed by
GitHub
Unverified
parent
3c70f6df28
commit
4566395d42
@@ -1,6 +1,6 @@
|
||||
import { expect, test } from "@playwright/test"
|
||||
import type { SessionMessageAssistant, SessionMessageInfo } from "@opencode-ai/client/promise"
|
||||
import { event, session, sessionID, setupTimeline } from "../performance/timeline-stability/fixture"
|
||||
import { event, session, sessionID, setupTimeline, toolPart } from "../performance/timeline-stability/fixture"
|
||||
|
||||
const user = { id: "msg_user", type: "user", text: "Run it", time: { created: 1 } } satisfies SessionMessageInfo
|
||||
|
||||
@@ -73,6 +73,30 @@ test("renders current protocol notices in CLI order", async ({ page }) => {
|
||||
expect(ownerWarnings).toEqual([])
|
||||
})
|
||||
|
||||
test("shows a delegating row while subagent input streams", async ({ page }) => {
|
||||
await setupTimeline(page, {
|
||||
sessionMessages: [
|
||||
user,
|
||||
{
|
||||
...assistant(false),
|
||||
content: [toolPart("call_subagent", "subagent", "streaming", {})],
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const delegating = page.locator('[data-component="task-tool-delegating"]')
|
||||
await expect(delegating).toBeVisible()
|
||||
await expect(delegating.locator('[data-component="text-shimmer"]')).toHaveAttribute(
|
||||
"aria-label",
|
||||
"Delegating agent...",
|
||||
)
|
||||
const icon = delegating.locator('[data-slot="icon-svg"]')
|
||||
await expect(icon.locator('use[href="#opencode-v2-icon-subagent"]')).toBeVisible()
|
||||
await expect(icon).toHaveCSS("color", "rgb(174, 174, 174)")
|
||||
await expect(page.locator('[data-component="task-tool-card"]')).toHaveCount(0)
|
||||
await expect(page.locator('[data-timeline-row="Thinking"]')).toHaveCount(0)
|
||||
})
|
||||
|
||||
test("moves blocking work to the background with Ctrl+B", async ({ page }) => {
|
||||
await setupTimeline(page, { sessionMessages: [user, assistant(false, true)] })
|
||||
const card = page.locator('[data-component="task-tool-card"]')
|
||||
@@ -83,20 +107,19 @@ test("moves blocking work to the background with Ctrl+B", async ({ page }) => {
|
||||
await expect(page.locator('[data-component="background-tool-control"]')).toHaveCount(0)
|
||||
const hint = page.locator('[data-component="session-background-hint"]')
|
||||
const hintPrefix = hint.locator('[data-slot="session-background-hint-prefix"]')
|
||||
const thinking = page.locator('[data-slot="session-turn-thinking"]')
|
||||
await expect(hint).toBeVisible()
|
||||
await expect(page.locator('[data-timeline-row="Thinking"]')).toHaveCount(0)
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const [cardBox, hintBox, prefixBox, thinkingBox] = await Promise.all([
|
||||
const [cardBox, hintBox, prefixBox] = await Promise.all([
|
||||
card.boundingBox(),
|
||||
hint.boundingBox(),
|
||||
hintPrefix.boundingBox(),
|
||||
thinking.boundingBox(),
|
||||
])
|
||||
if (!cardBox || !hintBox || !prefixBox || !thinkingBox) return undefined
|
||||
if (!cardBox || !hintBox || !prefixBox) return undefined
|
||||
return {
|
||||
aligned: Math.abs(cardBox.x - prefixBox.x) < 2,
|
||||
ordered: cardBox.y < hintBox.y && hintBox.y < thinkingBox.y,
|
||||
ordered: cardBox.y < hintBox.y,
|
||||
}
|
||||
})
|
||||
.toEqual({ aligned: true, ordered: true })
|
||||
|
||||
@@ -222,6 +222,12 @@ export namespace Timeline {
|
||||
.filter((entry) => renderable(entry.content, showReasoning))
|
||||
.map((entry) => ({ messageID: message.id, messageIndex, partID: entry.id, content: entry.content })),
|
||||
)
|
||||
const delegating = assistantPartRefs.some(
|
||||
(entry) =>
|
||||
entry.content.type === "tool" &&
|
||||
entry.content.name === "subagent" &&
|
||||
(entry.content.state.status === "streaming" || entry.content.state.status === "running"),
|
||||
)
|
||||
|
||||
if (previousUserMessage) rows.push(new TimelineRow.TurnGap({ userMessageID: turnID }))
|
||||
if (userMessage) rows.push(new TimelineRow.UserMessage({ userMessageID: turnID }))
|
||||
@@ -273,6 +279,7 @@ export namespace Timeline {
|
||||
status.type === "busy" &&
|
||||
!error &&
|
||||
!retry &&
|
||||
!delegating &&
|
||||
(showReasoning ? assistantPartRefs.length === 0 : true)
|
||||
) {
|
||||
const heading = assistantMessages
|
||||
|
||||
@@ -166,6 +166,38 @@ describe("current session timeline rows", () => {
|
||||
])
|
||||
})
|
||||
|
||||
test("suppresses thinking while a subagent is delegating or running", () => {
|
||||
const statuses = ["streaming", "running"] as const
|
||||
statuses.forEach((status) => {
|
||||
const source = [
|
||||
{ id: "msg_user", type: "user", text: "delegate", time: { created: 1 } },
|
||||
{
|
||||
id: "msg_assistant",
|
||||
type: "assistant",
|
||||
agent: "build",
|
||||
model: { id: "model", providerID: "provider" },
|
||||
content: [
|
||||
{
|
||||
type: "tool",
|
||||
id: "tool_subagent",
|
||||
name: "subagent",
|
||||
state:
|
||||
status === "streaming"
|
||||
? { status, input: "" }
|
||||
: { status, input: { description: "Inspect code" }, metadata: {} },
|
||||
time: { created: 2 },
|
||||
},
|
||||
],
|
||||
time: { created: 2 },
|
||||
},
|
||||
] satisfies SessionMessageInfo[]
|
||||
|
||||
expect(Timeline.constructSessionMessageRows(source, false, { type: "busy" }).rows.map((row) => row._tag)).toEqual(
|
||||
["UserMessage", "AssistantPart"],
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
test("renders retry state from the current assistant message", () => {
|
||||
const source = [
|
||||
{ id: "msg_user", type: "user", text: "retry", time: { created: 1 } },
|
||||
|
||||
@@ -1023,6 +1023,7 @@ ToolRegistry.register({
|
||||
render(props) {
|
||||
const data = useData()
|
||||
const i18n = useI18n()
|
||||
const delegating = () => props.status === "streaming"
|
||||
const childSessionId = createMemo(() => {
|
||||
const value = props.metadata.sessionID
|
||||
if (typeof value === "string" && value) return value
|
||||
@@ -1114,17 +1115,33 @@ ToolRegistry.register({
|
||||
)
|
||||
|
||||
return (
|
||||
<BasicTool
|
||||
icon="task"
|
||||
status={props.status}
|
||||
trigger={trigger()}
|
||||
hideDetails
|
||||
triggerAsLink
|
||||
triggerHref={href()}
|
||||
clickable={clickable()}
|
||||
onTriggerClick={navigate}
|
||||
onTriggerKeyDown={navigateKey}
|
||||
/>
|
||||
<Show
|
||||
when={delegating()}
|
||||
fallback={
|
||||
<BasicTool
|
||||
icon="task"
|
||||
status={props.status}
|
||||
trigger={trigger()}
|
||||
hideDetails
|
||||
triggerAsLink
|
||||
triggerHref={href()}
|
||||
clickable={clickable()}
|
||||
onTriggerClick={navigate}
|
||||
onTriggerKeyDown={navigateKey}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<div
|
||||
data-component="task-tool-delegating"
|
||||
class="flex h-9 w-fit max-w-full items-center gap-2 rounded-[8px] bg-v2-background-bg-layer-01 p-2.5"
|
||||
>
|
||||
<Icon name="subagent" size="small" class="shrink-0 text-v2-icon-icon-faint" />
|
||||
<TextShimmer
|
||||
text={i18n.t("ui.tool.agent.delegating")}
|
||||
class="min-w-0 truncate text-[13px] font-[530] leading-none tracking-[-0.04px]"
|
||||
/>
|
||||
</div>
|
||||
</Show>
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
@@ -168,6 +168,7 @@ const source = {
|
||||
"ui.tool.questions.numbered": "Questions {{number}}",
|
||||
"ui.tool.agent": "{{type}} Agent",
|
||||
"ui.tool.agent.default": "Agent",
|
||||
"ui.tool.agent.delegating": "Delegating agent...",
|
||||
"ui.tool.skill": "Skill",
|
||||
|
||||
"ui.basicTool.called": "Called `{{tool}}`",
|
||||
|
||||
@@ -252,6 +252,7 @@
|
||||
--color-v2-text-text-code-accent: var(--v2-text-text-code-accent);
|
||||
--color-v2-icon-icon-base: var(--v2-icon-icon-base);
|
||||
--color-v2-icon-icon-muted: var(--v2-icon-icon-muted);
|
||||
--color-v2-icon-icon-faint: var(--v2-icon-icon-faint);
|
||||
--color-v2-icon-icon-inverse: var(--v2-icon-icon-inverse);
|
||||
--color-v2-icon-icon-contrast: var(--v2-icon-icon-contrast);
|
||||
--color-v2-icon-icon-accent: var(--v2-icon-icon-accent);
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
/* ── Icon ── */
|
||||
--v2-icon-icon-base: var(--v2-grey-800);
|
||||
--v2-icon-icon-muted: var(--v2-grey-600);
|
||||
--v2-icon-icon-faint: var(--v2-grey-500);
|
||||
--v2-icon-icon-inverse: var(--v2-grey-50);
|
||||
--v2-icon-icon-contrast: var(--v2-grey-100);
|
||||
--v2-icon-icon-accent: var(--v2-blue-600);
|
||||
@@ -158,6 +159,7 @@
|
||||
|
||||
--v2-icon-icon-base: var(--v2-grey-400);
|
||||
--v2-icon-icon-muted: var(--v2-grey-600);
|
||||
--v2-icon-icon-faint: var(--v2-grey-500);
|
||||
--v2-icon-icon-inverse: var(--v2-grey-1000);
|
||||
--v2-icon-icon-contrast: var(--v2-grey-200);
|
||||
--v2-icon-icon-accent: var(--v2-blue-400);
|
||||
@@ -271,6 +273,7 @@
|
||||
|
||||
--v2-icon-icon-base: var(--v2-grey-800);
|
||||
--v2-icon-icon-muted: var(--v2-grey-600);
|
||||
--v2-icon-icon-faint: var(--v2-grey-500);
|
||||
--v2-icon-icon-inverse: var(--v2-grey-50);
|
||||
--v2-icon-icon-contrast: var(--v2-grey-100);
|
||||
--v2-icon-icon-accent: var(--v2-blue-600);
|
||||
@@ -393,6 +396,7 @@
|
||||
|
||||
--v2-icon-icon-base: var(--v2-grey-400);
|
||||
--v2-icon-icon-muted: var(--v2-grey-600);
|
||||
--v2-icon-icon-faint: var(--v2-grey-500);
|
||||
--v2-icon-icon-inverse: var(--v2-grey-1100);
|
||||
--v2-icon-icon-contrast: var(--v2-grey-100);
|
||||
--v2-icon-icon-accent: var(--v2-blue-400);
|
||||
|
||||
@@ -176,6 +176,7 @@
|
||||
"v2-text-text-code-accent": "var(--v2-blue-900)",
|
||||
"v2-icon-icon-base": "var(--v2-grey-800)",
|
||||
"v2-icon-icon-muted": "var(--v2-grey-600)",
|
||||
"v2-icon-icon-faint": "var(--v2-grey-500)",
|
||||
"v2-icon-icon-inverse": "var(--v2-grey-50)",
|
||||
"v2-icon-icon-contrast": "var(--v2-grey-100)",
|
||||
"v2-icon-icon-accent": "var(--v2-blue-600)",
|
||||
@@ -411,6 +412,7 @@
|
||||
"v2-text-text-code-accent": "var(--v2-blue-400)",
|
||||
"v2-icon-icon-base": "var(--v2-grey-400)",
|
||||
"v2-icon-icon-muted": "var(--v2-grey-600)",
|
||||
"v2-icon-icon-faint": "var(--v2-grey-500)",
|
||||
"v2-icon-icon-inverse": "var(--v2-grey-1100)",
|
||||
"v2-icon-icon-contrast": "var(--v2-grey-100)",
|
||||
"v2-icon-icon-accent": "var(--v2-blue-400)",
|
||||
|
||||
@@ -52,6 +52,7 @@ export function mapV2Foreground(
|
||||
"v2-text-text-faint": shift(body, { l: isDark ? -0.2 : 0.21, c: isDark ? 0.78 : 0.72 }),
|
||||
"v2-icon-icon-base": greyRef(pickGrey(primitives, bgBase, 7, isDark ? 400 : 800)),
|
||||
"v2-icon-icon-muted": greyRef(pickGrey(primitives, bgBase, 3, 600)),
|
||||
"v2-icon-icon-faint": greyRef(pickGrey(primitives, bgBase, 1.5, 500)),
|
||||
"v2-icon-icon-inverse": greyRef(pickGrey(primitives, bgInverse, 7, inverseTarget)),
|
||||
"v2-icon-icon-contrast": greyRef(pickGrey(primitives, bgContrast, 7, 100)),
|
||||
"v2-icon-icon-accent": isDark ? "var(--v2-blue-400)" : "var(--v2-blue-600)",
|
||||
|
||||
Reference in New Issue
Block a user