Skip to content

upload files to generate a context for new questions #211

Open
@henry-hz

Description

First of all, thanks for the plugin, amazing design and implementation!

I would like to ask if there is a way to have the repo files uploaded to the AI agent, so we can ask questions about the repo and even more, have the code generation follow the actual repo code style. In the same way we already have a context that is uploaded every request, we could follow the pattern and have an agent context, will all the repository data (see the script below), so questions about the repo could be answered.

I found this idea on the phind plugin on vscode.

#!/bin/bash

# Set the path to your Solidity project
PROJECT_DIR="."

# Set the output file name for the repository context
OUTPUT_FILE="repo_context.txt"

# Function to append content to the output file
append_to_file() {
    echo "$1" >> "$OUTPUT_FILE"
}

# Create an empty output file
echo "" > "$OUTPUT_FILE"

# Append project directory structure
append_to_file "Project Directory Structure:"
tree -d "$PROJECT_DIR" | grep -v "node_modules" | grep -v "artifacts" | sed 's/^/  /' >> "$OUTPUT_FILE"

# Append list of Solidity contracts
append_to_file "\nSolidity Contracts:"
find "$PROJECT_DIR" -name "*.sol" | sed 's|^./||' | while read -r contract; do
    append_to_file "  - $contract"
done

# Append list of test files
append_to_file "\nTest Files:"
find "$PROJECT_DIR/test" -name "*.t.sol" | sed 's|^./||' | while read -r test_file; do
    append_to_file "  - $test_file"
done

# Append list of script files
append_to_file "\nScript Files:"
find "$PROJECT_DIR/script" -name "*.s.sol" | sed 's|^./||' | while read -r script_file; do
    append_to_file "  - $script_file"
done

# Append contents of key project files
append_to_file "\nKey Project Files:"

# Foundry configuration file
if [ -f "$PROJECT_DIR/foundry.toml" ]; then
    append_to_file "\n  foundry.toml:"
    cat "$PROJECT_DIR/foundry.toml" | sed 's/^/    /' >> "$OUTPUT_FILE"
fi

# Readme file
if [ -f "$PROJECT_DIR/README.md" ]; then
    append_to_file "\n  README.md:"
    cat "$PROJECT_DIR/README.md" | sed 's/^/    /' >> "$OUTPUT_FILE"
fi

# Deployment scripts
deployment_scripts=$(find "$PROJECT_DIR/script" -name "deploy*.s.sol")
if [ -n "$deployment_scripts" ]; then
    append_to_file "\nDeployment Scripts:"
    echo "$deployment_scripts" | while read -r script; do
        append_to_file "\n  $script:"
        cat "$script" | sed 's/^/    /' >> "$OUTPUT_FILE"
    done
fi

append_to_file "\nConcatenated Files:"

append_to_file "\n  src files:"
find "$PROJECT_DIR/src" -type f -print0 | while IFS= read -r -d '' file; do
    append_to_file "\n    $file:"
    cat "$file" | sed 's/^/      /' >> "$OUTPUT_FILE"
done

append_to_file "\n  test files:"
find "$PROJECT_DIR/test" -type f -print0 | while IFS= read -r -d '' file; do
    append_to_file "\n    $file:"
    cat "$file" | sed 's/^/      /' >> "$OUTPUT_FILE"
done

echo "Repository context created in $OUTPUT_FILE"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions