DeepSeek Harness 安装插件与配置加载顺序
核对 profile 安装清单、配置叠加顺序与局部配置诊断。
学完这一章,你能够
- 核对 profile 安装清单、配置叠加顺序与局部配置诊断。
从已编写的包到实际配置
上一章交付包清单和配置文件。本章把多个组合包放进一个启动配置,查看同一行会得到哪个值。启动配置从空的条目列表开始,依次读取组合包清单、profile 文件、主目录文件和命令行传入的配置文件。下面的表列出各层的文件位置及次序。
应用自有参数由普通启动插件读取并通过服务传给消费者。它们与启动器用于叠加配置文件的 --patch 选项是两套输入。
多个层更新相同 id 时,后续显式提供的 config 覆盖整个 config 字段。实验让第二个包只写 color,检查先前的 border 是否消失。
把本地包加入一个练习 profile
准备一个由本站示例或自己编写的组合包。在它的父目录运行 dsh plugin --profile lesson-colors add ./bundle,将本地包加入练习 profile。普通包管理操作由 pnpm 在 profile 目录内执行,DSH 专用子命令由启动器处理。这个版本为新建的一般 CLI profile 提供 dsh-base 初始层。组合包在 dsh.bundle 中声明贡献层,普通库即使安装成功也没有这样的层。
查看 $DSH_HOME/profiles/lesson-colors/package.json,核对 dependencies 和 dsh.profile.bundles。依赖关系决定有哪些外部包可解析,有序列表决定选用哪些包的配置层。用相对目录安装的样例可能在依赖字段显示 link: 路径。安装的实际路径写法由包管理器确定。
用 dsh --profile lesson-colors --dump-config 检查组合结果,再用 dsh --profile lesson-colors 启动。配置诊断直接输出生效 YAML 并标注每组条目的来源与曾修改它的层。一个注释可以列出多个层,表达式保持未求值。ZIP 实验直接测试诊断函数,不启动插件。
移除时运行 dsh plugin --profile lesson-colors remove mbsky-profile-labels,随后核对 dependencies 以及组合包列表,再查看配置诊断是否还显示该层。此处列出检查步骤,当前离线实验没有执行包管理器增删或整条 dsh 命令。
覆盖整段 config 并区分包的安装位置
覆盖针对同一个 id 的 config 字段。只改 color 也要重述这一行仍需使用的其他键。应用层组合包可这样覆盖 dsh-base。用户可以用自己的 profile 级文件继续覆盖,无需修改包。作者可以把合适的默认值交给明确声明了它们的 schema。
解析 bundle 的配置文件时,先从启动器安装位置找包,再查 profile 的 node_modules。实验在两边放置同名的 dsh-base 样本,验证安装位置赢得选择。外部样本只在 profile 处可用,另一条没有组合包声明的条目被跳过。
本地 ZIP 用临时目录保存样本清单和 YAML,调用固定版本的 profile 读取器及配置诊断函数。对照配置值依次经过 navy、blue、green、yellow、orange、silver、purple,验证同包多文件、跨包、profile、主目录和两个启动器配置文件。
复核安装过程和生效结果
练习完成后复述四层次序,解释为何更新 color 仍要重述 border,再用配置诊断定位最后一次覆盖。若检查输出和预期不同,先确认 profile 名称、bundles 顺序、目标行 id 及 --patch 次序。
配置文件的叠加顺序
| 层 | 读取方式 |
|---|---|
| 1. 组合包列表 | dsh.profile.bundles 按数组次序读,每个包自己的多个配置文件也有次序。一般练习 profile 的初始层为 dsh-base。 |
| 2. profile 配置 | profiles/<name>/cordis.patch.yml 对当前 profile 生效。 |
| 3. 主目录配置 | DSH_HOME/cordis.patch.yml 跨 profile 使用。 |
| 4. 启动器配置 | 每个 --patch 按参数提供顺序叠加,同一行最后写入的 config 生效。 |
profile 的 package.json
| 字段 | 含义与条件 |
|---|---|
| name | 本地 profile 的包名,初始化样本为 dsh-profile-lesson-colors。 |
| private | 初始化时设为 true,以免把本地 profile 意外发布。 |
| dependencies | 登记由包管理器安装的 profile 依赖。样本初始化为空,未运行包管理器。 |
| dsh.profile.bundles | 列出选中的包及固定读取顺序。 |
覆盖同一 id 时的行为
| 策略 | 行为与结果 |
|---|---|
| 逐键深度合并 | 若采用这种算法,旧 config 中未重述的键会保留。配置层实验观察到旧 border 消失。 |
| 替换整个 config | 当 id 相同且后层写入 config 时,新的 config 接替旧值。需要保留的值应显式写出。 |
读取实际 profile 并观察覆盖结果
import assert from 'node:assert/strict'
import { createHash } from 'node:crypto'
import fs from 'node:fs'
import { createRequire, isBuiltin, registerHooks } from 'node:module'
import path from 'node:path'
import { pathToFileURL, fileURLToPath } from 'node:url'
assert.equal(process.argv.length, 4, 'Usage: node profile-load-order.mjs <checkout> <empty temporary directory>')
const repo = path.resolve(process.argv[2])
const scratch = path.resolve(process.argv[3])
assert.deepEqual(fs.readdirSync(scratch), [], 'The temporary directory must be empty')
const base = pathToFileURL(repo + path.sep).href
const store = path.join(repo, 'node_modules', '.pnpm')
const require = createRequire(import.meta.url)
const ts = require(path.join(store, 'typescript@6.0.3/node_modules/typescript/lib/typescript.js'))
const cachedPackages = fs.readdirSync(store)
const pinned = new Map([['ajv', 'ajv@8.20.0']])
// The local checkout lacks this dependency of the unrelated runtime import resolver.
const missingResolver = !fs.existsSync(path.join(store, 'resolve.exports@2.0.3/node_modules/resolve.exports/package.json'))
const unusedPackageImports = 'data:text/javascript,' + encodeURIComponent(
'export function imports() { throw new Error("Missing optional test-path dependency resolve.exports was invoked") }'
)
const packageRoots = new Map()
const sourceHashes = {}
const digest = (text) => createHash('sha256').update(text).digest('hex')
const fileUrl = (name) => pathToFileURL(name).href
const directories = (folder) => fs.readdirSync(folder, { withFileTypes: true })
.filter((entry) => entry.isDirectory()).map((entry) => path.join(folder, entry.name))
const read = (name) => JSON.parse(fs.readFileSync(name, 'utf8'))
const write = (name, body) => fs.writeFileSync(name, body, 'utf8')
const writeJson = (name, value) => write(name, JSON.stringify(value, null, 2))
for (const folder of [
...directories(path.join(repo, 'vendor')),
...directories(path.join(repo, 'packages')).flatMap(directories),
...directories(path.join(repo, 'apps')),
]) {
const manifest = path.join(folder, 'package.json')
if (fs.existsSync(manifest)) packageRoots.set(read(manifest).name, folder)
}
registerHooks({
resolve(specifier, context, nextResolve) {
if (isBuiltin(specifier) || /^(?:[./]|[a-z]+:)/i.test(specifier)) {
return nextResolve(specifier, context)
}
if (missingResolver && specifier === 'resolve.exports') return nextResolve(unusedPackageImports, context)
const segments = specifier.split('/')
const name = segments.splice(0, specifier.startsWith('@') ? 2 : 1).join('/')
const subpath = segments.join('/')
const root = packageRoots.get(name)
if (root) {
return nextResolve(fileUrl(path.join(root, subpath || 'src/index.ts')), context)
}
try {
return nextResolve(specifier, context)
} catch (error) {
if (error.code !== 'ERR_MODULE_NOT_FOUND' && error.code !== 'MODULE_NOT_FOUND') throw error
if (!context.parentURL?.startsWith(base)) throw error
const matches = cachedPackages.filter((entry) => entry.startsWith(name.replace('/', '+') + '@'))
const cached = pinned.get(name) ?? (matches.length === 1 ? matches[0] : undefined)
if (!cached) throw error
return nextResolve(specifier, { ...context, parentURL: fileUrl(path.join(store, cached, 'loader.mjs')) })
}
},
load(url, context, nextLoad) {
if (!url.startsWith(base) || !url.endsWith('.ts')) return nextLoad(url, context)
const filename = fileURLToPath(url)
const input = fs.readFileSync(filename, 'utf8')
sourceHashes[path.relative(repo, filename).split(path.sep).join('/')] = digest(input)
const output = ts.transpileModule(input, { compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2022 } })
return { format: 'module', source: output.outputText, shortCircuit: true }
},
})
const app = await import(base + 'packages/boot/app-boot/src/index.ts')
const { initProfile, loadProfile, composeEntries, resolveProfileDir, readProfileManifest } =
await import(base + 'packages/boot/app-boot/src/profile.ts')
const { readProfilePatches } = await import(base + 'packages/boot/app-boot/src/profile-context.ts')
const name = 'lesson-colors'
const home = path.join(scratch, 'home')
const profile = resolveProfileDir(name, home)
const install = path.join(scratch, 'install')
fs.mkdirSync(install, { recursive: true })
const installAnchor = path.join(install, 'package.json')
writeJson(installAnchor, { name: 'lesson-install', private: true })
const packaged = '@deepseek-ai/dsh-base'
const local = 'lesson-colors-bundle'
const inert = 'lesson-palette-library'
const bundleNames = [packaged, local, inert]
initProfile(profile, bundleNames)
const cases = []
function check(name, input, expected, actual) {
assert.deepEqual(actual, expected, name)
cases.push({ name, input, expected, actual, passed: true })
}
const initial = readProfileManifest('lesson', profile)
check('profile_directory_and_manifest', { name, bundleNames },
{ dir: 'home/profiles/lesson-colors', manifest: { name: 'dsh-profile-lesson-colors', private: true, dependencies: {},
dsh: { profile: { bundles: bundleNames } } }, userPatch: true, workspace: true },
{ dir: path.relative(scratch, profile).split(path.sep).join('/'), manifest: initial,
userPatch: fs.existsSync(path.join(profile, 'cordis.patch.yml')),
workspace: fs.existsSync(path.join(profile, 'pnpm-workspace.yaml')) })
initProfile(profile, ['new-ignored'])
check('reinitialization_preserves_bundles', ['new-ignored'], bundleNames, readProfileManifest('lesson', profile).dsh.profile.bundles)
function fixture(anchor, packageName, patches) {
const folder = path.join(anchor, 'node_modules', packageName)
fs.mkdirSync(folder, { recursive: true })
writeJson(path.join(folder, 'package.json'), {
name: packageName, version: '0.1.0',
...(patches.length ? { dsh: { bundle: { patch: patches.length === 1 ? patches[0][0] : patches.map(([file]) => file) } } } : {}),
})
for (const [file, text] of patches) write(path.join(folder, file), text)
}
const row = 'palette'
const color = (value) => '- id: palette\n config: { color: ' + value + ' }\n'
fixture(install, packaged, [['first.yml', '- insert:\n - id: palette\n name: lesson-colors\n config: { color: navy, border: true }\n'],
['second.yml', '- id: palette\n config: { color: blue, border: true }\n']])
fixture(profile, packaged, [['wrong-anchor.yml', color('red')]])
fixture(profile, local, [['bundle.yml', color('green')]])
fixture(profile, inert, [])
const patchPath = path.join(profile, 'cordis.patch.yml')
const homePatch = path.join(home, 'cordis.patch.yml')
const overlayPaths = ['overlay-first.yml', 'overlay-last.yml'].map((file) => path.join(scratch, file))
write(patchPath, color('yellow'))
write(homePatch, color('orange'))
write(overlayPaths[0], color('silver'))
write(overlayPaths[1], color('purple'))
const loaded = loadProfile('lesson', name, installAnchor, home)
check('bundle_order_and_no_bundle_declaration', bundleNames, { layers: [packaged, local], skipped: [inert], reason: true },
{ layers: loaded.layers.map((layer) => layer.packageName), skipped: loaded.skippedBundles.map((layer) => layer.packageName),
reason: loaded.skippedBundles[0].reason.includes('declares no dsh.bundle') })
check('installation_anchor_and_ordered_bundle_files', packaged,
{ installed: true, files: ['first.yml', 'second.yml'], config: { color: 'blue', border: true } },
{ installed: loaded.layers[0].packageDir.startsWith(install + path.sep),
files: loaded.layers[0].patchPaths.map((name) => path.basename(name)), config: composeEntries([loaded.layers[0].patches])[0].config })
check('profile_anchor_used_for_external_bundle', local, true, loaded.layers[1].packageDir.startsWith(profile + path.sep))
const bundlePatches = loaded.layers.map((layer) => layer.patches)
check('whole_config_replaced_in_real_profile', { row, lastBundle: local }, { color: 'green' }, composeEntries(bundlePatches)[0].config)
const context = { name, dir: profile, patchPath, installAnchor, cwd: scratch, home, startedBundles: [packaged, local],
overlayPaths, telemetryDisabledEnv: undefined }
const layers = readProfilePatches('lesson', context, loaded)
check('file_backed_layers_through_official_reader', 'bundle -> profile -> home -> argv overlays',
['navy', 'blue', 'green', 'yellow', 'orange', 'silver', 'purple'],
layers.map((layer) => layer.insert?.[0].config.color ?? layer.config.color))
check('argv_final_overlay_wins', ['overlay-first.yml', 'overlay-last.yml'], { color: 'purple' }, composeEntries([layers])[0].config)
const labels = [...loaded.layers.map((layer) => ({ label: layer.packageName, patches: layer.patches })),
{ label: 'profile' , patches: loaded.patches },
{ label: 'home', patches: app.loadOptionalPatches('lesson', homePatch) },
...overlayPaths.map((file) => ({ label: path.basename(file), patches: app.loadOverlayPatches('lesson', file) }))]
const rootConfig = path.join(profile, 'cordis.yml')
write(rootConfig, '[]\n')
const dump = app.renderConfigDump('lesson', rootConfig, labels)
check('config_dump_labels_preserve_layer_order', labels.map((layer) => layer.label),
['# == @deepseek-ai/dsh-base, patched by lesson-colors-bundle, profile, home, overlay-first.yml, overlay-last.yml'],
dump.split(/\r?\n/).filter((line) => line.startsWith('# == ')))
check('config_dump_marks_effective_row', row, true, /color: purple/.test(dump))
write(patchPath, 'not-a-list: true\n')
const bundlesOnly = loadProfile('lesson', name, installAnchor, home, { userLayer: false })
check('bundles_only_read_skips_invalid_user_layer', 'options.userLayer = false', [packaged, local],
bundlesOnly.layers.map((layer) => layer.packageName))
let rejected = false
try {
loadProfile('lesson', name, installAnchor, home)
} catch (error) {
rejected = /must be a top-level YAML array/.test(error.message)
}
check('invalid_user_layer_rejected_on_normal_read', 'mapping instead of patch array', true, rejected)
console.log(JSON.stringify({
cases, node: process.version, typescript: ts.version, code_sha256: digest(fs.readFileSync(fileURLToPath(import.meta.url))),
source_hashes: Object.fromEntries(Object.entries(sourceHashes).sort(([a], [b]) => a.localeCompare(b))),
isolated_missing_dependency: missingResolver ? 'resolve.exports@2.0.3' : null,
actual_profile_api_tested: true, product_cli_tested: false, pnpm_install_tested: false, config_js_evaluated: false,
}, null, 2))
- 实验的最终配置为 color: purple。诊断注释按次序列出初始包和修改过这行的各配置层。
所需环境:Node.js 24.22.3、TypeScript 6.0.3、固定版本源码、本地空临时目录。
当前源码 SHA256:1744281a113180c58ea7bc89b2d7b0bf9ce7cf5128bf3e2f39bd06049998cac7
本地复跑
按 ZIP 内的 README 准备空目录并运行实验。
所需环境:Node.js 24.22.3、TypeScript 6.0.3、固定版本源码、本地空临时目录。
ZIP SHA256:7268d285f2318bdc1f0ba8f1644f050669a6781be62615fc9ae71cb01bd0a319
常见错误与边界
- 配置诊断生成 YAML,插件启动和注入有各自的运行条件。
- 覆盖 config 时重述需要保留的键。
练习与解答
为什么给同一 id 只写 color 后,看不到前一层的 border?
展开参考解答
当前 patch 以 id 定位行,显式提供的 config 替换旧 config 整段。