feat: add Amp (Sourcegraph) as first-class agent with SDK + CLI support - #291
Conversation
- Add 'amp' to AgentType union and AGENTS config (#235) - Implement runAmpAgent() using @sourcegraph/amp-sdk execute() async generator - Add CLI fallback via amp --execute --stream-json for environments without SDK - Add --amp-mode flag (smart/rush/deep) for agent mode selection (#238) - Wire ampMode through CLI → RunCommandOptions → LoopOptions → AgentRunOptions (#236) - Export AmpMode type from package index for SDK consumers - Amp ranked 2nd in agent preference (after Claude Code) - Update tests for 6-agent detection and amp preference order Closes #234, #235, #236, #238 Amp-Thread-ID: https://ampcode.com/threads/T-019ce298-ab61-760e-b725-803364016be5 Co-authored-by: Amp <amp@ampcode.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
✔️ Bundle Size Analysis
Bundle breakdown |
Greptile SummaryThis PR integrates Amp by Sourcegraph as a first-class agent in ralph-starter, adding an SDK-first execution path ( Key issues found:
Confidence Score: 3/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[runAgent - agent.type === 'amp'] --> B[runAmpAgent]
B --> C{import '@sourcegraph/amp-sdk'}
C -- success --> D[SDK Path\nampSdk.execute async generator]
C -- ImportError --> E[CLI Fallback\nrunAmpCli]
D --> F[for await message of execute]
F --> G[onOutput / streamOutput callbacks]
G --> H{outputBytes > maxOutputBytes?}
H -- yes --> I[Trim output to 80%\nRecalculate outputBytes]
H -- no --> J[Continue]
I --> J
J --> K{message.type === 'result'?}
K -- error --> L[Return exitCode: 1]
K -- success --> M[Return exitCode: 0]
K -- no --> F
E --> N[spawn amp --execute --stream-json]
N --> O[stdout data handler]
O --> P{outputBytes > maxOutputBytes?}
P -- yes --> Q[Trim output / Reset counter\n⚠ chunk appended AFTER reset]
P -- no --> R[output += chunk]
Q --> R
R --> S[Parse NDJSON lines → onOutput]
N --> T[setTimeout SIGTERM at timeoutMs]
T --> U[Return exitCode: 124]
N --> V[close event → exitCode]
|
- Fix dangerouslyAllowAll defaulting to true → false (security) - Register --amp-mode flag on auto and template commands - Add maxOutputBytes truncation guard to runAmpCli Amp-Thread-ID: https://ampcode.com/threads/T-019ce298-ab61-760e-b725-803364016be5 Co-authored-by: Amp <amp@ampcode.com>
- Add maxOutputBytes truncation guard to runAmpAgent SDK path - Move @sourcegraph/amp-sdk to optionalDependencies to avoid bundling Amp CLI binary for all users and prevent false-positive agent detection - Return exit code 124 on timeout (TimeoutError/AbortError) in SDK path, matching CLI path and runAgent behavior Amp-Thread-ID: https://ampcode.com/threads/T-019ce298-ab61-760e-b725-803364016be5 Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019ce298-ab61-760e-b725-803364016be5 Co-authored-by: Amp <amp@ampcode.com>
- Pass options.env to SDK execute() (SDK supports env natively) - Replace curl|bash install hint with npm install -g @sourcegraph/amp Amp-Thread-ID: https://ampcode.com/threads/T-019ce298-ab61-760e-b725-803364016be5 Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019ce298-ab61-760e-b725-803364016be5 Co-authored-by: Amp <amp@ampcode.com>
Summary
Adds Amp by Sourcegraph as a first-class agent in ralph-starter, using the native
@sourcegraph/amp-sdkfor TypeScript integration with a CLI fallback.Changes
Agent Abstraction (#235)
amptoAgentTypeunion andAGENTSconfig objectamp --versionExecutor / Tool-use (#236)
runAmpAgent()— uses@sourcegraph/amp-sdkexecute()async generator with structured message streaming,AbortSignaltimeout, and error handlingrunAmpCli()— CLI fallback usingamp --execute --stream-json --dangerously-allow-allfor environments without the SDK installedonOutputcallback contract for step detectionConfig + CLI Flags (#238)
--agent ampflag acrossrun,auto,fix,figma, andtemplatecommands--amp-mode <smart|rush|deep>flag for agent mode selectionAmpModetype exported from package index for SDK consumersRunCommandOptions→LoopOptions→AgentRunOptionsTests
Usage
Auth
Amp SDK uses
AMP_API_KEYenv var (access token from ampcode.com/settings). No browser-based OAuth needed for programmatic use.Closes #234, #235, #236, #238