1
1
Fork
You've already forked zop
0

Add new feature: prompt templates #30

Merged
peterwwillis merged 3 commits from feature/add-prompt-templates into main 2026年03月21日 19:03:50 +01:00
peterwwillis commented 2026年03月21日 08:38:19 +01:00 (Migrated from github.com)
Copy link
No description provided.
gemini-code-assist[bot] commented 2026年03月21日 08:38:37 +01:00 (Migrated from github.com)
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1 ! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a powerful new prompt templating feature, enabling users to define and reuse dynamic prompts for AI agents and models. This enhancement significantly improves the flexibility and maintainability of prompt management by allowing prompts to be configured with variables, functions, and external files, rather than being static strings. The change integrates a robust templating engine into the application's core, making it easier to create sophisticated and context-aware interactions with various AI providers.

Highlights

  • New Prompt Templating System: Introduced a comprehensive prompt templating system allowing for dynamic and reusable system and user prompts. Templates can be defined directly in the configuration or loaded from external files.
  • Flexible Template Configuration: Agents and models can now reference named templates, or define prompts inline, from files, or via templates. This provides a hierarchical and flexible way to manage prompt definitions.
  • Go Template Engine Integration: The templating system leverages Go's text/template package, providing access to various data points like input, configuration, agent/model details, and environment variables, along with utility functions (e.g., date, time, upper, lower).
  • Enhanced Prompt Resolution Logic: Updated the core controller logic to resolve and execute system and user prompts using the new templating mechanism before sending them to the AI provider, ensuring dynamic prompt generation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.


  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩︎

## Summary of Changes Hello, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a powerful new prompt templating feature, enabling users to define and reuse dynamic prompts for AI agents and models. This enhancement significantly improves the flexibility and maintainability of prompt management by allowing prompts to be configured with variables, functions, and external files, rather than being static strings. The change integrates a robust templating engine into the application's core, making it easier to create sophisticated and context-aware interactions with various AI providers. ### Highlights * **New Prompt Templating System**: Introduced a comprehensive prompt templating system allowing for dynamic and reusable system and user prompts. Templates can be defined directly in the configuration or loaded from external files. * **Flexible Template Configuration**: Agents and models can now reference named templates, or define prompts inline, from files, or via templates. This provides a hierarchical and flexible way to manage prompt definitions. * **Go Template Engine Integration**: The templating system leverages Go's `text/template` package, providing access to various data points like input, configuration, agent/model details, and environment variables, along with utility functions (e.g., `date`, `time`, `upper`, `lower`). * **Enhanced Prompt Resolution Logic**: Updated the core controller logic to resolve and execute system and user prompts using the new templating mechanism before sending them to the AI provider, ensuring dynamic prompt generation. <details> <summary><b>Using Gemini Code Assist</b></summary> <br> The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips. <b>Invoking Gemini</b> You can request assistance from Gemini at any point by creating a comment using either `/gemini <command>` or `@gemini-code-assist <command>`. Below is a summary of the supported commands on the current page. Feature | Command | Description --- | --- | --- Code Review | `/gemini review` | Performs a code review for the current pull request in its current state. Pull Request Summary | `/gemini summary` | Provides a summary of the current pull request in its current state. Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments. Help | `/gemini help` | Displays a list of available commands. <b>Customization</b> To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a `.gemini/` folder in the base of the repository. Detailed instructions can be found [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). <b>Limitations & Feedback</b> Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up [here](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG). </details> [^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487).
gemini-code-assist[bot] (Migrated from github.com) reviewed 2026年03月21日 08:40:36 +01:00
gemini-code-assist[bot] (Migrated from github.com) left a comment
Copy link

Code Review

Thank you for adding the prompt templating feature. This is a powerful addition. I've reviewed the changes and have identified a few areas for improvement, primarily in the new internal/app/prompt.go file. My comments focus on improving error handling, reducing code duplication for better maintainability, and addressing a design choice that could lead to inconsistent and unexpected behavior for users. Please take a look at the specific comments for details.

## Code Review Thank you for adding the prompt templating feature. This is a powerful addition. I've reviewed the changes and have identified a few areas for improvement, primarily in the new `internal/app/prompt.go` file. My comments focus on improving error handling, reducing code duplication for better maintainability, and addressing a design choice that could lead to inconsistent and unexpected behavior for users. Please take a look at the specific comments for details.
@ -0,0 +1,147 @@
packageapp
gemini-code-assist[bot] (Migrated from github.com) commented 2026年03月21日 08:40:36 +01:00
Copy link

high

The errors returned from c.cfg.GetAgent and c.cfg.GetModel are being ignored. According to the repository's style guide, idiomatic Go error handling should be followed. While the controller's state management might prevent errors here in most cases, not handling them could lead to silent failures or unexpected behavior if an invalid agent or model is ever used. It's safer to check these errors and return them.

agent,err:=c.cfg.GetAgent(c.agentName)iferr!=nil{return"",fmt.Errorf("getting agent for template: %w",err)}model,err:=c.cfg.GetModel(agent.Model)iferr!=nil{return"",fmt.Errorf("getting model for template: %w",err)}
References
  1. The code ignores errors returned by functions, which goes against the principle of idiomatic Go error handling. (link)
![high](https://www.gstatic.com/codereviewagent/high-priority.svg) The errors returned from `c.cfg.GetAgent` and `c.cfg.GetModel` are being ignored. According to the repository's style guide, idiomatic Go error handling should be followed. While the controller's state management might prevent errors here in most cases, not handling them could lead to silent failures or unexpected behavior if an invalid agent or model is ever used. It's safer to check these errors and return them. ```go agent, err := c.cfg.GetAgent(c.agentName) if err != nil { return "", fmt.Errorf("getting agent for template: %w", err) } model, err := c.cfg.GetModel(agent.Model) if err != nil { return "", fmt.Errorf("getting model for template: %w", err) } ``` <details> <summary>References</summary> 1. The code ignores errors returned by functions, which goes against the principle of idiomatic Go error handling. <sup>([link](https://github.com/peterwwillis/zop/blob/main/.gemini/styleguide.md))</sup> </details>
@ -0,0 +42,4 @@
}
return"",nil
}
gemini-code-assist[bot] (Migrated from github.com) commented 2026年03月21日 08:40:36 +01:00
Copy link

medium

There is significant code duplication in resolveSystemPrompt when resolving the prompt source from an agent and then from a model. The logic for checking inline content, a file path, and a template reference is repeated. This pattern also appears in resolveUserPromptTemplate. Consolidating this logic into a private helper function would reduce duplication and improve maintainability.

![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg) There is significant code duplication in `resolveSystemPrompt` when resolving the prompt source from an agent and then from a model. The logic for checking inline content, a file path, and a template reference is repeated. This pattern also appears in `resolveUserPromptTemplate`. Consolidating this logic into a private helper function would reduce duplication and improve maintainability.
@ -0,0 +98,4 @@
func(c*Controller)executeTemplate(tmplStrstring,inputstring)(string,error){
iftmplStr==""{
returninput,nil
}
gemini-code-assist[bot] (Migrated from github.com) commented 2026年03月21日 08:40:36 +01:00
Copy link

high

This logic, which treats the user's raw input as a template when no agent-specific template is defined, introduces inconsistency and potential for unexpected behavior.

  1. Inconsistent Behavior: When an agent has a template, user input is treated as data (via {{.Input}}). When it doesn't, the user input itself is executed as a template. This switch in behavior can be confusing.
  2. Unexpected Execution: A user might paste text containing {{...}} (e.g., when asking about code) and not expect it to be executed, which could lead to errors or mangled output.

A safer and more consistent design would be to always treat user input as data. If no template is specified, the input should be used as-is.

iftmplStr==""{returninput,nil}
![high](https://www.gstatic.com/codereviewagent/high-priority.svg) This logic, which treats the user's raw input as a template when no agent-specific template is defined, introduces inconsistency and potential for unexpected behavior. 1. **Inconsistent Behavior**: When an agent has a template, user input is treated as data (via `{{.Input}}`). When it doesn't, the user input itself is executed as a template. This switch in behavior can be confusing. 2. **Unexpected Execution**: A user might paste text containing `{{...}}` (e.g., when asking about code) and not expect it to be executed, which could lead to errors or mangled output. A safer and more consistent design would be to always treat user input as data. If no template is specified, the input should be used as-is. ```go if tmplStr == "" { return input, nil } ```
github-actions[bot] commented 2026年03月21日 08:56:06 +01:00 (Migrated from github.com)
Copy link

Mobile UI Screenshot

zop mobile UI

### Mobile UI Screenshot ![zop mobile UI](https://raw.githubusercontent.com/peterwwillis/zop/ui-screenshots/pr-30/zop-mobile-ui.png) <!-- Sticky Pull Request Commentzop-mobile-ui -->
peterwwillis commented 2026年03月21日 18:33:30 +01:00 (Migrated from github.com)
Copy link

Resolved: user input is now treated as literal text when no template is specified. Added a test case to verify this behavior.

Resolved: user input is now treated as literal text when no template is specified. Added a test case to verify this behavior.
peterwwillis commented 2026年03月21日 18:33:41 +01:00 (Migrated from github.com)
Copy link

Resolved: added error handling for c.cfg.GetAgent and c.cfg.GetModel calls.

Resolved: added error handling for c.cfg.GetAgent and c.cfg.GetModel calls.
peterwwillis commented 2026年03月21日 18:33:52 +01:00 (Migrated from github.com)
Copy link

Resolved: consolidated prompt source resolution into a private resolvePromptSource helper function.

Resolved: consolidated prompt source resolution into a private resolvePromptSource helper function.
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mutablecc/zop!30
Reference in a new issue
mutablecc/zop
No description provided.
Delete branch "feature/add-prompt-templates"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?