Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(pi): preserve child readiness in control card steering
zqchris63799e5116c4
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/subagentRunsBroadcast.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/subagentRunsBroadcast.test.tsindex 954fceb0f4..7d0dc643dd 100644--- a/apps/desktop/src/main/localDb/ipc/__tests__/subagentRunsBroadcast.test.ts+++ b/apps/desktop/src/main/localDb/ipc/__tests__/subagentRunsBroadcast.test.ts@@ -73,7 +73,7 @@ vi.mock('../../subagentRuns.js', () => ({persistSubagentTaskUpdate: h.persistSubagentTaskUpdate,}));-import { SUBAGENT_RUNS_CHANGED_CHANNEL } from '@cindy/maker-shared/subagent-workspace';+import { SUBAGENT_RUNS_CHANGED_CHANNEL, type SubagentRunDetailResponse } from '@cindy/maker-shared/subagent-workspace';import {__resetSubagentReconcileFingerprintsForTests,broadcastSubagentRunsChanged,@@ -207,6 +207,35 @@ describe('Subagent runs broadcast boundary', () => {]);});+ it.each([false, true])('preserves explicit readiness and legacy absence in detail (remote=%s)', async (remote) => {+ h.deviceLinkInvoke = remote;+ registerSubagentRunsIpc();+ h.getSubagentRunDetail.mockResolvedValue({+ id: 'run-1', logicalAgentId: 'parent-tool', provider: 'pi', status: 'running',+ providerRunIds: [], capabilities: { steer: true },+ });+ h.listPiSubagentRuns.mockResolvedValue([{+ version: 1, runId: '123e4567-e89b-42d3-a456-426614174082', taskId: 'parent-tool',+ parentSessionId: 'session-1', runnerInstanceId: 'runner-1', state: 'running',+ startedAt: 1_000, updatedAt: 2_000,+ tasks: [false, true, undefined].map((resultReady, index) => ({+ childId: `child-${index}`, sessionId: `pi-session-${index}`, agent: 'worker', status: 'running',+ output: 'Some output', ...(resultReady === undefined ? {} : { resultReady }),+ })),+ }]);+ const handler = h.ipcHandlers.get('local-db:subagent-runs:detail')!;+ const response = await handler({}, {+ sessionId: 'session-1', provider: 'pi', runIdOrAlias: 'parent-tool',+ }) as SubagentRunDetailResponse;+ // Exercise the wire representation too: false must survive serialization,+ // and a legacy record must not gain a fabricated readiness value.+ const children = JSON.parse(JSON.stringify(response)).run.children;+ expect(children).toHaveLength(3);+ expect(children[0]).toMatchObject({ output: 'Some output', resultReady: false });+ expect(children[1]).toMatchObject({ output: 'Some output', resultReady: true });+ expect(children[2]).not.toHaveProperty('resultReady');+ });+it('leaves a child that has only ever had one id without aliases', async () => {registerSubagentRunsIpc();const detail = h.ipcHandlers.get('local-db:subagent-runs:detail')!;diff --git a/apps/desktop/src/main/localDb/ipc/subagentRuns.ts b/apps/desktop/src/main/localDb/ipc/subagentRuns.tsindex 322d0d5436..0c52a8b7cc 100644--- a/apps/desktop/src/main/localDb/ipc/subagentRuns.ts+++ b/apps/desktop/src/main/localDb/ipc/subagentRuns.ts@@ -518,6 +518,7 @@ export function registerSubagentRunsIpc(...(task.pendingApproval ? { awaitingApproval: true } : {}),output: task.output,outputTruncated: task.outputTruncated,+ ...(typeof task.resultReady === 'boolean' ? { resultReady: task.resultReady } : {}),error: task.error,})),};diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/subagents/DetailView.tsx b/apps/desktop/src/renderer/features/right-sidebar/plugins/subagents/DetailView.tsxindex 533fd32ce2..ed146bafd1 100644--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/subagents/DetailView.tsx+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/subagents/DetailView.tsx@@ -339,7 +339,10 @@ function PiDurableDetailView({const selectedChildActive = !selectedChild|| selectedChild.status === 'running'|| selectedChild.status === 'queued';- const selectedChildHasCompletedOutput = Boolean(selectedChild?.output?.trim());+ // Commentary can populate output while tools are still running. Only older+ // hosts/runners without explicit readiness need the output-based fallback.+ const selectedChildResultReady = selectedChild?.resultReady+ ?? Boolean(selectedChild?.output?.trim());// The composer works like the session's: one box, one send, and the same// keystrokes. While running, plain send queues a follow-up and the modifier// send interjects (steer) — exactly the main composer's Enter / ⌘+Enter@@ -352,7 +355,7 @@ function PiDurableDetailView({return detail.capabilities.resume ? 'resume' : undefined;}if (!detail.capabilities.steer || !selectedChildActive) return undefined;- if (intent === 'steer' && !selectedChildHasCompletedOutput) return 'steer';+ if (intent === 'steer' && !selectedChildResultReady) return 'steer';return 'follow_up';};const defaultComposerAction = composerActionForIntent('queue');diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/subagents/__tests__/SubagentsBody.test.tsx b/apps/desktop/src/renderer/features/right-sidebar/plugins/subagents/__tests__/SubagentsBody.test.tsxindex b1d50d69cb..a46de8768d 100644--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/subagents/__tests__/SubagentsBody.test.tsx+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/subagents/__tests__/SubagentsBody.test.tsx@@ -121,6 +121,7 @@ describe('SubagentsBody', () => {if (channel === 'local-db:subagent-runs:detail') {return { supported: true, run: currentDetail };}+ if (channel === 'maker:pi-subagent:control') return { ok: true, controlled: 1 };return { supported: false, run: null, entries: [] };};const deviceInvoke = vi.fn(defaultDeviceInvoke);@@ -1875,6 +1876,57 @@ describe('SubagentsBody', () => {expect(screen.getByLabelText('rightSidebar.subagents.controlActions.follow_up')).toBeTruthy();});+ describe.each([null, 'device-1'])('child composer readiness (device=%s)', (deviceLinkDeviceId) => {+ it.each([+ { resultReady: false, output: 'Checking with a tool', expectedAction: 'steer' },+ { resultReady: true, output: 'Final answer', expectedAction: 'follow_up' },+ { resultReady: true, output: '', expectedAction: 'follow_up' },+ { resultReady: undefined, output: 'Legacy answer', expectedAction: 'follow_up' },+ { resultReady: undefined, output: '', expectedAction: 'steer' },+ ])('routes modifier send to $expectedAction with readiness=$resultReady and output="$output"', async ({ resultReady, output, expectedAction }) => {+ currentDetail = {+ ...detail('running'),+ capabilities: { ...detail('running').capabilities, viewFullTranscript: true, steer: true },+ children: [{+ id: 'child-1', role: 'worker', status: 'running', output,+ ...(resultReady === undefined ? {} : { resultReady }),+ }],+ };+ render(+ <SubagentsBody+ state={{ selectedRunId: 'run-1', selectedProvider: 'pi' }}+ ctx={{+ tabId: 'tab-1', sessionId: 'session-1', workdir: '/workspace',+ remoteHostId: null, deviceLinkDeviceId, patchState: vi.fn(),+ onVisibilityChange: vi.fn(), setCloseInterceptor: vi.fn(() => () => undefined),+ }}+ />,+ );+ const input = await screen.findByPlaceholderText(expectedAction === 'steer'+ ? 'rightSidebar.subagents.composerPlaceholders.runningWithSteer'+ : 'rightSidebar.subagents.composerPlaceholders.follow_up');+ const expectControl = async (action: string, message: string) => {+ const request = { sessionId: 'session-1', taskId: 'task-1', childId: 'child-1', action, message };+ await waitFor(() => {+ if (deviceLinkDeviceId) {+ expect(deviceInvoke).toHaveBeenCalledWith(deviceLinkDeviceId, 'maker:pi-subagent:control', [request]);+ expect(controlPiSubagent).not.toHaveBeenCalled();+ } else {+ expect(controlPiSubagent).toHaveBeenCalledWith(request);+ }+ });+ await waitFor(() => expect((input as HTMLTextAreaElement).value).toBe(''));+ };+ fireEvent.change(input, { target: { value: 'Use the corrected target' } });+ fireEvent.keyDown(input, { key: 'Enter', ctrlKey: true });+ await expectControl(expectedAction, 'Use the corrected target');+ // Explicit readiness changes interjection eligibility, never plain send.+ fireEvent.change(input, { target: { value: 'Then verify the result' } });+ fireEvent.keyDown(input, { key: 'Enter' });+ await expectControl('follow_up', 'Then verify the result');+ });+ });+it('dispatches a follow-up automatically once the child has settled output', async () => {currentDetail = {...detail('running'),diff --git a/docs/research/pi-subagent-delegation.md b/docs/research/pi-subagent-delegation.mdindex 1a8a231e49..a7f64f4024 100644--- a/docs/research/pi-subagent-delegation.md+++ b/docs/research/pi-subagent-delegation.md@@ -11,6 +11,8 @@沿用 Cindy 的持久 runner、原生 RPC、独立 session、审批转发和现有子代理卡。模型控制与界面控制共用同一份持久状态和 resume 实现。+子代理详情的可选 `resultReady` 透传到本机与设备互联控制卡:显式 `false` 时中间输出不阻止+插话,`true` 时改为排队;旧宿主或 runner 缺少该字段时,界面保留按输出判断的回退。## 对标与取舍diff --git a/packages/maker-shared/src/subagentWorkspace.ts b/packages/maker-shared/src/subagentWorkspace.tsindex 3fd144f701..1ae56c8a81 100644--- a/packages/maker-shared/src/subagentWorkspace.ts+++ b/packages/maker-shared/src/subagentWorkspace.ts@@ -80,6 +80,8 @@ export interface SubagentChildRun {awaitingApproval?: boolean;output?: string;outputTruncated?: boolean;+ /** Final reply readiness, independent of commentary; absent on legacy hosts/runners. */+ resultReady?: boolean;error?: string;}