fix(desktop): preserve scoped steering drafts and worker timer origins
This commit is contained in:
@@ -323,7 +323,7 @@ function StreamLine({
|
||||
export function SubagentRow({ node, depth = 0, nowMs }: { node: SubagentNode; depth?: number; nowMs: number }) {
|
||||
const { t } = useI18n()
|
||||
const running = node.status === 'running' || node.status === 'queued'
|
||||
const elapsed = useElapsedSeconds(running, `subagent:${node.id}`)
|
||||
const elapsed = useElapsedSeconds(running, `subagent:${node.id}`, node.startedAt)
|
||||
|
||||
const durationSeconds =
|
||||
typeof node.durationSeconds === 'number' ? Math.max(0, Math.round(node.durationSeconds)) : elapsed
|
||||
|
||||
@@ -8,11 +8,12 @@ import { requestForOwnedSession } from '@/store/session-states'
|
||||
interface SubagentControlsProps {
|
||||
sessionId: string
|
||||
subagentId: string
|
||||
text: string
|
||||
setText: (text: string) => void
|
||||
}
|
||||
|
||||
export function SubagentControls({ sessionId, subagentId }: SubagentControlsProps) {
|
||||
export function SubagentControls({ sessionId, subagentId, text, setText }: SubagentControlsProps) {
|
||||
const { t } = useI18n()
|
||||
const [text, setText] = useState('')
|
||||
const [pending, setPending] = useState(false)
|
||||
const [feedback, setFeedback] = useState('')
|
||||
const [failed, setFailed] = useState(false)
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
|
||||
import { afterEach, expect, it, vi } from 'vitest'
|
||||
|
||||
import { $subagentsBySession, upsertSubagent } from '@/store/subagents'
|
||||
|
||||
import { SubagentSection } from './subagent-section'
|
||||
|
||||
vi.stubGlobal(
|
||||
'ResizeObserver',
|
||||
class {
|
||||
disconnect() {}
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
}
|
||||
)
|
||||
Element.prototype.animate = vi.fn(() => ({ cancel() {} }) as Animation)
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
$subagentsBySession.set({})
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('keeps each worker draft while inspecting siblings and removes settled selection', () => {
|
||||
upsertSubagent('parent', { subagent_id: 'a', goal: 'Worker A' })
|
||||
upsertSubagent('parent', { subagent_id: 'b', goal: 'Worker B' })
|
||||
render(<SubagentSection sessionId="parent" />)
|
||||
fireEvent.click(screen.getByRole('button', { name: /Worker A/ }))
|
||||
fireEvent.change(screen.getByRole('textbox'), { target: { value: 'Preserve my instruction' } })
|
||||
fireEvent.click(screen.getByRole('button', { name: /Worker B/ }))
|
||||
expect((screen.getByRole('textbox') as HTMLInputElement).value).toBe('')
|
||||
fireEvent.click(screen.getByRole('button', { name: /Worker A/ }))
|
||||
expect((screen.getByRole('textbox') as HTMLInputElement).value).toBe('Preserve my instruction')
|
||||
act(() => upsertSubagent('parent', { subagent_id: 'a', status: 'completed' }, false, 'subagent.complete'))
|
||||
expect(screen.queryByText('Worker A')).toBeNull()
|
||||
expect(screen.queryByRole('textbox')).toBeNull()
|
||||
})
|
||||
|
||||
it('measures detail elapsed from worker start rather than first inspection', () => {
|
||||
const now = vi.spyOn(Date, 'now').mockReturnValue(100000)
|
||||
upsertSubagent('parent', { subagent_id: 'timed', goal: 'Timed worker' })
|
||||
now.mockReturnValue(117000)
|
||||
const { container } = render(<SubagentSection sessionId="parent" />)
|
||||
fireEvent.click(screen.getByRole('button', { name: /Timed worker/ }))
|
||||
expect(
|
||||
container.querySelector(
|
||||
'[data-slot="composer-subagent-detail"] [data-slot="tool-block"] > button > span:last-child'
|
||||
)?.textContent
|
||||
).toBe('17s')
|
||||
})
|
||||
@@ -1,10 +1,11 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useState } from 'react'
|
||||
|
||||
import { SubagentRow } from '@/app/agents'
|
||||
import { ActivityTimerText } from '@/components/chat/activity-timer-text'
|
||||
import { StatusSection } from '@/components/chat/status-section'
|
||||
import { Codicon } from '@/components/ui/codicon'
|
||||
import { GlyphSpinner } from '@/components/ui/glyph-spinner'
|
||||
import { useViewedInterval } from '@/hooks/use-viewed-interval'
|
||||
import { useI18n } from '@/i18n'
|
||||
import { useSessionSlice } from '@/lib/use-session-slice'
|
||||
import { $subagentsBySession, type SubagentProgress } from '@/store/subagents'
|
||||
@@ -22,17 +23,10 @@ export function SubagentSection({ sessionId }: SubagentSectionProps) {
|
||||
const live = items.filter(item => item.status === 'running' || item.status === 'queued')
|
||||
const [nowMs, setNowMs] = useState(Date.now)
|
||||
const [selected, setSelected] = useState<string | null>(null)
|
||||
const [drafts, setDrafts] = useState<Record<string, string>>({})
|
||||
const hasLive = live.length > 0
|
||||
|
||||
useEffect(() => {
|
||||
if (!hasLive) {
|
||||
return
|
||||
}
|
||||
|
||||
const timer = setInterval(() => setNowMs(Date.now()), 1000)
|
||||
|
||||
return () => clearInterval(timer)
|
||||
}, [hasLive])
|
||||
useViewedInterval(() => setNowMs(Date.now()), 1000, hasLive)
|
||||
|
||||
if (!hasLive) {
|
||||
return null
|
||||
@@ -46,7 +40,11 @@ export function SubagentSection({ sessionId }: SubagentSectionProps) {
|
||||
onClick={() => setSelected(selected === item.id ? null : item.id)}
|
||||
type="button"
|
||||
>
|
||||
<GlyphSpinner ariaLabel={t.agents.running} className="mt-0.5 shrink-0 text-(--ui-purple)" spinner="braille" />
|
||||
<GlyphSpinner
|
||||
ariaLabel={item.status === 'queued' ? t.agents.queued : t.agents.running}
|
||||
className="mt-0.5 shrink-0 text-(--ui-purple)"
|
||||
spinner="braille"
|
||||
/>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-xs text-(--ui-text-primary)">{item.goal}</span>
|
||||
<span className="block truncate text-[0.68rem] text-(--ui-text-tertiary)">
|
||||
@@ -60,7 +58,7 @@ export function SubagentSection({ sessionId }: SubagentSectionProps) {
|
||||
</button>
|
||||
)
|
||||
|
||||
const detail = items.find(item => item.id === selected)
|
||||
const detail = live.find(item => item.id === selected)
|
||||
|
||||
return (
|
||||
<div className="composer-no-drag min-w-0" data-slot="composer-subagents">
|
||||
@@ -81,7 +79,13 @@ export function SubagentSection({ sessionId }: SubagentSectionProps) {
|
||||
{detail && (
|
||||
<div className="max-h-[25vh] overflow-y-auto overscroll-contain px-3 py-2" data-slot="composer-subagent-detail">
|
||||
{(detail.status === 'running' || detail.status === 'queued') && (
|
||||
<SubagentControls key={`${sessionId}:${detail.id}`} sessionId={sessionId} subagentId={detail.id} />
|
||||
<SubagentControls
|
||||
key={`${sessionId}:${detail.id}`}
|
||||
sessionId={sessionId}
|
||||
setText={text => setDrafts(previous => ({ ...previous, [detail.id]: text }))}
|
||||
subagentId={detail.id}
|
||||
text={drafts[detail.id] ?? ''}
|
||||
/>
|
||||
)}
|
||||
<SubagentRow node={{ ...detail, children: [] }} nowMs={nowMs} />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user