diff options
| author | Aiden Cline <[email protected]> | 2025-09-01 14:19:18 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-09-01 14:19:18 -0500 |
| commit | e2df3eb44dc8b032f74ed0273a53be5f83aaab13 (patch) | |
| tree | 8b52a13d44d680e353e8472bbc681ee8130f4b0c /packages | |
| parent | 38f9ce05f6067290fdba9ecbc5a66ae956d47780 (diff) | |
| download | opencode-e2df3eb44dc8b032f74ed0273a53be5f83aaab13.tar.gz opencode-e2df3eb44dc8b032f74ed0273a53be5f83aaab13.zip | |
add --command to opencode run (#2348)
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/opencode/src/cli/cmd/run.ts | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/packages/opencode/src/cli/cmd/run.ts b/packages/opencode/src/cli/cmd/run.ts index 181d8c1e7..969d99079 100644 --- a/packages/opencode/src/cli/cmd/run.ts +++ b/packages/opencode/src/cli/cmd/run.ts @@ -10,6 +10,7 @@ import { bootstrap } from "../bootstrap" import { MessageV2 } from "../../session/message-v2" import { Identifier } from "../../id/id" import { Agent } from "../../agent/agent" +import { Command } from "../../command" const TOOL: Record<string, [string, string]> = { todowrite: ["Todo", UI.Style.TEXT_WARNING_BOLD], @@ -35,6 +36,10 @@ export const RunCommand = cmd({ array: true, default: [], }) + .option("command", { + describe: "the command to run, use message for args", + type: "string", + }) .option("continue", { alias: ["c"], describe: "continue the last session", @@ -64,12 +69,20 @@ export const RunCommand = cmd({ if (!process.stdin.isTTY) message += "\n" + (await Bun.stdin.text()) - if (message.trim().length === 0) { - UI.error("Message cannot be empty") + if (message.trim().length === 0 && !args.command) { + UI.error("You must provide a message or a command") return } await bootstrap({ cwd: process.cwd() }, async () => { + if (args.command) { + const exists = await Command.get(args.command) + if (!exists) { + UI.error(`Command "${args.command}" not found`) + return + } + } + const session = await (async () => { if (args.continue) { const it = Session.list() @@ -172,6 +185,18 @@ export const RunCommand = cmd({ UI.error(err) }) + if (args.command) { + await Session.command({ + messageID: Identifier.ascending("message"), + sessionID: session.id, + agent: agent.name, + model: providerID + "/" + modelID, + command: args.command, + arguments: message, + }) + return + } + const messageID = Identifier.ascending("message") const result = await Session.chat({ sessionID: session.id, |
