@linxin666/dsh-liangshen 0.3.20 → 0.3.22

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.
Files changed (38) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +69 -39
  3. package/README.zh.md +70 -40
  4. package/lib/client.js +640 -0
  5. package/lib/client.js.map +1 -0
  6. package/lib/index.js +11 -6
  7. package/lib/types/announce.test.d.ts +1 -0
  8. package/lib/types/client/LiangShenLever.d.ts +17 -0
  9. package/lib/types/client/index.d.ts +45 -0
  10. package/lib/types/client/lever-controller.d.ts +133 -0
  11. package/lib/types/client/locales.d.ts +27 -0
  12. package/lib/types/core/lever.d.ts +50 -0
  13. package/lib/types/index.d.ts +11 -6
  14. package/lib/types/index.test.d.ts +1 -0
  15. package/lib/types/schema.test.d.ts +1 -0
  16. package/lib/types/sync.test.d.ts +1 -0
  17. package/package.json +29 -2
  18. package/presets/liangshen/NOTICE +4 -3
  19. package/presets/liangshen/agent.cordis.yml +129 -86
  20. package/presets/liangshen/custom-bash.mjs +4 -4
  21. package/presets/liangshen/minimal-prompt.mjs +835 -0
  22. package/presets/liangshen/tool-catalog.mjs +631 -0
  23. package/src/client/LiangShenLever.module.css +314 -0
  24. package/src/client/LiangShenLever.tsx +176 -0
  25. package/src/client/css-modules.d.ts +5 -0
  26. package/src/client/index.ts +89 -0
  27. package/src/client/lever-controller.ts +331 -0
  28. package/src/client/locales.ts +46 -0
  29. package/src/core/lever.ts +68 -0
  30. package/src/index.ts +11 -6
  31. package/src/schema.test.ts +1 -1
  32. package/src/sync.test.ts +4 -4
  33. package/tools/analyze-session.mjs +25 -5
  34. package/tools/benchmark-driver.mjs +124 -0
  35. package/tools/benchmark-live-run.mjs +771 -0
  36. package/tools/benchmark-report.mjs +354 -0
  37. package/tools/tasks/liangshen-v41-flash.json +127 -0
  38. package/presets/liangshen/tool-bootstrap.mjs +0 -601
@@ -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
+ }