diff --git a/README.md b/README.md index 23b1d224..3fc2cd29 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ pipelines ping pipelines help edit ``` -`new`/`edit` open OpenCode directly with `@pipelines`. The installed skill asks +CLI `new`/`edit` open OpenCode directly with `@pipelines`. The installed skill asks missing questions; `pipelines new` needs no preliminary questionnaire. Changes stay as drafts by default; CLI and TUI share validation and draft storage. Most commands support `--json` for agents and scripts. @@ -128,6 +128,9 @@ Initial run input also records `pwd`. Press **r** / **:retry** on a failed run (or `pipelines retry `) to start a new attempt with the same original input, directory, and pipeline version. Completed side effects are not undone. On Home, **r** opens all recent runs; both Home panels show the shortcut. +**n / :new** and creating from a template offer a Tab-navigable, fuzzy-searchable +picker: **nvim** opens the draft Markdown file; **OpenCode** authors it with you. +Canceling the picker creates no draft and publishes nothing. Wide terminals show runs and pipelines side by side; narrow terminals stack them. The dashboard includes all-history usage, success rate, average completed duration, per-pipeline usage, and a 14-day activity chart. CLI: `pipelines stats [--json]`. diff --git a/docs/cli.md b/docs/cli.md index 8ac73c8d..f518ee46 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -64,6 +64,17 @@ Every submission, including agent-issued `submit`/`rpc`, still uses server valid ## Drafts in the TUI +Home's `n` / `:new` and Enter on a template first ask how to author the new +pipeline: **nvim** opens a retained Markdown draft file, or **OpenCode** opens +the collaborative harness with `@pipelines`. Tab/Shift+Tab or arrows select; +typing fuzzy-searches the choices; Enter launches and Esc cancels without +creating a draft. The choice overrides `VISUAL`/`EDITOR`. New drafts preserve +the create-only publication guard and still require explicit submission unless +you already published them from OpenCode. OpenCode can ask for a missing name; +for an unnamed nvim draft, `pipelines submit --name NAME` names and +publishes it. CLI `pipelines new` retains its existing direct-OpenCode behavior; +`--no-open` creates the file without launching an editor. + Press `d` on the dashboard or use `:drafts` to browse the same retained drafts as `pipelines drafts`. Use `n/p` to select, `j/k` to scroll source, `e`/Enter to reopen the existing draft, `v` for server validation, and `s` for submission confirmation. diff --git a/docs/installation-verification.md b/docs/installation-verification.md index 59bf695b..3a886d5d 100644 --- a/docs/installation-verification.md +++ b/docs/installation-verification.md @@ -104,3 +104,9 @@ saves changes and still requires confirmation. A real local V2 no-inference create/wait/delete contract succeeded; the reported remote planner `/wait` failure could not be reproduced here. Safe CLI failure classification/exit-code reporting was executed with a failing subprocess fixture. + +New-pipeline picker checks cover both editor choices, fuzzy/Tab navigation, +cancel-without-creating, retained source/server/create-only metadata and template +source preservation. Compiled CLI/TUI PTY integration launches a new nvim draft +(confirmation required), then a new mock OpenCode author that names and publishes +through the real CLI (reloaded automatically, no extra submit prompt). diff --git a/internal/tui/create_test.go b/internal/tui/create_test.go index 58dd2315..8b14a3df 100644 --- a/internal/tui/create_test.go +++ b/internal/tui/create_test.go @@ -40,8 +40,14 @@ func TestCreateAndSubmit(t *testing.T) { var editor tea.Cmd updated, editor = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'n'}}) m = updated.(Model) - if editor == nil { - t.Fatal("n should launch authoring directly, without a questionnaire") + if editor == nil || !m.editorOpen || !m.editorDraft.createOnly { + t.Fatal("n should offer an editor for a new create-only draft") + } + m.editorInput.SetValue("ocd") + updated, editor = m.Update(tea.KeyMsg{Type: tea.KeyEnter}) + m = updated.(Model) + if editor == nil || m.editorOpen { + t.Fatal("new editor choice did not launch") } // Editor lifecycle is smoke-tested separately; feed its completion here. source := pipeline.Template([]string{"a", "b"}, true) diff --git a/internal/tui/editor_picker.go b/internal/tui/editor_picker.go index 007de9b3..064680a5 100644 --- a/internal/tui/editor_picker.go +++ b/internal/tui/editor_picker.go @@ -8,6 +8,19 @@ import ( "github.com/sahilm/fuzzy" ) +func (m Model) openAuthorPicker(edit editedMsg) (tea.Model, tea.Cmd) { + m.editorOpen = true + m.editorIndex = 0 + m.editorInput = newInput() + m.editorInput.Placeholder = "Search nvim or OpenCode…" + m.editorDraft = &edit + return m, m.editorInput.Focus() +} + +func (m Model) newPipeline(source string) (tea.Model, tea.Cmd) { + return m.openAuthorPicker(editedMsg{source: source, createOnly: true}) +} + func (m Model) editorChoices() []string { choices := []string{"nvim", "OpenCode"} if query := strings.TrimSpace(m.editorInput.Value()); query != "" { @@ -45,7 +58,7 @@ func (m Model) updateEditorPicker(msg tea.KeyMsg) (tea.Model, tea.Cmd) { d := m.editorDraft m.editorOpen = false m.editorDraft = nil - return m, editDraftUsing(choice, d.name, d.source, true, false, draft.Draft{Server: m.url, BaseVersion: d.baseVersion}) + return m, editDraftUsing(choice, d.name, d.source, true, d.createOnly, draft.Draft{Path: d.path, Name: d.name, Server: m.url, CreateOnly: d.createOnly, BaseVersion: d.baseVersion}) } var cmd tea.Cmd m.editorInput, cmd = m.editorInput.Update(msg) @@ -57,9 +70,17 @@ func (m Model) editorPickerView(height int) string { input := m.editorInput input.Width = max(1, min(60, m.width-12)) lines := []string{"Edit pipeline with…", input.View(), "Tab/Shift+Tab choose · type to search · Enter open · Esc cancel", ""} + if m.editorDraft != nil && m.editorDraft.createOnly { + lines[0] = "New pipeline with…" + } choices := m.editorChoices() for i, choice := range choices { lines = append(lines, menuOption(choice, i == m.editorIndex)) + if choice == "nvim" { + lines = append(lines, " Write the pipeline Markdown in a retained draft file.") + } else { + lines = append(lines, " Open the OpenCode harness to write it together.") + } } if len(choices) == 0 { lines = append(lines, "No matching editor.") diff --git a/internal/tui/editor_picker_test.go b/internal/tui/editor_picker_test.go index 904205e1..7b91d3b3 100644 --- a/internal/tui/editor_picker_test.go +++ b/internal/tui/editor_picker_test.go @@ -60,6 +60,47 @@ func TestPipelineEditPickerHasTabNavigationFuzzySearchAndRetainedDraft(t *testin } } +func TestNewPickerSupportsBothEditorsWithoutCreatingDraftOnCancel(t *testing.T) { + t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir()) + source := pipeline.Template([]string{"worker"}, true) + for _, choice := range []string{"nv", "ocd"} { + m := New(context.Background(), "ws://example/connect") + m.width = 120 + updated, _ := m.newPipeline(source) + m = updated.(Model) + view := ansi.Strip(m.editorPickerView(30)) + for _, text := range []string{"New pipeline with", "nvim", "OpenCode", "retained draft file", "write it together"} { + if !strings.Contains(view, text) { + t.Fatal("missing new authoring choice", text, view) + } + } + m.editorInput.SetValue(choice) + updated, cmd := m.Update(tea.KeyMsg{Type: tea.KeyEnter}) + m = updated.(Model) + if cmd == nil || m.editorOpen || m.confirmOpen || m.submitID != "" { + t.Fatal("new choice did not launch editor or bypassed publication") + } + } + items, err := draft.List() + if err != nil || len(items) != 2 { + t.Fatal("new choices did not retain drafts", items, err) + } + for _, item := range items { + text, err := draft.Read(item.Path) + if err != nil || text != source || !item.CreateOnly || item.BaseVersion != 0 || item.Server != "ws://example/connect" { + t.Fatal("new draft lost source/create-only/server metadata", item, err) + } + } + m := New(context.Background(), "") + updated, _ := m.newPipeline(source) + m = updated.(Model) + m = press(m, "esc") + after, _ := draft.List() + if m.editorOpen || len(after) != 2 { + t.Fatal("canceling New created a draft") + } +} + func TestDraftCleanupRequiresConfirmationAndPreservesOtherDraft(t *testing.T) { t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir()) a, _ := draft.Create("discard", "discard", "server", true, 0) diff --git a/internal/tui/model.go b/internal/tui/model.go index f3174a08..a289035d 100644 --- a/internal/tui/model.go +++ b/internal/tui/model.go @@ -554,7 +554,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.appendLine("not connected") return m, nil } - return m, editDraftMode("", pipeline.Template([]string{"worker"}, true), true, true, draft.Draft{Server: m.url}) + return m.newPipeline(pipeline.Template([]string{"worker"}, true)) case m.homePage() && key.Matches(msg, m.keys.ping): if m.conn == nil { m.appendLine("not connected") diff --git a/internal/tui/pipeline.go b/internal/tui/pipeline.go index b12dbc90..891e080e 100644 --- a/internal/tui/pipeline.go +++ b/internal/tui/pipeline.go @@ -194,13 +194,7 @@ func (m Model) editPipeline() (tea.Model, tea.Cmd) { m.appendLine("submission already in progress") return m, nil } - m.editorOpen = true - m.editorIndex = 0 - m.editorInput = newInput() - m.editorInput.Placeholder = "Search nvim or OpenCode…" - m.editorInput.Focus() - m.editorDraft = &editedMsg{name: m.detail.Name, source: pipeline.ExecutionSource(m.detail.Source), baseVersion: m.detail.LatestVersion} - return m, m.editorInput.Focus() + return m.openAuthorPicker(editedMsg{name: m.detail.Name, source: pipeline.ExecutionSource(m.detail.Source), baseVersion: m.detail.LatestVersion}) } func (m Model) updatePipeline(msg tea.KeyMsg) (tea.Model, tea.Cmd) { @@ -329,7 +323,7 @@ func (m Model) updateConfirm(msg tea.KeyMsg) (tea.Model, tea.Cmd) { func (m Model) confirmView(height int) string { lines := []string{"Submit edited pipeline", m.pendingDraft.name, "", "Creates a new immutable version.", "s submit · e edit again · Esc keep draft"} if m.pendingDraft.createOnly { - lines[0] = "Create pipeline from template" + lines[0] = "Create pipeline" lines[3] = "Creates a NEW pipeline only when you submit." } if strings.Contains(m.pendingDraft.source, "```schedule") { diff --git a/internal/tui/templates.go b/internal/tui/templates.go index fe6cb15d..825e637f 100644 --- a/internal/tui/templates.go +++ b/internal/tui/templates.go @@ -89,7 +89,7 @@ func (m Model) updateTemplates(msg tea.KeyMsg) (tea.Model, tea.Cmd) { m.templateTop = len(m.templateLines) case "enter": if len(m.templates) > 0 { - return m, editDraftMode("", m.templates[m.templateIndex].Source, true, true, draft.Draft{Server: m.url}) + return m.newPipeline(m.templates[m.templateIndex].Source) } } m.templateTop = max(0, min(m.templateTop, max(0, len(m.templateLines)-max(1, m.height-10)))) diff --git a/internal/tui/templates_test.go b/internal/tui/templates_test.go index 9c6b99b6..ed52670a 100644 --- a/internal/tui/templates_test.go +++ b/internal/tui/templates_test.go @@ -40,8 +40,12 @@ func TestTemplateMarkdownPreviewDraftAndKeyboardScope(t *testing.T) { m = press(m, "v") updated, cmd := m.updateTemplates(tea.KeyMsg{Type: tea.KeyEnter}) m = updated.(Model) - if cmd == nil { - t.Fatal("template should launch authoring directly") + if cmd == nil || !m.editorOpen || !m.editorDraft.createOnly || m.editorDraft.source != m.templates[m.templateIndex].Source { + t.Fatal("template should offer an editor without losing the selected source") + } + m = press(m, "esc") + if m.editorOpen || !m.templateOpen { + t.Fatal("canceling editor picker should return to template gallery") } m = press(m, "esc") if m.templateOpen {