Files
deepseek-harness/apps/cli/src/dump-config-schema.ts
T
Turtle 4eb26f0e71 feat(cli): export JSON Schema for Cordis configuration (#4705)
* feat(cli): dump native Cordis config schemas

* test(cli): include schema dump in launcher help snapshot

* feat(cli): export JSON Schema for Cordis configuration

* fix(cli): preserve config schema discovery and annotations

* fix(cli): conservatively project effectful config validation

* refactor(boot): encapsulate profile config schema generation

* fix(cli): follow Loader disabling and native writeback in config schema

- Dormant group/include rows (disabled without group: true) may omit
  config and are recorded as childless trees; the entry schema skips
  their child declarations, matching the Loader, which never creates them.
- Lazy builders run once per document, and a wrapped null-only projection
  keeps a deduplicated type list so the document stays compilable.
- Union widening applies only when an earlier branch can write adapted
  values back through a container; +Infinity max and -Infinity min
  without a step are treated as the native no-ops they are.
- Projection limitations repeat at every entry sharing a Config, and the
  entry schema documents the boolean/expression domain of disabled.
- Record the schema-dump validation policy as an Agent Note.
2026-09-21 09:19:24 +00:00

49 lines
2.2 KiB
TypeScript

/**
* Schema-dump entry: inspect the composed profile without applying its plugins.
* Imports and lazy schema builders execute trusted module code.
* @module @deepseek-ai/dsh/dump-config-schema
*/
/* v8 ignore file -- built-bin acceptance drives schema collection and output. */
import { generateConfigSchema, type ConfigSchemaDump } from '@deepseek-ai/dsh-app-boot'
import { collectConfigDumpLayers } from './dump-config.ts'
import { INSTALL_ANCHOR, prepareProfile } from './profile-boot.ts'
const NAME = 'dsh'
/**
* Print one JSON Schema document; incomplete collection or projection sets exitCode to 1.
* Profile initialization writes match the YAML dump. Plugin imports may execute
* top-level code, but collection never applies plugins or evaluates `!!js`.
* During schema generation, ordinary stdout writes are redirected to stderr.
* @param profile - the profile name.
* @param patches - overlay paths, in argv order.
* @param fromDefaultProfile - shipped template used once to initialize a missing profile.
* @returns after collection and output, with diagnostics also written to stderr.
*/
export async function runDumpConfigSchema(
profile: string,
patches: readonly string[],
fromDefaultProfile?: string,
): Promise<void> {
const loaded = prepareProfile(profile, true, fromDefaultProfile)
const layers = collectConfigDumpLayers(loaded, false, patches)
// oxlint-disable-next-line typescript/unbound-method -- Saved only for exact restoration, never called unbound.
const stdoutWrite = process.stdout.write
let dump: ConfigSchemaDump
// Trusted module diagnostics must not precede the JSON document on stdout.
process.stdout.write = process.stderr.write.bind(process.stderr)
try {
dump = await generateConfigSchema(NAME, loaded, layers.map(layer => layer.patches), INSTALL_ANCHOR)
} finally {
process.stdout.write = stdoutWrite
}
process.stdout.write(`${JSON.stringify(dump, null, 2)}\n`)
for (const diagnostic of dump['x-cordis'].diagnostics) {
const location = diagnostic.path === undefined ? '' : ` [${diagnostic.path}]`
process.stderr.write(`${NAME}: ${diagnostic.level}:${location} ${diagnostic.message}\n`)
}
if (!dump['x-cordis'].complete) process.exitCode = 1
}