Run tasks directly with language-independent project tools

This commit is contained in:
2026-10-09 01:48:46 +01:00
parent 998b0941d3
commit ed93d055bf
23 changed files with 170 additions and 156 deletions
+2 -8
View File
@@ -100,14 +100,8 @@ func (m Model) configureCLIRun() (tea.Model, tea.Cmd) {
m.runPaths = append([]string(nil), m.cliOptions.WritePaths...)
if m.cliOptions.Prompt != "" {
m.runTask = m.cliOptions.Prompt
m.runForm = 3
m.runInput = newInput()
m.runInput.Placeholder = "Type RUN to confirm"
cmd = m.runInput.Focus()
if m.cliOptions.Yes {
cmd = m.startSelectedRun()
return m, cmd
}
cmd = m.startSelectedRun()
return m, cmd
}
return m, cmd
}
+4 -4
View File
@@ -41,7 +41,7 @@ func TestCLIPickerAndMultilinePrompt(t *testing.T) {
m.runPrompt.SetValue("line one\nline two")
updated, _ = m.updateRunForm(tea.KeyMsg{Type: tea.KeyCtrlS})
m = updated.(Model)
if m.runForm != 2 || m.runTask != "line one\nline two" {
if m.runForm != 0 || !m.runOpen || m.runTask != "line one\nline two" {
t.Fatal("multiline prompt lost")
}
}
@@ -61,12 +61,12 @@ func TestDashboardRunUsesInvocationDirectory(t *testing.T) {
}
}
func TestCLISuppliedArgumentsStillRequireConfirmation(t *testing.T) {
func TestCLISuppliedArgumentsStartWithoutConfirmation(t *testing.T) {
m := NewRun(context.Background(), "", RunOptions{Pipeline: "test", Prompt: "task", Workspace: "/repos/a"})
m.detail = &protocol.PipelineDetail{PipelineSummary: protocol.PipelineSummary{ID: 1, Name: "test", Version: 1}}
updated, _ := m.configureCLIRun()
m = updated.(Model)
if m.runForm != 3 || m.runOpen || m.runTask != "task" || m.runWorkspace != "/repos/a" {
t.Fatal("arguments skipped approval or lost repository")
if m.runForm != 0 || !m.runOpen || m.runTask != "task" || m.runWorkspace != "/repos/a" {
t.Fatal("supplied task did not start immediately or lost repository")
}
}
+5 -1
View File
@@ -241,7 +241,11 @@ func (m Model) runSectionLines(width int) []string {
if m.runError != "" {
summary = append(summary, "Request error: "+m.runError)
}
content := [][]string{summary, valueLines(r.Input), valueLines(r.Output), {"Select a stage to inspect its tool calls."}, {"Workspace: " + r.Workspace, "Source hash: " + r.ContentHash, fmt.Sprintf("Manual shell/edit approval: %t", r.AllowTools), "Stage tools: defined by the pinned pipeline version", "Edit scope: " + strings.Join(r.WritePaths, ", ")}}
editScope := "all files in run directory"
if len(r.WritePaths) > 0 {
editScope = strings.Join(r.WritePaths, ", ")
}
content := [][]string{summary, valueLines(r.Input), valueLines(r.Output), {"Select a stage to inspect its tool calls."}, {"Workspace: " + r.Workspace, "Source hash: " + r.ContentHash, fmt.Sprintf("Shell/edit enabled: %t", r.AllowTools), "Stage tools: defined by the pinned pipeline version", "Edit scope: " + editScope}}
if m.runStepIndex > 0 && m.runStepIndex <= len(r.Steps) {
step := r.Steps[m.runStepIndex-1]
summary = []string{"Status: " + m.progress(m.stepProgressStatus(step)), "Route: " + outcomeLabel(step.Outcome, step.Outcome) + " → " + step.Target, "Started: " + dateLabel(step.StartedAt), "Finished: " + dateLabel(step.FinishedAt), "Duration: " + runDuration(step.StartedAt, step.FinishedAt)}
+14 -52
View File
@@ -9,7 +9,6 @@ import (
"git.a-wan.net/alan/pipelines/internal/protocol"
"github.com/charmbracelet/bubbles/textarea"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/x/ansi"
)
type runTick struct{}
@@ -65,7 +64,7 @@ func (m Model) beginRun() (tea.Model, tea.Cmd) {
m.runInput = newInput()
m.runPrompt = textarea.New()
m.runPrompt.CharLimit = 32000
m.runPrompt.Placeholder = "Describe the task. Enter adds a line; Ctrl+S continues."
m.runPrompt.Placeholder = "Describe the task. Enter adds a line; Ctrl+S runs it."
m.runPrompt.SetWidth(max(1, min(96, m.width-12)))
m.runPrompt.SetHeight(max(1, min(10, m.height-14)))
m.runPrompt.ShowLineNumbers = false
@@ -79,10 +78,8 @@ func (m Model) updateRunForm(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
return m, nil
}
m.runTask = m.runPrompt.Value()
m.runForm = 2
m.runInput = newInput()
m.runInput.Placeholder = "Exact Go edit paths, comma-separated; blank = no edits"
return m, m.runInput.Focus()
cmd := m.startSelectedRun()
return m, cmd
}
var cmd tea.Cmd
m.runPrompt, cmd = m.runPrompt.Update(msg)
@@ -92,26 +89,6 @@ func (m Model) updateRunForm(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
case "esc":
m.runForm = 0
return m, nil
case "enter":
switch m.runForm {
case 2:
m.runPaths = nil
for _, path := range strings.Split(m.runInput.Value(), ",") {
if path = strings.TrimSpace(path); path != "" {
m.runPaths = append(m.runPaths, path)
}
}
m.runForm = 3
m.runInput.SetValue("")
m.runInput.Placeholder = "Type RUN to confirm"
case 3:
if m.runInput.Value() != "RUN" {
return m, nil
}
cmd := m.startSelectedRun()
return m, cmd
}
return m, nil
}
var cmd tea.Cmd
m.runInput, cmd = m.runInput.Update(msg)
@@ -127,25 +104,24 @@ func (m *Model) startSelectedRun() tea.Cmd {
m.runCollapsed = nil
m.runDetail = nil
m.runTop = 0
approval := m.runToolApproval()
if m.cliRun && m.cliOptions.Yes {
approval = m.cliOptions.AllowTools
}
updated, cmd := m.runRequest(protocol.Message{Type: protocol.RunPipeline, PipelineID: m.detail.ID, Version: m.detail.Version, RequestKey: fmt.Sprintf("tui-%d", time.Now().UnixNano()), Input: initialRunInput(m.runTask), AllowTools: approval, WritePaths: m.runPaths, Workspace: m.runWorkspace})
updated, cmd := m.runRequest(protocol.Message{Type: protocol.RunPipeline, PipelineID: m.detail.ID, Version: m.detail.Version, RequestKey: fmt.Sprintf("tui-%d", time.Now().UnixNano()), Input: initialRunInput(m.runTask), AllowTools: m.runHasMutationTools(), WritePaths: m.runPaths, Workspace: m.runWorkspace})
*m = updated.(Model)
return cmd
}
func initialRunInput(prompt string) map[string]any { return map[string]any{"prompt": prompt} }
func (m Model) runToolApproval() bool {
func (m Model) runHasMutationTools() bool {
if len(m.runPaths) > 0 {
return true
}
if m.detail != nil {
for _, s := range m.detail.Graph.Stages {
if _, explicit := s.Blocks["tools"]; !explicit && s.Type != "ntfy" {
return true
}
for _, tool := range strings.Fields(s.Blocks["tools"]) {
if tool == "shell" {
if tool == "shell" || tool == "edit" {
return true
}
}
@@ -155,19 +131,9 @@ func (m Model) runToolApproval() bool {
}
func (m Model) runFormView(height int) string {
title := []string{"", "Run: task", "Run: edit scope", "Confirm execution"}[m.runForm]
input := m.runInput
input.Width = max(1, min(90, m.width-12))
lines := []string{title, input.View(), "Esc cancels"}
if m.runForm == 1 {
lines = []string{title, "Repository: " + m.runWorkspace, "Enter newline · Ctrl+S continue · Esc cancel"}
lines = append(lines, strings.Split(m.runPrompt.View(), "\n")...)
return popup(m.width, height, 104, lines)
}
if m.runForm == 3 {
lines[2] = "Type RUN and press Enter to start · Esc cancels"
lines = append(lines, "Repository: "+m.runWorkspace, "Prompt: "+ansi.Truncate(strings.ReplaceAll(m.runTask, "\n", " ↵ "), max(1, m.width-12), "…"))
lines = append(lines, fmt.Sprintf("%s v%d · 30 steps / 5 visits / 30 minutes", m.detail.Name, m.detail.Version))
lines := []string{"Run: task", "Repository: " + m.runWorkspace, "Enter newline · Ctrl+S run · Esc cancel"}
lines = append(lines, strings.Split(m.runPrompt.View(), "\n")...)
if m.detail != nil {
for _, s := range m.detail.Graph.Stages {
if s.Type == "ntfy" {
lines = append(lines, s.Key+" action: publish Markdown to ntfy destination "+s.Configs["destination"])
@@ -178,15 +144,11 @@ func (m Model) runFormView(height int) string {
if label == "" {
label = "none"
}
if !explicit && len(m.runPaths) > 0 {
label = "legacy project read/edit and Go checks"
if !explicit {
label = "project read/edit and shell"
}
lines = append(lines, s.Key+" tools: "+label)
}
if m.runToolApproval() {
lines = append(lines, "RUN approves scoped shell/edit access where declared.", "Go checks execute project code with your user privileges.")
}
lines = append(lines, "Changes are not rolled back on cancellation.", "Edit paths: "+strings.Join(m.runPaths, ", "))
}
return popup(m.width, height, 100, lines)
}
+3 -10
View File
@@ -22,18 +22,11 @@ func TestRunFormAndInspection(t *testing.T) {
m.runPrompt.SetValue("align arrows")
updated, _ = m.updateRunForm(tea.KeyMsg{Type: tea.KeyCtrlS})
m = updated.(Model)
m.runInput.SetValue("internal/tui/panels.go")
updated, _ = m.updateRunForm(tea.KeyMsg{Type: tea.KeyEnter})
m = updated.(Model)
if m.runForm != 3 || !strings.Contains(m.runFormView(20), "not rolled back") {
t.Fatal("missing explicit execution confirmation")
if m.runForm != 0 || !m.runOpen {
t.Fatal("task submission should run without a file list or confirmation")
}
m.runInput.SetValue("no")
updated, _ = m.updateRunForm(tea.KeyMsg{Type: tea.KeyEnter})
updated, _ = m.beginRun()
m = updated.(Model)
if m.runForm != 3 {
t.Fatal("unconfirmed run started")
}
updated, _ = m.updateRunForm(tea.KeyMsg{Type: tea.KeyEsc})
m = updated.(Model)
if m.runForm != 0 {
+7 -7
View File
@@ -33,12 +33,12 @@ func TestStageToolsVisible(t *testing.T) {
}
}
func TestRunConfirmationShowsStageScopedTools(t *testing.T) {
func TestRunComposerShowsStageScopedTools(t *testing.T) {
m := panelModel(t)
m.runForm = 3
m.runForm = 1
m.runInput = newInput()
m.detail.Graph.Stages[0].Blocks["tools"] = "websearch\nwebfetch"
if m.runToolApproval() {
if m.runHasMutationTools() {
t.Fatal("web stage requires mutation approval")
}
view := m.runFormView(40)
@@ -46,12 +46,12 @@ func TestRunConfirmationShowsStageScopedTools(t *testing.T) {
t.Fatal("incorrect web confirmation", view)
}
m.detail.Graph.Stages[0].Blocks["tools"] = "shell"
if !m.runToolApproval() {
if !m.runHasMutationTools() {
t.Fatal("shell cannot be approved without edits")
}
view = m.runFormView(40)
if !strings.Contains(view, "RUN approves scoped shell/edit") {
t.Fatal("shell approval is not explicit", view)
if !strings.Contains(view, "shell") || strings.Contains(view, "RUN approves") {
t.Fatal("composer should show tools, not demand approval", view)
}
}
@@ -67,7 +67,7 @@ func TestNativeNtfyStagePresentation(t *testing.T) {
if strings.Contains(header, "PROMPT") || !strings.Contains(view, "ntfy") || !strings.Contains(view, "anime") {
t.Fatal("native stage displayed as model", view)
}
m.runForm = 3
m.runForm = 1
m.runInput = newInput()
view = m.runFormView(40)
if !strings.Contains(view, "publish Markdown to ntfy destination anime") {