Metadata-Version: 2.5
Name: cognisn-spark
Version: 0.3.0rc22
Summary: Secure Personal AI Research Kit - Multi-provider LLM web interface with MCP tool integration
Project-URL: Homepage, https://github.com/Cognisn/spark
Project-URL: Documentation, https://github.com/Cognisn/spark#readme
Project-URL: Repository, https://github.com/Cognisn/spark
Project-URL: Issues, https://github.com/Cognisn/spark/issues
Project-URL: Changelog, https://github.com/Cognisn/spark/blob/main/CHANGELOG.md
Author: Matthew Westwood-Hill
License: MIT with Commons Clause
License-File: LICENSE
Keywords: ai,anthropic,aws,bedrock,chatbot,claude,llm,mcp,model-context-protocol,ollama,web
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: Science/Research
Classifier: License :: Other/Proprietary License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Communications :: Chat
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: aiohttp>=3.8.0
Requires-Dist: aiosqlite>=0.20.0
Requires-Dist: alembic>=1.13.0
Requires-Dist: apscheduler>=3.10.0
Requires-Dist: beautifulsoup4>=4.12.0
Requires-Dist: cognisn-conduit[anthropic,bedrock,bedrock-mantle,gemini,konfig,mcp,ollama,openai]>=0.1.0rc4
Requires-Dist: cognisn-konfig[aws]>=0.5.0
Requires-Dist: cognisn-warden>=0.1.0
Requires-Dist: cryptography>=42.0.0
Requires-Dist: fastapi>=0.100.0
Requires-Dist: httpx>=0.24.0
Requires-Dist: jinja2>=3.1.0
Requires-Dist: markdown>=3.4.0
Requires-Dist: markdownify>=0.13.0
Requires-Dist: mcp<3,>=2.3
Requires-Dist: numpy>=1.21.0
Requires-Dist: openpyxl>=3.1.0
Requires-Dist: pdfplumber>=0.10.0
Requires-Dist: pgvector>=0.4.0
Requires-Dist: pillow>=10.0.0
Requires-Dist: psycopg[binary,pool]>=3.2.0
Requires-Dist: pystray>=0.19.0
Requires-Dist: python-docx>=0.8.11
Requires-Dist: python-magic-bin>=0.4.14; sys_platform == 'win32'
Requires-Dist: python-magic>=0.4.27; sys_platform != 'win32'
Requires-Dist: python-multipart>=0.0.6
Requires-Dist: python-pptx>=0.6.21
Requires-Dist: pyyaml>=6.0
Requires-Dist: reportlab>=4.0
Requires-Dist: sentence-transformers>=2.2.0
Requires-Dist: sse-starlette>=1.6.0
Requires-Dist: tiktoken>=0.5.0
Requires-Dist: uvicorn>=0.22.0
Provides-Extra: dev
Requires-Dist: black==26.10.1; extra == 'dev'
Requires-Dist: isort==8.0.1; extra == 'dev'
Requires-Dist: mypy>=1.8.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=1.4.0; extra == 'dev'
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
Requires-Dist: pytest-timeout>=2.3.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Requires-Dist: testcontainers[postgres]>=4.8.0; extra == 'dev'
Description-Content-Type: text/markdown

# Spark

[![License: MIT + Commons Clause](https://img.shields.io/badge/License-MIT%20%2B%20Commons%20Clause-blue.svg)](LICENSE)
[![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)
[![PyPI](https://img.shields.io/pypi/v/cognisn-spark.svg)](https://pypi.org/project/cognisn-spark/)
[![CI](https://github.com/Cognisn/spark/actions/workflows/ci.yml/badge.svg)](https://github.com/Cognisn/spark/actions/workflows/ci.yml)
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=Cognisn_spark&metric=alert_status)](https://sonarcloud.io/summary/overall?id=Cognisn_spark)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=Cognisn_spark&metric=security_rating)](https://sonarcloud.io/summary/overall?id=Cognisn_spark)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=Cognisn_spark&metric=reliability_rating)](https://sonarcloud.io/summary/overall?id=Cognisn_spark)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=Cognisn_spark&metric=sqale_rating)](https://sonarcloud.io/summary/overall?id=Cognisn_spark)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=Cognisn_spark&metric=vulnerabilities)](https://sonarcloud.io/summary/overall?id=Cognisn_spark)
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=Cognisn_spark&metric=bugs)](https://sonarcloud.io/summary/overall?id=Cognisn_spark)

**Spark** is a secure, multi-provider AI research kit with a modern web interface. It connects to AI models through [conduit](https://pypi.org/project/cognisn-conduit/): Amazon Bedrock (including Claude through Bedrock's mantle endpoint), Anthropic, Claude in Microsoft Foundry, OpenAI, X.AI, Microsoft Foundry, Google Gemini and Ollama, with features like MCP tool integration, intelligent context management, persistent memory, and autonomous scheduled actions.

## Features

### Conversations
- **Named Model Connections** -- Nine services through conduit, several connections of one service side by side, each with its own Region, residency policy and chosen models
- **Real-Time Streaming** -- Server-Sent Events for token-by-token responses
- **Dark/Light Theme** -- Cognisn design system with theme persistence
- **Context Compaction** -- LLM-driven summarisation when approaching context limits
- **Conversation Linking** -- Share context between related conversations
- **Favourites** -- Star conversations for quick access
- **Global System Instructions** -- Define persistent instructions applied to all conversations (Settings > Conversation)
- **Voice Conversation Mode** -- Hands-free AI interaction via the headset button with text-to-speech output and voice selection
- **Speech-to-Text Input** -- Dictate messages using the microphone button

### Tools
- **MCP Integration** -- Connect external tool servers via stdio, HTTP, or SSE; edit server configurations and view tools from the dashboard
- **Built-in Tools** -- Filesystem, documents (Word/Excel/PDF/PowerPoint), web search, archives, email, system commands
- **Document Creation** -- Create Word (.docx), Excel (.xlsx), PowerPoint (.pptx), and PDF documents with advanced formatting (headings, tables, lists, images, styles)
- **Email Tools** -- Send and draft emails via SMTP with HTML/plain text, attachments, and cc/bcc; SMTP test connection button
- **Memory Tools** -- Persistent semantic memory across conversations
- **Per-Conversation Control** -- Enable/disable tools at the server or individual level
- **4-Level Tool Approval** -- Deny, Approve Once, Always (Conversation), Always (Global) with category-based grouping
- **Resizable Sidecar** -- Tools and Agents tabs with drag-to-resize handle; entries grouped by date with collapsible headers; width persists in session
- **Agent Spawning** -- Spawn independent sub-agents for parallel research, analysis, and data gathering with dedicated Agents tab; supports orchestrator-workers and chain modes
- **Tool Documentation** -- Built-in `get_tool_documentation` tool for querying tool usage information
- **Web Search Engines** -- DuckDuckGo, Brave, Google/SerpAPI, Bing/Azure, SearXNG
- **System Commands** -- Execute shell commands and CLI tools (git, docker, aws, etc.) with OS-aware execution and configurable approval prompts

### Memory
- **Persistent Storage** -- Facts, preferences, projects, instructions, relationships
- **Semantic Search** -- Vector embeddings for relevant recall
- **Auto-Retrieval** -- Relevant memories silently injected into context
- **Import/Export** -- JSON format for backup and sharing

### Autonomous Actions
- **Scheduled Tasks** -- Cron or one-off schedules via APScheduler with local timezone support
- **AI-Assisted Creation** -- Describe what you want and the AI builds the action
- **Create from Conversation** -- Turn any conversation into an autonomous action with AI-guided setup
- **Run Now** -- Execute any action immediately from the Actions page
- **Background Daemon** -- System tray icon (macOS/Windows) runs actions independently with sleep/wake recovery
- **Run History** -- Track execution status, results, tool activity log, and token usage

### Dashboard
- **Your Connections** -- The model connections you may use, with their model counts
- **MCP Tools View** -- View tools provided by each MCP server directly from the dashboard
- **Provider Setup Guides** -- In-app step-by-step guides to getting an account and a key from each service

### Security
- **Prompt Inspection** -- Pattern and keyword-based threat detection
- **Secret Management** -- API keys stored in the OS keychain (or konfig's encrypted store on a server), write-only in the UI, never in config files or the database
- **Settings Lock** -- Password-protect the settings page
- **Tool Permissions** -- Per-conversation, per-tool approval system

### Updates
- **Auto-Update Checker** -- Checks GitHub releases for new versions; update from the Help menu

## Installation

Spark is distributed through PyPI and runs on macOS, Windows and Linux with Python 3.12 or later.

Standalone builds (signed macOS DMGs and the Windows installer) are paused: releases since
0.2.0b14 are published to PyPI only. Install with pip or uv as below.

### Install from PyPI

```bash
pip install cognisn-spark
```

### Run with uv

[uv](https://docs.astral.sh/uv/) can install and run Spark from PyPI:

```bash
uv tool install cognisn-spark    # then run:
spark
```

`uv tool install` keeps Spark and its (large) dependencies installed between
runs, which is what you want. For a throwaway run, `uvx cognisn-spark` works too
but re-downloads everything each time.

### CPU-only PyTorch on Linux

Spark's embeddings run on the CPU. On Linux the default PyTorch from PyPI also
brings about 2.4 GB of NVIDIA CUDA packages that Spark never uses; install the
CPU-only build instead. macOS and Windows already get a CPU-only PyTorch and
need nothing extra.

```bash
# uv
uv tool install cognisn-spark --torch-backend cpu

# pip: PyTorch from its CPU index first, then Spark
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install cognisn-spark
```

With pip, a later `pip install --upgrade torch` without `--index-url` would bring
the CUDA build back; upgrade Spark with `pip install --upgrade cognisn-spark` instead.

On a headless server, disable the browser auto-open and pin a port:

```bash
SPARK__INTERFACE__OPEN_BROWSER=false SPARK__INTERFACE__PORT=8765 spark
```

#### Databases

Personal mode (the default) keeps everything in a local SQLite database and needs
nothing extra. Server mode uses PostgreSQL with pgvector 0.8 or later, through
psycopg 3, which is included; see [Server Mode](#server-mode). MySQL and SQL Server
are no longer supported.

## Quick Start

```bash
spark
```

On first launch, Spark creates a configuration file, starts the web server on a random port, and opens your browser. Add a model connection in **Settings > Connections** and start chatting.

### Connections

Every model is reached through a **connection**: one named service with its own
settings, credentials, Region and residency policy (in-Region for Bedrock and Microsoft
Foundry, global for the direct APIs, local for Ollama, by default). Add as many as you
like, several of one service included; each lists conduit's catalogue models for its
service and Region, marked reachable or not by a live discovery, and offers the ones
you enable. A model is chosen as `connection/model`, and the model picker groups models
by connection. On a server, administrators assign connections to roles and users, and
can meter a connection in credits with a monthly allowance per assignment. See
[Connections](https://github.com/Cognisn/spark/blob/main/docs/connections.md) and
[Metering](https://github.com/Cognisn/spark/blob/main/docs/metering.md). Upgrading from 0.2
converts `config.yaml`'s providers into connections on the first start.

### Configuration

Spark stores its configuration in platform-standard locations:

| Platform | Config | Data | Logs |
|----------|--------|------|------|
| macOS | ~/Library/Application Support/spark/ | ~/Library/Application Support/spark/ | ~/Library/Logs/spark/ |
| Linux | ~/.config/spark/ | ~/.local/share/spark/ | ~/.local/state/spark/logs/ |
| Windows | %APPDATA%/spark/ | %APPDATA%/spark/ | %LOCALAPPDATA%/spark/logs/ |

API keys are stored in the OS keychain (macOS Keychain, Windows Credential Locker, Linux Secret Service) via the [cognisn-konfig](https://pypi.org/project/cognisn-konfig/) library.

## Server Mode

Spark can also run as a multi-user server for a team: PostgreSQL with pgvector, the
web interface (`spark web`, one or more replicas) and a background worker
(`spark worker`) from one container image, with sign-in, two-step verification,
single sign-on, roles and an audit trail through
[warden](https://pypi.org/project/cognisn-warden/), and every secret in konfig's
encrypted store or AWS Secrets Manager.

```bash
cp deploy/spark.env.example deploy/spark.env   # then set real values
docker compose -p spark -f deploy/compose.yaml up -d
```

The stack runs `spark migrate` and `spark bootstrap` first, which invites the first
administrator (named in `spark.env`) by mail; `spark identity create-admin` is only for
recovery.

A server needs a TLS reverse proxy in front and `server.public_base_url` set to its
address. The [server deployment guide](https://github.com/Cognisn/spark/blob/main/docs/deployment/index.md) covers the Compose
stack, secrets, the reverse proxy, identity and mail, database roles, backups,
upgrades, and moving people over from personal mode with a user bundle.

## Architecture

```mermaid
graph TB
    subgraph UI ["Web Interface"]
        FE["FastAPI + SSE + Bootstrap 5 (Cognisn)"]
        Voice["Voice / Speech-to-Text"]
        Sidecar["Tool Activity Sidecar"]
    end

    subgraph Core ["Conversation Manager"]
        CM["Context Compaction / Memory / RAG / Tool Routing"]
    end

    subgraph Providers ["Model connections (conduit)"]
        Bedrock["Amazon Bedrock and mantle"]
        Anthropic["Anthropic and Claude in Foundry"]
        OpenAI["OpenAI, X.AI and Foundry"]
        Gemini["Google Gemini"]
        Ollama["Ollama"]
    end

    subgraph Tools ["Tools"]
        MCP["MCP Servers"]
        Builtin["Built-in Tools"]
        Memory["Memory"]
        WebSearch["Web Search"]
        EmailTool["Email (SMTP)"]
        DocCreate["Document Creation"]
        Agents["Sub-Agents"]
        SysCmd["System Commands"]
    end

    subgraph Foundation ["cognisn-konfig"]
        Settings["Settings"]
        Secrets["Secrets"]
        Logging["Logging"]
    end

    UI --> Core
    Core --> Providers
    Core --> Tools
    Core --> Foundation
```

## Keyboard Shortcuts

| Shortcut | Action |
|----------|--------|
| Ctrl/Cmd + K | Go to Conversations |
| Ctrl/Cmd + N | New Conversation |
| Ctrl/Cmd + , | Open Settings |
| Enter | Send message |
| Shift + Enter | New line |

## Development

```bash
git clone https://github.com/Cognisn/spark.git
cd spark
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest
```

## Changelog

See [CHANGELOG.md](CHANGELOG.md).

## Licence

MIT License with Commons Clause -- free for personal and educational use. Commercial use requires a licence from the author. See [LICENSE](LICENSE).

## Author

Matthew Westwood-Hill / [Cognisn](https://github.com/Cognisn)
