feat(tui): workflow-start intent input box wired to StartSession.input

This commit is contained in:
2026-06-04 02:24:41 +04:00
parent fe561ada09
commit 638f57709d
5 changed files with 82 additions and 13 deletions
+3
View File
@@ -20,6 +20,7 @@ type InputMode int
const (
ModeRouter InputMode = iota // chat / steering input
ModeFilter // session-list filter
ModeIntent // freeform request for a workflow being started
)
// EditMode is the vim-style modality: Normal = bare-key commands, Insert = typing.
@@ -146,6 +147,8 @@ type Model struct {
workflows []Workflow
wfIndex int // -1 = not in workflow picker
wfVisible bool
wfPendingID string // workflow chosen, awaiting an intent line before StartSession
wfPendingName string
bgUpdates int
// input
+34 -10
View File
@@ -243,6 +243,12 @@ func (m Model) handleInsertKey(k tea.KeyMsg) (tea.Model, tea.Cmd) {
if m.inputMode == ModeFilter {
m.inputMode = ModeRouter
}
if m.inputMode == ModeIntent {
m.wfPendingID = ""
m.wfPendingName = ""
m.clearInput()
m.inputMode = ModeRouter
}
case tea.KeyEnter:
return m.submit()
case tea.KeyBackspace:
@@ -275,6 +281,19 @@ func (m Model) handleInsertKey(k tea.KeyMsg) (tea.Model, tea.Cmd) {
return m, nil
}
// beginIntent stashes the chosen workflow and switches to a text-entry prompt for the
// freeform request. Submitting sends StartSession(id, intent); an empty line starts with no
// intent (fixed-task workflows). Esc cancels.
func (m *Model) beginIntent(wf Workflow) {
m.wfPendingID = wf.ID
m.wfPendingName = wf.ID
m.wfVisible = false
m.wfIndex = -1
m.clearInput()
m.editMode = ModeInsert
m.inputMode = ModeIntent
}
func (m *Model) enterInsert(mode InputMode) {
m.editMode = ModeInsert
m.inputMode = mode
@@ -296,11 +315,7 @@ func (m Model) normalEnter() (tea.Model, tea.Cmd) {
return m, nil
}
if m.wfVisible && m.wfIndex >= 0 && m.wfIndex < len(m.workflows) {
wf := m.workflows[m.wfIndex]
m.client.Send(protocol.StartSession(wf.ID))
m.wfVisible = false
m.wfIndex = -1
m.pendingWorkflowFocus = true
m.beginIntent(m.workflows[m.wfIndex])
return m, nil
}
if m.selectedID != "" {
@@ -537,12 +552,21 @@ func (m Model) submit() (tea.Model, tea.Cmd) {
switch ds {
case StateIdle:
// Workflow picker selection.
if m.wfIndex >= 0 && m.wfIndex < len(m.workflows) {
wf := m.workflows[m.wfIndex]
m.wfIndex = -1
m.client.Send(protocol.StartSession(wf.ID))
// Intent line for a workflow being started.
if m.wfPendingID != "" {
id := m.wfPendingID
m.client.Send(protocol.StartSession(id, text))
m.wfPendingID = ""
m.wfPendingName = ""
m.clearInput()
m.inputMode = ModeRouter
m.editMode = ModeNormal
m.pendingWorkflowFocus = true
return m, nil
}
// Workflow picker selection → prompt for the request first.
if m.wfIndex >= 0 && m.wfIndex < len(m.workflows) {
m.beginIntent(m.workflows[m.wfIndex])
return m, nil
}
// Entering an already-selected session (blank submit).
+5
View File
@@ -208,6 +208,8 @@ func (m Model) renderInput() string {
placeholder := "Ask anything…"
switch {
case m.inputMode == ModeIntent:
placeholder = "Describe the task for " + m.wfPendingName + " (Enter to start, empty = none)…"
case m.inputMode == ModeFilter:
placeholder = "Filter sessions…"
case m.displayState() == StateIdle:
@@ -241,6 +243,9 @@ func (m Model) renderInput() string {
if m.inputMode == ModeFilter {
mode = "filter"
}
if m.inputMode == ModeIntent {
mode = "task"
}
sub := lipgloss.NewStyle().Foreground(t.P.Accent2).Background(t.P.Bg).Render(name)
if m.selectedID != "" {
sub += t.span(" · ", t.P.Faint) +