@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,233 @@
1
+ /**
2
+ * LiangShen settings card: availability and the wire presentation. Registers
3
+ * into the `web-ui.plugin.item` child slot the Web UI plugin group renders,
4
+ * bound to the `liangshen` settings namespace (the Host profile entry id).
5
+ *
6
+ * The presentation field does not act on this client half: the Host applies it
7
+ * to the preset it declares to the agent-preset registry, so a session reads it
8
+ * from its preset. This card is the operator's only handle on it, which is why
9
+ * every field the Host schema carries appears here.
10
+ */
11
+
12
+ import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
13
+ import type { SnapshotStore } from '@deepseek-ai/dsh-client-store'
14
+ import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client'
15
+ import { BooleanField, ChoiceField, PluginSettingsCard, ValueField } from './PluginSettingsCard.tsx'
16
+ import { CardForm, booleanField, choiceField, numberField, type CardActions, type CardShell, type FieldState as CardFieldState } from './settings-form.ts'
17
+
18
+ /** Wire presentations the tool catalog accepts (mirrors the Host schema). */
19
+ export const PRESENTATION_CHOICES = ['ptc', 'native', 'both'] as const
20
+
21
+ /** Sensitivity presets for the circuit breaker (mirrors the Host schema). */
22
+ export const SENSITIVITY_CHOICES = ['conservative', 'balanced', 'aggressive'] as const
23
+
24
+ /** The LiangShen fields this card edits (the namespace's full schema). */
25
+ export interface LiangShenSettings {
26
+ /** Master switch for the plugin. */
27
+ enabled?: boolean
28
+ /** Whether the plugin announces itself in every agent's system prompt. */
29
+ announceToAgent?: boolean
30
+ /** Wire presentation the Host applies to the preset's tool-catalog row. */
31
+ presentation?: string
32
+ /** Master switch for the runtime degeneration circuit breaker. */
33
+ guardEnabled?: boolean
34
+ /** Sensitivity preset scaling the breaker's adaptive thresholds. */
35
+ guardSensitivity?: string
36
+ /** Per-step reasoning-character floor for the breaker's runaway ladder. */
37
+ guardStallReasoningChars?: number
38
+ /** Consecutive output-free reasoning steps for the breaker's slow-burn ladder. */
39
+ guardGlobalStallCap?: number
40
+ /** Identical-argument tool failures for the breaker's echo ladder. */
41
+ guardEchoFailures?: number
42
+ }
43
+
44
+ /** What the LiangShen card renders. */
45
+ export interface LiangShenSettingsCardState extends CardShell {
46
+ enabled: CardFieldState
47
+ announceToAgent: CardFieldState
48
+ presentation: CardFieldState
49
+ guardEnabled: CardFieldState
50
+ guardSensitivity: CardFieldState
51
+ guardStallReasoningChars: CardFieldState
52
+ guardGlobalStallCap: CardFieldState
53
+ guardEchoFailures: CardFieldState
54
+ }
55
+
56
+ /** The registration-side face the card's slot entry injects. */
57
+ export interface LiangShenSettingsCardFace extends CardActions {
58
+ hooks: {
59
+ /** Card snapshot bound by the renderer as useLiangShenSettingsCard. */
60
+ liangShenSettingsCard: SnapshotStore<LiangShenSettingsCardState>
61
+ }
62
+ }
63
+
64
+ /** Bridges the `liangshen` settings form onto the card's staged form. */
65
+ export class LiangShenSettingsCardController {
66
+ private readonly form: CardForm<LiangShenSettings>
67
+ private readonly store: SnapshotStore<LiangShenSettingsCardState>
68
+
69
+ /** @param scope - the bound configuration form of the entry that owns this namespace. */
70
+ constructor(scope: ConfigForm<LiangShenSettings>) {
71
+ this.form = new CardForm(scope, [
72
+ booleanField('enabled'),
73
+ booleanField('announceToAgent'),
74
+ choiceField('presentation', PRESENTATION_CHOICES),
75
+ booleanField('guardEnabled'),
76
+ choiceField('guardSensitivity', SENSITIVITY_CHOICES),
77
+ numberField('guardStallReasoningChars', { integer: true, min: 200 }),
78
+ numberField('guardGlobalStallCap', { integer: true, min: 2 }),
79
+ numberField('guardEchoFailures', { integer: true, min: 2 }),
80
+ ])
81
+ this.store = this.form.bind(() => this.projection())
82
+ }
83
+
84
+ private projection(): LiangShenSettingsCardState {
85
+ return {
86
+ ...this.form.shell(),
87
+ enabled: this.form.field('enabled'),
88
+ announceToAgent: this.form.field('announceToAgent'),
89
+ presentation: this.form.field('presentation'),
90
+ guardEnabled: this.form.field('guardEnabled'),
91
+ guardSensitivity: this.form.field('guardSensitivity'),
92
+ guardStallReasoningChars: this.form.field('guardStallReasoningChars'),
93
+ guardGlobalStallCap: this.form.field('guardGlobalStallCap'),
94
+ guardEchoFailures: this.form.field('guardEchoFailures'),
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Build the face the card's slot registration injects.
100
+ * @returns the card's snapshot and its form actions.
101
+ */
102
+ inject(): LiangShenSettingsCardFace {
103
+ return { hooks: { liangShenSettingsCard: this.store }, ...this.form.actions() }
104
+ }
105
+
106
+ /** Release the card's scope subscription and bound stores. */
107
+ dispose(): void {
108
+ this.form.dispose()
109
+ }
110
+ }
111
+
112
+ /** Props the renderer binds for the LiangShen card. */
113
+ export type LiangShenSettingsCardProps =
114
+ PropsRuntime<'web-ui.plugin.item'>
115
+ & PropsLocale<'liangshen'>
116
+ & InjectFace<LiangShenSettingsCardFace>
117
+
118
+ /**
119
+ * Render the LiangShen card.
120
+ * @param props - locale copy, the card snapshot, and its form actions.
121
+ * @returns the card.
122
+ */
123
+ export function LiangShenSettingsCard(props: LiangShenSettingsCardProps) {
124
+ const { t } = props
125
+ const state = props.useLiangShenSettingsCard((snapshot: LiangShenSettingsCardState) => snapshot)
126
+ const fieldProps = {
127
+ overriddenLabel: t('settings.overridden'),
128
+ resetLabel: t('settings.reset'),
129
+ invalidLabel: t('settings.invalidValue'),
130
+ disabled: !state.writable,
131
+ inheritLabel: t('settings.inherit'),
132
+ }
133
+ return (
134
+ <PluginSettingsCard
135
+ t={t}
136
+ titleKey="settings.title"
137
+ descriptionKey="settings.description"
138
+ defaultOpen={false}
139
+ state={state}
140
+ renderChildrenWhenNotExposed
141
+ hideNotExposedNotice
142
+ onSave={props.save}
143
+ onDiscard={props.discard}
144
+ >
145
+ <BooleanField
146
+ id="settings-liangshen-enabled"
147
+ label={t('settings.enabled')}
148
+ hint={t('settings.enabledHint')}
149
+ onLabel={t('settings.on')}
150
+ offLabel={t('settings.off')}
151
+ {...fieldProps}
152
+ {...state.enabled}
153
+ onEdit={(text) => { props.edit('enabled', text) }}
154
+ onReset={() => { props.resetField('enabled') }}
155
+ />
156
+ <BooleanField
157
+ id="settings-liangshen-announce"
158
+ label={t('settings.announceToAgent')}
159
+ hint={t('settings.announceToAgentHint')}
160
+ onLabel={t('settings.on')}
161
+ offLabel={t('settings.off')}
162
+ {...fieldProps}
163
+ {...state.announceToAgent}
164
+ onEdit={(text) => { props.edit('announceToAgent', text) }}
165
+ onReset={() => { props.resetField('announceToAgent') }}
166
+ />
167
+ <ChoiceField
168
+ id="settings-liangshen-presentation"
169
+ label={t('settings.presentation')}
170
+ hint={t('settings.presentationHint')}
171
+ choices={PRESENTATION_CHOICES.map(choice => ({ value: choice, label: t(`presentation.${choice}`) }))}
172
+ {...fieldProps}
173
+ {...state.presentation}
174
+ onEdit={(text) => { props.edit('presentation', text) }}
175
+ onReset={() => { props.resetField('presentation') }}
176
+ />
177
+ <BooleanField
178
+ id="settings-liangshen-guard-enabled"
179
+ label={t('settings.guardEnabled')}
180
+ hint={t('settings.guardEnabledHint')}
181
+ onLabel={t('settings.on')}
182
+ offLabel={t('settings.off')}
183
+ {...fieldProps}
184
+ {...state.guardEnabled}
185
+ onEdit={(text) => { props.edit('guardEnabled', text) }}
186
+ onReset={() => { props.resetField('guardEnabled') }}
187
+ />
188
+ <ChoiceField
189
+ id="settings-liangshen-guard-sensitivity"
190
+ label={t('settings.guardSensitivity')}
191
+ hint={t('settings.guardSensitivityHint')}
192
+ choices={SENSITIVITY_CHOICES.map(choice => ({ value: choice, label: t(`sensitivity.${choice}`) }))}
193
+ {...fieldProps}
194
+ {...state.guardSensitivity}
195
+ onEdit={(text) => { props.edit('guardSensitivity', text) }}
196
+ onReset={() => { props.resetField('guardSensitivity') }}
197
+ />
198
+ <ValueField
199
+ id="settings-liangshen-guard-stall-chars"
200
+ numeric
201
+ label={t('settings.guardStallChars')}
202
+ hint={t('settings.guardStallCharsHint')}
203
+ placeholder="8000"
204
+ {...fieldProps}
205
+ {...state.guardStallReasoningChars}
206
+ onEdit={(text) => { props.edit('guardStallReasoningChars', text) }}
207
+ onReset={() => { props.resetField('guardStallReasoningChars') }}
208
+ />
209
+ <ValueField
210
+ id="settings-liangshen-guard-global-cap"
211
+ numeric
212
+ label={t('settings.guardGlobalCap')}
213
+ hint={t('settings.guardGlobalCapHint')}
214
+ placeholder="4"
215
+ {...fieldProps}
216
+ {...state.guardGlobalStallCap}
217
+ onEdit={(text) => { props.edit('guardGlobalStallCap', text) }}
218
+ onReset={() => { props.resetField('guardGlobalStallCap') }}
219
+ />
220
+ <ValueField
221
+ id="settings-liangshen-guard-echo"
222
+ numeric
223
+ label={t('settings.guardEchoFailures')}
224
+ hint={t('settings.guardEchoFailuresHint')}
225
+ placeholder="3"
226
+ {...fieldProps}
227
+ {...state.guardEchoFailures}
228
+ onEdit={(text) => { props.edit('guardEchoFailures', text) }}
229
+ onReset={() => { props.resetField('guardEchoFailures') }}
230
+ />
231
+ </PluginSettingsCard>
232
+ )
233
+ }