feat(cli): dsh CLI with personal config overlays from ~/.config/dsh

This commit is contained in:
Turtle
2026-07-22 10:55:17 +08:00
parent a2f17d71ed
commit 6baa030594
17 changed files with 450 additions and 6 deletions

23
apps/cli/src/bin.ts Normal file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env node
/**
* dsh — command-line entry. Coarse dispatch only; each surface module owns its
* own argument handling. `web` and `-p`/`--prompt` are reserved for the
* browser GUI and headless surfaces (PR #443) so that dispatch merges as a
* union; everything else is the interactive TUI, the default surface.
* @module @deepseek-ai/dsh/bin
*/
/* v8 ignore file -- thin self-executing dispatch; the tui-agent PTY smoke
exercises the TUI path end to end */
import { loadEnv } from '@deepseek-ai/dsh-app-boot'
import { runTui } from './tui.ts'
loadEnv('dsh')
const argv = process.argv.slice(2)
if (argv[0] === 'web' || argv.includes('-p') || argv.includes('--prompt')) {
process.stderr.write('dsh: the web and headless surfaces are not on this branch (PR #443); run the TUI: dsh [config.yml]\n')
process.exit(1)
}
await runTui(argv)

50
apps/cli/src/tui.ts Normal file
View File

@@ -0,0 +1,50 @@
/**
* `dsh` default surface — the interactive TUI coding agent. Boots the shipped
* tui-agent config (or an explicit config argument) with the personal overlay
* from `~/.config/dsh`: its `.env` fills environment gaps (precedence: ambient
* environment, then the invoking directory's `.env`, then the personal one)
* and its `config.yaml` patches the booted tree. The workspace is the invoking
* directory: sessions, relative paths, and workspace instructions resolve from
* the cwd, so `dsh` acts on whatever project it is launched in.
* @module @deepseek-ai/dsh/tui
*/
import { fileURLToPath } from 'node:url'
import {
boot,
installFailLoud,
loadEnv,
loadPersonalPatches,
resolveConfigPath,
resolvePersonalConfigDir,
} from '@deepseek-ai/dsh-app-boot'
const NAME = 'dsh'
// Both the source tree (apps/cli/src) and the bundled bin (apps/cli/lib) sit
// one directory under apps/cli, so the shipped default config resolves with
// the same relative hop from either artifact.
const DEFAULT_CONFIG = fileURLToPath(new URL('../../../examples/tui-agent/cordis.yml', import.meta.url))
/* v8 ignore start -- composition over the unit-tested dsh-app-boot helpers;
the tui-agent PTY smoke drives this path end to end, personal overlay included */
/**
* Run the interactive TUI from the invoking directory.
* @param argv - arguments after the subcommand dispatch; `argv[0]` may name a
* config to boot instead of the shipped default.
*/
export async function runTui(argv: string[]): Promise<void> {
// Refuse pipes BEFORE booting: a compose-time throw inside the Loader tree
// is logged per-entry rather than rethrown, so a piped launch would
// otherwise settle into an idle UI-less process instead of exiting nonzero.
if (!process.stdin.isTTY || !process.stdout.isTTY) {
process.stderr.write(`${NAME}: the TUI requires stdin and stdout to be interactive TTYs\n`)
process.exit(1)
}
installFailLoud(NAME)
// The bin already loaded the invoking directory's .env; the personal .env
// only fills what is still unset (process.loadEnvFile never overrides).
loadEnv(NAME, resolvePersonalConfigDir())
await boot(NAME, resolveConfigPath(argv[0] ?? DEFAULT_CONFIG, undefined), loadPersonalPatches(NAME))
}
/* v8 ignore stop */