diff --git a/tools/ai/README.md b/tools/ai/README.md
index d36b890a2..470d559fe 100644
--- a/tools/ai/README.md
+++ b/tools/ai/README.md
@@ -1,26 +1,48 @@
-# repo-structure.sh
+## `repo-structure.sh`
-Quick utility to generate a repository file structure in a format optimized for AI assistants. The output uses XML-style context tags with proper indentation for easy understanding of the directory hierarchy.
+This tool creates a compact, hierarchical representation of your Git repository that you can
+paste directly into an assistant prompt to provide immediate context. Uses the XML format of
+Claude Code.
-## Why?
-
-Ever tried explaining a codebase to an AI assistant? This tool creates a compact, hierarchical representation of your Git repository that you can paste directly into an assistant prompt to provide immediate context.
-
-## Usage
-
-You need to be inside a Git repository to run this:
-
-### Direct execution (recommended)
+### Remote Execution
```bash
-# From the repository root:
-./tools/ai/repo-structure.sh
+# Run this from the ROOT of your git repository
+curl -fsSL https://raw.githubusercontent.com/enricoros/big-AGI/v2-dev/tools/ai/repo-structure.sh | sh
+```
-# Include hidden files (starting with .)
-./tools/ai/repo-structure.sh --all
+## Options
-# Copy directly to clipboard
-./tools/ai/repo-structure.sh --clipboard
+- `-a, --all`: Include hidden files and directories
+- `-o, --output FILE`: Save output to a file
+- `-h, --help`: Show help message
-# Save to a file
-./tools/ai/repo-structure.sh --output repo-structure.xml
+Example with options (include hidden files):
+
+- `curl -fsSL https://raw.githubusercontent.com/enricoros/big-AGI/v2-dev/tools/ai/repo-structure.sh | sh -s -- -a`
+
+## Requirements
+
+- Bash 4+ (for associative arrays)
+- Git (the repository must be initialized)
+- For clipboard functionality:
+ - macOS: pbcopy (built-in)
+ - Linux: xclip or xsel
+ - Windows: clip (Git Bash)
+
+## How does the output look?
+
+The output is specifically formatted for easy consumption by AI assistants:
+
+```xml
+
+- README.md
+- src/
+ - app/
+ - components/
+ - Button.tsx
+ ...
+
+```
+
+Just paste this into your AI assistant's prompt for instant context about the codebase structure.
diff --git a/tools/ai/repo-structure.sh b/tools/ai/repo-structure.sh
index 2569ebc1f..411200111 100644
--- a/tools/ai/repo-structure.sh
+++ b/tools/ai/repo-structure.sh
@@ -3,16 +3,17 @@
# Wraps output in tags.
# Hides dotfiles by default, use -a/--all to show them.
-# Default: exclude hidden files/dirs
+# Default settings
INCLUDE_HIDDEN=false
+COPY_TO_CLIPBOARD=true
# Function to print usage
print_usage() {
echo "Usage: $0 [options]"
echo "Options:"
- echo " -a, --all Include hidden files and directories (starting with '.')"
- echo " -o, --output Output to a file instead of stdout (e.g., -o structure.xml)"
- echo " -h, --help Show this help message"
+ echo " -a, --all Include hidden files and directories (starting with '.')"
+ echo " -o, --output Output to a file instead of stdout (e.g., -o structure.xml)"
+ echo " -h, --help Show this help message"
}
# Parse arguments
@@ -27,7 +28,33 @@ while [[ "$#" -gt 0 ]]; do
shift
done
-# Start the output generation
+# Check if we're in a git repository
+if ! git rev-parse --is-inside-work-tree &>/dev/null; then
+ echo "Error: This script must be run from within a Git repository." >&2
+ echo "Please navigate to your cloned Big-AGI repository and try again." >&2
+ exit 1
+fi
+
+
+# Try to find the clipboard command for the current OS
+clipboard_cmd=""
+if [[ "$OSTYPE" == "darwin"* ]]; then
+ # macOS
+ clipboard_cmd="pbcopy"
+elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
+ # Linux with X11
+ if command -v xclip &>/dev/null; then
+ clipboard_cmd="xclip -selection clipboard"
+ elif command -v xsel &>/dev/null; then
+ clipboard_cmd="xsel --clipboard --input"
+ fi
+elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
+ # Windows Git Bash or similar
+ clipboard_cmd="clip"
+fi
+
+
+# Generate the structure
generate_structure() {
# Use XML-like tags instead of markdown code fences
echo ''
@@ -104,10 +131,27 @@ if (( BASH_VERSINFO[0] < 4 )); then
exit 1
fi
-# Either output to file or stdout
+# Handle output to file, clipboard, or stdout
if [[ -n "$OUTPUT_FILE" ]]; then
generate_structure > "$OUTPUT_FILE"
echo "Repository structure saved to $OUTPUT_FILE"
+
+ if [[ "$COPY_TO_CLIPBOARD" == true ]]; then
+ if [[ -n "$clipboard_cmd" ]]; then
+ cat "$OUTPUT_FILE" | eval "$clipboard_cmd"
+ echo "Also copied to clipboard!"
+ else
+ echo "Warning: Clipboard copy requested but no clipboard command found for your OS." >&2
+ fi
+ fi
+elif [[ "$COPY_TO_CLIPBOARD" == true ]]; then
+ if [[ -n "$clipboard_cmd" ]]; then
+ generate_structure | tee >(eval "$clipboard_cmd" > /dev/null)
+ echo -e "\nStructure copied to clipboard!"
+ else
+ echo "Warning: No clipboard command found for your OS. Displaying output instead." >&2
+ generate_structure
+ fi
else
generate_structure
fi