How vikasprogrammer/agent-os works
Purpose and Entry Points
Agent OS is a Node.js control plane for safely running autonomous agents across isolated workspaces/tenants. Its defining invariant is that external side effects traverse a governed gateway.
Primary boot paths are CLI/server startup in src/index.ts, command handling in src/cli.ts, and composition/loading in src/kernel.ts. npm run serve exposes the API, console, and terminal proxy; src/demo.ts runs deterministic governance scenarios.
Kernel, Runs, and Agent Loading
The kernel assembles a tenant-scoped runtime: agents, policy, state, gateway, runtime adapters, connectors, and observability. Data-home resolution separates open-source software from private tenant data and establishes per-workspace storage boundaries.
• src/kernel.ts
• src/core/orchestrator.ts
• src/core/run.ts
• src/home.ts
A run is created from an agent/task, driven by a runtime adapter, and transitions through execution, approval waits, completion, or failure. Bundled agent manifests under config/agents/*/agent.json are seeds; tenant-home agents override matching IDs.
Governed Effect Gateway
src/gateway/gateway.ts is the architectural chokepoint for every registered capability invocation. Its pipeline classifies policy risk, obtains approval when required, reserves/debits budget, resolves acting identity, deduplicates retries, invokes the effect, and appends audit events.
• src/gateway/gateway.ts
• src/gateway/idempotency.ts
• src/capabilities/registry.ts
• src/capabilities/normalize.ts
Capabilities are the plugin boundary for external actions. Connector implementations and agent/runtime code should request effects through this boundary rather than invoke vendors directly.
Governance and Trust Plane
Governance supplies enforceable controls around the gateway: data-driven rules, human approval queues, cost/token caps, principal and recipient checks, append-only audit, semantic/file guards, and policy revision/reconciliation.
• src/governance/policy.ts
• src/governance/approvals.ts
• src/governance/budget.ts
• src/governance/audit.ts
• src/governance/identity.ts
Default and demo risk rules are externalized in config/policy/default.policy.json and config/policy/demo.policy.json. Policy classifies effects as green, yellow, red, or denied; yellow/red suspend the run until an authorized decision is recorded.
State, Memory, and Tenant Isolation
Persistent workspace state is centered on SQLite, with stores for members/auth, agents, tasks, goals, knowledge, artifacts, runtime accounts, policy revisions, and session activity. Audit JSONL remains the durable per-run system of record and is mirrored into state for console/API use.
• src/state/db.ts
• src/state/control.ts
• src/memory/index.ts
• src/tenant-registry.ts
A process-per-tenant deployment isolates by data home and DB. The optional registry mode constructs separate runtimes per tenant and routes by subdomain or trusted tenant header.
Runtime, Sessions, and External Boundaries
Agents run through mock or Claude Code adapters. Claude sessions are launched in agent folders through tmux and ttyd; the Claude pre-tool hook routes risky shell actions back into the gateway, preserving governance even for interactive sessions.
• src/runtime/claude-code-adapter.ts
• src/edge/launcher.ts
• terminal/claude-launch.sh
• terminal/gate-hook.sh
• src/edge/session-backend.ts
Material infrastructure is Node.js, built-in SQLite (node:sqlite), tmux, ttyd, and optionally systemd/nginx/Tailscale. Secrets are tenant/principal scoped via src/edge/secrets.ts; production vault replacement is an intended seam.
Edge, API, Console, and Integrations
The server exposes browser console/API routes, authentication/team management, approvals, live audit/session views, and terminal access. Edge modules adapt inbound channels, schedules, automation, connectors, LLM/media services, and operational maintenance into the kernel rather than embedding these concerns in governance.
• src/server.ts
• src/edge/router.ts
• src/edge/triggers.ts
• src/connectors/connectors.ts
• web/src/App.tsx
Supported integration boundaries include Slack, Discord, Telegram, GitHub, ClickUp, and Composio (src/connectors/). The React/Vite app in web/ is a separate frontend; public/console.html also supports the Node-served console path.
Main entry points: gateway.ts Governed effect gateway · kernel.ts Tenant kernel · server.ts Server and API · run.ts Run lifecycle
Components 21
Entry & Console
- CLI / server startup · Starts API, console, and terminal proxy.
src/index.ts - Server and API · Exposes console, API, approvals, audit, and terminal routes.
src/server.ts - React console
web/src/App.tsx - Edge router · Adapts inbound routes and channels into the kernel.
src/edge/router.ts
Tenant Control Plane
- Tenant kernel · Assembles the tenant-scoped agent runtime.
src/kernel.ts - Tenant registry · Optionally creates isolated runtimes per tenant.
src/tenant-registry.ts - Workspace data home · Separates software from private tenant workspace data.
src/home.ts - Run orchestrator · Creates and drives agent-task runs.
src/core/orchestrator.ts - Run lifecycle · Tracks execution, approval waits, completion, and failure.
src/core/run.ts - SQLite control state · Stores tenant control-plane records and mirrored audit views.
src/state/db.ts - Knowledge memory
src/memory/index.ts
Governance Gateway
- Governed effect gateway · All registered external effects traverse this pipeline.
src/gateway/gateway.ts - Capability registry · Normalizes and resolves allowed external actions.
src/capabilities/registry.ts - Policy and risk rules · Classifies effects as green, yellow, red, or denied.
src/governance/policy.ts - Approval queue · Authorized decisions resume or reject suspended runs.
src/governance/approvals.ts - Budget controls · Reserves and debits effect cost and token caps.
src/governance/budget.ts - Append-only audit · Durable per-run record of governed effects.
src/governance/audit.ts
Runtime & Integrations
- Claude Code runtime · Launches governed agent sessions in agent folders.
src/runtime/claude-code-adapter.ts - Terminal session backend · Backs tmux and ttyd terminal access.
src/edge/session-backend.ts - External connectors · Slack, GitHub, Discord, Telegram, ClickUp, and Composio boundary.
src/connectors/connectors.ts - Tenant scoped secrets · Resolves secrets by tenant and principal.
src/edge/secrets.ts
Connections 23
- CLI / server startup → Server and API: starts
- Server and API → React console: serves
- Server and API → Edge router: routes requests
- Edge router → Tenant registry: selects tenant
- Tenant registry → Tenant kernel: creates runtime
- Tenant kernel → Workspace data home: scopes storage
- Tenant kernel → Run orchestrator: assembles
- Tenant kernel → SQLite control state: uses
- Tenant kernel → Knowledge memory: uses
- Run orchestrator → Run lifecycle: creates and drives
- Run lifecycle → Claude Code runtime: executes through
- Claude Code runtime → Governed effect gateway: requests effects
- Terminal session backend → Governed effect gateway: pre-tool hook · Risky shell actions are routed back for governance.
- Server and API → Terminal session backend: terminal access
- Governed effect gateway → Policy and risk rules: classifies risk
- Governed effect gateway → Approval queue: queues yellow/red
- Approval queue → Run lifecycle: resumes decision
- Governed effect gateway → Budget controls: reserves/debits
- Governed effect gateway → Capability registry: resolves invocation
- Governed effect gateway → Append-only audit: appends event
- Append-only audit → SQLite control state: mirrors for views
- Capability registry → External connectors: invokes effects
- External connectors → Tenant scoped secrets: uses credentials