@linxin666/dsh-liangshen 0.4.5 → 0.4.6

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.
@@ -1,17 +1,19 @@
1
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).
2
+ * LiangShen settings card: availability, the wire presentation, and the
3
+ * dispatcher identity. Registers into the `web-ui.plugin.item` child slot the
4
+ * Web UI plugin group renders, bound to the `liangshen` settings namespace
5
+ * (the Host profile entry id).
5
6
  *
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.
7
+ * No field acts on this client half: the Host applies the presentation and the
8
+ * dispatcher switch to the preset it declares to the agent-preset registry, so
9
+ * a session reads both from its preset. The card is the operator's only handle
10
+ * on them, which is why every field the Host schema carries appears here.
10
11
  */
11
12
 
12
13
  import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
13
14
  import type { SnapshotStore } from '@deepseek-ai/dsh-client-store'
14
15
  import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client'
16
+ import { LiangShenMark } from './LiangShenMark.tsx'
15
17
  import { BooleanField, ChoiceField, PluginSettingsCard, ValueField } from './PluginSettingsCard.tsx'
16
18
  import { CardForm, booleanField, choiceField, numberField, type CardActions, type CardShell, type FieldState as CardFieldState } from './settings-form.ts'
17
19
 
@@ -29,6 +31,8 @@ export interface LiangShenSettings {
29
31
  announceToAgent?: boolean
30
32
  /** Wire presentation the Host applies to the preset's tool-catalog row. */
31
33
  presentation?: string
34
+ /** Whether the preset appends the dispatcher rules section after the persona. */
35
+ dispatcher?: boolean
32
36
  /** Master switch for the runtime degeneration circuit breaker. */
33
37
  guardEnabled?: boolean
34
38
  /** Sensitivity preset scaling the breaker's adaptive thresholds. */
@@ -46,6 +50,7 @@ export interface LiangShenSettingsCardState extends CardShell {
46
50
  enabled: CardFieldState
47
51
  announceToAgent: CardFieldState
48
52
  presentation: CardFieldState
53
+ dispatcher: CardFieldState
49
54
  guardEnabled: CardFieldState
50
55
  guardSensitivity: CardFieldState
51
56
  guardStallReasoningChars: CardFieldState
@@ -72,6 +77,7 @@ export class LiangShenSettingsCardController {
72
77
  booleanField('enabled'),
73
78
  booleanField('announceToAgent'),
74
79
  choiceField('presentation', PRESENTATION_CHOICES),
80
+ booleanField('dispatcher'),
75
81
  booleanField('guardEnabled'),
76
82
  choiceField('guardSensitivity', SENSITIVITY_CHOICES),
77
83
  numberField('guardStallReasoningChars', { integer: true, min: 200 }),
@@ -87,6 +93,7 @@ export class LiangShenSettingsCardController {
87
93
  enabled: this.form.field('enabled'),
88
94
  announceToAgent: this.form.field('announceToAgent'),
89
95
  presentation: this.form.field('presentation'),
96
+ dispatcher: this.form.field('dispatcher'),
90
97
  guardEnabled: this.form.field('guardEnabled'),
91
98
  guardSensitivity: this.form.field('guardSensitivity'),
92
99
  guardStallReasoningChars: this.form.field('guardStallReasoningChars'),
@@ -135,6 +142,7 @@ export function LiangShenSettingsCard(props: LiangShenSettingsCardProps) {
135
142
  t={t}
136
143
  titleKey="settings.title"
137
144
  descriptionKey="settings.description"
145
+ icon={<LiangShenMark />}
138
146
  defaultOpen={false}
139
147
  state={state}
140
148
  renderChildrenWhenNotExposed
@@ -174,6 +182,17 @@ export function LiangShenSettingsCard(props: LiangShenSettingsCardProps) {
174
182
  onEdit={(text) => { props.edit('presentation', text) }}
175
183
  onReset={() => { props.resetField('presentation') }}
176
184
  />
185
+ <BooleanField
186
+ id="settings-liangshen-dispatcher"
187
+ label={t('settings.dispatcher')}
188
+ hint={t('settings.dispatcherHint')}
189
+ onLabel={t('settings.on')}
190
+ offLabel={t('settings.off')}
191
+ {...fieldProps}
192
+ {...state.dispatcher}
193
+ onEdit={(text) => { props.edit('dispatcher', text) }}
194
+ onReset={() => { props.resetField('dispatcher') }}
195
+ />
177
196
  <BooleanField
178
197
  id="settings-liangshen-guard-enabled"
179
198
  label={t('settings.guardEnabled')}
@@ -200,7 +219,7 @@ export function LiangShenSettingsCard(props: LiangShenSettingsCardProps) {
200
219
  numeric
201
220
  label={t('settings.guardStallChars')}
202
221
  hint={t('settings.guardStallCharsHint')}
203
- placeholder="8000"
222
+ placeholder={t('settings.guardAdaptive')}
204
223
  {...fieldProps}
205
224
  {...state.guardStallReasoningChars}
206
225
  onEdit={(text) => { props.edit('guardStallReasoningChars', text) }}
@@ -211,7 +230,7 @@ export function LiangShenSettingsCard(props: LiangShenSettingsCardProps) {
211
230
  numeric
212
231
  label={t('settings.guardGlobalCap')}
213
232
  hint={t('settings.guardGlobalCapHint')}
214
- placeholder="4"
233
+ placeholder={t('settings.guardAdaptive')}
215
234
  {...fieldProps}
216
235
  {...state.guardGlobalStallCap}
217
236
  onEdit={(text) => { props.edit('guardGlobalStallCap', text) }}
@@ -222,7 +241,7 @@ export function LiangShenSettingsCard(props: LiangShenSettingsCardProps) {
222
241
  numeric
223
242
  label={t('settings.guardEchoFailures')}
224
243
  hint={t('settings.guardEchoFailuresHint')}
225
- placeholder="3"
244
+ placeholder={t('settings.guardAdaptive')}
226
245
  {...fieldProps}
227
246
  {...state.guardEchoFailures}
228
247
  onEdit={(text) => { props.edit('guardEchoFailures', text) }}
@@ -29,6 +29,8 @@ export const zh = {
29
29
  'settings.announceToAgentHint': '开启后向每一轮 agent 系统提示注入本插件公告;默认关闭以保持提示词干净。',
30
30
  'settings.presentation': '工具面呈现方式',
31
31
  'settings.presentationHint': '写入本插件声明的预设的 tool-catalog 行:both(出厂默认)让原生清单与 run_code 同驻(原生直调优先);native 保持原生工具清单;ptc 把 wire 收拢为 run_code。改动立即生效,但已开始的会话保持其已声明的组合。',
32
+ 'settings.dispatcher': '调度者身份',
33
+ 'settings.dispatcherHint': '开启后本模式按调度 Agent 工作:先分诊复杂度(L0/L1 直接执行,L2 走完整流程),L2 任务先澄清访谈再规划,由主代理派发子代理并逐层审查与验收。与工具面呈现方式无关,只决定身份与流程纪律。出厂默认开启;关闭后回到仅含工作纪律的极简 persona。',
32
34
  'settings.on': '开',
33
35
  'settings.off': '关',
34
36
  'settings.inherit': '继承(跟随部署默认)',
@@ -48,18 +50,19 @@ export const zh = {
48
50
  'presentation.native': 'native(原生工具清单)',
49
51
  'presentation.both': 'both(两者同驻)',
50
52
  'settings.guardEnabled': '启用退化熔断器',
51
- 'settings.guardEnabledHint': '运行时检测思考退化(连续零产出长思考 / 同参重复失败),触发时注入熔断提示并临时下调推理档位。关闭后不干预任何请求。',
53
+ 'settings.guardEnabledHint': '运行时检测思考退化(连续零产出长思考 / 同参重复失败),触发时注入熔断提示;仅停摆信号额外临时下调推理档位(max→high,不下探到甜区以下)。关闭后不干预任何请求。',
52
54
  'settings.guardStallChars': '单步暴走字符阈值',
53
- 'settings.guardStallCharsHint': '单条推理达到该字符数且零产出即触发熔断(按 V4.1 官方 384K 最大输出校准;默认 8000,约 2-4K 思考 token)。',
55
+ 'settings.guardStallCharsHint': '留空即按推理档位自适应:max 档 8000 / high 档 12000 / low 档 20000 字符(按 V4.1 官方 384K 最大输出校准,约 2-4K 思考 token),再按灵敏度预设缩放。填写本字段则以该固定值覆盖所有档位。',
54
56
  'settings.guardGlobalCap': '慢烧连续步数',
55
- 'settings.guardGlobalCapHint': '连续多少步有真实推理但零产出触发慢烧熔断(默认 4;步数越小越敏感,真实长调查建议调大)。',
57
+ 'settings.guardGlobalCapHint': '留空即按灵敏度预设缩放(均衡档为 4);provider 不持久化推理文本的会话也以此为兜底步骤计数。填写本字段则以该固定值覆盖。步数越小越敏感,真实长调查建议调大。',
56
58
  'settings.guardSensitivity': '熔断灵敏度',
57
- 'settings.guardSensitivityHint': '整体缩放熔断阈值:保守(更少打断,阈值×1.5)、均衡(出厂校准值)、激进(更早触发,阈值×0.5)。阈值随推理档位自适应:max 档 8000 / high 档 12000 / low 档 20000 字符。',
59
+ 'settings.guardSensitivityHint': '整体缩放熔断阈值:保守(更少打断,阈值×1.5)、均衡(出厂校准值)、激进(更早触发,阈值×0.5)。仅在对应细调字段留空时生效——阈值随推理档位自适应:max 档 8000 / high 档 12000 / low 档 20000 字符。',
58
60
  'sensitivity.conservative': '保守(少打断)',
59
61
  'sensitivity.balanced': '均衡(默认)',
60
62
  'sensitivity.aggressive': '激进(早触发)',
61
63
  'settings.guardEchoFailures': '同参连续失败次数',
62
- 'settings.guardEchoFailuresHint': '同一工具以相同参数连续失败多少次触发空转熔断(默认 3)。',
64
+ 'settings.guardEchoFailuresHint': '留空即按灵敏度预设缩放(均衡档为 3);填写本字段则以该固定值覆盖。空转信号只注入熔断消息,不下调推理档位。',
65
+ 'settings.guardAdaptive': '自适应',
63
66
  }
64
67
 
65
68
  /** English counterpart; the key set mirrors {@link zh} exactly. */
@@ -87,6 +90,8 @@ export const en: Record<keyof typeof zh, string> = {
87
90
  'settings.announceToAgentHint': 'Adds this plugin announcement to every agent system prompt; off by default so prompts stay clean.',
88
91
  'settings.presentation': 'Wire presentation',
89
92
  'settings.presentationHint': 'Written into the tool-catalog row of the preset this plugin declares: both (the shipped default) keeps the roster and run_code co-resident (direct native calls first); native keeps the native roster; ptc collapses the wire to run_code. A change re-declares the preset immediately; sessions that already started keep the composition they declared.',
93
+ 'settings.dispatcher': 'Dispatcher identity',
94
+ 'settings.dispatcherHint': 'When on, the mode works as a dispatcher agent: it triages complexity first (L0/L1 work is done directly, an L2 task runs the full flow), clarifies an L2 task through an interview before planning, and the lead agent dispatches subagents and reviews and accepts them layer by layer. It is unrelated to the wire presentation and decides identity and process discipline only. On by default; switching it off returns the prompt to the bare persona with its working discipline.',
90
95
  'settings.on': 'On',
91
96
  'settings.off': 'Off',
92
97
  'settings.inherit': 'Inherit (deployment default)',
@@ -106,18 +111,19 @@ export const en: Record<keyof typeof zh, string> = {
106
111
  'presentation.native': 'native (native tool roster)',
107
112
  'presentation.both': 'both (both co-resident)',
108
113
  'settings.guardEnabled': 'Degeneration circuit breaker',
109
- 'settings.guardEnabledHint': 'Detects reasoning degeneration at runtime (consecutive zero-output long reasoning / repeated identical-argument failures), injecting a breaker message and stepping the reasoning effort down when it fires. Disabled means requests are never touched.',
114
+ 'settings.guardEnabledHint': 'Detects reasoning degeneration at runtime (consecutive zero-output long reasoning / repeated identical-argument failures) and injects a breaker message; only a stall also steps the reasoning effort down (max to high, never below the sweet spot). Disabled means requests are never touched.',
110
115
  'settings.guardStallChars': 'Runaway reasoning character floor',
111
- 'settings.guardStallCharsHint': 'One reasoning block reaching this many characters with no output fires the breaker (calibrated against V4.1\'s official 384K max output; default 8000, roughly 2-4K thinking tokens).',
116
+ 'settings.guardStallCharsHint': 'Leave empty to adapt to the reasoning effort: 8000 at max / 12000 at high / 20000 at low characters (calibrated against V4.1\'s official 384K max output, roughly 2-4K thinking tokens), then scaled by the sensitivity preset. Setting a value pins it for every effort level.',
112
117
  'settings.guardGlobalCap': 'Slow-burn step count',
113
- 'settings.guardGlobalCapHint': 'Consecutive output-free steps of real reasoning that fire the slow-burn ladder (default 4; lower is more sensitive — raise it for genuinely long investigations).',
118
+ 'settings.guardGlobalCapHint': 'Leave empty to scale with the sensitivity preset (4 at balanced); it is also the fallback step count for a session whose provider persists no reasoning text. Setting a value pins it. Lower is more sensitive — raise it for genuinely long investigations.',
114
119
  'settings.guardSensitivity': 'Breaker sensitivity',
115
- 'settings.guardSensitivityHint': 'Scales every breaker threshold: conservative (fewer interruptions, x1.5), balanced (the calibrated defaults), aggressive (fires earlier, x0.5). Thresholds adapt to the reasoning effort: 8000 at max / 12000 at high / 20000 at low.',
120
+ 'settings.guardSensitivityHint': 'Scales every breaker threshold: conservative (fewer interruptions, x1.5), balanced (the calibrated defaults), aggressive (fires earlier, x0.5). It applies only where the matching fine-tuning field is left empty — thresholds adapt to the reasoning effort: 8000 at max / 12000 at high / 20000 at low.',
116
121
  'sensitivity.conservative': 'Conservative (fewer interruptions)',
117
122
  'sensitivity.balanced': 'Balanced (default)',
118
123
  'sensitivity.aggressive': 'Aggressive (fires earlier)',
119
124
  'settings.guardEchoFailures': 'Identical-argument failures',
120
- 'settings.guardEchoFailuresHint': 'Identical-argument failures of the same tool in a row that fire the echo ladder (default 3).',
125
+ 'settings.guardEchoFailuresHint': 'Leave empty to scale with the sensitivity preset (3 at balanced); setting a value pins it. An echo only injects the breaker message — it never steps the reasoning effort down.',
126
+ 'settings.guardAdaptive': 'Adaptive',
121
127
  }
122
128
 
123
129
  /** Every key in the locale catalog. */
@@ -86,6 +86,11 @@ export interface PluginCardSeat {
86
86
  label?: () => string
87
87
  /** Locale namespace the card renders with. */
88
88
  locale: string
89
+ /**
90
+ * Child slots this card declares and renders. Forwarded to whichever seat
91
+ * the host renders; absent for a card that declares none.
92
+ */
93
+ children?: Record<string, unknown>
89
94
  /** Business-face factory of the registration. */
90
95
  inject?: () => object
91
96
  /**
@@ -162,12 +167,14 @@ export function installPluginCard(ctx: PluginCardContext, seat: PluginCardSeat):
162
167
  ...(seat.order === undefined ? {} : { order: seat.order }),
163
168
  ...(seat.label === undefined ? {} : { label: seat.label }),
164
169
  locale: seat.locale,
170
+ ...(seat.children === undefined ? {} : { children: seat.children }),
165
171
  ...(seat.inject === undefined ? {} : { inject }),
166
172
  }
167
173
  : {
168
174
  name: OFFICIAL_PLUGIN_CARD_SEAT,
169
175
  key: seat.bundle,
170
176
  locale: seat.locale,
177
+ ...(seat.children === undefined ? {} : { children: seat.children }),
171
178
  ...(seat.inject === undefined ? {} : { inject }),
172
179
  }) as never, component) as () => void
173
180
  current = target
@@ -77,6 +77,14 @@ describe('readCompositionRows', () => {
77
77
  expect(catalog['pagedToolPatterns']).toEqual(['mcp__*'])
78
78
  })
79
79
 
80
+ it('operator reads the shipped dispatcher switch ON on the minimal-prompt row', () => {
81
+ // Given the factory composition, When the operator reads the minimal-prompt
82
+ // row, Then it declares `dispatcher: true`: the shipped default appends the
83
+ // dispatcher block, and the key is present so the overlay writes a value
84
+ // rather than inventing a key the row never carried.
85
+ expect(configOf(rowOf(rows(), 'minimal-prompt'))['dispatcher']).toBe(true)
86
+ })
87
+
80
88
  it('operator keeps a literal block scalar verbatim', () => {
81
89
  // Given the persona row's `prefix: |-` scalar, When the operator reads it,
82
90
  // Then the prose is content and the next composition row ends it.
@@ -235,6 +243,22 @@ describe('applyPresetOverrides', () => {
235
243
  expect(applyPresetOverrides(parsed, {})).toEqual(parsed)
236
244
  })
237
245
 
246
+ it('operator leaves every guard key out of the row while the settings are unset', () => {
247
+ // Given the shipped rows and settings whose guard overrides are unset (the
248
+ // factory state), When the operator applies the overlay, Then the guard row
249
+ // carries no fine-tuning key at all, so the guard's own effort-adaptive
250
+ // thresholds and sensitivity preset are what a session actually runs.
251
+ const applied = applyPresetOverrides(rows(), {
252
+ presentation: 'both',
253
+ guardEnabled: true,
254
+ guardSensitivity: 'balanced',
255
+ guardStallReasoningChars: undefined,
256
+ guardGlobalStallCap: undefined,
257
+ guardEchoFailures: undefined,
258
+ })
259
+ expect(configOf(rowOf(applied, 'guard'))).toEqual({ enabled: true, sensitivity: 'balanced' })
260
+ })
261
+
238
262
  it('operator writes the settings into the rows that carry them', () => {
239
263
  // Given committed settings, When the operator applies the overlay, Then
240
264
  // the tool-catalog and guard rows carry them and nothing else moves.
@@ -258,6 +282,38 @@ describe('applyPresetOverrides', () => {
258
282
  expect(rowOf(applied, 'minimal-prompt')).toEqual(rowOf(rows(), 'minimal-prompt'))
259
283
  })
260
284
 
285
+ it('operator leaves the dispatcher key out of the row while the setting is unset', () => {
286
+ // Given the shipped rows and no dispatcher choice, When the operator
287
+ // applies the overlay, Then the minimal-prompt row keeps exactly the keys
288
+ // the composition declares: the switch is only ever written when a caller
289
+ // committed a value for it, never invented as a factory default.
290
+ const applied = applyPresetOverrides(rows(), { presentation: 'both' })
291
+ expect(rowOf(applied, 'minimal-prompt')).toEqual(rowOf(rows(), 'minimal-prompt'))
292
+ expect(configOf(rowOf(applied, 'minimal-prompt'))['dispatcher']).toBe(true)
293
+ })
294
+
295
+ it('operator writes the dispatcher switch into the minimal-prompt row', () => {
296
+ // Given a committed dispatcher choice, When the operator applies the
297
+ // overlay, Then the minimal-prompt row carries it and the presentation key
298
+ // in the tool-catalog row is untouched: the two settings are orthogonal,
299
+ // and the row's other config keys survive.
300
+ const applied = applyPresetOverrides(rows(), { presentation: 'both', dispatcher: true })
301
+ const prompt = configOf(rowOf(applied, 'minimal-prompt'))
302
+ expect(prompt['dispatcher']).toBe(true)
303
+ expect(prompt['keepPlanPolicy']).toBe(true)
304
+ expect(prompt['instructionSource']).toBe('host')
305
+ expect(configOf(rowOf(applied, 'tool-catalog'))['presentation']).toBe('both')
306
+ expect(rowOf(applied, 'guard')).toEqual(rowOf(rows(), 'guard'))
307
+ })
308
+
309
+ it('operator turns the dispatcher switch back off through the same key', () => {
310
+ // Given a committed `false` for the dispatcher switch, When the operator
311
+ // applies the overlay, Then the row carries that value: the key is written
312
+ // for both directions, so a session can return to the bare persona.
313
+ const applied = applyPresetOverrides(rows(), { dispatcher: false })
314
+ expect(configOf(rowOf(applied, 'minimal-prompt'))['dispatcher']).toBe(false)
315
+ })
316
+
261
317
  it('operator is never given a row the composition does not carry', () => {
262
318
  // Given a composition with no tool-catalog row, When the operator applies
263
319
  // a presentation choice, Then no row is invented for it.
@@ -490,22 +490,25 @@ export function readPresetDefinition(id: string, dir: string): PresetDefinition
490
490
  *
491
491
  * The settings surface edits the PLUGIN's own Config, while the values that
492
492
  * shape a session live in the declared preset's rows; applying them here is what
493
- * connects the two. Every field is optional — an absent value leaves the shipped
494
- * row exactly as the composition declares it.
493
+ * connects the two. Every field is optional, and an absent OR `undefined` value
494
+ * writes nothing at all — the key stays out of the row and the guard's own
495
+ * adaptive resolution decides the effective threshold.
495
496
  */
496
497
  export interface PresetOverrides {
497
498
  /** The `tool-catalog` row's `presentation` value. */
498
499
  presentation?: string
500
+ /** The `minimal-prompt` row's `dispatcher` switch. */
501
+ dispatcher?: boolean
499
502
  /** The `guard` row's `enabled` switch. */
500
503
  guardEnabled?: boolean
501
504
  /** The `guard` row's sensitivity preset. */
502
505
  guardSensitivity?: string
503
- /** The `guard` row's per-step reasoning-character floor. */
504
- guardStallReasoningChars?: number
505
- /** The `guard` row's slow-burn step cap. */
506
- guardGlobalStallCap?: number
507
- /** The `guard` row's identical-argument failure count. */
508
- guardEchoFailures?: number
506
+ /** The `guard` row's per-step reasoning-character floor override. */
507
+ guardStallReasoningChars?: number | undefined
508
+ /** The `guard` row's slow-burn step cap override. */
509
+ guardGlobalStallCap?: number | undefined
510
+ /** The `guard` row's identical-argument failure count override. */
511
+ guardEchoFailures?: number | undefined
509
512
  }
510
513
 
511
514
  /** One settings overlay entry: the row it targets and the keys it writes. */
@@ -515,6 +518,7 @@ type OverrideTarget = readonly [string, Readonly<Record<string, unknown>>]
515
518
  function overrideTargets(overrides: PresetOverrides): OverrideTarget[] {
516
519
  return [
517
520
  ['tool-catalog', { ...overrides.presentation === undefined ? {} : { presentation: overrides.presentation } }],
521
+ ['minimal-prompt', { ...overrides.dispatcher === undefined ? {} : { dispatcher: overrides.dispatcher } }],
518
522
  ['guard', {
519
523
  ...overrides.guardEnabled === undefined ? {} : { enabled: overrides.guardEnabled },
520
524
  ...overrides.guardSensitivity === undefined ? {} : { sensitivity: overrides.guardSensitivity },
@@ -530,9 +534,10 @@ function overrideTargets(overrides: PresetOverrides): OverrideTarget[] {
530
534
  *
531
535
  * Rows are addressed by their `id`, and only a row the composition actually
532
536
  * carries is touched: the overlay narrows the shipped configuration, it never
533
- * invents a mount the preset did not have. The shipped composition declares
534
- * every key the overlay writes, so leaving a key absent only matters for a
535
- * composition that dropped it.
537
+ * invents a mount the preset did not have. A field the settings surface left
538
+ * unset is written as no key at all rather than as a value, which is what keeps
539
+ * the guard's effort-adaptive thresholds the shipped behavior: the overlay only
540
+ * ever adds an override on top of them.
536
541
  * @param rows - the parsed composition rows.
537
542
  * @param overrides - the operator's settings-surface choices.
538
543
  * @returns a new row list with the overlay applied.
package/src/index.test.ts CHANGED
@@ -86,6 +86,32 @@ describe('resolveConfig', () => {
86
86
  expect(resolveConfig(Config({}))).toEqual(DEFAULT_CONFIG)
87
87
  })
88
88
 
89
+ it('operator gets the guard fine-tuning fields UNSET by default', () => {
90
+ // Given the shipped schema and the reader, When the operator reads the
91
+ // effective guard settings, Then the three fine-tuning overrides resolve to
92
+ // undefined rather than to a factory constant. That is what lets the
93
+ // guard's effort-adaptive table and the sensitivity preset be the shipped
94
+ // behavior: a default here would be written into the declared preset's
95
+ // guard row on every activation and mask both.
96
+ const values = resolveConfig(Config({}))
97
+ expect(values.guardStallReasoningChars).toBeUndefined()
98
+ expect(values.guardGlobalStallCap).toBeUndefined()
99
+ expect(values.guardEchoFailures).toBeUndefined()
100
+ // The two fields that are NOT overrides keep their real defaults.
101
+ expect(values.guardEnabled).toBe(true)
102
+ expect(values.guardSensitivity).toBe('balanced')
103
+ expect(DEFAULT_CONFIG.guardStallReasoningChars).toBeUndefined()
104
+ })
105
+
106
+ it('operator who clears a guard field gets undefined, not the previous value', () => {
107
+ // Given a volatile reference the Host clears, When the operator reads the
108
+ // effective settings, Then the field reads as unset so the overlay leaves
109
+ // the guard row's key out and the adaptive table applies again.
110
+ const cleared = { get: () => undefined }
111
+ expect(resolveConfig({ guardStallReasoningChars: cleared }).guardStallReasoningChars).toBeUndefined()
112
+ expect(resolveConfig({ guardStallReasoningChars: undefined }).guardStallReasoningChars).toBeUndefined()
113
+ })
114
+
89
115
  it('operator sees a committed volatile write through the held reference', () => {
90
116
  // Given a volatile field the Host hands over as a stable reference, When
91
117
  // the operator commits a write and reads again, Then the read moves with it.
@@ -104,6 +130,7 @@ describe('resolveConfig', () => {
104
130
  enabled: false,
105
131
  announceToAgent: true,
106
132
  presentation: 'ptc',
133
+ dispatcher: true,
107
134
  guardEnabled: false,
108
135
  guardSensitivity: 'aggressive',
109
136
  guardStallReasoningChars: 12000,
@@ -113,6 +140,7 @@ describe('resolveConfig', () => {
113
140
  enabled: false,
114
141
  announceToAgent: true,
115
142
  presentation: 'ptc',
143
+ dispatcher: true,
116
144
  guardEnabled: false,
117
145
  guardSensitivity: 'aggressive',
118
146
  guardStallReasoningChars: 12000,
@@ -120,6 +148,34 @@ describe('resolveConfig', () => {
120
148
  guardEchoFailures: 2,
121
149
  })
122
150
  })
151
+
152
+ it('operator gets the dispatcher switch ON by default, as a volatile field', () => {
153
+ // Given the shipped schema, When the operator reads the effective settings,
154
+ // Then the dispatcher block is appended by default: a session that never
155
+ // touches the switch runs as a dispatcher, and switching it off is what
156
+ // returns the bare persona. The field is volatile like every other
157
+ // preset-shaping key, so the Host serves it as this entry's settings form
158
+ // and commits a write in place instead of remounting the row.
159
+ expect(DEFAULT_CONFIG.dispatcher).toBe(true)
160
+ expect(resolveConfig({}).dispatcher).toBe(true)
161
+ expect(resolveConfig(Config({})).dispatcher).toBe(true)
162
+ let committed = false
163
+ expect(resolveConfig({ dispatcher: { get: () => committed } }).dispatcher).toBe(false)
164
+ committed = true
165
+ expect(resolveConfig({ dispatcher: { get: () => committed } }).dispatcher).toBe(true)
166
+ })
167
+
168
+ it('operator sees dispatcher and presentation as independent settings', () => {
169
+ // Given the two orthogonal settings (dispatcher changes the PROMPT, its
170
+ // appended rule block; presentation changes the WIRE, the tool surface),
171
+ // When the operator reads every combination, Then each field resolves to
172
+ // the value it was given with no cross-talk between them.
173
+ for (const presentation of ['ptc', 'native', 'both'] as const) {
174
+ for (const dispatcher of [true, false]) {
175
+ expect(resolveConfig({ presentation, dispatcher })).toMatchObject({ presentation, dispatcher })
176
+ }
177
+ }
178
+ })
123
179
  })
124
180
 
125
181
  describe('bundledPresetDir', () => {
package/src/index.ts CHANGED
@@ -100,6 +100,15 @@ export interface Config {
100
100
  * the transport.
101
101
  */
102
102
  presentation?: ConfigField<Presentation>
103
+ /**
104
+ * When true, the preset appends the dispatcher rule block to its persona:
105
+ * the session becomes a dispatch agent whose deliverable is the plan, the
106
+ * task book, the review verdict, and the hand-off, on top of the mode's own
107
+ * working discipline. Orthogonal to `presentation` — the tool wire is the
108
+ * same either way. Default true: the shipped preset runs as a dispatcher,
109
+ * and the switch is what returns a session to the bare persona.
110
+ */
111
+ dispatcher?: ConfigField<boolean>
103
112
  /** Master switch for the runtime degeneration circuit breaker (default true). */
104
113
  guardEnabled?: ConfigField<boolean>
105
114
  /**
@@ -108,28 +117,37 @@ export interface Config {
108
117
  */
109
118
  guardSensitivity?: ConfigField<GuardSensitivity>
110
119
  /**
111
- * Reasoning characters one zero-output step must reach for the per-step
112
- * ladder to fire (default 8000, calibrated against V4.1's 384K max output).
120
+ * Override for the per-step runaway-reasoning character floor. Left unset,
121
+ * the floor adapts to the session's reasoning effort and is then scaled by
122
+ * `guardSensitivity`; setting it wins over both for every effort level.
123
+ */
124
+ guardStallReasoningChars?: ConfigField<number | undefined>
125
+ /**
126
+ * Override for the slow-burn step count. Left unset, the cap scales with
127
+ * `guardSensitivity`.
113
128
  */
114
- guardStallReasoningChars?: ConfigField<number>
129
+ guardGlobalStallCap?: ConfigField<number | undefined>
115
130
  /**
116
- * Consecutive output-free reasoning steps that trip the slow-burn ladder
117
- * (default 4).
131
+ * Override for the echo ladder. Left unset, the count scales with
132
+ * `guardSensitivity`.
118
133
  */
119
- guardGlobalStallCap?: ConfigField<number>
120
- /** Identical-argument tool failures in a row that trip the echo ladder (default 3). */
121
- guardEchoFailures?: ConfigField<number>
134
+ guardEchoFailures?: ConfigField<number | undefined>
122
135
  }
123
136
 
124
137
  export const Config = z.object({
125
138
  enabled: z.boolean().default(true).volatile(),
126
139
  announceToAgent: z.boolean().default(false).volatile(),
127
140
  presentation: z.union([...PRESENTATION_OPTIONS]).default('both').volatile(),
141
+ dispatcher: z.boolean().default(true).volatile(),
128
142
  guardEnabled: z.boolean().default(true).volatile(),
129
143
  guardSensitivity: z.union([...SENSITIVITY_OPTIONS]).default('balanced').volatile(),
130
- guardStallReasoningChars: z.number().default(8000).volatile(),
131
- guardGlobalStallCap: z.number().default(4).volatile(),
132
- guardEchoFailures: z.number().default(3).volatile(),
144
+ // Deliberately WITHOUT a default: these three are fine-tuning overrides, and
145
+ // a factory value here would be written into the declared preset's guard row
146
+ // on every activation, permanently masking the effort-adaptive table and the
147
+ // sensitivity preset behind a constant.
148
+ guardStallReasoningChars: z.number().volatile(),
149
+ guardGlobalStallCap: z.number().volatile(),
150
+ guardEchoFailures: z.number().volatile(),
133
151
  })
134
152
 
135
153
  /** The settings the runtime acts on, every field read at its use site. */
@@ -140,35 +158,44 @@ export interface ResolvedConfig {
140
158
  announceToAgent: boolean
141
159
  /** Wire presentation the declared preset's tool-catalog row carries. */
142
160
  presentation: Presentation
161
+ /** Whether the declared preset's minimal-prompt row appends the dispatcher rule block. */
162
+ dispatcher: boolean
143
163
  /** Breaker master switch written into the declared preset's guard row. */
144
164
  guardEnabled: boolean
145
165
  /** Breaker sensitivity written into the declared preset's guard row. */
146
166
  guardSensitivity: GuardSensitivity
147
- /** Per-step reasoning-character floor written into the guard row. */
148
- guardStallReasoningChars: number
149
- /** Slow-burn step cap written into the guard row. */
150
- guardGlobalStallCap: number
151
- /** Echo-ladder failure count written into the guard row. */
152
- guardEchoFailures: number
167
+ /** Per-step reasoning-character floor written into the guard row, or undefined to leave the adaptive table in charge. */
168
+ guardStallReasoningChars: number | undefined
169
+ /** Slow-burn step cap written into the guard row, or undefined to leave the sensitivity preset in charge. */
170
+ guardGlobalStallCap: number | undefined
171
+ /** Echo-ladder failure count written into the guard row, or undefined to leave the sensitivity preset in charge. */
172
+ guardEchoFailures: number | undefined
153
173
  }
154
174
 
155
- /** Schema defaults, re-read for hand-built test contexts. */
175
+ /**
176
+ * Schema defaults, re-read for hand-built test contexts. The three guard
177
+ * fine-tuning fields default to undefined — "unset" IS the shipped default,
178
+ * and the guard resolves the effective thresholds per request from the
179
+ * session's reasoning effort and the sensitivity preset.
180
+ */
156
181
  export const DEFAULT_CONFIG: ResolvedConfig = {
157
182
  enabled: true,
158
183
  announceToAgent: false,
159
184
  presentation: 'both',
185
+ dispatcher: true,
160
186
  guardEnabled: true,
161
187
  guardSensitivity: 'balanced',
162
- guardStallReasoningChars: 8000,
163
- guardGlobalStallCap: 4,
164
- guardEchoFailures: 3,
188
+ guardStallReasoningChars: undefined,
189
+ guardGlobalStallCap: undefined,
190
+ guardEchoFailures: undefined,
165
191
  }
166
192
 
167
193
  /**
168
194
  * Read one activation field. The Host validates the raw profile config and
169
195
  * hands volatile fields over as references, so a read goes through `get()`; a
170
196
  * plain value passes through, and an absent field falls back to the schema
171
- * default.
197
+ * default — which is `undefined` for the three guard fine-tuning overrides,
198
+ * so "unset" survives as a real value instead of collapsing into a constant.
172
199
  */
173
200
  function readField<T>(field: ConfigField<T>, fallback: T): T {
174
201
  if (field === undefined || field === null) return fallback
@@ -187,6 +214,7 @@ export function resolveConfig(config?: Config): ResolvedConfig {
187
214
  enabled: readField(config?.enabled, DEFAULT_CONFIG.enabled),
188
215
  announceToAgent: readField(config?.announceToAgent, DEFAULT_CONFIG.announceToAgent),
189
216
  presentation: readField(config?.presentation, DEFAULT_CONFIG.presentation),
217
+ dispatcher: readField(config?.dispatcher, DEFAULT_CONFIG.dispatcher),
190
218
  guardEnabled: readField(config?.guardEnabled, DEFAULT_CONFIG.guardEnabled),
191
219
  guardSensitivity: readField(config?.guardSensitivity, DEFAULT_CONFIG.guardSensitivity),
192
220
  guardStallReasoningChars: readField(config?.guardStallReasoningChars, DEFAULT_CONFIG.guardStallReasoningChars),
@@ -196,7 +224,7 @@ export function resolveConfig(config?: Config): ResolvedConfig {
196
224
  }
197
225
 
198
226
  /** Model-facing announcement: plugin presence, principle, and limits. */
199
- export const LIANGSHEN_GUIDANCE = '本机已安装 dsh-liangshen 插件(梁神模式 agent preset):新建会话的预设选择器中可选「梁神模式」。原理:系统提示词保持极简 persona(minimal-prompt 放行该段与 plan 模式的 plan:policy),persona 内置本模式工作纪律(反思熔断——同一假设推演不超过两轮、缺事实立即闭合思考并调用原生检测工具;行动导向——思考只决定下一步具体操作、不在思考中预演代码实现;并发探索——多处独立检查或搜索在单轮内并发发射多个工具调用;YAGNI/PDCA——单步验证单一假设、不写冗余注释;有界收敛——不无限下钻依赖链、前置检查最多2-3轮后立即收敛并作答或编辑),并在组装时追加工作区目录行 Your working directory is <cwd>.。AGENTS.md 工作区指令默认交还宿主自身的 agent-instructions 行,以 user 角色注入,本插件不追加任何系统提示词段、也不改动 pre-step 的消息批次;可选 instructionSource: system-prompt 才由本插件在组装时读取 AGENTS.md 链并追加 workspace-instructions 段(65536 字节预算,每次组装重读)。wire 呈现由 tool-catalog 按会话一次声明,取值 \'both\'(默认:原生清单与 run_code 同驻,原生直调优先、run_code 用于程序化批处理与并发扇出)、\'native\'(组装出的原生清单)或 \'ptc\'(wire 收拢为唯一的 run_code),并可在插件设置界面切换(写入所声明预设的 tool-catalog 行);未挂载 code runtime 时不做声明,会话运行原生工具面。温和工具分页出厂开启(pagedToolPatterns 默认 [\'mcp__*\']):匹配工具在激活前被作用域级工具限制移出可见面(既不在 wire,也不在生成的 SDK 声明中),目录消息列出常驻工具签名与未激活命名空间摘要,调用 tool_activate({ namespace }) 按需激活(LRU 上限 3 个活跃命名空间,驱逐最久未用);激活状态从持久会话事件流重建,resume/压缩后自然恢复。运行时退化熔断器(guard)从事件流折叠停摆(连续零产出长思考)与空转(同参重复失败)信号,每 episode 触发一次:注入熔断消息并把推理档位临时下调一档(max→high→low,窗口 3 个请求);无信号时从不改写请求。关键事实登记簿(fact_register)让模型把硬约束/已确认决策/失败路径登记为单行事实,随 working-context 行每步投射进局部注意力窗口。working-context 插件在 pre-step 注入单行 [Working Context: ...] 就近状态投射(plan 模式、活跃命名空间、进行中 todo、登记事实,全部从事件流折叠,读不到则省略,全部为空则不注入)。历史工具结果修剪为 4096 字符阈值(head 2048 / tail 1024)。文件操作受宿主沙箱约束;shell 在每个平台都挂上游标准 Stdio 栈(POSIX 为 bash,Windows 为 pwsh),带简短描述标题卡片与确定性退出码。真实推理探针通过不等于模式集成通过,更不等于统计效果提升。预设由插件在激活时向 agent-preset registry 直接注册(不写任何预设目录),插件停用即注销;默认预设由用户自行选择。用户提到「梁神模式 / 锚定模式 / anchored standard」时即指本插件,请据此协作。'
227
+ export const LIANGSHEN_GUIDANCE = '本机已安装 dsh-liangshen 插件(梁神模式 agent preset):新建会话的预设选择器中可选「梁神模式」。原理:系统提示词保持极简 persona(minimal-prompt 放行该段与 plan 模式的 plan:policy),persona 内置本模式工作纪律(反思熔断——同一假设推演不超过两轮、缺事实立即闭合思考并调用原生检测工具;行动导向——思考只决定下一步具体操作、不在思考中预演代码实现;并发探索——多处独立检查或搜索在单轮内并发发射多个工具调用;YAGNI/PDCA——单步验证单一假设、不写冗余注释;有界收敛——不无限下钻依赖链、前置检查最多2-3轮后立即收敛并作答或编辑),并在组装时追加工作区目录行 Your working directory is <cwd>.。AGENTS.md 工作区指令默认交还宿主自身的 agent-instructions 行,以 user 角色注入,本插件不追加任何系统提示词段、也不改动 pre-step 的消息批次;可选 instructionSource: system-prompt 才由本插件在组装时读取 AGENTS.md 链并追加 workspace-instructions 段(65536 字节预算,每次组装重读)。wire 呈现由 tool-catalog 按会话一次声明,取值 \'both\'(默认:原生清单与 run_code 同驻,原生直调优先、run_code 用于程序化批处理与并发扇出)、\'native\'(组装出的原生清单)或 \'ptc\'(wire 收拢为唯一的 run_code),并可在插件设置界面切换(写入所声明预设的 tool-catalog 行);未挂载 code runtime 时不做声明,会话运行原生工具面。温和工具分页出厂开启(pagedToolPatterns 默认 [\'mcp__*\']):匹配工具在激活前被作用域级工具限制移出可见面(既不在 wire,也不在生成的 SDK 声明中),目录消息列出常驻工具签名与未激活命名空间摘要,调用 tool_activate({ namespace }) 按需激活(LRU 上限 3 个活跃命名空间,驱逐最久未用);激活状态从持久会话事件流重建,resume/压缩后自然恢复。运行时退化熔断器(guard)从事件流折叠停摆(连续零产出长思考)与空转(同参重复失败)信号,每 episode 触发一次:注入熔断消息;仅停摆信号(成因是推理预算过剩)额外把推理档位临时下调一档(max→high,窗口 3 个请求,high 档本身处于甜区不动),空转信号只注入消息。阈值随会话推理档位自适应(max 8000 / high 12000 / low 20000 字符)并再按灵敏度预设缩放;provider 不持久化推理文本的会话降级为连续零产出步骤计数。无信号时从不改写请求。关键事实登记簿(fact_register)让模型把硬约束/已确认决策/失败路径登记为单行事实,随 working-context 行每步投射进局部注意力窗口。working-context 插件在 pre-step 注入单行 [Working Context: ...] 就近状态投射(plan 模式、活跃命名空间、进行中 todo、登记事实,全部从事件流折叠,读不到则省略,全部为空则不注入)。历史工具结果修剪为 4096 字符阈值(head 2048 / tail 1024)。文件操作受宿主沙箱约束;shell 在每个平台都挂上游标准 Stdio 栈(POSIX 为 bash,Windows 为 pwsh),带简短描述标题卡片与确定性退出码。真实推理探针通过不等于模式集成通过,更不等于统计效果提升。预设由插件在激活时向 agent-preset registry 直接注册(不写任何预设目录),插件停用即注销;默认预设由用户自行选择。用户提到「梁神模式 / 锚定模式 / anchored standard」时即指本插件,请据此协作。'
200
228
 
201
229
  /** Order of the announcement section within the tool-guidance band. */
202
230
  const SECTION_ORDER = 150