SaiphAI is a desktop AI coding assistant built on Electron, designed for flexible operation via integration with OpenAI and local AI instances. The application provides integrated codebase indexing, persistent chat history, and a built-in code editor with context-aware retrieval.
- AI Backend Integration: Supports both OpenAI (currently optimized for GPT-4o) and local operation via Ollama to leverage open-source models such as Llama 3 and Mistral.
- Intelligent Workspace Indexing: Recursively indexes workspace directories, respecting
.gitignorepatterns. Implements content chunking (1500 character blocks with 200 character overlap) and relevance scoring to provide precise code context to the AI. - Persistent Chat Management: Stores conversation history in an SQLite database (via sql.js) with JSON serialization of message threads. Supports chat restoration, history browsing, and atomic save operations.
- Integrated Development Environment: Embeds Monaco Editor for file viewing and editing, with support for multiple open tabs, scroll position restoration, and syntax highlighting.
- Real-time File Monitoring: Utilizes Chokidar to watch workspace directories for changes, automatically updating the search index and UI when files are added, modified, or removed.
- Atomic Configuration Management: Settings are written atomically using temporary files and rename operations, with automatic backup recovery in case of corruption.
The application follows Electron's multi-process architecture:
- Main Process (
main.js): Handles Node.js-level operations including file system access, database persistence (SQLite via sql.js), HTTP requests to the AI backend, and native dialog integration. Implements theWorkspaceIndexclass for content indexing and theSettingsManagerclass for configuration persistence with write queuing. - Preload Script (
preload.js): Securely exposes main process APIs to the renderer via ContextBridge, including file operations and IPC handlers. - Renderer Process (
renderer.js): Manages the user interface, Monaco Editor integration, chat state management, and communication with the AI backend.
- Node.js (v18 or later)
- npm or yarn
- An OpenAI API Key OR Ollama
Clone the repository
git clone "https://github.com/Serpenseth/saiphai"Enter into the cloned directory
cd saiphaiInstall SaiphAI
npm installFinally, run SaiphAI
npm startOn first launch, the application prompts for AI backend configuration:
- OpenAI: Requires a valid API key. Currently, the application is configured to support GPT-4o for high-reasoning coding assistance.
- Ollama: Requires a running Ollama instance on
localhost:11434. The application queries available models via the Ollama API for selection.
Workspace selection can be performed at any time via the interface. The application indexes the selected directory, excluding common patterns (node_modules, .git, build directories, etc.) and respecting .gitignore files.
The WorkspaceIndex class maintains an in-memory map of file metadata and content. When a query is submitted:
- Files are scored based on path matching and content relevance.
- Large files are split into overlapping chunks.
- Chunks are scored based on term frequency, exact phrase matching, and code reference detection (function definitions, class declarations).
- Top-scoring chunks are assembled into a context window and prepended to the system prompt.
File modifications are tracked via Chokidar watchers, with debounced index updates to handle batch operations (e.g., git checkout, npm install).
Conversations are structured with a system prompt (BASE_SYSTEM_PROMPT) that instructs the model on code quality standards (SOLID principles, DRY, security considerations). User messages can include:
- Direct text input
- Attached files (via file picker)
- Automatically retrieved workspace context (via semantic search)
Chat history is persisted in two layers:
- Current session state is saved to JSON for crash recovery.
- Completed conversations are stored in SQLite with timestamps and titles derived from the first user message.
- Atomic Writes: Configuration files are written to a temporary location, then renamed into place to prevent corruption during write operations. Backups are maintained and automatically restored if the primary file is corrupted.
- Database Initialization: Uses sql.js to create an in-memory SQLite instance that is serialized to disk on every write operation, ensuring durability without requiring native SQLite bindings.
- File Chunking Strategy: Implements a sliding window approach with overlap to ensure code blocks spanning chunk boundaries remain contextually intact.
SaiphAI includes a secure, integrated build system supporting multiple languages and frameworks.
The build system automatically detects project types and configures appropriate commands:
| Language | Detection Files | Default Commands |
|---|---|---|
| JavaScript/TypeScript | package.json, tsconfig.json |
npm run build, npx tsc |
| Python | requirements.txt, pyproject.toml, setup.py |
python -m build, pip install |
| Rust | Cargo.toml |
cargo build --release |
| Go | go.mod |
go build |
| Java | pom.xml, build.gradle |
mvn package |
| C# | .csproj, .sln |
dotnet build |
| C/C++ | CMakeLists.txt, Makefile |
make, cmake |
The build system implements strict security controls:
- Command Whitelisting: Only approved build tools (npm, cargo, make, etc.) can execute.
- Pattern Blocking: Prevents shell injection attacks by blocking dangerous patterns (
rm -rf,curl | sh, path traversal attempts). - Workspace Validation: Builds are restricted to the selected workspace directory.
- Safe Execution: Uses
execFileinstead of shell execution to prevent injection attacks.
Builds can be triggered from the integrated build panel in the UI:
- Automatic Detection: Open a workspace folder to automatically detect the build configuration.
- Quick Actions: Execute standard commands (Build, Install, Test) via the build panel buttons.
- Custom Scripts: For Node.js projects, quickly run any script from
package.json. - Real-time Output: View build progress and output in the integrated terminal.
- Error Analysis: Failed builds offer AI-powered error analysis to identify root causes and suggest fixes.
The system maintains a history of recent builds:
- View duration, status, and exit codes of previous builds.
- Re-run previous builds with one click.
- Automatic cleanup of old build records.
- Persistent across application restarts.
Build settings are automatically inferred from project files:
- JavaScript/TypeScript: Detects available npm scripts and TypeScript configuration.
- Python: Identifies build backends (setuptools, poetry, etc.).
- Multi-language projects: Scans file extensions to determine dominant language when no config files are present.
Build output is limited to 10MB per build to prevent memory issues, with a default timeout of 5 minutes.
- ContextIsolation is enabled in the BrowserWindow configuration.
- NodeIntegration is disabled; all main process communication flows through the preload script's ContextBridge.
- File system access is restricted to user-selected directories (workspace) and application-specific data directories (settings).
npm run buildThe build process uses electron-builder, outputting to the dist directory. Configuration is specified in package.json.
saiphai/
├── main/
│ └── index.js # Electron main process, IPC handlers, indexing logic
├── preload/
│ └── preload.js # ContextBridge API definitions
├── renderer/
│ ├── index.html # Application markup
│ ├── renderer.js # UI logic, editor integration, chat management
│ └── styles.css # Application styles
├── package.json # Dependencies and build configuration
├── package-lock.json # Dependency lock file
└── README.md # Project documentation
sql.js: SQLite compiled to WebAssembly for chat persistence.chokidar: File watching.ignore: Gitignore pattern matching for indexing.marked: Markdown parsing for chat rendering.
- Workspace indexing loads entire file contents into memory; extremely large codebases may impact performance.
- File watching on Windows may have slight delays compared to macOS/Linux due to Node.js fs.watch limitations.
MIT