dsh-dev-plan-presets 0.3.0 → 0.4.0

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.
@@ -45,6 +45,7 @@ async function loadClientTestApi() {
45
45
  useEffect: () => {},
46
46
  useRef: (initial) => ({ current: initial }),
47
47
  useCallback: (fn) => fn,
48
+ useMemo: (fn) => fn(),
48
49
  cloneElement: (element) => element,
49
50
  Fragment: 'Fragment',
50
51
  }
@@ -57,7 +58,7 @@ async function loadClientTestApi() {
57
58
  }
58
59
  }
59
60
 
60
- test('默认设置:standard + pin,零 deep-ptc 依赖', () => {
61
+ test('默认设置:standard + ask-edit + pin,零 deep-ptc 依赖', () => {
61
62
  const value = S.normalizeSettings(undefined)
62
63
  assert.equal(value.developMode, 'standard')
63
64
  assert.equal(value.modelGuardMode, 'pin')
@@ -65,6 +66,8 @@ test('默认设置:standard + pin,零 deep-ptc 依赖', () => {
65
66
  assert.equal(value.honorExplicit, false)
66
67
  assert.equal(value.audit, true)
67
68
  assert.equal(value.guardAllSubagents, false)
69
+ assert.equal(value.mainToolMode, 'ask-edit')
70
+ assert.equal(value.mainStepWarnThreshold, 6)
68
71
  assert.equal(value.childProvider, 'dsh-opencode-go')
69
72
  assert.equal(value.childModel, 'deepseek-v4.1-flash')
70
73
  assert.equal(value.childReasoningEffort, '')
@@ -91,9 +94,9 @@ test('Config 严格校验:默认值通过,非法枚举/空路由被拒绝',
91
94
  assert.ok(badEffort.issues.some((issue) => issue.path[0] === 'childReasoningEffort'))
92
95
  })
93
96
 
94
- test('standard 定义:四个委派工具、develop=standard、主窗无施工工具', () => {
97
+ test('standard 定义(mainToolMode=none):四个委派工具、develop=standard、主窗无施工工具', () => {
95
98
  const definition = P.buildPresetDefinition({
96
- settings: base(),
99
+ settings: { ...base(), mainToolMode: 'none' },
97
100
  mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
98
101
  })
99
102
  assert.equal(definition.id, 'dev-plan')
@@ -169,7 +172,7 @@ test('回退显式可见:standard + 原因,写进 description 与 persona',
169
172
  assert.match(definition.description, /已回退 standard/)
170
173
  const persona = definition.plugins.find((row) => row.id === 'persona').config.prefix
171
174
  assert.match(persona, /已回退 standard/)
172
- assert.match(persona, /不是静默降级/)
175
+ assert.match(persona, /回退显式可见/)
173
176
  })
174
177
 
175
178
  test('deep-ptc 已注册但激活失败也回退', () => {
@@ -188,10 +191,10 @@ test('apply 动态注册 preset,并在 dispose 时交还 disposer', async () =
188
191
  const ctx = createFakeContext({ registry })
189
192
  index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
190
193
  await ctx.flush()
191
- assert.equal(registry.definitions.length, 1)
192
- assert.equal(registry.definitions[0].id, 'dev-plan')
193
- const stateRoute = null
194
- assert.equal(stateRoute, null)
194
+ assert.deepEqual(
195
+ registry.definitions.map((d) => d.id),
196
+ ['dev-plan'],
197
+ )
195
198
  await ctx.dispose()
196
199
  assert.deepEqual(registry.released, ['dev-plan'])
197
200
  })
@@ -206,12 +209,18 @@ test('state 路由:默认 standard、preset 描述可用', async () => {
206
209
  assert.equal(typeof handler, 'function')
207
210
  const response = await callRoute(handler, 'GET')
208
211
  assert.equal(response.code, 200)
209
- assert.equal(response.body.version, '0.3.0')
212
+ assert.equal(response.body.version, '0.4.0')
213
+ assert.ok(Number.isInteger(response.body.stateVersion) && response.body.stateVersion >= 1)
214
+ assert.ok(typeof response.headers.etag === 'string' && response.headers.etag.length > 0)
210
215
  assert.equal(response.body.effectiveMode, 'standard')
211
216
  assert.equal(response.body.fallback.active, false)
212
217
  assert.equal(response.body.preset.id, 'dev-plan')
213
218
  assert.equal(response.body.config.guardAllSubagents, false)
219
+ assert.equal(response.body.config.mainToolMode, 'ask-edit')
220
+ assert.equal(response.body.config.mainStepWarnThreshold, 6)
214
221
  assert.equal(response.body.presets.selfId, 'dev-plan')
222
+ assert.deepEqual(response.body.presets.disabledIds, ['dev-plan', 'dev-plan-scout', 'dev-plan-scribe'])
223
+ assert.deepEqual(response.body.internalPresets, { scout: false, scribe: false })
215
224
  assert.match(response.body.preset.description, /standard/)
216
225
  await ctx.dispose()
217
226
  })
@@ -231,7 +240,8 @@ test('state 路由:请求 deep-ptc 但宿主没有时显式回退', async () =
231
240
  assert.deepEqual(response.body.presets.rows, [])
232
241
  assert.match(response.body.preset.description, /已回退 standard/)
233
242
  assert.ok(ctx.loggerCalls.warn.some((line) => line.includes('已回退 standard')))
234
- assert.equal(registry.definitions[0].plugins.at(-1).config.agentPreset, 'standard')
243
+ const mainDef = registry.definitions.find((d) => d.id === 'dev-plan')
244
+ assert.equal(mainDef.plugins.at(-1).config.agentPreset, 'standard')
235
245
  await ctx.dispose()
236
246
  })
237
247
 
@@ -243,10 +253,11 @@ test('registry 中实际存在 deep-ptc 时,develop 使用 deep-ptc', async ()
243
253
  })
244
254
  index.apply(ctx.ctx, { ...base(), developMode: 'deep-ptc' }, { verificationDelayMs: 0 })
245
255
  await ctx.flush()
246
- const definition = registry.definitions[0]
256
+ const definition = registry.definitions.find((d) => d.id === 'dev-plan')
247
257
  const develop = definition.plugins.find((row) => row.id === 'tool-subagent-develop')
248
258
  assert.equal(develop.config.agentPreset, 'deep-ptc')
249
259
  assert.equal(definition.plugins.find((row) => row.id === 'tool-subagent-recon').config.agentPreset, 'standard')
260
+ assert.equal(definition.plugins.find((row) => row.id === 'tool-subagent-scribe').config.agentPreset, 'standard')
250
261
  await ctx.dispose()
251
262
  })
252
263
 
@@ -261,7 +272,7 @@ test('目录中没有目标 preset 时回退,不把 loader entry 当可用证
261
272
  })
262
273
  index.apply(ctx.ctx, { ...base(), developMode: 'deep-ptc' }, { verificationDelayMs: 0 })
263
274
  await ctx.flush()
264
- const definition = registry.definitions[0]
275
+ const definition = registry.definitions.find((d) => d.id === 'dev-plan')
265
276
  assert.equal(definition.plugins.find((row) => row.id === 'tool-subagent-develop').config.agentPreset, 'standard')
266
277
  const state = await callRoute(webServer.handlers.get('/plugins/dev-plan-presets/state'), 'GET')
267
278
  assert.equal(state.body.effectiveMode, 'standard')
@@ -287,17 +298,19 @@ test('延迟复检可以在 registry 出现 deep-ptc 后把 develop 从 standard
287
298
  })
288
299
  index.apply(ctx.ctx, { ...base(), developMode: 'deep-ptc' }, { verificationDelayMs: 300 })
289
300
  await ctx.flush()
290
- assert.equal(registry.definitions.length, 1)
301
+ const initialMains = registry.definitions.filter((d) => d.id === 'dev-plan')
302
+ assert.equal(initialMains.length, 1)
291
303
  assert.equal(
292
- registry.definitions[0].plugins.find((row) => row.id === 'tool-subagent-develop').config.agentPreset,
304
+ initialMains[0].plugins.find((row) => row.id === 'tool-subagent-develop').config.agentPreset,
293
305
  'standard',
294
306
  )
295
307
 
296
308
  // 深度 PTC 完成动态注册后,下一次延迟复检应释放旧定义并注册 deep-ptc 版本。
297
309
  await sleep(600)
298
310
  await ctx.flush()
299
- assert.ok(registry.definitions.length >= 2)
300
- const latest = registry.definitions.at(-1)
311
+ const updatedMains = registry.definitions.filter((d) => d.id === 'dev-plan')
312
+ assert.ok(updatedMains.length >= 2)
313
+ const latest = updatedMains.at(-1)
301
314
  assert.equal(latest.plugins.find((row) => row.id === 'tool-subagent-develop').config.agentPreset, 'deep-ptc')
302
315
  assert.equal(latest.plugins.find((row) => row.id === 'tool-subagent-recon').config.agentPreset, 'standard')
303
316
  assert.ok(registry.released.includes('dev-plan'))
@@ -318,13 +331,15 @@ test('同 effective/fallback 但回退原因变化时,重新发布 preset 描
318
331
  const ctx = createFakeContext({ registry, webServer })
319
332
  index.apply(ctx.ctx, { ...base(), developMode: 'deep-ptc' }, { verificationDelayMs: 300 })
320
333
  await ctx.flush()
321
- assert.equal(registry.definitions.length, 1)
322
- assert.match(registry.definitions[0].description, /first failure/)
334
+ const firstMains = registry.definitions.filter((d) => d.id === 'dev-plan')
335
+ assert.equal(firstMains.length, 1)
336
+ assert.match(firstMains[0].description, /first failure/)
323
337
 
324
338
  await sleep(600)
325
339
  await ctx.flush()
326
- assert.ok(registry.definitions.length >= 2)
327
- const latest = registry.definitions.at(-1)
340
+ const updatedMains = registry.definitions.filter((d) => d.id === 'dev-plan')
341
+ assert.ok(updatedMains.length >= 2)
342
+ const latest = updatedMains.at(-1)
328
343
  assert.match(latest.description, /second failure/)
329
344
  assert.doesNotMatch(latest.description, /first failure/)
330
345
  const state = await callRoute(webServer.handlers.get('/plugins/dev-plan-presets/state'), 'GET')
@@ -358,6 +373,8 @@ test('config 路由:用 configEditor 写回,非法值 400 且不写', async
358
373
  honorExplicit: true,
359
374
  audit: false,
360
375
  guardAllSubagents: true,
376
+ mainToolMode: 'ask-edit',
377
+ mainStepWarnThreshold: 10,
361
378
  })
362
379
  assert.equal(ok.code, 200)
363
380
  assert.equal(configEditor.edits.length, 1)
@@ -371,6 +388,8 @@ test('config 路由:用 configEditor 写回,非法值 400 且不写', async
371
388
  honorExplicit: true,
372
389
  audit: false,
373
390
  guardAllSubagents: true,
391
+ mainToolMode: 'ask-edit',
392
+ mainStepWarnThreshold: 10,
374
393
  })
375
394
  assert.equal(ok.body.ok, true)
376
395
  await ctx.dispose()
@@ -449,11 +468,15 @@ test('模型守门 audit:只记录,不 select、不打断', async () => {
449
468
  await ctx.dispose()
450
469
  })
451
470
 
452
- test('模型守门 off:不注册监听、不 select、不检查', async () => {
471
+ test('模型守门 off(且 mainToolMode=none):不注册监听、不 select、不检查', async () => {
453
472
  const registry = createFakeRegistry()
454
473
  const child = createFakeAgent({ id: 'child-4', parentSession: 'main', origin: 'subagent' })
455
474
  const ctx = createFakeContext({ registry })
456
- index.apply(ctx.ctx, { ...base(), modelGuardMode: 'off' }, { verificationDelayMs: 0 })
475
+ index.apply(
476
+ ctx.ctx,
477
+ { ...base(), modelGuardMode: 'off', mainToolMode: 'none' },
478
+ { verificationDelayMs: 0 },
479
+ )
457
480
  await ctx.flush()
458
481
  assert.equal(ctx.listeners.get('agent/created'), undefined)
459
482
  assert.deepEqual(child.selects, [])
@@ -617,9 +640,13 @@ test('agent/disposed 清理 guard,随后插件卸载保持幂等', async () =>
617
640
  assert.equal(child.stepHandlers.length, 0)
618
641
  })
619
642
 
620
- test('modelGuardMode=off 不注册 agent/disposed', async () => {
643
+ test('modelGuardMode=off(且 mainToolMode=none)不注册 agent/disposed', async () => {
621
644
  const ctx = createFakeContext({ registry: createFakeRegistry() })
622
- index.apply(ctx.ctx, { ...base(), modelGuardMode: 'off' }, { verificationDelayMs: 0 })
645
+ index.apply(
646
+ ctx.ctx,
647
+ { ...base(), modelGuardMode: 'off', mainToolMode: 'none' },
648
+ { verificationDelayMs: 0 },
649
+ )
623
650
  await ctx.flush()
624
651
  assert.equal(ctx.listeners.get('agent/created'), undefined)
625
652
  assert.equal(ctx.listeners.get('agent/disposed'), undefined)
@@ -828,16 +855,16 @@ test('P0-1 风险分级:快速/标准/高风险 + 四维判定 + 快速路径
828
855
  const definition = P.buildPresetDefinition({
829
856
  settings: base(),
830
857
  mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
858
+ internalPresets: { scout: true, scribe: true },
831
859
  })
832
860
  const persona = definition.plugins.find((row) => row.id === 'persona').config.prefix
833
861
  for (const marker of ['快速路径', '标准路径', '高风险路径', '歧义', '影响面', '可逆性', '可验证性']) {
834
862
  assert.ok(persona.includes(marker), `缺 P0-1 标记:${marker}`)
835
863
  }
836
- assert.match(persona, /快速路径不取消用户开工批准、developer 自验和主窗审查/)
837
- assert.match(persona, /只选一条最短安全路径,不固定跑瀑布/)
838
- // 证据不足只能升级风险/补证据,不能反向降级。
839
- assert.match(persona, /提高风险等级|升级到能补足证据/)
840
- assert.match(persona, /绝不因验证困难降低路径等级/)
864
+ assert.match(persona, /不可取消用户开工批准、developer 自验与主窗审查/)
865
+ assert.match(persona, /不为了流程派 recon\/review\/scribe/)
866
+ assert.match(persona, /必须升级路径/)
867
+ assert.match(persona, /绝不因验证困难降级/)
841
868
  assert.doesNotMatch(persona, /降低路径等级并补验收/)
842
869
  })
843
870
 
@@ -845,74 +872,76 @@ test('P0-2 一次性开工契约:字段齐全且普通实现不反复批准',
845
872
  const definition = P.buildPresetDefinition({
846
873
  settings: base(),
847
874
  mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
875
+ internalPresets: { scout: true, scribe: true },
848
876
  })
849
877
  const persona = definition.plugins.find((row) => row.id === 'persona').config.prefix
850
878
  for (const marker of [
851
- '一次性开工契约',
852
- '范围:',
853
- '非目标:',
854
- '允许路径:',
855
- '接口/依赖:',
856
- '验收条件:',
857
- '检查命令:',
858
- '风险/回退:',
879
+ '开工契约',
880
+ '目标',
881
+ '非目标',
882
+ '允许与禁止改动路径',
883
+ '接口与兼容约束',
884
+ '验收标准',
885
+ '检查命令',
886
+ '风险',
859
887
  ]) {
860
888
  assert.ok(persona.includes(marker), `缺 P0-2 标记:${marker}`)
861
889
  }
862
- assert.match(persona, /普通文件编辑和实现细节不反复等待批准/)
863
- assert.match(persona, /只有范围扩大、风险变化或宿主权限要求/)
890
+ assert.match(persona, /普通实现不反复请示/)
891
+ assert.match(persona, /仅范围扩大、风险变化或宿主权限要求/)
864
892
  })
865
893
 
866
894
  test('P0-3 验收前置:最小切片→语法/静态契约→针对性测试→必要运行/GUI,且静态不冒充真实验证', () => {
867
895
  const definition = P.buildPresetDefinition({
868
896
  settings: base(),
869
897
  mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
898
+ internalPresets: { scout: true, scribe: true },
870
899
  })
871
900
  const persona = definition.plugins.find((row) => row.id === 'persona').config.prefix
872
- const ordered = ['最小切片', '语法/静态契约', '针对性测试', '必要运行/GUI 验收']
901
+ const ordered = ['最小切片', '语法/静态契约', '针对性测试', '必要运行/GUI']
873
902
  let cursor = -1
874
903
  for (const marker of ordered) {
875
904
  const index = persona.indexOf(marker)
876
905
  assert.ok(index > cursor, `P0-3 顺序错误或缺标记:${marker}`)
877
906
  cursor = index
878
907
  }
879
- assert.match(persona, /静态检查不等于真实验证/)
880
- assert.match(persona, /verified \/ partial \/ failed \/ 未验证/)
908
+ assert.match(persona, /静态检查\/单测不等于真实运行验收/)
909
+ assert.match(persona, /verified\|partial\|failed\|未验证/)
881
910
  })
882
911
 
883
912
  test('P0-4 非阻塞协作:不轮询/不忙等/不重复施工/不重复读文件,developer 打断边界明确', () => {
884
913
  const definition = P.buildPresetDefinition({
885
914
  settings: base(),
886
915
  mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
916
+ internalPresets: { scout: true, scribe: true },
887
917
  })
888
918
  const persona = definition.plugins.find((row) => row.id === 'persona').config.prefix
889
- for (const marker of ['非阻塞协作', '不轮询', '不忙等', '不重复施工', '不重复读取']) {
919
+ for (const marker of ['非阻塞协作', '不轮询', '不 `sleep`', '不重复施工', '读写 developer 正在改的文件']) {
890
920
  assert.ok(persona.includes(marker), `缺 P0-4 标记:${marker}`)
891
921
  }
892
- assert.match(persona, /developer 只在阻塞、范围冲突或关键契约需要决策时打断主窗/)
893
- assert.match(persona, /验收准备、审查基线、资料研究、独立任务/)
922
+ assert.match(persona, /developer 仅在阻塞、范围冲突或关键契约决策时打断/)
894
923
  })
895
924
 
896
925
  test('P0-5 证据化审查与严重度返工:实际 diff、阻塞/非阻塞、最终责任不外包', () => {
897
926
  const definition = P.buildPresetDefinition({
898
927
  settings: base(),
899
928
  mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
929
+ internalPresets: { scout: true, scribe: true },
900
930
  })
901
931
  const persona = definition.plugins.find((row) => row.id === 'persona').config.prefix
902
- for (const marker of ['实际 diff 和关键证据', '阻塞问题', '非阻塞建议', '主窗最终审查责任不外包']) {
932
+ for (const marker of ['证据化审查', '阻塞', '重要', '建议', 'review 不替代主窗最终审查']) {
903
933
  assert.ok(persona.includes(marker), `缺 P0-5 标记:${marker}`)
904
934
  }
905
- assert.match(persona, /send_message 续派同一 developer/)
906
- assert.match(persona, /不为一两条风格建议无限打磨/)
907
- assert.match(persona, /recon:只在缺少事实/)
908
- assert.match(persona, /review:只在高风险/)
909
- assert.match(persona, /scribe:只在文档属于验收范围/)
910
- // 实际变更证据闭环:摘要/文件清单不等于 diff 审查。
911
- for (const marker of ['实际变更证据', '不能只给文件清单', '不得声称审过实际 diff', '补证据']) {
935
+ assert.match(persona, /send_message.*developer/)
936
+ assert.match(persona, /不无限打磨/)
937
+ assert.match(persona, /recon.*仅在缺失事实/)
938
+ assert.match(persona, /review.*仅高风险/)
939
+ assert.match(persona, /scribe.*仅文档属验收范围/)
940
+ for (const marker of ['分层变更证据', '只有文件清单或口头摘要不算审过 diff', '补证据']) {
912
941
  assert.ok(persona.includes(marker), `缺实际变更证据标记:${marker}`)
913
942
  }
914
- assert.match(persona, /git diff.*等价|等价.*git diff/s)
915
- assert.match(persona, /修改前后内容/)
943
+ assert.match(persona, /git diff/)
944
+ assert.match(persona, /200 行/)
916
945
  assert.doesNotMatch(persona, /只有改动摘要也算证据|只给文件清单(?:也)?可以/)
917
946
  })
918
947
 
@@ -934,17 +963,17 @@ test('派工事实:实际 develop/send_message 工具调用才是派工,文
934
963
  const definition = P.buildPresetDefinition({
935
964
  settings: base(),
936
965
  mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
966
+ internalPresets: { scout: true, scribe: true },
937
967
  })
938
968
  const personaRow = definition.plugins.find((row) => row.id === 'persona')
939
969
  const persona = `${personaRow.config.prefix}${personaRow.config.suffix}`
940
970
  for (const marker of [
941
971
  '文本不是派工',
942
- '必须实际调用 develop',
943
- '只有工具接受后才可说“已派出 developer”',
944
- '未派工',
945
- '任务书是 develop 的 prompt 参数',
946
- '不得停在计划、前言或任务书文本',
947
- '实际调用 send_message',
972
+ '实际调用 develop',
973
+ '已派出 developer',
974
+ '未派工:原因',
975
+ 'prompt',
976
+ 'send_message',
948
977
  ]) {
949
978
  assert.ok(persona.includes(marker), `缺派工事实标记:${marker}`)
950
979
  }
@@ -1049,22 +1078,28 @@ test('任意有效 develop preset:不再限于 standard/deep-ptc', () => {
1049
1078
  })
1050
1079
  assert.equal(mode.effective, 'team-builder')
1051
1080
  assert.equal(mode.fallback, false)
1052
- const definition = P.buildPresetDefinition({ settings: base(), mode })
1081
+ const definition = P.buildPresetDefinition({
1082
+ settings: base(),
1083
+ mode,
1084
+ internalPresets: { scout: true, scribe: true },
1085
+ })
1053
1086
  const develop = definition.plugins.find((row) => row.id === 'tool-subagent-develop')
1054
1087
  assert.equal(develop.config.agentPreset, 'team-builder')
1055
1088
  assert.match(definition.description, /团队施工/)
1056
1089
  const persona = definition.plugins.find((row) => row.id === 'persona').config.prefix
1057
- assert.match(persona, /当前施工子代理模式:团队施工(team-builder)/)
1090
+ assert.match(persona, /当前施工子代理:团队施工(team-builder)/)
1058
1091
  })
1059
1092
 
1060
1093
  test('自引用与缺失/超时:保留配置原值,运行期回退 standard', async () => {
1061
- const selfMode = P.resolveDevelopMode({
1062
- requestedMode: 'dev-plan',
1063
- presets: [{ id: 'dev-plan', name: '开发规划与交付' }],
1064
- catalogChecked: true,
1065
- })
1066
- assert.equal(selfMode.fallback, true)
1067
- assert.match(selfMode.reason, /递归派工/)
1094
+ for (const selfId of ['dev-plan', 'dev-plan-scout', 'dev-plan-scribe']) {
1095
+ const selfMode = P.resolveDevelopMode({
1096
+ requestedMode: selfId,
1097
+ presets: [{ id: selfId, name: selfId }],
1098
+ catalogChecked: true,
1099
+ })
1100
+ assert.equal(selfMode.fallback, true)
1101
+ assert.match(selfMode.reason, /递归派工|内部预设/)
1102
+ }
1068
1103
 
1069
1104
  const missing = P.resolveDevelopMode({
1070
1105
  requestedMode: 'removed-preset',
@@ -1086,8 +1121,9 @@ test('自引用与缺失/超时:保留配置原值,运行期回退 standard'
1086
1121
  assert.equal(state.body.requestedMode, 'removed-preset')
1087
1122
  assert.equal(state.body.effectiveMode, 'standard')
1088
1123
  assert.equal(state.body.fallback.active, true)
1124
+ const mainDef = registry.definitions.find((d) => d.id === 'dev-plan')
1089
1125
  assert.equal(
1090
- registry.definitions[0].plugins.find((row) => row.id === 'tool-subagent-develop').config.agentPreset,
1126
+ mainDef.plugins.find((row) => row.id === 'tool-subagent-develop').config.agentPreset,
1091
1127
  'standard',
1092
1128
  )
1093
1129
  await ctx.dispose()
@@ -1262,23 +1298,23 @@ test('施工目录/权限规则写入主代理 persona', () => {
1262
1298
  const definition = P.buildPresetDefinition({
1263
1299
  settings: base(),
1264
1300
  mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
1301
+ internalPresets: { scout: true, scribe: true },
1265
1302
  })
1266
1303
  const persona = definition.plugins.find((row) => row.id === 'persona').config.prefix
1267
1304
  for (const marker of [
1268
- '施工目录与权限',
1269
- '工具创建参数',
1305
+ '施工目录边界',
1270
1306
  'cwd',
1271
1307
  '可写工作区',
1272
- '不得先以其他目录 spawn',
1273
- 'working_directory / cd',
1274
- '不假设已有子代理权限会随之扩大',
1275
- '沙箱模式',
1276
- '真实错误原文',
1308
+ 'working_directory',
1309
+ 'cd',
1310
+ '父会话事后提权不扩大已有子代理权限',
1311
+ '沙箱',
1312
+ '原错',
1277
1313
  ]) {
1278
1314
  assert.ok(persona.includes(marker), `缺权限防护标记:${marker}`)
1279
1315
  }
1280
- assert.match(persona, /目标目录不在可写范围/)
1281
- assert.match(persona, /停止派工/)
1316
+ assert.match(persona, /不在范围或不确定时停止并问用户/)
1317
+ assert.match(persona, /目标子目录尚未创建.*已存在的父目录.*自行创建该子目录/)
1282
1318
  })
1283
1319
 
1284
1320
  test('设置页契约:动态预设/模型下拉、原生控件、label 关联与守门范围开关', () => {
@@ -1327,7 +1363,7 @@ test('state 返回真实预设目录:名称、broken 与自定义预设生效'
1327
1363
  assert.equal(state.body.presets.rows[1].name, '团队施工')
1328
1364
  assert.equal(state.body.presets.rows[2].broken, 'import failed')
1329
1365
  assert.equal(
1330
- registry.definitions[0].plugins.find((row) => row.id === 'tool-subagent-develop').config.agentPreset,
1366
+ registry.definitions.find((d) => d.id === 'dev-plan').plugins.find((row) => row.id === 'tool-subagent-develop').config.agentPreset,
1331
1367
  'team-builder',
1332
1368
  )
1333
1369
  await ctx.dispose()
@@ -1466,3 +1502,411 @@ test('client 行为:provider→model 联动取首个模型,旧 provider/mode
1466
1502
  assert.equal(modelOptions.find((choice) => choice.value === 'gone').disabled, true)
1467
1503
  assert.equal(modelOptions.find((choice) => choice.value === 'a1').label, 'A1(a1)')
1468
1504
  })
1505
+
1506
+ // ── v0.4.0 新增测试(WP5)──────────────────────────────────────────────────
1507
+
1508
+ test('v0.4.0 preset 长度预算与子代理专用模板嵌入主预设', () => {
1509
+ const def = P.buildPresetDefinition({
1510
+ settings: base(),
1511
+ mode: P.resolveDevelopMode({ requestedMode: 'standard' }),
1512
+ })
1513
+ const persona = def.plugins.find((row) => row.id === 'persona').config
1514
+ const total = persona.prefix.length + persona.suffix.length
1515
+ assert.ok(total <= 6000, `persona 总长应 <= 6000,实际 ${total}`)
1516
+ assert.ok(!persona.prefix.includes('ROLE-TEMPLATE:SCOUT:BEGIN'), '不再使用旧的千字长模板标记')
1517
+ assert.ok(persona.prefix.includes('仅给子代理用,不改变主窗自身规则'))
1518
+ assert.ok(persona.prefix.includes('【仅子代理用 · 侦察/复核约束】'))
1519
+ assert.ok(persona.prefix.includes('【仅子代理用 · 文书落盘约束】'))
1520
+ assert.equal(def.plugins.find((r) => r.id === 'tool-subagent-recon').config.agentPreset, 'standard')
1521
+ assert.equal(def.plugins.find((r) => r.id === 'tool-subagent-review').config.agentPreset, 'standard')
1522
+ assert.equal(def.plugins.find((r) => r.id === 'tool-subagent-scribe').config.agentPreset, 'standard')
1523
+ const pruner = def.plugins
1524
+ .find((r) => r.id === 'compaction')
1525
+ .config.find((r) => r.id === 'tool-result-pruner').config
1526
+ assert.deepEqual(pruner, { thresholdChars: 24576, headChars: 16384, tailChars: 4096 })
1527
+ })
1528
+
1529
+ test('v0.4.0 内部轻量子预设插件面:dev-plan-scout 与 dev-plan-scribe 绝不含 Shell/委派', () => {
1530
+ const forbidden = new Set([
1531
+ '@deepseek-ai/dsh-tool-bash',
1532
+ '@deepseek-ai/dsh-tool-pwsh',
1533
+ '@deepseek-ai/dsh-tool-workflow',
1534
+ '@deepseek-ai/dsh-tool-jobs',
1535
+ '@deepseek-ai/dsh-tool-schedule',
1536
+ '@deepseek-ai/dsh-tool-goal',
1537
+ '@deepseek-ai/dsh-tool-skill',
1538
+ '@deepseek-ai/dsh-tool-todo',
1539
+ '@deepseek-ai/dsh-tool-subagent',
1540
+ '@deepseek-ai/dsh-plan-mode',
1541
+ ])
1542
+ const collect = (plugins, out = []) => {
1543
+ for (const row of plugins ?? []) {
1544
+ out.push(row)
1545
+ if (Array.isArray(row?.config)) collect(row.config, out)
1546
+ }
1547
+ return out
1548
+ }
1549
+
1550
+ const scout = P.buildScoutPresetDefinition()
1551
+ assert.equal(scout.id, 'dev-plan-scout')
1552
+ assert.equal(scout.order, 990)
1553
+ const scoutRows = collect(scout.plugins)
1554
+ for (const row of scoutRows) {
1555
+ assert.ok(!forbidden.has(row.name), `dev-plan-scout 不应含 ${row.name}`)
1556
+ }
1557
+ assert.equal(scoutRows.find((r) => r.name === '@deepseek-ai/dsh-tool-fs')?.config?.applyPatch, false)
1558
+ assert.deepEqual(
1559
+ scoutRows.find((r) => r.name === '@deepseek-ai/dsh-tool-fs-search')?.config,
1560
+ { sampleOverCapGlobResults: false },
1561
+ )
1562
+ assert.deepEqual(
1563
+ scoutRows.find((r) => r.name === '@deepseek-ai/dsh-tool-web')?.config,
1564
+ { fetch: true, searchTimeoutMs: 60000 },
1565
+ )
1566
+
1567
+ const scribe = P.buildScribePresetDefinition()
1568
+ assert.equal(scribe.id, 'dev-plan-scribe')
1569
+ assert.equal(scribe.order, 991)
1570
+ const scribeCompaction = scribe.plugins.find((r) => r.id === 'compaction')
1571
+ assert.equal(scribeCompaction?.group, true)
1572
+ assert.deepEqual(scribeCompaction?.isolate, { compaction: true, toolResultPruner: true })
1573
+ const scribeRows = collect(scribe.plugins)
1574
+ for (const row of scribeRows) {
1575
+ assert.ok(!forbidden.has(row.name), `dev-plan-scribe 不应含 ${row.name}`)
1576
+ }
1577
+ assert.equal(scribeRows.find((r) => r.name === '@deepseek-ai/dsh-tool-fs')?.config?.applyPatch, false)
1578
+ assert.ok(!scribeRows.some((r) => r.name === '@deepseek-ai/dsh-tool-fs-search'))
1579
+ assert.ok(!scribeRows.some((r) => r.name === '@deepseek-ai/dsh-tool-web'))
1580
+ })
1581
+
1582
+ test('v0.4.0 不向宿主公开列表注册 scout/scribe 独立预设,避免污染预设选择器', async () => {
1583
+ const registry = createFakeRegistry()
1584
+ const webServer = createFakeWebServer()
1585
+ const ctx = createFakeContext({ registry, webServer })
1586
+ index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
1587
+ await ctx.flush()
1588
+
1589
+ assert.deepEqual(registry.definitions.map((d) => d.id), ['dev-plan'])
1590
+ const mainDef = registry.definitions[0]
1591
+ assert.equal(mainDef.plugins.find((r) => r.id === 'tool-subagent-recon').config.agentPreset, 'standard')
1592
+ assert.equal(mainDef.plugins.find((r) => r.id === 'tool-subagent-review').config.agentPreset, 'standard')
1593
+ assert.equal(mainDef.plugins.find((r) => r.id === 'tool-subagent-scribe').config.agentPreset, 'standard')
1594
+
1595
+ const state = await callRoute(webServer.handlers.get('/plugins/dev-plan-presets/state'), 'GET')
1596
+ assert.equal(state.body.registration, 'active')
1597
+ assert.deepEqual(state.body.internalPresets, { scout: false, scribe: false })
1598
+ await ctx.dispose()
1599
+ })
1600
+
1601
+ test('v0.4.0 mainToolMode 三档矩阵:插件面、persona 规则与严格校验', () => {
1602
+ const neverAllowed = [
1603
+ '@deepseek-ai/dsh-tool-bash',
1604
+ '@deepseek-ai/dsh-tool-pwsh',
1605
+ '@deepseek-ai/dsh-tool-workflow',
1606
+ '@deepseek-ai/dsh-tool-jobs',
1607
+ '@deepseek-ai/dsh-tool-schedule',
1608
+ '@deepseek-ai/dsh-tool-goal',
1609
+ '@deepseek-ai/dsh-tool-skill',
1610
+ '@deepseek-ai/dsh-tool-todo',
1611
+ '@deepseek-ai/dsh-plan-mode',
1612
+ ]
1613
+ const mode = P.resolveDevelopMode({ requestedMode: 'standard' })
1614
+
1615
+ const noneDef = P.buildPresetDefinition({
1616
+ settings: { ...base(), mainToolMode: 'none' },
1617
+ mode,
1618
+ internalPresets: { scout: true, scribe: true },
1619
+ })
1620
+ assert.ok(!noneDef.plugins.some((r) => r.name === '@deepseek-ai/dsh-tool-fs'))
1621
+ assert.ok(!noneDef.plugins.some((r) => r.name === '@deepseek-ai/dsh-tool-fs-search'))
1622
+ assert.match(noneDef.plugins.find((r) => r.id === 'persona').config.prefix, /主窗工具权限(none)/)
1623
+
1624
+ const roDef = P.buildPresetDefinition({
1625
+ settings: { ...base(), mainToolMode: 'readonly' },
1626
+ mode,
1627
+ internalPresets: { scout: true, scribe: true },
1628
+ })
1629
+ assert.ok(!roDef.plugins.some((r) => r.name === '@deepseek-ai/dsh-tool-fs'))
1630
+ const roSearch = roDef.plugins.find((r) => r.name === '@deepseek-ai/dsh-tool-fs-search')
1631
+ assert.deepEqual(roSearch?.config, { sampleOverCapGlobResults: false })
1632
+ assert.match(roDef.plugins.find((r) => r.id === 'persona').config.prefix, /主窗工具权限(readonly)/)
1633
+
1634
+ const editDef = P.buildPresetDefinition({
1635
+ settings: { ...base(), mainToolMode: 'ask-edit' },
1636
+ mode,
1637
+ internalPresets: { scout: true, scribe: true },
1638
+ })
1639
+ const fsRow = editDef.plugins.find((r) => r.name === '@deepseek-ai/dsh-tool-fs')
1640
+ assert.ok(fsRow && fsRow.config?.applyPatch === false)
1641
+ assert.deepEqual(
1642
+ editDef.plugins.find((r) => r.name === '@deepseek-ai/dsh-tool-fs-search')?.config,
1643
+ { sampleOverCapGlobResults: false },
1644
+ )
1645
+ for (const def of [noneDef, roDef, editDef]) {
1646
+ for (const pkgName of neverAllowed) {
1647
+ assert.ok(!def.plugins.some((r) => r.name === pkgName), `主窗永不应挂 ${pkgName}`)
1648
+ }
1649
+ }
1650
+ assert.match(editDef.plugins.find((r) => r.id === 'persona').config.prefix, /主窗工具权限(ask-edit)/)
1651
+
1652
+ // settings 校验
1653
+ for (const validMode of ['none', 'readonly', 'ask-edit']) {
1654
+ const res = S.validateSettings({ mainToolMode: validMode, mainStepWarnThreshold: 2 })
1655
+ assert.equal(res.issues, undefined)
1656
+ assert.equal(res.value.mainToolMode, validMode)
1657
+ }
1658
+ assert.ok(S.validateSettings({ mainToolMode: 'full-shell' }).issues.some((i) => i.path[0] === 'mainToolMode'))
1659
+ assert.ok(S.validateSettings({ mainStepWarnThreshold: 1 }).issues.some((i) => i.path[0] === 'mainStepWarnThreshold'))
1660
+ assert.ok(S.validateSettings({ mainStepWarnThreshold: 31 }).issues.some((i) => i.path[0] === 'mainStepWarnThreshold'))
1661
+ assert.ok(S.validateSettings({ mainStepWarnThreshold: 4.5 }).issues.some((i) => i.path[0] === 'mainStepWarnThreshold'))
1662
+ })
1663
+
1664
+ test('v0.4.0 index.js 性能优化:免冗余二次复检、ETag 304 与空闲预热 modelCatalog', async () => {
1665
+ // 1) deep-ptc 首次命中后不再在 2s 后冗余触发第二次 registry.list()
1666
+ let listCalls = 0
1667
+ const registry = createFakeRegistry({ rows: [{ id: 'deep-ptc' }] })
1668
+ registry.list = async () => {
1669
+ listCalls += 1
1670
+ return [{ id: 'deep-ptc' }]
1671
+ }
1672
+ const webServer = createFakeWebServer()
1673
+ let modelCalls = 0
1674
+ const llm = {
1675
+ listProviders: () => [{ id: 'p', name: 'P' }],
1676
+ listModels: async () => {
1677
+ modelCalls += 1
1678
+ return [{ id: 'm', name: 'M' }]
1679
+ },
1680
+ }
1681
+ const ctx = createFakeContext({ registry, webServer, llm })
1682
+ index.apply(
1683
+ ctx.ctx,
1684
+ { ...base(), developMode: 'deep-ptc' },
1685
+ { verificationDelayMs: 40, prewarmDelayMs: 10 },
1686
+ )
1687
+ await ctx.flush()
1688
+ await sleep(90)
1689
+ await ctx.flush()
1690
+ assert.equal(listCalls, 1, '首次已找到目标 preset 时不应触发冗余二次 registry.list()')
1691
+ assert.equal(modelCalls, 1, '空闲预热应预先枚举一次模型目录')
1692
+
1693
+ // 2) 首次 /state 直接命中已预热 modelCatalog,且带 ETag 支持 304
1694
+ const handler = webServer.handlers.get('/plugins/dev-plan-presets/state')
1695
+ const first = await callRoute(handler, 'GET')
1696
+ assert.equal(first.code, 200)
1697
+ assert.equal(first.body.modelCatalog.checked, true)
1698
+ const etag = first.headers.etag
1699
+ assert.ok(etag, '响应头应包含 etag')
1700
+
1701
+ const notModified = await callRoute(handler, 'GET', undefined, { 'if-none-match': etag })
1702
+ assert.equal(notModified.code, 304)
1703
+ assert.equal(notModified.body, null)
1704
+ assert.equal(notModified.headers.etag, etag)
1705
+ await ctx.dispose()
1706
+ })
1707
+
1708
+ test('v0.4.0 guard.js 优化:stopped 快速拒绝、effect 释放清理与主会话步数软提醒', async () => {
1709
+ // 1) stopped=true 时直接 reject,不再调 next()
1710
+ const registry = createFakeRegistry()
1711
+ const child = createFakeAgent({ id: 'child-fast', parentSession: 'main', origin: 'subagent', current: undefined })
1712
+ const parent = createFakeAgent({
1713
+ id: 'main',
1714
+ agentPreset: 'dev-plan',
1715
+ current: { provider: 'expensive', model: 'main' },
1716
+ })
1717
+ const ctx = createFakeContext({
1718
+ registry,
1719
+ agents: { get: (id) => (id === 'main' ? parent.agent : child.agent) },
1720
+ })
1721
+ index.apply(ctx.ctx, base(), { verificationDelayMs: 0 })
1722
+ await ctx.flush()
1723
+ ctx.listeners.get('agent/created')[0]({ agent: child.agent })
1724
+ let nextCount = 0
1725
+ const next = async () => {
1726
+ nextCount += 1
1727
+ return { kind: 'enter', messages: [] }
1728
+ }
1729
+ const firstDecision = await child.stepHandlers[0](
1730
+ { modelSelection: { provider: 'other', model: 'bad' } },
1731
+ next,
1732
+ )
1733
+ assert.deepEqual(firstDecision, { kind: 'reject' })
1734
+ assert.equal(nextCount, 1)
1735
+ const secondDecision = await child.stepHandlers[0](
1736
+ { modelSelection: { provider: 'other', model: 'bad' } },
1737
+ next,
1738
+ )
1739
+ assert.deepEqual(secondDecision, { kind: 'reject' })
1740
+ assert.equal(nextCount, 1, 'stopped=true 后应短路,不再调用 next()')
1741
+
1742
+ // 2) agent.ctx.effect 清理时同步移除 stepHandler,不依赖 agent/disposed
1743
+ for (const dispose of child.agentEffects) dispose()
1744
+ assert.equal(child.stepHandlers.length, 0)
1745
+ await ctx.dispose()
1746
+
1747
+ // 3) mainToolMode='ask-edit' 下主会话步数超阈值触发温和提醒(不 select、不 cancel、不 reject)
1748
+ const budgetRegistry = createFakeRegistry()
1749
+ const mainAgent = createFakeAgent({
1750
+ id: 'main-budget',
1751
+ agentPreset: 'dev-plan',
1752
+ current: { provider: 'expensive', model: 'main' },
1753
+ })
1754
+ const budgetCtx = createFakeContext({ registry: budgetRegistry })
1755
+ index.apply(
1756
+ budgetCtx.ctx,
1757
+ { ...base(), modelGuardMode: 'off', mainToolMode: 'ask-edit', mainStepWarnThreshold: 2 },
1758
+ { verificationDelayMs: 0 },
1759
+ )
1760
+ await budgetCtx.flush()
1761
+ const created = budgetCtx.listeners.get('agent/created')
1762
+ assert.ok(Array.isArray(created) && created.length >= 1, 'mainToolMode!=none 时即便 guard=off 也应挂载主窗步数提醒')
1763
+ created[0]({ agent: mainAgent.agent })
1764
+ assert.equal(mainAgent.stepHandlers.length, 1)
1765
+
1766
+ for (let i = 0; i < 4; i += 1) {
1767
+ const decision = await mainAgent.stepHandlers[0](
1768
+ { turnId: 't1' },
1769
+ async () => ({ kind: 'enter', messages: [] }),
1770
+ )
1771
+ assert.equal(decision.kind, 'enter', '主会话步数提醒永不 reject')
1772
+ }
1773
+ assert.equal(mainAgent.selects.length, 0, '主会话永不被 select')
1774
+ assert.equal(mainAgent.cancelled.length, 0, '主会话永不被 cancel')
1775
+ assert.equal(mainAgent.injected.length, 1, '同回合超阈值只温和提醒 1 次')
1776
+ assert.match(mainAgent.injected[0].content[0].text, /转交 recon \/ develop/)
1777
+
1778
+ // 新回合重置计数
1779
+ for (let i = 0; i < 3; i += 1) {
1780
+ await mainAgent.stepHandlers[0]({ turnId: 't2' }, async () => ({ kind: 'enter', messages: [] }))
1781
+ }
1782
+ assert.equal(mainAgent.injected.length, 2)
1783
+ await budgetCtx.dispose()
1784
+ })
1785
+
1786
+ test('v0.4.0 client.js 行为与优化契约:禁用全部内部预设、304 跳过重渲染与新字段', async () => {
1787
+ const api = await loadClientTestApi()
1788
+ const T = (cn) => cn
1789
+ const choices = api.presetChoices(
1790
+ [
1791
+ { id: 'dev-plan', name: '开发规划与交付' },
1792
+ { id: 'dev-plan-scout', name: '内部侦察' },
1793
+ { id: 'dev-plan-scribe', name: '内部文书' },
1794
+ { id: 'deep-ptc', name: '深度 PTC' },
1795
+ ],
1796
+ 'standard',
1797
+ ['dev-plan', 'dev-plan-scout', 'dev-plan-scribe'],
1798
+ T,
1799
+ )
1800
+ const byValue = Object.fromEntries(choices.map((c) => [c.value, c]))
1801
+ assert.equal(byValue['dev-plan'].disabled, true)
1802
+ assert.equal(byValue['dev-plan-scout'].disabled, true)
1803
+ assert.equal(byValue['dev-plan-scribe'].disabled, true)
1804
+ assert.equal(byValue['deep-ptc'].disabled, undefined)
1805
+
1806
+ assert.equal(api.isStateConverged(null), false)
1807
+ assert.equal(
1808
+ api.isStateConverged({
1809
+ registration: 'active',
1810
+ modelCatalog: { checked: false },
1811
+ presets: { checked: true },
1812
+ }),
1813
+ false,
1814
+ )
1815
+ assert.equal(
1816
+ api.isStateConverged({
1817
+ registration: 'active',
1818
+ modelCatalog: { checked: true },
1819
+ presets: { checked: true },
1820
+ }),
1821
+ true,
1822
+ )
1823
+
1824
+ const clientSource = readFileSync(join(ROOT, 'client.js'), 'utf8')
1825
+ for (const marker of [
1826
+ 'if-none-match',
1827
+ '304',
1828
+ 'stateVersion',
1829
+ 'FAST_POLL_MS = 700',
1830
+ 'IDLE_POLL_MS = 30000',
1831
+ 'visibilitychange',
1832
+ 'document.hidden',
1833
+ 'AbortController',
1834
+ 'React.useMemo',
1835
+ 'timersRef',
1836
+ 'mainToolMode',
1837
+ 'mainStepWarnThreshold',
1838
+ 'scheduleNextRef',
1839
+ 'stateTag',
1840
+ '超过阈值仅提示转交子代理,绝不强制中断或改换主模型',
1841
+ ]) {
1842
+ assert.ok(clientSource.includes(marker), `client.js 缺少 v0.4.0 标记:${marker}`)
1843
+ }
1844
+ assert.ok(!/setInterval\(/.test(clientSource), 'client.js 不应再使用固定 setInterval 轮询')
1845
+
1846
+ const mode = P.resolveDevelopMode({ requestedMode: 'standard' })
1847
+ assert.doesNotMatch(P.buildDescription(mode, 'ask-edit'), /永不亲自写代码/)
1848
+ assert.match(P.buildDescription(mode, 'ask-edit'), /局部微改/)
1849
+ assert.match(P.buildDescription(mode, 'readonly'), /只读检索/)
1850
+ })
1851
+
1852
+ test('v0.4.0 插件重载后不同实例相同 stateVersion 不返回 304', async () => {
1853
+ const webServer1 = createFakeWebServer()
1854
+ const ctx1 = createFakeContext({ registry: createFakeRegistry(), webServer: webServer1 })
1855
+ index.apply(ctx1.ctx, base(), { verificationDelayMs: 0, prewarmModelCatalog: false })
1856
+ await ctx1.flush()
1857
+ const first = await callRoute(webServer1.handlers.get('/plugins/dev-plan-presets/state'), 'GET')
1858
+ assert.equal(first.code, 200)
1859
+ assert.ok(typeof first.body.stateTag === 'string' && first.body.stateTag.length > 0)
1860
+ await ctx1.dispose()
1861
+
1862
+ const webServer2 = createFakeWebServer()
1863
+ const ctx2 = createFakeContext({ registry: createFakeRegistry(), webServer: webServer2 })
1864
+ index.apply(ctx2.ctx, base(), { verificationDelayMs: 0, prewarmModelCatalog: false })
1865
+ await ctx2.flush()
1866
+ const handler2 = webServer2.handlers.get('/plugins/dev-plan-presets/state')
1867
+ const second = await callRoute(handler2, 'GET', undefined, { 'if-none-match': first.headers.etag })
1868
+ assert.equal(second.code, 200, '不同插件实例即使 stateVersion 相同也不应命中旧实例 ETag 返回 304')
1869
+ assert.equal(second.body.stateVersion, first.body.stateVersion)
1870
+ assert.notEqual(second.body.stateTag, first.body.stateTag)
1871
+ assert.notEqual(second.headers.etag, first.headers.etag)
1872
+ await ctx2.dispose()
1873
+ })
1874
+
1875
+ test('v0.4.0 guard 注入自身 source 消息不重置步数提醒', async () => {
1876
+ const registry = createFakeRegistry()
1877
+ const messages = [{ role: 'user', id: 'u1', content: 'start' }]
1878
+ const mainAgent = createFakeAgent({
1879
+ id: 'main-self-msg',
1880
+ agentPreset: 'dev-plan',
1881
+ current: { provider: 'expensive', model: 'main' },
1882
+ })
1883
+ mainAgent.agent.session.messages = messages
1884
+ mainAgent.agent.inject = (msg) => {
1885
+ mainAgent.injected.push(msg)
1886
+ messages.push({ role: 'user', id: `inj-${messages.length}`, ...msg })
1887
+ }
1888
+
1889
+ const ctx = createFakeContext({ registry })
1890
+ index.apply(
1891
+ ctx.ctx,
1892
+ { ...base(), modelGuardMode: 'off', mainToolMode: 'ask-edit', mainStepWarnThreshold: 2 },
1893
+ { verificationDelayMs: 0, prewarmModelCatalog: false },
1894
+ )
1895
+ await ctx.flush()
1896
+ ctx.listeners.get('agent/created')[0]({ agent: mainAgent.agent })
1897
+
1898
+ // 没有传 turnId,靠 session.messages 识别回合;第 3 步触发注入后,第 4/5/6 步不应重置再提醒
1899
+ for (let i = 0; i < 6; i += 1) {
1900
+ const decision = await mainAgent.stepHandlers[0]({}, async () => ({ kind: 'enter', messages: [] }))
1901
+ assert.equal(decision.kind, 'enter')
1902
+ }
1903
+ assert.equal(mainAgent.injected.length, 1, '自身注入的 source.kind=dev-plan-presets 消息不应重置当轮计数')
1904
+
1905
+ // 真正的新用户消息到来后,计数重置并可在超阈值后再次提醒一次
1906
+ messages.push({ role: 'user', id: 'u2', content: 'next turn' })
1907
+ for (let i = 0; i < 3; i += 1) {
1908
+ await mainAgent.stepHandlers[0]({}, async () => ({ kind: 'enter', messages: [] }))
1909
+ }
1910
+ assert.equal(mainAgent.injected.length, 2)
1911
+ await ctx.dispose()
1912
+ })