summaryrefslogtreecommitdiff
path: root/internal/hexaicli
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-09-07 17:54:42 +0300
committerPaul Buetow <paul@buetow.org>2025-09-07 17:54:42 +0300
commit77e41a1018715fa5ac4e6156354710b3b224b4fc (patch)
tree23d847008c34a4c8b1329151fd33ac107fdefe76 /internal/hexaicli
parenta240e1e106d3b8028bbb3667b44cf3085875e405 (diff)
feat: add Custom prompt action (p) with editor integration; shared editor helper in internal/editor; hexai CLI opens editor when no args
Diffstat (limited to 'internal/hexaicli')
-rw-r--r--internal/hexaicli/run.go19
1 files changed, 14 insertions, 5 deletions
diff --git a/internal/hexaicli/run.go b/internal/hexaicli/run.go
index f10850b..98e4c40 100644
--- a/internal/hexaicli/run.go
+++ b/internal/hexaicli/run.go
@@ -13,6 +13,7 @@ import (
"time"
"codeberg.org/snonux/hexai/internal/appconfig"
+ "codeberg.org/snonux/hexai/internal/editor"
"codeberg.org/snonux/hexai/internal/logging"
"codeberg.org/snonux/hexai/internal/llm"
"codeberg.org/snonux/hexai/internal/llmutils"
@@ -21,16 +22,24 @@ import (
// Run executes the Hexai CLI behavior given arguments and I/O streams.
// It assumes flags have already been parsed by the caller.
func Run(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) error {
- // Load configuration with a logger so file-based config is respected.
- logger := log.New(stderr, "hexai ", log.LstdFlags|log.Lmsgprefix)
- cfg := appconfig.Load(logger)
+ // Load configuration with a logger so file-based config is respected.
+ logger := log.New(stderr, "hexai ", log.LstdFlags|log.Lmsgprefix)
+ cfg := appconfig.Load(logger)
client, err := llmutils.NewClientFromApp(cfg)
if err != nil {
fmt.Fprintf(stderr, logging.AnsiBase+"hexai: LLM disabled: %v"+logging.AnsiReset+"\n", err)
return err
}
- // Inline the flow here to use configured CLI prompts.
- input, rerr := readInput(stdin, args)
+ // No args: open editor to capture a prompt, then combine with stdin as usual.
+ if len(args) == 0 {
+ if prompt, eerr := editor.OpenTempAndEdit([]byte("# Enter your prompt below\n\n")); eerr == nil && strings.TrimSpace(prompt) != "" {
+ args = []string{prompt}
+ } else {
+ // If editor fails or empty, continue; readInput will likely error if no stdin either.
+ }
+ }
+ // Inline the flow here to use configured CLI prompts.
+ input, rerr := readInput(stdin, args)
if rerr != nil {
fmt.Fprintln(stderr, logging.AnsiBase+rerr.Error()+logging.AnsiReset)
return rerr