@linxin666/dsh-liangshen 0.3.21 → 0.3.23
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 +38 -24
- package/README.zh.md +38 -24
- package/lib/index.js +11 -10
- package/lib/types/index.d.ts +11 -10
- package/package.json +2 -2
- package/presets/liangshen/agent.cordis.yml +34 -27
- package/presets/liangshen/minimal-prompt.mjs +393 -92
- package/presets/liangshen/tool-catalog.mjs +302 -189
- package/src/index.ts +11 -10
- package/tools/benchmark-driver.mjs +124 -0
- package/tools/benchmark-live-run.mjs +771 -0
- package/tools/benchmark-report.mjs +354 -0
- package/tools/tasks/liangshen-v41-flash.json +127 -0
package/src/index.ts
CHANGED
|
@@ -9,15 +9,16 @@
|
|
|
9
9
|
* surface (plugin config) or the profile patch. No browser half, no routes,
|
|
10
10
|
* no agent tools — the preset itself provides the tools.
|
|
11
11
|
*
|
|
12
|
-
* The preset
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
12
|
+
* The preset combines a minimal persona with a staged, promoted tool surface:
|
|
13
|
+
* the system prompt keeps a minimal persona with standing working discipline
|
|
14
|
+
* and workspace instructions, the session's entire first user turn runs a native
|
|
15
|
+
* foundational tool surface ([bash, str_replace_editor, exit_plan_mode, skill],
|
|
16
|
+
* with bash-only preserved as a configuration experiment), and from the second
|
|
17
|
+
* turn this session presents its tools in PTC mode upon successful activation,
|
|
18
|
+
* so the wire carries the single `run_code` transport while the generated SDK
|
|
19
|
+
* bindings and collapse rule travel in the tool list injected as a durable
|
|
20
|
+
* message after the user's message, preserving full input and output key
|
|
21
|
+
* parameter semantics.
|
|
21
22
|
*/
|
|
22
23
|
|
|
23
24
|
import { mkdirSync } from 'node:fs'
|
|
@@ -60,7 +61,7 @@ const DEFAULT_ANNOUNCE = false
|
|
|
60
61
|
const SECTION_ORDER = 150
|
|
61
62
|
|
|
62
63
|
/** Model-facing announcement: plugin presence, principle, and limits. */
|
|
63
|
-
export const LIANGSHEN_GUIDANCE = '本机已安装 dsh-liangshen 插件(梁神模式 agent preset
|
|
64
|
+
export const LIANGSHEN_GUIDANCE = '本机已安装 dsh-liangshen 插件(梁神模式 agent preset):新建会话的预设选择器中可选「梁神模式」。原理:系统提示词保持极简 persona(minimal-prompt 放行该段与 plan 模式的 plan:policy),persona 内置本模式工作纪律(思维循环即断、先理解需求与方案再实现验证、YAGNI/PDCA、代码不加冗余注释),并在组装时追加工作区目录 Your working directory is <cwd>. 与 AGENTS.md 工作区指令(workspace-instructions 段,65536 字节预算,每次组装重读);工具清单由 tool-catalog 从第一条用户消息起以 user 消息注入在用户消息之后,形如 skill catalog,仅当工具集变化或该消息离开可见面(压缩、恢复)时重发;wire 上的 schema 按回合分层:首轮整个 user turn 原生呈现基础锚定工具集(默认 [bash, str_replace_editor, exit_plan_mode, skill],且保留 bash-only 配置实验),第二个回合起在 PTC 成功激活后切换为 PTC 呈现(wire 上只有 run_code,其余工具在程序里以 await tools.<name>({...}) 调用,保留完整输入输出关键参数语义而非 200 字唯一契约;缺失 code runtime 时优雅回退至原生呈现);注入消息承载 SDK 绑定、程序契约(一段程序编排多步:独立只读调用用 Promise.all 并发、ToolCallError 处理、输出自选)与「激活后只有 run_code 可直接调用」的规则。工作区子目录动态指令支持注册文件工具含 str_replace_editor 及 PTC 内子调用触达的目录(不解析任意 bash/program 代码)。文件操作受宿主沙箱约束,Windows 下 bash 为 Git Bash 子进程且状态不跨调用保留。真实推理探针通过不等于模式集成通过,更不等于统计效果提升。preset 文件由插件维护于 ~/.dsh/.agent-presets,升级插件时自动更新;默认预设由用户自行选择。用户提到「梁神模式 / 锚定模式 / anchored standard」时即指本插件,请据此协作。'
|
|
64
65
|
// The harness-home resolution (DSH_HOME override with the platform-home
|
|
65
66
|
// fallback and ~ expansion) lives in the family-shared copy ./dsh-home.ts.
|
|
66
67
|
// Re-export it so the plugin surface stays stable while the implementation is
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Benchmark multi-turn agent driver.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the one-shot \`headless-runner\` row so a benchmark run can drive
|
|
5
|
+
* SEVERAL turns through ONE session: the preset's anchor turn and the promoted
|
|
6
|
+
* turn are a single session's first and second turn, so a one-shot driver could
|
|
7
|
+
* never observe the handoff.
|
|
8
|
+
*
|
|
9
|
+
* The composition it runs under is the real one: the profile's own registry,
|
|
10
|
+
* sandbox, persistence, and model rows, plus the preset mounted through
|
|
11
|
+
* \`agentPresets.mount\` exactly as the production session controller does
|
|
12
|
+
* (\`packages/api/session-controller/src/agent.ts\`, \`composeAgent\`).
|
|
13
|
+
*
|
|
14
|
+
* Nothing here is model-facing; it is evaluation scaffolding.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { writeFileSync } from 'node:fs'
|
|
18
|
+
import { join } from 'node:path'
|
|
19
|
+
import { createUserMessage } from '@deepseek-ai/dsh-llm'
|
|
20
|
+
|
|
21
|
+
/** Stable Cordis plugin name. */
|
|
22
|
+
export const name = 'benchmark-driver'
|
|
23
|
+
|
|
24
|
+
/** The official services this driver drives. */
|
|
25
|
+
export const inject = ['agents', 'sessions', 'agentDefaultModel']
|
|
26
|
+
|
|
27
|
+
/** One synthetic session id; uniqueness only has to hold within one run. */
|
|
28
|
+
function sessionIdFor(runId) {
|
|
29
|
+
return runId ?? `bench-${Date.now()}-${Math.floor(Math.random() * 1e6)}`
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Run every configured turn through one freshly created agent.
|
|
34
|
+
* @param ctx - host context carrying the driver's injected services.
|
|
35
|
+
* @param config - resolved driver config.
|
|
36
|
+
* @param io - process-facing effects.
|
|
37
|
+
*/
|
|
38
|
+
async function run(ctx, config, io) {
|
|
39
|
+
// Loader siblings mount concurrently: await the whole application before
|
|
40
|
+
// creating an agent, or its scoped tools and adapters are half-composed.
|
|
41
|
+
await ctx.get('loader')?.await()
|
|
42
|
+
const agents = ctx.get('agents')
|
|
43
|
+
const sessions = ctx.get('sessions')
|
|
44
|
+
const defaultModel = ctx.get('agentDefaultModel')
|
|
45
|
+
if (agents === undefined || sessions === undefined || defaultModel === undefined) {
|
|
46
|
+
throw new Error('benchmark-driver: agents, sessions, and agentDefaultModel must all be mounted')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const turns = Array.isArray(config?.turns) ? config.turns : []
|
|
50
|
+
if (turns.length === 0) throw new Error('benchmark-driver: at least one turn is required')
|
|
51
|
+
|
|
52
|
+
const presetId = typeof config?.preset === 'string' && config.preset.length > 0 ? config.preset : undefined
|
|
53
|
+
const cwd = typeof config?.cwd === 'string' && config.cwd.length > 0 ? config.cwd : process.cwd()
|
|
54
|
+
const selection = defaultModel.currentSelection()
|
|
55
|
+
const presets = ctx.get('agentPresets')
|
|
56
|
+
|
|
57
|
+
const { agent, dispose } = await agents.create({
|
|
58
|
+
sessionId: sessionIdFor(config?.sessionId),
|
|
59
|
+
meta: { cwd, ...presetId === undefined ? {} : { agentPreset: presetId } },
|
|
60
|
+
agentOptions: {
|
|
61
|
+
provider: selection.provider,
|
|
62
|
+
model: selection.model,
|
|
63
|
+
...selection.reasoningEffort === undefined ? {} : { reasoningEffort: selection.reasoningEffort },
|
|
64
|
+
},
|
|
65
|
+
setup: async (agentCtx) => {
|
|
66
|
+
// Joining the preset is what makes its rows (persona filter, tool catalog,
|
|
67
|
+
// shell) cover this agent. Without a roster the agent keeps host-plane rows,
|
|
68
|
+
// which is exactly the 'standard' baseline variant.
|
|
69
|
+
if (presetId === undefined) return
|
|
70
|
+
if (presets === undefined) {
|
|
71
|
+
throw new Error(`benchmark-driver: preset "${presetId}" was requested but no agentPresets roster is mounted`)
|
|
72
|
+
}
|
|
73
|
+
await presets.mount(agentCtx, presetId)
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const outcome = { ok: true, preset: presetId ?? null, cwd, turns: [], provider: selection.provider, model: selection.model }
|
|
78
|
+
try {
|
|
79
|
+
await agent.whenIdle()
|
|
80
|
+
outcome.sessionId = String(agent.session.header.id)
|
|
81
|
+
for (const turn of turns) {
|
|
82
|
+
const before = agent.session.seq
|
|
83
|
+
agent.followup(createUserMessage({ content: [{ type: 'text', text: String(turn) }], source: { kind: 'user' } }))
|
|
84
|
+
await agent.whenIdle()
|
|
85
|
+
outcome.turns.push({ fromSeq: before, toSeq: agent.session.seq })
|
|
86
|
+
}
|
|
87
|
+
await sessions.flush(agent.session)
|
|
88
|
+
} finally {
|
|
89
|
+
try {
|
|
90
|
+
await dispose()
|
|
91
|
+
} catch {
|
|
92
|
+
// Disposal is best-effort: the run's evidence is already persisted.
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
writeFileSync(join(cwd, 'benchmark-driver-outcome.json'), JSON.stringify(outcome, null, 2))
|
|
97
|
+
return outcome
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Mount the multi-turn driver.
|
|
102
|
+
* @param ctx - plugin context carrying core services and the launcher's exit.
|
|
103
|
+
* @param config - validated driver config.
|
|
104
|
+
*/
|
|
105
|
+
export function apply(ctx, config) {
|
|
106
|
+
const exit = ctx.get('appExit')
|
|
107
|
+
if (exit === undefined) throw new Error('benchmark-driver: the launcher must provide ctx.appExit before the tree mounts')
|
|
108
|
+
const io = { stdout: process.stdout, stderr: process.stderr, exit }
|
|
109
|
+
void run(ctx, config, io).then(
|
|
110
|
+
() => { exit(0) },
|
|
111
|
+
(error) => {
|
|
112
|
+
io.stderr.write(`benchmark-driver: ${error instanceof Error ? error.stack ?? error.message : String(error)}\n`)
|
|
113
|
+
try {
|
|
114
|
+
writeFileSync(join(process.cwd(), 'benchmark-driver-outcome.json'), JSON.stringify({
|
|
115
|
+
ok: false,
|
|
116
|
+
error: error instanceof Error ? error.message : String(error),
|
|
117
|
+
}, null, 2))
|
|
118
|
+
} catch {
|
|
119
|
+
// The failure is already on stderr.
|
|
120
|
+
}
|
|
121
|
+
exit(1)
|
|
122
|
+
},
|
|
123
|
+
)
|
|
124
|
+
}
|