# Agents Orchestrator Pro Edition

> This documentation covers Pro edition features available in the agents-orchestrator/agents-orchestrator private repository.

## Overview

Agents Orchestrator Pro extends the open-source community edition with commercial features for teams and organizations that need deeper analytics, cost controls, persistent agent knowledge, and a plugin marketplace. Pro features are architecturally isolated from the community codebase, implemented as a Tauri plugin crate and a separate Svelte module tree.

## Feature Summary

| Feature | Description | Documentation |
|---------|-------------|---------------|
| Analytics Dashboard | Session cost trends, model usage breakdown, daily statistics | [analytics.md](features/analytics.md) |
| Budget Governor | Per-project monthly token budgets with soft/hard limits | [cost-intelligence.md](features/cost-intelligence.md) |
| Smart Model Router | Cost-aware model selection with routing profiles | [cost-intelligence.md](features/cost-intelligence.md) |
| Persistent Agent Memory | Per-project knowledge fragments with FTS5 search and TTL | [knowledge-base.md](features/knowledge-base.md) |
| Codebase Symbol Graph | Regex-based symbol extraction and caller lookup | [knowledge-base.md](features/knowledge-base.md) |
| Git Context Injection | Branch, commit, and diff context for agent prompts | [git-integration.md](features/git-integration.md) |
| Branch Policy | Session-level protection for sensitive branches | [git-integration.md](features/git-integration.md) |
| Plugin Marketplace | Curated plugin catalog with install/update lifecycle | [marketplace/README.md](marketplace/README.md) |

## Architecture

Pro features are separated from the community codebase at two layers:

### Rust Backend: `agor-pro` Tauri Plugin Crate

The `agor-pro` crate is a standalone Tauri plugin located at `crates/agor-pro/` in the private repository. It contains all Pro-specific Rust logic: SQLite tables, commands, and business rules.

The crate exposes a single entry point:

```rust
pub fn init() -> TauriPlugin<tauri::Wry> { ... }
```

### Svelte Frontend: `src/lib/commercial/`

Pro UI components live under `src/lib/commercial/` with their own adapters and stores. Community components never import from this path. The commercial module tree mirrors the community structure:

```
src/lib/commercial/
  adapters/        -- IPC bridges for pro commands
  components/      -- Pro-specific UI (analytics, budgets, marketplace)
  stores/          -- Pro-specific state
```

## Feature Flag

Pro features are gated at both compile time and runtime.

### Cargo Feature Flag

The `pro` feature flag controls Rust compilation:

```bash
# Community build (default)
cargo build -p bterminal

# Pro build
cargo build -p bterminal --features pro
```

When `--features pro` is active, `lib.rs` registers the plugin:

```rust
#[cfg(feature = "pro")]
app.handle().plugin(agor_pro::init());
```

### Frontend Edition Flag

The `AGOR_EDITION` environment variable controls frontend feature visibility:

```bash
# Community build (default)
AGOR_EDITION=community npm run tauri build

# Pro build
AGOR_EDITION=pro npm run tauri build
```

Svelte components check this at module level:

```typescript
const isPro = import.meta.env.VITE_AGOR_EDITION === 'pro';
```

## IPC Pattern

All Pro commands follow the Tauri plugin IPC convention. Commands are namespaced under `plugin:agor-pro`:

```typescript
import { invoke } from '@tauri-apps/api/core';

const summary = await invoke('plugin:agor-pro|pro_analytics_summary', {
  period: 30,
});
```

Command names use the `pro_` prefix consistently. Arguments are passed as a single object. Return types are JSON-serialized Rust structs with `#[serde(rename_all = "camelCase")]`.

## Error Handling

Pro commands return `Result<T, String>` on the Rust side. The frontend adapters in `src/lib/commercial/adapters/` wrap `invoke()` calls and surface errors through the standard notification system. When the Pro plugin is not loaded (community build), invoke calls fail with a predictable `plugin not found` error that the adapters catch and handle silently.

## Database

Pro features use a dedicated SQLite database at `~/.local/share/bterminal/agor_pro.db` (WAL mode, 5s busy timeout). This keeps Pro data isolated from community tables. The `pro_budgets` and `pro_budget_log` tables are created on plugin init via migrations.

Read-only access to community tables (e.g., `session_metrics` in `sessions.db`) is done through a separate read-only connection.
