commands.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { Argument, Flag } from "effect/unstable/cli"
  2. import { Spec } from "../framework/spec"
  3. declare const OPENCODE_CLI_NAME: string | undefined
  4. export const Commands = Spec.make(typeof OPENCODE_CLI_NAME === "string" ? OPENCODE_CLI_NAME : "opencode", {
  5. description: "OpenCode 2.0 preview command line interface",
  6. commands: [
  7. Spec.make("api", {
  8. description: "Make a request to the running server",
  9. params: {
  10. request: Argument.string("operation | method path").pipe(
  11. Argument.withDescription("OpenAPI operation ID, or an HTTP method followed by a path"),
  12. Argument.variadic({ min: 1, max: 2 }),
  13. ),
  14. data: Flag.string("data").pipe(Flag.withAlias("d"), Flag.withDescription("Request body"), Flag.optional),
  15. header: Flag.string("header").pipe(
  16. Flag.withAlias("H"),
  17. Flag.withDescription("Request header in name:value form"),
  18. Flag.atMost(100),
  19. ),
  20. param: Flag.keyValuePair("param").pipe(Flag.withDescription("OpenAPI path or query parameter"), Flag.optional),
  21. },
  22. }),
  23. Spec.make("debug", {
  24. description: "Debugging and troubleshooting tools",
  25. commands: [Spec.make("agents", { description: "List all agents" })],
  26. }),
  27. Spec.make("migrate", { description: "Migrate v1 data to v2" }),
  28. Spec.make("service", {
  29. description: "Manage the background server",
  30. commands: [
  31. Spec.make("start", { description: "Start the background server" }),
  32. Spec.make("restart", { description: "Restart the background server" }),
  33. Spec.make("status", { description: "Show background server status" }),
  34. Spec.make("stop", { description: "Stop the background server" }),
  35. Spec.make("password", {
  36. description: "Get or set the server password",
  37. params: { value: Argument.string("value").pipe(Argument.optional) },
  38. }),
  39. ],
  40. }),
  41. Spec.make("serve", {
  42. description: "Start the v2 API server",
  43. params: {
  44. hostname: Flag.string("hostname").pipe(Flag.withDefault("127.0.0.1")),
  45. port: Flag.integer("port").pipe(Flag.optional),
  46. register: Flag.boolean("register").pipe(Flag.withDefault(false)),
  47. },
  48. }),
  49. ],
  50. })