allow selecting model and continuing previous session for opencode run

This commit is contained in:
Dax Raad
2025-06-19 12:29:34 -04:00
parent 24c0ce6e53
commit 7d1a1663c8
3 changed files with 48 additions and 5 deletions

View File

@@ -33,7 +33,13 @@ export const RunCommand = cmd({
array: true,
default: [],
})
.option("continue", {
alias: ["c"],
describe: "Continue the last session",
type: "boolean",
})
.option("session", {
alias: ["s"],
describe: "Session ID to continue",
type: "string",
})
@@ -41,6 +47,11 @@ export const RunCommand = cmd({
type: "boolean",
describe: "Share the session",
})
.option("model", {
type: "string",
alias: ["m"],
describe: "Model to use in the format of provider/model",
})
},
handler: async (args) => {
const message = args.message.join(" ")
@@ -50,9 +61,22 @@ export const RunCommand = cmd({
},
async () => {
await Share.init()
const session = args.session
? await Session.get(args.session)
: await Session.create()
const session = await (async () => {
if (args.continue) {
const first = await Session.list().next()
if (first.done) return
return first.value
}
if (args.session) return Session.get(args.session)
return Session.create()
})()
if (!session) {
UI.error("Session not found")
return
}
UI.empty()
UI.println(UI.logo())
@@ -71,7 +95,9 @@ export const RunCommand = cmd({
}
UI.empty()
const { providerID, modelID } = await Provider.defaultModel()
const { providerID, modelID } = args.model
? Provider.parseModel(args.model)
: await Provider.defaultModel()
UI.println(
UI.Style.TEXT_NORMAL_BOLD + "@ ",
UI.Style.TEXT_NORMAL + `${providerID}/${modelID}`,