Skip to content

Commit 88613b6

Browse files
committed
Fix all typos and the test suite.
1 parent 668d7f8 commit 88613b6

File tree

5 files changed

+65
-45
lines changed

5 files changed

+65
-45
lines changed
Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
2-
32
display\_name: Sourcegraph AMP
4-
icon: ../../../../.icons/sourcegraph-amp.svg
3+
icon: ../../../../.icons/sourcegraph_amp.svg
54
description: Run Sourcegraph AMP CLI in your workspace with AgentAPI integration
65
verified: true
76
tags: \[agent, sourcegraph, amp, ai, tasks]
@@ -13,19 +12,19 @@ Run [Sourcegraph AMP CLI](https://sourcegraph.com/amp) in your workspace to acce
1312

1413
```tf
1514
module "sourcegraph_amp" {
16-
source = "registry.coder.com/harsh9485/sourcegraph-amp/coder"
15+
source = "registry.coder.com/harsh9485/sourcegraph_amp/coder"
1716
version = "1.0.0"
1817
agent_id = coder_agent.example.id
1918
sourcegraph_amp_api_key = var.sourcegraph_amp_api_key
20-
install_sourcegraph-amp = true
19+
install_sourcegraph_amp = true
2120
agentapi_version = "latest"
2221
}
2322
```
2423

2524
## Prerequisites
2625

27-
* Include the [Coder Login](https://registry.coder.com/modules/coder-login/coder) module in your template
28-
* Node.js and npm are automatically installed (via NVM) if not already available
26+
- Include the [Coder Login](https://registry.coder.com/modules/coder-login/coder) module in your template
27+
- Node.js and npm are automatically installed (via NVM) if not already available
2928

3029
## Usage Example
3130

@@ -48,7 +47,7 @@ resource "coder_agent" "main" {
4847
4948
Always log task status to Coder.
5049
EOT
51-
SOURCEGRAPH_AMP_TASK_PROMPT = data.coder_parameter.ai_prompt.value
50+
SOURCEGRAPH_AMP_TASK_PROMPT = data.coder_parameter.ai_prompt.value
5251
}
5352
}
5453
@@ -59,33 +58,33 @@ variable "sourcegraph_amp_api_key" {
5958
}
6059
6160
module "sourcegraph_amp" {
62-
count = data.coder_workspace.me.start_count
63-
source = "registry.coder.com/harsh9485/sourcegraph-amp/coder"
64-
version = "1.0.0"
65-
agent_id = coder_agent.example.id
66-
sourcegraph_amp_api_key = var.sourcegraph_amp_api_key # recommended for authenticated usage
67-
install_sourcegraph-amp = true
61+
count = data.coder_workspace.me.start_count
62+
source = "registry.coder.com/harsh9485/sourcegraph_amp/coder"
63+
version = "1.0.0"
64+
agent_id = coder_agent.example.id
65+
sourcegraph_amp_api_key = var.sourcegraph_amp_api_key # recommended for authenticated usage
66+
install_sourcegraph_amp = true
6867
}
6968
```
7069

7170
## How it Works
7271

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

7776
## Troubleshooting
7877

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

8382
> \[!IMPORTANT]
8483
> For using **Coder Tasks** with Sourcegraph AMP, make sure to pass the `AI Prompt` parameter and set `sourcegraph_amp_api_key`.
8584
> This ensures task reporting and status updates work seamlessly.
8685
8786
## References
8887

89-
* [Sourcegraph AMP Documentation](https://sourcegraph.com/amp)
90-
* [AgentAPI Documentation](https://github.com/coder/agentapi)
91-
* [Coder AI Agents Guide](https://coder.com/docs/tutorials/ai-agents)
88+
- [Sourcegraph AMP Documentation](https://sourcegraph.com/amp)
89+
- [AgentAPI Documentation](https://github.com/coder/agentapi)
90+
- [Coder AI Agents Guide](https://coder.com/docs/tutorials/ai-agents)

registry/harsh9485/modules/sourcegraph_amp/main.test.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const setup = async (props?: SetupProps): Promise<{ id: string }> => {
6868

6969
setDefaultTimeout(60 * 1000);
7070

71-
describe("Sourcegraph AMP Module", async () => {
71+
describe("sourcegraph-amp", async () => {
7272
beforeAll(async () => {
7373
await runTerraformInit(import.meta.dir);
7474
});
@@ -79,7 +79,7 @@ describe("Sourcegraph AMP Module", async () => {
7979
await expectAgentAPIStarted(id);
8080
});
8181

82-
test("sourcegraph-amp-api-key", async () => {
82+
test("api-key", async () => {
8383
const apiKey = "test-api-key-123";
8484
const { id } = await setup({
8585
moduleVariables: {
@@ -88,7 +88,7 @@ describe("Sourcegraph AMP Module", async () => {
8888
});
8989
await execModuleScript(id);
9090
const resp = await readFileContainer(id, "/home/coder/.sourcegraph-amp-module/agentapi-start.log");
91-
expect(resp).toContain("AMP version: AMP CLI mock version v1.0.0");
91+
expect(resp).toContain("sourcegraph_amp_api_key provided !");
9292
});
9393

9494
test("custom-folder", async () => {
@@ -117,10 +117,23 @@ describe("Sourcegraph AMP Module", async () => {
117117
expect(postLog).toContain("post-install-script");
118118
});
119119

120-
test("amp-not-installed", async () => {
121-
const { id } = await setup({ skipAmpMock: true });
122-
await execModuleScript(id);
123-
const log = await readFileContainer(id, "/home/coder/.sourcegraph-amp-module/install.log");
124-
expect(log).toContain("Error");
120+
test("system-prompt", async () => {
121+
const prompt = "this is a system prompt for AMP";
122+
const {id} = await setup();
123+
await execModuleScript(id, {
124+
SOURCEGRAPH_AMP_SYSTEM_PROMPT : prompt,
125+
});
126+
const resp = await readFileContainer(id, "/home/coder/.sourcegraph-amp/SYSTEM_PROMPT.md");
127+
expect(resp).toContain(prompt);
125128
});
129+
130+
test("task-prompt", async () => {
131+
const prompt = "this is a task prompt for AMP";
132+
const {id} = await setup();
133+
await execModuleScript(id, {
134+
SOURCEGRAPH_AMP_TASK_PROMPT : prompt,
135+
});
136+
const resp = await readFileContainer(id, "/home/coder/.sourcegraph-amp-module/agentapi-start.log");
137+
expect(resp).toContain(`sourcegraph amp task prompt provided : ${prompt}`);
138+
})
126139
});

registry/harsh9485/modules/sourcegraph_amp/main.tf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,26 @@ variable "icon" {
3838

3939
variable "folder" {
4040
type = string
41-
description = "The folder to run sourcegraph-amp in."
41+
description = "The folder to run sourcegraph_amp in."
4242
default = "/home/coder"
4343
}
4444

45-
variable "install_sourcegraph-amp" {
45+
variable "install_sourcegraph_amp" {
4646
type = bool
4747
description = "Whether to install sourcegraph-amp."
4848
default = true
4949
}
5050

51-
variable "sourcegraph-amp_api_key" {
51+
variable "sourcegraph_amp_api_key" {
5252
type = string
5353
description = "sourcegraph-amp API Key"
5454
default = ""
5555
}
5656

57-
resource "coder_env" "sourcegraph-amp_api_key" {
57+
resource "coder_env" "sourcegraph_amp_api_key" {
5858
agent_id = var.agent_id
5959
name = "SOURCEGRAPH_AMP_API_KEY"
60-
value = var.sourcegraph-amp_api_key
60+
value = var.sourcegraph_amp_api_key
6161
}
6262

6363
variable "install_agentapi" {
@@ -74,13 +74,13 @@ variable "agentapi_version" {
7474

7575
variable "pre_install_script" {
7676
type = string
77-
description = "Custom script to run before installing sourcegraph-amp"
77+
description = "Custom script to run before installing sourcegraph_amp"
7878
default = null
7979
}
8080

8181
variable "post_install_script" {
8282
type = string
83-
description = "Custom script to run after installing sourcegraph-amp."
83+
description = "Custom script to run after installing sourcegraph_amp."
8484
default = null
8585
}
8686

@@ -138,7 +138,7 @@ module "agentapi" {
138138
139139
echo -n '${base64encode(local.start_script)}' | base64 -d > /tmp/start.sh
140140
chmod +x /tmp/start.sh
141-
SOURCEGRAPH_AMP_API_KEY='${var.sourcegraph-amp_api_key}' \
141+
SOURCEGRAPH_AMP_API_KEY='${var.sourcegraph_amp_api_key}' \
142142
SOURCEGRAPH_AMP_START_DIRECTORY='${var.folder}' \
143143
/tmp/start.sh
144144
EOT
@@ -150,7 +150,7 @@ module "agentapi" {
150150
151151
echo -n '${base64encode(local.install_script)}' | base64 -d > /tmp/install.sh
152152
chmod +x /tmp/install.sh
153-
ARG_INSTALL_SOURCEGRAPH_AMP='${var.install_sourcegraph-amp}' \
153+
ARG_INSTALL_SOURCEGRAPH_AMP='${var.install_sourcegraph_amp}' \
154154
SOURCEGRAPH_AMP_START_DIRECTORY='${var.folder}' \
155155
BASE_EXTENSIONS='${replace(local.base_extensions, "'", "'\\''")}' \
156156
/tmp/install.sh

registry/harsh9485/modules/sourcegraph_amp/scripts/install.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ function install_sourcegraph_amp() {
6060

6161
printf "%s Installing Sourcegraph AMP CLI...\n" "${BOLD}"
6262
npm install -g @sourcegraph/[email protected]
63-
export AMP_API_KEY="$SOURCEGRAPH_AMP_API_KEY"
6463
printf "%s Successfully installed Sourcegraph AMP CLI. Version: %s\n" "${BOLD}" "$(amp --version)"
6564
fi
6665
}

registry/harsh9485/modules/sourcegraph_amp/scripts/start.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ set -euo pipefail
55
# shellcheck source=/dev/null
66
source "$HOME/.bashrc"
77
# shellcheck source=/dev/null
8-
source "$HOME/.nvm/nvm.sh"
8+
if [ -f "$HOME/.nvm/nvm.sh" ]; then
9+
source "$HOME"/.nvm/nvm.sh
10+
else
11+
export PATH="$HOME/.npm-global/bin:$PATH"
12+
fi
913

1014
function ensure_command() {
1115
command -v "$1" &>/dev/null || { echo "Error: '$1' not found." >&2; exit 1; }
@@ -23,11 +27,16 @@ else
2327
mkdir -p "$dir"
2428
fi
2529
cd "$dir"
26-
echo "Add AMP API key"
27-
export AMP_API_KEY=$SOURCEGRAPH_AMP_API_KEY
2830

29-
if [ -n "$SOURCEGRAPH_AMP_TASK_PROMPT" ]; then
30-
printf "Running the task prompt: %s\n" "$SOURCEGRAPH_AMP_TASK_PROMPT"
31+
if [ -n "$SOURCEGRAPH_AMP_API_KEY" ]; then
32+
printf "sourcegraph_amp_api_key provided !\n"
33+
export AMP_API_KEY=$SOURCEGRAPH_AMP_API_KEY
34+
else
35+
printf "sourcegraph_amp_api_key not provided\n"
36+
fi
37+
38+
if [ -n "${SOURCEGRAPH_AMP_TASK_PROMPT:-}" ]; then
39+
printf "sourcegraph amp task prompt provided : $SOURCEGRAPH_AMP_TASK_PROMPT"
3140
PROMPT="Every step of the way, report tasks to Coder with proper descriptions and statuses. Your task at hand: $SOURCEGRAPH_AMP_TASK_PROMPT"
3241

3342
# Pipe the prompt into amp, which will be run inside agentapi

0 commit comments

Comments
 (0)