-
Notifications
You must be signed in to change notification settings - Fork 46
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
Harsh9485
wants to merge
30
commits into
coder:main
Choose a base branch
from
Harsh9485:sourcegraph-amp-module
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+549
−0
Open
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
8c43815
Add main files for Sourcegraph Amp module
Harsh9485 e233738
Merge branch 'main' into sourcegraph-amp-module
matifali 807650f
LF-error-solved
Harsh9485 83b002a
Merge branch 'sourcegraph-amp-module' of github.com:Harsh9485/registr…
Harsh9485 1690b53
Merge branch 'coder:main' into sourcegraph-amp-module
Harsh9485 a42eee5
Add README file for the module
Harsh9485 f724c39
Merge branch 'sourcegraph-amp-module' of github.com:Harsh9485/registr…
Harsh9485 667b1c1
Add test suite
Harsh9485 ba37d2c
Merge branch 'coder:main' into sourcegraph-amp-module
Harsh9485 e24a327
Merge branch 'coder:main' into sourcegraph-amp-module
Harsh9485 99b0f23
Merge branch 'coder:main' into sourcegraph-amp-module
Harsh9485 a93874b
Merge branch 'coder:main' into sourcegraph-amp-module
Harsh9485 b32dd64
Add support for the system prompt
Harsh9485 4d513bd
Merge branch 'sourcegraph-amp-module' of github.com:Harsh9485/registr…
Harsh9485 48bdcce
Merge branch 'coder:main' into sourcegraph-amp-module
Harsh9485 14bc314
Merge branch 'coder:main' into sourcegraph-amp-module
Harsh9485 2e5fd30
Fix DNS limitation issue
Harsh9485 7432ac8
Merge branch 'sourcegraph-amp-module' of github.com:Harsh9485/registr…
Harsh9485 ffd9484
Merge branch 'main' into sourcegraph-amp-module
DevelopmentCats dc60cc7
Add task prompt support
Harsh9485 668d7f8
Add task prompt support
Harsh9485 05ff1d0
Merge branch 'main' into sourcegraph-amp-module
DevelopmentCats ea70ea7
Merge branch 'main' into sourcegraph-amp-module
Harsh9485 88613b6
Fix all typos and the test suite.
Harsh9485 1a36efd
Merge branch 'sourcegraph-amp-module' of github.com:Harsh9485/registr…
Harsh9485 dcb3e65
Add an avatar and a README file
Harsh9485 4667254
fix typos
Harsh9485 55080f7
Merge branch 'main' into sourcegraph-amp-module
DevelopmentCats 90af1e7
Fix Readme file
Harsh9485 f3c68a4
Merge branch 'main' into sourcegraph-amp-module
DevelopmentCats File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
display_name: "Harsh Panwar" | ||
bio: "I'm a Software Engineer :)" | ||
avatar: "./.images/avatar.jpeg" | ||
github: "Harsh9485" | ||
linkedin: "https://www.linkedin.com/in/harsh-panwar-674884257" | ||
support_email: "[email protected]" | ||
status: "community" | ||
--- | ||
|
||
# Your Name | ||
|
||
I'm a Software Engineer :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: true | ||
Harsh9485 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tags: \[agent, sourcegraph, amp, ai, tasks] | ||
Harsh9485 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--- | ||
|
||
# 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/harsh9485/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 Aider to work on." | ||
Harsh9485 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type = "string" | ||
default = "" | ||
mutable = true | ||
ephemeral = true | ||
Harsh9485 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
# 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/harsh9485/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. | ||
Harsh9485 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
## References | ||
|
||
- [Sourcegraph AMP Documentation](https://sourcegraph.com/amp) | ||
Harsh9485 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- [AgentAPI Documentation](https://github.com/coder/agentapi) | ||
- [Coder AI Agents Guide](https://coder.com/docs/tutorials/ai-agents) |
139 changes: 139 additions & 0 deletions
139
registry/harsh9485/modules/sourcegraph_amp/main.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/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}`); | ||
}) | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.