Skip to content

feat: Sourcegraph Amp module #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8c43815
Add main files for Sourcegraph Amp module
Harsh9485 Jul 29, 2025
e233738
Merge branch 'main' into sourcegraph-amp-module
matifali Jul 29, 2025
807650f
LF-error-solved
Harsh9485 Jul 31, 2025
83b002a
Merge branch 'sourcegraph-amp-module' of github.com:Harsh9485/registr…
Harsh9485 Jul 31, 2025
1690b53
Merge branch 'coder:main' into sourcegraph-amp-module
Harsh9485 Aug 2, 2025
a42eee5
Add README file for the module
Harsh9485 Aug 2, 2025
f724c39
Merge branch 'sourcegraph-amp-module' of github.com:Harsh9485/registr…
Harsh9485 Aug 2, 2025
667b1c1
Add test suite
Harsh9485 Aug 4, 2025
ba37d2c
Merge branch 'coder:main' into sourcegraph-amp-module
Harsh9485 Aug 4, 2025
e24a327
Merge branch 'coder:main' into sourcegraph-amp-module
Harsh9485 Aug 4, 2025
99b0f23
Merge branch 'coder:main' into sourcegraph-amp-module
Harsh9485 Aug 5, 2025
a93874b
Merge branch 'coder:main' into sourcegraph-amp-module
Harsh9485 Aug 6, 2025
b32dd64
Add support for the system prompt
Harsh9485 Aug 6, 2025
4d513bd
Merge branch 'sourcegraph-amp-module' of github.com:Harsh9485/registr…
Harsh9485 Aug 6, 2025
48bdcce
Merge branch 'coder:main' into sourcegraph-amp-module
Harsh9485 Aug 6, 2025
14bc314
Merge branch 'coder:main' into sourcegraph-amp-module
Harsh9485 Aug 8, 2025
2e5fd30
Fix DNS limitation issue
Harsh9485 Aug 8, 2025
7432ac8
Merge branch 'sourcegraph-amp-module' of github.com:Harsh9485/registr…
Harsh9485 Aug 8, 2025
ffd9484
Merge branch 'main' into sourcegraph-amp-module
DevelopmentCats Aug 8, 2025
dc60cc7
Add task prompt support
Harsh9485 Aug 9, 2025
668d7f8
Add task prompt support
Harsh9485 Aug 9, 2025
05ff1d0
Merge branch 'main' into sourcegraph-amp-module
DevelopmentCats Aug 11, 2025
ea70ea7
Merge branch 'main' into sourcegraph-amp-module
Harsh9485 Aug 12, 2025
88613b6
Fix all typos and the test suite.
Harsh9485 Aug 12, 2025
1a36efd
Merge branch 'sourcegraph-amp-module' of github.com:Harsh9485/registr…
Harsh9485 Aug 12, 2025
dcb3e65
Add an avatar and a README file
Harsh9485 Aug 12, 2025
4667254
fix typos
Harsh9485 Aug 12, 2025
55080f7
Merge branch 'main' into sourcegraph-amp-module
DevelopmentCats Aug 13, 2025
90af1e7
Fix Readme file
Harsh9485 Aug 13, 2025
f3c68a4
Merge branch 'main' into sourcegraph-amp-module
DevelopmentCats Aug 13, 2025
30c1577
Merge branch 'coder:main' into sourcegraph-amp-module
Harsh9485 Aug 13, 2025
66a82ed
Move module into coder-labs
Harsh9485 Aug 13, 2025
223a0bb
Fix README file typo
Harsh9485 Aug 13, 2025
6b3e710
Remove old references
Harsh9485 Aug 13, 2025
8248866
Merge branch 'coder:main' into sourcegraph-amp-module
Harsh9485 Aug 14, 2025
5003a08
Fix typo
Harsh9485 Aug 14, 2025
a37fbe4
Remove reference directory
Harsh9485 Aug 14, 2025
42a594b
Implement MCP server
Harsh9485 Aug 15, 2025
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
7 changes: 7 additions & 0 deletions .icons/sourcegraph-amp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 90 additions & 0 deletions registry/coder-labs/modules/sourcegraph_amp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
display_name: Sourcegraph AMP
icon: ../../../../.icons/sourcegraph_amp.svg
description: Run Sourcegraph AMP CLI in your workspace with AgentAPI integration
verified: false
tags: [agent, sourcegraph, amp, ai, tasks]
---

# Sourcegraph AMP CLI

Run [Sourcegraph AMP CLI](https://sourcegraph.com/amp) in your workspace to access Sourcegraph's AI-powered code search and analysis tools, with AgentAPI integration for seamless Coder Tasks support.

```tf
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](https://registry.coder.com/modules/coder-login/coder) module in your template
- Node.js and npm are automatically installed (via NVM) if not already available

## Usage Example

```tf
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

- [Sourcegraph AMP Documentation](https://ampcode.com/manual)
- [AgentAPI Documentation](https://github.com/coder/agentapi)
- [Coder AI Agents Guide](https://coder.com/docs/tutorials/ai-agents)
139 changes: 139 additions & 0 deletions registry/coder-labs/modules/sourcegraph_amp/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import {
test,
afterEach,
describe,
setDefaultTimeout,
beforeAll,
expect,
} from "bun:test";
import { execContainer, readFileContainer, runTerraformInit } from "~test";
import {
loadTestFile,
writeExecutable,
setup as setupUtil,
execModuleScript,
expectAgentAPIStarted,
} from "../../../coder/modules/agentapi/test-util";

let cleanupFunctions: (() => Promise<void>)[] = [];
const registerCleanup = (cleanup: () => Promise<void>) => {
cleanupFunctions.push(cleanup);
};
afterEach(async () => {
const cleanupFnsCopy = cleanupFunctions.slice().reverse();
cleanupFunctions = [];
for (const cleanup of cleanupFnsCopy) {
try {
await cleanup();
} catch (error) {
console.error("Error during cleanup:", error);
}
}
});

interface SetupProps {
skipAgentAPIMock?: boolean;
skipAmpMock?: boolean;
moduleVariables?: Record<string, string>;
agentapiMockScript?: string;
}

const setup = async (props?: SetupProps): Promise<{ id: string }> => {
const projectDir = "/home/coder/project";
const { id } = await setupUtil({
moduleDir: import.meta.dir,
moduleVariables: {
install_sourcegraph_amp: props?.skipAmpMock ? "true" : "false",
install_agentapi: props?.skipAgentAPIMock ? "true" : "false",
sourcegraph_amp_model: "test-model",
...props?.moduleVariables,
},
registerCleanup,
projectDir,
skipAgentAPIMock: props?.skipAgentAPIMock,
agentapiMockScript: props?.agentapiMockScript,
});

// Place the AMP mock CLI binary inside the container
if (!props?.skipAmpMock) {
await writeExecutable({
containerId: id,
filePath: "/usr/bin/amp",
content: await loadTestFile(`${import.meta.dir}`, "amp-mock.sh"),
});
}

return { id };
};

setDefaultTimeout(60 * 1000);

describe("sourcegraph-amp", async () => {
beforeAll(async () => {
await runTerraformInit(import.meta.dir);
});

test("happy-path", async () => {
const { id } = await setup();
await execModuleScript(id);
await expectAgentAPIStarted(id);
});

test("api-key", async () => {
const apiKey = "test-api-key-123";
const { id } = await setup({
moduleVariables: {
sourcegraph_amp_api_key: apiKey,
},
});
await execModuleScript(id);
const resp = await readFileContainer(id, "/home/coder/.sourcegraph-amp-module/agentapi-start.log");
expect(resp).toContain("sourcegraph_amp_api_key provided !");
});

test("custom-folder", async () => {
const folder = "/tmp/sourcegraph-amp-test";
const { id } = await setup({
moduleVariables: {
folder,
},
});
await execModuleScript(id);
const resp = await readFileContainer(id, "/home/coder/.sourcegraph-amp-module/install.log");
expect(resp).toContain(folder);
});

test("pre-post-install-scripts", async () => {
const { id } = await setup({
moduleVariables: {
pre_install_script: "#!/bin/bash\necho 'pre-install-script'",
post_install_script: "#!/bin/bash\necho 'post-install-script'",
},
});
await execModuleScript(id);
const preLog = await readFileContainer(id, "/home/coder/.sourcegraph-amp-module/pre_install.log");
expect(preLog).toContain("pre-install-script");
const postLog = await readFileContainer(id, "/home/coder/.sourcegraph-amp-module/post_install.log");
expect(postLog).toContain("post-install-script");
});

test("system-prompt", async () => {
const prompt = "this is a system prompt for AMP";
const {id} = await setup();
await execModuleScript(id, {
SOURCEGRAPH_AMP_SYSTEM_PROMPT : prompt,
});
const resp = await readFileContainer(id, "/home/coder/.sourcegraph-amp-module/SYSTEM_PROMPT.md");
expect(resp).toContain(prompt);
});

test("task-prompt", async () => {
const prompt = "this is a task prompt for AMP";
const {id} = await setup();
await execModuleScript(id, {
SOURCEGRAPH_AMP_TASK_PROMPT : prompt,
});
const resp = await readFileContainer(id, "/home/coder/.sourcegraph-amp-module/agentapi-start.log");
expect(resp).toContain(`sourcegraph amp task prompt provided : ${prompt}`);
})
});
Loading