Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 45 additions & 12 deletions registry/coder-labs/modules/gemini/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Run [Gemini CLI](https://github.com/google-gemini/gemini-cli) in your workspace
```tf
module "gemini" {
source = "registry.coder.com/coder-labs/gemini/coder"
version = "3.0.0"
version = "3.0.1"
agent_id = coder_agent.main.id
folder = "/home/coder/project"
folder = "/home/coder"
}
```

Expand Down Expand Up @@ -45,19 +45,35 @@ variable "gemini_api_key" {
}

module "gemini" {
source = "registry.coder.com/coder-labs/gemini/coder"
version = "3.0.0"
agent_id = coder_agent.main.id
gemini_api_key = var.gemini_api_key
folder = "/home/coder/project"
source = "registry.coder.com/coder-labs/gemini/coder"
version = "3.0.1"
agent_id = coder_agent.main.id
gemini_api_key = var.gemini_api_key
folder = "/home/coder"
pre_install_script = <<-EOT
#!/bin/bash
set -e

echo "Installing Node.js via NodeSource..."

sudo apt-get update -qq && sudo apt-get install -y curl ca-certificates

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo bash -

sudo apt-get install -y nodejs

echo "Node version: $(node -v)"
echo "npm version: $(npm -v)"
echo "Node install complete."
EOT
}
```

This basic setup will:

- Install Gemini CLI in the workspace
- Configure authentication with your API key
- Set Gemini to run in `/home/coder/project` directory
- Set Gemini to run in `/home/coder` directory
- Enable interactive use from the terminal
- Set up MCP server integration for task reporting

Expand Down Expand Up @@ -94,11 +110,11 @@ data "coder_parameter" "ai_prompt" {
module "gemini" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder-labs/gemini/coder"
version = "3.0.0"
version = "3.0.1"
agent_id = coder_agent.main.id
gemini_api_key = var.gemini_api_key
gemini_model = "gemini-2.5-flash"
folder = "/home/coder/project"
folder = "/home/coder"
task_prompt = data.coder_parameter.ai_prompt.value
enable_yolo_mode = true # Auto-approve all tool calls for automation
gemini_system_prompt = <<-EOT
Expand All @@ -111,17 +127,34 @@ module "gemini" {
> [!WARNING]
> YOLO mode automatically approves all tool calls without user confirmation. The agent has access to your machine's file system and terminal. Only enable in trusted, isolated environments.

### Session Resumption Behavior

By default, Gemini CLI automatically resumes existing conversations when your workspace restarts. Sessions are tracked per workspace directory, so conversations continue where you left off. If no session exists (first start), your `ai_prompt` will run normally. To disable this behavior and always start fresh, set `continue = false`

## State Persistence

AgentAPI can save and restore its conversation state to disk across workspace restarts. This complements `continue` (which resumes the Gemini CLI session) by also preserving the AgentAPI-level context. Enabled by default, requires agentapi >= v0.12.0 (older versions skip it with a warning).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 continue in backticks implies a command or flag, but it doesn't exist in this module. The script uses --resume. (Hisoka P2, Leorio Nit, Pen Botter Nit)

grep -n "continue" registry/coder-labs/modules/gemini/main.tf returns no results. This text appears to be copied from the codex module's README, which does have a continue variable. A reader searching for continue in this codebase will find nothing.

If this refers to the --resume flag, call it --resume. If it's a Gemini CLI concept, link or explain it.

Nit The ## State Persistence heading breaks the heading hierarchy. ### Using Vertex AI (Enterprise) was previously a child of ## Examples. Now it appears to be a child of ## State Persistence, which has nothing to do with Vertex AI. Move this section after the Vertex AI subsection, or place it before ## Troubleshooting. (Leorio Nit, Pen Botter Nit)

🤖

To disable:

```tf
module "gemini" {
# ... other config
enable_state_persistence = false
}
```

### Using Vertex AI (Enterprise)

For enterprise users who prefer Google's Vertex AI platform:

```tf
module "gemini" {
source = "registry.coder.com/coder-labs/gemini/coder"
version = "3.0.0"
version = "3.0.1"
agent_id = coder_agent.main.id
gemini_api_key = var.gemini_api_key
folder = "/home/coder/project"
folder = "/home/coder"
use_vertexai = true
}
```
Expand Down
66 changes: 38 additions & 28 deletions registry/coder-labs/modules/gemini/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,16 @@ variable "install_agentapi" {
default = true
}

variable "continue" {
type = bool
description = "Automatically continue existing sessions on workspace restart. When true, resumes existing conversation if found, otherwise runs prompt or starts new session. When false, always starts fresh (ignores existing sessions)."
default = true
}

variable "agentapi_version" {
type = string
description = "The version of AgentAPI to install."
default = "v0.10.0"
default = "v0.12.0"
}

variable "gemini_model" {
Expand Down Expand Up @@ -126,6 +132,12 @@ variable "enable_yolo_mode" {
default = false
}

variable "enable_state_persistence" {
type = bool
description = "Enable AgentAPI conversation state persistence across restarts."
default = true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 enable_state_persistence defaults to true, but agentapi_version defaults to v0.10.0, which is below the >= v0.12.0 requirement stated in the README. (Mafuuu P1, Mafu-san P1, Meruem P1, Hisoka P2, Kurapika P2, Luffy P2)

A user who accepts all defaults gets enable_state_persistence = true with an agentapi binary that can't support it. The agentapi module gracefully skips persistence with a warning for old versions, but the default configuration enables a feature that cannot work. The codex module gets this right by defaulting agentapi_version to v0.12.1 when enabling state persistence.

Either bump the default agentapi_version to at least v0.12.0, or default enable_state_persistence to false.

🤖

}

resource "coder_env" "gemini_api_key" {
agent_id = var.agent_id
name = "GEMINI_API_KEY"
Expand All @@ -148,21 +160,17 @@ locals {
base_extensions = <<-EOT
{
"coder": {
"command": "coder",
"args": [
"exp",
"mcp",
"server"
],
"command": "coder",
"description": "Report ALL tasks and statuses (in progress, done, failed) you are working on.",
"enabled": true,
"env": {
"CODER_MCP_APP_STATUS_SLUG": "${local.app_slug}",
"CODER_MCP_AI_AGENTAPI_URL": "http://localhost:3284"
},
"name": "Coder",
"timeout": 3000,
"type": "stdio",
"trust": true
}
}
Expand All @@ -177,23 +185,24 @@ EOT

module "agentapi" {
source = "registry.coder.com/coder/agentapi/coder"
version = "2.0.0"

agent_id = var.agent_id
folder = local.folder
web_app_slug = local.app_slug
web_app_order = var.order
web_app_group = var.group
web_app_icon = var.icon
web_app_display_name = "Gemini"
cli_app_slug = "${local.app_slug}-cli"
cli_app_display_name = "Gemini CLI"
module_dir_name = local.module_dir_name
install_agentapi = var.install_agentapi
agentapi_version = var.agentapi_version
pre_install_script = var.pre_install_script
post_install_script = var.post_install_script
install_script = <<-EOT
version = "2.2.0"

agent_id = var.agent_id
folder = local.folder
web_app_slug = local.app_slug
web_app_order = var.order
web_app_group = var.group
web_app_icon = var.icon
web_app_display_name = "Gemini"
cli_app_slug = "${local.app_slug}-cli"
cli_app_display_name = "Gemini CLI"
module_dir_name = local.module_dir_name
install_agentapi = var.install_agentapi
agentapi_version = var.agentapi_version
enable_state_persistence = var.enable_state_persistence
pre_install_script = var.pre_install_script
post_install_script = var.post_install_script
install_script = <<-EOT
#!/bin/bash
set -o errexit
set -o pipefail
Expand All @@ -209,20 +218,21 @@ module "agentapi" {
GEMINI_SYSTEM_PROMPT='${base64encode(var.gemini_system_prompt)}' \
/tmp/install.sh
EOT
start_script = <<-EOT
start_script = <<-EOT
#!/bin/bash
set -o errexit
set -o pipefail

echo -n '${base64encode(local.start_script)}' | base64 -d > /tmp/start.sh
chmod +x /tmp/start.sh
GEMINI_API_KEY='${var.gemini_api_key}' \
GOOGLE_API_KEY='${var.gemini_api_key}' \
GEMINI_API_KEY='${base64encode(var.gemini_api_key)}' \
GOOGLE_API_KEY='${base64encode(var.gemini_api_key)}' \
GEMINI_YOLO_MODE='${base64encode(var.enable_yolo_mode)}' \
GOOGLE_GENAI_USE_VERTEXAI='${var.use_vertexai}' \
GEMINI_YOLO_MODE='${var.enable_yolo_mode}' \
GEMINI_MODEL='${var.gemini_model}' \
GEMINI_START_DIRECTORY='${var.folder}' \
GEMINI_TASK_PROMPT='${var.task_prompt}' \
GEMINI_TASK_PROMPT='${base64encode(var.task_prompt)}' \
ARG_CONTINUE='${base64encode(var.continue)}' \
/tmp/start.sh
EOT
}
Expand Down
Loading
Loading