From e2ddfe5526c0dcf44929c8719bfbbdd2fdbad9f3 Mon Sep 17 00:00:00 2001 From: aek676 Date: Sat, 27 Jun 2026 00:33:03 +0200 Subject: [PATCH 1/2] feat(prompts): add commit prompt for conventional commit generation Add a `commit` prompt to the select prompts that generates conventional commit messages from staged `git diff` output. Include a `oc` keymap example and a tip for copying the result in the README. --- README.md | 32 ++++++++++++++++++++++---------- lua/opencode/config.lua | 25 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 4dfa819e..2b65573e 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,10 @@ vim.o.autoread = true -- Required for `vim.g.opencode_opts.events.reload` vim.keymap.set({ "n", "x" }, "oa", function() require("opencode").ask("@this: ") end, { desc = "Ask OpenCode…" }) vim.keymap.set({ "n", "x" }, "os", function() require("opencode").select() end, { desc = "Select OpenCode…" }) +vim.keymap.set("n", "oc", function() + require("opencode").prompt(require("opencode.config").opts.select.prompts.commit) +end, { desc = "Generate conventional commit" }) + vim.keymap.set({ "n", "x" }, "go", function() return require("opencode").operator("@this ") end, { desc = "Append range to OpenCode", expr = true }) vim.keymap.set("n", "goo", function() return require("opencode").operator("@this ") .. "_" end, { desc = "Append line to OpenCode", expr = true }) @@ -72,6 +76,10 @@ vim.keymap.set("n", "", function() require("opencode").command("session.h vim.keymap.set({ "n", "x" }, "oa", function() require("opencode").ask("@this: ") end, { desc = "Ask OpenCode…" }) vim.keymap.set({ "n", "x" }, "os", function() require("opencode").select() end, { desc = "Select OpenCode…" }) + vim.keymap.set("n", "oc", function() + require("opencode").prompt(require("opencode.config").opts.select.prompts.commit) + end, { desc = "Generate conventional commit" }) + vim.keymap.set({ "n", "x" }, "go", function() return require("opencode").operator("@this ") end, { desc = "Append range to OpenCode", expr = true }) vim.keymap.set("n", "goo", function() return require("opencode").operator("@this ") .. "_" end, { desc = "Append line to OpenCode", expr = true }) @@ -202,16 +210,20 @@ opencode.nvim replaces placeholders in prompts with the corresponding context: Select prompts to review, explain, and improve your code: -| Name | Prompt | -| ------------- | ------------------------------------------------ | -| `diagnostics` | Explain `@diagnostics` | -| `document` | Add comments documenting `@this` | -| `explain` | Explain `@this` and its context | -| `fix` | Fix `@diagnostics` | -| `implement` | Implement `@this` | -| `optimize` | Optimize `@this` for performance and readability | -| `review` | Review `@this` for correctness and readability | -| `test` | Add tests for `@this` | +| Name | Prompt | +| ------------- | ------------------------------------------------------------------- | +| `commit` | Generate a conventional commit message from staged changes | +| `diagnostics` | Explain `@diagnostics` | +| `document` | Add comments documenting `@this` | +| `explain` | Explain `@this` and its context | +| `fix` | Fix `@diagnostics` | +| `implement` | Implement `@this` | +| `optimize` | Optimize `@this` for performance and readability | +| `review` | Review `@this` for correctness and readability | +| `test` | Add tests for `@this` | + +> [!TIP] +> After generating a commit message, copy it from the OpenCode TUI with `y` (press `ctrl+x` then `y`). ### Server diff --git a/lua/opencode/config.lua b/lua/opencode/config.lua index 4400010b..88af9e11 100644 --- a/lua/opencode/config.lua +++ b/lua/opencode/config.lua @@ -70,6 +70,31 @@ local defaults = { prompt = "OpenCode: ", prompts = { ask = "...", + commit = [[Write a conventional commit message for the staged changes. Follow these steps: + + 1. Run `git status` to review changed files. + 2. Run `git diff --cached` to inspect the staged changes. + 3. Construct a commit message following the Conventional Commits specification. + + Commit message structure: + - type: feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert + - scope: optional, recommended for clarity + - description: required, imperative mood (e.g. "add", not "added") + - body: optional, for additional context + - footer: optional, for breaking changes or issue references + + Format: `(): ` followed by optional body and footer. + + Examples: + - feat(parser): add ability to parse arrays + - fix(ui): correct button alignment + - docs: update README with usage instructions + - refactor: improve performance of data processing + - chore: update dependencies + - feat!: send email on registration (BREAKING CHANGE: email service required) + + Output only the commit message, do not commit. + Do not wrap the output in markdown code fences; respond with the raw commit message only.]], diagnostics = "Explain @diagnostics", document = "Add comments documenting @this", explain = "Explain @this and its context", From bf486864dde8e455fdbaa78a6a8e911a904bf4e7 Mon Sep 17 00:00:00 2001 From: Anass El Jabiry Kaddir Date: Sat, 27 Jun 2026 02:19:16 +0200 Subject: [PATCH 2/2] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 2b65573e..cb5940ec 100644 --- a/README.md +++ b/README.md @@ -46,9 +46,7 @@ vim.o.autoread = true -- Required for `vim.g.opencode_opts.events.reload` vim.keymap.set({ "n", "x" }, "oa", function() require("opencode").ask("@this: ") end, { desc = "Ask OpenCode…" }) vim.keymap.set({ "n", "x" }, "os", function() require("opencode").select() end, { desc = "Select OpenCode…" }) -vim.keymap.set("n", "oc", function() - require("opencode").prompt(require("opencode.config").opts.select.prompts.commit) -end, { desc = "Generate conventional commit" }) +vim.keymap.set("n", "oc", function() require("opencode").prompt(require("opencode.config").opts.select.prompts.commit) end, { desc = "Generate conventional commit" }) vim.keymap.set({ "n", "x" }, "go", function() return require("opencode").operator("@this ") end, { desc = "Append range to OpenCode", expr = true }) vim.keymap.set("n", "goo", function() return require("opencode").operator("@this ") .. "_" end, { desc = "Append line to OpenCode", expr = true })