@linxin666/dsh-liangshen 0.4.4 → 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.
- package/README.i18n.yaml +2 -2
- package/README.md +27 -9
- package/README.zh.md +26 -8
- package/lib/client.js +134 -31
- package/lib/client.js.map +1 -1
- package/lib/index.js +33 -19
- package/lib/types/client/LiangShenMark.d.ts +13 -0
- package/lib/types/client/LiangShenSettingsCard.d.ts +11 -7
- package/lib/types/client/PluginSettingsCard.d.ts +7 -0
- package/lib/types/client/locales.d.ts +3 -0
- package/lib/types/client/plugin-card-seat.d.ts +5 -0
- package/lib/types/client/settings-form.d.ts +16 -0
- package/lib/types/composition.d.ts +15 -11
- package/lib/types/index.d.ts +44 -22
- package/package.json +16 -16
- package/presets/liangshen/agent.cordis.yml +41 -6
- package/presets/liangshen/dispatcher-rules.mjs +121 -0
- package/presets/liangshen/guard.mjs +134 -34
- package/presets/liangshen/minimal-prompt.mjs +65 -9
- package/presets/liangshen/tool-catalog.mjs +45 -12
- package/src/announce.test.ts +3 -2
- package/src/client/LiangShenMark.tsx +25 -0
- package/src/client/LiangShenSettingsCard.tsx +29 -10
- package/src/client/PluginSettingsCard.tsx +9 -0
- package/src/client/locales.ts +16 -10
- package/src/client/plugin-card-seat.ts +7 -0
- package/src/client/settings-card.module.css +31 -5
- package/src/client/settings-form.ts +27 -1
- package/src/composition.test.ts +56 -0
- package/src/composition.ts +16 -11
- package/src/index.test.ts +56 -0
- package/src/index.ts +51 -23
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
|
-
*
|
|
112
|
-
*
|
|
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
|
-
|
|
129
|
+
guardGlobalStallCap?: ConfigField<number | undefined>
|
|
115
130
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
131
|
+
* Override for the echo ladder. Left unset, the count scales with
|
|
132
|
+
* `guardSensitivity`.
|
|
118
133
|
*/
|
|
119
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
/**
|
|
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:
|
|
163
|
-
guardGlobalStallCap:
|
|
164
|
-
guardEchoFailures:
|
|
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
|
|
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
|