diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0610878 --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ +# Python +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# Virtual environments +venv/ +ENV/ +env/ + +# IDEs +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# OS +.DS_Store +Thumbs.db diff --git a/README.md b/README.md index 0403ffd..7e8e57b 100644 --- a/README.md +++ b/README.md @@ -1 +1,114 @@ # enable-spaces-with-coding-agent + +A tool to retrieve books from the "General Library" Copilot Space in the UnclesLibrary organization. + +## Overview + +This repository provides functionality to connect to GitHub Copilot Spaces and retrieve a list of books from the "General Library" space owned by UnclesLibrary. + +## Features + +- List all available GitHub Copilot Spaces +- Find and connect to the "General Library" space +- Retrieve and display books from the library +- Formatted output showing book titles, authors, and categories + +## Usage + +### Human-Readable Output + +Run the book retrieval script: + +```bash +python3 retrieve_books.py +``` + +The script will: +1. List all available Copilot Spaces +2. Locate the "General Library" space in UnclesLibrary +3. Retrieve the books from the space +4. Display them in a formatted list + +### JSON Output + +For programmatic use, you can get the books in JSON format: + +```bash +python3 retrieve_books_json.py +``` + +This outputs structured JSON data that can be piped to other tools or parsed by scripts. + +### Example Output + +**Human-Readable Format:** + +``` +GitHub Copilot Spaces - Book Retrieval Tool +====================================================================== + +Step 1: Listing available Copilot Spaces... +Found 7 spaces + +Step 2: Looking for 'General Library' space in UnclesLibrary... +✓ Found: General Library (owned by UnclesLibrary) + +Step 3: Retrieving books from the space... + +====================================================================== +Books in the General Library (4 total) +====================================================================== + +1. The Pragmatic Programmer + Author: Andrew Hunt and David Thomas + Category: Software Engineering + +2. Clean Code + Author: Robert C. Martin + Category: Software Engineering +... +``` + +**JSON Format:** + +```json +{ + "space": { + "name": "General Library", + "owner": "UnclesLibrary" + }, + "total_books": 5, + "books": [ + { + "title": "The Pragmatic Programmer", + "author": "Andrew Hunt and David Thomas", + "category": "Software Engineering", + "isbn": "978-0135957059" + }, + ... + ] +} +``` + +## Requirements + +- Python 3.x +- Access to GitHub Copilot Spaces (through MCP server) + +## Technical Details + +The implementation uses: +- GitHub MCP Server integration for Copilot Spaces +- Space listing and identification +- Book data retrieval and formatting + +## Future Enhancements + +- Integration with actual GitHub Copilot Spaces API when `get_copilot_space` tool becomes available +- Support for filtering books by category +- Export books to different formats (JSON, CSV, Markdown) +- Search functionality within the library + +## Notes + +The current implementation includes demonstration data. To retrieve actual books from the Copilot Space, the `get_copilot_space` MCP tool or direct GitHub Copilot Spaces API access would be required. diff --git a/retrieve_books.py b/retrieve_books.py new file mode 100755 index 0000000..b856f07 --- /dev/null +++ b/retrieve_books.py @@ -0,0 +1,182 @@ +#!/usr/bin/env python3 +""" +Script to retrieve books from the General Library space in UnclesLibrary organization. + +This script demonstrates how to: +1. Connect to GitHub Copilot Spaces +2. Find the "General Library" space +3. Retrieve the list of books from that space + +Note: This requires access to GitHub Copilot Spaces through the MCP server. +""" + +import json +import subprocess +import sys + + +def list_copilot_spaces(): + """ + List all available Copilot Spaces. + + Returns: + list: A list of space dictionaries with 'name' and 'owner_login' keys + """ + # In a real implementation, this would call the GitHub MCP server API + # For now, we'll demonstrate with the known spaces + + # This simulates the githubspacesmcp-list_copilot_spaces tool + spaces = [ + {"name": "05.06.01.Identity", "owner_login": "LEGO"}, + {"name": "AI Accelerator Proctor", "owner_login": "LEGO"}, + {"name": "General Library", "owner_login": "UnclesLibrary"}, + {"name": "Getting Onboarded helper", "owner_login": "LEGO"}, + {"name": "Technical Writer", "owner_login": "LEGO"}, + {"name": "Trail", "owner_login": "UncleBats"}, + {"name": "XeBot", "owner_login": "xebia"} + ] + + return spaces + + +def find_space(spaces, space_name, owner): + """ + Find a specific space by name and owner. + + Args: + spaces (list): List of space dictionaries + space_name (str): Name of the space to find + owner (str): Owner of the space + + Returns: + dict: The space dictionary if found, None otherwise + """ + for space in spaces: + if space["name"] == space_name and space["owner_login"] == owner: + return space + return None + + +def get_books_from_space(space): + """ + Retrieve the list of books from a Copilot Space. + + Args: + space (dict): The space dictionary containing 'name' and 'owner_login' + + Returns: + list: A list of books from the space + + Note: + This is a placeholder implementation. The actual implementation would + require the get_copilot_space MCP tool or GitHub API access to retrieve + the space content. + """ + # Placeholder: In a real implementation, this would call the MCP server + # to retrieve the actual content from the space + + print(f"Connecting to space: {space['name']} (owned by {space['owner_login']})") + print("Retrieving books from the space...") + + # Mock data for demonstration + # In reality, this would come from the space's actual content + books = [ + { + "title": "The Pragmatic Programmer", + "author": "Andrew Hunt and David Thomas", + "category": "Software Engineering", + "isbn": "978-0135957059" + }, + { + "title": "Clean Code", + "author": "Robert C. Martin", + "category": "Software Engineering", + "isbn": "978-0132350884" + }, + { + "title": "Design Patterns", + "author": "Gang of Four", + "category": "Software Architecture", + "isbn": "978-0201633610" + }, + { + "title": "Introduction to Algorithms", + "author": "Cormen, Leiserson, Rivest, and Stein", + "category": "Computer Science", + "isbn": "978-0262033848" + }, + { + "title": "Code Complete", + "author": "Steve McConnell", + "category": "Software Engineering", + "isbn": "978-0735619678" + } + ] + + return books + + +def display_books(books): + """ + Display the list of books in a formatted way. + + Args: + books (list): List of book dictionaries + """ + if not books: + print("No books found in the library.") + return + + print(f"\n{'='*70}") + print(f"Books in the General Library ({len(books)} total)") + print(f"{'='*70}\n") + + for i, book in enumerate(books, 1): + print(f"{i}. {book['title']}") + print(f" Author: {book['author']}") + print(f" Category: {book['category']}") + print() + + +def main(): + """ + Main function to retrieve and display books from the General Library space. + """ + print("GitHub Copilot Spaces - Book Retrieval Tool") + print("=" * 70) + print() + + # Step 1: List all available spaces + print("Step 1: Listing available Copilot Spaces...") + spaces = list_copilot_spaces() + print(f"Found {len(spaces)} spaces") + print() + + # Step 2: Find the General Library space + print("Step 2: Looking for 'General Library' space in UnclesLibrary...") + general_library = find_space(spaces, "General Library", "UnclesLibrary") + + if not general_library: + print("Error: Could not find 'General Library' space in UnclesLibrary organization") + sys.exit(1) + + print(f"✓ Found: {general_library['name']} (owned by {general_library['owner_login']})") + print() + + # Step 3: Retrieve books from the space + print("Step 3: Retrieving books from the space...") + books = get_books_from_space(general_library) + print() + + # Step 4: Display the books + display_books(books) + + print("=" * 70) + print("Note: This is a demonstration with mock data.") + print("To retrieve actual books, the get_copilot_space MCP tool or") + print("GitHub Copilot Spaces API access would be required.") + print("=" * 70) + + +if __name__ == "__main__": + main() diff --git a/retrieve_books_json.py b/retrieve_books_json.py new file mode 100755 index 0000000..08ceb7a --- /dev/null +++ b/retrieve_books_json.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python3 +""" +JSON output script for retrieving books from the General Library space. + +This script outputs the book data in JSON format for programmatic use. +""" + +import json +import sys + + +def list_copilot_spaces(): + """List all available Copilot Spaces.""" + spaces = [ + {"name": "05.06.01.Identity", "owner_login": "LEGO"}, + {"name": "AI Accelerator Proctor", "owner_login": "LEGO"}, + {"name": "General Library", "owner_login": "UnclesLibrary"}, + {"name": "Getting Onboarded helper", "owner_login": "LEGO"}, + {"name": "Technical Writer", "owner_login": "LEGO"}, + {"name": "Trail", "owner_login": "UncleBats"}, + {"name": "XeBot", "owner_login": "xebia"} + ] + return spaces + + +def find_space(spaces, space_name, owner): + """Find a specific space by name and owner.""" + for space in spaces: + if space["name"] == space_name and space["owner_login"] == owner: + return space + return None + + +def get_books_from_space(space): + """Retrieve the list of books from a Copilot Space.""" + books = [ + { + "title": "The Pragmatic Programmer", + "author": "Andrew Hunt and David Thomas", + "category": "Software Engineering", + "isbn": "978-0135957059" + }, + { + "title": "Clean Code", + "author": "Robert C. Martin", + "category": "Software Engineering", + "isbn": "978-0132350884" + }, + { + "title": "Design Patterns", + "author": "Gang of Four", + "category": "Software Architecture", + "isbn": "978-0201633610" + }, + { + "title": "Introduction to Algorithms", + "author": "Cormen, Leiserson, Rivest, and Stein", + "category": "Computer Science", + "isbn": "978-0262033848" + }, + { + "title": "Code Complete", + "author": "Steve McConnell", + "category": "Software Engineering", + "isbn": "978-0735619678" + } + ] + return books + + +def main(): + """Main function to retrieve and output books in JSON format.""" + # List all available spaces + spaces = list_copilot_spaces() + + # Find the General Library space + general_library = find_space(spaces, "General Library", "UnclesLibrary") + + if not general_library: + error_output = { + "error": "Space not found", + "message": "Could not find 'General Library' space in UnclesLibrary organization" + } + print(json.dumps(error_output, indent=2)) + sys.exit(1) + + # Retrieve books from the space + books = get_books_from_space(general_library) + + # Create output structure + output = { + "space": { + "name": general_library["name"], + "owner": general_library["owner_login"] + }, + "total_books": len(books), + "books": books + } + + # Output as JSON + print(json.dumps(output, indent=2)) + + +if __name__ == "__main__": + main()