diff options
| author | Paul Buetow <paul@buetow.org> | 2025-09-07 17:54:42 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-09-07 17:54:42 +0300 |
| commit | 77e41a1018715fa5ac4e6156354710b3b224b4fc (patch) | |
| tree | 23d847008c34a4c8b1329151fd33ac107fdefe76 /internal/hexaicli | |
| parent | a240e1e106d3b8028bbb3667b44cf3085875e405 (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.go | 19 |
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 |
