mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 23:14:13 +08:00
Compare commits
3 Commits
claude/sla
...
ashwin/deb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5940655715 | ||
|
|
0c4374199a | ||
|
|
c67fb66a79 |
4
.github/workflows/sync-base-action.yml
vendored
4
.github/workflows/sync-base-action.yml
vendored
@@ -94,5 +94,5 @@ jobs:
|
|||||||
echo "✅ Successfully synced \`base-action\` directory to [anthropics/claude-code-base-action](https://github.com/anthropics/claude-code-base-action)" >> $GITHUB_STEP_SUMMARY
|
echo "✅ Successfully synced \`base-action\` directory to [anthropics/claude-code-base-action](https://github.com/anthropics/claude-code-base-action)" >> $GITHUB_STEP_SUMMARY
|
||||||
echo "" >> $GITHUB_STEP_SUMMARY
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
echo "- **Source commit**: [\`${GITHUB_SHA:0:7}\`](https://github.com/anthropics/claude-code-action/commit/${GITHUB_SHA})" >> $GITHUB_STEP_SUMMARY
|
echo "- **Source commit**: [\`${GITHUB_SHA:0:7}\`](https://github.com/anthropics/claude-code-action/commit/${GITHUB_SHA})" >> $GITHUB_STEP_SUMMARY
|
||||||
echo "- **Triggered by**: $GITHUB_EVENT_NAME" >> $GITHUB_STEP_SUMMARY
|
echo "- **Triggered by**: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
|
||||||
echo "- **Actor**: @$GITHUB_ACTOR" >> $GITHUB_STEP_SUMMARY
|
echo "- **Actor**: @${{ github.actor }}" >> $GITHUB_STEP_SUMMARY
|
||||||
|
|||||||
16
action.yml
16
action.yml
@@ -140,12 +140,10 @@ runs:
|
|||||||
- name: Setup Custom Bun Path
|
- name: Setup Custom Bun Path
|
||||||
if: inputs.path_to_bun_executable != ''
|
if: inputs.path_to_bun_executable != ''
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
|
||||||
PATH_TO_BUN_EXECUTABLE: ${{ inputs.path_to_bun_executable }}
|
|
||||||
run: |
|
run: |
|
||||||
echo "Using custom Bun executable: $PATH_TO_BUN_EXECUTABLE"
|
echo "Using custom Bun executable: ${{ inputs.path_to_bun_executable }}"
|
||||||
# Add the directory containing the custom executable to PATH
|
# Add the directory containing the custom executable to PATH
|
||||||
BUN_DIR=$(dirname "$PATH_TO_BUN_EXECUTABLE")
|
BUN_DIR=$(dirname "${{ inputs.path_to_bun_executable }}")
|
||||||
echo "$BUN_DIR" >> "$GITHUB_PATH"
|
echo "$BUN_DIR" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
@@ -184,8 +182,6 @@ runs:
|
|||||||
- name: Install Base Action Dependencies
|
- name: Install Base Action Dependencies
|
||||||
if: steps.prepare.outputs.contains_trigger == 'true'
|
if: steps.prepare.outputs.contains_trigger == 'true'
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
|
||||||
PATH_TO_CLAUDE_CODE_EXECUTABLE: ${{ inputs.path_to_claude_code_executable }}
|
|
||||||
run: |
|
run: |
|
||||||
echo "Installing base-action dependencies..."
|
echo "Installing base-action dependencies..."
|
||||||
cd ${GITHUB_ACTION_PATH}/base-action
|
cd ${GITHUB_ACTION_PATH}/base-action
|
||||||
@@ -194,8 +190,8 @@ runs:
|
|||||||
cd -
|
cd -
|
||||||
|
|
||||||
# Install Claude Code if no custom executable is provided
|
# Install Claude Code if no custom executable is provided
|
||||||
if [ -z "$PATH_TO_CLAUDE_CODE_EXECUTABLE" ]; then
|
if [ -z "${{ inputs.path_to_claude_code_executable }}" ]; then
|
||||||
CLAUDE_CODE_VERSION="2.0.62"
|
CLAUDE_CODE_VERSION="2.0.60"
|
||||||
echo "Installing Claude Code v${CLAUDE_CODE_VERSION}..."
|
echo "Installing Claude Code v${CLAUDE_CODE_VERSION}..."
|
||||||
for attempt in 1 2 3; do
|
for attempt in 1 2 3; do
|
||||||
echo "Installation attempt $attempt..."
|
echo "Installation attempt $attempt..."
|
||||||
@@ -214,9 +210,9 @@ runs:
|
|||||||
echo "Claude Code installed successfully"
|
echo "Claude Code installed successfully"
|
||||||
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
||||||
else
|
else
|
||||||
echo "Using custom Claude Code executable: $PATH_TO_CLAUDE_CODE_EXECUTABLE"
|
echo "Using custom Claude Code executable: ${{ inputs.path_to_claude_code_executable }}"
|
||||||
# Add the directory containing the custom executable to PATH
|
# Add the directory containing the custom executable to PATH
|
||||||
CLAUDE_DIR=$(dirname "$PATH_TO_CLAUDE_CODE_EXECUTABLE")
|
CLAUDE_DIR=$(dirname "${{ inputs.path_to_claude_code_executable }}")
|
||||||
echo "$CLAUDE_DIR" >> "$GITHUB_PATH"
|
echo "$CLAUDE_DIR" >> "$GITHUB_PATH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -101,12 +101,10 @@ runs:
|
|||||||
- name: Setup Custom Bun Path
|
- name: Setup Custom Bun Path
|
||||||
if: inputs.path_to_bun_executable != ''
|
if: inputs.path_to_bun_executable != ''
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
|
||||||
PATH_TO_BUN_EXECUTABLE: ${{ inputs.path_to_bun_executable }}
|
|
||||||
run: |
|
run: |
|
||||||
echo "Using custom Bun executable: $PATH_TO_BUN_EXECUTABLE"
|
echo "Using custom Bun executable: ${{ inputs.path_to_bun_executable }}"
|
||||||
# Add the directory containing the custom executable to PATH
|
# Add the directory containing the custom executable to PATH
|
||||||
BUN_DIR=$(dirname "$PATH_TO_BUN_EXECUTABLE")
|
BUN_DIR=$(dirname "${{ inputs.path_to_bun_executable }}")
|
||||||
echo "$BUN_DIR" >> "$GITHUB_PATH"
|
echo "$BUN_DIR" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
@@ -117,11 +115,9 @@ runs:
|
|||||||
|
|
||||||
- name: Install Claude Code
|
- name: Install Claude Code
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
|
||||||
PATH_TO_CLAUDE_CODE_EXECUTABLE: ${{ inputs.path_to_claude_code_executable }}
|
|
||||||
run: |
|
run: |
|
||||||
if [ -z "$PATH_TO_CLAUDE_CODE_EXECUTABLE" ]; then
|
if [ -z "${{ inputs.path_to_claude_code_executable }}" ]; then
|
||||||
CLAUDE_CODE_VERSION="2.0.62"
|
CLAUDE_CODE_VERSION="2.0.60"
|
||||||
echo "Installing Claude Code v${CLAUDE_CODE_VERSION}..."
|
echo "Installing Claude Code v${CLAUDE_CODE_VERSION}..."
|
||||||
for attempt in 1 2 3; do
|
for attempt in 1 2 3; do
|
||||||
echo "Installation attempt $attempt..."
|
echo "Installation attempt $attempt..."
|
||||||
@@ -139,9 +135,9 @@ runs:
|
|||||||
done
|
done
|
||||||
echo "Claude Code installed successfully"
|
echo "Claude Code installed successfully"
|
||||||
else
|
else
|
||||||
echo "Using custom Claude Code executable: $PATH_TO_CLAUDE_CODE_EXECUTABLE"
|
echo "Using custom Claude Code executable: ${{ inputs.path_to_claude_code_executable }}"
|
||||||
# Add the directory containing the custom executable to PATH
|
# Add the directory containing the custom executable to PATH
|
||||||
CLAUDE_DIR=$(dirname "$PATH_TO_CLAUDE_CODE_EXECUTABLE")
|
CLAUDE_DIR=$(dirname "${{ inputs.path_to_claude_code_executable }}")
|
||||||
echo "$CLAUDE_DIR" >> "$GITHUB_PATH"
|
echo "$CLAUDE_DIR" >> "$GITHUB_PATH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -75,15 +75,28 @@ export async function runClaudeWithSdk(
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Running Claude with prompt from file: ${promptPath}`);
|
console.log(`Running Claude with prompt from file: ${promptPath}`);
|
||||||
// Log SDK options without env (which could contain sensitive data)
|
console.log(
|
||||||
const { env, ...optionsToLog } = sdkOptions;
|
"[DEBUG] Prompt content (first 2000 chars):",
|
||||||
console.log("SDK options:", JSON.stringify(optionsToLog, null, 2));
|
prompt.substring(0, 2000),
|
||||||
|
);
|
||||||
|
console.log("[DEBUG] Prompt length:", prompt.length);
|
||||||
|
console.log(
|
||||||
|
"[DEBUG] sdkOptions passed to query():",
|
||||||
|
JSON.stringify(sdkOptions, null, 2),
|
||||||
|
);
|
||||||
|
|
||||||
const messages: SDKMessage[] = [];
|
const messages: SDKMessage[] = [];
|
||||||
let resultMessage: SDKResultMessage | undefined;
|
let resultMessage: SDKResultMessage | undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
console.log("[DEBUG] About to call query()...");
|
||||||
for await (const message of query({ prompt, options: sdkOptions })) {
|
for await (const message of query({ prompt, options: sdkOptions })) {
|
||||||
|
console.log(
|
||||||
|
"[DEBUG] Received message type:",
|
||||||
|
message.type,
|
||||||
|
"subtype:",
|
||||||
|
(message as any).subtype,
|
||||||
|
);
|
||||||
messages.push(message);
|
messages.push(message);
|
||||||
|
|
||||||
const sanitized = sanitizeSdkOutput(message, showFullOutput);
|
const sanitized = sanitizeSdkOutput(message, showFullOutput);
|
||||||
@@ -93,8 +106,16 @@ export async function runClaudeWithSdk(
|
|||||||
|
|
||||||
if (message.type === "result") {
|
if (message.type === "result") {
|
||||||
resultMessage = message as SDKResultMessage;
|
resultMessage = message as SDKResultMessage;
|
||||||
|
console.log(
|
||||||
|
"[DEBUG] Got result message:",
|
||||||
|
JSON.stringify(resultMessage, null, 2),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log(
|
||||||
|
"[DEBUG] Finished iterating query(), total messages:",
|
||||||
|
messages.length,
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("SDK execution error:", error);
|
console.error("SDK execution error:", error);
|
||||||
core.setOutput("conclusion", "failure");
|
core.setOutput("conclusion", "failure");
|
||||||
|
|||||||
@@ -174,7 +174,15 @@ export async function runClaude(promptPath: string, options: ClaudeOptions) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (useAgentSdk) {
|
if (useAgentSdk) {
|
||||||
|
console.log(
|
||||||
|
"[DEBUG] Raw options passed to SDK path:",
|
||||||
|
JSON.stringify(options, null, 2),
|
||||||
|
);
|
||||||
const parsedOptions = parseSdkOptions(options);
|
const parsedOptions = parseSdkOptions(options);
|
||||||
|
console.log(
|
||||||
|
"[DEBUG] Parsed SDK options:",
|
||||||
|
JSON.stringify(parsedOptions, null, 2),
|
||||||
|
);
|
||||||
return runClaudeWithSdk(promptPath, parsedOptions);
|
return runClaudeWithSdk(promptPath, parsedOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import { readFileSync, existsSync } from "fs";
|
import { readFileSync, existsSync } from "fs";
|
||||||
import { exit } from "process";
|
import { exit } from "process";
|
||||||
import { stripAnsiCodes } from "../github/utils/sanitizer";
|
|
||||||
|
|
||||||
export type ToolUse = {
|
export type ToolUse = {
|
||||||
type: string;
|
type: string;
|
||||||
@@ -173,9 +172,6 @@ export function formatResultContent(content: any): string {
|
|||||||
contentStr = String(content).trim();
|
contentStr = String(content).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strip ANSI escape codes from terminal output
|
|
||||||
contentStr = stripAnsiCodes(contentStr);
|
|
||||||
|
|
||||||
// Truncate very long results
|
// Truncate very long results
|
||||||
if (contentStr.length > 3000) {
|
if (contentStr.length > 3000) {
|
||||||
contentStr = contentStr.substring(0, 2997) + "...";
|
contentStr = contentStr.substring(0, 2997) + "...";
|
||||||
|
|||||||
@@ -1,11 +1,3 @@
|
|||||||
export function stripAnsiCodes(content: string): string {
|
|
||||||
// Matches ANSI escape sequences:
|
|
||||||
// - \x1B[ (CSI) followed by parameters and a final byte
|
|
||||||
// - \x1B followed by single-character sequences
|
|
||||||
// Common sequences: \x1B[1;33m (colors), \x1B[0m (reset), \x1B[K (clear line)
|
|
||||||
return content.replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
export function stripInvisibleCharacters(content: string): string {
|
export function stripInvisibleCharacters(content: string): string {
|
||||||
content = content.replace(/[\u200B\u200C\u200D\uFEFF]/g, "");
|
content = content.replace(/[\u200B\u200C\u200D\uFEFF]/g, "");
|
||||||
content = content.replace(
|
content = content.replace(
|
||||||
|
|||||||
@@ -111,27 +111,6 @@ describe("formatResultContent", () => {
|
|||||||
const result = formatResultContent(JSON.stringify(structuredContent));
|
const result = formatResultContent(JSON.stringify(structuredContent));
|
||||||
expect(result).toBe("**→** Hello world\n\n");
|
expect(result).toBe("**→** Hello world\n\n");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("strips ANSI color codes from terminal output", () => {
|
|
||||||
// Test bold yellow warning (the issue reported: [1;33m)
|
|
||||||
const coloredOutput = "\x1B[1;33mWarning: something happened\x1B[0m";
|
|
||||||
const result = formatResultContent(coloredOutput);
|
|
||||||
expect(result).toBe("**→** Warning: something happened\n\n");
|
|
||||||
expect(result).not.toContain("\x1B");
|
|
||||||
expect(result).not.toContain("[1;33m");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("strips ANSI codes from longer output in code blocks", () => {
|
|
||||||
const longColoredOutput =
|
|
||||||
"\x1B[32m✓\x1B[0m Test 1 passed\n" +
|
|
||||||
"\x1B[32m✓\x1B[0m Test 2 passed\n" +
|
|
||||||
"\x1B[31m✗\x1B[0m Test 3 failed\n" +
|
|
||||||
"Some additional output to make it longer";
|
|
||||||
const result = formatResultContent(longColoredOutput);
|
|
||||||
expect(result).toContain("✓ Test 1 passed");
|
|
||||||
expect(result).toContain("✗ Test 3 failed");
|
|
||||||
expect(result).not.toContain("\x1B");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("formatToolWithResult", () => {
|
describe("formatToolWithResult", () => {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { describe, expect, it } from "bun:test";
|
import { describe, expect, it } from "bun:test";
|
||||||
import {
|
import {
|
||||||
stripAnsiCodes,
|
|
||||||
stripInvisibleCharacters,
|
stripInvisibleCharacters,
|
||||||
stripMarkdownImageAltText,
|
stripMarkdownImageAltText,
|
||||||
stripMarkdownLinkTitles,
|
stripMarkdownLinkTitles,
|
||||||
@@ -11,51 +10,6 @@ import {
|
|||||||
redactGitHubTokens,
|
redactGitHubTokens,
|
||||||
} from "../src/github/utils/sanitizer";
|
} from "../src/github/utils/sanitizer";
|
||||||
|
|
||||||
describe("stripAnsiCodes", () => {
|
|
||||||
it("should remove color codes", () => {
|
|
||||||
// Bold yellow text: \x1B[1;33m
|
|
||||||
expect(stripAnsiCodes("\x1B[1;33mWarning\x1B[0m")).toBe("Warning");
|
|
||||||
// Red text: \x1B[31m
|
|
||||||
expect(stripAnsiCodes("\x1B[31mError\x1B[0m")).toBe("Error");
|
|
||||||
// Green text: \x1B[32m
|
|
||||||
expect(stripAnsiCodes("\x1B[32mSuccess\x1B[0m")).toBe("Success");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should remove bold and other style codes", () => {
|
|
||||||
// Bold: \x1B[1m
|
|
||||||
expect(stripAnsiCodes("\x1B[1mBold text\x1B[0m")).toBe("Bold text");
|
|
||||||
// Underline: \x1B[4m
|
|
||||||
expect(stripAnsiCodes("\x1B[4mUnderlined\x1B[0m")).toBe("Underlined");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should remove cursor movement codes", () => {
|
|
||||||
// Clear line: \x1B[K
|
|
||||||
expect(stripAnsiCodes("Text\x1B[K")).toBe("Text");
|
|
||||||
// Cursor up: \x1B[A
|
|
||||||
expect(stripAnsiCodes("Line1\x1B[ALine2")).toBe("Line1Line2");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should handle multiple ANSI codes in one string", () => {
|
|
||||||
const input = "\x1B[1;31mError:\x1B[0m \x1B[33mWarning\x1B[0m text";
|
|
||||||
expect(stripAnsiCodes(input)).toBe("Error: Warning text");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should preserve text without ANSI codes", () => {
|
|
||||||
expect(stripAnsiCodes("Normal text")).toBe("Normal text");
|
|
||||||
expect(stripAnsiCodes("Text with [brackets]")).toBe("Text with [brackets]");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should handle empty string", () => {
|
|
||||||
expect(stripAnsiCodes("")).toBe("");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should handle complex terminal output", () => {
|
|
||||||
// Simulates npm/yarn output with colors
|
|
||||||
const input = "\x1B[2K\x1B[1G\x1B[32m✓\x1B[0m Tests passed";
|
|
||||||
expect(stripAnsiCodes(input)).toBe("✓ Tests passed");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("stripInvisibleCharacters", () => {
|
describe("stripInvisibleCharacters", () => {
|
||||||
it("should remove zero-width characters", () => {
|
it("should remove zero-width characters", () => {
|
||||||
expect(stripInvisibleCharacters("Hello\u200BWorld")).toBe("HelloWorld");
|
expect(stripInvisibleCharacters("Hello\u200BWorld")).toBe("HelloWorld");
|
||||||
|
|||||||
Reference in New Issue
Block a user