$ show agegr/pi-web
Pi Web is a full-stack Next.js application that provides a browser-based interface for the Pi coding agent, an AI-powered coding assistant. It shares session files, configuration, and credential storage with the Pi CLI, enabling users to manage AI coding sessions, browse and edit files, run terminal commands, and configure models/plugins/skillsβall from a web browser. The application is designed for local use, running on Node.js β₯22.19 and opening at 127.0.0.1:30141 by default. Architecturally, Pi Web is a Next.js 16 App Router application with React 19 client components, a comprehensive REST API layer, and real-time streaming via Server-Sent Events (SSE) for agent events and terminal output. It features a PWA with service worker support for push notifications and offline fallback, optional password authentication with HMAC-signed session tokens, and an extension system for custom UI widgets. The frontend is organized around a chat-centric workspace with resizable panels for session management, file viewing, terminal emulation, and configuration. Key capabilities include session lifecycle management (create, fork, rename, delete, branch), file browsing with syntax highlighting and previews (images, audio, video, PDF, DOCX), Git worktree support, subagent runtime for background tasks, model catalog configuration with provider presets, and internationalization (English, Simplified Chinese, Traditional Chinese). The codebase is extensively tested with over 100 test files using Node's test runner and jiti for TypeScript imports, covering both unit and integration tests for API routes, components, and utilities.
The LLM identified 6 files worth highlighting for reuse:
Provides atomic file write operations by writing to a temporary file, then renaming to the target path with 0o600 permissions. This prevents partial writes and race conditions when multiple processes or requests write to the same file. The pattern is self-contained and can be extracted for any Node.js project needing safe file updates.
Implements password-based authentication with HMAC-signed session tokens, constant-time password comparison to prevent timing attacks, and Basic Auth header parsing. The module handles session token generation, validation, and expiry, and can be reused in any web application requiring simple yet secure local authentication.
A plugin-based internationalization system with a registry for locale messages, interpolation support, and relative-time formatting. It provides a React context provider (useI18n hook) with SSR-safe hydration. The architecture is decoupled from the application and can be extracted as a standalone i18n library for any React project.
Provides lexical and realpath-based path containment checks to prevent directory traversal attacks. It validates that a given path stays within an allowed root directory, handling symlinks, '..' segments, and cross-platform path separators. This is a reusable security utility for any Node.js application that serves user-accessible files.
Manages a Server-Sent Events (SSE) connection with automatic retry and exponential backoff, handling connection lifecycle, startup errors, and cancel-safe reconnection. It provides a clean interface for consuming real-time event streams and can be reused in any web application that needs resilient SSE consumption.
Parses compaction summary metadata from session files, extracting token counts, cost, and other aggregated statistics. It demonstrates a clean pattern for extracting structured data from semi-structured text blocks and can be adapted for any application that needs to parse summary metadata from log or session files.