The server is Allen's API, persistence, integration, and runtime coordination layer. It exposes the product backend that the UI and desktop shell use.
packages/server
-
Start the Express API and real-time streams.
-
Connect to MongoDB and manage persisted data.
-
Seed the built-in teams, agents, workflows, and scheduled jobs.
-
Manage users, auth, repos, chats, executions, interventions, artifacts, files, and workspaces.
- Repo management includes a
PUT /api/repos/:id/default-branchendpoint that fetches remote refs, validatesorigin/<branch>exists, switches the checkout viagit switch -C <branch> origin/<branch>, and persists the branch as the newdetected.defaultBranch. Local-only branches are rejected. - Chat management includes send, queue, steer, export, and import endpoints.
POST /api/chat/sessions/:id/steerinjects a user message into the running agent turn mid-stream — it bypasses the turn queue and delivers the message directly into the active persistent runtime (Claude or Codex). If no active turn exists, the message falls back transparently to the existing queue behavior. - Chat export/import:
GET /api/chat/sessions/:id/export-optionsreturns counts and estimated size for a download preview.POST /api/chat/sessions/:id/exportassembles and streams a portable JSON bundle with configurable toggles (messages, tool calls, logs, traces, artifacts, code-diffs, thinking text) and server-side redaction (paths, identity, secrets).GET /api/chat/sessions/:id/export-bundlereturns the last completed export.POST /api/chat/import/previewvalidates bundle JSON, version, required fields, XSS patterns, and size.POST /api/chat/import/confirmpersists the bundle with full ID remapping and reverse-order rollback on failure. - Imported replay guards: imported sessions block message send, cancel, steer, queue, code-diff creation, agent answer, and automation messages. Imported executions block resume and retry. Interventions on imported sessions block respond. Watcher registration rejects imported sessions;
pollOnce()force-resolves any watcher linked to an imported session or imported execution.
- Repo management includes a
-
Run the Execution Watcher — a background poller (
WatcherService) that automatically monitors chat-started workflow and agent executions, generates deterministic status text from execution logs and known milestones, publisheswatcher_updateSSE events in real time, and sends hidden Assistant triggers when executions complete, fail, are cancelled, or wait for input. Boot-time reconciliation recovers watchers after server restart. Imported replay watchers are stored withwatcherStatus: 'resolved'so the poller never picks them up;pollOnce()also force-resolves any watcher for an imported session or imported execution. -
Coordinate workspaces, terminals, file watchers, and preview proxies.
-
Integrate with GitHub, Linear, Slack, MCP servers, and scheduled jobs.
-
Dispatch workflow and agent runs through the engine, including model-recovery retries via
POST /api/executions/:executionId/recover-model. -
Validate provider+model selection through
CLAUDE_COMPATIBLE_PROVIDER_CONFIGSinchat-providers.ts— OpenRouter models that are not in theanthropic/family return a non-Claude warning (getOpenRouterNonClaudeWarning) in agent and workflow config routes. TherunClaudeCompatibleChatCLIfunction suppresses the hostANTHROPIC_API_KEYduring all Claude-compatible provider runs so the provider'sANTHROPIC_AUTH_TOKENis never silently overridden. -
Manage the model registry (
/api/system/models, Settings → Models) that drives every model dropdown, display name resolution, and per-MTok cost calculation. The same data populates the recovery model selector viaGET /api/system/models/recovery, which returns provider-grouped active models for model-recovery prompts. Each entry carriesfullId(canonical DB key),displayName(human label, required), andproviderDisplayName(provider-level label, e.g. "Claude", "Codex", "OpenRouter", "GLM/Z.AI"). The unique index is{provider, fullId}; thealiasfield has been removed. The seed catalog syncs on every boot without overwriting admin edits. OpenRouter has no seeded models; users register OpenRouter provider slugs manually asfullIdvalues in Settings → Models. -
Run an idempotent alias→fullId migration at boot (
runAliasToFullIdMigration) that rewrites legacy aliases (e.g.sonnet→claude-sonnet-4-6) inagents.model,chat_sessions.model,chat_sessions.agentOverrides.model, andworkflows.nodes[].agentOverrides.modelusing a frozenLEGACY_ALIAS_LOOKUP_MAPcovering all supported providers. Historical execution trace records are NOT rewritten — a read-time legacy alias lookup inmodel-cost.service.tskeeps pre-migration cost figures accurate (FR-3.3). -
Manage document commenting and versioning through the
/api/documentsroute group (mounted atserver.ts). Endpoints:GET /api/documents/by-artifact/:artifactId— look up document identity by source artifact. Returns identity summary or a 404 witheligibleForCommentingflag.POST /api/documents— lazily create a document identity from an artifact (bridge).GET /api/documents/:documentId— get document summary with latest version + comment counts.GET /api/documents/:documentId/versions— list version metadata.GET /api/documents/:documentId/versions/:versionNumber— get full version content.POST /api/documents/:documentId/versions— create a new version (agent or human).POST /api/documents/:documentId/versions/:versionNumber/restore— restore a prior version (creates a new version with restored content, marks affected comments stale).GET /api/documents/:documentId/versions/compare?v1=N&v2=M— diff two versions (line-level added/removed/modified).GET /api/documents/:documentId/comments?status=open|resolved|stale|all— list comments.POST /api/documents/:documentId/comments— add a comment (with text anchor).POST /api/documents/:documentId/comments/:commentId/reply— reply to a comment thread.POST /api/documents/:documentId/comments/:commentId/resolve— resolve a comment.POST /api/documents/:documentId/comments/:commentId/reopen— reopen a resolved comment.GET /api/documents/:documentId/timeline— chronological event feed.
Database collections:
document_identities(unique:documentId, indexed:sourceArtifactId),document_comments(indexed:commentId,{documentId, status, createdAt},{documentId, threadId, createdAt}), plus version data embedded in the identity document. -
Inject a document comment workflow contract (
DOCUMENT_COMMENT_WORKFLOW) into the base chat persona system prompt. This instructs chat agents to read comments when they fetch a commentable artifact, treat unresolved comments as revision instructions, publish new versions viaallen_create_document_version, and resolve/reply to comments via the corresponding MCP tools. Stale comments are noted but not actionable until re-anchored. -
Register three agent-accessible MCP tools for document interactions:
allen_create_document_version— publish a new version of a commentable document.allen_resolve_document_comment— mark a comment as resolved with a note.allen_reply_document_comment— reply to a comment thread (used when a comment cannot be addressed).
UI / Desktop
-> Server API
-> MongoDB + workspace services + integrations
-> Engine for agent and workflow execution
The server is the boundary between product actions and runtime execution. It should preserve clear authentication, authorization, and auditability around anything that can affect repositories or credentials.
- App and route wiring:
packages/server/src/app.ts - Embeddable server startup:
packages/server/src/server.ts - API routes:
packages/server/src/routes/- Document routes:
packages/server/src/routes/document.routes.ts
- Document routes:
- Runtime services:
packages/server/src/services/- Document service:
packages/server/src/services/document.service.ts
- Document service:
- Auth:
packages/server/src/auth/,packages/server/src/middleware/ - Runtime config:
packages/server/src/runtime/ - Execution Watcher service:
packages/server/src/services/watcher.service.ts - Execution Watcher routes:
packages/server/src/routes/watcher.routes.ts - MCP tool definitions:
packages/server/src/services/allen-mcp-server.ts - Chat Export/Import services:
packages/server/src/services/chat-export.service.ts,packages/server/src/services/chat-import.service.ts - Chat Export/Import routes:
packages/server/src/routes/chat-export-import.routes.ts