@linxin666/dsh-liangshen 0.3.24 → 0.4.1
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 +24 -17
- package/README.zh.md +25 -18
- package/cordis.patch.yml +3 -2
- package/icon.svg +3 -0
- package/lib/client.js +381 -77
- package/lib/client.js.map +1 -1
- package/lib/index.js +594 -428
- package/lib/types/announce.test.d.ts +10 -0
- package/lib/types/client/LiangShenSettingsCard.d.ts +27 -10
- package/lib/types/client/PluginSettingsCard.d.ts +4 -0
- package/lib/types/client/index.d.ts +32 -13
- package/lib/types/client/lever-controller.d.ts +16 -2
- package/lib/types/client/locales.d.ts +13 -0
- package/lib/types/client/main-session.d.ts +32 -0
- package/lib/types/client/plugin-card-seat.d.ts +23 -16
- package/lib/types/client/settings-form.d.ts +17 -17
- package/lib/types/composition.d.ts +116 -0
- package/lib/types/composition.test.d.ts +7 -0
- package/lib/types/index.d.ts +146 -31
- package/lib/types/index.test.d.ts +5 -0
- package/package.json +25 -20
- package/presets/liangshen/agent.cordis.yml +44 -10
- package/presets/liangshen/fact-ledger.mjs +141 -0
- package/presets/liangshen/guard.mjs +426 -0
- package/presets/liangshen/minimal-prompt.mjs +2 -2
- package/presets/liangshen/tool-catalog.mjs +24 -20
- package/presets/liangshen/working-context.mjs +10 -2
- package/src/announce.test.ts +248 -55
- package/src/client/LiangShenLever.module.css +2 -0
- package/src/client/LiangShenLever.tsx +37 -9
- package/src/client/LiangShenSettingsCard.tsx +96 -12
- package/src/client/PluginSettingsCard.tsx +7 -2
- package/src/client/index.ts +61 -23
- package/src/client/lever-controller.ts +76 -9
- package/src/client/locales.ts +30 -4
- package/src/client/main-session.ts +43 -0
- package/src/client/plugin-card-seat.ts +24 -17
- package/src/client/settings-form.ts +34 -31
- package/src/composition.test.ts +294 -0
- package/src/composition.ts +554 -0
- package/src/index.test.ts +68 -1
- package/src/index.ts +278 -107
- package/tools/benchmark-live-run.mjs +171 -32
- package/lib/types/schema.d.ts +0 -18
- package/lib/types/schema.test.d.ts +0 -1
- package/lib/types/sync.d.ts +0 -74
- package/lib/types/sync.test.d.ts +0 -1
- package/src/schema.test.ts +0 -64
- package/src/schema.ts +0 -110
- package/src/sync.test.ts +0 -303
- package/src/sync.ts +0 -324
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The composition reader the preset declaration is built from. It is the only
|
|
3
|
+
* thing standing between the shipped `agent.cordis.yml` and the registry, and
|
|
4
|
+
* it must not guess: these tests fence the supported subset against the real
|
|
5
|
+
* file, the settings overlay, and every construct it refuses.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { readFileSync } from 'node:fs'
|
|
9
|
+
import { join } from 'node:path'
|
|
10
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
11
|
+
import type { PresetDefinition } from '@deepseek-ai/dsh-agent-preset-registry'
|
|
12
|
+
import { describe, expect, it } from 'vitest'
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
CompositionError,
|
|
16
|
+
applyPresetOverrides,
|
|
17
|
+
readCompositionRows,
|
|
18
|
+
readPresetDefinition,
|
|
19
|
+
readPresetMetadata,
|
|
20
|
+
type CompositionRow,
|
|
21
|
+
} from './composition.ts'
|
|
22
|
+
|
|
23
|
+
const presetDir = join(process.cwd(), 'presets', 'liangshen')
|
|
24
|
+
const shipped = readFileSync(join(presetDir, 'agent.cordis.yml'), 'utf8')
|
|
25
|
+
|
|
26
|
+
/** The shipped composition parsed for the preset's own directory. */
|
|
27
|
+
function rows(): PresetDefinition['plugins'] {
|
|
28
|
+
return readCompositionRows(shipped, presetDir)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The rows of one parsed list as the loose records these tests read. */
|
|
32
|
+
function loose(list: PresetDefinition['plugins']): readonly CompositionRow[] {
|
|
33
|
+
return list as readonly CompositionRow[]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** One row of a parsed list, by id. */
|
|
37
|
+
function rowOf(list: PresetDefinition['plugins'], id: string): CompositionRow {
|
|
38
|
+
const found = loose(list).find(row => row.id === id)
|
|
39
|
+
if (found === undefined) throw new Error(`the composition carries no row ${id}`)
|
|
40
|
+
return found
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** One row's configuration, asserted to be the map the plugins mount with. */
|
|
44
|
+
function configOf(row: CompositionRow): Record<string, unknown> {
|
|
45
|
+
expect(typeof row.config).toBe('object')
|
|
46
|
+
return row.config as Record<string, unknown>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
describe('readCompositionRows', () => {
|
|
50
|
+
it('operator reads every row of the shipped composition once', () => {
|
|
51
|
+
// Given the shipped composition, When the operator reads it for the preset
|
|
52
|
+
// directory, Then every row arrives with a unique id and a module name.
|
|
53
|
+
const parsed = rows()
|
|
54
|
+
const ids = loose(parsed).map(row => row.id)
|
|
55
|
+
expect(ids.length).toBeGreaterThan(20)
|
|
56
|
+
expect(new Set(ids).size).toBe(ids.length)
|
|
57
|
+
for (const row of parsed) expect(typeof row.name).toBe('string')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('operator resolves relative module names against the preset directory', () => {
|
|
61
|
+
// Given a declaration mounted under the registry's own loader base, When
|
|
62
|
+
// the operator reads a relative row name, Then it is an absolute file URL
|
|
63
|
+
// beside the composition, while a bare package name stays a specifier.
|
|
64
|
+
expect(rowOf(rows(), 'minimal-prompt').name).toBe(pathToFileURL(join(presetDir, 'minimal-prompt.mjs')).href)
|
|
65
|
+
expect(rowOf(rows(), 'tool-catalog').name).toBe(pathToFileURL(join(presetDir, 'tool-catalog.mjs')).href)
|
|
66
|
+
expect(rowOf(rows(), 'persona').name).toBe('@deepseek-ai/dsh-persona')
|
|
67
|
+
expect(rowOf(rows(), 'tool-bash').name).toBe('@deepseek-ai/dsh-tool-bash')
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('operator keeps the row configuration the plugins mount with', () => {
|
|
71
|
+
// Given the tool-catalog row, When the operator reads its config, Then the
|
|
72
|
+
// shipped scalars and the single-line flow sequence survive.
|
|
73
|
+
const catalog = configOf(rowOf(rows(), 'tool-catalog'))
|
|
74
|
+
expect(catalog['presentation']).toBe('both')
|
|
75
|
+
expect(catalog['descriptionMaxLength']).toBe(200)
|
|
76
|
+
expect(catalog['maxResidentTokens']).toBe(8000)
|
|
77
|
+
expect(catalog['pagedToolPatterns']).toEqual(['mcp__*'])
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('operator keeps a literal block scalar verbatim', () => {
|
|
81
|
+
// Given the persona row's `prefix: |-` scalar, When the operator reads it,
|
|
82
|
+
// Then the prose is content and the next composition row ends it.
|
|
83
|
+
const persona = configOf(rowOf(rows(), 'persona'))
|
|
84
|
+
const prefix = persona['prefix']
|
|
85
|
+
expect(typeof prefix).toBe('string')
|
|
86
|
+
expect(prefix as string).toContain('You are a helpful software engineer assistant.')
|
|
87
|
+
expect(prefix as string).toContain('Thinking Disruption: Never reason through the same hypothesis more than twice')
|
|
88
|
+
expect(prefix as string).not.toContain('- id: minimal-prompt')
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('operator keeps a loader expression as data instead of executing it', () => {
|
|
92
|
+
// Given the platform-conditional shell rows, When the operator reads them,
|
|
93
|
+
// Then each `!!js` expression arrives as data for the Loader to evaluate.
|
|
94
|
+
expect(rowOf(rows(), 'tool-bash').disabled).toEqual({ __jsExpr: "process.platform === 'win32'" })
|
|
95
|
+
expect(rowOf(rows(), 'tool-pwsh').disabled).toEqual({ __jsExpr: "process.platform !== 'win32'" })
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('operator reads the nested entry list of a group row', () => {
|
|
99
|
+
// Given the planning and compaction group rows, When the operator reads
|
|
100
|
+
// them, Then the realm keys survive and their child rows are read too.
|
|
101
|
+
const planning = rowOf(rows(), 'planning')
|
|
102
|
+
expect(planning.group).toBe(true)
|
|
103
|
+
expect(planning.isolate).toEqual({ planMode: true })
|
|
104
|
+
const nested = planning.config as readonly CompositionRow[]
|
|
105
|
+
expect(Array.isArray(nested)).toBe(true)
|
|
106
|
+
expect(nested.map(row => row.id)).toEqual(['plan-mode'])
|
|
107
|
+
expect(rowOf(rows(), 'compaction').group).toBe(true)
|
|
108
|
+
expect((rowOf(rows(), 'compaction').config as readonly CompositionRow[]).map(row => row.id))
|
|
109
|
+
.toEqual(['compaction-basic', 'command-compact', 'tool-result-pruner'])
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('operator is refused a document the registry could never mount', () => {
|
|
113
|
+
// Given row lists that name no plugin, When the operator reads them, Then
|
|
114
|
+
// each is refused instead of producing an unmountable declaration.
|
|
115
|
+
expect(() => readCompositionRows('name: nope\n', presetDir)).toThrow(CompositionError)
|
|
116
|
+
expect(() => readCompositionRows('- id: a\n', presetDir)).toThrow(/names no plugin/)
|
|
117
|
+
expect(() => readCompositionRows('- name: ./x.mjs\n group: true\n config: nope\n', presetDir)).toThrow(/must hold a list/)
|
|
118
|
+
expect(() => readCompositionRows('- name: cordis:group\n group: true\n config:\n - nope\n', presetDir))
|
|
119
|
+
.toThrow(/not a plugin row/)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('operator is refused YAML outside the supported subset', () => {
|
|
123
|
+
// Given constructs the subset does not cover, When the operator reads them,
|
|
124
|
+
// Then every one raises instead of being guessed at.
|
|
125
|
+
const cases: readonly [string, RegExp][] = [
|
|
126
|
+
['- name: &a ./x.mjs\n', /unsupported YAML node/],
|
|
127
|
+
['- name: *a\n', /unsupported YAML node/],
|
|
128
|
+
['- name: !tag ./x.mjs\n', /unsupported YAML node/],
|
|
129
|
+
['- name: ./x.mjs\n config: {a: 1}\n', /flow mappings are not supported/],
|
|
130
|
+
['- name: ./x.mjs\n config: [[1]]\n', /nested flow collections are not supported/],
|
|
131
|
+
['- name: ./x.mjs\n config: [1,]\n', /empty item in a flow sequence/],
|
|
132
|
+
['- name: ./x.mjs\n config: [1\n', /unterminated flow sequence/],
|
|
133
|
+
['- name: ./x.mjs\n config: [1] trailing\n', /unexpected content after a flow sequence/],
|
|
134
|
+
['- name: ./x.mjs\n\tconfig: 1\n', /tabs must not be used for indentation/],
|
|
135
|
+
['- name: ./x.mjs\n config: |\n a\n b\n', /unexpected/],
|
|
136
|
+
['- name: "unterminated\n', /unterminated/],
|
|
137
|
+
['- name: ./x.mjs\n config: !!js\n', /!!js requires an expression/],
|
|
138
|
+
['- name: ./x.mjs\n config:\n a: 1\n a: 2\n', /duplicate key/],
|
|
139
|
+
['- name: ./x.mjs\nname: ./y.mjs\n', /unexpected indentation|unexpected content/],
|
|
140
|
+
['- name: ./x.mjs\n stray: 1\n', /unexpected indentation|not a plugin row/],
|
|
141
|
+
['', /not a plugin row|must be a top-level list/],
|
|
142
|
+
]
|
|
143
|
+
for (const [text, expected] of cases) {
|
|
144
|
+
expect(() => readCompositionRows(text, presetDir), text).toThrow(expected)
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
it('operator reads scalars the way YAML does', () => {
|
|
149
|
+
// Given a config map of every scalar shape the composition uses, When the
|
|
150
|
+
// operator reads it, Then each value resolves as YAML resolves it.
|
|
151
|
+
const parsed = readCompositionRows([
|
|
152
|
+
'- name: ./x.mjs',
|
|
153
|
+
' config:',
|
|
154
|
+
' truth: true',
|
|
155
|
+
' lie: false',
|
|
156
|
+
' empty: ~',
|
|
157
|
+
' count: 42',
|
|
158
|
+
' ratio: 0.5',
|
|
159
|
+
" quoted: 'it''s here'",
|
|
160
|
+
' double: "a\\nb"',
|
|
161
|
+
' plain: a value',
|
|
162
|
+
' hashed: a # comment',
|
|
163
|
+
' url: http://example.test/x#frag',
|
|
164
|
+
'',
|
|
165
|
+
].join('\n'), presetDir)
|
|
166
|
+
expect(configOf(loose(parsed)[0]!)).toEqual({
|
|
167
|
+
truth: true,
|
|
168
|
+
lie: false,
|
|
169
|
+
empty: null,
|
|
170
|
+
count: 42,
|
|
171
|
+
ratio: 0.5,
|
|
172
|
+
quoted: "it's here",
|
|
173
|
+
double: 'a\nb',
|
|
174
|
+
plain: 'a value',
|
|
175
|
+
hashed: 'a',
|
|
176
|
+
url: 'http://example.test/x#frag',
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('operator reads an absolute name as written and nested sequences of maps', () => {
|
|
181
|
+
// Given a group row whose child rows carry a nested list and an absolute
|
|
182
|
+
// module path, When the operator reads it, Then neither is rewritten.
|
|
183
|
+
const parsed = readCompositionRows([
|
|
184
|
+
'- id: top',
|
|
185
|
+
' name: cordis:group',
|
|
186
|
+
' group: true',
|
|
187
|
+
' config:',
|
|
188
|
+
' - id: inner',
|
|
189
|
+
" name: '@scope/pkg'",
|
|
190
|
+
' config:',
|
|
191
|
+
' list:',
|
|
192
|
+
' - one',
|
|
193
|
+
' - two',
|
|
194
|
+
' - name: /absolute/plugin.mjs',
|
|
195
|
+
'',
|
|
196
|
+
].join('\n'), presetDir)
|
|
197
|
+
const nested = rowOf(parsed, 'top').config as readonly CompositionRow[]
|
|
198
|
+
expect(nested.map(row => row.id)).toEqual(['inner', undefined])
|
|
199
|
+
expect(configOf(nested[0]!)['list']).toEqual(['one', 'two'])
|
|
200
|
+
expect(nested[1]!.name).toBe('/absolute/plugin.mjs')
|
|
201
|
+
})
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
describe('readPresetMetadata', () => {
|
|
205
|
+
it('operator reads the shipped display map', () => {
|
|
206
|
+
// Given the shipped preset.yml, When the operator reads it, Then the
|
|
207
|
+
// roster receives the display name, the sentence and the order rank.
|
|
208
|
+
const metadata = readPresetMetadata(readFileSync(join(presetDir, 'preset.yml'), 'utf8'))
|
|
209
|
+
expect(metadata.name).toBe('梁神模式')
|
|
210
|
+
expect(metadata.order).toBe(4)
|
|
211
|
+
expect(metadata.description?.length).toBeGreaterThan(0)
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
it('operator reads a display map with no optional field', () => {
|
|
215
|
+
// Given a preset.yml carrying only a name, When the operator reads it,
|
|
216
|
+
// Then the absent fields are simply not supplied.
|
|
217
|
+
expect(readPresetMetadata('name: only\n')).toEqual({ name: 'only' })
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
it('operator is refused a display map the roster cannot render', () => {
|
|
221
|
+
// Given a list, a multi-line name and a non-numeric order, When the
|
|
222
|
+
// operator reads them, Then each is refused rather than coerced.
|
|
223
|
+
expect(() => readPresetMetadata('- a\n')).toThrow(/must be a mapping/)
|
|
224
|
+
expect(() => readPresetMetadata('# nothing but a comment\n')).toThrow(/must be a mapping/)
|
|
225
|
+
expect(() => readPresetMetadata('name: |\n two\n lines\n')).toThrow(/single-line string/)
|
|
226
|
+
expect(() => readPresetMetadata('order: soon\n')).toThrow(/order must be a number/)
|
|
227
|
+
})
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
describe('applyPresetOverrides', () => {
|
|
231
|
+
it('operator keeps the composition unchanged when no setting is overridden', () => {
|
|
232
|
+
// Given the shipped rows and empty settings, When the operator applies the
|
|
233
|
+
// overlay, Then the declaration is exactly what the composition declares.
|
|
234
|
+
const parsed = rows()
|
|
235
|
+
expect(applyPresetOverrides(parsed, {})).toEqual(parsed)
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
it('operator writes the settings into the rows that carry them', () => {
|
|
239
|
+
// Given committed settings, When the operator applies the overlay, Then
|
|
240
|
+
// the tool-catalog and guard rows carry them and nothing else moves.
|
|
241
|
+
const applied = applyPresetOverrides(rows(), {
|
|
242
|
+
presentation: 'ptc',
|
|
243
|
+
guardEnabled: false,
|
|
244
|
+
guardSensitivity: 'aggressive',
|
|
245
|
+
guardStallReasoningChars: 12000,
|
|
246
|
+
guardGlobalStallCap: 6,
|
|
247
|
+
guardEchoFailures: 2,
|
|
248
|
+
})
|
|
249
|
+
expect(configOf(rowOf(applied, 'tool-catalog'))['presentation']).toBe('ptc')
|
|
250
|
+
expect(configOf(rowOf(applied, 'guard'))).toEqual({
|
|
251
|
+
enabled: false,
|
|
252
|
+
sensitivity: 'aggressive',
|
|
253
|
+
stallReasoningChars: 12000,
|
|
254
|
+
globalStallCap: 6,
|
|
255
|
+
echoFailures: 2,
|
|
256
|
+
})
|
|
257
|
+
expect(configOf(rowOf(applied, 'tool-catalog'))['descriptionMaxLength']).toBe(200)
|
|
258
|
+
expect(rowOf(applied, 'minimal-prompt')).toEqual(rowOf(rows(), 'minimal-prompt'))
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
it('operator is never given a row the composition does not carry', () => {
|
|
262
|
+
// Given a composition with no tool-catalog row, When the operator applies
|
|
263
|
+
// a presentation choice, Then no row is invented for it.
|
|
264
|
+
const parsed = readCompositionRows('- id: other\n name: ./other.mjs\n config:\n presentation: both\n', presetDir)
|
|
265
|
+
const applied = applyPresetOverrides(parsed, { presentation: 'ptc' })
|
|
266
|
+
expect(applied).toEqual(parsed)
|
|
267
|
+
})
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
describe('readPresetDefinition', () => {
|
|
271
|
+
it('operator builds the declaration from the shipped preset directory', () => {
|
|
272
|
+
// Given the bundled preset directory, When the operator reads its
|
|
273
|
+
// declaration, Then it carries the display text and mountable module rows.
|
|
274
|
+
const definition = readPresetDefinition('liangshen', presetDir)
|
|
275
|
+
expect(definition.id).toBe('liangshen')
|
|
276
|
+
expect(definition.name).toBe('梁神模式')
|
|
277
|
+
expect(definition.order).toBe(4)
|
|
278
|
+
expect(definition.plugins.length).toBe(loose(rows()).length)
|
|
279
|
+
for (const plugin of definition.plugins) {
|
|
280
|
+
expect(plugin.name, JSON.stringify(plugin)).toMatch(/^(file:|@|\.\/|cordis:)/)
|
|
281
|
+
}
|
|
282
|
+
const local = definition.plugins.filter(plugin => (plugin.name ?? '').startsWith('file:'))
|
|
283
|
+
expect(local.length).toBeGreaterThan(4)
|
|
284
|
+
for (const plugin of local) {
|
|
285
|
+
expect(fileURLToPath(plugin.name!)).toContain('presets')
|
|
286
|
+
}
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
it('operator is refused a directory that is not a preset', () => {
|
|
290
|
+
// Given a path holding no preset files, When the operator reads a
|
|
291
|
+
// declaration from it, Then the failure names the unreadable file.
|
|
292
|
+
expect(() => readPresetDefinition('nope', join(process.cwd(), 'presets', 'nope'))).toThrow(/unreadable/)
|
|
293
|
+
})
|
|
294
|
+
})
|