Skip to content

Commit 8c43815

Browse files
committed
Add main files for Sourcegraph Amp module
1 parent 0fe4794 commit 8c43815

File tree

6 files changed

+339
-0
lines changed

6 files changed

+339
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
display_name: "harsh9485"
3+
bio: "Brief description of what you do"
4+
avatar: "./.images/avatar.png"
5+
website: "https://your-website.com"
6+
support_email: "[email protected]"
7+
status: "community"
8+
---
9+
10+
# Your Name
11+
12+
Brief description of who you are and what you do.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
display_name: sourcegraph_amp
3+
description: Describe what this module does
4+
icon: ../../../../.icons/sourcegraph-amp.svg
5+
verified: false
6+
tags: [helper]
7+
---
8+
9+
# sourcegraph_amp
10+
11+
<!-- Describes what this module does -->
12+
13+
```tf
14+
module "sourcegraph_amp" {
15+
count = data.coder_workspace.me.start_count
16+
source = "registry.coder.com/harsh9485/sourcegraph_amp/coder"
17+
version = "1.0.0"
18+
}
19+
```
20+
21+
<!-- Add a screencast or screenshot here put them in .images directory -->
22+
23+
## Examples
24+
25+
### Example 1
26+
27+
Install the Dracula theme from [OpenVSX](https://open-vsx.org/):
28+
29+
```tf
30+
module "sourcegraph_amp" {
31+
count = data.coder_workspace.me.start_count
32+
source = "registry.coder.com/NAMESPACE/sourcegraph_amp/coder"
33+
version = "1.0.0"
34+
agent_id = coder_agent.example.id
35+
extensions = [
36+
"dracula-theme.theme-dracula"
37+
]
38+
}
39+
```
40+
41+
Enter the `<author>.<name>` into the extensions array and code-server will automatically install on start.
42+
43+
### Example 2
44+
45+
Configure VS Code's [settings.json](https://code.visualstudio.com/docs/getstarted/settings#_settingsjson) file:
46+
47+
```tf
48+
module "sourcegraph_amp" {
49+
count = data.coder_workspace.me.start_count
50+
source = "registry.coder.com/NAMESPACE/sourcegraph_amp/coder"
51+
version = "1.0.0"
52+
agent_id = coder_agent.example.id
53+
extensions = ["dracula-theme.theme-dracula"]
54+
settings = {
55+
"workbench.colorTheme" = "Dracula"
56+
}
57+
}
58+
```
59+
60+
### Example 3
61+
62+
Run code-server in the background, don't fetch it from GitHub:
63+
64+
```tf
65+
module "sourcegraph_amp" {
66+
source = "registry.coder.com/NAMESPACE/sourcegraph_amp/coder"
67+
version = "1.0.0"
68+
agent_id = coder_agent.example.id
69+
offline = true
70+
}
71+
```
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { describe, it, expect } from "bun:test";
2+
import {
3+
runTerraformInit,
4+
runTerraformApply,
5+
testRequiredVariables,
6+
findResourceInstance,
7+
} from "~test";
8+
import path from "path";
9+
10+
const moduleDir = path.resolve(__dirname);
11+
const requiredVars = { agent_id: "dummy-agent-id" };
12+
13+
describe("sourcegraph-amp module", () => {
14+
it("initializes and applies without errors", async () => {
15+
await runTerraformInit(moduleDir);
16+
testRequiredVariables(moduleDir, requiredVars);
17+
18+
const state = await runTerraformApply(moduleDir, requiredVars);
19+
const script = findResourceInstance(state, "coder_script");
20+
21+
expect(script).toBeDefined();
22+
expect(script.agent_id).toBe(requiredVars.agent_id);
23+
expect(script.script).toContain("ARG_INSTALL_SOURCEGRAPH_AMP='true'");
24+
expect(script.script).toContain("ARG_AGENTAPI_VERSION='v0.3.0'");
25+
expect(script.script).toMatch(/\/tmp\/install\.sh/);
26+
expect(script.script).toMatch(/\/tmp\/start\.sh/);
27+
});
28+
});
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
coder = {
6+
source = "coder/coder"
7+
version = ">= 2.7"
8+
}
9+
}
10+
}
11+
12+
variable "agent_id" {
13+
type = string
14+
description = "The ID of a Coder agent."
15+
}
16+
17+
data "coder_workspace" "me" {}
18+
19+
data "coder_workspace_owner" "me" {}
20+
21+
22+
variable "order" {
23+
type = number
24+
description = "The order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order)."
25+
default = null
26+
}
27+
28+
variable "group" {
29+
type = string
30+
description = "The name of a group that this app belongs to."
31+
default = null
32+
}
33+
34+
variable "icon" {
35+
type = string
36+
description = "The icon to use for the app."
37+
default = "/icon/sourcegraph-amp.svg"
38+
}
39+
40+
variable "folder" {
41+
type = string
42+
description = "The folder to run sourcegraph-amp in."
43+
default = "/home/coder/sourcegraph-amp"
44+
}
45+
46+
variable "install_sourcegraph-amp" {
47+
type = bool
48+
description = "Whether to install sourcegraph-amp."
49+
default = true
50+
}
51+
52+
variable "sourcegraph-amp_api_key" {
53+
type = string
54+
description = "sourcegraph-amp API Key"
55+
default = ""
56+
}
57+
58+
resource "coder_env" "sourcegraph-amp_api_key" {
59+
agent_id = var.agent_id
60+
name = "SOURCEGRAPH_AMP_API_KEY"
61+
value = var.sourcegraph-amp_api_key
62+
}
63+
64+
variable "install_agentapi" {
65+
type = bool
66+
description = "Whether to install AgentAPI."
67+
default = true
68+
}
69+
70+
variable "agentapi_version" {
71+
type = string
72+
description = "The version of AgentAPI to install."
73+
default = "v0.3.0"
74+
}
75+
76+
variable "pre_install_script" {
77+
type = string
78+
description = "Custom script to run before installing sourcegraph-amp"
79+
default = null
80+
}
81+
82+
variable "post_install_script" {
83+
type = string
84+
description = "Custom script to run after installing sourcegraph-amp."
85+
default = null
86+
}
87+
88+
locals {
89+
base_extensions = <<-EOT
90+
{
91+
"coder": {
92+
"args": [
93+
"exp",
94+
"mcp",
95+
"server"
96+
],
97+
"command": "coder",
98+
"description": "Report ALL tasks and statuses (in progress, done, failed) you are working on.",
99+
"enabled": true,
100+
"env": {
101+
"CODER_MCP_APP_STATUS_SLUG": "${local.app_slug}",
102+
"CODER_MCP_AI_AGENTAPI_URL": "http://localhost:3284"
103+
},
104+
"name": "Coder",
105+
"timeout": 3000,
106+
"type": "stdio",
107+
"trust": true
108+
}
109+
}
110+
EOT
111+
112+
app_slug = "sourcegraph-amp"
113+
install_script = file("${path.module}/scripts/install.sh")
114+
start_script = file("${path.module}/scripts/start.sh")
115+
module_dir_name = ".sourcegraph-amp-module"
116+
}
117+
118+
module "agentapi" {
119+
source = "registry.coder.com/coder/agentapi/coder"
120+
version = "1.0.1"
121+
122+
agent_id = var.agent_id
123+
web_app_slug = local.app_slug
124+
web_app_order = var.order
125+
web_app_group = var.group
126+
web_app_icon = var.icon
127+
web_app_display_name = "Sourcegraph Amp"
128+
cli_app_slug = "${local.app_slug}-cli"
129+
cli_app_display_name = "Sourcegraph Amp CLI"
130+
module_dir_name = local.module_dir_name
131+
install_agentapi = var.install_agentapi
132+
agentapi_version = var.agentapi_version
133+
pre_install_script = var.pre_install_script
134+
post_install_script = var.post_install_script
135+
start_script = <<-EOT
136+
#!/bin/bash
137+
set -o errexit
138+
set -o pipefail
139+
140+
echo -n '${base64encode(local.start_script)}' | base64 -d > /tmp/start.sh
141+
chmod +x /tmp/start.sh
142+
SOURCEGRAPH_AMP_API_KEY='${var.sourcegraph-amp_api_key}' \
143+
SOURCEGRAPH_AMP_START_DIRECTORY='${var.folder}' \
144+
/tmp/start.sh
145+
EOT
146+
147+
install_script = <<-EOT
148+
#!/bin/bash
149+
set -o errexit
150+
set -o pipefail
151+
152+
echo -n '${base64encode(local.install_script)}' | base64 -d > /tmp/install.sh
153+
chmod +x /tmp/install.sh
154+
ARG_INSTALL_SOURCEGRAPH_AMP='${var.install_sourcegraph-amp}' \
155+
SOURCEGRAPH_AMP_START_DIRECTORY='${var.folder}' \
156+
SOURCEGRAPH_AMP_API_KEY='${var.sourcegraph-amp_api_key}' \
157+
BASE_EXTENSIONS='${replace(local.base_extensions, "'", "'\\''")}' \
158+
/tmp/install.sh
159+
EOT
160+
}
161+
162+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# ANSI colors
5+
BOLD='\033[1m'
6+
RESET='\033[0m'
7+
8+
# Print arguments
9+
echo "--------------------------------"
10+
echo "Install flag: $ARG_INSTALL_SOURCEGRAPH_AMP"
11+
echo "Workspace: $SOURCEGRAPH_AMP_START_DIRECTORY"
12+
echo "--------------------------------"
13+
14+
# Check for npm/node and install via nvm if missing
15+
function ensure_node() {
16+
if ! command -v npm &>/dev/null; then
17+
echo "npm not found. Installing Node.js via NVM..."
18+
export NVM_DIR="$HOME/.nvm"
19+
mkdir -p "$NVM_DIR"
20+
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
21+
# shellcheck source=/dev/null
22+
source "$NVM_DIR/nvm.sh"
23+
nvm install --lts
24+
nvm alias default node
25+
fi
26+
}
27+
28+
function install_sourcegraph_amp() {
29+
if [[ "$ARG_INSTALL_SOURCEGRAPH_AMP" == "true" ]]; then
30+
ensure_node
31+
printf "%b Installing Sourcegraph AMP CLI...%b\n" "$BOLD" "$RESET"
32+
npm install -g @sourcegraph/amp
33+
export AMP_API_KEY="$SOURCEGRAPH_AMP_API_KEY"
34+
printf "%b Installation complete.%b\n" "$BOLD" "$RESET"
35+
fi
36+
}
37+
38+
install_sourcegraph_amp
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Load user environment
5+
# shellcheck source=/dev/null
6+
source "$HOME/.bashrc"
7+
# shellcheck source=/dev/null
8+
source "$HOME/.nvm/nvm.sh"
9+
10+
function ensure_command() {
11+
command -v "$1" &>/dev/null || { echo "Error: '$1' not found." >&2; exit 1; }
12+
}
13+
14+
ensure_command amp
15+
echo "AMP version: $(amp --version)"
16+
17+
18+
dir="$SOURCEGRAPH_AMP_START_DIRECTORY"
19+
if [[ -d "$dir" ]]; then
20+
echo "Using existing directory: $dir"
21+
else
22+
echo "Creating directory: $dir"
23+
mkdir -p "$dir"
24+
fi
25+
cd "$dir"
26+
27+
# Launch AgentAPI server with AMP
28+
agentapi server --term-width=67 --term-height=1190 -- amp

0 commit comments

Comments
 (0)