diff options
| author | Harsh Aggarwal (NVIDIA) <haaggarwal@nvidia.com> | 2025-07-11 00:06:10 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-10 18:36:10 +0000 |
| commit | df398fab63ac0c14a4a6cf34e4711a67ec1f4724 (patch) | |
| tree | b3f6eee30576e25a13c27dead4fe59c6ffb2a640 | |
| parent | aa3cc1e79315592e9b22fccd77fc27fef0c09762 (diff) | |
Fix#7676 - Add Claude Code Assistant for using LLMs (#7673)
* Add Claude Code Assistant for using LLMs
add claude.md files for context to the LLM
* format code
* Update claude.yml
add pull request target
* Force test claude.yml
* Remove sensitive flag - Update claude.yml
* Update claude.yml
Reverted the direct_prompt
* format code (#7674)
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
* Fix Claude workflow based on PR review feedback
- Remove unused pull_request_review_comment trigger
- Increase timeout from 30 to 60 minutes
- Change fetch-depth from 0 to 2 for minimal git history
- Add recursive submodule checkout following copilot pattern
- Add environment setup with libx11-dev dependency
- Switch to release build config following copilot pattern
- Increase max_turns from 10 to 20 for longer conversations
- Update custom instructions with build commands and OS info
๐ค Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Update workflow - configure debug build
* Update max turns to 50 for M size work
* Add Claude Code settings with auto-formatting hook
- Create .claude/settings.json with PostToolUse hook
- Automatically runs ./extras/formatting.sh after Write/Edit/MultiEdit operations
- Ensures code formatting consistency when Claude makes changes
๐ค Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Co-authored-by: slangbot <ellieh+slangbot@nvidia.com>
Co-authored-by: Claude <noreply@anthropic.com>
| -rw-r--r-- | .claude/settings.json | 15 | ||||
| -rw-r--r-- | .github/workflows/claude.yml | 317 | ||||
| -rwxr-xr-x | CLAUDE.local.md | 48 | ||||
| -rwxr-xr-x | CLAUDE.md | 210 |
4 files changed, 590 insertions, 0 deletions
diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 000000000..5e1dea6fb --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,15 @@ +{ + "hooks": { + "PostToolUse": [ + { + "matcher": "Write|Edit|MultiEdit", + "hooks": [ + { + "type": "command", + "command": "./extras/formatting.sh" + } + ] + } + ] + } +}
\ No newline at end of file diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml new file mode 100644 index 000000000..454077f06 --- /dev/null +++ b/.github/workflows/claude.yml @@ -0,0 +1,317 @@ +name: ClaudeCode - Slang Assistant + +permissions: + contents: write + pull-requests: write + issues: write + actions: read + id-token: write + +on: + issue_comment: + types: [created] + pull_request_review_comment: + types: [created] + issues: + types: [opened, assigned] + pull_request_review: + types: [submitted] + +env: + AWS_REGION: ${{ vars.AWS_REGION }} + AWS_ACCESS_KEY_ID: ${{ vars.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ vars.AWS_SECRET_ACCESS_KEY }} + +jobs: + claude: + name: Claude Code Assistant + if: | + (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) || + (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) || + (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) || + (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude'))) + + runs-on: ubuntu-latest + timeout-minutes: 60 + + # Cancel previous runs on new pushes + concurrency: + group: claude-${{ github.event.issue.number || github.event.pull_request.number || github.run_id }} + cancel-in-progress: true + + steps: + # Format setup and environment preparation + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: "recursive" + fetch-depth: 2 # fetch minimal history for git context + + - name: Format Setup and Environment Preparation + uses: ./.github/actions/format-setup + + - name: Setup Environment Dependencies + run: | + set -euo pipefail + echo "๐๏ธ Setting up environment dependencies..." + + sudo apt-get update + sudo apt-get install -y libx11-dev + + # Configure and build the project + cmake --preset default --fresh + cmake --workflow --preset debug + + echo "โ
Environment setup completed" + + # Validate environment and dependencies + - name: Validate Environment + run: | + set -euo pipefail + + # Check required secrets + if [ -z "${{ secrets.LLMGW_ID }}" ] || [ -z "${{ secrets.LLMGW_SECRET }}" ] || [ -z "${{ secrets.LLMGW_TOKEN_URL }}" ]; then + echo "::error::Missing required secrets: LLMGW_ID or LLMGW_SECRET or LLMGW_TOKEN_URL" + exit 1 + fi + + # Install required tools + command -v jq >/dev/null 2>&1 || { echo "::error::jq is required but not installed"; exit 1; } + command -v curl >/dev/null 2>&1 || { echo "::error::curl is required but not installed"; exit 1; } + + echo "โ
Environment validation passed" + + # Generate custom auth token and set as environment variable + - name: Generate Custom Auth Token + id: auth-token + env: + LLMGW_TOKEN_URL: ${{ secrets.LLMGW_TOKEN_URL }} + run: | + set -euo pipefail + + echo "๐ Generating authentication token..." + + # Set up error handling + cleanup() { + local exit_code=$? + echo "๐งน Cleaning up temporary files..." + rm -f /tmp/token_response.json 2>/dev/null || true + if [ $exit_code -ne 0 ]; then + echo "::error::Authentication failed - check your credentials and endpoint" + fi + exit $exit_code + } + trap cleanup EXIT + + # Generate token with comprehensive error handling + HTTP_CODE=$(curl -s -w "%{http_code}" -o /tmp/token_response.json --fail-with-body \ + --max-time 30 \ + --retry 3 \ + --retry-delay 2 \ + --location "${{ env.LLMGW_TOKEN_URL }}" \ + --header 'Content-Type: application/x-www-form-urlencoded' \ + --header "Authorization: Basic $(echo -n ${{ secrets.LLMGW_ID }}:${{ secrets.LLMGW_SECRET }} | base64 -w0)" \ + --data-urlencode 'grant_type=client_credentials' \ + --data-urlencode 'scope=awsanthropic-readwrite azureopenai-readwrite' \ + 2>/dev/null) + + # Check HTTP response code + if [ "$HTTP_CODE" -ne 200 ]; then + echo "::error::Authentication failed with HTTP code: $HTTP_CODE" + if [ -f /tmp/token_response.json ]; then + echo "::error::Response: $(cat /tmp/token_response.json | head -c 200)" + fi + exit 1 + fi + + # Extract and validate token + if [ ! -f /tmp/token_response.json ]; then + echo "::error::No response file generated" + exit 1 + fi + + ANTHROPIC_AUTH_TOKEN=$(jq -r '.access_token // empty' /tmp/token_response.json 2>/dev/null) + + # Validate token format and length + if [ -z "$ANTHROPIC_AUTH_TOKEN" ] || [ "$ANTHROPIC_AUTH_TOKEN" = "null" ]; then + echo "::error::Failed to extract access token from response" + exit 1 + fi + + # Basic token validation + if [ ${#ANTHROPIC_AUTH_TOKEN} -lt 10 ]; then + echo "::error::Token appears to be too short (${#ANTHROPIC_AUTH_TOKEN} characters)" + exit 1 + fi + + # CRITICAL: Mask the token BEFORE any output + echo "::add-mask::$ANTHROPIC_AUTH_TOKEN" + + # Set as environment variable for subsequent steps + echo "ANTHROPIC_AUTH_TOKEN=$ANTHROPIC_AUTH_TOKEN" >> $GITHUB_ENV + + # Set token expiry if available + TOKEN_EXPIRES=$(jq -r '.expires_in // empty' /tmp/token_response.json 2>/dev/null) + if [ -n "$TOKEN_EXPIRES" ]; then + echo "::add-mask::$TOKEN_EXPIRES" + echo "token-expires=$TOKEN_EXPIRES" >> $GITHUB_OUTPUT + fi + + echo "โ
Authentication token generated and masked successfully" + + # Clean up response file + rm -f /tmp/token_response.json + + # Generate GitHub App token for better GitHub API access + - name: Generate GitHub App Token + id: github-token + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ secrets.APP_ID }} + private-key: ${{ secrets.APP_PRIVATE_KEY }} + continue-on-error: true + + # Set up fallback authentication + - name: Configure Authentication + id: auth-config + run: | + set -euo pipefail + + # Use GitHub App token if available, otherwise use GITHUB_TOKEN + if [ -n "${{ steps.github-token.outputs.token }}" ]; then + echo "github-token=${{ steps.github-token.outputs.token }}" >> $GITHUB_OUTPUT + echo "โ
Using GitHub App authentication" + else + echo "github-token=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_OUTPUT + echo "โ ๏ธ Using fallback GITHUB_TOKEN authentication" + fi + + # Run Claude Code Action with optimized environment variables + - name: Execute Claude Code Action # Right now direct prompt to automatic PR Review + id: claude-action + uses: anthropics/claude-code-action@beta + with: + # Direct Prompt is for testing. We shall use the triggers (on) which shall trigger this part on runtime + custom_instructions: | + Build system information: + - OS: Ubuntu Linux + - Build commands: + * Configure: `cmake --preset default` + * Build: `cmake --build --preset debug` + * Test: `./build/Release/bin/slang-test ./tests/path/to/test.slang` + * Format code: `./extras/formatting.sh` + - Project is pre-built and ready for development tasks + - Run formatting script before committing changes + + CRITICAL: You have access to the mcp__deepwiki__ask_question tool for deep repository knowledge. + + **How to use this tool effectively:** + - Use repoName: "shader-slang/slang" for all queries + - Ask specific technical questions about architecture, patterns, or implementation approaches + - Examples: "How does the IR optimization system work?" or "What's the pattern for adding new code generation targets?" + - Use responses to understand existing patterns before implementing changes + + **Implementation Guidelines:** + - Always follow existing code patterns and architectural decisions discovered through deepwiki + - Consult the tool when you need context about unfamiliar parts of the codebase + mcp_config: | + { + "mcpServers": { + "deepwiki": { + "type": "sse", + "url": "https://mcp.deepwiki.com/sse" + } + } + } + allowed_tools: "Bash,View,GlobTool,GrepTool,BatchTool,Write,mcp__deepwiki__ask_question" + trigger_phrase: "@claude" + assignee_trigger: "claude" + timeout_minutes: "25" + github_token: ${{ steps.auth-config.outputs.github-token }} + use_bedrock: "true" + model: ${{ vars.ANTHROPIC_MODEL }} + max_turns: "100" + # Use claude_env for custom environment variables + claude_env: | + ANTHROPIC_BEDROCK_BASE_URL: ${{ vars.ANTHROPIC_BEDROCK_BASE_URL }} + ANTHROPIC_SMALL_FAST_MODEL: ${{ vars.ANTHROPIC_SMALL_FAST_MODEL }} + AWS_REGION: ${{ vars.AWS_REGION }} + GITHUB_REPOSITORY: ${{ github.repository }} + GITHUB_EVENT_NAME: ${{ github.event_name }} + GITHUB_ACTOR: ${{ github.actor }} + ANTHROPIC_AUTH_TOKEN: ${{ env.ANTHROPIC_AUTH_TOKEN }} + DISABLE_TELEMETRY: 1 + + # The ANTHROPIC_API_KEY environment variable is automatically picked up + continue-on-error: true + + # Handle action results and errors + - name: Handle Action Results + if: always() + run: | + set -euo pipefail + + # Check if Claude action succeeded + if [ "${{ steps.claude-action.outcome }}" = "success" ]; then + echo "โ
Claude Code action completed successfully" + + # Optional: Add success comment to PR/issue + if [ -n "${{ github.event.issue.number || github.event.pull_request.number }}" ]; then + echo "Claude has successfully processed your request! ๐" >> /tmp/comment.md + echo "<!-- Claude-success -->" >> /tmp/comment.md + fi + + elif [ "${{ steps.claude-action.outcome }}" = "failure" ]; then + echo "โ Claude Code action failed" + + # Create error comment for debugging + cat > /tmp/error_comment.md << 'EOF' + ## Claude Code Action Failed โ + + The Claude Code action encountered an error. This could be due to: + - Network connectivity issues + - Authentication problems + - Model availability issues + - Rate limiting + + Please check the workflow logs for more details and try again. + + <!-- Claude-error --> + EOF + + else + echo "โ ๏ธ Claude Code action was cancelled or skipped" + fi + + # Security cleanup + - name: Security Cleanup + if: always() + run: | + set -euo pipefail + + echo "๐งน Performing security cleanup..." + + # Clear any temporary files that might contain sensitive data + find /tmp -name "*token*" -type f -delete 2>/dev/null || true + find /tmp -name "*auth*" -type f -delete 2>/dev/null || true + find /tmp -name "*response*" -type f -delete 2>/dev/null || true + + # Clear environment variables (belt and suspenders approach) + unset ANTHROPIC_API_KEY 2>/dev/null || true + unset ANTHROPIC_AUTH_TOKEN 2>/dev/null || true + + echo "โ
Security cleanup completed" + + # Workflow summary + - name: Workflow Summary + if: always() + run: | + echo "## Claude Code Workflow Summary" >> $GITHUB_STEP_SUMMARY + echo "- **Trigger**: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY + echo "- **Repository**: ${{ github.repository }}" >> $GITHUB_STEP_SUMMARY + echo "- **Actor**: ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY + echo "- **Auth Token**: โ
Generated" >> $GITHUB_STEP_SUMMARY + echo "- **GitHub Token**: ${{ steps.github-token.outcome == 'success' && 'โ
GitHub App' || 'โ ๏ธ Fallback' }}" >> $GITHUB_STEP_SUMMARY + echo "- **Claude Action**: ${{ steps.claude-action.outcome == 'success' && 'โ
Success' || 'โ Failed' }}" >> $GITHUB_STEP_SUMMARY + echo "- **Model Used**: ${{ vars.ANTHROPIC_MODEL || 'default' }}" >> $GITHUB_STEP_SUMMARY + echo "- **Workflow Status**: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY diff --git a/CLAUDE.local.md b/CLAUDE.local.md new file mode 100755 index 000000000..282936701 --- /dev/null +++ b/CLAUDE.local.md @@ -0,0 +1,48 @@ +# Slang Repository Structure + +For the repoName: `shader-slang/slang` repository, the deepwiki mcp server structure includes: + +## Main Topics: + - 1 Overview + - 2 Compiler Architecture + - 2.1 Front-End: Parsing & AST + - 2.2 Semantic Analysis + - 2.3 Intermediate Representation + - 2.4 IR Lowering & Optimization + - 2.5 Code Generation + - 3 Session Management & API + - 3.1 Session & Linkage System + - 3.2 ComponentType Hierarchy + - 4 Language Features + - 4.1 Automatic Differentiation + - 4.2 Module System + - 4.3 Interfaces & Generics + - 4.4 Capabilities System + - 5 Target Platforms + - 5.1 HLSL & DirectX Targets + - 5.2 GLSL & Vulkan Targets + - 5.3 C++, CUDA & CPU Targets + - 5.4 Other Targets & Extensions + - 6 Rendering System + - 6.1 GFX API Architecture + - 6.2 Shader Objects & Resource Binding + - 6.3 Device & Pipeline Management + - 7 Testing & Build Infrastructure + - 7.1 Test Framework + - 7.2 Build System + - 7.3 CI/CD Pipeline + - 8 Development Tools + - 8.1 Language Server + - 8.2 Utilities & Core Libraries +### MCP Tools +#### 1. `mcp__deepwiki__ask_question` +- **Purpose**: Ask specific questions about a GitHub repository +- **Parameters**: + - `repoName` (required): GitHub repository in format "shader-slang/slang" + - `question` (required): The question to ask about the repository +- **Usage**: Returns AI-generated answers based on repository analysis + +## Build Instructions +- Build using: `cmake --build --preset debug` +- Test using: `./build/Debug/bin/slangc -target path/to/file.slang` + - Add `-dump-ir` for IR stages / optimization logs and understanding diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100755 index 000000000..8a01904db --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,210 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Essential Build Commands + +**Configure and build (recommended):** +```bash +cmake --preset default +cmake --build --preset releaseWithDebugInfo # or --preset debug, or --preset release +``` + +**Alternative Visual Studio workflow:** +```bash +cmake --preset vs2022 # or vs2019 +cmake --build --preset releaseWithDebugInfo +``` + +**Quick release build and package:** +```bash +cmake --workflow --preset release +``` + +**Build only generators for cross-compilation:** +```bash +cmake --workflow --preset generators --fresh +``` + +## Testing Commands + +**Run all tests:** +```bash +build/Release/bin/slang-test +# or for debug builds: +build/Debug/bin/slang-test +``` + +**Run specific test categories:** +```bash +slang-test -category smoke # Basic smoke tests +slang-test -category quick # Quick tests +slang-test -category full # Full test suite +slang-test -category compute # Compute shader tests +``` + +**Run tests with parallel execution:** +```bash +slang-test -use-test-server -server-count 8 +``` + +**Run specific API tests:** +```bash +slang-test -api vk # Vulkan only +slang-test -api dx12 # DirectX 12 only +``` + +**Full CI-style test run:** +```bash +slang-test -use-test-server -server-count 8 -category full -expected-failure-list tests/expected-failure-github.txt +``` + +**Run single test:** +```bash +slang-test tests/compute/array-param +``` + +## Core Architecture Overview + +### Main Compilation Pipeline +- **Front-end**: Source โ AST โ IR (with semantic checking and lowering) +- **Back-end**: IR โ Optimized IR โ Target Code Generation + +### Key Source Directories + +**`source/core/`** - Foundation utilities, platform abstraction, collections, memory management + +**`source/compiler-core/`** - Shared compiler infrastructure +- Lexical analysis, diagnostics, source locations +- Downstream compiler integration (DXC, FXC, GLSLANG) +- Artifact management and JSON utilities for tooling + +**`source/slang/`** - Main compiler implementation +- `slang-parser.cpp` - Recursive descent parser +- `slang-ast-*.cpp` - Abstract Syntax Tree and type system +- `slang-check-*.cpp` - Semantic checking and type checking +- `slang-ir*.cpp` - Intermediate representation and optimization passes +- `slang-emit-*.cpp` - Target-specific code generators (HLSL, GLSL, SPIR-V, Metal, etc.) +- `slang-lower-to-ir.cpp` - AST to IR transformation + +### IR System Characteristics +- **SSA Form**: Single Static Assignment with block parameters +- **Instruction-based**: Everything is an instruction (types, constants, operations) +- **Typed IR**: Every instruction has a type +- **Global Deduplication**: Types and constants automatically deduplicated + +### Code Generation Targets +- `slang-emit-hlsl.cpp` - HLSL generation +- `slang-emit-glsl.cpp` - GLSL generation +- `slang-emit-spirv.cpp` - Direct SPIR-V bytecode +- `slang-emit-metal.cpp` - Metal Shading Language +- `slang-emit-wgsl.cpp` - WebGPU Shading Language +- `slang-emit-cuda.cpp` - CUDA C++ generation +- `slang-emit-cpp.cpp` - Host C++ code generation + +## Key Build Configuration + +**CMake presets available:** +- `default` - Ninja Multi-Config (recommended) +- `vs2022` / `vs2019` - Visual Studio generators +- `emscripten` - WebAssembly build +- `generators` - Build only code generators + +**Important CMake options:** +- `SLANG_ENABLE_TESTS=TRUE` - Enable test targets (default) +- `SLANG_ENABLE_GFX=TRUE` - Enable graphics abstraction layer +- `SLANG_ENABLE_SLANGC=TRUE` - Enable standalone compiler +- `SLANG_LIB_TYPE=SHARED` - Build shared library (default) + +## Module and Generic System + +**Module compilation:** +- Independent compilation with cross-module linking +- Serialization support for caching and distribution +- Built-in core modules for language features + +**Generics and interfaces:** +- First-class generic types and functions +- Interface-based programming with witness tables +- Compile-time specialization and monomorphization + +## Development Notes + +**Language features:** +- HLSL compatibility with Slang extensions +- Automatic differentiation for neural graphics +- Multi-target compilation (DX11/12, Vulkan, Metal, CUDA, CPU) +- Capability system for platform feature management + +**Testing structure:** +- Main tests in `tests/` directory +- Categories: compute, autodiff, bugs, bindings, etc. +- Expected failure lists for CI (`tests/expected-failure-*.txt`) + +**Cross-compilation:** +First build generators for build platform, then configure with `SLANG_GENERATORS_PATH` pointing to them. + +## Debugging and Development Workflow + +**Using slangc for debugging:** +```bash +# Basic compilation with target-specific output +./build/Debug/bin/slangc -target cuda file.slang + +# Debug IR stages and optimization passes +./build/Debug/bin/slangc -dump-ir -target cuda file.slang + +# HLSL output for debugging +./build/Debug/bin/slangc -target hlsl file.slang -o output.hlsl +``` + +**Interactive debugging with slangi (interpreter):** +```bash +# Run bytecode interpreter for testing without GPU +./build/Debug/bin/slangi file.slang +``` + +**Test-driven development:** +```bash +# CPU-based testing (no GPU required) +slang-test tests/your-test.slang -cpu + +# Interpreter-based testing +slang-test tests/your-test.slang -slangi + +# Test with specific backend +slang-test tests/your-test.slang -api dx12 # or vk, metal, etc. +``` + +## Code Formatting and Style + +**Before submitting changes:** +```bash +# Format code according to project standards +./extras/formatting.sh +``` + +**PR requirements:** +- All PRs must be labeled "pr: non-breaking" or "pr: breaking" +- Include regression tests under `tests/` directory +- Breaking changes are rare and only for API/language compatibility issues + +## Test Structure and Patterns + +**Test file headers for different execution modes:** +```bash +# CPU execution (no GPU required) +//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-output-using-type -cpu + +# Interpreter execution +//TEST:INTERPRET(filecheck=CHECK): + +# HLSL compilation test +//TEST(hlsl):COMPARE_HLSL: -entry main -target hlsl +``` + +**Common test categories:** +- `tests/compute/` - Compute shader tests +- `tests/autodiff/` - Automatic differentiation tests +- `tests/bugs/` - Bug reproduction and regression tests +- `tests/bindings/` - Resource binding tests |
