Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(realtime): add PAT auth support to WebSocket endpoint (#568) (#587)

Bohan Jiangaec07456fc38
diff --git a/README.md b/README.md
index 4efdf6ab93..908f422c0c 100644
--- a/README.md
+++ b/README.md
@@ -31,7 +31,7 @@ Turn coding agents into real teammates — assign tasks, track progress, compoun
Multica turns coding agents into real teammates. Assign issues to an agent like you'd assign to a colleague — they'll pick up the work, write code, report blockers, and update statuses autonomously.
-No more copy-pasting prompts. No more babysitting runs. Your agents show up on the board, participate in conversations, and compound reusable skills over time. Think of it as open-source infrastructure for managed agents — vendor-neutral, self-hosted, and designed for human + AI teams. Works with **Claude Code** and **Codex**.
+No more copy-pasting prompts. No more babysitting runs. Your agents show up on the board, participate in conversations, and compound reusable skills over time. Think of it as open-source infrastructure for managed agents — vendor-neutral, self-hosted, and designed for human + AI teams. Works with **Claude Code**, **Codex**, **OpenClaw**, and **OpenCode**.
<p align="center">
<img src="docs/assets/hero-screenshot.png" alt="Multica board view" width="800">
@@ -72,7 +72,7 @@ See the [Self-Hosting Guide](SELF_HOSTING.md) for full instructions.
The `multica` CLI connects your local machine to Multica — authenticate, manage workspaces, and run the agent daemon.
-**Option A — paste this to your coding agent (Claude Code, Codex, etc.):**
+**Option A — paste this to your coding agent (Claude Code, Codex, OpenClaw, OpenCode, etc.):**
```
Fetch https://github.com/multica-ai/multica/blob/main/CLI_INSTALL.md and follow the instructions to install Multica CLI, log in, and start the daemon on this machine.
@@ -90,7 +90,7 @@ multica login
multica daemon start
```
-The daemon auto-detects available agent CLIs (`claude`, `codex`) on your PATH. When an agent is assigned a task, the daemon creates an isolated environment, runs the agent, and reports results back.
+The daemon auto-detects available agent CLIs (`claude`, `codex`, `openclaw`, `opencode`) on your PATH. When an agent is assigned a task, the daemon creates an isolated environment, runs the agent, and reports results back.
See the [CLI and Daemon Guide](CLI_AND_DAEMON.md) for the full command reference, daemon configuration, and advanced usage.
@@ -105,7 +105,7 @@ multica login # Authenticate with your Multica account
multica daemon start # Start the local agent runtime
```
-The daemon runs in the background and keeps your machine connected to Multica. It auto-detects agent CLIs (`claude`, `codex`) available on your PATH.
+The daemon runs in the background and keeps your machine connected to Multica. It auto-detects agent CLIs (`claude`, `codex`, `openclaw`, `opencode`) available on your PATH.
### 2. Verify your runtime
@@ -115,7 +115,7 @@ Open your workspace in the Multica web app. Navigate to **Settings → Runtimes*
### 3. Create an agent
-Go to **Settings → Agents** and click **New Agent**. Pick the runtime you just connected and choose a provider (Claude Code or Codex). Give your agent a name — this is how it will appear on the board, in comments, and in assignments.
+Go to **Settings → Agents** and click **New Agent**. Pick the runtime you just connected and choose a provider (Claude Code, Codex, OpenClaw, or OpenCode). Give your agent a name — this is how it will appear on the board, in comments, and in assignments.
### 4. Assign your first task
@@ -133,7 +133,8 @@ That's it! Your agent is now part of the team. 🎉
│
┌──────┴───────┐
│ Agent Daemon │ (runs on your machine)
- │ Claude/Codex │
+ │Claude/Codex/ │
+ │OpenClaw/Code │
└──────────────┘
```
@@ -142,7 +143,7 @@ That's it! Your agent is now part of the team. 🎉
| Frontend | Next.js 16 (App Router) |
| Backend | Go (Chi router, sqlc, gorilla/websocket) |
| Database | PostgreSQL 17 with pgvector |
-| Agent Runtime | Local daemon executing Claude Code or Codex |
+| Agent Runtime | Local daemon executing Claude Code, Codex, OpenClaw, or OpenCode |
## Development
diff --git a/README.zh-CN.md b/README.zh-CN.md
index d680ce154e..9d171ba20a 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -31,7 +31,7 @@
Multica 将编码 Agent 变成真正的队友。像分配给同事一样分配给 Agent——它们会自主接手工作、编写代码、报告阻塞问题、更新状态。
-不再需要复制粘贴 prompt,不再需要盯着运行过程。你的 Agent 出现在看板上、参与对话、随着时间积累可复用的技能。可以理解为开源的 Managed Agents 基础设施——厂商中立、可自部署、专为人类 + AI 团队设计。支持 **Claude Code** 和 **Codex**。
+不再需要复制粘贴 prompt,不再需要盯着运行过程。你的 Agent 出现在看板上、参与对话、随着时间积累可复用的技能。可以理解为开源的 Managed Agents 基础设施——厂商中立、可自部署、专为人类 + AI 团队设计。支持 **Claude Code**、**Codex**、**OpenClaw** 和 **OpenCode**。
<p align="center">
<img src="docs/assets/hero-screenshot.png" alt="Multica 看板视图" width="800">
@@ -72,7 +72,7 @@ make start # 启动应用
`multica` CLI 将你的本地机器连接到 Multica — 用于认证、管理工作区和运行 Agent daemon。
-**方式 A — 将以下指令粘贴给你的 coding agent(Claude Code、Codex 等):**
+**方式 A — 将以下指令粘贴给你的 coding agent(Claude Code、Codex、OpenClaw、OpenCode 等):**
```
Fetch https://github.com/multica-ai/multica/blob/main/CLI_INSTALL.md and follow the instructions to install Multica CLI, log in, and start the daemon on this machine.
@@ -90,7 +90,7 @@ multica login
multica daemon start
```
-daemon 会自动检测 PATH 中可用的 Agent CLI(`claude`、`codex`)。当 Agent 被分配任务时,daemon 会创建隔离环境、运行 Agent、并将结果回传。
+daemon 会自动检测 PATH 中可用的 Agent CLI(`claude`、`codex`、`openclaw`、`opencode`)。当 Agent 被分配任务时,daemon 会创建隔离环境、运行 Agent、并将结果回传。
完整命令参考请参阅 [CLI 与 Daemon 指南](CLI_AND_DAEMON.md)。
@@ -105,7 +105,7 @@ multica login # 使用你的 Multica 账号认证
multica daemon start # 启动本地 Agent 运行时
```
-daemon 在后台运行,保持你的机器与 Multica 的连接。它会自动检测 PATH 中可用的 Agent CLI(`claude`、`codex`)。
+daemon 在后台运行,保持你的机器与 Multica 的连接。它会自动检测 PATH 中可用的 Agent CLI(`claude`、`codex`、`openclaw`、`opencode`)。
### 2. 确认运行时已连接
@@ -115,7 +115,7 @@ daemon 在后台运行,保持你的机器与 Multica 的连接。它会自动
### 3. 创建 Agent
-进入 **设置 → Agents**,点击 **新建 Agent**。选择你刚连接的 Runtime,选择 Provider(Claude Code 或 Codex),并为 Agent 起个名字——它将以这个名字出现在看板、评论和任务分配中。
+进入 **设置 → Agents**,点击 **新建 Agent**。选择你刚连接的 Runtime,选择 Provider(Claude Code、Codex、OpenClaw 或 OpenCode),并为 Agent 起个名字——它将以这个名字出现在看板、评论和任务分配中。
### 4. 分配你的第一个任务
@@ -133,7 +133,8 @@ daemon 在后台运行,保持你的机器与 Multica 的连接。它会自动
│
┌──────┴───────┐
│ Agent Daemon │ (运行在你的机器上)
- │ Claude/Codex │
+ │Claude/Codex/ │
+ │OpenClaw/Code │
└──────────────┘
```
@@ -142,7 +143,7 @@ daemon 在后台运行,保持你的机器与 Multica 的连接。它会自动
| 前端 | Next.js 16 (App Router) |
| 后端 | Go (Chi router, sqlc, gorilla/websocket) |
| 数据库 | PostgreSQL 17 with pgvector |
-| Agent 运行时 | 本地 daemon 执行 Claude Code 或 Codex |
+| Agent 运行时 | 本地 daemon 执行 Claude Code、Codex、OpenClaw 或 OpenCode |
## 开发
diff --git a/server/cmd/server/router.go b/server/cmd/server/router.go
index 39e1194272..306ac75176 100644
--- a/server/cmd/server/router.go
+++ b/server/cmd/server/router.go
@@ -19,6 +19,7 @@ import (
"github.com/multica-ai/multica/server/internal/realtime"
"github.com/multica-ai/multica/server/internal/service"
"github.com/multica-ai/multica/server/internal/storage"
+ "github.com/multica-ai/multica/server/internal/util"
db "github.com/multica-ai/multica/server/pkg/db/generated"
)
@@ -75,8 +76,9 @@ func NewRouter(pool *pgxpool.Pool, hub *realtime.Hub, bus *events.Bus) chi.Route
// WebSocket
mc := &membershipChecker{queries: queries}
+ pr := &patResolver{queries: queries}
r.Get("/ws", func(w http.ResponseWriter, r *http.Request) {
- realtime.HandleWebSocket(hub, mc, w, r)
+ realtime.HandleWebSocket(hub, mc, pr, w, r)
})
// Auth (public)
@@ -299,6 +301,22 @@ func (mc *membershipChecker) IsMember(ctx context.Context, userID, workspaceID s
return err == nil
}
+// patResolver implements realtime.PATResolver using database queries.
+type patResolver struct {
+ queries *db.Queries
+}
+
+func (pr *patResolver) ResolveToken(ctx context.Context, token string) (string, bool) {
+ hash := auth.HashToken(token)
+ pat, err := pr.queries.GetPersonalAccessTokenByHash(ctx, hash)
+ if err != nil {
+ return "", false
+ }
+ // Best-effort: update last_used_at
+ go pr.queries.UpdatePersonalAccessTokenLastUsed(context.Background(), pat.ID)
+ return util.UUIDToString(pat.UserID), true
+}
+
func parseUUID(s string) pgtype.UUID {
var u pgtype.UUID
if err := u.Scan(s); err != nil {
diff --git a/server/internal/realtime/hub.go b/server/internal/realtime/hub.go
index 3098b7b190..ae797b2ddb 100644
--- a/server/internal/realtime/hub.go
+++ b/server/internal/realtime/hub.go
@@ -17,6 +17,12 @@ type MembershipChecker interface {
IsMember(ctx context.Context, userID, workspaceID string) bool
}
+// PATResolver resolves a Personal Access Token to a user ID.
+// Returns the user ID and true if the token is valid, or ("", false) otherwise.
+type PATResolver interface {
+ ResolveToken(ctx context.Context, token string) (userID string, ok bool)
+}
+
var upgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool {
// TODO: Restrict origins in production
@@ -214,8 +220,8 @@ func (h *Hub) Broadcast(message []byte) {
h.broadcast <- message
}
-// HandleWebSocket upgrades an HTTP connection to WebSocket with JWT auth.
-func HandleWebSocket(hub *Hub, mc MembershipChecker, w http.ResponseWriter, r *http.Request) {
+// HandleWebSocket upgrades an HTTP connection to WebSocket with JWT or PAT auth.
+func HandleWebSocket(hub *Hub, mc MembershipChecker, pr PATResolver, w http.ResponseWriter, r *http.Request) {
tokenStr := r.URL.Query().Get("token")
workspaceID := r.URL.Query().Get("workspace_id")
@@ -224,28 +230,45 @@ func HandleWebSocket(hub *Hub, mc MembershipChecker, w http.ResponseWriter, r *h
return
}
- // Validate JWT
- token, err := jwt.Parse(tokenStr, func(token *jwt.Token) (any, error) {
- if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
- return nil, jwt.ErrSignatureInvalid
+ var userID string
+
+ if strings.HasPrefix(tokenStr, "mul_") {
+ // PAT authentication
+ if pr == nil {
+ http.Error(w, `{"error":"invalid token"}`, http.StatusUnauthorized)
+ return
+ }
+ uid, ok := pr.ResolveToken(r.Context(), tokenStr)
+ if !ok {
+ http.Error(w, `{"error":"invalid token"}`, http.StatusUnauthorized)
+ return
+ }
+ userID = uid
+ } else {
+ // JWT authentication
+ token, err := jwt.Parse(tokenStr, func(token *jwt.Token) (any, error) {
+ if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
+ return nil, jwt.ErrSignatureInvalid
+ }
+ return auth.JWTSecret(), nil
+ })
+ if err != nil || !token.Valid {
+ http.Error(w, `{"error":"invalid token"}`, http.StatusUnauthorized)
+ return
}
- return auth.JWTSecret(), nil
- })
- if err != nil || !token.Valid {
- http.Error(w, `{"error":"invalid token"}`, http.StatusUnauthorized)
- return
- }
- claims, ok := token.Claims.(jwt.MapClaims)
- if !ok {
- http.Error(w, `{"error":"invalid claims"}`, http.StatusUnauthorized)
- return
- }
+ claims, ok := token.Claims.(jwt.MapClaims)
+ if !ok {
+ http.Error(w, `{"error":"invalid claims"}`, http.StatusUnauthorized)
+ return
+ }
- userID, ok := claims["sub"].(string)
- if !ok || strings.TrimSpace(userID) == "" {
- http.Error(w, `{"error":"invalid claims"}`, http.StatusUnauthorized)
- return
+ uid, ok := claims["sub"].(string)
+ if !ok || strings.TrimSpace(uid) == "" {
+ http.Error(w, `{"error":"invalid claims"}`, http.StatusUnauthorized)
+ return
+ }
+ userID = uid
}
// Verify user is a member of the workspace
diff --git a/server/internal/realtime/hub_test.go b/server/internal/realtime/hub_test.go
index 2a8df78690..2187f8d581 100644
--- a/server/internal/realtime/hub_test.go
+++ b/server/internal/realtime/hub_test.go
@@ -43,7 +43,7 @@ func newTestHub(t *testing.T) (*Hub, *httptest.Server) {
mc := &mockMembershipChecker{}
mux := http.NewServeMux()
mux.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
- HandleWebSocket(hub, mc, w, r)
+ HandleWebSocket(hub, mc, nil, w, r)
})
server := httptest.NewServer(mux)
return hub, server