dsh-dev-plan-presets 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +348 -2
- package/client.js +1634 -0
- package/cordis.patch.yml +24 -0
- package/detail.md +200 -0
- package/docs/flow-redesign.md +403 -0
- package/docs/v0.4-perf-optimization-plan.md +349 -0
- package/guard.js +547 -0
- package/icon.svg +12 -0
- package/index.js +791 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +53 -4
- package/preset.js +471 -0
- package/scripts/test-harness.mjs +290 -0
- package/scripts/verify-presets.mjs +1854 -0
- package/settings.js +208 -0
- package/test/plugin.test.mjs +1912 -0
package/client.js
ADDED
|
@@ -0,0 +1,1634 @@
|
|
|
1
|
+
// dsh-dev-plan-presets — Client module: the settings page for this plugin row.
|
|
2
|
+
// Registers into `plugins.row.config` keyed by "<package>#<rowId>". The page
|
|
3
|
+
// reads the Host state route, saves through the Host config route (which
|
|
4
|
+
// validates and writes back to the profile patch), and follows the host locale.
|
|
5
|
+
// Colours/radii use only the verified --dsw-alias-* / --dsw-radius-* tokens.
|
|
6
|
+
window.__ModuleLoader__.load({
|
|
7
|
+
id: 'dsh-dev-plan-presets',
|
|
8
|
+
factory(require) {
|
|
9
|
+
try {
|
|
10
|
+
const React = require('react')
|
|
11
|
+
const h = React.createElement
|
|
12
|
+
const API = '/plugins/dev-plan-presets'
|
|
13
|
+
|
|
14
|
+
const styles = {
|
|
15
|
+
root: {
|
|
16
|
+
display: 'flex',
|
|
17
|
+
flexDirection: 'column',
|
|
18
|
+
gap: 14,
|
|
19
|
+
padding: '4px 0 12px',
|
|
20
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
21
|
+
},
|
|
22
|
+
card: {
|
|
23
|
+
border: '1px solid var(--dsw-alias-border-l2)',
|
|
24
|
+
borderRadius: 'var(--dsw-radius-sm)',
|
|
25
|
+
padding: '12px 14px',
|
|
26
|
+
display: 'flex',
|
|
27
|
+
flexDirection: 'column',
|
|
28
|
+
gap: 10,
|
|
29
|
+
background: 'var(--dsw-alias-card-fill)',
|
|
30
|
+
},
|
|
31
|
+
head: { display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' },
|
|
32
|
+
legend: {
|
|
33
|
+
fontSize: 13,
|
|
34
|
+
fontWeight: 600,
|
|
35
|
+
padding: '0 4px',
|
|
36
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
37
|
+
},
|
|
38
|
+
title: { fontSize: 13, fontWeight: 600, color: 'var(--dsw-alias-label-primary)' },
|
|
39
|
+
hint: { fontSize: 12, color: 'var(--dsw-alias-label-tertiary)', lineHeight: 1.55 },
|
|
40
|
+
status: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)', lineHeight: 1.5 },
|
|
41
|
+
row: { display: 'flex', gap: 10, alignItems: 'center', flexWrap: 'wrap' },
|
|
42
|
+
field: { display: 'flex', flexDirection: 'column', gap: 4, minWidth: 168, flex: '1 1 168px' },
|
|
43
|
+
label: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)' },
|
|
44
|
+
control: {
|
|
45
|
+
padding: '4px 7px',
|
|
46
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
47
|
+
background: 'var(--dsw-alias-bg-layer-1)',
|
|
48
|
+
border: '1px solid var(--dsw-alias-border-l3)',
|
|
49
|
+
borderRadius: 'var(--dsw-radius-xs)',
|
|
50
|
+
font: 'inherit',
|
|
51
|
+
fontSize: 12,
|
|
52
|
+
width: '100%',
|
|
53
|
+
boxSizing: 'border-box',
|
|
54
|
+
},
|
|
55
|
+
controlDisabled: { opacity: 0.55, cursor: 'not-allowed' },
|
|
56
|
+
check: { display: 'flex', gap: 7, alignItems: 'center', fontSize: 12, color: 'var(--dsw-alias-label-secondary)' },
|
|
57
|
+
button: {
|
|
58
|
+
padding: '4px 14px',
|
|
59
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
60
|
+
background: 'var(--dsw-alias-bg-layer-2)',
|
|
61
|
+
border: '1px solid var(--dsw-alias-border-l3)',
|
|
62
|
+
borderRadius: 'var(--dsw-radius-xs)',
|
|
63
|
+
cursor: 'pointer',
|
|
64
|
+
font: 'inherit',
|
|
65
|
+
fontSize: 12,
|
|
66
|
+
},
|
|
67
|
+
primary: {
|
|
68
|
+
padding: '4px 14px',
|
|
69
|
+
color: 'var(--dsw-alias-label-on-color)',
|
|
70
|
+
background: 'var(--dsw-alias-button-primary-fill)',
|
|
71
|
+
border: '1px solid var(--dsw-alias-button-primary-fill)',
|
|
72
|
+
borderRadius: 'var(--dsw-radius-xs)',
|
|
73
|
+
cursor: 'pointer',
|
|
74
|
+
font: 'inherit',
|
|
75
|
+
fontSize: 12,
|
|
76
|
+
},
|
|
77
|
+
buttonDisabled: { opacity: 0.55, cursor: 'not-allowed' },
|
|
78
|
+
banner: {
|
|
79
|
+
border: '1px solid var(--dsw-alias-border-l2)',
|
|
80
|
+
borderLeft: '3px solid var(--dsw-alias-state-warn-primary)',
|
|
81
|
+
background: 'var(--dsw-alias-state-warn-tertiary)',
|
|
82
|
+
borderRadius: 'var(--dsw-radius-sm)',
|
|
83
|
+
padding: '8px 10px',
|
|
84
|
+
fontSize: 12,
|
|
85
|
+
lineHeight: 1.55,
|
|
86
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
87
|
+
},
|
|
88
|
+
errorBox: {
|
|
89
|
+
border: '1px solid var(--dsw-alias-state-error-primary)',
|
|
90
|
+
background: 'var(--dsw-alias-bg-layer-2)',
|
|
91
|
+
borderRadius: 'var(--dsw-radius-sm)',
|
|
92
|
+
padding: '8px 10px',
|
|
93
|
+
fontSize: 12,
|
|
94
|
+
lineHeight: 1.55,
|
|
95
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
96
|
+
},
|
|
97
|
+
mono: {
|
|
98
|
+
fontFamily: 'var(--ds-font-family-code)',
|
|
99
|
+
fontSize: 12,
|
|
100
|
+
color: 'var(--dsw-alias-label-secondary)',
|
|
101
|
+
overflowWrap: 'anywhere',
|
|
102
|
+
wordBreak: 'break-word',
|
|
103
|
+
},
|
|
104
|
+
dot: (kind) => ({
|
|
105
|
+
width: 8,
|
|
106
|
+
height: 8,
|
|
107
|
+
borderRadius: 'var(--dsw-radius-xs)',
|
|
108
|
+
background:
|
|
109
|
+
kind === 'error'
|
|
110
|
+
? 'var(--dsw-alias-state-error-primary)'
|
|
111
|
+
: kind === 'ready'
|
|
112
|
+
? 'var(--dsw-alias-state-success-primary)'
|
|
113
|
+
: 'var(--dsw-alias-state-idle-primary)',
|
|
114
|
+
display: 'inline-block',
|
|
115
|
+
flex: '0 0 auto',
|
|
116
|
+
}),
|
|
117
|
+
noticeOk: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)', lineHeight: 1.5 },
|
|
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,
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const FIELD_LABELS = {
|
|
224
|
+
developMode: ['施工方式', 'Development setup'],
|
|
225
|
+
modelGuardMode: ['守门方式', 'Guard behavior'],
|
|
226
|
+
childProvider: ['子代理服务商', 'Subagent provider'],
|
|
227
|
+
childModel: ['子代理模型', 'Subagent model'],
|
|
228
|
+
childReasoningEffort: ['推理强度', 'Reasoning effort'],
|
|
229
|
+
killOnViolation: ['越界时立即停止', 'Stop on violation'],
|
|
230
|
+
honorExplicit: ['尊重子代理自己选的模型', 'Honor an explicit child model'],
|
|
231
|
+
audit: ['记录详细日志', 'Write detailed logs'],
|
|
232
|
+
guardAllSubagents: ['同时管理其他插件的子代理', 'Also govern subagents from other plugins'],
|
|
233
|
+
mainToolMode: ['主窗工具权限', 'Main session tools'],
|
|
234
|
+
mainStepWarnThreshold: ['主窗连续步数提醒阈值', 'Main step warning threshold'],
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function useActiveLocale(locale) {
|
|
238
|
+
const read = () => {
|
|
239
|
+
try {
|
|
240
|
+
return String(locale?.getSnapshot?.().active ?? 'en')
|
|
241
|
+
} catch {
|
|
242
|
+
return 'en'
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const [active, setActive] = React.useState(read)
|
|
246
|
+
React.useEffect(() => {
|
|
247
|
+
if (typeof locale?.subscribe !== 'function') return undefined
|
|
248
|
+
const sync = () => setActive(read())
|
|
249
|
+
sync()
|
|
250
|
+
return locale.subscribe(sync)
|
|
251
|
+
}, [locale])
|
|
252
|
+
return active
|
|
253
|
+
}
|
|
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
|
+
|
|
269
|
+
function useHostState() {
|
|
270
|
+
const [state, setState] = React.useState(null)
|
|
271
|
+
const [error, setError] = React.useState(null)
|
|
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)
|
|
279
|
+
|
|
280
|
+
const load = React.useCallback(async (force = false) => {
|
|
281
|
+
if (stopped.current && force !== true) return null
|
|
282
|
+
if (inFlightRef.current) {
|
|
283
|
+
if (force !== true) return inFlightRef.current.promise
|
|
284
|
+
try {
|
|
285
|
+
if (inFlightRef.current.controller) inFlightRef.current.controller.abort()
|
|
286
|
+
} catch {
|
|
287
|
+
/* ignore */
|
|
288
|
+
}
|
|
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),
|
|
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
|
+
}
|
|
354
|
+
return null
|
|
355
|
+
} finally {
|
|
356
|
+
if (inFlightRef.current && inFlightRef.current.controller === controller) {
|
|
357
|
+
inFlightRef.current = null
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
})()
|
|
361
|
+
|
|
362
|
+
inFlightRef.current = { controller, promise: request }
|
|
363
|
+
return request
|
|
364
|
+
}, [])
|
|
365
|
+
|
|
366
|
+
React.useEffect(() => {
|
|
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
|
+
}
|
|
421
|
+
}, [load])
|
|
422
|
+
|
|
423
|
+
return {
|
|
424
|
+
state,
|
|
425
|
+
error,
|
|
426
|
+
stopped: stopped.current,
|
|
427
|
+
refresh: () => load(true),
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function fieldLabel(path, T) {
|
|
432
|
+
const key = Array.isArray(path) && path.length > 0 ? String(path[0]) : ''
|
|
433
|
+
const pair = FIELD_LABELS[key]
|
|
434
|
+
if (pair) return T(pair[0], pair[1])
|
|
435
|
+
return key || T('配置字段', 'configuration field')
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function formatHostError(body, status, T) {
|
|
439
|
+
const code = body && body.code
|
|
440
|
+
if (code === 'invalid-config') {
|
|
441
|
+
const issues = Array.isArray(body.issues) ? body.issues : []
|
|
442
|
+
if (issues.length === 0) return T('配置校验失败。', 'Configuration validation failed.')
|
|
443
|
+
const parts = issues.map((issue) => {
|
|
444
|
+
const key = Array.isArray(issue.path) && issue.path.length > 0 ? String(issue.path[0]) : ''
|
|
445
|
+
return FIELD_LABELS[key]
|
|
446
|
+
? fieldLabel(issue.path, T) + ': ' + T('取值不合法', 'invalid value')
|
|
447
|
+
: String(issue.message || issue)
|
|
448
|
+
})
|
|
449
|
+
return T('配置校验失败:', 'Configuration validation failed: ') + parts.join(';')
|
|
450
|
+
}
|
|
451
|
+
if (code === 'config-editor-unavailable') {
|
|
452
|
+
return T(
|
|
453
|
+
'当前环境不允许从页面保存。请到插件管理里修改这一行配置。',
|
|
454
|
+
'This environment does not allow saving from this page. Edit this plugin row in plugin management instead.',
|
|
455
|
+
)
|
|
456
|
+
}
|
|
457
|
+
if (code === 'unsupported-media-type') {
|
|
458
|
+
return T('保存请求格式不被接受(需要 application/json)。', 'The save request was rejected (application/json required).')
|
|
459
|
+
}
|
|
460
|
+
if (code === 'forbidden-origin') {
|
|
461
|
+
return T('保存请求被拒绝:来源校验未通过,请从 DSH 页面重试。', 'The save request was rejected by the origin check; retry from the DSH page.')
|
|
462
|
+
}
|
|
463
|
+
if (code === 'invalid-json' || code === 'invalid-body') {
|
|
464
|
+
return T('保存请求内容不是合法的配置对象。', 'The save request was not a valid configuration object.')
|
|
465
|
+
}
|
|
466
|
+
if (code === 'body-too-large') {
|
|
467
|
+
return T('保存请求过大。', 'The save request was too large.')
|
|
468
|
+
}
|
|
469
|
+
if (code === 'method-not-allowed') {
|
|
470
|
+
return T('保存请求方法不被接受。', 'The save request method was rejected.')
|
|
471
|
+
}
|
|
472
|
+
return (body && body.error) || 'HTTP ' + status
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function Field(props) {
|
|
476
|
+
const id = props.id
|
|
477
|
+
const hintId = props.hint && id ? id + '-hint' : undefined
|
|
478
|
+
const child = React.cloneElement(props.children, {
|
|
479
|
+
id,
|
|
480
|
+
...(hintId ? { 'aria-describedby': hintId } : null),
|
|
481
|
+
})
|
|
482
|
+
return h(
|
|
483
|
+
'div',
|
|
484
|
+
{ style: styles.field },
|
|
485
|
+
h('label', { htmlFor: id, style: styles.label }, props.label),
|
|
486
|
+
child,
|
|
487
|
+
hintId ? h('span', { id: hintId, style: styles.hint }, props.hint) : null,
|
|
488
|
+
)
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function phaseOf(state, error) {
|
|
492
|
+
if (error || (state && (state.error || state.registration === 'failed'))) return 'error'
|
|
493
|
+
if (!state || state.registration === 'pending' || state.registration === 'switching') return 'loading'
|
|
494
|
+
return 'ready'
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** 纯选择项构造:不依赖 React,供组件与行为测试共用。 */
|
|
498
|
+
const firstModelOf = (providers, providerId) => {
|
|
499
|
+
const entry = (Array.isArray(providers) ? providers : []).find(
|
|
500
|
+
(item) => item && item.provider === providerId,
|
|
501
|
+
)
|
|
502
|
+
return entry && Array.isArray(entry.models) && entry.models[0] ? entry.models[0].model : ''
|
|
503
|
+
}
|
|
504
|
+
|
|
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
|
+
)
|
|
513
|
+
const choices = [
|
|
514
|
+
{
|
|
515
|
+
value: 'standard',
|
|
516
|
+
label: 'standard — ' + T('默认,零额外依赖', 'default, no extra dependency'),
|
|
517
|
+
},
|
|
518
|
+
]
|
|
519
|
+
const seen = new Set(['standard'])
|
|
520
|
+
for (const row of Array.isArray(rows) ? rows : []) {
|
|
521
|
+
if (!row || typeof row.id !== 'string' || row.id.length === 0 || seen.has(row.id)) continue
|
|
522
|
+
seen.add(row.id)
|
|
523
|
+
const label = row.name && row.name !== row.id ? row.name + '(' + row.id + ')' : row.id
|
|
524
|
+
if (disabledIds.has(row.id)) {
|
|
525
|
+
choices.push({
|
|
526
|
+
value: row.id,
|
|
527
|
+
label: label + ' — ' + T('内部预设,不能选自己', 'internal preset, cannot use itself'),
|
|
528
|
+
disabled: true,
|
|
529
|
+
})
|
|
530
|
+
} else if (row.broken) {
|
|
531
|
+
choices.push({
|
|
532
|
+
value: row.id,
|
|
533
|
+
label: label + ' — ' + T('不可用(加载失败)', 'unavailable (failed to load)'),
|
|
534
|
+
disabled: true,
|
|
535
|
+
})
|
|
536
|
+
} else {
|
|
537
|
+
choices.push({ value: row.id, label })
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if (current && !seen.has(current)) {
|
|
541
|
+
choices.push({
|
|
542
|
+
value: current,
|
|
543
|
+
label: current + ' — ' + T('已保存,但宿主目录中不可用', 'saved, but unavailable on this host'),
|
|
544
|
+
disabled: true,
|
|
545
|
+
})
|
|
546
|
+
}
|
|
547
|
+
return choices
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
const providerChoices = (providers, current, T) => {
|
|
551
|
+
const choices = []
|
|
552
|
+
const seen = new Set()
|
|
553
|
+
for (const entry of Array.isArray(providers) ? providers : []) {
|
|
554
|
+
if (!entry || typeof entry.provider !== 'string' || entry.provider.length === 0) continue
|
|
555
|
+
seen.add(entry.provider)
|
|
556
|
+
const label =
|
|
557
|
+
entry.name && entry.name !== entry.provider
|
|
558
|
+
? entry.name + '(' + entry.provider + ')'
|
|
559
|
+
: entry.provider
|
|
560
|
+
choices.push({ value: entry.provider, label })
|
|
561
|
+
}
|
|
562
|
+
if (current && !seen.has(current)) {
|
|
563
|
+
choices.push({
|
|
564
|
+
value: current,
|
|
565
|
+
label: current + ' — ' + T('已保存,但目录中找不到', 'saved, but missing from the catalog'),
|
|
566
|
+
disabled: true,
|
|
567
|
+
})
|
|
568
|
+
}
|
|
569
|
+
return choices
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
const modelChoices = (models, current, T) => {
|
|
573
|
+
const choices = []
|
|
574
|
+
const seen = new Set()
|
|
575
|
+
for (const entry of Array.isArray(models) ? models : []) {
|
|
576
|
+
if (!entry || typeof entry.model !== 'string' || entry.model.length === 0) continue
|
|
577
|
+
seen.add(entry.model)
|
|
578
|
+
const label =
|
|
579
|
+
entry.name && entry.name !== entry.model ? entry.name + '(' + entry.model + ')' : entry.model
|
|
580
|
+
choices.push({ value: entry.model, label })
|
|
581
|
+
}
|
|
582
|
+
if (current && !seen.has(current)) {
|
|
583
|
+
choices.push({
|
|
584
|
+
value: current,
|
|
585
|
+
label: current + ' — ' + T('已保存,但目录中找不到', 'saved, but missing from the catalog'),
|
|
586
|
+
disabled: true,
|
|
587
|
+
})
|
|
588
|
+
}
|
|
589
|
+
return choices
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
const renderChoices = (choices) =>
|
|
593
|
+
choices.map((choice) =>
|
|
594
|
+
h(
|
|
595
|
+
'option',
|
|
596
|
+
{ key: choice.value, value: choice.value, disabled: choice.disabled },
|
|
597
|
+
choice.label,
|
|
598
|
+
),
|
|
599
|
+
)
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
function SettingsSummary(props) {
|
|
603
|
+
const isZh = useActiveLocale(props.locale).toLowerCase().startsWith('zh')
|
|
604
|
+
const T = (cn, en) => (isZh ? cn : en)
|
|
605
|
+
return h(
|
|
606
|
+
'span',
|
|
607
|
+
null,
|
|
608
|
+
T(
|
|
609
|
+
'设置施工方式、主窗工具权限(默认 ask-edit)、子代理服务商与模型,以及模型守门范围。',
|
|
610
|
+
'Configure the development setup, main-session tool mode (default ask-edit), subagent provider/model, and model guard scope.',
|
|
611
|
+
),
|
|
612
|
+
)
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function SettingsPage(props) {
|
|
616
|
+
const locale = props.locale
|
|
617
|
+
const isZh = useActiveLocale(locale).toLowerCase().startsWith('zh')
|
|
618
|
+
const T = (cn, en) => (isZh ? cn : en)
|
|
619
|
+
const { state, error, refresh } = useHostState()
|
|
620
|
+
const [draft, setDraft] = React.useState(null)
|
|
621
|
+
const [dirty, setDirty] = React.useState(false)
|
|
622
|
+
const [busy, setBusy] = React.useState(false)
|
|
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
|
+
)
|
|
644
|
+
|
|
645
|
+
const config = state && state.config ? state.config : null
|
|
646
|
+
React.useEffect(() => {
|
|
647
|
+
if (!config || dirty) return
|
|
648
|
+
const nextJson = JSON.stringify(config)
|
|
649
|
+
if (nextJson === lastSyncedConfigJsonRef.current) return
|
|
650
|
+
lastSyncedConfigJsonRef.current = nextJson
|
|
651
|
+
setDraft({ ...config })
|
|
652
|
+
}, [config, dirty])
|
|
653
|
+
|
|
654
|
+
const update = (patch) => {
|
|
655
|
+
setNotice(null)
|
|
656
|
+
setDirty(true)
|
|
657
|
+
setDraft((previous) => ({ ...(previous || config || {}), ...patch }))
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
const save = async () => {
|
|
661
|
+
if (!draft) return
|
|
662
|
+
setBusy(true)
|
|
663
|
+
setNotice(null)
|
|
664
|
+
try {
|
|
665
|
+
const response = await fetch(API + '/config', {
|
|
666
|
+
method: 'POST',
|
|
667
|
+
headers: { 'content-type': 'application/json' },
|
|
668
|
+
body: JSON.stringify(draft),
|
|
669
|
+
})
|
|
670
|
+
let json = null
|
|
671
|
+
try {
|
|
672
|
+
json = await response.json()
|
|
673
|
+
} catch {
|
|
674
|
+
json = null
|
|
675
|
+
}
|
|
676
|
+
if (!response.ok) {
|
|
677
|
+
const failure = new Error(formatHostError(json, response.status, T))
|
|
678
|
+
failure.hostFormatted = true
|
|
679
|
+
throw failure
|
|
680
|
+
}
|
|
681
|
+
const nextConfig = json && json.config ? json.config : draft
|
|
682
|
+
lastSyncedConfigJsonRef.current = JSON.stringify(nextConfig)
|
|
683
|
+
setDirty(false)
|
|
684
|
+
setDraft(nextConfig)
|
|
685
|
+
setNotice({
|
|
686
|
+
kind: json && json.unchanged ? 'unchanged' : 'saved',
|
|
687
|
+
text: json && json.unchanged
|
|
688
|
+
? T('配置没有变化。', 'No changes.')
|
|
689
|
+
: T(
|
|
690
|
+
'已保存并正在应用;现有会话继续使用当前设置,新建会话才会使用新设置。',
|
|
691
|
+
'Saved and applying; existing sessions keep their current settings, while new sessions use the new ones.',
|
|
692
|
+
),
|
|
693
|
+
})
|
|
694
|
+
scheduleRefresh(600)
|
|
695
|
+
scheduleRefresh(1800)
|
|
696
|
+
} catch (cause) {
|
|
697
|
+
// 保存会触发插件重建,连接可能短暂断开;重读一次若已是草稿值就按成功显示。
|
|
698
|
+
let applied = false
|
|
699
|
+
try {
|
|
700
|
+
const latest = await refresh()
|
|
701
|
+
applied =
|
|
702
|
+
latest &&
|
|
703
|
+
latest.config &&
|
|
704
|
+
JSON.stringify(latest.config) === JSON.stringify(draft)
|
|
705
|
+
} catch {
|
|
706
|
+
applied = false
|
|
707
|
+
}
|
|
708
|
+
if (applied) {
|
|
709
|
+
lastSyncedConfigJsonRef.current = JSON.stringify(draft)
|
|
710
|
+
setDirty(false)
|
|
711
|
+
setNotice({
|
|
712
|
+
kind: 'saved',
|
|
713
|
+
text: T(
|
|
714
|
+
'已保存并正在应用;现有会话继续使用当前设置,新建会话才会使用新设置。',
|
|
715
|
+
'Saved and applying; existing sessions keep their current settings, while new sessions use the new ones.',
|
|
716
|
+
),
|
|
717
|
+
})
|
|
718
|
+
} else {
|
|
719
|
+
const raw = String((cause && cause.message) || cause)
|
|
720
|
+
const formatted = cause && cause.hostFormatted
|
|
721
|
+
setNotice({
|
|
722
|
+
kind: 'error',
|
|
723
|
+
text: formatted ? raw : T('保存失败:', 'Save failed: ') + raw,
|
|
724
|
+
})
|
|
725
|
+
}
|
|
726
|
+
} finally {
|
|
727
|
+
setBusy(false)
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
const discardAndRefresh = () => {
|
|
732
|
+
if (dirty) {
|
|
733
|
+
setDirty(false)
|
|
734
|
+
lastSyncedConfigJsonRef.current = config ? JSON.stringify(config) : ''
|
|
735
|
+
setDraft(config ? { ...config } : null)
|
|
736
|
+
setNotice({ kind: 'discarded', text: T('已放弃未保存的修改。', 'Unsaved changes discarded.') })
|
|
737
|
+
}
|
|
738
|
+
refresh()
|
|
739
|
+
}
|
|
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
|
+
|
|
753
|
+
const mode = state ? state.effectiveMode : null
|
|
754
|
+
const modeName = state && state.modeName ? state.modeName : mode
|
|
755
|
+
const fallback = Boolean(state && state.fallback && state.fallback.active)
|
|
756
|
+
const presetsState = state && state.presets ? state.presets : null
|
|
757
|
+
const presetRows = presetsState && Array.isArray(presetsState.rows) ? presetsState.rows : []
|
|
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
|
|
764
|
+
const modelCatalog = state && state.modelCatalog ? state.modelCatalog : null
|
|
765
|
+
const providers = modelCatalog && Array.isArray(modelCatalog.providers) ? modelCatalog.providers : []
|
|
766
|
+
const catalogFailures = modelCatalog && Array.isArray(modelCatalog.failures) ? modelCatalog.failures : []
|
|
767
|
+
const preset = state && state.preset ? state.preset : null
|
|
768
|
+
const violations = (state && state.violations) || []
|
|
769
|
+
const route = state && state.route ? state.route : null
|
|
770
|
+
const phase = phaseOf(state, error)
|
|
771
|
+
const registration = state ? state.registration : null
|
|
772
|
+
|
|
773
|
+
const providerId = draft ? draft.childProvider : route ? route.provider : ''
|
|
774
|
+
const providerEntry = providers.find((entry) => entry && entry.provider === providerId)
|
|
775
|
+
const models = providerEntry && Array.isArray(providerEntry.models) ? providerEntry.models : []
|
|
776
|
+
const providerKnown = providers.some((entry) => entry && entry.provider === providerId)
|
|
777
|
+
const modelId = draft ? draft.childModel : route ? route.model : ''
|
|
778
|
+
const modelKnown = models.some((entry) => entry && entry.model === modelId)
|
|
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
|
+
|
|
794
|
+
const changeProvider = (nextProvider) => {
|
|
795
|
+
const firstModel = firstModelOf(providers, nextProvider)
|
|
796
|
+
update(
|
|
797
|
+
firstModel
|
|
798
|
+
? { childProvider: nextProvider, childModel: firstModel }
|
|
799
|
+
: { childProvider: nextProvider },
|
|
800
|
+
)
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
let statusText = T('状态读取中…', 'Loading state…')
|
|
804
|
+
if (error && error.kind === 'not-found') {
|
|
805
|
+
statusText = T('设置页面不可用', 'Settings page unavailable')
|
|
806
|
+
} else if (error) {
|
|
807
|
+
statusText = T('状态读取失败', 'State read failed')
|
|
808
|
+
} else if (state && state.error) {
|
|
809
|
+
statusText = T('施工配置加载失败', 'Development setup failed to load')
|
|
810
|
+
} else if (state && registration === 'pending') {
|
|
811
|
+
statusText = T('尚未注册', 'Not registered yet')
|
|
812
|
+
} else if (state && registration === 'switching') {
|
|
813
|
+
statusText = T('切换中…', 'Switching…')
|
|
814
|
+
} else if (state && registration === 'failed') {
|
|
815
|
+
statusText = T('注册失败', 'Registration failed')
|
|
816
|
+
} else if (state && registration === 'disposed') {
|
|
817
|
+
statusText = T('已卸载', 'Disposed')
|
|
818
|
+
} else if (state) {
|
|
819
|
+
statusText = mode
|
|
820
|
+
? T('当前施工方式:', 'Development setup: ') +
|
|
821
|
+
(modeName || mode) +
|
|
822
|
+
(fallback ? T('(已回退)', ' (fallback)') : '')
|
|
823
|
+
: T('已同步', 'Synced')
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
const readErrorText =
|
|
827
|
+
error && error.kind === 'not-found'
|
|
828
|
+
? T(
|
|
829
|
+
'Host 未加载新版插件或设置路由未注册。请重启 DSH,并确认本插件行已启用;已停止自动重试,点“刷新”可重试。',
|
|
830
|
+
'The Host has not loaded the updated plugin or its settings route is not registered. Restart DSH and confirm this plugin row is enabled. Auto-retry stopped; select Refresh to retry.',
|
|
831
|
+
)
|
|
832
|
+
: error && error.kind === 'network'
|
|
833
|
+
? T(
|
|
834
|
+
'无法连接 Host。请确认 DSH 正在运行、插件已启用,然后点“刷新”重试。',
|
|
835
|
+
'Cannot reach the Host. Confirm DSH is running and the plugin is enabled, then select Refresh to retry.',
|
|
836
|
+
)
|
|
837
|
+
: error
|
|
838
|
+
? T('读取状态失败(HTTP ', 'State read failed (HTTP ') + (error.status || '?') + ')。'
|
|
839
|
+
: ''
|
|
840
|
+
const readErrorDetail = error && error.kind !== 'not-found' ? String(error.message || '') : ''
|
|
841
|
+
|
|
842
|
+
const saveStateText = busy
|
|
843
|
+
? T('保存中…', 'Saving…')
|
|
844
|
+
: dirty
|
|
845
|
+
? T('未保存修改', 'Unsaved changes')
|
|
846
|
+
: notice && notice.kind === 'saved'
|
|
847
|
+
? T('已保存', 'Saved')
|
|
848
|
+
: notice && notice.kind === 'discarded'
|
|
849
|
+
? T('已放弃修改', 'Changes discarded')
|
|
850
|
+
: notice && notice.kind === 'error'
|
|
851
|
+
? T('保存失败', 'Save failed')
|
|
852
|
+
: error
|
|
853
|
+
? T('读取失败', 'Read failed')
|
|
854
|
+
: state
|
|
855
|
+
? T('已同步', 'Synced')
|
|
856
|
+
: T('未加载', 'Not loaded')
|
|
857
|
+
|
|
858
|
+
const guardMode = draft ? draft.modelGuardMode : 'pin'
|
|
859
|
+
const guardHint =
|
|
860
|
+
guardMode === 'audit'
|
|
861
|
+
? T('只记录用错模型的情况,不阻止。', 'Records model mismatches without blocking them.')
|
|
862
|
+
: guardMode === 'off'
|
|
863
|
+
? T('完全不管理子代理模型,也不记录。', 'No subagent model management or logging.')
|
|
864
|
+
: T('发现子代理用错模型就按下面的选择停止或记录。', 'Stops or records a subagent that uses the wrong model, per the choices below.')
|
|
865
|
+
|
|
866
|
+
const presetCatalogText = !presetsState
|
|
867
|
+
? ''
|
|
868
|
+
: presetsState.checked
|
|
869
|
+
? presetRows.length === 0
|
|
870
|
+
? T('宿主没有返回可用的施工方式,当前先按 standard 运行。', 'The host returned no available setups; standard is used for now.')
|
|
871
|
+
: ''
|
|
872
|
+
: presetsState.timedOut
|
|
873
|
+
? T(
|
|
874
|
+
'施工方式列表读取超时或失败' +
|
|
875
|
+
(presetsState.error ? ':' + presetsState.error : '') +
|
|
876
|
+
',稍后会自动复检;当前先按 standard 运行。',
|
|
877
|
+
'The setup list timed out or failed' +
|
|
878
|
+
(presetsState.error ? ': ' + presetsState.error : '') +
|
|
879
|
+
' and will retry shortly; standard is used for now.',
|
|
880
|
+
)
|
|
881
|
+
: T('施工方式列表尚未读取。', 'The setup list has not been read yet.')
|
|
882
|
+
|
|
883
|
+
const selectedPresetRow = draft
|
|
884
|
+
? presetRows.find((row) => row && row.id === draft.developMode)
|
|
885
|
+
: undefined
|
|
886
|
+
const selectedPresetText = (() => {
|
|
887
|
+
if (!draft) return ''
|
|
888
|
+
if (draft.developMode === selfId) {
|
|
889
|
+
return T(
|
|
890
|
+
'develop 不能使用“开发规划与交付”自身,运行时会回退 standard。',
|
|
891
|
+
'develop cannot use “Development planning & delivery” itself; standard is used at runtime.',
|
|
892
|
+
)
|
|
893
|
+
}
|
|
894
|
+
if (selectedPresetRow && selectedPresetRow.broken) {
|
|
895
|
+
return T('这个施工方式加载失败,暂不可用:', 'This setup failed to load: ') + selectedPresetRow.broken
|
|
896
|
+
}
|
|
897
|
+
const catalogReady = presetsState && presetsState.checked === true
|
|
898
|
+
if (draft.developMode !== 'standard' && catalogReady && !selectedPresetRow) {
|
|
899
|
+
return T(
|
|
900
|
+
'已保存的施工方式“' + draft.developMode + '”当前不在宿主目录中;配置会保留,运行时会先回退 standard。',
|
|
901
|
+
'The saved setup “' + draft.developMode + '” is not in the host catalog. The setting is kept, and standard is used at runtime.',
|
|
902
|
+
)
|
|
903
|
+
}
|
|
904
|
+
return ''
|
|
905
|
+
})()
|
|
906
|
+
|
|
907
|
+
const catalogText = !modelCatalog
|
|
908
|
+
? T('模型列表读取中…', 'Loading the model list…')
|
|
909
|
+
: modelCatalog.checked !== true && !modelCatalog.error
|
|
910
|
+
? T('模型列表读取中…', 'Loading the model list…')
|
|
911
|
+
: modelCatalog.error === 'llm-unavailable'
|
|
912
|
+
? T(
|
|
913
|
+
'当前环境没有可读取的模型目录。已保存的服务商与模型会保留,不会自动改成别的。',
|
|
914
|
+
'No model catalog is available in this environment. Saved provider and model are kept unchanged.',
|
|
915
|
+
)
|
|
916
|
+
: modelCatalog.error
|
|
917
|
+
? T('模型目录读取失败:', 'Model catalog failed: ') +
|
|
918
|
+
modelCatalog.error +
|
|
919
|
+
T('。已保存的值会保留。', ' Saved values are kept.')
|
|
920
|
+
: providers.length === 0
|
|
921
|
+
? T('宿主没有返回可用的服务商,已保存的值会保留。', 'The host returned no providers; saved values are kept.')
|
|
922
|
+
: catalogFailures.length > 0
|
|
923
|
+
? T('部分服务商读取失败:', 'Some providers failed to load: ') +
|
|
924
|
+
catalogFailures.map((item) => item.provider).join('、') +
|
|
925
|
+
T(';它们下面的模型列表可能不完整。', '; their model lists may be incomplete.')
|
|
926
|
+
: ''
|
|
927
|
+
|
|
928
|
+
const unavailableRouteText =
|
|
929
|
+
providerId && !providerKnown
|
|
930
|
+
? T(
|
|
931
|
+
'当前保存的服务商不在目录中(可能已卸载或改名);保存不会自动替换它。',
|
|
932
|
+
'The saved provider is missing from the catalog (removed or renamed?). Saving will not replace it.',
|
|
933
|
+
)
|
|
934
|
+
: modelId && providerKnown && !modelKnown
|
|
935
|
+
? T(
|
|
936
|
+
'当前保存的模型不在此服务商的列表中;保存不会自动替换它。',
|
|
937
|
+
'The saved model is not in this provider’s list. Saving will not replace it.',
|
|
938
|
+
)
|
|
939
|
+
: ''
|
|
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
|
+
|
|
978
|
+
return h(
|
|
979
|
+
'div',
|
|
980
|
+
{ style: styles.root },
|
|
981
|
+
|
|
982
|
+
h(
|
|
983
|
+
'div',
|
|
984
|
+
{ style: styles.head },
|
|
985
|
+
h('span', { style: styles.dot(phase) }),
|
|
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,
|
|
988
|
+
h('span', { style: styles.status, role: 'status', 'aria-live': 'polite' }, statusText),
|
|
989
|
+
),
|
|
990
|
+
h(
|
|
991
|
+
'div',
|
|
992
|
+
{ style: styles.hint },
|
|
993
|
+
T(
|
|
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.',
|
|
996
|
+
),
|
|
997
|
+
),
|
|
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
|
+
|
|
1042
|
+
readErrorText
|
|
1043
|
+
? h(
|
|
1044
|
+
'div',
|
|
1045
|
+
{ style: styles.errorBox, role: 'alert' },
|
|
1046
|
+
h('div', null, readErrorText),
|
|
1047
|
+
readErrorDetail ? h('div', { style: styles.mono }, readErrorDetail) : null,
|
|
1048
|
+
)
|
|
1049
|
+
: null,
|
|
1050
|
+
|
|
1051
|
+
state && state.error
|
|
1052
|
+
? h(
|
|
1053
|
+
'div',
|
|
1054
|
+
{ style: styles.errorBox, role: 'alert' },
|
|
1055
|
+
h(
|
|
1056
|
+
'div',
|
|
1057
|
+
null,
|
|
1058
|
+
state.errorCode === 'preset-registration-failed'
|
|
1059
|
+
? T('施工配置加载失败;详情见插件日志。', 'The development setup failed to load; see the plugin log for details.')
|
|
1060
|
+
: T('插件错误:', 'Plugin error: '),
|
|
1061
|
+
),
|
|
1062
|
+
h('div', { style: styles.mono }, String(state.error)),
|
|
1063
|
+
)
|
|
1064
|
+
: null,
|
|
1065
|
+
|
|
1066
|
+
fallback
|
|
1067
|
+
? h(
|
|
1068
|
+
'div',
|
|
1069
|
+
{ style: styles.banner, role: 'status' },
|
|
1070
|
+
h('strong', null, T('已回退 standard。', 'Fell back to standard. ')),
|
|
1071
|
+
T(
|
|
1072
|
+
' 你选择的方式当前不可用(可能未安装、未启用、已被移除或加载失败);develop 临时使用 standard,其他子代理不受影响。原因:',
|
|
1073
|
+
' The selected setup is currently unavailable (not installed, disabled, removed, or failed to load); develop uses standard for now. Other subagents are unaffected. Reason: ',
|
|
1074
|
+
),
|
|
1075
|
+
h('span', { style: styles.mono }, (state.fallback && state.fallback.reason) || ''),
|
|
1076
|
+
)
|
|
1077
|
+
: null,
|
|
1078
|
+
|
|
1079
|
+
mode && mode !== 'standard' && !fallback
|
|
1080
|
+
? h(
|
|
1081
|
+
'div',
|
|
1082
|
+
{ style: styles.hint },
|
|
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
|
+
),
|
|
1092
|
+
)
|
|
1093
|
+
: null,
|
|
1094
|
+
|
|
1095
|
+
h(
|
|
1096
|
+
'fieldset',
|
|
1097
|
+
{ style: { ...styles.card, margin: 0, minWidth: 0 } },
|
|
1098
|
+
h('legend', { style: styles.legend }, T('施工子代理', 'Development subagent')),
|
|
1099
|
+
h('div', { style: styles.hint }, T('只有 develop 使用这里的选择。', 'Only develop uses this choice.')),
|
|
1100
|
+
draft
|
|
1101
|
+
? h(
|
|
1102
|
+
React.Fragment,
|
|
1103
|
+
null,
|
|
1104
|
+
h(
|
|
1105
|
+
Field,
|
|
1106
|
+
{
|
|
1107
|
+
id: 'dev-plan-presets-develop-mode',
|
|
1108
|
+
label: T('施工方式', 'Development setup'),
|
|
1109
|
+
hint: T('列表中包含宿主已安装的施工方式;不可用的项会标明原因。', 'The list contains setups installed on this host; unavailable entries explain why.'),
|
|
1110
|
+
},
|
|
1111
|
+
h(
|
|
1112
|
+
'select',
|
|
1113
|
+
{
|
|
1114
|
+
name: 'developMode',
|
|
1115
|
+
style: { ...styles.control, ...(busy ? styles.controlDisabled : null) },
|
|
1116
|
+
value: draft.developMode,
|
|
1117
|
+
disabled: busy,
|
|
1118
|
+
onChange: (event) => update({ developMode: event.target.value }),
|
|
1119
|
+
},
|
|
1120
|
+
renderChoices(memoPresetChoices),
|
|
1121
|
+
),
|
|
1122
|
+
),
|
|
1123
|
+
presetCatalogText
|
|
1124
|
+
? h('div', { style: styles.hint, role: 'status' }, presetCatalogText)
|
|
1125
|
+
: null,
|
|
1126
|
+
selectedPresetText
|
|
1127
|
+
? h('div', { style: styles.banner, role: 'status' }, selectedPresetText)
|
|
1128
|
+
: null,
|
|
1129
|
+
h(
|
|
1130
|
+
'div',
|
|
1131
|
+
{ style: styles.row },
|
|
1132
|
+
h(
|
|
1133
|
+
Field,
|
|
1134
|
+
{
|
|
1135
|
+
id: 'dev-plan-presets-provider',
|
|
1136
|
+
label: T('服务商', 'Provider'),
|
|
1137
|
+
hint: T('子代理使用的模型服务商。', 'Model provider used by subagents.'),
|
|
1138
|
+
},
|
|
1139
|
+
h(
|
|
1140
|
+
'select',
|
|
1141
|
+
{
|
|
1142
|
+
name: 'childProvider',
|
|
1143
|
+
style: { ...styles.control, ...(busy ? styles.controlDisabled : null) },
|
|
1144
|
+
value: providerId,
|
|
1145
|
+
disabled: busy || providers.length === 0,
|
|
1146
|
+
onChange: (event) => changeProvider(event.target.value),
|
|
1147
|
+
},
|
|
1148
|
+
renderChoices(memoProviderChoices),
|
|
1149
|
+
),
|
|
1150
|
+
),
|
|
1151
|
+
h(
|
|
1152
|
+
Field,
|
|
1153
|
+
{
|
|
1154
|
+
id: 'dev-plan-presets-model',
|
|
1155
|
+
label: T('模型', 'Model'),
|
|
1156
|
+
hint: T('所选服务商下可用的模型。', 'A model available under the selected provider.'),
|
|
1157
|
+
},
|
|
1158
|
+
h(
|
|
1159
|
+
'select',
|
|
1160
|
+
{
|
|
1161
|
+
name: 'childModel',
|
|
1162
|
+
style: { ...styles.control, ...(busy ? styles.controlDisabled : null) },
|
|
1163
|
+
value: modelId,
|
|
1164
|
+
disabled: busy || models.length === 0,
|
|
1165
|
+
onChange: (event) => update({ childModel: event.target.value }),
|
|
1166
|
+
},
|
|
1167
|
+
renderChoices(memoModelChoices),
|
|
1168
|
+
),
|
|
1169
|
+
),
|
|
1170
|
+
),
|
|
1171
|
+
catalogText
|
|
1172
|
+
? h('div', { style: styles.hint, role: 'status' }, catalogText)
|
|
1173
|
+
: null,
|
|
1174
|
+
unavailableRouteText
|
|
1175
|
+
? h('div', { style: styles.banner, role: 'status' }, unavailableRouteText)
|
|
1176
|
+
: null,
|
|
1177
|
+
h(
|
|
1178
|
+
Field,
|
|
1179
|
+
{
|
|
1180
|
+
id: 'dev-plan-presets-effort',
|
|
1181
|
+
label: T('推理强度(可选)', 'Reasoning effort (optional)'),
|
|
1182
|
+
hint: T('留空就使用服务商默认值。', 'Leave empty to use the provider default.'),
|
|
1183
|
+
},
|
|
1184
|
+
h('input', {
|
|
1185
|
+
name: 'childReasoningEffort',
|
|
1186
|
+
style: { ...styles.control, ...(busy ? styles.controlDisabled : null) },
|
|
1187
|
+
value: draft.childReasoningEffort || '',
|
|
1188
|
+
disabled: busy,
|
|
1189
|
+
spellCheck: false,
|
|
1190
|
+
placeholder: T('留空 = 服务商默认', 'empty = provider default'),
|
|
1191
|
+
onChange: (event) => update({ childReasoningEffort: event.target.value }),
|
|
1192
|
+
}),
|
|
1193
|
+
),
|
|
1194
|
+
)
|
|
1195
|
+
: h('div', { style: styles.hint }, T('加载中…', 'Loading…')),
|
|
1196
|
+
route
|
|
1197
|
+
? h(
|
|
1198
|
+
'div',
|
|
1199
|
+
{ style: styles.hint },
|
|
1200
|
+
T('当前生效:', 'Currently effective: '),
|
|
1201
|
+
h(
|
|
1202
|
+
'span',
|
|
1203
|
+
{ style: styles.mono },
|
|
1204
|
+
route.provider + ' / ' + route.model + (route.reasoningEffort ? ' / ' + route.reasoningEffort : ''),
|
|
1205
|
+
),
|
|
1206
|
+
)
|
|
1207
|
+
: null,
|
|
1208
|
+
h(
|
|
1209
|
+
'div',
|
|
1210
|
+
{ style: styles.hint },
|
|
1211
|
+
T(
|
|
1212
|
+
'这四个委派工具(recon / review / scribe / develop)共用同一服务商与模型;只影响子代理,不动主会话。保存后以回读值为准。',
|
|
1213
|
+
'All four delegation tools (recon / review / scribe / develop) share this provider and model. It affects subagents only, never the main session. Trust the read-back value after saving.',
|
|
1214
|
+
),
|
|
1215
|
+
),
|
|
1216
|
+
),
|
|
1217
|
+
|
|
1218
|
+
h(
|
|
1219
|
+
'fieldset',
|
|
1220
|
+
{ style: { ...styles.card, margin: 0, minWidth: 0 } },
|
|
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')),
|
|
1349
|
+
h(
|
|
1350
|
+
'div',
|
|
1351
|
+
{ style: styles.hint },
|
|
1352
|
+
T('只管理子代理,主会话永远不受影响。', 'Governs subagents only; the main session is never touched.'),
|
|
1353
|
+
),
|
|
1354
|
+
draft
|
|
1355
|
+
? h(
|
|
1356
|
+
React.Fragment,
|
|
1357
|
+
null,
|
|
1358
|
+
h(
|
|
1359
|
+
Field,
|
|
1360
|
+
{
|
|
1361
|
+
id: 'dev-plan-presets-guard-mode',
|
|
1362
|
+
label: T('守门方式', 'Guard behavior'),
|
|
1363
|
+
hint: guardHint,
|
|
1364
|
+
},
|
|
1365
|
+
h(
|
|
1366
|
+
'select',
|
|
1367
|
+
{
|
|
1368
|
+
name: 'modelGuardMode',
|
|
1369
|
+
style: { ...styles.control, ...(busy ? styles.controlDisabled : null) },
|
|
1370
|
+
value: draft.modelGuardMode,
|
|
1371
|
+
disabled: busy,
|
|
1372
|
+
onChange: (event) => update({ modelGuardMode: event.target.value }),
|
|
1373
|
+
},
|
|
1374
|
+
h('option', { value: 'pin' }, 'pin — ' + T('发现用错就停止(默认)', 'stop a mismatch (default)')),
|
|
1375
|
+
h('option', { value: 'audit' }, 'audit — ' + T('只记录,不阻止', 'record only, never block')),
|
|
1376
|
+
h('option', { value: 'off' }, 'off — ' + T('不管理模型', 'no model management')),
|
|
1377
|
+
),
|
|
1378
|
+
),
|
|
1379
|
+
h(
|
|
1380
|
+
'div',
|
|
1381
|
+
{ style: styles.row },
|
|
1382
|
+
h(
|
|
1383
|
+
'label',
|
|
1384
|
+
{ style: styles.check, htmlFor: 'dev-plan-presets-guard-all' },
|
|
1385
|
+
h('input', {
|
|
1386
|
+
id: 'dev-plan-presets-guard-all',
|
|
1387
|
+
name: 'guardAllSubagents',
|
|
1388
|
+
type: 'checkbox',
|
|
1389
|
+
checked: Boolean(draft.guardAllSubagents),
|
|
1390
|
+
disabled: busy,
|
|
1391
|
+
onChange: (event) => update({ guardAllSubagents: event.target.checked }),
|
|
1392
|
+
}),
|
|
1393
|
+
T('同时管理其他插件的子代理', 'Also govern subagents from other plugins'),
|
|
1394
|
+
),
|
|
1395
|
+
),
|
|
1396
|
+
h(
|
|
1397
|
+
'div',
|
|
1398
|
+
{ style: styles.hint },
|
|
1399
|
+
T(
|
|
1400
|
+
'默认只管理“开发规划与交付”会话派出的子代理;勾选后管理所有子代理。',
|
|
1401
|
+
'By default only subagents started from “Development planning & delivery” sessions are governed; check this to govern every subagent.',
|
|
1402
|
+
),
|
|
1403
|
+
),
|
|
1404
|
+
h(
|
|
1405
|
+
'div',
|
|
1406
|
+
{ style: styles.row },
|
|
1407
|
+
h(
|
|
1408
|
+
'label',
|
|
1409
|
+
{ style: styles.check, htmlFor: 'dev-plan-presets-kill-violation' },
|
|
1410
|
+
h('input', {
|
|
1411
|
+
id: 'dev-plan-presets-kill-violation',
|
|
1412
|
+
type: 'checkbox',
|
|
1413
|
+
name: 'killOnViolation',
|
|
1414
|
+
checked: Boolean(draft.killOnViolation),
|
|
1415
|
+
disabled: busy || draft.modelGuardMode !== 'pin',
|
|
1416
|
+
onChange: (event) => update({ killOnViolation: event.target.checked }),
|
|
1417
|
+
}),
|
|
1418
|
+
T('越界时立即停止(仅 pin)', 'Stop on violation (pin only)'),
|
|
1419
|
+
),
|
|
1420
|
+
h(
|
|
1421
|
+
'label',
|
|
1422
|
+
{ style: styles.check, htmlFor: 'dev-plan-presets-honor-explicit' },
|
|
1423
|
+
h('input', {
|
|
1424
|
+
id: 'dev-plan-presets-honor-explicit',
|
|
1425
|
+
type: 'checkbox',
|
|
1426
|
+
name: 'honorExplicit',
|
|
1427
|
+
checked: Boolean(draft.honorExplicit),
|
|
1428
|
+
disabled: busy || draft.modelGuardMode !== 'pin',
|
|
1429
|
+
onChange: (event) => update({ honorExplicit: event.target.checked }),
|
|
1430
|
+
}),
|
|
1431
|
+
T('尊重子代理自己选的模型(仅 pin)', 'Honor an explicit child model (pin only)'),
|
|
1432
|
+
),
|
|
1433
|
+
h(
|
|
1434
|
+
'label',
|
|
1435
|
+
{ style: styles.check, htmlFor: 'dev-plan-presets-audit' },
|
|
1436
|
+
h('input', {
|
|
1437
|
+
id: 'dev-plan-presets-audit',
|
|
1438
|
+
type: 'checkbox',
|
|
1439
|
+
name: 'audit',
|
|
1440
|
+
checked: Boolean(draft.audit),
|
|
1441
|
+
disabled: busy || draft.modelGuardMode === 'off',
|
|
1442
|
+
onChange: (event) => update({ audit: event.target.checked }),
|
|
1443
|
+
}),
|
|
1444
|
+
T('记录详细日志', 'Write detailed logs'),
|
|
1445
|
+
),
|
|
1446
|
+
),
|
|
1447
|
+
h(
|
|
1448
|
+
'div',
|
|
1449
|
+
{ style: styles.hint },
|
|
1450
|
+
T(
|
|
1451
|
+
'“audit”守门方式只是不阻止越界;“记录详细日志”是单独的日志开关,off 时不可用,日志只含模型与事件,不含凭据。',
|
|
1452
|
+
'The “audit” guard behavior only avoids blocking; “write detailed logs” is a separate switch, unavailable in off mode, and contains models and events but no credentials.',
|
|
1453
|
+
),
|
|
1454
|
+
),
|
|
1455
|
+
)
|
|
1456
|
+
: null,
|
|
1457
|
+
),
|
|
1458
|
+
|
|
1459
|
+
h(
|
|
1460
|
+
'div',
|
|
1461
|
+
{ style: { ...styles.actionBar, ...(dirty ? styles.actionBarDirty : null) } },
|
|
1462
|
+
h(
|
|
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,
|
|
1480
|
+
},
|
|
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
|
+
),
|
|
1515
|
+
),
|
|
1516
|
+
notice
|
|
1517
|
+
? h(
|
|
1518
|
+
'div',
|
|
1519
|
+
{
|
|
1520
|
+
style: notice.kind === 'error' ? styles.noticeError : styles.noticeOk,
|
|
1521
|
+
role: notice.kind === 'error' ? 'alert' : 'status',
|
|
1522
|
+
'aria-live': notice.kind === 'error' ? 'assertive' : 'polite',
|
|
1523
|
+
},
|
|
1524
|
+
notice.text,
|
|
1525
|
+
)
|
|
1526
|
+
: null,
|
|
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
|
+
),
|
|
1534
|
+
),
|
|
1535
|
+
),
|
|
1536
|
+
|
|
1537
|
+
h('div', { style: styles.sectionCaption }, T('运行状态与诊断', 'Runtime status & diagnostics')),
|
|
1538
|
+
|
|
1539
|
+
preset
|
|
1540
|
+
? h(
|
|
1541
|
+
'div',
|
|
1542
|
+
{ style: styles.card },
|
|
1543
|
+
h(
|
|
1544
|
+
'div',
|
|
1545
|
+
{ style: styles.row },
|
|
1546
|
+
h('span', { style: styles.title }, T('当前运行说明', 'Current runtime description')),
|
|
1547
|
+
h('span', { style: styles.mono }, preset.id),
|
|
1548
|
+
),
|
|
1549
|
+
h('div', { style: styles.hint }, preset.description),
|
|
1550
|
+
)
|
|
1551
|
+
: null,
|
|
1552
|
+
|
|
1553
|
+
h(
|
|
1554
|
+
'div',
|
|
1555
|
+
{ style: styles.card },
|
|
1556
|
+
h(
|
|
1557
|
+
'div',
|
|
1558
|
+
{ style: styles.row },
|
|
1559
|
+
h('span', { style: styles.title }, T('越界记录', 'Violations')),
|
|
1560
|
+
h('span', { style: styles.hint }, violations.length === 0 ? T('暂无', 'none') : String(violations.length)),
|
|
1561
|
+
),
|
|
1562
|
+
violations.length === 0
|
|
1563
|
+
? h('div', { style: styles.hint }, T('还没有子代理跑过非目标模型。', 'No subagent has used a non-target model.'))
|
|
1564
|
+
: violations.map((entry, index) =>
|
|
1565
|
+
h(
|
|
1566
|
+
'div',
|
|
1567
|
+
{ key: index, style: styles.hint },
|
|
1568
|
+
h('span', { style: styles.mono }, (entry.at || '') + ' · '),
|
|
1569
|
+
(entry.text || '') +
|
|
1570
|
+
' ' +
|
|
1571
|
+
T('(实际 ', '(actual ') +
|
|
1572
|
+
(entry.from || '?') +
|
|
1573
|
+
' → ' +
|
|
1574
|
+
T('期望 ', 'want ') +
|
|
1575
|
+
(entry.want || '?') +
|
|
1576
|
+
')',
|
|
1577
|
+
),
|
|
1578
|
+
),
|
|
1579
|
+
),
|
|
1580
|
+
)
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
function SettingsEntry(props) {
|
|
1584
|
+
if (props && props.view === 'summary') {
|
|
1585
|
+
return h(SettingsSummary, { locale: props.locale })
|
|
1586
|
+
}
|
|
1587
|
+
return h(SettingsPage, { locale: props.locale })
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
const exportedModule = {
|
|
1591
|
+
inject: ['slots', 'locale'],
|
|
1592
|
+
apply(ctx) {
|
|
1593
|
+
try {
|
|
1594
|
+
ctx.slots.inject('plugins.row.config', () =>
|
|
1595
|
+
ctx.slots.register(
|
|
1596
|
+
{
|
|
1597
|
+
name: 'plugins.row.config',
|
|
1598
|
+
id: 'dev-plan-presets-config',
|
|
1599
|
+
key: 'dsh-dev-plan-presets#dev-plan-presets',
|
|
1600
|
+
order: 10,
|
|
1601
|
+
},
|
|
1602
|
+
(props) => h(SettingsEntry, { ...props, locale: ctx.locale }),
|
|
1603
|
+
),
|
|
1604
|
+
)
|
|
1605
|
+
} catch (error) {
|
|
1606
|
+
try {
|
|
1607
|
+
console.error('[dsh-dev-plan-presets] client slot registration failed', error)
|
|
1608
|
+
} catch {
|
|
1609
|
+
/* ignore */
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
},
|
|
1613
|
+
}
|
|
1614
|
+
// 仅测试开关打开时暴露纯选择函数;生产模块对象不变。
|
|
1615
|
+
if (globalThis.__DSH_DEV_PLAN_PRESETS_TEST__ === true) {
|
|
1616
|
+
exportedModule.__test = {
|
|
1617
|
+
presetChoices,
|
|
1618
|
+
providerChoices,
|
|
1619
|
+
modelChoices,
|
|
1620
|
+
firstModelOf,
|
|
1621
|
+
isStateConverged,
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
return exportedModule
|
|
1625
|
+
} catch (error) {
|
|
1626
|
+
try {
|
|
1627
|
+
console.error('[dsh-dev-plan-presets] client factory failed', error)
|
|
1628
|
+
} catch {
|
|
1629
|
+
/* ignore */
|
|
1630
|
+
}
|
|
1631
|
+
throw error
|
|
1632
|
+
}
|
|
1633
|
+
},
|
|
1634
|
+
})
|