From 4c93677c79983560eea13c372a20ed78f02af4f9 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 7 Sep 2025 14:39:22 +0300 Subject: feat: add 'Simplify and improve' action; configurable prompts in config; wire into LSP and TUI --- internal/hexaiaction/prompts.go | 10 ++++++++-- internal/hexaiaction/run.go | 34 +++++++++++++++++++--------------- internal/hexaiaction/tui.go | 3 ++- internal/hexaiaction/types.go | 11 ++++++----- 4 files changed, 35 insertions(+), 23 deletions(-) (limited to 'internal/hexaiaction') diff --git a/internal/hexaiaction/prompts.go b/internal/hexaiaction/prompts.go index 2e0e4e2..3c33f8a 100644 --- a/internal/hexaiaction/prompts.go +++ b/internal/hexaiaction/prompts.go @@ -43,8 +43,14 @@ func runDiagnostics(ctx context.Context, cfg appconfig.App, client chatDoer, dia } func runDocument(ctx context.Context, cfg appconfig.App, client chatDoer, selection string) (string, error) { - sys := cfg.PromptCodeActionDocumentSystem - user := Render(cfg.PromptCodeActionDocumentUser, map[string]string{"selection": selection}) + sys := cfg.PromptCodeActionDocumentSystem + user := Render(cfg.PromptCodeActionDocumentUser, map[string]string{"selection": selection}) + return runOnceWithOpts(ctx, client, sys, user, reqOptsFrom(cfg)) +} + +func runSimplify(ctx context.Context, cfg appconfig.App, client chatDoer, selection string) (string, error) { + sys := cfg.PromptCodeActionSimplifySystem + user := Render(cfg.PromptCodeActionSimplifyUser, map[string]string{"selection": selection}) return runOnceWithOpts(ctx, client, sys, user, reqOptsFrom(cfg)) } diff --git a/internal/hexaiaction/run.go b/internal/hexaiaction/run.go index a8d4243..5417d3f 100644 --- a/internal/hexaiaction/run.go +++ b/internal/hexaiaction/run.go @@ -46,10 +46,10 @@ func Run(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer) error { } func executeAction(ctx context.Context, kind ActionKind, parts InputParts, cfg appconfig.App, client chatDoer, stderr io.Writer) (string, error) { - switch kind { - case ActionSkip: - return parts.Selection, nil - case ActionRewrite: + switch kind { + case ActionSkip: + return parts.Selection, nil + case ActionRewrite: instr, cleaned := ExtractInstruction(parts.Selection) if strings.TrimSpace(instr) == "" { fmt.Fprintln(stderr, logging.AnsiBase+"hexai-tmux-action: no inline instruction found; echoing input"+logging.AnsiReset) @@ -62,17 +62,21 @@ func executeAction(ctx context.Context, kind ActionKind, parts InputParts, cfg a cctx, cancel := timeout10s(ctx) defer cancel() return runDiagnostics(cctx, cfg, client, parts.Diagnostics, parts.Selection) - case ActionDocument: - cctx, cancel := timeout10s(ctx) - defer cancel() - return runDocument(cctx, cfg, client, parts.Selection) - case ActionGoTest: - cctx, cancel := timeout8s(ctx) - defer cancel() - return runGoTest(cctx, cfg, client, parts.Selection) - default: - return parts.Selection, nil - } + case ActionDocument: + cctx, cancel := timeout10s(ctx) + defer cancel() + return runDocument(cctx, cfg, client, parts.Selection) + case ActionGoTest: + cctx, cancel := timeout8s(ctx) + defer cancel() + return runGoTest(cctx, cfg, client, parts.Selection) + case ActionSimplify: + cctx, cancel := timeout10s(ctx) + defer cancel() + return runSimplify(cctx, cfg, client, parts.Selection) + default: + return parts.Selection, nil + } } // client construction is shared via internal/llmutils diff --git a/internal/hexaiaction/tui.go b/internal/hexaiaction/tui.go index 7275480..80b1fee 100644 --- a/internal/hexaiaction/tui.go +++ b/internal/hexaiaction/tui.go @@ -28,6 +28,7 @@ type model struct { func newModel() model { items := []list.Item{ item{title: "Rewrite selection", desc: "", kind: ActionRewrite, hotkey: 'r'}, + 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: "Skip", desc: "", kind: ActionSkip, hotkey: 's'}, @@ -77,7 +78,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": + case "s", "r", "c", "t", "i": 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 2dc918f..708c433 100644 --- a/internal/hexaiaction/types.go +++ b/internal/hexaiaction/types.go @@ -5,11 +5,12 @@ package hexaiaction type ActionKind string const ( - ActionSkip ActionKind = "skip" - ActionRewrite ActionKind = "rewrite" - ActionDiagnostics ActionKind = "diagnostics" - ActionDocument ActionKind = "document" - ActionGoTest ActionKind = "gotest" + ActionSkip ActionKind = "skip" + ActionRewrite ActionKind = "rewrite" + ActionDiagnostics ActionKind = "diagnostics" + ActionDocument ActionKind = "document" + ActionGoTest ActionKind = "gotest" + ActionSimplify ActionKind = "simplify" ) // InputParts represents parsed stdin input for actions. -- cgit v1.2.3