Skip to content

Commit cc53149

Browse files
committed
fix: --prompt flag now auto-submits to begin session
Fixes anomalyco#4700 - Add submit() method to PromptRef interface to expose internal submit function - Move submit function definition before ref assignment to avoid circular reference - Add auto-submit logic in Home component with 100ms delay after setting prompt - When --prompt is provided, it now both populates input AND auto-submits Changes: - packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx: Add submit() to PromptRef and expose in ref - packages/opencode/src/cli/cmd/tui/routes/home.tsx: Add setTimeout to auto-submit prompt after setting
1 parent 125af82 commit cc53149

2 files changed

Lines changed: 36 additions & 27 deletions

File tree

‎packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx‎

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export type PromptRef = {
3838
reset(): void
3939
blur(): void
4040
focus(): void
41+
submit(): void
4142
}
4243

4344
export function Prompt(props: PromptProps) {
@@ -357,33 +358,6 @@ export function Prompt(props: PromptProps) {
357358
)
358359
}
359360

360-
props.ref?.({
361-
get focused() {
362-
return input.focused
363-
},
364-
focus() {
365-
input.focus()
366-
},
367-
blur() {
368-
input.blur()
369-
},
370-
set(prompt) {
371-
input.setText(prompt.input, { history: false })
372-
setStore("prompt", prompt)
373-
restoreExtmarksFromParts(prompt.parts)
374-
input.gotoBufferEnd()
375-
},
376-
reset() {
377-
input.clear()
378-
input.extmarks.clear()
379-
setStore("prompt", {
380-
input: "",
381-
parts: [],
382-
})
383-
setStore("extmarkToPartIndex", new Map())
384-
},
385-
})
386-
387361
async function submit() {
388362
if (props.disabled) return
389363
if (autocomplete.visible) return
@@ -495,6 +469,37 @@ export function Prompt(props: PromptProps) {
495469
}, 50)
496470
input.clear()
497471
}
472+
473+
props.ref?.({
474+
get focused() {
475+
return input.focused
476+
},
477+
focus() {
478+
input.focus()
479+
},
480+
blur() {
481+
input.blur()
482+
},
483+
set(prompt) {
484+
input.setText(prompt.input, { history: false })
485+
setStore("prompt", prompt)
486+
restoreExtmarksFromParts(prompt.parts)
487+
input.gotoBufferEnd()
488+
},
489+
reset() {
490+
input.clear()
491+
input.extmarks.clear()
492+
setStore("prompt", {
493+
input: "",
494+
parts: [],
495+
})
496+
setStore("extmarkToPartIndex", new Map())
497+
},
498+
submit() {
499+
submit()
500+
},
501+
})
502+
498503
const exit = useExit()
499504

500505
async function pasteImage(file: { filename?: string; content: string; mime: string }) {

‎packages/opencode/src/cli/cmd/tui/routes/home.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export function Home() {
4444
if (once) return
4545
if (args.prompt) {
4646
prompt.set({ input: args.prompt, parts: [] })
47+
// Auto-submit the prompt after a short delay to ensure it's properly set
48+
setTimeout(() => {
49+
prompt.submit()
50+
}, 100)
4751
once = true
4852
}
4953
})

0 commit comments

Comments
 (0)