Files
deepseek-harness/apps/cli/src/dump-config.ts
T
Yichen Jiang 5d742503ea feat(boot): own row ids across the stack instead of prefixing external bundles
An external bundle keeps the ids its patch declares. composeProfileStack
decides ownership before anything mounts: built-in and boot-staged layers
claim first and a duplicate among them fails the boot, a contained bundle
that collides is left out whole, a user-layer insert of a taken id is
dropped, and every row left out is a `conflict` record in pluginFailures,
printed at boot and replaced on each recomposition. Boot, live reloads, and
--dump-config compose through the same function, so the dump shows the
contained groups the tree mounts.

The prefix made a user patch, a third-party manager's disabled rows, and a
bundle's own `!!js` id comparison miss silently; the note records both cases.
2026-09-04 12:02:11 +08:00

59 lines
2.5 KiB
TypeScript

/**
* Config-dump entry for `dsh --profile <name> --dump-config`: compose the
* profile's patch layers through the include plugin's patch algorithm without
* booting or evaluating `!!js`, with one source layer per bundle, the
* profile's own patch file, and each `--patch` overlay.
* @module @deepseek-ai/dsh/dump-config
*/
import { existsSync } from 'node:fs'
import { join, resolve } from 'node:path'
import {
composeProfileStack,
formatRowConflict,
loadOptionalPatches,
loadOverlayPatches,
renderConfigDump,
type ConfigDumpLayer,
type StackUserLayer,
} from '@deepseek-ai/dsh-app-boot'
import { homePatchPath, prepareProfile, PROFILE_ROOT_FILENAME } from './profile-boot.ts'
const NAME = 'dsh'
/* v8 ignore start -- built-bin acceptance drives this boot-free dispatch */
/**
* Print a profile composition with comments naming each source file and patch layer.
* @param profile - the profile name.
* @param defaultOnly - omit the profile's user layer and `--patch` overlays
* (the recovery diagnostic for a broken `cordis.patch.yml`, which is then
* never parsed).
* @param patches - `--patch` overlay paths, in argv order.
*/
export function runDumpConfig(profile: string, defaultOnly: boolean, patches: readonly string[]): void {
const loaded = prepareProfile(profile, !defaultOnly)
const userLayers: StackUserLayer[] = []
if (!defaultOnly) {
if (existsSync(loaded.patchPath)) {
userLayers.push({ label: loaded.patchPath, patches: loaded.patches })
}
const homePatchFile = homePatchPath()
const homePatches = loadOptionalPatches(NAME, homePatchFile)
if (homePatches !== undefined) {
userLayers.push({ label: homePatchFile, patches: homePatches })
}
for (const file of patches) {
const absolute = resolve(file)
userLayers.push({ label: absolute, patches: loadOverlayPatches(NAME, absolute) })
}
}
// The same composition boot mounts: external bundles as contained groups,
// a bundle or row left out by an id conflict reported, not shown.
const stack = composeProfileStack(NAME, loaded.layers, userLayers)
for (const conflict of stack.conflicts) process.stderr.write(`${NAME}: ${formatRowConflict(conflict)}\n`)
const layers: ConfigDumpLayer[] = stack.layers.map(layer => ({ label: layer.label, patches: layer.patches }))
// The dump anchors on the same empty root file the boot includes.
process.stdout.write(renderConfigDump(NAME, join(loaded.dir, PROFILE_ROOT_FILENAME), layers))
}
/* v8 ignore stop */