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
25 changes: 7 additions & 18 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nix/hashes.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"nodeModules": "sha256-fFIJ8CneAo0gHRK8ghsYnEQw/Dnmu00xN5MHgPam8hg="
"nodeModules": "sha256-kgJKAqccRJOQcJ8+/j+lGe7T6WZuQqYv6UGl3jvI9wQ="
}
1 change: 1 addition & 0 deletions packages/opencode/bunfig.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ preload = ["@opentui/solid/preload"]

[test]
preload = ["./test/preload.ts"]
timeout = 10000 # 10 seconds (default is 5000ms)
# Enable code coverage
coverage = true
7 changes: 3 additions & 4 deletions packages/opencode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,18 @@
"@actions/github": "6.0.1",
"@agentclientprotocol/sdk": "0.5.1",
"@ai-sdk/amazon-bedrock": "3.0.57",
"@ai-sdk/azure": "2.0.82",
"@ai-sdk/anthropic": "2.0.56",
"@ai-sdk/azure": "2.0.73",
"@ai-sdk/cerebras": "1.0.33",
"@ai-sdk/cohere": "2.0.21",
"@ai-sdk/deepinfra": "1.0.30",
"@ai-sdk/gateway": "2.0.23",
"@ai-sdk/google": "2.0.44",
"@ai-sdk/google": "2.0.49",
"@ai-sdk/google-vertex": "3.0.81",
"@ai-sdk/groq": "2.0.33",
"@ai-sdk/mcp": "0.0.8",
"@ai-sdk/mistral": "2.0.26",
"@ai-sdk/openai": "2.0.71",
"@ai-sdk/openai-compatible": "1.0.27",
"@ai-sdk/openai-compatible": "1.0.29",
"@ai-sdk/perplexity": "2.0.22",
"@ai-sdk/provider": "2.0.0",
"@ai-sdk/provider-utils": "3.0.19",
Expand Down
49 changes: 49 additions & 0 deletions packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ export function Prompt(props: PromptProps) {
if (!props.disabled) input.cursorColor = theme.text
})

const lastUserMessage = createMemo(() => {
if (!props.sessionID) return undefined
const messages = sync.data.message[props.sessionID]
if (!messages) return undefined
return messages.findLast((m) => m.role === "user")
})

const [store, setStore] = createStore<{
prompt: PromptInfo
mode: "normal" | "shell"
Expand All @@ -184,6 +191,26 @@ export function Prompt(props: PromptProps) {
interrupt: 0,
})

createEffect(() => {
const msg = lastUserMessage()
if (!msg) return

// Set agent from last message
if (msg.agent) {
local.agent.set(msg.agent)
}

// Set model from last message
if (msg.model) {
local.model.set(msg.model)
}

// Set variant from last message
if (msg.variant) {
local.model.variant.set(msg.variant)
}
})

command.register(() => {
return [
{
Expand Down Expand Up @@ -562,6 +589,7 @@ export function Prompt(props: PromptProps) {

// Capture mode before it gets reset
const currentMode = store.mode
const variant = local.model.variant.current()

if (store.mode === "shell") {
sdk.client.session.shell({
Expand Down Expand Up @@ -590,6 +618,7 @@ export function Prompt(props: PromptProps) {
agent: local.agent.current().name,
model: `${selectedModel.providerID}/${selectedModel.modelID}`,
messageID,
variant,
})
} else {
sdk.client.session.prompt({
Expand All @@ -598,6 +627,7 @@ export function Prompt(props: PromptProps) {
messageID,
agent: local.agent.current().name,
model: selectedModel,
variant,
parts: [
{
id: Identifier.ascending("part"),
Expand Down Expand Up @@ -718,6 +748,13 @@ export function Prompt(props: PromptProps) {
return local.agent.color(local.agent.current().name)
})

const showVariant = createMemo(() => {
const variants = local.model.variant.list()
if (variants.length === 0) return false
const current = local.model.variant.current()
return !!current
})

const spinnerDef = createMemo(() => {
const color = local.agent.color(local.agent.current().name)
return {
Expand Down Expand Up @@ -843,6 +880,12 @@ export function Prompt(props: PromptProps) {
return
}
}
if (keybind.match("variant_cycle", e)) {
e.preventDefault()
if (local.model.variant.list().length === 0) return
local.model.variant.cycle()
return
}
if (store.mode === "normal") autocomplete.onKeyDown(e)
if (!autocomplete.visible) {
if (
Expand Down Expand Up @@ -958,6 +1001,12 @@ export function Prompt(props: PromptProps) {
{local.model.parsed().model}
</text>
<text fg={theme.textMuted}>{local.model.parsed().provider}</text>
<Show when={showVariant()}>
<text fg={theme.textMuted}>·</text>
<text>
<span style={{ fg: theme.warning, bold: true }}>{local.model.variant.current()}</span>
</text>
</Show>
</box>
</Show>
</box>
Expand Down
Loading