Skip to content

Commit d4d20af

Browse files
committed
add container deps and gracefully handle nonzero amp exit codes
1 parent 85a4d12 commit d4d20af

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ RUN pnpm run build
1515
# Runtime stage
1616
FROM node:20-alpine
1717

18+
# Install GNU coreutils for full env support (needed by npx/Amp CLI)
19+
RUN apk add --no-cache coreutils
20+
1821
RUN corepack enable
1922
WORKDIR /app
2023

src/amp.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,40 @@ export async function execute(options: ExecuteCommandOptions = {}): Promise<stri
9595

9696
return stdout;
9797
} catch (error) {
98-
throw new Error(`Failed to execute command: ${error instanceof Error ? error.message : String(error)}`);
98+
// Extract more details from the exec error
99+
const execError = error as { code: number, stderr: string };
100+
const exitCode = execError.code || 'unknown';
101+
const stderr = execError.stderr || '';
102+
103+
if (logging) {
104+
console.log(`[AMP] Command exited with code: ${exitCode}`);
105+
if (stderr) {
106+
console.log(`[AMP] stderr: ${stderr}`);
107+
}
108+
}
109+
110+
// Handle Amp CLI terminal cleanup behavior:
111+
// Amp returns exit code 1 when it runs terminal cleanup (writes cursor control codes to stderr)
112+
// even though the actual command execution succeeded. This happens in containerized environments
113+
// where Amp detects terminal-like behavior and attempts cleanup on exit.
114+
// Rather than trying to prevent this (fragile), we check if the expected output files exist,
115+
// which is the semantic definition of success for our use case.
116+
if (resultFilePath) {
117+
const fs = await import('fs');
118+
119+
if (fs.existsSync(resultFilePath)) {
120+
if (logging) {
121+
console.log(`[AMP] Result file exists despite exit code ${exitCode}, treating as success`);
122+
}
123+
try {
124+
return fs.readFileSync(resultFilePath, 'utf8');
125+
} catch (readError) {
126+
console.error(`[AMP] Failed to read result file: ${readError}`);
127+
}
128+
}
129+
}
130+
131+
throw new Error(`Failed to execute command (exit code ${exitCode}): ${error instanceof Error ? error.message : String(error)}${stderr ? `\nstderr: ${stderr}` : ''}`);
99132
}
100133
}
101134

src/github/process-review.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ export async function processReview(
9090

9191
if (fs.existsSync(commentsFilePath)) {
9292
try {
93-
console.log(`Reading collected comments from ${commentsFilePath}`);
9493
const fileContent = fs.readFileSync(commentsFilePath, 'utf8').trim();
94+
console.log(`Found comments file with ${fileContent.length} characters`);
9595

9696
if (fileContent) {
9797
const commentLines = fileContent.split('\n');

0 commit comments

Comments
 (0)