Metadata-Version: 2.1
Name: tabman
Version: 0.2.0
Home-page: https://github.com/Anshulgada/brave-tab-manager
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: playwright
Requires-Dist: requests
Requires-Dist: beautifulsoup4
Requires-Dist: google-generativeai
Requires-Dist: google-api-python-client
Requires-Dist: tenacity
Requires-Dist: openai
Requires-Dist: python-dotenv
Requires-Dist: ollama
Requires-Dist: markdown

# Tabman: Brave Tab Manager

A command-line tool designed to streamline your browsing experience by intelligently organizing your open tabs from the Brave browser. `tabman` helps you categorize, tag, and save your browsing sessions, making it easier to find and revisit websites later.

## Features

- **Tab Retrieval:** Fetches all open tabs from Brave using its remote debugging interface.
- **Intelligent Categorization:** Uses AI-powered language models to categorize your tabs:
  - **Google Gemini:** Employs the Gemini 2.0 Flash model for advanced and fast categorization.
  - **Mistral AI:** Leverages Mistral's large language models as an alternative to Gemini.
  - **Ollama:** Enables local categorization using Ollama, supporting a variety of LLMs (e.g., Llama 2, Mistral).
- **Dynamic Tagging:** Generates a list of concise and relevant keywords to describe the content of each tab.
- **Flexible Saving:**
  - Saves the tab data (title, URL, main category, and tags) as a JSON file, organized in date-based subfolders within the `data/` directory.
  - Creates a Markdown version of each tab session, also stored in the date-based subfolders within the `data/` directory.
  - Maintains a central `all_tabs.md` file in the `data/` directory, where all tab data is appended for easy access.
- **Secure API Key Management:** Utilizes a `.env` file to securely store API keys, which can be set using command-line arguments.

## Installation

1.  **Clone the repository:**

    ```bash
    git clone https://github.com/Anshulgada/brave-tab-manager.git
    ```


2.  **Navigate to the project directory:**

    ```bash
    cd Brave Tab Manager
    ```

    This assumes that your project folder is named `Brave Tab Manager`.

3.  **Install `pipx` (if you don't have it):**

    ```bash
    python -m pip install --user pipx
    python -m pipx ensurepath
    ```

    This ensures that `pipx` is installed globally and its executables are present in your system's PATH. You may need to restart your terminal for these changes to take effect.

4.  **Install `tabman` using `pipx`:**
    ```bash
    pipx install -e .
    ```
    This command installs your tool into an isolated environment and makes the `tabman` command accessible from anywhere. Make sure you run this command from the root of the project directory, i.e. `Brave Tab Manager`.

## Usage

1.  **Enable Remote Debugging in Brave:**
    To allow `tabman` to connect with your Brave browser, you must enable remote debugging. Here's how:

    - **Windows:**
      1.  Right-click on the Brave shortcut in your Start Menu or Taskbar and select "Properties."
      2.  In the "Target" field, add `--remote-debugging-port=9222` (or your preferred port number) to the end of the existing path, ensuring there's a space between the path and the flag. For example:
          ```
          "C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe" --remote-debugging-port=9222
          ```
      3.  Click "Apply" and "OK."
    - **macOS/Linux:** Modify the Brave shortcut (or application launcher) to include the `--remote-debugging-port=9222` flag in the command line that launches Brave. Consult your system's documentation for the specific method.
    - After enabling remote debugging, make sure that you have restarted your Brave browser.

2.  **Run the `tabman` tool:**

    ```bash
    tabman [OPTIONS]
    ```

    You can use the following options:

    - `-c`, `--categorize`: Categorize your open tabs using the selected LLM model, and save the data. This is not necessary when setting the api keys.
    - `-v`, `--version`: Display the version of `tabman` and exits.
    - `-m`, `--model <MODEL>`: Specify the LLM model for categorization:
      - `gemini` (default): Uses Google Gemini.
      - `mistral`: Uses Mistral AI.
      - `ollama`: Uses a local LLM with Ollama.
    - `--save-keys`: Save the provided API keys to the `.env` file. Use this in combination with `-mk` and `-gk` options to save the keys.
    - `-mk`, `--mistral-key <KEY>`: Provide your Mistral AI API key.
    - `-gk`, `--gemini-key <KEY>`: Provide your Google Gemini API key.
    - `-om`, `--ollama-model <MODEL>`: Provide the Ollama model name (e.g., `llama2`, `mistral`). Default is `llama2`.

**Examples:**

- **Categorize tabs using the default Gemini model:**
  ```bash
  tabman -c
  ```
- **Categorize tabs using Mistral:**
  ```bash
  tabman -c -m mistral
  ```
- **Categorize tabs using a specific Ollama model:**
  ```bash
  tabman -c -m ollama -om llama3.2
  ```
- **Save API keys to the `.env` file:**

  ```bash
  tabman --save-keys -gk YOUR_GEMINI_API_KEY -mk YOUR_MISTRAL_API_KEY
  ```
  Replace `YOUR_GEMINI_API_KEY` and `YOUR_MISTRAL_API_KEY` with your actual API keys.

- **Show help message:**
  ```bash
  tabman
  ```

## Configuration

- **API Keys:** API keys for Gemini and Mistral can be provided either directly via command-line arguments or saved to a `.env` file for later use. The tool will read keys from environment variables, and then the command line arguments and the `.env` file when using the tool.
- **Ollama:** If you select Ollama model, then you will have to install and run ollama on your system with your desired models.

## Development and Testing

- To avoid re-installing the package again and again, during local development, you should run the tool inside your virtual environment. For this you have to activate your environment and then run `pip install -e .` from the root directory. Now you can use the tool with the activated virtual environment. Whenever you want to update the global version then you have to uninstall the current version using `pipx uninstall tabman` and install again using `pipx install .`.

- **Running tests:**
  - The tests are located in the `tabman/tests` directory. You can run the tests using `pytest` rom the root of your project i.e. where `setup.py` exists.
  ```bash
  pytest -v -s tabman/tests
  ```

## Dependencies

- `openai`
- `ollama`
- `markdown`
- `requests`
- `tenacity`
- `playwright`
- `python-dotenv`
- `beautifulsoup4`
- `google-generativeai`
- `google-api-python-client`

## License

This project is licensed under the MIT License.
