diff options
| author | Paul Buetow <paul@buetow.org> | 2025-09-07 14:29:35 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-09-07 14:29:35 +0300 |
| commit | 23482b5d8da5c67da1fc501ddbafdd123be3972c (patch) | |
| tree | 452dc7c418055ebb79a88a303e50d2dbc1877f09 /internal/hexaiaction/cmdentry.go | |
| parent | 76f388f9759cdc15cb1eba985cd87cde1906208b (diff) | |
feat: rename hexai-action -> hexai-tmux-action; remove --tmux/--no-tmux; tmux-only flow; update docs and Magefile
Diffstat (limited to 'internal/hexaiaction/cmdentry.go')
| -rw-r--r-- | internal/hexaiaction/cmdentry.go | 41 |
1 files changed, 11 insertions, 30 deletions
diff --git a/internal/hexaiaction/cmdentry.go b/internal/hexaiaction/cmdentry.go index 1947390..cf72495 100644 --- a/internal/hexaiaction/cmdentry.go +++ b/internal/hexaiaction/cmdentry.go @@ -12,52 +12,32 @@ import ( "golang.org/x/term" ) -// Options configures the command-line orchestration for hexai-action. +// Options configures the command-line orchestration for hexai-tmux-action. type Options struct { Infile string Outfile string - ForceTmux bool - NoTmux bool UIChild bool TmuxTarget string TmuxSplit string // "v" or "h" TmuxPercent int // 1-100 } -// RunCommand is the CLI orchestrator used by cmd/hexai-action. It decides whether -// to run inline, in a tmux split pane, or in child mode; then delegates to Run. +// RunCommand is the CLI orchestrator used by cmd/hexai-tmux-action. It runs in tmux +// split-pane mode by default, or child mode when -ui-child is set. func RunCommand(ctx context.Context, opts Options, stdin io.Reader, stdout, stderr io.Writer) error { if opts.UIChild { return runChild(ctx, opts.Infile, opts.Outfile, stdout, stderr) } - if shouldRunInTmux(opts.ForceTmux, opts.NoTmux) { - return runInTmuxParent(stdin, stdout, opts.TmuxTarget, opts.TmuxSplit, opts.TmuxPercent) - } - // Inline path: only if we have a TTY for UI; otherwise echo input - if isTTYFn(os.Stdout.Fd()) && isTTYFn(os.Stdin.Fd()) { - in, out, closeIn, closeOut, err := openIO(opts.Infile, opts.Outfile) - if err != nil { return err } - defer closeIn(); defer closeOut() - return Run(ctx, in, out, stderr) - } - // Fallback: echo - return echoThrough(opts.Infile, opts.Outfile, stdin, stdout) + // Always use tmux path + return runInTmuxParent(stdin, stdout, opts.TmuxTarget, opts.TmuxSplit, opts.TmuxPercent) } // seams for unit tests var isTTYFn = func(fd uintptr) bool { return term.IsTerminal(int(fd)) } -var tmuxAvailableFn = tmux.Available var splitRunFn = tmux.SplitRun var osExecutableFn = os.Executable var runFn = Run -func shouldRunInTmux(forceTmux, noTmux bool) bool { - if noTmux { return false } - if forceTmux { return true } - if !(isTTYFn(os.Stdin.Fd()) && isTTYFn(os.Stdout.Fd())) && tmuxAvailableFn() { return true } - return false -} - // openIO returns readers/writers for infile/outfile flags with deferred closers. func openIO(infile, outfile string) (io.Reader, io.Writer, func(), func(), error) { in := io.Reader(os.Stdin) @@ -66,13 +46,13 @@ func openIO(infile, outfile string) (io.Reader, io.Writer, func(), func(), error closeOut := func() {} if path := infile; path != "" { f, err := os.Open(path) - if err != nil { return nil, nil, func(){}, func(){}, fmt.Errorf("hexai-action: cannot open infile: %w", err) } + if err != nil { return nil, nil, func(){}, func(){}, fmt.Errorf("hexai-tmux-action: cannot open infile: %w", err) } in = f closeIn = func() { _ = f.Close() } } if path := outfile; path != "" { f, err := os.Create(path) - if err != nil { return nil, nil, func(){}, func(){}, fmt.Errorf("hexai-action: cannot open outfile: %w", err) } + if err != nil { return nil, nil, func(){}, func(){}, fmt.Errorf("hexai-tmux-action: cannot open outfile: %w", err) } out = f closeOut = func() { _ = f.Close() } } @@ -99,7 +79,7 @@ func runChild(ctx context.Context, infile, outfile string, stdout, stderr io.Wri if err := runFn(ctx, in, out, stderr); err != nil { closeOut() if copyErr := echoThrough(infile, tmp, os.Stdin, stdout); copyErr != nil { - return fmt.Errorf("hexai-action child: %v; echo failed: %v", err, copyErr) + return fmt.Errorf("hexai-tmux-action child: %v; echo failed: %v", err, copyErr) } } else { closeOut() @@ -108,7 +88,7 @@ func runChild(ctx context.Context, infile, outfile string, stdout, stderr io.Wri } func runInTmuxParent(stdin io.Reader, stdout io.Writer, target, split string, percent int) error { - dir, err := os.MkdirTemp("", "hexai-action-") + dir, err := os.MkdirTemp("", "hexai-tmux-action-") if err != nil { return err } defer func() { _ = os.RemoveAll(dir) }() inPath := filepath.Join(dir, "input.txt") @@ -135,7 +115,7 @@ func waitForFile(path string, timeout time.Duration) error { deadline := time.Now().Add(timeout) for { if _, err := os.Stat(path); err == nil { return nil } - if time.Now().After(deadline) { return fmt.Errorf("hexai-action: timeout waiting for reply file") } + if time.Now().After(deadline) { return fmt.Errorf("hexai-tmux-action: timeout waiting for reply file") } time.Sleep(200 * time.Millisecond) } } @@ -148,6 +128,7 @@ func catFileTo(w io.Writer, path string) error { return err } +// echoThrough no longer used in tmux-only flow, but kept for potential reuse. func echoThrough(infile, outfile string, stdin io.Reader, stdout io.Writer) error { var in io.Reader = stdin var out io.Writer = stdout |
