### Common npm Commands for Astro Projects Source: https://github.com/smallcloudai/refact/blob/main/docs/README.md A list of essential npm commands for managing an Astro project. These commands cover installing dependencies, starting a development server, building for production, and previewing the build. ```bash npm install npm run dev npm run build npm run preview npm run astro ... npm run astro -- --help ``` -------------------------------- ### Install refact package Source: https://github.com/smallcloudai/refact/blob/main/refact-server/README.md Installs the refact package using pip. This is the standard way to install the library for use. ```shell pip install . ``` -------------------------------- ### Create Astro + Starlight Project Source: https://github.com/smallcloudai/refact/blob/main/docs/README.md Use npm to create a new Astro project with the Starlight template. This command initializes a new project and installs the necessary dependencies. ```bash npm create astro@latest -- --template starlight ``` -------------------------------- ### Install Refact for Development Source: https://github.com/smallcloudai/refact/blob/main/refact-server/CONTRIBUTING.md Clones the Refact repository from GitHub and installs it in editable mode using pip. This is the initial step for setting up a local development environment. ```commandline git clone https://github.com/smallcloudai/refact pip install -e refact/ ``` -------------------------------- ### Start Refact Agent Frontend (React) Source: https://github.com/smallcloudai/refact/blob/main/CONTRIBUTING.md Installs dependencies and starts the development server for the Refact Agent's React frontend. It connects to the Rust engine running on port 8001. ```bash # In a new terminal, navigate to the GUI directory cd refact-agent/gui/ # Install dependencies npm ci # Start the development server npm run dev ``` -------------------------------- ### Install Refact Python Package Source: https://github.com/smallcloudai/refact/blob/main/README.md Installs the Refact repository using pip. Supports GPU installations with CUDA and flash-attention v2. ```bash pip install . ``` ```bash FLASH_ATTENTION_FORCE_BUILD=TRUE MAX_JOBS=4 INSTALL_OPTIONAL=TRUE pip install . ``` -------------------------------- ### Install refact with flash-attention v2 Source: https://github.com/smallcloudai/refact/blob/main/refact-server/README.md Installs the refact package with support for flash-attention v2, which requires a compatible GPU (CUDA capability >= 8.0). It also sets maximum parallel jobs and installs optional dependencies. ```shell FLASH_ATTENTION_FORCE_BUILD=TRUE MAX_JOBS=4 INSTALL_OPTIONAL=TRUE pip install . ``` -------------------------------- ### Start an Existing Docker Container Source: https://github.com/smallcloudai/refact/blob/main/refact-server/README.md Starts a previously stopped Docker container. Replace 'XXX' with the container ID or name. ```commandline docker start XXX ``` -------------------------------- ### Run the Refact Server Source: https://github.com/smallcloudai/refact/blob/main/refact-server/CONTRIBUTING.md Starts the main Refact server process using the docker_watchdog module. This command is used to run the entire server infrastructure. ```commandline python -m self_hosting_machinery.watchdog.docker_watchdog ``` -------------------------------- ### MCP Server Command Examples Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/features/autonomous-agent/integrations/mcp.md Provides examples of how to execute MCP server commands using different package managers and environments, including Node.js, Python virtual environments, and Docker. ```shell npx -y ``` ```shell /my/path/venv/python -m ``` ```shell docker run -i --rm ``` ```shell npx.cmd -y ``` ```shell npm.cmd -y ``` -------------------------------- ### Compile and Install Refact Agent CLI (Rust) Source: https://github.com/smallcloudai/refact/blob/main/refact-agent/engine/README.md Instructions to compile the Refact Agent from source using Cargo and install it for command-line usage. This involves building the release version, copying the executable, and installing the Python package. ```bash cargo build --release cp target/release/refact-lsp python_binding_and_cmdline/refact/bin/ pip install -e python_binding_and_cmdline/ ``` -------------------------------- ### Start Nginx with Custom Configuration (Bash) Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/guides/reverse-proxy.md Starts the nginx server in the foreground using a specified configuration file. Running in the foreground allows for easier stopping and restarting. ```bash /opt/homebrew/opt/nginx/bin/nginx -g "daemon off;" -c ~/my_reverse_proxy.config ``` -------------------------------- ### Build and Run Refact Agent Backend (Rust) Source: https://github.com/smallcloudai/refact/blob/main/CONTRIBUTING.md Builds and runs the Rust backend for the Refact Agent. Requires Rust, Git, and an API key. It starts the engine on specified ports. ```bash git clone https://github.com/smallcloudai/refact.git cd refact # Install Rust if you haven't already curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source ~/.cargo/env # Navigate to the engine directory cd refact-agent/engine/ # Build the project cargo build # Run the engine with your API key cargo run -- --address-url Refact --api-key --http-port 8001 --lsp-port 8002 --logs-stderr --vecdb --ast --workspace-folder . ``` -------------------------------- ### Example Confirmation Rule: Deny Elevated Privileges Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/features/autonomous-agent/integrations/command-line-tool.md Illustrates a confirmation rule to automatically deny the execution of commands that require elevated privileges. This is achieved using a regular expression pattern that matches commands starting with 'sudo'. ```shell sudo* ``` -------------------------------- ### Example Command Parameter Substitution Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/features/autonomous-agent/integrations/command-line-tool.md Demonstrates how to use dynamic parameter substitution within a command string using the '%param_name%' notation. This allows the Refact.ai Agent to dynamically insert values into commands. ```shell echo %message% ``` -------------------------------- ### GitHub Integration Tool Description (YAML) Source: https://github.com/smallcloudai/refact/blob/main/refact-agent/engine/INTEGRATIONS.md Defines the configuration for the GitHub integration tool, including its name, experimental status, description, and required parameters like 'project_dir' and 'command'. It also shows example commands for interacting with the GitHub CLI. ```yaml - name: "github" agentic: true experimental: true description: "Access to gh command line command, to fetch issues, review PRs." parameters: - name: "project_dir" type: "string" description: "Look at system prompt for location of version control (.git folder) of the active file." - name: "command" type: "string" description: 'Examples:\ngh issue create --body "hello world" --title "Testing gh integration"\ngh issue list --author @me --json number,title,updatedAt,url\n' parameters_required: - "project_dir" - "command" ``` -------------------------------- ### Debug Refact Components Separately Source: https://github.com/smallcloudai/refact/blob/main/refact-server/CONTRIBUTING.md Runs the Refact web GUI and inference worker processes in separate terminals for easier debugging. The inference worker can be started with a specific model and debug flag. ```commandline python -m self_hosting_machinery.webgui.webgui DEBUG=1 python -m self_hosting_machinery.inference.inference_worker --model wizardlm/7b ``` -------------------------------- ### Keycloak Configuration Summary Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/guides/authentication/keycloak.md Provides essential Keycloak client configuration parameters required for integration with Refact.ai Enterprise. These include the client ID, client secret, realm name, and Keycloak server URL. ```text client_id = refact_client client_secret = ***** (Your generated client secret) realm = your_realm_name url = https://keycloak.refact.ai/ ``` -------------------------------- ### Add Completion Model Configuration (JSON) Source: https://github.com/smallcloudai/refact/blob/main/CONTRIBUTING.md Example of adding a new completion model, particularly FIM models, to the known models configuration in JSON format. Includes FIM token definitions and tokenizer path. ```json { "completion_models": { "your-completion-model": { "n_ctx": 8192, "scratchpad_patch": { "fim_prefix": "<|fim_prefix|>", "fim_suffix": "<|fim_suffix|>", "fim_middle": "<|fim_middle|>", "eot": "<|endoftext|>", "extra_stop_tokens": [ "<|repo_name|>", "<|file_sep|>" ], "context_format": "your-format", "rag_ratio": 0.5 }, "scratchpad": "FIM-PSM", "tokenizer": "hf://your-tokenizer-path", "similar_models": [] } } } ``` -------------------------------- ### Add Chat Model Configuration (YAML) Source: https://github.com/smallcloudai/refact/blob/main/CONTRIBUTING.md Example of adding a new chat model to an existing provider configuration in YAML format. Specifies model name, context size, and feature support. ```yaml # Example: anthropic.yaml running_models: - claude-3-7-sonnet-latest - claude-3-5-sonnet-latest - your-new-model # Add your model here chat_models: your-new-model: n_ctx: 200000 supports_tools: true supports_multimodality: true supports_agent: true tokenizer: hf://your-tokenizer-path ``` -------------------------------- ### Rust Mutex Locking Example Source: https://github.com/smallcloudai/refact/blob/main/refact-agent/engine/CONTRIBUTING.md Demonstrates the correct usage of `Arc>` in Rust for thread-safe access to data with short lock durations, preventing long-held locks. ```rust struct BigStruct { ... pub small_struct: Arc>; } fn some_code(big_struct: Arc>) { let small_struct = { let big_struct_locked = big_struct.lock().await; big_struct_locked.small_struct.clone() // cloning Arc is cheap // big_struct_locked is destroyed here because it goes out of scope }; // use small_struct without holding big_struct_locked } ``` -------------------------------- ### Nginx Configuration for Refact (Nginx Configuration) Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/guides/reverse-proxy.md An example nginx configuration file designed to proxy requests to a Refact server. It includes SSL/TLS settings, security headers, and upstream server definitions. ```nginx http { upstream refact-default { zone refact-default 1m; server 127.0.0.1:8008; # replace with your address keepalive 2; } server { listen 0.0.0.0:443 ssl http2; server_name myserver; ssl_certificate /your/path/certificate.crt; ssl_certificate_key /your/path/private_key.key; add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always; add_header X-Frame-Options SAMEORIGIN always; add_header X-Content-Type-Options nosniff always; add_header X-XSS-Protection "1; mode=block" always; add_header Referrer-Policy "no-referrer" always; add_header X-Permitted-Cross-Domain-Policies "none" always; add_header X-Robots-Tag "noindex, nofollow" always; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_buffering off; # makes chat streaming possible location / { allow all; proxy_pass http://refact-default; # here "refact-default" refers to the upstream block above } error_page 307 = @redirect; location @redirect { return 307 https://$host$request_uri; } client_max_body_size 1G; ssl_protocols TLSv1.2 TLSv1.3; # The refact-lsp binary does not support TLSv1.3 yet -- waiting for reqwest library to catch up ssl_prefer_server_ciphers on; ssl_ciphers EECDH+AESGCM:EDH+AESGCM; ssl_ecdh_curve secp384r1; ssl_session_timeout 10m; ssl_session_cache shared:SSL:10m; ssl_session_tickets off; ssl_stapling on; ssl_stapling_verify on; resolver_timeout 5s; } } events { worker_connections 1024; multi_accept on; } ``` -------------------------------- ### Project Structure Overview Source: https://github.com/smallcloudai/refact/blob/main/docs/README.md This snippet provides a visual representation of the typical file and folder structure within an Astro project using the Starlight theme. It highlights key directories like `public`, `src/content`, and configuration files. ```text . ├── public/ ├── src/ │ ├── assets/ │ ├── content/ │ │ ├── docs/ │ │ └── config.ts │ └── env.d.ts ├── astro.config.mjs ├── package.json └── tsconfig.json ``` -------------------------------- ### Compile and Run Refact LSP Server (Rust) Source: https://github.com/smallcloudai/refact/blob/main/refact-agent/engine/README.md Provides commands to compile the Refact LSP server using Cargo and run it with different configurations, including specifying API keys and HTTP ports. The `--help` flag can be used for more options. ```bash cargo build target/debug/refact-lsp --http-port 8001 --logs-stderr target/debug/refact-lsp --address-url Refact --api-key $REFACT_API_KEY --http-port 8001 --logs-stderr target/debug/refact-lsp --address-url http://my-refact-self-hosting/ --api-key $REFACT_API_KEY --http-port 8001 --logs-stderr ``` -------------------------------- ### Build and Run Refact Proxy Docker Container Source: https://github.com/smallcloudai/refact/blob/main/refact-server/README.md This command sequence clones the Refact repository, builds a Docker image for the Refact Proxy (a lightweight version suitable for non-GPU environments or external model providers), and then runs it. ```commandline git clone https://github.com/smallcloudai/refact.git cd refact/refact-server docker build -t refact_proxy -f Dockerfile.proxy . docker run -d --rm --shm-size=256m -p 8008:8008 -v refact-proxy-perm-storage:/perm_storage refact_proxy ``` -------------------------------- ### Upload Fine-Tuning Data via Link Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/features/finetuning.md Shows how to provide fine-tuning data by uploading a file via a direct URL. Ensure the provided link points directly to the file, such as a ZIP archive containing the training data. ```url https://yourserver.com/file.zip ``` -------------------------------- ### PostgreSQL PSQL Binary Path Configuration Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/features/autonomous-agent/integrations/postgresql.md Specifies the location of the `psql` executable. If `psql` is in the system's PATH, this can be left blank. Otherwise, provide the full path to the binary. ```text - Specifies the path to the psql binary - Leave this field blank if psql is available in the system's PATH - If the binary is located elsewhere, provide the full path (e.g., /usr/local/bin/psql) ``` -------------------------------- ### Running Refact-LSP Tests Source: https://github.com/smallcloudai/refact/blob/main/refact-agent/engine/CONTRIBUTING.md Command to build and run the Refact-LSP process for integration testing with Python scripts, specifying HTTP port, workspace folder, and enabling experimental features. ```bash cargo build && target/debug/refact-lsp --http-port 8001 --reset-memory --experimental --workspace-folder . --logs-stderr --vecdb --ast ``` -------------------------------- ### Run Refact Self-Hosted Docker Container Source: https://github.com/smallcloudai/refact/blob/main/refact-server/README.md This command runs the Refact self-hosted server in a Docker container. It maps port 8008, enables GPU access, and mounts a volume for persistent storage. ```commandline docker run -d --rm --gpus all --shm-size=256m -p 8008:8008 -v refact-perm-storage:/perm_storage smallcloud/refact_self_hosting:latest ``` -------------------------------- ### List All Docker Containers Source: https://github.com/smallcloudai/refact/blob/main/refact-server/README.md Displays a list of all Docker containers, including stopped ones. ```commandline docker ps -a ``` -------------------------------- ### Run Refact LSP for Debugging (Bash) Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/guides/reverse-proxy.md Executes the `refact-lsp` command with specific arguments to test the connection to the Refact server via HTTPS. It includes the server address, API key, and logging settings. ```bash PATH_TO_BINARY/refact-lsp --address-url https://127.0.0.1:443/ --api-key XXX --http-port 8001 --logs-stderr ``` -------------------------------- ### Find Running Refact LSP Process (Bash) Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/guides/reverse-proxy.md Searches for running processes related to `refact-lsp`. This command helps in identifying the executable path needed for debugging. ```bash ps aux | grep refact-lsp ``` -------------------------------- ### Inspect a Docker Volume Source: https://github.com/smallcloudai/refact/blob/main/refact-server/README.md Displays detailed information about a Docker volume. Replace 'VVV' with the volume name. ```commandline docker volume inspect VVV ``` -------------------------------- ### Perform Code Completion Request (Bash) Source: https://github.com/smallcloudai/refact/blob/main/refact-agent/engine/README.md Demonstrates how to send a POST request to the Refact LSP server's code completion endpoint using curl. It includes sample JSON payload for sources, cursor position, and parameters like temperature and max new tokens. ```bash curl http://127.0.0.1:8001/v1/code-completion -k \ -H 'Content-Type: application/json' \ -d '{ "inputs": { "sources": {"hello.py": "def hello_world():"}, "cursor": { "file": "hello.py", "line": 0, "character": 18 }, "multiline": true }, "stream": false, "parameters": { "temperature": 0.1, "max_new_tokens": 20 } }' ``` -------------------------------- ### Fetch Caps JSON with Curl (Bash) Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/guides/reverse-proxy.md Uses curl to fetch the `coding_assistant_caps.json` file from the Refact server via HTTPS. This is a diagnostic step to compare with the `refact-lsp` output. ```bash curl https://127.0.0.1:443/coding_assistant_caps.json ``` -------------------------------- ### View Docker Container Logs Source: https://github.com/smallcloudai/refact/blob/main/refact-server/README.md Follows the logs of a Docker container in real-time. Replace 'XXX' with the container ID or name. ```commandline docker logs -f XXX ``` -------------------------------- ### Add Git Repository for Fine-Tuning Data Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/features/finetuning.md Demonstrates how to add data for fine-tuning by referencing Git repositories. Supports both public (HTTPS) and private (SSH) repositories, with an option to specify a branch. Ensure SSH keys are set up for private repositories. ```git https://github.com/my_company/my_repo ``` ```git git@github.com:my_company/my_repo.git ``` -------------------------------- ### PostgreSQL Connection Settings Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/features/autonomous-agent/integrations/postgresql.md Configuration parameters for connecting to a PostgreSQL database. This includes host, port, user credentials, and the target database name. Environment variables can be used for sensitive information. ```text - Host: Specify the host to connect to, such as 127.0.0.1 or the name of a Docker container - Port: Define the port used for the connection (Default: 5432) - User and Password: Set the username and password for database access - Can be entered directly or referenced from environment variables (e.g., $POSTGRES_USER and $POSTGRES_PASSWORD) - Database: Enter the name of the database you want the tool to connect to ``` -------------------------------- ### Define Custom Toolbox Command (YAML) Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/features/ai-toolbox.md Defines a custom command for the Refact AI Toolbox using YAML. It includes a description, selection requirements, and a structured message for the user's prompt, incorporating placeholders for file, line numbers, and code selection. ```yaml description: "User-defined: translate to horrible code" selection_needed: [1, 50] messages: - role: "system" content: "%DEFAULT_PROMPT%" - role: "user" content: "@file %CURRENT_FILE%:%CURSOR_LINE%\nRewrite this specific code block into a very inefficient and cryptic one, but still correct. Rename variables to misleading gibberish. Add unnecessary complexity. Make O(N) worse. Don't forget about bad formatting and random spaces.\n\n```\n%CODE_SELECTION%```\n" ``` -------------------------------- ### Send Chat Request (Bash) Source: https://github.com/smallcloudai/refact/blob/main/refact-agent/engine/README.md Illustrates sending a chat request to the Refact LSP server using curl. It sends a user message and specifies parameters like stream, temperature, and max tokens. ```bash curl http://127.0.0.1:8001/v1/chat -k \ -H 'Content-Type: application/json' \ -d '{ "messages": [ {"role": "user", "content": "Who is Bill Clinton? What is his favorite programming language?"} ], "stream": false, "temperature": 0.1, "max_tokens": 20 }' ``` -------------------------------- ### PostgreSQL Confirmation Rules Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/features/autonomous-agent/integrations/postgresql.md Defines rules to control the execution of SQL commands. The 'Ask User' rule prompts for confirmation for commands that do not match a specified pattern, such as excluding SELECT statements. ```text - Ask User: Commands requiring confirmation, example: - psql*[!SELECT]*: Prompts for confirmation for commands other than SELECT - Deny: Commands matching these patterns are automatically blocked ``` -------------------------------- ### Generate Self-Signed Certificate (Bash) Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/guides/reverse-proxy.md Generates a self-signed SSL certificate and private key valid for 365 days. This is useful for testing but not recommended for production due to lack of trust. ```bash openssl req -x509 -newkey rsa:4096 -nodes -keyout private_key.key -out certificate.crt -days 365 ``` -------------------------------- ### GitLab CLI Confirmation Rule: Ask User for Delete Operations Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/features/autonomous-agent/integrations/gitlab.md This configuration prompts the user for confirmation before executing any 'glab' command that involves deleting resources. This is a safety mechanism to prevent unintended data loss. ```shell glab * delete * ``` -------------------------------- ### Define Response and Model Data Types (TypeScript) Source: https://github.com/smallcloudai/refact/blob/main/refact-agent/gui/README.md Defines TypeScript types for various responses and model configurations, including chat responses, capabilities responses, code completion models, and command completion responses. These types are crucial for handling API interactions and configuring model behavior. ```typescript type CapsResponse = { chat_default_model: string; chat_models: Record; }; type CodeCompletionModel = { default_scratchpad: string; n_ctx: number; similar_models: string[]; supports_scratchpads: Record>; }; type CommandCompletionResponse = { completions: string[]; replace: Replace; is_cmd_executable: false; }; interface Replace { 0: number; 1: number; } ``` -------------------------------- ### Command Confirmation Patterns (YAML) Source: https://github.com/smallcloudai/refact/blob/main/refact-agent/engine/INTEGRATIONS.md Specifies patterns for commands that require confirmation or are denied by default. These YAML lists are used to match against commands executed by the integrations. ```yaml commands_need_confirmation: - "gh * delete*" commands_deny: - "gh auth token*" ``` -------------------------------- ### Find Chrome Browser Path (Windows, macOS, Linux) Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/features/autonomous-agent/integrations/chrome.md Provides common file paths for locating the Chrome browser executable on Windows, macOS, and Linux systems. These paths are crucial for configuring the Chrome Tool. ```text Windows: C:\Program Files\Google\Chrome\Application\chrome.exe MacOS: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome Linux: /usr/bin/google-chrome or /usr/bin/chromium ``` -------------------------------- ### TypeScript Chat and Host Message Interfaces Source: https://github.com/smallcloudai/refact/blob/main/refact-agent/gui/README.md Defines TypeScript interfaces for messages exchanged between chat components and the host. These interfaces ensure structured communication for various actions like initialization, questions, responses, and streaming. ```typescript /** * This message is sent from the chat component to the host when the chat is mounted and ready to receive messages. */ interface ReadyMessage extends ActionFromChat { type: EVENT_NAMES_FROM_CHAT.READY; // "chat_ready" payload: { id: string }; } /** * This messages is sent from the host to the chat component to restore a previously saved chat. */ interface RestoreChat extends ActionToChat { type: EVENT_NAMES_TO_CHAT.RESTORE_CHAT; // = "restore_chat_from_history" payload: { id: string; chat: ChatThread & { messages: ChatThread["messages"] | [string, string][]; }; snippet?: Snippet; }; } /** * The host sends this message to start a new chat thread. */ interface CreateNewChatThread extends ActionToChat { type: EVENT_NAMES_TO_CHAT.NEW_CHAT; // = "create_new_chat" payload?: { id: string; snippet: string }; } /** * Chat sends this to the host when asking a question. */ interface QuestionFromChat extends ActionFromChat { type: EVENT_NAMES_FROM_CHAT.ASK_QUESTION; // = "chat_question" payload: ChatThread; } /** * Response from the host to the question */ interface ResponseToChat extends ActionToChat { type: EVENT_NAMES_TO_CHAT.CHAT_RESPONSE; // = "chat_response", payload: ChatResponse; } /** * This message is sent from the host to the chat when the lsp is done streaming it's response */ interface ChatDoneStreaming extends ActionToChat { type: EVENT_NAMES_TO_CHAT.DONE_STREAMING; // = "chat_done_streaming" payload: { id: string }; } /** * Sent from the host to the chat when an error has happened while streaming the response */ interface ChatErrorStreaming extends ActionToChat { type: EVENT_NAMES_TO_CHAT.ERROR_STREAMING; // = "chat_error_streaming" payload: { id: string; message: string }; } /** * Request for command completion from the lsp * trigger will be null if the user has selected a command at that point it should be fine to send the query to the lsp */ interface RequestAtCommandCompletion extends ActionFromChat { type: EVENT_NAMES_FROM_CHAT.REQUEST_AT_COMMAND_COMPLETION; // = "chat_request_at_command_completion" payload: { id: string; query: string; cursor: number; trigger: string | null; number?: number; }; } /** * This message is sent from the host to the chat contains the result of command completion request */ interface ReceiveAtCommandCompletion extends ActionToChat { type: EVENT_NAMES_TO_CHAT.RECEIVE_AT_COMMAND_COMPLETION; // = "chat_receive_at_command_completion" payload: { id: string } & CommandCompletionResponse; } /** * This message is sent from the chat component to the host to request for command preview */ interface RequestAtCommandPreview extends ActionFromChat { type: EVENT_NAMES_FROM_CHAT.REQUEST_AT_COMMAND_PREVIEW; // = "chat_request_at_command_preview" payload: { id: string; query: string; cursor: number }; } /** * This message is sent from the chat component to the host when the response to the question is received. */ interface SaveChatFromChat extends ActionFromChat { type: EVENT_NAMES_FROM_CHAT.SAVE_CHAT; // = "save_chat_to_history" payload: ChatThread; } /** * Tells chat to replace the current message list, this is done before sending a question to the lsp. */ interface BackUpMessages extends ActionToChat { type: EVENT_NAMES_TO_CHAT.BACKUP_MESSAGES; // = "back_up_messages" payload: { id: string; messages: ChatMessages }; } /** * This message is sent from the chat component to the host when the user clicks stop while the response is streaming. */ interface StopStreamingFromChat extends ActionFromChat { type: EVENT_NAMES_FROM_CHAT.STOP_STREAMING; // = "chat_stop_streaming" payload: { id: string }; } /** * chat requesting caps from the server. */ interface RequestCapsFromChat extends ActionFromChat { type: EVENT_NAMES_FROM_CHAT.REQUEST_CAPS; // = "chat_request_caps" payload: { id: string }; } /** * This message is sent from the host to the chat when the server responds with caps. */ interface ChatReceiveCaps extends ActionToChat { type: EVENT_NAMES_TO_CHAT.RECEIVE_CAPS; // = "receive_caps" payload: { id: string; caps: CapsResponse }; } /** * This message is sent from the host to the chat when the server responds with an error. */ interface ChatReceiveCapsError extends ActionToChat { type: EVENT_NAMES_TO_CHAT.RECEIVE_CAPS_ERROR; // = "receive_caps_error" payload: { id: string; message: string }; } /** * This message is sent from the host to the chat with information about the current active file */ interface ActiveFileInfo extends ActionToChat { type: EVENT_NAMES_TO_CHAT.ACTIVE_FILE_INFO; // = "chat_active_file_info" payload: { id: string; name: string; can_paste: boolean }; } /** * This message is sent from the host to the chat to set the selected snippet. */ ``` -------------------------------- ### Define Chat Message Data Types (TypeScript) Source: https://github.com/smallcloudai/refact/blob/main/refact-agent/gui/README.md Defines TypeScript types for chat messages, including context files, user messages, and assistant messages. It also defines structures for chat threads, chat responses, and individual chat choices, which are fundamental for managing chat history and responses. ```typescript type ChatContextFile = { file_name: string; file_content: string; line1: number; line2: number; }; interface ChatContextFileMessage extends BaseMessage { 0: "context_file"; 1: ChatContextFile[]; } interface UserMessage extends BaseMessage { 0: "user"; 1: string; } interface AssistantMessage extends BaseMessage { 0: "assistant"; 1: string; } type ChatMessage = UserMessage | AssistantMessage | ChatContextFileMessage; type ChatMessages = ChatMessage[]; type ChatThread = { id: string; messages: ChatMessages; title?: string | undefined; model: string; attach_file?: boolean | undefined; }; type ChatResponse = | { choices: ChatChoice[]; created: number; model: string; id: string } | ChatUserMessageResponse; type ChatChoice = { delta: Delta; finish_reason: "stop" | "abort" | null; index: number; }; type ChatUserMessageResponse = { id: string; role: "user" | "context_file"; content: string; }; ``` -------------------------------- ### GitLab CLI Confirmation Rule: Deny Auth Token Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/features/autonomous-agent/integrations/gitlab.md This configuration denies the execution of any 'glab auth token' commands. It is a security measure to prevent accidental or malicious exposure of authentication tokens. ```shell glab auth token * ``` -------------------------------- ### Check RAG Status (Bash) Source: https://github.com/smallcloudai/refact/blob/main/refact-agent/engine/README.md A simple curl command to query the Refact LSP server's RAG status endpoint. ```bash curl http://127.0.0.1:8001/v1/rag-status ``` -------------------------------- ### Define Chat Event Interfaces (TypeScript) Source: https://github.com/smallcloudai/refact/blob/main/refact-agent/gui/README.md Defines TypeScript interfaces for various chat-related events, such as setting selected snippets, disabling chat input, setting chat models, and creating new files from chat interactions. These interfaces specify the structure of the payloads exchanged between different parts of the application. ```typescript interface ChatSetSelectedSnippet extends ActionToChat { type: EVENT_NAMES_TO_CHAT.SET_SELECTED_SNIPPET; payload: { id: string; snippet: { code: string; language: string } }; } interface SetChatDisable extends ActionToChat { type: EVENT_NAMES_TO_CHAT.SET_DISABLE_CHAT; payload: { id: string; disable: boolean }; } interface SetChatModel extends ActionToChat { type: EVENT_NAMES_TO_CHAT.SET_CHAT_MODEL; payload: { id: string; model: string }; } interface NewFileFromChat extends ActionFromChat { type: EVENT_NAMES_FROM_CHAT.NEW_FILE; payload: { id: string; content: string }; } interface PasteDiffFromChat extends ActionFromChat { type: EVENT_NAMES_FROM_CHAT.PASTE_DIFF; payload: { id: string; content: string }; } ``` -------------------------------- ### Add User to Docker Group (Linux) Source: https://github.com/smallcloudai/refact/blob/main/refact-server/README.md This command adds the current user to the 'docker' group, allowing them to run Docker commands without sudo privileges. ```commandline sudo usermod -aG docker {your user} ``` -------------------------------- ### Configure Refact Inference URL Source: https://github.com/smallcloudai/refact/blob/main/README.md Sets the custom inference URL for the Refact plugin in JetBrains IDEs and VS Code. ```text http://127.0.0.1:8008 ``` -------------------------------- ### Remove a Docker Volume Source: https://github.com/smallcloudai/refact/blob/main/refact-server/README.md Deletes a Docker volume. This action is irreversible and will remove all data stored in the volume. Replace 'VVV' with the volume name. ```commandline docker volume rm VVV ``` -------------------------------- ### Stop an Existing Docker Container Source: https://github.com/smallcloudai/refact/blob/main/refact-server/README.md Stops a running Docker container without removing it. Replace 'XXX' with the container ID or name. ```commandline docker stop XXX ``` -------------------------------- ### Remove a Docker Container and its Data Source: https://github.com/smallcloudai/refact/blob/main/refact-server/README.md Removes a Docker container and all its associated data, except for data stored in volumes. Replace 'XXX' with the container ID or name. ```commandline docker rm XXX ``` -------------------------------- ### Fix JetBrains 2025.* JCEF Out-of-Process Mode Bug Source: https://github.com/smallcloudai/refact/blob/main/docs/src/content/docs/guides/plugins/jetbrains/troubleshooting.md This snippet provides the VM option to disable the JCEF out-of-process mode in JetBrains IDEs version 2025.* to resolve freezes. It's a workaround for IJPL-186252 until a permanent fix is released. ```text -Dide.browser.jcef.out-of-process.enabled=false ``` -------------------------------- ### Rust Function Extraction for Thread Safety Source: https://github.com/smallcloudai/refact/blob/main/refact-agent/engine/CONTRIBUTING.md Illustrates moving a potentially lengthy function outside a mutex-locked struct in Rust to avoid holding the lock for the entire duration of the function's execution. ```rust struct MyStruct { pub data1: i32, pub data2: i32, } impl MyStruct { pub fn lengthy_function1(&mut self) { } } fn some_code(my_struct: Arc>) { my_struct.lock().await.lengthy_function1(); // Whoops, lengthy_function has the whole structure locked for a long time, // and Rust won't not let you unlock it } pub fn lengthy_function2(s: Arc>) { let (data1, data2) = { let s_locked = s.lock().await; (s_locked.data1.clone(), s_locked.data2.clone()) } // Do lengthy stuff here without locks! } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.