agent-gear 2.11.0 → 2.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ export const DSH_ACP_PROFILE = 'acp';
14
14
  /** dsh ACP profile 组合包名(写入 patch 的 `acp` 条目)。 */
15
15
  export const DSH_ACP_APP_NAME = '@deepseek-ai/dsh-acp';
16
16
 
17
- /** 我方在 `cordis.patch.yml` 中维护的 4 个条目(按此顺序写入,按 id 替换)。 */
17
+ /** 我方在 `cordis.patch.yml` 中维护的 4 个扁平条目(按此顺序写入,按 id 替换)。 */
18
18
  export const DSH_PATCH_ENTRY_IDS = [
19
19
  'llm-deepseek',
20
20
  'llm-pi-ai',
@@ -22,6 +22,15 @@ export const DSH_PATCH_ENTRY_IDS = [
22
22
  'acp',
23
23
  ] as const;
24
24
 
25
+ /**
26
+ * 我方在 `cordis.patch.yml` 中维护的 insert 形态条目 id(位于顶层 `- insert: [...]` 块内)。
27
+ * 与扁平条目合计 5 个受管条目(`entryCount`)。
28
+ */
29
+ export const DSH_PATCH_INSERT_ENTRY_IDS = ['header-masq'] as const;
30
+
31
+ /** `header-masq` insert 条目对应的插件包名。 */
32
+ export const DSH_HEADER_MASQ_PLUGIN_NAME = 'dsh-header-masq';
33
+
25
34
  /** 写入 dsh 配置失败(消息只含路径/条目名,不含 API Key 等 secret)。 */
26
35
  export class DshConfigError extends Error {
27
36
  constructor(message: string) {
@@ -53,7 +62,7 @@ export interface WriteDshConfigResult {
53
62
  credentialsCreated: boolean;
54
63
  /** 写入的模型数量。 */
55
64
  modelCount: number;
56
- /** patch 中我方维护的条目数(固定 4)。 */
65
+ /** patch 中我方维护的条目数(4 扁平 + 1 insert,固定 5)。 */
57
66
  entryCount: number;
58
67
  }
59
68
 
@@ -113,6 +122,40 @@ function buildEntry(id: (typeof DSH_PATCH_ENTRY_IDS)[number], env: DshConfigEnv)
113
122
  }
114
123
  }
115
124
 
125
+ /**
126
+ * 我方 insert 条目(`- insert: [{id, name, config}]` 的内层条目)。
127
+ *
128
+ * 需求给定四键:`source` / `targets` / `fallbackToSessionId` / `debug`;
129
+ * `hosts` 缺省不写(插件缺省 `[]` = 所有主机,D6)。
130
+ */
131
+ function buildInsertEntry(
132
+ id: (typeof DSH_PATCH_INSERT_ENTRY_IDS)[number],
133
+ ): Record<string, unknown> {
134
+ switch (id) {
135
+ case 'header-masq':
136
+ return {
137
+ id,
138
+ name: DSH_HEADER_MASQ_PLUGIN_NAME,
139
+ config: {
140
+ source: 'x-deepseek-harness-session-id',
141
+ targets: ['x-opencode-session'],
142
+ fallbackToSessionId: true,
143
+ debug: false,
144
+ },
145
+ };
146
+ default:
147
+ throw new DshConfigError(`unsupported dsh patch insert entry: ${String(id)}`);
148
+ }
149
+ }
150
+
151
+ /** 顶层块是否为「内层条目 id 命中」的 insert 块。 */
152
+ function isInsertBlockFor(item: unknown, id: string): boolean {
153
+ if (!isMap(item)) return false;
154
+ const insert = item.get('insert');
155
+ if (!isSeq(insert)) return false;
156
+ return insert.items.some((inner) => isMap(inner) && inner.get('id') === id);
157
+ }
158
+
116
159
  function parsePatchDocument(text: string, path: string): Document {
117
160
  if (text.trim().length === 0) return new Document([]);
118
161
  const doc = parseDocument(text);
@@ -130,7 +173,9 @@ function parsePatchDocument(text: string, path: string): Document {
130
173
  /**
131
174
  * 合并 `cordis.patch.yml`:
132
175
  *
133
- * - 顶层条目数组,按 `id` 定位我方 4 个条目并**整体替换其 config**;
176
+ * - 顶层条目数组,按 `id` 定位我方 4 个扁平条目并**整体替换其 config**;
177
+ * - insert 形态条目:遍历顶层 `insert` 为 seq 的块,内层 `id` 命中即**整体替换该 insert 块**
178
+ * (我方块恰一个内层条目);未命中则在顶层数组**末尾追加**;
134
179
  * - 其余条目与注释逐字保留(新条目追加在末尾);
135
180
  * - 解析失败抛错、不写文件(不静默丢数据)。
136
181
  */
@@ -155,9 +200,22 @@ function mergePatchDocument(doc: Document, env: DshConfigEnv): { content: string
155
200
  if (id === 'acp') doc.setIn([index, 'name'], DSH_ACP_APP_NAME);
156
201
  }
157
202
 
203
+ for (const id of DSH_PATCH_INSERT_ENTRY_IDS) {
204
+ const block = doc.createNode({ insert: [buildInsertEntry(id)] });
205
+ const index = seq.items.findIndex((item) => isInsertBlockFor(item, id));
206
+ if (index === -1) {
207
+ seq.add(block);
208
+ continue;
209
+ }
210
+ doc.setIn([index], block);
211
+ }
212
+
158
213
  let content = doc.toString();
159
214
  if (!content.endsWith('\n')) content += '\n';
160
- return { content, entryCount: DSH_PATCH_ENTRY_IDS.length };
215
+ return {
216
+ content,
217
+ entryCount: DSH_PATCH_ENTRY_IDS.length + DSH_PATCH_INSERT_ENTRY_IDS.length,
218
+ };
161
219
  }
162
220
 
163
221
  /**
@@ -0,0 +1,118 @@
1
+ /**
2
+ * 手动复现脚本(不参与 `npm test`,vitest 只收集 *.test.ts / *.spec.ts):
3
+ * 「Agent 调用 question 工具后立即报 The user dismissed this question」。
4
+ *
5
+ * 为什么需要它:question 工具的失败文案由 OpenCode 侧产生,单元测试里的假 Agent
6
+ * 无法复刻「elicitation 被 cancel → form cancel → CancelledError」这条真实映射,
7
+ * 必须用真实 `opencode acp` 进程 + 真实 AcpSessionBridge 观测。
8
+ *
9
+ * 前置条件:
10
+ * - 本机已安装 `opencode`(>= 2.1.x),且 ~/.config/opencode 已配置可用模型;
11
+ * - 已 `npm ci`(需要 @agentclientprotocol/sdk)。
12
+ *
13
+ * 用法(在 packages/agent-controller 目录):
14
+ * npx tsx tests/manual/repro-question-tool.ts <policy> [prompt]
15
+ *
16
+ * policy = none 不响应问询(观测 65s bridge 超时后的工具结果)
17
+ * accept 收到问询立即 accept(对照组:question 工具应 completed)
18
+ * decline 收到问询立即 decline
19
+ * cancel 收到问询立即 cancel(秒级复现 "dismissed")
20
+ *
21
+ * 环境变量:
22
+ * REPRO_MODEL 指定模型(形如 zag/deepseek-v4.1-flash),不设则由 OpenCode 默认模型决定。
23
+ */
24
+ import { mkdtempSync } from 'node:fs';
25
+ import { tmpdir } from 'node:os';
26
+ import { join } from 'node:path';
27
+ import { AcpSessionBridge } from '../../src/acp/bridge.js';
28
+ import { AcpSpawner } from '../../src/acp/spawner.js';
29
+
30
+ type Policy = 'none' | 'accept' | 'decline' | 'cancel';
31
+
32
+ const policy = (process.argv[2] ?? 'none') as Policy;
33
+ const promptText =
34
+ process.argv[3] ?? '请用 question 工具向我提一个单选题(3 个选项),问完就停下等我回答。';
35
+
36
+ if (!['none', 'accept', 'decline', 'cancel'].includes(policy)) {
37
+ console.error(`unknown policy: ${policy}`);
38
+ process.exit(2);
39
+ }
40
+
41
+ const cwd = mkdtempSync(join(tmpdir(), 'repro-question-'));
42
+ const startedAt = Date.now();
43
+ const log = (...args: unknown[]) => console.log(`[${Date.now() - startedAt}ms]`, ...args);
44
+
45
+ let bridge: AcpSessionBridge;
46
+
47
+ const socket = {
48
+ emit(event: string, payload: Record<string, unknown>) {
49
+ log('emit', event, JSON.stringify(payload).slice(0, 1200));
50
+
51
+ if (event === 'acp:elicitation' && policy !== 'none') {
52
+ const requestId = payload.requestId as string;
53
+ setTimeout(() => {
54
+ log('-> respond elicitation', requestId, policy);
55
+ bridge.handleElicitationResponse(
56
+ requestId,
57
+ policy,
58
+ policy === 'accept' ? { q0: 'A' } : undefined,
59
+ );
60
+ }, 50);
61
+ }
62
+
63
+ if (event === 'acp:permission' && policy !== 'none') {
64
+ const requestId = payload.requestId as string;
65
+ const options = payload.options as Array<{ optionId: string; kind?: string }> | undefined;
66
+ const allow = options?.find((o) => o.kind === 'allow_once' || o.kind === 'allow_always') ?? options?.[0];
67
+ setTimeout(() => {
68
+ log('-> respond permission', requestId, allow?.optionId);
69
+ bridge.handlePermissionResponse(
70
+ requestId,
71
+ allow ? { outcome: 'selected', optionId: allow.optionId } : { outcome: 'cancelled' },
72
+ );
73
+ }, 50);
74
+ }
75
+ return true;
76
+ },
77
+ on() { return socket; },
78
+ off() { return socket; },
79
+ };
80
+
81
+ const spawner = new AcpSpawner({ sessionId: `repro-${Date.now()}`, cwd });
82
+ bridge = new AcpSessionBridge(
83
+ socket as never,
84
+ {
85
+ sessionId: `repro-${Date.now()}`,
86
+ cwd,
87
+ ...(process.env.REPRO_MODEL ? { initialModelId: process.env.REPRO_MODEL } : {}),
88
+ } as never,
89
+ spawner,
90
+ );
91
+
92
+ async function main(): Promise<void> {
93
+ log('bridge.start()', { cwd, policy });
94
+ await bridge.start();
95
+ log('bridge started');
96
+ bridge.sendInput({ type: 'text', content: promptText });
97
+ log('prompt sent');
98
+
99
+ await new Promise<void>((resolve) => {
100
+ // 65s bridge 超时 + 余量
101
+ const timer = setTimeout(() => { log('TIMEOUT 100s'); resolve(); }, 100_000);
102
+ bridge.on('acp:stopped', () => {
103
+ log('bridge stopped');
104
+ clearTimeout(timer);
105
+ resolve();
106
+ });
107
+ });
108
+
109
+ await bridge.stop().catch(() => {});
110
+ spawner.stop();
111
+ setTimeout(() => process.exit(0), 300);
112
+ }
113
+
114
+ main().catch((error) => {
115
+ console.error('repro failed', error);
116
+ spawner.stop();
117
+ process.exit(1);
118
+ });