refactor(cli): simplify mini arguments
This commit is contained in:
@@ -3,31 +3,6 @@ import { Spec } from "../framework/spec"
|
|||||||
|
|
||||||
declare const OPENCODE_CLI_NAME: string | undefined
|
declare const OPENCODE_CLI_NAME: string | undefined
|
||||||
|
|
||||||
const MiniParams = {
|
|
||||||
continue: Flag.boolean("continue").pipe(
|
|
||||||
Flag.withAlias("c"),
|
|
||||||
Flag.withDescription("Continue the last session"),
|
|
||||||
Flag.withDefault(false),
|
|
||||||
),
|
|
||||||
session: Flag.string("session").pipe(
|
|
||||||
Flag.withAlias("s"),
|
|
||||||
Flag.withDescription("Session ID to continue"),
|
|
||||||
Flag.optional,
|
|
||||||
),
|
|
||||||
fork: Flag.boolean("fork").pipe(
|
|
||||||
Flag.withDescription("Fork the session when continuing"),
|
|
||||||
Flag.withDefault(false),
|
|
||||||
),
|
|
||||||
replay: Flag.boolean("replay").pipe(
|
|
||||||
Flag.withDescription("Replay session history on resume and after resize"),
|
|
||||||
Flag.withDefault(true),
|
|
||||||
),
|
|
||||||
replayLimit: Flag.integer("replay-limit").pipe(
|
|
||||||
Flag.withDescription("Cap visible replay to the newest N messages"),
|
|
||||||
Flag.optional,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
|
|
||||||
const ServerParams = {
|
const ServerParams = {
|
||||||
standalone: Flag.boolean("standalone").pipe(
|
standalone: Flag.boolean("standalone").pipe(
|
||||||
Flag.withDescription("Run with a private server instead of the background service"),
|
Flag.withDescription("Run with a private server instead of the background service"),
|
||||||
@@ -131,11 +106,28 @@ export const Commands = Spec.make(typeof OPENCODE_CLI_NAME === "string" ? OPENCO
|
|||||||
Spec.make("mini", {
|
Spec.make("mini", {
|
||||||
description: "Start the minimal interactive interface",
|
description: "Start the minimal interactive interface",
|
||||||
params: {
|
params: {
|
||||||
...MiniParams,
|
|
||||||
...ServerParams,
|
...ServerParams,
|
||||||
project: Argument.string("project").pipe(
|
continue: Flag.boolean("continue").pipe(
|
||||||
Argument.withDescription("Path to start OpenCode in"),
|
Flag.withAlias("c"),
|
||||||
Argument.optional,
|
Flag.withDescription("Continue the last session"),
|
||||||
|
Flag.withDefault(false),
|
||||||
|
),
|
||||||
|
session: Flag.string("session").pipe(
|
||||||
|
Flag.withAlias("s"),
|
||||||
|
Flag.withDescription("Session ID to continue"),
|
||||||
|
Flag.optional,
|
||||||
|
),
|
||||||
|
fork: Flag.boolean("fork").pipe(
|
||||||
|
Flag.withDescription("Fork the session when continuing"),
|
||||||
|
Flag.withDefault(false),
|
||||||
|
),
|
||||||
|
replay: Flag.boolean("replay").pipe(
|
||||||
|
Flag.withDescription("Replay session history on resume and after resize"),
|
||||||
|
Flag.withDefault(true),
|
||||||
|
),
|
||||||
|
replayLimit: Flag.integer("replay-limit").pipe(
|
||||||
|
Flag.withDescription("Cap visible replay to the newest N messages"),
|
||||||
|
Flag.optional,
|
||||||
),
|
),
|
||||||
model: Flag.string("model").pipe(
|
model: Flag.string("model").pipe(
|
||||||
Flag.withAlias("m"),
|
Flag.withAlias("m"),
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Effect, Option } from "effect"
|
import { Effect, Option } from "effect"
|
||||||
import path from "node:path"
|
|
||||||
import { Commands } from "../commands"
|
import { Commands } from "../commands"
|
||||||
import { Runtime } from "../../framework/runtime"
|
import { Runtime } from "../../framework/runtime"
|
||||||
import { Server } from "../../services/server"
|
import { Server } from "../../services/server"
|
||||||
@@ -8,14 +7,11 @@ export default Runtime.handler(Commands.commands.mini, (input) =>
|
|||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const { runMini, validateMiniTerminal } = yield* Effect.promise(() => import("../../mini"))
|
const { runMini, validateMiniTerminal } = yield* Effect.promise(() => import("../../mini"))
|
||||||
yield* Effect.promise(async () => validateMiniTerminal())
|
yield* Effect.promise(async () => validateMiniTerminal())
|
||||||
const project = Option.getOrUndefined(input.project)
|
|
||||||
const serverURL = Option.getOrUndefined(input.server)
|
const serverURL = Option.getOrUndefined(input.server)
|
||||||
const server = yield* Server.resolve({ server: serverURL, standalone: input.standalone })
|
const server = yield* Server.resolve({ server: serverURL, standalone: input.standalone })
|
||||||
yield* Effect.promise(() =>
|
yield* Effect.promise(() =>
|
||||||
runMini({
|
runMini({
|
||||||
server,
|
server,
|
||||||
directory:
|
|
||||||
project === undefined ? process.cwd() : path.resolve(process.env.PWD ?? process.cwd(), project),
|
|
||||||
continue: input.continue,
|
continue: input.continue,
|
||||||
session: Option.getOrUndefined(input.session),
|
session: Option.getOrUndefined(input.session),
|
||||||
fork: input.fork,
|
fork: input.fork,
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { Service } from "@opencode-ai/client/effect"
|
import { Service } from "@opencode-ai/client/effect"
|
||||||
import { OpenCode, type OpenCodeClient } from "@opencode-ai/client/promise"
|
import { OpenCode, type OpenCodeClient } from "@opencode-ai/client/promise"
|
||||||
import path from "node:path"
|
|
||||||
import { Server } from "../services/server"
|
import { Server } from "../services/server"
|
||||||
import { waitForCatalogReady } from "./catalog.shared"
|
import { waitForCatalogReady } from "./catalog.shared"
|
||||||
import { INTERACTIVE_INPUT_ERROR, resolveInteractiveStdin } from "./runtime.stdin"
|
import { INTERACTIVE_INPUT_ERROR, resolveInteractiveStdin } from "./runtime.stdin"
|
||||||
@@ -8,7 +7,6 @@ import type { RunInput, RunTuiConfig } from "./types"
|
|||||||
|
|
||||||
export type MiniCommandInput = {
|
export type MiniCommandInput = {
|
||||||
server: Server.Resolved
|
server: Server.Resolved
|
||||||
directory?: string
|
|
||||||
continue?: boolean
|
continue?: boolean
|
||||||
session?: string
|
session?: string
|
||||||
fork?: boolean
|
fork?: boolean
|
||||||
@@ -26,7 +24,7 @@ export async function runMini(input: MiniCommandInput) {
|
|||||||
validate(input)
|
validate(input)
|
||||||
const initialInput = mergeInput(process.stdin.isTTY ? undefined : await Bun.stdin.text(), input.prompt)
|
const initialInput = mergeInput(process.stdin.isTTY ? undefined : await Bun.stdin.text(), input.prompt)
|
||||||
const runtimeTask = import("./runtime")
|
const runtimeTask = import("./runtime")
|
||||||
const directory = localDirectory(input.directory)
|
const directory = localDirectory()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const sdk = OpenCode.make({
|
const sdk = OpenCode.make({
|
||||||
@@ -98,13 +96,13 @@ function validate(input: MiniCommandInput) {
|
|||||||
resolveInteractiveStdin().cleanup?.()
|
resolveInteractiveStdin().cleanup?.()
|
||||||
}
|
}
|
||||||
|
|
||||||
function localDirectory(directory?: string): string {
|
function localDirectory(): string {
|
||||||
const root = process.env.PWD ?? process.cwd()
|
const root = process.env.PWD ?? process.cwd()
|
||||||
try {
|
try {
|
||||||
process.chdir(directory ? (path.isAbsolute(directory) ? directory : path.join(root, directory)) : root)
|
process.chdir(root)
|
||||||
return process.cwd()
|
return process.cwd()
|
||||||
} catch {
|
} catch {
|
||||||
fail(`Failed to change directory to ${directory}`)
|
fail(`Failed to change directory to ${root}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user