Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/opencode/src/cli/cmd/tui/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function tui(input: {
sessionID?: string
model?: string
agent?: string
prompt?: string
onExit?: () => Promise<void>
}) {
// promise to prevent immediate exit
Expand Down Expand Up @@ -65,7 +66,7 @@ export function tui(input: {
<SDKProvider url={input.url}>
<SyncProvider>
<ThemeProvider>
<LocalProvider initialModel={input.model} initialAgent={input.agent}>
<LocalProvider initialModel={input.model} initialAgent={input.agent} initialPrompt={input.prompt}>
<KeybindProvider>
<DialogProvider>
<CommandProvider>
Expand Down
18 changes: 14 additions & 4 deletions packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
dim,
fg,
} from "@opentui/core"
import { createEffect, createMemo, Match, Switch, type JSX, onMount } from "solid-js"
import { createEffect, createMemo, Match, Switch, type JSX, onMount, batch } from "solid-js"
import { useLocal } from "@tui/context/local"
import { SyntaxTheme, useTheme } from "@tui/context/theme"
import { SplitBorder } from "@tui/component/border"
Expand Down Expand Up @@ -194,6 +194,16 @@ export function Prompt(props: PromptProps) {
input.focus()
})

local.setInitialPrompt.listen((initialPrompt) => {
batch(() => {
setStore("prompt", {
input: initialPrompt,
parts: [],
})
input.insertText(initialPrompt)
})
})

onMount(() => {
promptPartTypeId = input.extmarks.registerType("prompt-part")
})
Expand Down Expand Up @@ -310,9 +320,9 @@ export function Prompt(props: PromptProps) {
const sessionID = props.sessionID
? props.sessionID
: await (async () => {
const sessionID = await sdk.client.session.create({}).then((x) => x.data!.id)
return sessionID
})()
const sessionID = await sdk.client.session.create({}).then((x) => x.data!.id)
return sessionID
})()
const messageID = Identifier.ascending("message")
let inputText = store.prompt.input

Expand Down
13 changes: 12 additions & 1 deletion packages/opencode/src/cli/cmd/tui/context/local.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import { Global } from "@/global"
import { iife } from "@/util/iife"
import { createSimpleContext } from "./helper"
import { useToast } from "../ui/toast"
import { createEventBus } from "@solid-primitives/event-bus"

export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
name: "Local",
init: (props: { initialModel?: string; initialAgent?: string }) => {
init: (props: { initialModel?: string; initialAgent?: string; initialPrompt?: string }) => {
const sync = useSync()
const toast = useToast()

Expand Down Expand Up @@ -239,9 +240,19 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
}
})

const setInitialPrompt = createEventBus<string>()

onMount(() => {
if (props.initialPrompt)
setInitialPrompt.emit(props.initialPrompt)
})

const result = {
model,
agent,
get setInitialPrompt() {
return setInitialPrompt
},
}
return result
},
Expand Down
6 changes: 6 additions & 0 deletions packages/opencode/src/cli/cmd/tui/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export const TuiThreadCommand = cmd({
describe: "session id to continue",
type: "string",
})
.option("prompt", {
alias: ["p"],
type: "string",
describe: "prompt to use",
})
.option("agent", {
type: "string",
describe: "agent to use",
Expand Down Expand Up @@ -95,6 +100,7 @@ export const TuiThreadCommand = cmd({
sessionID,
model: args.model,
agent: args.agent,
prompt: args.prompt,
onExit: async () => {
await client.call("shutdown", undefined)
},
Expand Down