Daemon & Portal Chat
Keep the agent always-on so your web portal can reach your servers and devices in real time — no terminal open required.
sudoji daemon and connect to the same hub.What the daemon is
sudoji daemon opens a persistent WebSocket from your server to the Sudoji cloud hub (agent.sudoji.io). While it is running:
┌──────────────────────┐ ┌───────────────────────────┐
│ Your Browser │ │ Your Server / Device │
│ │ │ │
│ sudoji.io/sessions │ │ $ sudoji daemon │
│ (portal chat UI) │ │ │
└──────────┬───────────┘ └─────────────┬─────────────┘
│ POST /portal/threads │ WebSocket
│ Bearer: Supabase JWT │ /v1/daemon
▼ ▼
┌────────────────────────────────────────────────────────────┐
│ agent.sudoji.io │
│ │
│ • Verifies JWT / API key │
│ • Checks plan + credits │
│ • Routes portal message → daemon WS │
│ • Writes thread_messages to Supabase │
│ • Supabase Realtime notifies portal UI │
└────────────────────────────────────────────────────────────┘
Requirements
Starting the daemon
Foreground (testing)
Run directly to see the banner and connection logs. Press Ctrl-C to stop.
sudoji daemon
░░░░░ ░░░░░ ░░░░░░ ░░░░░ ░░░░░ ░░
░ ░░ ░ ░ ░ ░ ░ ░ ░ ░ ░░
░░░░░ ░░░░░ ░░░░░░ ░░░░░ ░ ░░
░ ░ ░ ░ ░ ░ ░ ░ ░░
░ ░ ░ ░░░░░░ ░ ░ ░░░░░ ░░░░░░
connected cstock-dev
plan engineer
credits $8.43
hub wss://agent.sudoji.io/v1/daemon
✓ daemon onlineRunning under PM2 (recommended — no second SSH session needed)
For production servers, run the daemon under PM2 so it survives reboots, auto-restarts on crash, and requires no open terminal session.
# Install pm2 if not already installed
sudo npm install -g pm2
# Start the daemon as a named process — --interpreter none matters here,
# otherwise pm2 tries to run the file through Node itself instead of
# letting the sudoji binary's own shebang handle that
pm2 start $(which sudoji) --name sudoji-daemon --interpreter none -- daemon
# Save the process list so pm2 restores it after reboot
pm2 save
# Register pm2 as a system service — run the command it prints
pm2 startup
# Monitor
pm2 status
pm2 logs sudoji-daemon --lines 30pm2 startup, copy and run the command it outputs (e.g. sudo env PATH=... pm2 startup systemd -u ubuntu --hp /home/ubuntu). That registers pm2 itself with systemd so it starts on boot and restores all saved processes — including the daemon.Running under systemd
[Unit]
Description=Sudoji Daemon
After=network.target
[Service]
ExecStart=/usr/bin/sudoji daemon
Restart=always
RestartSec=5
User=ubuntu
Environment=SUDOJI_NO_KEYCHAIN=1
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable --now sudoji-daemon
sudo systemctl status sudoji-daemonSUDOJI_NO_KEYCHAIN=1 in the service environment when there is no interactive user session — systemd and pm2 service contexts have no D-Bus or GNOME Keyring session to attach to.Sending messages from the portal
Once the daemon is running, go to sudoji.io/dashboard/sessions and select a conversation thread. If the daemon is online for that server you will see ● daemon online in the thread header and the send bar becomes active.
Type a message and press Enter or click Send. The flow is:
sudoji daemon on the server to process messages." You can keep sending — messages queue in the thread and the daemon will process them once it reconnects.Approving tool calls
When the agent proposes a command that isn't pre-approved by your policy settings, the portal shows a "sudoji wants to run" bubble with the exact command and three buttons:
Stopping a run
While the agent is actively working on a turn, a red ■ stop button appears in the thread header. Clicking it kills any command currently running on the server — including background or child processes it launched — and halts the agent's loop rather than letting it finish or time out. The thread returns to idle once the stop takes effect.
What the agent can do from the portal
The agent mode is set when a thread is created (from sudoji chat --mode <mode>) and controls what the agent is allowed to do when it handles your messages:
sudoji chat terminal session to execute it.Terminal chat: sudoji chat
sudoji chat is the terminal-side companion to the portal. It opens an interactive REPL where you type messages and receive streamed responses — but unlike sudoji ask the conversation history is preserved across turns, so the agent can refer back to what it read and found earlier.
Every session is automatically assigned a generated name (like Brave Falcon) and saved as a thread. The thread is immediately visible in the portal Sessions → Chat tab, and you can rename it from the portal by clicking the title. If the daemon is running, the same thread is also reachable from the portal for sending follow-up messages from the web.
# Plan first in diagnose mode (read-only, safe)
sudoji chat
sudoji › I want to add swap to this server — walk me through it
› This server has 2 GB RAM and no swap. Recommended: 2 GB swap file.
Steps: fallocate → chmod → mkswap → swapon → /etc/fstab entry.
sudoji › exit
# Then execute in fix mode
sudoji chat --mode fix
sudoji › why is the API returning 503?
[agent reads nginx logs, pm2 status…]
› The upstream Node process (pm2 id 0) has crashed 4 times in the last hour.
Exit code 137 each time — it's being OOM-killed.
sudoji › how much memory is it using vs the limit?
[agent runs free -m, checks pm2 ecosystem…]
› Node is hitting 1.8 GB. The server has 2 GB total and no swap.
ecosystem.config.js sets max_memory_restart to 1500M.
sudoji › add 1 GB of swap and restart the app
allow? run fallocate -l 1G /swapfile [y/N] y
✓
allow? run chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile [y/N] y
✓
allow? run pm2 restart api [y/N] y
✓ Done.
sudoji › exitConversation threads
A thread is a stored multi-turn conversation. It records every message (user and assistant), tool calls made, and the cumulative token cost. Threads are associated with a specific server and visible in the portal.
Troubleshooting
Daemon won't connect
Run sudoji doctor to confirm your API key and network are working. Check that port 443 outbound to agent.sudoji.io is open. If behind a proxy, the proxy must support WebSocket upgrades (HTTP CONNECT tunnelling).
daemon.rejected: PLAN_INSUFFICIENT
Your account is on the Free plan. Upgrade to Engineer at sudoji.io/pricing to use the daemon.
daemon.rejected: SERVER_LIMIT
Engineer plan allows one connected daemon at a time. If you have the daemon running on multiple servers simultaneously, only the first one within the limit will be accepted. Enterprise plan removes this restriction.
Portal shows daemon offline after reconnect
The daemon updates the server's daemon_status column on connect and on disconnect. If a crash left the record stale, it will be corrected as soon as the daemon reconnects. Refresh the portal after reconnect to see the updated status.