dsh-dev-plan-presets 0.0.0-stage → 0.3.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 +341 -2
- package/client.js +1096 -0
- package/cordis.patch.yml +22 -0
- package/detail.md +192 -0
- package/docs/flow-redesign.md +403 -0
- package/guard.js +364 -0
- package/icon.svg +12 -0
- package/index.js +703 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +53 -4
- package/preset.js +485 -0
- package/scripts/test-harness.mjs +290 -0
- package/scripts/verify-presets.mjs +1650 -0
- package/settings.js +174 -0
- package/test/plugin.test.mjs +1468 -0
package/client.js
ADDED
|
@@ -0,0 +1,1096 @@
|
|
|
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
|
+
}
|
|
120
|
+
|
|
121
|
+
const FIELD_LABELS = {
|
|
122
|
+
developMode: ['施工方式', 'Development setup'],
|
|
123
|
+
modelGuardMode: ['守门方式', 'Guard behavior'],
|
|
124
|
+
childProvider: ['子代理服务商', 'Subagent provider'],
|
|
125
|
+
childModel: ['子代理模型', 'Subagent model'],
|
|
126
|
+
childReasoningEffort: ['推理强度', 'Reasoning effort'],
|
|
127
|
+
killOnViolation: ['越界时立即停止', 'Stop on violation'],
|
|
128
|
+
honorExplicit: ['尊重子代理自己选的模型', 'Honor an explicit child model'],
|
|
129
|
+
audit: ['记录详细日志', 'Write detailed logs'],
|
|
130
|
+
guardAllSubagents: ['同时管理其他插件的子代理', 'Also govern subagents from other plugins'],
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function useActiveLocale(locale) {
|
|
134
|
+
const read = () => {
|
|
135
|
+
try {
|
|
136
|
+
return String(locale?.getSnapshot?.().active ?? 'en')
|
|
137
|
+
} catch {
|
|
138
|
+
return 'en'
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const [active, setActive] = React.useState(read)
|
|
142
|
+
React.useEffect(() => {
|
|
143
|
+
if (typeof locale?.subscribe !== 'function') return undefined
|
|
144
|
+
const sync = () => setActive(read())
|
|
145
|
+
sync()
|
|
146
|
+
return locale.subscribe(sync)
|
|
147
|
+
}, [locale])
|
|
148
|
+
return active
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function useHostState() {
|
|
152
|
+
const [state, setState] = React.useState(null)
|
|
153
|
+
const [error, setError] = React.useState(null)
|
|
154
|
+
const stopped = React.useRef(false)
|
|
155
|
+
|
|
156
|
+
const load = React.useCallback(async (force = false) => {
|
|
157
|
+
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
|
|
166
|
+
try {
|
|
167
|
+
json = await response.json()
|
|
168
|
+
} catch {
|
|
169
|
+
throw new Error('invalid JSON response')
|
|
170
|
+
}
|
|
171
|
+
if (!response.ok) {
|
|
172
|
+
setError({
|
|
173
|
+
kind: 'http',
|
|
174
|
+
status: response.status,
|
|
175
|
+
message: (json && (json.error || json.code)) || 'HTTP ' + response.status,
|
|
176
|
+
})
|
|
177
|
+
return null
|
|
178
|
+
}
|
|
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
|
+
}
|
|
187
|
+
}, [])
|
|
188
|
+
|
|
189
|
+
React.useEffect(() => {
|
|
190
|
+
load(true)
|
|
191
|
+
const timer = setInterval(() => {
|
|
192
|
+
if (!stopped.current) load(false)
|
|
193
|
+
}, 4000)
|
|
194
|
+
return () => clearInterval(timer)
|
|
195
|
+
}, [load])
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
state,
|
|
199
|
+
error,
|
|
200
|
+
stopped: stopped.current,
|
|
201
|
+
refresh: () => load(true),
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function fieldLabel(path, T) {
|
|
206
|
+
const key = Array.isArray(path) && path.length > 0 ? String(path[0]) : ''
|
|
207
|
+
const pair = FIELD_LABELS[key]
|
|
208
|
+
if (pair) return T(pair[0], pair[1])
|
|
209
|
+
return key || T('配置字段', 'configuration field')
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function formatHostError(body, status, T) {
|
|
213
|
+
const code = body && body.code
|
|
214
|
+
if (code === 'invalid-config') {
|
|
215
|
+
const issues = Array.isArray(body.issues) ? body.issues : []
|
|
216
|
+
if (issues.length === 0) return T('配置校验失败。', 'Configuration validation failed.')
|
|
217
|
+
const parts = issues.map((issue) => {
|
|
218
|
+
const key = Array.isArray(issue.path) && issue.path.length > 0 ? String(issue.path[0]) : ''
|
|
219
|
+
return FIELD_LABELS[key]
|
|
220
|
+
? fieldLabel(issue.path, T) + ': ' + T('取值不合法', 'invalid value')
|
|
221
|
+
: String(issue.message || issue)
|
|
222
|
+
})
|
|
223
|
+
return T('配置校验失败:', 'Configuration validation failed: ') + parts.join(';')
|
|
224
|
+
}
|
|
225
|
+
if (code === 'config-editor-unavailable') {
|
|
226
|
+
return T(
|
|
227
|
+
'当前环境不允许从页面保存。请到插件管理里修改这一行配置。',
|
|
228
|
+
'This environment does not allow saving from this page. Edit this plugin row in plugin management instead.',
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
if (code === 'unsupported-media-type') {
|
|
232
|
+
return T('保存请求格式不被接受(需要 application/json)。', 'The save request was rejected (application/json required).')
|
|
233
|
+
}
|
|
234
|
+
if (code === 'forbidden-origin') {
|
|
235
|
+
return T('保存请求被拒绝:来源校验未通过,请从 DSH 页面重试。', 'The save request was rejected by the origin check; retry from the DSH page.')
|
|
236
|
+
}
|
|
237
|
+
if (code === 'invalid-json' || code === 'invalid-body') {
|
|
238
|
+
return T('保存请求内容不是合法的配置对象。', 'The save request was not a valid configuration object.')
|
|
239
|
+
}
|
|
240
|
+
if (code === 'body-too-large') {
|
|
241
|
+
return T('保存请求过大。', 'The save request was too large.')
|
|
242
|
+
}
|
|
243
|
+
if (code === 'method-not-allowed') {
|
|
244
|
+
return T('保存请求方法不被接受。', 'The save request method was rejected.')
|
|
245
|
+
}
|
|
246
|
+
return (body && body.error) || 'HTTP ' + status
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function Field(props) {
|
|
250
|
+
const id = props.id
|
|
251
|
+
const hintId = props.hint && id ? id + '-hint' : undefined
|
|
252
|
+
const child = React.cloneElement(props.children, {
|
|
253
|
+
id,
|
|
254
|
+
...(hintId ? { 'aria-describedby': hintId } : null),
|
|
255
|
+
})
|
|
256
|
+
return h(
|
|
257
|
+
'div',
|
|
258
|
+
{ style: styles.field },
|
|
259
|
+
h('label', { htmlFor: id, style: styles.label }, props.label),
|
|
260
|
+
child,
|
|
261
|
+
hintId ? h('span', { id: hintId, style: styles.hint }, props.hint) : null,
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function phaseOf(state, error) {
|
|
266
|
+
if (error || (state && (state.error || state.registration === 'failed'))) return 'error'
|
|
267
|
+
if (!state || state.registration === 'pending' || state.registration === 'switching') return 'loading'
|
|
268
|
+
return 'ready'
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** 纯选择项构造:不依赖 React,供组件与行为测试共用。 */
|
|
272
|
+
const firstModelOf = (providers, providerId) => {
|
|
273
|
+
const entry = (Array.isArray(providers) ? providers : []).find(
|
|
274
|
+
(item) => item && item.provider === providerId,
|
|
275
|
+
)
|
|
276
|
+
return entry && Array.isArray(entry.models) && entry.models[0] ? entry.models[0].model : ''
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const presetChoices = (rows, current, selfId, T) => {
|
|
280
|
+
const choices = [
|
|
281
|
+
{
|
|
282
|
+
value: 'standard',
|
|
283
|
+
label: 'standard — ' + T('默认,零额外依赖', 'default, no extra dependency'),
|
|
284
|
+
},
|
|
285
|
+
]
|
|
286
|
+
const seen = new Set(['standard'])
|
|
287
|
+
for (const row of Array.isArray(rows) ? rows : []) {
|
|
288
|
+
if (!row || typeof row.id !== 'string' || row.id.length === 0 || seen.has(row.id)) continue
|
|
289
|
+
seen.add(row.id)
|
|
290
|
+
const label = row.name && row.name !== row.id ? row.name + '(' + row.id + ')' : row.id
|
|
291
|
+
if (row.id === selfId) {
|
|
292
|
+
choices.push({
|
|
293
|
+
value: row.id,
|
|
294
|
+
label: label + ' — ' + T('不能选自己', 'cannot use itself'),
|
|
295
|
+
disabled: true,
|
|
296
|
+
})
|
|
297
|
+
} else if (row.broken) {
|
|
298
|
+
choices.push({
|
|
299
|
+
value: row.id,
|
|
300
|
+
label: label + ' — ' + T('不可用(加载失败)', 'unavailable (failed to load)'),
|
|
301
|
+
disabled: true,
|
|
302
|
+
})
|
|
303
|
+
} else {
|
|
304
|
+
choices.push({ value: row.id, label })
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (current && !seen.has(current)) {
|
|
308
|
+
choices.push({
|
|
309
|
+
value: current,
|
|
310
|
+
label: current + ' — ' + T('已保存,但宿主目录中不可用', 'saved, but unavailable on this host'),
|
|
311
|
+
disabled: true,
|
|
312
|
+
})
|
|
313
|
+
}
|
|
314
|
+
return choices
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const providerChoices = (providers, current, T) => {
|
|
318
|
+
const choices = []
|
|
319
|
+
const seen = new Set()
|
|
320
|
+
for (const entry of Array.isArray(providers) ? providers : []) {
|
|
321
|
+
if (!entry || typeof entry.provider !== 'string' || entry.provider.length === 0) continue
|
|
322
|
+
seen.add(entry.provider)
|
|
323
|
+
const label =
|
|
324
|
+
entry.name && entry.name !== entry.provider
|
|
325
|
+
? entry.name + '(' + entry.provider + ')'
|
|
326
|
+
: entry.provider
|
|
327
|
+
choices.push({ value: entry.provider, label })
|
|
328
|
+
}
|
|
329
|
+
if (current && !seen.has(current)) {
|
|
330
|
+
choices.push({
|
|
331
|
+
value: current,
|
|
332
|
+
label: current + ' — ' + T('已保存,但目录中找不到', 'saved, but missing from the catalog'),
|
|
333
|
+
disabled: true,
|
|
334
|
+
})
|
|
335
|
+
}
|
|
336
|
+
return choices
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const modelChoices = (models, current, T) => {
|
|
340
|
+
const choices = []
|
|
341
|
+
const seen = new Set()
|
|
342
|
+
for (const entry of Array.isArray(models) ? models : []) {
|
|
343
|
+
if (!entry || typeof entry.model !== 'string' || entry.model.length === 0) continue
|
|
344
|
+
seen.add(entry.model)
|
|
345
|
+
const label =
|
|
346
|
+
entry.name && entry.name !== entry.model ? entry.name + '(' + entry.model + ')' : entry.model
|
|
347
|
+
choices.push({ value: entry.model, label })
|
|
348
|
+
}
|
|
349
|
+
if (current && !seen.has(current)) {
|
|
350
|
+
choices.push({
|
|
351
|
+
value: current,
|
|
352
|
+
label: current + ' — ' + T('已保存,但目录中找不到', 'saved, but missing from the catalog'),
|
|
353
|
+
disabled: true,
|
|
354
|
+
})
|
|
355
|
+
}
|
|
356
|
+
return choices
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const renderChoices = (choices) =>
|
|
360
|
+
choices.map((choice) =>
|
|
361
|
+
h(
|
|
362
|
+
'option',
|
|
363
|
+
{ key: choice.value, value: choice.value, disabled: choice.disabled },
|
|
364
|
+
choice.label,
|
|
365
|
+
),
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
function SettingsSummary(props) {
|
|
370
|
+
const isZh = useActiveLocale(props.locale).toLowerCase().startsWith('zh')
|
|
371
|
+
const T = (cn, en) => (isZh ? cn : en)
|
|
372
|
+
return h(
|
|
373
|
+
'span',
|
|
374
|
+
null,
|
|
375
|
+
T(
|
|
376
|
+
'设置施工方式、子代理服务商与模型,以及模型守门的范围。',
|
|
377
|
+
'Choose the development setup, the subagent provider and model, and how far the model guard applies.',
|
|
378
|
+
),
|
|
379
|
+
)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function SettingsPage(props) {
|
|
383
|
+
const locale = props.locale
|
|
384
|
+
const isZh = useActiveLocale(locale).toLowerCase().startsWith('zh')
|
|
385
|
+
const T = (cn, en) => (isZh ? cn : en)
|
|
386
|
+
const { state, error, refresh } = useHostState()
|
|
387
|
+
const [draft, setDraft] = React.useState(null)
|
|
388
|
+
const [dirty, setDirty] = React.useState(false)
|
|
389
|
+
const [busy, setBusy] = React.useState(false)
|
|
390
|
+
const [notice, setNotice] = React.useState(null)
|
|
391
|
+
|
|
392
|
+
const config = state && state.config ? state.config : null
|
|
393
|
+
React.useEffect(() => {
|
|
394
|
+
if (config && !dirty) setDraft({ ...config })
|
|
395
|
+
}, [config, dirty])
|
|
396
|
+
|
|
397
|
+
const update = (patch) => {
|
|
398
|
+
setNotice(null)
|
|
399
|
+
setDirty(true)
|
|
400
|
+
setDraft((previous) => ({ ...(previous || config || {}), ...patch }))
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const save = async () => {
|
|
404
|
+
if (!draft) return
|
|
405
|
+
setBusy(true)
|
|
406
|
+
setNotice(null)
|
|
407
|
+
try {
|
|
408
|
+
const response = await fetch(API + '/config', {
|
|
409
|
+
method: 'POST',
|
|
410
|
+
headers: { 'content-type': 'application/json' },
|
|
411
|
+
body: JSON.stringify(draft),
|
|
412
|
+
})
|
|
413
|
+
let json = null
|
|
414
|
+
try {
|
|
415
|
+
json = await response.json()
|
|
416
|
+
} catch {
|
|
417
|
+
json = null
|
|
418
|
+
}
|
|
419
|
+
if (!response.ok) {
|
|
420
|
+
const failure = new Error(formatHostError(json, response.status, T))
|
|
421
|
+
failure.hostFormatted = true
|
|
422
|
+
throw failure
|
|
423
|
+
}
|
|
424
|
+
setDirty(false)
|
|
425
|
+
setDraft(json && json.config ? json.config : draft)
|
|
426
|
+
setNotice({
|
|
427
|
+
kind: json && json.unchanged ? 'unchanged' : 'saved',
|
|
428
|
+
text: json && json.unchanged
|
|
429
|
+
? T('配置没有变化。', 'No changes.')
|
|
430
|
+
: T(
|
|
431
|
+
'已保存并正在应用;现有会话继续使用当前设置,新建会话才会使用新设置。',
|
|
432
|
+
'Saved and applying; existing sessions keep their current settings, while new sessions use the new ones.',
|
|
433
|
+
),
|
|
434
|
+
})
|
|
435
|
+
setTimeout(refresh, 600)
|
|
436
|
+
setTimeout(refresh, 1800)
|
|
437
|
+
} catch (cause) {
|
|
438
|
+
// 保存会触发插件重建,连接可能短暂断开;重读一次若已是草稿值就按成功显示。
|
|
439
|
+
let applied = false
|
|
440
|
+
try {
|
|
441
|
+
const latest = await refresh()
|
|
442
|
+
applied =
|
|
443
|
+
latest &&
|
|
444
|
+
latest.config &&
|
|
445
|
+
JSON.stringify(latest.config) === JSON.stringify(draft)
|
|
446
|
+
} catch {
|
|
447
|
+
applied = false
|
|
448
|
+
}
|
|
449
|
+
if (applied) {
|
|
450
|
+
setDirty(false)
|
|
451
|
+
setNotice({
|
|
452
|
+
kind: 'saved',
|
|
453
|
+
text: T(
|
|
454
|
+
'已保存并正在应用;现有会话继续使用当前设置,新建会话才会使用新设置。',
|
|
455
|
+
'Saved and applying; existing sessions keep their current settings, while new sessions use the new ones.',
|
|
456
|
+
),
|
|
457
|
+
})
|
|
458
|
+
} else {
|
|
459
|
+
const raw = String((cause && cause.message) || cause)
|
|
460
|
+
const formatted = cause && cause.hostFormatted
|
|
461
|
+
setNotice({
|
|
462
|
+
kind: 'error',
|
|
463
|
+
text: formatted ? raw : T('保存失败:', 'Save failed: ') + raw,
|
|
464
|
+
})
|
|
465
|
+
}
|
|
466
|
+
} finally {
|
|
467
|
+
setBusy(false)
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const discardAndRefresh = () => {
|
|
472
|
+
if (dirty) {
|
|
473
|
+
setDirty(false)
|
|
474
|
+
setDraft(config ? { ...config } : null)
|
|
475
|
+
setNotice({ kind: 'discarded', text: T('已放弃未保存的修改。', 'Unsaved changes discarded.') })
|
|
476
|
+
}
|
|
477
|
+
refresh()
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
const mode = state ? state.effectiveMode : null
|
|
481
|
+
const modeName = state && state.modeName ? state.modeName : mode
|
|
482
|
+
const fallback = Boolean(state && state.fallback && state.fallback.active)
|
|
483
|
+
const presetsState = state && state.presets ? state.presets : null
|
|
484
|
+
const presetRows = presetsState && Array.isArray(presetsState.rows) ? presetsState.rows : []
|
|
485
|
+
const selfId = (presetsState && presetsState.selfId) || 'dev-plan'
|
|
486
|
+
const modelCatalog = state && state.modelCatalog ? state.modelCatalog : null
|
|
487
|
+
const providers = modelCatalog && Array.isArray(modelCatalog.providers) ? modelCatalog.providers : []
|
|
488
|
+
const catalogFailures = modelCatalog && Array.isArray(modelCatalog.failures) ? modelCatalog.failures : []
|
|
489
|
+
const preset = state && state.preset ? state.preset : null
|
|
490
|
+
const violations = (state && state.violations) || []
|
|
491
|
+
const route = state && state.route ? state.route : null
|
|
492
|
+
const phase = phaseOf(state, error)
|
|
493
|
+
const registration = state ? state.registration : null
|
|
494
|
+
|
|
495
|
+
const providerId = draft ? draft.childProvider : route ? route.provider : ''
|
|
496
|
+
const providerEntry = providers.find((entry) => entry && entry.provider === providerId)
|
|
497
|
+
const models = providerEntry && Array.isArray(providerEntry.models) ? providerEntry.models : []
|
|
498
|
+
const providerKnown = providers.some((entry) => entry && entry.provider === providerId)
|
|
499
|
+
const modelId = draft ? draft.childModel : route ? route.model : ''
|
|
500
|
+
const modelKnown = models.some((entry) => entry && entry.model === modelId)
|
|
501
|
+
|
|
502
|
+
const changeProvider = (nextProvider) => {
|
|
503
|
+
const firstModel = firstModelOf(providers, nextProvider)
|
|
504
|
+
update(
|
|
505
|
+
firstModel
|
|
506
|
+
? { childProvider: nextProvider, childModel: firstModel }
|
|
507
|
+
: { childProvider: nextProvider },
|
|
508
|
+
)
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
let statusText = T('状态读取中…', 'Loading state…')
|
|
512
|
+
if (error && error.kind === 'not-found') {
|
|
513
|
+
statusText = T('设置页面不可用', 'Settings page unavailable')
|
|
514
|
+
} else if (error) {
|
|
515
|
+
statusText = T('状态读取失败', 'State read failed')
|
|
516
|
+
} else if (state && state.error) {
|
|
517
|
+
statusText = T('施工配置加载失败', 'Development setup failed to load')
|
|
518
|
+
} else if (state && registration === 'pending') {
|
|
519
|
+
statusText = T('尚未注册', 'Not registered yet')
|
|
520
|
+
} else if (state && registration === 'switching') {
|
|
521
|
+
statusText = T('切换中…', 'Switching…')
|
|
522
|
+
} else if (state && registration === 'failed') {
|
|
523
|
+
statusText = T('注册失败', 'Registration failed')
|
|
524
|
+
} else if (state && registration === 'disposed') {
|
|
525
|
+
statusText = T('已卸载', 'Disposed')
|
|
526
|
+
} else if (state) {
|
|
527
|
+
statusText = mode
|
|
528
|
+
? T('当前施工方式:', 'Development setup: ') +
|
|
529
|
+
(modeName || mode) +
|
|
530
|
+
(fallback ? T('(已回退)', ' (fallback)') : '')
|
|
531
|
+
: T('已同步', 'Synced')
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const readErrorText =
|
|
535
|
+
error && error.kind === 'not-found'
|
|
536
|
+
? T(
|
|
537
|
+
'Host 未加载新版插件或设置路由未注册。请重启 DSH,并确认本插件行已启用;已停止自动重试,点“刷新”可重试。',
|
|
538
|
+
'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.',
|
|
539
|
+
)
|
|
540
|
+
: error && error.kind === 'network'
|
|
541
|
+
? T(
|
|
542
|
+
'无法连接 Host。请确认 DSH 正在运行、插件已启用,然后点“刷新”重试。',
|
|
543
|
+
'Cannot reach the Host. Confirm DSH is running and the plugin is enabled, then select Refresh to retry.',
|
|
544
|
+
)
|
|
545
|
+
: error
|
|
546
|
+
? T('读取状态失败(HTTP ', 'State read failed (HTTP ') + (error.status || '?') + ')。'
|
|
547
|
+
: ''
|
|
548
|
+
const readErrorDetail = error && error.kind !== 'not-found' ? String(error.message || '') : ''
|
|
549
|
+
|
|
550
|
+
const saveStateText = busy
|
|
551
|
+
? T('保存中…', 'Saving…')
|
|
552
|
+
: dirty
|
|
553
|
+
? T('未保存修改', 'Unsaved changes')
|
|
554
|
+
: notice && notice.kind === 'saved'
|
|
555
|
+
? T('已保存', 'Saved')
|
|
556
|
+
: notice && notice.kind === 'discarded'
|
|
557
|
+
? T('已放弃修改', 'Changes discarded')
|
|
558
|
+
: notice && notice.kind === 'error'
|
|
559
|
+
? T('保存失败', 'Save failed')
|
|
560
|
+
: error
|
|
561
|
+
? T('读取失败', 'Read failed')
|
|
562
|
+
: state
|
|
563
|
+
? T('已同步', 'Synced')
|
|
564
|
+
: T('未加载', 'Not loaded')
|
|
565
|
+
|
|
566
|
+
const guardMode = draft ? draft.modelGuardMode : 'pin'
|
|
567
|
+
const guardHint =
|
|
568
|
+
guardMode === 'audit'
|
|
569
|
+
? T('只记录用错模型的情况,不阻止。', 'Records model mismatches without blocking them.')
|
|
570
|
+
: guardMode === 'off'
|
|
571
|
+
? T('完全不管理子代理模型,也不记录。', 'No subagent model management or logging.')
|
|
572
|
+
: T('发现子代理用错模型就按下面的选择停止或记录。', 'Stops or records a subagent that uses the wrong model, per the choices below.')
|
|
573
|
+
|
|
574
|
+
const presetCatalogText = !presetsState
|
|
575
|
+
? ''
|
|
576
|
+
: presetsState.checked
|
|
577
|
+
? presetRows.length === 0
|
|
578
|
+
? T('宿主没有返回可用的施工方式,当前先按 standard 运行。', 'The host returned no available setups; standard is used for now.')
|
|
579
|
+
: ''
|
|
580
|
+
: presetsState.timedOut
|
|
581
|
+
? T(
|
|
582
|
+
'施工方式列表读取超时或失败' +
|
|
583
|
+
(presetsState.error ? ':' + presetsState.error : '') +
|
|
584
|
+
',稍后会自动复检;当前先按 standard 运行。',
|
|
585
|
+
'The setup list timed out or failed' +
|
|
586
|
+
(presetsState.error ? ': ' + presetsState.error : '') +
|
|
587
|
+
' and will retry shortly; standard is used for now.',
|
|
588
|
+
)
|
|
589
|
+
: T('施工方式列表尚未读取。', 'The setup list has not been read yet.')
|
|
590
|
+
|
|
591
|
+
const selectedPresetRow = draft
|
|
592
|
+
? presetRows.find((row) => row && row.id === draft.developMode)
|
|
593
|
+
: undefined
|
|
594
|
+
const selectedPresetText = (() => {
|
|
595
|
+
if (!draft) return ''
|
|
596
|
+
if (draft.developMode === selfId) {
|
|
597
|
+
return T(
|
|
598
|
+
'develop 不能使用“开发规划与交付”自身,运行时会回退 standard。',
|
|
599
|
+
'develop cannot use “Development planning & delivery” itself; standard is used at runtime.',
|
|
600
|
+
)
|
|
601
|
+
}
|
|
602
|
+
if (selectedPresetRow && selectedPresetRow.broken) {
|
|
603
|
+
return T('这个施工方式加载失败,暂不可用:', 'This setup failed to load: ') + selectedPresetRow.broken
|
|
604
|
+
}
|
|
605
|
+
const catalogReady = presetsState && presetsState.checked === true
|
|
606
|
+
if (draft.developMode !== 'standard' && catalogReady && !selectedPresetRow) {
|
|
607
|
+
return T(
|
|
608
|
+
'已保存的施工方式“' + draft.developMode + '”当前不在宿主目录中;配置会保留,运行时会先回退 standard。',
|
|
609
|
+
'The saved setup “' + draft.developMode + '” is not in the host catalog. The setting is kept, and standard is used at runtime.',
|
|
610
|
+
)
|
|
611
|
+
}
|
|
612
|
+
return ''
|
|
613
|
+
})()
|
|
614
|
+
|
|
615
|
+
const catalogText = !modelCatalog
|
|
616
|
+
? T('模型列表读取中…', 'Loading the model list…')
|
|
617
|
+
: modelCatalog.checked !== true && !modelCatalog.error
|
|
618
|
+
? T('模型列表读取中…', 'Loading the model list…')
|
|
619
|
+
: modelCatalog.error === 'llm-unavailable'
|
|
620
|
+
? T(
|
|
621
|
+
'当前环境没有可读取的模型目录。已保存的服务商与模型会保留,不会自动改成别的。',
|
|
622
|
+
'No model catalog is available in this environment. Saved provider and model are kept unchanged.',
|
|
623
|
+
)
|
|
624
|
+
: modelCatalog.error
|
|
625
|
+
? T('模型目录读取失败:', 'Model catalog failed: ') +
|
|
626
|
+
modelCatalog.error +
|
|
627
|
+
T('。已保存的值会保留。', ' Saved values are kept.')
|
|
628
|
+
: providers.length === 0
|
|
629
|
+
? T('宿主没有返回可用的服务商,已保存的值会保留。', 'The host returned no providers; saved values are kept.')
|
|
630
|
+
: catalogFailures.length > 0
|
|
631
|
+
? T('部分服务商读取失败:', 'Some providers failed to load: ') +
|
|
632
|
+
catalogFailures.map((item) => item.provider).join('、') +
|
|
633
|
+
T(';它们下面的模型列表可能不完整。', '; their model lists may be incomplete.')
|
|
634
|
+
: ''
|
|
635
|
+
|
|
636
|
+
const unavailableRouteText =
|
|
637
|
+
providerId && !providerKnown
|
|
638
|
+
? T(
|
|
639
|
+
'当前保存的服务商不在目录中(可能已卸载或改名);保存不会自动替换它。',
|
|
640
|
+
'The saved provider is missing from the catalog (removed or renamed?). Saving will not replace it.',
|
|
641
|
+
)
|
|
642
|
+
: modelId && providerKnown && !modelKnown
|
|
643
|
+
? T(
|
|
644
|
+
'当前保存的模型不在此服务商的列表中;保存不会自动替换它。',
|
|
645
|
+
'The saved model is not in this provider’s list. Saving will not replace it.',
|
|
646
|
+
)
|
|
647
|
+
: ''
|
|
648
|
+
|
|
649
|
+
return h(
|
|
650
|
+
'div',
|
|
651
|
+
{ style: styles.root },
|
|
652
|
+
|
|
653
|
+
h(
|
|
654
|
+
'div',
|
|
655
|
+
{ style: styles.head },
|
|
656
|
+
h('span', { style: styles.dot(phase) }),
|
|
657
|
+
h('span', { style: styles.title }, T('开发规划与交付 · 施工设置', 'Development planning & delivery · development settings')),
|
|
658
|
+
h('span', { style: styles.status, role: 'status', 'aria-live': 'polite' }, statusText),
|
|
659
|
+
),
|
|
660
|
+
h(
|
|
661
|
+
'div',
|
|
662
|
+
{ style: styles.hint },
|
|
663
|
+
T(
|
|
664
|
+
'主窗口只做规划、派工与复核,永不亲自写代码;develop 子代理负责施工并直接向主窗口汇报。',
|
|
665
|
+
'The main window only plans, dispatches, and reviews; it never writes code. The develop subagent implements and reports back directly.',
|
|
666
|
+
),
|
|
667
|
+
),
|
|
668
|
+
|
|
669
|
+
readErrorText
|
|
670
|
+
? h(
|
|
671
|
+
'div',
|
|
672
|
+
{ style: styles.errorBox, role: 'alert' },
|
|
673
|
+
h('div', null, readErrorText),
|
|
674
|
+
readErrorDetail ? h('div', { style: styles.mono }, readErrorDetail) : null,
|
|
675
|
+
)
|
|
676
|
+
: null,
|
|
677
|
+
|
|
678
|
+
state && state.error
|
|
679
|
+
? h(
|
|
680
|
+
'div',
|
|
681
|
+
{ style: styles.errorBox, role: 'alert' },
|
|
682
|
+
h(
|
|
683
|
+
'div',
|
|
684
|
+
null,
|
|
685
|
+
state.errorCode === 'preset-registration-failed'
|
|
686
|
+
? T('施工配置加载失败;详情见插件日志。', 'The development setup failed to load; see the plugin log for details.')
|
|
687
|
+
: T('插件错误:', 'Plugin error: '),
|
|
688
|
+
),
|
|
689
|
+
h('div', { style: styles.mono }, String(state.error)),
|
|
690
|
+
)
|
|
691
|
+
: null,
|
|
692
|
+
|
|
693
|
+
fallback
|
|
694
|
+
? h(
|
|
695
|
+
'div',
|
|
696
|
+
{ style: styles.banner, role: 'status' },
|
|
697
|
+
h('strong', null, T('已回退 standard。', 'Fell back to standard. ')),
|
|
698
|
+
T(
|
|
699
|
+
' 你选择的方式当前不可用(可能未安装、未启用、已被移除或加载失败);develop 临时使用 standard,其他子代理不受影响。原因:',
|
|
700
|
+
' The selected setup is currently unavailable (not installed, disabled, removed, or failed to load); develop uses standard for now. Other subagents are unaffected. Reason: ',
|
|
701
|
+
),
|
|
702
|
+
h('span', { style: styles.mono }, (state.fallback && state.fallback.reason) || ''),
|
|
703
|
+
)
|
|
704
|
+
: null,
|
|
705
|
+
|
|
706
|
+
mode && mode !== 'standard' && !fallback
|
|
707
|
+
? h(
|
|
708
|
+
'div',
|
|
709
|
+
{ 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
|
+
),
|
|
714
|
+
)
|
|
715
|
+
: null,
|
|
716
|
+
|
|
717
|
+
h(
|
|
718
|
+
'fieldset',
|
|
719
|
+
{ style: { ...styles.card, margin: 0, minWidth: 0 } },
|
|
720
|
+
h('legend', { style: styles.legend }, T('施工子代理', 'Development subagent')),
|
|
721
|
+
h('div', { style: styles.hint }, T('只有 develop 使用这里的选择。', 'Only develop uses this choice.')),
|
|
722
|
+
draft
|
|
723
|
+
? h(
|
|
724
|
+
React.Fragment,
|
|
725
|
+
null,
|
|
726
|
+
h(
|
|
727
|
+
Field,
|
|
728
|
+
{
|
|
729
|
+
id: 'dev-plan-presets-develop-mode',
|
|
730
|
+
label: T('施工方式', 'Development setup'),
|
|
731
|
+
hint: T('列表中包含宿主已安装的施工方式;不可用的项会标明原因。', 'The list contains setups installed on this host; unavailable entries explain why.'),
|
|
732
|
+
},
|
|
733
|
+
h(
|
|
734
|
+
'select',
|
|
735
|
+
{
|
|
736
|
+
name: 'developMode',
|
|
737
|
+
style: { ...styles.control, ...(busy ? styles.controlDisabled : null) },
|
|
738
|
+
value: draft.developMode,
|
|
739
|
+
disabled: busy,
|
|
740
|
+
onChange: (event) => update({ developMode: event.target.value }),
|
|
741
|
+
},
|
|
742
|
+
renderChoices(presetChoices(presetRows, draft.developMode, selfId, T)),
|
|
743
|
+
),
|
|
744
|
+
),
|
|
745
|
+
presetCatalogText
|
|
746
|
+
? h('div', { style: styles.hint, role: 'status' }, presetCatalogText)
|
|
747
|
+
: null,
|
|
748
|
+
selectedPresetText
|
|
749
|
+
? h('div', { style: styles.banner, role: 'status' }, selectedPresetText)
|
|
750
|
+
: null,
|
|
751
|
+
h(
|
|
752
|
+
'div',
|
|
753
|
+
{ style: styles.row },
|
|
754
|
+
h(
|
|
755
|
+
Field,
|
|
756
|
+
{
|
|
757
|
+
id: 'dev-plan-presets-provider',
|
|
758
|
+
label: T('服务商', 'Provider'),
|
|
759
|
+
hint: T('子代理使用的模型服务商。', 'Model provider used by subagents.'),
|
|
760
|
+
},
|
|
761
|
+
h(
|
|
762
|
+
'select',
|
|
763
|
+
{
|
|
764
|
+
name: 'childProvider',
|
|
765
|
+
style: { ...styles.control, ...(busy ? styles.controlDisabled : null) },
|
|
766
|
+
value: providerId,
|
|
767
|
+
disabled: busy || providers.length === 0,
|
|
768
|
+
onChange: (event) => changeProvider(event.target.value),
|
|
769
|
+
},
|
|
770
|
+
renderChoices(providerChoices(providers, providerId, T)),
|
|
771
|
+
),
|
|
772
|
+
),
|
|
773
|
+
h(
|
|
774
|
+
Field,
|
|
775
|
+
{
|
|
776
|
+
id: 'dev-plan-presets-model',
|
|
777
|
+
label: T('模型', 'Model'),
|
|
778
|
+
hint: T('所选服务商下可用的模型。', 'A model available under the selected provider.'),
|
|
779
|
+
},
|
|
780
|
+
h(
|
|
781
|
+
'select',
|
|
782
|
+
{
|
|
783
|
+
name: 'childModel',
|
|
784
|
+
style: { ...styles.control, ...(busy ? styles.controlDisabled : null) },
|
|
785
|
+
value: modelId,
|
|
786
|
+
disabled: busy || models.length === 0,
|
|
787
|
+
onChange: (event) => update({ childModel: event.target.value }),
|
|
788
|
+
},
|
|
789
|
+
renderChoices(modelChoices(models, modelId, T)),
|
|
790
|
+
),
|
|
791
|
+
),
|
|
792
|
+
),
|
|
793
|
+
catalogText
|
|
794
|
+
? h('div', { style: styles.hint, role: 'status' }, catalogText)
|
|
795
|
+
: null,
|
|
796
|
+
unavailableRouteText
|
|
797
|
+
? h('div', { style: styles.banner, role: 'status' }, unavailableRouteText)
|
|
798
|
+
: null,
|
|
799
|
+
h(
|
|
800
|
+
Field,
|
|
801
|
+
{
|
|
802
|
+
id: 'dev-plan-presets-effort',
|
|
803
|
+
label: T('推理强度(可选)', 'Reasoning effort (optional)'),
|
|
804
|
+
hint: T('留空就使用服务商默认值。', 'Leave empty to use the provider default.'),
|
|
805
|
+
},
|
|
806
|
+
h('input', {
|
|
807
|
+
name: 'childReasoningEffort',
|
|
808
|
+
style: { ...styles.control, ...(busy ? styles.controlDisabled : null) },
|
|
809
|
+
value: draft.childReasoningEffort || '',
|
|
810
|
+
disabled: busy,
|
|
811
|
+
spellCheck: false,
|
|
812
|
+
placeholder: T('留空 = 服务商默认', 'empty = provider default'),
|
|
813
|
+
onChange: (event) => update({ childReasoningEffort: event.target.value }),
|
|
814
|
+
}),
|
|
815
|
+
),
|
|
816
|
+
)
|
|
817
|
+
: h('div', { style: styles.hint }, T('加载中…', 'Loading…')),
|
|
818
|
+
route
|
|
819
|
+
? h(
|
|
820
|
+
'div',
|
|
821
|
+
{ style: styles.hint },
|
|
822
|
+
T('当前生效:', 'Currently effective: '),
|
|
823
|
+
h(
|
|
824
|
+
'span',
|
|
825
|
+
{ style: styles.mono },
|
|
826
|
+
route.provider + ' / ' + route.model + (route.reasoningEffort ? ' / ' + route.reasoningEffort : ''),
|
|
827
|
+
),
|
|
828
|
+
)
|
|
829
|
+
: null,
|
|
830
|
+
h(
|
|
831
|
+
'div',
|
|
832
|
+
{ style: styles.hint },
|
|
833
|
+
T(
|
|
834
|
+
'这四个委派工具(recon / review / scribe / develop)共用同一服务商与模型;只影响子代理,不动主会话。保存后以回读值为准。',
|
|
835
|
+
'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.',
|
|
836
|
+
),
|
|
837
|
+
),
|
|
838
|
+
),
|
|
839
|
+
|
|
840
|
+
h(
|
|
841
|
+
'fieldset',
|
|
842
|
+
{ style: { ...styles.card, margin: 0, minWidth: 0 } },
|
|
843
|
+
h('legend', { style: styles.legend }, T('模型守门', 'Model guard')),
|
|
844
|
+
h(
|
|
845
|
+
'div',
|
|
846
|
+
{ style: styles.hint },
|
|
847
|
+
T('只管理子代理,主会话永远不受影响。', 'Governs subagents only; the main session is never touched.'),
|
|
848
|
+
),
|
|
849
|
+
draft
|
|
850
|
+
? h(
|
|
851
|
+
React.Fragment,
|
|
852
|
+
null,
|
|
853
|
+
h(
|
|
854
|
+
Field,
|
|
855
|
+
{
|
|
856
|
+
id: 'dev-plan-presets-guard-mode',
|
|
857
|
+
label: T('守门方式', 'Guard behavior'),
|
|
858
|
+
},
|
|
859
|
+
h(
|
|
860
|
+
'select',
|
|
861
|
+
{
|
|
862
|
+
name: 'modelGuardMode',
|
|
863
|
+
style: { ...styles.control, ...(busy ? styles.controlDisabled : null) },
|
|
864
|
+
value: draft.modelGuardMode,
|
|
865
|
+
disabled: busy,
|
|
866
|
+
onChange: (event) => update({ modelGuardMode: event.target.value }),
|
|
867
|
+
},
|
|
868
|
+
h('option', { value: 'pin' }, 'pin — ' + T('发现用错就停止(默认)', 'stop a mismatch (default)')),
|
|
869
|
+
h('option', { value: 'audit' }, 'audit — ' + T('只记录,不阻止', 'record only, never block')),
|
|
870
|
+
h('option', { value: 'off' }, 'off — ' + T('不管理模型', 'no model management')),
|
|
871
|
+
),
|
|
872
|
+
),
|
|
873
|
+
h('div', { style: styles.hint }, guardHint),
|
|
874
|
+
h(
|
|
875
|
+
'div',
|
|
876
|
+
{ style: styles.row },
|
|
877
|
+
h(
|
|
878
|
+
'label',
|
|
879
|
+
{ style: styles.check, htmlFor: 'dev-plan-presets-guard-all' },
|
|
880
|
+
h('input', {
|
|
881
|
+
id: 'dev-plan-presets-guard-all',
|
|
882
|
+
name: 'guardAllSubagents',
|
|
883
|
+
type: 'checkbox',
|
|
884
|
+
checked: Boolean(draft.guardAllSubagents),
|
|
885
|
+
disabled: busy,
|
|
886
|
+
onChange: (event) => update({ guardAllSubagents: event.target.checked }),
|
|
887
|
+
}),
|
|
888
|
+
T('同时管理其他插件的子代理', 'Also govern subagents from other plugins'),
|
|
889
|
+
),
|
|
890
|
+
),
|
|
891
|
+
h(
|
|
892
|
+
'div',
|
|
893
|
+
{ style: styles.hint },
|
|
894
|
+
T(
|
|
895
|
+
'默认只管理“开发规划与交付”会话派出的子代理;勾选后管理所有子代理。',
|
|
896
|
+
'By default only subagents started from “Development planning & delivery” sessions are governed; check this to govern every subagent.',
|
|
897
|
+
),
|
|
898
|
+
),
|
|
899
|
+
h(
|
|
900
|
+
'div',
|
|
901
|
+
{ style: styles.row },
|
|
902
|
+
h(
|
|
903
|
+
'label',
|
|
904
|
+
{ style: styles.check },
|
|
905
|
+
h('input', {
|
|
906
|
+
type: 'checkbox',
|
|
907
|
+
name: 'killOnViolation',
|
|
908
|
+
checked: Boolean(draft.killOnViolation),
|
|
909
|
+
disabled: busy || draft.modelGuardMode !== 'pin',
|
|
910
|
+
onChange: (event) => update({ killOnViolation: event.target.checked }),
|
|
911
|
+
}),
|
|
912
|
+
T('越界时立即停止(仅 pin)', 'Stop on violation (pin only)'),
|
|
913
|
+
),
|
|
914
|
+
h(
|
|
915
|
+
'label',
|
|
916
|
+
{ style: styles.check },
|
|
917
|
+
h('input', {
|
|
918
|
+
type: 'checkbox',
|
|
919
|
+
name: 'honorExplicit',
|
|
920
|
+
checked: Boolean(draft.honorExplicit),
|
|
921
|
+
disabled: busy || draft.modelGuardMode !== 'pin',
|
|
922
|
+
onChange: (event) => update({ honorExplicit: event.target.checked }),
|
|
923
|
+
}),
|
|
924
|
+
T('尊重子代理自己选的模型(仅 pin)', 'Honor an explicit child model (pin only)'),
|
|
925
|
+
),
|
|
926
|
+
h(
|
|
927
|
+
'label',
|
|
928
|
+
{ style: styles.check },
|
|
929
|
+
h('input', {
|
|
930
|
+
type: 'checkbox',
|
|
931
|
+
name: 'audit',
|
|
932
|
+
checked: Boolean(draft.audit),
|
|
933
|
+
disabled: busy || draft.modelGuardMode === 'off',
|
|
934
|
+
onChange: (event) => update({ audit: event.target.checked }),
|
|
935
|
+
}),
|
|
936
|
+
T('记录详细日志', 'Write detailed logs'),
|
|
937
|
+
),
|
|
938
|
+
),
|
|
939
|
+
h(
|
|
940
|
+
'div',
|
|
941
|
+
{ style: styles.hint },
|
|
942
|
+
T(
|
|
943
|
+
'“audit”守门方式只是不阻止越界;“记录详细日志”是单独的日志开关,off 时不可用,日志只含模型与事件,不含凭据。',
|
|
944
|
+
'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.',
|
|
945
|
+
),
|
|
946
|
+
),
|
|
947
|
+
)
|
|
948
|
+
: null,
|
|
949
|
+
),
|
|
950
|
+
|
|
951
|
+
h(
|
|
952
|
+
'div',
|
|
953
|
+
{ style: styles.row },
|
|
954
|
+
h(
|
|
955
|
+
'button',
|
|
956
|
+
{
|
|
957
|
+
type: 'button',
|
|
958
|
+
style: {
|
|
959
|
+
...styles.primary,
|
|
960
|
+
...(busy || !draft || !dirty ? styles.buttonDisabled : null),
|
|
961
|
+
},
|
|
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,
|
|
984
|
+
),
|
|
985
|
+
notice
|
|
986
|
+
? h(
|
|
987
|
+
'span',
|
|
988
|
+
{
|
|
989
|
+
style: notice.kind === 'error' ? styles.noticeError : styles.noticeOk,
|
|
990
|
+
role: notice.kind === 'error' ? 'alert' : 'status',
|
|
991
|
+
'aria-live': notice.kind === 'error' ? 'assertive' : 'polite',
|
|
992
|
+
},
|
|
993
|
+
notice.text,
|
|
994
|
+
)
|
|
995
|
+
: 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.',
|
|
1004
|
+
),
|
|
1005
|
+
),
|
|
1006
|
+
|
|
1007
|
+
preset
|
|
1008
|
+
? h(
|
|
1009
|
+
'div',
|
|
1010
|
+
{ style: styles.card },
|
|
1011
|
+
h(
|
|
1012
|
+
'div',
|
|
1013
|
+
{ style: styles.row },
|
|
1014
|
+
h('span', { style: styles.title }, T('当前运行说明', 'Current runtime description')),
|
|
1015
|
+
h('span', { style: styles.mono }, preset.id),
|
|
1016
|
+
),
|
|
1017
|
+
h('div', { style: styles.hint }, preset.description),
|
|
1018
|
+
)
|
|
1019
|
+
: null,
|
|
1020
|
+
|
|
1021
|
+
h(
|
|
1022
|
+
'div',
|
|
1023
|
+
{ style: styles.card },
|
|
1024
|
+
h(
|
|
1025
|
+
'div',
|
|
1026
|
+
{ style: styles.row },
|
|
1027
|
+
h('span', { style: styles.title }, T('越界记录', 'Violations')),
|
|
1028
|
+
h('span', { style: styles.hint }, violations.length === 0 ? T('暂无', 'none') : String(violations.length)),
|
|
1029
|
+
),
|
|
1030
|
+
violations.length === 0
|
|
1031
|
+
? h('div', { style: styles.hint }, T('还没有子代理跑过非目标模型。', 'No subagent has used a non-target model.'))
|
|
1032
|
+
: violations.map((entry, index) =>
|
|
1033
|
+
h(
|
|
1034
|
+
'div',
|
|
1035
|
+
{ key: index, style: styles.hint },
|
|
1036
|
+
h('span', { style: styles.mono }, (entry.at || '') + ' · '),
|
|
1037
|
+
(entry.text || '') +
|
|
1038
|
+
' ' +
|
|
1039
|
+
T('(实际 ', '(actual ') +
|
|
1040
|
+
(entry.from || '?') +
|
|
1041
|
+
' → ' +
|
|
1042
|
+
T('期望 ', 'want ') +
|
|
1043
|
+
(entry.want || '?') +
|
|
1044
|
+
')',
|
|
1045
|
+
),
|
|
1046
|
+
),
|
|
1047
|
+
),
|
|
1048
|
+
)
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
function SettingsEntry(props) {
|
|
1052
|
+
if (props && props.view === 'summary') {
|
|
1053
|
+
return h(SettingsSummary, { locale: props.locale })
|
|
1054
|
+
}
|
|
1055
|
+
return h(SettingsPage, { locale: props.locale })
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
const exportedModule = {
|
|
1059
|
+
inject: ['slots', 'locale'],
|
|
1060
|
+
apply(ctx) {
|
|
1061
|
+
try {
|
|
1062
|
+
ctx.slots.inject('plugins.row.config', () =>
|
|
1063
|
+
ctx.slots.register(
|
|
1064
|
+
{
|
|
1065
|
+
name: 'plugins.row.config',
|
|
1066
|
+
id: 'dev-plan-presets-config',
|
|
1067
|
+
key: 'dsh-dev-plan-presets#dev-plan-presets',
|
|
1068
|
+
order: 10,
|
|
1069
|
+
},
|
|
1070
|
+
(props) => h(SettingsEntry, { ...props, locale: ctx.locale }),
|
|
1071
|
+
),
|
|
1072
|
+
)
|
|
1073
|
+
} catch (error) {
|
|
1074
|
+
try {
|
|
1075
|
+
console.error('[dsh-dev-plan-presets] client slot registration failed', error)
|
|
1076
|
+
} catch {
|
|
1077
|
+
/* ignore */
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
},
|
|
1081
|
+
}
|
|
1082
|
+
// 仅测试开关打开时暴露纯选择函数;生产模块对象不变。
|
|
1083
|
+
if (globalThis.__DSH_DEV_PLAN_PRESETS_TEST__ === true) {
|
|
1084
|
+
exportedModule.__test = { presetChoices, providerChoices, modelChoices, firstModelOf }
|
|
1085
|
+
}
|
|
1086
|
+
return exportedModule
|
|
1087
|
+
} catch (error) {
|
|
1088
|
+
try {
|
|
1089
|
+
console.error('[dsh-dev-plan-presets] client factory failed', error)
|
|
1090
|
+
} catch {
|
|
1091
|
+
/* ignore */
|
|
1092
|
+
}
|
|
1093
|
+
throw error
|
|
1094
|
+
}
|
|
1095
|
+
},
|
|
1096
|
+
})
|