Offer nvim or OpenCode when creating a pipeline

This commit is contained in:
2026-10-09 20:53:00 +01:00
parent a50e8648f6
commit dd50344170
10 changed files with 102 additions and 16 deletions
+4 -1
View File
@@ -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 <run-id>`) 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]`.
+11
View File
@@ -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 <draft.md> --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.
+6
View File
@@ -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).
+8 -2
View File
@@ -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)
+22 -1
View File
@@ -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.")
+41
View File
@@ -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)
+1 -1
View File
@@ -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")
+2 -8
View File
@@ -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") {
+1 -1
View File
@@ -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))))
+6 -2
View File
@@ -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 {