{"id":28203563,"url":"https://github.com/maxitservice/console2ai","last_synced_at":"2025-10-08T05:22:31.273Z","repository":{"id":292027740,"uuid":"978997554","full_name":"MaxITService/Console2Ai","owner":"MaxITService","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-22T11:17:00.000Z","size":1450,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-01T21:32:11.186Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MaxITService.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-06T20:44:57.000Z","updated_at":"2025-06-22T11:17:03.000Z","dependencies_parsed_at":"2025-05-07T19:39:56.206Z","dependency_job_id":"dabc1165-03c5-4671-9890-0005ce615414","html_url":"https://github.com/MaxITService/Console2Ai","commit_stats":null,"previous_names":["maxitservice/console2ai"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MaxITService/Console2Ai","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxITService%2FConsole2Ai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxITService%2FConsole2Ai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxITService%2FConsole2Ai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxITService%2FConsole2Ai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MaxITService","download_url":"https://codeload.github.com/MaxITService/Console2Ai/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaxITService%2FConsole2Ai/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278891761,"owners_count":26063860,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-17T02:10:22.041Z","updated_at":"2025-10-08T05:22:31.256Z","avatar_url":"https://github.com/MaxITService.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Console2Ai - PowerShell AI Assistant\n\n[![PowerShell Version](https://img.shields.io/badge/PowerShell-5.1%2B%20%7C%207%2B-blue.svg)](https://docs.microsoft.com/en-us/powershell/)\n[![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)\n[![Hits](https://hits.sh/github.com/MaxITService/Console2Ai.svg?style=flat)](https://hits.sh/github.com/MaxITService/Console2Ai/)\n\nConsole2Ai is a PowerShell script that captures your console screen buffer (or [transcript in other version](https://github.com/MaxITService/Console2Ai/tree/transcript)) content and sends it to an AI assistant. It uses [`aichat`](https://github.com/sigoden/aichat) as the backend for AI processing.\n\n---\n\n# ⚠️ Important Note\n\n\u003e *— But I’ve seen products like **Warp**, **Codex CLI**, **Terminal Beta**, **Azure AIShell**, or **VS Code GitHub Copilot** do exactly the same!*\n\n**There are similarities, but it's Not Exactly like this.** I’ve checked all these products, and technically, **none of them work with your past console screen buffer**—not a single one!\n\nLet me explain:  \nIf you’re using Windows Terminal and suddenly realize you want to use an AI tool, here’s the catch:  \nWith those other products, if you didn’t start them at the beginning of your session, you have to manually “spin them up” first (except for warp, it has a button for it). Their seamless experience only works if you planned to use them from the start.\n\n**This script is different:**  \n- **You don’t need to prepare or restart your session - in any PowerShell window, anywhere where you can load your profile, you can use your past context AFTER you realized you need it.**\n- **Just press a single key and starts supplying context to AI backend tool - it's script's single purpose.**  \n- **No need for large agent system prompts, thus super cheap**  \n- **No need to feed unneeded interactions to inference - only after you realized you need them, on a portion you need them**\n- **Starts at the speed of inference, super fast.**\n- **Price is your API token usage. (Hello warp)**\n- **FOSS**\n- **Windows terminal experience if you like it**\n\nIn short: **You get immediate, context-aware AI assistance, right when you need it—even if you decide to use it in the middle of your work. No setup, no waiting, no planning ahead.**\n\n---\n\n\n## Core Functionality\n\n![Demo GIF](Promo/Gif_Demo.gif)\n\n\n-   **Console Buffer to AI Prompt:** The main feature is capturing text from your PowerShell console buffer (the last N lines, you specify, 180 by default) and sending it directly to the AI as part of the prompt. This provides context from your recent commands and their output. You are unfortunately limited to what you see on screen. To capture more, you need to: in settings of your PowerShell profile, disable \"Scroll to input when typing\" and make window as big as possible and use Ctrl + Mousewheel to change scaling, the more you see, the more will be captured. Or, alternatively, you can use another version of this script that uses transcript. [Download it here.](https://github.com/MaxITService/Console2Ai/tree/transcript) (the file name is Console2Ai-transcript.ps1)\n-   **Alt+C Hotkey:** Quick access to AI command suggestion with a simple keyboard shortcut. (What you typed as prompt will be REPLACED with ready to press enter command)\n-   **Alt+S Hotkey:** Instantly start a conversational AI session with your console history and current query.\n-   **Context Control:** Specify how many lines of console history (1-1999) to include in the AI prompt. Simply type a number before prompt and let it go! like \"50 explain the last few commands and suggest an optimization\" - number will be automatically picked up and parsed into console history line count.\n-   **Session Logging:** Save your recent console lines to a text file for reference.\n\nWhen you press Alt+C, the script analyzes your current input line, captures the specified number of console history lines, and sends everything to `aichat`. The AI response then replaces your current input line in the console.\nAichat is free and open source application.\n\n## 📋 Prerequisites\n\nQuick recap: you will need this script loaded in powershell, and backend app \"aichat.exe\" which uses the AI API (which you will also need, this is like a key to your AI service). So you will have to install both - and guide below will explain every step that you need to take, and if somethign is not easy to understand, ask me in discussion!\n    -   **Installation:** Visit the [`aichat` GitHub releases page](https://github.com/sigoden/aichat/releases) and download the appropriate binary for your operating system (e.g., `aichat-*--x86_64-pc-windows-msvc.zip\n`).\n    -   **Link to repo if you need help:** [https://github.com/sigoden/aichat](https://github.com/sigoden/aichat)\n\n## 🛠️ Installation \u0026 Configuration\n\nFollow these steps to get Console2Ai up and running, (I've tried to make most detailed manual for every step, actual process does not take long):\n\n1.  **Install and Configure `aichat`**\n    a.  **Download `aichat`:**\n        Grab the latest release from [here](https://github.com/sigoden/aichat/releases). For Windows, you'll likely want the `...windows-x86_64.exe` file.\n\n    b.  **Add `aichat` to your PATH:**\n        For Console2Ai to find `aichat.exe`, it needs to be in your system's PATH.\n        -   Create a dedicated folder for CLI tools, e.g., `C:\\Tools\\bin`\n        -   Rename the downloaded `aichat` executable to `aichat.exe` and move it to this folder.\n        -   Add this folder to your PATH. You can do this via Windows GUI or via PowerShell:\n\n**For User PATH :**\n\n```powershell\n$CurrentUserPath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"User\")\n$AichatPath = \"C:\\Tools\\bin\" # Change this to your actual folder\nif (-not ($CurrentUserPath -split ';' -contains $AichatPath)) {\n    [System.Environment]::SetEnvironmentVariable(\"Path\", \"$CurrentUserPath;$AichatPath\", \"User\")\n    Write-Host \"Added '$AichatPath' to User PATH. Please restart PowerShell.\"\n} else {\n    Write-Host \"'$AichatPath' is already in User PATH.\"\n}\n```\n\n**For System PATH (requires Admin, affects all users):**\n\n\n\n```powershell\n$SystemPath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\")\n$AichatPath = \"C:\\Tools\\bin\" # Change this to your actual folder\nif (-not ($SystemPath -split ';' -contains $AichatPath)) {\n    [System.Environment]::SetEnvironmentVariable(\"Path\", \"$SystemPath;$AichatPath\", \"Machine\")\n    Write-Host \"Added '$AichatPath' to System PATH. Please restart PowerShell.\"\n} else {\n    Write-Host \"'$AichatPath' is already in System PATH.\"\n}\n```\n\n**Verify:** Open a *new* PowerShell terminal and type `aichat --version`. You should see the version information.\n\n**c. Configure `aichat` Model \u0026 API Key:**\n        `aichat` needs to know which AI model to use and requires an API key for that service (e.g., OpenAI, OpenRouter, Ollama, Gemini, etc.).\n        Configuration instructions are here [aichat configuration example](https://github.com/sigoden/aichat/blob/main/config.example.yaml). But to quickly get you started you may need only these steps:\n        Create or edit a `config.yaml` file. For Windows, this file should be put in youur user profile at: `C:\\Users\\Username\\AppData\\Roaming\\aichat\\config.yaml` (replace `Username` with your Windows username).\n        You can quickly open this folder by typing `explorer %APPDATA%\\aichat` in PowerShell.\n        You don't need to have everything, here is my config that works:\n        Example configuration file for OpenRouter with Claude:\n        \n        model: openrouter:anthropic/claude-3.7-sonnet\n        clients:\n        - type: openai-compatible\n          name: openrouter\n          api_base: https://openrouter.ai/api/v1\n          api_key: sk-or-v1-a96_YOUR_API_KEY_PASTE_IT_HERE_AND_KEEP_IT_SECRET\n        \n        \nTest `aichat` from your terminal after configuration:\n\n        aichat \"What is PowerShell?\"\n        \nThis will make sure the base application for this script is working.\n\n2.  **Install `Console2Ai.ps1`**\n    1.  Download `Console2Ai.ps1` from this repository and place it in a convenient folder (e.g., `C:\\Users\\YourUser\\Documents\\PowerShell\\Scripts\\Console2Ai.ps1` or `C:\\Scripts\\Console2Ai.ps1`).\n\n    2.  Open your PowerShell profile for editing:\n        ```powershell\n        notepad $PROFILE\n        ```\n\n    3.  Copy and paste the following snippet into your profile (adjust the path as needed):\n        ```powershell\n        # Import-Module PSReadLine  # Uncomment if needed\n        . C:\\Users\\YourUser\\Documents\\PowerShell\\Scripts\\Console2Ai.ps1  # Adjust path if needed\n        ```\n\n    4.  Save the profile and **restart PowerShell**.\n\n## 🚀 How to Use Console2Ai\n\nOnce installed, you have a few ways to interact with Console2Ai:\n\n1.  **The `Alt+C` Hotkey (Command Suggestion)** 🔥\n    This will replace your current text that you have typed in the console with AI's suggestion after a while. (Your text will be deleted and a command that resembles your text will appear instead)\n\n    a.  **Standard Query:**\n        Type your question, command fragment, or error message into the PowerShell prompt.\n\n        \n        PS C:\\\u003e Get-ChildItem -Path C:\\NonExistentFolder -Recurse # You see an error after this\n        PS C:\\\u003e Retry with correct path # Now press Alt+C   \n\n\n    It will send this to `aichat`, and replace your query with the AI's suggested command or explanation.\n\n    b.  **Specify Line Count for History:** ✨\n        If you want to provide more or less context from your console history:\n        -   Start your typed line with a number (1-1999) followed by a space, then your query.\n\n            \n             ... lots of previous output ...\n            PS C:\\\u003e 50 explain the last few commands and suggest an optimization # Press Alt+S\n            \n    Console2Ai will capture the last 50 lines of history along with your query.\n    If you only type a number (e.g., `30`) and press `Alt+C`, it will use that many lines of history and a generic prompt for the AI.\n\n2.  **The `Alt+S` Hotkey (Conversational Chat)** 💬\n    Start a conversational AI session with your console history as context and your current query. Unlike Alt+C, Alt+S is focused on back-and-forth conversation, not just command suggestions. Your text is not deleted.\n\n\n    -   **How it works:**\n        -   Type your question or message into the PowerShell prompt.\n        -   Press `Alt+S`.\n        -   Console2Ai will capture the last 180 lines of console history (by default) plus your typed query, then open a conversational AI session using `aichat`.\n        -   The AI will reply conversationally, focusing on explanations, troubleshooting, or general answers (not just commands).\n    -   **Example Usage:**\n        -   To ask why your script is running slowly, type your query and press `Alt+S`:\n            ```powershell\n            PS C:\\\u003e from this dir, which files are needed for funciton and which are temporary files? # Press Alt+S\n            ```\n            This will start a response from AI including recent console history as context.\n        -   To specify a different number of history lines (e.g., 40) works with both Alt+C and Alt+S:\n            ```powershell\n            PS C:\\\u003e 40 ok, all files you mentioned - delete them with Regex # Press Alt+C\n    -   Under the hood, Alt+S calls the `Invoke-Console2AiConversation` function. And Alt+C calls `Invoke-AIConsoleHelp` function.\n\n3.  **Using the PowerShell Functions** ⚙️\n    Console2Ai also provides standard PowerShell functions if you prefer:\n\n    a.  **`Invoke-AIConsoleHelp`**\n        Manually trigger AI assistance.\n\n        \n        # Get help based on the last 180 lines of console history\n        Invoke-AIConsoleHelp\n\n        # Get help with more context and a specific prompt\n        Invoke-AIConsoleHelp -LinesToCapture 25 -UserPrompt \"What does this error mean and how to fix it?\"\n        \n\n    b.  **`Invoke-Console2AiConversation`**\n        Manually start a conversational AI session (same as Alt+S):\n        \n        Invoke-Console2AiConversation -UserQuery \"Explain this error\" -LinesToCapture 20\n        \n\n    c.  **`Save-ConsoleHistoryLog`** 💾\n        Save recent console output to a file.\n        \n        # Save the last 180 lines to .\\log.txt (if your window is big enough)\n        Save-ConsoleHistoryLog\n\n        # Save the last 30 lines to a custom file\n        Save-ConsoleHistoryLog -LinesToCapture 30 -LogFilePath \"C:\\temp\\session_details.txt\"\n        \n\n4.  **Getting Help Within PowerShell** ❓\n    You can use PowerShell's built-in help system:\n    \n        Get-Help Invoke-AIConsoleHelp -Full\n        Get-Help Invoke-Console2AiConversation -Full\n        Get-Help Save-ConsoleHistoryLog -Full\n    \n\n## 🔧 Customization (Optional)\n\nYou can modify `Console2Ai.ps1` directly to change:\n\n-   **`$Global:Console2Ai_AIChatExecutable`**: If `aichat.exe` is named differently or you want to use a full path.\n-   **`$Global:Console2Ai_CommandMode_AIPromptInstruction`**: The default instruction template sent to the AI for Alt+C (command suggestion).\n-   **`$Global:Console2Ai_ConversationMode_AIPromptInstruction`**: The default instruction template sent to the AI for Alt+S (conversational chat).\n-   **`$Global:Console2Ai_MaxLinesForHotkeyParse`**: The maximum number of console history lines you can specify for Alt+C/Alt+S hotkeys (default: 1999). Change this if you want to allow more or fewer lines to be parsed from the prompt.\n\n## Troubleshooting\n\n### Alt+C doesn't work\n\n-   Ensure PSReadLine module is loaded. (It usually is by default in modern PowerShell).\n-   Check your PowerShell profile (`$PROFILE`) to ensure `Console2Ai.ps1` is being dot-sourced correctly and after PSReadLine might be imported.\n-   Ensure no other Alt+C binding is overriding it.\n\n### AI Errors (❌ Console2Ai AI Error...)\n\n-   Verify `aichat.exe` is in your PATH and working (`aichat --version`).\n-   Check your `aichat` configuration (`%APPDATA%\\aichat\\config.yaml`). Is the model correct? Is your API key valid and correctly configured (e.g., `OPENAI_API_KEY` environment variable)?\n-   Check your internet connection.\n\n### \"No console history was captured\"\n\n-   This can happen if the console buffer is empty or very short (e.g., right after `Clear-Host` or `cls`). The functions will still try to work with any typed user prompt.\n\n## License\n\nDo whatever you want just mention me if you can\n\n## Promo (My other stuff!)\nCheck out my Free Extension for Web AI chats to quickly reuse your prompts:\n\n[![Check out my Free Extension for Web AI chats to quickly reuse your prompts](https://github.com/MaxITService/ChatGPT-Quick-Buttons-for-your-text/raw/master/Promo/promo440_280.png)](https://chromewebstore.google.com/detail/oneclickprompts/iiofmimaakhhoiablomgcjpilebnndbf?authuser=1)\n\n[OneClickPrompts on Chrome Web Store](https://chromewebstore.google.com/detail/oneclickprompts/iiofmimaakhhoiablomgcjpilebnndbf?authuser=1)\n[it is open source](https://github.com/MaxITService/ChatGPT-Quick-Buttons-for-your-text)\n\n---\n\n[The PowerShell Ping Plotter](https://github.com/MaxITService/Ping-Plotter-PS51)\n\n## Warranties\n\nUSE AT YOUR OWN RISK! No warranties! If something does not work or you need help, please contact me here, and I will try to help. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxitservice%2Fconsole2ai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxitservice%2Fconsole2ai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxitservice%2Fconsole2ai/lists"}