Jarvis · architecture · draft 2026-10-26

How Jarvis works

A personal development agent on the owner's laptop. A task arrives in chat, Jarvis takes it to a verified draft PR and follows it until CI is green and the review is approved. All model calls go through the claude CLI on the Max subscription, with no API key.

Iteration 1: engine + Postgres + web (chat and admin)Iteration 2: Slack threadsAll ADRs: proposed

Components

Everything runs on a single laptop. The engine is the only process that controls the system. Claude does the substantive work, but changes state only through tools the engine provides.

flowchart LR
    O([Owner])
    subgraph L[Laptop]
        W[Web: chat + admin]
        subgraph E[Engine · Node]
            API[HTTP API + SSE]
            UC[Use cases, state machine, limits]
            RUN[ClaudeCliRunner]
            WT[Watcher · timer]
            MCP[Jarvis MCP · tools]
        end
        PG[(Postgres · Docker)]
        D["claude -p · dispatcher"]
        K["claude -p · worker"]
        FS[(~/.jarvis: artifacts, worktrees)]
    end
    GH[(GitHub)]
    SRC[(Claude Design · Notion · Google Docs)]
    S[(Slack · iteration 2)]
    O --> W
    W -- REST --> API
    API -- SSE --> W
    API --> UC --> PG
    UC --> RUN --> D & K
    D & K -- tool calls --> MCP --> API
    K --> FS
    K -- MCP with tokens --> SRC
    K -- git push, gh pr --> GH
    WT -- poll --> GH
    WT --> UC
    S -. Socket Mode .- API
  
Engine

Plain code

Receives messages, stores state, launches Claude, watches GitHub, streams events to the web. It does not “think” itself.

Dispatcher

One session per thread

Each of your messages triggers a short run that resumes the thread's session. It understands the request, creates and manages tasks, and replies. It does not write code.

Worker

One process per task stage

Works in the task's git worktree: context, spec, plan, code, checks, review, PR. No process exists between stages; the session is resumed.

Watcher

Polls GitHub

Once a minute: CI, reviews, comments. It never runs the model. It wakes the worker only when something changed.

Jarvis MCP

Capability boundary

Tools per role: create_task, report_stage, ask_owner, approve… There is no tool for merge or push to main.

Web

Chat and admin

Threads, decision and permission cards, tasks, artifacts, live run consoles, limits, connections.

Flow of a single task

sequenceDiagram
    actor O as Owner
    participant W as Web
    participant E as Engine
    participant D as Dispatcher
    participant K as Worker
    participant G as GitHub
    O->>W: message (new thread)
    W->>E: POST message
    E->>D: resume thread session
    D->>E: create_task
    E->>E: branch jarvis/T-1 + worktree
    E->>K: run: context, spec, plan
    K->>E: submit_spec_for_approval
    E-->>W: Approve / Comment card
    Note over K: process exited, slot free
    O->>W: Approve
    E->>K: resume: code, checks, review
    K->>G: push, draft PR
    K->>E: report_pr
    loop every 60 s
        E->>G: checks, reviews, comments
    end
    G-->>E: CI failed / reviewer comment
    E->>K: resume: fix
    K->>G: new commit
    G-->>E: CI green + approve
    E-->>W: summary in thread
  

While a task waits for you, CI or review, no Claude process runs and no limits are spent. Your message sent while the worker is running goes to its stdin; otherwise it waits for the next run.

Task states

stateDiagram-v2
    [*] --> Intake
    Intake --> Context
    Context --> SpecReview: spec and plan ready
    SpecReview --> Context: owner comment
    SpecReview --> Implementing: Approve
    Implementing --> Verifying
    Verifying --> Implementing: check red (up to 3 attempts)
    Verifying --> Reviewing
    Reviewing --> Implementing: blocking comment
    Reviewing --> PROpen: draft PR
    PROpen --> Fixing: CI failed / comment
    Fixing --> PROpen: new commit
    PROpen --> Done: CI green + approve
    Context --> Blocked: question or no access
    Implementing --> Blocked: question
    Blocked --> Context: answer
    Verifying --> Failed: attempts exhausted
    Fixing --> Blocked: rounds exhausted
    Done --> [*]
  

A task can be cancelled (Cancelled) from any state: the branch and PR remain. Only states where a process is actually running occupy a worker slot.

Where data lives

Data is split by who changes it and whether it can be shared. The agent definition is in git and can be shown to participants. Personal and working data live in ~/.jarvis, outside the repository. State is in Postgres. Session transcripts are stored by Claude Code itself.

1. Agent definition git · repo jarvis

Who Jarvis is and how it works. It is a Claude Code plugin that the engine attaches to every run via --plugin-dir.

agent/
  .claude-plugin/plugin.json
  SOUL.md                     role, principles, style
  USER.example.md             template of owner preferences
  prompts/
    dispatcher.md             how to interpret messages, when to create a task
    worker/context.md · implement.md · fix-ci.md · address-review.md
  agents/                     worker subagents
    context-researcher.md · implementer.md (per lane) · reviewer.md (the gate) · ui-tester.md
  skills/                     SDD process, PR handling, visual verification
  templates/                  context · spec · plan · tasks · result
  settings/worker.json        allow/deny: what is allowed without asking, what is forbidden
  settings/dispatcher.json

2. Personal and working data ~/.jarvis · outside git

Preferences, config, secrets, and everything the agent produces while working.

~/.jarvis/
  USER.md                     your preferences: language, plan format, PR
  jarvis.config.json          repository, limits, models, allowlist
  .env                        GITHUB_TOKEN, NOTION_TOKEN, Google, DATABASE_URL
  mcp/servers.json            connector MCP servers; tokens are substituted from .env
  dispatcher/                 dispatcher working folder (needed for --resume)
  worktrees/T-1/              task git worktree in the target repository
  tasks/T-1/
    context.md spec.md plan.md tasks.md result.md
    screenshots/
  runs/R-17/                  mcp.json and settings.json generated per run

3. State Postgres · Docker

Threads, messages, tasks, journal, runs and every run event, permissions, PR watch state, usage. Details below.

4. Claude sessions ~/.claude · managed by Claude Code

Transcripts in ~/.claude/projects/<folder>/<session>.jsonl and the subscription login (Keychain). Jarvis stores only the session_id. A session is bound to the launch folder, so the dispatcher always starts from ~/.jarvis/dispatcher and the worker from its own worktree.

5. Project rules target repository

AGENTS.md with check and dev-server commands, conventions, CI. The worker reads them from its worktree. Project rules are not mixed with the owner's profile.

6. External output GitHub

jarvis/* branches, draft PRs, comments and commits from the Jarvis account. This is what other people see.

claude runs start with --setting-sources project,local: your personal plugins, skills and hooks from ~/.claude do not reach the agent. It sees only the Jarvis plugin, the target repository's rules and the MCP servers from --mcp-config (with --strict-mcp-config).

What is in the database

TableWhat it storesKey fields
threadsConversations with the ownertitle, status, summary (thread memory), dispatcher_session_id, slack_thread_ts
messagesMessages in a thread, including cardsthread_id, author (owner / jarvis / system), kind (text, status, decision, question, permission), body, payload
tasksTasksthread_id, stage, waiting_for, branch, worktree_path, pr_number, head_sha, worker_session_id, attempt and round counters
task_eventsTask journal, append-onlytask_id, at, type, payload; written in the same transaction as the state change
runsclaude runsrole, task_id / thread_id, stage, session_id, pid, model, status, turns, cost_usd (estimate), exit_reason
run_eventsEvery stream-json event — this is the “console”run_id, seq, type (text, tool_use, tool_result, error, result), payload jsonb
permission_requestsPermission requestsrun_id, tool, input_preview, status, answered_at
watchesPR watchtask_id, pr_number, head_sha, checks jsonb, review_state, last_comment_id, next_poll_at
usage_dailyDaily cost estimatedate, cost_usd, runs, paused

There are no secrets in the database. Run events pass through a redactor that strips tokens before they are written to the database or sent to the web.

How Claude is launched

Dispatcher run
cd ~/.jarvis/dispatcher
claude -p "<message>"
  --resume <thread-session>
  --output-format stream-json --verbose
  --plugin-dir agent/ --setting-sources project,local
  --append-system-prompt-file agent/prompts/dispatcher.md
  --mcp-config runs/R-n/mcp.json --strict-mcp-config
  --permission-prompt-tool mcp__jarvis__approve
  --model sonnet --max-turns 15
Worker run
cd ~/.jarvis/worktrees/T-1
claude -p --resume <task-session>
  --input-format stream-json --output-format stream-json --verbose
  --plugin-dir agent/ --setting-sources project,local
  --append-system-prompt-file agent/prompts/worker/<stage>.md
  --settings runs/R-n/settings.json
  --mcp-config runs/R-n/mcp.json --strict-mcp-config
  --permission-prompt-tool mcp__jarvis__approve
  --model sonnet --max-turns 60 --max-budget-usd 3

The engine passes child processes only the variables they need: the worker gets GH_TOKEN and connector tokens, the dispatcher gets nothing. If ANTHROPIC_API_KEY is present in the environment, the engine refuses to start, because otherwise -p would silently switch to API billing.

How the code is organized

shared/        Zod contracts: HTTP, SSE, MCP, config
engine/src/
  domain/      Task and states, Thread, Run, LimitPolicy
  application/ PostOwnerMessage, ApproveSpec,
               HandleCodeHostChange, ResumeTask…
               + ports: AgentRunner, CodeHost,
               TaskRepository, OwnerChannel
  infrastructure/ Drizzle, ClaudeCliRunner, git,
                  GitHub (Octokit), files, config
  presentation/   HTTP+SSE, Jarvis MCP, watcher,
                  Slack (iteration 2)
web/           chat + admin (React)
agent/         plugin: SOUL, prompts, subagents
compose.yaml   Postgres

The onion rule

  • The domain knows nothing about the DB, processes or HTTP — the state machine and limits are tested without the outside world.
  • Use cases talk to the outside world only through ports.
  • claude, git, gh are run only in infrastructure.
  • Slack in iteration 2 is just another adapter in presentation next to the web; the domain and use cases do not change.

Safety and limits

What the agent can and cannot do

  • Changes files only in its own worktree.
  • Pushes only to jarvis/*; push to the base branch, force-push and merge are denied in settings and have no tools.
  • Any other action outside the allowlist produces an Allow / Deny card in the thread; with no answer it is denied on timeout.
  • Text from PRs, Notion and CI logs is data, not instructions.
  • PR comments are honored only from people on the allowlist.

Limits for Max 5x · jarvis.config.json

  • 1 worker at a time (2 possible).
  • 3 check attempts, 2 CI rounds, 3 review rounds.
  • Per run: 60 turns and $3 by the CLI estimate.
  • $20 per day: after that new runs are paused, with a banner in the web.
  • The watcher polls GitHub every 60 s without the model.

Dollars are a CLI estimate, not the subscription meter. It is a brake, not precise accounting.

Not yet decided

  1. Which demo task, and in which repository.
  2. How the worker gets the design from Claude Design: a link, a handoff, or an export into the repository.
  3. Which MCP servers to use for Notion and Google Docs, and which token permissions they need.
  4. Whether a fine-grained PAT is enough to read check runs, or another approach is needed.
  5. How much of the Max 5x limit one full run of the demo task consumes.
  6. Accept or change ADR-0002…0011.