# Remote Container Manager ## Table of Contents - [Overview](#overview) - [Features](#features) - [Prerequisites](#prerequisites) - [Installation](#installation) - [Configuration](#configuration) - [Usage](#usage) - [Logging](#logging) - [Troubleshooting](#troubleshooting) - [Contributing](#contributing) - [License](#license) ## Overview **Remote Container Manager** is a Node.js script designed to automate the management of remote Debian/Ubuntu-based Linux containers. Leveraging AI-driven command generation and robust API integrations, this tool simplifies tasks such as package installation and service management by executing precise shell commands on remote containers. ## Features - **AI-Powered Command Generation:** Utilizes AI to generate shell commands based on your specified goals and context. - **Verbose Logging:** Detailed and formatted logs make it easy to track the script's actions and outputs. - **API Integration:** Connects seamlessly with Groq and Discord Linux APIs to execute commands remotely. - **Iterative Execution:** Attempts to achieve the desired state through multiple iterations, refining commands based on previous outcomes. - **Environment Configuration:** Easily manage API keys and other settings via environment variables. ## Prerequisites Before you begin, ensure you have met the following requirements: - **Node.js:** Version 14.0 or higher. [Download Node.js](https://nodejs.org/) - **Git:** For cloning the repository. [Download Git](https://git-scm.com/) - **API Access:** - **Groq API Key** - **Discord Linux API Key** ## Installation 1. **Clone the Repository** ```bash git clone https://git.ssh.surf/snxraven/discord-linux-groq-agent.git cd discord-linux-groq-agent ``` 2. **Install Dependencies** Ensure you have [Node.js](https://nodejs.org/) installed. Then, install the required packages: ```bash npm install ``` ## Configuration 1. **Create Environment Variables** The script relies on environment variables for API keys and configurations. An example file named `default.env` is provided. Follow these steps to set up your environment variables: - **Copy the Example `.env` File** ```bash cp default.env .env ``` - **Edit the `.env` File** Open the `.env` file in your preferred text editor and replace the placeholder values with your actual API keys. ```env # .env DISCORD_LINUX_API_URL=https://api.ssh.surf DISCORD_LINUX_API_KEY=your_discord_linux_api_key GROQ_API_KEY=your_groq_api_key ``` - **Environment Variables Explained** | Variable | Description | | ---------------------- | -------------------------------------------------- | | `DISCORD_LINUX_API_URL`| The base URL for the Discord Linux API. | | `DISCORD_LINUX_API_KEY`| Your API key for authenticating with Discord Linux. | | `GROQ_API_KEY` | Your Groq API key for AI-driven command generation.| ## Usage To run the script, use the following command: ```bash node index.js ``` **Example Goal:** ```javascript const goal = 'install apache2 (apache2) on the container and run it with service'; ``` **Script Flow:** 1. **Initialization:** Sets up the Groq client and logs the starting process. 2. **AI Instruction Request:** Sends the current context and goal to the AI to receive shell commands. 3. **Command Execution:** Executes each command on the remote container, logging the output. 4. **Iteration:** Repeats the process up to a maximum number of iterations (`MAX_ITERATIONS`) until the goal is achieved or attempts are exhausted. ## Logging The script features comprehensive and formatted logging to ensure transparency and ease of monitoring. ### Log Components - **Headers:** Clearly marked sections indicating the start of processes and iterations. - **Subheaders:** Indicate specific actions like requesting AI instructions. - **Info Messages:** Provide status updates on command execution success or failure. - **Command Execution Logs:** Detailed output of each executed command, including `stdout` and `stderr`. **Example Log Output:** ``` ════════════════════════════════════════════════════════════════════════════════════════ ═ STARTING PROCESS TO ACHIEVE GOAL: install apache2 (apache2) on the container and run it with service ════════════════════════════════════════════════════════════════════════════════════════ ════════════════════════════════════════════════════════════════════════════════════════ ═ ITERATION 1 OF 5 ════════════════════════════════════════════════════════════════════════════════════════ ------------------------------------------------------------ > Asking AI for instructions ------------------------------------------------------------ AI PROVIDED COMMANDS: sudo apt-get update sudo apt-get install -y apache2 sudo service apache2 start [EXECUTING COMMAND] $ sudo apt-get update [STDOUT]: Get:1 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB] ... [STDERR]: (empty) INFO: Command executed successfully. ... SUCCESS! The goal appears to have been achieved. ``` ## Troubleshooting If you encounter issues while running the script, consider the following steps: 1. **Check Environment Variables:** - Ensure all required environment variables are set correctly in the `.env` file. - Verify that API keys are valid and have the necessary permissions. 2. **API Connectivity:** - Confirm that the `DISCORD_LINUX_API_URL` is correct and reachable. - Check your internet connection and any firewall settings that might block API requests. 3. **Dependencies:** - Make sure all dependencies are installed by running `npm install`. - Verify that you're using a compatible Node.js version (14.0 or higher). 4. **Script Errors:** - Review the console logs for specific error messages. - Ensure that the remote container is accessible and configured correctly. 5. **AI Command Accuracy:** - If the AI provides incorrect or ineffective commands, consider refining the `systemPrompt` or providing more context. ## Contributing Contributions are welcome! Follow these steps to contribute: 1. **Fork the Repository** 2. **Create a Feature Branch** ```bash git checkout -b feature/YourFeature ``` 3. **Commit Your Changes** ```bash git commit -m "Add your feature" ``` 4. **Push to the Branch** ```bash git push origin feature/YourFeature ``` 5. **Open a Pull Request** Please ensure your contributions adhere to the project's coding standards and include appropriate documentation.