How rockbite/localforge works
Purpose and entry points
Localforge is a local intelligent coding assistant: it serves a browser UI, lets an LLM autonomously inspect and modify a selected workspace, and can run as an Electron desktop app. The CLI entry point is cli.js; the application/server composition starts at src/index.js and src/server/index.js. Electron packaging launches electron/main.js, with isolated renderer access via electron/preload.js.
Application host and UI boundary
The Node server renders EJS views and serves the static browser client. Server-rendered shell and component layout live in views/main.ejs, views/partials/main-panel.ejs, and views/partials/right-panel.ejs. The client is modular vanilla JavaScript: bootstrap/state in public/js/main.js and public/js/state.js, HTTP access in public/js/api.js, and real-time messaging in public/js/socket.js. This separates browser interaction from privileged filesystem, model, and process operations on the local backend.
Agent orchestration
The core agent service coordinates conversations, model calls, tools, and task progress in src/services/agent/index.js. Agent-facing HTTP endpoints are exposed through src/routes/agentsRoutes.js; persisted agent definitions/state are handled by src/db/agentStore.js. Prompt templates provide role-specific system instructions and transformations, centered on prompts/main-system.ejs, with specialist templates such as prompts/expert-advice.ejs and prompts/compressor.ejs.
Model-provider abstraction and accounting
LLM middleware routes requests through a provider adapter layer in src/middleware/llm.js and src/middleware/providers/index.js. Implementations support hosted and local model backends, including src/middleware/providers/openai.js, src/middleware/providers/anthropic.js, src/middleware/providers/aws.bedrock.js, Gemini, Vertex AI, Hugging Face, and Ollama. Usage/cost tracking is a separate service in src/services/accounting/index.js, using model pricing definitions from src/config/pricing.js.
Autonomous tool execution
The agent acts on the local workspace through a centralized tool registry at tools/index.js. File discovery and edits are represented by tools such as tools/list/GrepTool.js, tools/list/EditTool.js, and tools/list/GlobTool.js; command execution is mediated by tools/list/BashTool.js and security controls in tools/utils/bashSecurity.js. Additional capabilities include web fetch, browser automation under tools/list/browser, expert delegation, and task management. This is the critical trust boundary: model-generated actions are translated into local filesystem/process/network operations.
Workspace, sessions, and persistence
Project/workspace lifecycle is exposed via src/routes/projectsRoutes.js, while session state is managed in src/services/sessions/index.js with schemas in src/services/sessions/schema.js. General persistence resides in src/db/store.js. The UI’s project and workspace controllers—public/js/ui/projects.js and public/js/ui/workspace.js—surface this state, and public/js/file-tree.js presents filesystem structure.
Auxiliary capabilities and deployment
Context compression is implemented across src/logic/compress.js, src/routes/compressionRoutes.js, and src/services/compressionTracker.js. The service layer also supports MCP integrations (src/logic/mcp.js, src/services/mcp/index.js), image handling, task tracking, and update checks. Electron-specific local hosting and release updates are handled by electron/server.js and electron/updater.js; CI release/build workflows are in .github/workflows/build-and-release.yml and .github/workflows/macos-build.yml.
Main entry points: agent/index.js Agent orchestrator · server/index.js Server composition · api.js Client API & sockets · llm.js LLM middleware
Components 20
Browser UI
Server-rendered shell and modular browser client.
- EJS application shell · Main layout and panel structure.
views/main.ejs - Browser client · Bootstraps UI state and user interactions.
public/js/main.js - Client API & sockets · HTTP and realtime messaging to the local backend.
public/js/api.js
Local Server
HTTP, realtime, and application composition.
- CLI entry point
cli.js - Application host · Composes the local application server.
src/index.js - Server composition · Serves views, static client, routes, and realtime services.
src/server/index.js - Agent endpoints
src/routes/agentsRoutes.js - Project endpoints
src/routes/projectsRoutes.js - Sessions & persistence · Session schemas plus general and agent state.
src/services/sessions/index.js
Agent Runtime
Conversation orchestration and autonomous actions.
- Agent orchestrator · Coordinates conversations, prompts, models, tools, and progress.
src/services/agent/index.js - Prompt templates · Role instructions and context transformations.
prompts/main-system.ejs - LLM middleware · Routes model requests through provider adapters.
src/middleware/llm.js - Model providers · Hosted and local backends including OpenAI, Anthropic, Bedrock, and Ollama.
src/middleware/providers/index.js - Usage accounting · Tracks model usage and cost from pricing definitions.
src/services/accounting/index.js - Tool registry · Translates model actions into local capabilities.
tools/index.js - Command security · Guards Bash tool process execution.
tools/utils/bashSecurity.js - Context compression · Compresses agent context and tracks compression state.
src/logic/compress.js
Desktop & Delivery
Electron hosting and release automation.
- Electron desktop host · Launches local hosting with isolated renderer access.
electron/main.js - Build & release workflow
.github/workflows/build-and-release.yml
Other components
- Workspace filesystem · Files are discovered, edited, and executed by tools.
Connections 20
- CLI entry point → Application host: starts
- Application host → Server composition: composes
- Server composition → EJS application shell: renders
- Server composition → Browser client: serves
- Browser client → Client API & sockets: uses
- Client API & sockets → Agent endpoints: agent requests
- Client API & sockets → Project endpoints: workspace requests
- Agent endpoints → Agent orchestrator: invokes
- Project endpoints → Sessions & persistence: loads and saves
- Agent orchestrator → Prompt templates: renders
- Agent orchestrator → LLM middleware: requests inference
- LLM middleware → Model providers: selects adapter
- LLM middleware → Usage accounting: records usage
- Agent orchestrator → Tool registry: dispatches actions
- Tool registry → Command security: guards commands
- Tool registry → Workspace filesystem: inspects and modifies
- Agent orchestrator → Sessions & persistence: persists state
- Agent orchestrator → Context compression: compresses context
- Electron desktop host → Server composition: hosts locally
- Build & release workflow → Electron desktop host: packages