# Product Requirements Document (PRD): Sutra AI Ecosystem

## 1. Product Vision
To build the most comprehensive, secure, and performant AI ecosystem for macOS. Sutra leverages the full potential of Apple Silicon and Apple Intelligence to provide developers and power users with a "local-first" alternative to cloud-based AI platforms.

## 2. Core Components (Implemented)

### 2.1 Sutra AFM (Library)
- ✅ **Inference Engine:** Asynchronous Rust/Swift FFI bridge with memory-safe session streaming.
- ✅ **Embeddings:** 512-dim vector generation via `NaturalLanguage`.
- ✅ **Tokenization:** High-fidelity token counting using the official Apple Foundation Model tokenizer.
- ✅ **Autonomous Agent:** Recursive reasoning loop with local tool execution and goal-based grounding.
- ✅ **MCP Protocol:** Support for third-party tool servers (JSON-RPC 2.0) with dynamic macOS sandboxing and environment variable injection.

### 2.2 Sutra AI (CLI)
- ✅ **Agentic UX:** Toggleable autonomous agent (`/mode`), execution planning (`/plan`), and functional MCP catalog (Filesystem, Brave, GitHub).
- ✅ **Human-in-the-Loop (HITL):** Safe execution environment requiring user approval before tool usage.
- ✅ **Task State Management:** Automatically injects goals and structured plans into the agentic reasoning loop.
- ✅ **Pro REPL:** Interactive, highly polished shell environment with slash commands (`/read`, `/sys`, `/history`, `/tools`).
- ✅ **Zero-DB Context Buffer:** Read files and execute shell commands directly into the AI's context window.
- ✅ **Unix Pipeline Mastery:** Native support for `stdin` piping (e.g., `cat file | sutra-ai "prompt"`).
- ✅ **Markdown Persistence:** Automatic session logging to `.sutra_history.md`.
- ✅ **Utilities:** Staged git change analysis, summarization, and proofreading.

## 3. Technical Constraints
- **Silicon Restricted:** Optimized for Apple M1, M2, M3, M4 chips.
- **Privacy Guaranteed:** Zero telemetry; zero cloud processing.
- **Memory Efficient:** Minimal RAM footprint by using system-resident model weights.

## 4. Roadmap (Future)

### 4.1 Durable Sessions & Resumable Workflows (In Progress)
- **Branch-Aware Persistence:** Store session history bound to specific Git branches inside a `.sutra/sessions/` directory.
- **State Re-hydration:** Allow users to close the terminal and resume the agent's context exactly where they left off by injecting the last `N` turns of markdown history into the prompt.
- **Two-Tier Project Memory:** Implement an auto-compacting active context window and a long-term `.sutra/knowledge.md` file for cross-session "fact" storage.

### 4.2 Extended Capabilities
- **Computer Use:** Vision-based screen analysis and native mouse/keyboard control via macOS Accessibility API.
- **Modular Plugin Market:** A community marketplace for MCP servers specifically for Sutra.
- **Voice Mode:** Integration with `Siri` and `Dictation` for fully hands-free AI interaction.
