@@ -24,6 +24,12 @@ import {
2424 PROTOCOL_VERSION ,
2525 RequestError ,
2626} from '@agentclientprotocol/sdk' ;
27+ import {
28+ EXTERNAL_TOOL_GUARD_READY_META_KEY ,
29+ EXTERNAL_TOOL_GUARD_REQUIRED_VALUE ,
30+ PRIVATE_EXTERNAL_TOOL_GUARD_ENV ,
31+ PRIVATE_EXTERNAL_TOOL_GUARD_PROVIDER_ENV ,
32+ } from '@qwen-code/acp-bridge/externalToolGuard' ;
2733import { Writable , Readable } from 'node:stream' ;
2834
2935// Protect the stdout NDJSON pipe — any console method that writes to
@@ -40,14 +46,37 @@ const delayMs = parseInt(process.env.MOCK_ACP_PROMPT_DELAY_MS || '100', 10);
4046const emitChunks = parseInt ( process . env . MOCK_ACP_EMIT_CHUNKS || '3' , 10 ) ;
4147let sessionCounter = 0 ;
4248
49+ // Mirror the real child (acpAgent.ts): `qwen serve` requires the guard ack
50+ // in the initialize response, and the markers are consumed + deleted before
51+ // anything else can inherit them.
52+ const externalToolGuardMarker = process . env [ PRIVATE_EXTERNAL_TOOL_GUARD_ENV ] ;
53+ delete process . env [ PRIVATE_EXTERNAL_TOOL_GUARD_ENV ] ;
54+ delete process . env [ PRIVATE_EXTERNAL_TOOL_GUARD_PROVIDER_ENV ] ;
55+ const externalToolGuardRequired =
56+ externalToolGuardMarker === EXTERNAL_TOOL_GUARD_REQUIRED_VALUE ;
57+
4358new AgentSideConnection (
4459 ( connection ) => ( {
4560 async initialize ( ) {
61+ // Build ONE meta record and attach `_meta` once, exactly like the
62+ // real child (acpAgent.ts), so a future conditional meta source
63+ // merges instead of clobbering the guard ack via duplicate keys.
64+ const responseMeta = {
65+ ...( externalToolGuardRequired
66+ ? {
67+ [ EXTERNAL_TOOL_GUARD_READY_META_KEY ] :
68+ EXTERNAL_TOOL_GUARD_REQUIRED_VALUE ,
69+ }
70+ : { } ) ,
71+ } ;
4672 return {
4773 protocolVersion : PROTOCOL_VERSION ,
4874 agentInfo : { name : 'mock-acp' , version : '0.0.1' } ,
4975 authMethods : [ ] ,
5076 agentCapabilities : { } ,
77+ ...( Object . keys ( responseMeta ) . length > 0
78+ ? { _meta : responseMeta }
79+ : { } ) ,
5180 } ;
5281 } ,
5382
0 commit comments