bin.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 acceptance exercises 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 'config': {
  27. const { runConfig } = await import('./config.ts')
  28. await runConfig(invocation.config)
  29. break
  30. }
  31. case 'web': {
  32. const { runWeb } = await import('./web.ts')
  33. await runWeb(invocation.host, invocation.port, invocation.dev, invocation.workspaceRoot, invocation.trustedHosts, invocation.config)
  34. break
  35. }
  36. case 'headless': {
  37. const { runHeadless } = await import('./headless.ts')
  38. await runHeadless(invocation.prompt)
  39. break
  40. }
  41. case 'dump-config': {
  42. const { runDumpConfig } = await import('./dump-config.ts')
  43. runDumpConfig(invocation.surface, invocation.defaultOnly, invocation.config)
  44. break
  45. }
  46. default:
  47. invocation satisfies never
  48. throw new Error(`dsh: unhandled invocation mode ${JSON.stringify(invocation)}`)
  49. }