summaryrefslogtreecommitdiff
path: root/cmd/hexai-tmux-edit
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/hexai-tmux-edit')
-rw-r--r--cmd/hexai-tmux-edit/main.go63
-rw-r--r--cmd/hexai-tmux-edit/main_test.go111
2 files changed, 0 insertions, 174 deletions
diff --git a/cmd/hexai-tmux-edit/main.go b/cmd/hexai-tmux-edit/main.go
deleted file mode 100644
index d61f68a..0000000
--- a/cmd/hexai-tmux-edit/main.go
+++ /dev/null
@@ -1,63 +0,0 @@
-// hexai-tmux-edit opens a tmux popup with $EDITOR for composing AI agent
-// prompts. It captures existing prompt text from the target pane, pre-fills
-// the editor, and sends the edited text back via tmux send-keys.
-//
-// Usage:
-//
-// hexai-tmux-edit [--config <path>] [--agent <name>] [--pane <id>]
-//
-// Tmux keybinding (add to ~/.tmux.conf):
-//
-// bind e run-shell -b "cd '#{pane_current_path}' && hexai-tmux-edit --pane '#{pane_id}'"
-package main
-
-import (
- "flag"
- "fmt"
- "io"
- "os"
- "strings"
-
- "codeberg.org/snonux/hexai/internal/appconfig"
- "codeberg.org/snonux/hexai/internal/tmuxedit"
-)
-
-type app struct {
- runTmuxEdit func(tmuxedit.Options) error
-}
-
-func newApp() *app { return &app{runTmuxEdit: tmuxedit.Run} }
-
-func main() { os.Exit(newApp().runMain(os.Args[1:], os.Stderr)) }
-
-// runMain parses flags from args and runs the tmux edit popup. It returns
-// the process exit code; flag errors return 2 (matching stdlib convention),
-// runtime failures return 1.
-func (a *app) runMain(args []string, stderr io.Writer) int {
- defaultPath := appconfig.DefaultConfigPath()
- fs := flag.NewFlagSet("hexai-tmux-edit", flag.ContinueOnError)
- fs.SetOutput(stderr)
- configPath := fs.String("config", "", fmt.Sprintf("path to config file (default: %s)", defaultPath))
- agent := fs.String("agent", "", "AI agent name (auto-detected if omitted)")
- pane := fs.String("pane", "", "tmux target pane ID (e.g. %5)")
- if err := fs.Parse(args); err != nil {
- return 2
- }
-
- opts := buildOptions(*configPath, *agent, *pane)
- if err := a.runTmuxEdit(opts); err != nil {
- fmt.Fprintln(stderr, err)
- return 1
- }
- return 0
-}
-
-// buildOptions constructs tmuxedit.Options from the parsed flag values,
-// trimming whitespace from each field.
-func buildOptions(configPath, agent, pane string) tmuxedit.Options {
- return tmuxedit.Options{
- ConfigPath: strings.TrimSpace(configPath),
- Agent: strings.TrimSpace(agent),
- Pane: strings.TrimSpace(pane),
- }
-}
diff --git a/cmd/hexai-tmux-edit/main_test.go b/cmd/hexai-tmux-edit/main_test.go
deleted file mode 100644
index 3171b86..0000000
--- a/cmd/hexai-tmux-edit/main_test.go
+++ /dev/null
@@ -1,111 +0,0 @@
-package main
-
-import (
- "bytes"
- "errors"
- "strings"
- "testing"
-
- "codeberg.org/snonux/hexai/internal/tmuxedit"
-)
-
-func TestBuildOptions_AllEmpty(t *testing.T) {
- opts := buildOptions("", "", "")
- if opts.ConfigPath != "" || opts.Agent != "" || opts.Pane != "" {
- t.Fatalf("expected all empty, got %+v", opts)
- }
-}
-
-func TestBuildOptions_TrimsWhitespace(t *testing.T) {
- opts := buildOptions(" /tmp/cfg.toml ", " claude ", " %5 ")
- if opts.ConfigPath != "/tmp/cfg.toml" {
- t.Fatalf("expected trimmed config path, got %q", opts.ConfigPath)
- }
- if opts.Agent != "claude" {
- t.Fatalf("expected trimmed agent, got %q", opts.Agent)
- }
- if opts.Pane != "%5" {
- t.Fatalf("expected trimmed pane, got %q", opts.Pane)
- }
-}
-
-func TestRunTmuxEdit_Success(t *testing.T) {
- var gotOpts tmuxedit.Options
- a := &app{runTmuxEdit: func(opts tmuxedit.Options) error {
- gotOpts = opts
- return nil
- }}
-
- opts := buildOptions("/tmp/cfg.toml", "cursor", "%3")
- if err := a.runTmuxEdit(opts); err != nil {
- t.Fatalf("runTmuxEdit: %v", err)
- }
- if gotOpts.ConfigPath != "/tmp/cfg.toml" || gotOpts.Agent != "cursor" || gotOpts.Pane != "%3" {
- t.Fatalf("unexpected opts: %+v", gotOpts)
- }
-}
-
-func TestRunTmuxEdit_Error(t *testing.T) {
- wantErr := errors.New("tmux not found")
- a := &app{runTmuxEdit: func(_ tmuxedit.Options) error { return wantErr }}
-
- if err := a.runTmuxEdit(tmuxedit.Options{}); !errors.Is(err, wantErr) {
- t.Fatalf("expected error, got: %v", err)
- }
-}
-
-// runMain happy path: flags parse, runTmuxEdit returns nil, exit code 0.
-// We capture the resolved Options to confirm flags map onto fields correctly.
-func TestRunMain_FlagsForwardedToTmuxedit(t *testing.T) {
- var got tmuxedit.Options
- a := &app{runTmuxEdit: func(opts tmuxedit.Options) error {
- got = opts
- return nil
- }}
-
- var stderr bytes.Buffer
- code := a.runMain([]string{"-config", " /tmp/cfg.toml ", "-agent", "claude", "-pane", "%9"}, &stderr)
- if code != 0 {
- t.Fatalf("runMain code = %d, want 0", code)
- }
- if got.ConfigPath != "/tmp/cfg.toml" || got.Agent != "claude" || got.Pane != "%9" {
- t.Fatalf("unexpected opts: %+v", got)
- }
- if stderr.Len() != 0 {
- t.Fatalf("stderr should be empty on success, got %q", stderr.String())
- }
-}
-
-// runMain reports tmuxedit.Run failures by writing to stderr and returning 1
-// — the production exit code that the shipped binary uses.
-func TestRunMain_RunErrorReturnsOne(t *testing.T) {
- a := &app{runTmuxEdit: func(tmuxedit.Options) error { return errors.New("boom") }}
-
- var stderr bytes.Buffer
- code := a.runMain(nil, &stderr)
- if code != 1 {
- t.Fatalf("runMain code = %d, want 1", code)
- }
- if !strings.Contains(stderr.String(), "boom") {
- t.Fatalf("stderr missing error: %q", stderr.String())
- }
-}
-
-// Unknown flags must yield exit 2 (the convention used by stdlib `flag` when
-// ExitOnError aborts) without ever invoking runTmuxEdit.
-func TestRunMain_BadFlagReturnsTwo(t *testing.T) {
- called := false
- a := &app{runTmuxEdit: func(tmuxedit.Options) error {
- called = true
- return nil
- }}
-
- var stderr bytes.Buffer
- code := a.runMain([]string{"--no-such-flag"}, &stderr)
- if code != 2 {
- t.Fatalf("runMain code = %d, want 2", code)
- }
- if called {
- t.Fatal("runTmuxEdit must not be called on flag-parse failure")
- }
-}