feat(workspace): session-scoped Caller.Holder + ReleaseByHolder for ACP integration

This commit is contained in:
2026-05-07 14:21:00 +08:00
parent 9fc96b0a1a
commit 3e50da4a49
6 changed files with 91 additions and 4 deletions
+15 -4
View File
@@ -112,14 +112,21 @@ type FetchTarget struct {
}
// Caller 表示发起请求的用户上下文。Service 据此判定鉴权与 holder 字符串。
// SessionID 非 nil 时,Holder() 返回 "session:<uuid>"(ACP 模块用),
// 否则返回 "user:<uuid>"。
type Caller struct {
UserID uuid.UUID
IsAdmin bool
UserID uuid.UUID
IsAdmin bool
SessionID *uuid.UUID
}
// Holder 把 Caller 折成 acquire_holder 字符串。Plan #4 的 ACP supervisor 会用
// "session:<sid>" 形式调相同接口。
// Holder 把 Caller 折成 acquire_holder 字符串。
// - SessionID 非 nil → "session:<sid>"(ACP supervisor)
// - 否则 → "user:<uid>"(普通 HTTP 调用)
func (c Caller) Holder() string {
if c.SessionID != nil {
return "session:" + c.SessionID.String()
}
return "user:" + c.UserID.String()
}
@@ -147,6 +154,10 @@ type WorktreeService interface {
Delete(ctx context.Context, c Caller, wtID uuid.UUID) error
Acquire(ctx context.Context, c Caller, wtID uuid.UUID) (*Worktree, error)
Release(ctx context.Context, c Caller, wtID uuid.UUID) (*Worktree, error)
// ReleaseByHolder 按 holder 字符串释放所有该 holder 持有的 worktree。
// 由 ACP startup reaper / supervisor.onExit 在不知道 wtID 时使用。
// 不写 audit(caller 自己写 — audit 上下文是 caller 知道的)。
ReleaseByHolder(ctx context.Context, holder string) ([]*Worktree, error)
}
// GitOpsService 暴露 status/commit/push 操作。target 既可以是 Workspace(main_path)