Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/channels/base/src/AcpBridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,41 @@ describe('AcpBridge', () => {
);
});

it('excludes nested subagent text from the final response', async () => {
const bridge = new AcpBridge({
cliEntryPath: '/tmp/qwen',
cwd: '/tmp',
}) as unknown as TestableAcpBridge;
bridge.child = { killed: false, exitCode: null };
bridge.connection = {
extMethod: vi.fn(),
prompt: vi.fn(async () => {
bridge.handleSessionUpdate({
sessionId: 's-1',
update: {
sessionUpdate: 'agent_message_chunk',
content: { type: 'text', text: 'Nested research report.' },
_meta: {
parentToolCallId: 'agent-call-1',
subagentType: 'Explore',
},
},
});
bridge.handleSessionUpdate({
sessionId: 's-1',
update: {
sessionUpdate: 'agent_message_chunk',
content: { type: 'text', text: 'Final answer.' },
},
});
}),
};

await expect(bridge.prompt('s-1', 'question')).resolves.toBe(
'Final answer.',
);
});

it('returns only the final turn text after auto-approved tool calls', async () => {
const bridge = new AcpBridge({
cliEntryPath: '/tmp/qwen',
Expand Down
4 changes: 4 additions & 0 deletions packages/channels/base/src/AcpBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ export class AcpBridge extends EventEmitter implements ChannelAgentBridge {

switch (type) {
case 'agent_message_chunk': {
const meta = update['_meta'] as Record<string, unknown> | undefined;
if (typeof meta?.['parentToolCallId'] === 'string') {
break;
}
const content = update['content'] as
| { type?: string; text?: string }
| undefined;
Expand Down
51 changes: 51 additions & 0 deletions packages/channels/base/src/DaemonChannelBridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,57 @@ describe('DaemonChannelBridge', () => {
bridge.stop();
});

it('excludes nested subagent text from the daemon response', async () => {
const events = new EventQueue();
const session = createFakeSession(events);
session.prompt.mockImplementation(async () => {
events.push({
id: 1,
v: 1,
type: 'session_update',
data: {
sessionId: 'session-1',
update: {
sessionUpdate: 'agent_message_chunk',
content: { type: 'text', text: 'Nested research report.' },
_meta: {
parentToolCallId: 'agent-call-1',
subagentType: 'Explore',
},
},
},
});
events.push({
id: 2,
v: 1,
type: 'session_update',
data: {
sessionId: 'session-1',
update: {
sessionUpdate: 'agent_message_chunk',
content: { type: 'text', text: 'Final answer.' },
},
},
});
events.push(turnCompleteEvent());
return { stopReason: 'end_turn' };
});
const bridge = new DaemonChannelBridge({
cwd: '/repo',
sessionFactory: vi.fn().mockResolvedValue(session),
});

await bridge.start();
await bridge.newSession('/repo');

await expect(bridge.prompt('session-1', 'summarize')).resolves.toBe(
'Final answer.',
);

events.close();
bridge.stop();
});

it('returns only the final turn text after daemon auto-approved tool calls', async () => {
const events = new EventQueue();
const session = createFakeSession(events);
Expand Down
4 changes: 4 additions & 0 deletions packages/channels/base/src/DaemonChannelBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,10 @@ export class DaemonChannelBridge
const type = getString(update['sessionUpdate']);
switch (type) {
case 'agent_message_chunk': {
const meta = isRecord(update['_meta']) ? update['_meta'] : undefined;
if (typeof meta?.['parentToolCallId'] === 'string') {
break;
}
const text = getTextContent(update['content']);
if (text) {
this.emit('textChunk', sessionId, text);
Expand Down
Loading