MCPcopy Create free account
hub / github.com/anomalyco/opencode / createPromptState

Function createPromptState

packages/opencode/src/cli/cmd/run/footer.prompt.tsx:282–1306  ·  view source on GitHub ↗
(input: PromptInput)

Source from the content-addressed store, hash-verified

280}
281
282export function createPromptState(input: PromptInput): PromptState {
283 const [shell, setShell] = createSignal(false)
284 const placeholder = createMemo(() => {
285 if (shell()) {
286 return new StyledText([fg(input.theme().muted)('Run a command... "git status"')])
287 }
288
289 if (!input.state().first) {
290 return ""
291 }
292
293 return new StyledText([fg(input.theme().muted)('Ask anything... "Fix a TODO in the codebase"')])
294 })
295
296 let history = createPromptHistory(input.history)
297 let draft: RunPrompt = { text: "", parts: [] }
298 let stash: RunPrompt = { text: "", parts: [] }
299 let area: TextareaRenderable | undefined
300 let tick = false
301 let prev = input.view()
302 let type = 0
303 let parts: Mention[] = []
304 let marks = new Map<number, number>()
305
306 const [mode, setMode] = createSignal<MenuMode>(false)
307 const [at, setAt] = createSignal(0)
308 const [query, setQuery] = createSignal("")
309 const visible = createMemo(() => mode() !== false)
310
311 const setShellMode = (value: boolean) => {
312 setShell(value)
313 draft = value ? { ...draft, mode: "shell" } : { text: draft.text, parts: structuredClone(draft.parts) }
314 }
315
316 const width = createMemo(() => Math.max(20, input.width() - 8))
317 const agents = createMemo<Auto[]>(() => {
318 return input
319 .agents()
320 .filter((item) => !item.hidden && item.mode !== "primary")
321 .map((item) => ({
322 kind: "mention",
323 display: "@" + item.name,
324 value: item.name,
325 part: {
326 type: "agent",
327 name: item.name,
328 source: {
329 start: 0,
330 end: 0,
331 value: "",
332 },
333 },
334 }))
335 })
336 const resources = createMemo<Auto[]>(() => {
337 return input.resources().map((item) => ({
338 kind: "mention",
339 display: Locale.truncateMiddle(`@${item.name} (${item.uri})`, width()),

Callers 1

RunFooterViewFunction · 0.90

Calls 15

createPromptHistoryFunction · 0.90
createFooterMenuStateFunction · 0.90
shellFunction · 0.85
fgFunction · 0.85
agentsFunction · 0.85
resourcesFunction · 0.85
baseBindingsEnabledFunction · 0.85
setShellModeFunction · 0.85
scheduleRowsFunction · 0.85
syncDraftFunction · 0.85
stateMethod · 0.80
offMethod · 0.80

Tested by

no test coverage detected