mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
Address review and cut ceremony: the adapter no longer models help/version/ errors as DshInvocation members. Commander owns those under exitOverride — it prints usage or the diagnostic and one try/catch in parseDshArgs turns the thrown CommanderError into process.exit with the intended code. bin.ts drops its help/version/error cases; the union is the three real modes. Domain checks bail via command.error(print + exit 1): --prompt rejects an empty task or a stray config/--resume, empty --resume= fails loud, and --host/--port are validated. A repeated --resume or a flag captured as a value is Commander's standard behavior, left alone (a bad id fails loud downstream). dsh --help discloses web via addHelpText. Net: args.ts 185 -> 112 lines. Also fixes review nits: built-bin e2e resolves on `close`; the /resume handoff uses `dsh --resume=<id> -- <config>` so a config named `web` stays a positional; and stale prose (cordis.yml comment, app-boot module doc + duplicate JSDoc, ui/README, two feature notes, an agent-loop test name) tracks the shipped state. Removes tui-demo's now-dead plugin-include dep and vendor/loader + app-boot tsconfig references.
52 lines
1.8 KiB
JavaScript
52 lines
1.8 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* 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;
|
|
* 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.
|
|
* @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 { loadEnv } 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'
|
|
}
|
|
|
|
loadEnv('dsh')
|
|
const invocation = parseDshArgs(process.argv.slice(2), readVersion())
|
|
|
|
switch (invocation.mode) {
|
|
case 'web': {
|
|
const { runWeb } = await import('./web.ts')
|
|
await runWeb(invocation.host, invocation.port, invocation.dev)
|
|
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)}`)
|
|
}
|