dump-config.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * Config-dump entry for raw `dsh --config` and `dsh web`: compose through the
  3. * include plugin's patch algorithm without booting or evaluating `!!js`.
  4. * @module @deepseek-ai/dsh/dump-config
  5. */
  6. import { basename, join } from 'node:path'
  7. import { fileURLToPath } from 'node:url'
  8. import {
  9. loadOverlayPatches,
  10. loadPersonalPatches,
  11. PERSONAL_CONFIG_FILENAME,
  12. renderConfigDump,
  13. type ConfigDumpLayer,
  14. } from '@deepseek-ai/dsh-app-boot'
  15. import { resolveDshHome } from '@deepseek-ai/dsh-paths'
  16. const NAME = 'dsh'
  17. const BASE_CONFIG = fileURLToPath(new URL('../config/base.cordis.yml', import.meta.url))
  18. const WEB_OVERLAY = fileURLToPath(new URL('../config/web.cordis.yml', import.meta.url))
  19. /* v8 ignore start -- built-bin acceptance drives this boot-free dispatch */
  20. /**
  21. * Print a raw or Web composition with provenance comments.
  22. * @param surface - raw base-plus-config composition, or the Web composition.
  23. * @param defaultOnly - omit the explicit or personal user layer.
  24. * @param config - explicit overlay path; required for a non-default raw dump.
  25. */
  26. export function runDumpConfig(surface: 'config' | 'web', defaultOnly: boolean, config?: string): void {
  27. const layers: ConfigDumpLayer[] = []
  28. if (surface === 'config') {
  29. if (!defaultOnly) {
  30. /* v8 ignore next -- parseDshArgs requires this combination */
  31. if (config === undefined) throw new Error('dsh: raw config dump requires an overlay')
  32. layers.push({ label: config, patches: loadOverlayPatches(NAME, config) })
  33. }
  34. } else {
  35. layers.push({ label: basename(WEB_OVERLAY), patches: loadOverlayPatches(NAME, WEB_OVERLAY) })
  36. if (!defaultOnly) {
  37. if (config === undefined) {
  38. const personal = loadPersonalPatches(NAME)
  39. if (personal !== undefined) {
  40. layers.push({ label: join(resolveDshHome(), PERSONAL_CONFIG_FILENAME), patches: personal })
  41. }
  42. } else {
  43. layers.push({ label: config, patches: loadOverlayPatches(NAME, config) })
  44. }
  45. }
  46. }
  47. process.stdout.write(renderConfigDump(NAME, BASE_CONFIG, layers))
  48. }
  49. /* v8 ignore stop */