Skip to content

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

Go

fix(workspaces): list only the bound workspace for a task token (#10984)

pseudoyu474cf3568ce8
diff --git a/apps/docs/content/docs/cli.fr.mdx b/apps/docs/content/docs/cli.fr.mdx
index 1dd11fd50a..fc17d7295b 100644
--- a/apps/docs/content/docs/cli.fr.mdx
+++ b/apps/docs/content/docs/cli.fr.mdx
@@ -521,7 +521,7 @@ Les tableaux ci-dessous couvrent toutes les commandes de premier niveau actuelle
| | `trigger <id>` | Déclencher une exécution manuellement | |
| | `runs <id>` | Afficher l'historique des exécutions | |
| | `trigger-add/trigger-update/trigger-delete/trigger-rotate-url` | Gérer les déclencheurs de planification et webhook | `trigger-add` : `--kind` (`schedule` ou `webhook`), `--cron`, `--timezone` (UTC par défaut), `--label` |
-| `workspace` | `list/get/create/update/switch` | Gérer les espaces de travail ; `switch` définit l'espace de travail par défaut du profil actuel | `create` : `--name`, `--slug` (tous deux obligatoires), `--issue-prefix`, `--description`, `--context` / `--context-stdin` ; `update` modifie les mêmes champs, sauf le slug |
+| `workspace` | `list/get/create/update/switch` | Gérer les espaces de travail ; `switch` définit l'espace de travail par défaut du profil actuel ; une exécution d'agent ne voit que son propre espace dans `list` | `create` : `--name`, `--slug` (tous deux obligatoires), `--issue-prefix`, `--description`, `--context` / `--context-stdin` ; `update` modifie les mêmes champs, sauf le slug |
| | `mcp list/add/update/remove` | Gérer la bibliothèque de serveurs MCP de l'espace de travail | Les écritures sont réservées aux propriétaires et administrateurs. Un serveur ajouté ici n'est assigné à aucun agent — attribuez-le à un agent avec `multica agent mcp add`. `list` n'affiche que les noms et les transports ; l'entrée enregistrée est en écriture seule et n'est jamais renvoyée. `--server-config-file` / `--server-config-stdin` gardent les jetons hors de l'historique du shell |
| | `member list/invite <email>` | Consulter les membres, envoyer des invitations | `invite` : `--role` (member ou admin, member par défaut) |
| `repo` | `list/add/remove/checkout` | Gérer les dépôts de l'espace de travail et les extraire localement | `--url` (répétable) ; `checkout` : `--ref` |
diff --git a/apps/docs/content/docs/cli.ja.mdx b/apps/docs/content/docs/cli.ja.mdx
index 32ed4a4411..18b80dd15d 100644
--- a/apps/docs/content/docs/cli.ja.mdx
+++ b/apps/docs/content/docs/cli.ja.mdx
@@ -513,7 +513,7 @@ CLI の設定ファイルには、あなたとして Multica にアクセスで
| | `trigger <id>` | 手動で 1 回トリガー | |
| | `runs <id>` | 実行履歴を表示 | |
| | `trigger-add/trigger-update/trigger-delete/trigger-rotate-url` | スケジュールと webhook のトリガーを管理 | `trigger-add`: `--kind`(`schedule` または `webhook`)、`--cron`、`--timezone`(既定は UTC)、`--label` |
-| `workspace` | `list/get/create/update/switch` | ワークスペースを管理。`switch` は現在のプロファイルのデフォルトワークスペースを設定 | `create`: `--name`、`--slug`(いずれも必須)、`--issue-prefix`、`--description`、`--context` / `--context-stdin`;`update` は slug 以外の同じ項目を変更 |
+| `workspace` | `list/get/create/update/switch` | ワークスペースを管理。`switch` は現在のプロファイルのデフォルトワークスペースを設定。エージェントの実行では `list` は自身のワークスペースのみ | `create`: `--name`、`--slug`(いずれも必須)、`--issue-prefix`、`--description`、`--context` / `--context-stdin`;`update` は slug 以外の同じ項目を変更 |
| | `mcp list/add/update/remove` | ワークスペースの MCP サーバーライブラリを管理 | 書き込みは owner/admin のみ。ここに追加したサーバーはどのエージェントにも割り当てられません — `multica agent mcp add` で割り当てます。`list` は名前と transport のみを表示し、保存されたエントリは書き込み専用でどのロールにも返りません。`--server-config-file` / `--server-config-stdin` はトークンをシェル履歴から守ります |
| | `member list/invite <email>` | メンバーの表示と招待 | `invite`: `--role`(member または admin。デフォルトは member) |
| `repo` | `list/add/remove/checkout` | ワークスペースのリポジトリを管理し、ローカルにチェックアウト | `--url`(繰り返し可);`checkout`: `--ref` |
diff --git a/apps/docs/content/docs/cli.ko.mdx b/apps/docs/content/docs/cli.ko.mdx
index f2eabea70b..efa7edf059 100644
--- a/apps/docs/content/docs/cli.ko.mdx
+++ b/apps/docs/content/docs/cli.ko.mdx
@@ -513,7 +513,7 @@ CLI 설정 파일에는 사용자를 대신해 Multica에 접근할 수 있는 t
| | `trigger <id>` | 수동으로 한 번 트리거 | |
| | `runs <id>` | 실행 기록 확인 | |
| | `trigger-add/trigger-update/trigger-delete/trigger-rotate-url` | 일정 및 webhook 트리거 관리 | `trigger-add`: `--kind`(`schedule` 또는 `webhook`), `--cron`, `--timezone`(기본값 UTC), `--label` |
-| `workspace` | `list/get/create/update/switch` | 워크스페이스 관리. `switch`는 현재 profile의 기본 워크스페이스 설정 | `create`: `--name`, `--slug`(모두 필수), `--issue-prefix`, `--description`, `--context` / `--context-stdin`. `update`는 slug를 제외한 같은 항목 변경 |
+| `workspace` | `list/get/create/update/switch` | 워크스페이스 관리. `switch`는 현재 profile의 기본 워크스페이스 설정. 에이전트 실행에서는 `list`에 해당 워크스페이스만 | `create`: `--name`, `--slug`(모두 필수), `--issue-prefix`, `--description`, `--context` / `--context-stdin`. `update`는 slug를 제외한 같은 항목 변경 |
| | `mcp list/add/update/remove` | 워크스페이스의 MCP 서버 라이브러리를 관리 | 쓰기는 owner/admin 전용. 여기에 추가한 서버는 어떤 에이전트에도 할당되지 않으며 `multica agent mcp add`로 할당합니다. `list`는 이름과 transport만 표시하고, 저장된 항목은 쓰기 전용이라 어떤 역할에도 반환되지 않습니다. `--server-config-file` / `--server-config-stdin`은 토큰이 셸 기록에 남지 않게 합니다 |
| | `member list/invite <email>` | 멤버 확인 및 초대 전송 | `invite`: `--role`(member 또는 admin, 기본 member) |
| `repo` | `list/add/remove/checkout` | 워크스페이스 저장소 관리 및 로컬 checkout | `--url`(반복 가능). `checkout`: `--ref` |
diff --git a/apps/docs/content/docs/cli.mdx b/apps/docs/content/docs/cli.mdx
index aff56652af..f916269ec5 100644
--- a/apps/docs/content/docs/cli.mdx
+++ b/apps/docs/content/docs/cli.mdx
@@ -548,7 +548,7 @@ Migration from CSV parsing: replace `--attachment a,b` with `--attachment a --at
| | `trigger <id>` | Trigger a run manually | |
| | `runs <id>` | View run history | |
| | `trigger-add/trigger-update/trigger-delete/trigger-rotate-url` | Manage schedule and webhook triggers | `trigger-add`: `--kind` (`schedule` or `webhook`), `--cron`, `--timezone` (default UTC), `--label` |
-| `workspace` | `list/get/create/update/switch` | Manage workspaces; `switch` sets the current profile's default workspace | `create`: `--name`, `--slug` (both required), `--issue-prefix`, `--description`, `--context` / `--context-stdin`; `update` changes the same fields except the slug |
+| `workspace` | `list/get/create/update/switch` | Manage workspaces; `switch` sets the current profile's default workspace; in an agent run, `list` shows only its own workspace | `create`: `--name`, `--slug` (both required), `--issue-prefix`, `--description`, `--context` / `--context-stdin`; `update` changes the same fields except the slug |
| | `mcp list/add/update/remove` | Manage the workspace's MCP server library | Writes are owner/admin. A server added here is assigned to no agent — give it to one with `multica agent mcp add`. `list` shows names and transports only; the stored entry is write-only and never returned. `--server-config-file` / `--server-config-stdin` keep tokens out of shell history |
| | `member list/invite <email>` | View members, send invites | `invite`: `--role` (member or admin, default member) |
| `repo` | `list/add/remove/checkout` | Manage workspace repositories and check them out locally | `--url` (repeatable); `checkout`: `--ref` |
diff --git a/apps/docs/content/docs/cli.zh-Hant.mdx b/apps/docs/content/docs/cli.zh-Hant.mdx
index 26c202bed2..82a2bf09a3 100644
--- a/apps/docs/content/docs/cli.zh-Hant.mdx
+++ b/apps/docs/content/docs/cli.zh-Hant.mdx
@@ -522,7 +522,7 @@ CLI 配置檔案包含可代表你訪問 Multica 的令牌。不要提交到倉
| | `trigger <id>` | 手動觸發一次 | |
| | `runs <id>` | 檢視執行歷史 | |
| | `trigger-add/trigger-update/trigger-delete/trigger-rotate-url` | 管理定時和 webhook 觸發器 | `trigger-add`:`--kind`(`schedule` 或 `webhook`)、`--cron`、`--timezone`(預設 UTC)、`--label` |
-| `workspace` | `list/get/create/update/switch` | 管理工作區;`switch` 設定當前 profile 的預設工作區 | `create`:`--name`、`--slug`(均必填)、`--issue-prefix`、`--description`、`--context` / `--context-stdin`;`update` 可改除 slug 外的同類欄位 |
+| `workspace` | `list/get/create/update/switch` | 管理工作區;`switch` 設定當前 profile 的預設工作區;AI 代理執行時 `list` 只回傳所在工作區 | `create`:`--name`、`--slug`(均必填)、`--issue-prefix`、`--description`、`--context` / `--context-stdin`;`update` 可改除 slug 外的同類欄位 |
| | `mcp list/add/update/remove` | 管理工作區的 MCP 服務庫 | 寫操作需要 owner/admin。這裡新增的服務不會分配給任何 agent——用 `multica agent mcp add` 分配給某個 agent。`list` 只列出名稱與 transport;儲存的條目是只寫的,任何角色都讀不回。`--server-config-file` / `--server-config-stdin` 避免 token 進入 shell 歷史 |
| | `member list/invite <email>` | 檢視成員、發出邀請 | `invite`:`--role`(member 或 admin,預設 member) |
| `repo` | `list/add/remove/checkout` | 管理工作區倉庫並檢出到本機 | `--url`(可重複);`checkout`:`--ref` |
diff --git a/apps/docs/content/docs/cli.zh.mdx b/apps/docs/content/docs/cli.zh.mdx
index 7bcf8fb26c..c921b3bbbf 100644
--- a/apps/docs/content/docs/cli.zh.mdx
+++ b/apps/docs/content/docs/cli.zh.mdx
@@ -525,7 +525,7 @@ CLI 配置文件包含可代表你访问 Multica 的令牌。不要提交到仓
| | `trigger <id>` | 手动触发一次 | |
| | `runs <id>` | 查看运行历史 | |
| | `trigger-add/trigger-update/trigger-delete/trigger-rotate-url` | 管理定时和 webhook 触发器 | `trigger-add`:`--kind`(`schedule` 或 `webhook`)、`--cron`、`--timezone`(默认 UTC)、`--label` |
-| `workspace` | `list/get/create/update/switch` | 管理工作区;`switch` 设置当前 profile 的默认工作区 | `create`:`--name`、`--slug`(均必填)、`--issue-prefix`、`--description`、`--context` / `--context-stdin`;`update` 可改除 slug 外的同类字段 |
+| `workspace` | `list/get/create/update/switch` | 管理工作区;`switch` 设置当前 profile 的默认工作区;智能体运行时 `list` 只返回所在工作区 | `create`:`--name`、`--slug`(均必填)、`--issue-prefix`、`--description`、`--context` / `--context-stdin`;`update` 可改除 slug 外的同类字段 |
| | `mcp list/add/update/remove` | 管理工作区的 MCP 服务库 | 写操作需要 owner/admin。这里添加的服务不会分配给任何 agent——用 `multica agent mcp add` 分配给某个 agent。`list` 只列出名称与 transport;存储的条目是只写的,任何角色都读不回。`--server-config-file` / `--server-config-stdin` 避免 token 进入 shell 历史 |
| | `member list/invite <email>` | 查看成员、发出邀请 | `invite`:`--role`(member 或 admin,默认 member) |
| `repo` | `list/add/remove/checkout` | 管理工作区仓库并检出到本机 | `--url`(可重复);`checkout`:`--ref` |
diff --git a/server/cmd/multica/cmd_workspace.go b/server/cmd/multica/cmd_workspace.go
index 4c974ded03..f8ef2d7ec0 100644
--- a/server/cmd/multica/cmd_workspace.go
+++ b/server/cmd/multica/cmd_workspace.go
@@ -22,6 +22,7 @@ var workspaceCmd = &cobra.Command{
var workspaceListCmd = &cobra.Command{
Use: "list",
Short: "List all workspaces you belong to",
+ Long: "List all workspaces you belong to. In an agent run, only the workspace the run belongs to is listed; the owner's other workspaces are left out.",
RunE: runWorkspaceList,
}
diff --git a/server/internal/handler/workspace.go b/server/internal/handler/workspace.go
index 3357b4d8c6..e280bc2fa3 100644
--- a/server/internal/handler/workspace.go
+++ b/server/internal/handler/workspace.go
@@ -171,9 +171,20 @@ func (h *Handler) ListWorkspaces(w http.ResponseWriter, r *http.Request) {
return
}
- resp := make([]WorkspaceResponse, len(workspaces))
- for i, ws := range workspaces {
- resp[i] = h.workspaceToResponse(db.Workspace{
+ // A task token is bound to one workspace, and Auth stamps that workspace
+ // into X-Workspace-ID. List only that one, so an agent the owner started
+ // in one workspace never sees the owner's other workspaces.
+ boundWorkspaceID := ""
+ if r.Header.Get("X-Actor-Source") == "task_token" {
+ boundWorkspaceID = r.Header.Get("X-Workspace-ID")
+ }
+
+ resp := make([]WorkspaceResponse, 0, len(workspaces))
+ for _, ws := range workspaces {
+ if boundWorkspaceID != "" && uuidToString(ws.ID) != boundWorkspaceID {
+ continue
+ }
+ item := h.workspaceToResponse(db.Workspace{
ID: ws.ID, Name: ws.Name, Slug: ws.Slug, Description: ws.Description,
Settings: ws.Settings, CreatedAt: ws.CreatedAt, UpdatedAt: ws.UpdatedAt,
Context: ws.Context, Repos: ws.Repos, IssuePrefix: ws.IssuePrefix,
@@ -182,8 +193,9 @@ func (h *Handler) ListWorkspaces(w http.ResponseWriter, r *http.Request) {
})
if ws.PinnedAt.Valid {
pinnedAt := timestampToString(ws.PinnedAt)
- resp[i].PinnedAt = &pinnedAt
+ item.PinnedAt = &pinnedAt
}
+ resp = append(resp, item)
}
writeJSON(w, http.StatusOK, resp)
diff --git a/server/internal/handler/workspace_test.go b/server/internal/handler/workspace_test.go
index 54f0dbb747..5f56d7b7fe 100644
--- a/server/internal/handler/workspace_test.go
+++ b/server/internal/handler/workspace_test.go
@@ -12,6 +12,7 @@ import (
"testing"
"time"
+ "github.com/multica-ai/multica/server/internal/middleware"
"github.com/multica-ai/multica/server/internal/testutil"
db "github.com/multica-ai/multica/server/pkg/db/generated"
)
@@ -1578,3 +1579,32 @@ func TestUpdateWorkspace_RejectsInvalidIssuePrefix(t *testing.T) {
t.Fatalf("issue_prefix changed on a rejected update: %q → %q", before, after)
}
}
+
+func TestListWorkspacesTaskCredentialSeesOnlyBoundWorkspace(t *testing.T) {
+ bound := newInboxWriteFixture(t)
+ other := newInboxWriteFixture(t)
+ token := bound.taskToken(t, testUserID)
+ ids := func(got []WorkspaceResponse) map[string]bool {
+ set := make(map[string]bool, len(got))
+ for _, ws := range got {
+ set[ws.ID] = true
+ }
+ return set
+ }
+
+ // The owner's own credential still lists every workspace.
+ var owner []WorkspaceResponse
+ testutil.Call(t, testHandler.ListWorkspaces, newRequest(http.MethodGet, "/api/workspaces", nil)).Want(http.StatusOK).JSON(&owner)
+ if got := ids(owner); !got[bound.workspaceID] || !got[other.workspaceID] {
+ t.Fatalf("owner list = %v, want both %s and %s", got, bound.workspaceID, other.workspaceID)
+ }
+
+ // The CLI lists workspaces without a workspace selector.
+ asAgent := middleware.Auth(testHandler.Queries, nil, nil, nil)(http.HandlerFunc(testHandler.ListWorkspaces))
+ req := testutil.WithHeaders(testutil.JSONRequest(http.MethodGet, "/api/workspaces", nil), "Authorization", "Bearer "+token)
+ var agent []WorkspaceResponse
+ testutil.Call(t, asAgent.ServeHTTP, req).Want(http.StatusOK).JSON(&agent)
+ if len(agent) != 1 || agent[0].ID != bound.workspaceID {
+ t.Fatalf("task credential list = %v, want only bound workspace %s", ids(agent), bound.workspaceID)
+ }
+}