@linxin666/dsh-liangshen 0.4.18 → 0.4.20
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 +11 -7
- package/README.zh.md +11 -7
- package/lib/client.js +118 -12
- package/lib/client.js.map +1 -1
- package/lib/index.js +46 -13
- package/lib/types/client/LiangShenSettingsCard.d.ts +3 -0
- package/lib/types/client/lever-controller.d.ts +26 -2
- package/lib/types/client/locales.d.ts +3 -0
- package/lib/types/client/settings-form.d.ts +2 -0
- package/lib/types/composition.d.ts +6 -0
- package/lib/types/index.d.ts +14 -1
- package/package.json +15 -15
- package/presets/liangshen/agent.cordis.yml +16 -3
- package/presets/liangshen/dispatcher-rules.mjs +87 -62
- package/presets/liangshen/fact-ledger.mjs +41 -25
- package/presets/liangshen/minimal-prompt.mjs +72 -25
- package/presets/liangshen/paging.mjs +269 -26
- package/presets/liangshen/subagent-routes.mjs +11 -22
- package/presets/liangshen/tool-activate.mjs +21 -13
- package/presets/liangshen/tool-catalog.mjs +162 -101
- package/presets/liangshen/wire-presentation.mjs +33 -0
- package/presets/liangshen/working-context.mjs +94 -96
- package/src/announce.test.ts +58 -0
- package/src/client/LiangShenSettingsCard.tsx +17 -1
- package/src/client/lever-controller.ts +57 -15
- package/src/client/locales.ts +6 -0
- package/src/client/settings-form.ts +21 -2
- package/src/composition.test.ts +33 -0
- package/src/composition.ts +22 -3
- package/src/index.test.ts +1 -0
- package/src/index.ts +37 -5
package/src/composition.ts
CHANGED
|
@@ -319,7 +319,15 @@ function parseMap(cursor: Cursor, indent: number): Record<string, unknown> {
|
|
|
319
319
|
throw new CompositionError(`line ${String(cursor.index + 1)}: duplicate key "${entry.key}"`)
|
|
320
320
|
}
|
|
321
321
|
cursor.index += 1
|
|
322
|
-
|
|
322
|
+
// Defined rather than assigned: a '__proto__' key is ordinary data here,
|
|
323
|
+
// and a plain assignment would rewrite the map's prototype instead of
|
|
324
|
+
// carrying the entry, letting a parsed document reach the prototype chain.
|
|
325
|
+
Object.defineProperty(map, entry.key, {
|
|
326
|
+
value: parseValue(cursor, indent, entry.rest),
|
|
327
|
+
enumerable: true,
|
|
328
|
+
writable: true,
|
|
329
|
+
configurable: true,
|
|
330
|
+
})
|
|
323
331
|
}
|
|
324
332
|
return map
|
|
325
333
|
}
|
|
@@ -504,6 +512,12 @@ export interface PresetOverrides {
|
|
|
504
512
|
* when blank or malformed.
|
|
505
513
|
*/
|
|
506
514
|
pagedToolPatterns?: string
|
|
515
|
+
/**
|
|
516
|
+
* Deferred idle-reclaim threshold in steps; written to every row that pages
|
|
517
|
+
* from the list (tool-catalog, tool-activate, working-context), skipped when
|
|
518
|
+
* absent.
|
|
519
|
+
*/
|
|
520
|
+
idleReclaimSteps?: number
|
|
507
521
|
}
|
|
508
522
|
|
|
509
523
|
/**
|
|
@@ -538,13 +552,18 @@ function overrideTargets(overrides: PresetOverrides): OverrideTarget[] {
|
|
|
538
552
|
// working-context renders it — so a row left on its own default would
|
|
539
553
|
// disagree about what is active and could strand a withheld namespace.
|
|
540
554
|
const pagedPatch = () => (paged === undefined ? {} : { pagedToolPatterns: [...paged] })
|
|
555
|
+
// The reclaim threshold is the same kind of three-row fact: all three rows
|
|
556
|
+
// replay the log with it, so a row left on its own default would disagree
|
|
557
|
+
// about which namespaces are still active.
|
|
558
|
+
const idlePatch = () => (overrides.idleReclaimSteps === undefined ? {} : { idleReclaimSteps: overrides.idleReclaimSteps })
|
|
541
559
|
return [
|
|
542
560
|
['tool-catalog', {
|
|
543
561
|
...overrides.presentation === undefined ? {} : { presentation: overrides.presentation },
|
|
544
562
|
...pagedPatch(),
|
|
563
|
+
...idlePatch(),
|
|
545
564
|
}],
|
|
546
|
-
['tool-activate', pagedPatch()],
|
|
547
|
-
['working-context', pagedPatch()],
|
|
565
|
+
['tool-activate', { ...pagedPatch(), ...idlePatch() }],
|
|
566
|
+
['working-context', { ...pagedPatch(), ...idlePatch() }],
|
|
548
567
|
['minimal-prompt', { ...overrides.dispatcher === undefined ? {} : { dispatcher: overrides.dispatcher } }],
|
|
549
568
|
]
|
|
550
569
|
}
|
package/src/index.test.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -111,6 +111,15 @@ export interface Config {
|
|
|
111
111
|
* malformed text is ignored.
|
|
112
112
|
*/
|
|
113
113
|
pagedToolPatterns?: ConfigField<string>
|
|
114
|
+
/**
|
|
115
|
+
* Deferred idle-reclaim threshold in steps, written to every row that replays
|
|
116
|
+
* the page (tool-catalog, tool-activate, working-context). 0 (the default)
|
|
117
|
+
* keeps every activation resident until LRU eviction — the shipped behavior.
|
|
118
|
+
* A positive N expires a namespace with no successful call for N steps, but
|
|
119
|
+
* the replay applies the expiry only at the next activation or compaction,
|
|
120
|
+
* so reclaim never adds a prefix-cache rebuild (issue #2066).
|
|
121
|
+
*/
|
|
122
|
+
idleReclaimSteps?: ConfigField<number>
|
|
114
123
|
}
|
|
115
124
|
|
|
116
125
|
export const Config = z.object({
|
|
@@ -122,6 +131,7 @@ export const Config = z.object({
|
|
|
122
131
|
]).default('ptc').volatile(),
|
|
123
132
|
dispatcher: z.boolean().default(true).volatile(),
|
|
124
133
|
pagedToolPatterns: z.string().default('').volatile(),
|
|
134
|
+
idleReclaimSteps: z.number().min(0).default(0).volatile(),
|
|
125
135
|
})
|
|
126
136
|
|
|
127
137
|
/** The settings the runtime acts on, every field read at its use site. */
|
|
@@ -136,6 +146,8 @@ export interface ResolvedConfig {
|
|
|
136
146
|
dispatcher: boolean
|
|
137
147
|
/** On-demand tool family text; empty inherits the preset's shipped list. */
|
|
138
148
|
pagedToolPatterns: string
|
|
149
|
+
/** Deferred idle-reclaim threshold in steps; 0 keeps the shipped resident behavior. */
|
|
150
|
+
idleReclaimSteps: number
|
|
139
151
|
}
|
|
140
152
|
|
|
141
153
|
/** Schema defaults, re-read for hand-built test contexts. */
|
|
@@ -145,6 +157,7 @@ export const DEFAULT_CONFIG: ResolvedConfig = {
|
|
|
145
157
|
presentation: 'ptc',
|
|
146
158
|
dispatcher: true,
|
|
147
159
|
pagedToolPatterns: '',
|
|
160
|
+
idleReclaimSteps: 0,
|
|
148
161
|
}
|
|
149
162
|
|
|
150
163
|
/**
|
|
@@ -173,11 +186,12 @@ export function resolveConfig(config?: Config): ResolvedConfig {
|
|
|
173
186
|
presentation: rawPresentation === 'both' ? 'ptc' : rawPresentation,
|
|
174
187
|
dispatcher: readField(config?.dispatcher, DEFAULT_CONFIG.dispatcher),
|
|
175
188
|
pagedToolPatterns: readField(config?.pagedToolPatterns, DEFAULT_CONFIG.pagedToolPatterns),
|
|
189
|
+
idleReclaimSteps: readField(config?.idleReclaimSteps, DEFAULT_CONFIG.idleReclaimSteps),
|
|
176
190
|
}
|
|
177
191
|
}
|
|
178
192
|
|
|
179
193
|
/** Model-facing announcement: plugin presence, principle, and limits. */
|
|
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
|
|
194
|
+
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/压缩后自然恢复。可选 idleReclaimSteps(设置「空闲收回步数」,默认 0=不收回)让连续 N 步无成功调用的已激活命名空间过期,但只在下次激活或压缩时延迟收回——这些时机前缀缓存本就要重建,因此不新增任何全量重建;应用前命名空间仍常驻可达,再次调用即续命。关键事实登记簿(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」时即指本插件,请据此协作。'
|
|
181
195
|
|
|
182
196
|
/** Order of the announcement section within the tool-guidance band. */
|
|
183
197
|
const SECTION_ORDER = 150
|
|
@@ -196,12 +210,12 @@ export function bundledPresetDir(): string {
|
|
|
196
210
|
/**
|
|
197
211
|
* Build the registry declaration of the bundled preset with the settings
|
|
198
212
|
* currently committed applied to the rows they shape.
|
|
213
|
+
* @param base - the bundled preset as parsed for this activation.
|
|
199
214
|
* @param values - the activation's effective settings.
|
|
200
215
|
* @returns the definition to submit to `ctx.agentPresets.register`.
|
|
201
216
|
*/
|
|
202
|
-
function declaration(values: ResolvedConfig): PresetDefinition {
|
|
203
|
-
|
|
204
|
-
return { ...definition, plugins: applyPresetOverrides(definition.plugins, values) }
|
|
217
|
+
function declaration(base: PresetDefinition, values: ResolvedConfig): PresetDefinition {
|
|
218
|
+
return { ...base, plugins: applyPresetOverrides(base.plugins, values) }
|
|
205
219
|
}
|
|
206
220
|
|
|
207
221
|
/**
|
|
@@ -237,6 +251,24 @@ function applyImpl(ctx: Context, config?: Config): void {
|
|
|
237
251
|
* already present at activation is never re-declared.
|
|
238
252
|
*/
|
|
239
253
|
let registryMissing = false
|
|
254
|
+
/**
|
|
255
|
+
* The bundled preset as parsed by this activation, read on first declaration.
|
|
256
|
+
* Every settings write re-declares, and the two preset files cannot change
|
|
257
|
+
* under a running row, so re-reading and re-parsing them on each write would
|
|
258
|
+
* block the event loop for a result identical to the one already held. A
|
|
259
|
+
* failed read is not remembered: the next declaration tries the disk again.
|
|
260
|
+
*/
|
|
261
|
+
let basePreset: PresetDefinition | undefined
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* The bundled preset definition for this activation, parsed at most once.
|
|
265
|
+
* The overlay derives a new row list from it, so the cached base keeps the
|
|
266
|
+
* values the composition ships for every declaration that follows.
|
|
267
|
+
*/
|
|
268
|
+
const baseDefinition = (): PresetDefinition => {
|
|
269
|
+
if (basePreset === undefined) basePreset = readPresetDefinition(LIANGSHEN_PRESET_ID, bundledPresetDir())
|
|
270
|
+
return basePreset
|
|
271
|
+
}
|
|
240
272
|
|
|
241
273
|
const warn = (message: string): void => { ctx.logger?.warn?.(`dsh-liangshen: ${message}`) }
|
|
242
274
|
|
|
@@ -275,7 +307,7 @@ function applyImpl(ctx: Context, config?: Config): void {
|
|
|
275
307
|
return
|
|
276
308
|
}
|
|
277
309
|
try {
|
|
278
|
-
release = await registry.register(declaration(values))
|
|
310
|
+
release = await registry.register(declaration(baseDefinition(), values))
|
|
279
311
|
registryMissing = false
|
|
280
312
|
ctx.logger?.info?.(`liangshen: preset ${LIANGSHEN_PRESET_ID} declared`)
|
|
281
313
|
} catch (error) {
|