summaryrefslogtreecommitdiff
path: root/internal/hexaiaction
diff options
context:
space:
mode:
Diffstat (limited to 'internal/hexaiaction')
-rw-r--r--internal/hexaiaction/run.go9
-rw-r--r--internal/hexaiaction/run_more_test.go17
2 files changed, 21 insertions, 5 deletions
diff --git a/internal/hexaiaction/run.go b/internal/hexaiaction/run.go
index f34a4cd..2a3ade1 100644
--- a/internal/hexaiaction/run.go
+++ b/internal/hexaiaction/run.go
@@ -38,7 +38,7 @@ func logTmuxActionError(stderr io.Writer, err error) error {
// requireInput validates that input selection is not empty.
func requireInput(sel string) error {
if strings.TrimSpace(sel) == "" {
- return fmt.Errorf("no input provided on stdin")
+ return fmt.Errorf("no input provided on stdin; pipe the selected text or pane contents into hexai-tmux-action")
}
return nil
}
@@ -193,11 +193,10 @@ func (r *Runner) Run(ctx context.Context, stdin io.Reader, stdout, stderr io.Wri
var client chatDoer = cli
parts, err := ParseInput(stdin)
if err != nil {
- _, _ = fmt.Fprintln(stderr, logging.AnsiBase+"hexai-tmux-action: failed to read input"+logging.AnsiReset)
- return err
+ return fmt.Errorf("hexai-tmux-action: failed to read action input from stdin (pipe the selected text or pane contents into hexai-tmux-action): %w", err)
}
- if strings.TrimSpace(parts.Selection) == "" {
- return fmt.Errorf("hexai-tmux-action: no input provided on stdin")
+ if err := requireInput(parts.Selection); err != nil {
+ return fmt.Errorf("hexai-tmux-action: %w", err)
}
choice, err := chooser(cfg)
if err != nil {
diff --git a/internal/hexaiaction/run_more_test.go b/internal/hexaiaction/run_more_test.go
index 6a4959e..67ffa96 100644
--- a/internal/hexaiaction/run_more_test.go
+++ b/internal/hexaiaction/run_more_test.go
@@ -3,6 +3,7 @@ package hexaiaction
import (
"bytes"
"context"
+ "log"
"os"
"strings"
"testing"
@@ -28,6 +29,22 @@ func TestRun_MissingAPIKey(t *testing.T) {
_ = os.Stderr
}
+func TestRun_NoInput_IsActionable(t *testing.T) {
+ runner := NewRunner()
+ runner.loadConfig = func(context.Context, *log.Logger) appconfig.App { return appconfig.Load(nil) }
+ runner.newClient = func(appconfig.App) (actionClient, error) { return llmFake{}, nil }
+ runner.chooseAction = func(appconfig.App) (actionChoice, error) {
+ return actionChoice{kind: ActionSkip}, nil
+ }
+ err := runner.Run(context.Background(), bytes.NewBufferString(""), &bytes.Buffer{}, &bytes.Buffer{})
+ if err == nil {
+ t.Fatal("expected actionable no-input error")
+ }
+ if !strings.Contains(err.Error(), "pipe the selected text or pane contents into hexai-tmux-action") {
+ t.Fatalf("expected actionable guidance, got %q", err.Error())
+ }
+}
+
type stubChatDoer struct {
calls int
msgs [][]llm.Message