How lilimozi/openhanako works
1. Product and Runtime Shape
HanaAgent is a local-first, multi-agent personal AI assistant: desktop GUI, server-first CLI, mobile/LAN clients, external messaging bridges, tools, memory, scheduling, and plugins. It is primarily an Electron application that starts or connects to a separate Node.js server process; clients consume server APIs and WebSockets.
Primary entry points:
• Electron main/preload: desktop/main.cjs, desktop/preload.cjs
• React renderer: desktop/src/main.tsx, desktop/src/react/App.tsx
• Server variants: server/main-full.ts, server/main-open.ts, server/index.ts
• CLI: cli/entry.ts
• Background hub: hub/index.ts
2. Server Composition and Transport Boundary
The Hono-based server is the application boundary for desktop, mobile PWA, LAN clients, plugins, and CLI. Composition roots distinguish full versus open/server artifacts; route modules expose chat, sessions, resources, models, bridges, plugins, and settings. WebSocket protocol carries streaming chat and resource/event updates.
• server/composition/full-root.ts
• server/composition/open-root.ts
• server/routes/chat.ts
• server/ws-protocol.ts
Request security is centralized around transport context, principals, route authorization, and audit logging rather than delegated to UI clients:
• server/http/boundary.ts
• server/http/route-security.ts
• core/server-auth.ts
3. Agent Engine, Sessions, and Model Execution
core/engine.ts is the orchestration facade over managers for agents, sessions, models, configuration, skills, channels, bridges, and plugins. Agents execute through the Pi SDK and the internal LLM/provider layer. Session coordination owns loading, turn lifecycle, model isolation, compaction, tool snapshots, and teardown; persisted conversation data includes JSONL and a session manifest layer.
• core/engine.ts
• core/agent-manager.ts
• core/session-coordinator.ts
• core/llm-client.ts
• lib/llm/provider-client.ts
• core/session-manifest/store.ts
Flow: a client submits a turn → server chat route/engine resolves agent and session → policy/context/tools are assembled → provider/Pi runtime streams execution → session state and stream events are persisted and published back over WebSocket.
4. Persistence, Memory, and Workspace Resources
User state is rooted under HANA_HOME; better-sqlite3 (WAL) is the material database runtime, alongside session files/manifests and controlled filesystem storage. Data-epoch migration/restore coordinates schema evolution. The memory subsystem derives facts, summaries, pinned and compiled memory, and scheduled “dream” revisions from sessions.
• shared/persistence/store-registry.ts
• core/data-epoch-coordinator.ts
• lib/memory/compile.ts
• lib/memory/fact-store.ts
• lib/resource-io/resource-io.ts
• core/session-jsonl-file.ts
Resource I/O is an authority boundary: local filesystem, mounts, URLs, and session files are represented through providers and access policy rather than arbitrary path access.
• lib/resource-io/resource-access-policy.ts
• lib/resource-io/providers/local-fs-provider.ts
5. Tools, Sandboxing, and Computer Control
Tools span files, terminal, browser, web search/read, automation, media, subagents, and computer use. Invocation permissions and capability policy gate tool exposure. Execution is isolated with application path guards plus platform-specific OS sandbox implementations: macOS Seatbelt, Linux Bubblewrap, and Windows restricted-token/helper paths.
• core/tool-catalog.ts
• lib/permission/tool-invocation-permission.ts
• lib/sandbox/index.ts
• lib/sandbox/path-guard.ts
• core/computer-use/computer-host.ts
• lib/terminal/terminal-session-manager.ts
6. Background Coordination and External Integrations
The hub is independent of the foreground chat turn and runs scheduling, heartbeats, channel routing, direct-message routing, and agent execution dispatch. Bridge adapters connect agents to Telegram, Feishu, QQ, WeChat, and DingTalk, preserving platform/media capabilities and session identity. MCP supports stdio and HTTP/JSON-RPC connectors with OAuth.
• hub/scheduler.ts
• hub/channel-router.ts
• lib/bridge/bridge-manager.ts
• lib/bridge/telegram-adapter.ts
• core/mcp/manager.ts
7. Desktop, Plugin, and Distribution Surfaces
Electron hosts React 19/Zustand UI surfaces for chat, workspace (“desk”), settings, onboarding, quick chat, and browser viewer. The plugin system can contribute tools, routes, providers, UI surfaces, skills, and lifecycle behavior, with restricted/full-access capability levels. Built-in plugins ship under plugins/; SDK/runtime packages define the extension contract.
• desktop/src/react/bootstrap.ts
• desktop/src/react/services/server-connection.ts
• core/plugin-manager.ts
• packages/plugin-sdk/src/index.ts
• packages/plugin-runtime/src/index.ts
Build scripts package server/runtime dependencies and native computer-use helpers for macOS and Windows:
• scripts/build-server.mjs
• scripts/build-computer-use-helper.mjs
Main entry points: engine.ts Agent engine · full-root.ts Server composition · tool-catalog.ts Tool catalog · session-coordinator.ts Session coordinator
Components 21
Client Surfaces
- Electron host · Starts or connects to the separate server process.
desktop/main.cjs - React desktop UI
desktop/src/react/App.tsx - Server-first CLI
cli/entry.ts
Server Boundary
- Server composition · Full and open artifacts compose the application boundary.
server/composition/full-root.ts - Chat API
server/routes/chat.ts - Transport security · Builds transport context, principals, authorization, and audit records.
server/http/boundary.ts - Streaming protocol · Carries chat streams and resource/event updates.
server/ws-protocol.ts
Agent Runtime
- Agent engine · Coordinates agents, sessions, models, skills, channels, bridges, and plugins.
core/engine.ts - Session coordinator · Owns loading, isolation, compaction, tool snapshots, and teardown.
core/session-coordinator.ts - Model execution · Executes provider-backed agent turns with streaming.
core/llm-client.ts
State and Resources
- Persistent state · HANA_HOME contains WAL-backed state, JSONL conversations, and manifests.
shared/persistence/store-registry.ts - Memory compiler · Derives facts, summaries, pinned, compiled, and dream-revised memory.
lib/memory/compile.ts - Resource I/O policy · Mediates filesystem, mounts, URLs, and session-file access.
lib/resource-io/resource-access-policy.ts
Automation and Integrations
- Tool catalog
core/tool-catalog.ts - Sandboxed tool execution · Uses path guards and platform-specific isolation.
lib/sandbox/index.ts - Computer and terminal control
core/computer-use/computer-host.ts - Background hub · Runs independent scheduling, heartbeats, routing, and dispatch.
hub/index.ts - Messaging bridges · Connects external messaging platforms while preserving identity and media capabilities.
lib/bridge/bridge-manager.ts
Extensions and Distribution
- Plugin manager · Loads capability-scoped tools, routes, providers, UI, skills, and lifecycle behavior.
core/plugin-manager.ts - Plugin SDK
packages/plugin-sdk/src/index.ts - Distribution build · Packages server dependencies and native computer-use helpers.
scripts/build-server.mjs
Connections 25
- Electron host → React desktop UI: hosts
- Electron host → Server composition: starts or connects
- React desktop UI → Chat API: submits turns
- Server-first CLI → Server composition: consumes APIs
- Server composition → Transport security: applies
- Transport security → Chat API: authorizes
- Server composition → Streaming protocol: exposes
- Chat API → Agent engine: dispatches turns
- Agent engine → Session coordinator: coordinates
- Agent engine → Model execution: invokes
- Agent engine → Tool catalog: assembles tools
- Session coordinator → Persistent state: persists sessions
- Session coordinator → Memory compiler: supplies conversation context
- Memory compiler → Persistent state: stores derived memory
- Tool catalog → Sandboxed tool execution: gates execution
- Sandboxed tool execution → Computer and terminal control: isolates
- Tool catalog → Resource I/O policy: uses controlled resources
- Agent engine → Streaming protocol: publishes streams
- Background hub → Agent engine: dispatches agent work
- Background hub → Messaging bridges: routes channels
- Messaging bridges → Agent engine: delivers external messages
- Plugin manager → Server composition: contributes routes and providers
- Plugin manager → Tool catalog: contributes tools
- Plugin SDK → Plugin manager: defines contract
- Distribution build → Electron host: packages desktop runtime