2026-07-22 10:55:17 +08:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
/**
|
2026-07-24 19:43:59 +08:00
|
|
|
* dsh — command-line entry. Parses argv once through the Commander adapter and
|
|
|
|
|
* switches on the resolved mode; dynamic imports keep unrelated modes out of
|
|
|
|
|
* each dispatch path. `web` and headless prompts run their own module;
|
2026-07-25 14:15:25 +08:00
|
|
|
* everything else opens the TUI. The adapter itself prints and exits for
|
|
|
|
|
* `--help`/`--version`/a parse error, so only a valid mode reaches the switch.
|
2026-07-22 10:55:17 +08:00
|
|
|
* @module @deepseek-ai/dsh/bin
|
|
|
|
|
*/
|
|
|
|
|
|
2026-07-22 20:45:24 +08:00
|
|
|
/* v8 ignore file -- built-bin and PTY tests exercise this self-executing dispatch. */
|
2026-07-22 10:55:17 +08:00
|
|
|
|
2026-07-24 19:43:59 +08:00
|
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
|
import { fileURLToPath } from 'node:url'
|
2026-07-22 10:55:17 +08:00
|
|
|
import { loadEnv } from '@deepseek-ai/dsh-app-boot'
|
2026-07-24 19:43:59 +08:00
|
|
|
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'
|
|
|
|
|
}
|
2026-07-22 10:55:17 +08:00
|
|
|
|
|
|
|
|
loadEnv('dsh')
|
2026-07-24 19:43:59 +08:00
|
|
|
const invocation = parseDshArgs(process.argv.slice(2), readVersion())
|
2026-07-22 10:55:17 +08:00
|
|
|
|
2026-07-24 19:43:59 +08:00
|
|
|
switch (invocation.mode) {
|
|
|
|
|
case 'web': {
|
|
|
|
|
const { runWeb } = await import('./web.ts')
|
2026-07-25 12:02:28 +08:00
|
|
|
await runWeb(invocation.host, invocation.port, invocation.dev)
|
2026-07-24 19:43:59 +08:00
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
case 'headless': {
|
|
|
|
|
const { runHeadless } = await import('./headless.ts')
|
|
|
|
|
await runHeadless(invocation.prompt)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
case 'tui': {
|
|
|
|
|
const { runTui } = await import('./tui.ts')
|
|
|
|
|
await runTui(invocation.config, invocation.resume)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
invocation satisfies never
|
|
|
|
|
throw new Error(`dsh: unhandled invocation mode ${JSON.stringify(invocation)}`)
|
2026-07-22 10:55:17 +08:00
|
|
|
}
|