mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-19 00:34:23 +01:00
add --command to opencode run (#2348)
This commit is contained in:
@@ -10,6 +10,7 @@ import { bootstrap } from "../bootstrap"
|
|||||||
import { MessageV2 } from "../../session/message-v2"
|
import { MessageV2 } from "../../session/message-v2"
|
||||||
import { Identifier } from "../../id/id"
|
import { Identifier } from "../../id/id"
|
||||||
import { Agent } from "../../agent/agent"
|
import { Agent } from "../../agent/agent"
|
||||||
|
import { Command } from "../../command"
|
||||||
|
|
||||||
const TOOL: Record<string, [string, string]> = {
|
const TOOL: Record<string, [string, string]> = {
|
||||||
todowrite: ["Todo", UI.Style.TEXT_WARNING_BOLD],
|
todowrite: ["Todo", UI.Style.TEXT_WARNING_BOLD],
|
||||||
@@ -35,6 +36,10 @@ export const RunCommand = cmd({
|
|||||||
array: true,
|
array: true,
|
||||||
default: [],
|
default: [],
|
||||||
})
|
})
|
||||||
|
.option("command", {
|
||||||
|
describe: "the command to run, use message for args",
|
||||||
|
type: "string",
|
||||||
|
})
|
||||||
.option("continue", {
|
.option("continue", {
|
||||||
alias: ["c"],
|
alias: ["c"],
|
||||||
describe: "continue the last session",
|
describe: "continue the last session",
|
||||||
@@ -64,12 +69,20 @@ export const RunCommand = cmd({
|
|||||||
|
|
||||||
if (!process.stdin.isTTY) message += "\n" + (await Bun.stdin.text())
|
if (!process.stdin.isTTY) message += "\n" + (await Bun.stdin.text())
|
||||||
|
|
||||||
if (message.trim().length === 0) {
|
if (message.trim().length === 0 && !args.command) {
|
||||||
UI.error("Message cannot be empty")
|
UI.error("You must provide a message or a command")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await bootstrap({ cwd: process.cwd() }, async () => {
|
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 () => {
|
const session = await (async () => {
|
||||||
if (args.continue) {
|
if (args.continue) {
|
||||||
const it = Session.list()
|
const it = Session.list()
|
||||||
@@ -172,6 +185,18 @@ export const RunCommand = cmd({
|
|||||||
UI.error(err)
|
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 messageID = Identifier.ascending("message")
|
||||||
const result = await Session.chat({
|
const result = await Session.chat({
|
||||||
sessionID: session.id,
|
sessionID: session.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user