@linxin666/dsh-liangshen 0.4.15 → 0.4.17

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.
@@ -14,8 +14,28 @@ import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-cli
14
14
  import type { SnapshotStore } from '@deepseek-ai/dsh-client-store'
15
15
  import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client'
16
16
  import { LiangShenMark } from './LiangShenMark.tsx'
17
- import { BooleanField, ChoiceField, PluginSettingsCard } from './PluginSettingsCard.tsx'
18
- import { CardForm, booleanField, choiceField, type CardActions, type CardShell, type FieldState as CardFieldState } from './settings-form.ts'
17
+ import { BooleanField, ChoiceField, PluginSettingsCard, ValueField } from './PluginSettingsCard.tsx'
18
+ import { CardForm, booleanField, choiceField, textField, type CardActions, type CardShell, type FieldSpec, type FieldState as CardFieldState } from './settings-form.ts'
19
+
20
+ /** A tool family entry: a prefix ending in exactly one trailing star. */
21
+ const FAMILY_ENTRY_RE = /^[^*]+\*$/
22
+
23
+ /**
24
+ * The on-demand tool family list: comma separated entries, each a prefix with
25
+ * one trailing star. Blank clears the field; any malformed entry holds the
26
+ * draft unwritten.
27
+ */
28
+ export function pagedToolPatternsField(field: string): FieldSpec {
29
+ return {
30
+ ...textField(field),
31
+ parse: (text) => {
32
+ const entries = text.split(',').map(entry => entry.trim()).filter(entry => entry !== '')
33
+ if (entries.length === 0) return { kind: 'clear' }
34
+ if (!entries.every(entry => FAMILY_ENTRY_RE.test(entry))) return undefined
35
+ return { kind: 'set', value: entries.join(', ') }
36
+ },
37
+ }
38
+ }
19
39
 
20
40
  /** Wire presentations the tool catalog accepts (mirrors the Host schema). */
21
41
  export const PRESENTATION_CHOICES = ['ptc', 'native'] as const
@@ -30,6 +50,8 @@ export interface LiangShenSettings {
30
50
  presentation?: string
31
51
  /** Whether the preset appends the dispatcher rules section after the persona. */
32
52
  dispatcher?: boolean
53
+ /** Comma-separated on-demand tool families the Host writes to the tool-catalog row. */
54
+ pagedToolPatterns?: string
33
55
  }
34
56
 
35
57
  /** What the LiangShen card renders. */
@@ -38,6 +60,7 @@ export interface LiangShenSettingsCardState extends CardShell {
38
60
  announceToAgent: CardFieldState
39
61
  presentation: CardFieldState
40
62
  dispatcher: CardFieldState
63
+ pagedToolPatterns: CardFieldState
41
64
  }
42
65
 
43
66
  /** The registration-side face the card's slot entry injects. */
@@ -60,6 +83,7 @@ export class LiangShenSettingsCardController {
60
83
  booleanField('announceToAgent'),
61
84
  choiceField('presentation', PRESENTATION_CHOICES),
62
85
  booleanField('dispatcher'),
86
+ pagedToolPatternsField('pagedToolPatterns'),
63
87
  ])
64
88
  this.store = this.form.bind(() => this.projection())
65
89
  }
@@ -71,6 +95,7 @@ export class LiangShenSettingsCardController {
71
95
  announceToAgent: this.form.field('announceToAgent'),
72
96
  presentation: this.form.field('presentation'),
73
97
  dispatcher: this.form.field('dispatcher'),
98
+ pagedToolPatterns: this.form.field('pagedToolPatterns'),
74
99
  }
75
100
  }
76
101
 
@@ -166,6 +191,17 @@ export function LiangShenSettingsCard(props: LiangShenSettingsCardProps) {
166
191
  onEdit={(text) => { props.edit('dispatcher', text) }}
167
192
  onReset={() => { props.resetField('dispatcher') }}
168
193
  />
194
+ <ValueField
195
+ id="settings-liangshen-paged-tool-patterns"
196
+ label={t('settings.pagedToolPatterns')}
197
+ hint={t('settings.pagedToolPatternsHint')}
198
+ placeholder="browser_*, task_board_*"
199
+ {...fieldProps}
200
+ invalidLabel={t('settings.pagedToolPatternsInvalid')}
201
+ {...state.pagedToolPatterns}
202
+ onEdit={(text) => { props.edit('pagedToolPatterns', text) }}
203
+ onReset={() => { props.resetField('pagedToolPatterns') }}
204
+ />
169
205
  </PluginSettingsCard>
170
206
  )
171
207
  }
@@ -31,6 +31,9 @@ export const zh = {
31
31
  'settings.presentationHint': 'ptc 把工具收进 run_code,native 保留原生清单。',
32
32
  'settings.dispatcher': '调度身份',
33
33
  'settings.dispatcherHint': '按调度 Agent 工作:分诊、访谈、派发子代理。',
34
+ 'settings.pagedToolPatterns': '按需工具族',
35
+ 'settings.pagedToolPatternsHint': '逗号分隔,每项以单个 * 结尾。命中这些前缀的工具默认不进上下文,需要时用 tool_activate 按需加载。留空继承出厂 7 项:mcp__*, browser_*, task_board_*, team_*, squad*, ui_*, ssh_*。',
36
+ 'settings.pagedToolPatternsInvalid': '每项须是非空前缀并以单个 * 结尾,逗号分隔,例如 task_board_*。',
34
37
  'settings.on': '开',
35
38
  'settings.off': '关',
36
39
  'settings.inherit': '继承',
@@ -73,6 +76,9 @@ export const en: Record<keyof typeof zh, string> = {
73
76
  'settings.presentationHint': 'ptc folds tools into run_code; native keeps the native roster.',
74
77
  'settings.dispatcher': 'Dispatcher',
75
78
  'settings.dispatcherHint': 'Works as a dispatcher: triage, interview, then dispatch subagents.',
79
+ 'settings.pagedToolPatterns': 'On-demand tool families',
80
+ 'settings.pagedToolPatternsHint': 'Comma separated, each entry ending in a single *. Tools matching these prefixes stay out of context by default; load them with tool_activate when needed. Leave empty to inherit the 7 factory entries: mcp__*, browser_*, task_board_*, team_*, squad*, ui_*, ssh_*.',
81
+ 'settings.pagedToolPatternsInvalid': 'Each entry must be a non-empty prefix ending in a single *, comma separated, for example task_board_*.',
76
82
  'settings.on': 'On',
77
83
  'settings.off': 'Off',
78
84
  'settings.inherit': 'Inherit',
@@ -14,6 +14,7 @@ import { describe, expect, it } from 'vitest'
14
14
  import {
15
15
  CompositionError,
16
16
  applyPresetOverrides,
17
+ parsePagedToolPatterns,
17
18
  readCompositionRows,
18
19
  readPresetDefinition,
19
20
  readPresetMetadata,
@@ -46,6 +47,13 @@ function configOf(row: CompositionRow): Record<string, unknown> {
46
47
  return row.config as Record<string, unknown>
47
48
  }
48
49
 
50
+ /**
51
+ * The rows the one `pagedToolPatterns` value must reach: the catalog installs
52
+ * the registry restriction, the activation tool replays the log against it, and
53
+ * working-context renders the resulting active set.
54
+ */
55
+ const PAGING_ROWS = ['tool-catalog', 'tool-activate', 'working-context']
56
+
49
57
  describe('readCompositionRows', () => {
50
58
  it('operator reads every row of the shipped composition once', () => {
51
59
  // Given the shipped composition, When the operator reads it for the preset
@@ -74,7 +82,7 @@ describe('readCompositionRows', () => {
74
82
  expect(catalog['presentation']).toBe('ptc')
75
83
  expect(catalog['descriptionMaxLength']).toBe(200)
76
84
  expect(catalog['maxResidentTokens']).toBe(8000)
77
- expect(catalog['pagedToolPatterns']).toEqual(['mcp__*'])
85
+ expect(catalog['pagedToolPatterns']).toEqual(['mcp__*', 'browser_*', 'task_board_*', 'team_*', 'squad*', 'ui_*', 'ssh_*'])
78
86
  })
79
87
 
80
88
  it('operator reads the shipped dispatcher switch ON on the minimal-prompt row', () => {
@@ -304,6 +312,49 @@ describe('applyPresetOverrides', () => {
304
312
  })
305
313
  })
306
314
 
315
+ describe('pagedToolPatterns override', () => {
316
+ it('operator writes the parsed family text as an array into every row that pages from it', () => {
317
+ // Given the shipped composition and a settings text naming two families
318
+ // When the overlay is applied
319
+ // Then all three paging rows carry the same parsed array, so the catalog,
320
+ // the activation tool and the working context cannot disagree about it
321
+ const applied = applyPresetOverrides(rows(), { pagedToolPatterns: ' mcp__* , ssh_*,, ' })
322
+ for (const id of PAGING_ROWS) {
323
+ expect(configOf(rowOf(applied, id))['pagedToolPatterns'], id).toEqual(['mcp__*', 'ssh_*'])
324
+ }
325
+ // Each row holds its own array: one shared instance would let a later
326
+ // mutation of one row's list reach the other two.
327
+ const lists = PAGING_ROWS.map(id => configOf(rowOf(applied, id))['pagedToolPatterns'])
328
+ expect(new Set(lists).size, 'one array per row').toBe(PAGING_ROWS.length)
329
+ // The row the value arrived with keeps its own keys.
330
+ expect(configOf(rowOf(applied, 'tool-catalog'))['presentation']).toBe('ptc')
331
+ })
332
+
333
+ it('operator inherits the shipped list for blank text', () => {
334
+ // Given a settings text of whitespace alone
335
+ // When the overlay is applied
336
+ // Then no paging row moves: each keeps exactly the shipped configuration
337
+ const applied = applyPresetOverrides(rows(), { pagedToolPatterns: ' ' })
338
+ for (const id of PAGING_ROWS) {
339
+ expect(rowOf(applied, id), id).toEqual(rowOf(rows(), id))
340
+ }
341
+ })
342
+
343
+ it('operator inherits the shipped list when any entry is malformed', () => {
344
+ // Given a settings text carrying one malformed entry
345
+ // When the overlay is applied
346
+ // Then nothing is parsed and every paging row keeps the shipped list, so a
347
+ // typo cannot split the three readers apart
348
+ for (const text of ['mcp__', 'a*b*', 'mcp**', 'good*, bad', '*', 'mcp__*, *']) {
349
+ expect(parsePagedToolPatterns(text), text).toBeUndefined()
350
+ const applied = applyPresetOverrides(rows(), { pagedToolPatterns: text })
351
+ for (const id of PAGING_ROWS) {
352
+ expect(rowOf(applied, id), `${id}: ${text}`).toEqual(rowOf(rows(), id))
353
+ }
354
+ }
355
+ })
356
+ })
357
+
307
358
  describe('readPresetDefinition', () => {
308
359
  it('operator builds the declaration from the shipped preset directory', () => {
309
360
  // Given the bundled preset directory, When the operator reads its
@@ -498,6 +498,26 @@ export interface PresetOverrides {
498
498
  presentation?: string
499
499
  /** The `minimal-prompt` row's `dispatcher` switch. */
500
500
  dispatcher?: boolean
501
+ /**
502
+ * Comma-separated on-demand tool families; written as an array to every row
503
+ * that pages from it (tool-catalog, tool-activate, working-context), skipped
504
+ * when blank or malformed.
505
+ */
506
+ pagedToolPatterns?: string
507
+ }
508
+
509
+ /**
510
+ * Parse the on-demand tool family text: comma separated, each entry a prefix
511
+ * ending in exactly one trailing `*`.
512
+ * @param text - the settings text.
513
+ * @returns the pattern list, or undefined when the text is blank or any entry is malformed.
514
+ */
515
+ export function parsePagedToolPatterns(text: string | undefined): string[] | undefined {
516
+ if (text === undefined) return undefined
517
+ const entries = text.split(',').map(entry => entry.trim()).filter(entry => entry !== '')
518
+ if (entries.length === 0) return undefined
519
+ const wellFormed = entries.every(entry => /^[^*]+\*$/.test(entry))
520
+ return wellFormed ? entries : undefined
501
521
  }
502
522
 
503
523
  /** One settings overlay entry: the row it targets and the config keys it writes. */
@@ -511,8 +531,20 @@ type OverrideTarget = readonly [string, Readonly<Record<string, unknown>>]
511
531
  * the assembled native roster remains the only surface.
512
532
  */
513
533
  function overrideTargets(overrides: PresetOverrides): OverrideTarget[] {
534
+ const paged = parsePagedToolPatterns(overrides.pagedToolPatterns)
535
+ // One pattern list reaches every row that pages from it. The three rows
536
+ // replay the same session log with the same patterns — the catalog installs
537
+ // the registry restriction, the activation tool answers against it, and
538
+ // working-context renders it — so a row left on its own default would
539
+ // disagree about what is active and could strand a withheld namespace.
540
+ const pagedPatch = () => (paged === undefined ? {} : { pagedToolPatterns: [...paged] })
514
541
  return [
515
- ['tool-catalog', { ...overrides.presentation === undefined ? {} : { presentation: overrides.presentation } }],
542
+ ['tool-catalog', {
543
+ ...overrides.presentation === undefined ? {} : { presentation: overrides.presentation },
544
+ ...pagedPatch(),
545
+ }],
546
+ ['tool-activate', pagedPatch()],
547
+ ['working-context', pagedPatch()],
516
548
  ['minimal-prompt', { ...overrides.dispatcher === undefined ? {} : { dispatcher: overrides.dispatcher } }],
517
549
  ]
518
550
  }
package/src/index.test.ts CHANGED
@@ -110,6 +110,7 @@ describe('resolveConfig', () => {
110
110
  announceToAgent: true,
111
111
  presentation: 'ptc',
112
112
  dispatcher: true,
113
+ pagedToolPatterns: '',
113
114
  })
114
115
  })
115
116
 
package/src/index.ts CHANGED
@@ -23,7 +23,7 @@
23
23
  * transport and every other tool is reached from inside the program through
24
24
  * the generated SDK ('native' keeps the assembled roster alone), declared once
25
25
  * per session instead of staged across a turn boundary. High-fan-out tool families
26
- * (default `mcp__*`) stay paged out of the executed surface through the
26
+ * (default `mcp__*`, `browser_*`, `task_board_*`, `team_*`, `squad*`, `ui_*`, `ssh_*`) stay paged out of the executed surface through the
27
27
  * host's scoped tool restriction until the preset's own `tool_activate` tool
28
28
  * loads their namespace (LRU cap three), with the activation state replayed
29
29
  * from the durable session event stream. The tool catalog — listing exactly
@@ -103,6 +103,14 @@ export interface Config {
103
103
  * and the switch is what returns a session to the bare persona.
104
104
  */
105
105
  dispatcher?: ConfigField<boolean>
106
+ /**
107
+ * On-demand tool families, comma separated (each entry a prefix ending in one
108
+ * `*`), written to every row that pages from the list — the catalog, the
109
+ * activation tool and the working context all replay the session log with it,
110
+ * so the three must never disagree. Empty keeps the preset's shipped list; a
111
+ * malformed text is ignored.
112
+ */
113
+ pagedToolPatterns?: ConfigField<string>
106
114
  }
107
115
 
108
116
  export const Config = z.object({
@@ -113,6 +121,7 @@ export const Config = z.object({
113
121
  z.transform('both', (): Presentation => 'ptc').deprecated().hidden(),
114
122
  ]).default('ptc').volatile(),
115
123
  dispatcher: z.boolean().default(true).volatile(),
124
+ pagedToolPatterns: z.string().default('').volatile(),
116
125
  })
117
126
 
118
127
  /** The settings the runtime acts on, every field read at its use site. */
@@ -125,6 +134,8 @@ export interface ResolvedConfig {
125
134
  presentation: Presentation
126
135
  /** Whether the declared preset's minimal-prompt row appends the dispatcher rule block. */
127
136
  dispatcher: boolean
137
+ /** On-demand tool family text; empty inherits the preset's shipped list. */
138
+ pagedToolPatterns: string
128
139
  }
129
140
 
130
141
  /** Schema defaults, re-read for hand-built test contexts. */
@@ -133,6 +144,7 @@ export const DEFAULT_CONFIG: ResolvedConfig = {
133
144
  announceToAgent: false,
134
145
  presentation: 'ptc',
135
146
  dispatcher: true,
147
+ pagedToolPatterns: '',
136
148
  }
137
149
 
138
150
  /**
@@ -160,11 +172,12 @@ export function resolveConfig(config?: Config): ResolvedConfig {
160
172
  announceToAgent: readField(config?.announceToAgent, DEFAULT_CONFIG.announceToAgent),
161
173
  presentation: rawPresentation === 'both' ? 'ptc' : rawPresentation,
162
174
  dispatcher: readField(config?.dispatcher, DEFAULT_CONFIG.dispatcher),
175
+ pagedToolPatterns: readField(config?.pagedToolPatterns, DEFAULT_CONFIG.pagedToolPatterns),
163
176
  }
164
177
  }
165
178
 
166
179
  /** Model-facing announcement: plugin presence, principle, and limits. */
167
- 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 按会话一次声明,取值 \'ptc\'(默认:wire 收拢为唯一的 run_code,其余工具经生成的 SDK 调用)或 \'native\'(组装出的原生清单,无程序化传输),并可在插件设置界面切换(写入所声明预设的 tool-catalog 行);未挂载 code runtime 时不做声明,会话运行原生工具面。温和工具分页出厂开启(pagedToolPatterns 默认 [\'mcp__*\']):匹配工具在激活前被作用域级工具限制移出可见面(既不在 wire,也不在生成的 SDK 声明中),目录消息列出常驻工具签名与未激活命名空间摘要,调用 tool_activate({ namespace }) 按需激活(LRU 上限 3 个活跃命名空间,驱逐最久未用);激活状态从持久会话事件流重建,resume/压缩后自然恢复。关键事实登记簿(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」时即指本插件,请据此协作。'
180
+ 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 按会话一次声明,取值 \'ptc\'(默认:wire 收拢为唯一的 run_code,其余工具经生成的 SDK 调用)或 \'native\'(组装出的原生清单,无程序化传输),并可在插件设置界面切换(写入所声明预设的 tool-catalog 行);未挂载 code runtime 时不做声明,会话运行原生工具面。按需工具族出厂开启(pagedToolPatterns 默认 [\'mcp__*\', \'browser_*\', \'task_board_*\', \'team_*\', \'squad*\', \'ui_*\', \'ssh_*\'],可在插件设置的「按需工具族」中用逗号分隔的前缀改写):匹配工具在激活前被作用域级工具限制移出可见面(既不在 wire,也不在生成的 SDK 声明中),目录消息列出常驻工具签名与未激活命名空间摘要,调用 tool_activate({ namespace }) 按需激活(LRU 上限 3 个活跃命名空间,驱逐最久未用);激活状态从持久会话事件流重建,resume/压缩后自然恢复。关键事实登记簿(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」时即指本插件,请据此协作。'
168
181
 
169
182
  /** Order of the announcement section within the tool-guidance band. */
170
183
  const SECTION_ORDER = 150