How anentrypoint/freddie works
Purpose and Entry Points
Freddie is a JavaScript agent harness: it runs LLM-driven agent turns with tools, persistent sessions, plugins, multi-channel gateway delivery, and optional dashboard/IDE integration. The main executable is bin/freddie.js; command dispatch and interactive/noninteractive flows live in src/cli/main.js, src/cli/interactive.js, and src/cli/oneshot.js. It also exposes an ACP JSON-RPC stdio server (src/acp/server.js) and browser bundle entry (src/browser/index.js).
Agent Runtime and Model Boundary
The central control loop is the XState-based agent machine in src/agent/machine.js, bridged to the pi agent/model substrate through src/agent/pi-bridge.js. Provider selection, ordered failover, credentials, retry/rate-limit behavior, and provider-specific wire formats are separated into src/agent/llm_resolver.js, src/credentials/pool.js, and adapters such as src/agent/adapters/anthropic_adapter.js, src/agent/adapters/openrouter_adapter.js, and src/agent/adapters/gemini_native_adapter.js. External LLM APIs are therefore behind adapters rather than directly coupled to CLI or platforms.
Context, State, and Persistence
Before model invocation, context is assembled by src/context/engine.js; long conversations are reduced by the dedicated compressor pipeline in src/agent/compress/index.js, src/agent/compress/compressor.js, and src/agent/compress/prune.js. Local durable state includes SQLite-backed sessions/search (src/sessions.js, src/db.js), machine snapshots/journals (src/machines/snapshot-store.js, src/machines/step-journal.js), and home/profile/config state (src/home.js, src/config.js). This is the key persistence boundary between transient agent execution and user-scoped ~/.freddie data.
Plugin Host and Tool Plane
The host loads native Freddie plugins and wraps plugsdk-compatible plugins; its contract, manifest schema, and middleware boundary are in src/host/host.js, src/host/contract.js, and src/host/tool-middleware.js. Plugin directories provide most capability surfaces: tools (plugins/tools/files/plugin.js, plugins/tools/bash/handler.js), memory (plugins/memory/memory/handler.js), workflows/agent controls (plugins/core/delegate/handler.js, plugins/core/checkpoint/handler.js), and security guards (plugins/security/path_security/handler.js). Skills are separately loaded from SKILL.md content through src/skills/index.js and skills/.
Gateway and Platform Adapters
Inbound messages and webhooks enter the gateway runtime in src/gateway/run.js, are routed through src/gateway/service.js and built-in hooks in src/gateway/builtin_hooks/, then reach agent execution/tooling. Channel-specific credential parsing and protocol formatting are plugin-owned, e.g. plugins/platform/platform-telegram/handler.js, plugins/platform/platform-discord/handler.js, and plugins/platform/platform-slack/handler.js. This isolates external messaging services from core agent semantics.
User Interfaces and Automation
The terminal REPL is the primary interactive interface; the dashboard is an Express/webjsx application rooted at src/web/server.js, src/web/app.js, and src/web/routes.js. Scheduled work uses src/cron/scheduler.js; parallel prompt execution is in src/batch.js. Agent workflows can also be represented as resumable persistent actors via src/machines/persistent-actor.js and templates under src/machines/templates/.
Runtime, Delivery, and Observability
The project runs on Node.js/CommonJS-style JavaScript with pi-mono, XState, floosie, Express, SQLite/FTS, and plugin-provided external APIs. Structured diagnostics and machine visibility are centralized in src/observability/log.js, src/observability/metrics.js, and src/observability/state-machines.js. GitHub Actions cover test, browser bundle, model matrix, publication, Pages, and upstream synchronization under .github/workflows/; static documentation is built from website/ and deployed through the Pages workflow.
Main entry points: machine.js Agent machine · service.js Gateway service · host.js Plugin host · main.js CLI flows
Components 21
Entry points
- CLI flows · Command dispatch plus interactive and one-shot execution.
src/cli/main.js - ACP server
src/acp/server.js - Browser entry
src/browser/index.js - Dashboard
src/web/server.js - Gateway service · Routes inbound channel messages and built-in hooks.
src/gateway/service.js
Agent runtime
- Agent machine · Central turn orchestration and tool execution state machine.
src/agent/machine.js - Context engine
src/context/engine.js - Conversation compressor · Prunes and compresses long conversations.
src/agent/compress/index.js - Pi bridge
src/agent/pi-bridge.js - LLM resolver · Selects providers with ordered failover and retry behavior.
src/agent/llm_resolver.js - LLM adapters · Provider-specific API wire formats.
src/agent/adapters/anthropic_adapter.js
Extensions & channels
- Plugin host · Loads native and plugsdk-compatible plugins with middleware.
src/host/host.js - Tools & controls · Files, shell, memory, delegation, checkpoints, and security guards.
plugins/tools/files/plugin.js - Skills
src/skills/index.js - Platform plugins · Telegram, Discord, Slack credentials and message formatting.
plugins/platform/platform-telegram/handler.js
State & operations
- Sessions & search · Durable user sessions and search index.
src/sessions.js - Machine durability · Persists resumable machine state and step history.
src/machines/snapshot-store.js - Persistent actors · Workflow actors backed by durable machine state.
src/machines/persistent-actor.js - Cron & batch · Scheduled and parallel prompt execution.
src/cron/scheduler.js - Observability
src/observability/log.js - User home/config · User-scoped ~/.freddie configuration and profile data.
src/home.js
Connections 23
- CLI flows → Agent machine: runs turns
- ACP server → Agent machine: RPC turns
- Browser entry → Agent machine: client integration
- Dashboard → Sessions & search: views sessions
- Gateway service → Agent machine: inbound messages
- Platform plugins → Gateway service: channel events
- Agent machine → Context engine: assembles context
- Context engine → Conversation compressor: reduces long history
- Agent machine → Pi bridge: invokes model
- Pi bridge → LLM resolver: resolves provider
- LLM resolver → LLM adapters: provider requests
- Agent machine → Plugin host: executes capabilities
- Plugin host → Tools & controls: loads tools and controls
- Plugin host → Skills: loads skills
- Agent machine → Sessions & search: reads/writes conversation
- Agent machine → Machine durability: snapshots steps
- Persistent actors → Agent machine: resumes workflows
- Persistent actors → Machine durability: persists actor state
- Cron & batch → Agent machine: starts prompts
- Agent machine → Observability: emits diagnostics
- Dashboard → Observability: machine visibility
- CLI flows → User home/config: loads profile
- Gateway service → User home/config: loads channel config