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/hexaiaction | |
| 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/hexaiaction')
| -rw-r--r-- | internal/hexaiaction/run.go | 11 | ||||
| -rw-r--r-- | internal/hexaiaction/tui.go | 3 | ||||
| -rw-r--r-- | internal/hexaiaction/types.go | 1 |
3 files changed, 14 insertions, 1 deletions
diff --git a/internal/hexaiaction/run.go b/internal/hexaiaction/run.go index 5417d3f..1325e9d 100644 --- a/internal/hexaiaction/run.go +++ b/internal/hexaiaction/run.go @@ -8,6 +8,7 @@ import ( "strings" "codeberg.org/snonux/hexai/internal/appconfig" + "codeberg.org/snonux/hexai/internal/editor" "codeberg.org/snonux/hexai/internal/logging" "codeberg.org/snonux/hexai/internal/llmutils" ) @@ -74,6 +75,16 @@ func executeAction(ctx context.Context, kind ActionKind, parts InputParts, cfg a cctx, cancel := timeout10s(ctx) defer cancel() return runSimplify(cctx, cfg, client, parts.Selection) + case ActionCustom: + cctx, cancel := timeout10s(ctx) + defer cancel() + // Open editor for free-form instruction + prompt, err := editor.OpenTempAndEdit([]byte("# Enter your instruction below\n\n")) + if err != nil || strings.TrimSpace(prompt) == "" { + fmt.Fprintln(stderr, logging.AnsiBase+"hexai-tmux-action: custom prompt canceled or empty; echoing input"+logging.AnsiReset) + return parts.Selection, nil + } + return runRewrite(cctx, cfg, client, prompt, parts.Selection) default: return parts.Selection, nil } diff --git a/internal/hexaiaction/tui.go b/internal/hexaiaction/tui.go index 80b1fee..317a991 100644 --- a/internal/hexaiaction/tui.go +++ b/internal/hexaiaction/tui.go @@ -31,6 +31,7 @@ func newModel() model { item{title: "Simplify and improve", desc: "", kind: ActionSimplify, hotkey: 'i'}, item{title: "Document code", desc: "", kind: ActionDocument, hotkey: 'c'}, item{title: "Generate Go unit test(s)", desc: "", kind: ActionGoTest, hotkey: 't'}, + item{title: "Custom prompt", desc: "", kind: ActionCustom, hotkey: 'p'}, item{title: "Skip", desc: "", kind: ActionSkip, hotkey: 's'}, } l := list.New(items, oneLineDelegate{}, 0, 0) @@ -78,7 +79,7 @@ func handleKey(m model, msg tea.KeyMsg) (tea.Model, tea.Cmd) { m.list.Select(0) case "end": if n := len(m.list.Items()); n > 0 { m.list.Select(n - 1) } - case "s", "r", "c", "t", "i": + case "s", "r", "c", "t", "i", "p": items := m.list.Items() for i := 0; i < len(items); i++ { if it, ok := items[i].(item); ok && strings.ToLower(string(it.hotkey)) == low { diff --git a/internal/hexaiaction/types.go b/internal/hexaiaction/types.go index 708c433..7bc292e 100644 --- a/internal/hexaiaction/types.go +++ b/internal/hexaiaction/types.go @@ -11,6 +11,7 @@ const ( ActionDocument ActionKind = "document" ActionGoTest ActionKind = "gotest" ActionSimplify ActionKind = "simplify" + ActionCustom ActionKind = "custom" ) // InputParts represents parsed stdin input for actions. |
