fix: complete subagent output and file workspace interactions

OpenCode child cards now show ordered text, reasoning and tool progress,
with the final result displayed separately. Local SDK and remote ACP paths
share child tracking, including progress retained across recovery and cancellation.
Remote live progress requires an Agent package containing the event plugin;
older Agent packages still expose final results without inventing missing history.

Knowledge-library rows remain clickable when native label activation changes
focus. File workspace changes use colored Git status letters and per-file
staged/unstaged diffs, including deleted, renamed and untracked files.
Refreshing reloads the selected diff and expanded directories, and more than
50 changes remain accessible through incremental loading.

Validated with 3552 passing tests, typecheck, lint, desktop build, current-source
Linux Host scenarios and isolated Windows desktop UI interactions.

Release note: 展开 OpenCode 子代理卡片可查看执行过程、工具详情与独立最终结果;知识库支持整行勾选。工作区支持单文件暂存与未暂存差异,刷新会更新当前差异,更多变更可继续加载。远端实时过程需要更新 GoodBuddy Agent。
This commit is contained in:
mesalogo
2026-09-06 22:13:45 +08:00
parent b03c25685c
commit d08ba33c3e
43 changed files with 1118 additions and 141 deletions
+145 -2
View File
@@ -1,5 +1,6 @@
import { createHash } from 'node:crypto'
import type { SubagentEvent } from '../../shared/contracts'
import type { ConversationMessageBlock } from '../../shared/assistant-contracts'
import { boundedToolDetail } from './approval-summary'
type OpenCodeSubagentState =
@@ -113,11 +114,19 @@ export function toOpenCodeSubagentEvent(
? 'completed'
: 'failed'
const failed = state === 'failed'
const detail = isRecord(update.output)
? update.output.output ?? update.output.error
: update.output
const result = typeof detail === 'string'
? detail.match(
/^\s*<task\b[^>]*>\s*<task_result>\s*([\s\S]*?)\s*<\/task_result>\s*<\/task>\s*$/u
)?.[1] ?? detail
: detail
const output = failed
? undefined
: boundedDetail(update.output, 16_000)
: boundedDetail(result, 16_000)
const error = failed
? boundedDetail(update.error ?? update.output, 1_000)
? boundedDetail(update.error ?? detail, 1_000)
: undefined
return {
@@ -138,3 +147,137 @@ export function toOpenCodeSubagentEvent(
...(error ? { error } : {})
}
}
/**
* Tracks only sessions explicitly linked by a Task's metadata.sessionId.
* The same snapshots travel through the local SDK and the remote ACP bridge.
*/
export class OpenCodeSubagentProgress {
private readonly roles = new Map<string, string>()
private readonly reasoning = new Set<string>()
private readonly tasks = new Map<string, {
event: SubagentEvent
sessionId?: string
blocks: ConversationMessageBlock[]
}>()
constructor(
private readonly requestId: string,
private readonly parentSessionId?: string
) {}
update(value: unknown, ownerCallId?: string): SubagentEvent | undefined {
if (!isRecord(value) || !isRecord(value.properties)) return undefined
const properties = value.properties
const part = properties.part
if (
value.type === 'message.part.updated' &&
isRecord(part) && part.type === 'tool' &&
part.tool === 'task' && isRecord(part.state) &&
(!this.parentSessionId || properties.sessionID === this.parentSessionId) &&
![...this.tasks.values()].some(
(task) => task.sessionId === properties.sessionID
)
) {
const callId = boundedText(part.callID ?? part.id, 256)
if (!callId) return undefined
const event = toOpenCodeSubagentEvent({
requestId: this.requestId,
callId,
input: part.state.input,
state: part.state.status as OpenCodeSubagentState,
output: part.state.output,
error: part.state.error
})
if (!event) return undefined
const previous = this.tasks.get(callId)
const metadata = part.state.metadata
const task = {
event,
sessionId: (isRecord(metadata)
? boundedText(metadata.sessionId, 256)
: undefined) ?? previous?.sessionId,
blocks: previous?.blocks ?? []
}
this.tasks.set(callId, task)
return { ...event, progress: [...task.blocks] }
}
const task = [...this.tasks.values()].find(
(candidate) => candidate.sessionId === properties.sessionID
) ?? (ownerCallId ? this.tasks.get(ownerCallId) : undefined)
if (!task) return undefined
if (value.type === 'message.updated' && isRecord(properties.info)) {
this.roles.set(String(properties.info.id), String(properties.info.role))
return undefined
}
const messageId = isRecord(part) ? part.messageID : properties.messageID
if (this.roles.get(String(messageId)) === 'user') return undefined
const partId = isRecord(part) ? part.id : properties.partID
if (typeof partId !== 'string') return undefined
const id = deterministicUuid(`${task.event.childTaskId}\0${partId}`)
const index = task.blocks.findIndex((block) => block.id === id)
const previous = task.blocks[index]
let block: ConversationMessageBlock | undefined
if (value.type === 'message.part.updated' && isRecord(part)) {
if (part.type === 'reasoning') this.reasoning.add(id)
if (
(part.type === 'text' || part.type === 'reasoning') &&
typeof part.text === 'string' && part.text &&
part.ignored !== true && part.synthetic !== true
) {
block = { id, type: part.type, content: part.text.slice(0, 16_000) }
} else if (part.type === 'tool' && isRecord(part.state)) {
block = {
id,
type: 'tool',
tool: {
callId: String(part.callID ?? partId).slice(0, 256),
name: String(part.tool).slice(0, 200),
summary: boundedText(part.state.title, 240) ?? String(part.tool),
state: part.state.status === 'error'
? 'failed'
: part.state.status as 'pending' | 'running' | 'completed',
input: boundedDetail(part.state.input, 4_000),
output: boundedDetail(part.state.output, 16_000),
error: boundedDetail(part.state.error, 1_000)
}
}
}
} else if (
value.type === 'message.part.delta' &&
typeof properties.delta === 'string' && properties.delta &&
(properties.field === 'text' || properties.field === 'reasoning')
) {
block = {
id,
type: this.reasoning.has(id) || previous?.type === 'reasoning' || properties.field === 'reasoning'
? 'reasoning'
: 'text',
content: (
(previous?.type === 'text' || previous?.type === 'reasoning'
? previous.content : '') + properties.delta
).slice(0, 16_000)
}
}
if (!block) return undefined
if (index >= 0) task.blocks[index] = block
else task.blocks.push(block)
return { ...task.event, progress: [...task.blocks] }
}
retain(event: SubagentEvent): SubagentEvent {
const task = event.runtimeCallId
? this.tasks.get(event.runtimeCallId)
: undefined
if (!task) {
if (event.runtimeCallId && event.progress) {
this.tasks.set(event.runtimeCallId, {
event, blocks: [...event.progress]
})
}
return event
}
task.event = event
return { ...event, progress: [...task.blocks] }
}
}