mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 14:24:13 +08:00
* refactor: remove CLI path, use Agent SDK exclusively - Remove CLI-based Claude execution in favor of Agent SDK - Delete prepareRunConfig, parseAndSetSessionId, parseAndSetStructuredOutputs functions - Remove named pipe IPC and sanitizeJsonOutput helper - Remove test-agent-sdk job from test-base-action workflow (SDK is now default) - Delete run-claude.test.ts and structured-output.test.ts (testing removed CLI code) - Update CLAUDE.md to remove named pipe references Co-Authored-By: Claude <noreply@anthropic.com> Claude-Generated-By: Claude Code (cli/claude-opus-4-5=100%) Claude-Steers: 2 Claude-Permission-Prompts: 1 Claude-Escapes: 0 Claude-Plan: <claude-plan> # Plan: Remove Non-Agent SDK Code Path ## Overview Since `use_agent_sdk` defaults to `true`, remove the legacy CLI code path entirely from `base-action/src/run-claude.ts`. ## Files to Modify ### 1. `base-action/src/run-claude.ts` - Main Cleanup **Remove imports:** - `exec` from `child_process` - `promisify` from `util` - `unlink`, `writeFile`, `stat` from `fs/promises` (keep `readFile` - check if needed) - `createWriteStream` from `fs` - `spawn` from `child_process` - `parseShellArgs` from `shell-quote` (still used in `parse-sdk-options.ts`, keep package) **Remove constants:** - `execAsync` - `PIPE_PATH` - `EXECUTION_FILE` (defined in both files, keep in SDK file) - `BASE_ARGS` **Remove types:** - `PreparedConfig` type (lines 85-89) - only used by `prepareRunConfig()` **Remove functions:** - `sanitizeJsonOutput()` (lines 21-68) - `prepareRunConfig()` (lines 91-125) - also remove export - `parseAndSetSessionId()` (lines 131-155) - also remove export - `parseAndSetStructuredOutputs()` (lines 162-197) - also remove export **Simplify `runClaude()`:** - Remove `useAgentSdk` flag check and logging (lines 200-204) - Remove the `if (useAgentSdk)` block, make SDK call direct - Remove entire CLI path (lines 211-438) - Resulting function becomes just: ```typescript export async function runClaude(promptPath: string, options: ClaudeOptions) { const parsedOptions = parseSdkOptions(options); return runClaudeWithSdk(promptPath, parsedOptions); } ``` ### 2. Delete Test Files **`base-action/test/run-claude.test.ts`:** - Delete entire file (only tests `prepareRunConfig()`) **`base-action/test/structured-output.test.ts`:** - Delete entire file (only tests `parseAndSetStructuredOutputs()` and `parseAndSetSessionId()`) ### 3. Workflow Update **`.github/workflows/test-base-action.yml`:** - Remove `test-agent-sdk` job (lines 120-176) - redundant now ### 4. Documentation Update **`base-action/CLAUDE.md`:** - Line 30: Remove "- Named pipes for IPC between prompt input and Claude process" - Line 57: Remove "- Uses `mkfifo` to create named pipes for prompt input" ## Verification 1. Run `bun run typecheck` to ensure no type errors 2. Run `bun test` to ensure remaining tests pass 3. Run `bun run format` to fix any formatting issues </claude-plan> * fix: address PR review comments - Add session_id output handling in run-claude-sdk.ts (critical) - Remove unused claudeEnv parameter from ClaudeOptions and index.ts - Update stale CLI path comment in parse-sdk-options.ts Claude-Generated-By: Claude Code (cli/claude-opus-4-5=100%) Claude-Steers: 0 Claude-Permission-Prompts: 0 Claude-Escapes: 0 Claude-Plan: <claude-plan> # Plan: Remove Non-Agent SDK Code Path ## Overview Since `use_agent_sdk` defaults to `true`, remove the legacy CLI code path entirely from `base-action/src/run-claude.ts`. ## Files to Modify ### 1. `base-action/src/run-claude.ts` - Main Cleanup **Remove imports:** - `exec` from `child_process` - `promisify` from `util` - `unlink`, `writeFile`, `stat` from `fs/promises` (keep `readFile` - check if needed) - `createWriteStream` from `fs` - `spawn` from `child_process` - `parseShellArgs` from `shell-quote` (still used in `parse-sdk-options.ts`, keep package) **Remove constants:** - `execAsync` - `PIPE_PATH` - `EXECUTION_FILE` (defined in both files, keep in SDK file) - `BASE_ARGS` **Remove types:** - `PreparedConfig` type (lines 85-89) - only used by `prepareRunConfig()` **Remove functions:** - `sanitizeJsonOutput()` (lines 21-68) - `prepareRunConfig()` (lines 91-125) - also remove export - `parseAndSetSessionId()` (lines 131-155) - also remove export - `parseAndSetStructuredOutputs()` (lines 162-197) - also remove export **Simplify `runClaude()`:** - Remove `useAgentSdk` flag check and logging (lines 200-204) - Remove the `if (useAgentSdk)` block, make SDK call direct - Remove entire CLI path (lines 211-438) - Resulting function becomes just: ```typescript export async function runClaude(promptPath: string, options: ClaudeOptions) { const parsedOptions = parseSdkOptions(options); return runClaudeWithSdk(promptPath, parsedOptions); } ``` ### 2. Delete Test Files **`base-action/test/run-claude.test.ts`:** - Delete entire file (only tests `prepareRunConfig()`) **`base-action/test/structured-output.test.ts`:** - Delete entire file (only tests `parseAndSetStructuredOutputs()` and `parseAndSetSessionId()`) ### 3. Workflow Update **`.github/workflows/test-base-action.yml`:** - Remove `test-agent-sdk` job (lines 120-176) - redundant now ### 4. Documentation Update **`base-action/CLAUDE.md`:** - Line 30: Remove "- Named pipes for IPC between prompt input and Claude process" - Line 57: Remove "- Uses `mkfifo` to create named pipes for prompt input" ## Verification 1. Run `bun run typecheck` to ensure no type errors 2. Run `bun test` to ensure remaining tests pass 3. Run `bun run format` to fix any formatting issues </claude-plan>
119 lines
3.7 KiB
YAML
119 lines
3.7 KiB
YAML
name: Test Claude Code Action
|
|
|
|
on:
|
|
pull_request:
|
|
workflow_dispatch:
|
|
inputs:
|
|
test_prompt:
|
|
description: "Test prompt for Claude"
|
|
required: false
|
|
default: "List the files in the current directory starting with 'package'"
|
|
workflow_call:
|
|
|
|
jobs:
|
|
test-inline-prompt:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
|
|
|
- name: Test with inline prompt
|
|
id: inline-test
|
|
uses: ./base-action
|
|
with:
|
|
prompt: ${{ github.event.inputs.test_prompt || 'List the files in the current directory starting with "package"' }}
|
|
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
allowed_tools: "LS,Read"
|
|
|
|
- name: Verify inline prompt output
|
|
run: |
|
|
OUTPUT_FILE="${{ steps.inline-test.outputs.execution_file }}"
|
|
CONCLUSION="${{ steps.inline-test.outputs.conclusion }}"
|
|
|
|
echo "Conclusion: $CONCLUSION"
|
|
echo "Output file: $OUTPUT_FILE"
|
|
|
|
if [ "$CONCLUSION" = "success" ]; then
|
|
echo "✅ Action completed successfully"
|
|
else
|
|
echo "❌ Action failed"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -f "$OUTPUT_FILE" ]; then
|
|
if [ -s "$OUTPUT_FILE" ]; then
|
|
echo "✅ Execution log file created successfully with content"
|
|
echo "Validating JSON format:"
|
|
if jq . "$OUTPUT_FILE" > /dev/null 2>&1; then
|
|
echo "✅ Output is valid JSON"
|
|
echo "Content preview:"
|
|
head -c 200 "$OUTPUT_FILE"
|
|
else
|
|
echo "❌ Output is not valid JSON"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "❌ Execution log file is empty"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "❌ Execution log file not found"
|
|
exit 1
|
|
fi
|
|
|
|
test-prompt-file:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
|
|
|
- name: Create test prompt file
|
|
run: |
|
|
cat > test-prompt.txt << EOF
|
|
${PROMPT}
|
|
EOF
|
|
env:
|
|
PROMPT: ${{ github.event.inputs.test_prompt || 'List the files in the current directory starting with "package"' }}
|
|
|
|
- name: Test with prompt file and allowed tools
|
|
id: prompt-file-test
|
|
uses: ./base-action
|
|
with:
|
|
prompt_file: "test-prompt.txt"
|
|
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
allowed_tools: "LS,Read"
|
|
|
|
- name: Verify prompt file output
|
|
run: |
|
|
OUTPUT_FILE="${{ steps.prompt-file-test.outputs.execution_file }}"
|
|
CONCLUSION="${{ steps.prompt-file-test.outputs.conclusion }}"
|
|
|
|
echo "Conclusion: $CONCLUSION"
|
|
echo "Output file: $OUTPUT_FILE"
|
|
|
|
if [ "$CONCLUSION" = "success" ]; then
|
|
echo "✅ Action completed successfully"
|
|
else
|
|
echo "❌ Action failed"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -f "$OUTPUT_FILE" ]; then
|
|
if [ -s "$OUTPUT_FILE" ]; then
|
|
echo "✅ Execution log file created successfully with content"
|
|
echo "Validating JSON format:"
|
|
if jq . "$OUTPUT_FILE" > /dev/null 2>&1; then
|
|
echo "✅ Output is valid JSON"
|
|
echo "Content preview:"
|
|
head -c 200 "$OUTPUT_FILE"
|
|
else
|
|
echo "❌ Output is not valid JSON"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "❌ Execution log file is empty"
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "❌ Execution log file not found"
|
|
exit 1
|
|
fi
|