pensieve-server 0.1.0

HTTP + gRPC query API, auth stub, health, observability.
//! Shared handler state for the `/v1/agent/*` surface.

use crate::agent::engine::EnginePreferenceStore;
use crate::agent::skills::EnabledSkillsStore;
use pensieve_core::catalog::Catalog;
use pensieve_core::credentials::CredentialStore;
use pensieve_core::segment_format::SegmentFormat;
use pensieve_core::tenant::TenantId;
use sqlx::PgPool;
use std::sync::Arc;

#[derive(Clone)]
pub struct AgentState {
    /// Catalog handle — used by tools to enumerate databases / tables.
    pub catalog: Arc<dyn Catalog>,
    /// Object-store + segment format — passed to PensieveTable for inline tool SQL execution.
    pub format: Arc<dyn SegmentFormat>,
    /// Postgres pool — used to persist `agent_runs`/session rows and read memory
    /// settings. `None` in **local mode** (`pensieve-local serve`): run/session
    /// history isn't persisted and settings default; memory recall/save and the
    /// data tools run over the catalog + engine and work unchanged.
    pub pool: Option<PgPool>,
    /// Persisted engine preference (provider/model/credential/host/extras).
    pub engines: Arc<dyn EnginePreferenceStore>,
    /// Tenant-scoped credential store — used by CredentialResolver.
    pub credentials: Arc<dyn CredentialStore>,
    /// Tenant id this server is scoped to. v1 single-tenant: `DEFAULT_TENANT`.
    pub tenant: TenantId,
    /// Enabled-skill names — drives system-prompt injection for non-CLI engines.
    pub skills: Arc<dyn EnabledSkillsStore>,
    /// Loopback URL of this server's own MCP endpoint (e.g.
    /// `http://127.0.0.1:8080/mcp/v1`). When set, the Claude CLI engine wires
    /// it via `--mcp-config` so the agent can query the user's data. `None`
    /// disables MCP wiring for that engine.
    pub mcp_url: Option<String>,
    /// Async memory ingest queue — flows into every [`super::SharedToolCtx`]
    /// built from this state. `None` ⇒ synchronous memory writes.
    pub memory: Option<pensieve_memory::MemoryQueue>,
    /// Degraded local-mode dreaming state (in-memory ring + SQLite). `Some` only
    /// in `pensieve serve` (single-binary local mode); `None` in the worker-fabric
    /// server, where dreaming runs persist to Postgres. When set, the dreaming
    /// HTTP handlers serve from this store and runs execute inline.
    pub local_dreaming: Option<std::sync::Arc<super::dreaming_local::LocalDreamingStore>>,
    /// Path to the local memory-settings JSON file (`${PENSIEVE_HOME}/memory-settings.json`).
    /// `Some` only in local mode — settings GET/PUT read/write this file there.
    /// `None` in server mode, where settings live in the Postgres `memory_settings`
    /// row.
    pub memory_settings_path: Option<std::path::PathBuf>,
    /// Live consumer-activity broadcast bus. Flows into the [`super::SharedToolCtx`]
    /// of every interactive memory tool path (as a [`super::tools::ConsumerSink`])
    /// and is subscribed by the `GET /v1/consumers/live` WebSocket that drives the
    /// graph explorer's realtime overlay. `None` ⇒ the overlay has no live feed.
    pub consumer_events: Option<pensieve_ingest_core::ConsumerEvents>,
}