Harsh Singh Panwar 545a245530
feat: Sourcegraph Amp module (#257)
Closes #238
/claim #238 

## Description

Video -
https://www.loom.com/share/59e80a7fa3e54973bb0318132bc849a7?sid=4900077a-6fdb-4760-978c-9ad2e2daa9d8
 
<img width="1365" height="599" alt="Screenshot 2025-08-02 164234"
src="https://github.com/user-attachments/assets/56ec7dc3-bc41-4976-9b78-3d6c011d80fe"
/>

<!-- Briefly describe what this PR does and why -->

## Type of Change

- [x] New module
- [ ] Bug fix
- [ ] Feature/enhancement
- [ ] Documentation
- [ ] Other

## Module Information

<!-- Delete this section if not applicable -->

**Path:** `registry/harsh9485]/modules/sourcegraph_amp`  
**New version:** `v1.0.0`  
**Breaking change:** [ ] Yes [x] No

## Testing & Validation

- [x] Tests pass (`bun test`)
- [x] Code formatted (`bun run fmt`)
- [x] Changes tested locally

## Related Issues

<!-- Link related issues or write "None" if not applicable -->

---------

Co-authored-by: Atif Ali <atif@coder.com>
Co-authored-by: DevCats <christofer@coder.com>
2025-08-19 15:25:17 -05:00
..
2025-08-19 15:25:17 -05:00
2025-08-19 15:25:17 -05:00

display_name icon description verified tags
Sourcegraph AMP ../../../../.icons/sourcegraph-amp.svg Run Sourcegraph AMP CLI in your workspace with AgentAPI integration false
agent
sourcegraph
amp
ai
tasks

Sourcegraph AMP CLI

Run Sourcegraph AMP CLI in your workspace to access Sourcegraph's AI-powered code search and analysis tools, with AgentAPI integration for seamless Coder Tasks support.

module "sourcegraph_amp" {
  source                  = "registry.coder.com/coder-labs/sourcegraph_amp/coder"
  version                 = "1.0.0"
  agent_id                = coder_agent.example.id
  sourcegraph_amp_api_key = var.sourcegraph_amp_api_key
  install_sourcegraph_amp = true
  agentapi_version        = "latest"
}

Prerequisites

  • Include the Coder Login module in your template
  • Node.js and npm are automatically installed (via NVM) if not already available

Usage Example

data "coder_parameter" "ai_prompt" {
  name        = "AI Prompt"
  description = "Write an initial prompt for AMP to work on."
  type        = "string"
  default     = ""
  mutable     = true

}

# Set system prompt for Sourcegraph Amp via environment variables
resource "coder_agent" "main" {
  # ...
  env = {
    SOURCEGRAPH_AMP_SYSTEM_PROMPT = <<-EOT
      You are an AMP assistant that helps developers debug and write code efficiently.

      Always log task status to Coder.
    EOT
    SOURCEGRAPH_AMP_TASK_PROMPT   = data.coder_parameter.ai_prompt.value
  }
}

variable "sourcegraph_amp_api_key" {
  type        = string
  description = "Sourcegraph AMP API key"
  sensitive   = true
}

module "sourcegraph_amp" {
  count                   = data.coder_workspace.me.start_count
  source                  = "registry.coder.com/coder-labs/sourcegraph_amp/coder"
  version                 = "1.0.0"
  agent_id                = coder_agent.example.id
  sourcegraph_amp_api_key = var.sourcegraph_amp_api_key # recommended for authenticated usage
  install_sourcegraph_amp = true
}

How it Works

  • Install: Installs Sourcegraph AMP CLI using npm (installs Node.js via NVM if required)
  • Start: Launches AMP CLI in the specified directory, wrapped with AgentAPI to enable tasks and AI interactions
  • Environment Variables: Sets SOURCEGRAPH_AMP_API_KEY and SOURCEGRAPH_AMP_START_DIRECTORY for the CLI execution

Troubleshooting

  • If amp is not found, ensure install_sourcegraph_amp = true and your API key is valid
  • Logs are written under /home/coder/.sourcegraph-amp-module/ (install.log, agentapi-start.log) for debugging
  • If AgentAPI fails to start, verify that your container has network access and executable permissions for the scripts

Important

For using Coder Tasks with Sourcegraph AMP, make sure to pass the AI Prompt parameter and set sourcegraph_amp_api_key. This ensures task reporting and status updates work seamlessly.

References