# Investibook

AI-powered investment research workspace inspired by NotebookLM.

## Overview

Investibook provides a workspace-based environment for AI-powered research and analysis. Each workspace is an independent environment with its own sources, chat history, and generated artifacts.

## Features

- **Workspace Management**: Create and manage multiple independent research workspaces
- **Three-Column Layout**:
  - **Sources Panel**: Manage data sources, workspace files, and available skills
  - **Chat Panel**: Interactive AI-powered chat with context from your sources
  - **Studio Panel**: View generated artifacts (reports, charts, summaries)
- **Persistent Storage**: Each workspace maintains its own sources, chat history, and artifacts
- **Session Management**: Independent sessions for each workspace

## Layout

```
Home Page (Workspace List)
┌─────────────────────────────────────────────────────┐
│              Investibook                            │
│   Your AI-powered investment research workspace     │
│                                                     │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐         │
│  │  Create  │  │ Workspace│  │ Workspace│         │
│  │Workspace │  │    #1    │  │    #2    │         │
│  └──────────┘  └──────────┘  └──────────┘         │
└─────────────────────────────────────────────────────┘

Workspace Detail Page
┌──────────────┬─────────────────────────────┬───────────────────┐
│   Sources    │           Chat              │     Studio        │
│   (280px)    │        (flex grow)          │    (flex grow)    │
│              │                             │                   │
│ 📋 Sources   │  💬 Chat with AI Agent      │  ✨ Artifacts     │
│              │                             │                   │
│ + Add Source │  Ask about your sources,    │  📊 Reports       │
│              │  alerts, metrics            │  📈 Charts        │
│ 🚨 Alert     │                             │  📝 Summaries     │
│ 📦 Git Repo  │                             │                   │
│ 🧠 Skills    │                             │  Click to view    │
│ 🏗️ Cluster   │                             │  full artifact    │
│ 👤 UserMeta  │                             │                   │
│   (readonly) │                             │                   │
└──────────────┴─────────────────────────────┴───────────────────┘
```

## Source Types

| Type | Icon | Description |
|------|------|-------------|
| **Alert** | 🚨 | Import alert items for analysis |
| **Git Repo** | 📦 | Connect a Git repository |
| **Skill** | 🧠 | Agent skill loaded on demand |
| **Cluster Meta** | 🏗️ | Cluster metadata and topology |
| **User Meta** | 👤 | Auto-injected read-only user context |

## Key Features

- **Workspace Management**: Create, view, and delete independent workspaces
- **Sources Panel**: Add/remove sources per workspace
- **Chat Panel**: agent chat (OpenCode/Claude via ACP, or Pi via RPC) with workspace context
- **Studio Panel**: View generated artifacts (reports, charts, summaries)
- **Persistent Storage**: All workspace data saved in browser localStorage
- **Independent Sessions**: Each workspace maintains its own session and history

## Quick Start

```bash
# 1. Install dependencies (auto-creates .env.local)
make install

# 2. Start backend (OpenCode agent) - in terminal 1
make run-api-opencode

# Or with Claude agent
# make run-api-claude

# Or with Pi agent
make run-api-pi

# 3. Start frontend (port 3000) - in terminal 2
make web
```

Open http://localhost:3000 and create your first workspace!

### Important: Configuration

**1. Frontend Environment (`.env.local`)**

The frontend needs to know the backend URL. This is automatically handled by `make install` or `make web`, which creates:

```bash
NEXT_PUBLIC_API_URL=http://localhost:8000
```

**Without this**, the frontend will fail to communicate with the backend.

**2. Agent Skills**

Agent skills are copied into each workspace under `.opencode/skills/` and are
configured by `agentkit/config/opencode.json.template`. Enabled skills are also
mirrored into `.pi/skills/` so the same workspace can run with `ACP_AGENT_TYPE=pi`.

**3. Optional Langfuse Tracing**

OpenCode telemetry is emitted by the local plugin in
`agentkit/plugins/ya-opencode-telemetry`. To send traces to Langfuse, configure
the backend process environment; OpenCode agent subprocesses inherit these
values.

```bash
LANGFUSE_ENABLED=true
LANGFUSE_PUBLIC_KEY=lf_pk_...
LANGFUSE_SECRET_KEY=lf_sk_...
LANGFUSE_BASE_URL=https://your-langfuse.example.com
LANGFUSE_ENVIRONMENT=dev
```

`LANGFUSE_BASE_URL` can point at a self-hosted Langfuse instance. `LANGFUSE_HOST`
is also accepted for compatibility. The plugin records OpenCode system prompts,
message history, assistant output, and tool calls without redaction.

For the dev Kubernetes environment, non-secret values are configured in
`deployment/kustomize/envs/dev/kustomization.yaml`, and API keys are read from
the optional `investibook-langfuse-secret` secret:

```bash
kubectl create secret generic investibook-langfuse-secret \
  -n investibook \
  --from-literal=LANGFUSE_PUBLIC_KEY=lf_pk_... \
  --from-literal=LANGFUSE_SECRET_KEY=lf_sk_...
```

## Usage Flow

1. **Home Page**: View all your workspaces or create a new one
2. **Create Workspace**: Click "Create Workspace" and enter a name and description
3. **Enter Workspace**: Click on a workspace card to enter the three-column layout
4. **Add Sources**: Use the left panel to add data sources for analysis
5. **Chat**: Ask questions in the middle panel about your sources
6. **View Artifacts**: Generated reports and charts appear in the right panel
7. **Switch Workspaces**: Click "Back to Workspaces" to return to the home page

## Data Storage

All workspace data is stored in browser localStorage:
- `investibook_workspaces`: List of all workspaces
- `workspace_{id}_sources`: Sources for each workspace
- `workspace_{id}_artifacts`: Artifacts for each workspace
- `workspace_{id}_session`: Session ID for each workspace

## Architecture

- **Frontend**: Next.js 16 (App Router), React 18, TypeScript
- **UI**: Ant Design, TiDB Cloud UIKit, Tailwind CSS
- **Backend**: FastAPI with ACP protocol
- **AI Agents**: OpenCode or Claude via Agent Client Protocol

## Project Structure

```
investibook/
├── app/
│   ├── page.tsx                    # Home page (workspace list)
│   ├── workspace/[id]/page.tsx     # Workspace detail page
│   ├── layout.tsx                  # Root layout
│   └── providers.tsx               # Client providers
├── components/
│   ├── SourcesPanel/               # Left panel
│   ├── ChatPanel/                  # Middle panel
│   ├── StudioPanel/                # Right panel
│   └── ...                         # Other components
├── lib/
│   ├── workspace.tsx               # Workspace context provider
│   ├── workspaces.ts               # Workspace management utilities
│   └── types.ts                    # TypeScript types
└── backend/
    ├── main.py                     # FastAPI + ACP server
    └── templates/
        └── example/                # Example workspace template
```

## Docker

```bash
docker-compose up -d
```

## Features

- **Workspace management**: Multiple independent workspaces
- **Home page**: Workspace list with create/delete functionality
- **Persistent storage**: Workspace-specific data storage in localStorage
- **Navigation**: Back button to return to workspace list
- **Workspace header**: Shows workspace name and description
- InsightReport component
- AnomaliesPanel component
- ChartCard and metrics-chart library
- ACP backend with OpenCode/Claude agents
- Three-column layout
- Source management
- Artifact generation
