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.
package/client.js CHANGED
@@ -116,6 +116,108 @@ window.__ModuleLoader__.load({
116
116
  }),
117
117
  noticeOk: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)', lineHeight: 1.5 },
118
118
  noticeError: { fontSize: 12, color: 'var(--dsw-alias-state-error-primary)', lineHeight: 1.5 },
119
+ badge: {
120
+ fontSize: 11,
121
+ padding: '1px 7px',
122
+ borderRadius: 'var(--dsw-radius-xs)',
123
+ border: '1px solid var(--dsw-alias-border-l3)',
124
+ background: 'var(--dsw-alias-bg-layer-2)',
125
+ color: 'var(--dsw-alias-label-secondary)',
126
+ fontFamily: 'var(--ds-font-family-code)',
127
+ },
128
+ summaryBar: {
129
+ display: 'flex',
130
+ gap: 8,
131
+ flexWrap: 'wrap',
132
+ padding: '8px 10px',
133
+ borderRadius: 'var(--dsw-radius-sm)',
134
+ border: '1px solid var(--dsw-alias-border-l2)',
135
+ background: 'var(--dsw-alias-bg-layer-1)',
136
+ },
137
+ summaryItem: {
138
+ display: 'flex',
139
+ gap: 5,
140
+ alignItems: 'center',
141
+ fontSize: 12,
142
+ color: 'var(--dsw-alias-label-secondary)',
143
+ paddingRight: 8,
144
+ },
145
+ summaryKey: { color: 'var(--dsw-alias-label-tertiary)' },
146
+ modeGrid: {
147
+ display: 'grid',
148
+ gridTemplateColumns: 'repeat(auto-fit, minmax(185px, 1fr))',
149
+ gap: 8,
150
+ },
151
+ modeCard: {
152
+ border: '1px solid var(--dsw-alias-border-l2)',
153
+ borderRadius: 'var(--dsw-radius-xs)',
154
+ padding: '8px 10px',
155
+ background: 'var(--dsw-alias-bg-layer-1)',
156
+ display: 'flex',
157
+ flexDirection: 'column',
158
+ gap: 4,
159
+ textAlign: 'left',
160
+ cursor: 'pointer',
161
+ font: 'inherit',
162
+ color: 'var(--dsw-alias-label-primary)',
163
+ },
164
+ modeCardActive: {
165
+ border: '1px solid var(--dsw-alias-button-primary-fill)',
166
+ borderLeft: '3px solid var(--dsw-alias-button-primary-fill)',
167
+ background: 'var(--dsw-alias-bg-layer-2)',
168
+ },
169
+ modeCardHead: {
170
+ display: 'flex',
171
+ justifyContent: 'space-between',
172
+ alignItems: 'center',
173
+ gap: 6,
174
+ fontSize: 12,
175
+ fontWeight: 600,
176
+ color: 'var(--dsw-alias-label-primary)',
177
+ },
178
+ modeCardDesc: {
179
+ fontSize: 11,
180
+ lineHeight: 1.5,
181
+ color: 'var(--dsw-alias-label-tertiary)',
182
+ },
183
+ actionBar: {
184
+ border: '1px solid var(--dsw-alias-border-l2)',
185
+ borderRadius: 'var(--dsw-radius-sm)',
186
+ padding: '10px 14px',
187
+ background: 'var(--dsw-alias-card-fill)',
188
+ display: 'flex',
189
+ flexDirection: 'column',
190
+ gap: 8,
191
+ },
192
+ actionBarDirty: {
193
+ borderLeft: '3px solid var(--dsw-alias-state-warn-primary)',
194
+ },
195
+ actionRow: {
196
+ display: 'flex',
197
+ gap: 8,
198
+ alignItems: 'center',
199
+ flexWrap: 'wrap',
200
+ },
201
+ sectionCaption: {
202
+ fontSize: 11,
203
+ fontWeight: 600,
204
+ color: 'var(--dsw-alias-label-tertiary)',
205
+ paddingTop: 2,
206
+ },
207
+ }
208
+
209
+ const RECOMMENDED_DEFAULTS = {
210
+ developMode: 'standard',
211
+ childProvider: 'dsh-opencode-go',
212
+ childModel: 'deepseek-v4.1-flash',
213
+ childReasoningEffort: '',
214
+ modelGuardMode: 'pin',
215
+ killOnViolation: true,
216
+ honorExplicit: false,
217
+ audit: true,
218
+ guardAllSubagents: false,
219
+ mainToolMode: 'ask-edit',
220
+ mainStepWarnThreshold: 6,
119
221
  }
120
222
 
121
223
  const FIELD_LABELS = {
@@ -128,6 +230,8 @@ window.__ModuleLoader__.load({
128
230
  honorExplicit: ['尊重子代理自己选的模型', 'Honor an explicit child model'],
129
231
  audit: ['记录详细日志', 'Write detailed logs'],
130
232
  guardAllSubagents: ['同时管理其他插件的子代理', 'Also govern subagents from other plugins'],
233
+ mainToolMode: ['主窗工具权限', 'Main session tools'],
234
+ mainStepWarnThreshold: ['主窗连续步数提醒阈值', 'Main step warning threshold'],
131
235
  }
132
236
 
133
237
  function useActiveLocale(locale) {
@@ -148,50 +252,172 @@ window.__ModuleLoader__.load({
148
252
  return active
149
253
  }
150
254
 
255
+ const FAST_POLL_MS = 700
256
+ const IDLE_POLL_MS = 30000
257
+
258
+ const isStateConverged = (state) =>
259
+ Boolean(
260
+ state &&
261
+ state.registration !== 'pending' &&
262
+ state.registration !== 'switching' &&
263
+ state.modelCatalog &&
264
+ state.modelCatalog.checked === true &&
265
+ state.presets &&
266
+ state.presets.checked === true,
267
+ )
268
+
151
269
  function useHostState() {
152
270
  const [state, setState] = React.useState(null)
153
271
  const [error, setError] = React.useState(null)
154
272
  const stopped = React.useRef(false)
273
+ const mountedRef = React.useRef(true)
274
+ const stateRef = React.useRef(null)
275
+ const lastVersionRef = React.useRef(null)
276
+ const inFlightRef = React.useRef(null)
277
+ const pollTimerRef = React.useRef(null)
278
+ const scheduleNextRef = React.useRef(null)
155
279
 
156
280
  const load = React.useCallback(async (force = false) => {
157
281
  if (stopped.current && force !== true) return null
158
- try {
159
- const response = await fetch(API + '/state', { cache: 'no-store' })
160
- if (response.status === 404) {
161
- stopped.current = true
162
- setError({ kind: 'not-found' })
163
- return null
164
- }
165
- let json = null
282
+ if (inFlightRef.current) {
283
+ if (force !== true) return inFlightRef.current.promise
166
284
  try {
167
- json = await response.json()
285
+ if (inFlightRef.current.controller) inFlightRef.current.controller.abort()
168
286
  } catch {
169
- throw new Error('invalid JSON response')
287
+ /* ignore */
170
288
  }
171
- if (!response.ok) {
172
- setError({
173
- kind: 'http',
174
- status: response.status,
175
- message: (json && (json.error || json.code)) || 'HTTP ' + response.status,
289
+ }
290
+
291
+ const controller = typeof AbortController === 'function' ? new AbortController() : null
292
+ const headers = {}
293
+ if (force !== true && lastVersionRef.current !== null && stateRef.current !== null) {
294
+ headers['if-none-match'] = '"' + String(lastVersionRef.current) + '"'
295
+ }
296
+
297
+ const request = (async () => {
298
+ try {
299
+ const response = await fetch(API + '/state', {
300
+ cache: 'no-store',
301
+ headers,
302
+ ...(controller ? { signal: controller.signal } : null),
176
303
  })
304
+ if (!mountedRef.current) return null
305
+ if (response.status === 304) {
306
+ stopped.current = false
307
+ setError((prev) => (prev ? null : prev))
308
+ if (force === true && scheduleNextRef.current) scheduleNextRef.current()
309
+ return stateRef.current
310
+ }
311
+ if (response.status === 404) {
312
+ stopped.current = true
313
+ setError({ kind: 'not-found' })
314
+ return null
315
+ }
316
+ let json = null
317
+ try {
318
+ json = await response.json()
319
+ } catch {
320
+ throw new Error('invalid JSON response')
321
+ }
322
+ if (!mountedRef.current) return null
323
+ if (!response.ok) {
324
+ setError({
325
+ kind: 'http',
326
+ status: response.status,
327
+ message: (json && (json.error || json.code)) || 'HTTP ' + response.status,
328
+ })
329
+ return null
330
+ }
331
+ stopped.current = false
332
+ const nextTag =
333
+ json && json.stateTag !== undefined
334
+ ? json.stateTag
335
+ : json && json.stateVersion !== undefined
336
+ ? json.stateVersion
337
+ : null
338
+ if (lastVersionRef.current !== null && nextTag !== null && nextTag === lastVersionRef.current) {
339
+ setError((prev) => (prev ? null : prev))
340
+ if (force === true && scheduleNextRef.current) scheduleNextRef.current()
341
+ return stateRef.current || json
342
+ }
343
+ lastVersionRef.current = nextTag
344
+ stateRef.current = json
345
+ setState(json)
346
+ setError((prev) => (prev ? null : prev))
347
+ if (force === true && scheduleNextRef.current) scheduleNextRef.current()
348
+ return json
349
+ } catch (cause) {
350
+ if (cause && cause.name === 'AbortError') return null
351
+ if (mountedRef.current) {
352
+ setError({ kind: 'network', message: String((cause && cause.message) || cause) })
353
+ }
177
354
  return null
355
+ } finally {
356
+ if (inFlightRef.current && inFlightRef.current.controller === controller) {
357
+ inFlightRef.current = null
358
+ }
178
359
  }
179
- stopped.current = false
180
- setState(json)
181
- setError(null)
182
- return json
183
- } catch (cause) {
184
- setError({ kind: 'network', message: String((cause && cause.message) || cause) })
185
- return null
186
- }
360
+ })()
361
+
362
+ inFlightRef.current = { controller, promise: request }
363
+ return request
187
364
  }, [])
188
365
 
189
366
  React.useEffect(() => {
190
- load(true)
191
- const timer = setInterval(() => {
192
- if (!stopped.current) load(false)
193
- }, 4000)
194
- return () => clearInterval(timer)
367
+ mountedRef.current = true
368
+ const clearPoll = () => {
369
+ if (pollTimerRef.current !== null) {
370
+ clearTimeout(pollTimerRef.current)
371
+ pollTimerRef.current = null
372
+ }
373
+ }
374
+ const scheduleNext = () => {
375
+ clearPoll()
376
+ if (!mountedRef.current || stopped.current) return
377
+ const delay = isStateConverged(stateRef.current) ? IDLE_POLL_MS : FAST_POLL_MS
378
+ pollTimerRef.current = setTimeout(() => {
379
+ pollTimerRef.current = null
380
+ if (!mountedRef.current || stopped.current) return
381
+ if (typeof document !== 'undefined' && document.hidden === true) {
382
+ scheduleNext()
383
+ return
384
+ }
385
+ load(false).finally(() => {
386
+ if (mountedRef.current) scheduleNext()
387
+ })
388
+ }, delay)
389
+ }
390
+ scheduleNextRef.current = scheduleNext
391
+ const onVisibilityChange = () => {
392
+ if (typeof document !== 'undefined' && document.hidden === true) return
393
+ if (!mountedRef.current || stopped.current) return
394
+ clearPoll()
395
+ load(false).finally(() => {
396
+ if (mountedRef.current) scheduleNext()
397
+ })
398
+ }
399
+ if (typeof document !== 'undefined' && typeof document.addEventListener === 'function') {
400
+ document.addEventListener('visibilitychange', onVisibilityChange)
401
+ }
402
+ load(true).finally(() => {
403
+ if (mountedRef.current) scheduleNext()
404
+ })
405
+ return () => {
406
+ mountedRef.current = false
407
+ scheduleNextRef.current = null
408
+ clearPoll()
409
+ if (typeof document !== 'undefined' && typeof document.removeEventListener === 'function') {
410
+ document.removeEventListener('visibilitychange', onVisibilityChange)
411
+ }
412
+ if (inFlightRef.current && inFlightRef.current.controller) {
413
+ try {
414
+ inFlightRef.current.controller.abort()
415
+ } catch {
416
+ /* ignore */
417
+ }
418
+ }
419
+ inFlightRef.current = null
420
+ }
195
421
  }, [load])
196
422
 
197
423
  return {
@@ -276,7 +502,14 @@ window.__ModuleLoader__.load({
276
502
  return entry && Array.isArray(entry.models) && entry.models[0] ? entry.models[0].model : ''
277
503
  }
278
504
 
279
- const presetChoices = (rows, current, selfId, T) => {
505
+ const presetChoices = (rows, current, selfIds, T) => {
506
+ const disabledIds = new Set(
507
+ Array.isArray(selfIds)
508
+ ? selfIds
509
+ : typeof selfIds === 'string' && selfIds.length > 0
510
+ ? [selfIds]
511
+ : ['dev-plan', 'dev-plan-scout', 'dev-plan-scribe'],
512
+ )
280
513
  const choices = [
281
514
  {
282
515
  value: 'standard',
@@ -288,10 +521,10 @@ window.__ModuleLoader__.load({
288
521
  if (!row || typeof row.id !== 'string' || row.id.length === 0 || seen.has(row.id)) continue
289
522
  seen.add(row.id)
290
523
  const label = row.name && row.name !== row.id ? row.name + '(' + row.id + ')' : row.id
291
- if (row.id === selfId) {
524
+ if (disabledIds.has(row.id)) {
292
525
  choices.push({
293
526
  value: row.id,
294
- label: label + ' — ' + T('不能选自己', 'cannot use itself'),
527
+ label: label + ' — ' + T('内部预设,不能选自己', 'internal preset, cannot use itself'),
295
528
  disabled: true,
296
529
  })
297
530
  } else if (row.broken) {
@@ -373,8 +606,8 @@ window.__ModuleLoader__.load({
373
606
  'span',
374
607
  null,
375
608
  T(
376
- '设置施工方式、子代理服务商与模型,以及模型守门的范围。',
377
- 'Choose the development setup, the subagent provider and model, and how far the model guard applies.',
609
+ '设置施工方式、主窗工具权限(默认 ask-edit)、子代理服务商与模型,以及模型守门范围。',
610
+ 'Configure the development setup, main-session tool mode (default ask-edit), subagent provider/model, and model guard scope.',
378
611
  ),
379
612
  )
380
613
  }
@@ -388,10 +621,34 @@ window.__ModuleLoader__.load({
388
621
  const [dirty, setDirty] = React.useState(false)
389
622
  const [busy, setBusy] = React.useState(false)
390
623
  const [notice, setNotice] = React.useState(null)
624
+ const timersRef = React.useRef([])
625
+ const lastSyncedConfigJsonRef = React.useRef('')
626
+
627
+ React.useEffect(() => {
628
+ return () => {
629
+ for (const timerId of timersRef.current) clearTimeout(timerId)
630
+ timersRef.current = []
631
+ }
632
+ }, [])
633
+
634
+ const scheduleRefresh = React.useCallback(
635
+ (delayMs) => {
636
+ const timerId = setTimeout(() => {
637
+ timersRef.current = timersRef.current.filter((item) => item !== timerId)
638
+ refresh()
639
+ }, delayMs)
640
+ timersRef.current.push(timerId)
641
+ },
642
+ [refresh],
643
+ )
391
644
 
392
645
  const config = state && state.config ? state.config : null
393
646
  React.useEffect(() => {
394
- if (config && !dirty) setDraft({ ...config })
647
+ if (!config || dirty) return
648
+ const nextJson = JSON.stringify(config)
649
+ if (nextJson === lastSyncedConfigJsonRef.current) return
650
+ lastSyncedConfigJsonRef.current = nextJson
651
+ setDraft({ ...config })
395
652
  }, [config, dirty])
396
653
 
397
654
  const update = (patch) => {
@@ -421,8 +678,10 @@ window.__ModuleLoader__.load({
421
678
  failure.hostFormatted = true
422
679
  throw failure
423
680
  }
681
+ const nextConfig = json && json.config ? json.config : draft
682
+ lastSyncedConfigJsonRef.current = JSON.stringify(nextConfig)
424
683
  setDirty(false)
425
- setDraft(json && json.config ? json.config : draft)
684
+ setDraft(nextConfig)
426
685
  setNotice({
427
686
  kind: json && json.unchanged ? 'unchanged' : 'saved',
428
687
  text: json && json.unchanged
@@ -432,8 +691,8 @@ window.__ModuleLoader__.load({
432
691
  'Saved and applying; existing sessions keep their current settings, while new sessions use the new ones.',
433
692
  ),
434
693
  })
435
- setTimeout(refresh, 600)
436
- setTimeout(refresh, 1800)
694
+ scheduleRefresh(600)
695
+ scheduleRefresh(1800)
437
696
  } catch (cause) {
438
697
  // 保存会触发插件重建,连接可能短暂断开;重读一次若已是草稿值就按成功显示。
439
698
  let applied = false
@@ -447,6 +706,7 @@ window.__ModuleLoader__.load({
447
706
  applied = false
448
707
  }
449
708
  if (applied) {
709
+ lastSyncedConfigJsonRef.current = JSON.stringify(draft)
450
710
  setDirty(false)
451
711
  setNotice({
452
712
  kind: 'saved',
@@ -471,18 +731,36 @@ window.__ModuleLoader__.load({
471
731
  const discardAndRefresh = () => {
472
732
  if (dirty) {
473
733
  setDirty(false)
734
+ lastSyncedConfigJsonRef.current = config ? JSON.stringify(config) : ''
474
735
  setDraft(config ? { ...config } : null)
475
736
  setNotice({ kind: 'discarded', text: T('已放弃未保存的修改。', 'Unsaved changes discarded.') })
476
737
  }
477
738
  refresh()
478
739
  }
479
740
 
741
+ const resetToDefaults = () => {
742
+ setDirty(true)
743
+ setDraft({ ...RECOMMENDED_DEFAULTS })
744
+ setNotice({
745
+ kind: 'reset',
746
+ text: T(
747
+ '已恢复为推荐默认值(草稿),点“保存并应用”后生效。',
748
+ 'Recommended defaults loaded into the draft; select Save & apply to take effect.',
749
+ ),
750
+ })
751
+ }
752
+
480
753
  const mode = state ? state.effectiveMode : null
481
754
  const modeName = state && state.modeName ? state.modeName : mode
482
755
  const fallback = Boolean(state && state.fallback && state.fallback.active)
483
756
  const presetsState = state && state.presets ? state.presets : null
484
757
  const presetRows = presetsState && Array.isArray(presetsState.rows) ? presetsState.rows : []
485
758
  const selfId = (presetsState && presetsState.selfId) || 'dev-plan'
759
+ const disabledIds =
760
+ presetsState && Array.isArray(presetsState.disabledIds)
761
+ ? presetsState.disabledIds
762
+ : [selfId, 'dev-plan-scout', 'dev-plan-scribe']
763
+ const internalPresets = state && state.internalPresets ? state.internalPresets : null
486
764
  const modelCatalog = state && state.modelCatalog ? state.modelCatalog : null
487
765
  const providers = modelCatalog && Array.isArray(modelCatalog.providers) ? modelCatalog.providers : []
488
766
  const catalogFailures = modelCatalog && Array.isArray(modelCatalog.failures) ? modelCatalog.failures : []
@@ -499,6 +777,20 @@ window.__ModuleLoader__.load({
499
777
  const modelId = draft ? draft.childModel : route ? route.model : ''
500
778
  const modelKnown = models.some((entry) => entry && entry.model === modelId)
501
779
 
780
+ const draftDevelopMode = draft ? draft.developMode : ''
781
+ const memoPresetChoices = React.useMemo(
782
+ () => presetChoices(presetRows, draftDevelopMode, disabledIds, T),
783
+ [presetRows, draftDevelopMode, disabledIds, isZh],
784
+ )
785
+ const memoProviderChoices = React.useMemo(
786
+ () => providerChoices(providers, providerId, T),
787
+ [providers, providerId, isZh],
788
+ )
789
+ const memoModelChoices = React.useMemo(
790
+ () => modelChoices(models, modelId, T),
791
+ [models, modelId, isZh],
792
+ )
793
+
502
794
  const changeProvider = (nextProvider) => {
503
795
  const firstModel = firstModelOf(providers, nextProvider)
504
796
  update(
@@ -646,6 +938,43 @@ window.__ModuleLoader__.load({
646
938
  )
647
939
  : ''
648
940
 
941
+ const activeMainToolMode =
942
+ draft && draft.mainToolMode
943
+ ? draft.mainToolMode
944
+ : config && config.mainToolMode
945
+ ? config.mainToolMode
946
+ : 'ask-edit'
947
+ const effectiveMainToolMode = config && config.mainToolMode ? config.mainToolMode : 'ask-edit'
948
+ const mainToolModeCards = [
949
+ {
950
+ value: 'ask-edit',
951
+ title: 'ask-edit',
952
+ badge: T('默认推荐', 'Default'),
953
+ desc: T(
954
+ '允许小范围只读核验(read/glob/grep ≤ 3 文件);任何 write/edit 必须先获你当轮明确同意且限局部微改(≤ 2 文件 / ≤ 50 行);永不挂 Shell。',
955
+ 'Allows small read-only checks (read/glob/grep ≤ 3 files) and local edits (≤ 2 files / ≤ 50 lines) only after your explicit approval in that turn; never mounts Shell.',
956
+ ),
957
+ },
958
+ {
959
+ value: 'readonly',
960
+ title: 'readonly',
961
+ badge: T('仅检索', 'Read-only'),
962
+ desc: T(
963
+ '仅开放小范围只读检索(glob/grep)用于快速定位文件或符号,完全不能改文件或跑命令;大仓库遍历与全部修改仍交子代理。',
964
+ 'Opens small read-only search (glob/grep) for quick file or symbol lookup; cannot edit files or run commands. Full scans and edits stay with subagents.',
965
+ ),
966
+ },
967
+ {
968
+ value: 'none',
969
+ title: 'none',
970
+ badge: T('最省额度', 'Lowest quota'),
971
+ desc: T(
972
+ '主窗零实操工具,只做规划、派工与复核;全部读写、检索、文档与施工均交给便宜模型子代理,最省昂贵主模型额度。',
973
+ 'No direct tools in the main window — planning, delegation, and review only. All reads, searches, edits, and commands run on cheaper subagents.',
974
+ ),
975
+ },
976
+ ]
977
+
649
978
  return h(
650
979
  'div',
651
980
  { style: styles.root },
@@ -655,17 +984,61 @@ window.__ModuleLoader__.load({
655
984
  { style: styles.head },
656
985
  h('span', { style: styles.dot(phase) }),
657
986
  h('span', { style: styles.title }, T('开发规划与交付 · 施工设置', 'Development planning & delivery · development settings')),
987
+ state && state.version ? h('span', { style: styles.badge }, 'v' + String(state.version)) : null,
658
988
  h('span', { style: styles.status, role: 'status', 'aria-live': 'polite' }, statusText),
659
989
  ),
660
990
  h(
661
991
  'div',
662
992
  { style: styles.hint },
663
993
  T(
664
- '主窗口只做规划、派工与复核,永不亲自写代码;develop 子代理负责施工并直接向主窗口汇报。',
665
- 'The main window only plans, dispatches, and reviews; it never writes code. The develop subagent implements and reports back directly.',
994
+ '主窗口负责规划、派工、复核与受控微实操(永不跑 Shell);实际施工、测试与大范围查证由便宜模型子代理完成并直接汇报。',
995
+ 'The main window handles planning, delegation, review, and controlled micro-actions (never Shell); full implementation, tests, and broad inspection run on cheaper subagents.',
666
996
  ),
667
997
  ),
668
998
 
999
+ state
1000
+ ? h(
1001
+ 'div',
1002
+ { style: styles.summaryBar },
1003
+ h(
1004
+ 'div',
1005
+ { style: styles.summaryItem },
1006
+ h('span', { style: styles.summaryKey }, T('施工方式', 'Setup')),
1007
+ h('span', { style: styles.mono }, modeName || mode || 'standard'),
1008
+ ),
1009
+ h(
1010
+ 'div',
1011
+ { style: styles.summaryItem },
1012
+ h('span', { style: styles.summaryKey }, T('主窗权限', 'Main tools')),
1013
+ h('span', { style: styles.mono }, effectiveMainToolMode),
1014
+ ),
1015
+ route
1016
+ ? h(
1017
+ 'div',
1018
+ { style: styles.summaryItem },
1019
+ h('span', { style: styles.summaryKey }, T('子代理模型', 'Subagent')),
1020
+ h(
1021
+ 'span',
1022
+ { style: styles.mono },
1023
+ route.provider + '/' + route.model + (route.reasoningEffort ? '/' + route.reasoningEffort : ''),
1024
+ ),
1025
+ )
1026
+ : null,
1027
+ config
1028
+ ? h(
1029
+ 'div',
1030
+ { style: styles.summaryItem },
1031
+ h('span', { style: styles.summaryKey }, T('模型守门', 'Guard')),
1032
+ h(
1033
+ 'span',
1034
+ { style: styles.mono },
1035
+ config.modelGuardMode + (config.guardAllSubagents ? ' · all' : ' · dev-plan'),
1036
+ ),
1037
+ )
1038
+ : null,
1039
+ )
1040
+ : null,
1041
+
669
1042
  readErrorText
670
1043
  ? h(
671
1044
  'div',
@@ -707,10 +1080,15 @@ window.__ModuleLoader__.load({
707
1080
  ? h(
708
1081
  'div',
709
1082
  { style: styles.hint },
710
- T(
711
- '只有 develop 使用“' + (modeName || mode) + '”;recon / review / scribe 仍为 standard。',
712
- 'Only develop uses “' + (modeName || mode) + '”; recon / review / scribe stay on standard.',
713
- ),
1083
+ internalPresets && internalPresets.scout && internalPresets.scribe
1084
+ ? T(
1085
+ '只有 develop 使用“' + (modeName || mode) + '”;recon / review 使用轻量只读子预设,scribe 使用轻量文书子预设。',
1086
+ 'Only develop uses “' + (modeName || mode) + '”; recon / review use the lightweight read-only preset, and scribe uses the lightweight scribe preset.',
1087
+ )
1088
+ : T(
1089
+ '只有 develop 使用“' + (modeName || mode) + '”;recon / review / scribe 仍为 standard。',
1090
+ 'Only develop uses “' + (modeName || mode) + '”; recon / review / scribe stay on standard.',
1091
+ ),
714
1092
  )
715
1093
  : null,
716
1094
 
@@ -739,7 +1117,7 @@ window.__ModuleLoader__.load({
739
1117
  disabled: busy,
740
1118
  onChange: (event) => update({ developMode: event.target.value }),
741
1119
  },
742
- renderChoices(presetChoices(presetRows, draft.developMode, selfId, T)),
1120
+ renderChoices(memoPresetChoices),
743
1121
  ),
744
1122
  ),
745
1123
  presetCatalogText
@@ -767,7 +1145,7 @@ window.__ModuleLoader__.load({
767
1145
  disabled: busy || providers.length === 0,
768
1146
  onChange: (event) => changeProvider(event.target.value),
769
1147
  },
770
- renderChoices(providerChoices(providers, providerId, T)),
1148
+ renderChoices(memoProviderChoices),
771
1149
  ),
772
1150
  ),
773
1151
  h(
@@ -786,7 +1164,7 @@ window.__ModuleLoader__.load({
786
1164
  disabled: busy || models.length === 0,
787
1165
  onChange: (event) => update({ childModel: event.target.value }),
788
1166
  },
789
- renderChoices(modelChoices(models, modelId, T)),
1167
+ renderChoices(memoModelChoices),
790
1168
  ),
791
1169
  ),
792
1170
  ),
@@ -840,7 +1218,134 @@ window.__ModuleLoader__.load({
840
1218
  h(
841
1219
  'fieldset',
842
1220
  { style: { ...styles.card, margin: 0, minWidth: 0 } },
843
- h('legend', { style: styles.legend }, T('模型守门', 'Model guard')),
1221
+ h('legend', { style: styles.legend }, T('主窗工具权限与额度提醒', 'Main session tool permissions & quota reminder')),
1222
+ h(
1223
+ 'div',
1224
+ { style: styles.hint },
1225
+ T(
1226
+ '控制昂贵主模型在主窗可直接使用的工具范围;Shell、测试与大改动始终留给便宜模型的 develop 子代理。',
1227
+ 'Controls what tools the expensive main model may use directly; Shell, tests, and larger edits always stay with the develop subagent.',
1228
+ ),
1229
+ ),
1230
+ draft
1231
+ ? h(
1232
+ React.Fragment,
1233
+ null,
1234
+ h(
1235
+ 'div',
1236
+ { style: styles.modeGrid },
1237
+ mainToolModeCards.map((item) => {
1238
+ const selected = activeMainToolMode === item.value
1239
+ return h(
1240
+ 'button',
1241
+ {
1242
+ key: item.value,
1243
+ type: 'button',
1244
+ disabled: busy,
1245
+ 'aria-pressed': selected,
1246
+ title: T('点击切换到 ', 'Select mode: ') + item.value,
1247
+ style: {
1248
+ ...styles.modeCard,
1249
+ ...(selected ? styles.modeCardActive : null),
1250
+ ...(busy ? styles.buttonDisabled : null),
1251
+ },
1252
+ onClick: () => update({ mainToolMode: item.value }),
1253
+ },
1254
+ h(
1255
+ 'div',
1256
+ { style: styles.modeCardHead },
1257
+ h('span', { style: styles.mono }, item.title),
1258
+ h(
1259
+ 'span',
1260
+ { style: styles.badge },
1261
+ selected ? T('当前 · ', 'Active · ') + item.badge : item.badge,
1262
+ ),
1263
+ ),
1264
+ h('div', { style: styles.modeCardDesc }, item.desc),
1265
+ )
1266
+ }),
1267
+ ),
1268
+ h(
1269
+ 'div',
1270
+ { style: styles.row },
1271
+ h(
1272
+ Field,
1273
+ {
1274
+ id: 'dev-plan-presets-main-tool-mode',
1275
+ label: T('主窗工具权限', 'Main session tools'),
1276
+ hint: T(
1277
+ '默认 ask-edit(上方三张卡片可直接点击切换);保存后对新建会话生效。',
1278
+ 'Defaults to ask-edit (you can also select any mode card above); applies to new sessions after saving.',
1279
+ ),
1280
+ },
1281
+ h(
1282
+ 'select',
1283
+ {
1284
+ name: 'mainToolMode',
1285
+ style: { ...styles.control, ...(busy ? styles.controlDisabled : null) },
1286
+ value: draft.mainToolMode || 'ask-edit',
1287
+ disabled: busy,
1288
+ onChange: (event) => update({ mainToolMode: event.target.value }),
1289
+ },
1290
+ h(
1291
+ 'option',
1292
+ { value: 'ask-edit' },
1293
+ 'ask-edit — ' + T('授权微实操(默认推荐:小范围只读 + 同意后微改,无 Shell)', 'Approved micro-edits (default: small read-only + approved edits, no Shell)'),
1294
+ ),
1295
+ h(
1296
+ 'option',
1297
+ { value: 'readonly' },
1298
+ 'readonly — ' + T('仅只读检索(小范围 glob/grep,不可改文件)', 'Read-only search (small glob/grep, no edits)'),
1299
+ ),
1300
+ h(
1301
+ 'option',
1302
+ { value: 'none' },
1303
+ 'none — ' + T('纯规划派工(零实操工具,最省主模型额度)', 'Plan & delegate only (no direct tools, lowest main quota)'),
1304
+ ),
1305
+ ),
1306
+ ),
1307
+ h(
1308
+ Field,
1309
+ {
1310
+ id: 'dev-plan-presets-main-step-warn',
1311
+ label: T('主窗连续步数提醒阈值(2–30 步)', 'Main step warning threshold (2–30)'),
1312
+ hint: T(
1313
+ '仅在非 none 模式下生效;超过阈值仅提示转交子代理,绝不强制中断或改换主模型。',
1314
+ 'Active when mode is not none; exceeding this threshold only suggests handing off to a subagent and never interrupts or changes the main model.',
1315
+ ),
1316
+ },
1317
+ h('input', {
1318
+ type: 'number',
1319
+ name: 'mainStepWarnThreshold',
1320
+ min: 2,
1321
+ max: 30,
1322
+ step: 1,
1323
+ style: {
1324
+ ...styles.control,
1325
+ ...(busy || (draft.mainToolMode || 'ask-edit') === 'none' ? styles.controlDisabled : null),
1326
+ },
1327
+ value: draft.mainStepWarnThreshold === undefined ? 6 : draft.mainStepWarnThreshold,
1328
+ disabled: busy || (draft.mainToolMode || 'ask-edit') === 'none',
1329
+ onChange: (event) => {
1330
+ const raw = String(event.target.value || '').trim()
1331
+ if (raw === '') {
1332
+ update({ mainStepWarnThreshold: '' })
1333
+ return
1334
+ }
1335
+ const num = Number(raw)
1336
+ update({ mainStepWarnThreshold: Number.isFinite(num) ? num : raw })
1337
+ },
1338
+ }),
1339
+ ),
1340
+ ),
1341
+ )
1342
+ : h('div', { style: styles.hint }, T('加载中…', 'Loading…')),
1343
+ ),
1344
+
1345
+ h(
1346
+ 'fieldset',
1347
+ { style: { ...styles.card, margin: 0, minWidth: 0 } },
1348
+ h('legend', { style: styles.legend }, T('子代理模型守门', 'Subagent model guard')),
844
1349
  h(
845
1350
  'div',
846
1351
  { style: styles.hint },
@@ -855,6 +1360,7 @@ window.__ModuleLoader__.load({
855
1360
  {
856
1361
  id: 'dev-plan-presets-guard-mode',
857
1362
  label: T('守门方式', 'Guard behavior'),
1363
+ hint: guardHint,
858
1364
  },
859
1365
  h(
860
1366
  'select',
@@ -870,7 +1376,6 @@ window.__ModuleLoader__.load({
870
1376
  h('option', { value: 'off' }, 'off — ' + T('不管理模型', 'no model management')),
871
1377
  ),
872
1378
  ),
873
- h('div', { style: styles.hint }, guardHint),
874
1379
  h(
875
1380
  'div',
876
1381
  { style: styles.row },
@@ -901,8 +1406,9 @@ window.__ModuleLoader__.load({
901
1406
  { style: styles.row },
902
1407
  h(
903
1408
  'label',
904
- { style: styles.check },
1409
+ { style: styles.check, htmlFor: 'dev-plan-presets-kill-violation' },
905
1410
  h('input', {
1411
+ id: 'dev-plan-presets-kill-violation',
906
1412
  type: 'checkbox',
907
1413
  name: 'killOnViolation',
908
1414
  checked: Boolean(draft.killOnViolation),
@@ -913,8 +1419,9 @@ window.__ModuleLoader__.load({
913
1419
  ),
914
1420
  h(
915
1421
  'label',
916
- { style: styles.check },
1422
+ { style: styles.check, htmlFor: 'dev-plan-presets-honor-explicit' },
917
1423
  h('input', {
1424
+ id: 'dev-plan-presets-honor-explicit',
918
1425
  type: 'checkbox',
919
1426
  name: 'honorExplicit',
920
1427
  checked: Boolean(draft.honorExplicit),
@@ -925,8 +1432,9 @@ window.__ModuleLoader__.load({
925
1432
  ),
926
1433
  h(
927
1434
  'label',
928
- { style: styles.check },
1435
+ { style: styles.check, htmlFor: 'dev-plan-presets-audit' },
929
1436
  h('input', {
1437
+ id: 'dev-plan-presets-audit',
930
1438
  type: 'checkbox',
931
1439
  name: 'audit',
932
1440
  checked: Boolean(draft.audit),
@@ -950,41 +1458,64 @@ window.__ModuleLoader__.load({
950
1458
 
951
1459
  h(
952
1460
  'div',
953
- { style: styles.row },
1461
+ { style: { ...styles.actionBar, ...(dirty ? styles.actionBarDirty : null) } },
954
1462
  h(
955
- 'button',
956
- {
957
- type: 'button',
958
- style: {
959
- ...styles.primary,
960
- ...(busy || !draft || !dirty ? styles.buttonDisabled : null),
1463
+ 'div',
1464
+ { style: styles.actionRow },
1465
+ h(
1466
+ 'button',
1467
+ {
1468
+ type: 'button',
1469
+ style: {
1470
+ ...styles.primary,
1471
+ ...(busy || !draft || !dirty ? styles.buttonDisabled : null),
1472
+ },
1473
+ disabled: busy || !draft || !dirty,
1474
+ 'aria-busy': busy,
1475
+ 'aria-disabled': busy || !draft || !dirty,
1476
+ title: !dirty
1477
+ ? T('当前没有未保存的修改', 'No unsaved changes')
1478
+ : T('写入配置并重载插件,新会话生效', 'Save configuration and reload the plugin for new sessions'),
1479
+ onClick: save,
961
1480
  },
962
- disabled: busy || !draft || !dirty,
963
- 'aria-busy': busy,
964
- 'aria-disabled': busy || !draft || !dirty,
965
- title: !dirty ? T('没有未保存的修改', 'No unsaved changes') : undefined,
966
- onClick: save,
967
- },
968
- busy ? T('保存中…', 'Saving…') : T('保存', 'Save'),
969
- ),
970
- h(
971
- 'button',
972
- {
973
- type: 'button',
974
- style: { ...styles.button, ...(busy ? styles.buttonDisabled : null) },
975
- disabled: busy,
976
- onClick: discardAndRefresh,
977
- },
978
- dirty ? T('放弃修改并刷新', 'Discard changes and refresh') : T('刷新', 'Refresh'),
979
- ),
980
- h(
981
- 'span',
982
- { style: styles.status, role: 'status', 'aria-live': 'polite' },
983
- saveStateText,
1481
+ busy ? T('保存中…', 'Saving…') : T('保存并应用', 'Save & apply'),
1482
+ ),
1483
+ h(
1484
+ 'button',
1485
+ {
1486
+ type: 'button',
1487
+ style: { ...styles.button, ...(busy ? styles.buttonDisabled : null) },
1488
+ disabled: busy,
1489
+ title: dirty
1490
+ ? T('放弃未保存草稿,重新从 Host 读取已生效配置', 'Discard unsaved draft and reload the active config from Host')
1491
+ : T('立即重新拉取预设目录、模型目录与最新运行状态', 'Reload presets, model catalog, and runtime state from Host'),
1492
+ onClick: discardAndRefresh,
1493
+ },
1494
+ dirty ? T('放弃修改并刷新', 'Discard changes and refresh') : T('刷新状态', 'Refresh state'),
1495
+ ),
1496
+ h(
1497
+ 'button',
1498
+ {
1499
+ type: 'button',
1500
+ style: { ...styles.button, ...(busy || !draft ? styles.buttonDisabled : null) },
1501
+ disabled: busy || !draft,
1502
+ title: T(
1503
+ '将表单填回推荐默认值(standard + ask-edit + pin),需点“保存并应用”才会落盘',
1504
+ 'Fill recommended defaults (standard + ask-edit + pin) into the draft; select Save & apply to persist',
1505
+ ),
1506
+ onClick: resetToDefaults,
1507
+ },
1508
+ T('恢复默认', 'Reset defaults'),
1509
+ ),
1510
+ h(
1511
+ 'span',
1512
+ { style: styles.badge, role: 'status', 'aria-live': 'polite' },
1513
+ saveStateText,
1514
+ ),
984
1515
  ),
985
1516
  notice
986
1517
  ? h(
987
- 'span',
1518
+ 'div',
988
1519
  {
989
1520
  style: notice.kind === 'error' ? styles.noticeError : styles.noticeOk,
990
1521
  role: notice.kind === 'error' ? 'alert' : 'status',
@@ -993,17 +1524,18 @@ window.__ModuleLoader__.load({
993
1524
  notice.text,
994
1525
  )
995
1526
  : null,
996
- ),
997
-
998
- h(
999
- 'div',
1000
- { style: styles.hint },
1001
- T(
1002
- '保存后插件会重新加载;现有会话继续使用当前设置,新建会话才会使用新设置。',
1003
- 'Saving reloads the plugin; existing sessions keep their current settings, and new sessions use the new ones.',
1527
+ h(
1528
+ 'div',
1529
+ { style: styles.hint },
1530
+ T(
1531
+ '按键说明:保存并应用 = 落盘并重载插件(现有会话保持旧设置,新建会话生效);刷新状态 = 拉取最新预设与模型目录;恢复默认 = 仅填回推荐草稿,保存前不会修改配置。',
1532
+ 'Buttons: Save & apply writes settings and reloads the plugin (new sessions use new settings); Refresh state reloads host catalogs; Reset defaults fills recommended values into the draft without saving yet.',
1533
+ ),
1004
1534
  ),
1005
1535
  ),
1006
1536
 
1537
+ h('div', { style: styles.sectionCaption }, T('运行状态与诊断', 'Runtime status & diagnostics')),
1538
+
1007
1539
  preset
1008
1540
  ? h(
1009
1541
  'div',
@@ -1081,7 +1613,13 @@ window.__ModuleLoader__.load({
1081
1613
  }
1082
1614
  // 仅测试开关打开时暴露纯选择函数;生产模块对象不变。
1083
1615
  if (globalThis.__DSH_DEV_PLAN_PRESETS_TEST__ === true) {
1084
- exportedModule.__test = { presetChoices, providerChoices, modelChoices, firstModelOf }
1616
+ exportedModule.__test = {
1617
+ presetChoices,
1618
+ providerChoices,
1619
+ modelChoices,
1620
+ firstModelOf,
1621
+ isStateConverged,
1622
+ }
1085
1623
  }
1086
1624
  return exportedModule
1087
1625
  } catch (error) {