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
590 changes: 590 additions & 0 deletions docs/design/acp-repeated-tool-call-protection.md

Large diffs are not rendered by default.

59 changes: 30 additions & 29 deletions docs/users/configuration/settings.md

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion packages/channels/base/src/AcpBridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
AcpBridge,
} from './AcpBridge.js';
import { CHANNEL_LOOP_MCP_SERVER_NAME } from './ChannelLoopTools.js';
import type { ChannelLoopToolHandler } from './ChannelAgentBridge.js';
import {
CHANNEL_PROMPT_META_KEY,
type ChannelLoopToolHandler,
} from './ChannelAgentBridge.js';

const child = vi.hoisted(() => {
class MockEmitter {
Expand Down Expand Up @@ -430,6 +433,11 @@ describe('AcpBridge', () => {
await expect(bridge.prompt('s-1', 'question')).resolves.toBe(
'Final answer.',
);
expect(bridge.connection.prompt).toHaveBeenCalledWith({
sessionId: 's-1',
prompt: [{ type: 'text', text: 'question' }],
_meta: { [CHANNEL_PROMPT_META_KEY]: true },
});
});

it('excludes nested subagent text from the final response', async () => {
Expand Down
14 changes: 8 additions & 6 deletions packages/channels/base/src/AcpBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import type {
RequestPermissionRequest,
RequestPermissionResponse,
} from '@agentclientprotocol/sdk';
import type {
AvailableCommand,
ChannelAgentBridge,
ChannelAgentBridgeSessionOptions,
ChannelLoopToolHandler,
ToolCallEvent,
import {
CHANNEL_PROMPT_META_KEY,
type AvailableCommand,
type ChannelAgentBridge,
type ChannelAgentBridgeSessionOptions,
type ChannelLoopToolHandler,
type ToolCallEvent,
} from './ChannelAgentBridge.js';
import {
CHANNEL_LOOP_MCP_SERVER_NAME,
Expand Down Expand Up @@ -280,6 +281,7 @@ export class AcpBridge extends EventEmitter implements ChannelAgentBridge {
await conn.prompt({
sessionId,
prompt: prompt as Array<{ type: 'text'; text: string }>,
_meta: { [CHANNEL_PROMPT_META_KEY]: true },
});
} finally {
this.off('textChunk', onChunk);
Expand Down
3 changes: 3 additions & 0 deletions packages/channels/base/src/ChannelAgentBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type {
RequestPermissionResponse,
} from '@agentclientprotocol/sdk';

// Client-supplied routing hint only; never use it as an authorization boundary.
export const CHANNEL_PROMPT_META_KEY = 'qwen.channel.prompt';
Comment thread
doudouOUC marked this conversation as resolved.
Comment thread
doudouOUC marked this conversation as resolved.

export interface AvailableCommand {
name: string;
description: string;
Expand Down
3 changes: 3 additions & 0 deletions packages/channels/base/src/DaemonChannelBridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
type DaemonChannelLoopMcpHost,
type DaemonChannelSessionClient,
} from './DaemonChannelBridge.js';
import { CHANNEL_PROMPT_META_KEY } from './ChannelAgentBridge.js';

class EventQueue implements AsyncGenerator<DaemonChannelEvent> {
private events: DaemonChannelEvent[] = [];
Expand Down Expand Up @@ -243,6 +244,7 @@ describe('DaemonChannelBridge', () => {
expect(session.prompt).toHaveBeenCalledWith(
{
prompt: [{ type: 'text', text: 'summarize' }],
_meta: { [CHANNEL_PROMPT_META_KEY]: true },
},
expect.any(AbortSignal),
);
Expand Down Expand Up @@ -1849,6 +1851,7 @@ describe('DaemonChannelBridge', () => {
{ type: 'image', data: 'base64-image', mimeType: 'image/png' },
{ type: 'text', text: 'describe' },
],
_meta: { [CHANNEL_PROMPT_META_KEY]: true },
},
expect.any(AbortSignal),
);
Expand Down
24 changes: 16 additions & 8 deletions packages/channels/base/src/DaemonChannelBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import type {
RequestPermissionRequest,
RequestPermissionResponse,
} from '@agentclientprotocol/sdk';
import type {
AvailableCommand,
BridgeSessionInfo,
ChannelAgentBridge,
ChannelAgentBridgeSessionOptions,
ChannelLoopToolHandler,
ToolCallEvent,
import {
CHANNEL_PROMPT_META_KEY,
type AvailableCommand,
type BridgeSessionInfo,
type ChannelAgentBridge,
type ChannelAgentBridgeSessionOptions,
type ChannelLoopToolHandler,
type ToolCallEvent,
} from './ChannelAgentBridge.js';
import { readAvailableCommandAltNames } from './AcpBridge.js';
import {
Expand All @@ -35,6 +36,7 @@ export interface DaemonChannelSessionClient {
prompt(
req: {
prompt: Array<Record<string, unknown>>;
_meta?: Record<string, unknown>;
},
Comment thread
doudouOUC marked this conversation as resolved.
signal?: AbortSignal,
): Promise<{ stopReason?: string; [key: string]: unknown }>;
Expand Down Expand Up @@ -404,7 +406,13 @@ export class DaemonChannelBridge
prompt.push({ type: 'text', text });

try {
const result = await session.prompt({ prompt }, controller.signal);
const result = await session.prompt(
{
prompt,
_meta: { [CHANNEL_PROMPT_META_KEY]: true },
},
controller.signal,
);
// Prefer turn_complete for deterministic chunk collection (SSE path).
// Fall back to one event-loop tick for non-SSE prompt paths (blocking
// HTTP, non-202 responses) where turn_complete never arrives.
Expand Down
1 change: 1 addition & 0 deletions packages/channels/base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type {
SessionDiedEvent,
ToolCallEvent,
} from './ChannelAgentBridge.js';
export { CHANNEL_PROMPT_META_KEY } from './ChannelAgentBridge.js';
export type { AcpBridgeOptions } from './AcpBridge.js';
export { DaemonChannelBridge } from './DaemonChannelBridge.js';
export type {
Expand Down
Loading
Loading