@linxin666/dsh-liangshen 0.3.23 → 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.
Files changed (59) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +55 -41
  3. package/README.zh.md +54 -40
  4. package/cordis.patch.yml +3 -2
  5. package/icon.svg +3 -0
  6. package/lib/client.js +1380 -29
  7. package/lib/client.js.map +1 -1
  8. package/lib/index.js +616 -367
  9. package/lib/types/announce.test.d.ts +10 -0
  10. package/lib/types/client/LiangShenSettingsCard.d.ts +78 -0
  11. package/lib/types/client/PluginSettingsCard.d.ts +137 -0
  12. package/lib/types/client/index.d.ts +57 -4
  13. package/lib/types/client/lever-controller.d.ts +16 -2
  14. package/lib/types/client/locales.d.ts +40 -1
  15. package/lib/types/client/main-session.d.ts +32 -0
  16. package/lib/types/client/plugin-card-seat.d.ts +103 -0
  17. package/lib/types/client/settings-form.d.ts +197 -0
  18. package/lib/types/composition.d.ts +116 -0
  19. package/lib/types/composition.test.d.ts +7 -0
  20. package/lib/types/core/lever.d.ts +6 -3
  21. package/lib/types/index.d.ts +160 -33
  22. package/lib/types/index.test.d.ts +5 -0
  23. package/package.json +27 -18
  24. package/presets/liangshen/NOTICE +4 -4
  25. package/presets/liangshen/agent.cordis.yml +168 -123
  26. package/presets/liangshen/fact-ledger.mjs +141 -0
  27. package/presets/liangshen/guard.mjs +426 -0
  28. package/presets/liangshen/minimal-prompt.mjs +73 -38
  29. package/presets/liangshen/paging.mjs +232 -0
  30. package/presets/liangshen/tool-activate.mjs +176 -0
  31. package/presets/liangshen/tool-catalog.mjs +615 -219
  32. package/presets/liangshen/working-context.mjs +222 -0
  33. package/src/announce.test.ts +248 -55
  34. package/src/client/LiangShenLever.module.css +2 -0
  35. package/src/client/LiangShenLever.tsx +41 -10
  36. package/src/client/LiangShenSettingsCard.tsx +233 -0
  37. package/src/client/PluginSettingsCard.tsx +555 -0
  38. package/src/client/index.ts +102 -5
  39. package/src/client/lever-controller.ts +76 -9
  40. package/src/client/locales.ts +79 -1
  41. package/src/client/main-session.ts +43 -0
  42. package/src/client/plugin-card-seat.ts +192 -0
  43. package/src/client/settings-card.module.css +418 -0
  44. package/src/client/settings-form.ts +442 -0
  45. package/src/composition.test.ts +294 -0
  46. package/src/composition.ts +554 -0
  47. package/src/core/lever.ts +7 -4
  48. package/src/index.test.ts +68 -1
  49. package/src/index.ts +293 -101
  50. package/tools/benchmark-live-run.mjs +193 -63
  51. package/lib/types/schema.d.ts +0 -18
  52. package/lib/types/schema.test.d.ts +0 -1
  53. package/lib/types/sync.d.ts +0 -47
  54. package/lib/types/sync.test.d.ts +0 -1
  55. package/presets/liangshen/custom-bash.mjs +0 -213
  56. package/src/schema.test.ts +0 -64
  57. package/src/schema.ts +0 -110
  58. package/src/sync.test.ts +0 -224
  59. package/src/sync.ts +0 -222
@@ -0,0 +1,555 @@
1
+ // Generated by scripts/sync-shared.mjs from shared/client/settings/PluginSettingsCard.tsx. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
2
+ /**
3
+ * Family-shared chrome for plugin settings cards: a disclosure header naming
4
+ * the plugin and what its settings govern, the controls inside, and the save
5
+ * that writes them. Renders nothing while the namespace is unavailable — a
6
+ * deployment that does not compose the owning plugin should show no trace of
7
+ * it. Inlined into each consumer's client bundle; mirrors the official
8
+ * ui-plugin-config PluginCard in a self-contained slice.
9
+ */
10
+
11
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent, type ReactNode } from 'react'
12
+ import type { CardShell } from './settings-form.ts'
13
+ import css from './settings-card.module.css'
14
+
15
+ /** Copy keys the card chrome itself reads; every consumer locale carries this shared vocabulary. */
16
+ export const CARD_COPY_KEYS = [
17
+ 'settings.collapse',
18
+ 'settings.expand',
19
+ 'settings.notExposed',
20
+ 'settings.unsaved',
21
+ 'settings.readOnly',
22
+ 'settings.saveFailed',
23
+ 'settings.discard',
24
+ 'settings.save',
25
+ 'settings.saving',
26
+ ] as const
27
+
28
+ /** Copy key the card chrome itself reads. */
29
+ export type CardCopyKey = (typeof CARD_COPY_KEYS)[number]
30
+
31
+ /** Key domain for the plugin's own copy (inferred per consumer). */
32
+ export type SettingsCardKey<TKey extends string = string> = TKey | CardCopyKey
33
+
34
+ /** Card chrome shared by every plugin settings card. */
35
+ export interface PluginSettingsCardProps<TKey extends string = string> {
36
+ /** Locale reader for this card's copy. */
37
+ t: (key: SettingsCardKey<TKey>, params?: Record<string, string | number>) => string
38
+ /** Locale key of the plugin's name. */
39
+ titleKey: TKey
40
+ /** Locale key of the line describing what this plugin's settings govern. */
41
+ descriptionKey: TKey
42
+ /** Optional rich header description rendered instead of the plain t(descriptionKey) text (the plain text stays as the tooltip). */
43
+ descriptionNode?: ReactNode
44
+ /** The card's form state: availability, writability, and what a save would do. */
45
+ state: CardShell
46
+ /** Write every staged edit. */
47
+ onSave: () => void
48
+ /** Drop every staged edit. */
49
+ onDiscard: () => void
50
+ /**
51
+ * Render the controls expanded on arrival (still collapsible). Defaults to
52
+ * true: promoted first-level sections show their settings immediately.
53
+ */
54
+ defaultOpen?: boolean
55
+ /**
56
+ * Render without the collapse affordance: a static header and an always
57
+ * visible body. Used by first-level settings sections whose nav entry
58
+ * already provides the selection.
59
+ */
60
+ alwaysOpen?: boolean
61
+ /**
62
+ * Hide the save/discard footer: cards whose body applies its own changes
63
+ * immediately (an embedded external settings section) have no staged
64
+ * edits, so the footer would sit there permanently disabled.
65
+ */
66
+ hideFooter?: boolean
67
+ /** Render children even when the settings namespace is not exposed by the host. */
68
+ renderChildrenWhenNotExposed?: boolean
69
+ /** Hide the 'not exposed' warning banner when the settings namespace is not exposed. */
70
+ hideNotExposedNotice?: boolean
71
+ /** The plugin's controls. */
72
+ children: ReactNode
73
+ }
74
+
75
+ /**
76
+ * Render one plugin settings card.
77
+ * @param props - the plugin's copy keys, its form state, and its controls.
78
+ * @returns the card, or nothing while the namespace is still loading.
79
+ */
80
+ export function PluginSettingsCard<TKey extends string = string>(props: PluginSettingsCardProps<TKey>) {
81
+ const [open, setOpen] = useState(props.defaultOpen ?? true)
82
+ const { state, alwaysOpen } = props
83
+ if (!state.available) return null
84
+ const title = props.t(props.titleKey)
85
+ const description = props.t(props.descriptionKey)
86
+ const blocked = !state.dirty || state.invalid || state.saving
87
+ const expanded = alwaysOpen === true || open
88
+ const cardClass = expanded ? `${css.cardOpen} ${css.card}` : css.card
89
+ // With alwaysOpen the nav entry already provides the selection, so the
90
+ // header is a static title row instead of a disclosure button.
91
+ const header = alwaysOpen === true
92
+ ? (
93
+ <div className={css.headerStatic}>
94
+ <span className={css.headText}>
95
+ <span className={css.name} title={title}>{title}</span>
96
+ <span className={css.description} title={description}>{props.descriptionNode ?? description}</span>
97
+ </span>
98
+ {state.dirty ? <span className={css.pending} title={props.t('settings.unsaved')}>{props.t('settings.unsaved')}</span> : null}
99
+ </div>
100
+ )
101
+ : (
102
+ <button
103
+ type="button"
104
+ className={css.header}
105
+ aria-expanded={open}
106
+ aria-label={`${props.t(open ? 'settings.collapse' : 'settings.expand')}: ${title}`}
107
+ onClick={() => { setOpen(!open) }}
108
+ >
109
+ <span className={css.headText}>
110
+ <span className={css.name} title={title}>{title}</span>
111
+ <span className={css.description} title={description}>{props.descriptionNode ?? description}</span>
112
+ </span>
113
+ {state.dirty ? <span className={css.pending} title={props.t('settings.unsaved')}>{props.t('settings.unsaved')}</span> : null}
114
+ <svg
115
+ width="14"
116
+ height="14"
117
+ viewBox="0 0 14 14"
118
+ fill="none"
119
+ xmlns="http://www.w3.org/2000/svg"
120
+ className={open ? `${css.chevron} ${css.chevronOpen}` : css.chevron}
121
+ >
122
+ <path
123
+ d="M11.8486 5.5L11.4238 5.92383L8.69727 8.65137C8.44157 8.90706 8.21562 9.13382 8.01172 9.29785C7.79912 9.46883 7.55595 9.61756 7.25 9.66602C7.08435 9.69222 6.91565 9.69222 6.75 9.66602C6.44405 9.61756 6.20088 9.46883 5.98828 9.29785C5.78438 9.13382 5.55843 8.90706 5.30273 8.65137L2.57617 5.92383L2.15137 5.5L3 4.65137L3.42383 5.07617L6.15137 7.80273C6.42595 8.07732 6.59876 8.24849 6.74023 8.3623C6.87291 8.46904 6.92272 8.47813 6.9375 8.48047C6.97895 8.48703 7.02105 8.48703 7.0625 8.48047C7.07728 8.47813 7.12709 8.46904 7.25977 8.3623C7.40124 8.24849 7.57405 8.07732 7.84863 7.80273L10.5762 5.07617L11 4.65137L11.8486 5.5Z"
124
+ fill="currentColor"
125
+ />
126
+ </svg>
127
+ </button>
128
+ )
129
+ // The namespace exists but the Host does not serve it to this client (the
130
+ // official settings allowlist omits third-party namespaces): show a card
131
+ // that explains the gap instead of vanishing, so a missing card never
132
+ // reads as a missing plugin.
133
+ if (!state.exposed && props.renderChildrenWhenNotExposed !== true) {
134
+ const showNotice = props.hideNotExposedNotice !== true
135
+ return (
136
+ <li className={cardClass}>
137
+ {header}
138
+ {expanded
139
+ ? (
140
+ <div className={css.body}>
141
+ {showNotice ? <p className={css.notExposed} role="status">{props.t('settings.notExposed')}</p> : null}
142
+ </div>
143
+ )
144
+ : null}
145
+ </li>
146
+ )
147
+ }
148
+ return (
149
+ <li className={cardClass}>
150
+ {header}
151
+ {expanded
152
+ ? (
153
+ <div className={css.body}>
154
+ {!state.writable ? <p className={css.readOnly} role="status">{props.t('settings.readOnly')}</p> : null}
155
+ {props.children}
156
+ {props.hideFooter === true
157
+ ? null
158
+ : (
159
+ <div className={css.footer}>
160
+ {state.failed
161
+ ? (
162
+ <p className={css.failed} role="status">
163
+ {props.t('settings.saveFailed')}{state.failedReason ? ' - ' + state.failedReason : ''}
164
+ </p>
165
+ )
166
+ : null}
167
+ <button
168
+ type="button"
169
+ className={css.discard}
170
+ disabled={!state.dirty || state.saving}
171
+ onClick={props.onDiscard}
172
+ >
173
+ {props.t('settings.discard')}
174
+ </button>
175
+ <button
176
+ type="button"
177
+ className={css.save}
178
+ disabled={blocked}
179
+ onClick={props.onSave}
180
+ >
181
+ {props.t(!state.saving ? 'settings.save' : 'settings.saving')}
182
+ </button>
183
+ </div>
184
+ )}
185
+ </div>
186
+ )
187
+ : null}
188
+ </li>
189
+ )
190
+ }
191
+
192
+ /** Props every field control needs regardless of its value type. */
193
+ export interface FieldProps {
194
+ /** Stable id associating the label with its control. */
195
+ id: string
196
+ /** Visible label. */
197
+ label: string
198
+ /** One-line explanation rendered under the control. */
199
+ hint: string
200
+ /** Draft text this control renders. */
201
+ text: string
202
+ /** True when saving would leave a user-layer entry for this field. */
203
+ overridden: boolean
204
+ /** True when the draft is not a value this field accepts. */
205
+ invalid: boolean
206
+ /** Copy for the overridden badge. */
207
+ overriddenLabel: string
208
+ /** Copy for the reset control. */
209
+ resetLabel: string
210
+ /** Copy shown in place of the hint while the draft is invalid. */
211
+ invalidLabel: string
212
+ /** Disables every control (read-only document, or an unavailable namespace). */
213
+ disabled: boolean
214
+ /** Stage draft text. */
215
+ onEdit: (text: string) => void
216
+ /** Stage a clear so the field re-inherits the composition layer. */
217
+ onReset: () => void
218
+ }
219
+
220
+ /** A staged value field. `numeric` only hints the keypad: which drafts a field accepts is decided by its spec. */
221
+ export function ValueField(props: FieldProps & {
222
+ /** Hints a numeric keypad without narrowing what the control accepts. */
223
+ numeric?: boolean
224
+ /** Placeholder shown while the draft is empty. */
225
+ placeholder?: string
226
+ }) {
227
+ return (
228
+ <div className={css.field}>
229
+ <div className={css.head}>
230
+ <label className={css.label} htmlFor={props.id}>{props.label}</label>
231
+ {props.overridden
232
+ ? (
233
+ <span className={css.badges}>
234
+ <span className={css.badge}>{props.overriddenLabel}</span>
235
+ <button
236
+ type="button"
237
+ className={css.reset}
238
+ disabled={props.disabled}
239
+ onClick={props.onReset}
240
+ >
241
+ {props.resetLabel}
242
+ </button>
243
+ </span>
244
+ )
245
+ : null}
246
+ </div>
247
+ <input
248
+ id={props.id}
249
+ className={props.invalid ? css.inputInvalid : css.input}
250
+ type="text"
251
+ {...props.numeric === true ? { inputMode: 'numeric' as const } : {}}
252
+ {...props.invalid ? { 'aria-invalid': true } : {}}
253
+ value={props.text}
254
+ placeholder={props.placeholder ?? ''}
255
+ disabled={props.disabled}
256
+ onChange={(event) => { props.onEdit(event.target.value) }}
257
+ />
258
+ <p className={props.invalid ? css.invalid : css.hint}>
259
+ {props.invalid ? props.invalidLabel : props.hint}
260
+ </p>
261
+ </div>
262
+ )
263
+ }
264
+
265
+ const NON_SKIN_BODY_MARKERS = new Set(['dshSkinCenter', 'dshSidebarCollapsed'])
266
+ // 检测使用使用皮肤,用了皮肤退回原生select样式,防止样式冲突。默认外观下使用优化后的select样式。
267
+ function isSkinActive(): boolean {
268
+ const datasetList = Object.keys(document.body.dataset)
269
+ const isActive = datasetList.some(key => key.startsWith('dsh') && !NON_SKIN_BODY_MARKERS.has(key))
270
+ return isActive
271
+ }
272
+
273
+ interface SelectOption {
274
+ value: string
275
+ label: string
276
+ }
277
+
278
+ const SELECT_CLOSE_MS = 100
279
+
280
+ /**
281
+ * The shared dual-mode select control. While an appearance skin is active it
282
+ * renders the legacy native `<select>` untouched, so element-level skin
283
+ * selectors keep working; under the default appearance it renders a
284
+ * self-drawn `role="listbox"` popup whose open/close is transition-animated.
285
+ * Staged cards reach it through BooleanField/ChoiceField; immediate-apply
286
+ * editors (the side-card prefs) bind it directly through onEdit.
287
+ * 双模式下拉框:皮肤激活时用原生 select,默认外观用自绘动画弹层。
288
+ */
289
+ export function SelectField(props: {
290
+ id: string
291
+ options: ReadonlyArray<SelectOption>
292
+ value: string
293
+ disabled: boolean
294
+ invalid: boolean
295
+ onEdit: (text: string) => void
296
+ }) {
297
+ const { id, options, value } = props
298
+ const [open, setOpen] = useState(false)
299
+ const [closing, setClosing] = useState(false)
300
+ const [phase, setPhase] = useState<'initial' | 'open'>('initial')
301
+ const [activeIndex, setActiveIndex] = useState(0)
302
+ const closeTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
303
+ const wrapRef = useRef<HTMLDivElement | null>(null)
304
+ const popupRef = useRef<HTMLDivElement | null>(null)
305
+
306
+ const currentIndex = () => {
307
+ const index = options.findIndex(option => option.value === value)
308
+ return index >= 0 ? index : 0
309
+ }
310
+
311
+ const close = useCallback(() => {
312
+ if (closeTimer.current !== undefined) clearTimeout(closeTimer.current)
313
+ setClosing(true)
314
+ closeTimer.current = setTimeout(() => {
315
+ setClosing(false)
316
+ setOpen(false)
317
+ }, SELECT_CLOSE_MS)
318
+ }, [])
319
+
320
+ const openPopup = () => {
321
+ if (closeTimer.current !== undefined) clearTimeout(closeTimer.current)
322
+ setActiveIndex(currentIndex())
323
+ setPhase('initial')
324
+ setClosing(false)
325
+ setOpen(true)
326
+ }
327
+
328
+ const commit = (index: number) => {
329
+ const option = options[index]
330
+ if (option) props.onEdit(option.value)
331
+ close()
332
+ }
333
+
334
+ const onTriggerClick = () => {
335
+ if (props.disabled) return
336
+ if (open && !closing) close()
337
+ else openPopup()
338
+ }
339
+
340
+ const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {
341
+ if (props.disabled) return
342
+ const count = options.length
343
+ switch (event.key) {
344
+ case 'ArrowDown':
345
+ case 'ArrowUp':
346
+ case 'Enter':
347
+ case ' ':
348
+ event.preventDefault()
349
+ if (!open) {
350
+ openPopup()
351
+ } else if (!closing) {
352
+ if (event.key === 'ArrowDown') setActiveIndex(index => (index + 1) % count)
353
+ else if (event.key === 'ArrowUp') setActiveIndex(index => (index - 1 + count) % count)
354
+ else commit(activeIndex)
355
+ }
356
+ break
357
+ case 'Escape':
358
+ if (open) {
359
+ event.preventDefault()
360
+ event.stopPropagation()
361
+ close()
362
+ }
363
+ break
364
+ case 'Tab':
365
+ if (open) close()
366
+ break
367
+ }
368
+ }
369
+
370
+ useEffect(() => () => {
371
+ if (closeTimer.current !== undefined) clearTimeout(closeTimer.current)
372
+ }, [])
373
+ useLayoutEffect(() => {
374
+ if (open && !closing && phase === 'initial') {
375
+ void popupRef.current?.offsetHeight
376
+ setPhase('open')
377
+ }
378
+ }, [open, closing, phase])
379
+
380
+ useEffect(() => {
381
+ if (!open) return
382
+ const onPointerDown = (event: PointerEvent) => {
383
+ const target = event.target
384
+ if (target instanceof Node && !wrapRef.current?.contains(target)) close()
385
+ }
386
+ document.addEventListener('pointerdown', onPointerDown)
387
+ return () => document.removeEventListener('pointerdown', onPointerDown)
388
+ }, [open, close])
389
+
390
+ useEffect(() => {
391
+ if (props.disabled && open) close()
392
+ }, [props.disabled, open, close])
393
+
394
+ // 使用了皮肤则退回原生select样式防止样式冲突。
395
+ if (isSkinActive()) {
396
+ return (
397
+ <select
398
+ id={id}
399
+ className={css.select}
400
+ value={value}
401
+ disabled={props.disabled}
402
+ onChange={(event) => { props.onEdit(event.target.value) }}
403
+ >
404
+ {options.map(option => (
405
+ <option key={option.value} value={option.value}>{option.label}</option>
406
+ ))}
407
+ </select>
408
+ )
409
+ }
410
+
411
+ const label = options.find(option => option.value === value)?.label ?? ''
412
+ const popupClass = closing
413
+ ? `${css.selectPopup} ${css.selectPopupClose}`
414
+ : phase === 'open'
415
+ ? `${css.selectPopup} ${css.selectPopupOpen}`
416
+ : css.selectPopup
417
+ return (
418
+ <div className={css.selectWrap} ref={wrapRef}>
419
+ <button
420
+ type="button"
421
+ id={id}
422
+ className={`${css.select} ${css.selectButton}`}
423
+ disabled={props.disabled}
424
+ aria-haspopup="listbox"
425
+ aria-expanded={open}
426
+ aria-activedescendant={open ? `${id}-o${activeIndex}` : undefined}
427
+ aria-invalid={props.invalid || undefined}
428
+ onClick={onTriggerClick}
429
+ onKeyDown={onKeyDown}
430
+ >
431
+ <span className={css.selectLabel}>{label}</span>
432
+ <svg
433
+ width="14"
434
+ height="14"
435
+ viewBox="0 0 14 14"
436
+ fill="none"
437
+ xmlns="http://www.w3.org/2000/svg"
438
+ className={open ? `${css.selectChevron} ${css.selectChevronOpen}` : css.selectChevron}
439
+ aria-hidden="true"
440
+ >
441
+ <path
442
+ d="M11.8486 5.5L11.4238 5.92383L8.69727 8.65137C8.44157 8.90706 8.21562 9.13382 8.01172 9.29785C7.79912 9.46883 7.55595 9.61756 7.25 9.66602C7.08435 9.69222 6.91565 9.69222 6.75 9.66602C6.44405 9.61756 6.20088 9.46883 5.98828 9.29785C5.78438 9.13382 5.55843 8.90706 5.30273 8.65137L2.57617 5.92383L2.15137 5.5L3 4.65137L3.42383 5.07617L6.15137 7.80273C6.42595 8.07732 6.59876 8.24849 6.74023 8.3623C6.87291 8.46904 6.92272 8.47813 6.9375 8.48047C6.97895 8.48703 7.02105 8.48703 7.0625 8.48047C7.07728 8.47813 7.12709 8.46904 7.25977 8.3623C7.40124 8.24849 7.57405 8.07732 7.84863 7.80273L10.5762 5.07617L11 4.65137L11.8486 5.5Z"
443
+ fill="currentColor"
444
+ />
445
+ </svg>
446
+ </button>
447
+ {open
448
+ ? (
449
+ <div className={popupClass} role="listbox" ref={popupRef}>
450
+ {options.map((option, index) => (
451
+ <div
452
+ key={option.value}
453
+ id={`${id}-o${index}`}
454
+ role="option"
455
+ aria-selected={option.value === value}
456
+ className={`${css.selectOption}${option.value === value ? ` ${css.selectOptionSelected}` : ''}${index === activeIndex && !closing ? ` ${css.selectOptionActive}` : ''}`}
457
+ onClick={() => { commit(index) }}
458
+ >
459
+ {option.label}
460
+ </div>
461
+ ))}
462
+ </div>
463
+ )
464
+ : null}
465
+ </div>
466
+ )
467
+ }
468
+
469
+ /** A staged boolean field: 继承 / 开 / 关. */
470
+ export function BooleanField(props: FieldProps & {
471
+ /** Copy for the inherit option. */
472
+ inheritLabel: string
473
+ /** Copy for the on option. */
474
+ onLabel: string
475
+ /** Copy for the off option. */
476
+ offLabel: string
477
+ }) {
478
+ return (
479
+ <div className={css.field}>
480
+ <div className={css.head}>
481
+ <label className={css.label} htmlFor={props.id}>{props.label}</label>
482
+ {props.overridden
483
+ ? (
484
+ <span className={css.badges}>
485
+ <span className={css.badge}>{props.overriddenLabel}</span>
486
+ <button
487
+ type="button"
488
+ className={css.reset}
489
+ disabled={props.disabled}
490
+ onClick={props.onReset}
491
+ >
492
+ {props.resetLabel}
493
+ </button>
494
+ </span>
495
+ )
496
+ : null}
497
+ </div>
498
+ <SelectField
499
+ id={props.id}
500
+ options={[
501
+ { value: '', label: props.inheritLabel },
502
+ { value: 'true', label: props.onLabel },
503
+ { value: 'false', label: props.offLabel },
504
+ ]}
505
+ value={props.text}
506
+ disabled={props.disabled}
507
+ invalid={props.invalid}
508
+ onEdit={props.onEdit}
509
+ />
510
+ <p className={css.hint}>{props.hint}</p>
511
+ </div>
512
+ )
513
+ }
514
+
515
+ /** A staged enumerated field rendered as a select. */
516
+ export function ChoiceField(props: FieldProps & {
517
+ /** Copy for the inherit option (draft text is the empty string). */
518
+ inheritLabel: string
519
+ /** Choices rendered in order; `value` is the draft/stored text. */
520
+ choices: ReadonlyArray<{ value: string; label: string }>
521
+ }) {
522
+ return (
523
+ <div className={css.field}>
524
+ <div className={css.head}>
525
+ <label className={css.label} htmlFor={props.id}>{props.label}</label>
526
+ {props.overridden
527
+ ? (
528
+ <span className={css.badges}>
529
+ <span className={css.badge}>{props.overriddenLabel}</span>
530
+ <button
531
+ type="button"
532
+ className={css.reset}
533
+ disabled={props.disabled}
534
+ onClick={props.onReset}
535
+ >
536
+ {props.resetLabel}
537
+ </button>
538
+ </span>
539
+ )
540
+ : null}
541
+ </div>
542
+ <SelectField
543
+ id={props.id}
544
+ options={[{ value: '', label: props.inheritLabel }, ...props.choices]}
545
+ value={props.text}
546
+ disabled={props.disabled}
547
+ invalid={props.invalid}
548
+ onEdit={props.onEdit}
549
+ />
550
+ <p className={props.invalid ? css.invalid : css.hint}>
551
+ {props.invalid ? props.invalidLabel : props.hint}
552
+ </p>
553
+ </div>
554
+ )
555
+ }
@@ -24,20 +24,89 @@ import type {} from '@deepseek-ai/dsh-client-locale/client'
24
24
  // Type-only: pulls the ui-conversation SlotMap merge (the composer tool row).
25
25
  import type {} from '@deepseek-ai/dsh-client-ui-conversation/client'
26
26
  import type {} from '@deepseek-ai/dsh-client-ui-slots'
27
+ import type { ConfigForm, ConfigForms } from '@deepseek-ai/dsh-client-ui-settings/client'
28
+ // Type-only: pulls the settings-surface Context merge (ctx.configForms).
29
+ import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
27
30
  import { LiangShenLever } from './LiangShenLever.tsx'
28
31
  import { LeverController } from './lever-controller.ts'
32
+ import { LiangShenSettingsCard, LiangShenSettingsCardController, type LiangShenSettings } from './LiangShenSettingsCard.tsx'
29
33
  import { en, zh, type LiangShenKey } from './locales.ts'
34
+ import { installPluginCard } from './plugin-card-seat.ts'
30
35
 
31
36
  /** Locale namespace this half owns. */
32
37
  export const NS = 'liangshen'
33
38
 
34
39
  /**
35
- * Required client services: the slot registry, locale, sessions, and the roster
36
- * Remote. Both `remote` and `remote.agentPresets` are declared: the context
37
- * proxy refuses an uninjected service, and a nested service name does not imply
38
- * its parent, so reading `ctx.remote.agentPresets` needs `remote` as well.
40
+ * Settings namespace the settings card edits. Under the 0.1.7 settings
41
+ * contract the namespace IS the Host profile entry id, so this names the
42
+ * standalone row; the aggregate install mounts the generated
43
+ * `web-ui-liangshen` row instead and the family binder resolves between the
44
+ * two. Without that binder the card binds the entry id directly.
39
45
  */
40
- export const inject = ['slots', 'locale', 'sessions', 'remote', 'remote.agentPresets']
46
+ export const SETTINGS_NAMESPACE = 'liangshen'
47
+ const AGGREGATE_ENTRY_ID = 'web-ui-liangshen'
48
+ const LIANGSHEN_ENTRY_IDS: readonly string[] = [AGGREGATE_ENTRY_ID, 'ui-liangshen', SETTINGS_NAMESPACE]
49
+
50
+ function servedEntryId(forms: ConfigForms): string {
51
+ let served: readonly string[] | undefined
52
+ try {
53
+ served = forms.describe().getSnapshot().view?.namespaces.map(view => view.ns)
54
+ } catch {
55
+ served = undefined
56
+ }
57
+ if (!served || served.length === 0) return SETTINGS_NAMESPACE
58
+ return LIANGSHEN_ENTRY_IDS.find(id => served.includes(id)) ?? SETTINGS_NAMESPACE
59
+ }
60
+
61
+ /** Owner share of a plugin card (the section supplies nothing). */
62
+ export interface SettingsPluginItemOwnerProps {
63
+ /** Marker field: card owner props are intentionally empty. */
64
+ children?: never
65
+ }
66
+
67
+ declare module '@deepseek-ai/dsh-client-ui-slots' {
68
+ interface SlotMap {
69
+ /**
70
+ * The child slot the Web UI plugin group declares; this card registers into
71
+ * the group's list seat rather than the official bundle-configuration
72
+ * seat. Declared here so this package needs no dependency on the sibling UI
73
+ * package.
74
+ */
75
+ 'web-ui.plugin.item': { kind: 'list'; scope: 'root'; owner: SettingsPluginItemOwnerProps }
76
+ }
77
+ }
78
+
79
+ declare module '@deepseek-ai/cordis' {
80
+ interface Context {
81
+ /**
82
+ * Optional family settings binder provided by dsh-web-settings; absent when
83
+ * that group plugin is not installed, so callers bind the shared forms
84
+ * service (`ctx.configForms`) by profile entry id directly.
85
+ */
86
+ webUiSettings?: { bind<S>(spec: LiangShenFormSpec<S>): ConfigForm<S> }
87
+ }
88
+ }
89
+
90
+ /**
91
+ * One settings namespace a family card binds. The 0.1.7 client exports no spec
92
+ * type (the form controller takes it privately), so the binder's input shape is
93
+ * restated here.
94
+ */
95
+ export interface LiangShenFormSpec<T> {
96
+ /** Settings namespace registered by the owning host plugin. */
97
+ namespace: string
98
+ /** Narrow one wire section; undefined keeps the last accepted value. */
99
+ decode?: (section: unknown) => T | undefined
100
+ }
101
+
102
+ /**
103
+ * Required client services: the slot registry, locale, sessions, the shared
104
+ * configuration forms, and the roster Remote. Both `remote` and
105
+ * `remote.agentPresets` are declared: the context proxy refuses an uninjected
106
+ * service, and a nested service name does not imply its parent, so reading
107
+ * `ctx.remote.agentPresets` needs `remote` as well.
108
+ */
109
+ export const inject = ['slots', 'locale', 'sessions', 'configForms', 'remote', 'remote.agentPresets']
41
110
 
42
111
  declare module '@deepseek-ai/dsh-client-ui-slots' {
43
112
  interface LocaleNamespaceMap {
@@ -73,6 +142,34 @@ export function apply(ctx: ClientContext): void {
73
142
  // view still renders and reports what it knows.
74
143
  }
75
144
 
145
+ // Plugin configuration card: one staged form over the `liangshen` settings
146
+ // namespace, contributed to the Web UI plugin group beside the
147
+ // remote-access and task-board cards.
148
+ try {
149
+ // The family binder resolves the family namespace onto this row's profile
150
+ // entry id and binds the native shared form; a deployment without the group
151
+ // plugin addresses the entry id directly (the standalone bundle row id).
152
+ const binder = ctx.get('webUiSettings')
153
+ const settingsForm = binder !== undefined && typeof binder.bind === 'function'
154
+ ? binder.bind<LiangShenSettings>({ namespace: SETTINGS_NAMESPACE })
155
+ : ctx.configForms.get<LiangShenSettings>(servedEntryId(ctx.configForms))
156
+ const settingsCard = new LiangShenSettingsCardController(settingsForm)
157
+ // Card seat: the family group's list seat, or the official
158
+ // bundle-configuration seat when the group is not installed.
159
+ installPluginCard(ctx, {
160
+ bundle: '@linxin666/dsh-liangshen',
161
+ id: 'liangshen',
162
+ order: 120,
163
+ locale: NS,
164
+ inject: () => settingsCard.inject(),
165
+ component: LiangShenSettingsCard,
166
+ })
167
+ ctx.effect(() => () => { settingsCard.dispose() }, 'liangshen: settings card')
168
+ } catch {
169
+ // A missing settings surface leaves the lever working and the card absent;
170
+ // one unavailable service must not take the browser half down.
171
+ }
172
+
76
173
  ctx.slots.inject('conversation.input.right', () => {
77
174
  try {
78
175
  const unregister = ctx.slots.register({