Skip to content

Commit b586b3e

Browse files
committed
feat(dogfood): integrate tasks support
1 parent 67e1567 commit b586b3e

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

dogfood/coder/main.tf

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ locals {
3838
repo_base_dir = data.coder_parameter.repo_base_dir.value == "~" ? "/home/coder" : replace(data.coder_parameter.repo_base_dir.value, "/^~\\//", "/home/coder/")
3939
repo_dir = replace(try(module.git-clone[0].repo_dir, ""), "/^~\\//", "/home/coder/")
4040
container_name = "coder-${data.coder_workspace_owner.me.name}-${lower(data.coder_workspace.me.name)}"
41+
has_ai_prompt = data.coder_parameter.ai_prompt.value != ""
4142
}
4243

4344
data "coder_workspace_preset" "cpt" {
@@ -150,6 +151,13 @@ data "coder_parameter" "image_type" {
150151
}
151152
}
152153

154+
variable "anthropic_api_key" {
155+
type = string
156+
description = "The API key used to authenticate with the Anthropic API."
157+
default = ""
158+
sensitive = true
159+
}
160+
153161
locals {
154162
default_regions = {
155163
// keys should match group names
@@ -242,6 +250,14 @@ data "coder_parameter" "devcontainer_autostart" {
242250
mutable = true
243251
}
244252

253+
data "coder_parameter" "ai_prompt" {
254+
type = "string"
255+
name = "AI Prompt"
256+
default = ""
257+
description = "Prompt for Claude Code"
258+
mutable = false
259+
}
260+
245261
provider "docker" {
246262
host = lookup(local.docker_host, data.coder_parameter.region.value)
247263
}
@@ -380,6 +396,25 @@ module "devcontainers-cli" {
380396
agent_id = coder_agent.dev.id
381397
}
382398

399+
module "claude-code" {
400+
count = local.has_ai_prompt ? data.coder_workspace.me.start_count : 0
401+
source = "dev.registry.coder.com/coder/claude-code/coder"
402+
version = "~>2.0"
403+
agent_id = coder_agent.dev.id
404+
folder = local.repo_dir
405+
install_claude_code = true
406+
claude_code_version = "latest"
407+
order = 999
408+
409+
experiment_report_tasks = true
410+
# TODO(Cian): Add post-install script to set up required MCP servers:
411+
# - desktop-commander
412+
# - playwright
413+
#experiment_post_install_script = <<-EOT
414+
#EOT
415+
}
416+
417+
383418
resource "coder_agent" "dev" {
384419
arch = "amd64"
385420
os = "linux"
@@ -710,4 +745,67 @@ resource "coder_metadata" "container_info" {
710745
key = "region"
711746
value = data.coder_parameter.region.option[index(data.coder_parameter.region.option.*.value, data.coder_parameter.region.value)].name
712747
}
748+
item {
749+
key = "ai_task"
750+
value = local.has_ai_prompt ? "yes" : "no"
751+
}
752+
}
753+
754+
resource "coder_env" "claude_system_prompt" {
755+
count = local.has_ai_prompt ? data.coder_workspace.me.start_count : 0
756+
agent_id = coder_agent.dev.id
757+
name = "CODER_MCP_CLAUDE_SYSTEM_PROMPT"
758+
value = <<-EOT
759+
<system>
760+
-- Framing --
761+
You are a helpful Coding assistant. Aim to autonomously investigate
762+
and solve issues the user gives you and test your work, whenever possible.
763+
764+
Avoid shortcuts like mocking tests. When you get stuck, you can ask the user
765+
but opt for autonomy.
766+
767+
-- Tool Selection --
768+
- coder_report_task: providing status updates or requesting user input.
769+
- Built-in tools - use for everything else:
770+
(file operations, git commands, builds & installs, one-off shell commands)
771+
772+
-- Task Reporting --
773+
Report all tasks to Coder, following these EXACT guidelines:
774+
1. Be granular. If you are investigating with multiple steps, report each step
775+
to coder.
776+
2. IMMEDIATELY report status after receiving ANY user message
777+
3. Use "state": "working" when actively processing WITHOUT needing
778+
additional user input
779+
4. Use "state": "complete" only when finished with a task
780+
5. Use "state": "failure" when you need ANY user input, lack sufficient
781+
details, or encounter blockers
782+
783+
In your summary:
784+
- Be specific about what you're doing
785+
- Clearly indicate what information you need from the user when in
786+
"failure" state
787+
- Keep it under 160 characters
788+
- Make it actionable
789+
790+
-- Context --
791+
There is an existing application in the current directory.
792+
Be sure to read CLAUDE.md before making any changes.
793+
794+
This is a real-world production application. As such, make sure to think carefully, use TODO lists, and plan carefully before making changes.
795+
</system>
796+
EOT
797+
}
798+
799+
resource "coder_env" "claude_task_prompt" {
800+
count = local.has_ai_prompt ? data.coder_workspace.me.start_count : 0
801+
agent_id = coder_agent.dev.id
802+
name = "CODER_MCP_CLAUDE_TASK_PROMPT"
803+
value = data.coder_parameter.ai_prompt.value
804+
}
805+
806+
resource "coder_env" "anthropic_api_key" {
807+
count = local.has_ai_prompt ? data.coder_workspace.me.start_count : 0
808+
agent_id = coder_agent.dev.id
809+
name = "ANTHROPIC_API_KEY"
810+
value = var.anthropic_api_key
713811
}

dogfood/main.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ variable "CODER_TEMPLATE_MESSAGE" {
3333
type = string
3434
}
3535

36+
variable "CODER_DOGFOOD_ANTHROPIC_API_KEY" {
37+
type = string
38+
description = "The API key that workspaces will use to authenticate with the Anthropic API."
39+
default = ""
40+
sensitive = true
41+
}
42+
3643
resource "coderd_template" "dogfood" {
3744
name = var.CODER_TEMPLATE_NAME
3845
display_name = "Write Coder on Coder"
@@ -45,6 +52,12 @@ resource "coderd_template" "dogfood" {
4552
message = var.CODER_TEMPLATE_MESSAGE
4653
directory = var.CODER_TEMPLATE_DIR
4754
active = true
55+
tf_vars = [
56+
{
57+
name = "anthropic_api_key"
58+
value = var.CODER_DOGFOOD_ANTHROPIC_API_KEY
59+
}
60+
]
4861
}
4962
]
5063
acl = {

0 commit comments

Comments
 (0)