@linxin666/dsh-liangshen 0.3.24 → 0.4.0
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
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* One bounded live benchmark run: a real DeepSeek session driven through the
|
|
3
|
-
* profile's own composition, with the evaluated preset supplied
|
|
4
|
-
*
|
|
3
|
+
* profile's own composition, with the evaluated preset supplied as an ISOLATED
|
|
4
|
+
* registry declaration.
|
|
5
5
|
*
|
|
6
6
|
* Isolation rules this script follows:
|
|
7
7
|
* - The harness home stays the real one, so credentials, settings, and the model
|
|
8
8
|
* route resolve exactly as they do for a user session. Nothing is copied or read
|
|
9
9
|
* by this script.
|
|
10
|
-
* - The evaluated preset is
|
|
11
|
-
*
|
|
12
|
-
* installed preset is edited.
|
|
10
|
+
* - The evaluated preset is materialized into a temporary directory and declared
|
|
11
|
+
* to the run's own agent-preset registry from the variant patch, so an installed
|
|
12
|
+
* preset cannot shadow it and no installed preset is edited. (Presets stopped
|
|
13
|
+
* being discovered from a configured root at 0.1.7-alpha.1: a preset is an
|
|
14
|
+
* ordinary registry declaration now, so there is no roster `roots` config to
|
|
15
|
+
* aim at.)
|
|
13
16
|
* - Session persistence is redirected into the run directory, so real session
|
|
14
17
|
* history is never appended to.
|
|
15
18
|
*
|
|
@@ -29,11 +32,11 @@
|
|
|
29
32
|
|
|
30
33
|
import { execFileSync, spawn } from 'node:child_process'
|
|
31
34
|
import { createHash } from 'node:crypto'
|
|
32
|
-
import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
35
|
+
import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
33
36
|
import { createRequire } from 'node:module'
|
|
34
37
|
import { tmpdir } from 'node:os'
|
|
35
38
|
import { dirname, join, relative, resolve, sep } from 'node:path'
|
|
36
|
-
import { fileURLToPath } from 'node:url'
|
|
39
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
37
40
|
|
|
38
41
|
const HERE = dirname(fileURLToPath(import.meta.url))
|
|
39
42
|
const PACKAGE_ROOT = resolve(HERE, '..')
|
|
@@ -136,13 +139,51 @@ function spawnCaptured(command, args, options, timeoutMs) {
|
|
|
136
139
|
})
|
|
137
140
|
}
|
|
138
141
|
|
|
139
|
-
/**
|
|
140
|
-
|
|
142
|
+
/**
|
|
143
|
+
* The official Minimal preset's declaration file: the `dsh-web-app` bundle
|
|
144
|
+
* patch that inserts the `@deepseek-ai/dsh-agent-preset` row for `minimal`.
|
|
145
|
+
* Resolved from the harness install the run actually spawns, because the
|
|
146
|
+
* benchmark drives whatever `dsh` this machine launched with credentials.
|
|
147
|
+
* @returns the absolute path of the official patch file.
|
|
148
|
+
* @throws when that harness cannot be located or ships no such preset.
|
|
149
|
+
*/
|
|
150
|
+
export function officialMinimalPresetPatch() {
|
|
151
|
+
const relative = join('@deepseek-ai', 'dsh-web-app', 'presets', 'minimal.patch.yml')
|
|
152
|
+
const tried = []
|
|
153
|
+
for (const shim of dshCommands()) {
|
|
154
|
+
try {
|
|
155
|
+
// The `dsh` shim is the only handle on the harness install: resolve the
|
|
156
|
+
// CLI package beside it, then the bundle package inside that install.
|
|
157
|
+
// alpha.2 note: createRequire derives module paths from the literal
|
|
158
|
+
// filename without resolving symlinks, so from the PATH shim
|
|
159
|
+
// (/opt/homebrew/bin/dsh) the lookup walks bin/node_modules and never
|
|
160
|
+
// reaches the install tree; realpath first lands inside the package.
|
|
161
|
+
const fromShim = createRequire(realpathSync(shim))
|
|
162
|
+
const cliPackage = fromShim.resolve('@deepseek-ai/dsh/package.json')
|
|
163
|
+
const patch = createRequire(cliPackage).resolve(relative)
|
|
164
|
+
if (existsSync(patch)) return patch
|
|
165
|
+
} catch (error) {
|
|
166
|
+
tried.push(`${shim}: ${error instanceof Error ? error.message : String(error)}`)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
throw new Error('benchmark: the official Minimal preset is unavailable'
|
|
170
|
+
+ (tried.length === 0 ? ' (no dsh command on PATH)' : `; tried ${tried.join(' | ')}`))
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Whether any `dsh` command is on PATH (the preset reference tests gate on it). */
|
|
174
|
+
export function harnessInstallAvailable() {
|
|
175
|
+
return dshCommands().length > 0
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Every `dsh` command the platform's PATH lookup reports. */
|
|
179
|
+
function dshCommands() {
|
|
141
180
|
try {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
181
|
+
return execFileSync(process.platform === 'win32' ? 'where' : 'which', ['dsh'], { encoding: 'utf8' })
|
|
182
|
+
.split(/\r?\n/)
|
|
183
|
+
.map(line => line.trim())
|
|
184
|
+
.filter(line => line !== '')
|
|
185
|
+
} catch {
|
|
186
|
+
return []
|
|
146
187
|
}
|
|
147
188
|
}
|
|
148
189
|
|
|
@@ -192,18 +233,76 @@ export function replacePersonaPrefix(text, persona) {
|
|
|
192
233
|
return [...lines.slice(0, start + 1), ...replacement, ...lines.slice(blockEnd)].join('\n')
|
|
193
234
|
}
|
|
194
235
|
|
|
195
|
-
/**
|
|
236
|
+
/**
|
|
237
|
+
* Absolutize the relative module names of one composition.
|
|
238
|
+
*
|
|
239
|
+
* A declared preset's rows resolve a relative `name` against the DECLARING
|
|
240
|
+
* loader's base, not against the directory the row list came from, so the
|
|
241
|
+
* variant patch inlines the composition with every `./x.mjs` already resolved
|
|
242
|
+
* to the materialized copy's file URL. The scan is block-scalar aware: the
|
|
243
|
+
* persona prefix is prose, and a line inside it that happens to read
|
|
244
|
+
* `name: ./something` is content, not a row.
|
|
245
|
+
*/
|
|
246
|
+
export function absolutizeModuleNames(text, baseDir) {
|
|
247
|
+
const base = pathToFileURL(baseDir + sep).href
|
|
248
|
+
const out = []
|
|
249
|
+
/** Indentation of the block scalar currently open, if any. */
|
|
250
|
+
let blockScalarIndent
|
|
251
|
+
for (const line of text.split('\n')) {
|
|
252
|
+
const body = line.trim()
|
|
253
|
+
if (blockScalarIndent !== undefined) {
|
|
254
|
+
// Content keeps the scalar open; blank lines belong to it too, and a line
|
|
255
|
+
// at or above the owning key's indentation closes it.
|
|
256
|
+
if (body === '' || line.length - line.trimStart().length > blockScalarIndent) {
|
|
257
|
+
out.push(line)
|
|
258
|
+
continue
|
|
259
|
+
}
|
|
260
|
+
blockScalarIndent = undefined
|
|
261
|
+
}
|
|
262
|
+
if (/^\s*[\w-]+:\s*[|>][-+]?\s*$/.test(line)) {
|
|
263
|
+
blockScalarIndent = line.length - line.trimStart().length
|
|
264
|
+
out.push(line)
|
|
265
|
+
continue
|
|
266
|
+
}
|
|
267
|
+
const match = /^(\s*)name: (\.\.?\/[^\s'"]+)$/.exec(line)
|
|
268
|
+
out.push(match === null ? line : `${match[1]}name: ${new URL(match[2], base).href}`)
|
|
269
|
+
}
|
|
270
|
+
return out.join('\n')
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** Indent one composition block so it can sit under a `plugins:` key. */
|
|
274
|
+
export function inlineComposition(text, baseDir, indent) {
|
|
275
|
+
const pad = ' '.repeat(indent)
|
|
276
|
+
return absolutizeModuleNames(text, baseDir)
|
|
277
|
+
.split('\n')
|
|
278
|
+
.map(line => (line.trim() === '' ? '' : pad + line))
|
|
279
|
+
.join('\n')
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Copy the evaluated preset into the run directory and apply the variant's
|
|
284
|
+
* configuration change.
|
|
285
|
+
*
|
|
286
|
+
* The non-official variants get the bundled preset tree with their persona and
|
|
287
|
+
* presentation applied; the official reference gets the harness bundle's own
|
|
288
|
+
* Minimal preset patch, copied so the run records the exact bytes it evaluated.
|
|
289
|
+
*/
|
|
196
290
|
export function materializePreset(root, variantId, variant) {
|
|
197
291
|
const target = join(root, variantId)
|
|
198
|
-
|
|
199
|
-
|
|
292
|
+
if (variant.official === true) {
|
|
293
|
+
mkdirSync(target, { recursive: true })
|
|
294
|
+
cpSync(officialMinimalPresetPatch(), join(target, 'minimal.patch.yml'))
|
|
295
|
+
return target
|
|
296
|
+
}
|
|
297
|
+
cpSync(PRESET_SOURCE, target, { recursive: true })
|
|
200
298
|
const composition = join(target, 'agent.cordis.yml')
|
|
201
299
|
if (variant.presentation !== null && variant.presentation !== undefined) {
|
|
202
300
|
const text = readFileSync(composition, 'utf8')
|
|
203
301
|
// Anchor on the config line: the composition also NAMES the presentation key
|
|
204
302
|
// inside its prose, and rewriting a comment would leave the real surface alone.
|
|
205
|
-
const
|
|
206
|
-
if (
|
|
303
|
+
const pattern = /^(\s*)presentation: '[^']*'/m
|
|
304
|
+
if (!pattern.test(text)) throw new Error('benchmark: the preset composition carries no presentation line to vary')
|
|
305
|
+
const replaced = text.replace(pattern, `$1presentation: '${variant.presentation}'`)
|
|
207
306
|
writeFileSync(composition, replaced)
|
|
208
307
|
}
|
|
209
308
|
if (variant.persona === 'candidate') {
|
|
@@ -492,8 +591,9 @@ export function priceRun(usage, prices, route) {
|
|
|
492
591
|
}
|
|
493
592
|
|
|
494
593
|
/** Build the variant patch that redirects persistence and selects the isolated preset. */
|
|
495
|
-
function buildPatch({ variantId,
|
|
496
|
-
|
|
594
|
+
export function buildPatch({ variantId, variant, presetDir, runDir, turns }) {
|
|
595
|
+
const presetId = variant.official === true ? OFFICIAL_PRESET_ID : variantId
|
|
596
|
+
const lines = [
|
|
497
597
|
'- id: headless-startup',
|
|
498
598
|
' disabled: true',
|
|
499
599
|
'',
|
|
@@ -511,26 +611,59 @@ function buildPatch({ variantId, presetRoot, runDir, turns }) {
|
|
|
511
611
|
` model: ${FIXED_ROUTE.model}`,
|
|
512
612
|
` reasoningEffort: ${FIXED_ROUTE.reasoningEffort}`,
|
|
513
613
|
'',
|
|
614
|
+
'# The preset roster. The headless profile mounts neither the registry nor a',
|
|
615
|
+
'# preset, so the variant supplies both: `default` names the evaluated preset',
|
|
616
|
+
'# for the session this run creates, and mode selection stays off so no picker',
|
|
617
|
+
'# or default-preset write can move a run off the evaluated arm.',
|
|
514
618
|
'- insert:',
|
|
515
|
-
' - id: agent-
|
|
516
|
-
" name: '@deepseek-ai/dsh-agent-
|
|
619
|
+
' - id: agent-preset-registry',
|
|
620
|
+
" name: '@deepseek-ai/dsh-agent-preset-registry'",
|
|
517
621
|
' config:',
|
|
518
|
-
` default: ${
|
|
519
|
-
'
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
622
|
+
` default: ${JSON.stringify(presetId)}`,
|
|
623
|
+
' modeSelectionEnabled: false',
|
|
624
|
+
]
|
|
625
|
+
if (variant.official !== true) {
|
|
626
|
+
lines.push(
|
|
627
|
+
'',
|
|
628
|
+
'# The evaluated preset as an ordinary declaration: its rows are the',
|
|
629
|
+
'# materialized composition, with every relative module name already',
|
|
630
|
+
'# resolved to that copy so the registry mounts exactly this tree.',
|
|
631
|
+
'- insert:',
|
|
632
|
+
` - id: preset-${variantId}`,
|
|
633
|
+
" name: '@deepseek-ai/dsh-agent-preset'",
|
|
634
|
+
' config:',
|
|
635
|
+
` id: ${JSON.stringify(presetId)}`,
|
|
636
|
+
' order: 1',
|
|
637
|
+
' plugins:',
|
|
638
|
+
inlineComposition(readFileSync(join(presetDir, 'agent.cordis.yml'), 'utf8'), presetDir, 10),
|
|
639
|
+
)
|
|
640
|
+
}
|
|
641
|
+
lines.push(
|
|
524
642
|
'',
|
|
525
643
|
'- insert:',
|
|
526
644
|
' - id: benchmark-driver',
|
|
527
645
|
` name: ${JSON.stringify(DRIVER)}`,
|
|
528
646
|
' config:',
|
|
529
|
-
` preset: ${JSON.stringify(
|
|
647
|
+
` preset: ${JSON.stringify(presetId)}`,
|
|
530
648
|
' turns:',
|
|
531
649
|
...(turns ?? DEFAULT_TURNS).map((turn) => ` - ${JSON.stringify(turn)}`),
|
|
532
650
|
'',
|
|
533
|
-
|
|
651
|
+
)
|
|
652
|
+
return lines.join('\n')
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* The official Minimal preset's own id: the harness bundle declares it, so the
|
|
657
|
+
* variant patch only selects it rather than declaring a second preset.
|
|
658
|
+
*/
|
|
659
|
+
export const OFFICIAL_PRESET_ID = 'minimal'
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* The reference variant's overlay: the harness bundle's own Minimal preset
|
|
663
|
+
* patch, copied into the run directory so the run records the exact bytes.
|
|
664
|
+
*/
|
|
665
|
+
function officialPresetPatchPath(presetDir) {
|
|
666
|
+
return join(presetDir, 'minimal.patch.yml')
|
|
534
667
|
}
|
|
535
668
|
|
|
536
669
|
/**
|
|
@@ -553,12 +686,18 @@ export async function runLiveCase(options) {
|
|
|
553
686
|
if (options.task !== undefined) writeTaskFiles(workspace, options.task.files)
|
|
554
687
|
|
|
555
688
|
const turns = options.turns ?? options.task?.turns ?? DEFAULT_TURNS
|
|
556
|
-
const patch = buildPatch({ variantId,
|
|
689
|
+
const patch = buildPatch({ variantId, variant, presetDir, runDir, turns })
|
|
557
690
|
|
|
558
691
|
const patchPath = join(runDir, 'variant.patch.yml')
|
|
559
692
|
writeFileSync(patchPath, patch, 'utf8')
|
|
560
693
|
|
|
561
|
-
|
|
694
|
+
// The reference variant evaluates the harness's own preset row, so its
|
|
695
|
+
// declaration rides a second overlay instead of the variant patch.
|
|
696
|
+
const overlays = ['--patch', patchPath]
|
|
697
|
+
if (variant.official === true) {
|
|
698
|
+
overlays.push('--patch', officialPresetPatchPath(presetDir))
|
|
699
|
+
}
|
|
700
|
+
const args = ['--profile', 'headless', ...overlays, 'run the configured turns']
|
|
562
701
|
const spec = process.platform === 'win32'
|
|
563
702
|
? { command: 'cmd.exe', args: windowsCmdShimArgs('dsh', args), windowsVerbatimArguments: true }
|
|
564
703
|
: { command: 'dsh', args }
|
package/lib/types/schema.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Structural validation for a bundled `agent.cordis.yml`.
|
|
3
|
-
*
|
|
4
|
-
* Deliberately dependency-free: it parses only the flat row metadata the sync
|
|
5
|
-
* and the dsh agent-presets loader rely on. Every top-level row is written as
|
|
6
|
-
* `- id: <id>` at column zero, with the `name`/`group`/`disabled` keys at two
|
|
7
|
-
* spaces of indentation. Nested `config:` and `isolate:` bodies are opaque to
|
|
8
|
-
* this validator — the dsh loader checks their semantics.
|
|
9
|
-
*
|
|
10
|
-
* Returns the list of problems found; an empty array means the document is
|
|
11
|
-
* structurally valid.
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Validate the structural contract of an `agent.cordis.yml` document.
|
|
15
|
-
* @param text - the raw YAML document text.
|
|
16
|
-
* @returns a list of human-readable problems; empty means valid.
|
|
17
|
-
*/
|
|
18
|
-
export declare function validateAgentCordis(text: string): string[];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/types/sync.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sync every preset directory under `sourceRoot` into `targetRoot` — the
|
|
3
|
-
* dsh agent-presets discovery root (harness-home `.agent-presets`).
|
|
4
|
-
*
|
|
5
|
-
* A preset is a directory holding `agent.cordis.yml`; the directory name is
|
|
6
|
-
* the preset id. Copy is per-directory and idempotent: a preset whose target
|
|
7
|
-
* tree is byte-identical to the source tree is skipped, otherwise the source
|
|
8
|
-
* tree is copied and any target files the source does not contain are removed.
|
|
9
|
-
* Directories the plugin does not own (other presets the user authored) are
|
|
10
|
-
* never touched.
|
|
11
|
-
*
|
|
12
|
-
* After a preset is synced its `agent.cordis.yml` is validated against the
|
|
13
|
-
* structural preset schema; a validation failure is reported through the
|
|
14
|
-
* run's `failed` entries instead of being a warn-only side effect, so callers
|
|
15
|
-
* can observe (and surface) a broken preset rather than silently shipping it.
|
|
16
|
-
*/
|
|
17
|
-
/** One sync run's outcome, grouped for diagnostics. */
|
|
18
|
-
export interface SyncResult {
|
|
19
|
-
/** Preset ids whose tree was (re)written this run. */
|
|
20
|
-
synced: string[];
|
|
21
|
-
/** Preset ids already current — nothing copied. */
|
|
22
|
-
current: string[];
|
|
23
|
-
/** Preset ids that failed, with the underlying error message. */
|
|
24
|
-
failed: {
|
|
25
|
-
id: string;
|
|
26
|
-
error: string;
|
|
27
|
-
}[];
|
|
28
|
-
/** Previously bundled preset ids removed from the target root this run. */
|
|
29
|
-
retired: string[];
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* The preset-row settings the plugin exposes in the web settings surface, as the
|
|
33
|
-
* overrides to write into the synced `agent.cordis.yml`.
|
|
34
|
-
*
|
|
35
|
-
* The settings surface edits the PLUGIN's namespace, while the values that shape
|
|
36
|
-
* a session live in the preset's rows. Writing the chosen values into the synced
|
|
37
|
-
* tree is what connects the two: the bundled source stays the shipped default,
|
|
38
|
-
* and the operator's choice rides on top of it. Every field is optional — an
|
|
39
|
-
* absent value leaves the shipped row exactly as it is.
|
|
40
|
-
*/
|
|
41
|
-
export interface PresetOverrides {
|
|
42
|
-
/** The `tool-catalog` row's `presentation` value. */
|
|
43
|
-
presentation?: string;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Render `agent.cordis.yml` with the settings overrides applied.
|
|
47
|
-
*
|
|
48
|
-
* Rows are matched by their `- id:` marker, so the transform does not depend on
|
|
49
|
-
* line numbers or on the values the shipped file happens to carry. A row or key
|
|
50
|
-
* the source does not contain is left alone rather than invented: the overlay
|
|
51
|
-
* narrows the shipped configuration, it never adds a mount the preset did not
|
|
52
|
-
* have.
|
|
53
|
-
* @param text - the bundled preset composition.
|
|
54
|
-
* @param overrides - the operator's settings-surface choices.
|
|
55
|
-
* @returns the composition to write into the synced tree.
|
|
56
|
-
*/
|
|
57
|
-
export declare function renderPresetOverrides(text: string, overrides: PresetOverrides): string;
|
|
58
|
-
/** Copy `sourceRoot/<id>` into `targetRoot/<id>`, idempotently. */
|
|
59
|
-
export declare function syncOnePreset(sourceDir: string, targetDir: string, overrides?: PresetOverrides): 'synced' | 'current';
|
|
60
|
-
/**
|
|
61
|
-
* Sync every preset under `sourceRoot` into `targetRoot`, then remove
|
|
62
|
-
* target directories named in `retire` that the bundle no longer ships —
|
|
63
|
-
* preset ids the plugin once owned and later dropped. Only those exact ids
|
|
64
|
-
* are removed; every other target directory is left untouched.
|
|
65
|
-
*
|
|
66
|
-
* Each synced (or already-current) preset is validated against the structural
|
|
67
|
-
* `agent.cordis.yml` schema; a validation failure lands in `failed` so the
|
|
68
|
-
* caller can surface a broken preset as a first-class result instead of a
|
|
69
|
-
* warn-only log line.
|
|
70
|
-
* @param sourceRoot - plugin-owned preset tree (bundled in the package).
|
|
71
|
-
* @param targetRoot - dsh agent-presets discovery root (e.g. <home>/.dsh/.agent-presets).
|
|
72
|
-
* @param retire - previously bundled preset ids to remove when absent from the source.
|
|
73
|
-
*/
|
|
74
|
-
export declare function syncPresetTrees(sourceRoot: string, targetRoot: string, retire?: string[], overrides?: PresetOverrides): SyncResult;
|
package/lib/types/sync.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/schema.test.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { validateAgentCordis } from './schema.ts'
|
|
3
|
-
|
|
4
|
-
const VALID = [
|
|
5
|
-
"- id: persona",
|
|
6
|
-
" name: '@deepseek-ai/dsh-persona'",
|
|
7
|
-
"- id: bootstrap",
|
|
8
|
-
" name: ./tool-catalog.mjs",
|
|
9
|
-
"- id: shell-group",
|
|
10
|
-
" name: cordis:group",
|
|
11
|
-
" group: true",
|
|
12
|
-
" isolate:",
|
|
13
|
-
" terminals: true",
|
|
14
|
-
" config:",
|
|
15
|
-
" - id: pty",
|
|
16
|
-
" name: '@deepseek-ai/dsh-terminal'",
|
|
17
|
-
].join('\n')
|
|
18
|
-
|
|
19
|
-
describe('validateAgentCordis', () => {
|
|
20
|
-
it('accepts a well-formed preset document', () => {
|
|
21
|
-
expect(validateAgentCordis(VALID)).toEqual([])
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it('rejects an empty document', () => {
|
|
25
|
-
expect(validateAgentCordis('')).not.toEqual([])
|
|
26
|
-
expect(validateAgentCordis('\n \n')).not.toEqual([])
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('rejects a document that is not a list of rows', () => {
|
|
30
|
-
expect(validateAgentCordis('rows: []\n')).not.toEqual([])
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('rejects a row without a name', () => {
|
|
34
|
-
const doc = "- id: persona\n group: true\n"
|
|
35
|
-
expect(validateAgentCordis(doc)).not.toEqual([])
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('rejects a row whose name starts with an unsupported prefix', () => {
|
|
39
|
-
const doc = "- id: bad\n name: 'plain-text'\n"
|
|
40
|
-
expect(validateAgentCordis(doc)).not.toEqual([])
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it('rejects duplicate row ids', () => {
|
|
44
|
-
const doc = [
|
|
45
|
-
"- id: persona",
|
|
46
|
-
" name: '@deepseek-ai/dsh-persona'",
|
|
47
|
-
"- id: persona",
|
|
48
|
-
" name: '@deepseek-ai/dsh-tool-todo'",
|
|
49
|
-
].join('\n')
|
|
50
|
-
const errors = validateAgentCordis(doc)
|
|
51
|
-
expect(errors.some(error => error.includes('duplicate row id'))).toBe(true)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
it('rejects a group-true row that does not use cordis:group', () => {
|
|
55
|
-
const doc = "- id: shell-group\n name: '@deepseek-ai/dsh-persona'\n group: true\n"
|
|
56
|
-
expect(validateAgentCordis(doc)).not.toEqual([])
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('rejects a row with a blank id', () => {
|
|
60
|
-
const doc = "- id: \n"
|
|
61
|
-
const errors = validateAgentCordis(doc)
|
|
62
|
-
expect(errors.some(error => error.includes('empty row id'))).toBe(true)
|
|
63
|
-
})
|
|
64
|
-
})
|
package/src/schema.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Structural validation for a bundled `agent.cordis.yml`.
|
|
3
|
-
*
|
|
4
|
-
* Deliberately dependency-free: it parses only the flat row metadata the sync
|
|
5
|
-
* and the dsh agent-presets loader rely on. Every top-level row is written as
|
|
6
|
-
* `- id: <id>` at column zero, with the `name`/`group`/`disabled` keys at two
|
|
7
|
-
* spaces of indentation. Nested `config:` and `isolate:` bodies are opaque to
|
|
8
|
-
* this validator — the dsh loader checks their semantics.
|
|
9
|
-
*
|
|
10
|
-
* Returns the list of problems found; an empty array means the document is
|
|
11
|
-
* structurally valid.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/** A top-level row opener: `- id: <id>` (id may be blank for diagnostics). */
|
|
15
|
-
const ROW_RE = /^-\s+id:\s*(.*)$/
|
|
16
|
-
/** Any top-level list item, for ids missing from a row opener. */
|
|
17
|
-
const ITEM_RE = /^-\s/
|
|
18
|
-
/** A two-space-indented flat metadata key: ` name: <value>`. */
|
|
19
|
-
const META_RE = /^ {2}([A-Za-z][A-Za-z0-9_-]*):\s*(.*)$/
|
|
20
|
-
/** The only `name` forms the dsh agent-presets loader mounts from a row. */
|
|
21
|
-
const NAME_PREFIX_RE = /^(\.\/|@|cordis:)/
|
|
22
|
-
|
|
23
|
-
/** Strip one pair of surrounding single or double quotes from a scalar. */
|
|
24
|
-
function unquote(value: string): string {
|
|
25
|
-
if (value.length >= 2) {
|
|
26
|
-
const first = value[0]
|
|
27
|
-
if ((first === "'" || first === '"') && value.endsWith(first)) {
|
|
28
|
-
return value.slice(1, -1)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return value
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Validate the structural contract of an `agent.cordis.yml` document.
|
|
36
|
-
* @param text - the raw YAML document text.
|
|
37
|
-
* @returns a list of human-readable problems; empty means valid.
|
|
38
|
-
*/
|
|
39
|
-
export function validateAgentCordis(text: string): string[] {
|
|
40
|
-
const errors: string[] = []
|
|
41
|
-
const normalized = text.replace(/\r\n/g, '\n')
|
|
42
|
-
if (normalized.trim() === '') {
|
|
43
|
-
return ['document is empty']
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const seenIds = new Set<string>()
|
|
47
|
-
const current = { id: null as string | null, name: null as string | null, group: null as string | null }
|
|
48
|
-
|
|
49
|
-
const closeRow = (): void => {
|
|
50
|
-
if (current.id === null) return
|
|
51
|
-
if (current.name === null) {
|
|
52
|
-
errors.push(`row "${current.id}": missing "name" key`)
|
|
53
|
-
} else if (!NAME_PREFIX_RE.test(current.name)) {
|
|
54
|
-
errors.push(`row "${current.id}": name "${current.name}" must start with "./", "@" or "cordis:"`)
|
|
55
|
-
}
|
|
56
|
-
if (current.group === 'true' && current.name !== 'cordis:group') {
|
|
57
|
-
errors.push(`row "${current.id}": "group: true" requires name "cordis:group"`)
|
|
58
|
-
}
|
|
59
|
-
current.name = null
|
|
60
|
-
current.group = null
|
|
61
|
-
current.id = null
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const lines = normalized.split('\n')
|
|
65
|
-
for (let index = 0; index < lines.length; index += 1) {
|
|
66
|
-
const lineNo = index + 1
|
|
67
|
-
const line = lines[index]
|
|
68
|
-
const trimmed = line.trim()
|
|
69
|
-
if (trimmed === '' || trimmed.startsWith('#')) continue
|
|
70
|
-
|
|
71
|
-
const row = ROW_RE.exec(line)
|
|
72
|
-
if (row !== null) {
|
|
73
|
-
closeRow()
|
|
74
|
-
const id = row[1].trim()
|
|
75
|
-
if (id === '') {
|
|
76
|
-
errors.push(`line ${lineNo}: empty row id`)
|
|
77
|
-
current.id = null
|
|
78
|
-
} else {
|
|
79
|
-
if (seenIds.has(id)) errors.push(`line ${lineNo}: duplicate row id "${id}"`)
|
|
80
|
-
seenIds.add(id)
|
|
81
|
-
current.id = id
|
|
82
|
-
}
|
|
83
|
-
current.name = null
|
|
84
|
-
current.group = null
|
|
85
|
-
continue
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (current.id === null) {
|
|
89
|
-
if (ITEM_RE.test(line)) {
|
|
90
|
-
errors.push(`line ${lineNo}: list item does not declare an "id:"`)
|
|
91
|
-
} else if (/^\S/.test(line)) {
|
|
92
|
-
errors.push(`line ${lineNo}: content outside a "- id:" row`)
|
|
93
|
-
}
|
|
94
|
-
continue
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const meta = META_RE.exec(line)
|
|
98
|
-
if (meta !== null) {
|
|
99
|
-
const value = unquote(meta[2].trim())
|
|
100
|
-
if (meta[1] === 'name') current.name = value
|
|
101
|
-
else if (meta[1] === 'group') current.group = value
|
|
102
|
-
continue
|
|
103
|
-
}
|
|
104
|
-
// Anything indented at least two spaces is a nested body, opaque here.
|
|
105
|
-
if (/^ {2}/.test(line)) continue
|
|
106
|
-
errors.push(`line ${lineNo}: unexpected content in row "${current.id}"`)
|
|
107
|
-
}
|
|
108
|
-
closeRow()
|
|
109
|
-
return errors
|
|
110
|
-
}
|