Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

Repository files navigation

opencode-action-template-plugin — pick a template, fill a form, send a perfect prompt

opencode-action-template-plugin

Turn /template into a tiny form builder for your AI sessions.

Pick a template → fill a form → preview → send a well-prepared prompt.

OpenCode plugin TypeScript Tests


An OpenCode plugin that lets you pick a prompt template, fill in a small form (selects, radio buttons, checkboxes, text fields), preview the result, and send a well-prepared prompt into your current session.

/template   →  pick template  →  fill form  →  preview  →  send

✨ Features

  • 📝 Form-driven prompts — six field types (select, radio, checkbox, checkboxes, text, textarea) render into a native OpenCode form dialog
  • 👀 Preview loop — see the fully rendered prompt before it goes: send, edit your answers again, or cancel with Esc — nothing is sent by accident
  • 🕐 Recents & Repeat — the last 5 used templates appear in a "Recent" category, and the most recent one offers a Repeat entry that reuses your previous answers instantly
  • 📁 Project over global — templates live in .opencode/templates/*.md (project) and ~/.config/opencode/templates/*.md (global); same file id → project wins
  • 🧭 Agent & model switches — frontmatter can route the prompt to a specific agent: or override the model: per template
  • 🔍 Searchable picker — filter templates while typing, grouped into Project / Global / Recent categories
  • 🛡️ Readable errors — invalid template files report their validation errors instead of breaking the picker
  • 🧩 Placeholder filters — default:"…" fallbacks, join:", " for checkbox groups, and automatic dropping of lines whose placeholders all resolve empty

Install

The easiest way is the OpenCode CLI:

opencode plugin add github:egel/opencode-action-template-plugin

Or add it to opencode.json(c) manually:

{
  "$schema": "https://opencode.ai/config.json",
  "plugins": ["github:egel/opencode-action-template-plugin"],
}

Then restart OpenCode (or run /reload). You should see a "Plugin loaded" toast.

Writing templates

Templates are Markdown files with YAML frontmatter, discovered in:

  • .opencode/templates/*.md — project (takes precedence)
  • ~/.config/opencode/templates/*.md — global

The frontmatter defines the form; the body is the prompt template with {{ fieldId }} placeholders. Copy examples/*.md to get started.

A fuller example showing several field types, defaults, placeholders, and frontmatter switches:

---
name: Code review
description: Review code for bugs, security and quality issues
preview: true # show a send/edit/cancel preview (default true)
agent: plan # optional agent switch before sending
# model: anthropic/claude-sonnet-5-5   # optional model override
fields:
  - id: path
    type: text
    label: Files or directory
    placeholder: e.g. src/render.ts # hint shown in the empty input
  - id: focus
    type: select # single-choice list
    label: Review focus
    default: bugs # pre-selected option value
    options:
      - { title: Bugs, value: bugs }
      - { title: Security, value: security }
      - { title: Performance, value: performance }
      - { title: Readability, value: readability }
  - id: severity
    type: radio # same UI as select, semantically exclusive
    label: Only report issues of severity
    default: major
    options:
      - { title: Critical, value: critical }
      - { title: Major, value: major }
      - { title: Minor, value: minor }
  - id: also
    type: checkboxes # toggle list with a "✔ Done" entry
    label: Also verify
    options:
      - { title: Tests, value: tests, default: true }
      - { title: Types, value: types, default: true }
      - { title: Error handling, value: errors }
      - { title: Naming, value: naming }
  - id: strict
    type: checkbox # simple yes/no
    label: Be blunt in the summary?
    checked: true # initial state
  - id: notes
    type: textarea
    label: Extra notes
    placeholder: Anything specific to look at?
---

Review {{ path | default:"the current changes" }} with focus on {{ focus }}.
Only report {{ severity }} issues or worse.
Also verify: {{ also | join:", " }}.
{{ strict == "yes" ? "" : "" }}Be direct in the summary.

> {{ notes }}

Field types

Type UI Prompt value
select single-choice list chosen option value
radio single-choice list chosen option value
checkboxes toggle list with a ✔ Done entry array, joined by the join filter
checkbox Yes/No list yes or empty
text single-line input typed text
textarea single-line input (multiline dialog planned) typed text

Field options: label, placeholder, default (text value or option value), checked (for checkbox), and options with title, value, default.

Placeholder filters

  • {{ path | default:"the current changes" }} — fallback when empty
  • {{ also | join:", " }} — join checkbox groups
  • Lines whose placeholders all resolve empty (e.g. > {{ notes }}) are dropped

Tips

  • Keep option values lowercase and space-free — they end up in the prompt
  • Put optional sections on their own lines so they drop out cleanly when empty
  • Use agent: plan for templates that only research, and leave it unset for templates that edit code

Examples

Ready-to-copy templates live in examples/:

Development

Install from a local checkout (useful while hacking on the plugin itself) by pointing the plugins entry at the path:

{
  "$schema": "https://opencode.ai/config.json",
  "plugins": [
    { "package": "<my_path_to_repo>/opencode-action-template-plugin" },
  ],
}

Then restart OpenCode (or run /reload).

npm test        # vitest
npm run typecheck

QA checklist (manual)

  • /template appears in slash and palette lists
  • Picker shows Project/Global categories and filters while typing
  • Form pre-fills defaults; Esc at any step cancels without sending
  • Checkbox toggles round-trip into the rendered prompt
  • Preview "Edit answers again" reopens the form; "Send" submits into the session
  • Repeat entry reuses last answers; recents category updates after send
  • A broken template shows its validation errors; the picker still works
  • agent:/model: frontmatter switches are applied (or warned about)

Known limitations

  • textarea fields use the single-line prompt dialog (multiline editor planned)
  • Checkbox groups toggle through a list with a ✔ Done entry (inline multi-select planned)
  • Submitting requires an open session; run /template from inside one

Built for OpenCode · MIT licensed

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages