bin.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env node
  2. /**
  3. * dsh — command-line entry. Dynamic imports per mode keep unrelated modes out
  4. * of each dispatch path; the adapter prints and exits for
  5. * `--help`/`--version`/a parse error, so only a valid mode reaches the switch.
  6. * @module @deepseek-ai/dsh/bin
  7. */
  8. /* v8 ignore file -- built-bin and PTY tests exercise this self-executing dispatch. */
  9. import { readFileSync } from 'node:fs'
  10. import { fileURLToPath } from 'node:url'
  11. import { loadEnv } from '@deepseek-ai/dsh-app-boot'
  12. import { parseDshArgs } from './args.ts'
  13. // Both the source tree (apps/cli/src) and the bundled bin (apps/cli/lib) sit
  14. // one directory under apps/cli, so the checked-in manifest resolves with the
  15. // same relative hop from either artifact.
  16. /** This app's version, read from its checked-in package.json. */
  17. function readVersion(): string {
  18. const manifest = JSON.parse(
  19. readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf8'),
  20. ) as { version?: unknown }
  21. return typeof manifest.version === 'string' ? manifest.version : '0.0.0'
  22. }
  23. loadEnv('dsh')
  24. const invocation = parseDshArgs(process.argv.slice(2), readVersion())
  25. switch (invocation.mode) {
  26. case 'web': {
  27. const { runWeb } = await import('./web.ts')
  28. await runWeb(invocation.host, invocation.port, invocation.dev, invocation.workspaceRoot)
  29. break
  30. }
  31. case 'headless': {
  32. const { runHeadless } = await import('./headless.ts')
  33. await runHeadless(invocation.prompt)
  34. break
  35. }
  36. case 'tui': {
  37. const { runTui } = await import('./tui.ts')
  38. await runTui(invocation.config, invocation.resume)
  39. break
  40. }
  41. default:
  42. invocation satisfies never
  43. throw new Error(`dsh: unhandled invocation mode ${JSON.stringify(invocation)}`)
  44. }