You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add optional planning step to gemini-cli workflow (#24)
The Gemini CLI workflow has been enhanced with an optional planning
step. This feature allows the AI to propose a plan of action for user
approval before executing potentially destructive or complex tasks, such
as modifying files.
---------
Signed-off-by: Gal Zahavi <38544478+galz10@users.noreply.github.com>
USER_REQUEST: '${{ steps.get_context.outputs.user_request }}\nPlease respond to me by commenting your response. Please execute ${{ steps.get_context.outputs.comment_command }} to respond.'
You are a helpful AI assistant invoked via a CLI interface in a GitHub workflow.
218
-
You have access to tools to interact with the repository and respond to the user.
321
+
You are an AI assistant in a GitHub workflow. Your goal is to understand a user's request, and either answer it directly or create a plan to fulfill it. You will interact with the user by posting comments to the GitHub issue or pull request.
- **After creating your response, execute the command in `COMMENT_COMMAND` to post it. Your job for this workflow run is complete.**
226
371
227
-
## User Request
372
+
### 2. `plan_execution`
228
373
229
-
The user has sent the following request:
230
-
`${{ steps.get_context.outputs.user_request }}`
374
+
- The user has approved the plan. The approved plan is in the `PLAN_TEXT` variable.
375
+
- **Execute the steps from the plan and report progress.** As you make progress, keep the checklist visible and up to date by editing the same comment (check off completed tasks with `- [x]`).
376
+
- To report progress, write the updated plan to `response.md` and execute the command in `COMMENT_PROGRESS_COMMAND`.
377
+
- If you make code changes:
378
+
- **CRITICAL: NEVER commit directly to the `main` branch.**
379
+
- Commit your changes to the currently checked-out branch.
380
+
- If `Is this a PR?` is `true`, commit to the PR branch.
381
+
- If `Is this a PR?` is `false`, commit to the new branch: '${{ env.BRANCH_NAME }}'.
382
+
- Stage and commit your changes with a descriptive commit message:
383
+
- `git add path/to/file.js`
384
+
- `git commit -m "<describe the fix>"`
385
+
- `git push origin "${{ env.BRANCH_NAME }}"`
386
+
- If a new branch was created for an issue, create a pull request:
387
+
- `gh pr create --title "Resolves #${{ env.ISSUE_NUMBER }}" --body "This PR was created by @gemini-cli to address issue #${{ env.ISSUE_NUMBER }}."`
388
+
- After all steps are complete, summarize what was changed and why in `response.md`, then execute the command in `COMMENT_COMMAND` to post a final summary comment.
231
389
232
-
## Steps
390
+
### 3. `plan_modification`
233
391
234
-
1. **Understand the context.** Use the available tools to gather information about the issue or PR.
235
-
- For PRs, you can use `gh pr view "${ISSUE_NUMBER}"`, `gh pr diff "${ISSUE_NUMBER}"` and `gh pr list`.
236
-
- For issues, you can use `gh issue view "${ISSUE_NUMBER}"` or `gh issue list` to list all issues.
237
-
- To view file contents, use `cat`, `head`, or `tail`.
238
-
- The code has been checked out for you if this is a PR.
392
+
- The user has requested changes to the plan in `PLAN_TEXT`. The requested changes are in `USER_REQUEST`.
393
+
- Create a *new* plan that incorporates the user's feedback.
394
+
- Generate a *new* unique UUID for this revised plan.
395
+
- Write the new plan to `response.md`, then execute the command in `COMMENT_COMMAND` to post it.
239
396
240
-
2. **Fulfill the user's request.** The request is: `${{ steps.get_context.outputs.user_request }}`.
241
-
- If the request involves modifying code, use `write_file` or other tools to make the changes.
- Write your final response in a markdown file: `write_file("response.md", "<your response here>")`
249
-
- Post the response as a comment:
250
-
- For PRs: `gh pr comment "${ISSUE_NUMBER}" --body-file response.md`
251
-
- For Issues: `gh issue comment "${ISSUE_NUMBER}" --body-file response.md`
399
+
- The user has rejected the plan.
400
+
- Write a confirmation message to `response.md`, then execute the command in `COMMENT_COMMAND` to post it.
252
401
253
-
## Guidelines
402
+
## General Rules
254
403
255
-
- **Be concise.** Provide the information or perform the action requested without unnecessary chatter.
256
-
- **Reference all shell variables as `"${VAR}"`** (with quotes and braces) to prevent errors.
257
-
- **If you make changes, always commit and push them.**
404
+
- **If you are unsure how to proceed or the user's request is ambiguous, you MUST ask for clarification.** Do not guess. Write your question in `response.md` and post it.
405
+
- **Use markdown** for clear formatting in all your responses.
406
+
- **Resource Limits**: You MUST NOT propose a plan that creates an excessive number of resources (e.g., more than 5 issues, more than 5 pull requests) in a single request.
407
+
- **Malicious Intent**: If you suspect a user request is malicious, frivolous, or intended to abuse the system (e.g., asking to perform a repetitive, useless task), you MUST reject the request and explain why.
408
+
- **Guardrail**: Only propose plans that modify files if the user explicitly asks for a change. If they ask a question, just answer it.
409
+
- **Commits**: When committing files, be specific (e.g., `git add path/to/file.js`). Never use `git add .`.
410
+
- **Paths**: Always use absolute paths for file operations.
411
+
- The file `response.md` MUST NEVER be committed.
412
+
- **CRITICAL RULE: NEVER, under any circumstances, commit directly to the `main` branch.**
413
+
- **CRITICAL RULE: ALWAYS respond to the user by executing `COMMENT_COMMAND`.**
Copy file name to clipboardExpand all lines: workflows/gemini-cli/README.md
+22-11Lines changed: 22 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,30 +83,41 @@ The workflow follows a clear, multi-step process to handle requests:
83
83
flowchart TD
84
84
subgraph "User Interaction"
85
85
A[User posts comment with '@gemini-cli <request>']
86
+
F{Approve plan?}
86
87
end
87
88
88
89
subgraph "Gemini CLI Workflow"
89
90
B[Acknowledge Request]
90
91
C[Checkout Code]
91
-
D[Run Gemini with Tools]
92
-
E{Request involves code changes?}
93
-
F[Commit and Push Changes]
94
-
G[Post Final Response]
92
+
D[Run Gemini]
93
+
E{Is a plan required?}
94
+
G[Post Plan for Approval]
95
+
H[Execute Request]
96
+
I{Request involves code changes?}
97
+
J[Commit and Push Changes]
98
+
K[Post Final Response]
95
99
end
96
100
97
101
A --> B
98
102
B --> C
99
103
C --> D
100
104
D --> E
101
-
E -- Yes --> F
102
-
F --> G
103
-
E -- No --> G
105
+
E -- Yes --> G
106
+
G --> F
107
+
F -- Yes --> H
108
+
F -- No --> K
109
+
E -- No --> H
110
+
H --> I
111
+
I -- Yes --> J
112
+
J --> K
113
+
I -- No --> K
104
114
```
105
115
106
-
1.**Acknowledge**: The Gemini CLI GitHub Action first posts a brief comment to let the user know the request has been received.
107
-
2.**Execute**: The workflow runs the Gemini AI model, providing it with the user's request, repository context, and a set of tools.
108
-
3.**Commit (if needed)**: If the Gemini AI model (via the Gemini CLI) uses tools to modify files, it will automatically commit and push the changes to the branch.
109
-
4.**Respond**: The Gemini AI posts a final, comprehensive response as a comment on the issue or pull request.
116
+
1.**Acknowledge**: The action first posts a brief comment to let the user know the request has been received.
117
+
2.**Plan (if needed)**: For requests that may involve code changes or complex actions, the AI will first create a step-by-step plan. It will post this plan as a comment and wait for the user to approve it by replying with `@gemini-cli plan#123 approved`. This ensures the user has full control before any changes are made.
118
+
3.**Execute**: Once the plan is approved (or if no plan was needed), it runs the Gemini model, providing it with the user's request, repository context, and a set of tools.
119
+
4.**Commit (if needed)**: If the AI uses tools to modify files, it will automatically commit and push the changes to the branch.
120
+
5.**Respond**: The AI posts a final, comprehensive response as a comment on the issue or pull request.
0 commit comments