0512b12714
$DSH_HOME/.env had just become an ordinary environment layer, which left the harness resolving user-facing values from a flattened process.env that could no longer say where a value came from. A key stored through the web page stayed shadowed by an older key in the user's own .env. An endpoint could be redirected by the project: the invoking directory's .env is materialized like every other layer, and a base URL decides where a resolved API key is sent, so a DEEPSEEK_BASE_URL written into a model-editable workspace would send the user's credential — and the prompts carrying their code — to whatever host that file named. Give every user-facing value one ordering, with four kinds of source: explicit for this run per-operation override, CLI argument > authored by deployment --config / --config-replace > this launch's shell inherited process environment > product-managed store settings.yaml, .credentials.yaml > discovered file $DSH_HOME/.env > defaults schema default, shipped base, public default The domains differ only in which tiers exist. The earlier split — credentials ranking the environment over the managed file while settings ranked over the environment — was inconsistent: the distinguishing fact is who authored the source, not the domain. packages/util/environment owns an immutable snapshot with per-layer provenance. getFrom(name, sources) searches only the layers a caller names, and omitting one is a refusal rather than a demotion: the adapters ask for ['process', 'user-env'], so no reordering can let a project file back into a decision it was excluded from. isBootstrapOnly rejects, before anything is materialized, any .env setting a variable that governs how a process launches (PATH, SHELL, NODE_OPTIONS, LD_PRELOAD), where code or model-visible instructions load from (the whole DSH_* namespace, HOME, XDG_*), or how the network is reached (proxy and CA variables). The namespace is denied wholesale so a switch added later cannot become settable by being forgotten, and there is no opt-out. verify-config-source-ownership keeps both rules: no unregistered process.env read under packages/*/*/src (26 allowlisted with reasons), and no apiKey, baseURL, or headers inlined from the environment in shipped Cordis config — removing those inlines is what makes the deployment tier meaningful.
69 lines
2.6 KiB
JavaScript
69 lines
2.6 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* dsh — command-line entry. Dynamic imports per mode keep unrelated modes out
|
|
* of each dispatch path; the adapter prints and exits for
|
|
* `--help`/`--version`/a parse error, so only a valid mode reaches the switch.
|
|
* @module @deepseek-ai/dsh/bin
|
|
*/
|
|
|
|
/* v8 ignore file -- built-bin and PTY tests exercise this self-executing dispatch. */
|
|
|
|
import { readFileSync } from 'node:fs'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { loadLayeredEnv } from '@deepseek-ai/dsh-app-boot'
|
|
import { parseDshArgs } from './args.ts'
|
|
|
|
// Both the source tree (apps/cli/src) and the bundled bin (apps/cli/lib) sit
|
|
// one directory under apps/cli, so the checked-in manifest resolves with the
|
|
// same relative hop from either artifact.
|
|
/** This app's version, read from its checked-in package.json. */
|
|
function readVersion(): string {
|
|
const manifest = JSON.parse(
|
|
readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf8'),
|
|
) as { version?: unknown }
|
|
return typeof manifest.version === 'string' ? manifest.version : '0.0.0'
|
|
}
|
|
|
|
const environment = loadLayeredEnv('dsh')
|
|
// The env opt-in is read at the process boundary; `1` is the documented value.
|
|
const invocation = parseDshArgs(process.argv.slice(2), readVersion(), process.env.DSH_EXPERIMENTAL === '1')
|
|
|
|
switch (invocation.mode) {
|
|
case 'web': {
|
|
const { runWeb } = await import('./web.ts')
|
|
await runWeb(
|
|
environment, invocation.host, invocation.port, invocation.dev,
|
|
invocation.workspaceRoot, invocation.trustedHosts, invocation.config,
|
|
)
|
|
break
|
|
}
|
|
case 'headless': {
|
|
const { runHeadless } = await import('./headless.ts')
|
|
await runHeadless(environment, invocation.prompt, invocation.config, invocation.configReplace)
|
|
break
|
|
}
|
|
case 'tui': {
|
|
const { runTui } = await import('./tui.ts')
|
|
await runTui(environment, invocation.config, invocation.resume, undefined, undefined, invocation.configReplace)
|
|
break
|
|
}
|
|
case 'dump-config': {
|
|
const { runDumpConfig } = await import('./dump-config.ts')
|
|
runDumpConfig(invocation.surface, invocation.defaultOnly, invocation.config)
|
|
break
|
|
}
|
|
case 'meta': {
|
|
const { runTui, SOURCE_ROOT } = await import('./tui.ts')
|
|
await runTui(environment, invocation.config, undefined, SOURCE_ROOT, undefined, invocation.configReplace)
|
|
break
|
|
}
|
|
case 'upgrade': {
|
|
const { runTui } = await import('./tui.ts')
|
|
await runTui(environment, invocation.config, undefined, undefined, `dsh-${invocation.mode}`, invocation.configReplace)
|
|
break
|
|
}
|
|
default:
|
|
invocation satisfies never
|
|
throw new Error(`dsh: unhandled invocation mode ${JSON.stringify(invocation)}`)
|
|
}
|