@linxin666/dsh-liangshen 0.4.6 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts CHANGED
@@ -19,11 +19,10 @@
19
19
  * The preset combines a minimal persona with a lifetime-declared tool
20
20
  * presentation: the system prompt keeps a minimal persona with standing
21
21
  * working discipline and workspace instructions, and the wire runs the SDK's
22
- * 'both' presentation by default — the assembled native roster stays on the
23
- * wire for ordinary work and the `run_code` transport sits co-resident for
24
- * programmatic batch computation and wide fan-out, declared once per session
25
- * instead of staged across a turn boundary ('native' and 'ptc' are one-line
26
- * opt-outs). High-fan-out tool families
22
+ * 'ptc' presentation by default — the wire collapses to the `run_code`
23
+ * transport and every other tool is reached from inside the program through
24
+ * the generated SDK ('native' keeps the assembled roster alone), declared once
25
+ * per session instead of staged across a turn boundary. High-fan-out tool families
27
26
  * (default `mcp__*`) stay paged out of the executed surface through the
28
27
  * host's scoped tool restriction until the preset's own `tool_activate` tool
29
28
  * loads their namespace (LRU cap three), with the activation state replayed
@@ -61,17 +60,11 @@ export const LIANGSHEN_SETTINGS_NAMESPACE = 'liangshen' as SettingsNamespace
61
60
  export const inject = ['systemPrompt']
62
61
 
63
62
  /** The wire presentations the preset's tool catalog accepts. */
64
- export const PRESENTATION_OPTIONS = ['ptc', 'native', 'both'] as const
65
-
66
- /** Sensitivity presets for the circuit breaker's adaptive thresholds. */
67
- export const SENSITIVITY_OPTIONS = ['conservative', 'balanced', 'aggressive'] as const
63
+ export const PRESENTATION_OPTIONS = ['ptc', 'native'] as const
68
64
 
69
65
  /** One wire presentation. */
70
66
  export type Presentation = (typeof PRESENTATION_OPTIONS)[number]
71
67
 
72
- /** One circuit-breaker sensitivity preset. */
73
- export type GuardSensitivity = (typeof SENSITIVITY_OPTIONS)[number]
74
-
75
68
  /**
76
69
  * One activation field as the Host hands it over: a stable reference whose
77
70
  * `get()` reads the value committed for this instance (a settings write updates
@@ -95,11 +88,12 @@ export interface Config {
95
88
  announceToAgent?: ConfigField<boolean>
96
89
  /**
97
90
  * Wire presentation written into the declared preset's tool-catalog row.
98
- * `both` (default) keeps the assembled roster and the `run_code` transport
99
- * co-resident; `native` keeps only the roster; `ptc` collapses the wire to
100
- * the transport.
91
+ * `ptc` (default) collapses the wire to the single `run_code` transport and
92
+ * reaches every other tool through the generated SDK; `native` keeps the
93
+ * assembled roster alone. Legacy `'both'` (the pre-0.2.1 shipped default) is
94
+ * accepted from older saved profiles and normalized to `'ptc'`.
101
95
  */
102
- presentation?: ConfigField<Presentation>
96
+ presentation?: ConfigField<Presentation | 'both'>
103
97
  /**
104
98
  * When true, the preset appends the dispatcher rule block to its persona:
105
99
  * the session becomes a dispatch agent whose deliverable is the plan, the
@@ -109,45 +103,16 @@ export interface Config {
109
103
  * and the switch is what returns a session to the bare persona.
110
104
  */
111
105
  dispatcher?: ConfigField<boolean>
112
- /** Master switch for the runtime degeneration circuit breaker (default true). */
113
- guardEnabled?: ConfigField<boolean>
114
- /**
115
- * Sensitivity preset scaling the breaker's adaptive thresholds
116
- * (default 'balanced'). 'conservative' interrupts less, 'aggressive' fires earlier.
117
- */
118
- guardSensitivity?: ConfigField<GuardSensitivity>
119
- /**
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`.
128
- */
129
- guardGlobalStallCap?: ConfigField<number | undefined>
130
- /**
131
- * Override for the echo ladder. Left unset, the count scales with
132
- * `guardSensitivity`.
133
- */
134
- guardEchoFailures?: ConfigField<number | undefined>
135
106
  }
136
107
 
137
108
  export const Config = z.object({
138
109
  enabled: z.boolean().default(true).volatile(),
139
110
  announceToAgent: z.boolean().default(false).volatile(),
140
- presentation: z.union([...PRESENTATION_OPTIONS]).default('both').volatile(),
111
+ presentation: z.union([
112
+ ...PRESENTATION_OPTIONS,
113
+ z.transform('both', (): Presentation => 'ptc').deprecated().hidden(),
114
+ ]).default('ptc').volatile(),
141
115
  dispatcher: z.boolean().default(true).volatile(),
142
- guardEnabled: z.boolean().default(true).volatile(),
143
- guardSensitivity: z.union([...SENSITIVITY_OPTIONS]).default('balanced').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(),
151
116
  })
152
117
 
153
118
  /** The settings the runtime acts on, every field read at its use site. */
@@ -160,42 +125,21 @@ export interface ResolvedConfig {
160
125
  presentation: Presentation
161
126
  /** Whether the declared preset's minimal-prompt row appends the dispatcher rule block. */
162
127
  dispatcher: boolean
163
- /** Breaker master switch written into the declared preset's guard row. */
164
- guardEnabled: boolean
165
- /** Breaker sensitivity written into the declared preset's guard row. */
166
- guardSensitivity: GuardSensitivity
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
173
128
  }
174
129
 
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
- */
130
+ /** Schema defaults, re-read for hand-built test contexts. */
181
131
  export const DEFAULT_CONFIG: ResolvedConfig = {
182
132
  enabled: true,
183
133
  announceToAgent: false,
184
- presentation: 'both',
134
+ presentation: 'ptc',
185
135
  dispatcher: true,
186
- guardEnabled: true,
187
- guardSensitivity: 'balanced',
188
- guardStallReasoningChars: undefined,
189
- guardGlobalStallCap: undefined,
190
- guardEchoFailures: undefined,
191
136
  }
192
137
 
193
138
  /**
194
139
  * Read one activation field. The Host validates the raw profile config and
195
140
  * hands volatile fields over as references, so a read goes through `get()`; a
196
141
  * plain value passes through, and an absent field falls back to the schema
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.
142
+ * default.
199
143
  */
200
144
  function readField<T>(field: ConfigField<T>, fallback: T): T {
201
145
  if (field === undefined || field === null) return fallback
@@ -210,21 +154,17 @@ function readField<T>(field: ConfigField<T>, fallback: T): T {
210
154
  * @returns every field resolved against the schema defaults.
211
155
  */
212
156
  export function resolveConfig(config?: Config): ResolvedConfig {
157
+ const rawPresentation = readField<Presentation | 'both'>(config?.presentation, DEFAULT_CONFIG.presentation)
213
158
  return {
214
159
  enabled: readField(config?.enabled, DEFAULT_CONFIG.enabled),
215
160
  announceToAgent: readField(config?.announceToAgent, DEFAULT_CONFIG.announceToAgent),
216
- presentation: readField(config?.presentation, DEFAULT_CONFIG.presentation),
161
+ presentation: rawPresentation === 'both' ? 'ptc' : rawPresentation,
217
162
  dispatcher: readField(config?.dispatcher, DEFAULT_CONFIG.dispatcher),
218
- guardEnabled: readField(config?.guardEnabled, DEFAULT_CONFIG.guardEnabled),
219
- guardSensitivity: readField(config?.guardSensitivity, DEFAULT_CONFIG.guardSensitivity),
220
- guardStallReasoningChars: readField(config?.guardStallReasoningChars, DEFAULT_CONFIG.guardStallReasoningChars),
221
- guardGlobalStallCap: readField(config?.guardGlobalStallCap, DEFAULT_CONFIG.guardGlobalStallCap),
222
- guardEchoFailures: readField(config?.guardEchoFailures, DEFAULT_CONFIG.guardEchoFailures),
223
163
  }
224
164
  }
225
165
 
226
166
  /** Model-facing announcement: plugin presence, principle, and limits. */
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」时即指本插件,请据此协作。'
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」时即指本插件,请据此协作。'
228
168
 
229
169
  /** Order of the announcement section within the tool-guidance band. */
230
170
  const SECTION_ORDER = 150
@@ -16,18 +16,18 @@
16
16
  * - Session persistence is redirected into the run directory, so real session
17
17
  * history is never appended to.
18
18
  *
19
- * The candidate matrix follows the LiangShen V4.1 Flash improvement plan:
20
- * B (current persona), P (candidate persona), T (candidate persona + PTC-only
21
- * presentation), T (candidate persona + 'both' presentation), N (candidate
22
- * persona + native presentation throughout), and M
23
- * (the official bundle's Minimal preset as an external reference). Persona
24
- * wording and tool presentation vary independently, and a run records the
25
- * baseline it ran against so an aggregated report can attribute a difference to
26
- * one factor.
19
+ * The candidate matrix follows the LiangShen V4.1 Flash improvement plan,
20
+ * minus the retired 'both' presentation arm (the SDK dropped the mode, so the
21
+ * shipped default IS the ptc wire): B (current persona + shipped 'ptc'
22
+ * presentation), P (candidate persona + shipped 'ptc' presentation), N
23
+ * (candidate persona + native presentation throughout), and M (the official
24
+ * bundle's Minimal preset as an external reference). Persona wording and tool
25
+ * presentation vary independently, and a run records the baseline it ran
26
+ * against so an aggregated report can attribute a difference to one factor.
27
27
  *
28
28
  * Usage:
29
29
  * node tools/benchmark-live-run.mjs --variant B [--timeout 300000] [--keep]
30
- * node tools/benchmark-live-run.mjs --tasks tools/tasks/liangshen-v41-flash.json --groups B,P,T,N,M --repeat 3 --max-sessions 60 --budget-cny 10 --prices tools/prices/deepseek-flash.json --out .benchmark-results
30
+ * node tools/benchmark-live-run.mjs --tasks tools/tasks/liangshen-v41-flash.json --groups B,P,N,M --repeat 3 --max-sessions 60 --budget-cny 10 --prices tools/prices/deepseek-flash.json --out .benchmark-results
31
31
  *
32
32
  * Cost is CNY: DeepSeek bills in CNY, and the published row the route prices at
33
33
  * is quoted in CNY per million tokens (cache hit / cache miss / output) off-peak,
@@ -60,7 +60,7 @@ export const DEFAULT_TURNS = [
60
60
  ]
61
61
 
62
62
  /**
63
- * The candidate persona for groups P/T/N. It keeps the identity line and replaces
63
+ * The candidate persona for groups P/N. It keeps the identity line and replaces
64
64
  * the shipped discipline: no ban on reasoning through concrete implementation, a
65
65
  * loop exits by changing method or using a tool instead of stopping, and PDCA is
66
66
  * expressed as inspect, smallest sufficient change, verify.
@@ -86,17 +86,12 @@ export const LIVE_VARIANTS = {
86
86
  B: {
87
87
  persona: 'current',
88
88
  presentation: null,
89
- note: "baseline: shipped persona, shipped 'both' presentation",
89
+ note: "baseline: shipped persona, shipped 'ptc' presentation",
90
90
  },
91
91
  P: {
92
92
  persona: 'candidate',
93
93
  presentation: null,
94
- note: "candidate persona, shipped 'both' presentation",
95
- },
96
- T: {
97
- persona: 'candidate',
98
- presentation: 'ptc',
99
- note: "candidate persona, 'ptc' presentation (collapsed wire to run_code)",
94
+ note: "candidate persona, shipped 'ptc' presentation",
100
95
  },
101
96
  N: {
102
97
  persona: 'candidate',
@@ -16,7 +16,7 @@ import { join } from 'node:path'
16
16
  import { pathToFileURL } from 'node:url'
17
17
 
18
18
  /** Presentational order of the candidate matrix. */
19
- export const GROUP_ORDER = ['B', 'P', 'T', 'N', 'M']
19
+ export const GROUP_ORDER = ['B', 'P', 'N', 'M']
20
20
 
21
21
  /** Two-sided 95% t critical values for small samples; the normal limit past 30 df. */
22
22
  const T95 = {
@@ -180,8 +180,7 @@ export function plannedComparisons(runs, baselineGroup = 'B') {
180
180
  const present = new Set(runs.map((run) => run.variant))
181
181
  const comparisons = []
182
182
  if (present.has(baselineGroup) && present.has('P')) comparisons.push(pairedComparison(runs, baselineGroup, 'P'))
183
- if (present.has('P') && present.has('T')) comparisons.push(pairedComparison(runs, 'P', 'T'))
184
- if (present.has('T') && present.has('N')) comparisons.push(pairedComparison(runs, 'T', 'N'))
183
+ if (present.has('P') && present.has('N')) comparisons.push(pairedComparison(runs, 'P', 'N'))
185
184
  if (present.has(baselineGroup) && present.has('M')) comparisons.push(pairedComparison(runs, baselineGroup, 'M'))
186
185
  return comparisons
187
186
  }
@@ -322,9 +321,8 @@ export function renderMarkdown(report) {
322
321
  lines.push('| Comparison | Purpose | Tasks paired | Mean delta (95% CI) |')
323
322
  lines.push('| --- | --- | --- | --- |')
324
323
  const purposes = {
325
- 'B-P': 'isolates the persona change',
326
- 'P-T': "compares the 'both' presentation against 'ptc'",
327
- 'T-N': 'compares the PTC transport against the native roster',
324
+ 'B-P': 'isolates the persona change at the shipped ptc wire',
325
+ 'P-N': "compares the 'ptc' presentation against the native roster",
328
326
  'B-M': 'external reference, not single-factor attribution',
329
327
  }
330
328
  for (const comparison of report.comparisons) {